All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: Hook up runtime PM support
@ 2010-02-03 13:22 Mark Brown
  2010-02-04 21:57 ` Rafael J. Wysocki
       [not found] ` <1265203367-21344-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-03 13:22 UTC (permalink / raw)
  To: Jean Delvare
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, Rafael J. Wysocki, Mark Brown

Allow I2C drivers to make use of the runtime PM framework by adding
bus implementations of the runtime PM operations. These simply
immediately suspend when the device is idle. The runtime PM framework
provides drivers with off the shelf refcounts for enables and sysfs
control for managing runtime suspend from userspace so is useful even
without meaningful input from the bus.

Signed-off-by: Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
 drivers/i2c/i2c-core.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 10be7b5..985eaac 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -34,6 +34,7 @@
 #include <linux/hardirq.h>
 #include <linux/irqflags.h>
 #include <linux/rwsem.h>
+#include <linux/pm_runtime.h>
 #include <asm/uaccess.h>
 
 #include "i2c-core.h"
@@ -184,6 +185,43 @@ static int i2c_device_pm_resume(struct device *dev)
 #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)
+{
+	/* I2C devices are very independent of each other so we
+	 * suspend them immediately. */
+	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);
@@ -251,6 +289,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
 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 = {
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found] ` <1265203367-21344-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2010-02-04 21:57   ` Rafael J. Wysocki
  2010-02-05 10:39     ` Mark Brown
       [not found]     ` <201002042257.27145.rjw-KKrjLPT3xs0@public.gmane.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-04 21:57 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jean Delvare, linux-i2c-u79uwXL29TY76Z2rM5mHXA, pm list,
	Alan Stern, Matthew Garrett

On Wednesday 03 February 2010, Mark Brown wrote:
> Allow I2C drivers to make use of the runtime PM framework by adding
> bus implementations of the runtime PM operations. These simply
> immediately suspend when the device is idle.

Perhaps it would be a good idea to give the driver a chance to veto
the suspend by calling its _idle callback?  We do that for PCI and turns out to
be quite useful.

> The runtime PM framework provides drivers with off the shelf refcounts for
> enables and sysfs control for managing runtime suspend from userspace so is
> useful even without meaningful input from the bus.
> 
> Signed-off-by: Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
> ---
>  drivers/i2c/i2c-core.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 10be7b5..985eaac 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/hardirq.h>
>  #include <linux/irqflags.h>
>  #include <linux/rwsem.h>
> +#include <linux/pm_runtime.h>
>  #include <asm/uaccess.h>
>  
>  #include "i2c-core.h"
> @@ -184,6 +185,43 @@ static int i2c_device_pm_resume(struct device *dev)
>  #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)
> +{
> +	/* I2C devices are very independent of each other so we
> +	 * suspend them immediately. */
> +	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);
> @@ -251,6 +289,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
>  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 = {
> 

Rafael

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
  2010-02-03 13:22 [PATCH] i2c: Hook up runtime PM support Mark Brown
@ 2010-02-04 21:57 ` Rafael J. Wysocki
       [not found] ` <1265203367-21344-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-04 21:57 UTC (permalink / raw)
  To: Mark Brown; +Cc: Jean Delvare, pm list, linux-i2c

On Wednesday 03 February 2010, Mark Brown wrote:
> Allow I2C drivers to make use of the runtime PM framework by adding
> bus implementations of the runtime PM operations. These simply
> immediately suspend when the device is idle.

Perhaps it would be a good idea to give the driver a chance to veto
the suspend by calling its _idle callback?  We do that for PCI and turns out to
be quite useful.

> The runtime PM framework provides drivers with off the shelf refcounts for
> enables and sysfs control for managing runtime suspend from userspace so is
> useful even without meaningful input from the bus.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
>  drivers/i2c/i2c-core.c |   41 +++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 41 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 10be7b5..985eaac 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/hardirq.h>
>  #include <linux/irqflags.h>
>  #include <linux/rwsem.h>
> +#include <linux/pm_runtime.h>
>  #include <asm/uaccess.h>
>  
>  #include "i2c-core.h"
> @@ -184,6 +185,43 @@ static int i2c_device_pm_resume(struct device *dev)
>  #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)
> +{
> +	/* I2C devices are very independent of each other so we
> +	 * suspend them immediately. */
> +	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);
> @@ -251,6 +289,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
>  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 = {
> 

Rafael

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [linux-pm] [PATCH] i2c: Hook up runtime PM support
       [not found]     ` <201002042257.27145.rjw-KKrjLPT3xs0@public.gmane.org>
@ 2010-02-05 10:39       ` Mark Brown
       [not found]         ` <20100205103915.GA2600-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  2010-02-05 22:09         ` Rafael J. Wysocki
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-05 10:39 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jean Delvare, pm list, linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Thu, Feb 04, 2010 at 10:57:27PM +0100, Rafael J. Wysocki wrote:
> On Wednesday 03 February 2010, Mark Brown wrote:
> > Allow I2C drivers to make use of the runtime PM framework by adding
> > bus implementations of the runtime PM operations. These simply
> > immediately suspend when the device is idle.

> Perhaps it would be a good idea to give the driver a chance to veto
> the suspend by calling its _idle callback?  We do that for PCI and turns out to
> be quite useful.

Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
there's nothing other than the driver involved so the request that is
being vetoed will have been initiated by the driver which seems wrong.
Out of interest do you have any pointers to drivers using this (my greps
aren't turning anything up in -next)?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
  2010-02-04 21:57   ` Rafael J. Wysocki
@ 2010-02-05 10:39     ` Mark Brown
       [not found]     ` <201002042257.27145.rjw-KKrjLPT3xs0@public.gmane.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-05 10:39 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jean Delvare, pm list, linux-i2c

On Thu, Feb 04, 2010 at 10:57:27PM +0100, Rafael J. Wysocki wrote:
> On Wednesday 03 February 2010, Mark Brown wrote:
> > Allow I2C drivers to make use of the runtime PM framework by adding
> > bus implementations of the runtime PM operations. These simply
> > immediately suspend when the device is idle.

> Perhaps it would be a good idea to give the driver a chance to veto
> the suspend by calling its _idle callback?  We do that for PCI and turns out to
> be quite useful.

Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
there's nothing other than the driver involved so the request that is
being vetoed will have been initiated by the driver which seems wrong.
Out of interest do you have any pointers to drivers using this (my greps
aren't turning anything up in -next)?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [linux-pm] [PATCH] i2c: Hook up runtime PM support
       [not found]         ` <20100205103915.GA2600-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2010-02-05 22:09           ` Rafael J. Wysocki
       [not found]             ` <201002052309.13966.rjw-KKrjLPT3xs0@public.gmane.org>
  2010-02-05 23:17             ` Mark Brown
  0 siblings, 2 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-05 22:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: Jean Delvare, pm list, linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Friday 05 February 2010, you wrote:
> On Thu, Feb 04, 2010 at 10:57:27PM +0100, Rafael J. Wysocki wrote:
> > On Wednesday 03 February 2010, Mark Brown wrote:
> > > Allow I2C drivers to make use of the runtime PM framework by adding
> > > bus implementations of the runtime PM operations. These simply
> > > immediately suspend when the device is idle.
> 
> > Perhaps it would be a good idea to give the driver a chance to veto
> > the suspend by calling its _idle callback?  We do that for PCI and turns out to
> > be quite useful.
> 
> Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
> there's nothing other than the driver involved so the request that is
> being vetoed will have been initiated by the driver which seems wrong.

Not really.  _idle is also called automatically by the runtime PM core after
_resume in case the device may be suspended again.  Your _idle has to handle
this case as well and that's when the driver may want to veto the suspend.

> Out of interest do you have any pointers to drivers using this (my greps
> aren't turning anything up in -next)?

There aren't any in -next, because I'm waiting for the base PCI runtime PM
code to settle down.  I have two in my private queue at the moment , for r8169
and e1000e (I posted some older versions of them some time ago, but they
wouldn't fit the current framework too well, which is the basic reason I'm
sitting on them, so that I don't have to post too many updates :-)).

I can send them to you privately, if needed.

Rafael

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
  2010-02-05 10:39       ` [linux-pm] " Mark Brown
       [not found]         ` <20100205103915.GA2600-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2010-02-05 22:09         ` Rafael J. Wysocki
  1 sibling, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-05 22:09 UTC (permalink / raw)
  To: Mark Brown; +Cc: Jean Delvare, pm list, linux-i2c

On Friday 05 February 2010, you wrote:
> On Thu, Feb 04, 2010 at 10:57:27PM +0100, Rafael J. Wysocki wrote:
> > On Wednesday 03 February 2010, Mark Brown wrote:
> > > Allow I2C drivers to make use of the runtime PM framework by adding
> > > bus implementations of the runtime PM operations. These simply
> > > immediately suspend when the device is idle.
> 
> > Perhaps it would be a good idea to give the driver a chance to veto
> > the suspend by calling its _idle callback?  We do that for PCI and turns out to
> > be quite useful.
> 
> Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
> there's nothing other than the driver involved so the request that is
> being vetoed will have been initiated by the driver which seems wrong.

Not really.  _idle is also called automatically by the runtime PM core after
_resume in case the device may be suspended again.  Your _idle has to handle
this case as well and that's when the driver may want to veto the suspend.

> Out of interest do you have any pointers to drivers using this (my greps
> aren't turning anything up in -next)?

There aren't any in -next, because I'm waiting for the base PCI runtime PM
code to settle down.  I have two in my private queue at the moment , for r8169
and e1000e (I posted some older versions of them some time ago, but they
wouldn't fit the current framework too well, which is the basic reason I'm
sitting on them, so that I don't have to post too many updates :-)).

I can send them to you privately, if needed.

Rafael

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [linux-pm] [PATCH] i2c: Hook up runtime PM support
       [not found]             ` <201002052309.13966.rjw-KKrjLPT3xs0@public.gmane.org>
@ 2010-02-05 23:17               ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-05 23:17 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jean Delvare, pm list, linux-i2c-u79uwXL29TY76Z2rM5mHXA

On Fri, Feb 05, 2010 at 11:09:13PM +0100, Rafael J. Wysocki wrote:
> On Friday 05 February 2010, you wrote:

> > Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
> > there's nothing other than the driver involved so the request that is
> > being vetoed will have been initiated by the driver which seems wrong.

> Not really.  _idle is also called automatically by the runtime PM core after
> _resume in case the device may be suspended again.  Your _idle has to handle
> this case as well and that's when the driver may want to veto the suspend.

I was viewing that as being part of the same case, going on the basis
that the driver would have marked the device as active already if
something had changed over the suspend.  The use cases that jumped out
at me for the veto were for buses or classes rather than for individual
devices.

> > Out of interest do you have any pointers to drivers using this (my greps
> > aren't turning anything up in -next)?

> There aren't any in -next, because I'm waiting for the base PCI runtime PM
> code to settle down.  I have two in my private queue at the moment , for r8169
> and e1000e (I posted some older versions of them some time ago, but they
> wouldn't fit the current framework too well, which is the basic reason I'm
> sitting on them, so that I don't have to post too many updates :-)).

> I can send them to you privately, if needed.

No, that's OK - like I say, it was just out of interest.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
  2010-02-05 22:09           ` Rafael J. Wysocki
       [not found]             ` <201002052309.13966.rjw-KKrjLPT3xs0@public.gmane.org>
@ 2010-02-05 23:17             ` Mark Brown
  1 sibling, 0 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-05 23:17 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jean Delvare, pm list, linux-i2c

On Fri, Feb 05, 2010 at 11:09:13PM +0100, Rafael J. Wysocki wrote:
> On Friday 05 February 2010, you wrote:

> > Hrm, I guess.  It seems an odd thing to want to use - for a bus like I2C
> > there's nothing other than the driver involved so the request that is
> > being vetoed will have been initiated by the driver which seems wrong.

> Not really.  _idle is also called automatically by the runtime PM core after
> _resume in case the device may be suspended again.  Your _idle has to handle
> this case as well and that's when the driver may want to veto the suspend.

I was viewing that as being part of the same case, going on the basis
that the driver would have marked the device as active already if
something had changed over the suspend.  The use cases that jumped out
at me for the veto were for buses or classes rather than for individual
devices.

> > Out of interest do you have any pointers to drivers using this (my greps
> > aren't turning anything up in -next)?

> There aren't any in -next, because I'm waiting for the base PCI runtime PM
> code to settle down.  I have two in my private queue at the moment , for r8169
> and e1000e (I posted some older versions of them some time ago, but they
> wouldn't fit the current framework too well, which is the basic reason I'm
> sitting on them, so that I don't have to post too many updates :-)).

> I can send them to you privately, if needed.

No, that's OK - like I say, it was just out of interest.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found]             ` <201002152008.24142.rjw-KKrjLPT3xs0@public.gmane.org>
  2010-02-15 19:14               ` Jean Delvare
@ 2010-02-15 19:15               ` Mark Brown
  1 sibling, 0 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-15 19:15 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Jean Delvare, Linux I2C

On Mon, Feb 15, 2010 at 08:08:24PM +0100, Rafael J. Wysocki wrote:
> On Monday 15 February 2010, Mark Brown wrote:
> > On Mon, Feb 15, 2010 at 07:14:09PM +0100, Jean Delvare wrote:

> > > Applied, thanks. I am a little surprised to see that these functions
> > > have nothing i2c-specific, so I am wondering why we have to duplicate
> > > them in every bus type... Shouldn't the functions above be part of
> > > drivers/base/power/runtime.c and exported so that all bus types that
> > > want them can reuse them?

> In fact this is the first bus type that doesn't need anything specific in these
> routines so fat.

Not really - the platform bus is the same, it's just that some platforms
are also able to do some neat stuff with the information they glean via
runtime PM.  The platform bus is actually a bit of a problem here since
it gets used both for on-SoC devices where that sort of stuff is
possible and also for things like MFDs and random memory mapped things
on the system, meaning that drivers can't take advantage of runtime PM
unless someone goes through and does something per-SoC which is a bit
inconvnient.

There's other buses like SPI that are in the same boat as I2C - they
don't really have a cohesive bus level power management structure, or
the power management is fully handled by with noop methods on the bus
and holding the parent open until all the children are idle.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found]             ` <201002152008.24142.rjw-KKrjLPT3xs0@public.gmane.org>
@ 2010-02-15 19:14               ` Jean Delvare
  2010-02-15 19:15               ` Mark Brown
  1 sibling, 0 replies; 17+ messages in thread
From: Jean Delvare @ 2010-02-15 19:14 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Mark Brown, Linux I2C

On Mon, 15 Feb 2010 20:08:24 +0100, Rafael J. Wysocki wrote:
> On Monday 15 February 2010, Mark Brown wrote:
> > On Mon, Feb 15, 2010 at 07:14:09PM +0100, Jean Delvare wrote:
> > 
> > > Applied, thanks. I am a little surprised to see that these functions
> > > have nothing i2c-specific, so I am wondering why we have to duplicate
> > > them in every bus type... Shouldn't the functions above be part of
> > > drivers/base/power/runtime.c and exported so that all bus types that
> > > want them can reuse them?
> 
> In fact this is the first bus type that doesn't need anything specific in these
> routines so fat.
> 
> > I tend to agree - in fact I'd been a little surprised the default for
> > buses that don't provide anything was to refuse to do runtime PM (though
> > I can see the transition issues when a bus does want to go and do its
> > own thing).
> > 
> > My actual plan here was to implement this for a couple of buses and then
> > present a patch factoring out the common code.
> 
> That's a good approach IMO.

OK, fine with me.

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found]         ` <20100215183058.GA24590-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
@ 2010-02-15 19:08           ` Rafael J. Wysocki
       [not found]             ` <201002152008.24142.rjw-KKrjLPT3xs0@public.gmane.org>
  0 siblings, 1 reply; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-15 19:08 UTC (permalink / raw)
  To: Mark Brown; +Cc: Jean Delvare, Linux I2C

On Monday 15 February 2010, Mark Brown wrote:
> On Mon, Feb 15, 2010 at 07:14:09PM +0100, Jean Delvare wrote:
> 
> > Applied, thanks. I am a little surprised to see that these functions
> > have nothing i2c-specific, so I am wondering why we have to duplicate
> > them in every bus type... Shouldn't the functions above be part of
> > drivers/base/power/runtime.c and exported so that all bus types that
> > want them can reuse them?

In fact this is the first bus type that doesn't need anything specific in these
routines so fat.

> I tend to agree - in fact I'd been a little surprised the default for
> buses that don't provide anything was to refuse to do runtime PM (though
> I can see the transition issues when a bus does want to go and do its
> own thing).
> 
> My actual plan here was to implement this for a couple of buses and then
> present a patch factoring out the common code.

That's a good approach IMO.

Rafael

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found]     ` <20100215191409.14d87257-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2010-02-15 18:30       ` Mark Brown
       [not found]         ` <20100215183058.GA24590-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
  0 siblings, 1 reply; 17+ messages in thread
From: Mark Brown @ 2010-02-15 18:30 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Rafael J. Wysocki, Linux I2C

On Mon, Feb 15, 2010 at 07:14:09PM +0100, Jean Delvare wrote:

> Applied, thanks. I am a little surprised to see that these functions
> have nothing i2c-specific, so I am wondering why we have to duplicate
> them in every bus type... Shouldn't the functions above be part of
> drivers/base/power/runtime.c and exported so that all bus types that
> want them can reuse them?

I tend to agree - in fact I'd been a little surprised the default for
buses that don't provide anything was to refuse to do runtime PM (though
I can see the transition issues when a bus does want to go and do its
own thing).

My actual plan here was to implement this for a couple of buses and then
present a patch factoring out the common code.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found] ` <1265373011-12874-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  2010-02-07 11:45   ` Rafael J. Wysocki
@ 2010-02-15 18:14   ` Jean Delvare
       [not found]     ` <20100215191409.14d87257-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  1 sibling, 1 reply; 17+ messages in thread
From: Jean Delvare @ 2010-02-15 18:14 UTC (permalink / raw)
  To: Mark Brown; +Cc: Rafael J. Wysocki, Linux I2C

Hi Mark,

On Fri,  5 Feb 2010 12:30:11 +0000, Mark Brown wrote:
> Allow I2C drivers to make use of the runtime PM framework by adding
> bus implementations of the runtime PM operations. These simply
> immediately suspend when the device is idle. The runtime PM framework
> provides drivers with off the shelf refcounts for enables and sysfs
> control for managing runtime suspend from userspace so is useful even
> without meaningful input from the bus.
> 
> Signed-off-by: Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
> ---
> 
> Changed to allow drivers to use the idle callback to veto suspend.
> 
>  drivers/i2c/i2c-core.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 50 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 10be7b5..4131698 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/hardirq.h>
>  #include <linux/irqflags.h>
>  #include <linux/rwsem.h>
> +#include <linux/pm_runtime.h>
>  #include <asm/uaccess.h>
>  
>  #include "i2c-core.h"
> @@ -184,6 +185,52 @@ static int i2c_device_pm_resume(struct device *dev)
>  #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);
> @@ -251,6 +298,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
>  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 = {

Applied, thanks. I am a little surprised to see that these functions
have nothing i2c-specific, so I am wondering why we have to duplicate
them in every bus type... Shouldn't the functions above be part of
drivers/base/power/runtime.c and exported so that all bus types that
want them can reuse them?

-- 
Jean Delvare

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
       [not found] ` <1265373011-12874-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2010-02-07 11:45   ` Rafael J. Wysocki
  2010-02-15 18:14   ` Jean Delvare
  1 sibling, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-07 11:45 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jean Delvare, linux-i2c-u79uwXL29TY76Z2rM5mHXA, Alan Stern, pm list

On Friday 05 February 2010, Mark Brown wrote:
> Allow I2C drivers to make use of the runtime PM framework by adding
> bus implementations of the runtime PM operations. These simply
> immediately suspend when the device is idle. The runtime PM framework
> provides drivers with off the shelf refcounts for enables and sysfs
> control for managing runtime suspend from userspace so is useful even
> without meaningful input from the bus.
> 
> Signed-off-by: Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>

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

> ---
> 
> Changed to allow drivers to use the idle callback to veto suspend.
> 
>  drivers/i2c/i2c-core.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 50 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 10be7b5..4131698 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/hardirq.h>
>  #include <linux/irqflags.h>
>  #include <linux/rwsem.h>
> +#include <linux/pm_runtime.h>
>  #include <asm/uaccess.h>
>  
>  #include "i2c-core.h"
> @@ -184,6 +185,52 @@ static int i2c_device_pm_resume(struct device *dev)
>  #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);
> @@ -251,6 +298,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
>  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 = {
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH] i2c: Hook up runtime PM support
  2010-02-05 12:30 Mark Brown
@ 2010-02-07 11:45 ` Rafael J. Wysocki
       [not found] ` <1265373011-12874-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  1 sibling, 0 replies; 17+ messages in thread
From: Rafael J. Wysocki @ 2010-02-07 11:45 UTC (permalink / raw)
  To: Mark Brown; +Cc: Jean Delvare, pm list, linux-i2c

On Friday 05 February 2010, Mark Brown wrote:
> Allow I2C drivers to make use of the runtime PM framework by adding
> bus implementations of the runtime PM operations. These simply
> immediately suspend when the device is idle. The runtime PM framework
> provides drivers with off the shelf refcounts for enables and sysfs
> control for managing runtime suspend from userspace so is useful even
> without meaningful input from the bus.
> 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

Acked-by: Rafael J. Wysocki <rjw@sisk.pl>

> ---
> 
> Changed to allow drivers to use the idle callback to veto suspend.
> 
>  drivers/i2c/i2c-core.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 50 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index 10be7b5..4131698 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -34,6 +34,7 @@
>  #include <linux/hardirq.h>
>  #include <linux/irqflags.h>
>  #include <linux/rwsem.h>
> +#include <linux/pm_runtime.h>
>  #include <asm/uaccess.h>
>  
>  #include "i2c-core.h"
> @@ -184,6 +185,52 @@ static int i2c_device_pm_resume(struct device *dev)
>  #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);
> @@ -251,6 +298,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
>  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 = {
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH] i2c: Hook up runtime PM support
@ 2010-02-05 12:30 Mark Brown
  2010-02-07 11:45 ` Rafael J. Wysocki
       [not found] ` <1265373011-12874-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Mark Brown @ 2010-02-05 12:30 UTC (permalink / raw)
  To: Jean Delvare
  Cc: Rafael J. Wysocki", linux-i2c-u79uwXL29TY76Z2rM5mHXA, Mark Brown

Allow I2C drivers to make use of the runtime PM framework by adding
bus implementations of the runtime PM operations. These simply
immediately suspend when the device is idle. The runtime PM framework
provides drivers with off the shelf refcounts for enables and sysfs
control for managing runtime suspend from userspace so is useful even
without meaningful input from the bus.

Signed-off-by: Mark Brown <broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---

Changed to allow drivers to use the idle callback to veto suspend.

 drivers/i2c/i2c-core.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 10be7b5..4131698 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -34,6 +34,7 @@
 #include <linux/hardirq.h>
 #include <linux/irqflags.h>
 #include <linux/rwsem.h>
+#include <linux/pm_runtime.h>
 #include <asm/uaccess.h>
 
 #include "i2c-core.h"
@@ -184,6 +185,52 @@ static int i2c_device_pm_resume(struct device *dev)
 #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);
@@ -251,6 +298,9 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
 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 = {
-- 
1.6.6

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-02-15 19:15 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-03 13:22 [PATCH] i2c: Hook up runtime PM support Mark Brown
2010-02-04 21:57 ` Rafael J. Wysocki
     [not found] ` <1265203367-21344-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2010-02-04 21:57   ` Rafael J. Wysocki
2010-02-05 10:39     ` Mark Brown
     [not found]     ` <201002042257.27145.rjw-KKrjLPT3xs0@public.gmane.org>
2010-02-05 10:39       ` [linux-pm] " Mark Brown
     [not found]         ` <20100205103915.GA2600-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2010-02-05 22:09           ` Rafael J. Wysocki
     [not found]             ` <201002052309.13966.rjw-KKrjLPT3xs0@public.gmane.org>
2010-02-05 23:17               ` Mark Brown
2010-02-05 23:17             ` Mark Brown
2010-02-05 22:09         ` Rafael J. Wysocki
2010-02-05 12:30 Mark Brown
2010-02-07 11:45 ` Rafael J. Wysocki
     [not found] ` <1265373011-12874-1-git-send-email-broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2010-02-07 11:45   ` Rafael J. Wysocki
2010-02-15 18:14   ` Jean Delvare
     [not found]     ` <20100215191409.14d87257-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-02-15 18:30       ` Mark Brown
     [not found]         ` <20100215183058.GA24590-HF5t3jzXg/6ND3a5+9QAFujbO/Zr0HzV@public.gmane.org>
2010-02-15 19:08           ` Rafael J. Wysocki
     [not found]             ` <201002152008.24142.rjw-KKrjLPT3xs0@public.gmane.org>
2010-02-15 19:14               ` Jean Delvare
2010-02-15 19:15               ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.