Skip to contentSkip to conversation

platform/x86: hp-wmi: Fan support for HP ZBook Studio G8

PATCH New Hasan-Hüseyin Kayisci 1 participant 3 messages Nov 22 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

cover platform/x86: hp-wmi: Fan support for HP ZBook Studio G8

On the HP ZBook Studio G8 (board 8873), hp-wmi registers a hwmon device that shows no fan speeds and has a pwm1_enable attribute that rejects every value, because the board lacks the gaming notebook fan WMI commands.

Patch 1 reads fan RPM through the thermal status WMI query (0x28), which this firmware implements in its GTMS method.

Patch 2 makes pwm1_enable 0 (full speed) and 2 (automatic) work by writing the EC fan mode register the DPTF IETM.IMOK method uses.

Manual PWM control isn't possible on this board. The EC ignores host writes to its fan target registers, both directly and through the thermal status write path (SetThermalStatus, 0x28 write).

Other ZBook and EliteBook models probably share this firmware interface (the same GTMS/STMM methods appear in their DSDTs), but I only have this machine, so the support is limited to board 8873 by DMI.

Testing: built with W=1 and tested on the ZBook Studio G8, BIOS T92 01.25.00, running 7.3.4. The out-of-tree build used this file from for-next with devm_kzalloc_obj() replaced by devm_kzalloc(), which 7.3 lacks. It hasn't been built inside a full for-next tree.

Tool use: an AI coding assistant (Claude Opus 5.5, via Claude Code) did most of this work in one interactive session from the prompt "try getting proper fan control through linux working on this HP ZBook Studio G8", followed by "do the hp-wmi rework". It disassembled the DSDT, probed the EC and WMI interfaces, wrote the code and drafted the changelogs. I reviewed the result, tested it on my machine and take responsibility for it.

Hasan-Hüseyin Kayisci (2):
platform/x86: hp-wmi: Add fan speed readout for ZBook Studio G8 platform/x86: hp-wmi: Support max fan mode on ZBook Studio G8

 drivers/platform/x86/hp/hp-wmi.c | 126 +++++++++++++++++++++++++++----
 1 file changed, 112 insertions(+), 14 deletions(-)

base-commit: 9c82959c37bf69c2ace8a0f975cf2129ec1fd982

Signature · 1 line
2.56.1
#1 lore raw

PATCH 1/2 platform/x86: hp-wmi: Add fan speed readout for ZBook Studio G8

The HP ZBook Studio G8 (board 8873) doesn't support the gaming notebook fan WMI commands, so the hwmon device registered by hp-wmi exposes no fan speed at all, only a pwm1_enable attribute that fails with -EINVAL.

Its firmware does report fan tachometer readings through the thermal status query (0x28, page 0x07), which returns a 16-bit tachometer period for each fan starting at byte 2. Convert the period to RPM the same way the firmware's own \_TZ.GFRM method does.

Byte 0 of the reply is the index of the last fan with a non-zero reading rather than a fan count, so take the fan count from the board data instead. The firmware rejects the query unless the input size is exactly 4 bytes.

Add a fan_count field to the fan profile parameters so boards can provide a static fan count, and only treat a board as supporting manual fan control when it also has a fan table, which this board doesn't.

Tested on a ZBook Studio G8 with BIOS T92 01.25.00: fan1_input and fan2_input match the values from the EC tachometer registers.

This patch was written with the help of an AI coding assistant (Claude Opus 5.5, via Claude Code), which disassembled the DSDT, probed the firmware interfaces, and drafted the code and this changelog. All of it was reviewed and tested on hardware by the submitter.

---
 drivers/platform/x86/hp/hp-wmi.c | 96 +++++++++++++++++++++++++++-----
 1 file changed, 82 insertions(+), 14 deletions(-)
drivers/platform/x86/hp/hp-wmi.c +82 -14
index 0069af868..c4896435c 100644
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/types.h>
+#include <linux/unaligned.h>
 #include <linux/workqueue.h>
 
 #include <acpi/battery.h>
@@ -148,6 +149,8 @@ static const struct thermal_profile_params omen_v1_no_ec_thermal_params = {
 
 struct hp_wmi_fan_profile_params {
 	int (*get_fan_speed)(int fan);
+	/* Number of fans, 0 to query it with HPWMI_FAN_COUNT_GET_QUERY */
+	int fan_count;
 	bool fan_table;
 };
 
@@ -183,6 +186,21 @@ static const struct hp_wmi_board_params omen_v1_no_ec_board_params = {
 	.fan_profile		= &victus_s_fan_profile_params,
 };
 
+static int hp_wmi_get_fan_speed_thermal_status(int fan);
+
+/*
+ * Business notebooks (e.g. ZBook) without the gaming fan commands, which
+ * report fan tachometer readings through the thermal status query.
+ */
+static const struct hp_wmi_fan_profile_params thermal_status_fan_profile_params = {
+	.get_fan_speed	= hp_wmi_get_fan_speed_thermal_status,
+	.fan_count	= 2,
+};
+
+static const struct hp_wmi_board_params thermal_status_board_params = {
+	.fan_profile		= &thermal_status_fan_profile_params,
+};
+
 static const struct hp_wmi_board_params *active_board_params;
 
 static const struct thermal_profile_params *hp_wmi_thermal_profile(void)
@@ -243,8 +261,13 @@ static const char * const victus_thermal_profile_boards[] = {
 	"8A26",
 };
 
-/* DMI board-specific feature data for Omen and Victus laptops. */
+/* DMI board-specific feature data for Omen, Victus and ZBook laptops. */
 static const struct dmi_system_id hp_wmi_feature_boards[] __initconst = {
+	{
+		/* HP ZBook Studio 15.6 inch G8 Mobile Workstation PC */
+		.matches = { DMI_MATCH(DMI_BOARD_NAME, "8873") },
+		.driver_data = (void *)&thermal_status_board_params,
+	},
 	{
 		.matches = { DMI_MATCH(DMI_BOARD_NAME, "8902") },
 		.driver_data = (void *)&omen_v1_legacy_board_params,
@@ -437,6 +460,7 @@ enum hp_wmi_commandtype {
 	HPWMI_HOTKEY_QUERY		= 0x0c,
 	HPWMI_FEATURE2_QUERY		= 0x0d,
 	HPWMI_WIRELESS2_QUERY		= 0x1b,
+	HPWMI_THERMAL_STATUS_QUERY	= 0x28,
 	HPWMI_POSTCODEERROR_QUERY	= 0x2a,
 	HPWMI_BATTERY_CHARGE_MODE	= 0x2b,
 	HPWMI_SYSTEM_DEVICE_MODE	= 0x40,
@@ -856,6 +880,43 @@ static int hp_wmi_get_fan_speed_victus_s(int fan)
 	return fan_data[fan] * 100;
 }
 
+/*
+ * Thermal status query, fan tachometer page. The output holds a 16-bit
+ * tachometer period per fan starting at byte 2. Byte 0 is the index of the
+ * last fan with a non-zero reading, so it can't be used as the fan count.
+ * The period is converted to RPM the same way the firmware does in its own
+ * \_TZ fan speed methods.
+ */
+#define HP_THERMAL_STATUS_FAN_TACH	0x07
+#define HP_THERMAL_STATUS_TACH_OFFSET	2
+#define HP_THERMAL_STATUS_MAX_FANS	2
+#define HP_FAN_TACH_PERIOD_TO_RPM	0x3c000
+
+static int hp_wmi_get_fan_speed_thermal_status(int fan)
+{
+	u8 data[128] = { HP_THERMAL_STATUS_FAN_TACH };
+	int ret, offset;
+	u16 period;
+
+	if (fan < 0 || fan >= HP_THERMAL_STATUS_MAX_FANS)
+		return -EINVAL;
+
+	/* The firmware rejects any input size other than 4 bytes */
+	ret = hp_wmi_perform_query(HPWMI_THERMAL_STATUS_QUERY, HPWMI_READ,
+				   data, sizeof(u32), sizeof(data));
+	if (ret)
+		return ret < 0 ? ret : -EINVAL;
+
+	offset = HP_THERMAL_STATUS_TACH_OFFSET + fan * sizeof(period);
+	period = get_unaligned_le16(&data[offset]);
+
+	/* A stopped fan reports an empty period */
+	if (!period)
+		return 0;
+
+	return DIV_ROUND_CLOSEST(HP_FAN_TACH_PERIOD_TO_RPM, period);
+}
+
 static int hp_wmi_read_int(int query)
 {
 	int val = 0, ret;
@@ -2271,7 +2332,7 @@ static bool hp_wmi_fan_control_supported(void)
 {
 	const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile();
 
-	return params && params->get_fan_speed;
+	return params && params->get_fan_speed && params->fan_table;
 }
 
 static bool hp_wmi_fan_table_supported(void)
@@ -2291,6 +2352,16 @@ static int hp_wmi_get_active_fan_speed(int fan)
 	return params->get_fan_speed(fan);
 }
 
+static int hp_wmi_read_fan_speed(int fan)
+{
+	const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile();
+
+	if (params && params->get_fan_speed)
+		return params->get_fan_speed(fan);
+
+	return hp_wmi_get_fan_speed(fan);
+}
+
 static int victus_s_gpu_thermal_profile_get(bool *ctgp_enable,
 					    bool *ppab_enable,
 					    u8 *dstate,
@@ -2963,13 +3034,8 @@ static umode_t hp_wmi_hwmon_is_visible(const void *data,
 	case hwmon_fan:
 		if (priv->fan_count <= 0)
 			return 0;
-		if (hp_wmi_fan_control_supported()) {
-			if (hp_wmi_get_active_fan_speed(channel) >= 0)
-				return 0444;
-		} else {
-			if (hp_wmi_get_fan_speed(channel) >= 0)
-				return 0444;
-		}
+		if (hp_wmi_read_fan_speed(channel) >= 0)
+			return 0444;
 		break;
 	default:
 		return 0;
@@ -2988,10 +3054,7 @@ static int hp_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 	priv = dev_get_drvdata(dev);
 	switch (type) {
 	case hwmon_fan:
-		if (hp_wmi_fan_control_supported())
-			ret = hp_wmi_get_active_fan_speed(channel);
-		else
-			ret = hp_wmi_get_fan_speed(channel);
+		ret = hp_wmi_read_fan_speed(channel);
 		if (ret < 0)
 			return ret;
 		*val = ret;
@@ -3122,6 +3185,7 @@ static void hp_wmi_hwmon_keep_alive_handler(struct work_struct *work)
 
 static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv)
 {
+	const struct hp_wmi_fan_profile_params *params;
 	u8 fan_data[128] = { 0 };
 	struct victus_s_fan_table *fan_table;
 	u8 min_rpm, max_rpm;
@@ -3131,7 +3195,11 @@ static int hp_wmi_setup_fan_settings(struct hp_wmi_hwmon_priv *priv)
 
 	/* Default behaviour on hwmon init is automatic mode */
 	priv->mode = PWM_MODE_AUTO;
-	priv->fan_count = hp_wmi_get_fan_count_userdefine_trigger();
+	params = hp_wmi_fan_profile();
+	if (params && params->fan_count)
+		priv->fan_count = params->fan_count;
+	else
+		priv->fan_count = hp_wmi_get_fan_count_userdefine_trigger();
 
 	/* Bypass devices without fan control support. */
 	if (!hp_wmi_fan_table_supported())

base-commit: 9c82959c37bf69c2ace8a0f975cf2129ec1fd982

Signature · 1 line
2.56.1
#2 lore raw

PATCH 2/2 platform/x86: hp-wmi: Support max fan mode on ZBook Studio G8

In reply to Hasan-Hüseyin Kayisci

On the ZBook Studio G8 the HPWMI_FAN_SPEED_MAX_SET_QUERY command fails, so writing pwm1_enable fails with -EINVAL and hwmon init logs "Failed to apply initial fan settings: -22".

The EC on this board has a fan mode register at offset 0x2d, which the DPTF IETM.IMOK method writes on Windows. The low nibble selects the mode for the CPU fan and the high nibble for the GPU fan. Mode 0 is the automatic fan curve and mode 1 holds the fans at the highest fixed level the EC offers (about 4700 RPM on this machine, versus about 4100 RPM reached in automatic mode under sustained full CPU load). The EC also accepts mode 2, a lower fixed level, which has no hwmon equivalent and isn't exposed. Writes of other values are ignored.

Add an optional set_fan_speed_max callback to the fan profile parameters and implement it for this board by writing the EC fan mode register, so pwm1_enable 0 (full speed) and 2 (automatic) work. Manual control (pwm1_enable 1) stays unsupported: the EC ignores host writes to its fan target registers.

Tested on a ZBook Studio G8 with BIOS T92 01.25.00.

This patch was written with the help of an AI coding assistant (Claude Opus 5.5, via Claude Code), which found the register by disassembling the DSDT and probing the EC, and drafted the code and this changelog. All of it was reviewed and tested on hardware by the submitter.

---
 drivers/platform/x86/hp/hp-wmi.c | 34 ++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
drivers/platform/x86/hp/hp-wmi.c +32 -2
index c4896435c..9e1729af4 100644
@@ -63,6 +63,15 @@ enum hp_ec_offsets {
 	HP_OMEN_EC_THERMAL_PROFILE_OFFSET		= 0x95,
 };
 
+/*
+ * EC fan mode register on ZBook boards, also written by the DPTF IETM.IMOK
+ * method. Low nibble is the CPU fan, high nibble the GPU fan. 0 selects the
+ * automatic fan curve, 1 the highest fixed fan level.
+ */
+#define HP_EC_FAN_MODE_OFFSET	0x2d
+#define HP_EC_FAN_MODE_AUTO	0x00
+#define HP_EC_FAN_MODE_MAX	0x11
+
 #define HP_FAN_SPEED_AUTOMATIC	 0x00
 #define HP_POWER_LIMIT_DEFAULT	 0x00
 #define HP_POWER_LIMIT_NO_CHANGE 0xFF
@@ -151,6 +160,8 @@ struct hp_wmi_fan_profile_params {
 	int (*get_fan_speed)(int fan);
 	/* Number of fans, 0 to query it with HPWMI_FAN_COUNT_GET_QUERY */
 	int fan_count;
+	/* Optional, defaults to HPWMI_FAN_SPEED_MAX_SET_QUERY */
+	int (*set_fan_speed_max)(int enabled);
 	bool fan_table;
 };
 
@@ -187,14 +198,17 @@ static const struct hp_wmi_board_params omen_v1_no_ec_board_params = {
 };
 
 static int hp_wmi_get_fan_speed_thermal_status(int fan);
+static int hp_wmi_ec_fan_speed_max_set(int enabled);
+static const struct hp_wmi_fan_profile_params *hp_wmi_fan_profile(void);
 
 /*
  * Business notebooks (e.g. ZBook) without the gaming fan commands, which
  * report fan tachometer readings through the thermal status query.
  */
 static const struct hp_wmi_fan_profile_params thermal_status_fan_profile_params = {
-	.get_fan_speed	= hp_wmi_get_fan_speed_thermal_status,
-	.fan_count	= 2,
+	.get_fan_speed		= hp_wmi_get_fan_speed_thermal_status,
+	.fan_count		= 2,
+	.set_fan_speed_max	= hp_wmi_ec_fan_speed_max_set,
 };
 
 static const struct hp_wmi_board_params thermal_status_board_params = {
@@ -1226,10 +1240,26 @@ static int omen_thermal_profile_get(void)
 	return data;
 }
 
+static int hp_wmi_ec_fan_speed_max_set(int enabled)
+{
+	int ret;
+
+	ret = ec_write(HP_EC_FAN_MODE_OFFSET,
+		       enabled ? HP_EC_FAN_MODE_MAX : HP_EC_FAN_MODE_AUTO);
+	if (ret)
+		return ret;
+
+	return enabled;
+}
+
 static int hp_wmi_fan_speed_max_set(int enabled)
 {
+	const struct hp_wmi_fan_profile_params *params = hp_wmi_fan_profile();
 	int ret;
 
+	if (params && params->set_fan_speed_max)
+		return params->set_fan_speed_max(enabled);
+
 	ret = hp_wmi_perform_query(HPWMI_FAN_SPEED_MAX_SET_QUERY, HPWMI_GM,
 				   &enabled, sizeof(enabled), 0);
 
Signature · 1 line
2.56.1