spi.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
  4. * All rights reserved.
  5. */
  6. #include <linux/clk.h>
  7. #include <linux/spi/spi.h>
  8. #include <linux/crc7.h>
  9. #include <linux/crc-itu-t.h>
  10. #include <linux/gpio/consumer.h>
  11. #include "netdev.h"
  12. #include "cfg80211.h"
  13. #define SPI_MODALIAS "wilc1000_spi"
  14. static bool enable_crc7; /* protect SPI commands with CRC7 */
  15. module_param(enable_crc7, bool, 0644);
  16. MODULE_PARM_DESC(enable_crc7,
  17. "Enable CRC7 checksum to protect command transfers\n"
  18. "\t\t\tagainst corruption during the SPI transfer.\n"
  19. "\t\t\tCommand transfers are short and the CPU-cycle cost\n"
  20. "\t\t\tof enabling this is small.");
  21. static bool enable_crc16; /* protect SPI data with CRC16 */
  22. module_param(enable_crc16, bool, 0644);
  23. MODULE_PARM_DESC(enable_crc16,
  24. "Enable CRC16 checksum to protect data transfers\n"
  25. "\t\t\tagainst corruption during the SPI transfer.\n"
  26. "\t\t\tData transfers can be large and the CPU-cycle cost\n"
  27. "\t\t\tof enabling this may be substantial.");
  28. /*
  29. * For CMD_SINGLE_READ and CMD_INTERNAL_READ, WILC may insert one or
  30. * more zero bytes between the command response and the DATA Start tag
  31. * (0xf3). This behavior appears to be undocumented in "ATWILC1000
  32. * USER GUIDE" (https://tinyurl.com/4hhshdts) but we have observed 1-4
  33. * zero bytes when the SPI bus operates at 48MHz and none when it
  34. * operates at 1MHz.
  35. */
  36. #define WILC_SPI_RSP_HDR_EXTRA_DATA 8
  37. struct wilc_spi {
  38. bool isinit; /* true if SPI protocol has been configured */
  39. bool probing_crc; /* true if we're probing chip's CRC config */
  40. bool crc7_enabled; /* true if crc7 is currently enabled */
  41. bool crc16_enabled; /* true if crc16 is currently enabled */
  42. struct wilc_gpios {
  43. struct gpio_desc *enable; /* ENABLE GPIO or NULL */
  44. struct gpio_desc *reset; /* RESET GPIO or NULL */
  45. } gpios;
  46. };
  47. static const struct wilc_hif_func wilc_hif_spi;
  48. static int wilc_spi_reset(struct wilc *wilc);
  49. /********************************************
  50. *
  51. * Spi protocol Function
  52. *
  53. ********************************************/
  54. #define CMD_DMA_WRITE 0xc1
  55. #define CMD_DMA_READ 0xc2
  56. #define CMD_INTERNAL_WRITE 0xc3
  57. #define CMD_INTERNAL_READ 0xc4
  58. #define CMD_TERMINATE 0xc5
  59. #define CMD_REPEAT 0xc6
  60. #define CMD_DMA_EXT_WRITE 0xc7
  61. #define CMD_DMA_EXT_READ 0xc8
  62. #define CMD_SINGLE_WRITE 0xc9
  63. #define CMD_SINGLE_READ 0xca
  64. #define CMD_RESET 0xcf
  65. #define SPI_ENABLE_VMM_RETRY_LIMIT 2
  66. /* SPI response fields (section 11.1.2 in ATWILC1000 User Guide): */
  67. #define RSP_START_FIELD GENMASK(7, 4)
  68. #define RSP_TYPE_FIELD GENMASK(3, 0)
  69. /* SPI response values for the response fields: */
  70. #define RSP_START_TAG 0xc
  71. #define RSP_TYPE_FIRST_PACKET 0x1
  72. #define RSP_TYPE_INNER_PACKET 0x2
  73. #define RSP_TYPE_LAST_PACKET 0x3
  74. #define RSP_STATE_NO_ERROR 0x00
  75. #define PROTOCOL_REG_PKT_SZ_MASK GENMASK(6, 4)
  76. #define PROTOCOL_REG_CRC16_MASK GENMASK(3, 3)
  77. #define PROTOCOL_REG_CRC7_MASK GENMASK(2, 2)
  78. /*
  79. * The SPI data packet size may be any integer power of two in the
  80. * range from 256 to 8192 bytes.
  81. */
  82. #define DATA_PKT_LOG_SZ_MIN 8 /* 256 B */
  83. #define DATA_PKT_LOG_SZ_MAX 13 /* 8 KiB */
  84. /*
  85. * Select the data packet size (log2 of number of bytes): Use the
  86. * maximum data packet size. We only retransmit complete packets, so
  87. * there is no benefit from using smaller data packets.
  88. */
  89. #define DATA_PKT_LOG_SZ DATA_PKT_LOG_SZ_MAX
  90. #define DATA_PKT_SZ (1 << DATA_PKT_LOG_SZ)
  91. #define WILC_SPI_COMMAND_STAT_SUCCESS 0
  92. #define WILC_GET_RESP_HDR_START(h) (((h) >> 4) & 0xf)
  93. struct wilc_spi_cmd {
  94. u8 cmd_type;
  95. union {
  96. struct {
  97. u8 addr[3];
  98. u8 crc[];
  99. } __packed simple_cmd;
  100. struct {
  101. u8 addr[3];
  102. u8 size[2];
  103. u8 crc[];
  104. } __packed dma_cmd;
  105. struct {
  106. u8 addr[3];
  107. u8 size[3];
  108. u8 crc[];
  109. } __packed dma_cmd_ext;
  110. struct {
  111. u8 addr[2];
  112. __be32 data;
  113. u8 crc[];
  114. } __packed internal_w_cmd;
  115. struct {
  116. u8 addr[3];
  117. __be32 data;
  118. u8 crc[];
  119. } __packed w_cmd;
  120. } u;
  121. } __packed;
  122. struct wilc_spi_read_rsp_data {
  123. u8 header;
  124. u8 data[4];
  125. u8 crc[];
  126. } __packed;
  127. struct wilc_spi_rsp_data {
  128. u8 rsp_cmd_type;
  129. u8 status;
  130. u8 data[];
  131. } __packed;
  132. struct wilc_spi_special_cmd_rsp {
  133. u8 skip_byte;
  134. u8 rsp_cmd_type;
  135. u8 status;
  136. } __packed;
  137. static int wilc_parse_gpios(struct wilc *wilc)
  138. {
  139. struct spi_device *spi = to_spi_device(wilc->dev);
  140. struct wilc_spi *spi_priv = wilc->bus_data;
  141. struct wilc_gpios *gpios = &spi_priv->gpios;
  142. /* get ENABLE pin and deassert it (if it is defined): */
  143. gpios->enable = devm_gpiod_get_optional(&spi->dev,
  144. "enable", GPIOD_OUT_LOW);
  145. /* get RESET pin and assert it (if it is defined): */
  146. if (gpios->enable) {
  147. /* if enable pin exists, reset must exist as well */
  148. gpios->reset = devm_gpiod_get(&spi->dev,
  149. "reset", GPIOD_OUT_HIGH);
  150. if (IS_ERR(gpios->reset)) {
  151. dev_err(&spi->dev, "missing reset gpio.\n");
  152. return PTR_ERR(gpios->reset);
  153. }
  154. } else {
  155. gpios->reset = devm_gpiod_get_optional(&spi->dev,
  156. "reset", GPIOD_OUT_HIGH);
  157. }
  158. return 0;
  159. }
  160. static void wilc_wlan_power(struct wilc *wilc, bool on)
  161. {
  162. struct wilc_spi *spi_priv = wilc->bus_data;
  163. struct wilc_gpios *gpios = &spi_priv->gpios;
  164. if (on) {
  165. /* assert ENABLE: */
  166. gpiod_set_value(gpios->enable, 1);
  167. mdelay(5);
  168. /* assert RESET: */
  169. gpiod_set_value(gpios->reset, 1);
  170. } else {
  171. /* deassert RESET: */
  172. gpiod_set_value(gpios->reset, 0);
  173. /* deassert ENABLE: */
  174. gpiod_set_value(gpios->enable, 0);
  175. }
  176. }
  177. static int wilc_bus_probe(struct spi_device *spi)
  178. {
  179. int ret;
  180. struct wilc *wilc;
  181. struct wilc_spi *spi_priv;
  182. spi_priv = kzalloc(sizeof(*spi_priv), GFP_KERNEL);
  183. if (!spi_priv)
  184. return -ENOMEM;
  185. ret = wilc_cfg80211_init(&wilc, &spi->dev, WILC_HIF_SPI, &wilc_hif_spi);
  186. if (ret)
  187. goto free;
  188. spi_set_drvdata(spi, wilc);
  189. wilc->dev = &spi->dev;
  190. wilc->bus_data = spi_priv;
  191. wilc->dev_irq_num = spi->irq;
  192. ret = wilc_parse_gpios(wilc);
  193. if (ret < 0)
  194. goto netdev_cleanup;
  195. wilc->rtc_clk = devm_clk_get_optional(&spi->dev, "rtc");
  196. if (IS_ERR(wilc->rtc_clk)) {
  197. ret = PTR_ERR(wilc->rtc_clk);
  198. goto netdev_cleanup;
  199. }
  200. clk_prepare_enable(wilc->rtc_clk);
  201. return 0;
  202. netdev_cleanup:
  203. wilc_netdev_cleanup(wilc);
  204. free:
  205. kfree(spi_priv);
  206. return ret;
  207. }
  208. static void wilc_bus_remove(struct spi_device *spi)
  209. {
  210. struct wilc *wilc = spi_get_drvdata(spi);
  211. struct wilc_spi *spi_priv = wilc->bus_data;
  212. clk_disable_unprepare(wilc->rtc_clk);
  213. wilc_netdev_cleanup(wilc);
  214. kfree(spi_priv);
  215. }
  216. static const struct of_device_id wilc_of_match[] = {
  217. { .compatible = "microchip,wilc1000", },
  218. { /* sentinel */ }
  219. };
  220. MODULE_DEVICE_TABLE(of, wilc_of_match);
  221. static const struct spi_device_id wilc_spi_id[] = {
  222. { "wilc1000", 0 },
  223. { /* sentinel */ }
  224. };
  225. MODULE_DEVICE_TABLE(spi, wilc_spi_id);
  226. static struct spi_driver wilc_spi_driver = {
  227. .driver = {
  228. .name = SPI_MODALIAS,
  229. .of_match_table = wilc_of_match,
  230. },
  231. .id_table = wilc_spi_id,
  232. .probe = wilc_bus_probe,
  233. .remove = wilc_bus_remove,
  234. };
  235. module_spi_driver(wilc_spi_driver);
  236. MODULE_LICENSE("GPL");
  237. static int wilc_spi_tx(struct wilc *wilc, u8 *b, u32 len)
  238. {
  239. struct spi_device *spi = to_spi_device(wilc->dev);
  240. int ret;
  241. struct spi_message msg;
  242. if (len > 0 && b) {
  243. struct spi_transfer tr = {
  244. .tx_buf = b,
  245. .len = len,
  246. .delay = {
  247. .value = 0,
  248. .unit = SPI_DELAY_UNIT_USECS
  249. },
  250. };
  251. char *r_buffer = kzalloc(len, GFP_KERNEL);
  252. if (!r_buffer)
  253. return -ENOMEM;
  254. tr.rx_buf = r_buffer;
  255. dev_dbg(&spi->dev, "Request writing %d bytes\n", len);
  256. memset(&msg, 0, sizeof(msg));
  257. spi_message_init(&msg);
  258. msg.spi = spi;
  259. spi_message_add_tail(&tr, &msg);
  260. ret = spi_sync(spi, &msg);
  261. if (ret < 0)
  262. dev_err(&spi->dev, "SPI transaction failed\n");
  263. kfree(r_buffer);
  264. } else {
  265. dev_err(&spi->dev,
  266. "can't write data with the following length: %d\n",
  267. len);
  268. ret = -EINVAL;
  269. }
  270. return ret;
  271. }
  272. static int wilc_spi_rx(struct wilc *wilc, u8 *rb, u32 rlen)
  273. {
  274. struct spi_device *spi = to_spi_device(wilc->dev);
  275. int ret;
  276. if (rlen > 0) {
  277. struct spi_message msg;
  278. struct spi_transfer tr = {
  279. .rx_buf = rb,
  280. .len = rlen,
  281. .delay = {
  282. .value = 0,
  283. .unit = SPI_DELAY_UNIT_USECS
  284. },
  285. };
  286. char *t_buffer = kzalloc(rlen, GFP_KERNEL);
  287. if (!t_buffer)
  288. return -ENOMEM;
  289. tr.tx_buf = t_buffer;
  290. memset(&msg, 0, sizeof(msg));
  291. spi_message_init(&msg);
  292. msg.spi = spi;
  293. spi_message_add_tail(&tr, &msg);
  294. ret = spi_sync(spi, &msg);
  295. if (ret < 0)
  296. dev_err(&spi->dev, "SPI transaction failed\n");
  297. kfree(t_buffer);
  298. } else {
  299. dev_err(&spi->dev,
  300. "can't read data with the following length: %u\n",
  301. rlen);
  302. ret = -EINVAL;
  303. }
  304. return ret;
  305. }
  306. static int wilc_spi_tx_rx(struct wilc *wilc, u8 *wb, u8 *rb, u32 rlen)
  307. {
  308. struct spi_device *spi = to_spi_device(wilc->dev);
  309. int ret;
  310. if (rlen > 0) {
  311. struct spi_message msg;
  312. struct spi_transfer tr = {
  313. .rx_buf = rb,
  314. .tx_buf = wb,
  315. .len = rlen,
  316. .bits_per_word = 8,
  317. .delay = {
  318. .value = 0,
  319. .unit = SPI_DELAY_UNIT_USECS
  320. },
  321. };
  322. memset(&msg, 0, sizeof(msg));
  323. spi_message_init(&msg);
  324. msg.spi = spi;
  325. spi_message_add_tail(&tr, &msg);
  326. ret = spi_sync(spi, &msg);
  327. if (ret < 0)
  328. dev_err(&spi->dev, "SPI transaction failed\n");
  329. } else {
  330. dev_err(&spi->dev,
  331. "can't read data with the following length: %u\n",
  332. rlen);
  333. ret = -EINVAL;
  334. }
  335. return ret;
  336. }
  337. static int spi_data_write(struct wilc *wilc, u8 *b, u32 sz)
  338. {
  339. struct spi_device *spi = to_spi_device(wilc->dev);
  340. struct wilc_spi *spi_priv = wilc->bus_data;
  341. int ix, nbytes;
  342. int result = 0;
  343. u8 cmd, order, crc[2];
  344. u16 crc_calc;
  345. /*
  346. * Data
  347. */
  348. ix = 0;
  349. do {
  350. if (sz <= DATA_PKT_SZ) {
  351. nbytes = sz;
  352. order = 0x3;
  353. } else {
  354. nbytes = DATA_PKT_SZ;
  355. if (ix == 0)
  356. order = 0x1;
  357. else
  358. order = 0x02;
  359. }
  360. /*
  361. * Write command
  362. */
  363. cmd = 0xf0;
  364. cmd |= order;
  365. if (wilc_spi_tx(wilc, &cmd, 1)) {
  366. dev_err(&spi->dev,
  367. "Failed data block cmd write, bus error...\n");
  368. result = -EINVAL;
  369. break;
  370. }
  371. /*
  372. * Write data
  373. */
  374. if (wilc_spi_tx(wilc, &b[ix], nbytes)) {
  375. dev_err(&spi->dev,
  376. "Failed data block write, bus error...\n");
  377. result = -EINVAL;
  378. break;
  379. }
  380. /*
  381. * Write CRC
  382. */
  383. if (spi_priv->crc16_enabled) {
  384. crc_calc = crc_itu_t(0xffff, &b[ix], nbytes);
  385. crc[0] = crc_calc >> 8;
  386. crc[1] = crc_calc;
  387. if (wilc_spi_tx(wilc, crc, 2)) {
  388. dev_err(&spi->dev, "Failed data block crc write, bus error...\n");
  389. result = -EINVAL;
  390. break;
  391. }
  392. }
  393. /*
  394. * No need to wait for response
  395. */
  396. ix += nbytes;
  397. sz -= nbytes;
  398. } while (sz);
  399. return result;
  400. }
  401. /********************************************
  402. *
  403. * Spi Internal Read/Write Function
  404. *
  405. ********************************************/
  406. static u8 wilc_get_crc7(u8 *buffer, u32 len)
  407. {
  408. return crc7_be(0xfe, buffer, len);
  409. }
  410. static int wilc_spi_single_read(struct wilc *wilc, u8 cmd, u32 adr, void *b,
  411. u8 clockless)
  412. {
  413. struct spi_device *spi = to_spi_device(wilc->dev);
  414. struct wilc_spi *spi_priv = wilc->bus_data;
  415. u8 wb[32], rb[32];
  416. int cmd_len, resp_len, i;
  417. u16 crc_calc, crc_recv;
  418. struct wilc_spi_cmd *c;
  419. struct wilc_spi_rsp_data *r;
  420. struct wilc_spi_read_rsp_data *r_data;
  421. memset(wb, 0x0, sizeof(wb));
  422. memset(rb, 0x0, sizeof(rb));
  423. c = (struct wilc_spi_cmd *)wb;
  424. c->cmd_type = cmd;
  425. if (cmd == CMD_SINGLE_READ) {
  426. c->u.simple_cmd.addr[0] = adr >> 16;
  427. c->u.simple_cmd.addr[1] = adr >> 8;
  428. c->u.simple_cmd.addr[2] = adr;
  429. } else if (cmd == CMD_INTERNAL_READ) {
  430. c->u.simple_cmd.addr[0] = adr >> 8;
  431. if (clockless == 1)
  432. c->u.simple_cmd.addr[0] |= BIT(7);
  433. c->u.simple_cmd.addr[1] = adr;
  434. c->u.simple_cmd.addr[2] = 0x0;
  435. } else {
  436. dev_err(&spi->dev, "cmd [%x] not supported\n", cmd);
  437. return -EINVAL;
  438. }
  439. cmd_len = offsetof(struct wilc_spi_cmd, u.simple_cmd.crc);
  440. resp_len = sizeof(*r) + sizeof(*r_data) + WILC_SPI_RSP_HDR_EXTRA_DATA;
  441. if (spi_priv->crc7_enabled) {
  442. c->u.simple_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
  443. cmd_len += 1;
  444. resp_len += 2;
  445. }
  446. if (cmd_len + resp_len > ARRAY_SIZE(wb)) {
  447. dev_err(&spi->dev,
  448. "spi buffer size too small (%d) (%d) (%zu)\n",
  449. cmd_len, resp_len, ARRAY_SIZE(wb));
  450. return -EINVAL;
  451. }
  452. if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) {
  453. dev_err(&spi->dev, "Failed cmd write, bus error...\n");
  454. return -EINVAL;
  455. }
  456. r = (struct wilc_spi_rsp_data *)&rb[cmd_len];
  457. if (r->rsp_cmd_type != cmd && !clockless) {
  458. if (!spi_priv->probing_crc)
  459. dev_err(&spi->dev,
  460. "Failed cmd, cmd (%02x), resp (%02x)\n",
  461. cmd, r->rsp_cmd_type);
  462. return -EINVAL;
  463. }
  464. if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS && !clockless) {
  465. dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
  466. r->status);
  467. return -EINVAL;
  468. }
  469. for (i = 0; i < WILC_SPI_RSP_HDR_EXTRA_DATA; ++i)
  470. if (WILC_GET_RESP_HDR_START(r->data[i]) == 0xf)
  471. break;
  472. if (i >= WILC_SPI_RSP_HDR_EXTRA_DATA) {
  473. dev_err(&spi->dev, "Error, data start missing\n");
  474. return -EINVAL;
  475. }
  476. r_data = (struct wilc_spi_read_rsp_data *)&r->data[i];
  477. if (b)
  478. memcpy(b, r_data->data, 4);
  479. if (!clockless && spi_priv->crc16_enabled) {
  480. crc_recv = (r_data->crc[0] << 8) | r_data->crc[1];
  481. crc_calc = crc_itu_t(0xffff, r_data->data, 4);
  482. if (crc_recv != crc_calc) {
  483. dev_err(&spi->dev, "%s: bad CRC 0x%04x "
  484. "(calculated 0x%04x)\n", __func__,
  485. crc_recv, crc_calc);
  486. return -EINVAL;
  487. }
  488. }
  489. return 0;
  490. }
  491. static int wilc_spi_write_cmd(struct wilc *wilc, u8 cmd, u32 adr, u32 data,
  492. u8 clockless)
  493. {
  494. struct spi_device *spi = to_spi_device(wilc->dev);
  495. struct wilc_spi *spi_priv = wilc->bus_data;
  496. u8 wb[32], rb[32];
  497. int cmd_len, resp_len;
  498. struct wilc_spi_cmd *c;
  499. struct wilc_spi_rsp_data *r;
  500. memset(wb, 0x0, sizeof(wb));
  501. memset(rb, 0x0, sizeof(rb));
  502. c = (struct wilc_spi_cmd *)wb;
  503. c->cmd_type = cmd;
  504. if (cmd == CMD_INTERNAL_WRITE) {
  505. c->u.internal_w_cmd.addr[0] = adr >> 8;
  506. if (clockless == 1)
  507. c->u.internal_w_cmd.addr[0] |= BIT(7);
  508. c->u.internal_w_cmd.addr[1] = adr;
  509. c->u.internal_w_cmd.data = cpu_to_be32(data);
  510. cmd_len = offsetof(struct wilc_spi_cmd, u.internal_w_cmd.crc);
  511. if (spi_priv->crc7_enabled)
  512. c->u.internal_w_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
  513. } else if (cmd == CMD_SINGLE_WRITE) {
  514. c->u.w_cmd.addr[0] = adr >> 16;
  515. c->u.w_cmd.addr[1] = adr >> 8;
  516. c->u.w_cmd.addr[2] = adr;
  517. c->u.w_cmd.data = cpu_to_be32(data);
  518. cmd_len = offsetof(struct wilc_spi_cmd, u.w_cmd.crc);
  519. if (spi_priv->crc7_enabled)
  520. c->u.w_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
  521. } else {
  522. dev_err(&spi->dev, "write cmd [%x] not supported\n", cmd);
  523. return -EINVAL;
  524. }
  525. if (spi_priv->crc7_enabled)
  526. cmd_len += 1;
  527. resp_len = sizeof(*r);
  528. if (cmd_len + resp_len > ARRAY_SIZE(wb)) {
  529. dev_err(&spi->dev,
  530. "spi buffer size too small (%d) (%d) (%zu)\n",
  531. cmd_len, resp_len, ARRAY_SIZE(wb));
  532. return -EINVAL;
  533. }
  534. if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) {
  535. dev_err(&spi->dev, "Failed cmd write, bus error...\n");
  536. return -EINVAL;
  537. }
  538. r = (struct wilc_spi_rsp_data *)&rb[cmd_len];
  539. /*
  540. * Clockless registers operations might return unexptected responses,
  541. * even if successful.
  542. */
  543. if (r->rsp_cmd_type != cmd && !clockless) {
  544. dev_err(&spi->dev,
  545. "Failed cmd response, cmd (%02x), resp (%02x)\n",
  546. cmd, r->rsp_cmd_type);
  547. return -EINVAL;
  548. }
  549. if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS && !clockless) {
  550. dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
  551. r->status);
  552. return -EINVAL;
  553. }
  554. return 0;
  555. }
  556. static int wilc_spi_dma_rw(struct wilc *wilc, u8 cmd, u32 adr, u8 *b, u32 sz)
  557. {
  558. struct spi_device *spi = to_spi_device(wilc->dev);
  559. struct wilc_spi *spi_priv = wilc->bus_data;
  560. u16 crc_recv, crc_calc;
  561. u8 wb[32], rb[32];
  562. int cmd_len, resp_len;
  563. int retry, ix = 0;
  564. u8 crc[2];
  565. struct wilc_spi_cmd *c;
  566. struct wilc_spi_rsp_data *r;
  567. memset(wb, 0x0, sizeof(wb));
  568. memset(rb, 0x0, sizeof(rb));
  569. c = (struct wilc_spi_cmd *)wb;
  570. c->cmd_type = cmd;
  571. if (cmd == CMD_DMA_WRITE || cmd == CMD_DMA_READ) {
  572. c->u.dma_cmd.addr[0] = adr >> 16;
  573. c->u.dma_cmd.addr[1] = adr >> 8;
  574. c->u.dma_cmd.addr[2] = adr;
  575. c->u.dma_cmd.size[0] = sz >> 8;
  576. c->u.dma_cmd.size[1] = sz;
  577. cmd_len = offsetof(struct wilc_spi_cmd, u.dma_cmd.crc);
  578. if (spi_priv->crc7_enabled)
  579. c->u.dma_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
  580. } else if (cmd == CMD_DMA_EXT_WRITE || cmd == CMD_DMA_EXT_READ) {
  581. c->u.dma_cmd_ext.addr[0] = adr >> 16;
  582. c->u.dma_cmd_ext.addr[1] = adr >> 8;
  583. c->u.dma_cmd_ext.addr[2] = adr;
  584. c->u.dma_cmd_ext.size[0] = sz >> 16;
  585. c->u.dma_cmd_ext.size[1] = sz >> 8;
  586. c->u.dma_cmd_ext.size[2] = sz;
  587. cmd_len = offsetof(struct wilc_spi_cmd, u.dma_cmd_ext.crc);
  588. if (spi_priv->crc7_enabled)
  589. c->u.dma_cmd_ext.crc[0] = wilc_get_crc7(wb, cmd_len);
  590. } else {
  591. dev_err(&spi->dev, "dma read write cmd [%x] not supported\n",
  592. cmd);
  593. return -EINVAL;
  594. }
  595. if (spi_priv->crc7_enabled)
  596. cmd_len += 1;
  597. resp_len = sizeof(*r);
  598. if (cmd_len + resp_len > ARRAY_SIZE(wb)) {
  599. dev_err(&spi->dev, "spi buffer size too small (%d)(%d) (%zu)\n",
  600. cmd_len, resp_len, ARRAY_SIZE(wb));
  601. return -EINVAL;
  602. }
  603. if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) {
  604. dev_err(&spi->dev, "Failed cmd write, bus error...\n");
  605. return -EINVAL;
  606. }
  607. r = (struct wilc_spi_rsp_data *)&rb[cmd_len];
  608. if (r->rsp_cmd_type != cmd) {
  609. dev_err(&spi->dev,
  610. "Failed cmd response, cmd (%02x), resp (%02x)\n",
  611. cmd, r->rsp_cmd_type);
  612. return -EINVAL;
  613. }
  614. if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) {
  615. dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
  616. r->status);
  617. return -EINVAL;
  618. }
  619. if (cmd == CMD_DMA_WRITE || cmd == CMD_DMA_EXT_WRITE)
  620. return 0;
  621. while (sz > 0) {
  622. int nbytes;
  623. u8 rsp;
  624. nbytes = min_t(u32, sz, DATA_PKT_SZ);
  625. /*
  626. * Data Response header
  627. */
  628. retry = 100;
  629. do {
  630. if (wilc_spi_rx(wilc, &rsp, 1)) {
  631. dev_err(&spi->dev,
  632. "Failed resp read, bus err\n");
  633. return -EINVAL;
  634. }
  635. if (WILC_GET_RESP_HDR_START(rsp) == 0xf)
  636. break;
  637. } while (retry--);
  638. /*
  639. * Read bytes
  640. */
  641. if (wilc_spi_rx(wilc, &b[ix], nbytes)) {
  642. dev_err(&spi->dev,
  643. "Failed block read, bus err\n");
  644. return -EINVAL;
  645. }
  646. /*
  647. * Read CRC
  648. */
  649. if (spi_priv->crc16_enabled) {
  650. if (wilc_spi_rx(wilc, crc, 2)) {
  651. dev_err(&spi->dev,
  652. "Failed block CRC read, bus err\n");
  653. return -EINVAL;
  654. }
  655. crc_recv = (crc[0] << 8) | crc[1];
  656. crc_calc = crc_itu_t(0xffff, &b[ix], nbytes);
  657. if (crc_recv != crc_calc) {
  658. dev_err(&spi->dev, "%s: bad CRC 0x%04x "
  659. "(calculated 0x%04x)\n", __func__,
  660. crc_recv, crc_calc);
  661. return -EINVAL;
  662. }
  663. }
  664. ix += nbytes;
  665. sz -= nbytes;
  666. }
  667. return 0;
  668. }
  669. static int wilc_spi_special_cmd(struct wilc *wilc, u8 cmd)
  670. {
  671. struct spi_device *spi = to_spi_device(wilc->dev);
  672. struct wilc_spi *spi_priv = wilc->bus_data;
  673. u8 wb[32], rb[32];
  674. int cmd_len, resp_len = 0;
  675. struct wilc_spi_cmd *c;
  676. struct wilc_spi_special_cmd_rsp *r;
  677. if (cmd != CMD_TERMINATE && cmd != CMD_REPEAT && cmd != CMD_RESET)
  678. return -EINVAL;
  679. memset(wb, 0x0, sizeof(wb));
  680. memset(rb, 0x0, sizeof(rb));
  681. c = (struct wilc_spi_cmd *)wb;
  682. c->cmd_type = cmd;
  683. if (cmd == CMD_RESET)
  684. memset(c->u.simple_cmd.addr, 0xFF, 3);
  685. cmd_len = offsetof(struct wilc_spi_cmd, u.simple_cmd.crc);
  686. resp_len = sizeof(*r);
  687. if (spi_priv->crc7_enabled) {
  688. c->u.simple_cmd.crc[0] = wilc_get_crc7(wb, cmd_len);
  689. cmd_len += 1;
  690. }
  691. if (cmd_len + resp_len > ARRAY_SIZE(wb)) {
  692. dev_err(&spi->dev, "spi buffer size too small (%d) (%d) (%zu)\n",
  693. cmd_len, resp_len, ARRAY_SIZE(wb));
  694. return -EINVAL;
  695. }
  696. if (wilc_spi_tx_rx(wilc, wb, rb, cmd_len + resp_len)) {
  697. dev_err(&spi->dev, "Failed cmd write, bus error...\n");
  698. return -EINVAL;
  699. }
  700. r = (struct wilc_spi_special_cmd_rsp *)&rb[cmd_len];
  701. if (r->rsp_cmd_type != cmd) {
  702. if (!spi_priv->probing_crc)
  703. dev_err(&spi->dev,
  704. "Failed cmd response, cmd (%02x), resp (%02x)\n",
  705. cmd, r->rsp_cmd_type);
  706. return -EINVAL;
  707. }
  708. if (r->status != WILC_SPI_COMMAND_STAT_SUCCESS) {
  709. dev_err(&spi->dev, "Failed cmd state response state (%02x)\n",
  710. r->status);
  711. return -EINVAL;
  712. }
  713. return 0;
  714. }
  715. static int wilc_spi_read_reg(struct wilc *wilc, u32 addr, u32 *data)
  716. {
  717. struct spi_device *spi = to_spi_device(wilc->dev);
  718. int result;
  719. u8 cmd = CMD_SINGLE_READ;
  720. u8 clockless = 0;
  721. if (addr < WILC_SPI_CLOCKLESS_ADDR_LIMIT) {
  722. /* Clockless register */
  723. cmd = CMD_INTERNAL_READ;
  724. clockless = 1;
  725. }
  726. result = wilc_spi_single_read(wilc, cmd, addr, data, clockless);
  727. if (result) {
  728. dev_err(&spi->dev, "Failed cmd, read reg (%08x)...\n", addr);
  729. return result;
  730. }
  731. le32_to_cpus(data);
  732. return 0;
  733. }
  734. static int wilc_spi_read(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
  735. {
  736. struct spi_device *spi = to_spi_device(wilc->dev);
  737. int result;
  738. if (size <= 4)
  739. return -EINVAL;
  740. result = wilc_spi_dma_rw(wilc, CMD_DMA_EXT_READ, addr, buf, size);
  741. if (result) {
  742. dev_err(&spi->dev, "Failed cmd, read block (%08x)...\n", addr);
  743. return result;
  744. }
  745. return 0;
  746. }
  747. static int spi_internal_write(struct wilc *wilc, u32 adr, u32 dat)
  748. {
  749. struct spi_device *spi = to_spi_device(wilc->dev);
  750. int result;
  751. result = wilc_spi_write_cmd(wilc, CMD_INTERNAL_WRITE, adr, dat, 0);
  752. if (result) {
  753. dev_err(&spi->dev, "Failed internal write cmd...\n");
  754. return result;
  755. }
  756. return 0;
  757. }
  758. static int spi_internal_read(struct wilc *wilc, u32 adr, u32 *data)
  759. {
  760. struct spi_device *spi = to_spi_device(wilc->dev);
  761. struct wilc_spi *spi_priv = wilc->bus_data;
  762. int result;
  763. result = wilc_spi_single_read(wilc, CMD_INTERNAL_READ, adr, data, 0);
  764. if (result) {
  765. if (!spi_priv->probing_crc)
  766. dev_err(&spi->dev, "Failed internal read cmd...\n");
  767. return result;
  768. }
  769. le32_to_cpus(data);
  770. return 0;
  771. }
  772. /********************************************
  773. *
  774. * Spi interfaces
  775. *
  776. ********************************************/
  777. static int wilc_spi_write_reg(struct wilc *wilc, u32 addr, u32 data)
  778. {
  779. struct spi_device *spi = to_spi_device(wilc->dev);
  780. int result;
  781. u8 cmd = CMD_SINGLE_WRITE;
  782. u8 clockless = 0;
  783. if (addr < WILC_SPI_CLOCKLESS_ADDR_LIMIT) {
  784. /* Clockless register */
  785. cmd = CMD_INTERNAL_WRITE;
  786. clockless = 1;
  787. }
  788. result = wilc_spi_write_cmd(wilc, cmd, addr, data, clockless);
  789. if (result) {
  790. dev_err(&spi->dev, "Failed cmd, write reg (%08x)...\n", addr);
  791. return result;
  792. }
  793. return 0;
  794. }
  795. static int spi_data_rsp(struct wilc *wilc, u8 cmd)
  796. {
  797. struct spi_device *spi = to_spi_device(wilc->dev);
  798. int result, i;
  799. u8 rsp[4];
  800. /*
  801. * The response to data packets is two bytes long. For
  802. * efficiency's sake, wilc_spi_write() wisely ignores the
  803. * responses for all packets but the final one. The downside
  804. * of that optimization is that when the final data packet is
  805. * short, we may receive (part of) the response to the
  806. * second-to-last packet before the one for the final packet.
  807. * To handle this, we always read 4 bytes and then search for
  808. * the last byte that contains the "Response Start" code (0xc
  809. * in the top 4 bits). We then know that this byte is the
  810. * first response byte of the final data packet.
  811. */
  812. result = wilc_spi_rx(wilc, rsp, sizeof(rsp));
  813. if (result) {
  814. dev_err(&spi->dev, "Failed bus error...\n");
  815. return result;
  816. }
  817. for (i = sizeof(rsp) - 2; i >= 0; --i)
  818. if (FIELD_GET(RSP_START_FIELD, rsp[i]) == RSP_START_TAG)
  819. break;
  820. if (i < 0) {
  821. dev_err(&spi->dev,
  822. "Data packet response missing (%02x %02x %02x %02x)\n",
  823. rsp[0], rsp[1], rsp[2], rsp[3]);
  824. return -1;
  825. }
  826. /* rsp[i] is the last response start byte */
  827. if (FIELD_GET(RSP_TYPE_FIELD, rsp[i]) != RSP_TYPE_LAST_PACKET
  828. || rsp[i + 1] != RSP_STATE_NO_ERROR) {
  829. dev_err(&spi->dev, "Data response error (%02x %02x)\n",
  830. rsp[i], rsp[i + 1]);
  831. return -1;
  832. }
  833. return 0;
  834. }
  835. static int wilc_spi_write(struct wilc *wilc, u32 addr, u8 *buf, u32 size)
  836. {
  837. struct spi_device *spi = to_spi_device(wilc->dev);
  838. int result;
  839. /*
  840. * has to be greated than 4
  841. */
  842. if (size <= 4)
  843. return -EINVAL;
  844. result = wilc_spi_dma_rw(wilc, CMD_DMA_EXT_WRITE, addr, NULL, size);
  845. if (result) {
  846. dev_err(&spi->dev,
  847. "Failed cmd, write block (%08x)...\n", addr);
  848. return result;
  849. }
  850. /*
  851. * Data
  852. */
  853. result = spi_data_write(wilc, buf, size);
  854. if (result) {
  855. dev_err(&spi->dev, "Failed block data write...\n");
  856. return result;
  857. }
  858. /*
  859. * Data response
  860. */
  861. return spi_data_rsp(wilc, CMD_DMA_EXT_WRITE);
  862. }
  863. /********************************************
  864. *
  865. * Bus interfaces
  866. *
  867. ********************************************/
  868. static int wilc_spi_reset(struct wilc *wilc)
  869. {
  870. struct spi_device *spi = to_spi_device(wilc->dev);
  871. struct wilc_spi *spi_priv = wilc->bus_data;
  872. int result;
  873. result = wilc_spi_special_cmd(wilc, CMD_RESET);
  874. if (result && !spi_priv->probing_crc)
  875. dev_err(&spi->dev, "Failed cmd reset\n");
  876. return result;
  877. }
  878. static bool wilc_spi_is_init(struct wilc *wilc)
  879. {
  880. struct wilc_spi *spi_priv = wilc->bus_data;
  881. return spi_priv->isinit;
  882. }
  883. static int wilc_spi_deinit(struct wilc *wilc)
  884. {
  885. struct wilc_spi *spi_priv = wilc->bus_data;
  886. spi_priv->isinit = false;
  887. wilc_wlan_power(wilc, false);
  888. return 0;
  889. }
  890. static int wilc_spi_init(struct wilc *wilc, bool resume)
  891. {
  892. struct spi_device *spi = to_spi_device(wilc->dev);
  893. struct wilc_spi *spi_priv = wilc->bus_data;
  894. u32 reg;
  895. u32 chipid;
  896. int ret, i;
  897. if (spi_priv->isinit) {
  898. /* Confirm we can read chipid register without error: */
  899. ret = wilc_spi_read_reg(wilc, WILC_CHIPID, &chipid);
  900. if (ret == 0)
  901. return 0;
  902. dev_err(&spi->dev, "Fail cmd read chip id...\n");
  903. }
  904. wilc_wlan_power(wilc, true);
  905. /*
  906. * configure protocol
  907. */
  908. /*
  909. * Infer the CRC settings that are currently in effect. This
  910. * is necessary because we can't be sure that the chip has
  911. * been RESET (e.g, after module unload and reload).
  912. */
  913. spi_priv->probing_crc = true;
  914. spi_priv->crc7_enabled = enable_crc7;
  915. spi_priv->crc16_enabled = false; /* don't check CRC16 during probing */
  916. for (i = 0; i < 2; ++i) {
  917. ret = spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, &reg);
  918. if (ret == 0)
  919. break;
  920. spi_priv->crc7_enabled = !enable_crc7;
  921. }
  922. if (ret) {
  923. dev_err(&spi->dev, "Failed with CRC7 on and off.\n");
  924. return ret;
  925. }
  926. /* set up the desired CRC configuration: */
  927. reg &= ~(PROTOCOL_REG_CRC7_MASK | PROTOCOL_REG_CRC16_MASK);
  928. if (enable_crc7)
  929. reg |= PROTOCOL_REG_CRC7_MASK;
  930. if (enable_crc16)
  931. reg |= PROTOCOL_REG_CRC16_MASK;
  932. /* set up the data packet size: */
  933. BUILD_BUG_ON(DATA_PKT_LOG_SZ < DATA_PKT_LOG_SZ_MIN
  934. || DATA_PKT_LOG_SZ > DATA_PKT_LOG_SZ_MAX);
  935. reg &= ~PROTOCOL_REG_PKT_SZ_MASK;
  936. reg |= FIELD_PREP(PROTOCOL_REG_PKT_SZ_MASK,
  937. DATA_PKT_LOG_SZ - DATA_PKT_LOG_SZ_MIN);
  938. /* establish the new setup: */
  939. ret = spi_internal_write(wilc, WILC_SPI_PROTOCOL_OFFSET, reg);
  940. if (ret) {
  941. dev_err(&spi->dev,
  942. "[wilc spi %d]: Failed internal write reg\n",
  943. __LINE__);
  944. return ret;
  945. }
  946. /* update our state to match new protocol settings: */
  947. spi_priv->crc7_enabled = enable_crc7;
  948. spi_priv->crc16_enabled = enable_crc16;
  949. /* re-read to make sure new settings are in effect: */
  950. spi_internal_read(wilc, WILC_SPI_PROTOCOL_OFFSET, &reg);
  951. spi_priv->probing_crc = false;
  952. /*
  953. * make sure can read chip id without protocol error
  954. */
  955. ret = wilc_spi_read_reg(wilc, WILC_CHIPID, &chipid);
  956. if (ret) {
  957. dev_err(&spi->dev, "Fail cmd read chip id...\n");
  958. return ret;
  959. }
  960. spi_priv->isinit = true;
  961. return 0;
  962. }
  963. static int wilc_spi_read_size(struct wilc *wilc, u32 *size)
  964. {
  965. int ret;
  966. ret = spi_internal_read(wilc,
  967. WILC_SPI_INT_STATUS - WILC_SPI_REG_BASE, size);
  968. *size = FIELD_GET(IRQ_DMA_WD_CNT_MASK, *size);
  969. return ret;
  970. }
  971. static int wilc_spi_read_int(struct wilc *wilc, u32 *int_status)
  972. {
  973. return spi_internal_read(wilc, WILC_SPI_INT_STATUS - WILC_SPI_REG_BASE,
  974. int_status);
  975. }
  976. static int wilc_spi_clear_int_ext(struct wilc *wilc, u32 val)
  977. {
  978. int ret;
  979. int retry = SPI_ENABLE_VMM_RETRY_LIMIT;
  980. u32 check;
  981. while (retry) {
  982. ret = spi_internal_write(wilc,
  983. WILC_SPI_INT_CLEAR - WILC_SPI_REG_BASE,
  984. val);
  985. if (ret)
  986. break;
  987. ret = spi_internal_read(wilc,
  988. WILC_SPI_INT_CLEAR - WILC_SPI_REG_BASE,
  989. &check);
  990. if (ret || ((check & EN_VMM) == (val & EN_VMM)))
  991. break;
  992. retry--;
  993. }
  994. return ret;
  995. }
  996. static int wilc_spi_sync_ext(struct wilc *wilc, int nint)
  997. {
  998. struct spi_device *spi = to_spi_device(wilc->dev);
  999. u32 reg;
  1000. int ret, i;
  1001. if (nint > MAX_NUM_INT) {
  1002. dev_err(&spi->dev, "Too many interrupts (%d)...\n", nint);
  1003. return -EINVAL;
  1004. }
  1005. /*
  1006. * interrupt pin mux select
  1007. */
  1008. ret = wilc_spi_read_reg(wilc, WILC_PIN_MUX_0, &reg);
  1009. if (ret) {
  1010. dev_err(&spi->dev, "Failed read reg (%08x)...\n",
  1011. WILC_PIN_MUX_0);
  1012. return ret;
  1013. }
  1014. reg |= BIT(8);
  1015. ret = wilc_spi_write_reg(wilc, WILC_PIN_MUX_0, reg);
  1016. if (ret) {
  1017. dev_err(&spi->dev, "Failed write reg (%08x)...\n",
  1018. WILC_PIN_MUX_0);
  1019. return ret;
  1020. }
  1021. /*
  1022. * interrupt enable
  1023. */
  1024. ret = wilc_spi_read_reg(wilc, WILC_INTR_ENABLE, &reg);
  1025. if (ret) {
  1026. dev_err(&spi->dev, "Failed read reg (%08x)...\n",
  1027. WILC_INTR_ENABLE);
  1028. return ret;
  1029. }
  1030. for (i = 0; (i < 5) && (nint > 0); i++, nint--)
  1031. reg |= (BIT((27 + i)));
  1032. ret = wilc_spi_write_reg(wilc, WILC_INTR_ENABLE, reg);
  1033. if (ret) {
  1034. dev_err(&spi->dev, "Failed write reg (%08x)...\n",
  1035. WILC_INTR_ENABLE);
  1036. return ret;
  1037. }
  1038. if (nint) {
  1039. ret = wilc_spi_read_reg(wilc, WILC_INTR2_ENABLE, &reg);
  1040. if (ret) {
  1041. dev_err(&spi->dev, "Failed read reg (%08x)...\n",
  1042. WILC_INTR2_ENABLE);
  1043. return ret;
  1044. }
  1045. for (i = 0; (i < 3) && (nint > 0); i++, nint--)
  1046. reg |= BIT(i);
  1047. ret = wilc_spi_write_reg(wilc, WILC_INTR2_ENABLE, reg);
  1048. if (ret) {
  1049. dev_err(&spi->dev, "Failed write reg (%08x)...\n",
  1050. WILC_INTR2_ENABLE);
  1051. return ret;
  1052. }
  1053. }
  1054. return 0;
  1055. }
  1056. /* Global spi HIF function table */
  1057. static const struct wilc_hif_func wilc_hif_spi = {
  1058. .hif_init = wilc_spi_init,
  1059. .hif_deinit = wilc_spi_deinit,
  1060. .hif_read_reg = wilc_spi_read_reg,
  1061. .hif_write_reg = wilc_spi_write_reg,
  1062. .hif_block_rx = wilc_spi_read,
  1063. .hif_block_tx = wilc_spi_write,
  1064. .hif_read_int = wilc_spi_read_int,
  1065. .hif_clear_int_ext = wilc_spi_clear_int_ext,
  1066. .hif_read_size = wilc_spi_read_size,
  1067. .hif_block_tx_ext = wilc_spi_write,
  1068. .hif_block_rx_ext = wilc_spi_read,
  1069. .hif_sync_ext = wilc_spi_sync_ext,
  1070. .hif_reset = wilc_spi_reset,
  1071. .hif_is_init = wilc_spi_is_init,
  1072. };