diff mbox series

pwm: atmel: Fix duty cycle calculation in .get_state()

Message ID 20210418205747.1488248-1-uwe@kleine-koenig.org (mailing list archive)
State New
Headers show
Series pwm: atmel: Fix duty cycle calculation in .get_state() | expand

Commit Message

Uwe Kleine-König April 18, 2021, 8:57 p.m. UTC
The CDTY register contains the number of inactive cycles. .apply() does
this correctly, however .get_state got this wrong.

Fixes: 651b510a74d4 ("pwm: atmel: Implement .get_state()")
Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 drivers/pwm/pwm-atmel.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Uwe Kleine-König April 19, 2021, 7:29 p.m. UTC | #1
Hello,

On Sun, Apr 18, 2021 at 10:57:47PM +0200, Uwe Kleine-König wrote:
> -		tmp = (u64)cdty * NSEC_PER_SEC;
> +		tmp = (u64)(cdty - cprd) * NSEC_PER_SEC;

This is wrong, it must be cprd - cdty. I will send a fixed patch
together with another patch that improves precision of _apply.

Best regards
Uwe
diff mbox series

Patch

diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c
index d49da708337f..c30a0dac4b2d 100644
--- a/drivers/pwm/pwm-atmel.c
+++ b/drivers/pwm/pwm-atmel.c
@@ -319,7 +319,7 @@  static void atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
 
 		cdty = atmel_pwm_ch_readl(atmel_pwm, pwm->hwpwm,
 					  atmel_pwm->data->regs.duty);
-		tmp = (u64)cdty * NSEC_PER_SEC;
+		tmp = (u64)(cdty - cprd) * NSEC_PER_SEC;
 		tmp <<= pres;
 		state->duty_cycle = DIV64_U64_ROUND_UP(tmp, rate);