spi-meson-spicc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Driver for Amlogic Meson SPI communication controller (SPICC)
  3. *
  4. * Copyright (C) BayLibre, SAS
  5. * Author: Neil Armstrong <narmstrong@baylibre.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <linux/bitfield.h>
  10. #include <linux/clk.h>
  11. #include <linux/device.h>
  12. #include <linux/io.h>
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/of.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/spi/spi.h>
  18. #include <linux/types.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/reset.h>
  21. #include <linux/gpio.h>
  22. /*
  23. * The Meson SPICC controller could support DMA based transfers, but is not
  24. * implemented by the vendor code, and while having the registers documentation
  25. * it has never worked on the GXL Hardware.
  26. * The PIO mode is the only mode implemented, and due to badly designed HW :
  27. * - all transfers are cutted in 16 words burst because the FIFO hangs on
  28. * TX underflow, and there is no TX "Half-Empty" interrupt, so we go by
  29. * FIFO max size chunk only
  30. * - CS management is dumb, and goes UP between every burst, so is really a
  31. * "Data Valid" signal than a Chip Select, GPIO link should be used instead
  32. * to have a CS go down over the full transfer
  33. */
  34. #define SPICC_MAX_FREQ 30000000
  35. #define SPICC_MAX_BURST 128
  36. /* Register Map */
  37. #define SPICC_RXDATA 0x00
  38. #define SPICC_TXDATA 0x04
  39. #define SPICC_CONREG 0x08
  40. #define SPICC_ENABLE BIT(0)
  41. #define SPICC_MODE_MASTER BIT(1)
  42. #define SPICC_XCH BIT(2)
  43. #define SPICC_SMC BIT(3)
  44. #define SPICC_POL BIT(4)
  45. #define SPICC_PHA BIT(5)
  46. #define SPICC_SSCTL BIT(6)
  47. #define SPICC_SSPOL BIT(7)
  48. #define SPICC_DRCTL_MASK GENMASK(9, 8)
  49. #define SPICC_DRCTL_IGNORE 0
  50. #define SPICC_DRCTL_FALLING 1
  51. #define SPICC_DRCTL_LOWLEVEL 2
  52. #define SPICC_CS_MASK GENMASK(13, 12)
  53. #define SPICC_DATARATE_MASK GENMASK(18, 16)
  54. #define SPICC_DATARATE_DIV4 0
  55. #define SPICC_DATARATE_DIV8 1
  56. #define SPICC_DATARATE_DIV16 2
  57. #define SPICC_DATARATE_DIV32 3
  58. #define SPICC_BITLENGTH_MASK GENMASK(24, 19)
  59. #define SPICC_BURSTLENGTH_MASK GENMASK(31, 25)
  60. #define SPICC_INTREG 0x0c
  61. #define SPICC_TE_EN BIT(0) /* TX FIFO Empty Interrupt */
  62. #define SPICC_TH_EN BIT(1) /* TX FIFO Half-Full Interrupt */
  63. #define SPICC_TF_EN BIT(2) /* TX FIFO Full Interrupt */
  64. #define SPICC_RR_EN BIT(3) /* RX FIFO Ready Interrupt */
  65. #define SPICC_RH_EN BIT(4) /* RX FIFO Half-Full Interrupt */
  66. #define SPICC_RF_EN BIT(5) /* RX FIFO Full Interrupt */
  67. #define SPICC_RO_EN BIT(6) /* RX FIFO Overflow Interrupt */
  68. #define SPICC_TC_EN BIT(7) /* Transfert Complete Interrupt */
  69. #define SPICC_DMAREG 0x10
  70. #define SPICC_DMA_ENABLE BIT(0)
  71. #define SPICC_TXFIFO_THRESHOLD_MASK GENMASK(5, 1)
  72. #define SPICC_RXFIFO_THRESHOLD_MASK GENMASK(10, 6)
  73. #define SPICC_READ_BURST_MASK GENMASK(14, 11)
  74. #define SPICC_WRITE_BURST_MASK GENMASK(18, 15)
  75. #define SPICC_DMA_URGENT BIT(19)
  76. #define SPICC_DMA_THREADID_MASK GENMASK(25, 20)
  77. #define SPICC_DMA_BURSTNUM_MASK GENMASK(31, 26)
  78. #define SPICC_STATREG 0x14
  79. #define SPICC_TE BIT(0) /* TX FIFO Empty Interrupt */
  80. #define SPICC_TH BIT(1) /* TX FIFO Half-Full Interrupt */
  81. #define SPICC_TF BIT(2) /* TX FIFO Full Interrupt */
  82. #define SPICC_RR BIT(3) /* RX FIFO Ready Interrupt */
  83. #define SPICC_RH BIT(4) /* RX FIFO Half-Full Interrupt */
  84. #define SPICC_RF BIT(5) /* RX FIFO Full Interrupt */
  85. #define SPICC_RO BIT(6) /* RX FIFO Overflow Interrupt */
  86. #define SPICC_TC BIT(7) /* Transfert Complete Interrupt */
  87. #define SPICC_PERIODREG 0x18
  88. #define SPICC_PERIOD GENMASK(14, 0) /* Wait cycles */
  89. #define SPICC_TESTREG 0x1c
  90. #define SPICC_TXCNT_MASK GENMASK(4, 0) /* TX FIFO Counter */
  91. #define SPICC_RXCNT_MASK GENMASK(9, 5) /* RX FIFO Counter */
  92. #define SPICC_SMSTATUS_MASK GENMASK(12, 10) /* State Machine Status */
  93. #define SPICC_LBC_RO BIT(13) /* Loop Back Control Read-Only */
  94. #define SPICC_LBC_W1 BIT(14) /* Loop Back Control Write-Only */
  95. #define SPICC_SWAP_RO BIT(14) /* RX FIFO Data Swap Read-Only */
  96. #define SPICC_SWAP_W1 BIT(15) /* RX FIFO Data Swap Write-Only */
  97. #define SPICC_DLYCTL_RO_MASK GENMASK(20, 15) /* Delay Control Read-Only */
  98. #define SPICC_DLYCTL_W1_MASK GENMASK(21, 16) /* Delay Control Write-Only */
  99. #define SPICC_FIFORST_RO_MASK GENMASK(22, 21) /* FIFO Softreset Read-Only */
  100. #define SPICC_FIFORST_W1_MASK GENMASK(23, 22) /* FIFO Softreset Write-Only */
  101. #define SPICC_DRADDR 0x20 /* Read Address of DMA */
  102. #define SPICC_DWADDR 0x24 /* Write Address of DMA */
  103. #define writel_bits_relaxed(mask, val, addr) \
  104. writel_relaxed((readl_relaxed(addr) & ~(mask)) | (val), addr)
  105. #define SPICC_BURST_MAX 16
  106. #define SPICC_FIFO_HALF 10
  107. struct meson_spicc_device {
  108. struct spi_master *master;
  109. struct platform_device *pdev;
  110. void __iomem *base;
  111. struct clk *core;
  112. struct spi_message *message;
  113. struct spi_transfer *xfer;
  114. u8 *tx_buf;
  115. u8 *rx_buf;
  116. unsigned int bytes_per_word;
  117. unsigned long tx_remain;
  118. unsigned long txb_remain;
  119. unsigned long rx_remain;
  120. unsigned long rxb_remain;
  121. unsigned long xfer_remain;
  122. bool is_burst_end;
  123. bool is_last_burst;
  124. };
  125. static inline bool meson_spicc_txfull(struct meson_spicc_device *spicc)
  126. {
  127. return !!FIELD_GET(SPICC_TF,
  128. readl_relaxed(spicc->base + SPICC_STATREG));
  129. }
  130. static inline bool meson_spicc_rxready(struct meson_spicc_device *spicc)
  131. {
  132. return FIELD_GET(SPICC_RH | SPICC_RR | SPICC_RF_EN,
  133. readl_relaxed(spicc->base + SPICC_STATREG));
  134. }
  135. static inline u32 meson_spicc_pull_data(struct meson_spicc_device *spicc)
  136. {
  137. unsigned int bytes = spicc->bytes_per_word;
  138. unsigned int byte_shift = 0;
  139. u32 data = 0;
  140. u8 byte;
  141. while (bytes--) {
  142. byte = *spicc->tx_buf++;
  143. data |= (byte & 0xff) << byte_shift;
  144. byte_shift += 8;
  145. }
  146. spicc->tx_remain--;
  147. return data;
  148. }
  149. static inline void meson_spicc_push_data(struct meson_spicc_device *spicc,
  150. u32 data)
  151. {
  152. unsigned int bytes = spicc->bytes_per_word;
  153. unsigned int byte_shift = 0;
  154. u8 byte;
  155. while (bytes--) {
  156. byte = (data >> byte_shift) & 0xff;
  157. *spicc->rx_buf++ = byte;
  158. byte_shift += 8;
  159. }
  160. spicc->rx_remain--;
  161. }
  162. static inline void meson_spicc_rx(struct meson_spicc_device *spicc)
  163. {
  164. /* Empty RX FIFO */
  165. while (spicc->rx_remain &&
  166. meson_spicc_rxready(spicc))
  167. meson_spicc_push_data(spicc,
  168. readl_relaxed(spicc->base + SPICC_RXDATA));
  169. }
  170. static inline void meson_spicc_tx(struct meson_spicc_device *spicc)
  171. {
  172. /* Fill Up TX FIFO */
  173. while (spicc->tx_remain &&
  174. !meson_spicc_txfull(spicc))
  175. writel_relaxed(meson_spicc_pull_data(spicc),
  176. spicc->base + SPICC_TXDATA);
  177. }
  178. static inline u32 meson_spicc_setup_rx_irq(struct meson_spicc_device *spicc,
  179. u32 irq_ctrl)
  180. {
  181. if (spicc->rx_remain > SPICC_FIFO_HALF)
  182. irq_ctrl |= SPICC_RH_EN;
  183. else
  184. irq_ctrl |= SPICC_RR_EN;
  185. return irq_ctrl;
  186. }
  187. static inline void meson_spicc_setup_burst(struct meson_spicc_device *spicc,
  188. unsigned int burst_len)
  189. {
  190. /* Setup Xfer variables */
  191. spicc->tx_remain = burst_len;
  192. spicc->rx_remain = burst_len;
  193. spicc->xfer_remain -= burst_len * spicc->bytes_per_word;
  194. spicc->is_burst_end = false;
  195. if (burst_len < SPICC_BURST_MAX || !spicc->xfer_remain)
  196. spicc->is_last_burst = true;
  197. else
  198. spicc->is_last_burst = false;
  199. /* Setup burst length */
  200. writel_bits_relaxed(SPICC_BURSTLENGTH_MASK,
  201. FIELD_PREP(SPICC_BURSTLENGTH_MASK,
  202. burst_len),
  203. spicc->base + SPICC_CONREG);
  204. /* Fill TX FIFO */
  205. meson_spicc_tx(spicc);
  206. }
  207. static irqreturn_t meson_spicc_irq(int irq, void *data)
  208. {
  209. struct meson_spicc_device *spicc = (void *) data;
  210. u32 ctrl = readl_relaxed(spicc->base + SPICC_INTREG);
  211. u32 stat = readl_relaxed(spicc->base + SPICC_STATREG) & ctrl;
  212. ctrl &= ~(SPICC_RH_EN | SPICC_RR_EN);
  213. /* Empty RX FIFO */
  214. meson_spicc_rx(spicc);
  215. /* Enable TC interrupt since we transferred everything */
  216. if (!spicc->tx_remain && !spicc->rx_remain) {
  217. spicc->is_burst_end = true;
  218. /* Enable TC interrupt */
  219. ctrl |= SPICC_TC_EN;
  220. /* Reload IRQ status */
  221. stat = readl_relaxed(spicc->base + SPICC_STATREG) & ctrl;
  222. }
  223. /* Check transfer complete */
  224. if ((stat & SPICC_TC) && spicc->is_burst_end) {
  225. unsigned int burst_len;
  226. /* Clear TC bit */
  227. writel_relaxed(SPICC_TC, spicc->base + SPICC_STATREG);
  228. /* Disable TC interrupt */
  229. ctrl &= ~SPICC_TC_EN;
  230. if (spicc->is_last_burst) {
  231. /* Disable all IRQs */
  232. writel(0, spicc->base + SPICC_INTREG);
  233. spi_finalize_current_transfer(spicc->master);
  234. return IRQ_HANDLED;
  235. }
  236. burst_len = min_t(unsigned int,
  237. spicc->xfer_remain / spicc->bytes_per_word,
  238. SPICC_BURST_MAX);
  239. /* Setup burst */
  240. meson_spicc_setup_burst(spicc, burst_len);
  241. /* Restart burst */
  242. writel_bits_relaxed(SPICC_XCH, SPICC_XCH,
  243. spicc->base + SPICC_CONREG);
  244. }
  245. /* Setup RX interrupt trigger */
  246. ctrl = meson_spicc_setup_rx_irq(spicc, ctrl);
  247. /* Reconfigure interrupts */
  248. writel(ctrl, spicc->base + SPICC_INTREG);
  249. return IRQ_HANDLED;
  250. }
  251. static u32 meson_spicc_setup_speed(struct meson_spicc_device *spicc, u32 conf,
  252. u32 speed)
  253. {
  254. unsigned long parent, value;
  255. unsigned int i, div;
  256. parent = clk_get_rate(spicc->core);
  257. /* Find closest inferior/equal possible speed */
  258. for (i = 0 ; i < 7 ; ++i) {
  259. /* 2^(data_rate+2) */
  260. value = parent >> (i + 2);
  261. if (value <= speed)
  262. break;
  263. }
  264. /* If provided speed it lower than max divider, use max divider */
  265. if (i > 7) {
  266. div = 7;
  267. dev_warn_once(&spicc->pdev->dev, "unable to get close to speed %u\n",
  268. speed);
  269. } else
  270. div = i;
  271. dev_dbg(&spicc->pdev->dev, "parent %lu, speed %u -> %lu (%u)\n",
  272. parent, speed, value, div);
  273. conf &= ~SPICC_DATARATE_MASK;
  274. conf |= FIELD_PREP(SPICC_DATARATE_MASK, div);
  275. return conf;
  276. }
  277. static void meson_spicc_setup_xfer(struct meson_spicc_device *spicc,
  278. struct spi_transfer *xfer)
  279. {
  280. u32 conf, conf_orig;
  281. /* Read original configuration */
  282. conf = conf_orig = readl_relaxed(spicc->base + SPICC_CONREG);
  283. /* Select closest divider */
  284. conf = meson_spicc_setup_speed(spicc, conf, xfer->speed_hz);
  285. /* Setup word width */
  286. conf &= ~SPICC_BITLENGTH_MASK;
  287. conf |= FIELD_PREP(SPICC_BITLENGTH_MASK,
  288. (spicc->bytes_per_word << 3) - 1);
  289. /* Ignore if unchanged */
  290. if (conf != conf_orig)
  291. writel_relaxed(conf, spicc->base + SPICC_CONREG);
  292. }
  293. static int meson_spicc_transfer_one(struct spi_master *master,
  294. struct spi_device *spi,
  295. struct spi_transfer *xfer)
  296. {
  297. struct meson_spicc_device *spicc = spi_master_get_devdata(master);
  298. unsigned int burst_len;
  299. u32 irq = 0;
  300. /* Store current transfer */
  301. spicc->xfer = xfer;
  302. /* Setup transfer parameters */
  303. spicc->tx_buf = (u8 *)xfer->tx_buf;
  304. spicc->rx_buf = (u8 *)xfer->rx_buf;
  305. spicc->xfer_remain = xfer->len;
  306. /* Pre-calculate word size */
  307. spicc->bytes_per_word =
  308. DIV_ROUND_UP(spicc->xfer->bits_per_word, 8);
  309. /* Setup transfer parameters */
  310. meson_spicc_setup_xfer(spicc, xfer);
  311. burst_len = min_t(unsigned int,
  312. spicc->xfer_remain / spicc->bytes_per_word,
  313. SPICC_BURST_MAX);
  314. meson_spicc_setup_burst(spicc, burst_len);
  315. irq = meson_spicc_setup_rx_irq(spicc, irq);
  316. /* Start burst */
  317. writel_bits_relaxed(SPICC_XCH, SPICC_XCH, spicc->base + SPICC_CONREG);
  318. /* Enable interrupts */
  319. writel_relaxed(irq, spicc->base + SPICC_INTREG);
  320. return 1;
  321. }
  322. static int meson_spicc_prepare_message(struct spi_master *master,
  323. struct spi_message *message)
  324. {
  325. struct meson_spicc_device *spicc = spi_master_get_devdata(master);
  326. struct spi_device *spi = message->spi;
  327. u32 conf = 0;
  328. /* Store current message */
  329. spicc->message = message;
  330. /* Enable Master */
  331. conf |= SPICC_ENABLE;
  332. conf |= SPICC_MODE_MASTER;
  333. /* SMC = 0 */
  334. /* Setup transfer mode */
  335. if (spi->mode & SPI_CPOL)
  336. conf |= SPICC_POL;
  337. else
  338. conf &= ~SPICC_POL;
  339. if (spi->mode & SPI_CPHA)
  340. conf |= SPICC_PHA;
  341. else
  342. conf &= ~SPICC_PHA;
  343. /* SSCTL = 0 */
  344. if (spi->mode & SPI_CS_HIGH)
  345. conf |= SPICC_SSPOL;
  346. else
  347. conf &= ~SPICC_SSPOL;
  348. if (spi->mode & SPI_READY)
  349. conf |= FIELD_PREP(SPICC_DRCTL_MASK, SPICC_DRCTL_LOWLEVEL);
  350. else
  351. conf |= FIELD_PREP(SPICC_DRCTL_MASK, SPICC_DRCTL_IGNORE);
  352. /* Select CS */
  353. conf |= FIELD_PREP(SPICC_CS_MASK, spi->chip_select);
  354. /* Default Clock rate core/4 */
  355. /* Default 8bit word */
  356. conf |= FIELD_PREP(SPICC_BITLENGTH_MASK, 8 - 1);
  357. writel_relaxed(conf, spicc->base + SPICC_CONREG);
  358. /* Setup no wait cycles by default */
  359. writel_relaxed(0, spicc->base + SPICC_PERIODREG);
  360. writel_bits_relaxed(BIT(24), BIT(24), spicc->base + SPICC_TESTREG);
  361. return 0;
  362. }
  363. static int meson_spicc_unprepare_transfer(struct spi_master *master)
  364. {
  365. struct meson_spicc_device *spicc = spi_master_get_devdata(master);
  366. /* Disable all IRQs */
  367. writel(0, spicc->base + SPICC_INTREG);
  368. /* Disable controller */
  369. writel_bits_relaxed(SPICC_ENABLE, 0, spicc->base + SPICC_CONREG);
  370. device_reset_optional(&spicc->pdev->dev);
  371. return 0;
  372. }
  373. static int meson_spicc_setup(struct spi_device *spi)
  374. {
  375. int ret = 0;
  376. if (!spi->controller_state)
  377. spi->controller_state = spi_master_get_devdata(spi->master);
  378. else if (gpio_is_valid(spi->cs_gpio))
  379. goto out_gpio;
  380. else if (spi->cs_gpio == -ENOENT)
  381. return 0;
  382. if (gpio_is_valid(spi->cs_gpio)) {
  383. ret = gpio_request(spi->cs_gpio, dev_name(&spi->dev));
  384. if (ret) {
  385. dev_err(&spi->dev, "failed to request cs gpio\n");
  386. return ret;
  387. }
  388. }
  389. out_gpio:
  390. ret = gpio_direction_output(spi->cs_gpio,
  391. !(spi->mode & SPI_CS_HIGH));
  392. return ret;
  393. }
  394. static void meson_spicc_cleanup(struct spi_device *spi)
  395. {
  396. if (gpio_is_valid(spi->cs_gpio))
  397. gpio_free(spi->cs_gpio);
  398. spi->controller_state = NULL;
  399. }
  400. static int meson_spicc_probe(struct platform_device *pdev)
  401. {
  402. struct spi_master *master;
  403. struct meson_spicc_device *spicc;
  404. struct resource *res;
  405. int ret, irq, rate;
  406. master = spi_alloc_master(&pdev->dev, sizeof(*spicc));
  407. if (!master) {
  408. dev_err(&pdev->dev, "master allocation failed\n");
  409. return -ENOMEM;
  410. }
  411. spicc = spi_master_get_devdata(master);
  412. spicc->master = master;
  413. spicc->pdev = pdev;
  414. platform_set_drvdata(pdev, spicc);
  415. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  416. spicc->base = devm_ioremap_resource(&pdev->dev, res);
  417. if (IS_ERR(spicc->base)) {
  418. dev_err(&pdev->dev, "io resource mapping failed\n");
  419. ret = PTR_ERR(spicc->base);
  420. goto out_master;
  421. }
  422. /* Disable all IRQs */
  423. writel_relaxed(0, spicc->base + SPICC_INTREG);
  424. irq = platform_get_irq(pdev, 0);
  425. ret = devm_request_irq(&pdev->dev, irq, meson_spicc_irq,
  426. 0, NULL, spicc);
  427. if (ret) {
  428. dev_err(&pdev->dev, "irq request failed\n");
  429. goto out_master;
  430. }
  431. spicc->core = devm_clk_get(&pdev->dev, "core");
  432. if (IS_ERR(spicc->core)) {
  433. dev_err(&pdev->dev, "core clock request failed\n");
  434. ret = PTR_ERR(spicc->core);
  435. goto out_master;
  436. }
  437. ret = clk_prepare_enable(spicc->core);
  438. if (ret) {
  439. dev_err(&pdev->dev, "core clock enable failed\n");
  440. goto out_master;
  441. }
  442. rate = clk_get_rate(spicc->core);
  443. device_reset_optional(&pdev->dev);
  444. master->num_chipselect = 4;
  445. master->dev.of_node = pdev->dev.of_node;
  446. master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_CS_HIGH;
  447. master->bits_per_word_mask = SPI_BPW_MASK(32) |
  448. SPI_BPW_MASK(24) |
  449. SPI_BPW_MASK(16) |
  450. SPI_BPW_MASK(8);
  451. master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX);
  452. master->min_speed_hz = rate >> 9;
  453. master->setup = meson_spicc_setup;
  454. master->cleanup = meson_spicc_cleanup;
  455. master->prepare_message = meson_spicc_prepare_message;
  456. master->unprepare_transfer_hardware = meson_spicc_unprepare_transfer;
  457. master->transfer_one = meson_spicc_transfer_one;
  458. /* Setup max rate according to the Meson GX datasheet */
  459. if ((rate >> 2) > SPICC_MAX_FREQ)
  460. master->max_speed_hz = SPICC_MAX_FREQ;
  461. else
  462. master->max_speed_hz = rate >> 2;
  463. ret = devm_spi_register_master(&pdev->dev, master);
  464. if (ret) {
  465. dev_err(&pdev->dev, "spi master registration failed\n");
  466. goto out_clk;
  467. }
  468. return 0;
  469. out_clk:
  470. clk_disable_unprepare(spicc->core);
  471. out_master:
  472. spi_master_put(master);
  473. return ret;
  474. }
  475. static int meson_spicc_remove(struct platform_device *pdev)
  476. {
  477. struct meson_spicc_device *spicc = platform_get_drvdata(pdev);
  478. /* Disable SPI */
  479. writel(0, spicc->base + SPICC_CONREG);
  480. clk_disable_unprepare(spicc->core);
  481. return 0;
  482. }
  483. static const struct of_device_id meson_spicc_of_match[] = {
  484. { .compatible = "amlogic,meson-gx-spicc", },
  485. { /* sentinel */ }
  486. };
  487. MODULE_DEVICE_TABLE(of, meson_spicc_of_match);
  488. static struct platform_driver meson_spicc_driver = {
  489. .probe = meson_spicc_probe,
  490. .remove = meson_spicc_remove,
  491. .driver = {
  492. .name = "meson-spicc",
  493. .of_match_table = of_match_ptr(meson_spicc_of_match),
  494. },
  495. };
  496. module_platform_driver(meson_spicc_driver);
  497. MODULE_DESCRIPTION("Meson SPI Communication Controller driver");
  498. MODULE_AUTHOR("Neil Armstrong <narmstrong@baylibre.com>");
  499. MODULE_LICENSE("GPL");