public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] Atmel-PWM: Fixed the PWM channel enable/disable issue which will cause the PWM output stop working after reenable. THe PWM channel status register is read to ensure  the PWM channel is really enabled or disabled.
@ 2014-10-01 21:08 robert yang
  2015-06-12 11:45 ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: robert yang @ 2014-10-01 21:08 UTC (permalink / raw)
  To: Thierry Reding, linux-pwm; +Cc: linux-kernel, ryang

From: ryang <ryang@hach.com>

Signed-off-by: ryang <ryang@hach.com>
---
 drivers/pwm/pwm-atmel.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 6e700a5..bab933a 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -237,7 +237,10 @@ static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
 	}
 
 	atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
-
+	while (!(atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm))) {
+		atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
+		cpu_relax();
+	}
 	return 0;
 }
 
@@ -246,7 +249,10 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
 	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
 
 	atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
-
+	while (atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm)) {
+		atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
+		cpu_relax();
+	}
 	clk_disable(atmel_pwm->clk);
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] Atmel-PWM: Fixed the PWM channel enable/disable issue which will cause the PWM output stop working after reenable. THe PWM channel status register is read to ensure  the PWM channel is really enabled or disabled.
  2014-10-01 21:08 [PATCH 1/1] Atmel-PWM: Fixed the PWM channel enable/disable issue which will cause the PWM output stop working after reenable. THe PWM channel status register is read to ensure the PWM channel is really enabled or disabled robert yang
@ 2015-06-12 11:45 ` Thierry Reding
  0 siblings, 0 replies; 2+ messages in thread
From: Thierry Reding @ 2015-06-12 11:45 UTC (permalink / raw)
  To: robert yang; +Cc: linux-pwm, linux-kernel, Nicolas Ferre, ryang

[-- Attachment #1: Type: text/plain, Size: 2486 bytes --]

On Wed, Oct 01, 2014 at 03:08:30PM -0600, robert yang wrote:
> From: ryang <ryang@hach.com>
> 
> Signed-off-by: ryang <ryang@hach.com>
> ---
>  drivers/pwm/pwm-atmel.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

Seems like I never got around to review this. Sorry for that.

First, you need to change the commit subject and message. The first line
should be a short description of what the patch does, something like
this:

	pwm: atmel: Ensure channel is enabled or disabled

Followed by a more verbose description of the change. What I don't
understand here is under what circumstances it can happen that the
channel isn't getting enabled. Is this because some error happened and
therefore the register needs to be written again? Or is it just that we
need to wait for some time for the PWM to become enabled and we use the
PWM enable register for that?

> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 6e700a5..bab933a 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -237,7 +237,10 @@ static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
>  	}
>  
>  	atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
> -
> +	while (!(atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm))) {
> +		atmel_pwm_writel(atmel_pwm, PWM_ENA, 1 << pwm->hwpwm);
> +		cpu_relax();
> +	}

So this indicates that the PWM_ENA register is used to enable multiple
PWM channels. Given that there is a PWM_DIS register too, I suspect that
this is a write-only register, so writing zeroes to an enable bit
doesn't actually cause the corresponding PWM to be disabled. That would
have been a nice explanation for why the original code could break.

>  	return 0;
>  }
>  
> @@ -246,7 +249,10 @@ static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
>  	struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>  
>  	atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
> -
> +	while (atmel_pwm_readl(atmel_pwm, PWM_SR) & (1 << pwm->hwpwm)) {
> +		atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
> +		cpu_relax();
> +	}
>  	clk_disable(atmel_pwm->clk);
>  }
>  

Same here. I don't really understand why this change is necessary. Maybe
you can provide a more detailed description of the error you're seeing.
Also adding Nicolas to Cc, perhaps he can help find out what the issue
is with the current code.

Thierry

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-06-12 11:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-01 21:08 [PATCH 1/1] Atmel-PWM: Fixed the PWM channel enable/disable issue which will cause the PWM output stop working after reenable. THe PWM channel status register is read to ensure the PWM channel is really enabled or disabled robert yang
2015-06-12 11:45 ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox