Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/gerg/m68knommu
[pandora-kernel.git] / drivers / dma / shdma.c
index 727f51e..dcc1b21 100644 (file)
@@ -1077,7 +1077,6 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
        struct sh_dmae_pdata *pdata = pdev->dev.platform_data;
        unsigned long irqflags = IRQF_DISABLED,
                chan_flag[SH_DMAC_MAX_CHANNELS] = {};
-       unsigned long flags;
        int errirq, chan_irq[SH_DMAC_MAX_CHANNELS];
        int err, i, irq_cnt = 0, irqres = 0;
        struct sh_dmae_device *shdev;
@@ -1143,9 +1142,9 @@ static int __init sh_dmae_probe(struct platform_device *pdev)
        pm_runtime_enable(&pdev->dev);
        pm_runtime_get_sync(&pdev->dev);
 
-       spin_lock_irqsave(&sh_dmae_lock, flags);
+       spin_lock_irq(&sh_dmae_lock);
        list_add_tail_rcu(&shdev->node, &sh_dmae_devices);
-       spin_unlock_irqrestore(&sh_dmae_lock, flags);
+       spin_unlock_irq(&sh_dmae_lock);
 
        /* reset dma controller - only needed as a test */
        err = sh_dmae_rst(shdev);
@@ -1250,15 +1249,18 @@ eirqres:
 eirq_err:
 #endif
 rst_err:
-       spin_lock_irqsave(&sh_dmae_lock, flags);
+       spin_lock_irq(&sh_dmae_lock);
        list_del_rcu(&shdev->node);
-       spin_unlock_irqrestore(&sh_dmae_lock, flags);
+       spin_unlock_irq(&sh_dmae_lock);
 
        pm_runtime_put(&pdev->dev);
+       pm_runtime_disable(&pdev->dev);
+
        if (dmars)
                iounmap(shdev->dmars);
 emapdmars:
        iounmap(shdev->chan_reg);
+       synchronize_rcu();
 emapchan:
        kfree(shdev);
 ealloc:
@@ -1274,7 +1276,6 @@ static int __exit sh_dmae_remove(struct platform_device *pdev)
 {
        struct sh_dmae_device *shdev = platform_get_drvdata(pdev);
        struct resource *res;
-       unsigned long flags;
        int errirq = platform_get_irq(pdev, 0);
 
        dma_async_device_unregister(&shdev->common);
@@ -1282,9 +1283,9 @@ static int __exit sh_dmae_remove(struct platform_device *pdev)
        if (errirq > 0)
                free_irq(errirq, shdev);
 
-       spin_lock_irqsave(&sh_dmae_lock, flags);
+       spin_lock_irq(&sh_dmae_lock);
        list_del_rcu(&shdev->node);
-       spin_unlock_irqrestore(&sh_dmae_lock, flags);
+       spin_unlock_irq(&sh_dmae_lock);
 
        /* channel data remove */
        sh_dmae_chan_remove(shdev);
@@ -1295,6 +1296,7 @@ static int __exit sh_dmae_remove(struct platform_device *pdev)
                iounmap(shdev->dmars);
        iounmap(shdev->chan_reg);
 
+       synchronize_rcu();
        kfree(shdev);
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1313,12 +1315,78 @@ static void sh_dmae_shutdown(struct platform_device *pdev)
        sh_dmae_ctl_stop(shdev);
 }
 
+static int sh_dmae_runtime_suspend(struct device *dev)
+{
+       return 0;
+}
+
+static int sh_dmae_runtime_resume(struct device *dev)
+{
+       struct sh_dmae_device *shdev = dev_get_drvdata(dev);
+
+       return sh_dmae_rst(shdev);
+}
+
+#ifdef CONFIG_PM
+static int sh_dmae_suspend(struct device *dev)
+{
+       struct sh_dmae_device *shdev = dev_get_drvdata(dev);
+       int i;
+
+       for (i = 0; i < shdev->pdata->channel_num; i++) {
+               struct sh_dmae_chan *sh_chan = shdev->chan[i];
+               if (sh_chan->descs_allocated)
+                       sh_chan->pm_error = pm_runtime_put_sync(dev);
+       }
+
+       return 0;
+}
+
+static int sh_dmae_resume(struct device *dev)
+{
+       struct sh_dmae_device *shdev = dev_get_drvdata(dev);
+       int i;
+
+       for (i = 0; i < shdev->pdata->channel_num; i++) {
+               struct sh_dmae_chan *sh_chan = shdev->chan[i];
+               struct sh_dmae_slave *param = sh_chan->common.private;
+
+               if (!sh_chan->descs_allocated)
+                       continue;
+
+               if (!sh_chan->pm_error)
+                       pm_runtime_get_sync(dev);
+
+               if (param) {
+                       const struct sh_dmae_slave_config *cfg = param->config;
+                       dmae_set_dmars(sh_chan, cfg->mid_rid);
+                       dmae_set_chcr(sh_chan, cfg->chcr);
+               } else {
+                       dmae_init(sh_chan);
+               }
+       }
+
+       return 0;
+}
+#else
+#define sh_dmae_suspend NULL
+#define sh_dmae_resume NULL
+#endif
+
+const struct dev_pm_ops sh_dmae_pm = {
+       .suspend                = sh_dmae_suspend,
+       .resume                 = sh_dmae_resume,
+       .runtime_suspend        = sh_dmae_runtime_suspend,
+       .runtime_resume         = sh_dmae_runtime_resume,
+};
+
 static struct platform_driver sh_dmae_driver = {
        .remove         = __exit_p(sh_dmae_remove),
        .shutdown       = sh_dmae_shutdown,
        .driver = {
                .owner  = THIS_MODULE,
                .name   = "sh-dma-engine",
+               .pm     = &sh_dmae_pm,
        },
 };