diff mbox series

[2/2] hwmon: (pwm-fan): Make default PWM duty cycle configurable

Message ID 20250102175041.822977-2-peter@korsgaard.com (mailing list archive)
State Superseded
Headers show
Series [1/2] dt-bindings: hwmon: pwm-fan: Document default-pwm property | expand

Commit Message

Peter Korsgaard Jan. 2, 2025, 5:50 p.m. UTC
The pwm-fan driver uses full PWM (255) duty cycle at startup, which may not
always be desirable because of noise or power consumption peaks, so support
an optional "default-pwm" property that can be used to specify the default
PWM duty cycle.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
 drivers/hwmon/pwm-fan.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 53a1a968d00d..09e9047635f7 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -499,6 +499,7 @@  static int pwm_fan_probe(struct platform_device *pdev)
 	const struct hwmon_channel_info **channels;
 	u32 pwm_min_from_stopped = 0;
 	u32 *fan_channel_config;
+	u32 default_pwm;
 	int channel_count = 1;	/* We always have a PWM channel. */
 	int i;
 
@@ -545,11 +546,15 @@  static int pwm_fan_probe(struct platform_device *pdev)
 
 	ctx->enable_mode = pwm_disable_reg_enable;
 
+	ret = device_property_read_u32(dev, "default-pwm", &default_pwm);
+	if (ret)
+		default_pwm = MAX_PWM;
+
 	/*
-	 * Set duty cycle to maximum allowed and enable PWM output as well as
+	 * Set duty cycle to default and enable PWM output as well as
 	 * the regulator. In case of error nothing is changed
 	 */
-	ret = set_pwm(ctx, MAX_PWM);
+	ret = set_pwm(ctx, default_pwm);
 	if (ret) {
 		dev_err(dev, "Failed to configure PWM: %d\n", ret);
 		return ret;