i2c: Factor out runtime suspend checks from PM operations
Subsystems (6)
PATCH 1/1 i2c: Factor out runtime suspend checks from PM operations
When devices use dev_pm_ops the I2C API is implementing standard functionality for integration with runtime PM and for checking for the presence of a per device op. The PM core provides pm_generic_ functions implementing this behaviour - use them to reduce coupling with future PM updates.
---
Depends on my patch to add prototypes for the pm_generic_ operations.
drivers/i2c/i2c-core.c | 70 ++++++++++++++++++------------------------------ 1 files changed, 26 insertions(+), 44 deletions(-)
drivers/i2c/i2c-core.c +26 -44
@@ -196,69 +196,50 @@ static int i2c_device_pm_suspend(struct device *dev) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -if (pm) { -if (pm_runtime_suspended (dev)) -return 0 ; -else -return pm->suspend ? pm->suspend (dev) :0 ; - } - -return i2c_legacy_suspend (dev,PMSG_SUSPEND ); +if (pm) +return pm_generic_suspend (dev); +else +return i2c_legacy_suspend (dev,PMSG_SUSPEND ); }static int i2c_device_pm_resume (struct device *dev) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -int ret;if (pm) - ret = pm->resume ? pm->resume (dev) :0 ; +return pm_generic_resume (dev);else - ret =i2c_legacy_resume (dev); - -return ret; +return i2c_legacy_resume (dev); }static int i2c_device_pm_freeze (struct device *dev) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -if (pm) { -if (pm_runtime_suspended (dev)) -return 0 ; -else -return pm->freeze ? pm->freeze (dev) :0 ; - } - -return i2c_legacy_suspend (dev,PMSG_FREEZE ); +if (pm) +return pm_generic_freeze (dev); +else +return i2c_legacy_suspend (dev,PMSG_FREEZE ); }static int i2c_device_pm_thaw (struct device *dev) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -if (pm) { -if (pm_runtime_suspended (dev)) -return 0 ; -else -return pm->thaw ? pm->thaw (dev) :0 ; - } - -return i2c_legacy_resume (dev); +if (pm) +return pm_generic_thaw (dev); +else +return i2c_legacy_resume (dev); }static int i2c_device_pm_poweroff (struct device *dev) {const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ; -if (pm) { -if (pm_runtime_suspended (dev)) -return 0 ; -else -return pm->poweroff ? pm->poweroff (dev) :0 ; - } - -return i2c_legacy_suspend (dev,PMSG_HIBERNATE ); +if (pm) +return pm_generic_poweroff (dev); +else +return i2c_legacy_suspend (dev,PMSG_HIBERNATE ); }static int i2c_device_pm_restore (struct device *dev)
@@ -266,15 +247,16 @@ static int i2c_device_pm_restore(struct device *dev)const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm :NULL ;int ret; -if (pm) - ret = pm->restore ? pm->restore (dev) :0 ; -else +if (pm) { + ret =pm_generic_restore (dev); + }else { ret =i2c_legacy_resume (dev); -if (!ret) { -pm_runtime_disable (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev); +if (!ret) { +pm_runtime_disable (dev); +pm_runtime_set_active (dev); +pm_runtime_enable (dev); + } }return ret;
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): 1293041268-7707-1-git-send-email-broonie-yzvPICuk2AATkU/[email protected]
Quoted 13 lines · Mark Brown
static int
i2c_device_pm_restore(struct device *dev)drivers/i2c/i2c-core.c +3
-3@@ -266,15 +247,16 @@ static int i2c_device_pm_restore(struct device *dev) const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int ret; - if (pm) - ret = pm->restore ? pm->restore(dev) : 0; - else + if (pm) { + ret = pm_generic_restore(dev); + } else { ret = i2c_legacy_resume(dev);
drivers/i2c/i2c-core.c static int i2c_device_pm_restore(struct device *dev) · line 260
Quoted 10 lines
drivers/i2c/i2c-core.c +5
-4- if (!ret) { - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + if (!ret) { + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + } }
I asked Rafael about the legacy operations earlier on the other thread:
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines · Rabin Vincent
If so, before I send patches to fix them: can it be assumed that only drivers using
dev_pm_ops(and not the legacy ops of these busses) will need the interactions between runtime PM and system sleep as done in the generic ops?Yes, you can make this assumption safely. The drivers that don't use
dev_pm_opscan't support runtime PM at all.
And even if we did want to support runtime PM interaction for legacy ops, the code for restore() above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email for resume():
Quoted 9 lines · Rabin Vincent
(2) Both I2C and platform do not set the device as active when a
pm->resumecallback exists and it succeeds.This seems to have been done in i2c until recently, but has been removed by
753419f59e("i2c: Fix for suspend/resume issue"). It seems to me that this removal is incorrect, and instead the real problem with the implementation was that it set the device as active even if no resume callback existed, whereas it should only do so when it exists and returns zero, like the generic ops.
A message that is not in the archive (sent off-list or not yet received): AANLkTin5eSg8vL4Q8yZ9tme38fbS2aAZ-xeLQSNu809B-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 4 lines · Rabin Vincent
And even if we did want to support runtime PM interaction for legacy ops, the code for
restore()above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email forresume():
I agree it's confused, I posted an updated patch which should behave exactly as the old code did - I think the confusion with the legacy behaviour should be addressed seperately (and ideally in 2.6.37 or at least a stable patch rather than 2.6.38 which is where the current patch is targetted).
A message that is not in the archive (sent off-list or not yet received): 20101222201413.GB8167-yzvPICuk2AATkU/[email protected]
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rabin Vincent
And even if we did want to support runtime PM interaction for legacy ops, the code for
restore()above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email forresume():
Quoted 5 lines
I agree it's confused, I posted an updated patch which should behave exactly as the old code did - I think the confusion with the legacy behaviour should be addressed seperately (and ideally in 2.6.37 or at least a stable patch rather than 2.6.38 which is where the current patch is targetted).
Rabin is right, runtime PM cannot be supported in the "legacy" case. Still, I see that __pm_generic_resume() has the problem that it sets RPM_ACTIVE unconditionally, which it shouldn't do if the runtime PM has been already disabled.
So, I think we need this patch:
--- drivers/base/power/generic_ops.c | 2 +- include/linux/pm_runtime.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/base/power/generic_ops.c +1 -1
@@ -185,7 +185,7 @@ static int __pm_generic_resume(struct dereturn 0 ; ret =callback (dev); -if (!ret) { +if (!ret &&pm_runtime_enabled (dev)) {pm_runtime_disable (dev);pm_runtime_set_active (dev);pm_runtime_enable (dev);
include/linux/pm_runtime.h +6 -0
@@ -82,6 +82,11 @@ static inline bool pm_runtime_suspended( && !dev->power.disable_depth; } +static inline bool pm_runtime_enabled (struct device *dev) +{ +return !dev->power.disable_depth; +} +static inline void pm_runtime_mark_last_busy (struct device *dev) {ACCESS_ONCE (dev->power.last_busy) = jiffies;
@@ -120,6 +125,7 @@ static inline void pm_runtime_put_noidlestatic inline bool device_run_wake (struct device *dev) {return false; }static inline void device_set_run_wake (struct device *dev,bool enable) {}static inline bool pm_runtime_suspended (struct device *dev) {return false; } +static inline bool pm_runtime_enabled (struct device *dev) {return false; }static inline int pm_generic_runtime_idle (struct device *dev) {return 0 ; }static inline int pm_generic_runtime_suspend (struct device *dev) {return 0 ; }
Quoted 7 lines · Mark Brown
Quoted 4 lines · Rabin Vincent
And even if we did want to support runtime PM interaction for legacy ops, the code for
restore()above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email forresume():
Quoted 5 lines
I agree it's confused, I posted an updated patch which should behave exactly as the old code did - I think the confusion with the legacy behaviour should be addressed seperately (and ideally in 2.6.37 or at least a stable patch rather than 2.6.38 which is where the current patch is targetted).
Rabin is right, runtime PM cannot be supported in the "legacy" case. Still, I see that __pm_generic_resume() has the problem that it sets RPM_ACTIVE unconditionally, which it shouldn't do if the runtime PM has been already disabled.
So, I think we need this patch:
--- drivers/base/power/generic_ops.c | 2 +- include/linux/pm_runtime.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
drivers/base/power/generic_ops.c +1 -1
@@ -185,7 +185,7 @@ static int __pm_generic_resume(struct dereturn 0 ; ret =callback (dev); -if (!ret) { +if (!ret &&pm_runtime_enabled (dev)) {pm_runtime_disable (dev);pm_runtime_set_active (dev);pm_runtime_enable (dev);
include/linux/pm_runtime.h +6 -0
@@ -82,6 +82,11 @@ static inline bool pm_runtime_suspended( && !dev->power.disable_depth; } +static inline bool pm_runtime_enabled (struct device *dev) +{ +return !dev->power.disable_depth; +} +static inline void pm_runtime_mark_last_busy (struct device *dev) {ACCESS_ONCE (dev->power.last_busy) = jiffies;
@@ -120,6 +125,7 @@ static inline void pm_runtime_put_noidlestatic inline bool device_run_wake (struct device *dev) {return false; }static inline void device_set_run_wake (struct device *dev,bool enable) {}static inline bool pm_runtime_suspended (struct device *dev) {return false; } +static inline bool pm_runtime_enabled (struct device *dev) {return false; }static inline int pm_generic_runtime_idle (struct device *dev) {return 0 ; }static inline int pm_generic_runtime_suspend (struct device *dev) {return 0 ; }
Quoted 4 lines · Rabin Vincent
And even if we did want to support runtime PM interaction for legacy ops, the code for
restore()above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email forresume():
I agree it's confused, I posted an updated patch which should behave exactly as the old code did - I think the confusion with the legacy behaviour should be addressed seperately (and ideally in 2.6.37 or at least a stable patch rather than 2.6.38 which is where the current patch is targetted).
Quoted 13 lines · Mark Brown
static int
i2c_device_pm_restore(struct device *dev)drivers/i2c/i2c-core.c +3
-3@@ -266,15 +247,16 @@ static int i2c_device_pm_restore(struct device *dev) const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL; int ret; - if (pm) - ret = pm->restore ? pm->restore(dev) : 0; - else + if (pm) { + ret = pm_generic_restore(dev); + } else { ret = i2c_legacy_resume(dev);
drivers/i2c/i2c-core.c static int i2c_device_pm_restore(struct device *dev) · line 260
Quoted 10 lines
drivers/i2c/i2c-core.c +5
-4- if (!ret) { - pm_runtime_disable(dev); - pm_runtime_set_active(dev); - pm_runtime_enable(dev); + if (!ret) { + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + } }
I asked Rafael about the legacy operations earlier on the other thread:
Quoted 8 lines · Rafael J. Wysocki
Quoted 4 lines · Rabin Vincent
If so, before I send patches to fix them: can it be assumed that only drivers using
dev_pm_ops(and not the legacy ops of these busses) will need the interactions between runtime PM and system sleep as done in the generic ops?Yes, you can make this assumption safely. The drivers that don't use
dev_pm_opscan't support runtime PM at all.
And even if we did want to support runtime PM interaction for legacy ops, the code for restore() above suffers from the problem of setting active even when no callback exists, like I mentioned in the same email for resume():
Quoted 9 lines · Rabin Vincent
(2) Both I2C and platform do not set the device as active when a
pm->resumecallback exists and it succeeds.This seems to have been done in i2c until recently, but has been removed by
753419f59e("i2c: Fix for suspend/resume issue"). It seems to me that this removal is incorrect, and instead the real problem with the implementation was that it set the device as active even if no resume callback existed, whereas it should only do so when it exists and returns zero, like the generic ops.