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_ERR("%s: BCM: Reading device address failed (%d)",
53 if (skb
->len
!= sizeof(*bda
)) {
54 BT_ERR("%s: BCM: Device address length mismatch", hdev
->name
);
59 bda
= (struct hci_rp_read_bd_addr
*)skb
->data
;
61 /* Check if the address indicates a controller with either an
62 * invalid or default address. In both cases the device needs
63 * to be marked as not having a valid address.
65 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
66 * with no configured address.
68 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
69 * with waiting for configuration state.
71 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
72 * with waiting for configuration state.
74 if (!bacmp(&bda
->bdaddr
, BDADDR_BCM20702A0
) ||
75 !bacmp(&bda
->bdaddr
, BDADDR_BCM4324B3
) ||
76 !bacmp(&bda
->bdaddr
, BDADDR_BCM4330B1
)) {
77 BT_INFO("%s: BCM: Using default device address (%pMR)",
78 hdev
->name
, &bda
->bdaddr
);
79 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
86 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr
);
88 int btbcm_set_bdaddr(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
93 skb
= __hci_cmd_sync(hdev
, 0xfc01, 6, bdaddr
, HCI_INIT_TIMEOUT
);
96 BT_ERR("%s: BCM: Change address command failed (%d)",
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_ERR("%s: 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_ERR("%s: BCM: Patch is corrupted", hdev
->name
);
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_ERR("%s: BCM: Patch command %04x failed (%d)",
155 hdev
->name
, opcode
, err
);
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_ERR("%s: BCM: Reset failed (%d)", hdev
->name
, err
);
184 static struct sk_buff
*btbcm_read_local_name(struct hci_dev
*hdev
)
188 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_NAME
, 0, NULL
,
191 BT_ERR("%s: BCM: Reading local name failed (%ld)",
192 hdev
->name
, PTR_ERR(skb
));
196 if (skb
->len
!= sizeof(struct hci_rp_read_local_name
)) {
197 BT_ERR("%s: BCM: Local name length mismatch", hdev
->name
);
199 return ERR_PTR(-EIO
);
205 static struct sk_buff
*btbcm_read_local_version(struct hci_dev
*hdev
)
209 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
212 BT_ERR("%s: BCM: Reading local version info failed (%ld)",
213 hdev
->name
, PTR_ERR(skb
));
217 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
218 BT_ERR("%s: BCM: Local version length mismatch", hdev
->name
);
220 return ERR_PTR(-EIO
);
226 static struct sk_buff
*btbcm_read_verbose_config(struct hci_dev
*hdev
)
230 skb
= __hci_cmd_sync(hdev
, 0xfc79, 0, NULL
, HCI_INIT_TIMEOUT
);
232 BT_ERR("%s: BCM: Read verbose config info failed (%ld)",
233 hdev
->name
, PTR_ERR(skb
));
238 BT_ERR("%s: BCM: Verbose config length mismatch", hdev
->name
);
240 return ERR_PTR(-EIO
);
246 static struct sk_buff
*btbcm_read_usb_product(struct hci_dev
*hdev
)
250 skb
= __hci_cmd_sync(hdev
, 0xfc5a, 0, NULL
, HCI_INIT_TIMEOUT
);
252 BT_ERR("%s: BCM: Read USB product info failed (%ld)",
253 hdev
->name
, PTR_ERR(skb
));
258 BT_ERR("%s: BCM: USB product length mismatch", hdev
->name
);
260 return ERR_PTR(-EIO
);
266 static const struct {
269 } bcm_uart_subver_table
[] = {
270 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
271 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
272 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
273 { 0x610c, "BCM4354" }, /* 003.001.012 */
277 int btbcm_initialize(struct hci_dev
*hdev
, char *fw_name
, size_t len
)
280 const char *hw_name
= NULL
;
282 struct hci_rp_read_local_version
*ver
;
286 err
= btbcm_reset(hdev
);
290 /* Read Local Version Info */
291 skb
= btbcm_read_local_version(hdev
);
295 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
296 rev
= le16_to_cpu(ver
->hci_rev
);
297 subver
= le16_to_cpu(ver
->lmp_subver
);
300 /* Read Verbose Config Version Info */
301 skb
= btbcm_read_verbose_config(hdev
);
305 BT_INFO("%s: BCM: chip id %u", hdev
->name
, skb
->data
[1]);
308 switch ((rev
& 0xf000) >> 12) {
312 for (i
= 0; bcm_uart_subver_table
[i
].name
; i
++) {
313 if (subver
== bcm_uart_subver_table
[i
].subver
) {
314 hw_name
= bcm_uart_subver_table
[i
].name
;
319 snprintf(fw_name
, len
, "brcm/%s.hcd", hw_name
? : "BCM");
325 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
326 hw_name
? : "BCM", (subver
& 0xe000) >> 13,
327 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
331 EXPORT_SYMBOL_GPL(btbcm_initialize
);
333 int btbcm_finalize(struct hci_dev
*hdev
)
336 struct hci_rp_read_local_version
*ver
;
341 err
= btbcm_reset(hdev
);
345 /* Read Local Version Info */
346 skb
= btbcm_read_local_version(hdev
);
350 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
351 rev
= le16_to_cpu(ver
->hci_rev
);
352 subver
= le16_to_cpu(ver
->lmp_subver
);
355 BT_INFO("%s: BCM (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
356 (subver
& 0xe000) >> 13, (subver
& 0x1f00) >> 8,
357 (subver
& 0x00ff), rev
& 0x0fff);
359 btbcm_check_bdaddr(hdev
);
361 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
365 EXPORT_SYMBOL_GPL(btbcm_finalize
);
367 static const struct {
370 } bcm_usb_subver_table
[] = {
371 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
372 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
373 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
374 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
375 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
376 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
377 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
378 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
379 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
380 { 0x610c, "BCM4354" }, /* 003.001.012 */
384 int btbcm_setup_patchram(struct hci_dev
*hdev
)
387 const struct firmware
*fw
;
388 u16 subver
, rev
, pid
, vid
;
389 const char *hw_name
= NULL
;
391 struct hci_rp_read_local_version
*ver
;
395 err
= btbcm_reset(hdev
);
399 /* Read Local Version Info */
400 skb
= btbcm_read_local_version(hdev
);
404 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
405 rev
= le16_to_cpu(ver
->hci_rev
);
406 subver
= le16_to_cpu(ver
->lmp_subver
);
409 /* Read Verbose Config Version Info */
410 skb
= btbcm_read_verbose_config(hdev
);
414 BT_INFO("%s: BCM: chip id %u", hdev
->name
, skb
->data
[1]);
417 /* Read Local Name */
418 skb
= btbcm_read_local_name(hdev
);
422 BT_INFO("%s: %s", hdev
->name
, (char *)(skb
->data
+ 1));
425 switch ((rev
& 0xf000) >> 12) {
428 for (i
= 0; bcm_uart_subver_table
[i
].name
; i
++) {
429 if (subver
== bcm_uart_subver_table
[i
].subver
) {
430 hw_name
= bcm_uart_subver_table
[i
].name
;
435 snprintf(fw_name
, sizeof(fw_name
), "brcm/%s.hcd",
440 /* Read USB Product Info */
441 skb
= btbcm_read_usb_product(hdev
);
445 vid
= get_unaligned_le16(skb
->data
+ 1);
446 pid
= get_unaligned_le16(skb
->data
+ 3);
449 for (i
= 0; bcm_usb_subver_table
[i
].name
; i
++) {
450 if (subver
== bcm_usb_subver_table
[i
].subver
) {
451 hw_name
= bcm_usb_subver_table
[i
].name
;
456 snprintf(fw_name
, sizeof(fw_name
), "brcm/%s-%4.4x-%4.4x.hcd",
457 hw_name
? : "BCM", vid
, pid
);
463 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
464 hw_name
? : "BCM", (subver
& 0xe000) >> 13,
465 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
467 err
= request_firmware(&fw
, fw_name
, &hdev
->dev
);
469 BT_INFO("%s: BCM: Patch %s not found", hdev
->name
, fw_name
);
473 btbcm_patchram(hdev
, fw
);
475 release_firmware(fw
);
478 err
= btbcm_reset(hdev
);
482 /* Read Local Version Info */
483 skb
= btbcm_read_local_version(hdev
);
487 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
488 rev
= le16_to_cpu(ver
->hci_rev
);
489 subver
= le16_to_cpu(ver
->lmp_subver
);
492 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
493 hw_name
? : "BCM", (subver
& 0xe000) >> 13,
494 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
496 /* Read Local Name */
497 skb
= btbcm_read_local_name(hdev
);
501 BT_INFO("%s: %s", hdev
->name
, (char *)(skb
->data
+ 1));
504 btbcm_check_bdaddr(hdev
);
506 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
510 EXPORT_SYMBOL_GPL(btbcm_setup_patchram
);
512 int btbcm_setup_apple(struct hci_dev
*hdev
)
518 err
= btbcm_reset(hdev
);
522 /* Read Verbose Config Version Info */
523 skb
= btbcm_read_verbose_config(hdev
);
525 BT_INFO("%s: BCM: chip id %u build %4.4u", hdev
->name
,
526 skb
->data
[1], get_unaligned_le16(skb
->data
+ 5));
530 /* Read USB Product Info */
531 skb
= btbcm_read_usb_product(hdev
);
533 BT_INFO("%s: BCM: product %4.4x:%4.4x", hdev
->name
,
534 get_unaligned_le16(skb
->data
+ 1),
535 get_unaligned_le16(skb
->data
+ 3));
539 /* Read Local Name */
540 skb
= btbcm_read_local_name(hdev
);
542 BT_INFO("%s: %s", hdev
->name
, (char *)(skb
->data
+ 1));
546 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
550 EXPORT_SYMBOL_GPL(btbcm_setup_apple
);
552 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
553 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION
);
554 MODULE_VERSION(VERSION
);
555 MODULE_LICENSE("GPL");