LOW power sleep support for TI PWM submodules
v2 cover LOW power sleep support for TI PWM submodules
TI PWM sub modules like ECAP & EHRPWM can enter in low power sleep state during low power transitions of the platforms (like in AM33XX). This patch series support low power sleep transition support. This patch series depend on [1] and [2] and tested for low sleep support on AM335x-evm for ECAP based PWM backlight.
1. ARM: OMAP2+: AM33XX: Add suspend-resume support
http://www.mail-archive.com/[email protected]/msg82635.html
2. HWMOD fixes for AM33xx PWM submodules and device tree nodes.
https://lkml.org/lkml/2013/1/2/87
Philip Avinash (2):
pwm: pwm-tiehrpwm: Low power sleep support
pwm: pwm-tiecap: Low power sleep support
drivers/pwm/pwm-tiecap.c | 53 ++++++++++++++++++++++++++++ drivers/pwm/pwm-tiehrpwm.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+)
Signature · 1 line
1.7.9.5
PATCH v2 1/2 pwm: pwm-tiehrpwm: Low power sleep support
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for EHRPWM driver.
---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspend
drivers/pwm/pwm-tiehrpwm.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
drivers/pwm/pwm-tiehrpwm.c +83 -0
@@ -113,6 +113,17 @@#define NUM_PWM_CHANNEL 2/* EHRPWM channels */ +struct ehrpwm_context { +u16 tbctl; +u16 tbprd; +u16 cmpa; +u16 cmpb; +u16 aqctla; +u16 aqctlb; +u16 aqsfrc; +u16 aqcsfrc; +}; +struct ehrpwm_pwm_chip {struct pwm_chip chip;unsigned int clk_rate;
@@ -120,6 +131,7 @@ struct ehrpwm_pwm_chip {unsigned long period_cycles[NUM_PWM_CHANNEL ];enum pwm_polarity polarity[NUM_PWM_CHANNEL ];struct clk *tbclk; +struct ehrpwm_context ctx; };static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip (struct pwm_chip *chip)
@@ -127,6 +139,11 @@ static inline struct ehrpwm_pwm_chip *to_ehrpwm_pwm_chip(struct pwm_chip *chip) return container_of(chip, struct ehrpwm_pwm_chip, chip); } +static u16 ehrpwm_read (void *base,int offset) +{ +return readw (base + offset); +} +static void ehrpwm_write (void *base,int offset,unsigned int val) {writew (val &0xFFFF , base + offset);
@@ -516,11 +533,77 @@ static int ehrpwm_pwm_remove(struct platform_device *pdev)return pwmchip_remove (&pc->chip); } +void ehrpwm_pwm_save_context (struct ehrpwm_pwm_chip *pc) +{ +pm_runtime_get_sync (pc->chip.dev); + pc->ctx.tbctl =ehrpwm_read (pc->mmio_base,TBCTL ); + pc->ctx.tbprd =ehrpwm_read (pc->mmio_base,TBPRD ); + pc->ctx.cmpa =ehrpwm_read (pc->mmio_base,CMPA ); + pc->ctx.cmpb =ehrpwm_read (pc->mmio_base,CMPB ); + pc->ctx.aqctla =ehrpwm_read (pc->mmio_base,AQCTLA ); + pc->ctx.aqctlb =ehrpwm_read (pc->mmio_base,AQCTLB ); + pc->ctx.aqsfrc =ehrpwm_read (pc->mmio_base,AQSFRC ); + pc->ctx.aqcsfrc =ehrpwm_read (pc->mmio_base,AQCSFRC ); +pm_runtime_put_sync (pc->chip.dev); +} + +void ehrpwm_pwm_restore_context (struct ehrpwm_pwm_chip *pc) +{ +ehrpwm_write (pc->mmio_base,TBPRD , pc->ctx.tbprd); +ehrpwm_write (pc->mmio_base,CMPA , pc->ctx.cmpa); +ehrpwm_write (pc->mmio_base,CMPB , pc->ctx.cmpb); +ehrpwm_write (pc->mmio_base,AQCTLA , pc->ctx.aqctla); +ehrpwm_write (pc->mmio_base,AQCTLB , pc->ctx.aqctlb); +ehrpwm_write (pc->mmio_base,AQSFRC , pc->ctx.aqsfrc); +ehrpwm_write (pc->mmio_base,AQCSFRC , pc->ctx.aqcsfrc); +ehrpwm_write (pc->mmio_base,TBCTL , pc->ctx.tbctl); +} + +static int ehrpwm_pwm_suspend (struct device *dev) +{ +struct ehrpwm_pwm_chip *pc =dev_get_drvdata (dev); +int i; + +ehrpwm_pwm_save_context (pc); +for (i =0 ; i < pc->chip.npwm; i++) { +struct pwm_device *pwm = &pc->chip.pwms[i]; + +if (!test_bit (PWMF_ENABLED , &pwm->flags)) +continue ; + +/* Disable explicitly if PWM is running */ +pm_runtime_put_sync (dev); + } +return 0 ; +} + +static int ehrpwm_pwm_resume (struct device *dev) +{ +struct ehrpwm_pwm_chip *pc =dev_get_drvdata (dev); +int i; + +for (i =0 ; i < pc->chip.npwm; i++) { +struct pwm_device *pwm = &pc->chip.pwms[i]; + +if (!test_bit (PWMF_ENABLED , &pwm->flags)) +continue ; + +/* Enable explicitly if PWM was running */ +pm_runtime_get_sync (dev); + } +ehrpwm_pwm_restore_context (pc); +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(ehrpwm_pwm_pm_ops, ehrpwm_pwm_suspend, + ehrpwm_pwm_resume); +static struct platform_driver ehrpwm_pwm_driver = { .driver = { .name ="ehrpwm" , .owner =THIS_MODULE , .of_match_table = ehrpwm_of_match, + .pm = &ehrpwm_pwm_pm_ops, }, .probe = ehrpwm_pwm_probe, .remove = ehrpwm_pwm_remove,
Signature · 1 line
1.7.9.5
Thierry Reding
AppliedRe: [PATCH v2 1/2] pwm: pwm-tiehrpwm: Low power sleep support
Quoted 4 lines · Philip Avinash
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for EHRPWM driver.
Quoted 8 lines
Signed-off-by Philip Avinash <[email protected]>---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspenddrivers/pwm/pwm-tiehrpwm.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)
Applied, thanks.
Thierry
RE: [PATCH v2 1/2] pwm: pwm-tiehrpwm: Low power sleep support
Quoted 11 lines · Thierry Reding
Quoted 10 lines · Philip Avinash
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for EHRPWM driver.
Signed-off-by Philip Avinash <[email protected]>---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspend
Quoted 4 lines
Quoted 2 lines
drivers/pwm/pwm-tiehrpwm.c | 83 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+)Applied, thanks.
Thanks for applying this patch
Avinash
Quoted 3 lines
Thierry
PATCH v2 2/2 pwm: pwm-tiecap: Low power sleep support
In reply to Philip AvinashIn low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for ECAP driver.
---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspend
drivers/pwm/pwm-tiecap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
drivers/pwm/pwm-tiecap.c +53 -0
@@ -41,10 +41,17 @@#define ECCTL2_SYNC_SEL_DISA (BIT(7) | BIT(6))#define ECCTL2_TSCTR_FREERUN BIT(4) +struct ecap_context { +u32 cap3; +u32 cap4; +u16 ecctl2; +}; +struct ecap_pwm_chip {struct pwm_chip chip;unsigned int clk_rate;void __iomem *mmio_base; +struct ecap_context ctx; };static inline struct ecap_pwm_chip *to_ecap_pwm_chip (struct pwm_chip *chip)
@@ -288,11 +295,57 @@ static int ecap_pwm_remove(struct platform_device *pdev)return pwmchip_remove (&pc->chip); } +void ecap_pwm_save_context (struct ecap_pwm_chip *pc) +{ +pm_runtime_get_sync (pc->chip.dev); + pc->ctx.ecctl2 =readw (pc->mmio_base +ECCTL2 ); + pc->ctx.cap4 =readl (pc->mmio_base +CAP4 ); + pc->ctx.cap3 =readl (pc->mmio_base +CAP3 ); +pm_runtime_put_sync (pc->chip.dev); +} + +void ecap_pwm_restore_context (struct ecap_pwm_chip *pc) +{ +writel (pc->ctx.cap3, pc->mmio_base +CAP3 ); +writel (pc->ctx.cap4, pc->mmio_base +CAP4 ); +writew (pc->ctx.ecctl2, pc->mmio_base +ECCTL2 ); +} + +static int ecap_pwm_suspend (struct device *dev) +{ +struct ecap_pwm_chip *pc =dev_get_drvdata (dev); +struct pwm_device *pwm = pc->chip.pwms; + +ecap_pwm_save_context (pc); + +/* Disable explicitly if PWM is running */ +if (test_bit (PWMF_ENABLED , &pwm->flags)) +pm_runtime_put_sync (dev); + +return 0 ; +} + +static int ecap_pwm_resume (struct device *dev) +{ +struct ecap_pwm_chip *pc =dev_get_drvdata (dev); +struct pwm_device *pwm = pc->chip.pwms; + +/* Enable explicitly if PWM was running */ +if (test_bit (PWMF_ENABLED , &pwm->flags)) +pm_runtime_get_sync (dev); + +ecap_pwm_restore_context (pc); +return 0 ; +} + +static SIMPLE_DEV_PM_OPS(ecap_pwm_pm_ops, ecap_pwm_suspend, ecap_pwm_resume); +static struct platform_driver ecap_pwm_driver = { .driver = { .name ="ecap" , .owner =THIS_MODULE , .of_match_table = ecap_of_match, + .pm = &ecap_pwm_pm_ops, }, .probe = ecap_pwm_probe, .remove = ecap_pwm_remove,
Signature · 1 line
1.7.9.5
Thierry Reding
AppliedRe: [PATCH v2 2/2] pwm: pwm-tiecap: Low power sleep support
Quoted 11 lines · Philip Avinash
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for ECAP driver.
Signed-off-by Philip Avinash <[email protected]>---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspenddrivers/pwm/pwm-tiecap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
Applied, thanks.
Thierry
RE: [PATCH v2 2/2] pwm: pwm-tiecap: Low power sleep support
Quoted 10 lines · Thierry Reding
Quoted 9 lines · Philip Avinash
In low power modes of AM33XX platforms, peripherals power is cut off. This patch supports low power sleep transition support for ECAP driver.
Signed-off-by Philip Avinash <[email protected]>---
Changes since v1:
- check the enabled status of pwm device for handling module enable/disable on resume/suspend
Quoted 4 lines
Quoted 2 lines
drivers/pwm/pwm-tiecap.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)Applied, thanks.
Thanks for applying this patch
Avinash
Quoted 3 lines
Thierry