pwm: atmel: Fix disabling of PWM channels
Subsystems (3)
PATCH 1/1 pwm: atmel: Fix disabling of PWM channels
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.
Fix this by waiting for the channel to be effectively disabled (by checking the PWM_SR register) before disabling the clock.
--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/pwm/pwm-atmel.c +10 -0
@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm); +/* +* Wait for the PWM channel disable operation to be effective before +* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +clk_disable (atmel_pwm->clk); }
Signature · 1 line
1.7.9.5
Hello,
Any comments on this patch?
Guillermo
2016-05-13 13:09 GMT+02:00 Guillermo Rodriguez <[email protected]>:
Quoted 37 lines
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]>--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/pwm/pwm-atmel.c +10
-1@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm); +/* +* Wait for the PWM channel disable operation to be effective before +* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +clk_disable (atmel_pwm->clk); } --1.7.9.5
Signature · 2 lines
Guillermo Rodriguez Garcia [email protected]
Hi,
Quoted 21 lines · Guillermo Rodriguez
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]>--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/pwm/pwm-atmel.c +0
-0@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm);
drivers/pwm/pwm-atmel.c static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) · line 283
Quoted 10 lines
drivers/pwm/pwm-atmel.c +10
-0+/* +* Wait for the PWM channel disable operation to be effective before +* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +
While this seems good, can you tell on which SoC you observed that? I'd like to understand whether this is only on v1 or v2 or both.
Thanks!
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
Hi,
Quoted 38 lines · Alexandre Belloni
Hi,
Quoted 9 lines · Guillermo Rodriguez
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]<javascript:;>>
drivers/pwm/pwm-atmel.c static void atmel_pwm_disable(struct pwm_chip
Quoted 9 lines
--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/pwm/pwm-atmel.c +0
-0@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip*chip, struct
pwm_device*pwm)drivers/pwm/pwm-atmel.c static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
Quoted 5 lines
drivers/pwm/pwm-atmel.c +2
-0mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm); +/* +* Wait for the PWM channel disable operation to be effective before
drivers/pwm/pwm-atmel.c static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) · line 283
Quoted 8 lines
drivers/pwm/pwm-atmel.c +8
-0+* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +
Quoted 2 lines
While this seems good, can you tell on which SoC you observed that? I'd like to understand whether this is only on v1 or v2 or both.
I observed it on a sama5d3, however this article from atmel's KB would seem to suggest that it is not specific to this SoC:
http://atmel.force.com/support/pkb_mobile#/articles/en_US/FAQ/Why-PWM-Channel-Polarity-Inversion
Guillermo
Signature · 2 lines
Guillermo Rodriguez Garcia [email protected]
(resending to MLs for the record -- previous message bounced)
Quoted 25 lines · Alexandre Belloni
Hi,
Quoted 21 lines · Guillermo Rodriguez
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]>--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/pwm/pwm-atmel.c +0
-0@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm);
Quoted 13 lines
drivers/pwm/pwm-atmel.c static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm) · line 283
Quoted 10 lines
drivers/pwm/pwm-atmel.c +10
-0+/* +* Wait for the PWM channel disable operation to be effective before +* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +While this seems good, can you tell on which SoC you observed that? I'd like to understand whether this is only on v1 or v2 or both.
I observed it on a sama5d3, however this article from atmel's KB would seem to suggest that it is not specific to this SoC:
http://atmel.force.com/support/pkb_mobile#/articles/en_US/FAQ/Why-PWM-Channel-Polarity-Inversion
Guillermo
Quoted 9 lines · Guillermo Rodriguez
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]>
Quoted 25 lines
--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/pwm/pwm-atmel.c +10
-0@@ -271,6 +271,16 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)mutex_unlock (&atmel_pwm->isr_lock);atmel_pwm_writel (atmel_pwm,PWM_DIS ,1 << pwm->hwpwm); +/* +* Wait for the PWM channel disable operation to be effective before +* stopping the clock. +*/ + timeout = jiffies +2 *HZ ; +while ((atmel_pwm_readl (atmel_pwm,PWM_SR )& (1 << pwm->hwpwm)) && +time_before (jiffies, timeout)) { +usleep_range (10 ,100 ); + } +clk_disable (atmel_pwm->clk); }
Signature · 3 lines
Alexandre Belloni, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
Thierry Reding
AppliedQuoted 5 lines · Guillermo Rodriguez
When disabling a PWM channel, the PWM clock was being stopped immediately after writing to
PWM_DIS. As a result, the disabling of the PWM channel did not complete properly, and the PWM output might be left at the wrong level.
Quoted 7 lines
Fix this by waiting for the channel to be effectively disabled (by checking the
PWM_SRregister) before disabling the clock.Signed-off-by Guillermo Rodriguez <[email protected]>--- drivers/pwm/pwm-atmel.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Applied, thanks.
Thierry