* [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable
@ 2013-09-27 20:10 Alexandre Belloni
2013-09-29 10:12 ` Bo Shen
0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Belloni @ 2013-09-27 20:10 UTC (permalink / raw)
To: Thierry Reding
Cc: linux-pwm, voice.shen, Nicolas Ferre, Ludovic Desroches,
linux-kernel, linux-arm-kernel, Alexandre Belloni
I found that disabling a pwm while it is at a low level will actually put it
back at a high level. The main symptom is that leds-pwm is calling pwm_disable()
after setting the duty cycle to 0. Hence, instead of getting a switched off LED,
you get an LED lit up at full brightness.
Solve that by using the request and free callbacks to enable and disable the
pwm channels and the clock.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
This patch applies after:
[PATCH v4] PWM: atmel-pwm: add PWM controller driver
drivers/pwm/pwm-atmel.c | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 6af7a50..4526e71 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -209,7 +209,7 @@ static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
return 0;
}
-static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
+static int atmel_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
int ret;
@@ -225,23 +225,19 @@ static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
return 0;
}
-static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
+static void atmel_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
{
struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
- u32 val;
atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
-
- val = atmel_pwm_readl(atmel_pwm, PWM_SR);
- if ((val & PWM_SR_ALL_CH_ON) == 0)
- clk_disable(atmel_pwm->clk);
+ clk_disable(atmel_pwm->clk);
}
static const struct pwm_ops atmel_pwm_ops = {
.config = atmel_pwm_config,
.set_polarity = atmel_pwm_set_polarity,
- .enable = atmel_pwm_enable,
- .disable = atmel_pwm_disable,
+ .request = atmel_pwm_request,
+ .free = atmel_pwm_free,
.owner = THIS_MODULE,
};
--
1.8.1.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable
2013-09-27 20:10 [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable Alexandre Belloni
@ 2013-09-29 10:12 ` Bo Shen
2013-09-29 15:54 ` Alexandre Belloni
0 siblings, 1 reply; 3+ messages in thread
From: Bo Shen @ 2013-09-29 10:12 UTC (permalink / raw)
To: Alexandre Belloni
Cc: Thierry Reding, linux-pwm, Nicolas Ferre, Ludovic Desroches,
linux-kernel, linux-arm-kernel
Hi Alexandre,
On 9/28/2013 04:10, Alexandre Belloni wrote:
> I found that disabling a pwm while it is at a low level will actually put it
> back at a high level. The main symptom is that leds-pwm is calling pwm_disable()
> after setting the duty cycle to 0. Hence, instead of getting a switched off LED,
> you get an LED lit up at full brightness.
>
> Solve that by using the request and free callbacks to enable and disable the
> pwm channels and the clock.
>
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> ---
>
> This patch applies after:
> [PATCH v4] PWM: atmel-pwm: add PWM controller driver
>
> drivers/pwm/pwm-atmel.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 6af7a50..4526e71 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -209,7 +209,7 @@ static int atmel_pwm_set_polarity(struct pwm_chip *chip, struct pwm_device *pwm,
> return 0;
> }
>
> -static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
> +static int atmel_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
> {
> struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
> int ret;
> @@ -225,23 +225,19 @@ static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm)
> return 0;
> }
>
> -static void atmel_pwm_disable(struct pwm_chip *chip, struct pwm_device *pwm)
> +static void atmel_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
> {
> struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
> - u32 val;
>
> atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
> -
> - val = atmel_pwm_readl(atmel_pwm, PWM_SR);
> - if ((val & PWM_SR_ALL_CH_ON) == 0)
> - clk_disable(atmel_pwm->clk);
> + clk_disable(atmel_pwm->clk);
> }
>
> static const struct pwm_ops atmel_pwm_ops = {
> .config = atmel_pwm_config,
> .set_polarity = atmel_pwm_set_polarity,
> - .enable = atmel_pwm_enable,
> - .disable = atmel_pwm_disable,
> + .request = atmel_pwm_request,
> + .free = atmel_pwm_free,
This will cause pwmadd_chip failure.
Code from <drivers/pwm/core.c>, in function: pwmadd_chip()
---8>---
if (!chip || !chip->dev || !chip->ops || !chip->ops->config ||
!chip->ops->enable || !chip->ops->disable)
return -EINVAL;
---<8---
> .owner = THIS_MODULE,
> };
>
Best Regards,
Bo Shen
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable
2013-09-29 10:12 ` Bo Shen
@ 2013-09-29 15:54 ` Alexandre Belloni
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Belloni @ 2013-09-29 15:54 UTC (permalink / raw)
To: Bo Shen
Cc: Thierry Reding, linux-pwm, Nicolas Ferre, Ludovic Desroches,
linux-kernel, linux-arm-kernel
On 29/09/2013 12:12, Bo Shen wrote:
> Hi Alexandre,
>
> On 9/28/2013 04:10, Alexandre Belloni wrote:
>> I found that disabling a pwm while it is at a low level will actually
>> put it
>> back at a high level. The main symptom is that leds-pwm is calling
>> pwm_disable()
>> after setting the duty cycle to 0. Hence, instead of getting a
>> switched off LED,
>> you get an LED lit up at full brightness.
>>
>> Solve that by using the request and free callbacks to enable and
>> disable the
>> pwm channels and the clock.
>>
>> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>> ---
>>
>> This patch applies after:
>> [PATCH v4] PWM: atmel-pwm: add PWM controller driver
>>
>> drivers/pwm/pwm-atmel.c | 14 +++++---------
>> 1 file changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
>> index 6af7a50..4526e71 100644
>> --- a/drivers/pwm/pwm-atmel.c
>> +++ b/drivers/pwm/pwm-atmel.c
>> @@ -209,7 +209,7 @@ static int atmel_pwm_set_polarity(struct pwm_chip
>> *chip, struct pwm_device *pwm,
>> return 0;
>> }
>>
>> -static int atmel_pwm_enable(struct pwm_chip *chip, struct pwm_device
>> *pwm)
>> +static int atmel_pwm_request(struct pwm_chip *chip, struct
>> pwm_device *pwm)
>> {
>> struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>> int ret;
>> @@ -225,23 +225,19 @@ static int atmel_pwm_enable(struct pwm_chip
>> *chip, struct pwm_device *pwm)
>> return 0;
>> }
>>
>> -static void atmel_pwm_disable(struct pwm_chip *chip, struct
>> pwm_device *pwm)
>> +static void atmel_pwm_free(struct pwm_chip *chip, struct pwm_device
>> *pwm)
>> {
>> struct atmel_pwm_chip *atmel_pwm = to_atmel_pwm_chip(chip);
>> - u32 val;
>>
>> atmel_pwm_writel(atmel_pwm, PWM_DIS, 1 << pwm->hwpwm);
>> -
>> - val = atmel_pwm_readl(atmel_pwm, PWM_SR);
>> - if ((val & PWM_SR_ALL_CH_ON) == 0)
>> - clk_disable(atmel_pwm->clk);
>> + clk_disable(atmel_pwm->clk);
>> }
>>
>> static const struct pwm_ops atmel_pwm_ops = {
>> .config = atmel_pwm_config,
>> .set_polarity = atmel_pwm_set_polarity,
>> - .enable = atmel_pwm_enable,
>> - .disable = atmel_pwm_disable,
>> + .request = atmel_pwm_request,
>> + .free = atmel_pwm_free,
>
> This will cause pwmadd_chip failure.
>
> Code from <drivers/pwm/core.c>, in function: pwmadd_chip()
> ---8>---
> if (!chip || !chip->dev || !chip->ops || !chip->ops->config ||
> !chip->ops->enable || !chip->ops->disable)
> return -EINVAL;
> ---<8---
>
You are right, I tested with dummy pwm_enable/pwm_disable functions and
removed them before sending the patch, thinking they weren't needed.
I'll respin that patch.
>> .owner = THIS_MODULE,
>> };
>>
>
> Best Regards,
> Bo Shen
>
--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-09-29 15:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-27 20:10 [PATCH] PWM: atmel-pwm: use request/free instead of enable/disable Alexandre Belloni
2013-09-29 10:12 ` Bo Shen
2013-09-29 15:54 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox