Skip to content

Commit ecf1cf1

Browse files
jacmetgroeck
authored andcommitted
hwmon: (pwm-fan) Default to the Maximum cooling level if provided
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Dropped double empty line] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 74a2594 commit ecf1cf1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

drivers/hwmon/pwm-fan.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int pwm_fan_probe(struct platform_device *pdev)
497497
struct device *hwmon;
498498
int ret;
499499
const struct hwmon_channel_info **channels;
500-
u32 pwm_min_from_stopped = 0;
500+
u32 initial_pwm, pwm_min_from_stopped = 0;
501501
u32 *fan_channel_config;
502502
int channel_count = 1; /* We always have a PWM channel. */
503503
int i;
@@ -545,11 +545,21 @@ static int pwm_fan_probe(struct platform_device *pdev)
545545

546546
ctx->enable_mode = pwm_disable_reg_enable;
547547

548+
ret = pwm_fan_get_cooling_data(dev, ctx);
549+
if (ret)
550+
return ret;
551+
552+
/* use maximum cooling level if provided */
553+
if (ctx->pwm_fan_cooling_levels)
554+
initial_pwm = ctx->pwm_fan_cooling_levels[ctx->pwm_fan_max_state];
555+
else
556+
initial_pwm = MAX_PWM;
557+
548558
/*
549559
* Set duty cycle to maximum allowed and enable PWM output as well as
550560
* the regulator. In case of error nothing is changed
551561
*/
552-
ret = set_pwm(ctx, MAX_PWM);
562+
ret = set_pwm(ctx, initial_pwm);
553563
if (ret) {
554564
dev_err(dev, "Failed to configure PWM: %d\n", ret);
555565
return ret;
@@ -661,10 +671,6 @@ static int pwm_fan_probe(struct platform_device *pdev)
661671
return PTR_ERR(hwmon);
662672
}
663673

664-
ret = pwm_fan_get_cooling_data(dev, ctx);
665-
if (ret)
666-
return ret;
667-
668674
ctx->pwm_fan_state = ctx->pwm_fan_max_state;
669675
if (IS_ENABLED(CONFIG_THERMAL)) {
670676
cdev = devm_thermal_of_cooling_device_register(dev,

0 commit comments

Comments
 (0)