Skip to content

Commit affe93d

Browse files
fancerbroonie
authored andcommitted
spi: dw-dma: Fix Tx DMA channel working too fast
It turns out having a Rx DMA channel serviced with higher priority than a Tx DMA channel is not enough to provide a well balanced DMA-based SPI transfer interface. There might still be moments when the Tx DMA channel is occasionally handled faster than the Rx DMA channel. That in its turn will eventually cause the SPI Rx FIFO overflow if SPI bus speed is high enough to fill the SPI Rx FIFO in before it's cleared by the Rx DMA channel. That's why having the DMA-based SPI Tx interface too optimized is the errors prone, so the commit 0b2b665 ("spi: dw: Use DMA max burst to set the request thresholds") though being perfectly normal from the standard functionality point of view implicitly introduced the problem described above. In order to fix that the Tx DMA activity is intentionally slowed down by limiting the SPI Tx FIFO depth with a value twice bigger than the Tx burst length calculated earlier by the dw_spi_dma_maxburst_init() method. Fixes: 0b2b665 ("spi: dw: Use DMA max burst to set the request thresholds") Signed-off-by: Serge Semin <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Alexey Malahov <[email protected]> Cc: Feng Tang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ed7815d commit affe93d

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

drivers/spi/spi-dw-dma.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,20 @@ static int dw_spi_dma_setup(struct dw_spi *dws, struct spi_transfer *xfer)
372372
{
373373
u16 imr = 0, dma_ctrl = 0;
374374

375+
/*
376+
* Having a Rx DMA channel serviced with higher priority than a Tx DMA
377+
* channel might not be enough to provide a well balanced DMA-based
378+
* SPI transfer interface. There might still be moments when the Tx DMA
379+
* channel is occasionally handled faster than the Rx DMA channel.
380+
* That in its turn will eventually cause the SPI Rx FIFO overflow if
381+
* SPI bus speed is high enough to fill the SPI Rx FIFO in before it's
382+
* cleared by the Rx DMA channel. In order to fix the problem the Tx
383+
* DMA activity is intentionally slowed down by limiting the SPI Tx
384+
* FIFO depth with a value twice bigger than the Tx burst length
385+
* calculated earlier by the dw_spi_dma_maxburst_init() method.
386+
*/
375387
dw_writel(dws, DW_SPI_DMARDLR, dws->rxburst - 1);
376-
dw_writel(dws, DW_SPI_DMATDLR, dws->fifo_len - dws->txburst);
388+
dw_writel(dws, DW_SPI_DMATDLR, dws->txburst);
377389

378390
if (xfer->tx_buf)
379391
dma_ctrl |= SPI_DMA_TDMAE;

0 commit comments

Comments
 (0)