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}})
36 #define BDADDR_BCM20702A1 (&(bdaddr_t) {{0x00, 0x00, 0xa0, 0x02, 0x70, 0x20}})
37 #define BDADDR_BCM43430A0 (&(bdaddr_t) {{0xac, 0x1f, 0x12, 0xa0, 0x43, 0x43}})
38 #define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
39 #define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
41 int btbcm_check_bdaddr(struct hci_dev *hdev)
43 struct hci_rp_read_bd_addr *bda;
46 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
49 int err = PTR_ERR(skb);
50 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
54 if (skb->len != sizeof(*bda)) {
55 bt_dev_err(hdev, "BCM: Device address length mismatch");
60 bda = (struct hci_rp_read_bd_addr *)skb->data;
62 /* Check if the address indicates a controller with either an
63 * invalid or default address. In both cases the device needs
64 * to be marked as not having a valid address.
66 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
67 * with no configured address.
69 * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller
70 * with no configured address.
72 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
73 * with waiting for configuration state.
75 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
76 * with waiting for configuration state.
78 * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller
79 * with no configured address.
81 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
82 !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) ||
83 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
84 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) ||
85 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0)) {
86 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
88 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
95 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
97 int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
102 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
105 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
112 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
114 int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
116 const struct hci_command_hdr *cmd;
124 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
127 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
133 /* 50 msec delay after Download Minidrv completes */
139 while (fw_size >= sizeof(*cmd)) {
142 cmd = (struct hci_command_hdr *)fw_ptr;
143 fw_ptr += sizeof(*cmd);
144 fw_size -= sizeof(*cmd);
146 if (fw_size < cmd->plen) {
147 bt_dev_err(hdev, "BCM: Patch is corrupted");
154 fw_size -= cmd->plen;
156 opcode = le16_to_cpu(cmd->opcode);
158 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
162 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
169 /* 250 msec delay after Launch Ram completes */
175 EXPORT_SYMBOL(btbcm_patchram);
177 static int btbcm_reset(struct hci_dev *hdev)
181 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
183 int err = PTR_ERR(skb);
184 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
189 /* 100 msec delay for module to complete reset process */
195 static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
199 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
202 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
207 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
208 bt_dev_err(hdev, "BCM: Local name length mismatch");
210 return ERR_PTR(-EIO);
216 static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
220 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
223 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
228 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
229 bt_dev_err(hdev, "BCM: Local version length mismatch");
231 return ERR_PTR(-EIO);
237 static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
241 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
243 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
249 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
251 return ERR_PTR(-EIO);
257 static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
261 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
263 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
269 bt_dev_err(hdev, "BCM: Controller features length mismatch");
271 return ERR_PTR(-EIO);
277 static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
281 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
283 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
289 bt_dev_err(hdev, "BCM: USB product length mismatch");
291 return ERR_PTR(-EIO);
297 static int btbcm_read_info(struct hci_dev *hdev)
301 /* Read Verbose Config Version Info */
302 skb = btbcm_read_verbose_config(hdev);
306 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
309 /* Read Controller Features */
310 skb = btbcm_read_controller_features(hdev);
314 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
317 /* Read Local Name */
318 skb = btbcm_read_local_name(hdev);
322 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
328 struct bcm_subver_table {
333 static const struct bcm_subver_table bcm_uart_subver_table[] = {
334 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
335 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
336 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
337 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
338 { 0x610c, "BCM4354" }, /* 003.001.012 */
339 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
340 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
341 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
342 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
343 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
344 { 0x4217, "BCM4329B1" }, /* 002.002.023 */
348 static const struct bcm_subver_table bcm_usb_subver_table[] = {
349 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
350 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
351 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
352 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
353 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
354 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
355 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
356 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
357 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
358 { 0x610c, "BCM4354" }, /* 003.001.012 */
362 int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len,
365 u16 subver, rev, pid, vid;
366 const char *hw_name = "BCM";
368 struct hci_rp_read_local_version *ver;
369 const struct bcm_subver_table *bcm_subver_table;
373 err = btbcm_reset(hdev);
377 /* Read Local Version Info */
378 skb = btbcm_read_local_version(hdev);
382 ver = (struct hci_rp_read_local_version *)skb->data;
383 rev = le16_to_cpu(ver->hci_rev);
384 subver = le16_to_cpu(ver->lmp_subver);
387 /* Read controller information */
389 err = btbcm_read_info(hdev);
394 /* Upper nibble of rev should be between 0 and 3? */
395 if (((rev & 0xf000) >> 12) > 3)
398 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
399 bcm_uart_subver_table;
401 for (i = 0; bcm_subver_table[i].name; i++) {
402 if (subver == bcm_subver_table[i].subver) {
403 hw_name = bcm_subver_table[i].name;
408 if (hdev->bus == HCI_USB) {
409 /* Read USB Product Info */
410 skb = btbcm_read_usb_product(hdev);
414 vid = get_unaligned_le16(skb->data + 1);
415 pid = get_unaligned_le16(skb->data + 3);
418 snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd",
421 snprintf(fw_name, len, "brcm/%s.hcd", hw_name);
424 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
425 hw_name, (subver & 0xe000) >> 13,
426 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
430 EXPORT_SYMBOL_GPL(btbcm_initialize);
432 int btbcm_finalize(struct hci_dev *hdev)
438 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
442 btbcm_check_bdaddr(hdev);
444 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
448 EXPORT_SYMBOL_GPL(btbcm_finalize);
450 int btbcm_setup_patchram(struct hci_dev *hdev)
453 const struct firmware *fw;
458 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false);
462 err = request_firmware(&fw, fw_name, &hdev->dev);
464 bt_dev_info(hdev, "BCM: Patch %s not found", fw_name);
468 btbcm_patchram(hdev, fw);
470 release_firmware(fw);
473 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
477 /* Read Local Name */
478 skb = btbcm_read_local_name(hdev);
482 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
486 btbcm_check_bdaddr(hdev);
488 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
492 EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
494 int btbcm_setup_apple(struct hci_dev *hdev)
500 err = btbcm_reset(hdev);
504 /* Read Verbose Config Version Info */
505 skb = btbcm_read_verbose_config(hdev);
507 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
508 skb->data[1], get_unaligned_le16(skb->data + 5));
512 /* Read USB Product Info */
513 skb = btbcm_read_usb_product(hdev);
515 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
516 get_unaligned_le16(skb->data + 1),
517 get_unaligned_le16(skb->data + 3));
521 /* Read Controller Features */
522 skb = btbcm_read_controller_features(hdev);
524 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
528 /* Read Local Name */
529 skb = btbcm_read_local_name(hdev);
531 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
535 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
539 EXPORT_SYMBOL_GPL(btbcm_setup_apple);
542 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
543 MODULE_VERSION(VERSION);
544 MODULE_LICENSE("GPL");