All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] pwm: atmel: Fix duty cycle calculation in .get_state()
@ 2021-04-20  9:51 ` Uwe Kleine-König
  0 siblings, 0 replies; 19+ messages in thread
From: Uwe Kleine-König @ 2021-04-20  9:51 UTC (permalink / raw)
  To: Claudiu Beznea, Thierry Reding, Lee Jones
  Cc: Nicolas Ferre, Alexandre Belloni, Ludovic Desroches,
	linux-arm-kernel, linux-pwm, kernel

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 <u.kleine-koenig@pengutronix.de>
---
 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 d49da708337f..ebaeb50dcfde 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)(cprd - cdty) * NSEC_PER_SEC;
 		tmp <<= pres;
 		state->duty_cycle = DIV64_U64_ROUND_UP(tmp, rate);
 
-- 
2.30.2


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

end of thread, other threads:[~2021-07-05  7:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20  9:51 [PATCH 1/2] pwm: atmel: Fix duty cycle calculation in .get_state() Uwe Kleine-König
2021-04-20  9:51 ` Uwe Kleine-König
2021-04-20  9:51 ` [PATCH 2/2] pwm: atmel: Improve duty cycle calculation in .apply() Uwe Kleine-König
2021-04-20  9:51   ` Uwe Kleine-König
2021-04-23 17:07   ` Thierry Reding
2021-04-23 17:07     ` Thierry Reding
2021-04-21  9:26 ` [PATCH] pwm: atmel: rework tracking updates pending in hardware Uwe Kleine-König
2021-04-21  9:26   ` Uwe Kleine-König
2021-04-21 11:03   ` overflow and wrong timeout errors in pwm-atmel Uwe Kleine-König
2021-04-21 13:48     ` Uwe Kleine-König
2021-04-21 13:48       ` Uwe Kleine-König
2021-04-21 14:18       ` Alexandre Belloni
2021-04-21 14:18         ` Alexandre Belloni
2021-04-21 15:26         ` Uwe Kleine-König
2021-04-21 15:26           ` Uwe Kleine-König
2021-07-05  7:55   ` [PATCH] pwm: atmel: rework tracking updates pending in hardware Uwe Kleine-König
2021-07-05  7:55     ` Uwe Kleine-König
2021-04-23 17:07 ` [PATCH 1/2] pwm: atmel: Fix duty cycle calculation in .get_state() Thierry Reding
2021-04-23 17:07   ` Thierry Reding

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.