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}})
37 int btbcm_check_bdaddr(struct hci_dev
*hdev
)
39 struct hci_rp_read_bd_addr
*bda
;
42 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_BD_ADDR
, 0, NULL
,
45 int err
= PTR_ERR(skb
);
46 BT_ERR("%s: BCM: Reading device address failed (%d)",
51 if (skb
->len
!= sizeof(*bda
)) {
52 BT_ERR("%s: BCM: Device address length mismatch", hdev
->name
);
57 bda
= (struct hci_rp_read_bd_addr
*)skb
->data
;
59 /* The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
60 * with no configured address.
62 if (!bacmp(&bda
->bdaddr
, BDADDR_BCM20702A0
)) {
63 BT_INFO("%s: BCM: Using default device address (%pMR)",
64 hdev
->name
, &bda
->bdaddr
);
65 set_bit(HCI_QUIRK_INVALID_BDADDR
, &hdev
->quirks
);
72 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr
);
74 int btbcm_set_bdaddr(struct hci_dev
*hdev
, const bdaddr_t
*bdaddr
)
79 skb
= __hci_cmd_sync(hdev
, 0xfc01, 6, bdaddr
, HCI_INIT_TIMEOUT
);
82 BT_ERR("%s: BCM: Change address command failed (%d)",
90 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr
);
92 int btbcm_patchram(struct hci_dev
*hdev
, const char *firmware
)
94 const struct hci_command_hdr
*cmd
;
95 const struct firmware
*fw
;
102 err
= request_firmware(&fw
, firmware
, &hdev
->dev
);
104 BT_INFO("%s: BCM: Patch %s not found", hdev
->name
, firmware
);
109 skb
= __hci_cmd_sync(hdev
, 0xfc2e, 0, NULL
, HCI_INIT_TIMEOUT
);
112 BT_ERR("%s: BCM: Download Minidrv command failed (%d)",
118 /* 50 msec delay after Download Minidrv completes */
124 while (fw_size
>= sizeof(*cmd
)) {
127 cmd
= (struct hci_command_hdr
*)fw_ptr
;
128 fw_ptr
+= sizeof(*cmd
);
129 fw_size
-= sizeof(*cmd
);
131 if (fw_size
< cmd
->plen
) {
132 BT_ERR("%s: BCM: Patch %s is corrupted", hdev
->name
,
140 fw_size
-= cmd
->plen
;
142 opcode
= le16_to_cpu(cmd
->opcode
);
144 skb
= __hci_cmd_sync(hdev
, opcode
, cmd
->plen
, cmd_param
,
148 BT_ERR("%s: BCM: Patch command %04x failed (%d)",
149 hdev
->name
, opcode
, err
);
155 /* 250 msec delay after Launch Ram completes */
159 release_firmware(fw
);
162 EXPORT_SYMBOL(btbcm_patchram
);
164 static int btbcm_reset(struct hci_dev
*hdev
)
168 skb
= __hci_cmd_sync(hdev
, HCI_OP_RESET
, 0, NULL
, HCI_INIT_TIMEOUT
);
170 int err
= PTR_ERR(skb
);
171 BT_ERR("%s: BCM: Reset failed (%d)", hdev
->name
, err
);
179 static struct sk_buff
*btbcm_read_local_version(struct hci_dev
*hdev
)
183 skb
= __hci_cmd_sync(hdev
, HCI_OP_READ_LOCAL_VERSION
, 0, NULL
,
186 BT_ERR("%s: BCM: Reading local version info failed (%ld)",
187 hdev
->name
, PTR_ERR(skb
));
191 if (skb
->len
!= sizeof(struct hci_rp_read_local_version
)) {
192 BT_ERR("%s: BCM: Local version length mismatch", hdev
->name
);
194 return ERR_PTR(-EIO
);
200 static struct sk_buff
*btbcm_read_verbose_config(struct hci_dev
*hdev
)
204 skb
= __hci_cmd_sync(hdev
, 0xfc79, 0, NULL
, HCI_INIT_TIMEOUT
);
206 BT_ERR("%s: BCM: Read verbose config info failed (%ld)",
207 hdev
->name
, PTR_ERR(skb
));
212 BT_ERR("%s: BCM: Verbose config length mismatch", hdev
->name
);
214 return ERR_PTR(-EIO
);
220 static struct sk_buff
*btbcm_read_usb_product(struct hci_dev
*hdev
)
224 skb
= __hci_cmd_sync(hdev
, 0xfc5a, 0, NULL
, HCI_INIT_TIMEOUT
);
226 BT_ERR("%s: BCM: Read USB product info failed (%ld)",
227 hdev
->name
, PTR_ERR(skb
));
232 BT_ERR("%s: BCM: USB product length mismatch", hdev
->name
);
234 return ERR_PTR(-EIO
);
240 static const struct {
243 } bcm_uart_subver_table
[] = {
244 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
248 static const struct {
251 } bcm_usb_subver_table
[] = {
252 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
253 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
254 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
255 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
256 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
257 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
258 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
259 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
260 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
261 { 0x610c, "BCM4354" }, /* 003.001.012 */
265 int btbcm_setup_patchram(struct hci_dev
*hdev
)
268 u16 subver
, rev
, pid
, vid
;
269 const char *hw_name
= NULL
;
271 struct hci_rp_read_local_version
*ver
;
275 err
= btbcm_reset(hdev
);
279 /* Read Local Version Info */
280 skb
= btbcm_read_local_version(hdev
);
284 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
285 rev
= le16_to_cpu(ver
->hci_rev
);
286 subver
= le16_to_cpu(ver
->lmp_subver
);
289 /* Read Verbose Config Version Info */
290 skb
= btbcm_read_verbose_config(hdev
);
294 BT_INFO("%s: BCM: chip id %u", hdev
->name
, skb
->data
[1]);
297 switch ((rev
& 0xf000) >> 12) {
299 for (i
= 0; bcm_uart_subver_table
[i
].name
; i
++) {
300 if (subver
== bcm_uart_subver_table
[i
].subver
) {
301 hw_name
= bcm_uart_subver_table
[i
].name
;
306 snprintf(fw_name
, sizeof(fw_name
), "brcm/%s.hcd",
311 /* Read USB Product Info */
312 skb
= btbcm_read_usb_product(hdev
);
316 vid
= get_unaligned_le16(skb
->data
+ 1);
317 pid
= get_unaligned_le16(skb
->data
+ 3);
320 for (i
= 0; bcm_usb_subver_table
[i
].name
; i
++) {
321 if (subver
== bcm_usb_subver_table
[i
].subver
) {
322 hw_name
= bcm_usb_subver_table
[i
].name
;
327 snprintf(fw_name
, sizeof(fw_name
), "brcm/%s-%4.4x-%4.4x.hcd",
328 hw_name
? : "BCM", vid
, pid
);
334 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
335 hw_name
? : "BCM", (subver
& 0x7000) >> 13,
336 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
338 err
= btbcm_patchram(hdev
, fw_name
);
343 err
= btbcm_reset(hdev
);
347 /* Read Local Version Info */
348 skb
= btbcm_read_local_version(hdev
);
352 ver
= (struct hci_rp_read_local_version
*)skb
->data
;
353 rev
= le16_to_cpu(ver
->hci_rev
);
354 subver
= le16_to_cpu(ver
->lmp_subver
);
357 BT_INFO("%s: %s (%3.3u.%3.3u.%3.3u) build %4.4u", hdev
->name
,
358 hw_name
? : "BCM", (subver
& 0x7000) >> 13,
359 (subver
& 0x1f00) >> 8, (subver
& 0x00ff), rev
& 0x0fff);
361 btbcm_check_bdaddr(hdev
);
363 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
367 EXPORT_SYMBOL_GPL(btbcm_setup_patchram
);
369 int btbcm_setup_apple(struct hci_dev
*hdev
)
373 /* Read Verbose Config Version Info */
374 skb
= btbcm_read_verbose_config(hdev
);
378 BT_INFO("%s: BCM: chip id %u build %4.4u", hdev
->name
, skb
->data
[1],
379 get_unaligned_le16(skb
->data
+ 5));
382 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER
, &hdev
->quirks
);
386 EXPORT_SYMBOL_GPL(btbcm_setup_apple
);
388 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
389 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION
);
390 MODULE_VERSION(VERSION
);
391 MODULE_LICENSE("GPL");