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 { 0x4606, "BCM4324B5" }, /* 002.006.006 */
384 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
385 { 0x610c, "BCM4354" }, /* 003.001.012 */
386 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
387 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
388 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
389 { 0x6606, "BCM4345C5" }, /* 003.006.006 */
390 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
391 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
392 { 0x4217, "BCM4329B1" }, /* 002.002.023 */
393 { 0x6106, "BCM4359C0" }, /* 003.001.006 */
394 { 0x4106, "BCM4335A0" }, /* 002.001.006 */
398 static const struct bcm_subver_table bcm_usb_subver_table
[] = {
399 { 0x2105, "BCM20703A1" }, /* 001.001.005 */
400 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
401 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
402 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
403 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
404 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
405 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
406 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
407 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
408 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
409 { 0x610c, "BCM4354" }, /* 003.001.012 */
413 int btbcm_initialize(struct hci_dev
*hdev
, char *fw_name
, size_t len
,
416 u16 subver
, rev
, pid
, vid
;
417 const char *hw_name
= "BCM";
419 struct hci_rp_read_local_version
*ver
;
420 const struct bcm_subver_table
*bcm_subver_table
;
424 err
= btbcm_reset(hdev
);
428 /* Read Local Version Info */
429 skb
= btbcm_read_local_version(hdev
);
433 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
434 rev
= le16_to_cpu(ver
->hci_rev
);
435 subver
= le16_to_cpu(ver
->lmp_subver
);
438 /* Read controller information */
440 err
= btbcm_read_info(hdev
);
445 /* Upper nibble of rev should be between 0 and 3? */
446 if (((rev
& 0xf000) >> 12) > 3)
449 bcm_subver_table
= (hdev
->bus
== HCI_USB
) ? bcm_usb_subver_table
:
450 bcm_uart_subver_table
;
452 for (i
= 0; bcm_subver_table
[i
].name
; i
++) {
453 if (subver
== bcm_subver_table
[i
].subver
) {
454 hw_name
= bcm_subver_table
[i
].name
;
459 if (hdev
->bus
== HCI_USB
) {
460 /* Read USB Product Info */
461 skb
= btbcm_read_usb_product(hdev
);
465 vid
= get_unaligned_le16(skb
->data
+ 1);
466 pid
= get_unaligned_le16(skb
->data
+ 3);
469 snprintf(fw_name
, len
, "brcm/%s-%4.4x-%4.4x.hcd",
472 snprintf(fw_name
, len
, "brcm/%s.hcd", hw_name
);
475 bt_dev_info(hdev
, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
476 hw_name
, (subver
& 0xe000) >> 13,
477 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
481 EXPORT_SYMBOL_GPL(btbcm_initialize
);
483 int btbcm_finalize(struct hci_dev
*hdev
)
489 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), true);
493 btbcm_check_bdaddr(hdev
);
495 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
497 /* Some devices ship with the controller default address.
498 * Allow the bootloader to set a valid address through the
501 set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY
, &hdev
->quirks
);
505 EXPORT_SYMBOL_GPL(btbcm_finalize
);
507 int btbcm_setup_patchram(struct hci_dev
*hdev
)
510 const struct firmware
*fw
;
515 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), false);
519 err
= request_firmware(&fw
, fw_name
, &hdev
->dev
);
521 bt_dev_info(hdev
, "BCM: Patch %s not found", fw_name
);
525 btbcm_patchram(hdev
, fw
);
527 release_firmware(fw
);
530 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), true);
534 /* Read Local Name */
535 skb
= btbcm_read_local_name(hdev
);
539 bt_dev_info(hdev
, "%s", (char *)(skb
->data
+ 1));
543 btbcm_check_bdaddr(hdev
);
545 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
549 EXPORT_SYMBOL_GPL(btbcm_setup_patchram
);
551 int btbcm_setup_apple(struct hci_dev
*hdev
)
557 err
= btbcm_reset(hdev
);
561 /* Read Verbose Config Version Info */
562 skb
= btbcm_read_verbose_config(hdev
);
564 bt_dev_info(hdev
, "BCM: chip id %u build %4.4u",
565 skb
->data
[1], get_unaligned_le16(skb
->data
+ 5));
569 /* Read USB Product Info */
570 skb
= btbcm_read_usb_product(hdev
);
572 bt_dev_info(hdev
, "BCM: product %4.4x:%4.4x",
573 get_unaligned_le16(skb
->data
+ 1),
574 get_unaligned_le16(skb
->data
+ 3));
578 /* Read Controller Features */
579 skb
= btbcm_read_controller_features(hdev
);
581 bt_dev_info(hdev
, "BCM: features 0x%2.2x", skb
->data
[1]);
585 /* Read Local Name */
586 skb
= btbcm_read_local_name(hdev
);
588 bt_dev_info(hdev
, "%s", (char *)(skb
->data
+ 1));
592 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
596 EXPORT_SYMBOL_GPL(btbcm_setup_apple
);
598 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
599 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION
);
600 MODULE_VERSION(VERSION
);
601 MODULE_LICENSE("GPL");