ath3k.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/kernel.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/types.h>
  24. #include <linux/errno.h>
  25. #include <linux/device.h>
  26. #include <linux/firmware.h>
  27. #include <linux/usb.h>
  28. #include <asm/unaligned.h>
  29. #include <net/bluetooth/bluetooth.h>
  30. #define VERSION "1.0"
  31. #define ATH3K_FIRMWARE "ath3k-1.fw"
  32. #define ATH3K_DNLOAD 0x01
  33. #define ATH3K_GETSTATE 0x05
  34. #define ATH3K_SET_NORMAL_MODE 0x07
  35. #define ATH3K_GETVERSION 0x09
  36. #define USB_REG_SWITCH_VID_PID 0x0a
  37. #define ATH3K_MODE_MASK 0x3F
  38. #define ATH3K_NORMAL_MODE 0x0E
  39. #define ATH3K_PATCH_UPDATE 0x80
  40. #define ATH3K_SYSCFG_UPDATE 0x40
  41. #define ATH3K_XTAL_FREQ_26M 0x00
  42. #define ATH3K_XTAL_FREQ_40M 0x01
  43. #define ATH3K_XTAL_FREQ_19P2 0x02
  44. #define ATH3K_NAME_LEN 0xFF
  45. struct ath3k_version {
  46. __le32 rom_version;
  47. __le32 build_version;
  48. __le32 ram_version;
  49. __u8 ref_clock;
  50. __u8 reserved[7];
  51. } __packed;
  52. static const struct usb_device_id ath3k_table[] = {
  53. /* Atheros AR3011 */
  54. { USB_DEVICE(0x0CF3, 0x3000) },
  55. /* Atheros AR3011 with sflash firmware*/
  56. { USB_DEVICE(0x0489, 0xE027) },
  57. { USB_DEVICE(0x0489, 0xE03D) },
  58. { USB_DEVICE(0x04F2, 0xAFF1) },
  59. { USB_DEVICE(0x0930, 0x0215) },
  60. { USB_DEVICE(0x0CF3, 0x3002) },
  61. { USB_DEVICE(0x0CF3, 0xE019) },
  62. { USB_DEVICE(0x13d3, 0x3304) },
  63. /* Atheros AR9285 Malbec with sflash firmware */
  64. { USB_DEVICE(0x03F0, 0x311D) },
  65. /* Atheros AR3012 with sflash firmware*/
  66. { USB_DEVICE(0x0489, 0xe04d) },
  67. { USB_DEVICE(0x0489, 0xe04e) },
  68. { USB_DEVICE(0x0489, 0xe057) },
  69. { USB_DEVICE(0x0489, 0xe056) },
  70. { USB_DEVICE(0x0489, 0xe05f) },
  71. { USB_DEVICE(0x0489, 0xe076) },
  72. { USB_DEVICE(0x0489, 0xe078) },
  73. { USB_DEVICE(0x0489, 0xe095) },
  74. { USB_DEVICE(0x04c5, 0x1330) },
  75. { USB_DEVICE(0x04CA, 0x3004) },
  76. { USB_DEVICE(0x04CA, 0x3005) },
  77. { USB_DEVICE(0x04CA, 0x3006) },
  78. { USB_DEVICE(0x04CA, 0x3007) },
  79. { USB_DEVICE(0x04CA, 0x3008) },
  80. { USB_DEVICE(0x04CA, 0x300b) },
  81. { USB_DEVICE(0x04CA, 0x300d) },
  82. { USB_DEVICE(0x04CA, 0x300f) },
  83. { USB_DEVICE(0x04CA, 0x3010) },
  84. { USB_DEVICE(0x04CA, 0x3014) },
  85. { USB_DEVICE(0x04CA, 0x3018) },
  86. { USB_DEVICE(0x0930, 0x0219) },
  87. { USB_DEVICE(0x0930, 0x021c) },
  88. { USB_DEVICE(0x0930, 0x0220) },
  89. { USB_DEVICE(0x0930, 0x0227) },
  90. { USB_DEVICE(0x0b05, 0x17d0) },
  91. { USB_DEVICE(0x0CF3, 0x0036) },
  92. { USB_DEVICE(0x0CF3, 0x3004) },
  93. { USB_DEVICE(0x0CF3, 0x3008) },
  94. { USB_DEVICE(0x0CF3, 0x311D) },
  95. { USB_DEVICE(0x0CF3, 0x311E) },
  96. { USB_DEVICE(0x0CF3, 0x311F) },
  97. { USB_DEVICE(0x0cf3, 0x3121) },
  98. { USB_DEVICE(0x0CF3, 0x817a) },
  99. { USB_DEVICE(0x0CF3, 0x817b) },
  100. { USB_DEVICE(0x0cf3, 0xe003) },
  101. { USB_DEVICE(0x0CF3, 0xE004) },
  102. { USB_DEVICE(0x0CF3, 0xE005) },
  103. { USB_DEVICE(0x0CF3, 0xE006) },
  104. { USB_DEVICE(0x13d3, 0x3362) },
  105. { USB_DEVICE(0x13d3, 0x3375) },
  106. { USB_DEVICE(0x13d3, 0x3393) },
  107. { USB_DEVICE(0x13d3, 0x3395) },
  108. { USB_DEVICE(0x13d3, 0x3402) },
  109. { USB_DEVICE(0x13d3, 0x3408) },
  110. { USB_DEVICE(0x13d3, 0x3423) },
  111. { USB_DEVICE(0x13d3, 0x3432) },
  112. { USB_DEVICE(0x13d3, 0x3472) },
  113. { USB_DEVICE(0x13d3, 0x3474) },
  114. { USB_DEVICE(0x13d3, 0x3487) },
  115. { USB_DEVICE(0x13d3, 0x3490) },
  116. /* Atheros AR5BBU12 with sflash firmware */
  117. { USB_DEVICE(0x0489, 0xE02C) },
  118. /* Atheros AR5BBU22 with sflash firmware */
  119. { USB_DEVICE(0x0489, 0xE036) },
  120. { USB_DEVICE(0x0489, 0xE03C) },
  121. { } /* Terminating entry */
  122. };
  123. MODULE_DEVICE_TABLE(usb, ath3k_table);
  124. #define BTUSB_ATH3012 0x80
  125. /* This table is to load patch and sysconfig files
  126. * for AR3012
  127. */
  128. static const struct usb_device_id ath3k_blist_tbl[] = {
  129. /* Atheros AR3012 with sflash firmware*/
  130. { USB_DEVICE(0x0489, 0xe04e), .driver_info = BTUSB_ATH3012 },
  131. { USB_DEVICE(0x0489, 0xe04d), .driver_info = BTUSB_ATH3012 },
  132. { USB_DEVICE(0x0489, 0xe056), .driver_info = BTUSB_ATH3012 },
  133. { USB_DEVICE(0x0489, 0xe057), .driver_info = BTUSB_ATH3012 },
  134. { USB_DEVICE(0x0489, 0xe05f), .driver_info = BTUSB_ATH3012 },
  135. { USB_DEVICE(0x0489, 0xe076), .driver_info = BTUSB_ATH3012 },
  136. { USB_DEVICE(0x0489, 0xe078), .driver_info = BTUSB_ATH3012 },
  137. { USB_DEVICE(0x0489, 0xe095), .driver_info = BTUSB_ATH3012 },
  138. { USB_DEVICE(0x04c5, 0x1330), .driver_info = BTUSB_ATH3012 },
  139. { USB_DEVICE(0x04ca, 0x3004), .driver_info = BTUSB_ATH3012 },
  140. { USB_DEVICE(0x04ca, 0x3005), .driver_info = BTUSB_ATH3012 },
  141. { USB_DEVICE(0x04ca, 0x3006), .driver_info = BTUSB_ATH3012 },
  142. { USB_DEVICE(0x04ca, 0x3007), .driver_info = BTUSB_ATH3012 },
  143. { USB_DEVICE(0x04ca, 0x3008), .driver_info = BTUSB_ATH3012 },
  144. { USB_DEVICE(0x04ca, 0x300b), .driver_info = BTUSB_ATH3012 },
  145. { USB_DEVICE(0x04ca, 0x300d), .driver_info = BTUSB_ATH3012 },
  146. { USB_DEVICE(0x04ca, 0x300f), .driver_info = BTUSB_ATH3012 },
  147. { USB_DEVICE(0x04ca, 0x3010), .driver_info = BTUSB_ATH3012 },
  148. { USB_DEVICE(0x04ca, 0x3014), .driver_info = BTUSB_ATH3012 },
  149. { USB_DEVICE(0x04ca, 0x3018), .driver_info = BTUSB_ATH3012 },
  150. { USB_DEVICE(0x0930, 0x0219), .driver_info = BTUSB_ATH3012 },
  151. { USB_DEVICE(0x0930, 0x021c), .driver_info = BTUSB_ATH3012 },
  152. { USB_DEVICE(0x0930, 0x0220), .driver_info = BTUSB_ATH3012 },
  153. { USB_DEVICE(0x0930, 0x0227), .driver_info = BTUSB_ATH3012 },
  154. { USB_DEVICE(0x0b05, 0x17d0), .driver_info = BTUSB_ATH3012 },
  155. { USB_DEVICE(0x0CF3, 0x0036), .driver_info = BTUSB_ATH3012 },
  156. { USB_DEVICE(0x0cf3, 0x3004), .driver_info = BTUSB_ATH3012 },
  157. { USB_DEVICE(0x0cf3, 0x3008), .driver_info = BTUSB_ATH3012 },
  158. { USB_DEVICE(0x0cf3, 0x311D), .driver_info = BTUSB_ATH3012 },
  159. { USB_DEVICE(0x0cf3, 0x311E), .driver_info = BTUSB_ATH3012 },
  160. { USB_DEVICE(0x0cf3, 0x311F), .driver_info = BTUSB_ATH3012 },
  161. { USB_DEVICE(0x0cf3, 0x3121), .driver_info = BTUSB_ATH3012 },
  162. { USB_DEVICE(0x0CF3, 0x817a), .driver_info = BTUSB_ATH3012 },
  163. { USB_DEVICE(0x0CF3, 0x817b), .driver_info = BTUSB_ATH3012 },
  164. { USB_DEVICE(0x0cf3, 0xe004), .driver_info = BTUSB_ATH3012 },
  165. { USB_DEVICE(0x0cf3, 0xe005), .driver_info = BTUSB_ATH3012 },
  166. { USB_DEVICE(0x0cf3, 0xe006), .driver_info = BTUSB_ATH3012 },
  167. { USB_DEVICE(0x0cf3, 0xe003), .driver_info = BTUSB_ATH3012 },
  168. { USB_DEVICE(0x13d3, 0x3362), .driver_info = BTUSB_ATH3012 },
  169. { USB_DEVICE(0x13d3, 0x3375), .driver_info = BTUSB_ATH3012 },
  170. { USB_DEVICE(0x13d3, 0x3393), .driver_info = BTUSB_ATH3012 },
  171. { USB_DEVICE(0x13d3, 0x3395), .driver_info = BTUSB_ATH3012 },
  172. { USB_DEVICE(0x13d3, 0x3402), .driver_info = BTUSB_ATH3012 },
  173. { USB_DEVICE(0x13d3, 0x3408), .driver_info = BTUSB_ATH3012 },
  174. { USB_DEVICE(0x13d3, 0x3423), .driver_info = BTUSB_ATH3012 },
  175. { USB_DEVICE(0x13d3, 0x3432), .driver_info = BTUSB_ATH3012 },
  176. { USB_DEVICE(0x13d3, 0x3472), .driver_info = BTUSB_ATH3012 },
  177. { USB_DEVICE(0x13d3, 0x3474), .driver_info = BTUSB_ATH3012 },
  178. { USB_DEVICE(0x13d3, 0x3487), .driver_info = BTUSB_ATH3012 },
  179. { USB_DEVICE(0x13d3, 0x3490), .driver_info = BTUSB_ATH3012 },
  180. /* Atheros AR5BBU22 with sflash firmware */
  181. { USB_DEVICE(0x0489, 0xE036), .driver_info = BTUSB_ATH3012 },
  182. { USB_DEVICE(0x0489, 0xE03C), .driver_info = BTUSB_ATH3012 },
  183. { } /* Terminating entry */
  184. };
  185. static inline void ath3k_log_failed_loading(int err, int len, int size)
  186. {
  187. BT_ERR("Error in firmware loading err = %d, len = %d, size = %d",
  188. err, len, size);
  189. }
  190. #define USB_REQ_DFU_DNLOAD 1
  191. #define BULK_SIZE 4096
  192. #define FW_HDR_SIZE 20
  193. #define TIMEGAP_USEC_MIN 50
  194. #define TIMEGAP_USEC_MAX 100
  195. static int ath3k_load_firmware(struct usb_device *udev,
  196. const struct firmware *firmware)
  197. {
  198. u8 *send_buf;
  199. int len = 0;
  200. int err, pipe, size, sent = 0;
  201. int count = firmware->size;
  202. BT_DBG("udev %p", udev);
  203. pipe = usb_sndctrlpipe(udev, 0);
  204. send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
  205. if (!send_buf) {
  206. BT_ERR("Can't allocate memory chunk for firmware");
  207. return -ENOMEM;
  208. }
  209. memcpy(send_buf, firmware->data, FW_HDR_SIZE);
  210. err = usb_control_msg(udev, pipe, USB_REQ_DFU_DNLOAD, USB_TYPE_VENDOR,
  211. 0, 0, send_buf, FW_HDR_SIZE,
  212. USB_CTRL_SET_TIMEOUT);
  213. if (err < 0) {
  214. BT_ERR("Can't change to loading configuration err");
  215. goto error;
  216. }
  217. sent += FW_HDR_SIZE;
  218. count -= FW_HDR_SIZE;
  219. pipe = usb_sndbulkpipe(udev, 0x02);
  220. while (count) {
  221. /* workaround the compatibility issue with xHCI controller*/
  222. usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
  223. size = min_t(uint, count, BULK_SIZE);
  224. memcpy(send_buf, firmware->data + sent, size);
  225. err = usb_bulk_msg(udev, pipe, send_buf, size,
  226. &len, 3000);
  227. if (err || (len != size)) {
  228. ath3k_log_failed_loading(err, len, size);
  229. goto error;
  230. }
  231. sent += size;
  232. count -= size;
  233. }
  234. error:
  235. kfree(send_buf);
  236. return err;
  237. }
  238. static int ath3k_get_state(struct usb_device *udev, unsigned char *state)
  239. {
  240. int ret, pipe = 0;
  241. char *buf;
  242. buf = kmalloc(sizeof(*buf), GFP_KERNEL);
  243. if (!buf)
  244. return -ENOMEM;
  245. pipe = usb_rcvctrlpipe(udev, 0);
  246. ret = usb_control_msg(udev, pipe, ATH3K_GETSTATE,
  247. USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
  248. buf, sizeof(*buf), USB_CTRL_SET_TIMEOUT);
  249. *state = *buf;
  250. kfree(buf);
  251. return ret;
  252. }
  253. static int ath3k_get_version(struct usb_device *udev,
  254. struct ath3k_version *version)
  255. {
  256. int ret, pipe = 0;
  257. struct ath3k_version *buf;
  258. const int size = sizeof(*buf);
  259. buf = kmalloc(size, GFP_KERNEL);
  260. if (!buf)
  261. return -ENOMEM;
  262. pipe = usb_rcvctrlpipe(udev, 0);
  263. ret = usb_control_msg(udev, pipe, ATH3K_GETVERSION,
  264. USB_TYPE_VENDOR | USB_DIR_IN, 0, 0,
  265. buf, size, USB_CTRL_SET_TIMEOUT);
  266. memcpy(version, buf, size);
  267. kfree(buf);
  268. return ret;
  269. }
  270. static int ath3k_load_fwfile(struct usb_device *udev,
  271. const struct firmware *firmware)
  272. {
  273. u8 *send_buf;
  274. int len = 0;
  275. int err, pipe, size, count, sent = 0;
  276. int ret;
  277. count = firmware->size;
  278. send_buf = kmalloc(BULK_SIZE, GFP_KERNEL);
  279. if (!send_buf) {
  280. BT_ERR("Can't allocate memory chunk for firmware");
  281. return -ENOMEM;
  282. }
  283. size = min_t(uint, count, FW_HDR_SIZE);
  284. memcpy(send_buf, firmware->data, size);
  285. pipe = usb_sndctrlpipe(udev, 0);
  286. ret = usb_control_msg(udev, pipe, ATH3K_DNLOAD,
  287. USB_TYPE_VENDOR, 0, 0, send_buf,
  288. size, USB_CTRL_SET_TIMEOUT);
  289. if (ret < 0) {
  290. BT_ERR("Can't change to loading configuration err");
  291. kfree(send_buf);
  292. return ret;
  293. }
  294. sent += size;
  295. count -= size;
  296. pipe = usb_sndbulkpipe(udev, 0x02);
  297. while (count) {
  298. /* workaround the compatibility issue with xHCI controller*/
  299. usleep_range(TIMEGAP_USEC_MIN, TIMEGAP_USEC_MAX);
  300. size = min_t(uint, count, BULK_SIZE);
  301. memcpy(send_buf, firmware->data + sent, size);
  302. err = usb_bulk_msg(udev, pipe, send_buf, size,
  303. &len, 3000);
  304. if (err || (len != size)) {
  305. ath3k_log_failed_loading(err, len, size);
  306. kfree(send_buf);
  307. return err;
  308. }
  309. sent += size;
  310. count -= size;
  311. }
  312. kfree(send_buf);
  313. return 0;
  314. }
  315. static int ath3k_switch_pid(struct usb_device *udev)
  316. {
  317. int pipe = 0;
  318. pipe = usb_sndctrlpipe(udev, 0);
  319. return usb_control_msg(udev, pipe, USB_REG_SWITCH_VID_PID,
  320. USB_TYPE_VENDOR, 0, 0,
  321. NULL, 0, USB_CTRL_SET_TIMEOUT);
  322. }
  323. static int ath3k_set_normal_mode(struct usb_device *udev)
  324. {
  325. unsigned char fw_state;
  326. int pipe = 0, ret;
  327. ret = ath3k_get_state(udev, &fw_state);
  328. if (ret < 0) {
  329. BT_ERR("Can't get state to change to normal mode err");
  330. return ret;
  331. }
  332. if ((fw_state & ATH3K_MODE_MASK) == ATH3K_NORMAL_MODE) {
  333. BT_DBG("firmware was already in normal mode");
  334. return 0;
  335. }
  336. pipe = usb_sndctrlpipe(udev, 0);
  337. return usb_control_msg(udev, pipe, ATH3K_SET_NORMAL_MODE,
  338. USB_TYPE_VENDOR, 0, 0,
  339. NULL, 0, USB_CTRL_SET_TIMEOUT);
  340. }
  341. static int ath3k_load_patch(struct usb_device *udev)
  342. {
  343. unsigned char fw_state;
  344. char filename[ATH3K_NAME_LEN];
  345. const struct firmware *firmware;
  346. struct ath3k_version fw_version;
  347. __u32 pt_rom_version, pt_build_version;
  348. int ret;
  349. ret = ath3k_get_state(udev, &fw_state);
  350. if (ret < 0) {
  351. BT_ERR("Can't get state to change to load ram patch err");
  352. return ret;
  353. }
  354. if (fw_state & ATH3K_PATCH_UPDATE) {
  355. BT_DBG("Patch was already downloaded");
  356. return 0;
  357. }
  358. ret = ath3k_get_version(udev, &fw_version);
  359. if (ret < 0) {
  360. BT_ERR("Can't get version to change to load ram patch err");
  361. return ret;
  362. }
  363. snprintf(filename, ATH3K_NAME_LEN, "ar3k/AthrBT_0x%08x.dfu",
  364. le32_to_cpu(fw_version.rom_version));
  365. ret = request_firmware(&firmware, filename, &udev->dev);
  366. if (ret)
  367. return ret;
  368. pt_rom_version = get_unaligned_le32(firmware->data +
  369. firmware->size - 8);
  370. pt_build_version = get_unaligned_le32(firmware->data +
  371. firmware->size - 4);
  372. if (pt_rom_version != le32_to_cpu(fw_version.rom_version) ||
  373. pt_build_version <= le32_to_cpu(fw_version.build_version)) {
  374. BT_ERR("Patch file version did not match with firmware");
  375. release_firmware(firmware);
  376. return -EINVAL;
  377. }
  378. ret = ath3k_load_fwfile(udev, firmware);
  379. release_firmware(firmware);
  380. return ret;
  381. }
  382. static int ath3k_load_syscfg(struct usb_device *udev)
  383. {
  384. unsigned char fw_state;
  385. char filename[ATH3K_NAME_LEN];
  386. const struct firmware *firmware;
  387. struct ath3k_version fw_version;
  388. int clk_value, ret;
  389. ret = ath3k_get_state(udev, &fw_state);
  390. if (ret < 0) {
  391. BT_ERR("Can't get state to change to load configuration err");
  392. return -EBUSY;
  393. }
  394. ret = ath3k_get_version(udev, &fw_version);
  395. if (ret < 0) {
  396. BT_ERR("Can't get version to change to load ram patch err");
  397. return ret;
  398. }
  399. switch (fw_version.ref_clock) {
  400. case ATH3K_XTAL_FREQ_26M:
  401. clk_value = 26;
  402. break;
  403. case ATH3K_XTAL_FREQ_40M:
  404. clk_value = 40;
  405. break;
  406. case ATH3K_XTAL_FREQ_19P2:
  407. clk_value = 19;
  408. break;
  409. default:
  410. clk_value = 0;
  411. break;
  412. }
  413. snprintf(filename, ATH3K_NAME_LEN, "ar3k/ramps_0x%08x_%d%s",
  414. le32_to_cpu(fw_version.rom_version), clk_value, ".dfu");
  415. ret = request_firmware(&firmware, filename, &udev->dev);
  416. if (ret)
  417. return ret;
  418. ret = ath3k_load_fwfile(udev, firmware);
  419. release_firmware(firmware);
  420. return ret;
  421. }
  422. static int ath3k_probe(struct usb_interface *intf,
  423. const struct usb_device_id *id)
  424. {
  425. const struct firmware *firmware;
  426. struct usb_device *udev = interface_to_usbdev(intf);
  427. int ret;
  428. BT_DBG("intf %p id %p", intf, id);
  429. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  430. return -ENODEV;
  431. /* match device ID in ath3k blacklist table */
  432. if (!id->driver_info) {
  433. const struct usb_device_id *match;
  434. match = usb_match_id(intf, ath3k_blist_tbl);
  435. if (match)
  436. id = match;
  437. }
  438. /* load patch and sysconfig files for AR3012 */
  439. if (id->driver_info & BTUSB_ATH3012) {
  440. /* New firmware with patch and sysconfig files already loaded */
  441. if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x0001)
  442. return -ENODEV;
  443. ret = ath3k_load_patch(udev);
  444. if (ret < 0) {
  445. BT_ERR("Loading patch file failed");
  446. return ret;
  447. }
  448. ret = ath3k_load_syscfg(udev);
  449. if (ret < 0) {
  450. BT_ERR("Loading sysconfig file failed");
  451. return ret;
  452. }
  453. ret = ath3k_set_normal_mode(udev);
  454. if (ret < 0) {
  455. BT_ERR("Set normal mode failed");
  456. return ret;
  457. }
  458. ath3k_switch_pid(udev);
  459. return 0;
  460. }
  461. ret = request_firmware(&firmware, ATH3K_FIRMWARE, &udev->dev);
  462. if (ret < 0) {
  463. if (ret == -ENOENT)
  464. BT_ERR("Firmware file \"%s\" not found",
  465. ATH3K_FIRMWARE);
  466. else
  467. BT_ERR("Firmware file \"%s\" request failed (err=%d)",
  468. ATH3K_FIRMWARE, ret);
  469. return ret;
  470. }
  471. ret = ath3k_load_firmware(udev, firmware);
  472. release_firmware(firmware);
  473. return ret;
  474. }
  475. static void ath3k_disconnect(struct usb_interface *intf)
  476. {
  477. BT_DBG("%s intf %p", __func__, intf);
  478. }
  479. static struct usb_driver ath3k_driver = {
  480. .name = "ath3k",
  481. .probe = ath3k_probe,
  482. .disconnect = ath3k_disconnect,
  483. .id_table = ath3k_table,
  484. .disable_hub_initiated_lpm = 1,
  485. };
  486. module_usb_driver(ath3k_driver);
  487. MODULE_AUTHOR("Atheros Communications");
  488. MODULE_DESCRIPTION("Atheros AR30xx firmware driver");
  489. MODULE_VERSION(VERSION);
  490. MODULE_LICENSE("GPL");
  491. MODULE_FIRMWARE(ATH3K_FIRMWARE);