12025cf9eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
264e36824Saddy ke /*
364e36824Saddy ke * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
45dcc44edSAddy Ke * Author: Addy Ke <addy.ke@rock-chips.com>
564e36824Saddy ke */
664e36824Saddy ke
764e36824Saddy ke #include <linux/clk.h>
864e36824Saddy ke #include <linux/dmaengine.h>
98af0c18aSSuren Baghdasaryan #include <linux/interrupt.h>
10ec5c5d8aSShawn Lin #include <linux/module.h>
11ec5c5d8aSShawn Lin #include <linux/of.h>
1223e291c2SBrian Norris #include <linux/pinctrl/consumer.h>
13ec5c5d8aSShawn Lin #include <linux/platform_device.h>
14ec5c5d8aSShawn Lin #include <linux/spi/spi.h>
15ec5c5d8aSShawn Lin #include <linux/pm_runtime.h>
16ec5c5d8aSShawn Lin #include <linux/scatterlist.h>
1764e36824Saddy ke
1864e36824Saddy ke #define DRIVER_NAME "rockchip-spi"
1964e36824Saddy ke
20aa099382SJeffy Chen #define ROCKCHIP_SPI_CLR_BITS(reg, bits) \
21aa099382SJeffy Chen writel_relaxed(readl_relaxed(reg) & ~(bits), reg)
22aa099382SJeffy Chen #define ROCKCHIP_SPI_SET_BITS(reg, bits) \
23aa099382SJeffy Chen writel_relaxed(readl_relaxed(reg) | (bits), reg)
24aa099382SJeffy Chen
2564e36824Saddy ke /* SPI register offsets */
2664e36824Saddy ke #define ROCKCHIP_SPI_CTRLR0 0x0000
2764e36824Saddy ke #define ROCKCHIP_SPI_CTRLR1 0x0004
2864e36824Saddy ke #define ROCKCHIP_SPI_SSIENR 0x0008
2964e36824Saddy ke #define ROCKCHIP_SPI_SER 0x000c
3064e36824Saddy ke #define ROCKCHIP_SPI_BAUDR 0x0010
3164e36824Saddy ke #define ROCKCHIP_SPI_TXFTLR 0x0014
3264e36824Saddy ke #define ROCKCHIP_SPI_RXFTLR 0x0018
3364e36824Saddy ke #define ROCKCHIP_SPI_TXFLR 0x001c
3464e36824Saddy ke #define ROCKCHIP_SPI_RXFLR 0x0020
3564e36824Saddy ke #define ROCKCHIP_SPI_SR 0x0024
3664e36824Saddy ke #define ROCKCHIP_SPI_IPR 0x0028
3764e36824Saddy ke #define ROCKCHIP_SPI_IMR 0x002c
3864e36824Saddy ke #define ROCKCHIP_SPI_ISR 0x0030
3964e36824Saddy ke #define ROCKCHIP_SPI_RISR 0x0034
4064e36824Saddy ke #define ROCKCHIP_SPI_ICR 0x0038
4164e36824Saddy ke #define ROCKCHIP_SPI_DMACR 0x003c
4264e36824Saddy ke #define ROCKCHIP_SPI_DMATDLR 0x0040
4364e36824Saddy ke #define ROCKCHIP_SPI_DMARDLR 0x0044
4413a96935SJon Lin #define ROCKCHIP_SPI_VERSION 0x0048
4564e36824Saddy ke #define ROCKCHIP_SPI_TXDR 0x0400
4664e36824Saddy ke #define ROCKCHIP_SPI_RXDR 0x0800
4764e36824Saddy ke
4864e36824Saddy ke /* Bit fields in CTRLR0 */
4964e36824Saddy ke #define CR0_DFS_OFFSET 0
5065498c6aSEmil Renner Berthing #define CR0_DFS_4BIT 0x0
5165498c6aSEmil Renner Berthing #define CR0_DFS_8BIT 0x1
5265498c6aSEmil Renner Berthing #define CR0_DFS_16BIT 0x2
5364e36824Saddy ke
5464e36824Saddy ke #define CR0_CFS_OFFSET 2
5564e36824Saddy ke
5664e36824Saddy ke #define CR0_SCPH_OFFSET 6
5764e36824Saddy ke
5864e36824Saddy ke #define CR0_SCPOL_OFFSET 7
5964e36824Saddy ke
6064e36824Saddy ke #define CR0_CSM_OFFSET 8
6164e36824Saddy ke #define CR0_CSM_KEEP 0x0
6264e36824Saddy ke /* ss_n be high for half sclk_out cycles */
6364e36824Saddy ke #define CR0_CSM_HALF 0X1
6464e36824Saddy ke /* ss_n be high for one sclk_out cycle */
6564e36824Saddy ke #define CR0_CSM_ONE 0x2
6664e36824Saddy ke
6764e36824Saddy ke /* ss_n to sclk_out delay */
6864e36824Saddy ke #define CR0_SSD_OFFSET 10
6964e36824Saddy ke /*
7064e36824Saddy ke * The period between ss_n active and
7164e36824Saddy ke * sclk_out active is half sclk_out cycles
7264e36824Saddy ke */
7364e36824Saddy ke #define CR0_SSD_HALF 0x0
7464e36824Saddy ke /*
7564e36824Saddy ke * The period between ss_n active and
7664e36824Saddy ke * sclk_out active is one sclk_out cycle
7764e36824Saddy ke */
7864e36824Saddy ke #define CR0_SSD_ONE 0x1
7964e36824Saddy ke
8064e36824Saddy ke #define CR0_EM_OFFSET 11
8164e36824Saddy ke #define CR0_EM_LITTLE 0x0
8264e36824Saddy ke #define CR0_EM_BIG 0x1
8364e36824Saddy ke
8464e36824Saddy ke #define CR0_FBM_OFFSET 12
8564e36824Saddy ke #define CR0_FBM_MSB 0x0
8664e36824Saddy ke #define CR0_FBM_LSB 0x1
8764e36824Saddy ke
8864e36824Saddy ke #define CR0_BHT_OFFSET 13
8964e36824Saddy ke #define CR0_BHT_16BIT 0x0
9064e36824Saddy ke #define CR0_BHT_8BIT 0x1
9164e36824Saddy ke
9264e36824Saddy ke #define CR0_RSD_OFFSET 14
9374b7efa8SEmil Renner Berthing #define CR0_RSD_MAX 0x3
9464e36824Saddy ke
9564e36824Saddy ke #define CR0_FRF_OFFSET 16
9664e36824Saddy ke #define CR0_FRF_SPI 0x0
9764e36824Saddy ke #define CR0_FRF_SSP 0x1
9864e36824Saddy ke #define CR0_FRF_MICROWIRE 0x2
9964e36824Saddy ke
10064e36824Saddy ke #define CR0_XFM_OFFSET 18
10164e36824Saddy ke #define CR0_XFM_MASK (0x03 << SPI_XFM_OFFSET)
10264e36824Saddy ke #define CR0_XFM_TR 0x0
10364e36824Saddy ke #define CR0_XFM_TO 0x1
10464e36824Saddy ke #define CR0_XFM_RO 0x2
10564e36824Saddy ke
10664e36824Saddy ke #define CR0_OPM_OFFSET 20
1071a3ccff3SYang Yingliang #define CR0_OPM_HOST 0x0
1081a3ccff3SYang Yingliang #define CR0_OPM_TARGET 0x1
10964e36824Saddy ke
110736b81e0SJon Lin #define CR0_SOI_OFFSET 23
111736b81e0SJon Lin
11264e36824Saddy ke #define CR0_MTM_OFFSET 0x21
11364e36824Saddy ke
11464e36824Saddy ke /* Bit fields in SER, 2bit */
11564e36824Saddy ke #define SER_MASK 0x3
11664e36824Saddy ke
117420b82f8SEmil Renner Berthing /* Bit fields in BAUDR */
118420b82f8SEmil Renner Berthing #define BAUDR_SCKDV_MIN 2
119420b82f8SEmil Renner Berthing #define BAUDR_SCKDV_MAX 65534
120420b82f8SEmil Renner Berthing
1212758bd09SJon Lin /* Bit fields in SR, 6bit */
1222758bd09SJon Lin #define SR_MASK 0x3f
12364e36824Saddy ke #define SR_BUSY (1 << 0)
12464e36824Saddy ke #define SR_TF_FULL (1 << 1)
12564e36824Saddy ke #define SR_TF_EMPTY (1 << 2)
12664e36824Saddy ke #define SR_RF_EMPTY (1 << 3)
12764e36824Saddy ke #define SR_RF_FULL (1 << 4)
1281a3ccff3SYang Yingliang #define SR_TARGET_TX_BUSY (1 << 5)
12964e36824Saddy ke
13064e36824Saddy ke /* Bit fields in ISR, IMR, ISR, RISR, 5bit */
13164e36824Saddy ke #define INT_MASK 0x1f
13264e36824Saddy ke #define INT_TF_EMPTY (1 << 0)
13364e36824Saddy ke #define INT_TF_OVERFLOW (1 << 1)
13464e36824Saddy ke #define INT_RF_UNDERFLOW (1 << 2)
13564e36824Saddy ke #define INT_RF_OVERFLOW (1 << 3)
13664e36824Saddy ke #define INT_RF_FULL (1 << 4)
137869f2c94SJon Lin #define INT_CS_INACTIVE (1 << 6)
13864e36824Saddy ke
13964e36824Saddy ke /* Bit fields in ICR, 4bit */
14064e36824Saddy ke #define ICR_MASK 0x0f
14164e36824Saddy ke #define ICR_ALL (1 << 0)
14264e36824Saddy ke #define ICR_RF_UNDERFLOW (1 << 1)
14364e36824Saddy ke #define ICR_RF_OVERFLOW (1 << 2)
14464e36824Saddy ke #define ICR_TF_OVERFLOW (1 << 3)
14564e36824Saddy ke
14664e36824Saddy ke /* Bit fields in DMACR */
14764e36824Saddy ke #define RF_DMA_EN (1 << 0)
14864e36824Saddy ke #define TF_DMA_EN (1 << 1)
14964e36824Saddy ke
150fab3e487SEmil Renner Berthing /* Driver state flags */
151fab3e487SEmil Renner Berthing #define RXDMA (1 << 0)
152fab3e487SEmil Renner Berthing #define TXDMA (1 << 1)
15364e36824Saddy ke
1541a3ccff3SYang Yingliang /* sclk_out: spi host internal logic in rk3x can support 50Mhz */
155420b82f8SEmil Renner Berthing #define MAX_SCLK_OUT 50000000U
156f9cfd522SAddy Ke
1575185a81cSBrian Norris /*
1585185a81cSBrian Norris * SPI_CTRLR1 is 16-bits, so we should support lengths of 0xffff + 1. However,
1595185a81cSBrian Norris * the controller seems to hang when given 0x10000, so stick with this for now.
1605185a81cSBrian Norris */
1615185a81cSBrian Norris #define ROCKCHIP_SPI_MAX_TRANLEN 0xffff
1625185a81cSBrian Norris
16307d67493SLuis de Arquer #define ROCKCHIP_SPI_MAX_NATIVE_CS_NUM 2
16413a96935SJon Lin #define ROCKCHIP_SPI_VER2_TYPE1 0x05EC0002
16513a96935SJon Lin #define ROCKCHIP_SPI_VER2_TYPE2 0x00110002
166aa099382SJeffy Chen
167940f3bbfSAlexander Kochetkov #define ROCKCHIP_AUTOSUSPEND_TIMEOUT 2000
168940f3bbfSAlexander Kochetkov
16964e36824Saddy ke struct rockchip_spi {
17064e36824Saddy ke struct device *dev;
17164e36824Saddy ke
17264e36824Saddy ke struct clk *spiclk;
17364e36824Saddy ke struct clk *apb_pclk;
17464e36824Saddy ke
17564e36824Saddy ke void __iomem *regs;
176eee06a9eSEmil Renner Berthing dma_addr_t dma_addr_rx;
177eee06a9eSEmil Renner Berthing dma_addr_t dma_addr_tx;
178fab3e487SEmil Renner Berthing
17901b59ce5SEmil Renner Berthing const void *tx;
18001b59ce5SEmil Renner Berthing void *rx;
18101b59ce5SEmil Renner Berthing unsigned int tx_left;
18201b59ce5SEmil Renner Berthing unsigned int rx_left;
18301b59ce5SEmil Renner Berthing
184fab3e487SEmil Renner Berthing atomic_t state;
185fab3e487SEmil Renner Berthing
18664e36824Saddy ke /*depth of the FIFO buffer */
18764e36824Saddy ke u32 fifo_len;
188420b82f8SEmil Renner Berthing /* frequency of spiclk */
189420b82f8SEmil Renner Berthing u32 freq;
19064e36824Saddy ke
19164e36824Saddy ke u8 n_bytes;
19274b7efa8SEmil Renner Berthing u8 rsd;
19364e36824Saddy ke
1941a3ccff3SYang Yingliang bool target_abort;
1951a3ccff3SYang Yingliang bool cs_inactive; /* spi target tansmition stop when cs inactive */
196d5d933f0SLuca Ceresoli bool cs_high_supported; /* native CS supports active-high polarity */
197d5d933f0SLuca Ceresoli
198869f2c94SJon Lin struct spi_transfer *xfer; /* Store xfer temporarily */
19964e36824Saddy ke };
20064e36824Saddy ke
spi_enable_chip(struct rockchip_spi * rs,bool enable)20130688e4eSEmil Renner Berthing static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable)
20264e36824Saddy ke {
20330688e4eSEmil Renner Berthing writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR);
20464e36824Saddy ke }
20564e36824Saddy ke
wait_for_tx_idle(struct rockchip_spi * rs,bool target_mode)2061a3ccff3SYang Yingliang static inline void wait_for_tx_idle(struct rockchip_spi *rs, bool target_mode)
2072df08e78SAddy Ke {
2082df08e78SAddy Ke unsigned long timeout = jiffies + msecs_to_jiffies(5);
2092df08e78SAddy Ke
2102df08e78SAddy Ke do {
2111a3ccff3SYang Yingliang if (target_mode) {
2121a3ccff3SYang Yingliang if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_TARGET_TX_BUSY) &&
2132758bd09SJon Lin !((readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY)))
2142758bd09SJon Lin return;
2152758bd09SJon Lin } else {
2162df08e78SAddy Ke if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
2172df08e78SAddy Ke return;
2182758bd09SJon Lin }
21964bc0110SDoug Anderson } while (!time_after(jiffies, timeout));
2202df08e78SAddy Ke
2212df08e78SAddy Ke dev_warn(rs->dev, "spi controller is in busy state!\n");
2222df08e78SAddy Ke }
2232df08e78SAddy Ke
get_fifo_len(struct rockchip_spi * rs)22464e36824Saddy ke static u32 get_fifo_len(struct rockchip_spi *rs)
22564e36824Saddy ke {
22613a96935SJon Lin u32 ver;
22764e36824Saddy ke
22813a96935SJon Lin ver = readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION);
22913a96935SJon Lin
23013a96935SJon Lin switch (ver) {
23113a96935SJon Lin case ROCKCHIP_SPI_VER2_TYPE1:
23213a96935SJon Lin case ROCKCHIP_SPI_VER2_TYPE2:
23313a96935SJon Lin return 64;
23413a96935SJon Lin default:
23513a96935SJon Lin return 32;
23664e36824Saddy ke }
23764e36824Saddy ke }
23864e36824Saddy ke
rockchip_spi_set_cs(struct spi_device * spi,bool enable)23964e36824Saddy ke static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
24064e36824Saddy ke {
241d66571a2SChris Ruehl struct spi_controller *ctlr = spi->controller;
242d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
243736b81e0SJon Lin bool cs_asserted = spi->mode & SPI_CS_HIGH ? enable : !enable;
244b920cc31SHuibin Hong
245aa099382SJeffy Chen if (cs_asserted) {
246aa099382SJeffy Chen /* Keep things powered as long as CS is asserted */
247b920cc31SHuibin Hong pm_runtime_get_sync(rs->dev);
24864e36824Saddy ke
2499e264f3fSAmit Kumar Mahapatra via Alsa-devel if (spi_get_csgpiod(spi, 0))
250b8d42371SJon Lin ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER, 1);
251b8d42371SJon Lin else
2529e264f3fSAmit Kumar Mahapatra via Alsa-devel ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER,
2539e264f3fSAmit Kumar Mahapatra via Alsa-devel BIT(spi_get_chipselect(spi, 0)));
254aa099382SJeffy Chen } else {
2559e264f3fSAmit Kumar Mahapatra via Alsa-devel if (spi_get_csgpiod(spi, 0))
256b8d42371SJon Lin ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER, 1);
257b8d42371SJon Lin else
2589e264f3fSAmit Kumar Mahapatra via Alsa-devel ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER,
2599e264f3fSAmit Kumar Mahapatra via Alsa-devel BIT(spi_get_chipselect(spi, 0)));
26064e36824Saddy ke
261aa099382SJeffy Chen /* Drop reference from when we first asserted CS */
262aa099382SJeffy Chen pm_runtime_put(rs->dev);
263aa099382SJeffy Chen }
26464e36824Saddy ke }
26564e36824Saddy ke
rockchip_spi_handle_err(struct spi_controller * ctlr,struct spi_message * msg)266d66571a2SChris Ruehl static void rockchip_spi_handle_err(struct spi_controller *ctlr,
26764e36824Saddy ke struct spi_message *msg)
26864e36824Saddy ke {
269d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
27064e36824Saddy ke
271ce386100SEmil Renner Berthing /* stop running spi transfer
272ce386100SEmil Renner Berthing * this also flushes both rx and tx fifos
2735dcc44edSAddy Ke */
274ce386100SEmil Renner Berthing spi_enable_chip(rs, false);
275ce386100SEmil Renner Berthing
2762fcdde56SJon Lin /* make sure all interrupts are masked and status cleared */
27701b59ce5SEmil Renner Berthing writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR);
2782fcdde56SJon Lin writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR);
27901b59ce5SEmil Renner Berthing
280fab3e487SEmil Renner Berthing if (atomic_read(&rs->state) & TXDMA)
281d66571a2SChris Ruehl dmaengine_terminate_async(ctlr->dma_tx);
282fab3e487SEmil Renner Berthing
283ce386100SEmil Renner Berthing if (atomic_read(&rs->state) & RXDMA)
284d66571a2SChris Ruehl dmaengine_terminate_async(ctlr->dma_rx);
28564e36824Saddy ke }
28664e36824Saddy ke
rockchip_spi_pio_writer(struct rockchip_spi * rs)28764e36824Saddy ke static void rockchip_spi_pio_writer(struct rockchip_spi *rs)
28864e36824Saddy ke {
28901b59ce5SEmil Renner Berthing u32 tx_free = rs->fifo_len - readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFLR);
29001b59ce5SEmil Renner Berthing u32 words = min(rs->tx_left, tx_free);
29164e36824Saddy ke
29201b59ce5SEmil Renner Berthing rs->tx_left -= words;
29301b59ce5SEmil Renner Berthing for (; words; words--) {
29401b59ce5SEmil Renner Berthing u32 txw;
29501b59ce5SEmil Renner Berthing
29664e36824Saddy ke if (rs->n_bytes == 1)
29701b59ce5SEmil Renner Berthing txw = *(u8 *)rs->tx;
29864e36824Saddy ke else
29901b59ce5SEmil Renner Berthing txw = *(u16 *)rs->tx;
30064e36824Saddy ke
30164e36824Saddy ke writel_relaxed(txw, rs->regs + ROCKCHIP_SPI_TXDR);
30264e36824Saddy ke rs->tx += rs->n_bytes;
30364e36824Saddy ke }
30464e36824Saddy ke }
30564e36824Saddy ke
rockchip_spi_pio_reader(struct rockchip_spi * rs)30664e36824Saddy ke static void rockchip_spi_pio_reader(struct rockchip_spi *rs)
30764e36824Saddy ke {
30801b59ce5SEmil Renner Berthing u32 words = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
3094294e4acSJon Lin u32 rx_left = (rs->rx_left > words) ? rs->rx_left - words : 0;
31064e36824Saddy ke
31101b59ce5SEmil Renner Berthing /* the hardware doesn't allow us to change fifo threshold
31201b59ce5SEmil Renner Berthing * level while spi is enabled, so instead make sure to leave
31301b59ce5SEmil Renner Berthing * enough words in the rx fifo to get the last interrupt
31401b59ce5SEmil Renner Berthing * exactly when all words have been received
31501b59ce5SEmil Renner Berthing */
31601b59ce5SEmil Renner Berthing if (rx_left) {
31701b59ce5SEmil Renner Berthing u32 ftl = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFTLR) + 1;
31801b59ce5SEmil Renner Berthing
31901b59ce5SEmil Renner Berthing if (rx_left < ftl) {
32001b59ce5SEmil Renner Berthing rx_left = ftl;
32101b59ce5SEmil Renner Berthing words = rs->rx_left - rx_left;
32201b59ce5SEmil Renner Berthing }
32301b59ce5SEmil Renner Berthing }
32401b59ce5SEmil Renner Berthing
32501b59ce5SEmil Renner Berthing rs->rx_left = rx_left;
32601b59ce5SEmil Renner Berthing for (; words; words--) {
32701b59ce5SEmil Renner Berthing u32 rxw = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
32801b59ce5SEmil Renner Berthing
32901b59ce5SEmil Renner Berthing if (!rs->rx)
33001b59ce5SEmil Renner Berthing continue;
33101b59ce5SEmil Renner Berthing
33264e36824Saddy ke if (rs->n_bytes == 1)
33301b59ce5SEmil Renner Berthing *(u8 *)rs->rx = (u8)rxw;
33464e36824Saddy ke else
33501b59ce5SEmil Renner Berthing *(u16 *)rs->rx = (u16)rxw;
33664e36824Saddy ke rs->rx += rs->n_bytes;
3375dcc44edSAddy Ke }
33864e36824Saddy ke }
33964e36824Saddy ke
rockchip_spi_isr(int irq,void * dev_id)34001b59ce5SEmil Renner Berthing static irqreturn_t rockchip_spi_isr(int irq, void *dev_id)
34164e36824Saddy ke {
342d66571a2SChris Ruehl struct spi_controller *ctlr = dev_id;
343d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
34464e36824Saddy ke
3451a3ccff3SYang Yingliang /* When int_cs_inactive comes, spi target abort */
346869f2c94SJon Lin if (rs->cs_inactive && readl_relaxed(rs->regs + ROCKCHIP_SPI_IMR) & INT_CS_INACTIVE) {
3471a3ccff3SYang Yingliang ctlr->target_abort(ctlr);
348869f2c94SJon Lin writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR);
349869f2c94SJon Lin writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR);
350869f2c94SJon Lin
351869f2c94SJon Lin return IRQ_HANDLED;
352869f2c94SJon Lin }
353869f2c94SJon Lin
35401b59ce5SEmil Renner Berthing if (rs->tx_left)
35501b59ce5SEmil Renner Berthing rockchip_spi_pio_writer(rs);
35601b59ce5SEmil Renner Berthing
35701b59ce5SEmil Renner Berthing rockchip_spi_pio_reader(rs);
35801b59ce5SEmil Renner Berthing if (!rs->rx_left) {
35901b59ce5SEmil Renner Berthing spi_enable_chip(rs, false);
36001b59ce5SEmil Renner Berthing writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR);
361869f2c94SJon Lin writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR);
362d66571a2SChris Ruehl spi_finalize_current_transfer(ctlr);
36301b59ce5SEmil Renner Berthing }
36401b59ce5SEmil Renner Berthing
36501b59ce5SEmil Renner Berthing return IRQ_HANDLED;
36601b59ce5SEmil Renner Berthing }
36701b59ce5SEmil Renner Berthing
rockchip_spi_prepare_irq(struct rockchip_spi * rs,struct spi_controller * ctlr,struct spi_transfer * xfer)36801b59ce5SEmil Renner Berthing static int rockchip_spi_prepare_irq(struct rockchip_spi *rs,
369869f2c94SJon Lin struct spi_controller *ctlr,
37001b59ce5SEmil Renner Berthing struct spi_transfer *xfer)
37101b59ce5SEmil Renner Berthing {
37201b59ce5SEmil Renner Berthing rs->tx = xfer->tx_buf;
37301b59ce5SEmil Renner Berthing rs->rx = xfer->rx_buf;
37401b59ce5SEmil Renner Berthing rs->tx_left = rs->tx ? xfer->len / rs->n_bytes : 0;
37501b59ce5SEmil Renner Berthing rs->rx_left = xfer->len / rs->n_bytes;
37601b59ce5SEmil Renner Berthing
377419bc8f6SJon Lin writel_relaxed(0xffffffff, rs->regs + ROCKCHIP_SPI_ICR);
378419bc8f6SJon Lin
37930688e4eSEmil Renner Berthing spi_enable_chip(rs, true);
380a3c17402SEmil Renner Berthing
38101b59ce5SEmil Renner Berthing if (rs->tx_left)
38264e36824Saddy ke rockchip_spi_pio_writer(rs);
38364e36824Saddy ke
384419bc8f6SJon Lin if (rs->cs_inactive)
385419bc8f6SJon Lin writel_relaxed(INT_RF_FULL | INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR);
386419bc8f6SJon Lin else
387419bc8f6SJon Lin writel_relaxed(INT_RF_FULL, rs->regs + ROCKCHIP_SPI_IMR);
388419bc8f6SJon Lin
38901b59ce5SEmil Renner Berthing /* 1 means the transfer is in progress */
39001b59ce5SEmil Renner Berthing return 1;
39164e36824Saddy ke }
39264e36824Saddy ke
rockchip_spi_dma_rxcb(void * data)39364e36824Saddy ke static void rockchip_spi_dma_rxcb(void *data)
39464e36824Saddy ke {
395d66571a2SChris Ruehl struct spi_controller *ctlr = data;
396d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
397fab3e487SEmil Renner Berthing int state = atomic_fetch_andnot(RXDMA, &rs->state);
39864e36824Saddy ke
3991a3ccff3SYang Yingliang if (state & TXDMA && !rs->target_abort)
400fab3e487SEmil Renner Berthing return;
40164e36824Saddy ke
402869f2c94SJon Lin if (rs->cs_inactive)
403869f2c94SJon Lin writel_relaxed(0, rs->regs + ROCKCHIP_SPI_IMR);
404869f2c94SJon Lin
40530688e4eSEmil Renner Berthing spi_enable_chip(rs, false);
406d66571a2SChris Ruehl spi_finalize_current_transfer(ctlr);
407c28be31bSAddy Ke }
40864e36824Saddy ke
rockchip_spi_dma_txcb(void * data)40964e36824Saddy ke static void rockchip_spi_dma_txcb(void *data)
41064e36824Saddy ke {
411d66571a2SChris Ruehl struct spi_controller *ctlr = data;
412d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
413fab3e487SEmil Renner Berthing int state = atomic_fetch_andnot(TXDMA, &rs->state);
414fab3e487SEmil Renner Berthing
4151a3ccff3SYang Yingliang if (state & RXDMA && !rs->target_abort)
416fab3e487SEmil Renner Berthing return;
41764e36824Saddy ke
4182df08e78SAddy Ke /* Wait until the FIFO data completely. */
4191a3ccff3SYang Yingliang wait_for_tx_idle(rs, ctlr->target);
4202df08e78SAddy Ke
42130688e4eSEmil Renner Berthing spi_enable_chip(rs, false);
422d66571a2SChris Ruehl spi_finalize_current_transfer(ctlr);
4232c2bc748SAddy Ke }
42464e36824Saddy ke
rockchip_spi_calc_burst_size(u32 data_len)4254d9ca632SJon Lin static u32 rockchip_spi_calc_burst_size(u32 data_len)
4264d9ca632SJon Lin {
4274d9ca632SJon Lin u32 i;
4284d9ca632SJon Lin
4294d9ca632SJon Lin /* burst size: 1, 2, 4, 8 */
4304d9ca632SJon Lin for (i = 1; i < 8; i <<= 1) {
4314d9ca632SJon Lin if (data_len & i)
4324d9ca632SJon Lin break;
4334d9ca632SJon Lin }
4344d9ca632SJon Lin
4354d9ca632SJon Lin return i;
4364d9ca632SJon Lin }
4374d9ca632SJon Lin
rockchip_spi_prepare_dma(struct rockchip_spi * rs,struct spi_controller * ctlr,struct spi_transfer * xfer)438fc1ad8eeSEmil Renner Berthing static int rockchip_spi_prepare_dma(struct rockchip_spi *rs,
439d66571a2SChris Ruehl struct spi_controller *ctlr, struct spi_transfer *xfer)
44064e36824Saddy ke {
44164e36824Saddy ke struct dma_async_tx_descriptor *rxdesc, *txdesc;
44264e36824Saddy ke
443fab3e487SEmil Renner Berthing atomic_set(&rs->state, 0);
44464e36824Saddy ke
445869f2c94SJon Lin rs->tx = xfer->tx_buf;
446869f2c94SJon Lin rs->rx = xfer->rx_buf;
447869f2c94SJon Lin
44897cf5669SArnd Bergmann rxdesc = NULL;
449fc1ad8eeSEmil Renner Berthing if (xfer->rx_buf) {
45031bcb57bSEmil Renner Berthing struct dma_slave_config rxconf = {
45131bcb57bSEmil Renner Berthing .direction = DMA_DEV_TO_MEM,
452eee06a9eSEmil Renner Berthing .src_addr = rs->dma_addr_rx,
45331bcb57bSEmil Renner Berthing .src_addr_width = rs->n_bytes,
454869f2c94SJon Lin .src_maxburst = rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes),
45531bcb57bSEmil Renner Berthing };
45631bcb57bSEmil Renner Berthing
457d66571a2SChris Ruehl dmaengine_slave_config(ctlr->dma_rx, &rxconf);
45864e36824Saddy ke
4595dcc44edSAddy Ke rxdesc = dmaengine_prep_slave_sg(
460d66571a2SChris Ruehl ctlr->dma_rx,
461fc1ad8eeSEmil Renner Berthing xfer->rx_sg.sgl, xfer->rx_sg.nents,
462d9071b7eSEmil Renner Berthing DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
463ea984911SShawn Lin if (!rxdesc)
464ea984911SShawn Lin return -EINVAL;
46564e36824Saddy ke
46664e36824Saddy ke rxdesc->callback = rockchip_spi_dma_rxcb;
467d66571a2SChris Ruehl rxdesc->callback_param = ctlr;
46864e36824Saddy ke }
46964e36824Saddy ke
47097cf5669SArnd Bergmann txdesc = NULL;
471fc1ad8eeSEmil Renner Berthing if (xfer->tx_buf) {
47231bcb57bSEmil Renner Berthing struct dma_slave_config txconf = {
47331bcb57bSEmil Renner Berthing .direction = DMA_MEM_TO_DEV,
474eee06a9eSEmil Renner Berthing .dst_addr = rs->dma_addr_tx,
47531bcb57bSEmil Renner Berthing .dst_addr_width = rs->n_bytes,
47647300728SEmil Renner Berthing .dst_maxburst = rs->fifo_len / 4,
47731bcb57bSEmil Renner Berthing };
47831bcb57bSEmil Renner Berthing
479d66571a2SChris Ruehl dmaengine_slave_config(ctlr->dma_tx, &txconf);
48064e36824Saddy ke
4815dcc44edSAddy Ke txdesc = dmaengine_prep_slave_sg(
482d66571a2SChris Ruehl ctlr->dma_tx,
483fc1ad8eeSEmil Renner Berthing xfer->tx_sg.sgl, xfer->tx_sg.nents,
484d9071b7eSEmil Renner Berthing DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
485ea984911SShawn Lin if (!txdesc) {
486ea984911SShawn Lin if (rxdesc)
487d66571a2SChris Ruehl dmaengine_terminate_sync(ctlr->dma_rx);
488ea984911SShawn Lin return -EINVAL;
489ea984911SShawn Lin }
49064e36824Saddy ke
49164e36824Saddy ke txdesc->callback = rockchip_spi_dma_txcb;
492d66571a2SChris Ruehl txdesc->callback_param = ctlr;
49364e36824Saddy ke }
49464e36824Saddy ke
49564e36824Saddy ke /* rx must be started before tx due to spi instinct */
49697cf5669SArnd Bergmann if (rxdesc) {
497fab3e487SEmil Renner Berthing atomic_or(RXDMA, &rs->state);
498869f2c94SJon Lin ctlr->dma_rx->cookie = dmaengine_submit(rxdesc);
499d66571a2SChris Ruehl dma_async_issue_pending(ctlr->dma_rx);
50064e36824Saddy ke }
50164e36824Saddy ke
502869f2c94SJon Lin if (rs->cs_inactive)
503869f2c94SJon Lin writel_relaxed(INT_CS_INACTIVE, rs->regs + ROCKCHIP_SPI_IMR);
504869f2c94SJon Lin
50530688e4eSEmil Renner Berthing spi_enable_chip(rs, true);
506a3c17402SEmil Renner Berthing
50797cf5669SArnd Bergmann if (txdesc) {
508fab3e487SEmil Renner Berthing atomic_or(TXDMA, &rs->state);
50964e36824Saddy ke dmaengine_submit(txdesc);
510d66571a2SChris Ruehl dma_async_issue_pending(ctlr->dma_tx);
51164e36824Saddy ke }
512ea984911SShawn Lin
513a3c17402SEmil Renner Berthing /* 1 means the transfer is in progress */
514a3c17402SEmil Renner Berthing return 1;
51564e36824Saddy ke }
51664e36824Saddy ke
rockchip_spi_config(struct rockchip_spi * rs,struct spi_device * spi,struct spi_transfer * xfer,bool use_dma,bool target_mode)517e5098952SArnd Bergmann static int rockchip_spi_config(struct rockchip_spi *rs,
518eff0275eSEmil Renner Berthing struct spi_device *spi, struct spi_transfer *xfer,
5191a3ccff3SYang Yingliang bool use_dma, bool target_mode)
52064e36824Saddy ke {
5212410d6a3SEmil Renner Berthing u32 cr0 = CR0_FRF_SPI << CR0_FRF_OFFSET
5222410d6a3SEmil Renner Berthing | CR0_BHT_8BIT << CR0_BHT_OFFSET
5232410d6a3SEmil Renner Berthing | CR0_SSD_ONE << CR0_SSD_OFFSET
5242410d6a3SEmil Renner Berthing | CR0_EM_BIG << CR0_EM_OFFSET;
52565498c6aSEmil Renner Berthing u32 cr1;
52665498c6aSEmil Renner Berthing u32 dmacr = 0;
52764e36824Saddy ke
5281a3ccff3SYang Yingliang if (target_mode)
5291a3ccff3SYang Yingliang cr0 |= CR0_OPM_TARGET << CR0_OPM_OFFSET;
5301a3ccff3SYang Yingliang rs->target_abort = false;
531d065f41aSChris Ruehl
53274b7efa8SEmil Renner Berthing cr0 |= rs->rsd << CR0_RSD_OFFSET;
533fc1ad8eeSEmil Renner Berthing cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET;
53404290192SEmil Renner Berthing if (spi->mode & SPI_LSB_FIRST)
53504290192SEmil Renner Berthing cr0 |= CR0_FBM_LSB << CR0_FBM_OFFSET;
536736b81e0SJon Lin if (spi->mode & SPI_CS_HIGH)
5379e264f3fSAmit Kumar Mahapatra via Alsa-devel cr0 |= BIT(spi_get_chipselect(spi, 0)) << CR0_SOI_OFFSET;
538fc1ad8eeSEmil Renner Berthing
539fc1ad8eeSEmil Renner Berthing if (xfer->rx_buf && xfer->tx_buf)
540fc1ad8eeSEmil Renner Berthing cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET;
541fc1ad8eeSEmil Renner Berthing else if (xfer->rx_buf)
542fc1ad8eeSEmil Renner Berthing cr0 |= CR0_XFM_RO << CR0_XFM_OFFSET;
54301b59ce5SEmil Renner Berthing else if (use_dma)
544fc1ad8eeSEmil Renner Berthing cr0 |= CR0_XFM_TO << CR0_XFM_OFFSET;
54564e36824Saddy ke
54665498c6aSEmil Renner Berthing switch (xfer->bits_per_word) {
54765498c6aSEmil Renner Berthing case 4:
54865498c6aSEmil Renner Berthing cr0 |= CR0_DFS_4BIT << CR0_DFS_OFFSET;
54965498c6aSEmil Renner Berthing cr1 = xfer->len - 1;
55065498c6aSEmil Renner Berthing break;
55165498c6aSEmil Renner Berthing case 8:
55265498c6aSEmil Renner Berthing cr0 |= CR0_DFS_8BIT << CR0_DFS_OFFSET;
55365498c6aSEmil Renner Berthing cr1 = xfer->len - 1;
55465498c6aSEmil Renner Berthing break;
55565498c6aSEmil Renner Berthing case 16:
55665498c6aSEmil Renner Berthing cr0 |= CR0_DFS_16BIT << CR0_DFS_OFFSET;
55765498c6aSEmil Renner Berthing cr1 = xfer->len / 2 - 1;
55865498c6aSEmil Renner Berthing break;
55965498c6aSEmil Renner Berthing default:
56065498c6aSEmil Renner Berthing /* we only whitelist 4, 8 and 16 bit words in
561d66571a2SChris Ruehl * ctlr->bits_per_word_mask, so this shouldn't
56265498c6aSEmil Renner Berthing * happen
56365498c6aSEmil Renner Berthing */
564e5098952SArnd Bergmann dev_err(rs->dev, "unknown bits per word: %d\n",
565e5098952SArnd Bergmann xfer->bits_per_word);
566e5098952SArnd Bergmann return -EINVAL;
56765498c6aSEmil Renner Berthing }
56865498c6aSEmil Renner Berthing
569eff0275eSEmil Renner Berthing if (use_dma) {
570fc1ad8eeSEmil Renner Berthing if (xfer->tx_buf)
57164e36824Saddy ke dmacr |= TF_DMA_EN;
572fc1ad8eeSEmil Renner Berthing if (xfer->rx_buf)
57364e36824Saddy ke dmacr |= RF_DMA_EN;
57464e36824Saddy ke }
57564e36824Saddy ke
57664e36824Saddy ke writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
57765498c6aSEmil Renner Berthing writel_relaxed(cr1, rs->regs + ROCKCHIP_SPI_CTRLR1);
57804b37d2dSHuibin Hong
57901b59ce5SEmil Renner Berthing /* unfortunately setting the fifo threshold level to generate an
58001b59ce5SEmil Renner Berthing * interrupt exactly when the fifo is full doesn't seem to work,
58101b59ce5SEmil Renner Berthing * so we need the strict inequality here
58201b59ce5SEmil Renner Berthing */
5834a47fcdbSJon Lin if ((xfer->len / rs->n_bytes) < rs->fifo_len)
5844a47fcdbSJon Lin writel_relaxed(xfer->len / rs->n_bytes - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
58501b59ce5SEmil Renner Berthing else
58664e36824Saddy ke writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
58764e36824Saddy ke
5882758bd09SJon Lin writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_DMATDLR);
5894d9ca632SJon Lin writel_relaxed(rockchip_spi_calc_burst_size(xfer->len / rs->n_bytes) - 1,
5904d9ca632SJon Lin rs->regs + ROCKCHIP_SPI_DMARDLR);
59164e36824Saddy ke writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
59264e36824Saddy ke
593420b82f8SEmil Renner Berthing /* the hardware only supports an even clock divisor, so
594420b82f8SEmil Renner Berthing * round divisor = spiclk / speed up to nearest even number
595420b82f8SEmil Renner Berthing * so that the resulting speed is <= the requested speed
596420b82f8SEmil Renner Berthing */
597420b82f8SEmil Renner Berthing writel_relaxed(2 * DIV_ROUND_UP(rs->freq, 2 * xfer->speed_hz),
598420b82f8SEmil Renner Berthing rs->regs + ROCKCHIP_SPI_BAUDR);
599e5098952SArnd Bergmann
600e5098952SArnd Bergmann return 0;
60164e36824Saddy ke }
60264e36824Saddy ke
rockchip_spi_max_transfer_size(struct spi_device * spi)6035185a81cSBrian Norris static size_t rockchip_spi_max_transfer_size(struct spi_device *spi)
6045185a81cSBrian Norris {
6055185a81cSBrian Norris return ROCKCHIP_SPI_MAX_TRANLEN;
6065185a81cSBrian Norris }
6075185a81cSBrian Norris
rockchip_spi_target_abort(struct spi_controller * ctlr)6081a3ccff3SYang Yingliang static int rockchip_spi_target_abort(struct spi_controller *ctlr)
609d065f41aSChris Ruehl {
610d065f41aSChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
611869f2c94SJon Lin u32 rx_fifo_left;
612869f2c94SJon Lin struct dma_tx_state state;
613869f2c94SJon Lin enum dma_status status;
614d065f41aSChris Ruehl
615869f2c94SJon Lin /* Get current dma rx point */
616869f2c94SJon Lin if (atomic_read(&rs->state) & RXDMA) {
617869f2c94SJon Lin dmaengine_pause(ctlr->dma_rx);
618869f2c94SJon Lin status = dmaengine_tx_status(ctlr->dma_rx, ctlr->dma_rx->cookie, &state);
619869f2c94SJon Lin if (status == DMA_ERROR) {
620869f2c94SJon Lin rs->rx = rs->xfer->rx_buf;
621869f2c94SJon Lin rs->xfer->len = 0;
622869f2c94SJon Lin rx_fifo_left = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
623869f2c94SJon Lin for (; rx_fifo_left; rx_fifo_left--)
624869f2c94SJon Lin readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
625869f2c94SJon Lin goto out;
626869f2c94SJon Lin } else {
627869f2c94SJon Lin rs->rx += rs->xfer->len - rs->n_bytes * state.residue;
628869f2c94SJon Lin }
629869f2c94SJon Lin }
630869f2c94SJon Lin
631869f2c94SJon Lin /* Get the valid data left in rx fifo and set rs->xfer->len real rx size */
632869f2c94SJon Lin if (rs->rx) {
633869f2c94SJon Lin rx_fifo_left = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
634869f2c94SJon Lin for (; rx_fifo_left; rx_fifo_left--) {
635869f2c94SJon Lin u32 rxw = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
636869f2c94SJon Lin
637869f2c94SJon Lin if (rs->n_bytes == 1)
638869f2c94SJon Lin *(u8 *)rs->rx = (u8)rxw;
639869f2c94SJon Lin else
640869f2c94SJon Lin *(u16 *)rs->rx = (u16)rxw;
641869f2c94SJon Lin rs->rx += rs->n_bytes;
642869f2c94SJon Lin }
643869f2c94SJon Lin rs->xfer->len = (unsigned int)(rs->rx - rs->xfer->rx_buf);
644869f2c94SJon Lin }
645869f2c94SJon Lin
646869f2c94SJon Lin out:
64780808768SJon Lin if (atomic_read(&rs->state) & RXDMA)
64880808768SJon Lin dmaengine_terminate_sync(ctlr->dma_rx);
64980808768SJon Lin if (atomic_read(&rs->state) & TXDMA)
65080808768SJon Lin dmaengine_terminate_sync(ctlr->dma_tx);
65180808768SJon Lin atomic_set(&rs->state, 0);
65280808768SJon Lin spi_enable_chip(rs, false);
6531a3ccff3SYang Yingliang rs->target_abort = true;
6546bd2c867SVincent Pelletier spi_finalize_current_transfer(ctlr);
655d065f41aSChris Ruehl
656d065f41aSChris Ruehl return 0;
657d065f41aSChris Ruehl }
658d065f41aSChris Ruehl
rockchip_spi_transfer_one(struct spi_controller * ctlr,struct spi_device * spi,struct spi_transfer * xfer)6595dcc44edSAddy Ke static int rockchip_spi_transfer_one(
660d66571a2SChris Ruehl struct spi_controller *ctlr,
66164e36824Saddy ke struct spi_device *spi,
66264e36824Saddy ke struct spi_transfer *xfer)
66364e36824Saddy ke {
664d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
665e5098952SArnd Bergmann int ret;
666eff0275eSEmil Renner Berthing bool use_dma;
66764e36824Saddy ke
6685457773eSTobias Schramm /* Zero length transfers won't trigger an interrupt on completion */
6695457773eSTobias Schramm if (!xfer->len) {
6705457773eSTobias Schramm spi_finalize_current_transfer(ctlr);
6715457773eSTobias Schramm return 1;
6725457773eSTobias Schramm }
6735457773eSTobias Schramm
67462946172SDoug Anderson WARN_ON(readl_relaxed(rs->regs + ROCKCHIP_SPI_SSIENR) &&
67562946172SDoug Anderson (readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY));
67664e36824Saddy ke
67764e36824Saddy ke if (!xfer->tx_buf && !xfer->rx_buf) {
67864e36824Saddy ke dev_err(rs->dev, "No buffer for transfer\n");
67964e36824Saddy ke return -EINVAL;
68064e36824Saddy ke }
68164e36824Saddy ke
6825185a81cSBrian Norris if (xfer->len > ROCKCHIP_SPI_MAX_TRANLEN) {
6835185a81cSBrian Norris dev_err(rs->dev, "Transfer is too long (%d)\n", xfer->len);
6845185a81cSBrian Norris return -EINVAL;
6855185a81cSBrian Norris }
6865185a81cSBrian Norris
68765498c6aSEmil Renner Berthing rs->n_bytes = xfer->bits_per_word <= 8 ? 1 : 2;
688869f2c94SJon Lin rs->xfer = xfer;
689d66571a2SChris Ruehl use_dma = ctlr->can_dma ? ctlr->can_dma(ctlr, spi, xfer) : false;
69064e36824Saddy ke
6911a3ccff3SYang Yingliang ret = rockchip_spi_config(rs, spi, xfer, use_dma, ctlr->target);
692e5098952SArnd Bergmann if (ret)
693e5098952SArnd Bergmann return ret;
69464e36824Saddy ke
695eff0275eSEmil Renner Berthing if (use_dma)
696d66571a2SChris Ruehl return rockchip_spi_prepare_dma(rs, ctlr, xfer);
69764e36824Saddy ke
698869f2c94SJon Lin return rockchip_spi_prepare_irq(rs, ctlr, xfer);
69964e36824Saddy ke }
70064e36824Saddy ke
rockchip_spi_can_dma(struct spi_controller * ctlr,struct spi_device * spi,struct spi_transfer * xfer)701d66571a2SChris Ruehl static bool rockchip_spi_can_dma(struct spi_controller *ctlr,
70264e36824Saddy ke struct spi_device *spi,
70364e36824Saddy ke struct spi_transfer *xfer)
70464e36824Saddy ke {
705d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
70601b59ce5SEmil Renner Berthing unsigned int bytes_per_word = xfer->bits_per_word <= 8 ? 1 : 2;
70764e36824Saddy ke
70801b59ce5SEmil Renner Berthing /* if the numbor of spi words to transfer is less than the fifo
70901b59ce5SEmil Renner Berthing * length we can just fill the fifo and wait for a single irq,
71001b59ce5SEmil Renner Berthing * so don't bother setting up dma
71101b59ce5SEmil Renner Berthing */
71201b59ce5SEmil Renner Berthing return xfer->len / bytes_per_word >= rs->fifo_len;
71364e36824Saddy ke }
71464e36824Saddy ke
rockchip_spi_setup(struct spi_device * spi)7153a4bf922SJon Lin static int rockchip_spi_setup(struct spi_device *spi)
7163a4bf922SJon Lin {
7173a4bf922SJon Lin struct rockchip_spi *rs = spi_controller_get_devdata(spi->controller);
7183a4bf922SJon Lin u32 cr0;
7193a4bf922SJon Lin
7209e264f3fSAmit Kumar Mahapatra via Alsa-devel if (!spi_get_csgpiod(spi, 0) && (spi->mode & SPI_CS_HIGH) && !rs->cs_high_supported) {
721d5d933f0SLuca Ceresoli dev_warn(&spi->dev, "setup: non GPIO CS can't be active-high\n");
722d5d933f0SLuca Ceresoli return -EINVAL;
723d5d933f0SLuca Ceresoli }
724d5d933f0SLuca Ceresoli
7253a4bf922SJon Lin pm_runtime_get_sync(rs->dev);
7263a4bf922SJon Lin
7273a4bf922SJon Lin cr0 = readl_relaxed(rs->regs + ROCKCHIP_SPI_CTRLR0);
7283a4bf922SJon Lin
7293a4bf922SJon Lin cr0 &= ~(0x3 << CR0_SCPH_OFFSET);
7303a4bf922SJon Lin cr0 |= ((spi->mode & 0x3) << CR0_SCPH_OFFSET);
7319e264f3fSAmit Kumar Mahapatra via Alsa-devel if (spi->mode & SPI_CS_HIGH && spi_get_chipselect(spi, 0) <= 1)
7329e264f3fSAmit Kumar Mahapatra via Alsa-devel cr0 |= BIT(spi_get_chipselect(spi, 0)) << CR0_SOI_OFFSET;
7339e264f3fSAmit Kumar Mahapatra via Alsa-devel else if (spi_get_chipselect(spi, 0) <= 1)
7349e264f3fSAmit Kumar Mahapatra via Alsa-devel cr0 &= ~(BIT(spi_get_chipselect(spi, 0)) << CR0_SOI_OFFSET);
7353a4bf922SJon Lin
7363a4bf922SJon Lin writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
7373a4bf922SJon Lin
7383a4bf922SJon Lin pm_runtime_put(rs->dev);
7393a4bf922SJon Lin
7403a4bf922SJon Lin return 0;
7413a4bf922SJon Lin }
7423a4bf922SJon Lin
rockchip_spi_probe(struct platform_device * pdev)74364e36824Saddy ke static int rockchip_spi_probe(struct platform_device *pdev)
74464e36824Saddy ke {
74543de979dSJeffy Chen int ret;
74664e36824Saddy ke struct rockchip_spi *rs;
747d66571a2SChris Ruehl struct spi_controller *ctlr;
74864e36824Saddy ke struct resource *mem;
749d065f41aSChris Ruehl struct device_node *np = pdev->dev.of_node;
7509382df0aSJon Lin u32 rsd_nsecs, num_cs;
7511a3ccff3SYang Yingliang bool target_mode;
75264e36824Saddy ke
7531a3ccff3SYang Yingliang target_mode = of_property_read_bool(np, "spi-slave");
754d065f41aSChris Ruehl
7551a3ccff3SYang Yingliang if (target_mode)
7561a3ccff3SYang Yingliang ctlr = spi_alloc_target(&pdev->dev,
757d065f41aSChris Ruehl sizeof(struct rockchip_spi));
758d065f41aSChris Ruehl else
7591a3ccff3SYang Yingliang ctlr = spi_alloc_host(&pdev->dev,
760d065f41aSChris Ruehl sizeof(struct rockchip_spi));
761d065f41aSChris Ruehl
762d66571a2SChris Ruehl if (!ctlr)
76364e36824Saddy ke return -ENOMEM;
7645dcc44edSAddy Ke
765d66571a2SChris Ruehl platform_set_drvdata(pdev, ctlr);
76664e36824Saddy ke
767d66571a2SChris Ruehl rs = spi_controller_get_devdata(ctlr);
76864e36824Saddy ke
76964e36824Saddy ke /* Get basic io resource and map it */
770d447fa65SLizhe rs->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
77164e36824Saddy ke if (IS_ERR(rs->regs)) {
77264e36824Saddy ke ret = PTR_ERR(rs->regs);
773d66571a2SChris Ruehl goto err_put_ctlr;
77464e36824Saddy ke }
77564e36824Saddy ke
776d6c612a3SLi Zetao rs->apb_pclk = devm_clk_get_enabled(&pdev->dev, "apb_pclk");
77764e36824Saddy ke if (IS_ERR(rs->apb_pclk)) {
77864e36824Saddy ke dev_err(&pdev->dev, "Failed to get apb_pclk\n");
77964e36824Saddy ke ret = PTR_ERR(rs->apb_pclk);
780d66571a2SChris Ruehl goto err_put_ctlr;
78164e36824Saddy ke }
78264e36824Saddy ke
783d6c612a3SLi Zetao rs->spiclk = devm_clk_get_enabled(&pdev->dev, "spiclk");
78464e36824Saddy ke if (IS_ERR(rs->spiclk)) {
78564e36824Saddy ke dev_err(&pdev->dev, "Failed to get spi_pclk\n");
78664e36824Saddy ke ret = PTR_ERR(rs->spiclk);
787d66571a2SChris Ruehl goto err_put_ctlr;
78864e36824Saddy ke }
78964e36824Saddy ke
79030688e4eSEmil Renner Berthing spi_enable_chip(rs, false);
79164e36824Saddy ke
79201b59ce5SEmil Renner Berthing ret = platform_get_irq(pdev, 0);
79301b59ce5SEmil Renner Berthing if (ret < 0)
794d6c612a3SLi Zetao goto err_put_ctlr;
79501b59ce5SEmil Renner Berthing
79601b59ce5SEmil Renner Berthing ret = devm_request_threaded_irq(&pdev->dev, ret, rockchip_spi_isr, NULL,
797d66571a2SChris Ruehl IRQF_ONESHOT, dev_name(&pdev->dev), ctlr);
79801b59ce5SEmil Renner Berthing if (ret)
799d6c612a3SLi Zetao goto err_put_ctlr;
80001b59ce5SEmil Renner Berthing
80164e36824Saddy ke rs->dev = &pdev->dev;
802420b82f8SEmil Renner Berthing rs->freq = clk_get_rate(rs->spiclk);
80364e36824Saddy ke
80476b17e6eSJulius Werner if (!of_property_read_u32(pdev->dev.of_node, "rx-sample-delay-ns",
80574b7efa8SEmil Renner Berthing &rsd_nsecs)) {
80674b7efa8SEmil Renner Berthing /* rx sample delay is expressed in parent clock cycles (max 3) */
80774b7efa8SEmil Renner Berthing u32 rsd = DIV_ROUND_CLOSEST(rsd_nsecs * (rs->freq >> 8),
80874b7efa8SEmil Renner Berthing 1000000000 >> 8);
80974b7efa8SEmil Renner Berthing if (!rsd) {
81074b7efa8SEmil Renner Berthing dev_warn(rs->dev, "%u Hz are too slow to express %u ns delay\n",
81174b7efa8SEmil Renner Berthing rs->freq, rsd_nsecs);
81274b7efa8SEmil Renner Berthing } else if (rsd > CR0_RSD_MAX) {
81374b7efa8SEmil Renner Berthing rsd = CR0_RSD_MAX;
81474b7efa8SEmil Renner Berthing dev_warn(rs->dev, "%u Hz are too fast to express %u ns delay, clamping at %u ns\n",
81574b7efa8SEmil Renner Berthing rs->freq, rsd_nsecs,
81674b7efa8SEmil Renner Berthing CR0_RSD_MAX * 1000000000U / rs->freq);
81774b7efa8SEmil Renner Berthing }
81874b7efa8SEmil Renner Berthing rs->rsd = rsd;
81974b7efa8SEmil Renner Berthing }
82076b17e6eSJulius Werner
82164e36824Saddy ke rs->fifo_len = get_fifo_len(rs);
82264e36824Saddy ke if (!rs->fifo_len) {
82364e36824Saddy ke dev_err(&pdev->dev, "Failed to get fifo length\n");
824db7e8d90SWei Yongjun ret = -EINVAL;
825d6c612a3SLi Zetao goto err_put_ctlr;
82664e36824Saddy ke }
82764e36824Saddy ke
828940f3bbfSAlexander Kochetkov pm_runtime_set_autosuspend_delay(&pdev->dev, ROCKCHIP_AUTOSUSPEND_TIMEOUT);
829940f3bbfSAlexander Kochetkov pm_runtime_use_autosuspend(&pdev->dev);
83064e36824Saddy ke pm_runtime_set_active(&pdev->dev);
83164e36824Saddy ke pm_runtime_enable(&pdev->dev);
83264e36824Saddy ke
833d66571a2SChris Ruehl ctlr->auto_runtime_pm = true;
834d66571a2SChris Ruehl ctlr->bus_num = pdev->id;
835d66571a2SChris Ruehl ctlr->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP | SPI_LSB_FIRST;
8361a3ccff3SYang Yingliang if (target_mode) {
837d065f41aSChris Ruehl ctlr->mode_bits |= SPI_NO_CS;
8381a3ccff3SYang Yingliang ctlr->target_abort = rockchip_spi_target_abort;
839d065f41aSChris Ruehl } else {
84082238d2cSAndy Shevchenko ctlr->flags = SPI_CONTROLLER_GPIO_SS;
84107d67493SLuis de Arquer ctlr->max_native_cs = ROCKCHIP_SPI_MAX_NATIVE_CS_NUM;
842eb1262e3SChris Ruehl /*
843eb1262e3SChris Ruehl * rk spi0 has two native cs, spi1..5 one cs only
844eb1262e3SChris Ruehl * if num-cs is missing in the dts, default to 1
845eb1262e3SChris Ruehl */
8469382df0aSJon Lin if (of_property_read_u32(np, "num-cs", &num_cs))
8479382df0aSJon Lin num_cs = 1;
8489382df0aSJon Lin ctlr->num_chipselect = num_cs;
849eb1262e3SChris Ruehl ctlr->use_gpio_descriptors = true;
850d065f41aSChris Ruehl }
851d66571a2SChris Ruehl ctlr->dev.of_node = pdev->dev.of_node;
852d66571a2SChris Ruehl ctlr->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8) | SPI_BPW_MASK(4);
853d66571a2SChris Ruehl ctlr->min_speed_hz = rs->freq / BAUDR_SCKDV_MAX;
854d66571a2SChris Ruehl ctlr->max_speed_hz = min(rs->freq / BAUDR_SCKDV_MIN, MAX_SCLK_OUT);
85564e36824Saddy ke
8563a4bf922SJon Lin ctlr->setup = rockchip_spi_setup;
857d66571a2SChris Ruehl ctlr->set_cs = rockchip_spi_set_cs;
858d66571a2SChris Ruehl ctlr->transfer_one = rockchip_spi_transfer_one;
859d66571a2SChris Ruehl ctlr->max_transfer_size = rockchip_spi_max_transfer_size;
860d66571a2SChris Ruehl ctlr->handle_err = rockchip_spi_handle_err;
86164e36824Saddy ke
862d66571a2SChris Ruehl ctlr->dma_tx = dma_request_chan(rs->dev, "tx");
863d66571a2SChris Ruehl if (IS_ERR(ctlr->dma_tx)) {
86461cadcf4SShawn Lin /* Check tx to see if we need defer probing driver */
865d66571a2SChris Ruehl if (PTR_ERR(ctlr->dma_tx) == -EPROBE_DEFER) {
86661cadcf4SShawn Lin ret = -EPROBE_DEFER;
867c351587eSJeffy Chen goto err_disable_pm_runtime;
86861cadcf4SShawn Lin }
86964e36824Saddy ke dev_warn(rs->dev, "Failed to request TX DMA channel\n");
870d66571a2SChris Ruehl ctlr->dma_tx = NULL;
87164e36824Saddy ke }
872e4c0e06fSShawn Lin
873d66571a2SChris Ruehl ctlr->dma_rx = dma_request_chan(rs->dev, "rx");
874d66571a2SChris Ruehl if (IS_ERR(ctlr->dma_rx)) {
875d66571a2SChris Ruehl if (PTR_ERR(ctlr->dma_rx) == -EPROBE_DEFER) {
876e4c0e06fSShawn Lin ret = -EPROBE_DEFER;
8775de7ed0cSDan Carpenter goto err_free_dma_tx;
878e4c0e06fSShawn Lin }
87964e36824Saddy ke dev_warn(rs->dev, "Failed to request RX DMA channel\n");
880d66571a2SChris Ruehl ctlr->dma_rx = NULL;
88164e36824Saddy ke }
88264e36824Saddy ke
883d66571a2SChris Ruehl if (ctlr->dma_tx && ctlr->dma_rx) {
884eee06a9eSEmil Renner Berthing rs->dma_addr_tx = mem->start + ROCKCHIP_SPI_TXDR;
885eee06a9eSEmil Renner Berthing rs->dma_addr_rx = mem->start + ROCKCHIP_SPI_RXDR;
886d66571a2SChris Ruehl ctlr->can_dma = rockchip_spi_can_dma;
88764e36824Saddy ke }
88864e36824Saddy ke
889736b81e0SJon Lin switch (readl_relaxed(rs->regs + ROCKCHIP_SPI_VERSION)) {
890736b81e0SJon Lin case ROCKCHIP_SPI_VER2_TYPE2:
891d5d933f0SLuca Ceresoli rs->cs_high_supported = true;
892736b81e0SJon Lin ctlr->mode_bits |= SPI_CS_HIGH;
8931a3ccff3SYang Yingliang if (ctlr->can_dma && target_mode)
894869f2c94SJon Lin rs->cs_inactive = true;
895869f2c94SJon Lin else
896869f2c94SJon Lin rs->cs_inactive = false;
897736b81e0SJon Lin break;
898736b81e0SJon Lin default:
899869f2c94SJon Lin rs->cs_inactive = false;
900736b81e0SJon Lin break;
901736b81e0SJon Lin }
902736b81e0SJon Lin
903d66571a2SChris Ruehl ret = devm_spi_register_controller(&pdev->dev, ctlr);
90443de979dSJeffy Chen if (ret < 0) {
905d66571a2SChris Ruehl dev_err(&pdev->dev, "Failed to register controller\n");
906c351587eSJeffy Chen goto err_free_dma_rx;
90764e36824Saddy ke }
90864e36824Saddy ke
90964e36824Saddy ke return 0;
91064e36824Saddy ke
911c351587eSJeffy Chen err_free_dma_rx:
912d66571a2SChris Ruehl if (ctlr->dma_rx)
913d66571a2SChris Ruehl dma_release_channel(ctlr->dma_rx);
9145de7ed0cSDan Carpenter err_free_dma_tx:
915d66571a2SChris Ruehl if (ctlr->dma_tx)
916d66571a2SChris Ruehl dma_release_channel(ctlr->dma_tx);
917c351587eSJeffy Chen err_disable_pm_runtime:
918c351587eSJeffy Chen pm_runtime_disable(&pdev->dev);
919d66571a2SChris Ruehl err_put_ctlr:
920d66571a2SChris Ruehl spi_controller_put(ctlr);
92164e36824Saddy ke
92264e36824Saddy ke return ret;
92364e36824Saddy ke }
92464e36824Saddy ke
rockchip_spi_remove(struct platform_device * pdev)9255ff5e676SUwe Kleine-König static void rockchip_spi_remove(struct platform_device *pdev)
92664e36824Saddy ke {
927d66571a2SChris Ruehl struct spi_controller *ctlr = spi_controller_get(platform_get_drvdata(pdev));
92864e36824Saddy ke
9296a06e895SJeffy Chen pm_runtime_get_sync(&pdev->dev);
93064e36824Saddy ke
9316a06e895SJeffy Chen pm_runtime_put_noidle(&pdev->dev);
9326a06e895SJeffy Chen pm_runtime_disable(&pdev->dev);
9336a06e895SJeffy Chen pm_runtime_set_suspended(&pdev->dev);
9346a06e895SJeffy Chen
935d66571a2SChris Ruehl if (ctlr->dma_tx)
936d66571a2SChris Ruehl dma_release_channel(ctlr->dma_tx);
937d66571a2SChris Ruehl if (ctlr->dma_rx)
938d66571a2SChris Ruehl dma_release_channel(ctlr->dma_rx);
93964e36824Saddy ke
940d66571a2SChris Ruehl spi_controller_put(ctlr);
94164e36824Saddy ke }
94264e36824Saddy ke
94364e36824Saddy ke #ifdef CONFIG_PM_SLEEP
rockchip_spi_suspend(struct device * dev)94464e36824Saddy ke static int rockchip_spi_suspend(struct device *dev)
94564e36824Saddy ke {
94643de979dSJeffy Chen int ret;
947d66571a2SChris Ruehl struct spi_controller *ctlr = dev_get_drvdata(dev);
94864e36824Saddy ke
949d66571a2SChris Ruehl ret = spi_controller_suspend(ctlr);
95043de979dSJeffy Chen if (ret < 0)
95164e36824Saddy ke return ret;
95264e36824Saddy ke
953*be721b45SBrian Norris ret = pm_runtime_force_suspend(dev);
954*be721b45SBrian Norris if (ret < 0) {
955*be721b45SBrian Norris spi_controller_resume(ctlr);
956*be721b45SBrian Norris return ret;
957*be721b45SBrian Norris }
95864e36824Saddy ke
95923e291c2SBrian Norris pinctrl_pm_select_sleep_state(dev);
96023e291c2SBrian Norris
96143de979dSJeffy Chen return 0;
96264e36824Saddy ke }
96364e36824Saddy ke
rockchip_spi_resume(struct device * dev)96464e36824Saddy ke static int rockchip_spi_resume(struct device *dev)
96564e36824Saddy ke {
96643de979dSJeffy Chen int ret;
967d66571a2SChris Ruehl struct spi_controller *ctlr = dev_get_drvdata(dev);
96864e36824Saddy ke
96923e291c2SBrian Norris pinctrl_pm_select_default_state(dev);
97023e291c2SBrian Norris
971*be721b45SBrian Norris ret = pm_runtime_force_resume(dev);
97264e36824Saddy ke if (ret < 0)
97364e36824Saddy ke return ret;
97464e36824Saddy ke
975*be721b45SBrian Norris return spi_controller_resume(ctlr);
97664e36824Saddy ke }
97764e36824Saddy ke #endif /* CONFIG_PM_SLEEP */
97864e36824Saddy ke
979ec833050SRafael J. Wysocki #ifdef CONFIG_PM
rockchip_spi_runtime_suspend(struct device * dev)98064e36824Saddy ke static int rockchip_spi_runtime_suspend(struct device *dev)
98164e36824Saddy ke {
982d66571a2SChris Ruehl struct spi_controller *ctlr = dev_get_drvdata(dev);
983d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
98464e36824Saddy ke
98564e36824Saddy ke clk_disable_unprepare(rs->spiclk);
98664e36824Saddy ke clk_disable_unprepare(rs->apb_pclk);
98764e36824Saddy ke
98864e36824Saddy ke return 0;
98964e36824Saddy ke }
99064e36824Saddy ke
rockchip_spi_runtime_resume(struct device * dev)99164e36824Saddy ke static int rockchip_spi_runtime_resume(struct device *dev)
99264e36824Saddy ke {
99364e36824Saddy ke int ret;
994d66571a2SChris Ruehl struct spi_controller *ctlr = dev_get_drvdata(dev);
995d66571a2SChris Ruehl struct rockchip_spi *rs = spi_controller_get_devdata(ctlr);
99664e36824Saddy ke
99764e36824Saddy ke ret = clk_prepare_enable(rs->apb_pclk);
99843de979dSJeffy Chen if (ret < 0)
99964e36824Saddy ke return ret;
100064e36824Saddy ke
100164e36824Saddy ke ret = clk_prepare_enable(rs->spiclk);
100243de979dSJeffy Chen if (ret < 0)
100364e36824Saddy ke clk_disable_unprepare(rs->apb_pclk);
100464e36824Saddy ke
100543de979dSJeffy Chen return 0;
100664e36824Saddy ke }
1007ec833050SRafael J. Wysocki #endif /* CONFIG_PM */
100864e36824Saddy ke
100964e36824Saddy ke static const struct dev_pm_ops rockchip_spi_pm = {
1010e882575eSshengfei Xu SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(rockchip_spi_suspend, rockchip_spi_resume)
101164e36824Saddy ke SET_RUNTIME_PM_OPS(rockchip_spi_runtime_suspend,
101264e36824Saddy ke rockchip_spi_runtime_resume, NULL)
101364e36824Saddy ke };
101464e36824Saddy ke
101564e36824Saddy ke static const struct of_device_id rockchip_spi_dt_match[] = {
1016c6486eadSJohan Jonker { .compatible = "rockchip,px30-spi", },
1017aa29ea3dSCaesar Wang { .compatible = "rockchip,rk3036-spi", },
101864e36824Saddy ke { .compatible = "rockchip,rk3066-spi", },
1019b839b785SAddy Ke { .compatible = "rockchip,rk3188-spi", },
1020aa29ea3dSCaesar Wang { .compatible = "rockchip,rk3228-spi", },
1021b839b785SAddy Ke { .compatible = "rockchip,rk3288-spi", },
1022c6486eadSJohan Jonker { .compatible = "rockchip,rk3308-spi", },
1023c6486eadSJohan Jonker { .compatible = "rockchip,rk3328-spi", },
1024aa29ea3dSCaesar Wang { .compatible = "rockchip,rk3368-spi", },
10259b7a5622SXu Jianqun { .compatible = "rockchip,rk3399-spi", },
1026c6486eadSJohan Jonker { .compatible = "rockchip,rv1108-spi", },
10270f4f58b8SJon Lin { .compatible = "rockchip,rv1126-spi", },
102864e36824Saddy ke { },
102964e36824Saddy ke };
103064e36824Saddy ke MODULE_DEVICE_TABLE(of, rockchip_spi_dt_match);
103164e36824Saddy ke
103264e36824Saddy ke static struct platform_driver rockchip_spi_driver = {
103364e36824Saddy ke .driver = {
103464e36824Saddy ke .name = DRIVER_NAME,
103564e36824Saddy ke .pm = &rockchip_spi_pm,
103664e36824Saddy ke .of_match_table = of_match_ptr(rockchip_spi_dt_match),
103764e36824Saddy ke },
103864e36824Saddy ke .probe = rockchip_spi_probe,
10395ff5e676SUwe Kleine-König .remove_new = rockchip_spi_remove,
104064e36824Saddy ke };
104164e36824Saddy ke
104264e36824Saddy ke module_platform_driver(rockchip_spi_driver);
104364e36824Saddy ke
10445dcc44edSAddy Ke MODULE_AUTHOR("Addy Ke <addy.ke@rock-chips.com>");
104564e36824Saddy ke MODULE_DESCRIPTION("ROCKCHIP SPI Controller Driver");
104664e36824Saddy ke MODULE_LICENSE("GPL v2");
1047