diff mbox

[2/2] PWM: atmel: correct CDTY calculation

Message ID 1394806749-29778-3-git-send-email-alexandre.belloni@free-electrons.com
State Accepted
Headers show

Commit Message

Alexandre Belloni March 14, 2014, 2:19 p.m. UTC
From the datasheet, the actual duty cycle is:
(period - (1/clk) * CDTY)/period

This actually correct the polarity of the PWM and solves the issue that pwm-leds
exhibits: when setting a duty cycle of 0 and then disabling a channel, the level
was wrong (1 when the polarity was normal and 0 when the polarity was inversed).

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/pwm/pwm-atmel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nicolas Ferre March 14, 2014, 2:54 p.m. UTC | #1
On 14/03/2014 15:19, Alexandre Belloni :
>>From the datasheet, the actual duty cycle is:
> (period - (1/clk) * CDTY)/period
> 
> This actually correct the polarity of the PWM and solves the issue that pwm-leds
> exhibits: when setting a duty cycle of 0 and then disabling a channel, the level
> was wrong (1 when the polarity was normal and 0 when the polarity was inversed).
> 
> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>

> ---
>  drivers/pwm/pwm-atmel.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
> index 2d69e9c431dd..0adc952cc4ef 100644
> --- a/drivers/pwm/pwm-atmel.c
> +++ b/drivers/pwm/pwm-atmel.c
> @@ -133,7 +133,7 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
>  	prd = div;
>  	div *= duty_ns;
>  	do_div(div, period_ns);
> -	dty = div;
> +	dty = prd - div;
>  
>  	ret = clk_enable(atmel_pwm->clk);
>  	if (ret) {
>
diff mbox

Patch

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index 2d69e9c431dd..0adc952cc4ef 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -133,7 +133,7 @@  static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm,
 	prd = div;
 	div *= duty_ns;
 	do_div(div, period_ns);
-	dty = div;
+	dty = prd - div;
 
 	ret = clk_enable(atmel_pwm->clk);
 	if (ret) {