if_spi.c 32 KB

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