Skip to content

Commit a4b306e

Browse files
ADESTMvinodkoul
authored andcommitted
dmaengine: stm32-mdma: use Link Address Register to compute residue
Current implementation relies on curr_hwdesc index. But to keep this index up to date, Block Transfer interrupt (BTIE) has to be enabled. If it is not, curr_hwdesc is not updated, and then residue is not reliable. Rely on Link Address Register instead. And disable BTIE interrupt in stm32_mdma_setup_xfer() because it is no more needed in case of _prep_slave_sg() to maintain curr_hwdesc up to date. It avoids extra interrupts and also ensures a reliable residue. These improvements are required for STM32 DCMI camera capture use case, which need STM32 DMA and MDMA chaining for good performance. Fixes: 6968743 ("dmaengine: stm32-mdma: add support to be triggered by STM32 DMA") Signed-off-by: Amelie Delaunay <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 81337b9 commit a4b306e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/dma/stm32-mdma.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,6 @@ static int stm32_mdma_setup_xfer(struct stm32_mdma_chan *chan,
777777
/* Enable interrupts */
778778
ccr &= ~STM32_MDMA_CCR_IRQ_MASK;
779779
ccr |= STM32_MDMA_CCR_TEIE | STM32_MDMA_CCR_CTCIE;
780-
if (sg_len > 1)
781-
ccr |= STM32_MDMA_CCR_BTIE;
782780
desc->ccr = ccr;
783781

784782
return 0;
@@ -1324,12 +1322,21 @@ static size_t stm32_mdma_desc_residue(struct stm32_mdma_chan *chan,
13241322
{
13251323
struct stm32_mdma_device *dmadev = stm32_mdma_get_dev(chan);
13261324
struct stm32_mdma_hwdesc *hwdesc;
1327-
u32 cbndtr, residue, modulo, burst_size;
1325+
u32 cisr, clar, cbndtr, residue, modulo, burst_size;
13281326
int i;
13291327

1328+
cisr = stm32_mdma_read(dmadev, STM32_MDMA_CISR(chan->id));
1329+
13301330
residue = 0;
1331-
for (i = curr_hwdesc + 1; i < desc->count; i++) {
1331+
/* Get the next hw descriptor to process from current transfer */
1332+
clar = stm32_mdma_read(dmadev, STM32_MDMA_CLAR(chan->id));
1333+
for (i = desc->count - 1; i >= 0; i--) {
13321334
hwdesc = desc->node[i].hwdesc;
1335+
1336+
if (hwdesc->clar == clar)
1337+
break;/* Current transfer found, stop cumulating */
1338+
1339+
/* Cumulate residue of unprocessed hw descriptors */
13331340
residue += STM32_MDMA_CBNDTR_BNDT(hwdesc->cbndtr);
13341341
}
13351342
cbndtr = stm32_mdma_read(dmadev, STM32_MDMA_CBNDTR(chan->id));

0 commit comments

Comments
 (0)