linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw-KKrjLPT3xs0@public.gmane.org>
To: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: Mark Brown
	<broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>,
	Linux I2C <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	pm list
	<linux-pm-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Subject: [PATCH] i2c: Use generic subsystem-level power management callbacks
Date: Sat, 13 Mar 2010 22:04:30 +0100	[thread overview]
Message-ID: <201003132204.30905.rjw@sisk.pl> (raw)

From: Rafael J. Wysocki <rjw-KKrjLPT3xs0@public.gmane.org>

There are three issues with the i2c's power management callbacks at
the moment.  First, they don't include any hibernate callbacks,
although they should at least include the .restore() callback
(there's no guarantee that the driver will be in memory before
loading the image kernel and we must restore the pre-hibernation
state of the device).  Second, the "legacy" callbacks are not going
to be invoked by the PM core since the bus type's pm object is not
NULL.  Finally, the system power transition (ie. suspend/resume)
callbacks don't check if the device hasn't been already suspended
at run time, in which case they should skip suspending it and
handle it in a special way during resume.  Also, it looks like the
i2c bus type itself doesn't need any power management handling beyond
that provided by the generic subsystem-level PM callbacks.

For these reasons, remove the power management callbacks defined by
the i2c bus type and make it use the generic subsystem-level power
management callbacks.

Signed-off-by: Rafael J. Wysocki <rjw-KKrjLPT3xs0@public.gmane.org>
---
Jean,

I know I said I wanted to implement the generic callbacks later, but they
were implemented in the meantime anyway, so I think we can use them now.

Please note that the "legacy" callbacks removed by this patch are already
effectively dead, because they are not going to be called by the PM core
anyway.  I'm not sure if this is what we want, though, so please let me know
in case it's not.

Thanks,
Rafael
---
 drivers/i2c/i2c-core.c |  113 -------------------------------------------------
 1 file changed, 1 insertion(+), 112 deletions(-)

Index: linux-2.6/drivers/i2c/i2c-core.c
===================================================================
--- linux-2.6.orig/drivers/i2c/i2c-core.c
+++ linux-2.6/drivers/i2c/i2c-core.c
@@ -156,107 +156,6 @@ static void i2c_device_shutdown(struct d
 		driver->shutdown(client);
 }
 
-#ifdef CONFIG_SUSPEND
-static int i2c_device_pm_suspend(struct device *dev)
-{
-	const struct dev_pm_ops *pm;
-
-	if (!dev->driver)
-		return 0;
-	pm = dev->driver->pm;
-	if (!pm || !pm->suspend)
-		return 0;
-	return pm->suspend(dev);
-}
-
-static int i2c_device_pm_resume(struct device *dev)
-{
-	const struct dev_pm_ops *pm;
-
-	if (!dev->driver)
-		return 0;
-	pm = dev->driver->pm;
-	if (!pm || !pm->resume)
-		return 0;
-	return pm->resume(dev);
-}
-#else
-#define i2c_device_pm_suspend	NULL
-#define i2c_device_pm_resume	NULL
-#endif
-
-#ifdef CONFIG_PM_RUNTIME
-static int i2c_device_runtime_suspend(struct device *dev)
-{
-	const struct dev_pm_ops *pm;
-
-	if (!dev->driver)
-		return 0;
-	pm = dev->driver->pm;
-	if (!pm || !pm->runtime_suspend)
-		return 0;
-	return pm->runtime_suspend(dev);
-}
-
-static int i2c_device_runtime_resume(struct device *dev)
-{
-	const struct dev_pm_ops *pm;
-
-	if (!dev->driver)
-		return 0;
-	pm = dev->driver->pm;
-	if (!pm || !pm->runtime_resume)
-		return 0;
-	return pm->runtime_resume(dev);
-}
-
-static int i2c_device_runtime_idle(struct device *dev)
-{
-	const struct dev_pm_ops *pm = NULL;
-	int ret;
-
-	if (dev->driver)
-		pm = dev->driver->pm;
-	if (pm && pm->runtime_idle) {
-		ret = pm->runtime_idle(dev);
-		if (ret)
-			return ret;
-	}
-
-	return pm_runtime_suspend(dev);
-}
-#else
-#define i2c_device_runtime_suspend	NULL
-#define i2c_device_runtime_resume	NULL
-#define i2c_device_runtime_idle		NULL
-#endif
-
-static int i2c_device_suspend(struct device *dev, pm_message_t mesg)
-{
-	struct i2c_client *client = i2c_verify_client(dev);
-	struct i2c_driver *driver;
-
-	if (!client || !dev->driver)
-		return 0;
-	driver = to_i2c_driver(dev->driver);
-	if (!driver->suspend)
-		return 0;
-	return driver->suspend(client, mesg);
-}
-
-static int i2c_device_resume(struct device *dev)
-{
-	struct i2c_client *client = i2c_verify_client(dev);
-	struct i2c_driver *driver;
-
-	if (!client || !dev->driver)
-		return 0;
-	driver = to_i2c_driver(dev->driver);
-	if (!driver->resume)
-		return 0;
-	return driver->resume(client);
-}
-
 static void i2c_client_dev_release(struct device *dev)
 {
 	kfree(to_i2c_client(dev));
@@ -295,23 +194,13 @@ static const struct attribute_group *i2c
 	NULL
 };
 
-static const struct dev_pm_ops i2c_device_pm_ops = {
-	.suspend = i2c_device_pm_suspend,
-	.resume = i2c_device_pm_resume,
-	.runtime_suspend = i2c_device_runtime_suspend,
-	.runtime_resume = i2c_device_runtime_resume,
-	.runtime_idle = i2c_device_runtime_idle,
-};
-
 struct bus_type i2c_bus_type = {
 	.name		= "i2c",
 	.match		= i2c_device_match,
 	.probe		= i2c_device_probe,
 	.remove		= i2c_device_remove,
 	.shutdown	= i2c_device_shutdown,
-	.suspend	= i2c_device_suspend,
-	.resume		= i2c_device_resume,
-	.pm		= &i2c_device_pm_ops,
+	.pm		= GENERIC_SUBSYS_PM_OPS,
 };
 EXPORT_SYMBOL_GPL(i2c_bus_type);
 

             reply	other threads:[~2010-03-13 21:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-13 21:04 Rafael J. Wysocki [this message]
     [not found] ` <201003132204.30905.rjw-KKrjLPT3xs0@public.gmane.org>
2010-03-13 21:34   ` [linux-pm] [PATCH] i2c: Use generic subsystem-level power management callbacks Alan Stern
     [not found]     ` <Pine.LNX.4.44L0.1003131627270.19476-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2010-03-14 19:58       ` Rafael J. Wysocki
     [not found]         ` <201003142058.45981.rjw-KKrjLPT3xs0@public.gmane.org>
2010-03-14 20:26           ` Alan Stern
     [not found]             ` <Pine.LNX.4.44L0.1003141620540.1752-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2010-03-14 22:52               ` Rafael J. Wysocki
     [not found]                 ` <201003142352.50692.rjw-KKrjLPT3xs0@public.gmane.org>
2010-03-15  1:28                   ` Alan Stern
     [not found]                     ` <Pine.LNX.4.44L0.1003142117200.7108-100000-pYrvlCTfrz9XsRXLowluHWD2FQJk+8+b@public.gmane.org>
2010-03-15 19:34                       ` Rafael J. Wysocki
     [not found]                         ` <201003152034.12195.rjw-KKrjLPT3xs0@public.gmane.org>
2010-03-15 20:38                           ` Alan Stern
     [not found]                             ` <Pine.LNX.4.44L0.1003151630370.1332-100000-IYeN2dnnYyZXsRXLowluHWD2FQJk+8+b@public.gmane.org>
2010-03-15 22:06                               ` Rafael J. Wysocki
2010-03-19 22:44   ` [PATCH] i2c: Fix bus-level " Rafael J. Wysocki
     [not found]     ` <201003192344.09000.rjw-KKrjLPT3xs0@public.gmane.org>
2010-03-25  8:57       ` Jean Delvare
     [not found]         ` <20100325095720.0b115056-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-03-25  9:28           ` Mark Brown
     [not found]             ` <20100325092802.GA27729-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
2010-03-25 20:16               ` Rafael J. Wysocki

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=201003132204.30905.rjw@sisk.pl \
    --to=rjw-kkrjlpt3xs0@public.gmane.org \
    --cc=broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
    --cc=khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-pm-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@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).