if_spi.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329
  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/moduleparam.h>
  21. #include <linux/firmware.h>
  22. #include <linux/jiffies.h>
  23. #include <linux/list.h>
  24. #include <linux/netdevice.h>
  25. #include <linux/slab.h>
  26. #include <linux/spi/libertas_spi.h>
  27. #include <linux/spi/spi.h>
  28. #include "host.h"
  29. #include "decl.h"
  30. #include "defs.h"
  31. #include "dev.h"
  32. #include "if_spi.h"
  33. struct if_spi_packet {
  34. struct list_head list;
  35. u16 blen;
  36. u8 buffer[0] __attribute__((aligned(4)));
  37. };
  38. struct if_spi_card {
  39. struct spi_device *spi;
  40. struct lbs_private *priv;
  41. struct libertas_spi_platform_data *pdata;
  42. /* The card ID and card revision, as reported by the hardware. */
  43. u16 card_id;
  44. u8 card_rev;
  45. /* The last time that we initiated an SPU operation */
  46. unsigned long prev_xfer_time;
  47. int use_dummy_writes;
  48. unsigned long spu_port_delay;
  49. unsigned long spu_reg_delay;
  50. /* Handles all SPI communication (except for FW load) */
  51. struct workqueue_struct *workqueue;
  52. struct work_struct packet_work;
  53. struct work_struct resume_work;
  54. u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
  55. /* A buffer of incoming packets from libertas core.
  56. * Since we can't sleep in hw_host_to_card, we have to buffer
  57. * them. */
  58. struct list_head cmd_packet_list;
  59. struct list_head data_packet_list;
  60. /* Protects cmd_packet_list and data_packet_list */
  61. spinlock_t buffer_lock;
  62. /* True is card suspended */
  63. u8 suspended;
  64. };
  65. static void free_if_spi_card(struct if_spi_card *card)
  66. {
  67. struct list_head *cursor, *next;
  68. struct if_spi_packet *packet;
  69. list_for_each_safe(cursor, next, &card->cmd_packet_list) {
  70. packet = container_of(cursor, struct if_spi_packet, list);
  71. list_del(&packet->list);
  72. kfree(packet);
  73. }
  74. list_for_each_safe(cursor, next, &card->data_packet_list) {
  75. packet = container_of(cursor, struct if_spi_packet, list);
  76. list_del(&packet->list);
  77. kfree(packet);
  78. }
  79. spi_set_drvdata(card->spi, NULL);
  80. kfree(card);
  81. }
  82. #define MODEL_8385 0x04
  83. #define MODEL_8686 0x0b
  84. #define MODEL_8688 0x10
  85. static const struct lbs_fw_table fw_table[] = {
  86. { MODEL_8385, "libertas/gspi8385_helper.bin", "libertas/gspi8385.bin" },
  87. { MODEL_8385, "libertas/gspi8385_hlp.bin", "libertas/gspi8385.bin" },
  88. { MODEL_8686, "libertas/gspi8686_v9_helper.bin", "libertas/gspi8686_v9.bin" },
  89. { MODEL_8686, "libertas/gspi8686_hlp.bin", "libertas/gspi8686.bin" },
  90. { MODEL_8688, "libertas/gspi8688_helper.bin", "libertas/gspi8688.bin" },
  91. { 0, NULL, NULL }
  92. };
  93. MODULE_FIRMWARE("libertas/gspi8385_helper.bin");
  94. MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
  95. MODULE_FIRMWARE("libertas/gspi8385.bin");
  96. MODULE_FIRMWARE("libertas/gspi8686_v9_helper.bin");
  97. MODULE_FIRMWARE("libertas/gspi8686_v9.bin");
  98. MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
  99. MODULE_FIRMWARE("libertas/gspi8686.bin");
  100. MODULE_FIRMWARE("libertas/gspi8688_helper.bin");
  101. MODULE_FIRMWARE("libertas/gspi8688.bin");
  102. /*
  103. * SPI Interface Unit Routines
  104. *
  105. * The SPU sits between the host and the WLAN module.
  106. * All communication with the firmware is through SPU transactions.
  107. *
  108. * First we have to put a SPU register name on the bus. Then we can
  109. * either read from or write to that register.
  110. *
  111. */
  112. static void spu_transaction_init(struct if_spi_card *card)
  113. {
  114. if (!time_after(jiffies, card->prev_xfer_time + 1)) {
  115. /* Unfortunately, the SPU requires a delay between successive
  116. * transactions. If our last transaction was more than a jiffy
  117. * ago, we have obviously already delayed enough.
  118. * If not, we have to busy-wait to be on the safe side. */
  119. ndelay(400);
  120. }
  121. }
  122. static void spu_transaction_finish(struct if_spi_card *card)
  123. {
  124. card->prev_xfer_time = jiffies;
  125. }
  126. /*
  127. * Write out a byte buffer to an SPI register,
  128. * using a series of 16-bit transfers.
  129. */
  130. static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
  131. {
  132. int err = 0;
  133. __le16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK);
  134. struct spi_message m;
  135. struct spi_transfer reg_trans;
  136. struct spi_transfer data_trans;
  137. spi_message_init(&m);
  138. memset(&reg_trans, 0, sizeof(reg_trans));
  139. memset(&data_trans, 0, sizeof(data_trans));
  140. /* You must give an even number of bytes to the SPU, even if it
  141. * doesn't care about the last one. */
  142. BUG_ON(len & 0x1);
  143. spu_transaction_init(card);
  144. /* write SPU register index */
  145. reg_trans.tx_buf = &reg_out;
  146. reg_trans.len = sizeof(reg_out);
  147. data_trans.tx_buf = buf;
  148. data_trans.len = len;
  149. spi_message_add_tail(&reg_trans, &m);
  150. spi_message_add_tail(&data_trans, &m);
  151. err = spi_sync(card->spi, &m);
  152. spu_transaction_finish(card);
  153. return err;
  154. }
  155. static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val)
  156. {
  157. __le16 buff;
  158. buff = cpu_to_le16(val);
  159. return spu_write(card, reg, (u8 *)&buff, sizeof(u16));
  160. }
  161. static inline int spu_reg_is_port_reg(u16 reg)
  162. {
  163. switch (reg) {
  164. case IF_SPI_IO_RDWRPORT_REG:
  165. case IF_SPI_CMD_RDWRPORT_REG:
  166. case IF_SPI_DATA_RDWRPORT_REG:
  167. return 1;
  168. default:
  169. return 0;
  170. }
  171. }
  172. static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
  173. {
  174. unsigned int delay;
  175. int err = 0;
  176. __le16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK);
  177. struct spi_message m;
  178. struct spi_transfer reg_trans;
  179. struct spi_transfer dummy_trans;
  180. struct spi_transfer data_trans;
  181. /*
  182. * You must take an even number of bytes from the SPU, even if you
  183. * don't care about the last one.
  184. */
  185. BUG_ON(len & 0x1);
  186. spu_transaction_init(card);
  187. spi_message_init(&m);
  188. memset(&reg_trans, 0, sizeof(reg_trans));
  189. memset(&dummy_trans, 0, sizeof(dummy_trans));
  190. memset(&data_trans, 0, sizeof(data_trans));
  191. /* write SPU register index */
  192. reg_trans.tx_buf = &reg_out;
  193. reg_trans.len = sizeof(reg_out);
  194. spi_message_add_tail(&reg_trans, &m);
  195. delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay :
  196. card->spu_reg_delay;
  197. if (card->use_dummy_writes) {
  198. /* Clock in dummy cycles while the SPU fills the FIFO */
  199. dummy_trans.len = delay / 8;
  200. spi_message_add_tail(&dummy_trans, &m);
  201. } else {
  202. /* Busy-wait while the SPU fills the FIFO */
  203. reg_trans.delay_usecs =
  204. DIV_ROUND_UP((100 + (delay * 10)), 1000);
  205. }
  206. /* read in data */
  207. data_trans.rx_buf = buf;
  208. data_trans.len = len;
  209. spi_message_add_tail(&data_trans, &m);
  210. err = spi_sync(card->spi, &m);
  211. spu_transaction_finish(card);
  212. return err;
  213. }
  214. /* Read 16 bits from an SPI register */
  215. static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
  216. {
  217. __le16 buf;
  218. int ret;
  219. ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  220. if (ret == 0)
  221. *val = le16_to_cpup(&buf);
  222. return ret;
  223. }
  224. /*
  225. * Read 32 bits from an SPI register.
  226. * The low 16 bits are read first.
  227. */
  228. static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
  229. {
  230. __le32 buf;
  231. int err;
  232. err = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  233. if (!err)
  234. *val = le32_to_cpup(&buf);
  235. return err;
  236. }
  237. /*
  238. * Keep reading 16 bits from an SPI register until you get the correct result.
  239. *
  240. * If mask = 0, the correct result is any non-zero number.
  241. * If mask != 0, the correct result is any number where
  242. * number & target_mask == target
  243. *
  244. * Returns -ETIMEDOUT if a second passes without the correct result.
  245. */
  246. static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
  247. u16 target_mask, u16 target)
  248. {
  249. int err;
  250. unsigned long timeout = jiffies + 5*HZ;
  251. while (1) {
  252. u16 val;
  253. err = spu_read_u16(card, reg, &val);
  254. if (err)
  255. return err;
  256. if (target_mask) {
  257. if ((val & target_mask) == target)
  258. return 0;
  259. } else {
  260. if (val)
  261. return 0;
  262. }
  263. udelay(100);
  264. if (time_after(jiffies, timeout)) {
  265. pr_err("%s: timeout with val=%02x, target_mask=%02x, target=%02x\n",
  266. __func__, val, target_mask, target);
  267. return -ETIMEDOUT;
  268. }
  269. }
  270. }
  271. /*
  272. * Read 16 bits from an SPI register until you receive a specific value.
  273. * Returns -ETIMEDOUT if a 4 tries pass without success.
  274. */
  275. static int spu_wait_for_u32(struct if_spi_card *card, u32 reg, u32 target)
  276. {
  277. int err, try;
  278. for (try = 0; try < 4; ++try) {
  279. u32 val = 0;
  280. err = spu_read_u32(card, reg, &val);
  281. if (err)
  282. return err;
  283. if (val == target)
  284. return 0;
  285. mdelay(100);
  286. }
  287. return -ETIMEDOUT;
  288. }
  289. static int spu_set_interrupt_mode(struct if_spi_card *card,
  290. int suppress_host_int,
  291. int auto_int)
  292. {
  293. int err = 0;
  294. /*
  295. * We can suppress a host interrupt by clearing the appropriate
  296. * bit in the "host interrupt status mask" register
  297. */
  298. if (suppress_host_int) {
  299. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
  300. if (err)
  301. return err;
  302. } else {
  303. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG,
  304. IF_SPI_HISM_TX_DOWNLOAD_RDY |
  305. IF_SPI_HISM_RX_UPLOAD_RDY |
  306. IF_SPI_HISM_CMD_DOWNLOAD_RDY |
  307. IF_SPI_HISM_CARDEVENT |
  308. IF_SPI_HISM_CMD_UPLOAD_RDY);
  309. if (err)
  310. return err;
  311. }
  312. /*
  313. * If auto-interrupts are on, the completion of certain transactions
  314. * will trigger an interrupt automatically. If auto-interrupts
  315. * are off, we need to set the "Card Interrupt Cause" register to
  316. * trigger a card interrupt.
  317. */
  318. if (auto_int) {
  319. err = spu_write_u16(card, IF_SPI_HOST_INT_CTRL_REG,
  320. IF_SPI_HICT_TX_DOWNLOAD_OVER_AUTO |
  321. IF_SPI_HICT_RX_UPLOAD_OVER_AUTO |
  322. IF_SPI_HICT_CMD_DOWNLOAD_OVER_AUTO |
  323. IF_SPI_HICT_CMD_UPLOAD_OVER_AUTO);
  324. if (err)
  325. return err;
  326. } else {
  327. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_MASK_REG, 0);
  328. if (err)
  329. return err;
  330. }
  331. return err;
  332. }
  333. static int spu_get_chip_revision(struct if_spi_card *card,
  334. u16 *card_id, u8 *card_rev)
  335. {
  336. int err = 0;
  337. u32 dev_ctrl;
  338. err = spu_read_u32(card, IF_SPI_DEVICEID_CTRL_REG, &dev_ctrl);
  339. if (err)
  340. return err;
  341. *card_id = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_ID(dev_ctrl);
  342. *card_rev = IF_SPI_DEVICEID_CTRL_REG_TO_CARD_REV(dev_ctrl);
  343. return err;
  344. }
  345. static int spu_set_bus_mode(struct if_spi_card *card, u16 mode)
  346. {
  347. int err = 0;
  348. u16 rval;
  349. /* set bus mode */
  350. err = spu_write_u16(card, IF_SPI_SPU_BUS_MODE_REG, mode);
  351. if (err)
  352. return err;
  353. /* Check that we were able to read back what we just wrote. */
  354. err = spu_read_u16(card, IF_SPI_SPU_BUS_MODE_REG, &rval);
  355. if (err)
  356. return err;
  357. if ((rval & 0xF) != mode) {
  358. pr_err("Can't read bus mode register\n");
  359. return -EIO;
  360. }
  361. return 0;
  362. }
  363. static int spu_init(struct if_spi_card *card, int use_dummy_writes)
  364. {
  365. int err = 0;
  366. u32 delay;
  367. /*
  368. * We have to start up in timed delay mode so that we can safely
  369. * read the Delay Read Register.
  370. */
  371. card->use_dummy_writes = 0;
  372. err = spu_set_bus_mode(card,
  373. IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
  374. IF_SPI_BUS_MODE_DELAY_METHOD_TIMED |
  375. IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
  376. if (err)
  377. return err;
  378. card->spu_port_delay = 1000;
  379. card->spu_reg_delay = 1000;
  380. err = spu_read_u32(card, IF_SPI_DELAY_READ_REG, &delay);
  381. if (err)
  382. return err;
  383. card->spu_port_delay = delay & 0x0000ffff;
  384. card->spu_reg_delay = (delay & 0xffff0000) >> 16;
  385. /* If dummy clock delay mode has been requested, switch to it now */
  386. if (use_dummy_writes) {
  387. card->use_dummy_writes = 1;
  388. err = spu_set_bus_mode(card,
  389. IF_SPI_BUS_MODE_SPI_CLOCK_PHASE_RISING |
  390. IF_SPI_BUS_MODE_DELAY_METHOD_DUMMY_CLOCK |
  391. IF_SPI_BUS_MODE_16_BIT_ADDRESS_16_BIT_DATA);
  392. if (err)
  393. return err;
  394. }
  395. lbs_deb_spi("Initialized SPU unit. "
  396. "spu_port_delay=0x%04lx, spu_reg_delay=0x%04lx\n",
  397. card->spu_port_delay, card->spu_reg_delay);
  398. return err;
  399. }
  400. /*
  401. * Firmware Loading
  402. */
  403. static int if_spi_prog_helper_firmware(struct if_spi_card *card,
  404. const struct firmware *firmware)
  405. {
  406. int err = 0;
  407. int bytes_remaining;
  408. const u8 *fw;
  409. u8 temp[HELPER_FW_LOAD_CHUNK_SZ];
  410. lbs_deb_enter(LBS_DEB_SPI);
  411. err = spu_set_interrupt_mode(card, 1, 0);
  412. if (err)
  413. goto out;
  414. bytes_remaining = firmware->size;
  415. fw = firmware->data;
  416. /* Load helper firmware image */
  417. while (bytes_remaining > 0) {
  418. /*
  419. * Scratch pad 1 should contain the number of bytes we
  420. * want to download to the firmware
  421. */
  422. err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG,
  423. HELPER_FW_LOAD_CHUNK_SZ);
  424. if (err)
  425. goto out;
  426. err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  427. IF_SPI_HIST_CMD_DOWNLOAD_RDY,
  428. IF_SPI_HIST_CMD_DOWNLOAD_RDY);
  429. if (err)
  430. goto out;
  431. /*
  432. * Feed the data into the command read/write port reg
  433. * in chunks of 64 bytes
  434. */
  435. memset(temp, 0, sizeof(temp));
  436. memcpy(temp, fw,
  437. min(bytes_remaining, HELPER_FW_LOAD_CHUNK_SZ));
  438. mdelay(10);
  439. err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
  440. temp, HELPER_FW_LOAD_CHUNK_SZ);
  441. if (err)
  442. goto out;
  443. /* Interrupt the boot code */
  444. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  445. if (err)
  446. goto out;
  447. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
  448. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  449. if (err)
  450. goto out;
  451. bytes_remaining -= HELPER_FW_LOAD_CHUNK_SZ;
  452. fw += HELPER_FW_LOAD_CHUNK_SZ;
  453. }
  454. /*
  455. * Once the helper / single stage firmware download is complete,
  456. * write 0 to scratch pad 1 and interrupt the
  457. * bootloader. This completes the helper download.
  458. */
  459. err = spu_write_u16(card, IF_SPI_SCRATCH_1_REG, FIRMWARE_DNLD_OK);
  460. if (err)
  461. goto out;
  462. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  463. if (err)
  464. goto out;
  465. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG,
  466. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  467. goto out;
  468. lbs_deb_spi("waiting for helper to boot...\n");
  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");