From patchwork Wed Jun 15 17:23:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dirk.brandewie@gmail.com X-Patchwork-Id: 882812 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5FHNtG5015370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 15 Jun 2011 17:24:16 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QWton-00024U-4w; Wed, 15 Jun 2011 17:23:53 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1QWtom-00024P-9o for spi-devel-general@lists.sourceforge.net; Wed, 15 Jun 2011 17:23:52 +0000 Received-SPF: pass (sog-mx-1.v43.ch3.sourceforge.com: domain of gmail.com designates 74.125.83.175 as permitted sender) client-ip=74.125.83.175; envelope-from=dirk.brandewie@gmail.com; helo=mail-pv0-f175.google.com; Received: from mail-pv0-f175.google.com ([74.125.83.175]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:RC4-SHA:128) (Exim 4.76) id 1QWtol-00047W-GP for spi-devel-general@lists.sourceforge.net; Wed, 15 Jun 2011 17:23:52 +0000 Received: by pvc30 with SMTP id 30so656400pvc.34 for ; Wed, 15 Jun 2011 10:23:45 -0700 (PDT) Received: by 10.68.17.38 with SMTP id l6mr569070pbd.174.1308158625606; Wed, 15 Jun 2011 10:23:45 -0700 (PDT) Received: from localhost.localdomain (static-50-43-44-248.bvtn.or.frontiernet.net [50.43.44.248]) by mx.google.com with ESMTPS id f3sm365872pbj.80.2011.06.15.10.23.44 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 15 Jun 2011 10:23:45 -0700 (PDT) From: dirk.brandewie@gmail.com To: linux-kernel@vger.kernel.org, spi-devel-general@lists.sourceforge.net Subject: [PATCH 5/5] spi_dw_pci: Add runtime power management Date: Wed, 15 Jun 2011 10:23:08 -0700 Message-Id: <1308158588-17249-6-git-send-email-dirk.brandewie@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1308158588-17249-1-git-send-email-dirk.brandewie@gmail.com> References: <1308158588-17249-1-git-send-email-dirk.brandewie@gmail.com> X-Spam-Score: -1.6 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain 0.0 FREEMAIL_FROM Sender email is freemail (dirk.brandewie[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.0 RFC_ABUSE_POST Both abuse and postmaster missing on sender domain 0.0 T_TO_NO_BRKTS_FREEMAIL T_TO_NO_BRKTS_FREEMAIL -0.0 AWL AWL: From: address is in the auto white-list X-Headers-End: 1QWtol-00047W-GP Cc: Dirk Brandewie , Kristen Carlson Accardi X-BeenThere: spi-devel-general@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Linux SPI core/device drivers discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: spi-devel-general-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 15 Jun 2011 17:24:16 +0000 (UTC) From: Dirk Brandewie This patch adds runtime power management to the PCI variant of the designware SPI host controller driver. Signed-off-by: Kristen Carlson Accardi Signed-off-by: Dirk Brandewie --- drivers/spi/spi-dw-pci.c | 59 +++++++++++++++++++++++++++++++++++++++++++++- drivers/spi/spi-dw.c | 4 ++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c index eb35fa5..d661c2a 100644 --- a/drivers/spi/spi-dw-pci.c +++ b/drivers/spi/spi-dw-pci.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "spi-dw.h" @@ -91,6 +92,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: @@ -110,6 +116,9 @@ static void __devexit spi_pci_remove(struct pci_dev *pdev) pci_set_drvdata(pdev, NULL); spi_dw_remove_host(&dwpci->dws); + pm_runtime_forbid(&pdev->dev); + pm_runtime_get_noresume(&pdev->dev); + iounmap(dwpci->dws.regs); pci_release_region(pdev, 0); kfree(dwpci); @@ -143,16 +152,61 @@ static int spi_resume(struct pci_dev *pdev) return ret; return spi_dw_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 = spi_dw_stop_queue(&dwpci->dws); + if (ret == 0) + spi_dw_enable(&dwpci->dws); + + 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 spi_dw_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 = { - /* Intel MID platform SPI controller 0 */ + /* Intel Moorestown platform SPI controller 0 */ { 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, @@ -161,6 +215,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/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 20f94fa..1210460 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include "spi-dw.h" @@ -438,7 +439,7 @@ static void pump_messages(struct work_struct *work) struct slave_cfg *controller; int err = 0; - + pm_runtime_get_sync(dws->parent_dev); message = get_message(dws); while (message && dws->run != QUEUE_STOPPED) { @@ -473,6 +474,7 @@ static void pump_messages(struct work_struct *work) } if (dws->run == QUEUE_STOPPED) drain_message_queue(dws); + pm_runtime_put_sync(dws->parent_dev); } /* spi_device use this to queue in their spi_msg */