blob: 1c813797f96375893f33ae462b3b23cada10eea4 [file] [log] [blame]
addy ke64e36822014-07-01 09:03:59 +08001/*
2 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
Addy Ke5dcc44e2014-07-11 10:07:56 +08003 * Author: Addy Ke <addy.ke@rock-chips.com>
addy ke64e36822014-07-01 09:03:59 +08004 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 */
15
addy ke64e36822014-07-01 09:03:59 +080016#include <linux/clk.h>
addy ke64e36822014-07-01 09:03:59 +080017#include <linux/dmaengine.h>
Shawn Linec5c5d82016-03-10 14:51:48 +080018#include <linux/module.h>
19#include <linux/of.h>
Brian Norris23e291c2016-12-16 16:59:16 -080020#include <linux/pinctrl/consumer.h>
Shawn Linec5c5d82016-03-10 14:51:48 +080021#include <linux/platform_device.h>
22#include <linux/spi/spi.h>
23#include <linux/pm_runtime.h>
24#include <linux/scatterlist.h>
addy ke64e36822014-07-01 09:03:59 +080025
26#define DRIVER_NAME "rockchip-spi"
27
Jeffy Chenaa099382017-06-28 12:38:43 +080028#define ROCKCHIP_SPI_CLR_BITS(reg, bits) \
29 writel_relaxed(readl_relaxed(reg) & ~(bits), reg)
30#define ROCKCHIP_SPI_SET_BITS(reg, bits) \
31 writel_relaxed(readl_relaxed(reg) | (bits), reg)
32
addy ke64e36822014-07-01 09:03:59 +080033/* SPI register offsets */
34#define ROCKCHIP_SPI_CTRLR0 0x0000
35#define ROCKCHIP_SPI_CTRLR1 0x0004
36#define ROCKCHIP_SPI_SSIENR 0x0008
37#define ROCKCHIP_SPI_SER 0x000c
38#define ROCKCHIP_SPI_BAUDR 0x0010
39#define ROCKCHIP_SPI_TXFTLR 0x0014
40#define ROCKCHIP_SPI_RXFTLR 0x0018
41#define ROCKCHIP_SPI_TXFLR 0x001c
42#define ROCKCHIP_SPI_RXFLR 0x0020
43#define ROCKCHIP_SPI_SR 0x0024
44#define ROCKCHIP_SPI_IPR 0x0028
45#define ROCKCHIP_SPI_IMR 0x002c
46#define ROCKCHIP_SPI_ISR 0x0030
47#define ROCKCHIP_SPI_RISR 0x0034
48#define ROCKCHIP_SPI_ICR 0x0038
49#define ROCKCHIP_SPI_DMACR 0x003c
50#define ROCKCHIP_SPI_DMATDLR 0x0040
51#define ROCKCHIP_SPI_DMARDLR 0x0044
52#define ROCKCHIP_SPI_TXDR 0x0400
53#define ROCKCHIP_SPI_RXDR 0x0800
54
55/* Bit fields in CTRLR0 */
56#define CR0_DFS_OFFSET 0
57
58#define CR0_CFS_OFFSET 2
59
60#define CR0_SCPH_OFFSET 6
61
62#define CR0_SCPOL_OFFSET 7
63
64#define CR0_CSM_OFFSET 8
65#define CR0_CSM_KEEP 0x0
66/* ss_n be high for half sclk_out cycles */
67#define CR0_CSM_HALF 0X1
68/* ss_n be high for one sclk_out cycle */
69#define CR0_CSM_ONE 0x2
70
71/* ss_n to sclk_out delay */
72#define CR0_SSD_OFFSET 10
73/*
74 * The period between ss_n active and
75 * sclk_out active is half sclk_out cycles
76 */
77#define CR0_SSD_HALF 0x0
78/*
79 * The period between ss_n active and
80 * sclk_out active is one sclk_out cycle
81 */
82#define CR0_SSD_ONE 0x1
83
84#define CR0_EM_OFFSET 11
85#define CR0_EM_LITTLE 0x0
86#define CR0_EM_BIG 0x1
87
88#define CR0_FBM_OFFSET 12
89#define CR0_FBM_MSB 0x0
90#define CR0_FBM_LSB 0x1
91
92#define CR0_BHT_OFFSET 13
93#define CR0_BHT_16BIT 0x0
94#define CR0_BHT_8BIT 0x1
95
96#define CR0_RSD_OFFSET 14
97
98#define CR0_FRF_OFFSET 16
99#define CR0_FRF_SPI 0x0
100#define CR0_FRF_SSP 0x1
101#define CR0_FRF_MICROWIRE 0x2
102
103#define CR0_XFM_OFFSET 18
104#define CR0_XFM_MASK (0x03 << SPI_XFM_OFFSET)
105#define CR0_XFM_TR 0x0
106#define CR0_XFM_TO 0x1
107#define CR0_XFM_RO 0x2
108
109#define CR0_OPM_OFFSET 20
110#define CR0_OPM_MASTER 0x0
111#define CR0_OPM_SLAVE 0x1
112
113#define CR0_MTM_OFFSET 0x21
114
115/* Bit fields in SER, 2bit */
116#define SER_MASK 0x3
117
118/* Bit fields in SR, 5bit */
119#define SR_MASK 0x1f
120#define SR_BUSY (1 << 0)
121#define SR_TF_FULL (1 << 1)
122#define SR_TF_EMPTY (1 << 2)
123#define SR_RF_EMPTY (1 << 3)
124#define SR_RF_FULL (1 << 4)
125
126/* Bit fields in ISR, IMR, ISR, RISR, 5bit */
127#define INT_MASK 0x1f
128#define INT_TF_EMPTY (1 << 0)
129#define INT_TF_OVERFLOW (1 << 1)
130#define INT_RF_UNDERFLOW (1 << 2)
131#define INT_RF_OVERFLOW (1 << 3)
132#define INT_RF_FULL (1 << 4)
133
134/* Bit fields in ICR, 4bit */
135#define ICR_MASK 0x0f
136#define ICR_ALL (1 << 0)
137#define ICR_RF_UNDERFLOW (1 << 1)
138#define ICR_RF_OVERFLOW (1 << 2)
139#define ICR_TF_OVERFLOW (1 << 3)
140
141/* Bit fields in DMACR */
142#define RF_DMA_EN (1 << 0)
143#define TF_DMA_EN (1 << 1)
144
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100145/* Driver state flags */
146#define RXDMA (1 << 0)
147#define TXDMA (1 << 1)
addy ke64e36822014-07-01 09:03:59 +0800148
Addy Kef9cfd522014-10-15 19:25:49 +0800149/* sclk_out: spi master internal logic in rk3x can support 50Mhz */
150#define MAX_SCLK_OUT 50000000
151
Brian Norris5185a812016-07-14 18:30:59 -0700152/*
153 * SPI_CTRLR1 is 16-bits, so we should support lengths of 0xffff + 1. However,
154 * the controller seems to hang when given 0x10000, so stick with this for now.
155 */
156#define ROCKCHIP_SPI_MAX_TRANLEN 0xffff
157
Jeffy Chenaa099382017-06-28 12:38:43 +0800158#define ROCKCHIP_SPI_MAX_CS_NUM 2
159
addy ke64e36822014-07-01 09:03:59 +0800160struct rockchip_spi_dma_data {
161 struct dma_chan *ch;
addy ke64e36822014-07-01 09:03:59 +0800162 dma_addr_t addr;
163};
164
165struct rockchip_spi {
166 struct device *dev;
167 struct spi_master *master;
168
169 struct clk *spiclk;
170 struct clk *apb_pclk;
171
172 void __iomem *regs;
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100173
174 atomic_t state;
175
addy ke64e36822014-07-01 09:03:59 +0800176 /*depth of the FIFO buffer */
177 u32 fifo_len;
178 /* max bus freq supported */
179 u32 max_freq;
addy ke64e36822014-07-01 09:03:59 +0800180
181 u16 mode;
182 u8 tmode;
183 u8 bpw;
184 u8 n_bytes;
Shawn Lin108b5c82016-03-10 14:52:27 +0800185 u32 rsd_nsecs;
addy ke64e36822014-07-01 09:03:59 +0800186 unsigned len;
187 u32 speed;
188
189 const void *tx;
190 const void *tx_end;
191 void *rx;
192 void *rx_end;
193
Jeffy Chenaa099382017-06-28 12:38:43 +0800194 bool cs_asserted[ROCKCHIP_SPI_MAX_CS_NUM];
195
Emil Renner Berthingf340b922018-10-10 11:00:36 +0200196 bool use_dma;
addy ke64e36822014-07-01 09:03:59 +0800197 struct sg_table tx_sg;
198 struct sg_table rx_sg;
199 struct rockchip_spi_dma_data dma_rx;
200 struct rockchip_spi_dma_data dma_tx;
201};
202
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100203static inline void spi_enable_chip(struct rockchip_spi *rs, bool enable)
addy ke64e36822014-07-01 09:03:59 +0800204{
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100205 writel_relaxed((enable ? 1U : 0U), rs->regs + ROCKCHIP_SPI_SSIENR);
addy ke64e36822014-07-01 09:03:59 +0800206}
207
208static inline void spi_set_clk(struct rockchip_spi *rs, u16 div)
209{
210 writel_relaxed(div, rs->regs + ROCKCHIP_SPI_BAUDR);
211}
212
213static inline void flush_fifo(struct rockchip_spi *rs)
214{
215 while (readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR))
216 readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
217}
218
Addy Ke2df08e72014-07-11 10:08:24 +0800219static inline void wait_for_idle(struct rockchip_spi *rs)
220{
221 unsigned long timeout = jiffies + msecs_to_jiffies(5);
222
223 do {
224 if (!(readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY))
225 return;
Doug Anderson64bc0112014-09-03 13:44:25 -0700226 } while (!time_after(jiffies, timeout));
Addy Ke2df08e72014-07-11 10:08:24 +0800227
228 dev_warn(rs->dev, "spi controller is in busy state!\n");
229}
230
addy ke64e36822014-07-01 09:03:59 +0800231static u32 get_fifo_len(struct rockchip_spi *rs)
232{
233 u32 fifo;
234
235 for (fifo = 2; fifo < 32; fifo++) {
236 writel_relaxed(fifo, rs->regs + ROCKCHIP_SPI_TXFTLR);
237 if (fifo != readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFTLR))
238 break;
239 }
240
241 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_TXFTLR);
242
243 return (fifo == 31) ? 0 : fifo;
244}
245
246static inline u32 tx_max(struct rockchip_spi *rs)
247{
248 u32 tx_left, tx_room;
249
250 tx_left = (rs->tx_end - rs->tx) / rs->n_bytes;
251 tx_room = rs->fifo_len - readl_relaxed(rs->regs + ROCKCHIP_SPI_TXFLR);
252
253 return min(tx_left, tx_room);
254}
255
256static inline u32 rx_max(struct rockchip_spi *rs)
257{
258 u32 rx_left = (rs->rx_end - rs->rx) / rs->n_bytes;
259 u32 rx_room = (u32)readl_relaxed(rs->regs + ROCKCHIP_SPI_RXFLR);
260
261 return min(rx_left, rx_room);
262}
263
264static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
265{
Huibin Hongb920cc32016-02-24 18:00:04 +0800266 struct spi_master *master = spi->master;
267 struct rockchip_spi *rs = spi_master_get_devdata(master);
Jeffy Chenaa099382017-06-28 12:38:43 +0800268 bool cs_asserted = !enable;
Huibin Hongb920cc32016-02-24 18:00:04 +0800269
Jeffy Chenaa099382017-06-28 12:38:43 +0800270 /* Return immediately for no-op */
271 if (cs_asserted == rs->cs_asserted[spi->chip_select])
272 return;
addy ke64e36822014-07-01 09:03:59 +0800273
Jeffy Chenaa099382017-06-28 12:38:43 +0800274 if (cs_asserted) {
275 /* Keep things powered as long as CS is asserted */
276 pm_runtime_get_sync(rs->dev);
addy ke64e36822014-07-01 09:03:59 +0800277
Jeffy Chenaa099382017-06-28 12:38:43 +0800278 ROCKCHIP_SPI_SET_BITS(rs->regs + ROCKCHIP_SPI_SER,
279 BIT(spi->chip_select));
280 } else {
281 ROCKCHIP_SPI_CLR_BITS(rs->regs + ROCKCHIP_SPI_SER,
282 BIT(spi->chip_select));
addy ke64e36822014-07-01 09:03:59 +0800283
Jeffy Chenaa099382017-06-28 12:38:43 +0800284 /* Drop reference from when we first asserted CS */
285 pm_runtime_put(rs->dev);
286 }
Huibin Hongb920cc32016-02-24 18:00:04 +0800287
Jeffy Chenaa099382017-06-28 12:38:43 +0800288 rs->cs_asserted[spi->chip_select] = cs_asserted;
addy ke64e36822014-07-01 09:03:59 +0800289}
290
291static int rockchip_spi_prepare_message(struct spi_master *master,
Addy Ke5dcc44e2014-07-11 10:07:56 +0800292 struct spi_message *msg)
addy ke64e36822014-07-01 09:03:59 +0800293{
294 struct rockchip_spi *rs = spi_master_get_devdata(master);
295 struct spi_device *spi = msg->spi;
296
addy ke64e36822014-07-01 09:03:59 +0800297 rs->mode = spi->mode;
298
299 return 0;
300}
301
Andy Shevchenko22917932015-02-27 17:34:16 +0200302static void rockchip_spi_handle_err(struct spi_master *master,
303 struct spi_message *msg)
addy ke64e36822014-07-01 09:03:59 +0800304{
addy ke64e36822014-07-01 09:03:59 +0800305 struct rockchip_spi *rs = spi_master_get_devdata(master);
306
Addy Ke5dcc44e2014-07-11 10:07:56 +0800307 /*
308 * For DMA mode, we need terminate DMA channel and flush
309 * fifo for the next transfer if DMA thansfer timeout.
Andy Shevchenko22917932015-02-27 17:34:16 +0200310 * handle_err() was called by core if transfer failed.
311 * Maybe it is reasonable for error handling here.
Addy Ke5dcc44e2014-07-11 10:07:56 +0800312 */
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100313 if (atomic_read(&rs->state) & TXDMA)
314 dmaengine_terminate_async(rs->dma_tx.ch);
addy ke64e36822014-07-01 09:03:59 +0800315
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100316 if (atomic_read(&rs->state) & RXDMA) {
317 dmaengine_terminate_async(rs->dma_rx.ch);
318 flush_fifo(rs);
addy ke64e36822014-07-01 09:03:59 +0800319 }
Andy Shevchenko22917932015-02-27 17:34:16 +0200320}
321
322static int rockchip_spi_unprepare_message(struct spi_master *master,
323 struct spi_message *msg)
324{
325 struct rockchip_spi *rs = spi_master_get_devdata(master);
addy ke64e36822014-07-01 09:03:59 +0800326
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100327 spi_enable_chip(rs, false);
Addy Kec28be312014-10-15 19:26:18 +0800328
addy ke64e36822014-07-01 09:03:59 +0800329 return 0;
330}
331
332static void rockchip_spi_pio_writer(struct rockchip_spi *rs)
333{
334 u32 max = tx_max(rs);
335 u32 txw = 0;
336
337 while (max--) {
338 if (rs->n_bytes == 1)
339 txw = *(u8 *)(rs->tx);
340 else
341 txw = *(u16 *)(rs->tx);
342
343 writel_relaxed(txw, rs->regs + ROCKCHIP_SPI_TXDR);
344 rs->tx += rs->n_bytes;
345 }
346}
347
348static void rockchip_spi_pio_reader(struct rockchip_spi *rs)
349{
350 u32 max = rx_max(rs);
351 u32 rxw;
352
353 while (max--) {
354 rxw = readl_relaxed(rs->regs + ROCKCHIP_SPI_RXDR);
355 if (rs->n_bytes == 1)
356 *(u8 *)(rs->rx) = (u8)rxw;
357 else
358 *(u16 *)(rs->rx) = (u16)rxw;
359 rs->rx += rs->n_bytes;
Addy Ke5dcc44e2014-07-11 10:07:56 +0800360 }
addy ke64e36822014-07-01 09:03:59 +0800361}
362
363static int rockchip_spi_pio_transfer(struct rockchip_spi *rs)
364{
365 int remain = 0;
366
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100367 spi_enable_chip(rs, true);
Emil Renner Berthinga3c17402018-10-10 11:00:38 +0200368
addy ke64e36822014-07-01 09:03:59 +0800369 do {
370 if (rs->tx) {
371 remain = rs->tx_end - rs->tx;
372 rockchip_spi_pio_writer(rs);
373 }
374
375 if (rs->rx) {
376 remain = rs->rx_end - rs->rx;
377 rockchip_spi_pio_reader(rs);
378 }
379
380 cpu_relax();
381 } while (remain);
382
Addy Ke2df08e72014-07-11 10:08:24 +0800383 /* If tx, wait until the FIFO data completely. */
384 if (rs->tx)
385 wait_for_idle(rs);
386
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100387 spi_enable_chip(rs, false);
Addy Kec28be312014-10-15 19:26:18 +0800388
addy ke64e36822014-07-01 09:03:59 +0800389 return 0;
390}
391
392static void rockchip_spi_dma_rxcb(void *data)
393{
addy ke64e36822014-07-01 09:03:59 +0800394 struct rockchip_spi *rs = data;
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100395 int state = atomic_fetch_andnot(RXDMA, &rs->state);
addy ke64e36822014-07-01 09:03:59 +0800396
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100397 if (state & TXDMA)
398 return;
addy ke64e36822014-07-01 09:03:59 +0800399
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100400 spi_enable_chip(rs, false);
401 spi_finalize_current_transfer(rs->master);
addy ke64e36822014-07-01 09:03:59 +0800402}
403
404static void rockchip_spi_dma_txcb(void *data)
405{
addy ke64e36822014-07-01 09:03:59 +0800406 struct rockchip_spi *rs = data;
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100407 int state = atomic_fetch_andnot(TXDMA, &rs->state);
408
409 if (state & RXDMA)
410 return;
addy ke64e36822014-07-01 09:03:59 +0800411
Addy Ke2df08e72014-07-11 10:08:24 +0800412 /* Wait until the FIFO data completely. */
413 wait_for_idle(rs);
414
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100415 spi_enable_chip(rs, false);
416 spi_finalize_current_transfer(rs->master);
addy ke64e36822014-07-01 09:03:59 +0800417}
418
Shawn Linea984912016-03-09 16:11:15 +0800419static int rockchip_spi_prepare_dma(struct rockchip_spi *rs)
addy ke64e36822014-07-01 09:03:59 +0800420{
addy ke64e36822014-07-01 09:03:59 +0800421 struct dma_async_tx_descriptor *rxdesc, *txdesc;
422
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100423 atomic_set(&rs->state, 0);
addy ke64e36822014-07-01 09:03:59 +0800424
Arnd Bergmann97cf5662015-01-28 14:25:10 +0100425 rxdesc = NULL;
addy ke64e36822014-07-01 09:03:59 +0800426 if (rs->rx) {
Emil Renner Berthing31bcb572018-10-31 11:56:59 +0100427 struct dma_slave_config rxconf = {
428 .direction = DMA_DEV_TO_MEM,
429 .src_addr = rs->dma_rx.addr,
430 .src_addr_width = rs->n_bytes,
431 .src_maxburst = 1,
432 };
433
addy ke64e36822014-07-01 09:03:59 +0800434 dmaengine_slave_config(rs->dma_rx.ch, &rxconf);
435
Addy Ke5dcc44e2014-07-11 10:07:56 +0800436 rxdesc = dmaengine_prep_slave_sg(
437 rs->dma_rx.ch,
addy ke64e36822014-07-01 09:03:59 +0800438 rs->rx_sg.sgl, rs->rx_sg.nents,
Emil Renner Berthingd9071b72018-10-10 11:00:37 +0200439 DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
Shawn Linea984912016-03-09 16:11:15 +0800440 if (!rxdesc)
441 return -EINVAL;
addy ke64e36822014-07-01 09:03:59 +0800442
443 rxdesc->callback = rockchip_spi_dma_rxcb;
444 rxdesc->callback_param = rs;
445 }
446
Arnd Bergmann97cf5662015-01-28 14:25:10 +0100447 txdesc = NULL;
addy ke64e36822014-07-01 09:03:59 +0800448 if (rs->tx) {
Emil Renner Berthing31bcb572018-10-31 11:56:59 +0100449 struct dma_slave_config txconf = {
450 .direction = DMA_MEM_TO_DEV,
451 .dst_addr = rs->dma_tx.addr,
452 .dst_addr_width = rs->n_bytes,
453 .dst_maxburst = rs->fifo_len / 2,
454 };
455
addy ke64e36822014-07-01 09:03:59 +0800456 dmaengine_slave_config(rs->dma_tx.ch, &txconf);
457
Addy Ke5dcc44e2014-07-11 10:07:56 +0800458 txdesc = dmaengine_prep_slave_sg(
459 rs->dma_tx.ch,
addy ke64e36822014-07-01 09:03:59 +0800460 rs->tx_sg.sgl, rs->tx_sg.nents,
Emil Renner Berthingd9071b72018-10-10 11:00:37 +0200461 DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
Shawn Linea984912016-03-09 16:11:15 +0800462 if (!txdesc) {
463 if (rxdesc)
464 dmaengine_terminate_sync(rs->dma_rx.ch);
465 return -EINVAL;
466 }
addy ke64e36822014-07-01 09:03:59 +0800467
468 txdesc->callback = rockchip_spi_dma_txcb;
469 txdesc->callback_param = rs;
470 }
471
472 /* rx must be started before tx due to spi instinct */
Arnd Bergmann97cf5662015-01-28 14:25:10 +0100473 if (rxdesc) {
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100474 atomic_or(RXDMA, &rs->state);
addy ke64e36822014-07-01 09:03:59 +0800475 dmaengine_submit(rxdesc);
476 dma_async_issue_pending(rs->dma_rx.ch);
477 }
478
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100479 spi_enable_chip(rs, true);
Emil Renner Berthinga3c17402018-10-10 11:00:38 +0200480
Arnd Bergmann97cf5662015-01-28 14:25:10 +0100481 if (txdesc) {
Emil Renner Berthingfab3e482018-10-31 11:57:01 +0100482 atomic_or(TXDMA, &rs->state);
addy ke64e36822014-07-01 09:03:59 +0800483 dmaengine_submit(txdesc);
484 dma_async_issue_pending(rs->dma_tx.ch);
485 }
Shawn Linea984912016-03-09 16:11:15 +0800486
Emil Renner Berthinga3c17402018-10-10 11:00:38 +0200487 /* 1 means the transfer is in progress */
488 return 1;
addy ke64e36822014-07-01 09:03:59 +0800489}
490
491static void rockchip_spi_config(struct rockchip_spi *rs)
492{
493 u32 div = 0;
494 u32 dmacr = 0;
Julius Werner76b17e62015-03-26 16:30:25 -0700495 int rsd = 0;
addy ke64e36822014-07-01 09:03:59 +0800496
Emil Renner Berthing2410d6a2018-10-31 11:57:00 +0100497 u32 cr0 = CR0_FRF_SPI << CR0_FRF_OFFSET
498 | CR0_BHT_8BIT << CR0_BHT_OFFSET
499 | CR0_SSD_ONE << CR0_SSD_OFFSET
500 | CR0_EM_BIG << CR0_EM_OFFSET;
addy ke64e36822014-07-01 09:03:59 +0800501
502 cr0 |= (rs->n_bytes << CR0_DFS_OFFSET);
503 cr0 |= ((rs->mode & 0x3) << CR0_SCPH_OFFSET);
504 cr0 |= (rs->tmode << CR0_XFM_OFFSET);
addy ke64e36822014-07-01 09:03:59 +0800505
506 if (rs->use_dma) {
507 if (rs->tx)
508 dmacr |= TF_DMA_EN;
509 if (rs->rx)
510 dmacr |= RF_DMA_EN;
511 }
512
Addy Kef9cfd522014-10-15 19:25:49 +0800513 if (WARN_ON(rs->speed > MAX_SCLK_OUT))
514 rs->speed = MAX_SCLK_OUT;
515
Geert Uytterhoevenbb515372016-03-14 16:30:16 +0100516 /* the minimum divisor is 2 */
Addy Kef9cfd522014-10-15 19:25:49 +0800517 if (rs->max_freq < 2 * rs->speed) {
518 clk_set_rate(rs->spiclk, 2 * rs->speed);
519 rs->max_freq = clk_get_rate(rs->spiclk);
520 }
521
addy ke64e36822014-07-01 09:03:59 +0800522 /* div doesn't support odd number */
Julius Werner754ec432015-03-26 16:30:24 -0700523 div = DIV_ROUND_UP(rs->max_freq, rs->speed);
addy ke64e36822014-07-01 09:03:59 +0800524 div = (div + 1) & 0xfffe;
525
Julius Werner76b17e62015-03-26 16:30:25 -0700526 /* Rx sample delay is expressed in parent clock cycles (max 3) */
527 rsd = DIV_ROUND_CLOSEST(rs->rsd_nsecs * (rs->max_freq >> 8),
528 1000000000 >> 8);
529 if (!rsd && rs->rsd_nsecs) {
530 pr_warn_once("rockchip-spi: %u Hz are too slow to express %u ns delay\n",
531 rs->max_freq, rs->rsd_nsecs);
532 } else if (rsd > 3) {
533 rsd = 3;
534 pr_warn_once("rockchip-spi: %u Hz are too fast to express %u ns delay, clamping at %u ns\n",
535 rs->max_freq, rs->rsd_nsecs,
536 rsd * 1000000000U / rs->max_freq);
537 }
538 cr0 |= rsd << CR0_RSD_OFFSET;
539
addy ke64e36822014-07-01 09:03:59 +0800540 writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0);
541
Huibin Hong04b37d22017-08-16 10:12:02 +0800542 if (rs->n_bytes == 1)
543 writel_relaxed(rs->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
544 else if (rs->n_bytes == 2)
545 writel_relaxed((rs->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
546 else
547 writel_relaxed((rs->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1);
548
addy ke64e36822014-07-01 09:03:59 +0800549 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_TXFTLR);
550 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR);
551
Huibin Hongdcfc8612018-10-10 11:00:33 +0200552 writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_DMATDLR);
addy ke64e36822014-07-01 09:03:59 +0800553 writel_relaxed(0, rs->regs + ROCKCHIP_SPI_DMARDLR);
554 writel_relaxed(dmacr, rs->regs + ROCKCHIP_SPI_DMACR);
555
556 spi_set_clk(rs, div);
557
Addy Ke5dcc44e2014-07-11 10:07:56 +0800558 dev_dbg(rs->dev, "cr0 0x%x, div %d\n", cr0, div);
addy ke64e36822014-07-01 09:03:59 +0800559}
560
Brian Norris5185a812016-07-14 18:30:59 -0700561static size_t rockchip_spi_max_transfer_size(struct spi_device *spi)
562{
563 return ROCKCHIP_SPI_MAX_TRANLEN;
564}
565
Addy Ke5dcc44e2014-07-11 10:07:56 +0800566static int rockchip_spi_transfer_one(
567 struct spi_master *master,
addy ke64e36822014-07-01 09:03:59 +0800568 struct spi_device *spi,
569 struct spi_transfer *xfer)
570{
addy ke64e36822014-07-01 09:03:59 +0800571 struct rockchip_spi *rs = spi_master_get_devdata(master);
572
Doug Anderson62946172014-09-03 13:44:26 -0700573 WARN_ON(readl_relaxed(rs->regs + ROCKCHIP_SPI_SSIENR) &&
574 (readl_relaxed(rs->regs + ROCKCHIP_SPI_SR) & SR_BUSY));
addy ke64e36822014-07-01 09:03:59 +0800575
576 if (!xfer->tx_buf && !xfer->rx_buf) {
577 dev_err(rs->dev, "No buffer for transfer\n");
578 return -EINVAL;
579 }
580
Brian Norris5185a812016-07-14 18:30:59 -0700581 if (xfer->len > ROCKCHIP_SPI_MAX_TRANLEN) {
582 dev_err(rs->dev, "Transfer is too long (%d)\n", xfer->len);
583 return -EINVAL;
584 }
585
addy ke64e36822014-07-01 09:03:59 +0800586 rs->speed = xfer->speed_hz;
587 rs->bpw = xfer->bits_per_word;
588 rs->n_bytes = rs->bpw >> 3;
589
590 rs->tx = xfer->tx_buf;
591 rs->tx_end = rs->tx + xfer->len;
592 rs->rx = xfer->rx_buf;
593 rs->rx_end = rs->rx + xfer->len;
594 rs->len = xfer->len;
595
596 rs->tx_sg = xfer->tx_sg;
597 rs->rx_sg = xfer->rx_sg;
598
addy ke64e36822014-07-01 09:03:59 +0800599 if (rs->tx && rs->rx)
600 rs->tmode = CR0_XFM_TR;
601 else if (rs->tx)
602 rs->tmode = CR0_XFM_TO;
603 else if (rs->rx)
604 rs->tmode = CR0_XFM_RO;
605
Addy Kea24e70c2014-09-25 14:59:41 +0800606 /* we need prepare dma before spi was enabled */
Addy Kec28be312014-10-15 19:26:18 +0800607 if (master->can_dma && master->can_dma(master, spi, xfer))
Emil Renner Berthingf340b922018-10-10 11:00:36 +0200608 rs->use_dma = true;
Addy Kec28be312014-10-15 19:26:18 +0800609 else
Emil Renner Berthingf340b922018-10-10 11:00:36 +0200610 rs->use_dma = false;
addy ke64e36822014-07-01 09:03:59 +0800611
612 rockchip_spi_config(rs);
613
Emil Renner Berthinga3c17402018-10-10 11:00:38 +0200614 if (rs->use_dma)
615 return rockchip_spi_prepare_dma(rs);
addy ke64e36822014-07-01 09:03:59 +0800616
Emil Renner Berthinga3c17402018-10-10 11:00:38 +0200617 return rockchip_spi_pio_transfer(rs);
addy ke64e36822014-07-01 09:03:59 +0800618}
619
620static bool rockchip_spi_can_dma(struct spi_master *master,
Addy Ke5dcc44e2014-07-11 10:07:56 +0800621 struct spi_device *spi,
622 struct spi_transfer *xfer)
addy ke64e36822014-07-01 09:03:59 +0800623{
624 struct rockchip_spi *rs = spi_master_get_devdata(master);
625
626 return (xfer->len > rs->fifo_len);
627}
628
629static int rockchip_spi_probe(struct platform_device *pdev)
630{
Jeffy Chen43de9792017-08-07 20:40:18 +0800631 int ret;
addy ke64e36822014-07-01 09:03:59 +0800632 struct rockchip_spi *rs;
633 struct spi_master *master;
634 struct resource *mem;
Julius Werner76b17e62015-03-26 16:30:25 -0700635 u32 rsd_nsecs;
addy ke64e36822014-07-01 09:03:59 +0800636
637 master = spi_alloc_master(&pdev->dev, sizeof(struct rockchip_spi));
Addy Ke5dcc44e2014-07-11 10:07:56 +0800638 if (!master)
addy ke64e36822014-07-01 09:03:59 +0800639 return -ENOMEM;
Addy Ke5dcc44e2014-07-11 10:07:56 +0800640
addy ke64e36822014-07-01 09:03:59 +0800641 platform_set_drvdata(pdev, master);
642
643 rs = spi_master_get_devdata(master);
addy ke64e36822014-07-01 09:03:59 +0800644
645 /* Get basic io resource and map it */
646 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 rs->regs = devm_ioremap_resource(&pdev->dev, mem);
648 if (IS_ERR(rs->regs)) {
addy ke64e36822014-07-01 09:03:59 +0800649 ret = PTR_ERR(rs->regs);
Jeffy Chenc3515872017-06-13 13:25:40 +0800650 goto err_put_master;
addy ke64e36822014-07-01 09:03:59 +0800651 }
652
653 rs->apb_pclk = devm_clk_get(&pdev->dev, "apb_pclk");
654 if (IS_ERR(rs->apb_pclk)) {
655 dev_err(&pdev->dev, "Failed to get apb_pclk\n");
656 ret = PTR_ERR(rs->apb_pclk);
Jeffy Chenc3515872017-06-13 13:25:40 +0800657 goto err_put_master;
addy ke64e36822014-07-01 09:03:59 +0800658 }
659
660 rs->spiclk = devm_clk_get(&pdev->dev, "spiclk");
661 if (IS_ERR(rs->spiclk)) {
662 dev_err(&pdev->dev, "Failed to get spi_pclk\n");
663 ret = PTR_ERR(rs->spiclk);
Jeffy Chenc3515872017-06-13 13:25:40 +0800664 goto err_put_master;
addy ke64e36822014-07-01 09:03:59 +0800665 }
666
667 ret = clk_prepare_enable(rs->apb_pclk);
Jeffy Chen43de9792017-08-07 20:40:18 +0800668 if (ret < 0) {
addy ke64e36822014-07-01 09:03:59 +0800669 dev_err(&pdev->dev, "Failed to enable apb_pclk\n");
Jeffy Chenc3515872017-06-13 13:25:40 +0800670 goto err_put_master;
addy ke64e36822014-07-01 09:03:59 +0800671 }
672
673 ret = clk_prepare_enable(rs->spiclk);
Jeffy Chen43de9792017-08-07 20:40:18 +0800674 if (ret < 0) {
addy ke64e36822014-07-01 09:03:59 +0800675 dev_err(&pdev->dev, "Failed to enable spi_clk\n");
Jeffy Chenc3515872017-06-13 13:25:40 +0800676 goto err_disable_apbclk;
addy ke64e36822014-07-01 09:03:59 +0800677 }
678
Emil Renner Berthing30688e42018-10-31 11:56:58 +0100679 spi_enable_chip(rs, false);
addy ke64e36822014-07-01 09:03:59 +0800680
addy ke64e36822014-07-01 09:03:59 +0800681 rs->master = master;
682 rs->dev = &pdev->dev;
683 rs->max_freq = clk_get_rate(rs->spiclk);
684
Julius Werner76b17e62015-03-26 16:30:25 -0700685 if (!of_property_read_u32(pdev->dev.of_node, "rx-sample-delay-ns",
686 &rsd_nsecs))
687 rs->rsd_nsecs = rsd_nsecs;
688
addy ke64e36822014-07-01 09:03:59 +0800689 rs->fifo_len = get_fifo_len(rs);
690 if (!rs->fifo_len) {
691 dev_err(&pdev->dev, "Failed to get fifo length\n");
Wei Yongjundb7e8d92014-07-20 22:02:04 +0800692 ret = -EINVAL;
Jeffy Chenc3515872017-06-13 13:25:40 +0800693 goto err_disable_spiclk;
addy ke64e36822014-07-01 09:03:59 +0800694 }
695
addy ke64e36822014-07-01 09:03:59 +0800696 pm_runtime_set_active(&pdev->dev);
697 pm_runtime_enable(&pdev->dev);
698
699 master->auto_runtime_pm = true;
700 master->bus_num = pdev->id;
Addy Keee780992014-07-11 10:08:51 +0800701 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
Jeffy Chenaa099382017-06-28 12:38:43 +0800702 master->num_chipselect = ROCKCHIP_SPI_MAX_CS_NUM;
addy ke64e36822014-07-01 09:03:59 +0800703 master->dev.of_node = pdev->dev.of_node;
704 master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8);
705
706 master->set_cs = rockchip_spi_set_cs;
707 master->prepare_message = rockchip_spi_prepare_message;
708 master->unprepare_message = rockchip_spi_unprepare_message;
709 master->transfer_one = rockchip_spi_transfer_one;
Brian Norris5185a812016-07-14 18:30:59 -0700710 master->max_transfer_size = rockchip_spi_max_transfer_size;
Andy Shevchenko22917932015-02-27 17:34:16 +0200711 master->handle_err = rockchip_spi_handle_err;
Jeffy Chenc8637952017-06-28 12:38:42 +0800712 master->flags = SPI_MASTER_GPIO_SS;
addy ke64e36822014-07-01 09:03:59 +0800713
Shawn Line4c0e062016-03-31 11:11:41 +0800714 rs->dma_tx.ch = dma_request_chan(rs->dev, "tx");
715 if (IS_ERR(rs->dma_tx.ch)) {
Shawn Lin61cadcf2016-03-09 16:11:32 +0800716 /* Check tx to see if we need defer probing driver */
717 if (PTR_ERR(rs->dma_tx.ch) == -EPROBE_DEFER) {
718 ret = -EPROBE_DEFER;
Jeffy Chenc3515872017-06-13 13:25:40 +0800719 goto err_disable_pm_runtime;
Shawn Lin61cadcf2016-03-09 16:11:32 +0800720 }
addy ke64e36822014-07-01 09:03:59 +0800721 dev_warn(rs->dev, "Failed to request TX DMA channel\n");
Shawn Line4c0e062016-03-31 11:11:41 +0800722 rs->dma_tx.ch = NULL;
Shawn Lin61cadcf2016-03-09 16:11:32 +0800723 }
addy ke64e36822014-07-01 09:03:59 +0800724
Shawn Line4c0e062016-03-31 11:11:41 +0800725 rs->dma_rx.ch = dma_request_chan(rs->dev, "rx");
726 if (IS_ERR(rs->dma_rx.ch)) {
727 if (PTR_ERR(rs->dma_rx.ch) == -EPROBE_DEFER) {
Shawn Line4c0e062016-03-31 11:11:41 +0800728 ret = -EPROBE_DEFER;
Dan Carpenter5de7ed02016-05-04 09:25:46 +0300729 goto err_free_dma_tx;
addy ke64e36822014-07-01 09:03:59 +0800730 }
731 dev_warn(rs->dev, "Failed to request RX DMA channel\n");
Shawn Line4c0e062016-03-31 11:11:41 +0800732 rs->dma_rx.ch = NULL;
addy ke64e36822014-07-01 09:03:59 +0800733 }
734
735 if (rs->dma_tx.ch && rs->dma_rx.ch) {
736 rs->dma_tx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_TXDR);
737 rs->dma_rx.addr = (dma_addr_t)(mem->start + ROCKCHIP_SPI_RXDR);
addy ke64e36822014-07-01 09:03:59 +0800738
739 master->can_dma = rockchip_spi_can_dma;
740 master->dma_tx = rs->dma_tx.ch;
741 master->dma_rx = rs->dma_rx.ch;
742 }
743
744 ret = devm_spi_register_master(&pdev->dev, master);
Jeffy Chen43de9792017-08-07 20:40:18 +0800745 if (ret < 0) {
addy ke64e36822014-07-01 09:03:59 +0800746 dev_err(&pdev->dev, "Failed to register master\n");
Jeffy Chenc3515872017-06-13 13:25:40 +0800747 goto err_free_dma_rx;
addy ke64e36822014-07-01 09:03:59 +0800748 }
749
addy ke64e36822014-07-01 09:03:59 +0800750 return 0;
751
Jeffy Chenc3515872017-06-13 13:25:40 +0800752err_free_dma_rx:
addy ke64e36822014-07-01 09:03:59 +0800753 if (rs->dma_rx.ch)
754 dma_release_channel(rs->dma_rx.ch);
Dan Carpenter5de7ed02016-05-04 09:25:46 +0300755err_free_dma_tx:
756 if (rs->dma_tx.ch)
757 dma_release_channel(rs->dma_tx.ch);
Jeffy Chenc3515872017-06-13 13:25:40 +0800758err_disable_pm_runtime:
759 pm_runtime_disable(&pdev->dev);
760err_disable_spiclk:
addy ke64e36822014-07-01 09:03:59 +0800761 clk_disable_unprepare(rs->spiclk);
Jeffy Chenc3515872017-06-13 13:25:40 +0800762err_disable_apbclk:
addy ke64e36822014-07-01 09:03:59 +0800763 clk_disable_unprepare(rs->apb_pclk);
Jeffy Chenc3515872017-06-13 13:25:40 +0800764err_put_master:
addy ke64e36822014-07-01 09:03:59 +0800765 spi_master_put(master);
766
767 return ret;
768}
769
770static int rockchip_spi_remove(struct platform_device *pdev)
771{
772 struct spi_master *master = spi_master_get(platform_get_drvdata(pdev));
773 struct rockchip_spi *rs = spi_master_get_devdata(master);
774
Jeffy Chen6a06e892017-08-07 20:40:19 +0800775 pm_runtime_get_sync(&pdev->dev);
addy ke64e36822014-07-01 09:03:59 +0800776
777 clk_disable_unprepare(rs->spiclk);
778 clk_disable_unprepare(rs->apb_pclk);
779
Jeffy Chen6a06e892017-08-07 20:40:19 +0800780 pm_runtime_put_noidle(&pdev->dev);
781 pm_runtime_disable(&pdev->dev);
782 pm_runtime_set_suspended(&pdev->dev);
783
addy ke64e36822014-07-01 09:03:59 +0800784 if (rs->dma_tx.ch)
785 dma_release_channel(rs->dma_tx.ch);
786 if (rs->dma_rx.ch)
787 dma_release_channel(rs->dma_rx.ch);
788
Shawn Lin844c9f42016-02-15 16:28:12 +0800789 spi_master_put(master);
790
addy ke64e36822014-07-01 09:03:59 +0800791 return 0;
792}
793
794#ifdef CONFIG_PM_SLEEP
795static int rockchip_spi_suspend(struct device *dev)
796{
Jeffy Chen43de9792017-08-07 20:40:18 +0800797 int ret;
addy ke64e36822014-07-01 09:03:59 +0800798 struct spi_master *master = dev_get_drvdata(dev);
799 struct rockchip_spi *rs = spi_master_get_devdata(master);
800
801 ret = spi_master_suspend(rs->master);
Jeffy Chen43de9792017-08-07 20:40:18 +0800802 if (ret < 0)
addy ke64e36822014-07-01 09:03:59 +0800803 return ret;
804
Jeffy Chend38c4ae12017-08-07 20:40:20 +0800805 ret = pm_runtime_force_suspend(dev);
806 if (ret < 0)
807 return ret;
addy ke64e36822014-07-01 09:03:59 +0800808
Brian Norris23e291c2016-12-16 16:59:16 -0800809 pinctrl_pm_select_sleep_state(dev);
810
Jeffy Chen43de9792017-08-07 20:40:18 +0800811 return 0;
addy ke64e36822014-07-01 09:03:59 +0800812}
813
814static int rockchip_spi_resume(struct device *dev)
815{
Jeffy Chen43de9792017-08-07 20:40:18 +0800816 int ret;
addy ke64e36822014-07-01 09:03:59 +0800817 struct spi_master *master = dev_get_drvdata(dev);
818 struct rockchip_spi *rs = spi_master_get_devdata(master);
819
Brian Norris23e291c2016-12-16 16:59:16 -0800820 pinctrl_pm_select_default_state(dev);
821
Jeffy Chend38c4ae12017-08-07 20:40:20 +0800822 ret = pm_runtime_force_resume(dev);
823 if (ret < 0)
824 return ret;
addy ke64e36822014-07-01 09:03:59 +0800825
826 ret = spi_master_resume(rs->master);
827 if (ret < 0) {
828 clk_disable_unprepare(rs->spiclk);
829 clk_disable_unprepare(rs->apb_pclk);
830 }
831
Jeffy Chen43de9792017-08-07 20:40:18 +0800832 return 0;
addy ke64e36822014-07-01 09:03:59 +0800833}
834#endif /* CONFIG_PM_SLEEP */
835
Rafael J. Wysockiec833052014-12-13 00:41:15 +0100836#ifdef CONFIG_PM
addy ke64e36822014-07-01 09:03:59 +0800837static int rockchip_spi_runtime_suspend(struct device *dev)
838{
839 struct spi_master *master = dev_get_drvdata(dev);
840 struct rockchip_spi *rs = spi_master_get_devdata(master);
841
842 clk_disable_unprepare(rs->spiclk);
843 clk_disable_unprepare(rs->apb_pclk);
844
845 return 0;
846}
847
848static int rockchip_spi_runtime_resume(struct device *dev)
849{
850 int ret;
851 struct spi_master *master = dev_get_drvdata(dev);
852 struct rockchip_spi *rs = spi_master_get_devdata(master);
853
854 ret = clk_prepare_enable(rs->apb_pclk);
Jeffy Chen43de9792017-08-07 20:40:18 +0800855 if (ret < 0)
addy ke64e36822014-07-01 09:03:59 +0800856 return ret;
857
858 ret = clk_prepare_enable(rs->spiclk);
Jeffy Chen43de9792017-08-07 20:40:18 +0800859 if (ret < 0)
addy ke64e36822014-07-01 09:03:59 +0800860 clk_disable_unprepare(rs->apb_pclk);
861
Jeffy Chen43de9792017-08-07 20:40:18 +0800862 return 0;
addy ke64e36822014-07-01 09:03:59 +0800863}
Rafael J. Wysockiec833052014-12-13 00:41:15 +0100864#endif /* CONFIG_PM */
addy ke64e36822014-07-01 09:03:59 +0800865
866static const struct dev_pm_ops rockchip_spi_pm = {
867 SET_SYSTEM_SLEEP_PM_OPS(rockchip_spi_suspend, rockchip_spi_resume)
868 SET_RUNTIME_PM_OPS(rockchip_spi_runtime_suspend,
869 rockchip_spi_runtime_resume, NULL)
870};
871
872static const struct of_device_id rockchip_spi_dt_match[] = {
Andy Yan6b860e62017-08-14 16:34:22 +0800873 { .compatible = "rockchip,rv1108-spi", },
Caesar Wangaa29ea32016-05-20 07:56:21 +0800874 { .compatible = "rockchip,rk3036-spi", },
addy ke64e36822014-07-01 09:03:59 +0800875 { .compatible = "rockchip,rk3066-spi", },
Addy Keb839b782014-07-11 10:09:19 +0800876 { .compatible = "rockchip,rk3188-spi", },
Caesar Wangaa29ea32016-05-20 07:56:21 +0800877 { .compatible = "rockchip,rk3228-spi", },
Addy Keb839b782014-07-11 10:09:19 +0800878 { .compatible = "rockchip,rk3288-spi", },
Caesar Wangaa29ea32016-05-20 07:56:21 +0800879 { .compatible = "rockchip,rk3368-spi", },
Xu Jianqun9b7a5622016-02-18 19:16:31 +0800880 { .compatible = "rockchip,rk3399-spi", },
addy ke64e36822014-07-01 09:03:59 +0800881 { },
882};
883MODULE_DEVICE_TABLE(of, rockchip_spi_dt_match);
884
885static struct platform_driver rockchip_spi_driver = {
886 .driver = {
887 .name = DRIVER_NAME,
addy ke64e36822014-07-01 09:03:59 +0800888 .pm = &rockchip_spi_pm,
889 .of_match_table = of_match_ptr(rockchip_spi_dt_match),
890 },
891 .probe = rockchip_spi_probe,
892 .remove = rockchip_spi_remove,
893};
894
895module_platform_driver(rockchip_spi_driver);
896
Addy Ke5dcc44e2014-07-11 10:07:56 +0800897MODULE_AUTHOR("Addy Ke <addy.ke@rock-chips.com>");
addy ke64e36822014-07-01 09:03:59 +0800898MODULE_DESCRIPTION("ROCKCHIP SPI Controller Driver");
899MODULE_LICENSE("GPL v2");