i2c: Hook up runtime PM support
Subsystems (2)
PATCH 1/1 i2c: Hook up runtime PM support
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.
--- drivers/i2c/i2c-core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)
drivers/i2c/i2c-core.c +41 -0
@@ -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 = {
Signature · 1 line
1.6.6
A message that is not in the archive (sent off-list or not yet received): 1265203367-21344-1-git-send-email-broonie-yzvPICuk2AATkU/[email protected]
Quoted 3 lines · 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.
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.
Quoted 67 lines
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/[email protected]>--- drivers/i2c/i2c-core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)drivers/i2c/i2c-core.c +38
-0@@ -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);
drivers/i2c/i2c-core.c static const struct attribute_group *i2c_dev_attr_groups[] = { · line 297
Quoted 9 lines
drivers/i2c/i2c-core.c +3
-0@@ -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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · 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.
Perhaps it would be a good idea to give the driver a chance to veto the suspend by calling its
_idlecallback? 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)?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · you
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · 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.
Quoted 7 lines
Quoted 3 lines
Perhaps it would be a good idea to give the driver a chance to veto the suspend by calling its
_idlecallback? 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.
Quoted 2 lines
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
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · you
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.
_idleis also called automatically by the runtime PM core after_resumein case the device may be suspended again. Your_idlehas 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.
Quoted 10 lines
Quoted 2 lines
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.
Quoted 9 lines · Rafael J. Wysocki
Quoted 3 lines · you
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.
_idleis also called automatically by the runtime PM core after_resumein case the device may be suspended again. Your_idlehas 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.
Quoted 10 lines
Quoted 2 lines
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.
Quoted 6 lines · you
Quoted 4 lines · Rafael J. Wysocki
Quoted 3 lines · 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.
Quoted 7 lines
Quoted 3 lines
Perhaps it would be a good idea to give the driver a chance to veto the suspend by calling its
_idlecallback? 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.
Quoted 2 lines
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
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · 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.
Perhaps it would be a good idea to give the driver a chance to veto the suspend by calling its
_idlecallback? 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)?
Quoted 3 lines · 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.
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.
Quoted 67 lines
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 <[email protected]>--- drivers/i2c/i2c-core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)drivers/i2c/i2c-core.c +38
-0@@ -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);
drivers/i2c/i2c-core.c static const struct attribute_group *i2c_dev_attr_groups[] = { · line 297
Quoted 9 lines
drivers/i2c/i2c-core.c +3
-0@@ -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