blob: 08e1f3dd4e03c950b1d733c61ed195457604f29c [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}})
Maxime Ripard92ffe0d2018-12-17 12:04:45 +080036#define BDADDR_BCM20702A1 (&(bdaddr_t) {{0x00, 0x00, 0xa0, 0x02, 0x70, 0x20}})
Chen-Yu Tsai0697607a2018-12-17 12:04:47 +080037#define BDADDR_BCM43430A0 (&(bdaddr_t) {{0xac, 0x1f, 0x12, 0xa0, 0x43, 0x43}})
Frederic Danisa8f3b942015-05-28 11:25:02 +020038#define BDADDR_BCM4324B3 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb3, 0x24, 0x43}})
Frederic Danis4a546ec2015-07-27 18:02:25 +020039#define BDADDR_BCM4330B1 (&(bdaddr_t) {{0x00, 0x00, 0x00, 0xb1, 0x30, 0x43}})
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070040
41int btbcm_check_bdaddr(struct hci_dev *hdev)
42{
43 struct hci_rp_read_bd_addr *bda;
44 struct sk_buff *skb;
45
46 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
47 HCI_INIT_TIMEOUT);
48 if (IS_ERR(skb)) {
49 int err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +010050 bt_dev_err(hdev, "BCM: Reading device address failed (%d)", err);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070051 return err;
52 }
53
54 if (skb->len != sizeof(*bda)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010055 bt_dev_err(hdev, "BCM: Device address length mismatch");
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070056 kfree_skb(skb);
57 return -EIO;
58 }
59
60 bda = (struct hci_rp_read_bd_addr *)skb->data;
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070061
Frederic Danisa8f3b942015-05-28 11:25:02 +020062 /* Check if the address indicates a controller with either an
63 * invalid or default address. In both cases the device needs
64 * to be marked as not having a valid address.
65 *
66 * The address 00:20:70:02:A0:00 indicates a BCM20702A0 controller
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070067 * with no configured address.
Frederic Danisa8f3b942015-05-28 11:25:02 +020068 *
Maxime Ripard92ffe0d2018-12-17 12:04:45 +080069 * The address 20:70:02:A0:00:00 indicates a BCM20702A1 controller
70 * with no configured address.
71 *
Frederic Danisa8f3b942015-05-28 11:25:02 +020072 * The address 43:24:B3:00:00:00 indicates a BCM4324B3 controller
73 * with waiting for configuration state.
Frederic Danis4a546ec2015-07-27 18:02:25 +020074 *
75 * The address 43:30:B1:00:00:00 indicates a BCM4330B1 controller
76 * with waiting for configuration state.
Chen-Yu Tsai0697607a2018-12-17 12:04:47 +080077 *
78 * The address 43:43:A0:12:1F:AC indicates a BCM43430A0 controller
79 * with no configured address.
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070080 */
Frederic Danisa8f3b942015-05-28 11:25:02 +020081 if (!bacmp(&bda->bdaddr, BDADDR_BCM20702A0) ||
Maxime Ripard92ffe0d2018-12-17 12:04:45 +080082 !bacmp(&bda->bdaddr, BDADDR_BCM20702A1) ||
Frederic Danis4a546ec2015-07-27 18:02:25 +020083 !bacmp(&bda->bdaddr, BDADDR_BCM4324B3) ||
Chen-Yu Tsai0697607a2018-12-17 12:04:47 +080084 !bacmp(&bda->bdaddr, BDADDR_BCM4330B1) ||
85 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010086 bt_dev_info(hdev, "BCM: Using default device address (%pMR)",
87 &bda->bdaddr);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -070088 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
89 }
90
91 kfree_skb(skb);
92
93 return 0;
94}
95EXPORT_SYMBOL_GPL(btbcm_check_bdaddr);
96
97int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
98{
99 struct sk_buff *skb;
100 int err;
101
102 skb = __hci_cmd_sync(hdev, 0xfc01, 6, bdaddr, HCI_INIT_TIMEOUT);
103 if (IS_ERR(skb)) {
104 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100105 bt_dev_err(hdev, "BCM: Change address command failed (%d)", err);
Marcel Holtmann4fba30f2015-04-05 22:52:10 -0700106 return err;
107 }
108 kfree_skb(skb);
109
110 return 0;
111}
112EXPORT_SYMBOL_GPL(btbcm_set_bdaddr);
113
Frederic Danis18aeb442015-05-28 11:25:01 +0200114int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw)
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700115{
116 const struct hci_command_hdr *cmd;
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700117 const u8 *fw_ptr;
118 size_t fw_size;
119 struct sk_buff *skb;
120 u16 opcode;
Frederic Danis18aeb442015-05-28 11:25:01 +0200121 int err = 0;
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700122
123 /* Start Download */
124 skb = __hci_cmd_sync(hdev, 0xfc2e, 0, NULL, HCI_INIT_TIMEOUT);
125 if (IS_ERR(skb)) {
126 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100127 bt_dev_err(hdev, "BCM: Download Minidrv command failed (%d)",
128 err);
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700129 goto done;
130 }
131 kfree_skb(skb);
132
133 /* 50 msec delay after Download Minidrv completes */
134 msleep(50);
135
136 fw_ptr = fw->data;
137 fw_size = fw->size;
138
139 while (fw_size >= sizeof(*cmd)) {
140 const u8 *cmd_param;
141
142 cmd = (struct hci_command_hdr *)fw_ptr;
143 fw_ptr += sizeof(*cmd);
144 fw_size -= sizeof(*cmd);
145
146 if (fw_size < cmd->plen) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100147 bt_dev_err(hdev, "BCM: Patch is corrupted");
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700148 err = -EINVAL;
149 goto done;
150 }
151
152 cmd_param = fw_ptr;
153 fw_ptr += cmd->plen;
154 fw_size -= cmd->plen;
155
156 opcode = le16_to_cpu(cmd->opcode);
157
158 skb = __hci_cmd_sync(hdev, opcode, cmd->plen, cmd_param,
159 HCI_INIT_TIMEOUT);
160 if (IS_ERR(skb)) {
161 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100162 bt_dev_err(hdev, "BCM: Patch command %04x failed (%d)",
163 opcode, err);
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700164 goto done;
165 }
166 kfree_skb(skb);
167 }
168
169 /* 250 msec delay after Launch Ram completes */
170 msleep(250);
171
172done:
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700173 return err;
174}
175EXPORT_SYMBOL(btbcm_patchram);
176
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700177static int btbcm_reset(struct hci_dev *hdev)
178{
179 struct sk_buff *skb;
180
181 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
182 if (IS_ERR(skb)) {
183 int err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100184 bt_dev_err(hdev, "BCM: Reset failed (%d)", err);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700185 return err;
186 }
187 kfree_skb(skb);
188
Wen-chien Jesse Sung3af3a592017-01-10 11:46:28 +0800189 /* 100 msec delay for module to complete reset process */
190 msleep(100);
191
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700192 return 0;
193}
194
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200195static struct sk_buff *btbcm_read_local_name(struct hci_dev *hdev)
196{
197 struct sk_buff *skb;
198
199 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL,
200 HCI_INIT_TIMEOUT);
201 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100202 bt_dev_err(hdev, "BCM: Reading local name failed (%ld)",
203 PTR_ERR(skb));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200204 return skb;
205 }
206
207 if (skb->len != sizeof(struct hci_rp_read_local_name)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100208 bt_dev_err(hdev, "BCM: Local name length mismatch");
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200209 kfree_skb(skb);
210 return ERR_PTR(-EIO);
211 }
212
213 return skb;
214}
215
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700216static struct sk_buff *btbcm_read_local_version(struct hci_dev *hdev)
217{
218 struct sk_buff *skb;
219
220 skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_VERSION, 0, NULL,
221 HCI_INIT_TIMEOUT);
222 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100223 bt_dev_err(hdev, "BCM: Reading local version info failed (%ld)",
224 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700225 return skb;
226 }
227
228 if (skb->len != sizeof(struct hci_rp_read_local_version)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100229 bt_dev_err(hdev, "BCM: Local version length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700230 kfree_skb(skb);
231 return ERR_PTR(-EIO);
232 }
233
234 return skb;
235}
236
237static struct sk_buff *btbcm_read_verbose_config(struct hci_dev *hdev)
238{
239 struct sk_buff *skb;
240
241 skb = __hci_cmd_sync(hdev, 0xfc79, 0, NULL, HCI_INIT_TIMEOUT);
242 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100243 bt_dev_err(hdev, "BCM: Read verbose config info failed (%ld)",
244 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700245 return skb;
246 }
247
248 if (skb->len != 7) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100249 bt_dev_err(hdev, "BCM: Verbose config length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700250 kfree_skb(skb);
251 return ERR_PTR(-EIO);
252 }
253
254 return skb;
255}
256
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200257static struct sk_buff *btbcm_read_controller_features(struct hci_dev *hdev)
258{
259 struct sk_buff *skb;
260
261 skb = __hci_cmd_sync(hdev, 0xfc6e, 0, NULL, HCI_INIT_TIMEOUT);
262 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100263 bt_dev_err(hdev, "BCM: Read controller features failed (%ld)",
264 PTR_ERR(skb));
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200265 return skb;
266 }
267
268 if (skb->len != 9) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100269 bt_dev_err(hdev, "BCM: Controller features length mismatch");
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200270 kfree_skb(skb);
271 return ERR_PTR(-EIO);
272 }
273
274 return skb;
275}
276
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700277static struct sk_buff *btbcm_read_usb_product(struct hci_dev *hdev)
278{
279 struct sk_buff *skb;
280
281 skb = __hci_cmd_sync(hdev, 0xfc5a, 0, NULL, HCI_INIT_TIMEOUT);
282 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100283 bt_dev_err(hdev, "BCM: Read USB product info failed (%ld)",
284 PTR_ERR(skb));
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700285 return skb;
286 }
287
288 if (skb->len != 5) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100289 bt_dev_err(hdev, "BCM: USB product length mismatch");
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700290 kfree_skb(skb);
291 return ERR_PTR(-EIO);
292 }
293
294 return skb;
295}
296
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200297static int btbcm_read_info(struct hci_dev *hdev)
298{
299 struct sk_buff *skb;
300
301 /* Read Verbose Config Version Info */
302 skb = btbcm_read_verbose_config(hdev);
303 if (IS_ERR(skb))
304 return PTR_ERR(skb);
305
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100306 bt_dev_info(hdev, "BCM: chip id %u", skb->data[1]);
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200307 kfree_skb(skb);
308
309 /* Read Controller Features */
310 skb = btbcm_read_controller_features(hdev);
311 if (IS_ERR(skb))
312 return PTR_ERR(skb);
313
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100314 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200315 kfree_skb(skb);
316
317 /* Read Local Name */
318 skb = btbcm_read_local_name(hdev);
319 if (IS_ERR(skb))
320 return PTR_ERR(skb);
321
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100322 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200323 kfree_skb(skb);
324
325 return 0;
326}
327
Hans de Goedef7328382018-04-20 14:44:03 +0200328struct bcm_subver_table {
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700329 u16 subver;
330 const char *name;
Hans de Goedef7328382018-04-20 14:44:03 +0200331};
332
333static const struct bcm_subver_table bcm_uart_subver_table[] = {
Frederic Danis4a546ec2015-07-27 18:02:25 +0200334 { 0x4103, "BCM4330B1" }, /* 002.001.003 */
Marcel Holtmann9a0bb572015-04-05 22:52:19 -0700335 { 0x410e, "BCM43341B0" }, /* 002.001.014 */
Frederic Danisa8f3b942015-05-28 11:25:02 +0200336 { 0x4406, "BCM4324B3" }, /* 002.004.006 */
Christian Hewitta357ea02018-09-04 21:50:57 +0400337 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
Ilya Faenson40db5f02015-06-17 11:42:46 -0400338 { 0x610c, "BCM4354" }, /* 003.001.012 */
Jörg Kraused456f672018-01-18 10:21:55 +0100339 { 0x2122, "BCM4343A0" }, /* 001.001.034 */
Ian Moltonfeb16722017-06-28 20:10:55 +0100340 { 0x2209, "BCM43430A1" }, /* 001.002.009 */
Ian W MORRISON18a39b92017-10-06 18:34:18 +1100341 { 0x6119, "BCM4345C0" }, /* 003.001.025 */
Hans de Goedeb133e0c2017-10-13 17:54:01 +0200342 { 0x230f, "BCM4356A2" }, /* 001.003.015 */
Maxime Ripard92ffe0d2018-12-17 12:04:45 +0800343 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
Marcel Holtmann9a0bb572015-04-05 22:52:19 -0700344 { }
345};
346
Hans de Goedefec0de22018-04-20 14:44:04 +0200347static const struct bcm_subver_table bcm_usb_subver_table[] = {
348 { 0x210b, "BCM43142A0" }, /* 001.001.011 */
349 { 0x2112, "BCM4314A0" }, /* 001.001.018 */
350 { 0x2118, "BCM20702A0" }, /* 001.001.024 */
351 { 0x2126, "BCM4335A0" }, /* 001.001.038 */
352 { 0x220e, "BCM20702A1" }, /* 001.002.014 */
353 { 0x230f, "BCM4354A2" }, /* 001.003.015 */
354 { 0x4106, "BCM4335B0" }, /* 002.001.006 */
355 { 0x410e, "BCM20702B0" }, /* 002.001.014 */
356 { 0x6109, "BCM4335C0" }, /* 003.001.009 */
357 { 0x610c, "BCM4354" }, /* 003.001.012 */
358 { }
359};
360
Hans de Goede22ac1912018-04-20 14:44:05 +0200361int btbcm_initialize(struct hci_dev *hdev, char *fw_name, size_t len,
362 bool reinit)
Frederic Danis75e167e2015-05-28 11:25:04 +0200363{
Hans de Goedefec0de22018-04-20 14:44:04 +0200364 u16 subver, rev, pid, vid;
Hans de Goede2cc6d072018-04-20 14:44:07 +0200365 const char *hw_name = "BCM";
Frederic Danis75e167e2015-05-28 11:25:04 +0200366 struct sk_buff *skb;
367 struct hci_rp_read_local_version *ver;
Hans de Goedefec0de22018-04-20 14:44:04 +0200368 const struct bcm_subver_table *bcm_subver_table;
Frederic Danis75e167e2015-05-28 11:25:04 +0200369 int i, err;
370
371 /* Reset */
372 err = btbcm_reset(hdev);
373 if (err)
374 return err;
375
376 /* Read Local Version Info */
377 skb = btbcm_read_local_version(hdev);
378 if (IS_ERR(skb))
379 return PTR_ERR(skb);
380
381 ver = (struct hci_rp_read_local_version *)skb->data;
382 rev = le16_to_cpu(ver->hci_rev);
383 subver = le16_to_cpu(ver->lmp_subver);
384 kfree_skb(skb);
385
Marcel Holtmanne76dc1d2017-08-17 11:02:40 +0200386 /* Read controller information */
Hans de Goede22ac1912018-04-20 14:44:05 +0200387 if (!reinit) {
388 err = btbcm_read_info(hdev);
389 if (err)
390 return err;
391 }
Frederic Danis75e167e2015-05-28 11:25:04 +0200392
Hans de Goedefec0de22018-04-20 14:44:04 +0200393 /* Upper nibble of rev should be between 0 and 3? */
394 if (((rev & 0xf000) >> 12) > 3)
Frederic Danis75e167e2015-05-28 11:25:04 +0200395 return 0;
Hans de Goedefec0de22018-04-20 14:44:04 +0200396
397 bcm_subver_table = (hdev->bus == HCI_USB) ? bcm_usb_subver_table :
398 bcm_uart_subver_table;
399
400 for (i = 0; bcm_subver_table[i].name; i++) {
401 if (subver == bcm_subver_table[i].subver) {
402 hw_name = bcm_subver_table[i].name;
403 break;
404 }
405 }
406
407 if (hdev->bus == HCI_USB) {
408 /* Read USB Product Info */
409 skb = btbcm_read_usb_product(hdev);
410 if (IS_ERR(skb))
411 return PTR_ERR(skb);
412
413 vid = get_unaligned_le16(skb->data + 1);
414 pid = get_unaligned_le16(skb->data + 3);
415 kfree_skb(skb);
416
417 snprintf(fw_name, len, "brcm/%s-%4.4x-%4.4x.hcd",
Hans de Goede2cc6d072018-04-20 14:44:07 +0200418 hw_name, vid, pid);
Hans de Goedefec0de22018-04-20 14:44:04 +0200419 } else {
Hans de Goede2cc6d072018-04-20 14:44:07 +0200420 snprintf(fw_name, len, "brcm/%s.hcd", hw_name);
Frederic Danis75e167e2015-05-28 11:25:04 +0200421 }
422
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100423 bt_dev_info(hdev, "%s (%3.3u.%3.3u.%3.3u) build %4.4u",
Hans de Goede2cc6d072018-04-20 14:44:07 +0200424 hw_name, (subver & 0xe000) >> 13,
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100425 (subver & 0x1f00) >> 8, (subver & 0x00ff), rev & 0x0fff);
Frederic Danis75e167e2015-05-28 11:25:04 +0200426
427 return 0;
428}
429EXPORT_SYMBOL_GPL(btbcm_initialize);
430
431int btbcm_finalize(struct hci_dev *hdev)
432{
Hans de Goede22ac1912018-04-20 14:44:05 +0200433 char fw_name[64];
Frederic Danis75e167e2015-05-28 11:25:04 +0200434 int err;
435
Hans de Goede22ac1912018-04-20 14:44:05 +0200436 /* Re-initialize */
437 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
Frederic Danis75e167e2015-05-28 11:25:04 +0200438 if (err)
439 return err;
440
Frederic Danis75e167e2015-05-28 11:25:04 +0200441 btbcm_check_bdaddr(hdev);
442
443 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
444
445 return 0;
446}
447EXPORT_SYMBOL_GPL(btbcm_finalize);
448
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700449int btbcm_setup_patchram(struct hci_dev *hdev)
450{
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700451 char fw_name[64];
Frederic Danis18aeb442015-05-28 11:25:01 +0200452 const struct firmware *fw;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700453 struct sk_buff *skb;
Hans de Goede59ce5692018-04-20 14:44:06 +0200454 int err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700455
Hans de Goede59ce5692018-04-20 14:44:06 +0200456 /* Initialize */
457 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), false);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700458 if (err)
459 return err;
460
Frederic Danis18aeb442015-05-28 11:25:01 +0200461 err = request_firmware(&fw, fw_name, &hdev->dev);
462 if (err < 0) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100463 bt_dev_info(hdev, "BCM: Patch %s not found", fw_name);
Petri Gyntherad750fa12016-02-10 12:00:46 -0800464 goto done;
Frederic Danis18aeb442015-05-28 11:25:01 +0200465 }
466
467 btbcm_patchram(hdev, fw);
468
469 release_firmware(fw);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700470
Hans de Goede59ce5692018-04-20 14:44:06 +0200471 /* Re-initialize */
472 err = btbcm_initialize(hdev, fw_name, sizeof(fw_name), true);
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700473 if (err)
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700474 return err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700475
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200476 /* Read Local Name */
477 skb = btbcm_read_local_name(hdev);
478 if (IS_ERR(skb))
479 return PTR_ERR(skb);
480
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100481 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200482 kfree_skb(skb);
483
Petri Gyntherad750fa12016-02-10 12:00:46 -0800484done:
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700485 btbcm_check_bdaddr(hdev);
486
Marcel Holtmann941521e2015-04-05 22:52:15 -0700487 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
488
Marcel Holtmann50862ee2015-04-10 14:02:20 -0700489 return 0;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700490}
491EXPORT_SYMBOL_GPL(btbcm_setup_patchram);
492
493int btbcm_setup_apple(struct hci_dev *hdev)
494{
495 struct sk_buff *skb;
Marcel Holtmannb224d3f2015-10-03 12:01:08 +0200496 int err;
497
498 /* Reset */
499 err = btbcm_reset(hdev);
500 if (err)
501 return err;
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700502
503 /* Read Verbose Config Version Info */
504 skb = btbcm_read_verbose_config(hdev);
Chris Mason7bee8b02015-07-14 16:25:30 -0400505 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100506 bt_dev_info(hdev, "BCM: chip id %u build %4.4u",
507 skb->data[1], get_unaligned_le16(skb->data + 5));
Chris Mason7bee8b02015-07-14 16:25:30 -0400508 kfree_skb(skb);
509 }
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700510
Marcel Holtmann34cea412015-10-18 22:48:28 +0200511 /* Read USB Product Info */
512 skb = btbcm_read_usb_product(hdev);
513 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100514 bt_dev_info(hdev, "BCM: product %4.4x:%4.4x",
515 get_unaligned_le16(skb->data + 1),
516 get_unaligned_le16(skb->data + 3));
Marcel Holtmann34cea412015-10-18 22:48:28 +0200517 kfree_skb(skb);
518 }
519
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200520 /* Read Controller Features */
521 skb = btbcm_read_controller_features(hdev);
522 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100523 bt_dev_info(hdev, "BCM: features 0x%2.2x", skb->data[1]);
Marcel Holtmann4284ecb2017-06-10 14:33:16 +0200524 kfree_skb(skb);
525 }
526
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200527 /* Read Local Name */
528 skb = btbcm_read_local_name(hdev);
529 if (!IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100530 bt_dev_info(hdev, "%s", (char *)(skb->data + 1));
Marcel Holtmann9bc63ca2015-10-05 12:43:57 +0200531 kfree_skb(skb);
532 }
533
Marcel Holtmann941521e2015-04-05 22:52:15 -0700534 set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
535
Marcel Holtmann1c8ba6d2015-04-05 22:52:13 -0700536 return 0;
537}
538EXPORT_SYMBOL_GPL(btbcm_setup_apple);
539
Marcel Holtmann4fba30f2015-04-05 22:52:10 -0700540MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
541MODULE_DESCRIPTION("Bluetooth support for Broadcom devices ver " VERSION);
542MODULE_VERSION(VERSION);
543MODULE_LICENSE("GPL");