aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm/pwm-jz4740.c
diff options
context:
space:
mode:
authorPaul Cercueil <paul@crapouillou.net>2020-05-27 13:52:23 +0200
committerThierry Reding <thierry.reding@gmail.com>2020-06-02 14:24:00 +0200
commit9017dc4fbd59c09463019ce494cfe36d654495a8 (patch)
tree284a1b3f595e017977c4c0e9fd3836947e42b521 /drivers/pwm/pwm-jz4740.c
parentpwm: jz4740: Drop dependency on MACH_INGENIC (diff)
downloadlinux-dev-9017dc4fbd59c09463019ce494cfe36d654495a8.tar.xz
linux-dev-9017dc4fbd59c09463019ce494cfe36d654495a8.zip
pwm: jz4740: Enhance precision in calculation of duty cycle
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: <stable@vger.kernel.org> Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Reviewed-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Paul Cercueil <paul@crapouillou.net> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm/pwm-jz4740.c')
-rw-r--r--drivers/pwm/pwm-jz4740.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/drivers/pwm/pwm-jz4740.c b/drivers/pwm/pwm-jz4740.c
index 3cd5c054ad9a..4fe9d99ac9a9 100644
--- a/drivers/pwm/pwm-jz4740.c
+++ b/drivers/pwm/pwm-jz4740.c
@@ -158,11 +158,11 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
/* Calculate period value */
tmp = (unsigned long long)rate * state->period;
do_div(tmp, NSEC_PER_SEC);
- period = (unsigned long)tmp;
+ period = tmp;
/* Calculate duty value */
- 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)