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

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(-)

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);
 
-- 
2.30.2


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

* [PATCH] pwm: atmel: Fix duty cycle calculation in .get_state()
@ 2021-04-18 20:57 ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2021-04-18 20:57 UTC (permalink / raw)
  To: Claudiu Beznea, Thierry Reding, Lee Jones
  Cc: linux-pwm, Alexandre Belloni, Ludovic Desroches, linux-arm-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 <uwe@kleine-koenig.org>
---
 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..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);
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] pwm: atmel: Fix duty cycle calculation in .get_state()
  2021-04-18 20:57 ` Uwe Kleine-König
@ 2021-04-19 19:29   ` Uwe Kleine-König
  -1 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2021-04-19 19:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Claudiu Beznea, Thierry Reding, Lee Jones, Nicolas Ferre,
	Alexandre Belloni, Ludovic Desroches, linux-arm-kernel,
	linux-pwm

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

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

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] pwm: atmel: Fix duty cycle calculation in .get_state()
@ 2021-04-19 19:29   ` Uwe Kleine-König
  0 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2021-04-19 19:29 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: linux-pwm, Alexandre Belloni, Ludovic Desroches, Thierry Reding,
	Lee Jones, Claudiu Beznea, linux-arm-kernel


[-- Attachment #1.1: Type: text/plain, Size: 474 bytes --]

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

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-04-19 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-18 20:57 [PATCH] pwm: atmel: Fix duty cycle calculation in .get_state() Uwe Kleine-König
2021-04-18 20:57 ` Uwe Kleine-König
2021-04-19 19:29 ` Uwe Kleine-König
2021-04-19 19:29   ` Uwe Kleine-König

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.