if_spi.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. /*
  2. * linux/drivers/net/wireless/libertas/if_spi.c
  3. *
  4. * Driver for Marvell SPI WLAN cards.
  5. *
  6. * Copyright 2008 Analog Devices Inc.
  7. *
  8. * Authors:
  9. * Andrey Yurovsky <andrey@cozybit.com>
  10. * Colin McCabe <colin@cozybit.com>
  11. *
  12. * Inspired by if_sdio.c, Copyright 2007-2008 Pierre Ossman
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. */
  19. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  20. #include <linux/hardirq.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/module.h>
  23. #include <linux/firmware.h>
  24. #include <linux/jiffies.h>
  25. #include <linux/list.h>
  26. #include <linux/netdevice.h>
  27. #include <linux/slab.h>
  28. #include <linux/spi/libertas_spi.h>
  29. #include <linux/spi/spi.h>
  30. #include "host.h"
  31. #include "decl.h"
  32. #include "defs.h"
  33. #include "dev.h"
  34. #include "if_spi.h"
  35. struct if_spi_packet {
  36. struct list_head list;
  37. u16 blen;
  38. u8 buffer[0] __attribute__((aligned(4)));
  39. };
  40. struct if_spi_card {
  41. struct spi_device *spi;
  42. struct lbs_private *priv;
  43. struct libertas_spi_platform_data *pdata;
  44. /* The card ID and card revision, as reported by the hardware. */
  45. u16 card_id;
  46. u8 card_rev;
  47. /* The last time that we initiated an SPU operation */
  48. unsigned long prev_xfer_time;
  49. int use_dummy_writes;
  50. unsigned long spu_port_delay;
  51. unsigned long spu_reg_delay;
  52. /* Handles all SPI communication (except for FW load) */
  53. struct workqueue_struct *workqueue;
  54. struct work_struct packet_work;
  55. struct work_struct resume_work;
  56. u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
  57. /* A buffer of incoming packets from libertas core.
  58. * Since we can't sleep in hw_host_to_card, we have to buffer
  59. * them. */
  60. struct list_head cmd_packet_list;
  61. struct list_head data_packet_list;
  62. /* Protects cmd_packet_list and data_packet_list */
  63. spinlock_t buffer_lock;
  64. /* True is card suspended */
  65. u8 suspended;
  66. };
  67. static void free_if_spi_card(struct if_spi_card *card)
  68. {
  69. struct list_head *cursor, *next;
  70. struct if_spi_packet *packet;
  71. list_for_each_safe(cursor, next, &card->cmd_packet_list) {
  72. packet = container_of(cursor, struct if_spi_packet, list);
  73. list_del(&packet->list);
  74. kfree(packet);
  75. }
  76. list_for_each_safe(cursor, next, &card->data_packet_list) {
  77. packet = container_of(cursor, struct if_spi_packet, list);
  78. list_del(&packet->list);
  79. kfree(packet);
  80. }
  81. spi_set_drvdata(card->spi, NULL);
  82. kfree(card);
  83. }
  84. #define MODEL_8385 0x04
  85. #define MODEL_8686 0x0b
  86. #define MODEL_8688 0x10
  87. static const struct lbs_fw_table fw_table[] = {
  88. { MODEL_8385, "libertas/gspi8385_helper.bin", "libertas/gspi8385.bin" },
  89. { MODEL_8385, "libertas/gspi8385_hlp.bin", "libertas/gspi8385.bin" },
  90. { MODEL_8686, "libertas/gspi8686_v9_helper.bin", "libertas/gspi8686_v9.bin" },
  91. { MODEL_8686, "libertas/gspi8686_hlp.bin", "libertas/gspi8686.bin" },
  92. { MODEL_8688, "libertas/gspi8688_helper.bin", "libertas/gspi8688.bin" },
  93. { 0, NULL, NULL }
  94. };
  95. MODULE_FIRMWARE("libertas/gspi8385_helper.bin");
  96. MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
  97. MODULE_FIRMWARE("libertas/gspi8385.bin");
  98. MODULE_FIRMWARE("libertas/gspi8686_v9_helper.bin");
  99. MODULE_FIRMWARE("libertas/gspi8686_v9.bin");
  100. MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
  101. MODULE_FIRMWARE("libertas/gspi8686.bin");
  102. MODULE_FIRMWARE("libertas/gspi8688_helper.bin");
  103. MODULE_FIRMWARE("libertas/gspi8688.bin");
  104. /*
  105. * SPI Interface Unit Routines
  106. *
  107. * The SPU sits between the host and the WLAN module.
  108. * All communication with the firmware is through SPU transactions.
  109. *
  110. * First we have to put a SPU register name on the bus. Then we can
  111. * either read from or write to that register.
  112. *
  113. */
  114. static void spu_transaction_init(struct if_spi_card *card)
  115. {
  116. if (!time_after(jiffies, card->prev_xfer_time + 1)) {
  117. /* Unfortunately, the SPU requires a delay between successive
  118. * transactions. If our last transaction was more than a jiffy
  119. * ago, we have obviously already delayed enough.
  120. * If not, we have to busy-wait to be on the safe side. */
  121. ndelay(400);
  122. }
  123. }
  124. static void spu_transaction_finish(struct if_spi_card *card)
  125. {
  126. card->prev_xfer_time = jiffies;
  127. }
  128. /*
  129. * Write out a byte buffer to an SPI register,
  130. * using a series of 16-bit transfers.
  131. */
  132. static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
  133. {
  134. int err = 0;
  135. __le16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK);
  136. struct spi_message m;
  137. struct spi_transfer reg_trans;
  138. struct spi_transfer data_trans;
  139. spi_message_init(&m);
  140. memset(&reg_trans, 0, sizeof(reg_trans));
  141. memset(&data_trans, 0, sizeof(data_trans));
  142. /* You must give an even number of bytes to the SPU, even if it
  143. * doesn't care about the last one. */
  144. BUG_ON(len & 0x1);
  145. spu_transaction_init(card);
  146. /* write SPU register index */
  147. reg_trans.tx_buf = &reg_out;
  148. reg_trans.len = sizeof(reg_out);
  149. data_trans.tx_buf = buf;
  150. data_trans.len = len;
  151. spi_message_add_tail(&reg_trans, &m);
  152. spi_message_add_tail(&data_trans, &m);
  153. err = spi_sync(card->spi, &m);
  154. spu_transaction_finish(card);
  155. return err;
  156. }
  157. static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val)
  158. {
  159. __le16 buff;
  160. buff = cpu_to_le16(val);
  161. return spu_write(card, reg, (u8 *)&buff, sizeof(u16));
  162. }
  163. static inline int spu_reg_is_port_reg(u16 reg)
  164. {
  165. switch (reg) {
  166. case IF_SPI_IO_RDWRPORT_REG:
  167. case IF_SPI_CMD_RDWRPORT_REG:
  168. case IF_SPI_DATA_RDWRPORT_REG:
  169. return 1;
  170. default:
  171. return 0;
  172. }
  173. }
  174. static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
  175. {
  176. unsigned int delay;
  177. int err = 0;
  178. __le16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK);
  179. struct spi_message m;
  180. struct spi_transfer reg_trans;
  181. struct spi_transfer dummy_trans;
  182. struct spi_transfer data_trans;
  183. /*
  184. * You must take an even number of bytes from the SPU, even if you
  185. * don't care about the last one.
  186. */
  187. BUG_ON(len & 0x1);
  188. spu_transaction_init(card);
  189. spi_message_init(&m);
  190. memset(&reg_trans, 0, sizeof(reg_trans));
  191. memset(&dummy_trans, 0, sizeof(dummy_trans));
  192. memset(&data_trans, 0, sizeof(data_trans));
  193. /* write SPU register index */
  194. reg_trans.tx_buf = &reg_out;
  195. reg_trans.len = sizeof(reg_out);
  196. spi_message_add_tail(&reg_trans, &m);
  197. delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay :
  198. card->spu_reg_delay;
  199. if (card->use_dummy_writes) {
  200. /* Clock in dummy cycles while the SPU fills the FIFO */
  201. dummy_trans.len = delay / 8;
  202. spi_message_add_tail(&dummy_trans, &m);
  203. } else {
  204. /* Busy-wait while the SPU fills the FIFO */
  205. reg_trans.delay_usecs =
  206. DIV_ROUND_UP((100 + (delay * 10)), 1000);
  207. }
  208. /* read in data */
  209. data_trans.rx_buf = buf;
  210. data_trans.len = len;
  211. spi_message_add_tail(&data_trans, &m);
  212. err = spi_sync(card->spi, &m);
  213. spu_transaction_finish(card);
  214. return err;
  215. }
  216. /* Read 16 bits from an SPI register */
  217. static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
  218. {
  219. __le16 buf;
  220. int ret;
  221. ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  222. if (ret == 0)
  223. *val = le16_to_cpup(&buf);
  224. return ret;
  225. }
  226. /*
  227. * Read 32 bits from an SPI register.
  228. * The low 16 bits are read first.
  229. */
  230. static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
  231. {
  232. __le32 buf;
  233. int err;
  234. err = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  235. if (!err)
  236. *val = le32_to_cpup(&buf);
  237. return err;
  238. }
  239. /*
  240. * Keep reading 16 bits from an SPI register until you get the correct result.
  241. *
  242. * If mask = 0, the correct result is any non-zero number.
  243. * If mask != 0, the correct result is any number where
  244. * number & target_mask == target
  245. *
  246. * Returns -ETIMEDOUT if a second passes without the correct result.
  247. */
  248. static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
  249. u16 target_mask, u16 target)
  250. {
  251. int err;
  252. unsigned long timeout = jiffies + 5*HZ;
  253. while (1) {
  254. u16 val;
  255. err = spu_read_u16(card, reg, &val);
  256. if (err)
  257. return err;
  258. if (target_mask) {
  259. if ((val & target_mask) == target)
  260. return 0;
  261. } else {
  262. if (val)
  263. return 0;
  264. }
  265. udelay(100);
  266. if (time_after(jiffies, timeout)) {
  267. pr_err("%s: timeout with val=%02x, target_mask=%02x, target=%02x\n",
  268. __func__, val, target_mask, target);
  269. return -ETIMEDOUT;
  270. }
  271. }
  272. }
  273. /*
  274. * Read 16 bits from an SPI register until you receive a specific value.
  275. * Returns -ETIMEDOUT if a 4 tries pass without success.
  276. */
  277. static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target)
  278. {
  279. int err, try;
  280. for (try = 0; try < 4; ++try) {
  281. u32 val = 0;
  282. err = spu_read_u32(card, reg, &val);
  283. if (err)
  284. return err;
  285. if (val == target)
  286. return 0;
  287. mdelay(100);
  288. }
  289. return -ETIMEDOUT;
  290. }
  291. static int spu_set_interrupt_mode(struct if_spi_card *card,
  292. int suppress_host_int,
  293. int auto_int)
  294. {
  295. int err = 0;
  296. /*
  297. * We can suppress a host interrupt by clearing the appropriate
  298. * bit in the "host interrupt status mask" register
  299. */
  300. if (suppress_host_int) {
  301. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
  302. if (err)
  303. return err;
  304. } else {
  305. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG,
  306. IF_SPI_HISM_TX_DOWNLOAD_RDY |
  307. IF_SPI_HISM_RX_UPLOAD_RDY |
  308. IF_SPI_HISM_CMD_DOWNLOAD_RDY |
  309. IF_SPI_HISM_CARDEVENT |
  310. IF_SPI_HISM_CMD_UPLOAD_RDY);
  311. if (err)
  312. return err;
  313. }
  314. /*
  315. * If auto-interrupts are on, the completion of certain transactions
  316. * will trigger an interrupt automatically. If auto-interrupts
  317. * are off, we need to set the "Card Interrupt Cause" register to
  318. * trigger a card interrupt.
  319. */
  320. if (auto_int) {
  321. err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG,
  322. IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO |
  323. IF_SPI_HICT_RX_UPLOAD_OVER_AUTO |
  324. IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO |
  325. IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO);
  326. if (err)
  327. return err;
  328. } else {
  329. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
  330. if (err)
  331. return err;
  332. }
  333. return err;
  334. }
  335. static int spu_get_chip_revision(struct if_spi_card *card,
  336. u16 *card_id, u8 *card_rev)
  337. {
  338. int err = 0;
  339. u32 dev_ctrl;
  340. err = spu_read_u32(card, IF_SPI_DEVICEID_CTRL_REG, &dev_ctrl);
  341. if (err)
  342. return err;
  343. *card_id = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_ID(dev_ctrl);
  344. *card_rev = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dev_ctrl);
  345. return err;
  346. }
  347. static int spu_set_bus_mode(struct if_spi_card *card, u16 mode)
  348. {
  349. int err = 0;
  350. u16 rval;
  351. /* set bus mode */
  352. err = spu_write_u16(card, IF_SPI_SPU_BUS_MODE_REG, mode);
  353. if (err)
  354. return err;
  355. /* Check that we were able to read back what we just wrote. */
  356. err = spu_read_u16(card, IF_SPI_SPU_BUS_MODE_REG, &rval);
  357. if (err)
  358. return err;
  359. if ((rval & 0xF) != mode) {
  360. pr_err("Can't read bus mode register\n");
  361. return -EIO;
  362. }
  363. return 0;
  364. }
  365. static int spu_init(struct if_spi_card *card, int use_dummy_writes)
  366. {
  367. int err = 0;
  368. u32 delay;
  369. /*
  370. * We have to start up in timed delay mode so that we can safely
  371. * read the Delay Read Register.
  372. */
  373. card->use_dummy_writes = 0;
  374. err = spu_set_bus_mode(card,
  375. IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
  376. IF_SPI_BUS_MODE_DELAY_METHOD_TIMED |
  377. IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
  378. if (err)
  379. return err;
  380. card->spu_port_delay = 1000;
  381. card->spu_reg_delay = 1000;
  382. err = spu_read_u32(card, IF_SPI_DELAY_READ_REG, &delay);
  383. if (err)
  384. return err;
  385. card->spu_port_delay = delay & 0x0000ffff;
  386. card->spu_reg_delay = (delay & 0xffff0000) >> 16;
  387. /* If dummy clock delay mode has been requested, switch to it now */
  388. if (use_dummy_writes) {
  389. card->use_dummy_writes = 1;
  390. err = spu_set_bus_mode(card,
  391. IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
  392. IF_SPI_BUS_MODE_DELAY_METHOD_DUMMY_CLOCK |
  393. IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
  394. if (err)
  395. return err;
  396. }
  397. lbs_deb_spi("Initialized SPU unit. "
  398. "spu_port_delay=0x%04lx, spu_reg_delay=0x%04lx\n",
  399. card->spu_port_delay, card->spu_reg_delay);
  400. return err;
  401. }
  402. /*
  403. * Firmware Loading
  404. */
  405. static int if_spi_prog_helper_firmware(struct if_spi_card *card,
  406. const struct firmware *firmware)
  407. {
  408. int err = 0;
  409. int bytes_remaining;
  410. const u8 *fw;
  411. u8 temp[HELPER_FW_LOAD_CHUNK_SZ];
  412. lbs_deb_enter(LBS_DEB_SPI);
  413. err = spu_set_interrupt_mode(card, 1, 0);
  414. if (err)
  415. goto out;
  416. bytes_remaining = firmware->size;
  417. fw = firmware->data;
  418. /* Load helper firmware image */
  419. while (bytes_remaining > 0) {
  420. /*
  421. * Scratch pad 1 should contain the number of bytes we
  422. * want to download to the firmware
  423. */
  424. err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG,
  425. HELPER_FW_LOAD_CHUNK_SZ);
  426. if (err)
  427. goto out;
  428. err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  429. IF_SPI_HIST_CMD_DOWNLOAD_RDY,
  430. IF_SPI_HIST_CMD_DOWNLOAD_RDY);
  431. if (err)
  432. goto out;
  433. /*
  434. * Feed the data into the command read/write port reg
  435. * in chunks of 64 bytes
  436. */
  437. memset(temp, 0, sizeof(temp));
  438. memcpy(temp, fw,
  439. min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ));
  440. mdelay(10);
  441. err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
  442. temp, HELPER_FW_LOAD_CHUNK_SZ);
  443. if (err)
  444. goto out;
  445. /* Interrupt the boot code */
  446. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  447. if (err)
  448. goto out;
  449. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
  450. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  451. if (err)
  452. goto out;
  453. bytes_remaining -= HELPER_FW_LOAD_CHUNK_SZ;
  454. fw += HELPER_FW_LOAD_CHUNK_SZ;
  455. }
  456. /*
  457. * Once the helper / single stage firmware download is complete,
  458. * write 0 to scratch pad 1 and interrupt the
  459. * bootloader. This completes the helper download.
  460. */
  461. err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK);
  462. if (err)
  463. goto out;
  464. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  465. if (err)
  466. goto out;
  467. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
  468. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  469. out:
  470. if (err)
  471. pr_err("failed to load helper firmware (err=%d)\n", err);
  472. lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
  473. return err;
  474. }
  475. /*
  476. * Returns the length of the next packet the firmware expects us to send.
  477. * Sets crc_err if the previous transfer had a CRC error.
  478. */
  479. static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
  480. int *crc_err)
  481. {
  482. u16 len;
  483. int err = 0;
  484. /*
  485. * wait until the host interrupt status register indicates
  486. * that we are ready to download
  487. */
  488. err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  489. IF_SPI_HIST_CMD_DOWNLOAD_RDY,
  490. IF_SPI_HIST_CMD_DOWNLOAD_RDY);
  491. if (err) {
  492. pr_err("timed out waiting for host_int_status\n");
  493. return err;
  494. }
  495. /* Ask the device how many bytes of firmware it wants. */
  496. err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
  497. if (err)
  498. return err;
  499. if (len > IF_SPI_CMD_BUF_SIZE) {
  500. pr_err("firmware load device requested a larger transfer than we are prepared to handle (len = %d)\n",
  501. len);
  502. return -EIO;
  503. }
  504. if (len & 0x1) {
  505. lbs_deb_spi("%s: crc error\n", __func__);
  506. len &= ~0x1;
  507. *crc_err = 1;
  508. } else
  509. *crc_err = 0;
  510. return len;
  511. }
  512. static int if_spi_prog_main_firmware(struct if_spi_card *card,
  513. const struct firmware *firmware)
  514. {
  515. struct lbs_private *priv = card->priv;
  516. int len, prev_len;
  517. int bytes, crc_err = 0, err = 0;
  518. const u8 *fw;
  519. u16 num_crc_errs;
  520. lbs_deb_enter(LBS_DEB_SPI);
  521. err = spu_set_interrupt_mode(card, 1, 0);
  522. if (err)
  523. goto out;
  524. err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0);
  525. if (err) {
  526. netdev_err(priv->dev,
  527. "%s: timed out waiting for initial scratch reg = 0\n",
  528. __func__);
  529. goto out;
  530. }
  531. num_crc_errs = 0;
  532. prev_len = 0;
  533. bytes = firmware->size;
  534. fw = firmware->data;
  535. while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) {
  536. if (len < 0) {
  537. err = len;
  538. goto out;
  539. }
  540. if (bytes < 0) {
  541. /*
  542. * If there are no more bytes left, we would normally
  543. * expect to have terminated with len = 0
  544. */
  545. netdev_err(priv->dev,
  546. "Firmware load wants more bytes than we have to offer.\n");
  547. break;
  548. }
  549. if (crc_err) {
  550. /* Previous transfer failed. */
  551. if (++num_crc_errs > MAX_MAIN_FW_LOAD_CRC_ERR) {
  552. pr_err("Too many CRC errors encountered in firmware load.\n");
  553. err = -EIO;
  554. goto out;
  555. }
  556. } else {
  557. /* Previous transfer succeeded. Advance counters. */
  558. bytes -= prev_len;
  559. fw += prev_len;
  560. }
  561. if (bytes < len) {
  562. memset(card->cmd_buffer, 0, len);
  563. memcpy(card->cmd_buffer, fw, bytes);
  564. } else
  565. memcpy(card->cmd_buffer, fw, len);
  566. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  567. if (err)
  568. goto out;
  569. err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
  570. card->cmd_buffer, len);
  571. if (err)
  572. goto out;
  573. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG ,
  574. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  575. if (err)
  576. goto out;
  577. prev_len = len;
  578. }
  579. if (bytes > prev_len) {
  580. pr_err("firmware load wants fewer bytes than we have to offer\n");
  581. }
  582. /* Confirm firmware download */
  583. err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG,
  584. SUCCESSFUL_FW_DOWNLOAD_MAGIC);
  585. if (err) {
  586. pr_err("failed to confirm the firmware download\n");
  587. goto out;
  588. }
  589. out:
  590. if (err)
  591. pr_err("failed to load firmware (err=%d)\n", err);
  592. lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
  593. return err;
  594. }
  595. /*
  596. * SPI Transfer Thread
  597. *
  598. * The SPI worker handles all SPI transfers, so there is no need for a lock.
  599. */
  600. /* Move a command from the card to the host */
  601. static int if_spi_c2h_cmd(struct if_spi_card *card)
  602. {
  603. struct lbs_private *priv = card->priv;
  604. unsigned long flags;
  605. int err = 0;
  606. u16 len;
  607. u8 i;
  608. /*
  609. * We need a buffer big enough to handle whatever people send to
  610. * hw_host_to_card
  611. */
  612. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
  613. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
  614. /*
  615. * It's just annoying if the buffer size isn't a multiple of 4, because
  616. * then we might have len < IF_SPI_CMD_BUF_SIZE but
  617. * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
  618. */
  619. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
  620. lbs_deb_enter(LBS_DEB_SPI);
  621. /* How many bytes are there to read? */
  622. err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len);
  623. if (err)
  624. goto out;
  625. if (!len) {
  626. netdev_err(priv->dev, "%s: error: card has no data for host\n",
  627. __func__);
  628. err = -EINVAL;
  629. goto out;
  630. } else if (len > IF_SPI_CMD_BUF_SIZE) {
  631. netdev_err(priv->dev,
  632. "%s: error: response packet too large: %d bytes, but maximum is %d\n",
  633. __func__, len, IF_SPI_CMD_BUF_SIZE);
  634. err = -EINVAL;
  635. goto out;
  636. }
  637. /* Read the data from the WLAN module into our command buffer */
  638. err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG,
  639. card->cmd_buffer, ALIGN(len, 4));
  640. if (err)
  641. goto out;
  642. spin_lock_irqsave(&priv->driver_lock, flags);
  643. i = (priv->resp_idx == 0) ? 1 : 0;
  644. BUG_ON(priv->resp_len[i]);
  645. priv->resp_len[i] = len;
  646. memcpy(priv->resp_buf[i], card->cmd_buffer, len);
  647. lbs_notify_command_response(priv, i);
  648. spin_unlock_irqrestore(&priv->driver_lock, flags);
  649. out:
  650. if (err)
  651. netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
  652. lbs_deb_leave(LBS_DEB_SPI);
  653. return err;
  654. }
  655. /* Move data from the card to the host */
  656. static int if_spi_c2h_data(struct if_spi_card *card)
  657. {
  658. struct lbs_private *priv = card->priv;
  659. struct sk_buff *skb;
  660. char *data;
  661. u16 len;
  662. int err = 0;
  663. lbs_deb_enter(LBS_DEB_SPI);
  664. /* How many bytes are there to read? */
  665. err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
  666. if (err)
  667. goto out;
  668. if (!len) {
  669. netdev_err(priv->dev, "%s: error: card has no data for host\n",
  670. __func__);
  671. err = -EINVAL;
  672. goto out;
  673. } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
  674. netdev_err(priv->dev,
  675. "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n",
  676. __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
  677. err = -EINVAL;
  678. goto out;
  679. }
  680. /* TODO: should we allocate a smaller skb if we have less data? */
  681. skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
  682. if (!skb) {
  683. err = -ENOBUFS;
  684. goto out;
  685. }
  686. skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
  687. data = skb_put(skb, len);
  688. /* Read the data from the WLAN module into our skb... */
  689. err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
  690. if (err)
  691. goto free_skb;
  692. /* pass the SKB to libertas */
  693. err = lbs_process_rxed_packet(card->priv, skb);
  694. if (err)
  695. goto free_skb;
  696. /* success */
  697. goto out;
  698. free_skb:
  699. dev_kfree_skb(skb);
  700. out:
  701. if (err)
  702. netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
  703. lbs_deb_leave(LBS_DEB_SPI);
  704. return err;
  705. }
  706. /* Move data or a command from the host to the card. */
  707. static void if_spi_h2c(struct if_spi_card *card,
  708. struct if_spi_packet *packet, int type)
  709. {
  710. struct lbs_private *priv = card->priv;
  711. int err = 0;
  712. u16 int_type, port_reg;
  713. switch (type) {
  714. case MVMS_DAT:
  715. int_type = IF_SPI_CIC_TX_DOWNLOAD_OVER;
  716. port_reg = IF_SPI_DATA_RDWRPORT_REG;
  717. break;
  718. case MVMS_CMD:
  719. int_type = IF_SPI_CIC_CMD_DOWNLOAD_OVER;
  720. port_reg = IF_SPI_CMD_RDWRPORT_REG;
  721. break;
  722. default:
  723. netdev_err(priv->dev, "can't transfer buffer of type %d\n",
  724. type);
  725. err = -EINVAL;
  726. goto out;
  727. }
  728. /* Write the data to the card */
  729. err = spu_write(card, port_reg, packet->buffer, packet->blen);
  730. if (err)
  731. goto out;
  732. out:
  733. kfree(packet);
  734. if (err)
  735. netdev_err(priv->dev, "%s: error %d\n", __func__, err);
  736. }
  737. /* Inform the host about a card event */
  738. static void if_spi_e2h(struct if_spi_card *card)
  739. {
  740. int err = 0;
  741. u32 cause;
  742. struct lbs_private *priv = card->priv;
  743. err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause);
  744. if (err)
  745. goto out;
  746. /* re-enable the card event interrupt */
  747. spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  748. ~IF_SPI_HICU_CARD_EVENT);
  749. /* generate a card interrupt */
  750. spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, IF_SPI_CIC_HOST_EVENT);
  751. lbs_queue_event(priv, cause & 0xff);
  752. out:
  753. if (err)
  754. netdev_err(priv->dev, "%s: error %d\n", __func__, err);
  755. }
  756. static void if_spi_host_to_card_worker(struct work_struct *work)
  757. {
  758. int err;
  759. struct if_spi_card *card;
  760. u16 hiStatus;
  761. unsigned long flags;
  762. struct if_spi_packet *packet;
  763. struct lbs_private *priv;
  764. card = container_of(work, struct if_spi_card, packet_work);
  765. priv = card->priv;
  766. lbs_deb_enter(LBS_DEB_SPI);
  767. /*
  768. * Read the host interrupt status register to see what we
  769. * can do.
  770. */
  771. err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  772. &hiStatus);
  773. if (err) {
  774. netdev_err(priv->dev, "I/O error\n");
  775. goto err;
  776. }
  777. if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) {
  778. err = if_spi_c2h_cmd(card);
  779. if (err)
  780. goto err;
  781. }
  782. if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) {
  783. err = if_spi_c2h_data(card);
  784. if (err)
  785. goto err;
  786. }
  787. /*
  788. * workaround: in PS mode, the card does not set the Command
  789. * Download Ready bit, but it sets TX Download Ready.
  790. */
  791. if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
  792. (card->priv->psstate != PS_STATE_FULL_POWER &&
  793. (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
  794. /*
  795. * This means two things. First of all,
  796. * if there was a previous command sent, the card has
  797. * successfully received it.
  798. * Secondly, it is now ready to download another
  799. * command.
  800. */
  801. lbs_host_to_card_done(card->priv);
  802. /* Do we have any command packets from the host to send? */
  803. packet = NULL;
  804. spin_lock_irqsave(&card->buffer_lock, flags);
  805. if (!list_empty(&card->cmd_packet_list)) {
  806. packet = (struct if_spi_packet *)(card->
  807. cmd_packet_list.next);
  808. list_del(&packet->list);
  809. }
  810. spin_unlock_irqrestore(&card->buffer_lock, flags);
  811. if (packet)
  812. if_spi_h2c(card, packet, MVMS_CMD);
  813. }
  814. if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
  815. /* Do we have any data packets from the host to send? */
  816. packet = NULL;
  817. spin_lock_irqsave(&card->buffer_lock, flags);
  818. if (!list_empty(&card->data_packet_list)) {
  819. packet = (struct if_spi_packet *)(card->
  820. data_packet_list.next);
  821. list_del(&packet->list);
  822. }
  823. spin_unlock_irqrestore(&card->buffer_lock, flags);
  824. if (packet)
  825. if_spi_h2c(card, packet, MVMS_DAT);
  826. }
  827. if (hiStatus & IF_SPI_HIST_CARD_EVENT)
  828. if_spi_e2h(card);
  829. err:
  830. if (err)
  831. netdev_err(priv->dev, "%s: got error %d\n", __func__, err);
  832. lbs_deb_leave(LBS_DEB_SPI);
  833. }
  834. /*
  835. * Host to Card
  836. *
  837. * Called from Libertas to transfer some data to the WLAN device
  838. * We can't sleep here.
  839. */
  840. static int if_spi_host_to_card(struct lbs_private *priv,
  841. u8 type, u8 *buf, u16 nb)
  842. {
  843. int err = 0;
  844. unsigned long flags;
  845. struct if_spi_card *card = priv->card;
  846. struct if_spi_packet *packet;
  847. u16 blen;
  848. lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb);
  849. if (nb == 0) {
  850. netdev_err(priv->dev, "%s: invalid size requested: %d\n",
  851. __func__, nb);
  852. err = -EINVAL;
  853. goto out;
  854. }
  855. blen = ALIGN(nb, 4);
  856. packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
  857. if (!packet) {
  858. err = -ENOMEM;
  859. goto out;
  860. }
  861. packet->blen = blen;
  862. memcpy(packet->buffer, buf, nb);
  863. memset(packet->buffer + nb, 0, blen - nb);
  864. switch (type) {
  865. case MVMS_CMD:
  866. priv->dnld_sent = DNLD_CMD_SENT;
  867. spin_lock_irqsave(&card->buffer_lock, flags);
  868. list_add_tail(&packet->list, &card->cmd_packet_list);
  869. spin_unlock_irqrestore(&card->buffer_lock, flags);
  870. break;
  871. case MVMS_DAT:
  872. priv->dnld_sent = DNLD_DATA_SENT;
  873. spin_lock_irqsave(&card->buffer_lock, flags);
  874. list_add_tail(&packet->list, &card->data_packet_list);
  875. spin_unlock_irqrestore(&card->buffer_lock, flags);
  876. break;
  877. default:
  878. netdev_err(priv->dev, "can't transfer buffer of type %d\n",
  879. type);
  880. err = -EINVAL;
  881. break;
  882. }
  883. /* Queue spi xfer work */
  884. queue_work(card->workqueue, &card->packet_work);
  885. out:
  886. lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
  887. return err;
  888. }
  889. /*
  890. * Host Interrupts
  891. *
  892. * Service incoming interrupts from the WLAN device. We can't sleep here, so
  893. * don't try to talk on the SPI bus, just queue the SPI xfer work.
  894. */
  895. static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
  896. {
  897. struct if_spi_card *card = dev_id;
  898. queue_work(card->workqueue, &card->packet_work);
  899. return IRQ_HANDLED;
  900. }
  901. /*
  902. * SPI callbacks
  903. */
  904. static int if_spi_init_card(struct if_spi_card *card)
  905. {
  906. struct lbs_private *priv = card->priv;
  907. int err, i;
  908. u32 scratch;
  909. const struct firmware *helper = NULL;
  910. const struct firmware *mainfw = NULL;
  911. lbs_deb_enter(LBS_DEB_SPI);
  912. err = spu_init(card, card->pdata->use_dummy_writes);
  913. if (err)
  914. goto out;
  915. err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
  916. if (err)
  917. goto out;
  918. err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
  919. if (err)
  920. goto out;
  921. if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
  922. lbs_deb_spi("Firmware is already loaded for "
  923. "Marvell WLAN 802.11 adapter\n");
  924. else {
  925. /* Check if we support this card */
  926. for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
  927. if (card->card_id == fw_table[i].model)
  928. break;
  929. }
  930. if (i == ARRAY_SIZE(fw_table)) {
  931. netdev_err(priv->dev, "Unsupported chip_id: 0x%02x\n",
  932. card->card_id);
  933. err = -ENODEV;
  934. goto out;
  935. }
  936. err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
  937. card->card_id, &fw_table[0], &helper,
  938. &mainfw);
  939. if (err) {
  940. netdev_err(priv->dev, "failed to find firmware (%d)\n",
  941. err);
  942. goto out;
  943. }
  944. lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
  945. "(chip_id = 0x%04x, chip_rev = 0x%02x) "
  946. "attached to SPI bus_num %d, chip_select %d. "
  947. "spi->max_speed_hz=%d\n",
  948. card->card_id, card->card_rev,
  949. card->spi->master->bus_num,
  950. card->spi->chip_select,
  951. card->spi->max_speed_hz);
  952. err = if_spi_prog_helper_firmware(card, helper);
  953. if (err)
  954. goto out;
  955. err = if_spi_prog_main_firmware(card, mainfw);
  956. if (err)
  957. goto out;
  958. lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
  959. }
  960. err = spu_set_interrupt_mode(card, 0, 1);
  961. if (err)
  962. goto out;
  963. out:
  964. if (helper)
  965. release_firmware(helper);
  966. if (mainfw)
  967. release_firmware(mainfw);
  968. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  969. return err;
  970. }
  971. static void if_spi_resume_worker(struct work_struct *work)
  972. {
  973. struct if_spi_card *card;
  974. card = container_of(work, struct if_spi_card, resume_work);
  975. if (card->suspended) {
  976. if (card->pdata->setup)
  977. card->pdata->setup(card->spi);
  978. /* Init card ... */
  979. if_spi_init_card(card);
  980. enable_irq(card->spi->irq);
  981. /* And resume it ... */
  982. lbs_resume(card->priv);
  983. card->suspended = 0;
  984. }
  985. }
  986. static int __devinit if_spi_probe(struct spi_device *spi)
  987. {
  988. struct if_spi_card *card;
  989. struct lbs_private *priv = NULL;
  990. struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
  991. int err = 0;
  992. lbs_deb_enter(LBS_DEB_SPI);
  993. if (!pdata) {
  994. err = -EINVAL;
  995. goto out;
  996. }
  997. if (pdata->setup) {
  998. err = pdata->setup(spi);
  999. if (err)
  1000. goto out;
  1001. }
  1002. /* Allocate card structure to represent this specific device */
  1003. card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
  1004. if (!card) {
  1005. err = -ENOMEM;
  1006. goto teardown;
  1007. }
  1008. spi_set_drvdata(spi, card);
  1009. card->pdata = pdata;
  1010. card->spi = spi;
  1011. card->prev_xfer_time = jiffies;
  1012. INIT_LIST_HEAD(&card->cmd_packet_list);
  1013. INIT_LIST_HEAD(&card->data_packet_list);
  1014. spin_lock_init(&card->buffer_lock);
  1015. /* Initialize the SPI Interface Unit */
  1016. /* Firmware load */
  1017. err = if_spi_init_card(card);
  1018. if (err)
  1019. goto free_card;
  1020. /*
  1021. * Register our card with libertas.
  1022. * This will call alloc_etherdev.
  1023. */
  1024. priv = lbs_add_card(card, &spi->dev);
  1025. if (!priv) {
  1026. err = -ENOMEM;
  1027. goto free_card;
  1028. }
  1029. card->priv = priv;
  1030. priv->setup_fw_on_resume = 1;
  1031. priv->card = card;
  1032. priv->hw_host_to_card = if_spi_host_to_card;
  1033. priv->enter_deep_sleep = NULL;
  1034. priv->exit_deep_sleep = NULL;
  1035. priv->reset_deep_sleep_wakeup = NULL;
  1036. priv->fw_ready = 1;
  1037. /* Initialize interrupt handling stuff. */
  1038. card->workqueue = create_workqueue("libertas_spi");
  1039. INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
  1040. INIT_WORK(&card->resume_work, if_spi_resume_worker);
  1041. err = request_irq(spi->irq, if_spi_host_interrupt,
  1042. IRQF_TRIGGER_FALLING, "libertas_spi", card);
  1043. if (err) {
  1044. pr_err("can't get host irq line-- request_irq failed\n");
  1045. goto terminate_workqueue;
  1046. }
  1047. /*
  1048. * Start the card.
  1049. * This will call register_netdev, and we'll start
  1050. * getting interrupts...
  1051. */
  1052. err = lbs_start_card(priv);
  1053. if (err)
  1054. goto release_irq;
  1055. lbs_deb_spi("Finished initializing WLAN module.\n");
  1056. /* successful exit */
  1057. goto out;
  1058. release_irq:
  1059. free_irq(spi->irq, card);
  1060. terminate_workqueue:
  1061. flush_workqueue(card->workqueue);
  1062. destroy_workqueue(card->workqueue);
  1063. lbs_remove_card(priv); /* will call free_netdev */
  1064. free_card:
  1065. free_if_spi_card(card);
  1066. teardown:
  1067. if (pdata->teardown)
  1068. pdata->teardown(spi);
  1069. out:
  1070. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  1071. return err;
  1072. }
  1073. static int __devexit libertas_spi_remove(struct spi_device *spi)
  1074. {
  1075. struct if_spi_card *card = spi_get_drvdata(spi);
  1076. struct lbs_private *priv = card->priv;
  1077. lbs_deb_spi("libertas_spi_remove\n");
  1078. lbs_deb_enter(LBS_DEB_SPI);
  1079. cancel_work_sync(&card->resume_work);
  1080. lbs_stop_card(priv);
  1081. lbs_remove_card(priv); /* will call free_netdev */
  1082. free_irq(spi->irq, card);
  1083. flush_workqueue(card->workqueue);
  1084. destroy_workqueue(card->workqueue);
  1085. if (card->pdata->teardown)
  1086. card->pdata->teardown(spi);
  1087. free_if_spi_card(card);
  1088. lbs_deb_leave(LBS_DEB_SPI);
  1089. return 0;
  1090. }
  1091. static int if_spi_suspend(struct device *dev)
  1092. {
  1093. struct spi_device *spi = to_spi_device(dev);
  1094. struct if_spi_card *card = spi_get_drvdata(spi);
  1095. if (!card->suspended) {
  1096. lbs_suspend(card->priv);
  1097. flush_workqueue(card->workqueue);
  1098. disable_irq(spi->irq);
  1099. if (card->pdata->teardown)
  1100. card->pdata->teardown(spi);
  1101. card->suspended = 1;
  1102. }
  1103. return 0;
  1104. }
  1105. static int if_spi_resume(struct device *dev)
  1106. {
  1107. struct spi_device *spi = to_spi_device(dev);
  1108. struct if_spi_card *card = spi_get_drvdata(spi);
  1109. /* Schedule delayed work */
  1110. schedule_work(&card->resume_work);
  1111. return 0;
  1112. }
  1113. static const struct dev_pm_ops if_spi_pm_ops = {
  1114. .suspend = if_spi_suspend,
  1115. .resume = if_spi_resume,
  1116. };
  1117. static struct spi_driver libertas_spi_driver = {
  1118. .probe = if_spi_probe,
  1119. .remove = __devexit_p(libertas_spi_remove),
  1120. .driver = {
  1121. .name = "libertas_spi",
  1122. .bus = &spi_bus_type,
  1123. .owner = THIS_MODULE,
  1124. .pm = &if_spi_pm_ops,
  1125. },
  1126. };
  1127. /*
  1128. * Module functions
  1129. */
  1130. static int __init if_spi_init_module(void)
  1131. {
  1132. int ret = 0;
  1133. lbs_deb_enter(LBS_DEB_SPI);
  1134. printk(KERN_INFO "libertas_spi: Libertas SPI driver\n");
  1135. ret = spi_register_driver(&libertas_spi_driver);
  1136. lbs_deb_leave(LBS_DEB_SPI);
  1137. return ret;
  1138. }
  1139. static void __exit if_spi_exit_module(void)
  1140. {
  1141. lbs_deb_enter(LBS_DEB_SPI);
  1142. spi_unregister_driver(&libertas_spi_driver);
  1143. lbs_deb_leave(LBS_DEB_SPI);
  1144. }
  1145. module_init(if_spi_init_module);
  1146. module_exit(if_spi_exit_module);
  1147. MODULE_DESCRIPTION("Libertas SPI WLAN Driver");
  1148. MODULE_AUTHOR("Andrey Yurovsky <andrey@cozybit.com>, "
  1149. "Colin McCabe <colin@cozybit.com>");
  1150. MODULE_LICENSE("GPL");
  1151. MODULE_ALIAS("spi:libertas_spi");