[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20251225142310.204831-3-krishna.chomal108@gmail.com>
Date: Thu, 25 Dec 2025 19:53:10 +0530
From: Krishna Chomal <krishna.chomal108@...il.com>
To: ilpo.jarvinen@...ux.intel.com,
hansg@...nel.org,
linux@...ck-us.net
Cc: platform-driver-x86@...r.kernel.org,
linux-hwmon@...r.kernel.org,
linux-kernel@...r.kernel.org,
Krishna Chomal <krishna.chomal108@...il.com>
Subject: [PATCH 2/2] platform/x86: hp-wmi: implement fan keep-alive
The firmware on some HP laptops automatically reverts the fan speed
control to "Auto" mode after a 120 second timeout window.
To ensure that the user-selected fan profile (Max/Manual) persists,
implement a keep-alive mechanism that periodically refreshes the fan
mode trigger before the timeout occurs.
- Introduce a delayed workqueue to trigger the fan mode refresh every 90
seconds, ensuring the system maintains the correct fan mode setting.
- Integrate the refresh mechanism into hp_wmi_hwmon_enforce_ctx() to
start, update or cancel the keep-alive process based on the current
fan mode.
This ensures that the driver stays in sync with the hardware.
Tested on: HP Omen 16-wf1xxx (board ID 8C78)
Signed-off-by: Krishna Chomal <krishna.chomal108@...il.com>
---
drivers/platform/x86/hp/hp-wmi.c | 52 +++++++++++++++++++++++++++++---
1 file changed, 48 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
index 9fb956ce809a..fbe012e7a342 100644
--- a/drivers/platform/x86/hp/hp-wmi.c
+++ b/drivers/platform/x86/hp/hp-wmi.c
@@ -31,6 +31,7 @@
#include <linux/string.h>
#include <linux/dmi.h>
#include <linux/fixp-arith.h>
+#include <linux/workqueue.h>
MODULE_AUTHOR("Matthew Garrett <mjg59@...f.ucam.org>");
MODULE_DESCRIPTION("HP laptop WMI driver");
@@ -365,8 +366,15 @@ struct hp_wmi_hwmon_priv {
u8 gpu_delta;
u8 mode;
u8 pwm;
+ struct delayed_work keep_alive_dwork;
};
+/*
+ * 90s delay to prevent the firmware from resetting fan mode after fixed
+ * 120s timeout
+ */
+#define KEEP_ALIVE_DELAY 90
+
#define RPM_TO_PWM(rpm, ctx) fixp_linear_interpolate(0, 0, \
(ctx)->max_rpm, U8_MAX, \
clamp_val((rpm), \
@@ -2073,6 +2081,7 @@ static int __init hp_wmi_bios_setup(struct platform_device *device)
static void __exit hp_wmi_bios_remove(struct platform_device *device)
{
int i;
+ struct hp_wmi_hwmon_priv *ctx;
for (i = 0; i < rfkill2_count; i++) {
rfkill_unregister(rfkill2[i].rfkill);
@@ -2091,6 +2100,10 @@ static void __exit hp_wmi_bios_remove(struct platform_device *device)
rfkill_unregister(wwan_rfkill);
rfkill_destroy(wwan_rfkill);
}
+
+ ctx = platform_get_drvdata(device);
+ if (ctx)
+ cancel_delayed_work_sync(&ctx->keep_alive_dwork);
}
static int hp_wmi_resume_handler(struct device *device)
@@ -2152,6 +2165,8 @@ static struct platform_driver hp_wmi_driver __refdata = {
static int hp_wmi_hwmon_enforce_ctx(struct hp_wmi_hwmon_priv *ctx)
{
+ int ret;
+
if (!ctx)
return -ENODEV;
@@ -2159,23 +2174,36 @@ static int hp_wmi_hwmon_enforce_ctx(struct hp_wmi_hwmon_priv *ctx)
case PWM_MODE_MAX:
if (is_victus_s_thermal_profile())
hp_wmi_get_fan_count_userdefine_trigger();
- return hp_wmi_fan_speed_max_set(1);
+ ret = hp_wmi_fan_speed_max_set(1);
+ break;
case PWM_MODE_MANUAL:
if (!is_victus_s_thermal_profile())
return -EOPNOTSUPP;
- return hp_wmi_fan_speed_set(ctx, PWM_TO_RPM(ctx->pwm, ctx));
+ ret = hp_wmi_fan_speed_set(ctx, PWM_TO_RPM(ctx->pwm, ctx));
+ break;
case PWM_MODE_AUTO:
if (is_victus_s_thermal_profile()) {
hp_wmi_get_fan_count_userdefine_trigger();
- return hp_wmi_fan_speed_max_reset(ctx);
+ ret = hp_wmi_fan_speed_max_reset(ctx);
} else {
- return hp_wmi_fan_speed_max_set(0);
+ ret = hp_wmi_fan_speed_max_set(0);
}
+ break;
default:
/* shouldn't happen */
return -EINVAL;
}
+ if (ret < 0)
+ return ret;
+
+ /* Reschedule keep-alive work based on the new state */
+ if (ctx->mode == PWM_MODE_MAX || ctx->mode == PWM_MODE_MANUAL)
+ schedule_delayed_work(&ctx->keep_alive_dwork,
+ secs_to_jiffies(KEEP_ALIVE_DELAY));
+ else
+ cancel_delayed_work_sync(&ctx->keep_alive_dwork);
+
return 0;
}
@@ -2321,6 +2349,20 @@ static const struct hwmon_chip_info chip_info = {
.info = info,
};
+static void hp_wmi_hwmon_keep_alive_handler(struct work_struct *work)
+{
+ struct delayed_work *dwork;
+ struct hp_wmi_hwmon_priv *ctx;
+
+ dwork = to_delayed_work(work);
+ ctx = container_of(dwork, struct hp_wmi_hwmon_priv, keep_alive_dwork);
+ /*
+ * Re-apply the current hwmon context settings.
+ * NOTE: hp_wmi_hwmon_enforce_ctx will handle the re-scheduling.
+ */
+ hp_wmi_hwmon_enforce_ctx(ctx);
+}
+
static int hp_wmi_hwmon_setup_ctx(struct hp_wmi_hwmon_priv *ctx)
{
u8 fan_data[128];
@@ -2377,6 +2419,8 @@ static int hp_wmi_hwmon_init(void)
return PTR_ERR(hwmon);
}
+ INIT_DELAYED_WORK(&ctx->keep_alive_dwork, hp_wmi_hwmon_keep_alive_handler);
+ platform_set_drvdata(hp_wmi_platform_dev, ctx);
hp_wmi_hwmon_enforce_ctx(ctx);
return 0;
--
2.52.0
Powered by blists - more mailing lists