Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: John den Heijer <jdenheijer74@gmail.com>
To: linux-hwmon@vger.kernel.org
Cc: eugene.shalygin@gmail.com, linux@roeck-us.net
Subject: [RFC PATCH v2 2/3] hwmon: (asus-ec-sensors) add opt-in MAXIMUS XI HERO EXT fan RPM
Date: Sat, 28 Nov 2026 20:12:24 +0100	[thread overview]
Message-ID: <20261128191225.2990-3-jdenheijer74@gmail.com> (raw)
In-Reply-To: <20261128191225.2990-1-jdenheijer74@gmail.com>

BIOS 2004 reads the three optional extension fan tachometers by writing
selector 0x0a, 0x0b or 0x0c to EC bank-0 register 0x43 and reading the
high and low RPM bytes from 0x57/0x58.

Before the first read, or after a lost latch, the BIOS getter sets bit 7
of 0xd4 and bits 0-2 of 0x89. Reuse the upstream MAXIMUS IX EXTREME
selector path, but add this initialization only for the exact non-WiFi
MAXIMUS XI HERO DMI name. Keep the optional-card support default-off:
a reliable live card-presence detector has not been established.

Signed-off-by: John den Heijer <jdenheijer74@gmail.com>
---
 drivers/hwmon/asus-ec-sensors.c | 76 ++++++++++++++++++++++++++++++---
 1 file changed, 71 insertions(+), 5 deletions(-)

diff --git a/drivers/hwmon/asus-ec-sensors.c b/drivers/hwmon/asus-ec-sensors.c
index 6e06256a5..45beba10f 100644
--- a/drivers/hwmon/asus-ec-sensors.c
+++ b/drivers/hwmon/asus-ec-sensors.c
@@ -37,6 +37,7 @@
 #include <linux/unaligned.h>
 
 static char *mutex_path_override;
+static bool enable_ext_fan;
 
 /* Writing to this EC register switches EC bank */
 #define ASUS_EC_BANK_REGISTER	0xff
@@ -45,6 +46,9 @@ static char *mutex_path_override;
  * group of registers reports (e.g. one of the fans of the fan extension card).
  */
 #define ASUS_EC_SELECT_REGISTER	0x43
+#define ASUS_EC_EXT_FAN_RPM_MIN	0xa5
+#define ASUS_EC_EXT_FAN_ENABLE_REGISTER	0xd4
+#define ASUS_EC_EXT_FAN_CHANNEL_REGISTER	0x89
 #define SENSOR_LABEL_LEN	16
 
 /*
@@ -414,6 +418,12 @@ static const struct ec_sensor_info sensors_family_intel_300[] = {
 	[ec_sensor_fan_vrm_hs] = EC_SENSOR("VRM HS", hwmon_fan, 2, 0x00, 0xb2),
 	[ec_sensor_fan_water_flow] =
 		EC_SENSOR("Water_Flow", hwmon_fan, 2, 0x00, 0xbc),
+	[ec_sensor_fan_ext_1] =
+		EC_SENSOR_SELECT("EXT_FAN1", hwmon_fan, 2, 0x00, 0x57, 0x0a),
+	[ec_sensor_fan_ext_2] =
+		EC_SENSOR_SELECT("EXT_FAN2", hwmon_fan, 2, 0x00, 0x57, 0x0b),
+	[ec_sensor_fan_ext_3] =
+		EC_SENSOR_SELECT("EXT_FAN3", hwmon_fan, 2, 0x00, 0x57, 0x0c),
 	[ec_sensor_temp_water_in] =
 		EC_SENSOR("Water_In", hwmon_temp, 1, 0x01, 0x00),
 	[ec_sensor_temp_water_out] =
@@ -484,6 +494,7 @@ static const struct ec_sensor_info sensors_family_intel_700[] = {
 
 struct ec_board_info {
 	unsigned long sensors;
+	bool ext_fan_capable;
 	/*
 	 * Defines which mutex to use for guarding access to the state and the
 	 * hardware. Can be either a full path to an AML mutex or the
@@ -593,6 +604,16 @@ static const struct ec_board_info board_info_maximus_xi_hero = {
 	.family = family_intel_300_series,
 };
 
+static const struct ec_board_info board_info_maximus_xi_hero_ext = {
+	.sensors = SENSOR_SET_TEMP_CHIPSET_CPU_MB |
+		SENSOR_TEMP_T_SENSOR |
+		SENSOR_TEMP_VRM | SENSOR_SET_TEMP_WATER |
+		SENSOR_FAN_CPU_OPT | SENSOR_FAN_WATER_FLOW,
+	.ext_fan_capable = true,
+	.mutex_path = ASUS_HW_ACCESS_MUTEX_ASMX,
+	.family = family_intel_300_series,
+};
+
 static const struct ec_board_info board_info_maximus_z690_formula = {
 	.sensors = SENSOR_TEMP_T_SENSOR | SENSOR_TEMP_VRM |
 		SENSOR_SET_TEMP_WATER | SENSOR_FAN_WATER_FLOW,
@@ -1004,7 +1025,7 @@ static const struct dmi_system_id dmi_table[] = {
 	DMI_EXACT_MATCH_ASUS_BOARD_NAME("ROG CROSSHAIR X870E HERO",
 					&board_info_crosshair_x870e_hero),
 	DMI_EXACT_MATCH_ASUS_BOARD_NAME("ROG MAXIMUS XI HERO",
-					&board_info_maximus_xi_hero),
+					&board_info_maximus_xi_hero_ext),
 	DMI_EXACT_MATCH_ASUS_BOARD_NAME("ROG MAXIMUS XI HERO (WI-FI)",
 					&board_info_maximus_xi_hero),
 	DMI_EXACT_MATCH_ASUS_BOARD_NAME("ROG MAXIMUS X HERO",
@@ -1135,6 +1156,9 @@ static bool unlock_global_acpi_lock(struct lock_data *data)
 struct ec_sensors_data {
 	const struct ec_board_info *board_info;
 	const struct ec_sensor_info *sensors_info;
+	unsigned long sensor_mask;
+	bool ext_fan_enabled;
+	bool ext_fan_initialized;
 	struct ec_sensor *sensors;
 	/*
 	 * EC registers to read from: (select << 16) + (bank << 8) + index,
@@ -1224,8 +1248,8 @@ static void setup_sensor_data(struct ec_sensors_data *ec)
 	ec->nr_banks = 0;
 	ec->nr_registers = 0;
 
-	for_each_set_bit(i, &ec->board_info->sensors,
-			 BITS_PER_TYPE(ec->board_info->sensors)) {
+	for_each_set_bit(i, &ec->sensor_mask,
+			 BITS_PER_TYPE(ec->sensor_mask)) {
 		s->info_index = i;
 		s->cached_value = 0;
 		ec->nr_registers +=
@@ -1306,6 +1330,30 @@ static int asus_ec_bank_switch(u8 bank, u8 *old)
 	return ec_write(ASUS_EC_BANK_REGISTER, bank);
 }
 
+static int asus_ec_prepare_ext_fans(struct ec_sensors_data *ec)
+{
+	u8 enabled, channels;
+	int status;
+
+	status = ec_read(ASUS_EC_EXT_FAN_ENABLE_REGISTER, &enabled);
+	if (status)
+		return status;
+	if (ec->ext_fan_initialized && (enabled & BIT(7)))
+		return 0;
+
+	status = ec_write(ASUS_EC_EXT_FAN_ENABLE_REGISTER, enabled | BIT(7));
+	if (status)
+		return status;
+	status = ec_read(ASUS_EC_EXT_FAN_CHANNEL_REGISTER, &channels);
+	if (status)
+		return status;
+	status = ec_write(ASUS_EC_EXT_FAN_CHANNEL_REGISTER,
+			  channels | GENMASK(2, 0));
+	if (!status)
+		ec->ext_fan_initialized = true;
+	return status;
+}
+
 static int asus_ec_block_read(const struct device *dev,
 			      struct ec_sensors_data *ec)
 {
@@ -1325,6 +1373,11 @@ static int asus_ec_block_read(const struct device *dev,
 		dev_warn(dev,
 			"Concurrent access to the ACPI EC detected.\nRace condition possible.");
 	}
+	if (ec->ext_fan_enabled) {
+		status = asus_ec_prepare_ext_fans(ec);
+		if (status)
+			goto restore_bank;
+	}
 
 	/* read registers minimizing bank switches. */
 	for (ibank = 0; ibank < ec->nr_banks; ibank++) {
@@ -1373,6 +1426,7 @@ restore_select:
 			break;
 	}
 
+restore_bank:
 	restore_status = asus_ec_bank_switch(prev_bank, NULL);
 	if (!status)
 		status = restore_status;
@@ -1503,8 +1557,11 @@ static int asus_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
 		return ret;
 
 	sensor_info = get_sensor_info(state, sidx);
+	ec_sensor = get_ec_sensor_type(state, sidx);
+	if (state->ext_fan_enabled && ec_sensor >= ec_sensor_fan_ext_1 &&
+	    ec_sensor <= ec_sensor_fan_ext_3 && value < ASUS_EC_EXT_FAN_RPM_MIN)
+		value = 0;
 	if (sensor_info->type == hwmon_temp) {
-		ec_sensor = get_ec_sensor_type(state, sidx);
 		if ((environment_temp_sensors & BIT(ec_sensor)) &&
 		    is_blank_temperature_value(value))
 			return -ENODATA;
@@ -1601,6 +1658,12 @@ static int asus_ec_probe(struct platform_device *pdev)
 	ec_data->next_update = INITIAL_JIFFIES;
 	dev_set_drvdata(dev, ec_data);
 	ec_data->board_info = pboard_info;
+	ec_data->sensor_mask = pboard_info->sensors;
+	ec_data->ext_fan_enabled = pboard_info->ext_fan_capable &&
+				   enable_ext_fan;
+	if (ec_data->ext_fan_enabled)
+		ec_data->sensor_mask |= SENSOR_FAN_EXT_1 |
+					SENSOR_FAN_EXT_2 | SENSOR_FAN_EXT_3;
 
 	switch (ec_data->board_info->family) {
 	case family_amd_400_series:
@@ -1645,7 +1708,7 @@ static int asus_ec_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	ec_data->nr_sensors = hweight_long(ec_data->board_info->sensors);
+	ec_data->nr_sensors = hweight_long(ec_data->sensor_mask);
 	ec_data->sensors = devm_kzalloc_objs(dev, struct ec_sensor,
 					     ec_data->nr_sensors);
 	if (!ec_data->sensors)
@@ -1745,6 +1808,9 @@ module_exit(asus_ec_exit);
 module_param_named(mutex_path, mutex_path_override, charp, 0);
 MODULE_PARM_DESC(mutex_path,
 		 "Override ACPI mutex path used to guard access to hardware");
+module_param(enable_ext_fan, bool, 0);
+MODULE_PARM_DESC(enable_ext_fan,
+		 "Enable Fan Extension Card sensors on ROG MAXIMUS XI HERO");
 
 MODULE_AUTHOR("Eugene Shalygin <eugene.shalygin@gmail.com>");
 MODULE_DESCRIPTION(
-- 
2.54.0 (Apple Git-157)


  parent reply	other threads:[~2026-11-28 19:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 19:12 [RFC PATCH v2 0/3] hwmon: asus-ec-sensors: MAXIMUS XI HERO Fan Extension Card John den Heijer
2026-11-28 19:12 ` [RFC PATCH v2 1/3] hwmon: (asus-ec-sensors) propagate EC read and selector errors John den Heijer
2026-11-28 19:17   ` sashiko-bot
2026-11-28 19:12 ` John den Heijer [this message]
2026-11-28 19:19   ` [RFC PATCH v2 2/3] hwmon: (asus-ec-sensors) add opt-in MAXIMUS XI HERO EXT fan RPM sashiko-bot
2026-11-28 19:12 ` [RFC PATCH v2 3/3] hwmon: (asus-ec-sensors) add MAXIMUS XI HERO EXT thermistors John den Heijer
2026-11-28 19:19 ` [RFC PATCH v2 0/3] hwmon: asus-ec-sensors: MAXIMUS XI HERO Fan Extension Card sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261128191225.2990-3-jdenheijer74@gmail.com \
    --to=jdenheijer74@gmail.com \
    --cc=eugene.shalygin@gmail.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox