Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (pwm-fan) Implement after shutdown fan settings

Add fan-shutdown-percent property, used to describe fan RPM in percent set
during shutdown. This is used to keep the fan running at fixed RPM after
the kernel shut down, which is useful on hardware that does keep heating
itself even after the kernel did shut down, for example from some sort of
management core. The current behavior of pwm-fan is to unconditionally
stop the fan on shutdown, which is not always the safe and correct thing
to do, so let the hardware description include the expected behavior.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Link: https://lore.kernel.org/r/20250904202157.170600-2-marek.vasut+renesas@mailbox.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Marek Vasut and committed by
Guenter Roeck
da0a3cc7 bd48b5a4

+15 -3
+15 -3
drivers/hwmon/pwm-fan.c
··· 64 64 65 65 u64 pwm_duty_cycle_from_stopped; 66 66 u32 pwm_usec_from_stopped; 67 + u8 pwm_shutdown; 67 68 }; 68 69 69 70 /* This handler assumes self resetting edge triggered interrupt. */ ··· 485 484 struct pwm_fan_ctx *ctx = __ctx; 486 485 487 486 timer_delete_sync(&ctx->rpm_timer); 488 - /* Switch off everything */ 489 - ctx->enable_mode = pwm_disable_reg_disable; 490 - pwm_fan_power_off(ctx, true); 487 + if (ctx->pwm_shutdown) { 488 + ctx->enable_mode = pwm_enable_reg_enable; 489 + __set_pwm(ctx, ctx->pwm_shutdown); 490 + } else { 491 + /* Switch off everything */ 492 + ctx->enable_mode = pwm_disable_reg_disable; 493 + pwm_fan_power_off(ctx, true); 494 + } 491 495 } 492 496 493 497 static int pwm_fan_probe(struct platform_device *pdev) ··· 504 498 int ret; 505 499 const struct hwmon_channel_info **channels; 506 500 u32 initial_pwm, pwm_min_from_stopped = 0; 501 + u32 pwm_shutdown_percent = 0; 507 502 u32 *fan_channel_config; 508 503 int channel_count = 1; /* We always have a PWM channel. */ 509 504 int i; ··· 654 647 655 648 channels[1] = &ctx->fan_channel; 656 649 } 650 + 651 + ret = device_property_read_u32(dev, "fan-shutdown-percent", 652 + &pwm_shutdown_percent); 653 + if (!ret && pwm_shutdown_percent) 654 + ctx->pwm_shutdown = (clamp(pwm_shutdown_percent, 0, 100) * 255) / 100; 657 655 658 656 ret = device_property_read_u32(dev, "fan-stop-to-start-percent", 659 657 &pwm_min_from_stopped);