diff mbox series

[v3,5/6] hwmon: pwm-fan: Move PWM enable into separate function

Message ID 20220517142620.1523143-6-alexander.stein@ew.tq-group.com (mailing list archive)
State Superseded
Headers show
Series hwmon: pwm-fan: switch regulator dynamically | expand

Commit Message

Alexander Stein May 17, 2022, 2:26 p.m. UTC
This allows reusage in other code paths.

Signed-off-by: Alexander Stein <alexander.stein@ew.tq-group.com>
---
 drivers/hwmon/pwm-fan.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 21bfd0e931ba..9ebe958cc908 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -84,9 +84,17 @@  static void sample_timer(struct timer_list *t)
 	mod_timer(&ctx->rpm_timer, jiffies + HZ);
 }
 
-static int pwm_fan_power_on(struct pwm_fan_ctx *ctx)
+static int pwm_fan_enable_pwm(struct pwm_fan_ctx *ctx)
 {
 	struct pwm_state state;
+
+	pwm_get_state(ctx->pwm, &state);
+	state.enabled = true;
+	return pwm_apply_state(ctx->pwm, &state);
+}
+
+static int pwm_fan_power_on(struct pwm_fan_ctx *ctx)
+{
 	int ret;
 
 	if (ctx->enabled)
@@ -98,9 +106,7 @@  static int pwm_fan_power_on(struct pwm_fan_ctx *ctx)
 		return ret;
 	}
 
-	pwm_get_state(ctx->pwm, &state);
-	state.enabled = true;
-	ret = pwm_apply_state(ctx->pwm, &state);
+	ret = pwm_fan_enable_pwm(ctx);
 	if (ret) {
 		dev_err(ctx->dev, "failed to enable PWM\n");
 		goto disable_regulator;