unsigned long period;
int ret = 0;
- mutex_lock(&ctx->lock);
-
if (pwm > 0) {
period = state->period;
state->duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);
ret = pwm_apply_state(ctx->pwm, state);
if (ret)
- goto exit_set_pwm_err;
+ return ret;
ret = pwm_fan_power_on(ctx);
} else {
ret = pwm_fan_power_off(ctx);
if (!ret)
ctx->pwm_value = pwm;
-exit_set_pwm_err:
+ return ret;
+}
+
+static int set_pwm(struct pwm_fan_ctx *ctx, unsigned long pwm)
+{
+ int ret;
+
+ mutex_lock(&ctx->lock);
+ ret = __set_pwm(ctx, pwm);
mutex_unlock(&ctx->lock);
+
return ret;
}
if (val < 0 || val > MAX_PWM)
return -EINVAL;
- ret = __set_pwm(ctx, val);
+ ret = set_pwm(ctx, val);
if (ret)
return ret;
if (state == ctx->pwm_fan_state)
return 0;
- ret = __set_pwm(ctx, ctx->pwm_fan_cooling_levels[state]);
+ ret = set_pwm(ctx, ctx->pwm_fan_cooling_levels[state]);
if (ret) {
dev_err(&cdev->device, "Cannot set pwm!\n");
return ret;
pwm_init_state(ctx->pwm, &ctx->pwm_state);
/*
- * __set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
+ * set_pwm assumes that MAX_PWM * (period - 1) fits into an unsigned
* long. Check this here to prevent the fan running at a too low
* frequency.
*/
}
/* Set duty cycle to maximum allowed and enable PWM output */
- ret = __set_pwm(ctx, MAX_PWM);
+ ret = set_pwm(ctx, MAX_PWM);
if (ret) {
dev_err(dev, "Failed to configure PWM: %d\n", ret);
return ret;