From: Paul Cercueil <p...@crapouillou.net>

commit 9017dc4fbd59c09463019ce494cfe36d654495a8 upstream.

Calculating the hardware value for the duty from the hardware value of
the period resulted in a precision loss versus calculating it from the
clock rate directly.

(Also remove a cast that doesn't really need to be here)

Fixes: f6b8a5700057 ("pwm: Add Ingenic JZ4740 support")
Cc: <sta...@vger.kernel.org>
Suggested-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
Reviewed-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
Signed-off-by: Paul Cercueil <p...@crapouillou.net>
Signed-off-by: Thierry Reding <thierry.red...@gmail.com>
[ukl: backport to v5.4.y and adapt commit log accordingly]
Signed-off-by: Uwe Kleine-König <u.kleine-koe...@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>

---
 drivers/pwm/pwm-jz4740.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/drivers/pwm/pwm-jz4740.c
+++ b/drivers/pwm/pwm-jz4740.c
@@ -108,8 +108,8 @@ static int jz4740_pwm_apply(struct pwm_c
        if (prescaler == 6)
                return -EINVAL;
 
-       tmp = (unsigned long long)period * state->duty_cycle;
-       do_div(tmp, state->period);
+       tmp = (unsigned long long)rate * state->duty_cycle;
+       do_div(tmp, NSEC_PER_SEC);
        duty = period - tmp;
 
        if (duty >= period)


Reply via email to