Skip to content

Commit

Permalink
hwmon: (pwm-fan) Fix suspend/resume behavior
Browse files Browse the repository at this point in the history
The state of a PWM output is not clearly defined after resume. Some PWM
drivers do not restore the duty cycle upon resume, thus it is necessary to
manually restore the correct value.

Signed-off-by: Kamil Debski <[email protected]>
Signed-off-by: Guenter Roeck <[email protected]>
  • Loading branch information
Kamil Debski authored and groeck committed Nov 11, 2014
1 parent aab18da commit 48b9d5b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/hwmon/pwm-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,17 @@ static int pwm_fan_suspend(struct device *dev)
static int pwm_fan_resume(struct device *dev)
{
struct pwm_fan_ctx *ctx = dev_get_drvdata(dev);
unsigned long duty;
int ret;

if (ctx->pwm_value)
return pwm_enable(ctx->pwm);
return 0;
if (ctx->pwm_value == 0)
return 0;

duty = DIV_ROUND_UP(ctx->pwm_value * (ctx->pwm->period - 1), MAX_PWM);
ret = pwm_config(ctx->pwm, duty, ctx->pwm->period);
if (ret)
return ret;
return pwm_enable(ctx->pwm);
}
#endif

Expand Down

0 comments on commit 48b9d5b

Please sign in to comment.