Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / bluetooth / btbcm.c
bloba1153ada74d20689ebf0c4cd0cfdfd6333dfe910
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
4 * Bluetooth support for Broadcom devices
6 * Copyright (C) 2015 Intel Corporation
7 */
9 #include <linux/efi.h>
10 #include <linux/module.h>
11 #include <linux/firmware.h>
12 #include <linux/dmi.h>
13 #include <linux/of.h>
14 #include <linux/string.h>
15 #include <linux/unaligned.h>
17 #include <net/bluetooth/bluetooth.h>
18 #include <net/bluetooth/hci_core.h>
20 #include "btbcm.h"
22 #define VERSION "0.1"
24 #define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
25 #define BDADDR_BCM20702A1 (&(bdaddr_t) {{0x00, 0x00, 0xa0, 0x02, 0x70, 0x20}})
26 #define BDADDR_BCM2076B1 (&(bdaddr_t) {{0x79, 0x56, 0x00, 0xa0, 0x76, 0x20}})
27 #define BDADDR_BCM43430A0 (&(bdaddr_t) {{0xac, 0x1f, 0x12, 0xa0, 0x43, 0x43}})
28 #define BDADDR_BCM43430A1 (&(bdaddr_t) {{0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa}})
29 #define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
30 #define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
31 #define BDADDR_BCM4334B0 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb0, 0x34, 0x43}})
32 #define BDADDR_BCM4345C5 (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0xc5, 0x45, 0x43}})
33 #define BDADDR_BCM43341B (&(bdaddr_t) {{0xac, 0x1f, 0x00, 0x1b, 0x34, 0x43}})
35 #define BCM_FW_NAME_LEN 64
36 #define BCM_FW_NAME_COUNT_MAX 4
37 /* For kmalloc-ing the fw-name array instead of putting it on the stack */
38 typedef char bcm_fw_name[BCM_FW_NAME_LEN];
40 #ifdef CONFIG_EFI
41 static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev)
43 efi_guid_t guid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61, 0xb5, 0x1f,
44 0x43, 0x26, 0x81, 0x23, 0xd1, 0x13);
45 bdaddr_t efi_bdaddr, bdaddr;
46 efi_status_t status;
47 unsigned long len;
48 int ret;
50 if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE))
51 return -EOPNOTSUPP;
53 len = sizeof(efi_bdaddr);
54 status = efi.get_variable(L"BDADDR", &guid, NULL, &len, &efi_bdaddr);
55 if (status != EFI_SUCCESS)
56 return -ENXIO;
58 if (len != sizeof(efi_bdaddr))
59 return -EIO;
61 baswap(&bdaddr, &efi_bdaddr);
63 ret = btbcm_set_bdaddr(hdev, &bdaddr);
64 if (ret)
65 return ret;
67 bt_dev_info(hdev, "BCM: Using EFI device address (%pMR)", &bdaddr);
68 return 0;
70 #else
71 static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev)
73 return -EOPNOTSUPP;
75 #endif
77 int btbcm_check_bdaddr(struct hci_dev *hdev)
79 struct hci_rp_read_bd_addr *bda;
80 struct sk_buff *skb;
82 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
83 HCI_INIT_TIMEOUT);
84 if (IS_ERR(skb)) {
85 int err = PTR_ERR(skb);
87 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
88 return err;
91 if (skb->len != sizeof(*bda)) {
92 bt_dev_err(hdev, "BCM: Device address length mismatch");
93 kfree_skb(skb);
94 return -EIO;
97 bda = (struct hci_rp_read_bd_addr *)skb->data;
99 /* Check if the address indicates a controller with either an
100 * invalid or default address. In both cases the device needs
101 * to be marked as not having a valid address.
103 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
104 * with no configured address.
106 * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller
107 * with no configured address.
109 * The address 20:76:A0:00:56:79 indicates a BCM2076B1 controller
110 * with no configured address.
112 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
113 * with waiting for configuration state.
115 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
116 * with waiting for configuration state.
118 * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller
119 * with no configured address.
121 * The address AA:AA:AA:AA:AA:AA indicates a BCM43430A1 controller
122 * with no configured address.
124 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
125 !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) ||
126 !bacmp(&bda->bdaddr, BDADDR_BCM2076B1) ||
127 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
128 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) ||
129 !bacmp(&bda->bdaddr, BDADDR_BCM4334B0) ||
130 !bacmp(&bda->bdaddr, BDADDR_BCM4345C5) ||
131 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) ||
132 !bacmp(&bda->bdaddr, BDADDR_BCM43430A1) ||
133 !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) {
134 /* Try falling back to BDADDR EFI variable */
135 if (btbcm_set_bdaddr_from_efi(hdev) != 0) {
136 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
137 &bda->bdaddr);
138 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
142 kfree_skb(skb);
144 return 0;
146 EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
148 int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
150 struct sk_buff *skb;
151 int err;
153 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
154 if (IS_ERR(skb)) {
155 err = PTR_ERR(skb);
156 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
157 return err;
159 kfree_skb(skb);
161 return 0;
163 EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
165 int btbcm_read_pcm_int_params(struct hci_dev *hdev,
166 struct bcm_set_pcm_int_params *params)
168 struct sk_buff *skb;
169 int err = 0;
171 skb = __hci_cmd_sync(hdev, 0xfc1d, 0, NULL, HCI_INIT_TIMEOUT);
172 if (IS_ERR(skb)) {
173 err = PTR_ERR(skb);
174 bt_dev_err(hdev, "BCM: Read PCM int params failed (%d)", err);
175 return err;
178 if (skb->len != 6 || skb->data[0]) {
179 bt_dev_err(hdev, "BCM: Read PCM int params length mismatch");
180 kfree_skb(skb);
181 return -EIO;
184 if (params)
185 memcpy(params, skb->data + 1, 5);
187 kfree_skb(skb);
189 return 0;
191 EXPORT_SYMBOL_GPL(btbcm_read_pcm_int_params);
193 int btbcm_write_pcm_int_params(struct hci_dev *hdev,
194 const struct bcm_set_pcm_int_params *params)
196 struct sk_buff *skb;
197 int err;
199 skb = __hci_cmd_sync(hdev, 0xfc1c, 5, params, HCI_INIT_TIMEOUT);
200 if (IS_ERR(skb)) {
201 err = PTR_ERR(skb);
202 bt_dev_err(hdev, "BCM: Write PCM int params failed (%d)", err);
203 return err;
205 kfree_skb(skb);
207 return 0;
209 EXPORT_SYMBOL_GPL(btbcm_write_pcm_int_params);
211 int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
213 const struct hci_command_hdr *cmd;
214 const u8 *fw_ptr;
215 size_t fw_size;
216 struct sk_buff *skb;
217 u16 opcode;
218 int err = 0;
220 /* Start Download */
221 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
222 if (IS_ERR(skb)) {
223 err = PTR_ERR(skb);
224 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
225 err);
226 goto done;
228 kfree_skb(skb);
230 /* 50 msec delay after Download Minidrv completes */
231 msleep(50);
233 fw_ptr = fw->data;
234 fw_size = fw->size;
236 while (fw_size >= sizeof(*cmd)) {
237 const u8 *cmd_param;
239 cmd = (struct hci_command_hdr *)fw_ptr;
240 fw_ptr += sizeof(*cmd);
241 fw_size -= sizeof(*cmd);
243 if (fw_size < cmd->plen) {
244 bt_dev_err(hdev, "BCM: Patch is corrupted");
245 err = -EINVAL;
246 goto done;
249 cmd_param = fw_ptr;
250 fw_ptr += cmd->plen;
251 fw_size -= cmd->plen;
253 opcode = le16_to_cpu(cmd->opcode);
255 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
256 HCI_INIT_TIMEOUT);
257 if (IS_ERR(skb)) {
258 err = PTR_ERR(skb);
259 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
260 opcode, err);
261 goto done;
263 kfree_skb(skb);
266 /* 250 msec delay after Launch Ram completes */
267 msleep(250);
269 done:
270 return err;
272 EXPORT_SYMBOL(btbcm_patchram);
274 static int btbcm_reset(struct hci_dev *hdev)
276 struct sk_buff *skb;
278 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
279 if (IS_ERR(skb)) {
280 int err = PTR_ERR(skb);
282 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
283 return err;
285 kfree_skb(skb);
287 /* 100 msec delay for module to complete reset process */
288 msleep(100);
290 return 0;
293 static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
295 struct sk_buff *skb;
297 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
298 HCI_INIT_TIMEOUT);
299 if (IS_ERR(skb)) {
300 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
301 PTR_ERR(skb));
302 return skb;
305 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
306 bt_dev_err(hdev, "BCM: Local name length mismatch");
307 kfree_skb(skb);
308 return ERR_PTR(-EIO);
311 return skb;
314 static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
316 struct sk_buff *skb;
318 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
319 HCI_INIT_TIMEOUT);
320 if (IS_ERR(skb)) {
321 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
322 PTR_ERR(skb));
323 return skb;
326 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
327 bt_dev_err(hdev, "BCM: Local version length mismatch");
328 kfree_skb(skb);
329 return ERR_PTR(-EIO);
332 return skb;
335 static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
337 struct sk_buff *skb;
339 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
340 if (IS_ERR(skb)) {
341 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
342 PTR_ERR(skb));
343 return skb;
346 if (skb->len != 7) {
347 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
348 kfree_skb(skb);
349 return ERR_PTR(-EIO);
352 return skb;
355 static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
357 struct sk_buff *skb;
359 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
360 if (IS_ERR(skb)) {
361 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
362 PTR_ERR(skb));
363 return skb;
366 if (skb->len != 9) {
367 bt_dev_err(hdev, "BCM: Controller features length mismatch");
368 kfree_skb(skb);
369 return ERR_PTR(-EIO);
372 return skb;
375 static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
377 struct sk_buff *skb;
379 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
380 if (IS_ERR(skb)) {
381 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
382 PTR_ERR(skb));
383 return skb;
386 if (skb->len != 5) {
387 bt_dev_err(hdev, "BCM: USB product length mismatch");
388 kfree_skb(skb);
389 return ERR_PTR(-EIO);
392 return skb;
395 static const struct dmi_system_id disable_broken_read_transmit_power[] = {
397 .matches = {
398 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
399 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro16,1"),
403 .matches = {
404 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
405 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro16,2"),
409 .matches = {
410 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
411 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro16,4"),
415 .matches = {
416 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
417 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir8,1"),
421 .matches = {
422 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
423 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookAir8,2"),
427 .matches = {
428 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
429 DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,1"),
433 .matches = {
434 DMI_MATCH(DMI_BOARD_VENDOR, "Apple Inc."),
435 DMI_MATCH(DMI_PRODUCT_NAME, "iMac20,2"),
441 static int btbcm_read_info(struct hci_dev *hdev)
443 struct sk_buff *skb;
445 /* Read Verbose Config Version Info */
446 skb = btbcm_read_verbose_config(hdev);
447 if (IS_ERR(skb))
448 return PTR_ERR(skb);
450 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
451 kfree_skb(skb);
453 return 0;
456 static int btbcm_print_controller_features(struct hci_dev *hdev)
458 struct sk_buff *skb;
460 /* Read Controller Features */
461 skb = btbcm_read_controller_features(hdev);
462 if (IS_ERR(skb))
463 return PTR_ERR(skb);
465 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
466 kfree_skb(skb);
468 /* Read DMI and disable broken Read LE Min/Max Tx Power */
469 if (dmi_first_match(disable_broken_read_transmit_power))
470 set_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks);
472 return 0;
475 static int btbcm_print_local_name(struct hci_dev *hdev)
477 struct sk_buff *skb;
479 /* Read Local Name */
480 skb = btbcm_read_local_name(hdev);
481 if (IS_ERR(skb))
482 return PTR_ERR(skb);
484 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
485 kfree_skb(skb);
487 return 0;
490 struct bcm_subver_table {
491 u16 subver;
492 const char *name;
495 static const struct bcm_subver_table bcm_uart_subver_table[] = {
496 { 0x1111, "BCM4362A2" }, /* 000.017.017 */
497 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
498 { 0x410d, "BCM4334B0" }, /* 002.001.013 */
499 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
500 { 0x4204, "BCM2076B1" }, /* 002.002.004 */
501 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
502 { 0x4606, "BCM4324B5" }, /* 002.006.006 */
503 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
504 { 0x610c, "BCM4354" }, /* 003.001.012 */
505 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
506 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
507 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
508 { 0x6606, "BCM4345C5" }, /* 003.006.006 */
509 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
510 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
511 { 0x420d, "BCM4349B1" }, /* 002.002.013 */
512 { 0x420e, "BCM4349B1" }, /* 002.002.014 */
513 { 0x4217, "BCM4329B1" }, /* 002.002.023 */
514 { 0x6106, "BCM4359C0" }, /* 003.001.006 */
515 { 0x4106, "BCM4335A0" }, /* 002.001.006 */
516 { 0x410c, "BCM43430B0" }, /* 002.001.012 */
517 { 0x2119, "BCM4373A0" }, /* 001.001.025 */
521 static const struct bcm_subver_table bcm_usb_subver_table[] = {
522 { 0x2105, "BCM20703A1" }, /* 001.001.005 */
523 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
524 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
525 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
526 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
527 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
528 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
529 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
530 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
531 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
532 { 0x610c, "BCM4354" }, /* 003.001.012 */
533 { 0x6607, "BCM4350C5" }, /* 003.006.007 */
538 * This currently only looks up the device tree board appendix,
539 * but can be expanded to other mechanisms.
541 static const char *btbcm_get_board_name(struct device *dev)
543 #ifdef CONFIG_OF
544 struct device_node *root __free(device_node) = of_find_node_by_path("/");
545 char *board_type;
546 const char *tmp;
548 if (!root)
549 return NULL;
551 if (of_property_read_string_index(root, "compatible", 0, &tmp))
552 return NULL;
554 /* get rid of any '/' in the compatible string */
555 board_type = devm_kstrdup(dev, tmp, GFP_KERNEL);
556 strreplace(board_type, '/', '-');
558 return board_type;
559 #else
560 return NULL;
561 #endif
564 int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode)
566 u16 subver, rev, pid, vid;
567 struct sk_buff *skb;
568 struct hci_rp_read_local_version *ver;
569 const struct bcm_subver_table *bcm_subver_table;
570 const char *hw_name = NULL;
571 const char *board_name;
572 char postfix[16] = "";
573 int fw_name_count = 0;
574 bcm_fw_name *fw_name;
575 const struct firmware *fw;
576 int i, err;
578 board_name = btbcm_get_board_name(&hdev->dev);
580 /* Reset */
581 err = btbcm_reset(hdev);
582 if (err)
583 return err;
585 /* Read Local Version Info */
586 skb = btbcm_read_local_version(hdev);
587 if (IS_ERR(skb))
588 return PTR_ERR(skb);
590 ver = (struct hci_rp_read_local_version *)skb->data;
591 rev = le16_to_cpu(ver->hci_rev);
592 subver = le16_to_cpu(ver->lmp_subver);
593 kfree_skb(skb);
595 /* Read controller information */
596 if (!(*fw_load_done)) {
597 err = btbcm_read_info(hdev);
598 if (err)
599 return err;
602 if (!use_autobaud_mode) {
603 err = btbcm_print_controller_features(hdev);
604 if (err)
605 return err;
607 err = btbcm_print_local_name(hdev);
608 if (err)
609 return err;
612 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
613 bcm_uart_subver_table;
615 for (i = 0; bcm_subver_table[i].name; i++) {
616 if (subver == bcm_subver_table[i].subver) {
617 hw_name = bcm_subver_table[i].name;
618 break;
622 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
623 hw_name ? hw_name : "BCM", (subver & 0xe000) >> 13,
624 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
626 if (*fw_load_done)
627 return 0;
629 if (hdev->bus == HCI_USB) {
630 /* Read USB Product Info */
631 skb = btbcm_read_usb_product(hdev);
632 if (IS_ERR(skb))
633 return PTR_ERR(skb);
635 vid = get_unaligned_le16(skb->data + 1);
636 pid = get_unaligned_le16(skb->data + 3);
637 kfree_skb(skb);
639 snprintf(postfix, sizeof(postfix), "-%4.4x-%4.4x", vid, pid);
642 fw_name = kmalloc(BCM_FW_NAME_COUNT_MAX * BCM_FW_NAME_LEN, GFP_KERNEL);
643 if (!fw_name)
644 return -ENOMEM;
646 if (hw_name) {
647 if (board_name) {
648 snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
649 "brcm/%s%s.%s.hcd", hw_name, postfix, board_name);
650 fw_name_count++;
652 snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
653 "brcm/%s%s.hcd", hw_name, postfix);
654 fw_name_count++;
657 if (board_name) {
658 snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
659 "brcm/BCM%s.%s.hcd", postfix, board_name);
660 fw_name_count++;
662 snprintf(fw_name[fw_name_count], BCM_FW_NAME_LEN,
663 "brcm/BCM%s.hcd", postfix);
664 fw_name_count++;
666 for (i = 0; i < fw_name_count; i++) {
667 err = firmware_request_nowarn(&fw, fw_name[i], &hdev->dev);
668 if (err == 0) {
669 bt_dev_info(hdev, "%s '%s' Patch",
670 hw_name ? hw_name : "BCM", fw_name[i]);
671 *fw_load_done = true;
672 break;
676 if (*fw_load_done) {
677 err = btbcm_patchram(hdev, fw);
678 if (err)
679 bt_dev_info(hdev, "BCM: Patch failed (%d)", err);
681 release_firmware(fw);
682 } else {
683 bt_dev_err(hdev, "BCM: firmware Patch file not found, tried:");
684 for (i = 0; i < fw_name_count; i++)
685 bt_dev_err(hdev, "BCM: '%s'", fw_name[i]);
688 kfree(fw_name);
689 return 0;
691 EXPORT_SYMBOL_GPL(btbcm_initialize);
693 int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode)
695 int err;
697 /* Re-initialize if necessary */
698 if (*fw_load_done) {
699 err = btbcm_initialize(hdev, fw_load_done, use_autobaud_mode);
700 if (err)
701 return err;
704 btbcm_check_bdaddr(hdev);
706 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
708 return 0;
710 EXPORT_SYMBOL_GPL(btbcm_finalize);
712 int btbcm_setup_patchram(struct hci_dev *hdev)
714 bool fw_load_done = false;
715 bool use_autobaud_mode = false;
716 int err;
718 /* Initialize */
719 err = btbcm_initialize(hdev, &fw_load_done, use_autobaud_mode);
720 if (err)
721 return err;
723 /* Re-initialize after loading Patch */
724 return btbcm_finalize(hdev, &fw_load_done, use_autobaud_mode);
726 EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
728 int btbcm_setup_apple(struct hci_dev *hdev)
730 struct sk_buff *skb;
731 int err;
733 /* Reset */
734 err = btbcm_reset(hdev);
735 if (err)
736 return err;
738 /* Read Verbose Config Version Info */
739 skb = btbcm_read_verbose_config(hdev);
740 if (!IS_ERR(skb)) {
741 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
742 skb->data[1], get_unaligned_le16(skb->data + 5));
743 kfree_skb(skb);
746 /* Read USB Product Info */
747 skb = btbcm_read_usb_product(hdev);
748 if (!IS_ERR(skb)) {
749 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
750 get_unaligned_le16(skb->data + 1),
751 get_unaligned_le16(skb->data + 3));
752 kfree_skb(skb);
755 /* Read Controller Features */
756 skb = btbcm_read_controller_features(hdev);
757 if (!IS_ERR(skb)) {
758 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
759 kfree_skb(skb);
762 /* Read Local Name */
763 skb = btbcm_read_local_name(hdev);
764 if (!IS_ERR(skb)) {
765 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
766 kfree_skb(skb);
769 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
771 return 0;
773 EXPORT_SYMBOL_GPL(btbcm_setup_apple);
775 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
776 MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
777 MODULE_VERSION(VERSION);
778 MODULE_LICENSE("GPL");