if_spi.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  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. 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. out:
  468. if (err)
  469. pr_err("failed to load helper firmware (err=%d)\n", err);
  470. return err;
  471. }
  472. /*
  473. * Returns the length of the next packet the firmware expects us to send.
  474. * Sets crc_err if the previous transfer had a CRC error.
  475. */
  476. static int if_spi_prog_main_firmware_check_len(struct if_spi_card *card,
  477. int *crc_err)
  478. {
  479. u16 len;
  480. int err = 0;
  481. /*
  482. * wait until the host interrupt status register indicates
  483. * that we are ready to download
  484. */
  485. err = spu_wait_for_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  486. IF_SPI_HIST_CMD_DOWNLOAD_RDY,
  487. IF_SPI_HIST_CMD_DOWNLOAD_RDY);
  488. if (err) {
  489. pr_err("timed out waiting for host_int_status\n");
  490. return err;
  491. }
  492. /* Ask the device how many bytes of firmware it wants. */
  493. err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
  494. if (err)
  495. return err;
  496. if (len > IF_SPI_CMD_BUF_SIZE) {
  497. pr_err("firmware load device requested a larger transfer than we are prepared to handle (len = %d)\n",
  498. len);
  499. return -EIO;
  500. }
  501. if (len & 0x1) {
  502. lbs_deb_spi("%s: crc error\n", __func__);
  503. len &= ~0x1;
  504. *crc_err = 1;
  505. } else
  506. *crc_err = 0;
  507. return len;
  508. }
  509. static int if_spi_prog_main_firmware(struct if_spi_card *card,
  510. const struct firmware *firmware)
  511. {
  512. struct lbs_private *priv = card->priv;
  513. int len, prev_len;
  514. int bytes, crc_err = 0, err = 0;
  515. const u8 *fw;
  516. u16 num_crc_errs;
  517. err = spu_set_interrupt_mode(card, 1, 0);
  518. if (err)
  519. goto out;
  520. err = spu_wait_for_u16(card, IF_SPI_SCRATCH_1_REG, 0, 0);
  521. if (err) {
  522. netdev_err(priv->dev,
  523. "%s: timed out waiting for initial scratch reg = 0\n",
  524. __func__);
  525. goto out;
  526. }
  527. num_crc_errs = 0;
  528. prev_len = 0;
  529. bytes = firmware->size;
  530. fw = firmware->data;
  531. while ((len = if_spi_prog_main_firmware_check_len(card, &crc_err))) {
  532. if (len < 0) {
  533. err = len;
  534. goto out;
  535. }
  536. if (bytes < 0) {
  537. /*
  538. * If there are no more bytes left, we would normally
  539. * expect to have terminated with len = 0
  540. */
  541. netdev_err(priv->dev,
  542. "Firmware load wants more bytes than we have to offer.\n");
  543. break;
  544. }
  545. if (crc_err) {
  546. /* Previous transfer failed. */
  547. if (++num_crc_errs > MAX_MAIN_FW_LOAD_CRC_ERR) {
  548. pr_err("Too many CRC errors encountered in firmware load.\n");
  549. err = -EIO;
  550. goto out;
  551. }
  552. } else {
  553. /* Previous transfer succeeded. Advance counters. */
  554. bytes -= prev_len;
  555. fw += prev_len;
  556. }
  557. if (bytes < len) {
  558. memset(card->cmd_buffer, 0, len);
  559. memcpy(card->cmd_buffer, fw, bytes);
  560. } else
  561. memcpy(card->cmd_buffer, fw, len);
  562. err = spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG, 0);
  563. if (err)
  564. goto out;
  565. err = spu_write(card, IF_SPI_CMD_RDWRPORT_REG,
  566. card->cmd_buffer, len);
  567. if (err)
  568. goto out;
  569. err = spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG ,
  570. IF_SPI_CIC_CMD_DOWNLOAD_OVER);
  571. if (err)
  572. goto out;
  573. prev_len = len;
  574. }
  575. if (bytes > prev_len) {
  576. pr_err("firmware load wants fewer bytes than we have to offer\n");
  577. }
  578. /* Confirm firmware download */
  579. err = spu_wait_for_u32(card, IF_SPI_SCRATCH_4_REG,
  580. SUCCESSFUL_FW_DOWNLOAD_MAGIC);
  581. if (err) {
  582. pr_err("failed to confirm the firmware download\n");
  583. goto out;
  584. }
  585. out:
  586. if (err)
  587. pr_err("failed to load firmware (err=%d)\n", err);
  588. return err;
  589. }
  590. /*
  591. * SPI Transfer Thread
  592. *
  593. * The SPI worker handles all SPI transfers, so there is no need for a lock.
  594. */
  595. /* Move a command from the card to the host */
  596. static int if_spi_c2h_cmd(struct if_spi_card *card)
  597. {
  598. struct lbs_private *priv = card->priv;
  599. unsigned long flags;
  600. int err = 0;
  601. u16 len;
  602. u8 i;
  603. /*
  604. * We need a buffer big enough to handle whatever people send to
  605. * hw_host_to_card
  606. */
  607. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_CMD_BUFFER_SIZE);
  608. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE < LBS_UPLD_SIZE);
  609. /*
  610. * It's just annoying if the buffer size isn't a multiple of 4, because
  611. * then we might have len < IF_SPI_CMD_BUF_SIZE but
  612. * ALIGN(len, 4) > IF_SPI_CMD_BUF_SIZE
  613. */
  614. BUILD_BUG_ON(IF_SPI_CMD_BUF_SIZE % 4 != 0);
  615. /* How many bytes are there to read? */
  616. err = spu_read_u16(card, IF_SPI_SCRATCH_2_REG, &len);
  617. if (err)
  618. goto out;
  619. if (!len) {
  620. netdev_err(priv->dev, "%s: error: card has no data for host\n",
  621. __func__);
  622. err = -EINVAL;
  623. goto out;
  624. } else if (len > IF_SPI_CMD_BUF_SIZE) {
  625. netdev_err(priv->dev,
  626. "%s: error: response packet too large: %d bytes, but maximum is %d\n",
  627. __func__, len, IF_SPI_CMD_BUF_SIZE);
  628. err = -EINVAL;
  629. goto out;
  630. }
  631. /* Read the data from the WLAN module into our command buffer */
  632. err = spu_read(card, IF_SPI_CMD_RDWRPORT_REG,
  633. card->cmd_buffer, ALIGN(len, 4));
  634. if (err)
  635. goto out;
  636. spin_lock_irqsave(&priv->driver_lock, flags);
  637. i = (priv->resp_idx == 0) ? 1 : 0;
  638. BUG_ON(priv->resp_len[i]);
  639. priv->resp_len[i] = len;
  640. memcpy(priv->resp_buf[i], card->cmd_buffer, len);
  641. lbs_notify_command_response(priv, i);
  642. spin_unlock_irqrestore(&priv->driver_lock, flags);
  643. out:
  644. if (err)
  645. netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
  646. return err;
  647. }
  648. /* Move data from the card to the host */
  649. static int if_spi_c2h_data(struct if_spi_card *card)
  650. {
  651. struct lbs_private *priv = card->priv;
  652. struct sk_buff *skb;
  653. char *data;
  654. u16 len;
  655. int err = 0;
  656. /* How many bytes are there to read? */
  657. err = spu_read_u16(card, IF_SPI_SCRATCH_1_REG, &len);
  658. if (err)
  659. goto out;
  660. if (!len) {
  661. netdev_err(priv->dev, "%s: error: card has no data for host\n",
  662. __func__);
  663. err = -EINVAL;
  664. goto out;
  665. } else if (len > MRVDRV_ETH_RX_PACKET_BUFFER_SIZE) {
  666. netdev_err(priv->dev,
  667. "%s: error: card has %d bytes of data, but our maximum skb size is %zu\n",
  668. __func__, len, MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
  669. err = -EINVAL;
  670. goto out;
  671. }
  672. /* TODO: should we allocate a smaller skb if we have less data? */
  673. skb = dev_alloc_skb(MRVDRV_ETH_RX_PACKET_BUFFER_SIZE);
  674. if (!skb) {
  675. err = -ENOBUFS;
  676. goto out;
  677. }
  678. skb_reserve(skb, IPFIELD_ALIGN_OFFSET);
  679. data = skb_put(skb, len);
  680. /* Read the data from the WLAN module into our skb... */
  681. err = spu_read(card, IF_SPI_DATA_RDWRPORT_REG, data, ALIGN(len, 4));
  682. if (err)
  683. goto free_skb;
  684. /* pass the SKB to libertas */
  685. err = lbs_process_rxed_packet(card->priv, skb);
  686. if (err)
  687. goto free_skb;
  688. /* success */
  689. goto out;
  690. free_skb:
  691. dev_kfree_skb(skb);
  692. out:
  693. if (err)
  694. netdev_err(priv->dev, "%s: err=%d\n", __func__, err);
  695. return err;
  696. }
  697. /* Move data or a command from the host to the card. */
  698. static void if_spi_h2c(struct if_spi_card *card,
  699. struct if_spi_packet *packet, int type)
  700. {
  701. struct lbs_private *priv = card->priv;
  702. int err = 0;
  703. u16 int_type, port_reg;
  704. switch (type) {
  705. case MVMS_DAT:
  706. int_type = IF_SPI_CIC_TX_DOWNLOAD_OVER;
  707. port_reg = IF_SPI_DATA_RDWRPORT_REG;
  708. break;
  709. case MVMS_CMD:
  710. int_type = IF_SPI_CIC_CMD_DOWNLOAD_OVER;
  711. port_reg = IF_SPI_CMD_RDWRPORT_REG;
  712. break;
  713. default:
  714. netdev_err(priv->dev, "can't transfer buffer of type %d\n",
  715. type);
  716. err = -EINVAL;
  717. goto out;
  718. }
  719. /* Write the data to the card */
  720. err = spu_write(card, port_reg, packet->buffer, packet->blen);
  721. if (err)
  722. goto out;
  723. out:
  724. kfree(packet);
  725. if (err)
  726. netdev_err(priv->dev, "%s: error %d\n", __func__, err);
  727. }
  728. /* Inform the host about a card event */
  729. static void if_spi_e2h(struct if_spi_card *card)
  730. {
  731. int err = 0;
  732. u32 cause;
  733. struct lbs_private *priv = card->priv;
  734. err = spu_read_u32(card, IF_SPI_SCRATCH_3_REG, &cause);
  735. if (err)
  736. goto out;
  737. /* re-enable the card event interrupt */
  738. spu_write_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  739. ~IF_SPI_HICU_CARD_EVENT);
  740. /* generate a card interrupt */
  741. spu_write_u16(card, IF_SPI_CARD_INT_CAUSE_REG, IF_SPI_CIC_HOST_EVENT);
  742. lbs_queue_event(priv, cause & 0xff);
  743. out:
  744. if (err)
  745. netdev_err(priv->dev, "%s: error %d\n", __func__, err);
  746. }
  747. static void if_spi_host_to_card_worker(struct work_struct *work)
  748. {
  749. int err;
  750. struct if_spi_card *card;
  751. u16 hiStatus;
  752. unsigned long flags;
  753. struct if_spi_packet *packet;
  754. struct lbs_private *priv;
  755. card = container_of(work, struct if_spi_card, packet_work);
  756. priv = card->priv;
  757. /*
  758. * Read the host interrupt status register to see what we
  759. * can do.
  760. */
  761. err = spu_read_u16(card, IF_SPI_HOST_INT_STATUS_REG,
  762. &hiStatus);
  763. if (err) {
  764. netdev_err(priv->dev, "I/O error\n");
  765. goto err;
  766. }
  767. if (hiStatus & IF_SPI_HIST_CMD_UPLOAD_RDY) {
  768. err = if_spi_c2h_cmd(card);
  769. if (err)
  770. goto err;
  771. }
  772. if (hiStatus & IF_SPI_HIST_RX_UPLOAD_RDY) {
  773. err = if_spi_c2h_data(card);
  774. if (err)
  775. goto err;
  776. }
  777. /*
  778. * workaround: in PS mode, the card does not set the Command
  779. * Download Ready bit, but it sets TX Download Ready.
  780. */
  781. if (hiStatus & IF_SPI_HIST_CMD_DOWNLOAD_RDY ||
  782. (card->priv->psstate != PS_STATE_FULL_POWER &&
  783. (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY))) {
  784. /*
  785. * This means two things. First of all,
  786. * if there was a previous command sent, the card has
  787. * successfully received it.
  788. * Secondly, it is now ready to download another
  789. * command.
  790. */
  791. lbs_host_to_card_done(card->priv);
  792. /* Do we have any command packets from the host to send? */
  793. packet = NULL;
  794. spin_lock_irqsave(&card->buffer_lock, flags);
  795. if (!list_empty(&card->cmd_packet_list)) {
  796. packet = (struct if_spi_packet *)(card->
  797. cmd_packet_list.next);
  798. list_del(&packet->list);
  799. }
  800. spin_unlock_irqrestore(&card->buffer_lock, flags);
  801. if (packet)
  802. if_spi_h2c(card, packet, MVMS_CMD);
  803. }
  804. if (hiStatus & IF_SPI_HIST_TX_DOWNLOAD_RDY) {
  805. /* Do we have any data packets from the host to send? */
  806. packet = NULL;
  807. spin_lock_irqsave(&card->buffer_lock, flags);
  808. if (!list_empty(&card->data_packet_list)) {
  809. packet = (struct if_spi_packet *)(card->
  810. data_packet_list.next);
  811. list_del(&packet->list);
  812. }
  813. spin_unlock_irqrestore(&card->buffer_lock, flags);
  814. if (packet)
  815. if_spi_h2c(card, packet, MVMS_DAT);
  816. }
  817. if (hiStatus & IF_SPI_HIST_CARD_EVENT)
  818. if_spi_e2h(card);
  819. err:
  820. if (err)
  821. netdev_err(priv->dev, "%s: got error %d\n", __func__, err);
  822. }
  823. /*
  824. * Host to Card
  825. *
  826. * Called from Libertas to transfer some data to the WLAN device
  827. * We can't sleep here.
  828. */
  829. static int if_spi_host_to_card(struct lbs_private *priv,
  830. u8 type, u8 *buf, u16 nb)
  831. {
  832. int err = 0;
  833. unsigned long flags;
  834. struct if_spi_card *card = priv->card;
  835. struct if_spi_packet *packet;
  836. u16 blen;
  837. if (nb == 0) {
  838. netdev_err(priv->dev, "%s: invalid size requested: %d\n",
  839. __func__, nb);
  840. err = -EINVAL;
  841. goto out;
  842. }
  843. blen = ALIGN(nb, 4);
  844. packet = kzalloc(sizeof(struct if_spi_packet) + blen, GFP_ATOMIC);
  845. if (!packet) {
  846. err = -ENOMEM;
  847. goto out;
  848. }
  849. packet->blen = blen;
  850. memcpy(packet->buffer, buf, nb);
  851. memset(packet->buffer + nb, 0, blen - nb);
  852. switch (type) {
  853. case MVMS_CMD:
  854. priv->dnld_sent = DNLD_CMD_SENT;
  855. spin_lock_irqsave(&card->buffer_lock, flags);
  856. list_add_tail(&packet->list, &card->cmd_packet_list);
  857. spin_unlock_irqrestore(&card->buffer_lock, flags);
  858. break;
  859. case MVMS_DAT:
  860. priv->dnld_sent = DNLD_DATA_SENT;
  861. spin_lock_irqsave(&card->buffer_lock, flags);
  862. list_add_tail(&packet->list, &card->data_packet_list);
  863. spin_unlock_irqrestore(&card->buffer_lock, flags);
  864. break;
  865. default:
  866. kfree(packet);
  867. netdev_err(priv->dev, "can't transfer buffer of type %d\n",
  868. type);
  869. err = -EINVAL;
  870. break;
  871. }
  872. /* Queue spi xfer work */
  873. queue_work(card->workqueue, &card->packet_work);
  874. out:
  875. return err;
  876. }
  877. /*
  878. * Host Interrupts
  879. *
  880. * Service incoming interrupts from the WLAN device. We can't sleep here, so
  881. * don't try to talk on the SPI bus, just queue the SPI xfer work.
  882. */
  883. static irqreturn_t if_spi_host_interrupt(int irq, void *dev_id)
  884. {
  885. struct if_spi_card *card = dev_id;
  886. queue_work(card->workqueue, &card->packet_work);
  887. return IRQ_HANDLED;
  888. }
  889. /*
  890. * SPI callbacks
  891. */
  892. static int if_spi_init_card(struct if_spi_card *card)
  893. {
  894. struct lbs_private *priv = card->priv;
  895. int err, i;
  896. u32 scratch;
  897. const struct firmware *helper = NULL;
  898. const struct firmware *mainfw = NULL;
  899. err = spu_init(card, card->pdata->use_dummy_writes);
  900. if (err)
  901. goto out;
  902. err = spu_get_chip_revision(card, &card->card_id, &card->card_rev);
  903. if (err)
  904. goto out;
  905. err = spu_read_u32(card, IF_SPI_SCRATCH_4_REG, &scratch);
  906. if (err)
  907. goto out;
  908. if (scratch == SUCCESSFUL_FW_DOWNLOAD_MAGIC)
  909. lbs_deb_spi("Firmware is already loaded for "
  910. "Marvell WLAN 802.11 adapter\n");
  911. else {
  912. /* Check if we support this card */
  913. for (i = 0; i < ARRAY_SIZE(fw_table); i++) {
  914. if (card->card_id == fw_table[i].model)
  915. break;
  916. }
  917. if (i == ARRAY_SIZE(fw_table)) {
  918. netdev_err(priv->dev, "Unsupported chip_id: 0x%02x\n",
  919. card->card_id);
  920. err = -ENODEV;
  921. goto out;
  922. }
  923. err = lbs_get_firmware(&card->spi->dev, card->card_id,
  924. &fw_table[0], &helper, &mainfw);
  925. if (err) {
  926. netdev_err(priv->dev, "failed to find firmware (%d)\n",
  927. err);
  928. goto out;
  929. }
  930. lbs_deb_spi("Initializing FW for Marvell WLAN 802.11 adapter "
  931. "(chip_id = 0x%04x, chip_rev = 0x%02x) "
  932. "attached to SPI bus_num %d, chip_select %d. "
  933. "spi->max_speed_hz=%d\n",
  934. card->card_id, card->card_rev,
  935. card->spi->master->bus_num,
  936. card->spi->chip_select,
  937. card->spi->max_speed_hz);
  938. err = if_spi_prog_helper_firmware(card, helper);
  939. if (err)
  940. goto out;
  941. err = if_spi_prog_main_firmware(card, mainfw);
  942. if (err)
  943. goto out;
  944. lbs_deb_spi("loaded FW for Marvell WLAN 802.11 adapter\n");
  945. }
  946. err = spu_set_interrupt_mode(card, 0, 1);
  947. if (err)
  948. goto out;
  949. out:
  950. return err;
  951. }
  952. static void if_spi_resume_worker(struct work_struct *work)
  953. {
  954. struct if_spi_card *card;
  955. card = container_of(work, struct if_spi_card, resume_work);
  956. if (card->suspended) {
  957. if (card->pdata->setup)
  958. card->pdata->setup(card->spi);
  959. /* Init card ... */
  960. if_spi_init_card(card);
  961. enable_irq(card->spi->irq);
  962. /* And resume it ... */
  963. lbs_resume(card->priv);
  964. card->suspended = 0;
  965. }
  966. }
  967. static int if_spi_probe(struct spi_device *spi)
  968. {
  969. struct if_spi_card *card;
  970. struct lbs_private *priv = NULL;
  971. struct libertas_spi_platform_data *pdata = dev_get_platdata(&spi->dev);
  972. int err = 0;
  973. if (!pdata) {
  974. err = -EINVAL;
  975. goto out;
  976. }
  977. if (pdata->setup) {
  978. err = pdata->setup(spi);
  979. if (err)
  980. goto out;
  981. }
  982. /* Allocate card structure to represent this specific device */
  983. card = kzalloc(sizeof(struct if_spi_card), GFP_KERNEL);
  984. if (!card) {
  985. err = -ENOMEM;
  986. goto teardown;
  987. }
  988. spi_set_drvdata(spi, card);
  989. card->pdata = pdata;
  990. card->spi = spi;
  991. card->prev_xfer_time = jiffies;
  992. INIT_LIST_HEAD(&card->cmd_packet_list);
  993. INIT_LIST_HEAD(&card->data_packet_list);
  994. spin_lock_init(&card->buffer_lock);
  995. /* Initialize the SPI Interface Unit */
  996. /* Firmware load */
  997. err = if_spi_init_card(card);
  998. if (err)
  999. goto free_card;
  1000. /*
  1001. * Register our card with libertas.
  1002. * This will call alloc_etherdev.
  1003. */
  1004. priv = lbs_add_card(card, &spi->dev);
  1005. if (!priv) {
  1006. err = -ENOMEM;
  1007. goto free_card;
  1008. }
  1009. card->priv = priv;
  1010. priv->setup_fw_on_resume = 1;
  1011. priv->card = card;
  1012. priv->hw_host_to_card = if_spi_host_to_card;
  1013. priv->enter_deep_sleep = NULL;
  1014. priv->exit_deep_sleep = NULL;
  1015. priv->reset_deep_sleep_wakeup = NULL;
  1016. priv->fw_ready = 1;
  1017. /* Initialize interrupt handling stuff. */
  1018. card->workqueue = alloc_workqueue("libertas_spi", WQ_MEM_RECLAIM, 0);
  1019. if (!card->workqueue) {
  1020. err = -ENOMEM;
  1021. goto remove_card;
  1022. }
  1023. INIT_WORK(&card->packet_work, if_spi_host_to_card_worker);
  1024. INIT_WORK(&card->resume_work, if_spi_resume_worker);
  1025. err = request_irq(spi->irq, if_spi_host_interrupt,
  1026. IRQF_TRIGGER_FALLING, "libertas_spi", card);
  1027. if (err) {
  1028. pr_err("can't get host irq line-- request_irq failed\n");
  1029. goto terminate_workqueue;
  1030. }
  1031. /*
  1032. * Start the card.
  1033. * This will call register_netdev, and we'll start
  1034. * getting interrupts...
  1035. */
  1036. err = lbs_start_card(priv);
  1037. if (err)
  1038. goto release_irq;
  1039. lbs_deb_spi("Finished initializing WLAN module.\n");
  1040. /* successful exit */
  1041. goto out;
  1042. release_irq:
  1043. free_irq(spi->irq, card);
  1044. terminate_workqueue:
  1045. destroy_workqueue(card->workqueue);
  1046. remove_card:
  1047. lbs_remove_card(priv); /* will call free_netdev */
  1048. free_card:
  1049. free_if_spi_card(card);
  1050. teardown:
  1051. if (pdata->teardown)
  1052. pdata->teardown(spi);
  1053. out:
  1054. return err;
  1055. }
  1056. static int libertas_spi_remove(struct spi_device *spi)
  1057. {
  1058. struct if_spi_card *card = spi_get_drvdata(spi);
  1059. struct lbs_private *priv = card->priv;
  1060. lbs_deb_spi("libertas_spi_remove\n");
  1061. cancel_work_sync(&card->resume_work);
  1062. lbs_stop_card(priv);
  1063. lbs_remove_card(priv); /* will call free_netdev */
  1064. free_irq(spi->irq, card);
  1065. destroy_workqueue(card->workqueue);
  1066. if (card->pdata->teardown)
  1067. card->pdata->teardown(spi);
  1068. free_if_spi_card(card);
  1069. return 0;
  1070. }
  1071. static int if_spi_suspend(struct device *dev)
  1072. {
  1073. struct spi_device *spi = to_spi_device(dev);
  1074. struct if_spi_card *card = spi_get_drvdata(spi);
  1075. if (!card->suspended) {
  1076. lbs_suspend(card->priv);
  1077. flush_workqueue(card->workqueue);
  1078. disable_irq(spi->irq);
  1079. if (card->pdata->teardown)
  1080. card->pdata->teardown(spi);
  1081. card->suspended = 1;
  1082. }
  1083. return 0;
  1084. }
  1085. static int if_spi_resume(struct device *dev)
  1086. {
  1087. struct spi_device *spi = to_spi_device(dev);
  1088. struct if_spi_card *card = spi_get_drvdata(spi);
  1089. /* Schedule delayed work */
  1090. schedule_work(&card->resume_work);
  1091. return 0;
  1092. }
  1093. static const struct dev_pm_ops if_spi_pm_ops = {
  1094. .suspend = if_spi_suspend,
  1095. .resume = if_spi_resume,
  1096. };
  1097. static struct spi_driver libertas_spi_driver = {
  1098. .probe = if_spi_probe,
  1099. .remove = libertas_spi_remove,
  1100. .driver = {
  1101. .name = "libertas_spi",
  1102. .pm = &if_spi_pm_ops,
  1103. },
  1104. };
  1105. /*
  1106. * Module functions
  1107. */
  1108. static int __init if_spi_init_module(void)
  1109. {
  1110. int ret = 0;
  1111. printk(KERN_INFO "libertas_spi: Libertas SPI driver\n");
  1112. ret = spi_register_driver(&libertas_spi_driver);
  1113. return ret;
  1114. }
  1115. static void __exit if_spi_exit_module(void)
  1116. {
  1117. spi_unregister_driver(&libertas_spi_driver);
  1118. }
  1119. module_init(if_spi_init_module);
  1120. module_exit(if_spi_exit_module);
  1121. MODULE_DESCRIPTION("Libertas SPI WLAN Driver");
  1122. MODULE_AUTHOR("Andrey Yurovsky <andrey@cozybit.com>, "
  1123. "Colin McCabe <colin@cozybit.com>");
  1124. MODULE_LICENSE("GPL");
  1125. MODULE_ALIAS("spi:libertas_spi");