Merge tag 'dmaengine-6.7-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/vkoul...
[linux-2.6-microblaze.git] / drivers / dma / stm32-dma.c
index c8089e7..72d83cd 100644 (file)
@@ -1113,8 +1113,10 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
                chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_PFCTRL;
 
        /* Activate Double Buffer Mode if DMA triggers STM32 MDMA and more than 1 sg */
-       if (chan->trig_mdma && sg_len > 1)
+       if (chan->trig_mdma && sg_len > 1) {
                chan->chan_reg.dma_scr |= STM32_DMA_SCR_DBM;
+               chan->chan_reg.dma_scr &= ~STM32_DMA_SCR_CT;
+       }
 
        for_each_sg(sgl, sg, sg_len, i) {
                ret = stm32_dma_set_xfer_param(chan, direction, &buswidth,
@@ -1383,11 +1385,12 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
 
        residue = stm32_dma_get_remaining_bytes(chan);
 
-       if (chan->desc->cyclic && !stm32_dma_is_current_sg(chan)) {
+       if ((chan->desc->cyclic || chan->trig_mdma) && !stm32_dma_is_current_sg(chan)) {
                n_sg++;
                if (n_sg == chan->desc->num_sgs)
                        n_sg = 0;
-               residue = sg_req->len;
+               if (!chan->trig_mdma)
+                       residue = sg_req->len;
        }
 
        /*
@@ -1397,7 +1400,7 @@ static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan,
         * residue = remaining bytes from NDTR + remaining
         * periods/sg to be transferred
         */
-       if (!chan->desc->cyclic || n_sg != 0)
+       if ((!chan->desc->cyclic && !chan->trig_mdma) || n_sg != 0)
                for (i = n_sg; i < desc->num_sgs; i++)
                        residue += desc->sg_req[i].len;