Skip to contentSkip to conversation

pwm: atmel: Fix disabling of PWM channels

PATCH Applied Guillermo Rodriguez 3 participants 7 messages May 13, 2016 – Jul 11, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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
index 0e4bd4e..a714434 100644
@@ -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
#1 lore raw

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_SR register) before disabling the clock.

---
 drivers/pwm/pwm-atmel.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pwm/pwm-atmel.c +10 -1
index 0e4bd4e..a714434 100644
@@ -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]
#2 lore raw
In reply to Guillermo Rodriguez

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_SR register) before disabling the clock.

---
 drivers/pwm/pwm-atmel.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pwm/pwm-atmel.c +0 -0
index 0e4bd4e..a714434 100644
@@ -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
#3 lore raw

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_SR register) before disabling the clock.

<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
index 0e4bd4e..a714434 100644
@@ -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 -0
      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

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]
Acked-by on v1 1/1
#5 lore raw
In reply to Guillermo Rodriguez
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_SR register) before disabling the clock.

Quoted 25 lines
---
 drivers/pwm/pwm-atmel.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pwm/pwm-atmel.c +10 -0
index 0e4bd4e..a714434 100644
@@ -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
#4 lore raw
In reply to Alexandre Belloni

(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_SR register) before disabling the clock.

---
 drivers/pwm/pwm-atmel.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pwm/pwm-atmel.c +0 -0
index 0e4bd4e..a714434 100644
@@ -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

#6 lore raw
In reply to Guillermo Rodriguez
Quoted 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_SR register) before disabling the clock.

---
 drivers/pwm/pwm-atmel.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Applied, thanks.

Thierry