blob: 99cde1f9467d4edae71cc9820b35c00a75016650 [file] [log] [blame]
Marcel Holtmann4fba30f2015-04-05 22:52:10 -07001/*
2 *
3 * Bluetooth support for Broadcom devices
4 *
5 * Copyright (C) 2015 Intel Corporation
6 *
7 *
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.
12 *
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.
17 *
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
21 *
22 */
23
24#include <linux/module.h>
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -070025#include <linux/firmware.h>
26#include <asm/unaligned.h>
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070027
28#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h>
30
31#include "btbcm.h"
32
33#define VERSION "0.1"
34
35#define BDADDR_BCM20702A0 (&(bdaddr_t) {{0x00, 0xa0, 0x02, 0x70, 0x20, 0x00}})
Frederic Danisa8f3b942015-05-28 11:25:02 +020036#define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
Frederic Danis4a546ec2015-07-27 18:02:25 +020037#define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070038
39int btbcm_check_bdaddr(struct hci_dev *hdev)
40{
41 struct hci_rp_read_bd_addr *bda;
42 struct sk_buff *skb;
43
44 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
45 HCI_INIT_TIMEOUT);
46 if (IS_ERR(skb)) {
47 int err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +010048 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070049 return err;
50 }
51
52 if (skb->len != sizeof(*bda)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010053 bt_dev_err(hdev, "BCM: Device address length mismatch");
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070054 kfree_skb(skb);
55 return -EIO;
56 }
57
58 bda = (struct hci_rp_read_bd_addr *)skb->data;
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070059
Frederic Danisa8f3b942015-05-28 11:25:02 +020060 /* 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.
63 *
64 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070065 * with no configured address.
Frederic Danisa8f3b942015-05-28 11:25:02 +020066 *
67 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
68 * with waiting for configuration state.
Frederic Danis4a546ec2015-07-27 18:02:25 +020069 *
70 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
71 * with waiting for configuration state.
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070072 */
Frederic Danisa8f3b942015-05-28 11:25:02 +020073 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
Frederic Danis4a546ec2015-07-27 18:02:25 +020074 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
75 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010076 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
77 &bda->bdaddr);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070078 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
79 }
80
81 kfree_skb(skb);
82
83 return 0;
84}
85EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
86
87int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
88{
89 struct sk_buff *skb;
90 int err;
91
92 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
93 if (IS_ERR(skb)) {
94 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +010095 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070096 return err;
97 }
98 kfree_skb(skb);
99
100 return 0;
101}
102EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
103
Frederic Danis18aeb442015-05-28 11:25:01 +0200104int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700105{
106 const struct hci_command_hdr *cmd;
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700107 const u8 *fw_ptr;
108 size_t fw_size;
109 struct sk_buff *skb;
110 u16 opcode;
Frederic Danis18aeb442015-05-28 11:25:01 +0200111 int err = 0;
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700112
113 /* Start Download */
114 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
115 if (IS_ERR(skb)) {
116 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100117 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
118 err);
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700119 goto done;
120 }
121 kfree_skb(skb);
122
123 /* 50 msec delay after Download Minidrv completes */
124 msleep(50);
125
126 fw_ptr = fw->data;
127 fw_size = fw->size;
128
129 while (fw_size >= sizeof(*cmd)) {
130 const u8 *cmd_param;
131
132 cmd = (struct hci_command_hdr *)fw_ptr;
133 fw_ptr += sizeof(*cmd);
134 fw_size -= sizeof(*cmd);
135
136 if (fw_size < cmd->plen) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100137 bt_dev_err(hdev, "BCM: Patch is corrupted");
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700138 err = -EINVAL;
139 goto done;
140 }
141
142 cmd_param = fw_ptr;
143 fw_ptr += cmd->plen;
144 fw_size -= cmd->plen;
145
146 opcode = le16_to_cpu(cmd->opcode);
147
148 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
149 HCI_INIT_TIMEOUT);
150 if (IS_ERR(skb)) {
151 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100152 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
153 opcode, err);
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700154 goto done;
155 }
156 kfree_skb(skb);
157 }
158
159 /* 250 msec delay after Launch Ram completes */
160 msleep(250);
161
162done:
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700163 return err;
164}
165EXPORT_SYMBOL(btbcm_patchram);
166
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700167static int btbcm_reset(struct hci_dev *hdev)
168{
169 struct sk_buff *skb;
170
171 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
172 if (IS_ERR(skb)) {
173 int err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100174 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700175 return err;
176 }
177 kfree_skb(skb);
178
Wen-chien Jesse Sung3af3a592017-01-10 11:46:28 +0800179 /* 100 msec delay for module to complete reset process */
180 msleep(100);
181
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700182 return 0;
183}
184
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200185static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
186{
187 struct sk_buff *skb;
188
189 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
190 HCI_INIT_TIMEOUT);
191 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100192 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
193 PTR_ERR(skb));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200194 return skb;
195 }
196
197 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100198 bt_dev_err(hdev, "BCM: Local name length mismatch");
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200199 kfree_skb(skb);
200 return ERR_PTR(-EIO);
201 }
202
203 return skb;
204}
205
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700206static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
207{
208 struct sk_buff *skb;
209
210 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
211 HCI_INIT_TIMEOUT);
212 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100213 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
214 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700215 return skb;
216 }
217
218 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100219 bt_dev_err(hdev, "BCM: Local version length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700220 kfree_skb(skb);
221 return ERR_PTR(-EIO);
222 }
223
224 return skb;
225}
226
227static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
228{
229 struct sk_buff *skb;
230
231 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
232 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100233 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
234 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700235 return skb;
236 }
237
238 if (skb->len != 7) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100239 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700240 kfree_skb(skb);
241 return ERR_PTR(-EIO);
242 }
243
244 return skb;
245}
246
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200247static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
248{
249 struct sk_buff *skb;
250
251 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
252 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100253 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
254 PTR_ERR(skb));
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200255 return skb;
256 }
257
258 if (skb->len != 9) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100259 bt_dev_err(hdev, "BCM: Controller features length mismatch");
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200260 kfree_skb(skb);
261 return ERR_PTR(-EIO);
262 }
263
264 return skb;
265}
266
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700267static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
268{
269 struct sk_buff *skb;
270
271 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
272 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100273 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
274 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700275 return skb;
276 }
277
278 if (skb->len != 5) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100279 bt_dev_err(hdev, "BCM: USB product length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700280 kfree_skb(skb);
281 return ERR_PTR(-EIO);
282 }
283
284 return skb;
285}
286
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200287static int btbcm_read_info(struct hci_dev *hdev)
288{
289 struct sk_buff *skb;
290
291 /* Read Verbose Config Version Info */
292 skb = btbcm_read_verbose_config(hdev);
293 if (IS_ERR(skb))
294 return PTR_ERR(skb);
295
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100296 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200297 kfree_skb(skb);
298
299 /* Read Controller Features */
300 skb = btbcm_read_controller_features(hdev);
301 if (IS_ERR(skb))
302 return PTR_ERR(skb);
303
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100304 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200305 kfree_skb(skb);
306
307 /* Read Local Name */
308 skb = btbcm_read_local_name(hdev);
309 if (IS_ERR(skb))
310 return PTR_ERR(skb);
311
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100312 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200313 kfree_skb(skb);
314
315 return 0;
316}
317
Hans de Goedef7328382018-04-20 14:44:03 +0200318struct bcm_subver_table {
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700319 u16 subver;
320 const char *name;
Hans de Goedef7328382018-04-20 14:44:03 +0200321};
322
323static const struct bcm_subver_table bcm_uart_subver_table[] = {
Frederic Danis4a546ec2015-07-27 18:02:25 +0200324 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
Marcel Holtmann9a0bb572015-04-05 22:52:19 -0700325 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
Frederic Danisa8f3b942015-05-28 11:25:02 +0200326 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
Ilya Faenson40db5f02015-06-17 11:42:46 -0400327 { 0x610c, "BCM4354" }, /* 003.001.012 */
Jörg Kraused456f672018-01-18 10:21:55 +0100328 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
Ian Moltonfeb16722017-06-28 20:10:55 +0100329 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
Ian W MORRISON18a39b92017-10-06 18:34:18 +1100330 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
Hans de Goedeb133e0c2017-10-13 17:54:01 +0200331 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
Marcel Holtmann9a0bb572015-04-05 22:52:19 -0700332 { }
333};
334
Hans de Goedefec0de22018-04-20 14:44:04 +0200335static const struct bcm_subver_table bcm_usb_subver_table[] = {
336 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
337 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
338 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
339 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
340 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
341 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
342 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
343 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
344 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
345 { 0x610c, "BCM4354" }, /* 003.001.012 */
346 { }
347};
348
Hans de Goede22ac1912018-04-20 14:44:05 +0200349int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len,
350 bool reinit)
Frederic Danis75e167e2015-05-28 11:25:04 +0200351{
Hans de Goedefec0de22018-04-20 14:44:04 +0200352 u16 subver, rev, pid, vid;
Hans de Goede2cc6d072018-04-20 14:44:07 +0200353 const char *hw_name = "BCM";
Frederic Danis75e167e2015-05-28 11:25:04 +0200354 struct sk_buff *skb;
355 struct hci_rp_read_local_version *ver;
Hans de Goedefec0de22018-04-20 14:44:04 +0200356 const struct bcm_subver_table *bcm_subver_table;
Frederic Danis75e167e2015-05-28 11:25:04 +0200357 int i, err;
358
359 /* Reset */
360 err = btbcm_reset(hdev);
361 if (err)
362 return err;
363
364 /* Read Local Version Info */
365 skb = btbcm_read_local_version(hdev);
366 if (IS_ERR(skb))
367 return PTR_ERR(skb);
368
369 ver = (struct hci_rp_read_local_version *)skb->data;
370 rev = le16_to_cpu(ver->hci_rev);
371 subver = le16_to_cpu(ver->lmp_subver);
372 kfree_skb(skb);
373
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200374 /* Read controller information */
Hans de Goede22ac1912018-04-20 14:44:05 +0200375 if (!reinit) {
376 err = btbcm_read_info(hdev);
377 if (err)
378 return err;
379 }
Frederic Danis75e167e2015-05-28 11:25:04 +0200380
Hans de Goedefec0de22018-04-20 14:44:04 +0200381 /* Upper nibble of rev should be between 0 and 3? */
382 if (((rev & 0xf000) >> 12) > 3)
Frederic Danis75e167e2015-05-28 11:25:04 +0200383 return 0;
Hans de Goedefec0de22018-04-20 14:44:04 +0200384
385 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
386 bcm_uart_subver_table;
387
388 for (i = 0; bcm_subver_table[i].name; i++) {
389 if (subver == bcm_subver_table[i].subver) {
390 hw_name = bcm_subver_table[i].name;
391 break;
392 }
393 }
394
395 if (hdev->bus == HCI_USB) {
396 /* Read USB Product Info */
397 skb = btbcm_read_usb_product(hdev);
398 if (IS_ERR(skb))
399 return PTR_ERR(skb);
400
401 vid = get_unaligned_le16(skb->data + 1);
402 pid = get_unaligned_le16(skb->data + 3);
403 kfree_skb(skb);
404
405 snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd",
Hans de Goede2cc6d072018-04-20 14:44:07 +0200406 hw_name, vid, pid);
Hans de Goedefec0de22018-04-20 14:44:04 +0200407 } else {
Hans de Goede2cc6d072018-04-20 14:44:07 +0200408 snprintf(fw_name, len, "brcm/%s.hcd", hw_name);
Frederic Danis75e167e2015-05-28 11:25:04 +0200409 }
410
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100411 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
Hans de Goede2cc6d072018-04-20 14:44:07 +0200412 hw_name, (subver & 0xe000) >> 13,
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100413 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
Frederic Danis75e167e2015-05-28 11:25:04 +0200414
415 return 0;
416}
417EXPORT_SYMBOL_GPL(btbcm_initialize);
418
419int btbcm_finalize(struct hci_dev *hdev)
420{
Hans de Goede22ac1912018-04-20 14:44:05 +0200421 char fw_name[64];
Frederic Danis75e167e2015-05-28 11:25:04 +0200422 int err;
423
Hans de Goede22ac1912018-04-20 14:44:05 +0200424 /* Re-initialize */
425 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
Frederic Danis75e167e2015-05-28 11:25:04 +0200426 if (err)
427 return err;
428
Frederic Danis75e167e2015-05-28 11:25:04 +0200429 btbcm_check_bdaddr(hdev);
430
431 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
432
433 return 0;
434}
435EXPORT_SYMBOL_GPL(btbcm_finalize);
436
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700437int btbcm_setup_patchram(struct hci_dev *hdev)
438{
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700439 char fw_name[64];
Frederic Danis18aeb442015-05-28 11:25:01 +0200440 const struct firmware *fw;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700441 struct sk_buff *skb;
Hans de Goede59ce5692018-04-20 14:44:06 +0200442 int err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700443
Hans de Goede59ce5692018-04-20 14:44:06 +0200444 /* Initialize */
445 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700446 if (err)
447 return err;
448
Frederic Danis18aeb442015-05-28 11:25:01 +0200449 err = request_firmware(&fw, fw_name, &hdev->dev);
450 if (err < 0) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100451 bt_dev_info(hdev, "BCM: Patch %s not found", fw_name);
Petri Gyntherad750fa12016-02-10 12:00:46 -0800452 goto done;
Frederic Danis18aeb442015-05-28 11:25:01 +0200453 }
454
455 btbcm_patchram(hdev, fw);
456
457 release_firmware(fw);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700458
Hans de Goede59ce5692018-04-20 14:44:06 +0200459 /* Re-initialize */
460 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700461 if (err)
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700462 return err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700463
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200464 /* Read Local Name */
465 skb = btbcm_read_local_name(hdev);
466 if (IS_ERR(skb))
467 return PTR_ERR(skb);
468
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100469 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200470 kfree_skb(skb);
471
Petri Gyntherad750fa12016-02-10 12:00:46 -0800472done:
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700473 btbcm_check_bdaddr(hdev);
474
Marcel Holtmann941521e2015-04-05 22:52:15 -0700475 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
476
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700477 return 0;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700478}
479EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
480
481int btbcm_setup_apple(struct hci_dev *hdev)
482{
483 struct sk_buff *skb;
Marcel Holtmannb224d3f2015-10-03 12:01:08 +0200484 int err;
485
486 /* Reset */
487 err = btbcm_reset(hdev);
488 if (err)
489 return err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700490
491 /* Read Verbose Config Version Info */
492 skb = btbcm_read_verbose_config(hdev);
Chris Mason7bee8b02015-07-14 16:25:30 -0400493 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100494 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
495 skb->data[1], get_unaligned_le16(skb->data + 5));
Chris Mason7bee8b02015-07-14 16:25:30 -0400496 kfree_skb(skb);
497 }
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700498
Marcel Holtmann34cea412015-10-18 22:48:28 +0200499 /* Read USB Product Info */
500 skb = btbcm_read_usb_product(hdev);
501 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100502 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
503 get_unaligned_le16(skb->data + 1),
504 get_unaligned_le16(skb->data + 3));
Marcel Holtmann34cea412015-10-18 22:48:28 +0200505 kfree_skb(skb);
506 }
507
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200508 /* Read Controller Features */
509 skb = btbcm_read_controller_features(hdev);
510 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100511 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200512 kfree_skb(skb);
513 }
514
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200515 /* Read Local Name */
516 skb = btbcm_read_local_name(hdev);
517 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100518 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200519 kfree_skb(skb);
520 }
521
Marcel Holtmann941521e2015-04-05 22:52:15 -0700522 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
523
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700524 return 0;
525}
526EXPORT_SYMBOL_GPL(btbcm_setup_apple);
527
Marcel Holtmann4fba30f2015-04-05 22:52:10 -0700528MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
529MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
530MODULE_VERSION(VERSION);
531MODULE_LICENSE("GPL");