main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * iwmc3200top - Intel Wireless MultiCom 3200 Top Driver
  3. * drivers/misc/iwmc3200top/main.c
  4. *
  5. * Copyright (C) 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19. * 02110-1301, USA.
  20. *
  21. *
  22. * Author Name: Maxim Grabarnik <maxim.grabarnink@intel.com>
  23. * -
  24. *
  25. */
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/debugfs.h>
  30. #include <linux/mmc/sdio_ids.h>
  31. #include <linux/mmc/sdio_func.h>
  32. #include <linux/mmc/sdio.h>
  33. #include "iwmc3200top.h"
  34. #include "log.h"
  35. #include "fw-msg.h"
  36. #include "debugfs.h"
  37. #define DRIVER_DESCRIPTION "Intel(R) IWMC 3200 Top Driver"
  38. #define DRIVER_COPYRIGHT "Copyright (c) 2008 Intel Corporation."
  39. #define IWMCT_VERSION "0.1.62"
  40. #ifdef REPOSITORY_LABEL
  41. #define RL REPOSITORY_LABEL
  42. #else
  43. #define RL local
  44. #endif
  45. #ifdef CONFIG_IWMC3200TOP_DEBUG
  46. #define VD "-d"
  47. #else
  48. #define VD
  49. #endif
  50. #define DRIVER_VERSION IWMCT_VERSION "-" __stringify(RL) VD
  51. MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
  52. MODULE_VERSION(DRIVER_VERSION);
  53. MODULE_LICENSE("GPL");
  54. MODULE_AUTHOR(DRIVER_COPYRIGHT);
  55. /*
  56. * This workers main task is to wait for OP_OPR_ALIVE
  57. * from TOP FW until ALIVE_MSG_TIMOUT timeout is elapsed.
  58. * When OP_OPR_ALIVE received it will issue
  59. * a call to "bus_rescan_devices".
  60. */
  61. static void iwmct_rescan_worker(struct work_struct *ws)
  62. {
  63. struct iwmct_priv *priv;
  64. int ret;
  65. priv = container_of(ws, struct iwmct_priv, bus_rescan_worker);
  66. LOG_INFO(priv, FW_MSG, "Calling bus_rescan\n");
  67. ret = bus_rescan_devices(priv->func->dev.bus);
  68. if (ret < 0)
  69. LOG_INFO(priv, FW_DOWNLOAD, "bus_rescan_devices FAILED!!!\n");
  70. }
  71. static void op_top_message(struct iwmct_priv *priv, struct top_msg *msg)
  72. {
  73. switch (msg->hdr.opcode) {
  74. case OP_OPR_ALIVE:
  75. LOG_INFO(priv, FW_MSG, "Got ALIVE from device, wake rescan\n");
  76. queue_work(priv->bus_rescan_wq, &priv->bus_rescan_worker);
  77. break;
  78. default:
  79. LOG_INFO(priv, FW_MSG, "Received msg opcode 0x%X\n",
  80. msg->hdr.opcode);
  81. break;
  82. }
  83. }
  84. static void handle_top_message(struct iwmct_priv *priv, u8 *buf, int len)
  85. {
  86. struct top_msg *msg;
  87. msg = (struct top_msg *)buf;
  88. if (msg->hdr.type != COMM_TYPE_D2H) {
  89. LOG_ERROR(priv, FW_MSG,
  90. "Message from TOP with invalid message type 0x%X\n",
  91. msg->hdr.type);
  92. return;
  93. }
  94. if (len < sizeof(msg->hdr)) {
  95. LOG_ERROR(priv, FW_MSG,
  96. "Message from TOP is too short for message header "
  97. "received %d bytes, expected at least %zd bytes\n",
  98. len, sizeof(msg->hdr));
  99. return;
  100. }
  101. if (len < le16_to_cpu(msg->hdr.length) + sizeof(msg->hdr)) {
  102. LOG_ERROR(priv, FW_MSG,
  103. "Message length (%d bytes) is shorter than "
  104. "in header (%d bytes)\n",
  105. len, le16_to_cpu(msg->hdr.length));
  106. return;
  107. }
  108. switch (msg->hdr.category) {
  109. case COMM_CATEGORY_OPERATIONAL:
  110. op_top_message(priv, (struct top_msg *)buf);
  111. break;
  112. case COMM_CATEGORY_DEBUG:
  113. case COMM_CATEGORY_TESTABILITY:
  114. case COMM_CATEGORY_DIAGNOSTICS:
  115. iwmct_log_top_message(priv, buf, len);
  116. break;
  117. default:
  118. LOG_ERROR(priv, FW_MSG,
  119. "Message from TOP with unknown category 0x%X\n",
  120. msg->hdr.category);
  121. break;
  122. }
  123. }
  124. int iwmct_send_hcmd(struct iwmct_priv *priv, u8 *cmd, u16 len)
  125. {
  126. int ret;
  127. u8 *buf;
  128. LOG_INFOEX(priv, FW_MSG, "Sending hcmd:\n");
  129. /* add padding to 256 for IWMC */
  130. ((struct top_msg *)cmd)->hdr.flags |= CMD_FLAG_PADDING_256;
  131. LOG_HEXDUMP(FW_MSG, cmd, len);
  132. if (len > FW_HCMD_BLOCK_SIZE) {
  133. LOG_ERROR(priv, FW_MSG, "size %d exceeded hcmd max size %d\n",
  134. len, FW_HCMD_BLOCK_SIZE);
  135. return -1;
  136. }
  137. buf = kzalloc(FW_HCMD_BLOCK_SIZE, GFP_KERNEL);
  138. if (!buf) {
  139. LOG_ERROR(priv, FW_MSG, "kzalloc error, buf size %d\n",
  140. FW_HCMD_BLOCK_SIZE);
  141. return -1;
  142. }
  143. memcpy(buf, cmd, len);
  144. sdio_claim_host(priv->func);
  145. ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR, buf,
  146. FW_HCMD_BLOCK_SIZE);
  147. sdio_release_host(priv->func);
  148. kfree(buf);
  149. return ret;
  150. }
  151. int iwmct_tx(struct iwmct_priv *priv, unsigned int addr,
  152. void *src, int count)
  153. {
  154. int ret;
  155. sdio_claim_host(priv->func);
  156. ret = sdio_memcpy_toio(priv->func, addr, src, count);
  157. sdio_release_host(priv->func);
  158. return ret;
  159. }
  160. static void iwmct_irq_read_worker(struct work_struct *ws)
  161. {
  162. struct iwmct_priv *priv;
  163. struct iwmct_work_struct *read_req;
  164. __le32 *buf = NULL;
  165. int ret;
  166. int iosize;
  167. u32 barker;
  168. bool is_barker;
  169. priv = container_of(ws, struct iwmct_priv, isr_worker);
  170. LOG_INFO(priv, IRQ, "enter iwmct_irq_read_worker %p\n", ws);
  171. /* --------------------- Handshake with device -------------------- */
  172. sdio_claim_host(priv->func);
  173. /* all list manipulations have to be protected by
  174. * sdio_claim_host/sdio_release_host */
  175. if (list_empty(&priv->read_req_list)) {
  176. LOG_ERROR(priv, IRQ, "read_req_list empty in read worker\n");
  177. goto exit_release;
  178. }
  179. read_req = list_entry(priv->read_req_list.next,
  180. struct iwmct_work_struct, list);
  181. list_del(&read_req->list);
  182. iosize = read_req->iosize;
  183. kfree(read_req);
  184. buf = kzalloc(iosize, GFP_KERNEL);
  185. if (!buf) {
  186. LOG_ERROR(priv, IRQ, "kzalloc error, buf size %d\n", iosize);
  187. goto exit_release;
  188. }
  189. LOG_INFO(priv, IRQ, "iosize=%d, buf=%p, func=%d\n",
  190. iosize, buf, priv->func->num);
  191. /* read from device */
  192. ret = sdio_memcpy_fromio(priv->func, buf, IWMC_SDIO_DATA_ADDR, iosize);
  193. if (ret) {
  194. LOG_ERROR(priv, IRQ, "error %d reading buffer\n", ret);
  195. goto exit_release;
  196. }
  197. LOG_HEXDUMP(IRQ, (u8 *)buf, iosize);
  198. barker = le32_to_cpu(buf[0]);
  199. /* Verify whether it's a barker and if not - treat as regular Rx */
  200. if (barker == IWMC_BARKER_ACK ||
  201. (barker & BARKER_DNLOAD_BARKER_MSK) == IWMC_BARKER_REBOOT) {
  202. /* Valid Barker is equal on first 4 dwords */
  203. is_barker = (buf[1] == buf[0]) &&
  204. (buf[2] == buf[0]) &&
  205. (buf[3] == buf[0]);
  206. if (!is_barker) {
  207. LOG_WARNING(priv, IRQ,
  208. "Potentially inconsistent barker "
  209. "%08X_%08X_%08X_%08X\n",
  210. le32_to_cpu(buf[0]), le32_to_cpu(buf[1]),
  211. le32_to_cpu(buf[2]), le32_to_cpu(buf[3]));
  212. }
  213. } else {
  214. is_barker = false;
  215. }
  216. /* Handle Top CommHub message */
  217. if (!is_barker) {
  218. sdio_release_host(priv->func);
  219. handle_top_message(priv, (u8 *)buf, iosize);
  220. goto exit;
  221. } else if (barker == IWMC_BARKER_ACK) { /* Handle barkers */
  222. if (atomic_read(&priv->dev_sync) == 0) {
  223. LOG_ERROR(priv, IRQ,
  224. "ACK barker arrived out-of-sync\n");
  225. goto exit_release;
  226. }
  227. /* Continuing to FW download (after Sync is completed)*/
  228. atomic_set(&priv->dev_sync, 0);
  229. LOG_INFO(priv, IRQ, "ACK barker arrived "
  230. "- starting FW download\n");
  231. } else { /* REBOOT barker */
  232. LOG_INFO(priv, IRQ, "Recieved reboot barker: %x\n", barker);
  233. priv->barker = barker;
  234. if (barker & BARKER_DNLOAD_SYNC_MSK) {
  235. /* Send the same barker back */
  236. ret = sdio_memcpy_toio(priv->func, IWMC_SDIO_DATA_ADDR,
  237. buf, iosize);
  238. if (ret) {
  239. LOG_ERROR(priv, IRQ,
  240. "error %d echoing barker\n", ret);
  241. goto exit_release;
  242. }
  243. LOG_INFO(priv, IRQ, "Echoing barker to device\n");
  244. atomic_set(&priv->dev_sync, 1);
  245. goto exit_release;
  246. }
  247. /* Continuing to FW download (without Sync) */
  248. LOG_INFO(priv, IRQ, "No sync requested "
  249. "- starting FW download\n");
  250. }
  251. sdio_release_host(priv->func);
  252. LOG_INFO(priv, IRQ, "barker download request 0x%x is:\n", priv->barker);
  253. LOG_INFO(priv, IRQ, "******* Top FW %s requested ********\n",
  254. (priv->barker & BARKER_DNLOAD_TOP_MSK) ? "was" : "not");
  255. LOG_INFO(priv, IRQ, "******* GPS FW %s requested ********\n",
  256. (priv->barker & BARKER_DNLOAD_GPS_MSK) ? "was" : "not");
  257. LOG_INFO(priv, IRQ, "******* BT FW %s requested ********\n",
  258. (priv->barker & BARKER_DNLOAD_BT_MSK) ? "was" : "not");
  259. if (priv->dbg.fw_download)
  260. iwmct_fw_load(priv);
  261. else
  262. LOG_ERROR(priv, IRQ, "FW download not allowed\n");
  263. goto exit;
  264. exit_release:
  265. sdio_release_host(priv->func);
  266. exit:
  267. kfree(buf);
  268. LOG_INFO(priv, IRQ, "exit iwmct_irq_read_worker\n");
  269. }
  270. static void iwmct_irq(struct sdio_func *func)
  271. {
  272. struct iwmct_priv *priv;
  273. int val, ret;
  274. int iosize;
  275. int addr = IWMC_SDIO_INTR_GET_SIZE_ADDR;
  276. struct iwmct_work_struct *read_req;
  277. priv = sdio_get_drvdata(func);
  278. LOG_INFO(priv, IRQ, "enter iwmct_irq\n");
  279. /* read the function's status register */
  280. val = sdio_readb(func, IWMC_SDIO_INTR_STATUS_ADDR, &ret);
  281. LOG_INFO(priv, IRQ, "iir value = %d, ret=%d\n", val, ret);
  282. if (!val) {
  283. LOG_ERROR(priv, IRQ, "iir = 0, exiting ISR\n");
  284. goto exit_clear_intr;
  285. }
  286. /*
  287. * read 2 bytes of the transaction size
  288. * IMPORTANT: sdio transaction size has to be read before clearing
  289. * sdio interrupt!!!
  290. */
  291. val = sdio_readb(priv->func, addr++, &ret);
  292. iosize = val;
  293. val = sdio_readb(priv->func, addr++, &ret);
  294. iosize += val << 8;
  295. LOG_INFO(priv, IRQ, "READ size %d\n", iosize);
  296. if (iosize == 0) {
  297. LOG_ERROR(priv, IRQ, "READ size %d, exiting ISR\n", iosize);
  298. goto exit_clear_intr;
  299. }
  300. /* allocate a work structure to pass iosize to the worker */
  301. read_req = kzalloc(sizeof(struct iwmct_work_struct), GFP_KERNEL);
  302. if (!read_req) {
  303. LOG_ERROR(priv, IRQ, "failed to allocate read_req, exit ISR\n");
  304. goto exit_clear_intr;
  305. }
  306. INIT_LIST_HEAD(&read_req->list);
  307. read_req->iosize = iosize;
  308. list_add_tail(&priv->read_req_list, &read_req->list);
  309. /* clear the function's interrupt request bit (write 1 to clear) */
  310. sdio_writeb(func, 1, IWMC_SDIO_INTR_CLEAR_ADDR, &ret);
  311. queue_work(priv->wq, &priv->isr_worker);
  312. LOG_INFO(priv, IRQ, "exit iwmct_irq\n");
  313. return;
  314. exit_clear_intr:
  315. /* clear the function's interrupt request bit (write 1 to clear) */
  316. sdio_writeb(func, 1, IWMC_SDIO_INTR_CLEAR_ADDR, &ret);
  317. }
  318. static int blocks;
  319. module_param(blocks, int, 0604);
  320. MODULE_PARM_DESC(blocks, "max_blocks_to_send");
  321. static int dump;
  322. module_param(dump, bool, 0604);
  323. MODULE_PARM_DESC(dump, "dump_hex_content");
  324. static int jump = 1;
  325. module_param(jump, bool, 0604);
  326. static int direct = 1;
  327. module_param(direct, bool, 0604);
  328. static int checksum = 1;
  329. module_param(checksum, bool, 0604);
  330. static int fw_download = 1;
  331. module_param(fw_download, bool, 0604);
  332. static int block_size = IWMC_SDIO_BLK_SIZE;
  333. module_param(block_size, int, 0404);
  334. static int download_trans_blks = IWMC_DEFAULT_TR_BLK;
  335. module_param(download_trans_blks, int, 0604);
  336. static int rubbish_barker;
  337. module_param(rubbish_barker, bool, 0604);
  338. #ifdef CONFIG_IWMC3200TOP_DEBUG
  339. static int log_level[LOG_SRC_MAX];
  340. static unsigned int log_level_argc;
  341. module_param_array(log_level, int, &log_level_argc, 0604);
  342. MODULE_PARM_DESC(log_level, "log_level");
  343. static int log_level_fw[FW_LOG_SRC_MAX];
  344. static unsigned int log_level_fw_argc;
  345. module_param_array(log_level_fw, int, &log_level_fw_argc, 0604);
  346. MODULE_PARM_DESC(log_level_fw, "log_level_fw");
  347. #endif
  348. void iwmct_dbg_init_params(struct iwmct_priv *priv)
  349. {
  350. #ifdef CONFIG_IWMC3200TOP_DEBUG
  351. int i;
  352. for (i = 0; i < log_level_argc; i++) {
  353. dev_notice(&priv->func->dev, "log_level[%d]=0x%X\n",
  354. i, log_level[i]);
  355. iwmct_log_set_filter((log_level[i] >> 8) & 0xFF,
  356. log_level[i] & 0xFF);
  357. }
  358. for (i = 0; i < log_level_fw_argc; i++) {
  359. dev_notice(&priv->func->dev, "log_level_fw[%d]=0x%X\n",
  360. i, log_level_fw[i]);
  361. iwmct_log_set_fw_filter((log_level_fw[i] >> 8) & 0xFF,
  362. log_level_fw[i] & 0xFF);
  363. }
  364. #endif
  365. priv->dbg.blocks = blocks;
  366. LOG_INFO(priv, INIT, "blocks=%d\n", blocks);
  367. priv->dbg.dump = (bool)dump;
  368. LOG_INFO(priv, INIT, "dump=%d\n", dump);
  369. priv->dbg.jump = (bool)jump;
  370. LOG_INFO(priv, INIT, "jump=%d\n", jump);
  371. priv->dbg.direct = (bool)direct;
  372. LOG_INFO(priv, INIT, "direct=%d\n", direct);
  373. priv->dbg.checksum = (bool)checksum;
  374. LOG_INFO(priv, INIT, "checksum=%d\n", checksum);
  375. priv->dbg.fw_download = (bool)fw_download;
  376. LOG_INFO(priv, INIT, "fw_download=%d\n", fw_download);
  377. priv->dbg.block_size = block_size;
  378. LOG_INFO(priv, INIT, "block_size=%d\n", block_size);
  379. priv->dbg.download_trans_blks = download_trans_blks;
  380. LOG_INFO(priv, INIT, "download_trans_blks=%d\n", download_trans_blks);
  381. }
  382. /*****************************************************************************
  383. *
  384. * sysfs attributes
  385. *
  386. *****************************************************************************/
  387. static ssize_t show_iwmct_fw_version(struct device *d,
  388. struct device_attribute *attr, char *buf)
  389. {
  390. struct iwmct_priv *priv = dev_get_drvdata(d);
  391. return sprintf(buf, "%s\n", priv->dbg.label_fw);
  392. }
  393. static DEVICE_ATTR(cc_label_fw, S_IRUGO, show_iwmct_fw_version, NULL);
  394. #ifdef CONFIG_IWMC3200TOP_DEBUG
  395. static DEVICE_ATTR(log_level, S_IWUSR | S_IRUGO,
  396. show_iwmct_log_level, store_iwmct_log_level);
  397. static DEVICE_ATTR(log_level_fw, S_IWUSR | S_IRUGO,
  398. show_iwmct_log_level_fw, store_iwmct_log_level_fw);
  399. #endif
  400. static struct attribute *iwmct_sysfs_entries[] = {
  401. &dev_attr_cc_label_fw.attr,
  402. #ifdef CONFIG_IWMC3200TOP_DEBUG
  403. &dev_attr_log_level.attr,
  404. &dev_attr_log_level_fw.attr,
  405. #endif
  406. NULL
  407. };
  408. static struct attribute_group iwmct_attribute_group = {
  409. .name = NULL, /* put in device directory */
  410. .attrs = iwmct_sysfs_entries,
  411. };
  412. static int iwmct_probe(struct sdio_func *func,
  413. const struct sdio_device_id *id)
  414. {
  415. struct iwmct_priv *priv;
  416. int ret;
  417. int val = 1;
  418. int addr = IWMC_SDIO_INTR_ENABLE_ADDR;
  419. dev_dbg(&func->dev, "enter iwmct_probe\n");
  420. dev_dbg(&func->dev, "IRQ polling period id %u msecs, HZ is %d\n",
  421. jiffies_to_msecs(2147483647), HZ);
  422. priv = kzalloc(sizeof(struct iwmct_priv), GFP_KERNEL);
  423. if (!priv) {
  424. dev_err(&func->dev, "kzalloc error\n");
  425. return -ENOMEM;
  426. }
  427. priv->func = func;
  428. sdio_set_drvdata(func, priv);
  429. /* create drivers work queue */
  430. priv->wq = create_workqueue(DRV_NAME "_wq");
  431. priv->bus_rescan_wq = create_workqueue(DRV_NAME "_rescan_wq");
  432. INIT_WORK(&priv->bus_rescan_worker, iwmct_rescan_worker);
  433. INIT_WORK(&priv->isr_worker, iwmct_irq_read_worker);
  434. init_waitqueue_head(&priv->wait_q);
  435. sdio_claim_host(func);
  436. /* FIXME: Remove after it is fixed in the Boot ROM upgrade */
  437. func->enable_timeout = 10;
  438. /* In our HW, setting the block size also wakes up the boot rom. */
  439. ret = sdio_set_block_size(func, priv->dbg.block_size);
  440. if (ret) {
  441. LOG_ERROR(priv, INIT,
  442. "sdio_set_block_size() failure: %d\n", ret);
  443. goto error_sdio_enable;
  444. }
  445. ret = sdio_enable_func(func);
  446. if (ret) {
  447. LOG_ERROR(priv, INIT, "sdio_enable_func() failure: %d\n", ret);
  448. goto error_sdio_enable;
  449. }
  450. /* init reset and dev_sync states */
  451. atomic_set(&priv->reset, 0);
  452. atomic_set(&priv->dev_sync, 0);
  453. /* init read req queue */
  454. INIT_LIST_HEAD(&priv->read_req_list);
  455. /* process configurable parameters */
  456. iwmct_dbg_init_params(priv);
  457. ret = sysfs_create_group(&func->dev.kobj, &iwmct_attribute_group);
  458. if (ret) {
  459. LOG_ERROR(priv, INIT, "Failed to register attributes and "
  460. "initialize module_params\n");
  461. goto error_dev_attrs;
  462. }
  463. iwmct_dbgfs_register(priv, DRV_NAME);
  464. if (!priv->dbg.direct && priv->dbg.download_trans_blks > 8) {
  465. LOG_INFO(priv, INIT,
  466. "Reducing transaction to 8 blocks = 2K (from %d)\n",
  467. priv->dbg.download_trans_blks);
  468. priv->dbg.download_trans_blks = 8;
  469. }
  470. priv->trans_len = priv->dbg.download_trans_blks * priv->dbg.block_size;
  471. LOG_INFO(priv, INIT, "Transaction length = %d\n", priv->trans_len);
  472. ret = sdio_claim_irq(func, iwmct_irq);
  473. if (ret) {
  474. LOG_ERROR(priv, INIT, "sdio_claim_irq() failure: %d\n", ret);
  475. goto error_claim_irq;
  476. }
  477. /* Enable function's interrupt */
  478. sdio_writeb(priv->func, val, addr, &ret);
  479. if (ret) {
  480. LOG_ERROR(priv, INIT, "Failure writing to "
  481. "Interrupt Enable Register (%d): %d\n", addr, ret);
  482. goto error_enable_int;
  483. }
  484. sdio_release_host(func);
  485. LOG_INFO(priv, INIT, "exit iwmct_probe\n");
  486. return ret;
  487. error_enable_int:
  488. sdio_release_irq(func);
  489. error_claim_irq:
  490. sdio_disable_func(func);
  491. error_dev_attrs:
  492. iwmct_dbgfs_unregister(priv->dbgfs);
  493. sysfs_remove_group(&func->dev.kobj, &iwmct_attribute_group);
  494. error_sdio_enable:
  495. sdio_release_host(func);
  496. return ret;
  497. }
  498. static void iwmct_remove(struct sdio_func *func)
  499. {
  500. struct iwmct_work_struct *read_req;
  501. struct iwmct_priv *priv = sdio_get_drvdata(func);
  502. priv = sdio_get_drvdata(func);
  503. LOG_INFO(priv, INIT, "enter\n");
  504. sdio_claim_host(func);
  505. sdio_release_irq(func);
  506. sdio_release_host(func);
  507. /* Safely destroy osc workqueue */
  508. destroy_workqueue(priv->bus_rescan_wq);
  509. destroy_workqueue(priv->wq);
  510. sdio_claim_host(func);
  511. sdio_disable_func(func);
  512. sysfs_remove_group(&func->dev.kobj, &iwmct_attribute_group);
  513. iwmct_dbgfs_unregister(priv->dbgfs);
  514. sdio_release_host(func);
  515. /* free read requests */
  516. while (!list_empty(&priv->read_req_list)) {
  517. read_req = list_entry(priv->read_req_list.next,
  518. struct iwmct_work_struct, list);
  519. list_del(&read_req->list);
  520. kfree(read_req);
  521. }
  522. kfree(priv);
  523. }
  524. static const struct sdio_device_id iwmct_ids[] = {
  525. /* Intel Wireless MultiCom 3200 Top Driver */
  526. { SDIO_DEVICE(SDIO_VENDOR_ID_INTEL, 0x1404)},
  527. { }, /* Terminating entry */
  528. };
  529. MODULE_DEVICE_TABLE(sdio, iwmct_ids);
  530. static struct sdio_driver iwmct_driver = {
  531. .probe = iwmct_probe,
  532. .remove = iwmct_remove,
  533. .name = DRV_NAME,
  534. .id_table = iwmct_ids,
  535. };
  536. static int __init iwmct_init(void)
  537. {
  538. int rc;
  539. /* Default log filter settings */
  540. iwmct_log_set_filter(LOG_SRC_ALL, LOG_SEV_FILTER_RUNTIME);
  541. iwmct_log_set_filter(LOG_SRC_FW_MSG, LOG_SEV_FILTER_ALL);
  542. iwmct_log_set_fw_filter(LOG_SRC_ALL, FW_LOG_SEV_FILTER_RUNTIME);
  543. rc = sdio_register_driver(&iwmct_driver);
  544. return rc;
  545. }
  546. static void __exit iwmct_exit(void)
  547. {
  548. sdio_unregister_driver(&iwmct_driver);
  549. }
  550. module_init(iwmct_init);
  551. module_exit(iwmct_exit);