spi-fsl-dspi.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Copyright 2013 Freescale Semiconductor, Inc.
  4. //
  5. // Freescale DSPI driver
  6. // This file contains a driver for the Freescale DSPI
  7. #include <linux/clk.h>
  8. #include <linux/delay.h>
  9. #include <linux/dmaengine.h>
  10. #include <linux/dma-mapping.h>
  11. #include <linux/err.h>
  12. #include <linux/errno.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/io.h>
  15. #include <linux/kernel.h>
  16. #include <linux/math64.h>
  17. #include <linux/module.h>
  18. #include <linux/of.h>
  19. #include <linux/of_device.h>
  20. #include <linux/pinctrl/consumer.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/pm_runtime.h>
  23. #include <linux/regmap.h>
  24. #include <linux/sched.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/spi/spi-fsl-dspi.h>
  27. #include <linux/spi/spi_bitbang.h>
  28. #include <linux/time.h>
  29. #define DRIVER_NAME "fsl-dspi"
  30. #ifdef CONFIG_M5441x
  31. #define DSPI_FIFO_SIZE 16
  32. #else
  33. #define DSPI_FIFO_SIZE 4
  34. #endif
  35. #define DSPI_DMA_BUFSIZE (DSPI_FIFO_SIZE * 1024)
  36. #define SPI_MCR 0x00
  37. #define SPI_MCR_MASTER (1 << 31)
  38. #define SPI_MCR_PCSIS (0x3F << 16)
  39. #define SPI_MCR_CLR_TXF (1 << 11)
  40. #define SPI_MCR_CLR_RXF (1 << 10)
  41. #define SPI_MCR_XSPI (1 << 3)
  42. #define SPI_TCR 0x08
  43. #define SPI_TCR_GET_TCNT(x) (((x) & 0xffff0000) >> 16)
  44. #define SPI_CTAR(x) (0x0c + (((x) & 0x3) * 4))
  45. #define SPI_CTAR_FMSZ(x) (((x) & 0x0000000f) << 27)
  46. #define SPI_CTAR_CPOL(x) ((x) << 26)
  47. #define SPI_CTAR_CPHA(x) ((x) << 25)
  48. #define SPI_CTAR_LSBFE(x) ((x) << 24)
  49. #define SPI_CTAR_PCSSCK(x) (((x) & 0x00000003) << 22)
  50. #define SPI_CTAR_PASC(x) (((x) & 0x00000003) << 20)
  51. #define SPI_CTAR_PDT(x) (((x) & 0x00000003) << 18)
  52. #define SPI_CTAR_PBR(x) (((x) & 0x00000003) << 16)
  53. #define SPI_CTAR_CSSCK(x) (((x) & 0x0000000f) << 12)
  54. #define SPI_CTAR_ASC(x) (((x) & 0x0000000f) << 8)
  55. #define SPI_CTAR_DT(x) (((x) & 0x0000000f) << 4)
  56. #define SPI_CTAR_BR(x) ((x) & 0x0000000f)
  57. #define SPI_CTAR_SCALE_BITS 0xf
  58. #define SPI_CTAR0_SLAVE 0x0c
  59. #define SPI_SR 0x2c
  60. #define SPI_SR_EOQF 0x10000000
  61. #define SPI_SR_TCFQF 0x80000000
  62. #define SPI_SR_CLEAR 0xdaad0000
  63. #define SPI_RSER_TFFFE BIT(25)
  64. #define SPI_RSER_TFFFD BIT(24)
  65. #define SPI_RSER_RFDFE BIT(17)
  66. #define SPI_RSER_RFDFD BIT(16)
  67. #define SPI_RSER 0x30
  68. #define SPI_RSER_EOQFE 0x10000000
  69. #define SPI_RSER_TCFQE 0x80000000
  70. #define SPI_PUSHR 0x34
  71. #define SPI_PUSHR_CMD_CONT (1 << 15)
  72. #define SPI_PUSHR_CONT (SPI_PUSHR_CMD_CONT << 16)
  73. #define SPI_PUSHR_CMD_CTAS(x) (((x) & 0x0003) << 12)
  74. #define SPI_PUSHR_CTAS(x) (SPI_PUSHR_CMD_CTAS(x) << 16)
  75. #define SPI_PUSHR_CMD_EOQ (1 << 11)
  76. #define SPI_PUSHR_EOQ (SPI_PUSHR_CMD_EOQ << 16)
  77. #define SPI_PUSHR_CMD_CTCNT (1 << 10)
  78. #define SPI_PUSHR_CTCNT (SPI_PUSHR_CMD_CTCNT << 16)
  79. #define SPI_PUSHR_CMD_PCS(x) ((1 << x) & 0x003f)
  80. #define SPI_PUSHR_PCS(x) (SPI_PUSHR_CMD_PCS(x) << 16)
  81. #define SPI_PUSHR_TXDATA(x) ((x) & 0x0000ffff)
  82. #define SPI_PUSHR_SLAVE 0x34
  83. #define SPI_POPR 0x38
  84. #define SPI_POPR_RXDATA(x) ((x) & 0x0000ffff)
  85. #define SPI_TXFR0 0x3c
  86. #define SPI_TXFR1 0x40
  87. #define SPI_TXFR2 0x44
  88. #define SPI_TXFR3 0x48
  89. #define SPI_RXFR0 0x7c
  90. #define SPI_RXFR1 0x80
  91. #define SPI_RXFR2 0x84
  92. #define SPI_RXFR3 0x88
  93. #define SPI_CTARE(x) (0x11c + (((x) & 0x3) * 4))
  94. #define SPI_CTARE_FMSZE(x) (((x) & 0x1) << 16)
  95. #define SPI_CTARE_DTCP(x) ((x) & 0x7ff)
  96. #define SPI_SREX 0x13c
  97. #define SPI_FRAME_BITS(bits) SPI_CTAR_FMSZ((bits) - 1)
  98. #define SPI_FRAME_BITS_MASK SPI_CTAR_FMSZ(0xf)
  99. #define SPI_FRAME_BITS_16 SPI_CTAR_FMSZ(0xf)
  100. #define SPI_FRAME_BITS_8 SPI_CTAR_FMSZ(0x7)
  101. #define SPI_FRAME_EBITS(bits) SPI_CTARE_FMSZE(((bits) - 1) >> 4)
  102. #define SPI_FRAME_EBITS_MASK SPI_CTARE_FMSZE(1)
  103. /* Register offsets for regmap_pushr */
  104. #define PUSHR_CMD 0x0
  105. #define PUSHR_TX 0x2
  106. #define SPI_CS_INIT 0x01
  107. #define SPI_CS_ASSERT 0x02
  108. #define SPI_CS_DROP 0x04
  109. #define DMA_COMPLETION_TIMEOUT msecs_to_jiffies(3000)
  110. struct chip_data {
  111. u32 ctar_val;
  112. u16 void_write_data;
  113. };
  114. enum dspi_trans_mode {
  115. DSPI_EOQ_MODE = 0,
  116. DSPI_TCFQ_MODE,
  117. DSPI_DMA_MODE,
  118. };
  119. struct fsl_dspi_devtype_data {
  120. enum dspi_trans_mode trans_mode;
  121. u8 max_clock_factor;
  122. bool xspi_mode;
  123. };
  124. static const struct fsl_dspi_devtype_data vf610_data = {
  125. .trans_mode = DSPI_DMA_MODE,
  126. .max_clock_factor = 2,
  127. };
  128. static const struct fsl_dspi_devtype_data ls1021a_v1_data = {
  129. .trans_mode = DSPI_TCFQ_MODE,
  130. .max_clock_factor = 8,
  131. .xspi_mode = true,
  132. };
  133. static const struct fsl_dspi_devtype_data ls2085a_data = {
  134. .trans_mode = DSPI_TCFQ_MODE,
  135. .max_clock_factor = 8,
  136. };
  137. static const struct fsl_dspi_devtype_data coldfire_data = {
  138. .trans_mode = DSPI_EOQ_MODE,
  139. .max_clock_factor = 8,
  140. };
  141. struct fsl_dspi_dma {
  142. /* Length of transfer in words of DSPI_FIFO_SIZE */
  143. u32 curr_xfer_len;
  144. u32 *tx_dma_buf;
  145. struct dma_chan *chan_tx;
  146. dma_addr_t tx_dma_phys;
  147. struct completion cmd_tx_complete;
  148. struct dma_async_tx_descriptor *tx_desc;
  149. u32 *rx_dma_buf;
  150. struct dma_chan *chan_rx;
  151. dma_addr_t rx_dma_phys;
  152. struct completion cmd_rx_complete;
  153. struct dma_async_tx_descriptor *rx_desc;
  154. };
  155. struct fsl_dspi {
  156. struct spi_master *master;
  157. struct platform_device *pdev;
  158. struct regmap *regmap;
  159. struct regmap *regmap_pushr;
  160. int irq;
  161. struct clk *clk;
  162. struct spi_transfer *cur_transfer;
  163. struct spi_message *cur_msg;
  164. struct chip_data *cur_chip;
  165. size_t len;
  166. const void *tx;
  167. void *rx;
  168. void *rx_end;
  169. u16 void_write_data;
  170. u16 tx_cmd;
  171. u8 bits_per_word;
  172. u8 bytes_per_word;
  173. const struct fsl_dspi_devtype_data *devtype_data;
  174. wait_queue_head_t waitq;
  175. u32 waitflags;
  176. struct fsl_dspi_dma *dma;
  177. };
  178. static u32 dspi_pop_tx(struct fsl_dspi *dspi)
  179. {
  180. u32 txdata = 0;
  181. if (dspi->tx) {
  182. if (dspi->bytes_per_word == 1)
  183. txdata = *(u8 *)dspi->tx;
  184. else if (dspi->bytes_per_word == 2)
  185. txdata = *(u16 *)dspi->tx;
  186. else /* dspi->bytes_per_word == 4 */
  187. txdata = *(u32 *)dspi->tx;
  188. dspi->tx += dspi->bytes_per_word;
  189. }
  190. dspi->len -= dspi->bytes_per_word;
  191. return txdata;
  192. }
  193. static u32 dspi_pop_tx_pushr(struct fsl_dspi *dspi)
  194. {
  195. u16 cmd = dspi->tx_cmd, data = dspi_pop_tx(dspi);
  196. if (dspi->len > 0)
  197. cmd |= SPI_PUSHR_CMD_CONT;
  198. return cmd << 16 | data;
  199. }
  200. static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata)
  201. {
  202. if (!dspi->rx)
  203. return;
  204. /* Mask of undefined bits */
  205. rxdata &= (1 << dspi->bits_per_word) - 1;
  206. if (dspi->bytes_per_word == 1)
  207. *(u8 *)dspi->rx = rxdata;
  208. else if (dspi->bytes_per_word == 2)
  209. *(u16 *)dspi->rx = rxdata;
  210. else /* dspi->bytes_per_word == 4 */
  211. *(u32 *)dspi->rx = rxdata;
  212. dspi->rx += dspi->bytes_per_word;
  213. }
  214. static void dspi_tx_dma_callback(void *arg)
  215. {
  216. struct fsl_dspi *dspi = arg;
  217. struct fsl_dspi_dma *dma = dspi->dma;
  218. complete(&dma->cmd_tx_complete);
  219. }
  220. static void dspi_rx_dma_callback(void *arg)
  221. {
  222. struct fsl_dspi *dspi = arg;
  223. struct fsl_dspi_dma *dma = dspi->dma;
  224. int i;
  225. if (dspi->rx) {
  226. for (i = 0; i < dma->curr_xfer_len; i++)
  227. dspi_push_rx(dspi, dspi->dma->rx_dma_buf[i]);
  228. }
  229. complete(&dma->cmd_rx_complete);
  230. }
  231. static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
  232. {
  233. struct fsl_dspi_dma *dma = dspi->dma;
  234. struct device *dev = &dspi->pdev->dev;
  235. int time_left;
  236. int i;
  237. for (i = 0; i < dma->curr_xfer_len; i++)
  238. dspi->dma->tx_dma_buf[i] = dspi_pop_tx_pushr(dspi);
  239. dma->tx_desc = dmaengine_prep_slave_single(dma->chan_tx,
  240. dma->tx_dma_phys,
  241. dma->curr_xfer_len *
  242. DMA_SLAVE_BUSWIDTH_4_BYTES,
  243. DMA_MEM_TO_DEV,
  244. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  245. if (!dma->tx_desc) {
  246. dev_err(dev, "Not able to get desc for DMA xfer\n");
  247. return -EIO;
  248. }
  249. dma->tx_desc->callback = dspi_tx_dma_callback;
  250. dma->tx_desc->callback_param = dspi;
  251. if (dma_submit_error(dmaengine_submit(dma->tx_desc))) {
  252. dev_err(dev, "DMA submit failed\n");
  253. return -EINVAL;
  254. }
  255. dma->rx_desc = dmaengine_prep_slave_single(dma->chan_rx,
  256. dma->rx_dma_phys,
  257. dma->curr_xfer_len *
  258. DMA_SLAVE_BUSWIDTH_4_BYTES,
  259. DMA_DEV_TO_MEM,
  260. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  261. if (!dma->rx_desc) {
  262. dev_err(dev, "Not able to get desc for DMA xfer\n");
  263. return -EIO;
  264. }
  265. dma->rx_desc->callback = dspi_rx_dma_callback;
  266. dma->rx_desc->callback_param = dspi;
  267. if (dma_submit_error(dmaengine_submit(dma->rx_desc))) {
  268. dev_err(dev, "DMA submit failed\n");
  269. return -EINVAL;
  270. }
  271. reinit_completion(&dspi->dma->cmd_rx_complete);
  272. reinit_completion(&dspi->dma->cmd_tx_complete);
  273. dma_async_issue_pending(dma->chan_rx);
  274. dma_async_issue_pending(dma->chan_tx);
  275. time_left = wait_for_completion_timeout(&dspi->dma->cmd_tx_complete,
  276. DMA_COMPLETION_TIMEOUT);
  277. if (time_left == 0) {
  278. dev_err(dev, "DMA tx timeout\n");
  279. dmaengine_terminate_all(dma->chan_tx);
  280. dmaengine_terminate_all(dma->chan_rx);
  281. return -ETIMEDOUT;
  282. }
  283. time_left = wait_for_completion_timeout(&dspi->dma->cmd_rx_complete,
  284. DMA_COMPLETION_TIMEOUT);
  285. if (time_left == 0) {
  286. dev_err(dev, "DMA rx timeout\n");
  287. dmaengine_terminate_all(dma->chan_tx);
  288. dmaengine_terminate_all(dma->chan_rx);
  289. return -ETIMEDOUT;
  290. }
  291. return 0;
  292. }
  293. static int dspi_dma_xfer(struct fsl_dspi *dspi)
  294. {
  295. struct fsl_dspi_dma *dma = dspi->dma;
  296. struct device *dev = &dspi->pdev->dev;
  297. struct spi_message *message = dspi->cur_msg;
  298. int curr_remaining_bytes;
  299. int bytes_per_buffer;
  300. int ret = 0;
  301. curr_remaining_bytes = dspi->len;
  302. bytes_per_buffer = DSPI_DMA_BUFSIZE / DSPI_FIFO_SIZE;
  303. while (curr_remaining_bytes) {
  304. /* Check if current transfer fits the DMA buffer */
  305. dma->curr_xfer_len = curr_remaining_bytes
  306. / dspi->bytes_per_word;
  307. if (dma->curr_xfer_len > bytes_per_buffer)
  308. dma->curr_xfer_len = bytes_per_buffer;
  309. ret = dspi_next_xfer_dma_submit(dspi);
  310. if (ret) {
  311. dev_err(dev, "DMA transfer failed\n");
  312. goto exit;
  313. } else {
  314. const int len =
  315. dma->curr_xfer_len * dspi->bytes_per_word;
  316. curr_remaining_bytes -= len;
  317. message->actual_length += len;
  318. if (curr_remaining_bytes < 0)
  319. curr_remaining_bytes = 0;
  320. }
  321. }
  322. exit:
  323. return ret;
  324. }
  325. static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
  326. {
  327. struct fsl_dspi_dma *dma;
  328. struct dma_slave_config cfg;
  329. struct device *dev = &dspi->pdev->dev;
  330. int ret;
  331. dma = devm_kzalloc(dev, sizeof(*dma), GFP_KERNEL);
  332. if (!dma)
  333. return -ENOMEM;
  334. dma->chan_rx = dma_request_slave_channel(dev, "rx");
  335. if (!dma->chan_rx) {
  336. dev_err(dev, "rx dma channel not available\n");
  337. ret = -ENODEV;
  338. return ret;
  339. }
  340. dma->chan_tx = dma_request_slave_channel(dev, "tx");
  341. if (!dma->chan_tx) {
  342. dev_err(dev, "tx dma channel not available\n");
  343. ret = -ENODEV;
  344. goto err_tx_channel;
  345. }
  346. dma->tx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE,
  347. &dma->tx_dma_phys, GFP_KERNEL);
  348. if (!dma->tx_dma_buf) {
  349. ret = -ENOMEM;
  350. goto err_tx_dma_buf;
  351. }
  352. dma->rx_dma_buf = dma_alloc_coherent(dev, DSPI_DMA_BUFSIZE,
  353. &dma->rx_dma_phys, GFP_KERNEL);
  354. if (!dma->rx_dma_buf) {
  355. ret = -ENOMEM;
  356. goto err_rx_dma_buf;
  357. }
  358. cfg.src_addr = phy_addr + SPI_POPR;
  359. cfg.dst_addr = phy_addr + SPI_PUSHR;
  360. cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  361. cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  362. cfg.src_maxburst = 1;
  363. cfg.dst_maxburst = 1;
  364. cfg.direction = DMA_DEV_TO_MEM;
  365. ret = dmaengine_slave_config(dma->chan_rx, &cfg);
  366. if (ret) {
  367. dev_err(dev, "can't configure rx dma channel\n");
  368. ret = -EINVAL;
  369. goto err_slave_config;
  370. }
  371. cfg.direction = DMA_MEM_TO_DEV;
  372. ret = dmaengine_slave_config(dma->chan_tx, &cfg);
  373. if (ret) {
  374. dev_err(dev, "can't configure tx dma channel\n");
  375. ret = -EINVAL;
  376. goto err_slave_config;
  377. }
  378. dspi->dma = dma;
  379. init_completion(&dma->cmd_tx_complete);
  380. init_completion(&dma->cmd_rx_complete);
  381. return 0;
  382. err_slave_config:
  383. dma_free_coherent(dev, DSPI_DMA_BUFSIZE,
  384. dma->rx_dma_buf, dma->rx_dma_phys);
  385. err_rx_dma_buf:
  386. dma_free_coherent(dev, DSPI_DMA_BUFSIZE,
  387. dma->tx_dma_buf, dma->tx_dma_phys);
  388. err_tx_dma_buf:
  389. dma_release_channel(dma->chan_tx);
  390. err_tx_channel:
  391. dma_release_channel(dma->chan_rx);
  392. devm_kfree(dev, dma);
  393. dspi->dma = NULL;
  394. return ret;
  395. }
  396. static void dspi_release_dma(struct fsl_dspi *dspi)
  397. {
  398. struct fsl_dspi_dma *dma = dspi->dma;
  399. struct device *dev = &dspi->pdev->dev;
  400. if (dma) {
  401. if (dma->chan_tx) {
  402. dma_unmap_single(dev, dma->tx_dma_phys,
  403. DSPI_DMA_BUFSIZE, DMA_TO_DEVICE);
  404. dma_release_channel(dma->chan_tx);
  405. }
  406. if (dma->chan_rx) {
  407. dma_unmap_single(dev, dma->rx_dma_phys,
  408. DSPI_DMA_BUFSIZE, DMA_FROM_DEVICE);
  409. dma_release_channel(dma->chan_rx);
  410. }
  411. }
  412. }
  413. static void hz_to_spi_baud(char *pbr, char *br, int speed_hz,
  414. unsigned long clkrate)
  415. {
  416. /* Valid baud rate pre-scaler values */
  417. int pbr_tbl[4] = {2, 3, 5, 7};
  418. int brs[16] = { 2, 4, 6, 8,
  419. 16, 32, 64, 128,
  420. 256, 512, 1024, 2048,
  421. 4096, 8192, 16384, 32768 };
  422. int scale_needed, scale, minscale = INT_MAX;
  423. int i, j;
  424. scale_needed = clkrate / speed_hz;
  425. if (clkrate % speed_hz)
  426. scale_needed++;
  427. for (i = 0; i < ARRAY_SIZE(brs); i++)
  428. for (j = 0; j < ARRAY_SIZE(pbr_tbl); j++) {
  429. scale = brs[i] * pbr_tbl[j];
  430. if (scale >= scale_needed) {
  431. if (scale < minscale) {
  432. minscale = scale;
  433. *br = i;
  434. *pbr = j;
  435. }
  436. break;
  437. }
  438. }
  439. if (minscale == INT_MAX) {
  440. pr_warn("Can not find valid baud rate,speed_hz is %d,clkrate is %ld, we use the max prescaler value.\n",
  441. speed_hz, clkrate);
  442. *pbr = ARRAY_SIZE(pbr_tbl) - 1;
  443. *br = ARRAY_SIZE(brs) - 1;
  444. }
  445. }
  446. static void ns_delay_scale(char *psc, char *sc, int delay_ns,
  447. unsigned long clkrate)
  448. {
  449. int pscale_tbl[4] = {1, 3, 5, 7};
  450. int scale_needed, scale, minscale = INT_MAX;
  451. int i, j;
  452. u32 remainder;
  453. scale_needed = div_u64_rem((u64)delay_ns * clkrate, NSEC_PER_SEC,
  454. &remainder);
  455. if (remainder)
  456. scale_needed++;
  457. for (i = 0; i < ARRAY_SIZE(pscale_tbl); i++)
  458. for (j = 0; j <= SPI_CTAR_SCALE_BITS; j++) {
  459. scale = pscale_tbl[i] * (2 << j);
  460. if (scale >= scale_needed) {
  461. if (scale < minscale) {
  462. minscale = scale;
  463. *psc = i;
  464. *sc = j;
  465. }
  466. break;
  467. }
  468. }
  469. if (minscale == INT_MAX) {
  470. pr_warn("Cannot find correct scale values for %dns delay at clkrate %ld, using max prescaler value",
  471. delay_ns, clkrate);
  472. *psc = ARRAY_SIZE(pscale_tbl) - 1;
  473. *sc = SPI_CTAR_SCALE_BITS;
  474. }
  475. }
  476. static void fifo_write(struct fsl_dspi *dspi)
  477. {
  478. regmap_write(dspi->regmap, SPI_PUSHR, dspi_pop_tx_pushr(dspi));
  479. }
  480. static void cmd_fifo_write(struct fsl_dspi *dspi)
  481. {
  482. u16 cmd = dspi->tx_cmd;
  483. if (dspi->len > 0)
  484. cmd |= SPI_PUSHR_CMD_CONT;
  485. regmap_write(dspi->regmap_pushr, PUSHR_CMD, cmd);
  486. }
  487. static void tx_fifo_write(struct fsl_dspi *dspi, u16 txdata)
  488. {
  489. regmap_write(dspi->regmap_pushr, PUSHR_TX, txdata);
  490. }
  491. static void dspi_tcfq_write(struct fsl_dspi *dspi)
  492. {
  493. /* Clear transfer count */
  494. dspi->tx_cmd |= SPI_PUSHR_CMD_CTCNT;
  495. if (dspi->devtype_data->xspi_mode && dspi->bits_per_word > 16) {
  496. /* Write two TX FIFO entries first, and then the corresponding
  497. * CMD FIFO entry.
  498. */
  499. u32 data = dspi_pop_tx(dspi);
  500. if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) {
  501. /* LSB */
  502. tx_fifo_write(dspi, data & 0xFFFF);
  503. tx_fifo_write(dspi, data >> 16);
  504. } else {
  505. /* MSB */
  506. tx_fifo_write(dspi, data >> 16);
  507. tx_fifo_write(dspi, data & 0xFFFF);
  508. }
  509. cmd_fifo_write(dspi);
  510. } else {
  511. /* Write one entry to both TX FIFO and CMD FIFO
  512. * simultaneously.
  513. */
  514. fifo_write(dspi);
  515. }
  516. }
  517. static u32 fifo_read(struct fsl_dspi *dspi)
  518. {
  519. u32 rxdata = 0;
  520. regmap_read(dspi->regmap, SPI_POPR, &rxdata);
  521. return rxdata;
  522. }
  523. static void dspi_tcfq_read(struct fsl_dspi *dspi)
  524. {
  525. dspi_push_rx(dspi, fifo_read(dspi));
  526. }
  527. static void dspi_eoq_write(struct fsl_dspi *dspi)
  528. {
  529. int fifo_size = DSPI_FIFO_SIZE;
  530. u16 xfer_cmd = dspi->tx_cmd;
  531. /* Fill TX FIFO with as many transfers as possible */
  532. while (dspi->len && fifo_size--) {
  533. dspi->tx_cmd = xfer_cmd;
  534. /* Request EOQF for last transfer in FIFO */
  535. if (dspi->len == dspi->bytes_per_word || fifo_size == 0)
  536. dspi->tx_cmd |= SPI_PUSHR_CMD_EOQ;
  537. /* Clear transfer count for first transfer in FIFO */
  538. if (fifo_size == (DSPI_FIFO_SIZE - 1))
  539. dspi->tx_cmd |= SPI_PUSHR_CMD_CTCNT;
  540. /* Write combined TX FIFO and CMD FIFO entry */
  541. fifo_write(dspi);
  542. }
  543. }
  544. static void dspi_eoq_read(struct fsl_dspi *dspi)
  545. {
  546. int fifo_size = DSPI_FIFO_SIZE;
  547. /* Read one FIFO entry at and push to rx buffer */
  548. while ((dspi->rx < dspi->rx_end) && fifo_size--)
  549. dspi_push_rx(dspi, fifo_read(dspi));
  550. }
  551. static int dspi_transfer_one_message(struct spi_master *master,
  552. struct spi_message *message)
  553. {
  554. struct fsl_dspi *dspi = spi_master_get_devdata(master);
  555. struct spi_device *spi = message->spi;
  556. struct spi_transfer *transfer;
  557. int status = 0;
  558. enum dspi_trans_mode trans_mode;
  559. message->actual_length = 0;
  560. list_for_each_entry(transfer, &message->transfers, transfer_list) {
  561. dspi->cur_transfer = transfer;
  562. dspi->cur_msg = message;
  563. dspi->cur_chip = spi_get_ctldata(spi);
  564. /* Prepare command word for CMD FIFO */
  565. dspi->tx_cmd = SPI_PUSHR_CMD_CTAS(0) |
  566. SPI_PUSHR_CMD_PCS(spi->chip_select);
  567. if (list_is_last(&dspi->cur_transfer->transfer_list,
  568. &dspi->cur_msg->transfers)) {
  569. /* Leave PCS activated after last transfer when
  570. * cs_change is set.
  571. */
  572. if (transfer->cs_change)
  573. dspi->tx_cmd |= SPI_PUSHR_CMD_CONT;
  574. } else {
  575. /* Keep PCS active between transfers in same message
  576. * when cs_change is not set, and de-activate PCS
  577. * between transfers in the same message when
  578. * cs_change is set.
  579. */
  580. if (!transfer->cs_change)
  581. dspi->tx_cmd |= SPI_PUSHR_CMD_CONT;
  582. }
  583. dspi->void_write_data = dspi->cur_chip->void_write_data;
  584. dspi->tx = transfer->tx_buf;
  585. dspi->rx = transfer->rx_buf;
  586. dspi->rx_end = dspi->rx + transfer->len;
  587. dspi->len = transfer->len;
  588. /* Validated transfer specific frame size (defaults applied) */
  589. dspi->bits_per_word = transfer->bits_per_word;
  590. if (transfer->bits_per_word <= 8)
  591. dspi->bytes_per_word = 1;
  592. else if (transfer->bits_per_word <= 16)
  593. dspi->bytes_per_word = 2;
  594. else
  595. dspi->bytes_per_word = 4;
  596. regmap_update_bits(dspi->regmap, SPI_MCR,
  597. SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF,
  598. SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF);
  599. regmap_write(dspi->regmap, SPI_CTAR(0),
  600. dspi->cur_chip->ctar_val |
  601. SPI_FRAME_BITS(transfer->bits_per_word));
  602. if (dspi->devtype_data->xspi_mode)
  603. regmap_write(dspi->regmap, SPI_CTARE(0),
  604. SPI_FRAME_EBITS(transfer->bits_per_word)
  605. | SPI_CTARE_DTCP(1));
  606. trans_mode = dspi->devtype_data->trans_mode;
  607. switch (trans_mode) {
  608. case DSPI_EOQ_MODE:
  609. regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_EOQFE);
  610. dspi_eoq_write(dspi);
  611. break;
  612. case DSPI_TCFQ_MODE:
  613. regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_TCFQE);
  614. dspi_tcfq_write(dspi);
  615. break;
  616. case DSPI_DMA_MODE:
  617. regmap_write(dspi->regmap, SPI_RSER,
  618. SPI_RSER_TFFFE | SPI_RSER_TFFFD |
  619. SPI_RSER_RFDFE | SPI_RSER_RFDFD);
  620. status = dspi_dma_xfer(dspi);
  621. break;
  622. default:
  623. dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n",
  624. trans_mode);
  625. status = -EINVAL;
  626. goto out;
  627. }
  628. if (trans_mode != DSPI_DMA_MODE) {
  629. if (wait_event_interruptible(dspi->waitq,
  630. dspi->waitflags))
  631. dev_err(&dspi->pdev->dev,
  632. "wait transfer complete fail!\n");
  633. dspi->waitflags = 0;
  634. }
  635. if (transfer->delay_usecs)
  636. udelay(transfer->delay_usecs);
  637. }
  638. out:
  639. message->status = status;
  640. spi_finalize_current_message(master);
  641. return status;
  642. }
  643. static int dspi_setup(struct spi_device *spi)
  644. {
  645. struct chip_data *chip;
  646. struct fsl_dspi *dspi = spi_master_get_devdata(spi->master);
  647. struct fsl_dspi_platform_data *pdata;
  648. u32 cs_sck_delay = 0, sck_cs_delay = 0;
  649. unsigned char br = 0, pbr = 0, pcssck = 0, cssck = 0;
  650. unsigned char pasc = 0, asc = 0;
  651. unsigned long clkrate;
  652. /* Only alloc on first setup */
  653. chip = spi_get_ctldata(spi);
  654. if (chip == NULL) {
  655. chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
  656. if (!chip)
  657. return -ENOMEM;
  658. }
  659. pdata = dev_get_platdata(&dspi->pdev->dev);
  660. if (!pdata) {
  661. of_property_read_u32(spi->dev.of_node, "fsl,spi-cs-sck-delay",
  662. &cs_sck_delay);
  663. of_property_read_u32(spi->dev.of_node, "fsl,spi-sck-cs-delay",
  664. &sck_cs_delay);
  665. } else {
  666. cs_sck_delay = pdata->cs_sck_delay;
  667. sck_cs_delay = pdata->sck_cs_delay;
  668. }
  669. chip->void_write_data = 0;
  670. clkrate = clk_get_rate(dspi->clk);
  671. hz_to_spi_baud(&pbr, &br, spi->max_speed_hz, clkrate);
  672. /* Set PCS to SCK delay scale values */
  673. ns_delay_scale(&pcssck, &cssck, cs_sck_delay, clkrate);
  674. /* Set After SCK delay scale values */
  675. ns_delay_scale(&pasc, &asc, sck_cs_delay, clkrate);
  676. chip->ctar_val = SPI_CTAR_CPOL(spi->mode & SPI_CPOL ? 1 : 0)
  677. | SPI_CTAR_CPHA(spi->mode & SPI_CPHA ? 1 : 0)
  678. | SPI_CTAR_LSBFE(spi->mode & SPI_LSB_FIRST ? 1 : 0)
  679. | SPI_CTAR_PCSSCK(pcssck)
  680. | SPI_CTAR_CSSCK(cssck)
  681. | SPI_CTAR_PASC(pasc)
  682. | SPI_CTAR_ASC(asc)
  683. | SPI_CTAR_PBR(pbr)
  684. | SPI_CTAR_BR(br);
  685. spi_set_ctldata(spi, chip);
  686. return 0;
  687. }
  688. static void dspi_cleanup(struct spi_device *spi)
  689. {
  690. struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
  691. dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n",
  692. spi->master->bus_num, spi->chip_select);
  693. kfree(chip);
  694. }
  695. static irqreturn_t dspi_interrupt(int irq, void *dev_id)
  696. {
  697. struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id;
  698. struct spi_message *msg = dspi->cur_msg;
  699. enum dspi_trans_mode trans_mode;
  700. u32 spi_sr, spi_tcr;
  701. u16 spi_tcnt;
  702. regmap_read(dspi->regmap, SPI_SR, &spi_sr);
  703. regmap_write(dspi->regmap, SPI_SR, spi_sr);
  704. if (spi_sr & (SPI_SR_EOQF | SPI_SR_TCFQF)) {
  705. /* Get transfer counter (in number of SPI transfers). It was
  706. * reset to 0 when transfer(s) were started.
  707. */
  708. regmap_read(dspi->regmap, SPI_TCR, &spi_tcr);
  709. spi_tcnt = SPI_TCR_GET_TCNT(spi_tcr);
  710. /* Update total number of bytes that were transferred */
  711. msg->actual_length += spi_tcnt * dspi->bytes_per_word;
  712. trans_mode = dspi->devtype_data->trans_mode;
  713. switch (trans_mode) {
  714. case DSPI_EOQ_MODE:
  715. dspi_eoq_read(dspi);
  716. break;
  717. case DSPI_TCFQ_MODE:
  718. dspi_tcfq_read(dspi);
  719. break;
  720. default:
  721. dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n",
  722. trans_mode);
  723. return IRQ_HANDLED;
  724. }
  725. if (!dspi->len) {
  726. dspi->waitflags = 1;
  727. wake_up_interruptible(&dspi->waitq);
  728. } else {
  729. switch (trans_mode) {
  730. case DSPI_EOQ_MODE:
  731. dspi_eoq_write(dspi);
  732. break;
  733. case DSPI_TCFQ_MODE:
  734. dspi_tcfq_write(dspi);
  735. break;
  736. default:
  737. dev_err(&dspi->pdev->dev,
  738. "unsupported trans_mode %u\n",
  739. trans_mode);
  740. }
  741. }
  742. }
  743. return IRQ_HANDLED;
  744. }
  745. static const struct of_device_id fsl_dspi_dt_ids[] = {
  746. { .compatible = "fsl,vf610-dspi", .data = &vf610_data, },
  747. { .compatible = "fsl,ls1021a-v1.0-dspi", .data = &ls1021a_v1_data, },
  748. { .compatible = "fsl,ls2085a-dspi", .data = &ls2085a_data, },
  749. { /* sentinel */ }
  750. };
  751. MODULE_DEVICE_TABLE(of, fsl_dspi_dt_ids);
  752. #ifdef CONFIG_PM_SLEEP
  753. static int dspi_suspend(struct device *dev)
  754. {
  755. struct spi_master *master = dev_get_drvdata(dev);
  756. struct fsl_dspi *dspi = spi_master_get_devdata(master);
  757. spi_master_suspend(master);
  758. clk_disable_unprepare(dspi->clk);
  759. pinctrl_pm_select_sleep_state(dev);
  760. return 0;
  761. }
  762. static int dspi_resume(struct device *dev)
  763. {
  764. struct spi_master *master = dev_get_drvdata(dev);
  765. struct fsl_dspi *dspi = spi_master_get_devdata(master);
  766. int ret;
  767. pinctrl_pm_select_default_state(dev);
  768. ret = clk_prepare_enable(dspi->clk);
  769. if (ret)
  770. return ret;
  771. spi_master_resume(master);
  772. return 0;
  773. }
  774. #endif /* CONFIG_PM_SLEEP */
  775. static SIMPLE_DEV_PM_OPS(dspi_pm, dspi_suspend, dspi_resume);
  776. static const struct regmap_range dspi_volatile_ranges[] = {
  777. regmap_reg_range(SPI_MCR, SPI_TCR),
  778. regmap_reg_range(SPI_SR, SPI_SR),
  779. regmap_reg_range(SPI_PUSHR, SPI_RXFR3),
  780. };
  781. static const struct regmap_access_table dspi_volatile_table = {
  782. .yes_ranges = dspi_volatile_ranges,
  783. .n_yes_ranges = ARRAY_SIZE(dspi_volatile_ranges),
  784. };
  785. static const struct regmap_config dspi_regmap_config = {
  786. .reg_bits = 32,
  787. .val_bits = 32,
  788. .reg_stride = 4,
  789. .max_register = 0x88,
  790. .volatile_table = &dspi_volatile_table,
  791. };
  792. static const struct regmap_range dspi_xspi_volatile_ranges[] = {
  793. regmap_reg_range(SPI_MCR, SPI_TCR),
  794. regmap_reg_range(SPI_SR, SPI_SR),
  795. regmap_reg_range(SPI_PUSHR, SPI_RXFR3),
  796. regmap_reg_range(SPI_SREX, SPI_SREX),
  797. };
  798. static const struct regmap_access_table dspi_xspi_volatile_table = {
  799. .yes_ranges = dspi_xspi_volatile_ranges,
  800. .n_yes_ranges = ARRAY_SIZE(dspi_xspi_volatile_ranges),
  801. };
  802. static const struct regmap_config dspi_xspi_regmap_config[] = {
  803. {
  804. .reg_bits = 32,
  805. .val_bits = 32,
  806. .reg_stride = 4,
  807. .max_register = 0x13c,
  808. .volatile_table = &dspi_xspi_volatile_table,
  809. },
  810. {
  811. .name = "pushr",
  812. .reg_bits = 16,
  813. .val_bits = 16,
  814. .reg_stride = 2,
  815. .max_register = 0x2,
  816. },
  817. };
  818. static void dspi_init(struct fsl_dspi *dspi)
  819. {
  820. regmap_write(dspi->regmap, SPI_MCR, SPI_MCR_MASTER | SPI_MCR_PCSIS |
  821. (dspi->devtype_data->xspi_mode ? SPI_MCR_XSPI : 0));
  822. regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);
  823. if (dspi->devtype_data->xspi_mode)
  824. regmap_write(dspi->regmap, SPI_CTARE(0),
  825. SPI_CTARE_FMSZE(0) | SPI_CTARE_DTCP(1));
  826. }
  827. static int dspi_probe(struct platform_device *pdev)
  828. {
  829. struct device_node *np = pdev->dev.of_node;
  830. struct spi_master *master;
  831. struct fsl_dspi *dspi;
  832. struct resource *res;
  833. const struct regmap_config *regmap_config;
  834. void __iomem *base;
  835. struct fsl_dspi_platform_data *pdata;
  836. int ret = 0, cs_num, bus_num;
  837. master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi));
  838. if (!master)
  839. return -ENOMEM;
  840. dspi = spi_master_get_devdata(master);
  841. dspi->pdev = pdev;
  842. dspi->master = master;
  843. master->transfer = NULL;
  844. master->setup = dspi_setup;
  845. master->transfer_one_message = dspi_transfer_one_message;
  846. master->dev.of_node = pdev->dev.of_node;
  847. master->cleanup = dspi_cleanup;
  848. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LSB_FIRST;
  849. pdata = dev_get_platdata(&pdev->dev);
  850. if (pdata) {
  851. master->num_chipselect = pdata->cs_num;
  852. master->bus_num = pdata->bus_num;
  853. dspi->devtype_data = &coldfire_data;
  854. } else {
  855. ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num);
  856. if (ret < 0) {
  857. dev_err(&pdev->dev, "can't get spi-num-chipselects\n");
  858. goto out_master_put;
  859. }
  860. master->num_chipselect = cs_num;
  861. ret = of_property_read_u32(np, "bus-num", &bus_num);
  862. if (ret < 0) {
  863. dev_err(&pdev->dev, "can't get bus-num\n");
  864. goto out_master_put;
  865. }
  866. master->bus_num = bus_num;
  867. dspi->devtype_data = of_device_get_match_data(&pdev->dev);
  868. if (!dspi->devtype_data) {
  869. dev_err(&pdev->dev, "can't get devtype_data\n");
  870. ret = -EFAULT;
  871. goto out_master_put;
  872. }
  873. }
  874. if (dspi->devtype_data->xspi_mode)
  875. master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32);
  876. else
  877. master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16);
  878. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  879. base = devm_ioremap_resource(&pdev->dev, res);
  880. if (IS_ERR(base)) {
  881. ret = PTR_ERR(base);
  882. goto out_master_put;
  883. }
  884. if (dspi->devtype_data->xspi_mode)
  885. regmap_config = &dspi_xspi_regmap_config[0];
  886. else
  887. regmap_config = &dspi_regmap_config;
  888. dspi->regmap = devm_regmap_init_mmio(&pdev->dev, base, regmap_config);
  889. if (IS_ERR(dspi->regmap)) {
  890. dev_err(&pdev->dev, "failed to init regmap: %ld\n",
  891. PTR_ERR(dspi->regmap));
  892. ret = PTR_ERR(dspi->regmap);
  893. goto out_master_put;
  894. }
  895. if (dspi->devtype_data->xspi_mode) {
  896. dspi->regmap_pushr = devm_regmap_init_mmio(
  897. &pdev->dev, base + SPI_PUSHR,
  898. &dspi_xspi_regmap_config[1]);
  899. if (IS_ERR(dspi->regmap_pushr)) {
  900. dev_err(&pdev->dev,
  901. "failed to init pushr regmap: %ld\n",
  902. PTR_ERR(dspi->regmap_pushr));
  903. ret = PTR_ERR(dspi->regmap_pushr);
  904. goto out_master_put;
  905. }
  906. }
  907. dspi->clk = devm_clk_get(&pdev->dev, "dspi");
  908. if (IS_ERR(dspi->clk)) {
  909. ret = PTR_ERR(dspi->clk);
  910. dev_err(&pdev->dev, "unable to get clock\n");
  911. goto out_master_put;
  912. }
  913. ret = clk_prepare_enable(dspi->clk);
  914. if (ret)
  915. goto out_master_put;
  916. dspi_init(dspi);
  917. dspi->irq = platform_get_irq(pdev, 0);
  918. if (dspi->irq < 0) {
  919. dev_err(&pdev->dev, "can't get platform irq\n");
  920. ret = dspi->irq;
  921. goto out_clk_put;
  922. }
  923. ret = devm_request_irq(&pdev->dev, dspi->irq, dspi_interrupt, 0,
  924. pdev->name, dspi);
  925. if (ret < 0) {
  926. dev_err(&pdev->dev, "Unable to attach DSPI interrupt\n");
  927. goto out_clk_put;
  928. }
  929. if (dspi->devtype_data->trans_mode == DSPI_DMA_MODE) {
  930. ret = dspi_request_dma(dspi, res->start);
  931. if (ret < 0) {
  932. dev_err(&pdev->dev, "can't get dma channels\n");
  933. goto out_clk_put;
  934. }
  935. }
  936. master->max_speed_hz =
  937. clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor;
  938. init_waitqueue_head(&dspi->waitq);
  939. platform_set_drvdata(pdev, master);
  940. ret = spi_register_master(master);
  941. if (ret != 0) {
  942. dev_err(&pdev->dev, "Problem registering DSPI master\n");
  943. goto out_clk_put;
  944. }
  945. return ret;
  946. out_clk_put:
  947. clk_disable_unprepare(dspi->clk);
  948. out_master_put:
  949. spi_master_put(master);
  950. return ret;
  951. }
  952. static int dspi_remove(struct platform_device *pdev)
  953. {
  954. struct spi_master *master = platform_get_drvdata(pdev);
  955. struct fsl_dspi *dspi = spi_master_get_devdata(master);
  956. /* Disconnect from the SPI framework */
  957. dspi_release_dma(dspi);
  958. clk_disable_unprepare(dspi->clk);
  959. spi_unregister_master(dspi->master);
  960. return 0;
  961. }
  962. static struct platform_driver fsl_dspi_driver = {
  963. .driver.name = DRIVER_NAME,
  964. .driver.of_match_table = fsl_dspi_dt_ids,
  965. .driver.owner = THIS_MODULE,
  966. .driver.pm = &dspi_pm,
  967. .probe = dspi_probe,
  968. .remove = dspi_remove,
  969. };
  970. module_platform_driver(fsl_dspi_driver);
  971. MODULE_DESCRIPTION("Freescale DSPI Controller Driver");
  972. MODULE_LICENSE("GPL");
  973. MODULE_ALIAS("platform:" DRIVER_NAME);