]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/dma/imx-sdma.c
KARO: cleanup after merge of Freescale 3.10.17 stuff
[karo-tx-linux.git] / drivers / dma / imx-sdma.c
index 128714622bf5d154a21ad17ff906d1bb17518c2d..14867e3ac8ffadc4f2c803d1c927fd33dc46d189 100644 (file)
@@ -255,6 +255,7 @@ struct sdma_channel {
        enum dma_slave_buswidth         word_size;
        unsigned int                    buf_tail;
        unsigned int                    num_bd;
+       unsigned int                    period_len;
        struct sdma_buffer_descriptor   *bd;
        dma_addr_t                      bd_phys;
        unsigned int                    pc_from_device, pc_to_device;
@@ -592,6 +593,12 @@ static void sdma_event_disable(struct sdma_channel *sdmac, unsigned int event)
 }
 
 static void sdma_handle_channel_loop(struct sdma_channel *sdmac)
+{
+       if (sdmac->desc.callback)
+               sdmac->desc.callback(sdmac->desc.callback_param);
+}
+
+static void sdma_update_channel_loop(struct sdma_channel *sdmac)
 {
        struct sdma_buffer_descriptor *bd;
 
@@ -611,9 +618,6 @@ static void sdma_handle_channel_loop(struct sdma_channel *sdmac)
                bd->mode.status |= BD_DONE;
                sdmac->buf_tail++;
                sdmac->buf_tail %= sdmac->num_bd;
-
-               if (sdmac->desc.callback)
-                       sdmac->desc.callback(sdmac->desc.callback_param);
        }
 }
 
@@ -669,6 +673,9 @@ static irqreturn_t sdma_int_handler(int irq, void *dev_id)
                int channel = fls(stat) - 1;
                struct sdma_channel *sdmac = &sdma->channel[channel];
 
+               if (sdmac->flags & IMX_DMA_SG_LOOP)
+                       sdma_update_channel_loop(sdmac);
+
                tasklet_schedule(&sdmac->tasklet);
 
                __clear_bit(channel, &stat);
@@ -1129,6 +1136,7 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic(
        sdmac->status = DMA_IN_PROGRESS;
 
        sdmac->buf_tail = 0;
+       sdmac->period_len = period_len;
 
        sdmac->flags |= IMX_DMA_SG_LOOP;
        sdmac->direction = direction;
@@ -1225,9 +1233,15 @@ static enum dma_status sdma_tx_status(struct dma_chan *chan,
                                      struct dma_tx_state *txstate)
 {
        struct sdma_channel *sdmac = to_sdma_chan(chan);
+       u32 residue;
+
+       if (sdmac->flags & IMX_DMA_SG_LOOP)
+               residue = (sdmac->num_bd - sdmac->buf_tail) * sdmac->period_len;
+       else
+               residue = sdmac->chn_count - sdmac->chn_real_count;
 
        dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie,
-                       sdmac->chn_count - sdmac->chn_real_count);
+                        residue);
 
        return sdmac->status;
 }