Merge tag 'armsoc-cleanup' of git://git.kernel.org/pub/scm/linux/kernel/git/arm/arm-soc
[deliverable/linux.git] / drivers / dma / pxa_dma.c
index 77c1c44009d87115f2c44d5fd698dc8a1626ec51..dc7850a422b8d4212495d067c4ea31c26e0af8a2 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/of_device.h>
 #include <linux/of_dma.h>
 #include <linux/of.h>
+#include <linux/wait.h>
 #include <linux/dma/pxa-dma.h>
 
 #include "dmaengine.h"
@@ -117,6 +118,9 @@ struct pxad_chan {
        /* protected by vc->lock */
        struct pxad_phy         *phy;
        struct dma_pool         *desc_pool;     /* Descriptors pool */
+       dma_cookie_t            bus_error;
+
+       wait_queue_head_t       wq_state;
 };
 
 struct pxad_device {
@@ -317,7 +321,6 @@ static int dbg_open_##name(struct inode *inode, struct file *file) \
        return single_open(file, dbg_show_##name, inode->i_private); \
 } \
 static const struct file_operations dbg_fops_##name = { \
-       .owner          = THIS_MODULE, \
        .open           = dbg_open_##name, \
        .llseek         = seq_lseek, \
        .read           = seq_read, \
@@ -563,6 +566,7 @@ static void pxad_launch_chan(struct pxad_chan *chan,
                        return;
                }
        }
+       chan->bus_error = 0;
 
        /*
         * Program the descriptor's address into the DMA controller,
@@ -570,6 +574,7 @@ static void pxad_launch_chan(struct pxad_chan *chan,
         */
        phy_writel(chan->phy, desc->first, DDADR);
        phy_enable(chan->phy, chan->misaligned);
+       wake_up(&chan->wq_state);
 }
 
 static void set_updater_desc(struct pxad_desc_sw *sw_desc,
@@ -666,6 +671,7 @@ static irqreturn_t pxad_chan_handler(int irq, void *dev_id)
        struct virt_dma_desc *vd, *tmp;
        unsigned int dcsr;
        unsigned long flags;
+       dma_cookie_t last_started = 0;
 
        BUG_ON(!chan);
 
@@ -678,6 +684,7 @@ static irqreturn_t pxad_chan_handler(int irq, void *dev_id)
                dev_dbg(&chan->vc.chan.dev->device,
                        "%s(): checking txd %p[%x]: completed=%d\n",
                        __func__, vd, vd->tx.cookie, is_desc_completed(vd));
+               last_started = vd->tx.cookie;
                if (to_pxad_sw_desc(vd)->cyclic) {
                        vchan_cyclic_callback(vd);
                        break;
@@ -690,7 +697,12 @@ static irqreturn_t pxad_chan_handler(int irq, void *dev_id)
                }
        }
 
-       if (dcsr & PXA_DCSR_STOPSTATE) {
+       if (dcsr & PXA_DCSR_BUSERR) {
+               chan->bus_error = last_started;
+               phy_disable(phy);
+       }
+
+       if (!chan->bus_error && dcsr & PXA_DCSR_STOPSTATE) {
                dev_dbg(&chan->vc.chan.dev->device,
                "%s(): channel stopped, submitted_empty=%d issued_empty=%d",
                        __func__,
@@ -708,6 +720,7 @@ static irqreturn_t pxad_chan_handler(int irq, void *dev_id)
                }
        }
        spin_unlock_irqrestore(&chan->vc.lock, flags);
+       wake_up(&chan->wq_state);
 
        return IRQ_HANDLED;
 }
@@ -1249,6 +1262,9 @@ static enum dma_status pxad_tx_status(struct dma_chan *dchan,
        struct pxad_chan *chan = to_pxad_chan(dchan);
        enum dma_status ret;
 
+       if (cookie == chan->bus_error)
+               return DMA_ERROR;
+
        ret = dma_cookie_status(dchan, cookie, txstate);
        if (likely(txstate && (ret != DMA_ERROR)))
                dma_set_residue(txstate, pxad_residue(chan, cookie));
@@ -1256,6 +1272,14 @@ static enum dma_status pxad_tx_status(struct dma_chan *dchan,
        return ret;
 }
 
+static void pxad_synchronize(struct dma_chan *dchan)
+{
+       struct pxad_chan *chan = to_pxad_chan(dchan);
+
+       wait_event(chan->wq_state, !is_chan_running(chan));
+       vchan_synchronize(&chan->vc);
+}
+
 static void pxad_free_channels(struct dma_device *dmadev)
 {
        struct pxad_chan *c, *cn;
@@ -1321,7 +1345,7 @@ static int pxad_init_phys(struct platform_device *op,
        return 0;
 }
 
-static const struct of_device_id const pxad_dt_ids[] = {
+static const struct of_device_id pxad_dt_ids[] = {
        { .compatible = "marvell,pdma-1.0", },
        {}
 };
@@ -1360,6 +1384,7 @@ static int pxad_init_dmadev(struct platform_device *op,
        pdev->slave.device_tx_status = pxad_tx_status;
        pdev->slave.device_issue_pending = pxad_issue_pending;
        pdev->slave.device_config = pxad_config;
+       pdev->slave.device_synchronize = pxad_synchronize;
        pdev->slave.device_terminate_all = pxad_terminate_all;
 
        if (op->dev.coherent_dma_mask)
@@ -1377,6 +1402,7 @@ static int pxad_init_dmadev(struct platform_device *op,
                        return -ENOMEM;
                c->vc.desc_free = pxad_free_desc;
                vchan_init(&c->vc, &pdev->slave);
+               init_waitqueue_head(&c->wq_state);
        }
 
        return dma_async_device_register(&pdev->slave);
This page took 0.029066 seconds and 5 git commands to generate.