From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Vishnu Sankar <vishnuocv@gmail.com>
Cc: Hans de Goede <hansg@kernel.org>,
Mark Pearson <mpearson-lenovo@squebb.ca>,
"Derek J . Clark" <derekjohn.clark@gmail.com>,
Rong Zhang <i@rong.moe>,
Henrique de Moraes Holschuh <hmh@hmh.eng.br>,
Huang Wei <huangwei@kylinos.cn>,
platform-driver-x86@vger.kernel.org,
ibm-acpi-devel@lists.sourceforge.net,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1
Date: Tue, 1 Dec 2026 12:02:38 +0200 (EET) [thread overview]
Message-ID: <cfdefe1a-011e-2528-e00e-5aaf89a7d9a9@linux.intel.com> (raw)
In-Reply-To: <20261201002430.75063-1-vishnuocv@gmail.com>
On Tue, 1 Dec 2026, 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. The
> unlatched read intentionally reads the MSB first; the LSB-first order
> is only needed on ECs that latch the MSB when the LSB is read.
>
> 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).
>
> Reviewed-by: Huang Wei <huangwei@kylinos.cn>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Reviewed-by: Rong Zhang <i@rong.moe>
> Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
> ---
>
> Notes:
> v2:
> - Add a comment explaining the unlatched read order (Huang Wei)
> - Collect Reviewed-by tags
>
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 82 ++++++++++++++++++---
> 1 file changed, 71 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 4f81855ad721..e2869f68d81e 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,51 @@ 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) {
> + /*
> + * Not latched, so the LSB-first order is not needed:
> + * read MSB, LSB, MSB and retry 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;
Hi,
What I'd like to see is a two patch series. First change refactors the
existing code and then only in the second one add the new stuff to better
differentiate these two from each other.
--
i.
> if (fan_speed_in_tpr && *speed != 0)
> *speed = FAN_CLOCK_TPM / *speed;
> }
> @@ -8238,7 +8278,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 +8287,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 +8916,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 +8953,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 +9006,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 +9046,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;
>
next prev parent reply other threads:[~2026-12-01 10:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 0:24 [PATCH v2] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1 Vishnu Sankar
2026-12-01 10:02 ` Ilpo Järvinen [this message]
2026-12-01 10:40 ` Vishnu Sankar
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=cfdefe1a-011e-2528-e00e-5aaf89a7d9a9@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=derekjohn.clark@gmail.com \
--cc=hansg@kernel.org \
--cc=hmh@hmh.eng.br \
--cc=huangwei@kylinos.cn \
--cc=i@rong.moe \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=vishnuocv@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.