From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796119367; b=TH4KxR0UjX6/iccMBYfIGC41pub/Uxv4yUiQpGwODj1O4CFhgjcIELNCGodB49l2+hh2 rc7eObtkxNT4WiDkdYSsszG7ril0GjuiChRB+hAFWtPGAB0qNFc3Y8hOryOZXFRpysHIW Nc2e0534fSo7f2vV8bu7htRQauayA48Z/7/ysQ9HONknBWjJZA805EEigDSHc1x7qQvaI c+dQ9Sf7qLQbusIdBPmquVlnbsyFtdWL+fDOhk9T4lq4UfDvdqYsPrb0QfInYr/4zZTLP rHLnm+xp69gSdXFTU7GlLMjsugE4HjnuKl+yTt4NX286ew9YxscCJQffqZ8qWMpNavw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796119367; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=AmFt/ay/4V1+fDxJYJ7dKgxau4NXw/uQAEtMOjZvy2Y=; b=Q3WFQ3C2IE7vNjwo/j6x8f5gvG+hJnvpGoRDfVXUXuVhHlbt0yWlNDEViSWDpDrEkxWE 1HrbuOVYFKtELWjvEHDMmksyjHutSuOBKNQhYpu07oOOaEkN8g2tLRa5e7EOMgnR9hFVP La8/jvxjDZ8HnFY60WuXWLimd2FxWG/jOc0It0Gu6O59hYTnO1cxusDdgeKkqHkBLShoV 1/D8xCkM6gOg7xZyAYY5d9CG4WXkS2rRylCbkAxFx8G5MXlBwGgxafPcWJF/+y/e2sQdw 2wJTEHo+pTmYxQp7OTUYWI2xKEc7NIFsfgbXgCsLpgXFwFlnzfmclAnmH4/aZ+vJ/wg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SrUHz+6n; arc=none smtp.remote-ip=192.198.163.9 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0545D606A320; Tue, 1 Dec 2026 10:02:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0545D606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=SrUHz+6n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796119367; x=1827655367; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=AmFt/ay/4V1+fDxJYJ7dKgxau4NXw/uQAEtMOjZvy2Y=; b=SrUHz+6nbqdOtrulwd3/WQTEeiTkfFX3agGHOgS7cvYCdFfQkbVPi0BT uVPrvt8BzqvE8Pk2e427/Sm4gdxIlrlIHq2od7UPFtAkPVsYpnCndhrvR Fwb0rfrbu+IP20Pm0FepBRitLccwSGMhSREg5y9YXqIUaSVrBnimdzsMp hfThjuIZkE4p5PYis7kQ3bR0p3fafIqVmWOIq/l0LbsQEI+irKIZ3fb5I Ku+mTJe5xAYjqLHH8E7x1Xnj58b2FmyViS3ZBsuTLsFi98XmIwHT994yN 60Ypt3hvnitMi2NBS4l5LLEuJhgcgXDbiN4tIMjTd1sC0+n5btfYdV98+ Q==; X-CSE-ConnectionGUID: H8qch8TxRreUht6V6i+Z3w== X-CSE-MsgGUID: ea93B2wWRraoUtQM8v3ZBw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4841845" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4841845" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 02:02:46 -0800 X-CSE-ConnectionGUID: m7Uevx1tRG6MBAa4Sco/JQ== X-CSE-MsgGUID: IXTBokS7S8mjcvzHG8CSeQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13363048" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 02:02:42 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 1 Dec 2026 12:02:38 +0200 (EET) To: Vishnu Sankar cc: Hans de Goede , Mark Pearson , "Derek J . Clark" , Rong Zhang , Henrique de Moraes Holschuh , Huang Wei , platform-driver-x86@vger.kernel.org, ibm-acpi-devel@lists.sourceforge.net, LKML Subject: Re: [PATCH v2] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1 In-Reply-To: <20261201002430.75063-1-vishnuocv@gmail.com> Message-ID: References: <20261201002430.75063-1-vishnuocv@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII 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 > Reviewed-by: Mark Pearson > Reviewed-by: Rong Zhang > Signed-off-by: Vishnu Sankar > --- > > 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; >