spi-sun6i.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /*
  2. * Copyright (C) 2012 - 2014 Allwinner Tech
  3. * Pan Nan <pannan@allwinnertech.com>
  4. *
  5. * Copyright (C) 2014 Maxime Ripard
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. */
  13. #include <linux/clk.h>
  14. #include <linux/delay.h>
  15. #include <linux/device.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/io.h>
  18. #include <linux/module.h>
  19. #include <linux/of_device.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/pm_runtime.h>
  22. #include <linux/reset.h>
  23. #include <linux/spi/spi.h>
  24. #define SUN6I_FIFO_DEPTH 128
  25. #define SUN8I_FIFO_DEPTH 64
  26. #define SUN6I_GBL_CTL_REG 0x04
  27. #define SUN6I_GBL_CTL_BUS_ENABLE BIT(0)
  28. #define SUN6I_GBL_CTL_MASTER BIT(1)
  29. #define SUN6I_GBL_CTL_TP BIT(7)
  30. #define SUN6I_GBL_CTL_RST BIT(31)
  31. #define SUN6I_TFR_CTL_REG 0x08
  32. #define SUN6I_TFR_CTL_CPHA BIT(0)
  33. #define SUN6I_TFR_CTL_CPOL BIT(1)
  34. #define SUN6I_TFR_CTL_SPOL BIT(2)
  35. #define SUN6I_TFR_CTL_CS_MASK 0x30
  36. #define SUN6I_TFR_CTL_CS(cs) (((cs) << 4) & SUN6I_TFR_CTL_CS_MASK)
  37. #define SUN6I_TFR_CTL_CS_MANUAL BIT(6)
  38. #define SUN6I_TFR_CTL_CS_LEVEL BIT(7)
  39. #define SUN6I_TFR_CTL_DHB BIT(8)
  40. #define SUN6I_TFR_CTL_FBS BIT(12)
  41. #define SUN6I_TFR_CTL_XCH BIT(31)
  42. #define SUN6I_INT_CTL_REG 0x10
  43. #define SUN6I_INT_CTL_RF_RDY BIT(0)
  44. #define SUN6I_INT_CTL_TF_ERQ BIT(4)
  45. #define SUN6I_INT_CTL_RF_OVF BIT(8)
  46. #define SUN6I_INT_CTL_TC BIT(12)
  47. #define SUN6I_INT_STA_REG 0x14
  48. #define SUN6I_FIFO_CTL_REG 0x18
  49. #define SUN6I_FIFO_CTL_RF_RDY_TRIG_LEVEL_MASK 0xff
  50. #define SUN6I_FIFO_CTL_RF_RDY_TRIG_LEVEL_BITS 0
  51. #define SUN6I_FIFO_CTL_RF_RST BIT(15)
  52. #define SUN6I_FIFO_CTL_TF_ERQ_TRIG_LEVEL_MASK 0xff
  53. #define SUN6I_FIFO_CTL_TF_ERQ_TRIG_LEVEL_BITS 16
  54. #define SUN6I_FIFO_CTL_TF_RST BIT(31)
  55. #define SUN6I_FIFO_STA_REG 0x1c
  56. #define SUN6I_FIFO_STA_RF_CNT_MASK 0x7f
  57. #define SUN6I_FIFO_STA_RF_CNT_BITS 0
  58. #define SUN6I_FIFO_STA_TF_CNT_MASK 0x7f
  59. #define SUN6I_FIFO_STA_TF_CNT_BITS 16
  60. #define SUN6I_CLK_CTL_REG 0x24
  61. #define SUN6I_CLK_CTL_CDR2_MASK 0xff
  62. #define SUN6I_CLK_CTL_CDR2(div) (((div) & SUN6I_CLK_CTL_CDR2_MASK) << 0)
  63. #define SUN6I_CLK_CTL_CDR1_MASK 0xf
  64. #define SUN6I_CLK_CTL_CDR1(div) (((div) & SUN6I_CLK_CTL_CDR1_MASK) << 8)
  65. #define SUN6I_CLK_CTL_DRS BIT(12)
  66. #define SUN6I_MAX_XFER_SIZE 0xffffff
  67. #define SUN6I_BURST_CNT_REG 0x30
  68. #define SUN6I_BURST_CNT(cnt) ((cnt) & SUN6I_MAX_XFER_SIZE)
  69. #define SUN6I_XMIT_CNT_REG 0x34
  70. #define SUN6I_XMIT_CNT(cnt) ((cnt) & SUN6I_MAX_XFER_SIZE)
  71. #define SUN6I_BURST_CTL_CNT_REG 0x38
  72. #define SUN6I_BURST_CTL_CNT_STC(cnt) ((cnt) & SUN6I_MAX_XFER_SIZE)
  73. #define SUN6I_TXDATA_REG 0x200
  74. #define SUN6I_RXDATA_REG 0x300
  75. struct sun6i_spi {
  76. struct spi_master *master;
  77. void __iomem *base_addr;
  78. struct clk *hclk;
  79. struct clk *mclk;
  80. struct reset_control *rstc;
  81. struct completion done;
  82. const u8 *tx_buf;
  83. u8 *rx_buf;
  84. int len;
  85. unsigned long fifo_depth;
  86. };
  87. static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg)
  88. {
  89. return readl(sspi->base_addr + reg);
  90. }
  91. static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value)
  92. {
  93. writel(value, sspi->base_addr + reg);
  94. }
  95. static inline u32 sun6i_spi_get_tx_fifo_count(struct sun6i_spi *sspi)
  96. {
  97. u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
  98. reg >>= SUN6I_FIFO_STA_TF_CNT_BITS;
  99. return reg & SUN6I_FIFO_STA_TF_CNT_MASK;
  100. }
  101. static inline void sun6i_spi_enable_interrupt(struct sun6i_spi *sspi, u32 mask)
  102. {
  103. u32 reg = sun6i_spi_read(sspi, SUN6I_INT_CTL_REG);
  104. reg |= mask;
  105. sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg);
  106. }
  107. static inline void sun6i_spi_disable_interrupt(struct sun6i_spi *sspi, u32 mask)
  108. {
  109. u32 reg = sun6i_spi_read(sspi, SUN6I_INT_CTL_REG);
  110. reg &= ~mask;
  111. sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg);
  112. }
  113. static inline void sun6i_spi_drain_fifo(struct sun6i_spi *sspi, int len)
  114. {
  115. u32 reg, cnt;
  116. u8 byte;
  117. /* See how much data is available */
  118. reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG);
  119. reg &= SUN6I_FIFO_STA_RF_CNT_MASK;
  120. cnt = reg >> SUN6I_FIFO_STA_RF_CNT_BITS;
  121. if (len > cnt)
  122. len = cnt;
  123. while (len--) {
  124. byte = readb(sspi->base_addr + SUN6I_RXDATA_REG);
  125. if (sspi->rx_buf)
  126. *sspi->rx_buf++ = byte;
  127. }
  128. }
  129. static inline void sun6i_spi_fill_fifo(struct sun6i_spi *sspi, int len)
  130. {
  131. u32 cnt;
  132. u8 byte;
  133. /* See how much data we can fit */
  134. cnt = sspi->fifo_depth - sun6i_spi_get_tx_fifo_count(sspi);
  135. len = min3(len, (int)cnt, sspi->len);
  136. while (len--) {
  137. byte = sspi->tx_buf ? *sspi->tx_buf++ : 0;
  138. writeb(byte, sspi->base_addr + SUN6I_TXDATA_REG);
  139. sspi->len--;
  140. }
  141. }
  142. static void sun6i_spi_set_cs(struct spi_device *spi, bool enable)
  143. {
  144. struct sun6i_spi *sspi = spi_master_get_devdata(spi->master);
  145. u32 reg;
  146. reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
  147. reg &= ~SUN6I_TFR_CTL_CS_MASK;
  148. reg |= SUN6I_TFR_CTL_CS(spi->chip_select);
  149. if (enable)
  150. reg |= SUN6I_TFR_CTL_CS_LEVEL;
  151. else
  152. reg &= ~SUN6I_TFR_CTL_CS_LEVEL;
  153. sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg);
  154. }
  155. static size_t sun6i_spi_max_transfer_size(struct spi_device *spi)
  156. {
  157. return SUN6I_MAX_XFER_SIZE - 1;
  158. }
  159. static int sun6i_spi_transfer_one(struct spi_master *master,
  160. struct spi_device *spi,
  161. struct spi_transfer *tfr)
  162. {
  163. struct sun6i_spi *sspi = spi_master_get_devdata(master);
  164. unsigned int mclk_rate, div, div_cdr1, div_cdr2, timeout;
  165. unsigned int start, end, tx_time;
  166. unsigned int trig_level;
  167. unsigned int tx_len = 0;
  168. int ret = 0;
  169. u32 reg;
  170. if (tfr->len > SUN6I_MAX_XFER_SIZE)
  171. return -EINVAL;
  172. reinit_completion(&sspi->done);
  173. sspi->tx_buf = tfr->tx_buf;
  174. sspi->rx_buf = tfr->rx_buf;
  175. sspi->len = tfr->len;
  176. /* Clear pending interrupts */
  177. sun6i_spi_write(sspi, SUN6I_INT_STA_REG, ~0);
  178. /* Reset FIFO */
  179. sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG,
  180. SUN6I_FIFO_CTL_RF_RST | SUN6I_FIFO_CTL_TF_RST);
  181. /*
  182. * Setup FIFO interrupt trigger level
  183. * Here we choose 3/4 of the full fifo depth, as it's the hardcoded
  184. * value used in old generation of Allwinner SPI controller.
  185. * (See spi-sun4i.c)
  186. */
  187. trig_level = sspi->fifo_depth / 4 * 3;
  188. sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG,
  189. (trig_level << SUN6I_FIFO_CTL_RF_RDY_TRIG_LEVEL_BITS) |
  190. (trig_level << SUN6I_FIFO_CTL_TF_ERQ_TRIG_LEVEL_BITS));
  191. /*
  192. * Setup the transfer control register: Chip Select,
  193. * polarities, etc.
  194. */
  195. reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
  196. if (spi->mode & SPI_CPOL)
  197. reg |= SUN6I_TFR_CTL_CPOL;
  198. else
  199. reg &= ~SUN6I_TFR_CTL_CPOL;
  200. if (spi->mode & SPI_CPHA)
  201. reg |= SUN6I_TFR_CTL_CPHA;
  202. else
  203. reg &= ~SUN6I_TFR_CTL_CPHA;
  204. if (spi->mode & SPI_LSB_FIRST)
  205. reg |= SUN6I_TFR_CTL_FBS;
  206. else
  207. reg &= ~SUN6I_TFR_CTL_FBS;
  208. /*
  209. * If it's a TX only transfer, we don't want to fill the RX
  210. * FIFO with bogus data
  211. */
  212. if (sspi->rx_buf)
  213. reg &= ~SUN6I_TFR_CTL_DHB;
  214. else
  215. reg |= SUN6I_TFR_CTL_DHB;
  216. /* We want to control the chip select manually */
  217. reg |= SUN6I_TFR_CTL_CS_MANUAL;
  218. sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg);
  219. /* Ensure that we have a parent clock fast enough */
  220. mclk_rate = clk_get_rate(sspi->mclk);
  221. if (mclk_rate < (2 * tfr->speed_hz)) {
  222. clk_set_rate(sspi->mclk, 2 * tfr->speed_hz);
  223. mclk_rate = clk_get_rate(sspi->mclk);
  224. }
  225. /*
  226. * Setup clock divider.
  227. *
  228. * We have two choices there. Either we can use the clock
  229. * divide rate 1, which is calculated thanks to this formula:
  230. * SPI_CLK = MOD_CLK / (2 ^ cdr)
  231. * Or we can use CDR2, which is calculated with the formula:
  232. * SPI_CLK = MOD_CLK / (2 * (cdr + 1))
  233. * Wether we use the former or the latter is set through the
  234. * DRS bit.
  235. *
  236. * First try CDR2, and if we can't reach the expected
  237. * frequency, fall back to CDR1.
  238. */
  239. div_cdr1 = DIV_ROUND_UP(mclk_rate, tfr->speed_hz);
  240. div_cdr2 = DIV_ROUND_UP(div_cdr1, 2);
  241. if (div_cdr2 <= (SUN6I_CLK_CTL_CDR2_MASK + 1)) {
  242. reg = SUN6I_CLK_CTL_CDR2(div_cdr2 - 1) | SUN6I_CLK_CTL_DRS;
  243. } else {
  244. div = min(SUN6I_CLK_CTL_CDR1_MASK, order_base_2(div_cdr1));
  245. reg = SUN6I_CLK_CTL_CDR1(div);
  246. }
  247. sun6i_spi_write(sspi, SUN6I_CLK_CTL_REG, reg);
  248. /* Setup the transfer now... */
  249. if (sspi->tx_buf)
  250. tx_len = tfr->len;
  251. /* Setup the counters */
  252. sun6i_spi_write(sspi, SUN6I_BURST_CNT_REG, SUN6I_BURST_CNT(tfr->len));
  253. sun6i_spi_write(sspi, SUN6I_XMIT_CNT_REG, SUN6I_XMIT_CNT(tx_len));
  254. sun6i_spi_write(sspi, SUN6I_BURST_CTL_CNT_REG,
  255. SUN6I_BURST_CTL_CNT_STC(tx_len));
  256. /* Fill the TX FIFO */
  257. sun6i_spi_fill_fifo(sspi, sspi->fifo_depth);
  258. /* Enable the interrupts */
  259. sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, SUN6I_INT_CTL_TC);
  260. sun6i_spi_enable_interrupt(sspi, SUN6I_INT_CTL_TC |
  261. SUN6I_INT_CTL_RF_RDY);
  262. if (tx_len > sspi->fifo_depth)
  263. sun6i_spi_enable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ);
  264. /* Start the transfer */
  265. reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
  266. sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH);
  267. tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
  268. start = jiffies;
  269. timeout = wait_for_completion_timeout(&sspi->done,
  270. msecs_to_jiffies(tx_time));
  271. end = jiffies;
  272. if (!timeout) {
  273. dev_warn(&master->dev,
  274. "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
  275. dev_name(&spi->dev), tfr->len, tfr->speed_hz,
  276. jiffies_to_msecs(end - start), tx_time);
  277. ret = -ETIMEDOUT;
  278. goto out;
  279. }
  280. out:
  281. sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0);
  282. return ret;
  283. }
  284. static irqreturn_t sun6i_spi_handler(int irq, void *dev_id)
  285. {
  286. struct sun6i_spi *sspi = dev_id;
  287. u32 status = sun6i_spi_read(sspi, SUN6I_INT_STA_REG);
  288. /* Transfer complete */
  289. if (status & SUN6I_INT_CTL_TC) {
  290. sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TC);
  291. sun6i_spi_drain_fifo(sspi, sspi->fifo_depth);
  292. complete(&sspi->done);
  293. return IRQ_HANDLED;
  294. }
  295. /* Receive FIFO 3/4 full */
  296. if (status & SUN6I_INT_CTL_RF_RDY) {
  297. sun6i_spi_drain_fifo(sspi, SUN6I_FIFO_DEPTH);
  298. /* Only clear the interrupt _after_ draining the FIFO */
  299. sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_RF_RDY);
  300. return IRQ_HANDLED;
  301. }
  302. /* Transmit FIFO 3/4 empty */
  303. if (status & SUN6I_INT_CTL_TF_ERQ) {
  304. sun6i_spi_fill_fifo(sspi, SUN6I_FIFO_DEPTH);
  305. if (!sspi->len)
  306. /* nothing left to transmit */
  307. sun6i_spi_disable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ);
  308. /* Only clear the interrupt _after_ re-seeding the FIFO */
  309. sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TF_ERQ);
  310. return IRQ_HANDLED;
  311. }
  312. return IRQ_NONE;
  313. }
  314. static int sun6i_spi_runtime_resume(struct device *dev)
  315. {
  316. struct spi_master *master = dev_get_drvdata(dev);
  317. struct sun6i_spi *sspi = spi_master_get_devdata(master);
  318. int ret;
  319. ret = clk_prepare_enable(sspi->hclk);
  320. if (ret) {
  321. dev_err(dev, "Couldn't enable AHB clock\n");
  322. goto out;
  323. }
  324. ret = clk_prepare_enable(sspi->mclk);
  325. if (ret) {
  326. dev_err(dev, "Couldn't enable module clock\n");
  327. goto err;
  328. }
  329. ret = reset_control_deassert(sspi->rstc);
  330. if (ret) {
  331. dev_err(dev, "Couldn't deassert the device from reset\n");
  332. goto err2;
  333. }
  334. sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG,
  335. SUN6I_GBL_CTL_BUS_ENABLE | SUN6I_GBL_CTL_MASTER | SUN6I_GBL_CTL_TP);
  336. return 0;
  337. err2:
  338. clk_disable_unprepare(sspi->mclk);
  339. err:
  340. clk_disable_unprepare(sspi->hclk);
  341. out:
  342. return ret;
  343. }
  344. static int sun6i_spi_runtime_suspend(struct device *dev)
  345. {
  346. struct spi_master *master = dev_get_drvdata(dev);
  347. struct sun6i_spi *sspi = spi_master_get_devdata(master);
  348. reset_control_assert(sspi->rstc);
  349. clk_disable_unprepare(sspi->mclk);
  350. clk_disable_unprepare(sspi->hclk);
  351. return 0;
  352. }
  353. static int sun6i_spi_probe(struct platform_device *pdev)
  354. {
  355. struct spi_master *master;
  356. struct sun6i_spi *sspi;
  357. struct resource *res;
  358. int ret = 0, irq;
  359. master = spi_alloc_master(&pdev->dev, sizeof(struct sun6i_spi));
  360. if (!master) {
  361. dev_err(&pdev->dev, "Unable to allocate SPI Master\n");
  362. return -ENOMEM;
  363. }
  364. platform_set_drvdata(pdev, master);
  365. sspi = spi_master_get_devdata(master);
  366. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  367. sspi->base_addr = devm_ioremap_resource(&pdev->dev, res);
  368. if (IS_ERR(sspi->base_addr)) {
  369. ret = PTR_ERR(sspi->base_addr);
  370. goto err_free_master;
  371. }
  372. irq = platform_get_irq(pdev, 0);
  373. if (irq < 0) {
  374. dev_err(&pdev->dev, "No spi IRQ specified\n");
  375. ret = -ENXIO;
  376. goto err_free_master;
  377. }
  378. ret = devm_request_irq(&pdev->dev, irq, sun6i_spi_handler,
  379. 0, "sun6i-spi", sspi);
  380. if (ret) {
  381. dev_err(&pdev->dev, "Cannot request IRQ\n");
  382. goto err_free_master;
  383. }
  384. sspi->master = master;
  385. sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev);
  386. master->max_speed_hz = 100 * 1000 * 1000;
  387. master->min_speed_hz = 3 * 1000;
  388. master->set_cs = sun6i_spi_set_cs;
  389. master->transfer_one = sun6i_spi_transfer_one;
  390. master->num_chipselect = 4;
  391. master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST;
  392. master->bits_per_word_mask = SPI_BPW_MASK(8);
  393. master->dev.of_node = pdev->dev.of_node;
  394. master->auto_runtime_pm = true;
  395. master->max_transfer_size = sun6i_spi_max_transfer_size;
  396. sspi->hclk = devm_clk_get(&pdev->dev, "ahb");
  397. if (IS_ERR(sspi->hclk)) {
  398. dev_err(&pdev->dev, "Unable to acquire AHB clock\n");
  399. ret = PTR_ERR(sspi->hclk);
  400. goto err_free_master;
  401. }
  402. sspi->mclk = devm_clk_get(&pdev->dev, "mod");
  403. if (IS_ERR(sspi->mclk)) {
  404. dev_err(&pdev->dev, "Unable to acquire module clock\n");
  405. ret = PTR_ERR(sspi->mclk);
  406. goto err_free_master;
  407. }
  408. init_completion(&sspi->done);
  409. sspi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
  410. if (IS_ERR(sspi->rstc)) {
  411. dev_err(&pdev->dev, "Couldn't get reset controller\n");
  412. ret = PTR_ERR(sspi->rstc);
  413. goto err_free_master;
  414. }
  415. /*
  416. * This wake-up/shutdown pattern is to be able to have the
  417. * device woken up, even if runtime_pm is disabled
  418. */
  419. ret = sun6i_spi_runtime_resume(&pdev->dev);
  420. if (ret) {
  421. dev_err(&pdev->dev, "Couldn't resume the device\n");
  422. goto err_free_master;
  423. }
  424. pm_runtime_set_active(&pdev->dev);
  425. pm_runtime_enable(&pdev->dev);
  426. pm_runtime_idle(&pdev->dev);
  427. ret = devm_spi_register_master(&pdev->dev, master);
  428. if (ret) {
  429. dev_err(&pdev->dev, "cannot register SPI master\n");
  430. goto err_pm_disable;
  431. }
  432. return 0;
  433. err_pm_disable:
  434. pm_runtime_disable(&pdev->dev);
  435. sun6i_spi_runtime_suspend(&pdev->dev);
  436. err_free_master:
  437. spi_master_put(master);
  438. return ret;
  439. }
  440. static int sun6i_spi_remove(struct platform_device *pdev)
  441. {
  442. pm_runtime_force_suspend(&pdev->dev);
  443. return 0;
  444. }
  445. static const struct of_device_id sun6i_spi_match[] = {
  446. { .compatible = "allwinner,sun6i-a31-spi", .data = (void *)SUN6I_FIFO_DEPTH },
  447. { .compatible = "allwinner,sun8i-h3-spi", .data = (void *)SUN8I_FIFO_DEPTH },
  448. {}
  449. };
  450. MODULE_DEVICE_TABLE(of, sun6i_spi_match);
  451. static const struct dev_pm_ops sun6i_spi_pm_ops = {
  452. .runtime_resume = sun6i_spi_runtime_resume,
  453. .runtime_suspend = sun6i_spi_runtime_suspend,
  454. };
  455. static struct platform_driver sun6i_spi_driver = {
  456. .probe = sun6i_spi_probe,
  457. .remove = sun6i_spi_remove,
  458. .driver = {
  459. .name = "sun6i-spi",
  460. .of_match_table = sun6i_spi_match,
  461. .pm = &sun6i_spi_pm_ops,
  462. },
  463. };
  464. module_platform_driver(sun6i_spi_driver);
  465. MODULE_AUTHOR("Pan Nan <pannan@allwinnertech.com>");
  466. MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
  467. MODULE_DESCRIPTION("Allwinner A31 SPI controller driver");
  468. MODULE_LICENSE("GPL");