Re: [PATCH] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1
From: Rong Zhang
Date: Fri Nov 27 2026 - 08:33:36 EST
Hi Vishnu,
Thanks for working on this.
On Thu, 2026-11-26 at 17:59 +0900, Vishnu Sankar wrote:
> On the ThinkPad X9-14 Gen 1 and X9-15 Gen 1, the EC reports fan1 RPM
> in registers 0x84/0x85 and fan2 RPM in 0x82/0x83, and does not use
> bit 0 of 0x31 as a fan select. As a result fan2 reports fan1's speed,
> and every fan read overwrites an EC-owned bit.
>
> The EC also does not latch either register pair, so a read can combine
> the LSB of a new value with the MSB of an old one.
>
> Add two quirks: TPACPI_FAN_2REG reads fan2 from 0x82/0x83 and never
> touches 0x31, and TPACPI_FAN_UNLATCH re-reads an RPM register pair
> until the MSB is stable. Enable both for the X9 Gen 1 models.
>
> A single fan level write controls both fans on these models, so second
> fan control is disabled when TPACPI_FAN_2REG is set.
>
> Tested on X9-14 Gen 1 (BIOS N4DET42W, EC N4DHT39W).
>
> Signed-off-by: Vishnu Sankar <vishnuocv@xxxxxxxxx>
Reviewed-by: Rong Zhang <i@xxxxxxxx>
Thanks,
Rong
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 79 ++++++++++++++++++---
> 1 file changed, 68 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 4f81855ad721..266f774b8ac3 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -7964,6 +7964,8 @@ enum { /* Fan control constants */
> fan_select_offset = 0x31, /* EC register 0x31 (Firmware 7M)
> bit 0 selects which fan is active */
>
> + fan2_rpm_offset = 0x82, /* EC register 0x82: LSB, 0x83 MSB (fan2 RPM) */
> +
> fan_status_offset_ns = 0x93, /* Special status/control offset for non-standard EC Fan1 */
> fan2_status_offset_ns = 0x96, /* Special status/control offset for non-standard EC Fan2 */
> fan_rpm_status_ns = 0x95, /* Special offset for Fan1 RPM status for non-standard EC */
> @@ -8012,6 +8014,8 @@ static int fan_watchdog_maxinterval;
> static bool fan_with_ns_addr;
> static bool ecfw_with_fan_dec_rpm;
> static bool fan_speed_in_tpr;
> +static bool fan2_with_own_rpm_reg;
> +static bool fan_rpm_unlatched;
>
> static struct mutex fan_mutex;
>
> @@ -8073,6 +8077,9 @@ static void fan_quirk1_handle(u8 *fan_status)
> /* Select main fan on X60/X61, NOOP on others */
> static bool fan_select_fan1(void)
> {
> + if (fan2_with_own_rpm_reg)
> + return true;
> +
> if (tp_features.second_fan) {
> u8 val;
>
> @@ -8093,6 +8100,9 @@ static bool fan_select_fan2(void)
> if (!tp_features.second_fan)
> return false;
>
> + if (fan2_with_own_rpm_reg)
> + return true;
> +
> if (ec_read(fan_select_offset, &val) < 0)
> return false;
> val |= 0x01U;
> @@ -8202,21 +8212,48 @@ static int fan_get_status_safe(u8 *status)
> return 0;
> }
>
> +/* Read a 16-bit RPM register pair (LSB at offset, MSB at offset + 1) */
> +static bool fan_read_rpm(u8 offset, unsigned int *rpm)
> +{
> + u8 hi, lo, hi2;
> + int retries = 3;
> +
> + if (fan_rpm_unlatched) {
> + /* No latch: re-read until the MSB is stable */
> + do {
> + if (!acpi_ec_read(offset + 1, &hi) ||
> + !acpi_ec_read(offset, &lo) ||
> + !acpi_ec_read(offset + 1, &hi2))
> + return false;
> + } while (hi != hi2 && --retries);
> +
> + if (hi != hi2)
> + return false;
> + } else {
> + if (!acpi_ec_read(offset, &lo) || !acpi_ec_read(offset + 1, &hi))
> + return false;
> + }
> +
> + *rpm = (hi << 8) | lo;
> + return true;
> +}
> +
> static int fan_get_speed(unsigned int *speed)
> {
> - u8 hi, lo;
> + unsigned int rpm;
> + u8 lo;
>
> switch (fan_status_access_mode) {
> case TPACPI_FAN_RD_TPEC:
> /* all except 570, 600e/x, 770e, 770x */
> if (unlikely(!fan_select_fan1()))
> return -EIO;
> - if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
> - !acpi_ec_read(fan_rpm_offset + 1, &hi)))
> +
> + if (unlikely(!fan_read_rpm(fan_rpm_offset, &rpm)))
> return -EIO;
>
> if (likely(speed)) {
> - *speed = (hi << 8) | lo;
> + *speed = rpm;
> if (fan_speed_in_tpr && *speed != 0)
> *speed = FAN_CLOCK_TPM / *speed;
> }
> @@ -8238,7 +8275,8 @@ static int fan_get_speed(unsigned int *speed)
>
> static int fan2_get_speed(unsigned int *speed)
> {
> - u8 hi, lo, status;
> + unsigned int rpm;
> + u8 lo, status;
> bool rc;
>
> switch (fan_status_access_mode) {
> @@ -8246,14 +8284,16 @@ static int fan2_get_speed(unsigned int *speed)
> /* all except 570, 600e/x, 770e, 770x */
> if (unlikely(!fan_select_fan2()))
> return -EIO;
> - rc = !acpi_ec_read(fan_rpm_offset, &lo) ||
> - !acpi_ec_read(fan_rpm_offset + 1, &hi);
> +
> + rc = !fan_read_rpm(fan2_with_own_rpm_reg ? fan2_rpm_offset : fan_rpm_offset,
> + &rpm);
> +
> fan_select_fan1(); /* play it safe */
> if (rc)
> return -EIO;
>
> if (likely(speed)) {
> - *speed = (hi << 8) | lo;
> + *speed = rpm;
> if (fan_speed_in_tpr && *speed != 0)
> *speed = FAN_CLOCK_TPM / *speed;
> }
> @@ -8873,6 +8913,8 @@ static const struct attribute_group fan_driver_attr_group = {
> #define TPACPI_FAN_DECRPM 0x0020 /* For ECFW's with RPM in register as decimal */
> #define TPACPI_FAN_TPR 0x0040 /* Fan speed is in Ticks Per Revolution */
> #define TPACPI_FAN_NOACPI 0x0080 /* Don't use ACPI methods even if detected */
> +#define TPACPI_FAN_2REG 0x0100 /* Fan2 RPM in EC regs 0x82/0x83, no fan select */
> +#define TPACPI_FAN_UNLATCH 0x0200 /* RPM registers are not latched */
>
> static const struct tpacpi_quirk fan_quirk_table[] __initconst = {
> TPACPI_QEC_IBM('1', 'Y', TPACPI_FAN_Q1),
> @@ -8908,6 +8950,8 @@ static const struct tpacpi_quirk fan_quirk_table[] __initconst = {
> TPACPI_Q_LNV3('R', '0', '0', TPACPI_FAN_NOACPI),/* E560 */
> TPACPI_Q_LNV3('R', '1', '2', TPACPI_FAN_NOACPI),/* T495 */
> TPACPI_Q_LNV3('R', '1', '3', TPACPI_FAN_NOACPI),/* T495s */
> + TPACPI_Q_LNV3('N', '4', 'D', TPACPI_FAN_2REG | TPACPI_FAN_UNLATCH), /* X9-14 Gen 1 */
> + TPACPI_Q_LNV3('N', '4', 'C', TPACPI_FAN_2REG | TPACPI_FAN_UNLATCH), /* X9-15 Gen 1 */
> };
>
> static int __init fan_init(struct ibm_init_struct *iibm)
> @@ -8959,6 +9003,12 @@ static int __init fan_init(struct ibm_init_struct *iibm)
> tp_features.fan_ctrl_status_undef = 1;
> }
>
> + if (quirks & TPACPI_FAN_2REG)
> + fan2_with_own_rpm_reg = true;
> +
> + if (quirks & TPACPI_FAN_UNLATCH)
> + fan_rpm_unlatched = true;
> +
> if (quirks & TPACPI_FAN_NOACPI) {
> /* E560, T495, T495s */
> pr_info("Ignoring buggy ACPI fan access method\n");
> @@ -8993,9 +9043,16 @@ static int __init fan_init(struct ibm_init_struct *iibm)
> if (res >= 0 && speed != FAN_NOT_PRESENT) {
> /* It responded - so let's assume it's there */
> tp_features.second_fan = 1;
> - /* fan control not currently available for ns ECFW */
> - tp_features.second_fan_ctl = !fan_with_ns_addr;
> - pr_info("secondary fan control detected & enabled\n");
> + /*
> + * fan control not currently available for ns ECFW,
> + * and not needed with 2REG: one write drives both fans
> + */
> + tp_features.second_fan_ctl = !fan_with_ns_addr &&
> + !fan2_with_own_rpm_reg;
> + if (tp_features.second_fan_ctl)
> + pr_info("secondary fan control detected & enabled\n");
> + else
> + pr_info("secondary fan detected\n");
> } else {
> /* Fan not auto-detected */
> tp_features.second_fan = 0;