3 * Bluetooth support for Broadcom devices
5 * Copyright (C) 2015 Intel Corporation
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/firmware.h>
26 #include <asm/unaligned.h>
28 #include <net/bluetooth/bluetooth.h>
29 #include <net/bluetooth/hci_core.h>
35 #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
37 int btbcm_check_bdaddr(struct hci_dev *hdev)
39 struct hci_rp_read_bd_addr *bda;
42 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
45 int err = PTR_ERR(skb);
46 BT_ERR("%s: BCM: Reading device address failed (%d)",
51 if (skb->len != sizeof(*bda)) {
52 BT_ERR("%s: BCM: Device address length mismatch", hdev->name);
57 bda = (struct hci_rp_read_bd_addr *)skb->data;
59 BT_ERR("%s: BCM: Device address result failed (%02x)",
60 hdev->name, bda->status);
62 return -bt_to_errno(bda->status);
65 /* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
66 * with no configured address.
68 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0)) {
69 BT_INFO("%s: BCM: Using default device address (%pMR)",
70 hdev->name, &bda->bdaddr);
71 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
78 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
80 int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
85 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
88 BT_ERR("%s: BCM: Change address command failed (%d)",
96 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
98 static int btbcm_reset(struct hci_dev *hdev)
102 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
104 int err = PTR_ERR(skb);
105 BT_ERR("%s: BCM: Reset failed (%d)", hdev->name, err);
113 static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
117 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
120 BT_ERR("%s: BCM: Reading local version info failed (%ld)",
121 hdev->name, PTR_ERR(skb));
125 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
126 BT_ERR("%s: BCM: Local version length mismatch", hdev->name);
128 return ERR_PTR(-EIO);
134 static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
138 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
140 BT_ERR("%s: BCM: Read verbose config info failed (%ld)",
141 hdev->name, PTR_ERR(skb));
146 BT_ERR("%s: BCM: Verbose config length mismatch", hdev->name);
148 return ERR_PTR(-EIO);
154 static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
158 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
160 BT_ERR("%s: BCM: Read USB product info failed (%ld)",
161 hdev->name, PTR_ERR(skb));
166 BT_ERR("%s: BCM: USB product length mismatch", hdev->name);
168 return ERR_PTR(-EIO);
174 static const struct {
177 } bcm_subver_table[] = {
178 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
179 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
180 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
181 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
182 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
183 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
184 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
185 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
186 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
187 { 0x610c, "BCM4354" }, /* 003.001.012 */
191 int btbcm_setup_patchram(struct hci_dev *hdev)
193 const struct hci_command_hdr *cmd;
194 const struct firmware *fw;
198 u16 opcode, subver, rev, pid, vid;
199 const char *hw_name = NULL;
201 struct hci_rp_read_local_version *ver;
205 err = btbcm_reset(hdev);
209 /* Read Local Version Info */
210 skb = btbcm_read_local_version(hdev);
214 ver = (struct hci_rp_read_local_version *)skb->data;
215 rev = le16_to_cpu(ver->hci_rev);
216 subver = le16_to_cpu(ver->lmp_subver);
219 /* Read Verbose Config Version Info */
220 skb = btbcm_read_verbose_config(hdev);
224 BT_INFO("%s: BCM: chip id %u", hdev->name, skb->data[1]);
227 /* Read USB Product Info */
228 skb = btbcm_read_usb_product(hdev);
232 vid = get_unaligned_le16(skb->data + 1);
233 pid = get_unaligned_le16(skb->data + 3);
236 for (i = 0; bcm_subver_table[i].name; i++) {
237 if (subver == bcm_subver_table[i].subver) {
238 hw_name = bcm_subver_table[i].name;
243 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev->name,
244 hw_name ? : "BCM", (subver & 0x7000) >> 13,
245 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
247 snprintf(fw_name, sizeof(fw_name), "brcm/%s-%4.4x-%4.4x.hcd",
248 hw_name ? : "BCM", vid, pid);
250 err = request_firmware(&fw, fw_name, &hdev->dev);
252 BT_INFO("%s: BCM: patch %s not found", hdev->name, fw_name);
257 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
260 BT_ERR("%s: BCM: Download Minidrv command failed (%d)",
266 /* 50 msec delay after Download Minidrv completes */
272 while (fw_size >= sizeof(*cmd)) {
275 cmd = (struct hci_command_hdr *)fw_ptr;
276 fw_ptr += sizeof(*cmd);
277 fw_size -= sizeof(*cmd);
279 if (fw_size < cmd->plen) {
280 BT_ERR("%s: BCM: patch %s is corrupted", hdev->name,
288 fw_size -= cmd->plen;
290 opcode = le16_to_cpu(cmd->opcode);
292 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
296 BT_ERR("%s: BCM: patch command %04x failed (%d)",
297 hdev->name, opcode, err);
303 /* 250 msec delay after Launch Ram completes */
308 err = btbcm_reset(hdev);
312 /* Read Local Version Info */
313 skb = btbcm_read_local_version(hdev);
319 ver = (struct hci_rp_read_local_version *)skb->data;
320 rev = le16_to_cpu(ver->hci_rev);
321 subver = le16_to_cpu(ver->lmp_subver);
324 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev->name,
325 hw_name ? : "BCM", (subver & 0x7000) >> 13,
326 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
328 btbcm_check_bdaddr(hdev);
330 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
333 release_firmware(fw);
337 EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
339 int btbcm_setup_apple(struct hci_dev *hdev)
343 /* Read Verbose Config Version Info */
344 skb = btbcm_read_verbose_config(hdev);
348 BT_INFO("%s: BCM: chip id %u build %4.4u", hdev->name, skb->data[1],
349 get_unaligned_le16(skb->data + 5));
352 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
356 EXPORT_SYMBOL_GPL(btbcm_setup_apple);
358 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
359 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
360 MODULE_VERSION(VERSION);
361 MODULE_LICENSE("GPL");