[PATCH v2 2/5] gpio: mvebu: improve pwm period calculation accuracy
Baruch Siach
baruch at tkos.co.il
Wed Jan 13 04:22:42 EST 2021
Change 'off' register value calculation from
$off = (period - duty_cycle) * clkrate / NSEC_PER_SEC
to
$off = (period * clkrate / NSEC_PER_SEC) - $on
That is, divide the full period value to reduce rounding error.
Reported-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
Reviewed-by: Uwe Kleine-König <u.kleine-koenig at pengutronix.de>
Signed-off-by: Baruch Siach <baruch at tkos.co.il>
---
drivers/gpio/gpio-mvebu.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a912a8fed197..c424d88e9e2b 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -715,9 +715,9 @@ static int mvebu_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
else
on = 1;
- val = (unsigned long long) mvpwm->clk_rate *
- (state->period - state->duty_cycle);
+ val = (unsigned long long) mvpwm->clk_rate * state->period;
do_div(val, NSEC_PER_SEC);
+ val -= on;
if (val > UINT_MAX)
return -EINVAL;
if (val)
--
2.29.2
More information about the linux-arm-kernel
mailing list