From: dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH 12/13] i2c-designware: Add runtime power management support
Date: Sat, 12 Mar 2011 12:23:26 -0800 [thread overview]
Message-ID: <1299961407-26852-13-git-send-email-dirk.brandewie@gmail.com> (raw)
In-Reply-To: <1299961407-26852-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
From: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Add runtime power management to the PCI driver.
Signed-off-by: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
drivers/i2c/busses/i2c-designware-core.c | 10 +++-
drivers/i2c/busses/i2c-designware-core.h | 1 +
drivers/i2c/busses/i2c-designware-pcidrv.c | 89 ++++++++++++++++++++++++++++
3 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index b22a2c5..299e717 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -31,6 +31,7 @@
#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/io.h>
+#include <linux/pm_runtime.h>
#include "i2c-designware-core.h"
/*
@@ -500,6 +501,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
dev_dbg(dev->dev, "%s: msgs: %d\n", __func__, num);
mutex_lock(&dev->lock);
+ pm_runtime_get_sync(dev->dev);
INIT_COMPLETION(dev->cmd_complete);
dev->msgs = msgs;
@@ -549,6 +551,7 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
ret = -EIO;
done:
+ pm_runtime_put(dev->dev);
mutex_unlock(&dev->lock);
return ret;
@@ -670,10 +673,13 @@ void i2c_dw_enable(struct dw_i2c_dev *dev)
dw_writel(dev, 1, DW_IC_ENABLE);
}
-void i2c_dw_disable(struct dw_i2c_dev *dev)
+u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev)
{
- int ret;
+ return dw_readl(dev, DW_IC_ENABLE);
+}
+void i2c_dw_disable(struct dw_i2c_dev *dev)
+{
/* Disable controller */
dw_writel(dev, 0, DW_IC_ENABLE);
diff --git a/drivers/i2c/busses/i2c-designware-core.h b/drivers/i2c/busses/i2c-designware-core.h
index 6450a6a..4a75888 100644
--- a/drivers/i2c/busses/i2c-designware-core.h
+++ b/drivers/i2c/busses/i2c-designware-core.h
@@ -98,6 +98,7 @@ extern int i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],
extern u32 i2c_dw_func(struct i2c_adapter *adap);
extern irqreturn_t i2c_dw_isr(int this_irq, void *dev_id);
extern void i2c_dw_enable(struct dw_i2c_dev *dev);
+extern u32 i2c_dw_is_enabled(struct dw_i2c_dev *dev);
extern void i2c_dw_disable(struct dw_i2c_dev *dev);
extern void i2c_dw_clear_int(struct dw_i2c_dev *dev);
extern void i2c_dw_disable_int(struct dw_i2c_dev *dev);
diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 83307ef..d2223b5 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -38,6 +38,7 @@
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/pci.h>
+#include <linux/pm_runtime.h>
#include "i2c-designware-core.h"
#define DRIVER_NAME "i2c-designware-pci"
@@ -137,6 +138,82 @@ static struct i2c_algorithm i2c_dw_algo = {
.functionality = i2c_dw_func,
};
+static int i2c_dw_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
+{
+ struct dw_i2c_dev *i2c = pci_get_drvdata(pdev);
+ int err;
+
+
+ i2c_dw_disable(i2c);
+
+ err = pci_save_state(pdev);
+ if (err) {
+ dev_err(&pdev->dev, "pci_save_state failed\n");
+ return err;
+ }
+
+ err = pci_set_power_state(pdev, PCI_D3hot);
+ if (err) {
+ dev_err(&pdev->dev, "pci_set_power_state failed\n");
+ return err;
+ }
+
+ return 0;
+}
+
+static int i2c_dw_pci_runtime_suspend(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ dev_dbg(dev, "PCI suspend called\n");
+ return i2c_dw_pci_suspend(pdev, PMSG_SUSPEND);
+}
+
+static int i2c_dw_pci_resume(struct pci_dev *pdev)
+{
+ struct dw_i2c_dev *i2c = pci_get_drvdata(pdev);
+ int err;
+ u32 enabled;
+
+ enabled = i2c_dw_is_enabled(i2c);
+ if (enabled)
+ return 0;
+
+ err = pci_set_power_state(pdev, PCI_D0);
+ if (err) {
+ dev_err(&pdev->dev, "pci_set_power_state() failed\n");
+ return err;
+ }
+
+ pci_restore_state(pdev);
+
+ i2c_dw_init(i2c);
+ i2c_dw_enable(i2c);
+ return 0;
+}
+
+static int i2c_dw_pci_runtime_resume(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ dev_dbg(dev, "runtime_resume called\n");
+ return i2c_dw_pci_resume(pdev);
+}
+
+static int i2c_dw_pci_runtime_idle(struct device *dev)
+{
+ int err = pm_schedule_suspend(dev, 500);
+ dev_dbg(dev, "runtime_idle called\n");
+
+ if (err != 0)
+ return 0;
+ return -EBUSY;
+}
+
+static const struct dev_pm_ops i2c_dw_pm_ops = {
+ .runtime_suspend = i2c_dw_pci_runtime_suspend,
+ .runtime_resume = i2c_dw_pci_runtime_resume,
+ .runtime_idle = i2c_dw_pci_runtime_idle,
+};
+
static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev)
{
return dev->controller->clk_khz;
@@ -245,6 +322,9 @@ const struct pci_device_id *id)
goto err_free_irq;
}
+ pm_runtime_put_noidle(&pdev->dev);
+ pm_runtime_allow(&pdev->dev);
+
return 0;
err_free_irq:
@@ -264,6 +344,10 @@ static void __devexit i2c_dw_pci_remove(struct pci_dev *pdev)
{
struct dw_i2c_dev *dev = pci_get_drvdata(pdev);
+ i2c_dw_disable(dev);
+ pm_runtime_forbid(&pdev->dev);
+ pm_runtime_get_noresume(&pdev->dev);
+
pci_set_drvdata(pdev, NULL);
i2c_del_adapter(&dev->adapter);
put_device(&pdev->dev);
@@ -297,6 +381,11 @@ static struct pci_driver dw_i2c_driver = {
.id_table = i2_designware_pci_ids,
.probe = i2c_dw_pci_probe,
.remove = __devexit_p(i2c_dw_pci_remove),
+ .resume = i2c_dw_pci_resume,
+ .suspend = i2c_dw_pci_suspend,
+ .driver = {
+ .pm = &i2c_dw_pm_ops,
+ },
};
static int __init dw_i2c_init_driver(void)
--
1.7.3.4
next prev parent reply other threads:[~2011-03-12 20:23 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-12 20:23 [PATCH 00/13] V3 Split i2c-designware.c to support PCI drivers dirk.brandewie
2011-03-12 20:23 ` [PATCH 01/13] i2c-designware: Use local version of readl & writel dirk.brandewie
2011-03-12 20:23 ` [PATCH 03/13] i2c-designware: Allow mixed endianness accesses dirk.brandewie
2011-03-12 20:23 ` [PATCH 05/13] i2c-designware: split of i2c-designware.c into core and bus specific parts dirk.brandewie
[not found] ` <1299961407-26852-6-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-03-12 21:00 ` Randy Dunlap
2011-03-12 20:23 ` [PATCH 07/13] i2c-designware: move i2c functionality bit field to be adapter specific dirk.brandewie
2011-03-12 20:23 ` [PATCH 08/13] i2c-designware: move controller config to bus specific portion of driver dirk.brandewie
2011-03-12 20:23 ` [PATCH 09/13] i2c-designware: Support multiple cores using same ISR dirk.brandewie
2011-03-12 20:23 ` [PATCH 10/13] i2c-designware: Push all register reads/writes into the core code dirk.brandewie
2011-03-12 20:23 ` [PATCH 13/13] i2c-intel-mid.c: Remove i2c-intel-mid.c dirk.brandewie
[not found] ` <1299961407-26852-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-03-12 20:23 ` [PATCH 02/13] i2c-designware: Check component type register dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-03-12 20:23 ` [PATCH 04/13] i2c-designware: Move checking of IP core version to i2c_dw_init() dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-03-12 20:23 ` [PATCH 06/13] i2c-designware: Move retriveving the clock speed out of core code dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-03-12 20:23 ` [PATCH 11/13] i2c-designware: Add support for Designware core behind PCI devices dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-03-12 20:23 ` dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w [this message]
2011-03-14 23:43 ` [PATCH 00/13] V3 Split i2c-designware.c to support PCI drivers Ben Dooks
[not found] ` <20110314234337.GN15795-SMNkleLxa3Z6Wcw2j4pizdi2O/JbrIOy@public.gmane.org>
2011-05-24 22:00 ` Dirk Brandewie
-- strict thread matches above, loose matches on Subject: below --
2011-10-06 18:26 [PATCH 00/13] V5 " dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
[not found] ` <1317925597-32245-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-10-06 18:26 ` [PATCH 12/13] i2c-designware: Add runtime power management support dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-06-09 19:21 [PATCH 00/13] V4 Split i2c-designware.c to support PCI drivers dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
[not found] ` <1307647310-24332-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-06-09 19:21 ` [PATCH 12/13] i2c-designware: Add runtime power management support dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
2011-02-10 16:21 [PATCH 00/13] V2 Split i2c-designware.c to support PCI drivers dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
[not found] ` <1297354889-20721-1-git-send-email-dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2011-02-10 16:21 ` [PATCH 12/13] i2c-designware: Add runtime power management support dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1299961407-26852-13-git-send-email-dirk.brandewie@gmail.com \
--to=dirk.brandewie-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).