if_spi.c 31 KB

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