117
117
#define STM32_DMA_FIFO_THRESHOLD_HALFFULL 0x01
118
118
#define STM32_DMA_FIFO_THRESHOLD_3QUARTERSFULL 0x02
119
119
#define STM32_DMA_FIFO_THRESHOLD_FULL 0x03
120
+ #define STM32_DMA_FIFO_THRESHOLD_NONE 0x04
120
121
121
122
#define STM32_DMA_MAX_DATA_ITEMS 0xffff
122
123
/*
136
137
/* DMA Features */
137
138
#define STM32_DMA_THRESHOLD_FTR_MASK GENMASK(1, 0)
138
139
#define STM32_DMA_THRESHOLD_FTR_GET (n ) ((n) & STM32_DMA_THRESHOLD_FTR_MASK)
140
+ #define STM32_DMA_DIRECT_MODE_MASK BIT(2)
141
+ #define STM32_DMA_DIRECT_MODE_GET (n ) (((n) & STM32_DMA_DIRECT_MODE_MASK) \
142
+ >> 2)
139
143
140
144
enum stm32_dma_width {
141
145
STM32_DMA_BYTE ,
@@ -281,6 +285,9 @@ static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold,
281
285
{
282
286
u32 remaining ;
283
287
288
+ if (threshold == STM32_DMA_FIFO_THRESHOLD_NONE )
289
+ return false;
290
+
284
291
if (width != DMA_SLAVE_BUSWIDTH_UNDEFINED ) {
285
292
if (burst != 0 ) {
286
293
/*
@@ -302,6 +309,10 @@ static bool stm32_dma_fifo_threshold_is_allowed(u32 burst, u32 threshold,
302
309
303
310
static bool stm32_dma_is_burst_possible (u32 buf_len , u32 threshold )
304
311
{
312
+ /* If FIFO direct mode, burst is not possible */
313
+ if (threshold == STM32_DMA_FIFO_THRESHOLD_NONE )
314
+ return false;
315
+
305
316
/*
306
317
* Buffer or period length has to be aligned on FIFO depth.
307
318
* Otherwise bytes may be stuck within FIFO at buffer or period
@@ -657,6 +668,12 @@ static irqreturn_t stm32_dma_chan_irq(int irq, void *devid)
657
668
dev_dbg (chan2dev (chan ), "FIFO over/underrun\n" );
658
669
}
659
670
}
671
+ if (status & STM32_DMA_DMEI ) {
672
+ stm32_dma_irq_clear (chan , STM32_DMA_DMEI );
673
+ status &= ~STM32_DMA_DMEI ;
674
+ if (sfcr & STM32_DMA_SCR_DMEIE )
675
+ dev_dbg (chan2dev (chan ), "Direct mode overrun\n" );
676
+ }
660
677
if (status ) {
661
678
stm32_dma_irq_clear (chan , status );
662
679
dev_err (chan2dev (chan ), "DMA error: status=0x%08x\n" , status );
@@ -692,13 +709,13 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
692
709
int src_bus_width , dst_bus_width ;
693
710
int src_burst_size , dst_burst_size ;
694
711
u32 src_maxburst , dst_maxburst , src_best_burst , dst_best_burst ;
695
- u32 dma_scr , threshold ;
712
+ u32 dma_scr , fifoth ;
696
713
697
714
src_addr_width = chan -> dma_sconfig .src_addr_width ;
698
715
dst_addr_width = chan -> dma_sconfig .dst_addr_width ;
699
716
src_maxburst = chan -> dma_sconfig .src_maxburst ;
700
717
dst_maxburst = chan -> dma_sconfig .dst_maxburst ;
701
- threshold = chan -> threshold ;
718
+ fifoth = chan -> threshold ;
702
719
703
720
switch (direction ) {
704
721
case DMA_MEM_TO_DEV :
@@ -710,15 +727,15 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
710
727
/* Set device burst size */
711
728
dst_best_burst = stm32_dma_get_best_burst (buf_len ,
712
729
dst_maxburst ,
713
- threshold ,
730
+ fifoth ,
714
731
dst_addr_width );
715
732
716
733
dst_burst_size = stm32_dma_get_burst (chan , dst_best_burst );
717
734
if (dst_burst_size < 0 )
718
735
return dst_burst_size ;
719
736
720
737
/* Set memory data size */
721
- src_addr_width = stm32_dma_get_max_width (buf_len , threshold );
738
+ src_addr_width = stm32_dma_get_max_width (buf_len , fifoth );
722
739
chan -> mem_width = src_addr_width ;
723
740
src_bus_width = stm32_dma_get_width (chan , src_addr_width );
724
741
if (src_bus_width < 0 )
@@ -728,7 +745,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
728
745
src_maxburst = STM32_DMA_MAX_BURST ;
729
746
src_best_burst = stm32_dma_get_best_burst (buf_len ,
730
747
src_maxburst ,
731
- threshold ,
748
+ fifoth ,
732
749
src_addr_width );
733
750
src_burst_size = stm32_dma_get_burst (chan , src_best_burst );
734
751
if (src_burst_size < 0 )
@@ -742,7 +759,8 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
742
759
743
760
/* Set FIFO threshold */
744
761
chan -> chan_reg .dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK ;
745
- chan -> chan_reg .dma_sfcr |= STM32_DMA_SFCR_FTH (threshold );
762
+ if (fifoth != STM32_DMA_FIFO_THRESHOLD_NONE )
763
+ chan -> chan_reg .dma_sfcr |= STM32_DMA_SFCR_FTH (fifoth );
746
764
747
765
/* Set peripheral address */
748
766
chan -> chan_reg .dma_spar = chan -> dma_sconfig .dst_addr ;
@@ -758,15 +776,15 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
758
776
/* Set device burst size */
759
777
src_best_burst = stm32_dma_get_best_burst (buf_len ,
760
778
src_maxburst ,
761
- threshold ,
779
+ fifoth ,
762
780
src_addr_width );
763
781
chan -> mem_burst = src_best_burst ;
764
782
src_burst_size = stm32_dma_get_burst (chan , src_best_burst );
765
783
if (src_burst_size < 0 )
766
784
return src_burst_size ;
767
785
768
786
/* Set memory data size */
769
- dst_addr_width = stm32_dma_get_max_width (buf_len , threshold );
787
+ dst_addr_width = stm32_dma_get_max_width (buf_len , fifoth );
770
788
chan -> mem_width = dst_addr_width ;
771
789
dst_bus_width = stm32_dma_get_width (chan , dst_addr_width );
772
790
if (dst_bus_width < 0 )
@@ -776,7 +794,7 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
776
794
dst_maxburst = STM32_DMA_MAX_BURST ;
777
795
dst_best_burst = stm32_dma_get_best_burst (buf_len ,
778
796
dst_maxburst ,
779
- threshold ,
797
+ fifoth ,
780
798
dst_addr_width );
781
799
chan -> mem_burst = dst_best_burst ;
782
800
dst_burst_size = stm32_dma_get_burst (chan , dst_best_burst );
@@ -791,7 +809,8 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan,
791
809
792
810
/* Set FIFO threshold */
793
811
chan -> chan_reg .dma_sfcr &= ~STM32_DMA_SFCR_FTH_MASK ;
794
- chan -> chan_reg .dma_sfcr |= STM32_DMA_SFCR_FTH (threshold );
812
+ if (fifoth != STM32_DMA_FIFO_THRESHOLD_NONE )
813
+ chan -> chan_reg .dma_sfcr |= STM32_DMA_SFCR_FTH (fifoth );
795
814
796
815
/* Set peripheral address */
797
816
chan -> chan_reg .dma_spar = chan -> dma_sconfig .src_addr ;
@@ -1216,6 +1235,8 @@ static void stm32_dma_set_config(struct stm32_dma_chan *chan,
1216
1235
chan -> chan_reg .dma_scr |= STM32_DMA_SCR_TEIE | STM32_DMA_SCR_TCIE ;
1217
1236
1218
1237
chan -> threshold = STM32_DMA_THRESHOLD_FTR_GET (cfg -> features );
1238
+ if (STM32_DMA_DIRECT_MODE_GET (cfg -> features ))
1239
+ chan -> threshold = STM32_DMA_FIFO_THRESHOLD_NONE ;
1219
1240
}
1220
1241
1221
1242
static struct dma_chan * stm32_dma_of_xlate (struct of_phandle_args * dma_spec ,
0 commit comments