@@ -119,7 +119,6 @@ struct fsl_dspi_devtype_data {
119
119
enum dspi_trans_mode trans_mode ;
120
120
u8 max_clock_factor ;
121
121
int fifo_size ;
122
- int dma_bufsize ;
123
122
};
124
123
125
124
enum {
@@ -138,7 +137,6 @@ static const struct fsl_dspi_devtype_data devtype_data[] = {
138
137
[VF610 ] = {
139
138
.trans_mode = DSPI_DMA_MODE ,
140
139
.max_clock_factor = 2 ,
141
- .dma_bufsize = 4096 ,
142
140
.fifo_size = 4 ,
143
141
},
144
142
[LS1021A ] = {
@@ -167,19 +165,16 @@ static const struct fsl_dspi_devtype_data devtype_data[] = {
167
165
},
168
166
[LS2080A ] = {
169
167
.trans_mode = DSPI_DMA_MODE ,
170
- .dma_bufsize = 8 ,
171
168
.max_clock_factor = 8 ,
172
169
.fifo_size = 4 ,
173
170
},
174
171
[LS2085A ] = {
175
172
.trans_mode = DSPI_DMA_MODE ,
176
- .dma_bufsize = 8 ,
177
173
.max_clock_factor = 8 ,
178
174
.fifo_size = 4 ,
179
175
},
180
176
[LX2160A ] = {
181
177
.trans_mode = DSPI_DMA_MODE ,
182
- .dma_bufsize = 8 ,
183
178
.max_clock_factor = 8 ,
184
179
.fifo_size = 4 ,
185
180
},
@@ -191,9 +186,6 @@ static const struct fsl_dspi_devtype_data devtype_data[] = {
191
186
};
192
187
193
188
struct fsl_dspi_dma {
194
- /* Length of transfer in words of dspi->fifo_size */
195
- u32 curr_xfer_len ;
196
-
197
189
u32 * tx_dma_buf ;
198
190
struct dma_chan * chan_tx ;
199
191
dma_addr_t tx_dma_phys ;
@@ -352,7 +344,7 @@ static void dspi_rx_dma_callback(void *arg)
352
344
int i ;
353
345
354
346
if (dspi -> rx ) {
355
- for (i = 0 ; i < dma -> curr_xfer_len ; i ++ )
347
+ for (i = 0 ; i < dspi -> words_in_flight ; i ++ )
356
348
dspi_push_rx (dspi , dspi -> dma -> rx_dma_buf [i ]);
357
349
}
358
350
@@ -366,12 +358,12 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
366
358
int time_left ;
367
359
int i ;
368
360
369
- for (i = 0 ; i < dma -> curr_xfer_len ; i ++ )
361
+ for (i = 0 ; i < dspi -> words_in_flight ; i ++ )
370
362
dspi -> dma -> tx_dma_buf [i ] = dspi_pop_tx_pushr (dspi );
371
363
372
364
dma -> tx_desc = dmaengine_prep_slave_single (dma -> chan_tx ,
373
365
dma -> tx_dma_phys ,
374
- dma -> curr_xfer_len *
366
+ dspi -> words_in_flight *
375
367
DMA_SLAVE_BUSWIDTH_4_BYTES ,
376
368
DMA_MEM_TO_DEV ,
377
369
DMA_PREP_INTERRUPT | DMA_CTRL_ACK );
@@ -389,7 +381,7 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
389
381
390
382
dma -> rx_desc = dmaengine_prep_slave_single (dma -> chan_rx ,
391
383
dma -> rx_dma_phys ,
392
- dma -> curr_xfer_len *
384
+ dspi -> words_in_flight *
393
385
DMA_SLAVE_BUSWIDTH_4_BYTES ,
394
386
DMA_DEV_TO_MEM ,
395
387
DMA_PREP_INTERRUPT | DMA_CTRL_ACK );
@@ -437,46 +429,42 @@ static int dspi_next_xfer_dma_submit(struct fsl_dspi *dspi)
437
429
return 0 ;
438
430
}
439
431
432
+ static void dspi_setup_accel (struct fsl_dspi * dspi );
433
+
440
434
static int dspi_dma_xfer (struct fsl_dspi * dspi )
441
435
{
442
436
struct spi_message * message = dspi -> cur_msg ;
443
437
struct device * dev = & dspi -> pdev -> dev ;
444
- struct fsl_dspi_dma * dma = dspi -> dma ;
445
- int curr_remaining_bytes ;
446
- int bytes_per_buffer ;
447
438
int ret = 0 ;
448
439
449
- curr_remaining_bytes = dspi -> len ;
450
- bytes_per_buffer = dspi -> devtype_data -> dma_bufsize /
451
- dspi -> devtype_data -> fifo_size ;
452
- while (curr_remaining_bytes ) {
453
- /* Check if current transfer fits the DMA buffer */
454
- dma -> curr_xfer_len = curr_remaining_bytes /
455
- dspi -> oper_word_size ;
456
- if (dma -> curr_xfer_len > bytes_per_buffer )
457
- dma -> curr_xfer_len = bytes_per_buffer ;
440
+ /*
441
+ * dspi->len gets decremented by dspi_pop_tx_pushr in
442
+ * dspi_next_xfer_dma_submit
443
+ */
444
+ while (dspi -> len ) {
445
+ /* Figure out operational bits-per-word for this chunk */
446
+ dspi_setup_accel (dspi );
447
+
448
+ dspi -> words_in_flight = dspi -> len / dspi -> oper_word_size ;
449
+ if (dspi -> words_in_flight > dspi -> devtype_data -> fifo_size )
450
+ dspi -> words_in_flight = dspi -> devtype_data -> fifo_size ;
451
+
452
+ message -> actual_length += dspi -> words_in_flight *
453
+ dspi -> oper_word_size ;
458
454
459
455
ret = dspi_next_xfer_dma_submit (dspi );
460
456
if (ret ) {
461
457
dev_err (dev , "DMA transfer failed\n" );
462
- goto exit ;
463
-
464
- } else {
465
- const int len = dma -> curr_xfer_len *
466
- dspi -> oper_word_size ;
467
- curr_remaining_bytes -= len ;
468
- message -> actual_length += len ;
469
- if (curr_remaining_bytes < 0 )
470
- curr_remaining_bytes = 0 ;
458
+ break ;
471
459
}
472
460
}
473
461
474
- exit :
475
462
return ret ;
476
463
}
477
464
478
465
static int dspi_request_dma (struct fsl_dspi * dspi , phys_addr_t phy_addr )
479
466
{
467
+ int dma_bufsize = dspi -> devtype_data -> fifo_size * 2 ;
480
468
struct device * dev = & dspi -> pdev -> dev ;
481
469
struct dma_slave_config cfg ;
482
470
struct fsl_dspi_dma * dma ;
@@ -501,16 +489,16 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
501
489
}
502
490
503
491
dma -> tx_dma_buf = dma_alloc_coherent (dma -> chan_tx -> device -> dev ,
504
- dspi -> devtype_data -> dma_bufsize ,
505
- & dma -> tx_dma_phys , GFP_KERNEL );
492
+ dma_bufsize , & dma -> tx_dma_phys ,
493
+ GFP_KERNEL );
506
494
if (!dma -> tx_dma_buf ) {
507
495
ret = - ENOMEM ;
508
496
goto err_tx_dma_buf ;
509
497
}
510
498
511
499
dma -> rx_dma_buf = dma_alloc_coherent (dma -> chan_rx -> device -> dev ,
512
- dspi -> devtype_data -> dma_bufsize ,
513
- & dma -> rx_dma_phys , GFP_KERNEL );
500
+ dma_bufsize , & dma -> rx_dma_phys ,
501
+ GFP_KERNEL );
514
502
if (!dma -> rx_dma_buf ) {
515
503
ret = - ENOMEM ;
516
504
goto err_rx_dma_buf ;
@@ -547,12 +535,10 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
547
535
548
536
err_slave_config :
549
537
dma_free_coherent (dma -> chan_rx -> device -> dev ,
550
- dspi -> devtype_data -> dma_bufsize ,
551
- dma -> rx_dma_buf , dma -> rx_dma_phys );
538
+ dma_bufsize , dma -> rx_dma_buf , dma -> rx_dma_phys );
552
539
err_rx_dma_buf :
553
540
dma_free_coherent (dma -> chan_tx -> device -> dev ,
554
- dspi -> devtype_data -> dma_bufsize ,
555
- dma -> tx_dma_buf , dma -> tx_dma_phys );
541
+ dma_bufsize , dma -> tx_dma_buf , dma -> tx_dma_phys );
556
542
err_tx_dma_buf :
557
543
dma_release_channel (dma -> chan_tx );
558
544
err_tx_channel :
@@ -566,22 +552,21 @@ static int dspi_request_dma(struct fsl_dspi *dspi, phys_addr_t phy_addr)
566
552
567
553
static void dspi_release_dma (struct fsl_dspi * dspi )
568
554
{
555
+ int dma_bufsize = dspi -> devtype_data -> fifo_size * 2 ;
569
556
struct fsl_dspi_dma * dma = dspi -> dma ;
570
557
571
558
if (!dma )
572
559
return ;
573
560
574
561
if (dma -> chan_tx ) {
575
562
dma_unmap_single (dma -> chan_tx -> device -> dev , dma -> tx_dma_phys ,
576
- dspi -> devtype_data -> dma_bufsize ,
577
- DMA_TO_DEVICE );
563
+ dma_bufsize , DMA_TO_DEVICE );
578
564
dma_release_channel (dma -> chan_tx );
579
565
}
580
566
581
567
if (dma -> chan_rx ) {
582
568
dma_unmap_single (dma -> chan_rx -> device -> dev , dma -> rx_dma_phys ,
583
- dspi -> devtype_data -> dma_bufsize ,
584
- DMA_FROM_DEVICE );
569
+ dma_bufsize , DMA_FROM_DEVICE );
585
570
dma_release_channel (dma -> chan_rx );
586
571
}
587
572
}
@@ -833,7 +818,7 @@ static void dspi_setup_accel(struct fsl_dspi *dspi)
833
818
dspi -> oper_word_size = DIV_ROUND_UP (dspi -> oper_bits_per_word , 8 );
834
819
835
820
/*
836
- * Update CTAR here (code is common for both EOQ and XSPI modes).
821
+ * Update CTAR here (code is common for EOQ, XSPI and DMA modes).
837
822
* We will update CTARE in the portion specific to XSPI, when we
838
823
* also know the preload value (DTCP).
839
824
*/
@@ -960,13 +945,6 @@ static int dspi_transfer_one_message(struct spi_controller *ctlr,
960
945
regmap_update_bits (dspi -> regmap , SPI_MCR ,
961
946
SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF ,
962
947
SPI_MCR_CLR_TXF | SPI_MCR_CLR_RXF );
963
- /*
964
- * Static CTAR setup for modes that don't dynamically adjust it
965
- * via dspi_setup_accel (aka for DMA)
966
- */
967
- regmap_write (dspi -> regmap , SPI_CTAR (0 ),
968
- dspi -> cur_chip -> ctar_val |
969
- SPI_FRAME_BITS (transfer -> bits_per_word ));
970
948
971
949
spi_take_timestamp_pre (dspi -> ctlr , dspi -> cur_transfer ,
972
950
dspi -> progress , !dspi -> irq );
0 commit comments