Merge branch 'for-6.4/nintendo' into for-linus
[linux-2.6-block.git] / drivers / bluetooth / ath3k.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
9670d80a
VK
2/*
3 * Copyright (c) 2008-2009 Atheros Communications Inc.
9670d80a
VK
4 */
5
6
7#include <linux/module.h>
8#include <linux/kernel.h>
9#include <linux/init.h>
10#include <linux/slab.h>
11#include <linux/types.h>
12#include <linux/errno.h>
9670d80a
VK
13#include <linux/firmware.h>
14#include <linux/usb.h>
72dd2b2a 15#include <asm/unaligned.h>
9670d80a
VK
16#include <net/bluetooth/bluetooth.h>
17
18#define VERSION "1.0"
c3eae82a 19#define ATH3K_FIRMWARE "ath3k-1.fw"
9670d80a 20
d9f51b51
BS
21#define ATH3K_DNLOAD 0x01
22#define ATH3K_GETSTATE 0x05
23#define ATH3K_SET_NORMAL_MODE 0x07
24#define ATH3K_GETVERSION 0x09
25#define USB_REG_SWITCH_VID_PID 0x0a
26
27#define ATH3K_MODE_MASK 0x3F
28#define ATH3K_NORMAL_MODE 0x0E
29
30#define ATH3K_PATCH_UPDATE 0x80
31#define ATH3K_SYSCFG_UPDATE 0x40
32
33#define ATH3K_XTAL_FREQ_26M 0x00
34#define ATH3K_XTAL_FREQ_40M 0x01
35#define ATH3K_XTAL_FREQ_19P2 0x02
36#define ATH3K_NAME_LEN 0xFF
37
38struct ath3k_version {
72dd2b2a
MH
39 __le32 rom_version;
40 __le32 build_version;
41 __le32 ram_version;
42 __u8 ref_clock;
43 __u8 reserved[7];
44} __packed;
9670d80a 45
3932eb33 46static const struct usb_device_id ath3k_table[] = {
9670d80a
VK
47 /* Atheros AR3011 */
48 { USB_DEVICE(0x0CF3, 0x3000) },
be93112a
BS
49
50 /* Atheros AR3011 with sflash firmware*/
0b880062
AS
51 { USB_DEVICE(0x0489, 0xE027) },
52 { USB_DEVICE(0x0489, 0xE03D) },
2eeff0b4 53 { USB_DEVICE(0x04F2, 0xAFF1) },
0b880062 54 { USB_DEVICE(0x0930, 0x0215) },
be93112a 55 { USB_DEVICE(0x0CF3, 0x3002) },
6eda541d 56 { USB_DEVICE(0x0CF3, 0xE019) },
2a7bcccc 57 { USB_DEVICE(0x13d3, 0x3304) },
be93112a 58
509e7861
CYC
59 /* Atheros AR9285 Malbec with sflash firmware */
60 { USB_DEVICE(0x03F0, 0x311D) },
d9f51b51
BS
61
62 /* Atheros AR3012 with sflash firmware*/
0b880062
AS
63 { USB_DEVICE(0x0489, 0xe04d) },
64 { USB_DEVICE(0x0489, 0xe04e) },
65 { USB_DEVICE(0x0489, 0xe057) },
66 { USB_DEVICE(0x0489, 0xe056) },
67 { USB_DEVICE(0x0489, 0xe05f) },
692c062e 68 { USB_DEVICE(0x0489, 0xe076) },
4b552bc9 69 { USB_DEVICE(0x0489, 0xe078) },
28c971d8 70 { USB_DEVICE(0x0489, 0xe095) },
0b880062
AS
71 { USB_DEVICE(0x04c5, 0x1330) },
72 { USB_DEVICE(0x04CA, 0x3004) },
73 { USB_DEVICE(0x04CA, 0x3005) },
74 { USB_DEVICE(0x04CA, 0x3006) },
1fb4e09a 75 { USB_DEVICE(0x04CA, 0x3007) },
0b880062
AS
76 { USB_DEVICE(0x04CA, 0x3008) },
77 { USB_DEVICE(0x04CA, 0x300b) },
7e730c7f 78 { USB_DEVICE(0x04CA, 0x300d) },
ec0810d2 79 { USB_DEVICE(0x04CA, 0x300f) },
134d3b35 80 { USB_DEVICE(0x04CA, 0x3010) },
81d90442 81 { USB_DEVICE(0x04CA, 0x3014) },
441ad62d 82 { USB_DEVICE(0x04CA, 0x3018) },
0b880062 83 { USB_DEVICE(0x0930, 0x0219) },
cd355ff0 84 { USB_DEVICE(0x0930, 0x021c) },
0b880062 85 { USB_DEVICE(0x0930, 0x0220) },
89d2975f 86 { USB_DEVICE(0x0930, 0x0227) },
a735f9e2 87 { USB_DEVICE(0x0b05, 0x17d0) },
d66629c1 88 { USB_DEVICE(0x0CF3, 0x0036) },
d9f51b51 89 { USB_DEVICE(0x0CF3, 0x3004) },
94a32d10 90 { USB_DEVICE(0x0CF3, 0x3008) },
07c0ea87 91 { USB_DEVICE(0x0CF3, 0x311D) },
b131237c 92 { USB_DEVICE(0x0CF3, 0x311E) },
1e56f1eb 93 { USB_DEVICE(0x0CF3, 0x311F) },
0b880062 94 { USB_DEVICE(0x0cf3, 0x3121) },
ebaf5795 95 { USB_DEVICE(0x0CF3, 0x817a) },
18e0afab 96 { USB_DEVICE(0x0CF3, 0x817b) },
0b880062 97 { USB_DEVICE(0x0cf3, 0xe003) },
ac71311e 98 { USB_DEVICE(0x0CF3, 0xE004) },
0a3658cc 99 { USB_DEVICE(0x0CF3, 0xE005) },
ca79f232 100 { USB_DEVICE(0x0CF3, 0xE006) },
0b880062
AS
101 { USB_DEVICE(0x13d3, 0x3362) },
102 { USB_DEVICE(0x13d3, 0x3375) },
eed307e2 103 { USB_DEVICE(0x13d3, 0x3393) },
609574eb 104 { USB_DEVICE(0x13d3, 0x3395) },
5b77a1f3 105 { USB_DEVICE(0x13d3, 0x3402) },
3bb30a7c 106 { USB_DEVICE(0x13d3, 0x3408) },
033efa92 107 { USB_DEVICE(0x13d3, 0x3423) },
fa2f1394 108 { USB_DEVICE(0x13d3, 0x3432) },
75c6aca4 109 { USB_DEVICE(0x13d3, 0x3472) },
0d0cef61 110 { USB_DEVICE(0x13d3, 0x3474) },
72f9f8b5 111 { USB_DEVICE(0x13d3, 0x3487) },
12d86896 112 { USB_DEVICE(0x13d3, 0x3490) },
d9f51b51 113
e9036e33
CYC
114 /* Atheros AR5BBU12 with sflash firmware */
115 { USB_DEVICE(0x0489, 0xE02C) },
b67afe7f 116
85d59726 117 /* Atheros AR5BBU22 with sflash firmware */
bc21fde2 118 { USB_DEVICE(0x0489, 0xE036) },
0b880062 119 { USB_DEVICE(0x0489, 0xE03C) },
85d59726 120
9670d80a
VK
121 { } /* Terminating entry */
122};
123
124MODULE_DEVICE_TABLE(usb, ath3k_table);
125
d9f51b51
BS
126#define BTUSB_ATH3012 0x80
127/* This table is to load patch and sysconfig files
d98422cb
DR
128 * for AR3012
129 */
3932eb33 130static const struct usb_device_id ath3k_blist_tbl[] = {
d9f51b51
BS
131
132 /* Atheros AR3012 with sflash firmware*/
0b880062
AS
133 { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
134 { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
135 { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
136 { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
137 { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
692c062e 138 { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 },
4b552bc9 139 { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
28c971d8 140 { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 },
0b880062
AS
141 { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
142 { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
143 { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
144 { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
1fb4e09a 145 { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
0b880062
AS
146 { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
147 { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
7e730c7f 148 { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 },
ec0810d2 149 { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
134d3b35 150 { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
81d90442 151 { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 },
441ad62d 152 { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 },
0b880062 153 { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
cd355ff0 154 { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 },
0b880062 155 { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
89d2975f 156 { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
a735f9e2 157 { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
d66629c1 158 { USB_DEVICE(0x0CF3, 0x0036), .driver_info = BTUSB_ATH3012 },
d9f51b51 159 { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
94a32d10 160 { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
07c0ea87 161 { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 },
b131237c 162 { USB_DEVICE(0x0cf3, 0x311E), .driver_info = BTUSB_ATH3012 },
1e56f1eb 163 { USB_DEVICE(0x0cf3, 0x311F), .driver_info = BTUSB_ATH3012 },
0b880062 164 { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
ebaf5795 165 { USB_DEVICE(0x0CF3, 0x817a), .driver_info = BTUSB_ATH3012 },
18e0afab 166 { USB_DEVICE(0x0CF3, 0x817b), .driver_info = BTUSB_ATH3012 },
ac71311e 167 { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
0a3658cc 168 { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
ca79f232 169 { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
0b880062
AS
170 { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
171 { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
172 { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
eed307e2 173 { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
609574eb 174 { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 },
5b77a1f3 175 { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
3bb30a7c 176 { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
033efa92 177 { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
fa2f1394 178 { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
75c6aca4 179 { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 },
0d0cef61 180 { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 },
72f9f8b5 181 { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 },
12d86896 182 { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 },
d9f51b51 183
85d59726 184 /* Atheros AR5BBU22 with sflash firmware */
bc21fde2 185 { USB_DEVICE(0x0489, 0xE036), .driver_info = BTUSB_ATH3012 },
0b880062 186 { USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 },
85d59726 187
d9f51b51
BS
188 { } /* Terminating entry */
189};
190
d6b372f6
LCR
191static inline void ath3k_log_failed_loading(int err, int len, int size,
192 int count)
3d08f43c 193{
d6b372f6
LCR
194 BT_ERR("Firmware loading err = %d, len = %d, size = %d, count = %d",
195 err, len, size, count);
3d08f43c
MZ
196}
197
9670d80a
VK
198#define USB_REQ_DFU_DNLOAD 1
199#define BULK_SIZE 4096
d9f51b51 200#define FW_HDR_SIZE 20
c561a575
AL
201#define TIMEGAP_USEC_MIN 50
202#define TIMEGAP_USEC_MAX 100
9670d80a 203
86e09287
AH
204static int ath3k_load_firmware(struct usb_device *udev,
205 const struct firmware *firmware)
9670d80a
VK
206{
207 u8 *send_buf;
e9fc7164
DC
208 int len = 0;
209 int err, pipe, size, sent = 0;
86e09287 210 int count = firmware->size;
9670d80a 211
86e09287 212 BT_DBG("udev %p", udev);
9670d80a 213
52a1020e 214 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
86e09287
AH
215 if (!send_buf) {
216 BT_ERR("Can't allocate memory chunk for firmware");
217 return -ENOMEM;
218 }
219
dbb29de7
GKH
220 err = usb_control_msg_send(udev, 0, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR,
221 0, 0, firmware->data, FW_HDR_SIZE,
222 USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
223 if (err) {
9670d80a 224 BT_ERR("Can't change to loading configuration err");
86e09287 225 goto error;
9670d80a 226 }
8b077bdb
MZ
227 sent += FW_HDR_SIZE;
228 count -= FW_HDR_SIZE;
9670d80a 229
3abb56de
AL
230 pipe = usb_sndbulkpipe(udev, 0x02);
231
9670d80a 232 while (count) {
c561a575
AL
233 /* workaround the compatibility issue with xHCI controller*/
234 usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
235
9670d80a 236 size = min_t(uint, count, BULK_SIZE);
86e09287 237 memcpy(send_buf, firmware->data + sent, size);
9670d80a 238
86e09287 239 err = usb_bulk_msg(udev, pipe, send_buf, size,
9670d80a
VK
240 &len, 3000);
241
242 if (err || (len != size)) {
d6b372f6 243 ath3k_log_failed_loading(err, len, size, count);
9670d80a
VK
244 goto error;
245 }
246
247 sent += size;
248 count -= size;
249 }
250
9670d80a
VK
251error:
252 kfree(send_buf);
253 return err;
254}
255
d9f51b51
BS
256static int ath3k_get_state(struct usb_device *udev, unsigned char *state)
257{
dbb29de7
GKH
258 return usb_control_msg_recv(udev, 0, ATH3K_GETSTATE,
259 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
260 state, 1, USB_CTRL_SET_TIMEOUT,
261 GFP_KERNEL);
d9f51b51
BS
262}
263
264static int ath3k_get_version(struct usb_device *udev,
265 struct ath3k_version *version)
266{
dbb29de7
GKH
267 return usb_control_msg_recv(udev, 0, ATH3K_GETVERSION,
268 USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
269 version, sizeof(*version), USB_CTRL_SET_TIMEOUT,
270 GFP_KERNEL);
d9f51b51
BS
271}
272
273static int ath3k_load_fwfile(struct usb_device *udev,
274 const struct firmware *firmware)
275{
276 u8 *send_buf;
e9fc7164
DC
277 int len = 0;
278 int err, pipe, size, count, sent = 0;
d9f51b51
BS
279 int ret;
280
281 count = firmware->size;
282
52a1020e 283 send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
d9f51b51
BS
284 if (!send_buf) {
285 BT_ERR("Can't allocate memory chunk for firmware");
286 return -ENOMEM;
287 }
288
289 size = min_t(uint, count, FW_HDR_SIZE);
d9f51b51 290
dbb29de7
GKH
291 ret = usb_control_msg_send(udev, 0, ATH3K_DNLOAD, USB_TYPE_VENDOR, 0, 0,
292 firmware->data, size, USB_CTRL_SET_TIMEOUT,
293 GFP_KERNEL);
294 if (ret) {
d9f51b51
BS
295 BT_ERR("Can't change to loading configuration err");
296 kfree(send_buf);
297 return ret;
298 }
299
300 sent += size;
301 count -= size;
302
b0c3e138
AL
303 pipe = usb_sndbulkpipe(udev, 0x02);
304
d9f51b51 305 while (count) {
c561a575
AL
306 /* workaround the compatibility issue with xHCI controller*/
307 usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
308
d9f51b51 309 size = min_t(uint, count, BULK_SIZE);
d9f51b51
BS
310 memcpy(send_buf, firmware->data + sent, size);
311
312 err = usb_bulk_msg(udev, pipe, send_buf, size,
313 &len, 3000);
314 if (err || (len != size)) {
d6b372f6 315 ath3k_log_failed_loading(err, len, size, count);
d9f51b51
BS
316 kfree(send_buf);
317 return err;
318 }
319 sent += size;
320 count -= size;
321 }
322
323 kfree(send_buf);
324 return 0;
325}
326
dbb29de7 327static void ath3k_switch_pid(struct usb_device *udev)
d9f51b51 328{
dbb29de7
GKH
329 usb_control_msg_send(udev, 0, USB_REG_SWITCH_VID_PID, USB_TYPE_VENDOR,
330 0, 0, NULL, 0, USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
d9f51b51
BS
331}
332
333static int ath3k_set_normal_mode(struct usb_device *udev)
334{
335 unsigned char fw_state;
dbb29de7 336 int ret;
d9f51b51
BS
337
338 ret = ath3k_get_state(udev, &fw_state);
dbb29de7 339 if (ret) {
d9f51b51
BS
340 BT_ERR("Can't get state to change to normal mode err");
341 return ret;
342 }
343
344 if ((fw_state & ATH3K_MODE_MASK) == ATH3K_NORMAL_MODE) {
345 BT_DBG("firmware was already in normal mode");
346 return 0;
347 }
348
dbb29de7
GKH
349 return usb_control_msg_send(udev, 0, ATH3K_SET_NORMAL_MODE,
350 USB_TYPE_VENDOR, 0, 0, NULL, 0,
351 USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
d9f51b51
BS
352}
353
354static int ath3k_load_patch(struct usb_device *udev)
355{
356 unsigned char fw_state;
b3baa242 357 char filename[ATH3K_NAME_LEN];
d9f51b51 358 const struct firmware *firmware;
72dd2b2a
MH
359 struct ath3k_version fw_version;
360 __u32 pt_rom_version, pt_build_version;
d9f51b51
BS
361 int ret;
362
363 ret = ath3k_get_state(udev, &fw_state);
dbb29de7 364 if (ret) {
d9f51b51
BS
365 BT_ERR("Can't get state to change to load ram patch err");
366 return ret;
367 }
368
369 if (fw_state & ATH3K_PATCH_UPDATE) {
370 BT_DBG("Patch was already downloaded");
371 return 0;
372 }
373
374 ret = ath3k_get_version(udev, &fw_version);
dbb29de7 375 if (ret) {
d9f51b51
BS
376 BT_ERR("Can't get version to change to load ram patch err");
377 return ret;
378 }
379
380 snprintf(filename, ATH3K_NAME_LEN, "ar3k/AthrBT_0x%08x.dfu",
72dd2b2a 381 le32_to_cpu(fw_version.rom_version));
d9f51b51
BS
382
383 ret = request_firmware(&firmware, filename, &udev->dev);
384 if (ret < 0) {
385 BT_ERR("Patch file not found %s", filename);
386 return ret;
387 }
388
72dd2b2a
MH
389 pt_rom_version = get_unaligned_le32(firmware->data +
390 firmware->size - 8);
391 pt_build_version = get_unaligned_le32(firmware->data +
392 firmware->size - 4);
d9f51b51 393
72dd2b2a
MH
394 if (pt_rom_version != le32_to_cpu(fw_version.rom_version) ||
395 pt_build_version <= le32_to_cpu(fw_version.build_version)) {
d9f51b51
BS
396 BT_ERR("Patch file version did not match with firmware");
397 release_firmware(firmware);
398 return -EINVAL;
399 }
400
401 ret = ath3k_load_fwfile(udev, firmware);
402 release_firmware(firmware);
403
404 return ret;
405}
406
407static int ath3k_load_syscfg(struct usb_device *udev)
408{
409 unsigned char fw_state;
b3baa242 410 char filename[ATH3K_NAME_LEN];
d9f51b51
BS
411 const struct firmware *firmware;
412 struct ath3k_version fw_version;
413 int clk_value, ret;
414
415 ret = ath3k_get_state(udev, &fw_state);
dbb29de7 416 if (ret) {
8a168ca7 417 BT_ERR("Can't get state to change to load configuration err");
d9f51b51
BS
418 return -EBUSY;
419 }
420
421 ret = ath3k_get_version(udev, &fw_version);
dbb29de7 422 if (ret) {
d9f51b51
BS
423 BT_ERR("Can't get version to change to load ram patch err");
424 return ret;
425 }
426
427 switch (fw_version.ref_clock) {
428
429 case ATH3K_XTAL_FREQ_26M:
430 clk_value = 26;
431 break;
432 case ATH3K_XTAL_FREQ_40M:
433 clk_value = 40;
434 break;
435 case ATH3K_XTAL_FREQ_19P2:
436 clk_value = 19;
437 break;
438 default:
439 clk_value = 0;
440 break;
441 }
442
443 snprintf(filename, ATH3K_NAME_LEN, "ar3k/ramps_0x%08x_%d%s",
b9e2535a 444 le32_to_cpu(fw_version.rom_version), clk_value, ".dfu");
d9f51b51
BS
445
446 ret = request_firmware(&firmware, filename, &udev->dev);
447 if (ret < 0) {
448 BT_ERR("Configuration file not found %s", filename);
449 return ret;
450 }
451
452 ret = ath3k_load_fwfile(udev, firmware);
453 release_firmware(firmware);
454
455 return ret;
456}
457
9670d80a
VK
458static int ath3k_probe(struct usb_interface *intf,
459 const struct usb_device_id *id)
460{
461 const struct firmware *firmware;
462 struct usb_device *udev = interface_to_usbdev(intf);
84f0e17f 463 int ret;
9670d80a
VK
464
465 BT_DBG("intf %p id %p", intf, id);
466
467 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
468 return -ENODEV;
469
d9f51b51
BS
470 /* match device ID in ath3k blacklist table */
471 if (!id->driver_info) {
472 const struct usb_device_id *match;
d2ee9c2e 473
d9f51b51
BS
474 match = usb_match_id(intf, ath3k_blist_tbl);
475 if (match)
476 id = match;
477 }
478
479 /* load patch and sysconfig files for AR3012 */
480 if (id->driver_info & BTUSB_ATH3012) {
2d25f8b4
SL
481 /* New firmware with patch and sysconfig files already loaded */
482 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x0001)
483 return -ENODEV;
484
d9f51b51
BS
485 ret = ath3k_load_patch(udev);
486 if (ret < 0) {
487 BT_ERR("Loading patch file failed");
488 return ret;
489 }
490 ret = ath3k_load_syscfg(udev);
491 if (ret < 0) {
492 BT_ERR("Loading sysconfig file failed");
493 return ret;
494 }
495 ret = ath3k_set_normal_mode(udev);
dbb29de7 496 if (ret) {
d9f51b51
BS
497 BT_ERR("Set normal mode failed");
498 return ret;
499 }
500 ath3k_switch_pid(udev);
501 return 0;
502 }
503
c3eae82a
PF
504 ret = request_firmware(&firmware, ATH3K_FIRMWARE, &udev->dev);
505 if (ret < 0) {
506 if (ret == -ENOENT)
507 BT_ERR("Firmware file \"%s\" not found",
508 ATH3K_FIRMWARE);
509 else
510 BT_ERR("Firmware file \"%s\" request failed (err=%d)",
511 ATH3K_FIRMWARE, ret);
512 return ret;
9670d80a
VK
513 }
514
84f0e17f 515 ret = ath3k_load_firmware(udev, firmware);
86e09287 516 release_firmware(firmware);
9670d80a 517
84f0e17f 518 return ret;
9670d80a
VK
519}
520
521static void ath3k_disconnect(struct usb_interface *intf)
522{
0a21963a 523 BT_DBG("%s intf %p", __func__, intf);
9670d80a
VK
524}
525
526static struct usb_driver ath3k_driver = {
527 .name = "ath3k",
528 .probe = ath3k_probe,
529 .disconnect = ath3k_disconnect,
530 .id_table = ath3k_table,
e1f12eb6 531 .disable_hub_initiated_lpm = 1,
9670d80a
VK
532};
533
93f1508c 534module_usb_driver(ath3k_driver);
9670d80a
VK
535
536MODULE_AUTHOR("Atheros Communications");
537MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
538MODULE_VERSION(VERSION);
539MODULE_LICENSE("GPL");
c3eae82a 540MODULE_FIRMWARE(ATH3K_FIRMWARE);