[PATCH v2 1/2] hwmon: (pwm-fan) add option to leave fan on shutdown

Akinobu Mita posted 2 patches 1 month ago
[PATCH v2 1/2] hwmon: (pwm-fan) add option to leave fan on shutdown
Posted by Akinobu Mita 1 month ago
This adds an optional property "retain-state-shutdown" as requested by
Billy Tsai.

Billy said:
 "Our platform is BMC that will use a PWM-FAN driver to control the fan
 on the managed host. In our case, we do not want to stop the fan when
 the BMC is reboot, which may cause the temperature of the managed host
 not to be lowered."

Cc: Jean Delvare <jdelvare@suse.com>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Rob Herring <robh@kernel.org>
Cc: Krzysztof Kozlowski <krzk+dt@kernel.org>
Cc: Conor Dooley <conor+dt@kernel.org>
Cc: Billy Tsai <billy_tsai@aspeedtech.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 drivers/hwmon/pwm-fan.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index c434db4656e7..dcb48a41f9f0 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -51,6 +51,7 @@ struct pwm_fan_ctx {
 	u32 *pulses_per_revolution;
 	ktime_t sample_start;
 	struct timer_list rpm_timer;
+	bool retain_state_shutdown;
 
 	unsigned int pwm_value;
 	unsigned int pwm_fan_state;
@@ -490,6 +491,8 @@ static int pwm_fan_probe(struct platform_device *pdev)
 
 	mutex_init(&ctx->lock);
 
+	ctx->retain_state_shutdown = device_property_read_bool(dev, "retain-state-shutdown");
+
 	ctx->dev = &pdev->dev;
 	ctx->pwm = devm_pwm_get(dev, NULL);
 	if (IS_ERR(ctx->pwm))
@@ -655,7 +658,8 @@ static void pwm_fan_shutdown(struct platform_device *pdev)
 {
 	struct pwm_fan_ctx *ctx = platform_get_drvdata(pdev);
 
-	pwm_fan_cleanup(ctx);
+	if (!ctx->retain_state_shutdown)
+		pwm_fan_cleanup(ctx);
 }
 
 static int pwm_fan_suspend(struct device *dev)
-- 
2.34.1