13
13
*
14
14
*/
15
15
16
- #include <linux/init.h>
17
- #include <linux/module.h>
18
16
#include <linux/clk.h>
19
- #include <linux/err .h>
20
- #include <linux/delay .h>
21
- #include <linux/interrupt .h>
17
+ #include <linux/dmaengine .h>
18
+ #include <linux/module .h>
19
+ #include <linux/of .h>
22
20
#include <linux/platform_device.h>
23
- #include <linux/slab.h>
24
21
#include <linux/spi/spi.h>
25
- #include <linux/scatterlist.h>
26
- #include <linux/of.h>
27
22
#include <linux/pm_runtime.h>
28
- #include <linux/io.h>
29
- #include <linux/dmaengine.h>
23
+ #include <linux/scatterlist.h>
30
24
31
25
#define DRIVER_NAME "rockchip-spi"
32
26
@@ -179,7 +173,7 @@ struct rockchip_spi {
179
173
u8 tmode ;
180
174
u8 bpw ;
181
175
u8 n_bytes ;
182
- u8 rsd_nsecs ;
176
+ u32 rsd_nsecs ;
183
177
unsigned len ;
184
178
u32 speed ;
185
179
@@ -192,8 +186,6 @@ struct rockchip_spi {
192
186
/* protect state */
193
187
spinlock_t lock ;
194
188
195
- struct completion xfer_completion ;
196
-
197
189
u32 use_dma ;
198
190
struct sg_table tx_sg ;
199
191
struct sg_table rx_sg ;
@@ -265,7 +257,10 @@ static inline u32 rx_max(struct rockchip_spi *rs)
265
257
static void rockchip_spi_set_cs (struct spi_device * spi , bool enable )
266
258
{
267
259
u32 ser ;
268
- struct rockchip_spi * rs = spi_master_get_devdata (spi -> master );
260
+ struct spi_master * master = spi -> master ;
261
+ struct rockchip_spi * rs = spi_master_get_devdata (master );
262
+
263
+ pm_runtime_get_sync (rs -> dev );
269
264
270
265
ser = readl_relaxed (rs -> regs + ROCKCHIP_SPI_SER ) & SER_MASK ;
271
266
@@ -290,6 +285,8 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable)
290
285
ser &= ~(1 << spi -> chip_select );
291
286
292
287
writel_relaxed (ser , rs -> regs + ROCKCHIP_SPI_SER );
288
+
289
+ pm_runtime_put_sync (rs -> dev );
293
290
}
294
291
295
292
static int rockchip_spi_prepare_message (struct spi_master * master ,
@@ -319,12 +316,12 @@ static void rockchip_spi_handle_err(struct spi_master *master,
319
316
*/
320
317
if (rs -> use_dma ) {
321
318
if (rs -> state & RXBUSY ) {
322
- dmaengine_terminate_all (rs -> dma_rx .ch );
319
+ dmaengine_terminate_async (rs -> dma_rx .ch );
323
320
flush_fifo (rs );
324
321
}
325
322
326
323
if (rs -> state & TXBUSY )
327
- dmaengine_terminate_all (rs -> dma_tx .ch );
324
+ dmaengine_terminate_async (rs -> dma_tx .ch );
328
325
}
329
326
330
327
spin_unlock_irqrestore (& rs -> lock , flags );
@@ -433,7 +430,7 @@ static void rockchip_spi_dma_txcb(void *data)
433
430
spin_unlock_irqrestore (& rs -> lock , flags );
434
431
}
435
432
436
- static void rockchip_spi_prepare_dma (struct rockchip_spi * rs )
433
+ static int rockchip_spi_prepare_dma (struct rockchip_spi * rs )
437
434
{
438
435
unsigned long flags ;
439
436
struct dma_slave_config rxconf , txconf ;
@@ -456,6 +453,8 @@ static void rockchip_spi_prepare_dma(struct rockchip_spi *rs)
456
453
rs -> dma_rx .ch ,
457
454
rs -> rx_sg .sgl , rs -> rx_sg .nents ,
458
455
rs -> dma_rx .direction , DMA_PREP_INTERRUPT );
456
+ if (!rxdesc )
457
+ return - EINVAL ;
459
458
460
459
rxdesc -> callback = rockchip_spi_dma_rxcb ;
461
460
rxdesc -> callback_param = rs ;
@@ -473,6 +472,11 @@ static void rockchip_spi_prepare_dma(struct rockchip_spi *rs)
473
472
rs -> dma_tx .ch ,
474
473
rs -> tx_sg .sgl , rs -> tx_sg .nents ,
475
474
rs -> dma_tx .direction , DMA_PREP_INTERRUPT );
475
+ if (!txdesc ) {
476
+ if (rxdesc )
477
+ dmaengine_terminate_sync (rs -> dma_rx .ch );
478
+ return - EINVAL ;
479
+ }
476
480
477
481
txdesc -> callback = rockchip_spi_dma_txcb ;
478
482
txdesc -> callback_param = rs ;
@@ -494,6 +498,8 @@ static void rockchip_spi_prepare_dma(struct rockchip_spi *rs)
494
498
dmaengine_submit (txdesc );
495
499
dma_async_issue_pending (rs -> dma_tx .ch );
496
500
}
501
+
502
+ return 0 ;
497
503
}
498
504
499
505
static void rockchip_spi_config (struct rockchip_spi * rs )
@@ -503,7 +509,8 @@ static void rockchip_spi_config(struct rockchip_spi *rs)
503
509
int rsd = 0 ;
504
510
505
511
u32 cr0 = (CR0_BHT_8BIT << CR0_BHT_OFFSET )
506
- | (CR0_SSD_ONE << CR0_SSD_OFFSET );
512
+ | (CR0_SSD_ONE << CR0_SSD_OFFSET )
513
+ | (CR0_EM_BIG << CR0_EM_OFFSET );
507
514
508
515
cr0 |= (rs -> n_bytes << CR0_DFS_OFFSET );
509
516
cr0 |= ((rs -> mode & 0x3 ) << CR0_SCPH_OFFSET );
@@ -606,12 +613,12 @@ static int rockchip_spi_transfer_one(
606
613
if (rs -> use_dma ) {
607
614
if (rs -> tmode == CR0_XFM_RO ) {
608
615
/* rx: dma must be prepared first */
609
- rockchip_spi_prepare_dma (rs );
616
+ ret = rockchip_spi_prepare_dma (rs );
610
617
spi_enable_chip (rs , 1 );
611
618
} else {
612
619
/* tx or tr: spi must be enabled first */
613
620
spi_enable_chip (rs , 1 );
614
- rockchip_spi_prepare_dma (rs );
621
+ ret = rockchip_spi_prepare_dma (rs );
615
622
}
616
623
} else {
617
624
spi_enable_chip (rs , 1 );
@@ -717,8 +724,14 @@ static int rockchip_spi_probe(struct platform_device *pdev)
717
724
master -> handle_err = rockchip_spi_handle_err ;
718
725
719
726
rs -> dma_tx .ch = dma_request_slave_channel (rs -> dev , "tx" );
720
- if (!rs -> dma_tx .ch )
727
+ if (IS_ERR_OR_NULL (rs -> dma_tx .ch )) {
728
+ /* Check tx to see if we need defer probing driver */
729
+ if (PTR_ERR (rs -> dma_tx .ch ) == - EPROBE_DEFER ) {
730
+ ret = - EPROBE_DEFER ;
731
+ goto err_get_fifo_len ;
732
+ }
721
733
dev_warn (rs -> dev , "Failed to request TX DMA channel\n" );
734
+ }
722
735
723
736
rs -> dma_rx .ch = dma_request_slave_channel (rs -> dev , "rx" );
724
737
if (!rs -> dma_rx .ch ) {
@@ -871,6 +884,7 @@ static const struct of_device_id rockchip_spi_dt_match[] = {
871
884
{ .compatible = "rockchip,rk3066-spi" , },
872
885
{ .compatible = "rockchip,rk3188-spi" , },
873
886
{ .compatible = "rockchip,rk3288-spi" , },
887
+ { .compatible = "rockchip,rk3399-spi" , },
874
888
{ },
875
889
};
876
890
MODULE_DEVICE_TABLE (of , rockchip_spi_dt_match );
0 commit comments