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_BCM4334B0 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb0, 0x34, 0x43}})
27 #define BDADDR_BCM4345C5 (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0xc5, 0x45, 0x43}})
28 #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}})
30 int btbcm_check_bdaddr(struct hci_dev *hdev)
32 struct hci_rp_read_bd_addr *bda;
35 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
38 int err = PTR_ERR(skb);
40 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
44 if (skb->len != sizeof(*bda)) {
45 bt_dev_err(hdev, "BCM: Device address length mismatch");
50 bda = (struct hci_rp_read_bd_addr *)skb->data;
52 /* Check if the address indicates a controller with either an
53 * invalid or default address. In both cases the device needs
54 * to be marked as not having a valid address.
56 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
57 * with no configured address.
59 * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller
60 * with no configured address.
62 * The address 20:76:A0:00:56:79 indicates a BCM2076B1 controller
63 * with no configured address.
65 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
66 * with waiting for configuration state.
68 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
69 * with waiting for configuration state.
71 * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller
72 * with no configured address.
74 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
75 !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) ||
76 !bacmp(&bda->bdaddr, BDADDR_BCM2076B1) ||
77 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
78 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) ||
79 !bacmp(&bda->bdaddr, BDADDR_BCM4334B0) ||
80 !bacmp(&bda->bdaddr, BDADDR_BCM4345C5) ||
81 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) ||
82 !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) {
83 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
85 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
92 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
94 int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
99 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
102 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
109 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
111 int btbcm_read_pcm_int_params(struct hci_dev *hdev,
112 struct bcm_set_pcm_int_params *params)
117 skb = __hci_cmd_sync(hdev, 0xfc1d, 0, NULL, HCI_INIT_TIMEOUT);
120 bt_dev_err(hdev, "BCM: Read PCM int params failed (%d)", err);
124 if (skb->len != 6 || skb->data[0]) {
125 bt_dev_err(hdev, "BCM: Read PCM int params length mismatch");
131 memcpy(params, skb->data + 1, 5);
137 EXPORT_SYMBOL_GPL(btbcm_read_pcm_int_params);
139 int btbcm_write_pcm_int_params(struct hci_dev *hdev,
140 const struct bcm_set_pcm_int_params *params)
145 skb = __hci_cmd_sync(hdev, 0xfc1c, 5, params, HCI_INIT_TIMEOUT);
148 bt_dev_err(hdev, "BCM: Write PCM int params failed (%d)", err);
155 EXPORT_SYMBOL_GPL(btbcm_write_pcm_int_params);
157 int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
159 const struct hci_command_hdr *cmd;
167 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
170 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
176 /* 50 msec delay after Download Minidrv completes */
182 while (fw_size >= sizeof(*cmd)) {
185 cmd = (struct hci_command_hdr *)fw_ptr;
186 fw_ptr += sizeof(*cmd);
187 fw_size -= sizeof(*cmd);
189 if (fw_size < cmd->plen) {
190 bt_dev_err(hdev, "BCM: Patch is corrupted");
197 fw_size -= cmd->plen;
199 opcode = le16_to_cpu(cmd->opcode);
201 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
205 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
212 /* 250 msec delay after Launch Ram completes */
218 EXPORT_SYMBOL(btbcm_patchram);
220 static int btbcm_reset(struct hci_dev *hdev)
224 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
226 int err = PTR_ERR(skb);
228 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
233 /* 100 msec delay for module to complete reset process */
239 static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
243 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
246 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
251 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
252 bt_dev_err(hdev, "BCM: Local name length mismatch");
254 return ERR_PTR(-EIO);
260 static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
264 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
267 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
272 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
273 bt_dev_err(hdev, "BCM: Local version length mismatch");
275 return ERR_PTR(-EIO);
281 static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
285 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
287 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
293 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
295 return ERR_PTR(-EIO);
301 static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
305 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
307 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
313 bt_dev_err(hdev, "BCM: Controller features length mismatch");
315 return ERR_PTR(-EIO);
321 static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
325 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
327 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
333 bt_dev_err(hdev, "BCM: USB product length mismatch");
335 return ERR_PTR(-EIO);
341 static int btbcm_read_info(struct hci_dev *hdev)
345 /* Read Verbose Config Version Info */
346 skb = btbcm_read_verbose_config(hdev);
350 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
353 /* Read Controller Features */
354 skb = btbcm_read_controller_features(hdev);
358 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
361 /* Read Local Name */
362 skb = btbcm_read_local_name(hdev);
366 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
372 struct bcm_subver_table {
377 static const struct bcm_subver_table bcm_uart_subver_table[] = {
378 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
379 { 0x410d, "BCM4334B0" }, /* 002.001.013 */
380 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
381 { 0x4204, "BCM2076B1" }, /* 002.002.004 */
382 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
383 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
384 { 0x610c, "BCM4354" }, /* 003.001.012 */
385 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
386 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
387 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
388 { 0x6606, "BCM4345C5" }, /* 003.006.006 */
389 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
390 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
391 { 0x4217, "BCM4329B1" }, /* 002.002.023 */
392 { 0x6106, "BCM4359C0" }, /* 003.001.006 */
393 { 0x4106, "BCM4335A0" }, /* 002.001.006 */
397 static const struct bcm_subver_table bcm_usb_subver_table[] = {
398 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
399 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
400 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
401 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
402 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
403 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
404 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
405 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
406 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
407 { 0x610c, "BCM4354" }, /* 003.001.012 */
411 int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len,
414 u16 subver, rev, pid, vid;
415 const char *hw_name = "BCM";
417 struct hci_rp_read_local_version *ver;
418 const struct bcm_subver_table *bcm_subver_table;
422 err = btbcm_reset(hdev);
426 /* Read Local Version Info */
427 skb = btbcm_read_local_version(hdev);
431 ver = (struct hci_rp_read_local_version *)skb->data;
432 rev = le16_to_cpu(ver->hci_rev);
433 subver = le16_to_cpu(ver->lmp_subver);
436 /* Read controller information */
438 err = btbcm_read_info(hdev);
443 /* Upper nibble of rev should be between 0 and 3? */
444 if (((rev & 0xf000) >> 12) > 3)
447 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
448 bcm_uart_subver_table;
450 for (i = 0; bcm_subver_table[i].name; i++) {
451 if (subver == bcm_subver_table[i].subver) {
452 hw_name = bcm_subver_table[i].name;
457 if (hdev->bus == HCI_USB) {
458 /* Read USB Product Info */
459 skb = btbcm_read_usb_product(hdev);
463 vid = get_unaligned_le16(skb->data + 1);
464 pid = get_unaligned_le16(skb->data + 3);
467 snprintf(fw_name, len, "/*(DEBLOBBED)*/",
470 snprintf(fw_name, len, "/*(DEBLOBBED)*/", hw_name);
473 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
474 hw_name, (subver & 0xe000) >> 13,
475 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
479 EXPORT_SYMBOL_GPL(btbcm_initialize);
481 int btbcm_finalize(struct hci_dev *hdev)
487 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
491 btbcm_check_bdaddr(hdev);
493 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
495 /* Some devices ship with the controller default address.
496 * Allow the bootloader to set a valid address through the
499 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks);
503 EXPORT_SYMBOL_GPL(btbcm_finalize);
505 int btbcm_setup_patchram(struct hci_dev *hdev)
508 const struct firmware *fw;
513 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false);
517 err = reject_firmware(&fw, fw_name, &hdev->dev);
519 bt_dev_info(hdev, "BCM: Patch %s not found", fw_name);
523 btbcm_patchram(hdev, fw);
525 release_firmware(fw);
528 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
532 /* Read Local Name */
533 skb = btbcm_read_local_name(hdev);
537 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
541 btbcm_check_bdaddr(hdev);
543 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
547 EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
549 int btbcm_setup_apple(struct hci_dev *hdev)
555 err = btbcm_reset(hdev);
559 /* Read Verbose Config Version Info */
560 skb = btbcm_read_verbose_config(hdev);
562 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
563 skb->data[1], get_unaligned_le16(skb->data + 5));
567 /* Read USB Product Info */
568 skb = btbcm_read_usb_product(hdev);
570 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
571 get_unaligned_le16(skb->data + 1),
572 get_unaligned_le16(skb->data + 3));
576 /* Read Controller Features */
577 skb = btbcm_read_controller_features(hdev);
579 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
583 /* Read Local Name */
584 skb = btbcm_read_local_name(hdev);
586 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
590 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
594 EXPORT_SYMBOL_GPL(btbcm_setup_apple);
596 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
597 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
598 MODULE_VERSION(VERSION);
599 MODULE_LICENSE("GPL");