Skip to content

Commit 9017dc4

Browse files
pcercueithierryreding
authored andcommitted
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: f6b8a57 ("pwm: Add Ingenic JZ4740 support") Cc: <[email protected]> Suggested-by: Uwe Kleine-König <[email protected]> Reviewed-by: Uwe Kleine-König <[email protected]> Signed-off-by: Paul Cercueil <[email protected]> Signed-off-by: Thierry Reding <[email protected]>
1 parent b48d49e commit 9017dc4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/pwm/pwm-jz4740.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@ static int jz4740_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
158158
/* Calculate period value */
159159
tmp = (unsigned long long)rate * state->period;
160160
do_div(tmp, NSEC_PER_SEC);
161-
period = (unsigned long)tmp;
161+
period = tmp;
162162

163163
/* Calculate duty value */
164-
tmp = (unsigned long long)period * state->duty_cycle;
165-
do_div(tmp, state->period);
164+
tmp = (unsigned long long)rate * state->duty_cycle;
165+
do_div(tmp, NSEC_PER_SEC);
166166
duty = period - tmp;
167167

168168
if (duty >= period)

0 commit comments

Comments
 (0)