---
 drivers/spi/dw_spi.c       |   22 ++++++++---------
 drivers/spi/dw_spi_pci.c   |   54 +++++++++++++++++++++++++++++++++++++++++++-
 include/linux/spi/dw_spi.h |    2 +-
 3 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index 4f29488..c7e3d31 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);
@@ -906,7 +903,7 @@ void __devexit dw_spi_remove_host(struct dw_spi *dws)
 }
 EXPORT_SYMBOL_GPL(dw_spi_remove_host);
 
-int dw_spi_suspend_host(struct dw_spi *dws)
+int dw_spi_suspend_host(struct dw_spi *dws, bool runtime)
 {
        int ret = 0;
 
@@ -914,7 +911,8 @@ int dw_spi_suspend_host(struct dw_spi *dws)
        if (ret)
                return ret;
        spi_enable_chip(dws, 0);
-       spi_set_clk(dws, 0);
+       if (!runtime)
+               spi_set_clk(dws, 0);
        return ret;
 }
 EXPORT_SYMBOL_GPL(dw_spi_suspend_host);
diff --git a/drivers/spi/dw_spi_pci.c b/drivers/spi/dw_spi_pci.c
index 076d1f8..c4da64b 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);
@@ -117,7 +127,7 @@ static int spi_suspend(struct pci_dev *pdev, pm_message_t 
state)
        struct dw_spi_pci *dwpci = pci_get_drvdata(pdev);
        int ret;
 
-       ret = dw_spi_suspend_host(&dwpci->dws);
+       ret = dw_spi_suspend_host(&dwpci->dws, false);
        if (ret)
                return ret;
        pci_save_state(pdev);
@@ -138,9 +148,43 @@ 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);
+
+       dev_dbg(dev, "PCI runtime suspend called\n");
+       return dw_spi_suspend_host(&dwpci->dws, false);
+}
+
+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 +192,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 +205,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..76745c3 100644
--- a/include/linux/spi/dw_spi.h
+++ b/include/linux/spi/dw_spi.h
@@ -222,7 +222,7 @@ struct dw_spi_chip {
 
 extern int dw_spi_add_host(struct dw_spi *dws);
 extern void dw_spi_remove_host(struct dw_spi *dws);
-extern int dw_spi_suspend_host(struct dw_spi *dws);
+extern int dw_spi_suspend_host(struct dw_spi *dws, bool runtime);
 extern int dw_spi_resume_host(struct dw_spi *dws);
 extern void dw_spi_xfer_done(struct dw_spi *dws);
 
-- 
1.7.3.1

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

Reply via email to