From nobody Sun Feb 8 06:21:41 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78F1D322C70 for ; Thu, 25 Dec 2025 14:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766672616; cv=none; b=cnehqkfsSuCultmKyTjbrjhTIL63x7rSRiZiGCZ5t8PsAZOdASW2U94KSZoSTdpZ7hRyqYS8X2Whzr0K8gYTgbqYXiKKsoRgR1ND2Nlvm5ZvarkgUZwI3waZpmAC3v9L6aCrXn98kvaLhi2KjHUDyU2yhvfBg6KMF+GecORdFzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766672616; c=relaxed/simple; bh=mVPS6LkRPl+sxwDQfI689mE4Ko3BwxorlYHQVKDDTOM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pghIxGjT9bN3OcyIMH+IkMLY+O3qp9wRglzecGl2V88j3vBUpUCY82v6gk8OdBoX0kpoPYqfG9O5YefKIU9zTp8AUED+0FJ/inbA7H9ea6K9cLUnLbmY9jVVf5fim5tHe1Vg1eyjIlw+XF7Ce/PM9aMbmE/YvYcyGLjirzJnPJY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aqFoQmiR; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aqFoQmiR" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2a07f8dd9cdso70789655ad.1 for ; Thu, 25 Dec 2025 06:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766672614; x=1767277414; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6XtGbvPPOEhA++1tnsjmmdjZm8y7YdqsFQGc+i7WZUg=; b=aqFoQmiRm9a8kF7agSMU9qGmkcBflkC7WGX4d80tkfk+jytYY/AFkZDhXhzQGJ6HWw UJuYVMLXMxScy/5c6IplWo/V5XqsEETr0k1ssEp4WqAQujIS8lfcIIdhoDuW5hN/1L9L ikY9+oumhDjcifzh9c8rDoGvnLVX5/iLzB06z5EpIwcJRfhpON2uC97CVbpqhZulMoDR dmsF1S2j/8cpy5tdqX0CDjtFjX5mrUHs8DTc3S2y92iIrO3os6bB7g1+m+fbw4s3Qggj mPVg8Xcz+gDqQcu/lIzdXdnTYg0VQd0Ul5L8wqvhSnTw3Nn2DXROjkYntvHkiSCef0x/ KP3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766672614; x=1767277414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=6XtGbvPPOEhA++1tnsjmmdjZm8y7YdqsFQGc+i7WZUg=; b=jZbmeZxWnxWrI07AlIwc70NpFbSjbc9hUgY1v/tyaLBcDZ9bESXt/WUBjN+15WxXPe p6DozNTfN2qLNY6x5fuYAPguVUV90MeNtIlqQL5/j+IeUi00bpu/IHwONWGVbFvw5XXe rrW3VyTvet0iKL1xHJ6lHTmm6KTZ/wCd9lzIHaUv1krAIzbvZDKoy1zSBPspQ8mvopDo rb97SI5TfyGoGLej1QkJRvYIy4Rr602cZi0vaxoa/JtRhtdttnxi+/MhkrMfCdeDKvwW e2XhF9i/MYk6C1em2MSruxn1WoR2+EfxFTQCQydk0uv8GShdM+gKKZmchbLmIeWXupt5 EpYw== X-Forwarded-Encrypted: i=1; AJvYcCVvtkDGOH3xlcC5JA50Z1hunp+/bU7bzoLoGZWf3+m5lpP+aAhtiziF0oBC1S49iX1VGMYgxEkNeDbhXHw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxl0Biar8BKXal4YCVprkpC6dj5REbTCxnCCKQ908SBkIKv+47d m7bJeGIdMga79q5M8+lU1YQT6D126befO0P76vi1ZmATnjX4GP/hS6Dy X-Gm-Gg: AY/fxX5N2SgYRU5fAVp+NliFabPGIVCYyBhJQPiawockWUqM/FCZeH0Mp7Q1RIiqG3U OfZo7MOh7sK6SCY4RMkQdq8DMnF6fEo4olUZMi0zyetYsYXyPbeS9o26+CiRnjsMog0jfY48HXz ryApDQtWl/C6nov0O4qvyX+fUDW6TFvQGKiCaO3aJGi/4Nl7mlQrx48EdBfma70wwhjfP8lS44Z Y7MmplFhYayOgkDUciUH6GKud6XDpbpbNkNpggVcz1va1zHLCuI8F/tER6grtW1W89lvxmWR+th jLg1iX4oilotE1KREbd7PTFOAlxahuNYDITyMISOa8H+4sfCaxJMyYFhIYtXXIhspGV/1mNrjNp /BCOyCdt314pTjQIy5EsnAAZrDJHI5ObL2pTJYXDiuvEvg6PxPoKBl9ZOgjoHUnC7vJrwfXgvRg z/NPlIvGEphSbZPwzcLq0s7yp7+HagTg== X-Google-Smtp-Source: AGHT+IEfZuFwJNEM07LBr6PnqvkSk5drPf1sIoilREe3rc89Scyt2QFKpZoCXX/Sodddgl7xn9n3ZQ== X-Received: by 2002:a17:902:e746:b0:2a0:d074:e9f4 with SMTP id d9443c01a7336-2a2f2c4e3dcmr207774055ad.59.1766672613689; Thu, 25 Dec 2025 06:23:33 -0800 (PST) Received: from archlinux ([2405:201:1b:225c:eb9d:1fc0:f95c:bd90]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3da7dabsm180892195ad.25.2025.12.25.06.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Dec 2025 06:23:33 -0800 (PST) From: Krishna Chomal To: ilpo.jarvinen@linux.intel.com, hansg@kernel.org, linux@roeck-us.net Cc: platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Chomal Subject: [PATCH 1/2] platform/x86: hp-wmi: add manual fan control for Victus S models Date: Thu, 25 Dec 2025 19:53:09 +0530 Message-ID: <20251225142310.204831-2-krishna.chomal108@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251225142310.204831-1-krishna.chomal108@gmail.com> References: <20251225142310.204831-1-krishna.chomal108@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add manual fan speed control and PWM reporting for HP Victus S-series laptops. While HPWMI_FAN_SPEED_SET_QUERY was previously added to reset max fan mode, it is actually capable of individual fan control. This patch implements hp_wmi_fan_speed_set() to allow manual control and hides PWM inputs for non-Victus devices as the query is Victus specific. The existing hp_wmi_fan_speed_max_get() query is unreliable on Victus S firmware, often incorrectly reporting "Auto" mode even when "Max" is active. To resolve this synchronization issue, move state tracking to a per-device private context and enforce "Auto" mode during driver initialization to ensure a consistent starting point. Tested on: HP Omen 16-wf1xxx (board ID 8C78) Signed-off-by: Krishna Chomal --- drivers/platform/x86/hp/hp-wmi.c | 243 +++++++++++++++++++++++++------ 1 file changed, 199 insertions(+), 44 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index f4ea1ea05997..9fb956ce809a 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -30,6 +30,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Matthew Garrett "); MODULE_DESCRIPTION("HP laptop WMI driver"); @@ -190,7 +191,8 @@ enum hp_wmi_gm_commandtype { HPWMI_SET_GPU_THERMAL_MODES_QUERY =3D 0x22, HPWMI_SET_POWER_LIMITS_QUERY =3D 0x29, HPWMI_VICTUS_S_FAN_SPEED_GET_QUERY =3D 0x2D, - HPWMI_FAN_SPEED_SET_QUERY =3D 0x2E, + HPWMI_VICTUS_S_FAN_SPEED_SET_QUERY =3D 0x2E, + HPWMI_VICTUS_S_GET_FAN_TABLE_QUERY =3D 0x2F, }; =20 enum hp_wmi_command { @@ -348,6 +350,32 @@ static const char * const tablet_chassis_types[] =3D { =20 #define DEVICE_MODE_TABLET 0x06 =20 +#define CPU_FAN 0 +#define GPU_FAN 1 + +enum pwm_modes { + PWM_MODE_MAX =3D 0, + PWM_MODE_MANUAL =3D 1, + PWM_MODE_AUTO =3D 2, +}; + +struct hp_wmi_hwmon_priv { + u8 min_rpm; + u8 max_rpm; + u8 gpu_delta; + u8 mode; + u8 pwm; +}; + +#define RPM_TO_PWM(rpm, ctx) fixp_linear_interpolate(0, 0, \ + (ctx)->max_rpm, U8_MAX, \ + clamp_val((rpm), \ + 0, (ctx)->max_rpm)) +#define PWM_TO_RPM(pwm, ctx) fixp_linear_interpolate(0, 0, \ + U8_MAX, (ctx)->max_rpm, \ + clamp_val((pwm), \ + 0, U8_MAX)) + /* map output size to the corresponding WMI method id */ static inline int encode_outsize_for_pvsz(int outsize) { @@ -637,41 +665,55 @@ static int hp_wmi_fan_speed_max_set(int enabled) return enabled; } =20 -static int hp_wmi_fan_speed_reset(void) +static int hp_wmi_fan_speed_set(struct hp_wmi_hwmon_priv *ctx, u8 speed) { - u8 fan_speed[2] =3D { HP_FAN_SPEED_AUTOMATIC, HP_FAN_SPEED_AUTOMATIC }; + u8 fan_speed[2]; int ret; =20 - ret =3D hp_wmi_perform_query(HPWMI_FAN_SPEED_SET_QUERY, HPWMI_GM, - &fan_speed, sizeof(fan_speed), 0); + if (!ctx) + return -ENODEV; =20 - return ret; -} + fan_speed[CPU_FAN] =3D speed; + fan_speed[GPU_FAN] =3D speed; =20 -static int hp_wmi_fan_speed_max_reset(void) -{ - int ret; + /* + * GPU fan speed is always a little higher than CPU fan speed, we fetch + * this delta value from the fan table during hwmon init. + * Exception: Speed is set to HP_FAN_SPEED_AUTOMATIC, to revert to + * automatic mode. + */ + if (speed !=3D HP_FAN_SPEED_AUTOMATIC) + fan_speed[GPU_FAN] =3D clamp_val(speed + ctx->gpu_delta, 0, U8_MAX); =20 + ret =3D hp_wmi_get_fan_count_userdefine_trigger(); + if (ret < 0) + return ret; + /* Max fans need to be explicitly disabled */ ret =3D hp_wmi_fan_speed_max_set(0); - if (ret) + if (ret < 0) return ret; + ret =3D hp_wmi_perform_query(HPWMI_VICTUS_S_FAN_SPEED_SET_QUERY, HPWMI_GM, + &fan_speed, sizeof(fan_speed), 0); =20 - /* Disabling max fan speed on Victus s1xxx laptops needs a 2nd step: */ - ret =3D hp_wmi_fan_speed_reset(); return ret; } =20 -static int hp_wmi_fan_speed_max_get(void) +static int hp_wmi_fan_speed_reset(struct hp_wmi_hwmon_priv *ctx) { - int val =3D 0, ret; + return hp_wmi_fan_speed_set(ctx, HP_FAN_SPEED_AUTOMATIC); +} =20 - ret =3D hp_wmi_perform_query(HPWMI_FAN_SPEED_MAX_GET_QUERY, HPWMI_GM, - &val, zero_if_sup(val), sizeof(val)); +static int hp_wmi_fan_speed_max_reset(struct hp_wmi_hwmon_priv *ctx) +{ + int ret; =20 + ret =3D hp_wmi_fan_speed_max_set(0); if (ret) - return ret < 0 ? ret : -EINVAL; + return ret; =20 - return val; + /* Disabling max fan speed on Victus s1xxx laptops needs a 2nd step: */ + ret =3D hp_wmi_fan_speed_reset(ctx); + return ret; } =20 static int __init hp_wmi_bios_2008_later(void) @@ -2108,12 +2150,43 @@ static struct platform_driver hp_wmi_driver __refda= ta =3D { .remove =3D __exit_p(hp_wmi_bios_remove), }; =20 +static int hp_wmi_hwmon_enforce_ctx(struct hp_wmi_hwmon_priv *ctx) +{ + if (!ctx) + return -ENODEV; + + switch (ctx->mode) { + 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); + 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)); + 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); + } else { + return hp_wmi_fan_speed_max_set(0); + } + default: + /* shouldn't happen */ + return -EINVAL; + } + + return 0; +} + static umode_t hp_wmi_hwmon_is_visible(const void *data, enum hwmon_sensor_types type, u32 attr, int channel) { switch (type) { case hwmon_pwm: + if (attr =3D=3D hwmon_pwm_input && !is_victus_s_thermal_profile()) + return 0; /* Hide PWM input if not Victus S */ return 0644; case hwmon_fan: if (is_victus_s_thermal_profile()) { @@ -2134,7 +2207,12 @@ static umode_t hp_wmi_hwmon_is_visible(const void *d= ata, static int hp_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types t= ype, u32 attr, int channel, long *val) { - int ret; + struct hp_wmi_hwmon_priv *ctx; + int current_rpm, ret; + + ctx =3D dev_get_drvdata(dev); + if (!ctx) + return -ENODEV; =20 switch (type) { case hwmon_fan: @@ -2147,16 +2225,21 @@ static int hp_wmi_hwmon_read(struct device *dev, en= um hwmon_sensor_types type, *val =3D ret; return 0; case hwmon_pwm: - switch (hp_wmi_fan_speed_max_get()) { - case 0: - /* 0 is automatic fan, which is 2 for hwmon */ - *val =3D 2; + if (attr =3D=3D hwmon_pwm_input) { + if (!is_victus_s_thermal_profile()) + return -EOPNOTSUPP; + ret =3D hp_wmi_get_fan_speed_victus_s(channel); + if (ret < 0) + return ret; + current_rpm =3D ret; + *val =3D RPM_TO_PWM(current_rpm / 100, ctx); return 0; - case 1: - /* 1 is max fan, which is 0 - * (no fan speed control) for hwmon - */ - *val =3D 0; + } + switch (ctx->mode) { + case PWM_MODE_MAX: + case PWM_MODE_MANUAL: + case PWM_MODE_AUTO: + *val =3D ctx->mode; return 0; default: /* shouldn't happen */ @@ -2170,23 +2253,50 @@ static int hp_wmi_hwmon_read(struct device *dev, en= um hwmon_sensor_types type, static int hp_wmi_hwmon_write(struct device *dev, enum hwmon_sensor_types = type, u32 attr, int channel, long val) { + struct hp_wmi_hwmon_priv *ctx; + int current_rpm, ret; + + ctx =3D dev_get_drvdata(dev); + if (!ctx) + return -ENODEV; + switch (type) { case hwmon_pwm: + if (attr =3D=3D hwmon_pwm_input) { + if (!is_victus_s_thermal_profile()) + return -EOPNOTSUPP; + /* pwm input is invalid when not in manual mode */ + if (ctx->mode !=3D PWM_MODE_MANUAL) + return -EINVAL; + /* ensure pwm input is within valid fan speeds */ + ctx->pwm =3D RPM_TO_PWM(clamp_val(PWM_TO_RPM(val, ctx), + ctx->min_rpm, + ctx->max_rpm), + ctx); + return hp_wmi_hwmon_enforce_ctx(ctx); + } switch (val) { - case 0: - if (is_victus_s_thermal_profile()) - hp_wmi_get_fan_count_userdefine_trigger(); - /* 0 is no fan speed control (max), which is 1 for us */ - return hp_wmi_fan_speed_max_set(1); - case 2: - /* 2 is automatic speed control, which is 0 for us */ - if (is_victus_s_thermal_profile()) { - hp_wmi_get_fan_count_userdefine_trigger(); - return hp_wmi_fan_speed_max_reset(); - } else - return hp_wmi_fan_speed_max_set(0); + case PWM_MODE_MAX: + ctx->mode =3D PWM_MODE_MAX; + return hp_wmi_hwmon_enforce_ctx(ctx); + case PWM_MODE_MANUAL: + if (!is_victus_s_thermal_profile()) + return -EOPNOTSUPP; + /* + * When switching to manual mode, set fan speed to + * current RPM values to ensure a smooth transition. + */ + ret =3D hp_wmi_get_fan_speed_victus_s(channel); + if (ret < 0) + return ret; + current_rpm =3D ret; + ctx->pwm =3D RPM_TO_PWM(current_rpm / 100, ctx); + ctx->mode =3D PWM_MODE_MANUAL; + return hp_wmi_hwmon_enforce_ctx(ctx); + case PWM_MODE_AUTO: + ctx->mode =3D PWM_MODE_AUTO; + return hp_wmi_hwmon_enforce_ctx(ctx); default: - /* we don't support manual fan speed control */ return -EINVAL; } default: @@ -2196,7 +2306,7 @@ static int hp_wmi_hwmon_write(struct device *dev, enu= m hwmon_sensor_types type, =20 static const struct hwmon_channel_info * const info[] =3D { HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT, HWMON_F_INPUT), - HWMON_CHANNEL_INFO(pwm, HWMON_PWM_ENABLE), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_ENABLE | HWMON_PWM_INPUT), NULL }; =20 @@ -2211,12 +2321,55 @@ static const struct hwmon_chip_info chip_info =3D { .info =3D info, }; =20 +static int hp_wmi_hwmon_setup_ctx(struct hp_wmi_hwmon_priv *ctx) +{ + u8 fan_data[128]; + u8 (*fan_table)[3]; + u8 rows, min_rpm, max_rpm, gpu_delta; + int ret; + + /* Default behaviour on hwmon init is automatic mode */ + ctx->mode =3D PWM_MODE_AUTO; + + /* Bypass all non-Victus S devices */ + if (!is_victus_s_thermal_profile()) + return 0; + + ret =3D hp_wmi_perform_query(HPWMI_VICTUS_S_GET_FAN_TABLE_QUERY, + HPWMI_GM, &fan_data, 4, sizeof(fan_data)); + if (ret !=3D 0) + return ret; + + rows =3D fan_data[1]; + if (2 + rows * 3 >=3D sizeof(fan_data)) + return -EINVAL; + + fan_table =3D (u8 (*)[3]) & fan_data[2]; + min_rpm =3D fan_table[0][CPU_FAN]; + max_rpm =3D fan_table[rows - 1][CPU_FAN]; + gpu_delta =3D fan_table[0][GPU_FAN] - fan_table[0][CPU_FAN]; + ctx->min_rpm =3D min_rpm; + ctx->max_rpm =3D max_rpm; + ctx->gpu_delta =3D gpu_delta; + + return 0; +} + static int hp_wmi_hwmon_init(void) { struct device *dev =3D &hp_wmi_platform_dev->dev; + struct hp_wmi_hwmon_priv *ctx; struct device *hwmon; + int ret; =20 - hwmon =3D devm_hwmon_device_register_with_info(dev, "hp", &hp_wmi_driver, + ctx =3D devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ret =3D hp_wmi_hwmon_setup_ctx(ctx); + if (ret !=3D 0) + return ret; + hwmon =3D devm_hwmon_device_register_with_info(dev, "hp", ctx, &chip_info, NULL); =20 if (IS_ERR(hwmon)) { @@ -2224,6 +2377,8 @@ static int hp_wmi_hwmon_init(void) return PTR_ERR(hwmon); } =20 + hp_wmi_hwmon_enforce_ctx(ctx); + return 0; } =20 --=20 2.52.0 From nobody Sun Feb 8 06:21:41 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91B36322B8A for ; Thu, 25 Dec 2025 14:23:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766672619; cv=none; b=EA1NAsBfPA+Uc/jl11lz56igsboYJ7jPfCngDx6GaP1w35njIYyL0SLoIPtEcI1LxAjQ1zETN42LnQjp18gMPmfpexbSZmPQA8tawTya0za2zKFKIvw4VAgnLNnohbCPowSsPsJqvmEMsP3yMC3azq5QazuaejmoSNwpe/EKsvw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766672619; c=relaxed/simple; bh=8as6Tg+WQ8IFIRqRkyQHtagnR5iib3TLHnxyF1PKz80=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NXaW8hthITls+VLH5u4xlHFLe3DJutRIkhgSxnVHI2nQDJ8DTp/Ni7lhoyCJ4MFeZ7ylht98cSvlX13EIBCknEiHJ1KZsZZ7AVnvhFuF2OOb2LsoL/E0H4WllnBF7N2/w1Z0vRWFDtjEwJXa6l/5/WgvX0vfqPzedle9kp8OUk0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=EV3OUiw0; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EV3OUiw0" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2a0a95200e8so60282715ad.0 for ; Thu, 25 Dec 2025 06:23:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766672617; x=1767277417; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7sdD19Re9ro0Yav25pXuBH3cxFpqUWhOZekWhN56D70=; b=EV3OUiw0/9Xycj6Kpi5+FEozSbXQNLuquz2WWZkDyz9I79Am6C1aB2k2gcaOE1+Iyn UMFIbS3RZFah4reuB6CQY8K6WrM+NPjZs0PHCBt/oUwyTtFyHlsh8ejktUVlL1omC65v C1YTETcYOfrEEJoV9woSb8nOYJSFqlqWH5bFawIVcO5TuH4M/WVp67Wh4MhI+7yoPoVA AdqGmsc6HTvHX8eZFGYuhSXvTelVcP1I22vnrPjd6jF7pJDzdhRQgNAcsVjrax0cDqNK qtJ8NpbZ4ox74XSOXMNwLpi/YBzWBwXyfRnAONDIZlIKJWThs5UVsMm6gRfery/MfVft oEVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766672617; x=1767277417; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=7sdD19Re9ro0Yav25pXuBH3cxFpqUWhOZekWhN56D70=; b=eUvt5hb6j1wbVkpWMjggEmr04VKc97QxFoT/JZa7fSNXRPpuba6OYoB02PgzA5JQxe DvRwM1m2SQqGNGYgDmtN/c1wNTcou9uqgPrNU7SBKSjRbl4X7YaSggCaNhCVZPGSYr09 CBr1q7BD3ho1f5J/zNbK0N9csfF2lgku1JUGCsQhKUQIvHUbqiKYUFQtPQk30fii3QDO zbP7kPjGNEeuJaMQtow0VRMaa4osr5FXRXCzishMLzU7pekv/3cf/rOvsuIc4teCCZnH REL2jQcokGFrCub5RXtXuE2PBQAdkA8E7EppHSCOmVTtyvDwGmb3fq+0sYWLx2zW/iKA e31Q== X-Forwarded-Encrypted: i=1; AJvYcCX+1fsnaLMB2CeRAmf/ZHG7S+qZNp26Cefc+A/PyXjFFQUhEivQ9wzlL95WyDFYqMkJRol74prtT7TNGBo=@vger.kernel.org X-Gm-Message-State: AOJu0YwMsklmqNn5gUbSjGv3DFREKOnC35HvIfGQYjkY3mxyFASQtovk lSCGzRRM/fBUXbYvv172WISBYBtCCgIFXQIcFIbQfhWws/gVTwAvhbxo X-Gm-Gg: AY/fxX7h2Yx72P+OUQjCiqg6Ub051+y7TiIMsx1ZdfIMS6hmcGsbL/RxxGR1u3BlLKv QiESkzC7BTQknyD5JNFHLu5s3AUepRKth7qUROjWp5KMIlRml0NCfM2I2v6o4iYAN0ncq0fOHTi XRSqi28ftXGc4UPWYHnwg8iu7ydfLqUA2lg+rimJWS+mhJ99o0cYE0eJE23Cy39+EaNCjgilpC8 UzApti+W7zevybKrsiacJL7MyhZsWfjDq3qPz56Hc+wUrhudSmVTjldQkwl/2QHxuJjWZUgTTKY LJ841pFitKBZ/gM8BHV8cEqGbtKNmGPViw44tpt6C6zwuyD+aHaAAuIEVPy4BcS5ycNcyAgLTwd pZI/afUMgafGYINGdCfs/LPplZUF5YBdJNy8CCNx2/ehRts+bafGdcLqdncnOorUWrZzgk91i+e /BSg8xPIN4NViZ9zbdY4M= X-Google-Smtp-Source: AGHT+IHhLxUJC8jIpI5cCyFf9GFQOizdf8CcwKsNqsRfZMhwDQ1kXzIt0SrXUQnK6EXtUrfYhROXMA== X-Received: by 2002:a17:903:1c8:b0:295:c2e7:7199 with SMTP id d9443c01a7336-2a2f2732890mr201635125ad.29.1766672616760; Thu, 25 Dec 2025 06:23:36 -0800 (PST) Received: from archlinux ([2405:201:1b:225c:eb9d:1fc0:f95c:bd90]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3da7dabsm180892195ad.25.2025.12.25.06.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Dec 2025 06:23:36 -0800 (PST) From: Krishna Chomal To: ilpo.jarvinen@linux.intel.com, hansg@kernel.org, linux@roeck-us.net Cc: platform-driver-x86@vger.kernel.org, linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, Krishna Chomal Subject: [PATCH 2/2] platform/x86: hp-wmi: implement fan keep-alive Date: Thu, 25 Dec 2025 19:53:10 +0530 Message-ID: <20251225142310.204831-3-krishna.chomal108@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251225142310.204831-1-krishna.chomal108@gmail.com> References: <20251225142310.204831-1-krishna.chomal108@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 #include #include +#include =20 MODULE_AUTHOR("Matthew Garrett "); 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; }; =20 +/* + * 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_d= evice *device) static void __exit hp_wmi_bios_remove(struct platform_device *device) { int i; + struct hp_wmi_hwmon_priv *ctx; =20 for (i =3D 0; i < rfkill2_count; i++) { rfkill_unregister(rfkill2[i].rfkill); @@ -2091,6 +2100,10 @@ static void __exit hp_wmi_bios_remove(struct platfor= m_device *device) rfkill_unregister(wwan_rfkill); rfkill_destroy(wwan_rfkill); } + + ctx =3D platform_get_drvdata(device); + if (ctx) + cancel_delayed_work_sync(&ctx->keep_alive_dwork); } =20 static int hp_wmi_resume_handler(struct device *device) @@ -2152,6 +2165,8 @@ static struct platform_driver hp_wmi_driver __refdata= =3D { =20 static int hp_wmi_hwmon_enforce_ctx(struct hp_wmi_hwmon_priv *ctx) { + int ret; + if (!ctx) return -ENODEV; =20 @@ -2159,23 +2174,36 @@ static int hp_wmi_hwmon_enforce_ctx(struct hp_wmi_h= wmon_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 =3D 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 =3D 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 =3D hp_wmi_fan_speed_max_reset(ctx); } else { - return hp_wmi_fan_speed_max_set(0); + ret =3D hp_wmi_fan_speed_max_set(0); } + break; default: /* shouldn't happen */ return -EINVAL; } =20 + if (ret < 0) + return ret; + + /* Reschedule keep-alive work based on the new state */ + if (ctx->mode =3D=3D PWM_MODE_MAX || ctx->mode =3D=3D 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; } =20 @@ -2321,6 +2349,20 @@ static const struct hwmon_chip_info chip_info =3D { .info =3D info, }; =20 +static void hp_wmi_hwmon_keep_alive_handler(struct work_struct *work) +{ + struct delayed_work *dwork; + struct hp_wmi_hwmon_priv *ctx; + + dwork =3D to_delayed_work(work); + ctx =3D 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); } =20 + 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); =20 return 0; --=20 2.52.0