1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Bluetooth support for Broadcom devices
6 * Copyright (C) 2015 Intel Corporation
9 #include <linux/module.h>
10 #include <linux/firmware.h>
11 #include <asm/unaligned.h>
13 #include <net/bluetooth/bluetooth.h>
14 #include <net/bluetooth/hci_core.h>
20 #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
21 #define BDADDR_BCM20702A1 (&(bdaddr_t) {{0x00, 0x00, 0xa0, 0x02, 0x70, 0x20}})
22 #define BDADDR_BCM2076B1 (&(bdaddr_t) {{0x79, 0x56, 0x00, 0xa0, 0x76, 0x20}})
23 #define BDADDR_BCM43430A0 (&(bdaddr_t) {{0xac, 0x1f, 0x12, 0xa0, 0x43, 0x43}})
24 #define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
25 #define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
26 #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}})
28 int btbcm_check_bdaddr(struct hci_dev *hdev)
30 struct hci_rp_read_bd_addr *bda;
33 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
36 int err = PTR_ERR(skb);
37 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
41 if (skb->len != sizeof(*bda)) {
42 bt_dev_err(hdev, "BCM: Device address length mismatch");
47 bda = (struct hci_rp_read_bd_addr *)skb->data;
49 /* Check if the address indicates a controller with either an
50 * invalid or default address. In both cases the device needs
51 * to be marked as not having a valid address.
53 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
54 * with no configured address.
56 * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller
57 * with no configured address.
59 * The address 20:76:A0:00:56:79 indicates a BCM2076B1 controller
60 * with no configured address.
62 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
63 * with waiting for configuration state.
65 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
66 * with waiting for configuration state.
68 * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller
69 * with no configured address.
71 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
72 !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) ||
73 !bacmp(&bda->bdaddr, BDADDR_BCM2076B1) ||
74 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
75 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) ||
76 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) ||
77 !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) {
78 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
80 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
87 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
89 int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
94 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
97 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
104 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
106 int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
108 const struct hci_command_hdr *cmd;
116 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
119 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
125 /* 50 msec delay after Download Minidrv completes */
131 while (fw_size >= sizeof(*cmd)) {
134 cmd = (struct hci_command_hdr *)fw_ptr;
135 fw_ptr += sizeof(*cmd);
136 fw_size -= sizeof(*cmd);
138 if (fw_size < cmd->plen) {
139 bt_dev_err(hdev, "BCM: Patch is corrupted");
146 fw_size -= cmd->plen;
148 opcode = le16_to_cpu(cmd->opcode);
150 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
154 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
161 /* 250 msec delay after Launch Ram completes */
167 EXPORT_SYMBOL(btbcm_patchram);
169 static int btbcm_reset(struct hci_dev *hdev)
173 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
175 int err = PTR_ERR(skb);
176 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
181 /* 100 msec delay for module to complete reset process */
187 static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
191 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
194 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
199 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
200 bt_dev_err(hdev, "BCM: Local name length mismatch");
202 return ERR_PTR(-EIO);
208 static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
212 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
215 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
220 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
221 bt_dev_err(hdev, "BCM: Local version length mismatch");
223 return ERR_PTR(-EIO);
229 static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
233 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
235 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
241 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
243 return ERR_PTR(-EIO);
249 static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
253 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
255 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
261 bt_dev_err(hdev, "BCM: Controller features length mismatch");
263 return ERR_PTR(-EIO);
269 static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
273 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
275 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
281 bt_dev_err(hdev, "BCM: USB product length mismatch");
283 return ERR_PTR(-EIO);
289 static int btbcm_read_info(struct hci_dev *hdev)
293 /* Read Verbose Config Version Info */
294 skb = btbcm_read_verbose_config(hdev);
298 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
301 /* Read Controller Features */
302 skb = btbcm_read_controller_features(hdev);
306 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
309 /* Read Local Name */
310 skb = btbcm_read_local_name(hdev);
314 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
320 struct bcm_subver_table {
325 static const struct bcm_subver_table bcm_uart_subver_table[] = {
326 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
327 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
328 { 0x4204, "BCM2076B1" }, /* 002.002.004 */
329 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
330 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
331 { 0x610c, "BCM4354" }, /* 003.001.012 */
332 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
333 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
334 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
335 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
336 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
337 { 0x4217, "BCM4329B1" }, /* 002.002.023 */
341 static const struct bcm_subver_table bcm_usb_subver_table[] = {
342 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
343 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
344 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
345 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
346 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
347 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
348 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
349 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
350 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
351 { 0x610c, "BCM4354" }, /* 003.001.012 */
355 int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len,
358 u16 subver, rev, pid, vid;
359 const char *hw_name = "BCM";
361 struct hci_rp_read_local_version *ver;
362 const struct bcm_subver_table *bcm_subver_table;
366 err = btbcm_reset(hdev);
370 /* Read Local Version Info */
371 skb = btbcm_read_local_version(hdev);
375 ver = (struct hci_rp_read_local_version *)skb->data;
376 rev = le16_to_cpu(ver->hci_rev);
377 subver = le16_to_cpu(ver->lmp_subver);
380 /* Read controller information */
382 err = btbcm_read_info(hdev);
387 /* Upper nibble of rev should be between 0 and 3? */
388 if (((rev & 0xf000) >> 12) > 3)
391 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
392 bcm_uart_subver_table;
394 for (i = 0; bcm_subver_table[i].name; i++) {
395 if (subver == bcm_subver_table[i].subver) {
396 hw_name = bcm_subver_table[i].name;
401 if (hdev->bus == HCI_USB) {
402 /* Read USB Product Info */
403 skb = btbcm_read_usb_product(hdev);
407 vid = get_unaligned_le16(skb->data + 1);
408 pid = get_unaligned_le16(skb->data + 3);
411 snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd",
414 snprintf(fw_name, len, "brcm/%s.hcd", hw_name);
417 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
418 hw_name, (subver & 0xe000) >> 13,
419 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
423 EXPORT_SYMBOL_GPL(btbcm_initialize);
425 int btbcm_finalize(struct hci_dev *hdev)
431 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
435 btbcm_check_bdaddr(hdev);
437 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
441 EXPORT_SYMBOL_GPL(btbcm_finalize);
443 int btbcm_setup_patchram(struct hci_dev *hdev)
446 const struct firmware *fw;
451 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false);
455 err = request_firmware(&fw, fw_name, &hdev->dev);
457 bt_dev_info(hdev, "BCM: Patch %s not found", fw_name);
461 btbcm_patchram(hdev, fw);
463 release_firmware(fw);
466 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
470 /* Read Local Name */
471 skb = btbcm_read_local_name(hdev);
475 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
479 btbcm_check_bdaddr(hdev);
481 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
485 EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
487 int btbcm_setup_apple(struct hci_dev *hdev)
493 err = btbcm_reset(hdev);
497 /* Read Verbose Config Version Info */
498 skb = btbcm_read_verbose_config(hdev);
500 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
501 skb->data[1], get_unaligned_le16(skb->data + 5));
505 /* Read USB Product Info */
506 skb = btbcm_read_usb_product(hdev);
508 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
509 get_unaligned_le16(skb->data + 1),
510 get_unaligned_le16(skb->data + 3));
514 /* Read Controller Features */
515 skb = btbcm_read_controller_features(hdev);
517 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
521 /* Read Local Name */
522 skb = btbcm_read_local_name(hdev);
524 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
528 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
532 EXPORT_SYMBOL_GPL(btbcm_setup_apple);
535 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
536 MODULE_VERSION(VERSION);
537 MODULE_LICENSE("GPL");