---
 drivers/spi/dw_spi.c       |   24 ++++++++----------
 drivers/spi/dw_spi_pci.c   |   58 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/spi/dw_spi.h |    1 +
 3 files changed, 70 insertions(+), 13 deletions(-)

diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index 4f29488..0663d13 100644
--- a/drivers/spi/dw_spi.c
+++ b/drivers/spi/dw_spi.c
@@ -22,6 +22,7 @@
 #include <linux/highmem.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 
 #include <linux/spi/dw_spi.h>
 #include <linux/spi/spi.h>
@@ -291,6 +292,8 @@ static void giveback(struct dw_spi *dws)
        msg->state = NULL;
        if (msg->complete)
                msg->complete(msg->context);
+
+       pm_runtime_put(dws->parent_dev);
 }
 
 static void int_error_stop(struct dw_spi *dws, const char *msg)
@@ -598,12 +601,9 @@ static int dw_spi_transfer(struct spi_device *spi, struct 
spi_message *msg)
        struct dw_spi *dws = spi_master_get_devdata(spi->master);
        unsigned long flags;
 
-       spin_lock_irqsave(&dws->lock, flags);
+       pm_runtime_get(dws->parent_dev);
 
-       if (dws->run == QUEUE_STOPPED) {
-               spin_unlock_irqrestore(&dws->lock, flags);
-               return -ESHUTDOWN;
-       }
+       spin_lock_irqsave(&dws->lock, flags);
 
        msg->actual_length = 0;
        msg->status = -EINPROGRESS;
@@ -622,7 +622,8 @@ static int dw_spi_transfer(struct spi_device *spi, struct 
spi_message *msg)
                        pump_messages(&dws->pump_messages);
                        return 0;
                }
-       }
+       } else
+               queue_work(dws->workqueue, &dws->pump_messages);
 
        spin_unlock_irqrestore(&dws->lock, flags);
        return 0;
@@ -733,10 +734,6 @@ static int start_queue(struct dw_spi *dws)
        }
 
        dws->run = QUEUE_RUNNING;
-       dws->cur_msg = NULL;
-       dws->cur_transfer = NULL;
-       dws->cur_chip = NULL;
-       dws->prev_chip = NULL;
        spin_unlock_irqrestore(&dws->lock, flags);
 
        queue_work(dws->workqueue, &dws->pump_messages);
@@ -744,7 +741,7 @@ static int start_queue(struct dw_spi *dws)
        return 0;
 }
 
-static int stop_queue(struct dw_spi *dws)
+int dw_spi_stop_queue(struct dw_spi *dws)
 {
        unsigned long flags;
        unsigned limit = 50;
@@ -764,12 +761,13 @@ static int stop_queue(struct dw_spi *dws)
 
        return status;
 }
+EXPORT_SYMBOL_GPL(dw_spi_stop_queue);
 
 static int destroy_queue(struct dw_spi *dws)
 {
        int status;
 
-       status = stop_queue(dws);
+       status = dw_spi_stop_queue(dws);
        if (status != 0)
                return status;
        destroy_workqueue(dws->workqueue);
@@ -910,7 +908,7 @@ int dw_spi_suspend_host(struct dw_spi *dws)
 {
        int ret = 0;
 
-       ret = stop_queue(dws);
+       ret = dw_spi_stop_queue(dws);
        if (ret)
                return ret;
        spi_enable_chip(dws, 0);
diff --git a/drivers/spi/dw_spi_pci.c b/drivers/spi/dw_spi_pci.c
index 076d1f8..97bbfe1 100644
--- a/drivers/spi/dw_spi_pci.c
+++ b/drivers/spi/dw_spi_pci.c
@@ -20,6 +20,7 @@
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/slab.h>
+#include <linux/pm_runtime.h>
 #include <linux/spi/dw_spi.h>
 #include <linux/spi/spi.h>
 
@@ -86,6 +87,11 @@ static int __devinit spi_pci_probe(struct pci_dev *pdev,
 
        /* PCI hook and SPI hook use the same drv data */
        pci_set_drvdata(pdev, dwpci);
+
+       pm_suspend_ignore_children(&pdev->dev, true);
+       pm_runtime_put_noidle(&pdev->dev);
+       pm_runtime_allow(&pdev->dev);
+
        return 0;
 
 err_unmap:
@@ -104,6 +110,10 @@ static void __devexit spi_pci_remove(struct pci_dev *pdev)
        struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
 
        pci_set_drvdata(pdev, NULL);
+
+       pm_runtime_forbid(&pdev->dev);
+       pm_runtime_get_noresume(&pdev->dev);
+
        dw_spi_remove_host(&dwpci->dws);
        iounmap(dwpci->dws.regs);
        pci_release_region(pdev, 0);
@@ -138,9 +148,49 @@ static int spi_resume(struct pci_dev *pdev)
                return ret;
        return dw_spi_resume_host(&dwpci->dws);
 }
+
+static int spi_dw_pci_runtime_suspend(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
+       int ret;
+
+       dev_dbg(dev, "PCI runtime suspend called\n");
+
+       ret = dw_spi_stop_queue(&dwpci->dws);
+       if (ret == 0)
+               spi_enable_chip(&dwpci->dws, 0);
+
+       return ret;
+}
+
+static int spi_dw_pci_runtime_resume(struct device *dev)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
+
+       dev_dbg(dev, "pci_runtime_resume called\n");
+       return dw_spi_resume_host(&dwpci->dws);
+}
+
+static int spi_dw_pci_runtime_idle(struct device *dev)
+{
+       int err;
+
+       dev_dbg(dev, "pci_runtime_idle called\n");
+
+       err = pm_schedule_suspend(dev, 500);
+       if (err != 0)
+               return 0;
+       return -EBUSY;
+}
+
 #else
 #define spi_suspend    NULL
 #define spi_resume     NULL
+#define spi_dw_pci_runtime_suspend NULL
+#define spi_dw_pci_runtime_resume NULL
+#define spi_dw_pci_runtime_idle NULL
 #endif
 
 static const struct pci_device_id pci_ids[] __devinitdata = {
@@ -148,6 +198,11 @@ static const struct pci_device_id pci_ids[] __devinitdata 
= {
        { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
        {},
 };
+static const struct dev_pm_ops dw_spi_pm_ops = {
+       .runtime_suspend = spi_dw_pci_runtime_suspend,
+       .runtime_resume = spi_dw_pci_runtime_resume,
+       .runtime_idle = spi_dw_pci_runtime_idle,
+};
 
 static struct pci_driver dw_spi_driver = {
        .name =         DRIVER_NAME,
@@ -156,6 +211,9 @@ static struct pci_driver dw_spi_driver = {
        .remove =       __devexit_p(spi_pci_remove),
        .suspend =      spi_suspend,
        .resume =       spi_resume,
+       .driver =       {
+               .pm     = &dw_spi_pm_ops,
+       },
 };
 
 static int __init mrst_spi_init(void)
diff --git a/include/linux/spi/dw_spi.h b/include/linux/spi/dw_spi.h
index c74969a..5c978e4 100644
--- a/include/linux/spi/dw_spi.h
+++ b/include/linux/spi/dw_spi.h
@@ -225,6 +225,7 @@ extern void dw_spi_remove_host(struct dw_spi *dws);
 extern int dw_spi_suspend_host(struct dw_spi *dws);
 extern int dw_spi_resume_host(struct dw_spi *dws);
 extern void dw_spi_xfer_done(struct dw_spi *dws);
+extern int dw_spi_stop_queue(struct dw_spi *dws);
 
 /* platform related setup */
 extern int dw_spi_mid_init(struct dw_spi *dws); /* Intel MID platforms */
-- 
1.7.3.1

_______________________________________________
MeeGo-kernel mailing list
[email protected]
http://lists.meego.com/listinfo/meego-kernel

Reply via email to