From: Baruch Siach Date: Wed, 20 Jan 2021 16:16:26 +0000 (+0200) Subject: gpio: mvebu: make pwm .get_state closer to idempotent X-Git-Tag: accepted/tizen/unified/20230118.172025~7806^2~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=de1eaf6016b311dcc53d2297952edcdc87bcc941;p=platform%2Fkernel%2Flinux-rpi.git gpio: mvebu: make pwm .get_state closer to idempotent Round up the divisions in .get_state() to make applying the read out configuration idempotent in most cases as .apply rounds down. Reported-by: Uwe Kleine-König Reviewed-by: Uwe Kleine-König Reviewed-by: Linus Walleij Signed-off-by: Baruch Siach Signed-off-by: Bartosz Golaszewski --- diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c index c424d88..8673ba7 100644 --- a/drivers/gpio/gpio-mvebu.c +++ b/drivers/gpio/gpio-mvebu.c @@ -668,7 +668,7 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip, regmap_read(mvpwm->regs, mvebu_pwmreg_blink_on_duration(mvpwm), &u); val = (unsigned long long) u * NSEC_PER_SEC; - do_div(val, mvpwm->clk_rate); + val = DIV_ROUND_UP_ULL(val, mvpwm->clk_rate); if (val > UINT_MAX) state->duty_cycle = UINT_MAX; else if (val) @@ -680,7 +680,7 @@ static void mvebu_pwm_get_state(struct pwm_chip *chip, regmap_read(mvpwm->regs, mvebu_pwmreg_blink_off_duration(mvpwm), &u); val += (unsigned long long) u; /* period = on + off duration */ val *= NSEC_PER_SEC; - do_div(val, mvpwm->clk_rate); + val = DIV_ROUND_UP_ULL(val, mvpwm->clk_rate); if (val > UINT_MAX) state->period = UINT_MAX; else if (val)