From nobody Sun Feb 8 11:45:04 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 18452392829 for ; Tue, 13 Jan 2026 12:37:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307874; cv=none; b=dTGOAViFRJgz+2R/SuqcrAZQkfe3uIAxGKD1GaFYUSONOEEKOKOBV9Qa4FUu0mt3Mna2fdAVBSkwZRteo76eOD4u+VFsqebzyUY72liA/bgh6NS4xtJ6A6PewAlrG5+RhOoBH/NgZBL4G0qsbiQdjh12VI+/25KfM6PgVscZTqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307874; c=relaxed/simple; bh=MxZjnyoTjZPXcSMm3+p11VDtCqa1QXLdN/oQCkmvRzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e+XVrACnINJl0LkgY9kYXvsvX81uJFm7XdkvjjFh1w7W9zFCACVdDs271rJzx7/iForACN/NMHpB033W1B8BTTsnfCv2wkHjZmWhMAqlf6dLlh2n7TlMV94lgT23Eu4Q+sI8ilDiLRliKJgmIX290eIMJNH8xcRkllwq3pgFDVs= 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=GBg2nsve; arc=none smtp.client-ip=209.85.210.179 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="GBg2nsve" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-81f223c70d8so2523344b3a.1 for ; Tue, 13 Jan 2026 04:37:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768307871; x=1768912671; 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=Ek8W9y2dSmyH8NdT5cyv4Sc3qF3sYWSc+37c6yKZ4wM=; b=GBg2nsvep9xmycM+d+VsY1gAtIvi285U0uDXfhWGguC3iCKmOZHkXAD5G+9L8ncu25 eszEqLn2nUb+u7Cuq32+uxa1RMWqa7xL+Z3CTr5Qy+Xi1WpQ8mOqZUBA/LQyIRWUsjVA 2sAIqYjkSq9ASU/oL5wSE7sThfZqsNFPF7CRyug9oq35hSJqEhBSlBao5RD+g0fO2eby rTSXgZPx934AaAe1suDhYOUM9Ae5xIKExesXwXGVJZlOGhe6LBpTrFYl+KQblYykPIdb aOc3DCT4ADRmHwBwHdpcwMQynqHP9Myo8s2H7lymjls9MzKYoEGAIKRzp8dRRlanQ69S S6Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768307871; x=1768912671; 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=Ek8W9y2dSmyH8NdT5cyv4Sc3qF3sYWSc+37c6yKZ4wM=; b=rsAQWRUPsPH8KWNKcvIQ0VK8Au/mIqiMmukvtbqFeGEYY9UgASAZjah1cpwFcqC+TB c1q+IM8iONGgrrDuBTj2ZbKd1FQZV/sR1E+6Dw0RcKWfsrKDyQI+Iiyr0sgnFd+IgO+A s/oT9s7/XnAcBKcLEeIyF+AY3NFXwVFkIQKrCiHi+mOdXkCnGJGrpyx9bW2Qdyna75Uc vpIgBR7d2lFDNT0YIf2lPuIlzN/r6IoKFAB2qc91KJXI/OMzI3wFStJmrboNWjrghim8 67pqONd2laJnhTi10STZwng1roXR1fkIUS+y4xPl6SUlsxh74+jsJrNvvxZBm8HxoQFP QG4w== X-Forwarded-Encrypted: i=1; AJvYcCXTfA5DzT2Ho1lZ1o1Am6qf5KKzYVTvJpq+8EtcG8ODm06FWFnRftDNJD4Lya46W673QN6/N8brfrxaUoo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzsv+W2KZAiZnAQDXWjNpgVImEbBozEOtq4xS5AWZpw66/XlLGE XBsZn9Fix1m9/48ToTK50gK1NSjztlTBs1vsSLnH40C7j2prYTq0ElZZ X-Gm-Gg: AY/fxX4MLnC1GoBVh9cjDqT8Ge0ysiCaDPW216WpZmK8ptyiutwzf9lxe9JTV1+D0mS YxMkuaLtVkodgzAlyVlN8nhfYSuVk+XqiY2zZEpq+qmKFZm/uEhTyUQ9zdXGToiQXUyUN/+tkwc h2tx6iTEt7b111y5UtGGZpRN3/VqfskBHKEYJJbP0lh3RRAngXggxuhZvw55Hl5I1XNvDSqsNKo kiwIszZzuP2qwI2a9VnsCR8bw7Vgpp9U+zBnE0zI/vyxzkv0NGQlyta2oqGoSeIz5zrXvTGsYBw F0XuMyXNIHRvr/tfcIns6A4BGJIm90Di1izaYyvsKoBW3z5tuDhxLhcagVVBk0OhjVpjX21887H yRR39iQv9XklaOA1W0kI1UukN9MQj+XbR3Z2M2TF6rZ4lQdrEhfGahhyc/DQlnlR/S9zHm1f9C5 onxd2j2nD9bUT3G5IN0wI= X-Google-Smtp-Source: AGHT+IG8e45P51e2OmFz4s7Q7ej/2pZW+W1U90Wu+Xy4EBZ5q2CmssSDDyFnRXP9uzzT3G4y4GiWYA== X-Received: by 2002:a05:6a00:35c6:b0:772:8101:870c with SMTP id d2e1a72fcca58-81b7d260374mr16760305b3a.11.1768307871275; Tue, 13 Jan 2026 04:37:51 -0800 (PST) Received: from archlinux ([2405:201:1b:225c:eb9d:1fc0:f95c:bd90]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81e9dd8fd8dsm11409000b3a.10.2026.01.13.04.37.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 04:37:50 -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 v3 1/3] platform/x86: hp-wmi: order include headers Date: Tue, 13 Jan 2026 18:07:36 +0530 Message-ID: <20260113123738.222244-2-krishna.chomal108@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260113123738.222244-1-krishna.chomal108@gmail.com> References: <20251230145053.516196-1-krishna.chomal108@gmail.com> <20260113123738.222244-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 include headers in hp-wmi driver are currently not in any specific order. As the driver continues to grow, keep the header block organized by sorting them alphabetically. Signed-off-by: Krishna Chomal --- Changes in v3: - New patch in this series --- drivers/platform/x86/hp/hp-wmi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index f4ea1ea05997..fac8e227cee0 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -13,23 +13,23 @@ =20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt =20 -#include -#include +#include +#include +#include +#include #include -#include -#include #include #include +#include +#include +#include #include #include -#include -#include -#include -#include #include #include +#include #include -#include +#include =20 MODULE_AUTHOR("Matthew Garrett "); MODULE_DESCRIPTION("HP laptop WMI driver"); --=20 2.52.0 From nobody Sun Feb 8 11:45:04 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 2E79539341F for ; Tue, 13 Jan 2026 12:37:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307878; cv=none; b=Eu2sB0yUM3vvkDY95Ev5DkWW3zbFoqPYLCmqWICGc4mqrfBEkA8rUZsypif0luYH8refIu76dOTaMteREd3Wo5/2Unn/dCHUJRpHLexRlaeeAjs/zTBpIvIRMOdPYDBnIWZNI+dGcLdSpuHbjQZz/9p8g/CWdMSQOfVWt+qhVY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307878; c=relaxed/simple; bh=HaKSx6NV65iDN09fzoWQFtP8zgGFb5cOLVHtPVcS5R0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XTuM74H0EGZKxFtSAhRuvI11+62tkCBLIEv4Y3p8UW/hKLY68WfZXNNrDesnWsZ3zs1x1J7I3dmkM4pWyYXBx5nOCRBk60s3sfRxt2VsP6Av37UtVsX2ZXiSa7VdLtqfM2b6+LFD6rWU1QcqY4bv9/7T4a25wpF5LVPcJItRtmA= 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=XC64qy5l; arc=none smtp.client-ip=209.85.210.182 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="XC64qy5l" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-81f4ba336b4so2009337b3a.1 for ; Tue, 13 Jan 2026 04:37:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768307875; x=1768912675; 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=nCJ3wfOiyPLlBjH6Yx10fmzb6SWvLj34yQj3s2/EvN8=; b=XC64qy5ljQRlbY7rRea8kmHBUPmwLZlNG72us0Kwm/mwbneVkopyofAq6hsaScKhro GDul+zsIcjl6YY7HTwExDb71hv3r7Y9yskaZYAu9tmwpqh5sgx6UVsO/6wDnmSIkjVd0 Tfrejm944FFwtY80d7sRvquW/6/NmtxVrQbnoHsHKULbA5EUXPSYWvE+vYiWy4/m3Tr1 L6T61IOYkKjiFeBscgYL2Nu1G0e34PNdSS3gDZ1Sknc4t9Pp8Lvgi6gHj8+vs7iedsWh t37XpU/4n57m4VKNaBWgflLeRB3XpuxiUoOfZIxoN3iEnsi8cJOeFqcT0D+nKcjETnur KakA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768307875; x=1768912675; 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=nCJ3wfOiyPLlBjH6Yx10fmzb6SWvLj34yQj3s2/EvN8=; b=QKENb+B6vrmYLFb92sx0dFEq6UvhNP9DXvI3b9hqEns6XS1gJA7OJSmkSy2WRD8JH6 /BvcXhm5uyuk0PnzfUsw92MRbZLzRsrU9OQS3w2hxeGmcTT/FqTCDI0Zh4FikH/VK26k AbAtUN2dCAPtUeqeCxHew6Kuh6mnftKtsuDRQfOkZo/BpwtLg42dw4X+nft5QlXNf1pr STVNergGe6rWu/GvmMu4pAF+3UmaDWYmQIGBUImsTQ797ikWEMEekFAz9Hr9zMYK7JOu GlcH8DC6TIqLtjTesZuTHsbXF5YcUfbQhiOcuf+sQzissgES+hywvD8XzlIrdhbinHo0 b+3A== X-Forwarded-Encrypted: i=1; AJvYcCWrNUJo0d/o1brwpOSEjghI/bgp83y1CBeg5jerZTWRMTJcRqCgaVMm/yoqBDm+tP1DfFmxLzW1xzDMx20=@vger.kernel.org X-Gm-Message-State: AOJu0Yx4fSQ5pA8rEajGlk4uw5NpQLKJORHNZo4FRjK/Ub6YCk5IbRFD C2RMLibjOQnsGSElw5cuFMPzDfIfKFTQVp7z5uzXbF+wrI3uqWZzF7J1 X-Gm-Gg: AY/fxX4y4bYCnFpc0/zwndWB8QXAxtbFlEu2B2vAXOYqF9YuChux3mnPv0cXuxjnqMP y6PEichr5koyloay4phC3lDu0qqFJWc/5jd8mIK8oLevyhxucj2BgAOc3h6AhVib77r510M2jvj +hlB+gOAfp8BrLeM9r4o/h0imm57I5Jx5vVJoepIqs8PGWE1YfVN9TsThyv5vB7wPDKoZyufrzu X2STp5kHt4s/fIua+V5gQHIl0aVEzWLOemc+L2X6I784d5VXqXdfs+6kIn3u9HE327uptp6ktrg E0TWlfyPFgunhhnh9D6HUOWdqfUEOvVe2P82OwlUaMS6gOx+eMIrzShFhH2K4qs86e3D1bHmCBd MfVs5qZF3dzbPFXA3EHRjAGY23TZI/vsibAvKy/vzTp6BKRDynA7DoLANn6nJ2msC7+44kzTct5 PR4X47CtS9ZL0xu6g/Ni8= X-Google-Smtp-Source: AGHT+IFp1K2ZEyWnmebqckNT+9GMRo5kic58OuYaodTR4pDXjpCurP4xmY65f8al7xrC2Tb6clvzdA== X-Received: by 2002:a05:6a00:6087:b0:81d:a1b1:731d with SMTP id d2e1a72fcca58-81da1c0baf1mr13732623b3a.53.1768307875265; Tue, 13 Jan 2026 04:37:55 -0800 (PST) Received: from archlinux ([2405:201:1b:225c:eb9d:1fc0:f95c:bd90]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81e9dd8fd8dsm11409000b3a.10.2026.01.13.04.37.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 04:37:54 -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 v3 2/3] platform/x86: hp-wmi: add manual fan control for Victus S models Date: Tue, 13 Jan 2026 18:07:37 +0530 Message-ID: <20260113123738.222244-3-krishna.chomal108@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260113123738.222244-1-krishna.chomal108@gmail.com> References: <20251230145053.516196-1-krishna.chomal108@gmail.com> <20260113123738.222244-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 apply "Auto" mode during driver initialization to ensure a consistent starting point. Refactor hp_wmi_apply_fan_settings() to use an intermediate ret variable. This prepares the switch block for keep-alive logic being added in a later patch, avoiding the need for duplicated mode check. Tested on: HP Omen 16-wf1xxx (board ID 8C78) Signed-off-by: Krishna Chomal --- Changes in v3: - Fixed improper alignment of multi-line functions and if statements - Fixed GPU fan speed calculation to use signed int to safely handle overflows/underflows - Directly use rpm instead of intermediate ret in hp_wmi_hwmon_read/write - Updated comments to use proper (uppercase) "PWM" terminology - Split deeply nested pwm sanity check logic into separate statements for readability. Changes in v2: - Added limits.h and minmax.h headers - Re-written pwm-to-rpm (and vice-versa) conversion from macros to static inline functions - Removed redundant NULL checking of drvdata - Made integer promotion explicit by casting intermediate result to unsigned int when calculating the GPU fan speed - Renamed "enforce_ctx" to "apply_fan_settings" for clarity - Removed unnecessary comments - Renamed "ctx" to "priv" as it is more consistent for drvdata - Added new struct victus_s_fan_table to avoid complex type casting --- drivers/platform/x86/hp/hp-wmi.c | 263 +++++++++++++++++++++++++------ 1 file changed, 217 insertions(+), 46 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index fac8e227cee0..d04e53ae1803 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -15,12 +15,16 @@ =20 #include #include +#include #include +#include #include #include #include #include #include +#include +#include #include #include #include @@ -190,7 +194,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 +353,51 @@ 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; +}; + +struct victus_s_fan_table_header { + u8 unknown; + u8 num_entries; +} __packed; + +struct victus_s_fan_table_entry { + u8 cpu_rpm; + u8 gpu_rpm; + u8 unknown; +} __packed; + +struct victus_s_fan_table { + struct victus_s_fan_table_header header; + struct victus_s_fan_table_entry entries[]; +} __packed; + +static inline u8 rpm_to_pwm(u8 rpm, struct hp_wmi_hwmon_priv *priv) +{ + return fixp_linear_interpolate(0, 0, priv->max_rpm, U8_MAX, + clamp_val(rpm, 0, priv->max_rpm)); +} + +static inline u8 pwm_to_rpm(u8 pwm, struct hp_wmi_hwmon_priv *priv) +{ + return fixp_linear_interpolate(0, 0, U8_MAX, priv->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 +687,53 @@ 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 *priv, u8 speed) { - u8 fan_speed[2] =3D { HP_FAN_SPEED_AUTOMATIC, HP_FAN_SPEED_AUTOMATIC }; - int ret; - - ret =3D hp_wmi_perform_query(HPWMI_FAN_SPEED_SET_QUERY, HPWMI_GM, - &fan_speed, sizeof(fan_speed), 0); + u8 fan_speed[2]; + int gpu_speed, ret; =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) { + gpu_speed =3D speed + priv->gpu_delta; + fan_speed[GPU_FAN] =3D clamp_val(gpu_speed, 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 *priv) { - int val =3D 0, ret; + return hp_wmi_fan_speed_set(priv, 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 *priv) +{ + 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: */ + return hp_wmi_fan_speed_reset(priv); } =20 static int __init hp_wmi_bios_2008_later(void) @@ -2108,12 +2170,45 @@ static struct platform_driver hp_wmi_driver __refda= ta =3D { .remove =3D __exit_p(hp_wmi_bios_remove), }; =20 +static int hp_wmi_apply_fan_settings(struct hp_wmi_hwmon_priv *priv) +{ + int ret; + + switch (priv->mode) { + case PWM_MODE_MAX: + if (is_victus_s_thermal_profile()) + hp_wmi_get_fan_count_userdefine_trigger(); + ret =3D hp_wmi_fan_speed_max_set(1); + return ret; + case PWM_MODE_MANUAL: + if (!is_victus_s_thermal_profile()) + return -EOPNOTSUPP; + ret =3D hp_wmi_fan_speed_set(priv, pwm_to_rpm(priv->pwm, priv)); + return ret; + case PWM_MODE_AUTO: + if (is_victus_s_thermal_profile()) { + hp_wmi_get_fan_count_userdefine_trigger(); + ret =3D hp_wmi_fan_speed_max_reset(priv); + } else { + ret =3D hp_wmi_fan_speed_max_set(0); + } + return ret; + 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; return 0644; case hwmon_fan: if (is_victus_s_thermal_profile()) { @@ -2134,8 +2229,10 @@ 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 *priv; + int rpm, ret; =20 + priv =3D dev_get_drvdata(dev); switch (type) { case hwmon_fan: if (is_victus_s_thermal_profile()) @@ -2147,16 +2244,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; + + rpm =3D hp_wmi_get_fan_speed_victus_s(channel); + if (rpm < 0) + return rpm; + *val =3D rpm_to_pwm(rpm / 100, priv); return 0; - case 1: - /* 1 is max fan, which is 0 - * (no fan speed control) for hwmon - */ - *val =3D 0; + } + switch (priv->mode) { + case PWM_MODE_MAX: + case PWM_MODE_MANUAL: + case PWM_MODE_AUTO: + *val =3D priv->mode; return 0; default: /* shouldn't happen */ @@ -2170,23 +2272,46 @@ 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 *priv; + int rpm; + + priv =3D dev_get_drvdata(dev); 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 (priv->mode !=3D PWM_MODE_MANUAL) + return -EINVAL; + + /* ensure PWM input is within valid fan speeds */ + rpm =3D pwm_to_rpm(val, priv); + rpm =3D clamp_val(rpm, priv->min_rpm, priv->max_rpm); + priv->pwm =3D rpm_to_pwm(rpm, priv); + return hp_wmi_apply_fan_settings(priv); + } 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: + priv->mode =3D PWM_MODE_MAX; + return hp_wmi_apply_fan_settings(priv); + 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. + */ + rpm =3D hp_wmi_get_fan_speed_victus_s(channel); + if (rpm < 0) + return rpm; + priv->pwm =3D rpm_to_pwm(rpm / 100, priv); + priv->mode =3D PWM_MODE_MANUAL; + return hp_wmi_apply_fan_settings(priv); + case PWM_MODE_AUTO: + priv->mode =3D PWM_MODE_AUTO; + return hp_wmi_apply_fan_settings(priv); default: - /* we don't support manual fan speed control */ return -EINVAL; } default: @@ -2196,7 +2321,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 +2336,56 @@ static const struct hwmon_chip_info chip_info =3D { .info =3D info, }; =20 +static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv) +{ + u8 fan_data[128] =3D { 0 }; + struct victus_s_fan_table *fan_table; + u8 min_rpm, max_rpm, gpu_delta; + int ret; + + /* Default behaviour on hwmon init is automatic mode */ + priv->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) + return ret; + + fan_table =3D (struct victus_s_fan_table *)fan_data; + if (fan_table->header.num_entries =3D=3D 0 || + sizeof(struct victus_s_fan_table_header) + + sizeof(struct victus_s_fan_table_entry) * fan_table->header.num_entri= es > sizeof(fan_data)) + return -EINVAL; + + min_rpm =3D fan_table->entries[0].cpu_rpm; + max_rpm =3D fan_table->entries[fan_table->header.num_entries - 1].cpu_rpm; + gpu_delta =3D fan_table->entries[0].gpu_rpm - fan_table->entries[0].cpu_r= pm; + priv->min_rpm =3D min_rpm; + priv->max_rpm =3D max_rpm; + priv->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 *priv; struct device *hwmon; + int ret; =20 - hwmon =3D devm_hwmon_device_register_with_info(dev, "hp", &hp_wmi_driver, + priv =3D devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + ret =3D hp_wmi_setup_fan_settings(priv); + if (ret) + return ret; + hwmon =3D devm_hwmon_device_register_with_info(dev, "hp", priv, &chip_info, NULL); =20 if (IS_ERR(hwmon)) { @@ -2224,6 +2393,8 @@ static int hp_wmi_hwmon_init(void) return PTR_ERR(hwmon); } =20 + hp_wmi_apply_fan_settings(priv); + return 0; } =20 --=20 2.52.0 From nobody Sun Feb 8 11:45:04 2026 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (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 091B5394489 for ; Tue, 13 Jan 2026 12:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307884; cv=none; b=kCA+y+j7VzVIzNrIAyA5Cpn+PC6wHXCBlWpDqvYa38WbRZ6zuQQLJ1WfP+BasiKNv268KnHV1+9+oawQKYftuz2VUYlHKsEhuniSVXCxOtt9AqKO8ji89cLKvXNg81+nZKxMNmmMvxSyW3l6bxpUxWJMKQenWOExUz7+BLYj+WE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768307884; c=relaxed/simple; bh=CCULviIUt1z9O4zm0Y/tKUyP/DMbEeojREOXeyucv0w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fD/82Zuh2Rb5OPgN8hcgHwdQjTeT3dootT66AL2bN85qX+xifecBFcnwV1qk8hLeV61c9b66E7egludzdwk0uZEbSSy82AUaQBjnORbiaXwrzl/xv2yCk7iVLX8kokYRJKDZK8u5n8/QxoAiLv7mob0evYiaFpZl98bhxZwP99I= 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=TjAF6B46; arc=none smtp.client-ip=209.85.210.172 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="TjAF6B46" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-81f47610542so1198813b3a.0 for ; Tue, 13 Jan 2026 04:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768307880; x=1768912680; 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=2KgPNZ1+hiG4bP2a4hNVRlEnc7lnvw26sruTYHkKl3A=; b=TjAF6B46C1880MRmAKko5tS55L1chEmPHhJ2d5ObRAw6+1tmQZM5Z8aMnBXN9GaU32 wqP7DWJ0NYNfPyaMqvhKYQtLzklElcrshJHU6Cal4Lki5dOyBKGAdCPi2IUjIdy71bUj TLne4nfC4SnF3rg9UC1Nn+fxPzGDT+Ru12+7TgcoQHK1GkIxz8LU1rS47dfIh4Gongw4 NZe3KmEhFA5oSccgvX3sGeL/N3Sh8jcx6bHtErJCVnVtwzO2ftvVt+VZ1y446XAyryEx 3PAP5rlUnQ+8AI8ga8ry3WlS7Wlp0+ahgxQ1LkPkqBmZT24uYqrR+T2G/KpfrqNdXF+b 6NZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768307880; x=1768912680; 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=2KgPNZ1+hiG4bP2a4hNVRlEnc7lnvw26sruTYHkKl3A=; b=WEmDPzRURra7MjIVVO3LRNCcaBGQ0NEb8urSSLlvnSPm/rvO9YYzDfU0Epd9V1ACEI YzYh2CoxbXdQujYf0vJm5wzOoV65E/5VWmCji13AoaY2BV3DdpwfuQjCcHGuMNTtnViE eFCOArGSNv5TvlyZ/C5i7VfV8e/cj7zHob5HCj9vTOxsbJ2hLXAufZo1M4qy27nbvrQA r6RdPrmyczqoS1dT0gJDKKTlpdgAdR9mN8yZ7SNUcOpTiAw0DScn7vuyTBP+uc7RWwVg GmBK2IeSbFYaT0gOt1rhelbbF3ta7WibHMatRTJX5c+gA/YpxI4L7vj+TAw0sap11TzU 2OMQ== X-Forwarded-Encrypted: i=1; AJvYcCUXRpyjjc7zkhL5G4y6ybYNDVRjOlM0JYcplhNLVjA+jAA8mSwLYo2NpRvbC8efA927QouzarMzqy9rbxo=@vger.kernel.org X-Gm-Message-State: AOJu0YySE1sxGTofZ1VZqDRBJzM8fFB3PuFdy8fbJryvzMnZZU/VbfxD gnAPIJI8lJHjjVDqsgYRvIXBR9n59fzcqkIlH6WT2zkezSGfh5JyMvK7 X-Gm-Gg: AY/fxX7ZLB7+bKljsEfFZaFVAKaYAerkAsHp6nDs5mteqfp0lmqQpRXP3wODyK3Suha 2b+8xVqWyeobKd3/fD8Y9SJFcuQamLQo/5KNN+vf2ANOfFfbMgpljhbVkOlTwHZh2YD5Q8qDZ8S KqRF/F3aqIvqpylK8wVx3euDfRrsJ/P/71zVnjGrOGlH7K7rnnc0fgUCRiAywtbfkTqfsQart3N Uwfs0Vic1yTPTz0GLCnLiDZ13A1ssVXot38Xc/EBsP/Mtq5G5BUknoNLSxocxXfBoj3FNFvFguO Stqno8cH2AUQQ97iJ/zIYkVqEZjAqPjGNzGoojHGCHzGv/qB8t6vW6T6Po+TXQ56CAG44AmhFlm xDpR5lDiP2fCEmZo2B63DLt9RmdWelmCQoZ4cfB90Ussx03l7E3N+IUwRy2w3KAiawmdHltX5Zh RKBbEh/MxiUKS8u5ET5HM= X-Google-Smtp-Source: AGHT+IE4FDzI2fl3iF/FeHvk73xQO0/uUff9GpZajmdaH4++8DOBr9WgUzShXoJrvM7PV7zAGGon7Q== X-Received: by 2002:a05:6a00:8c10:b0:7b7:5066:7f9 with SMTP id d2e1a72fcca58-81b7e928742mr18063499b3a.7.1768307880309; Tue, 13 Jan 2026 04:38:00 -0800 (PST) Received: from archlinux ([2405:201:1b:225c:eb9d:1fc0:f95c:bd90]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81e9dd8fd8dsm11409000b3a.10.2026.01.13.04.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jan 2026 04:38:00 -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 v3 3/3] platform/x86: hp-wmi: implement fan keep-alive Date: Tue, 13 Jan 2026 18:07:38 +0530 Message-ID: <20260113123738.222244-4-krishna.chomal108@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260113123738.222244-1-krishna.chomal108@gmail.com> References: <20251230145053.516196-1-krishna.chomal108@gmail.com> <20260113123738.222244-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 --- Changes in v3: - Rename "ctx" to "priv" for drvdata Changes in v2: - Explicitly specify time unit in KEEP_ALIVE_DELAY macro - Handle work rescheduling directly in switch/case --- drivers/platform/x86/hp/hp-wmi.c | 46 +++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-= wmi.c index d04e53ae1803..45ab644ff10e 100644 --- a/drivers/platform/x86/hp/hp-wmi.c +++ b/drivers/platform/x86/hp/hp-wmi.c @@ -34,6 +34,7 @@ #include #include #include +#include =20 MODULE_AUTHOR("Matthew Garrett "); MODULE_DESCRIPTION("HP laptop WMI driver"); @@ -368,6 +369,7 @@ struct hp_wmi_hwmon_priv { u8 gpu_delta; u8 mode; u8 pwm; + struct delayed_work keep_alive_dwork; }; =20 struct victus_s_fan_table_header { @@ -386,6 +388,12 @@ struct victus_s_fan_table { struct victus_s_fan_table_entry entries[]; } __packed; =20 +/* + * 90s delay to prevent the firmware from resetting fan mode after fixed + * 120s timeout + */ +#define KEEP_ALIVE_DELAY_SECS 90 + static inline u8 rpm_to_pwm(u8 rpm, struct hp_wmi_hwmon_priv *priv) { return fixp_linear_interpolate(0, 0, priv->max_rpm, U8_MAX, @@ -2093,6 +2101,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 *priv; =20 for (i =3D 0; i < rfkill2_count; i++) { rfkill_unregister(rfkill2[i].rfkill); @@ -2111,6 +2120,10 @@ static void __exit hp_wmi_bios_remove(struct platfor= m_device *device) rfkill_unregister(wwan_rfkill); rfkill_destroy(wwan_rfkill); } + + priv =3D platform_get_drvdata(device); + if (priv) + cancel_delayed_work_sync(&priv->keep_alive_dwork); } =20 static int hp_wmi_resume_handler(struct device *device) @@ -2179,12 +2192,20 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_= hwmon_priv *priv) if (is_victus_s_thermal_profile()) hp_wmi_get_fan_count_userdefine_trigger(); ret =3D hp_wmi_fan_speed_max_set(1); - return ret; + if (ret < 0) + return ret; + schedule_delayed_work(&priv->keep_alive_dwork, + secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); + return 0; case PWM_MODE_MANUAL: if (!is_victus_s_thermal_profile()) return -EOPNOTSUPP; ret =3D hp_wmi_fan_speed_set(priv, pwm_to_rpm(priv->pwm, priv)); - return ret; + if (ret < 0) + return ret; + schedule_delayed_work(&priv->keep_alive_dwork, + secs_to_jiffies(KEEP_ALIVE_DELAY_SECS)); + return 0; case PWM_MODE_AUTO: if (is_victus_s_thermal_profile()) { hp_wmi_get_fan_count_userdefine_trigger(); @@ -2192,7 +2213,10 @@ static int hp_wmi_apply_fan_settings(struct hp_wmi_h= wmon_priv *priv) } else { ret =3D hp_wmi_fan_speed_max_set(0); } - return ret; + if (ret < 0) + return ret; + cancel_delayed_work_sync(&priv->keep_alive_dwork); + return 0; default: /* shouldn't happen */ return -EINVAL; @@ -2336,6 +2360,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 *priv; + + dwork =3D to_delayed_work(work); + priv =3D container_of(dwork, struct hp_wmi_hwmon_priv, keep_alive_dwork); + /* + * Re-apply the current hwmon context settings. + * NOTE: hp_wmi_apply_fan_settings will handle the re-scheduling. + */ + hp_wmi_apply_fan_settings(priv); +} + static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv) { u8 fan_data[128] =3D { 0 }; @@ -2393,6 +2431,8 @@ static int hp_wmi_hwmon_init(void) return PTR_ERR(hwmon); } =20 + INIT_DELAYED_WORK(&priv->keep_alive_dwork, hp_wmi_hwmon_keep_alive_handle= r); + platform_set_drvdata(hp_wmi_platform_dev, priv); hp_wmi_apply_fan_settings(priv); =20 return 0; --=20 2.52.0