diff options
author | Wolfram Sang <wsa@kernel.org> | 2020-12-07 07:57:42 +0100 |
---|---|---|
committer | Wolfram Sang <wsa@kernel.org> | 2020-12-07 07:57:42 +0100 |
commit | 1e04538c751bfc572bfa9995996c7f4af098a625 (patch) | |
tree | 40aa603803f857af4a5a5f25f81b6fb31b8e0152 /drivers/hwmon/pwm-fan.c | |
parent | 5e9a97b1f4491b8b65874901ad084348fcaba327 (diff) | |
parent | 0477e92881850d44910a7e94fc2c46f96faa131f (diff) |
Merge branch 'i2c/for-current' into i2c/for-5.11
Diffstat (limited to 'drivers/hwmon/pwm-fan.c')
-rw-r--r-- | drivers/hwmon/pwm-fan.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index bdba2143021a..1f63807c0399 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -54,16 +54,18 @@ static irqreturn_t pulse_handler(int irq, void *dev_id) static void sample_timer(struct timer_list *t) { struct pwm_fan_ctx *ctx = from_timer(ctx, t, rpm_timer); + unsigned int delta = ktime_ms_delta(ktime_get(), ctx->sample_start); int pulses; - u64 tmp; - pulses = atomic_read(&ctx->pulses); - atomic_sub(pulses, &ctx->pulses); - tmp = (u64)pulses * ktime_ms_delta(ktime_get(), ctx->sample_start) * 60; - do_div(tmp, ctx->pulses_per_revolution * 1000); - ctx->rpm = tmp; + if (delta) { + pulses = atomic_read(&ctx->pulses); + atomic_sub(pulses, &ctx->pulses); + ctx->rpm = (unsigned int)(pulses * 1000 * 60) / + (ctx->pulses_per_revolution * delta); + + ctx->sample_start = ktime_get(); + } - ctx->sample_start = ktime_get(); mod_timer(&ctx->rpm_timer, jiffies + HZ); } |