mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v5] hwmon: (pwm-fan): Default to the Maximum cooling level if provided
@ 2025-01-13 13:51 Peter Korsgaard
  2025-01-13 16:56 ` Guenter Roeck
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Korsgaard @ 2025-01-13 13:51 UTC (permalink / raw)
  To: Guenter Roeck, linux-hwmon; +Cc: Peter Korsgaard, Jean Delvare, open list

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.

The driver optionally accept a list of "cooling-levels" for the thermal
subsystem.  If provided, use the PWM value corresponding to the maximum
cooling level rather than the full level as the initial PWM setting.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
Changes since v4:
- Dropped custom property, use highest cooling level

Changes since v3:
- Readded validation code from v2, reworded commit message

Changes since v2:
- Recreated/resent

Changes since v1:
- Rename property to default-pwm
- Drop u32 cast

 drivers/hwmon/pwm-fan.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 53a1a968d00d..f8282050a4dd 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -497,7 +497,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
 	struct device *hwmon;
 	int ret;
 	const struct hwmon_channel_info **channels;
-	u32 pwm_min_from_stopped = 0;
+	u32 initial_pwm, pwm_min_from_stopped = 0;
 	u32 *fan_channel_config;
 	int channel_count = 1;	/* We always have a PWM channel. */
 	int i;
@@ -545,11 +545,22 @@ static int pwm_fan_probe(struct platform_device *pdev)
 
 	ctx->enable_mode = pwm_disable_reg_enable;
 
+	ret = pwm_fan_get_cooling_data(dev, ctx);
+	if (ret)
+		return ret;
+
+
+	/* use maximum cooling level if provided */
+	if (ctx->pwm_fan_cooling_levels)
+		initial_pwm = ctx->pwm_fan_cooling_levels[ctx->pwm_fan_max_state];
+	else
+		initial_pwm = MAX_PWM;
+
 	/*
 	 * Set duty cycle to maximum allowed 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, initial_pwm);
 	if (ret) {
 		dev_err(dev, "Failed to configure PWM: %d\n", ret);
 		return ret;
@@ -661,10 +672,6 @@ static int pwm_fan_probe(struct platform_device *pdev)
 		return PTR_ERR(hwmon);
 	}
 
-	ret = pwm_fan_get_cooling_data(dev, ctx);
-	if (ret)
-		return ret;
-
 	ctx->pwm_fan_state = ctx->pwm_fan_max_state;
 	if (IS_ENABLED(CONFIG_THERMAL)) {
 		cdev = devm_thermal_of_cooling_device_register(dev,
-- 
2.39.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v5] hwmon: (pwm-fan): Default to the Maximum cooling level if provided
  2025-01-13 13:51 [PATCH v5] hwmon: (pwm-fan): Default to the Maximum cooling level if provided Peter Korsgaard
@ 2025-01-13 16:56 ` Guenter Roeck
  0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2025-01-13 16:56 UTC (permalink / raw)
  To: Peter Korsgaard; +Cc: linux-hwmon, Jean Delvare, open list

On Mon, Jan 13, 2025 at 02:51:18PM +0100, Peter Korsgaard wrote:
> 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.
> 
> The driver optionally accept a list of "cooling-levels" for the thermal
> subsystem.  If provided, use the PWM value corresponding to the maximum
> cooling level rather than the full level as the initial PWM setting.
> 
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>

Applied, after

> +	ret = pwm_fan_get_cooling_data(dev, ctx);
> +	if (ret)
> +		return ret;
> +
> +

dropping this double empty line.

Guenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-13 16:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-13 13:51 [PATCH v5] hwmon: (pwm-fan): Default to the Maximum cooling level if provided Peter Korsgaard
2025-01-13 16:56 ` Guenter Roeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®