initial runtime PM layer for OMAP
cover initial runtime PM layer for OMAP
Here's a first pass implementaton at the runtime PM layer for OMAP. As you can see, it's a pretty thin layer and the omap_device layer does all the heavy lifting.
Following shortly to this series will be a conversion of the MMC driver as an example of how to use the runtime PM API.
Kevin Hilman (2):
OMAP: omap_device: add omap_device_has_lost_context()
OMAP: PM: initial runtime PM support
arch/arm/mach-omap2/Makefile | 6 ++ arch/arm/mach-omap2/pm_runtime.c | 119 +++++++++++++++++++++++++ arch/arm/plat-omap/include/plat/omap_device.h | 3 + arch/arm/plat-omap/omap_device.c | 35 +++++++ 4 files changed, 163 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/pm_runtime.c
PATCH 1/2 OMAP: omap_device: add omap_device_has_lost_context()
Add new function omap_device_has_lost_context() as a simple check to be used after omap_device_enable() to determine if device has lost context (and thus needs context restore.)
Motivation: Currently, each driver needs to read the context-loss count before suspend, and again upon resume to determine if device context needs to be restored. Rather than duplicating this process across all drivers, move it into omap_device. After omap_device_enable(), omap_device_has_lost_context() can be called to determine if context was lost.
This API is not intended for direct use by drivers. Rather, the OMAP runtime PM core will use this to determine whether or not to call the drivers runtime_resume hook which can then be used to restore context.
The goal is to only call drivers "restore" hook when necessary.
--- arch/arm/plat-omap/include/plat/omap_device.h | 3 ++ arch/arm/plat-omap/omap_device.c | 35 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-)
arch/arm/plat-omap/include/plat/omap_device.h +3 -0
@@ -71,6 +71,8 @@ struct omap_device {s8 pm_lat_level;u8 hwmods_cnt;u8 _state; +u32 activate_loss_cnt; +u32 deactivate_loss_cnt; };/* Device driver interface (call via platform_data fn ptrs) */
@@ -78,6 +80,7 @@ struct omap_device {int omap_device_enable (struct platform_device *pdev);int omap_device_idle (struct platform_device *pdev);int omap_device_shutdown (struct platform_device *pdev); +bool omap_device_has_lost_context (struct platform_device *pdev);/* Core code interface */
arch/arm/plat-omap/omap_device.c +35 -0
@@ -84,6 +84,7 @@#include <plat/omap_device.h> #include <plat/omap_hwmod.h> +#include <plat/powerdomain.h> /* These parameters are passed to _omap_device_{de,}activate() */ #define USE_WAKEUP_LAT 0
@@ -119,6 +120,7 @@static int _omap_device_activate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: activating\n" , od->pdev.name);
@@ -168,6 +170,10 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) od->dev_wakeup_lat -= odpl->activate_lat; } + pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->activate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ]; +return 0 ; }
@@ -188,6 +194,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)static int _omap_device_deactivate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: deactivating\n" , od->pdev.name);
@@ -239,6 +246,10 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) od->pm_lat_level++; } + pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->deactivate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ]; +return 0 ; }
@@ -560,6 +571,30 @@ int omap_device_shutdown(struct platform_device *pdev) }/** +* omap_device_has_lost_context() - check if omap_device has lost context +* @od: struct omap_device * +* +* When an omap_device has been deactivated via omap_device_idle() or +* omap_device_shutdown() and then (re)activated using omap_device_enable() +* This function should be used to determine if the omap_device has +* lost context (due to an off-mode transistion) +*/ +bool omap_device_has_lost_context (struct platform_device *pdev) +{ +struct omap_device *od; + + od =_find_by_pdev (pdev); + +if (od->_state !=OMAP_DEVICE_STATE_ENABLED ) { +WARN (1 ,"omap_device: %s.%d: has_lost_context() called " +"from invalid state\n" , od->pdev.name, od->pdev.id); +return -EINVAL ; + } + +return (od->activate_loss_cnt != od->deactivate_loss_cnt); +} + +/** * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim * @od: struct omap_device * *
Signature · 1 line
1.6.6
PATCH 2/2 OMAP: PM: initial runtime PM support
In reply to Kevin HilmanImplement the new runtime PM framework as a thin layer on top of the omap_device API. Since we don't have an OMAP-specific bus, override the runtime PM hooks for the platform_bus for the OMAP specific implementation.
While the runtime PM API has three main states (idle, suspend, resume) This version treats idle and suspend the same way by implementing both on top of omap_device_disable().
Device driver ->runtime_suspend() hooks are called just before the device is disabled (via omap_device_idle()), and device driver ->runtime_resume() hooks are called just after device has been enabled, but ONLY IF device has lost context due to an off-mode transition.
To convert other device drivers, simply change clk_disable() calls to pm_runtime_put_sync() and clk_enable() calls to pm_runtime_get_sync().
NOTE: the bus notifier stuff is currently there for debug purposes.
In the future, we may want to use the notifiers to do some automatic enable/disabling of devices.
--- arch/arm/mach-omap2/Makefile | 6 ++ arch/arm/mach-omap2/pm_runtime.c | 119 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 0 deletions(-) create mode 100644 arch/arm/mach-omap2/pm_runtime.c
arch/arm/mach-omap2/Makefile +6 -0
@@ -55,6 +55,12 @@ obj-$(CONFIG_PM_DEBUG) += pm-debug.o AFLAGS_sleep24xx.o :=-Wa,-march=armv6 AFLAGS_sleep34xx.o :=-Wa,-march=armv7-a +# Runtime PM support +obj-$(CONFIG_PM_RUNTIME) += pm_runtime.o +ifeq ($(CONFIG_PM_VERBOSE),y) +CFLAGS_pm_runtime.o += -DDEBUG +endif + endif # PRCM
arch/arm/mach-omap2/pm_runtime.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
1.6.6
Re: [PATCH/RFC 1/2] OMAP: omap_device: add omap_device_has_lost_context()
In reply to Kevin HilmanHi Kevin,
a few questions:
Quoted 29 lines · Kevin Hilman
Add new function
omap_device_has_lost_context()as a simple check to be used afteromap_device_enable()to determine if device has lost context (and thus needs context restore.)Motivation: Currently, each driver needs to read the context-loss count before suspend, and again upon resume to determine if device context needs to be restored. Rather than duplicating this process across all drivers, move it into
omap_device. Afteromap_device_enable(),omap_device_has_lost_context()can be called to determine if context was lost.This API is not intended for direct use by drivers. Rather, the OMAP runtime PM core will use this to determine whether or not to call the drivers
runtime_resumehook which can then be used to restore context.The goal is to only call drivers "restore" hook when necessary.
Signed-off-by Kevin Hilman <[email protected]>--- arch/arm/plat-omap/include/plat/omap_device.h | 3 ++ arch/arm/plat-omap/omap_device.c | 35 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-)arch/arm/plat-omap/include/plat/omap_device.h +0
-0
arch/arm/plat-omap/include/plat/omap_device.h struct omap_device { · line 75
Quoted 5 lines
arch/arm/plat-omap/include/plat/omap_device.h +2
-0@@ -71,6 +71,8 @@ struct omap_device {s8 pm_lat_level;u8 hwmods_cnt;u8 _state; +u32 activate_loss_cnt; +u32 deactivate_loss_cnt;
Would it be sufficient to just note the context loss count on a disable and then compare it against the powerdomain's loss count during activate, and if different, set a flag in _state ? That way only one loss count variable would be needed.
Quoted 32 lines
arch/arm/plat-omap/include/plat/omap_device.h +1
-0};/* Device driver interface (call via platform_data fn ptrs) */ @@ -78,6 +80,7 @@ struct omap_device {int omap_device_enable (struct platform_device *pdev);int omap_device_idle (struct platform_device *pdev);int omap_device_shutdown (struct platform_device *pdev); +bool omap_device_has_lost_context (struct platform_device *pdev);/* Core code interface */ arch/arm/plat-omap/omap_device.c +2
-0@@ -84,6 +84,7 @@#include <plat/omap_device.h> #include <plat/omap_hwmod.h> +#include <plat/powerdomain.h> /* These parameters are passed to _omap_device_{de,}activate() */ #define USE_WAKEUP_LAT 0@@ -119,6 +120,7 @@static int _omap_device_activate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: activating\n" , od->pdev.name);
arch/arm/plat-omap/omap_device.c static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) · line 175
Quoted 6 lines
arch/arm/plat-omap/omap_device.c +3
-0@@ -168,6 +170,10 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) od->dev_wakeup_lat -= odpl->activate_lat; } + pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->activate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ];
This probably will also depend on the powerdomain's logic_retst, mem_retst, mem_onst bits, since context can be lost even when the powerdomain is in RET or ON state.
Quoted 13 lines
arch/arm/plat-omap/omap_device.c +2
-0+return 0 ; }@@ -188,6 +194,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)static int _omap_device_deactivate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: deactivating\n" , od->pdev.name);
arch/arm/plat-omap/omap_device.c static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) · line 251
Quoted 6 lines
arch/arm/plat-omap/omap_device.c +3
-0@@ -239,6 +246,10 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) od->pm_lat_level++; } + pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->deactivate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ];
Same comment as above.
Quoted 43 lines
arch/arm/plat-omap/omap_device.c +25
-0+return 0 ; }@@ -560,6 +571,30 @@ int omap_device_shutdown(struct platform_device *pdev) }/** +* omap_device_has_lost_context() - check if omap_device has lost context +* @od: struct omap_device * +* +* When an omap_device has been deactivated via omap_device_idle() or +* omap_device_shutdown() and then (re)activated using omap_device_enable() +* This function should be used to determine if the omap_device has +* lost context (due to an off-mode transistion) +*/ +bool omap_device_has_lost_context (struct platform_device *pdev) +{ +struct omap_device *od; + + od =_find_by_pdev (pdev); + +if (od->_state !=OMAP_DEVICE_STATE_ENABLED ) { +WARN (1 ,"omap_device: %s.%d: has_lost_context() called " +"from invalid state\n" , od->pdev.name, od->pdev.id); +return -EINVAL ; + } + +return (od->activate_loss_cnt != od->deactivate_loss_cnt); +} + +/** * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim * @od: struct omap_device * * Signature · 6 lines
1.6.6 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
- Paul
Re: [PATCH/RFC 1/2] OMAP: omap_device: add omap_device_has_lost_context()
Quoted 30 lines · Paul Walmsley
Hi Kevin,
a few questions:
Quoted 24 lines · Kevin Hilman
Add new function
omap_device_has_lost_context()as a simple check to be used afteromap_device_enable()to determine if device has lost context (and thus needs context restore.)Motivation: Currently, each driver needs to read the context-loss count before suspend, and again upon resume to determine if device context needs to be restored. Rather than duplicating this process across all drivers, move it into
omap_device. Afteromap_device_enable(),omap_device_has_lost_context()can be called to determine if context was lost.This API is not intended for direct use by drivers. Rather, the OMAP runtime PM core will use this to determine whether or not to call the drivers
runtime_resumehook which can then be used to restore context.The goal is to only call drivers "restore" hook when necessary.
Signed-off-by Kevin Hilman <[email protected]>--- arch/arm/plat-omap/include/plat/omap_device.h | 3 ++ arch/arm/plat-omap/omap_device.c | 35 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 0 deletions(-)
Quoted 15 lines
arch/arm/plat-omap/include/plat/omap_device.h struct omap_device { · line 75
Quoted 10 lines
arch/arm/plat-omap/include/plat/omap_device.h +2
-0@@ -71,6 +71,8 @@ struct omap_device {s8 pm_lat_level;u8 hwmods_cnt;u8 _state; +u32 activate_loss_cnt; +u32 deactivate_loss_cnt;Would it be sufficient to just note the context loss count on a disable and then compare it against the powerdomain's loss count during activate, and if different, set a flag in
_state? That way only one loss count variable would be needed.
That's possible, but when should that flag be cleared? when has_lost_context() is called? Maybe before _deactivate() actually does the deactivate? Thoughts?
Quoted 35 lines
Quoted 35 lines
arch/arm/plat-omap/include/plat/omap_device.h +1
-0};/* Device driver interface (call via platform_data fn ptrs) */ @@ -78,6 +80,7 @@ struct omap_device {int omap_device_enable (struct platform_device *pdev);int omap_device_idle (struct platform_device *pdev);int omap_device_shutdown (struct platform_device *pdev); +bool omap_device_has_lost_context (struct platform_device *pdev);/* Core code interface */ arch/arm/plat-omap/omap_device.c +2
-0@@ -84,6 +84,7 @@#include <plat/omap_device.h> #include <plat/omap_hwmod.h> +#include <plat/powerdomain.h> /* These parameters are passed to _omap_device_{de,}activate() */ #define USE_WAKEUP_LAT 0@@ -119,6 +120,7 @@static int _omap_device_activate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: activating\n" , od->pdev.name);@@ -168,6 +170,10 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) od->dev_wakeup_lat -= odpl->activate_lat; }
Quoted 7 lines
arch/arm/plat-omap/omap_device.c static int _omap_device_activate(struct omap_device *od, u8 ignore_lat) · line 175
Quoted 3 lines
arch/arm/plat-omap/omap_device.c +3
-0+ pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->activate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ];This probably will also depend on the powerdomain's
logic_retst,mem_retst,mem_onstbits, since context can be lost even when the powerdomain is in RET or ON state.
Agreed.
Seems like this type of thing belongs in the powerdomain layer, don't you think? Maybe, along with the OSWR patches, we can add some more checking/accounting for whether a domain has gone off (or needs restore.)
Kevin
Quoted 69 lines
Quoted 14 lines
arch/arm/plat-omap/omap_device.c +2
-0+return 0 ; }@@ -188,6 +194,7 @@ static int _omap_device_activate(struct omap_device *od, u8 ignore_lat)static int _omap_device_deactivate (struct omap_device *od,u8 ignore_lat) {struct timespec a, b, c; +struct powerdomain *pwrdm;pr_debug ("omap_device: %s: deactivating\n" , od->pdev.name);arch/arm/plat-omap/omap_device.c static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) · line 251
Quoted 6 lines
arch/arm/plat-omap/omap_device.c +3
-0@@ -239,6 +246,10 @@ static int _omap_device_deactivate(struct omap_device *od, u8 ignore_lat) od->pm_lat_level++; } + pwrdm =omap_device_get_pwrdm (od); +if (pwrdm) + od->deactivate_loss_cnt = pwrdm->state_counter[PWRDM_POWER_OFF ];Same comment as above.
Quoted 43 lines
arch/arm/plat-omap/omap_device.c +25
-0+return 0 ; }@@ -560,6 +571,30 @@ int omap_device_shutdown(struct platform_device *pdev) }/** +* omap_device_has_lost_context() - check if omap_device has lost context +* @od: struct omap_device * +* +* When an omap_device has been deactivated via omap_device_idle() or +* omap_device_shutdown() and then (re)activated using omap_device_enable() +* This function should be used to determine if the omap_device has +* lost context (due to an off-mode transistion) +*/ +bool omap_device_has_lost_context (struct platform_device *pdev) +{ +struct omap_device *od; + + od =_find_by_pdev (pdev); + +if (od->_state !=OMAP_DEVICE_STATE_ENABLED ) { +WARN (1 ,"omap_device: %s.%d: has_lost_context() called " +"from invalid state\n" , od->pdev.name, od->pdev.id); +return -EINVAL ; + } + +return (od->activate_loss_cnt != od->deactivate_loss_cnt); +} + +/** * omap_device_align_pm_lat - activate/deactivate device to match wakeup lat lim * @od: struct omap_device * * Signature · 6 lines
1.6.6 -- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html- Paul