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_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
37 #define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
39 int btbcm_check_bdaddr(struct hci_dev
*hdev
)
41 struct hci_rp_read_bd_addr
*bda
;
44 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_BD_ADDR
, 0, NULL
,
47 int err
= PTR_ERR(skb
);
48 bt_dev_err(hdev
, "BCM: Reading device address failed (%d)", err
);
52 if (skb
->len
!= sizeof(*bda
)) {
53 bt_dev_err(hdev
, "BCM: Device address length mismatch");
58 bda
= (struct hci_rp_read_bd_addr
*)skb
->data
;
60 /* Check if the address indicates a controller with either an
61 * invalid or default address. In both cases the device needs
62 * to be marked as not having a valid address.
64 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
65 * with no configured address.
67 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
68 * with waiting for configuration state.
70 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
71 * with waiting for configuration state.
73 if (!bacmp(&bda
->bdaddr
, BDADDR_BCM20702A0
) ||
74 !bacmp(&bda
->bdaddr
, BDADDR_BCM4324B3
) ||
75 !bacmp(&bda
->bdaddr
, BDADDR_BCM4330B1
)) {
76 bt_dev_info(hdev
, "BCM: Using default device address (%pMR)",
78 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
85 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr
);
87 int btbcm_set_bdaddr(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
92 skb
= __hci_cmd_sync(hdev
, 0xfc01, 6, bdaddr
, HCI_INIT_TIMEOUT
);
95 bt_dev_err(hdev
, "BCM: Change address command failed (%d)", err
);
102 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr
);
104 int btbcm_patchram(struct hci_dev
*hdev
, const struct firmware
*fw
)
106 const struct hci_command_hdr
*cmd
;
114 skb
= __hci_cmd_sync(hdev
, 0xfc2e, 0, NULL
, HCI_INIT_TIMEOUT
);
117 bt_dev_err(hdev
, "BCM: Download Minidrv command failed (%d)",
123 /* 50 msec delay after Download Minidrv completes */
129 while (fw_size
>= sizeof(*cmd
)) {
132 cmd
= (struct hci_command_hdr
*)fw_ptr
;
133 fw_ptr
+= sizeof(*cmd
);
134 fw_size
-= sizeof(*cmd
);
136 if (fw_size
< cmd
->plen
) {
137 bt_dev_err(hdev
, "BCM: Patch is corrupted");
144 fw_size
-= cmd
->plen
;
146 opcode
= le16_to_cpu(cmd
->opcode
);
148 skb
= __hci_cmd_sync(hdev
, opcode
, cmd
->plen
, cmd_param
,
152 bt_dev_err(hdev
, "BCM: Patch command %04x failed (%d)",
159 /* 250 msec delay after Launch Ram completes */
165 EXPORT_SYMBOL(btbcm_patchram
);
167 static int btbcm_reset(struct hci_dev
*hdev
)
171 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
173 int err
= PTR_ERR(skb
);
174 bt_dev_err(hdev
, "BCM: Reset failed (%d)", err
);
179 /* 100 msec delay for module to complete reset process */
185 static struct sk_buff
*btbcm_read_local_name(struct hci_dev
*hdev
)
189 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_NAME
, 0, NULL
,
192 bt_dev_err(hdev
, "BCM: Reading local name failed (%ld)",
197 if (skb
->len
!= sizeof(struct hci_rp_read_local_name
)) {
198 bt_dev_err(hdev
, "BCM: Local name length mismatch");
200 return ERR_PTR(-EIO
);
206 static struct sk_buff
*btbcm_read_local_version(struct hci_dev
*hdev
)
210 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
213 bt_dev_err(hdev
, "BCM: Reading local version info failed (%ld)",
218 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
219 bt_dev_err(hdev
, "BCM: Local version length mismatch");
221 return ERR_PTR(-EIO
);
227 static struct sk_buff
*btbcm_read_verbose_config(struct hci_dev
*hdev
)
231 skb
= __hci_cmd_sync(hdev
, 0xfc79, 0, NULL
, HCI_INIT_TIMEOUT
);
233 bt_dev_err(hdev
, "BCM: Read verbose config info failed (%ld)",
239 bt_dev_err(hdev
, "BCM: Verbose config length mismatch");
241 return ERR_PTR(-EIO
);
247 static struct sk_buff
*btbcm_read_controller_features(struct hci_dev
*hdev
)
251 skb
= __hci_cmd_sync(hdev
, 0xfc6e, 0, NULL
, HCI_INIT_TIMEOUT
);
253 bt_dev_err(hdev
, "BCM: Read controller features failed (%ld)",
259 bt_dev_err(hdev
, "BCM: Controller features length mismatch");
261 return ERR_PTR(-EIO
);
267 static struct sk_buff
*btbcm_read_usb_product(struct hci_dev
*hdev
)
271 skb
= __hci_cmd_sync(hdev
, 0xfc5a, 0, NULL
, HCI_INIT_TIMEOUT
);
273 bt_dev_err(hdev
, "BCM: Read USB product info failed (%ld)",
279 bt_dev_err(hdev
, "BCM: USB product length mismatch");
281 return ERR_PTR(-EIO
);
287 static int btbcm_read_info(struct hci_dev
*hdev
)
291 /* Read Verbose Config Version Info */
292 skb
= btbcm_read_verbose_config(hdev
);
296 bt_dev_info(hdev
, "BCM: chip id %u", skb
->data
[1]);
299 /* Read Controller Features */
300 skb
= btbcm_read_controller_features(hdev
);
304 bt_dev_info(hdev
, "BCM: features 0x%2.2x", skb
->data
[1]);
307 /* Read Local Name */
308 skb
= btbcm_read_local_name(hdev
);
312 bt_dev_info(hdev
, "%s", (char *)(skb
->data
+ 1));
318 struct bcm_subver_table
{
323 static const struct bcm_subver_table bcm_uart_subver_table
[] = {
324 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
325 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
326 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
327 { 0x4606, "BCM4324B5" }, /* 002.006.006 */
328 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
329 { 0x610c, "BCM4354" }, /* 003.001.012 */
330 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
331 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
332 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
333 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
337 static const struct bcm_subver_table bcm_usb_subver_table
[] = {
338 { 0x2105, "BCM20703A1" }, /* 001.001.005 */
339 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
340 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
341 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
342 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
343 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
344 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
345 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
346 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
347 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
348 { 0x610c, "BCM4354" }, /* 003.001.012 */
352 int btbcm_initialize(struct hci_dev
*hdev
, char *fw_name
, size_t len
,
355 u16 subver
, rev
, pid
, vid
;
356 const char *hw_name
= "BCM";
358 struct hci_rp_read_local_version
*ver
;
359 const struct bcm_subver_table
*bcm_subver_table
;
363 err
= btbcm_reset(hdev
);
367 /* Read Local Version Info */
368 skb
= btbcm_read_local_version(hdev
);
372 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
373 rev
= le16_to_cpu(ver
->hci_rev
);
374 subver
= le16_to_cpu(ver
->lmp_subver
);
377 /* Read controller information */
379 err
= btbcm_read_info(hdev
);
384 /* Upper nibble of rev should be between 0 and 3? */
385 if (((rev
& 0xf000) >> 12) > 3)
388 bcm_subver_table
= (hdev
->bus
== HCI_USB
) ? bcm_usb_subver_table
:
389 bcm_uart_subver_table
;
391 for (i
= 0; bcm_subver_table
[i
].name
; i
++) {
392 if (subver
== bcm_subver_table
[i
].subver
) {
393 hw_name
= bcm_subver_table
[i
].name
;
398 if (hdev
->bus
== HCI_USB
) {
399 /* Read USB Product Info */
400 skb
= btbcm_read_usb_product(hdev
);
404 vid
= get_unaligned_le16(skb
->data
+ 1);
405 pid
= get_unaligned_le16(skb
->data
+ 3);
408 snprintf(fw_name
, len
, "brcm/%s-%4.4x-%4.4x.hcd",
411 snprintf(fw_name
, len
, "brcm/%s.hcd", hw_name
);
414 bt_dev_info(hdev
, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
415 hw_name
, (subver
& 0xe000) >> 13,
416 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
420 EXPORT_SYMBOL_GPL(btbcm_initialize
);
422 int btbcm_finalize(struct hci_dev
*hdev
)
428 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), true);
432 btbcm_check_bdaddr(hdev
);
434 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
438 EXPORT_SYMBOL_GPL(btbcm_finalize
);
440 int btbcm_setup_patchram(struct hci_dev
*hdev
)
443 const struct firmware
*fw
;
448 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), false);
452 err
= request_firmware(&fw
, fw_name
, &hdev
->dev
);
454 bt_dev_info(hdev
, "BCM: Patch %s not found", fw_name
);
458 btbcm_patchram(hdev
, fw
);
460 release_firmware(fw
);
463 err
= btbcm_initialize(hdev
, fw_name
, sizeof(fw_name
), true);
467 /* Read Local Name */
468 skb
= btbcm_read_local_name(hdev
);
472 bt_dev_info(hdev
, "%s", (char *)(skb
->data
+ 1));
476 btbcm_check_bdaddr(hdev
);
478 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
482 EXPORT_SYMBOL_GPL(btbcm_setup_patchram
);
484 int btbcm_setup_apple(struct hci_dev
*hdev
)
490 err
= btbcm_reset(hdev
);
494 /* Read Verbose Config Version Info */
495 skb
= btbcm_read_verbose_config(hdev
);
497 bt_dev_info(hdev
, "BCM: chip id %u build %4.4u",
498 skb
->data
[1], get_unaligned_le16(skb
->data
+ 5));
502 /* Read USB Product Info */
503 skb
= btbcm_read_usb_product(hdev
);
505 bt_dev_info(hdev
, "BCM: product %4.4x:%4.4x",
506 get_unaligned_le16(skb
->data
+ 1),
507 get_unaligned_le16(skb
->data
+ 3));
511 /* Read Controller Features */
512 skb
= btbcm_read_controller_features(hdev
);
514 bt_dev_info(hdev
, "BCM: features 0x%2.2x", skb
->data
[1]);
518 /* Read Local Name */
519 skb
= btbcm_read_local_name(hdev
);
521 bt_dev_info(hdev
, "%s", (char *)(skb
->data
+ 1));
525 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
529 EXPORT_SYMBOL_GPL(btbcm_setup_apple
);
531 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
532 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION
);
533 MODULE_VERSION(VERSION
);
534 MODULE_LICENSE("GPL");