if_spi.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  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. kfree(packet);
  879. netdev_err(priv->dev, "can't transfer buffer of type %d\n",
  880. type);
  881. err = -EINVAL;
  882. break;
  883. }
  884. /* Queue spi xfer work */
  885. queue_work(card->workqueue, &card->packet_work);
  886. out:
  887. lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
  888. return err;
  889. }
  890. /*
  891. * Host Interrupts
  892. *
  893. * Service incoming interrupts from the WLAN device. We can't sleep here, so
  894. * don't try to talk on the SPI bus, just queue the SPI xfer work.
  895. */
  896. static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
  897. {
  898. struct if_spi_card *card = dev_id;
  899. queue_work(card->workqueue, &card->packet_work);
  900. return IRQ_HANDLED;
  901. }
  902. /*
  903. * SPI callbacks
  904. */
  905. static int if_spi_init_card(struct if_spi_card *card)
  906. {
  907. struct lbs_private *priv = card->priv;
  908. int err, i;
  909. u32 scratch;
  910. const struct firmware *helper = NULL;
  911. const struct firmware *mainfw = NULL;
  912. lbs_deb_enter(LBS_DEB_SPI);
  913. err = spu_init(card, card->pdata->use_dummy_writes);
  914. if (err)
  915. goto out;
  916. err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
  917. if (err)
  918. goto out;
  919. err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
  920. if (err)
  921. goto out;
  922. if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
  923. lbs_deb_spi("Firmware is already loaded for "
  924. "Marvell WLAN 802.11 adapter\n");
  925. else {
  926. /* Check if we support this card */
  927. for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
  928. if (card->card_id == fw_table[i].model)
  929. break;
  930. }
  931. if (i == ARRAY_SIZE(fw_table)) {
  932. netdev_err(priv->dev, "Unsupported chip_id: 0x%02x\n",
  933. card->card_id);
  934. err = -ENODEV;
  935. goto out;
  936. }
  937. err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
  938. card->card_id, &fw_table[0], &helper,
  939. &mainfw);
  940. if (err) {
  941. netdev_err(priv->dev, "failed to find firmware (%d)\n",
  942. err);
  943. goto out;
  944. }
  945. lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
  946. "(chip_id = 0x%04x, chip_rev = 0x%02x) "
  947. "attached to SPI bus_num %d, chip_select %d. "
  948. "spi->max_speed_hz=%d\n",
  949. card->card_id, card->card_rev,
  950. card->spi->master->bus_num,
  951. card->spi->chip_select,
  952. card->spi->max_speed_hz);
  953. err = if_spi_prog_helper_firmware(card, helper);
  954. if (err)
  955. goto out;
  956. err = if_spi_prog_main_firmware(card, mainfw);
  957. if (err)
  958. goto out;
  959. lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
  960. }
  961. err = spu_set_interrupt_mode(card, 0, 1);
  962. if (err)
  963. goto out;
  964. out:
  965. if (helper)
  966. release_firmware(helper);
  967. if (mainfw)
  968. release_firmware(mainfw);
  969. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  970. return err;
  971. }
  972. static void if_spi_resume_worker(struct work_struct *work)
  973. {
  974. struct if_spi_card *card;
  975. card = container_of(work, struct if_spi_card, resume_work);
  976. if (card->suspended) {
  977. if (card->pdata->setup)
  978. card->pdata->setup(card->spi);
  979. /* Init card ... */
  980. if_spi_init_card(card);
  981. enable_irq(card->spi->irq);
  982. /* And resume it ... */
  983. lbs_resume(card->priv);
  984. card->suspended = 0;
  985. }
  986. }
  987. static int __devinit if_spi_probe(struct spi_device *spi)
  988. {
  989. struct if_spi_card *card;
  990. struct lbs_private *priv = NULL;
  991. struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
  992. int err = 0;
  993. lbs_deb_enter(LBS_DEB_SPI);
  994. if (!pdata) {
  995. err = -EINVAL;
  996. goto out;
  997. }
  998. if (pdata->setup) {
  999. err = pdata->setup(spi);
  1000. if (err)
  1001. goto out;
  1002. }
  1003. /* Allocate card structure to represent this specific device */
  1004. card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
  1005. if (!card) {
  1006. err = -ENOMEM;
  1007. goto teardown;
  1008. }
  1009. spi_set_drvdata(spi, card);
  1010. card->pdata = pdata;
  1011. card->spi = spi;
  1012. card->prev_xfer_time = jiffies;
  1013. INIT_LIST_HEAD(&card->cmd_packet_list);
  1014. INIT_LIST_HEAD(&card->data_packet_list);
  1015. spin_lock_init(&card->buffer_lock);
  1016. /* Initialize the SPI Interface Unit */
  1017. /* Firmware load */
  1018. err = if_spi_init_card(card);
  1019. if (err)
  1020. goto free_card;
  1021. /*
  1022. * Register our card with libertas.
  1023. * This will call alloc_etherdev.
  1024. */
  1025. priv = lbs_add_card(card, &spi->dev);
  1026. if (!priv) {
  1027. err = -ENOMEM;
  1028. goto free_card;
  1029. }
  1030. card->priv = priv;
  1031. priv->setup_fw_on_resume = 1;
  1032. priv->card = card;
  1033. priv->hw_host_to_card = if_spi_host_to_card;
  1034. priv->enter_deep_sleep = NULL;
  1035. priv->exit_deep_sleep = NULL;
  1036. priv->reset_deep_sleep_wakeup = NULL;
  1037. priv->fw_ready = 1;
  1038. /* Initialize interrupt handling stuff. */
  1039. card->workqueue = create_workqueue("libertas_spi");
  1040. INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
  1041. INIT_WORK(&card->resume_work, if_spi_resume_worker);
  1042. err = request_irq(spi->irq, if_spi_host_interrupt,
  1043. IRQF_TRIGGER_FALLING, "libertas_spi", card);
  1044. if (err) {
  1045. pr_err("can't get host irq line-- request_irq failed\n");
  1046. goto terminate_workqueue;
  1047. }
  1048. /*
  1049. * Start the card.
  1050. * This will call register_netdev, and we'll start
  1051. * getting interrupts...
  1052. */
  1053. err = lbs_start_card(priv);
  1054. if (err)
  1055. goto release_irq;
  1056. lbs_deb_spi("Finished initializing WLAN module.\n");
  1057. /* successful exit */
  1058. goto out;
  1059. release_irq:
  1060. free_irq(spi->irq, card);
  1061. terminate_workqueue:
  1062. flush_workqueue(card->workqueue);
  1063. destroy_workqueue(card->workqueue);
  1064. lbs_remove_card(priv); /* will call free_netdev */
  1065. free_card:
  1066. free_if_spi_card(card);
  1067. teardown:
  1068. if (pdata->teardown)
  1069. pdata->teardown(spi);
  1070. out:
  1071. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  1072. return err;
  1073. }
  1074. static int __devexit libertas_spi_remove(struct spi_device *spi)
  1075. {
  1076. struct if_spi_card *card = spi_get_drvdata(spi);
  1077. struct lbs_private *priv = card->priv;
  1078. lbs_deb_spi("libertas_spi_remove\n");
  1079. lbs_deb_enter(LBS_DEB_SPI);
  1080. cancel_work_sync(&card->resume_work);
  1081. lbs_stop_card(priv);
  1082. lbs_remove_card(priv); /* will call free_netdev */
  1083. free_irq(spi->irq, card);
  1084. flush_workqueue(card->workqueue);
  1085. destroy_workqueue(card->workqueue);
  1086. if (card->pdata->teardown)
  1087. card->pdata->teardown(spi);
  1088. free_if_spi_card(card);
  1089. lbs_deb_leave(LBS_DEB_SPI);
  1090. return 0;
  1091. }
  1092. static int if_spi_suspend(struct device *dev)
  1093. {
  1094. struct spi_device *spi = to_spi_device(dev);
  1095. struct if_spi_card *card = spi_get_drvdata(spi);
  1096. if (!card->suspended) {
  1097. lbs_suspend(card->priv);
  1098. flush_workqueue(card->workqueue);
  1099. disable_irq(spi->irq);
  1100. if (card->pdata->teardown)
  1101. card->pdata->teardown(spi);
  1102. card->suspended = 1;
  1103. }
  1104. return 0;
  1105. }
  1106. static int if_spi_resume(struct device *dev)
  1107. {
  1108. struct spi_device *spi = to_spi_device(dev);
  1109. struct if_spi_card *card = spi_get_drvdata(spi);
  1110. /* Schedule delayed work */
  1111. schedule_work(&card->resume_work);
  1112. return 0;
  1113. }
  1114. static const struct dev_pm_ops if_spi_pm_ops = {
  1115. .suspend = if_spi_suspend,
  1116. .resume = if_spi_resume,
  1117. };
  1118. static struct spi_driver libertas_spi_driver = {
  1119. .probe = if_spi_probe,
  1120. .remove = __devexit_p(libertas_spi_remove),
  1121. .driver = {
  1122. .name = "libertas_spi",
  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");