@@ -65,19 +65,18 @@ static void sample_timer(struct timer_list *t)
{
struct pwm_fan_ctx *ctx = from_timer(ctx, t, rpm_timer);
ktime_t now = ktime_get();
+ unsigned int delta = ktime_ms_delta(now, ctx->sample_start);
int i;
for (i = 0; i < ctx->tach_count; i++) {
struct pwm_fan_tach *tach;
- int pulses;
- u64 tmp;
+ unsigned int pulses;
tach = &ctx->tachs[i];
pulses = atomic_read(&tach->pulses);
atomic_sub(pulses, &tach->pulses);
- tmp = (u64)pulses * ktime_ms_delta(now, ctx->sample_start) * 60;
- do_div(tmp, tach->pulses_per_revolution * 1000);
- tach->rpm = tmp;
+ tach->rpm = (pulses * 1000 * 60) /
+ (tach->pulses_per_revolution * delta);
}
ctx->sample_start = now;
To convert the number of pulses counted into an RPM estimation, we need to divide by the width of our measurement interval instead of multiplying by it. We also don't need to do 64-bit division, with 32-bits we can handle a fan running at over 4 million RPM. Signed-off-by: Paul Barker <pbarker@konsulko.com> --- drivers/hwmon/pwm-fan.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)