summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorBaruch Siach <baruch@tkos.co.il>2021-01-20 19:16:25 +0300
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2021-02-15 13:43:30 +0300
commitaa37e27f610fe3e7539c066d9c1f5304390086d6 (patch)
tree40e5f553d7fb46c1976af9952b053db5044d6f7f /drivers/gpio
parent4bf2426103d2dd89c1b48bd5eba8cd16903ec40b (diff)
downloadlinux-aa37e27f610fe3e7539c066d9c1f5304390086d6.tar.xz
gpio: mvebu: improve pwm period calculation accuracy
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@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-mvebu.c4
1 files 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)