if_spi.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  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. #include <linux/moduleparam.h>
  20. #include <linux/firmware.h>
  21. #include <linux/jiffies.h>
  22. #include <linux/list.h>
  23. #include <linux/netdevice.h>
  24. #include <linux/slab.h>
  25. #include <linux/spi/libertas_spi.h>
  26. #include <linux/spi/spi.h>
  27. #include "host.h"
  28. #include "decl.h"
  29. #include "defs.h"
  30. #include "dev.h"
  31. #include "if_spi.h"
  32. struct if_spi_packet {
  33. struct list_head list;
  34. u16 blen;
  35. u8 buffer[0] __attribute__((aligned(4)));
  36. };
  37. struct if_spi_card {
  38. struct spi_device *spi;
  39. struct lbs_private *priv;
  40. struct libertas_spi_platform_data *pdata;
  41. /* The card ID and card revision, as reported by the hardware. */
  42. u16 card_id;
  43. u8 card_rev;
  44. /* The last time that we initiated an SPU operation */
  45. unsigned long prev_xfer_time;
  46. int use_dummy_writes;
  47. unsigned long spu_port_delay;
  48. unsigned long spu_reg_delay;
  49. /* Handles all SPI communication (except for FW load) */
  50. struct workqueue_struct *workqueue;
  51. struct work_struct packet_work;
  52. struct work_struct resume_work;
  53. u8 cmd_buffer[IF_SPI_CMD_BUF_SIZE];
  54. /* A buffer of incoming packets from libertas core.
  55. * Since we can't sleep in hw_host_to_card, we have to buffer
  56. * them. */
  57. struct list_head cmd_packet_list;
  58. struct list_head data_packet_list;
  59. /* Protects cmd_packet_list and data_packet_list */
  60. spinlock_t buffer_lock;
  61. /* True is card suspended */
  62. u8 suspended;
  63. };
  64. static void free_if_spi_card(struct if_spi_card *card)
  65. {
  66. struct list_head *cursor, *next;
  67. struct if_spi_packet *packet;
  68. list_for_each_safe(cursor, next, &card->cmd_packet_list) {
  69. packet = container_of(cursor, struct if_spi_packet, list);
  70. list_del(&packet->list);
  71. kfree(packet);
  72. }
  73. list_for_each_safe(cursor, next, &card->data_packet_list) {
  74. packet = container_of(cursor, struct if_spi_packet, list);
  75. list_del(&packet->list);
  76. kfree(packet);
  77. }
  78. spi_set_drvdata(card->spi, NULL);
  79. kfree(card);
  80. }
  81. #define MODEL_8385 0x04
  82. #define MODEL_8686 0x0b
  83. #define MODEL_8688 0x10
  84. static const struct lbs_fw_table fw_table[] = {
  85. { MODEL_8385, "libertas/gspi8385_helper.bin", "libertas/gspi8385.bin" },
  86. { MODEL_8385, "libertas/gspi8385_hlp.bin", "libertas/gspi8385.bin" },
  87. { MODEL_8686, "libertas/gspi8686_v9_helper.bin", "libertas/gspi8686_v9.bin" },
  88. { MODEL_8686, "libertas/gspi8686_hlp.bin", "libertas/gspi8686.bin" },
  89. { MODEL_8688, "libertas/gspi8688_helper.bin", "libertas/gspi8688.bin" },
  90. { 0, NULL, NULL }
  91. };
  92. MODULE_FIRMWARE("libertas/gspi8385_helper.bin");
  93. MODULE_FIRMWARE("libertas/gspi8385_hlp.bin");
  94. MODULE_FIRMWARE("libertas/gspi8385.bin");
  95. MODULE_FIRMWARE("libertas/gspi8686_v9_helper.bin");
  96. MODULE_FIRMWARE("libertas/gspi8686_v9.bin");
  97. MODULE_FIRMWARE("libertas/gspi8686_hlp.bin");
  98. MODULE_FIRMWARE("libertas/gspi8686.bin");
  99. MODULE_FIRMWARE("libertas/gspi8688_helper.bin");
  100. MODULE_FIRMWARE("libertas/gspi8688.bin");
  101. /*
  102. * SPI Interface Unit Routines
  103. *
  104. * The SPU sits between the host and the WLAN module.
  105. * All communication with the firmware is through SPU transactions.
  106. *
  107. * First we have to put a SPU register name on the bus. Then we can
  108. * either read from or write to that register.
  109. *
  110. */
  111. static void spu_transaction_init(struct if_spi_card *card)
  112. {
  113. if (!time_after(jiffies, card->prev_xfer_time + 1)) {
  114. /* Unfortunately, the SPU requires a delay between successive
  115. * transactions. If our last transaction was more than a jiffy
  116. * ago, we have obviously already delayed enough.
  117. * If not, we have to busy-wait to be on the safe side. */
  118. ndelay(400);
  119. }
  120. }
  121. static void spu_transaction_finish(struct if_spi_card *card)
  122. {
  123. card->prev_xfer_time = jiffies;
  124. }
  125. /*
  126. * Write out a byte buffer to an SPI register,
  127. * using a series of 16-bit transfers.
  128. */
  129. static int spu_write(struct if_spi_card *card, u16 reg, const u8 *buf, int len)
  130. {
  131. int err = 0;
  132. __le16 reg_out = cpu_to_le16(reg | IF_SPI_WRITE_OPERATION_MASK);
  133. struct spi_message m;
  134. struct spi_transfer reg_trans;
  135. struct spi_transfer data_trans;
  136. spi_message_init(&m);
  137. memset(&reg_trans, 0, sizeof(reg_trans));
  138. memset(&data_trans, 0, sizeof(data_trans));
  139. /* You must give an even number of bytes to the SPU, even if it
  140. * doesn't care about the last one. */
  141. BUG_ON(len & 0x1);
  142. spu_transaction_init(card);
  143. /* write SPU register index */
  144. reg_trans.tx_buf = &reg_out;
  145. reg_trans.len = sizeof(reg_out);
  146. data_trans.tx_buf = buf;
  147. data_trans.len = len;
  148. spi_message_add_tail(&reg_trans, &m);
  149. spi_message_add_tail(&data_trans, &m);
  150. err = spi_sync(card->spi, &m);
  151. spu_transaction_finish(card);
  152. return err;
  153. }
  154. static inline int spu_write_u16(struct if_spi_card *card, u16 reg, u16 val)
  155. {
  156. __le16 buff;
  157. buff = cpu_to_le16(val);
  158. return spu_write(card, reg, (u8 *)&buff, sizeof(u16));
  159. }
  160. static inline int spu_reg_is_port_reg(u16 reg)
  161. {
  162. switch (reg) {
  163. case IF_SPI_IO_RDWRPORT_REG:
  164. case IF_SPI_CMD_RDWRPORT_REG:
  165. case IF_SPI_DATA_RDWRPORT_REG:
  166. return 1;
  167. default:
  168. return 0;
  169. }
  170. }
  171. static int spu_read(struct if_spi_card *card, u16 reg, u8 *buf, int len)
  172. {
  173. unsigned int delay;
  174. int err = 0;
  175. __le16 reg_out = cpu_to_le16(reg | IF_SPI_READ_OPERATION_MASK);
  176. struct spi_message m;
  177. struct spi_transfer reg_trans;
  178. struct spi_transfer dummy_trans;
  179. struct spi_transfer data_trans;
  180. /*
  181. * You must take an even number of bytes from the SPU, even if you
  182. * don't care about the last one.
  183. */
  184. BUG_ON(len & 0x1);
  185. spu_transaction_init(card);
  186. spi_message_init(&m);
  187. memset(&reg_trans, 0, sizeof(reg_trans));
  188. memset(&dummy_trans, 0, sizeof(dummy_trans));
  189. memset(&data_trans, 0, sizeof(data_trans));
  190. /* write SPU register index */
  191. reg_trans.tx_buf = &reg_out;
  192. reg_trans.len = sizeof(reg_out);
  193. spi_message_add_tail(&reg_trans, &m);
  194. delay = spu_reg_is_port_reg(reg) ? card->spu_port_delay :
  195. card->spu_reg_delay;
  196. if (card->use_dummy_writes) {
  197. /* Clock in dummy cycles while the SPU fills the FIFO */
  198. dummy_trans.len = delay / 8;
  199. spi_message_add_tail(&dummy_trans, &m);
  200. } else {
  201. /* Busy-wait while the SPU fills the FIFO */
  202. reg_trans.delay_usecs =
  203. DIV_ROUND_UP((100 + (delay * 10)), 1000);
  204. }
  205. /* read in data */
  206. data_trans.rx_buf = buf;
  207. data_trans.len = len;
  208. spi_message_add_tail(&data_trans, &m);
  209. err = spi_sync(card->spi, &m);
  210. spu_transaction_finish(card);
  211. return err;
  212. }
  213. /* Read 16 bits from an SPI register */
  214. static inline int spu_read_u16(struct if_spi_card *card, u16 reg, u16 *val)
  215. {
  216. __le16 buf;
  217. int ret;
  218. ret = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  219. if (ret == 0)
  220. *val = le16_to_cpup(&buf);
  221. return ret;
  222. }
  223. /*
  224. * Read 32 bits from an SPI register.
  225. * The low 16 bits are read first.
  226. */
  227. static int spu_read_u32(struct if_spi_card *card, u16 reg, u32 *val)
  228. {
  229. __le32 buf;
  230. int err;
  231. err = spu_read(card, reg, (u8 *)&buf, sizeof(buf));
  232. if (!err)
  233. *val = le32_to_cpup(&buf);
  234. return err;
  235. }
  236. /*
  237. * Keep reading 16 bits from an SPI register until you get the correct result.
  238. *
  239. * If mask = 0, the correct result is any non-zero number.
  240. * If mask != 0, the correct result is any number where
  241. * number & target_mask == target
  242. *
  243. * Returns -ETIMEDOUT if a second passes without the correct result.
  244. */
  245. static int spu_wait_for_u16(struct if_spi_card *card, u16 reg,
  246. u16 target_mask, u16 target)
  247. {
  248. int err;
  249. unsigned long timeout = jiffies + 5*HZ;
  250. while (1) {
  251. u16 val;
  252. err = spu_read_u16(card, reg, &val);
  253. if (err)
  254. return err;
  255. if (target_mask) {
  256. if ((val & target_mask) == target)
  257. return 0;
  258. } else {
  259. if (val)
  260. return 0;
  261. }
  262. udelay(100);
  263. if (time_after(jiffies, timeout)) {
  264. lbs_pr_err("%s: timeout with val=%02x, "
  265. "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. lbs_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. lbs_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. lbs_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. lbs_pr_err("firmware load device requested a larger "
  501. "tranfer than we are prepared to "
  502. "handle. (len = %d)\n", len);
  503. return -EIO;
  504. }
  505. if (len & 0x1) {
  506. lbs_deb_spi("%s: crc error\n", __func__);
  507. len &= ~0x1;
  508. *crc_err = 1;
  509. } else
  510. *crc_err = 0;
  511. return len;
  512. }
  513. static int if_spi_prog_main_firmware(struct if_spi_card *card,
  514. const struct firmware *firmware)
  515. {
  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. lbs_pr_err("%s: timed out waiting for initial "
  527. "scratch reg = 0\n", __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. lbs_pr_err("Firmware load wants more bytes "
  545. "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. lbs_pr_err("Too many CRC errors encountered "
  552. "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. lbs_pr_err("firmware load wants fewer bytes than "
  581. "we have to offer.\n");
  582. }
  583. /* Confirm firmware download */
  584. err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG,
  585. SUCCESSFUL_FW_DOWNLOAD_MAGIC);
  586. if (err) {
  587. lbs_pr_err("failed to confirm the firmware download\n");
  588. goto out;
  589. }
  590. out:
  591. if (err)
  592. lbs_pr_err("failed to load firmware (err=%d)\n", err);
  593. lbs_deb_leave_args(LBS_DEB_SPI, "err %d", err);
  594. return err;
  595. }
  596. /*
  597. * SPI Transfer Thread
  598. *
  599. * The SPI worker handles all SPI transfers, so there is no need for a lock.
  600. */
  601. /* Move a command from the card to the host */
  602. static int if_spi_c2h_cmd(struct if_spi_card *card)
  603. {
  604. struct lbs_private *priv = card->priv;
  605. unsigned long flags;
  606. int err = 0;
  607. u16 len;
  608. u8 i;
  609. /*
  610. * We need a buffer big enough to handle whatever people send to
  611. * hw_host_to_card
  612. */
  613. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
  614. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
  615. /*
  616. * It's just annoying if the buffer size isn't a multiple of 4, because
  617. * then we might have len < IF_SPI_CMD_BUF_SIZE but
  618. * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
  619. */
  620. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
  621. lbs_deb_enter(LBS_DEB_SPI);
  622. /* How many bytes are there to read? */
  623. err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len);
  624. if (err)
  625. goto out;
  626. if (!len) {
  627. lbs_pr_err("%s: error: card has no data for host\n",
  628. __func__);
  629. err = -EINVAL;
  630. goto out;
  631. } else if (len > IF_SPI_CMD_BUF_SIZE) {
  632. lbs_pr_err("%s: error: response packet too large: "
  633. "%d bytes, but maximum is %d\n",
  634. __func__, len, IF_SPI_CMD_BUF_SIZE);
  635. err = -EINVAL;
  636. goto out;
  637. }
  638. /* Read the data from the WLAN module into our command buffer */
  639. err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG,
  640. card->cmd_buffer, ALIGN(len, 4));
  641. if (err)
  642. goto out;
  643. spin_lock_irqsave(&priv->driver_lock, flags);
  644. i = (priv->resp_idx == 0) ? 1 : 0;
  645. BUG_ON(priv->resp_len[i]);
  646. priv->resp_len[i] = len;
  647. memcpy(priv->resp_buf[i], card->cmd_buffer, len);
  648. lbs_notify_command_response(priv, i);
  649. spin_unlock_irqrestore(&priv->driver_lock, flags);
  650. out:
  651. if (err)
  652. lbs_pr_err("%s: err=%d\n", __func__, err);
  653. lbs_deb_leave(LBS_DEB_SPI);
  654. return err;
  655. }
  656. /* Move data from the card to the host */
  657. static int if_spi_c2h_data(struct if_spi_card *card)
  658. {
  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. lbs_pr_err("%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. lbs_pr_err("%s: error: card has %d bytes of data, but "
  675. "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. lbs_pr_err("%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. 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. lbs_pr_err("can't transfer buffer of type %d\n", type);
  723. err = -EINVAL;
  724. goto out;
  725. }
  726. /* Write the data to the card */
  727. err = spu_write(card, port_reg, packet->buffer, packet->blen);
  728. if (err)
  729. goto out;
  730. out:
  731. kfree(packet);
  732. if (err)
  733. lbs_pr_err("%s: error %d\n", __func__, err);
  734. }
  735. /* Inform the host about a card event */
  736. static void if_spi_e2h(struct if_spi_card *card)
  737. {
  738. int err = 0;
  739. u32 cause;
  740. struct lbs_private *priv = card->priv;
  741. err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause);
  742. if (err)
  743. goto out;
  744. /* re-enable the card event interrupt */
  745. spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  746. ~IF_SPI_HICU_CARD_EVENT);
  747. /* generate a card interrupt */
  748. spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, IF_SPI_CIC_HOST_EVENT);
  749. lbs_queue_event(priv, cause & 0xff);
  750. out:
  751. if (err)
  752. lbs_pr_err("%s: error %d\n", __func__, err);
  753. }
  754. static void if_spi_host_to_card_worker(struct work_struct *work)
  755. {
  756. int err;
  757. struct if_spi_card *card;
  758. u16 hiStatus;
  759. unsigned long flags;
  760. struct if_spi_packet *packet;
  761. card = container_of(work, struct if_spi_card, packet_work);
  762. lbs_deb_enter(LBS_DEB_SPI);
  763. /*
  764. * Read the host interrupt status register to see what we
  765. * can do.
  766. */
  767. err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  768. &hiStatus);
  769. if (err) {
  770. lbs_pr_err("I/O error\n");
  771. goto err;
  772. }
  773. if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) {
  774. err = if_spi_c2h_cmd(card);
  775. if (err)
  776. goto err;
  777. }
  778. if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) {
  779. err = if_spi_c2h_data(card);
  780. if (err)
  781. goto err;
  782. }
  783. /*
  784. * workaround: in PS mode, the card does not set the Command
  785. * Download Ready bit, but it sets TX Download Ready.
  786. */
  787. if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
  788. (card->priv->psstate != PS_STATE_FULL_POWER &&
  789. (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
  790. /*
  791. * This means two things. First of all,
  792. * if there was a previous command sent, the card has
  793. * successfully received it.
  794. * Secondly, it is now ready to download another
  795. * command.
  796. */
  797. lbs_host_to_card_done(card->priv);
  798. /* Do we have any command packets from the host to send? */
  799. packet = NULL;
  800. spin_lock_irqsave(&card->buffer_lock, flags);
  801. if (!list_empty(&card->cmd_packet_list)) {
  802. packet = (struct if_spi_packet *)(card->
  803. cmd_packet_list.next);
  804. list_del(&packet->list);
  805. }
  806. spin_unlock_irqrestore(&card->buffer_lock, flags);
  807. if (packet)
  808. if_spi_h2c(card, packet, MVMS_CMD);
  809. }
  810. if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
  811. /* Do we have any data packets from the host to send? */
  812. packet = NULL;
  813. spin_lock_irqsave(&card->buffer_lock, flags);
  814. if (!list_empty(&card->data_packet_list)) {
  815. packet = (struct if_spi_packet *)(card->
  816. data_packet_list.next);
  817. list_del(&packet->list);
  818. }
  819. spin_unlock_irqrestore(&card->buffer_lock, flags);
  820. if (packet)
  821. if_spi_h2c(card, packet, MVMS_DAT);
  822. }
  823. if (hiStatus & IF_SPI_HIST_CARD_EVENT)
  824. if_spi_e2h(card);
  825. err:
  826. if (err)
  827. lbs_pr_err("%s: got error %d\n", __func__, err);
  828. lbs_deb_leave(LBS_DEB_SPI);
  829. }
  830. /*
  831. * Host to Card
  832. *
  833. * Called from Libertas to transfer some data to the WLAN device
  834. * We can't sleep here.
  835. */
  836. static int if_spi_host_to_card(struct lbs_private *priv,
  837. u8 type, u8 *buf, u16 nb)
  838. {
  839. int err = 0;
  840. unsigned long flags;
  841. struct if_spi_card *card = priv->card;
  842. struct if_spi_packet *packet;
  843. u16 blen;
  844. lbs_deb_enter_args(LBS_DEB_SPI, "type %d, bytes %d", type, nb);
  845. if (nb == 0) {
  846. lbs_pr_err("%s: invalid size requested: %d\n", __func__, nb);
  847. err = -EINVAL;
  848. goto out;
  849. }
  850. blen = ALIGN(nb, 4);
  851. packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
  852. if (!packet) {
  853. err = -ENOMEM;
  854. goto out;
  855. }
  856. packet->blen = blen;
  857. memcpy(packet->buffer, buf, nb);
  858. memset(packet->buffer + nb, 0, blen - nb);
  859. switch (type) {
  860. case MVMS_CMD:
  861. priv->dnld_sent = DNLD_CMD_SENT;
  862. spin_lock_irqsave(&card->buffer_lock, flags);
  863. list_add_tail(&packet->list, &card->cmd_packet_list);
  864. spin_unlock_irqrestore(&card->buffer_lock, flags);
  865. break;
  866. case MVMS_DAT:
  867. priv->dnld_sent = DNLD_DATA_SENT;
  868. spin_lock_irqsave(&card->buffer_lock, flags);
  869. list_add_tail(&packet->list, &card->data_packet_list);
  870. spin_unlock_irqrestore(&card->buffer_lock, flags);
  871. break;
  872. default:
  873. lbs_pr_err("can't transfer buffer of type %d", type);
  874. err = -EINVAL;
  875. break;
  876. }
  877. /* Queue spi xfer work */
  878. queue_work(card->workqueue, &card->packet_work);
  879. out:
  880. lbs_deb_leave_args(LBS_DEB_SPI, "err=%d", err);
  881. return err;
  882. }
  883. /*
  884. * Host Interrupts
  885. *
  886. * Service incoming interrupts from the WLAN device. We can't sleep here, so
  887. * don't try to talk on the SPI bus, just queue the SPI xfer work.
  888. */
  889. static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
  890. {
  891. struct if_spi_card *card = dev_id;
  892. queue_work(card->workqueue, &card->packet_work);
  893. return IRQ_HANDLED;
  894. }
  895. /*
  896. * SPI callbacks
  897. */
  898. static int if_spi_init_card(struct if_spi_card *card)
  899. {
  900. struct spi_device *spi = card->spi;
  901. int err, i;
  902. u32 scratch;
  903. const struct firmware *helper = NULL;
  904. const struct firmware *mainfw = NULL;
  905. lbs_deb_enter(LBS_DEB_SPI);
  906. err = spu_init(card, card->pdata->use_dummy_writes);
  907. if (err)
  908. goto out;
  909. err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
  910. if (err)
  911. goto out;
  912. err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
  913. if (err)
  914. goto out;
  915. if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
  916. lbs_deb_spi("Firmware is already loaded for "
  917. "Marvell WLAN 802.11 adapter\n");
  918. else {
  919. /* Check if we support this card */
  920. for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
  921. if (card->card_id == fw_table[i].model)
  922. break;
  923. }
  924. if (i == ARRAY_SIZE(fw_table)) {
  925. lbs_pr_err("Unsupported chip_id: 0x%02x\n",
  926. card->card_id);
  927. err = -ENODEV;
  928. goto out;
  929. }
  930. err = lbs_get_firmware(&card->spi->dev, NULL, NULL,
  931. card->card_id, &fw_table[0], &helper,
  932. &mainfw);
  933. if (err) {
  934. lbs_pr_err("failed to find firmware (%d)\n", err);
  935. goto out;
  936. }
  937. lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
  938. "(chip_id = 0x%04x, chip_rev = 0x%02x) "
  939. "attached to SPI bus_num %d, chip_select %d. "
  940. "spi->max_speed_hz=%d\n",
  941. card->card_id, card->card_rev,
  942. spi->master->bus_num, spi->chip_select,
  943. spi->max_speed_hz);
  944. err = if_spi_prog_helper_firmware(card, helper);
  945. if (err)
  946. goto out;
  947. err = if_spi_prog_main_firmware(card, mainfw);
  948. if (err)
  949. goto out;
  950. lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
  951. }
  952. err = spu_set_interrupt_mode(card, 0, 1);
  953. if (err)
  954. goto out;
  955. out:
  956. if (helper)
  957. release_firmware(helper);
  958. if (mainfw)
  959. release_firmware(mainfw);
  960. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  961. return err;
  962. }
  963. static void if_spi_resume_worker(struct work_struct *work)
  964. {
  965. struct if_spi_card *card;
  966. card = container_of(work, struct if_spi_card, resume_work);
  967. if (card->suspended) {
  968. if (card->pdata->setup)
  969. card->pdata->setup(card->spi);
  970. /* Init card ... */
  971. if_spi_init_card(card);
  972. enable_irq(card->spi->irq);
  973. /* And resume it ... */
  974. lbs_resume(card->priv);
  975. card->suspended = 0;
  976. }
  977. }
  978. static int __devinit if_spi_probe(struct spi_device *spi)
  979. {
  980. struct if_spi_card *card;
  981. struct lbs_private *priv = NULL;
  982. struct libertas_spi_platform_data *pdata = spi->dev.platform_data;
  983. int err = 0;
  984. lbs_deb_enter(LBS_DEB_SPI);
  985. if (!pdata) {
  986. err = -EINVAL;
  987. goto out;
  988. }
  989. if (pdata->setup) {
  990. err = pdata->setup(spi);
  991. if (err)
  992. goto out;
  993. }
  994. /* Allocate card structure to represent this specific device */
  995. card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
  996. if (!card) {
  997. err = -ENOMEM;
  998. goto teardown;
  999. }
  1000. spi_set_drvdata(spi, card);
  1001. card->pdata = pdata;
  1002. card->spi = spi;
  1003. card->prev_xfer_time = jiffies;
  1004. INIT_LIST_HEAD(&card->cmd_packet_list);
  1005. INIT_LIST_HEAD(&card->data_packet_list);
  1006. spin_lock_init(&card->buffer_lock);
  1007. /* Initialize the SPI Interface Unit */
  1008. /* Firmware load */
  1009. err = if_spi_init_card(card);
  1010. if (err)
  1011. goto free_card;
  1012. /*
  1013. * Register our card with libertas.
  1014. * This will call alloc_etherdev.
  1015. */
  1016. priv = lbs_add_card(card, &spi->dev);
  1017. if (!priv) {
  1018. err = -ENOMEM;
  1019. goto free_card;
  1020. }
  1021. card->priv = priv;
  1022. priv->setup_fw_on_resume = 1;
  1023. priv->card = card;
  1024. priv->hw_host_to_card = if_spi_host_to_card;
  1025. priv->enter_deep_sleep = NULL;
  1026. priv->exit_deep_sleep = NULL;
  1027. priv->reset_deep_sleep_wakeup = NULL;
  1028. priv->fw_ready = 1;
  1029. /* Initialize interrupt handling stuff. */
  1030. card->workqueue = create_workqueue("libertas_spi");
  1031. INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
  1032. INIT_WORK(&card->resume_work, if_spi_resume_worker);
  1033. err = request_irq(spi->irq, if_spi_host_interrupt,
  1034. IRQF_TRIGGER_FALLING, "libertas_spi", card);
  1035. if (err) {
  1036. lbs_pr_err("can't get host irq line-- request_irq failed\n");
  1037. goto terminate_workqueue;
  1038. }
  1039. /*
  1040. * Start the card.
  1041. * This will call register_netdev, and we'll start
  1042. * getting interrupts...
  1043. */
  1044. err = lbs_start_card(priv);
  1045. if (err)
  1046. goto release_irq;
  1047. lbs_deb_spi("Finished initializing WLAN module.\n");
  1048. /* successful exit */
  1049. goto out;
  1050. release_irq:
  1051. free_irq(spi->irq, card);
  1052. terminate_workqueue:
  1053. flush_workqueue(card->workqueue);
  1054. destroy_workqueue(card->workqueue);
  1055. lbs_remove_card(priv); /* will call free_netdev */
  1056. free_card:
  1057. free_if_spi_card(card);
  1058. teardown:
  1059. if (pdata->teardown)
  1060. pdata->teardown(spi);
  1061. out:
  1062. lbs_deb_leave_args(LBS_DEB_SPI, "err %d\n", err);
  1063. return err;
  1064. }
  1065. static int __devexit libertas_spi_remove(struct spi_device *spi)
  1066. {
  1067. struct if_spi_card *card = spi_get_drvdata(spi);
  1068. struct lbs_private *priv = card->priv;
  1069. lbs_deb_spi("libertas_spi_remove\n");
  1070. lbs_deb_enter(LBS_DEB_SPI);
  1071. cancel_work_sync(&card->resume_work);
  1072. lbs_stop_card(priv);
  1073. lbs_remove_card(priv); /* will call free_netdev */
  1074. free_irq(spi->irq, card);
  1075. flush_workqueue(card->workqueue);
  1076. destroy_workqueue(card->workqueue);
  1077. if (card->pdata->teardown)
  1078. card->pdata->teardown(spi);
  1079. free_if_spi_card(card);
  1080. lbs_deb_leave(LBS_DEB_SPI);
  1081. return 0;
  1082. }
  1083. static int if_spi_suspend(struct device *dev)
  1084. {
  1085. struct spi_device *spi = to_spi_device(dev);
  1086. struct if_spi_card *card = spi_get_drvdata(spi);
  1087. if (!card->suspended) {
  1088. lbs_suspend(card->priv);
  1089. flush_workqueue(card->workqueue);
  1090. disable_irq(spi->irq);
  1091. if (card->pdata->teardown)
  1092. card->pdata->teardown(spi);
  1093. card->suspended = 1;
  1094. }
  1095. return 0;
  1096. }
  1097. static int if_spi_resume(struct device *dev)
  1098. {
  1099. struct spi_device *spi = to_spi_device(dev);
  1100. struct if_spi_card *card = spi_get_drvdata(spi);
  1101. /* Schedule delayed work */
  1102. schedule_work(&card->resume_work);
  1103. return 0;
  1104. }
  1105. static const struct dev_pm_ops if_spi_pm_ops = {
  1106. .suspend = if_spi_suspend,
  1107. .resume = if_spi_resume,
  1108. };
  1109. static struct spi_driver libertas_spi_driver = {
  1110. .probe = if_spi_probe,
  1111. .remove = __devexit_p(libertas_spi_remove),
  1112. .driver = {
  1113. .name = "libertas_spi",
  1114. .bus = &spi_bus_type,
  1115. .owner = THIS_MODULE,
  1116. .pm = &if_spi_pm_ops,
  1117. },
  1118. };
  1119. /*
  1120. * Module functions
  1121. */
  1122. static int __init if_spi_init_module(void)
  1123. {
  1124. int ret = 0;
  1125. lbs_deb_enter(LBS_DEB_SPI);
  1126. printk(KERN_INFO "libertas_spi: Libertas SPI driver\n");
  1127. ret = spi_register_driver(&libertas_spi_driver);
  1128. lbs_deb_leave(LBS_DEB_SPI);
  1129. return ret;
  1130. }
  1131. static void __exit if_spi_exit_module(void)
  1132. {
  1133. lbs_deb_enter(LBS_DEB_SPI);
  1134. spi_unregister_driver(&libertas_spi_driver);
  1135. lbs_deb_leave(LBS_DEB_SPI);
  1136. }
  1137. module_init(if_spi_init_module);
  1138. module_exit(if_spi_exit_module);
  1139. MODULE_DESCRIPTION("Libertas SPI WLAN Driver");
  1140. MODULE_AUTHOR("Andrey Yurovsky <andrey@cozybit.com>, "
  1141. "Colin McCabe <colin@cozybit.com>");
  1142. MODULE_LICENSE("GPL");
  1143. MODULE_ALIAS("spi:libertas_spi");