From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.178 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796385340; b=ePa9q9pjhdK/xN9m1LjlByoGkLdGTQHmdFqp6WxjwqQ2Ez06PgoqRL3cRnW2QLnqZ/Dp GNGVmcUUyDI5hlTOdCF5YVh3yRPA23UQFzTKhcmwNFNBbpNx7lsR8DWH0KDEbcytxXx3r rYEPAXdMb3PSUPCSw+IUoyKB92/lPyT5olDkyL88S7LeVU1wPjllrfSSVrsBSxyuriWA6 5cMEQzMh7COXxG3o1g8Evl25zeyRYq6VKSR6XcZZ3SdvjcT9a0wP+EOqsFIW0mHYy+xq5 8n/00CWIqHbzonnM9Y4XaKpUoBkns/WCMUGy4e2hc/Z8PpiMaaLKJnVfxnFdlEHvunw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385340; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=ppsR32ZkbXNVC550btOvBI6G6csMMfN2W//aPNi7gnQ=; b=tShij27NAS0M9lteVjfpWr6mwtJadeCSeAcbgqDZY9GZzE6dPHYy2p+PzjuQu/UB1QWd vXykX7uc9y2b/NLkM9ZyEmoh36L1JrvT1QZpcr49JjMix9Wo1qOEYEViyauOeFMcPuJ2X G5CI3auhQ7wRnN56gKFHO+oFFpuRgXxSbetn456K6XaqEa3/iBnzht5thyEP2iLmrN1Xd CKgoYE4OsDB1iB9kLA4CT34DQj/GmEy0SKpB+b5e59DnC4f/fe1lHBVXOvTmBp0qqVR4j Jz7XNbAo0k9fkkQ7ywefSf8V5LROejz3Ld0vhJnIvyUuVWRii1vRa0ko0E5TNvSnssQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UEtfUZwB; arc=none smtp.remote-ip=74.125.82.178 Received: from mail-dy1-f178.google.com (mail-dy1-f178.google.com [74.125.82.178]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE847606A322 for ; Fri, 4 Dec 2026 11:55:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BE847606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UEtfUZwB Received: by mail-dy1-f178.google.com with SMTP id 5a478bee46e88-386d1859e1cso847593eec.0 for ; Fri, 04 Dec 2026 03:55:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796385339; x=1796990139; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ppsR32ZkbXNVC550btOvBI6G6csMMfN2W//aPNi7gnQ=; b=UEtfUZwBh9d0BtcI8AKnSBqAzTx4uGKOFxJwexAzBd5u4nx0sUTzZjAqM56/M2+QFy lH685U4SP7cGXJCvPcGHE9WiqatDyl6zoS+kba/XuHXbGO8C6Z8fn6nzklpegAHOBPnO iReMb1kffotTBSZAS0kKawWTQuroz9EKJwK+2BhSYUa5IlKZ/WekpRbalTT33Z2wB5fr oC8zFrInXhVYmGTtq8g+PQ+cCHvTihhmHkIh1ayrUKXXtbvbhA5nvOvop/ess6tfF4Yd TiwqkJn8ltN3cclAihqiySD5sLhtt3/KJWXxvhYlcrFa64cjQZxTLBLe86Hxl9e0yMJU tv1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796385339; x=1796990139; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=ppsR32ZkbXNVC550btOvBI6G6csMMfN2W//aPNi7gnQ=; b=g1vhCJtZs9gUaB+d5XBTYkTRs6KferL6YrlSMGK4VohUQiV74izDDgCVUkSe6CttYj iyiPpeH2Ya8MIskUHs/xoDmADxgjB1RsFzsUv9ghZgD8kxQc3y5wlJkLFpLs4ng1KNMZ rQBW0q4zo0B+nFt272dIT47ZI/vGULNK1VlE1Qc3GX3QV6+A/Wuwuu8t2KdGz+0gESJW hADx19WDmQcpNjlPWz4mIHG7MDuyw/MCy0SzSx5InwWsG1j6ulukAdKxlrQ2Eo+wHxEN Xnq49FgrFlFwCpgzQPzXDVs3bl0zGvgaGvL6Ljw0A94IQJe0Q7YO+hUbCi6/MEtIN7ov NaYw== X-Forwarded-Encrypted: i=1; AL+hErHDOnwV3BGTcQ5cGSFTgvf55J8ntTI2ZRDVOcemVkkrvQKFUMSz32PL8OKEo3nfS0NnyN+BLlxDV2avryc=@vger.kernel.org X-Gm-Message-State: APuU4Z/nK8aJ816RAlzCtnnuaPIcJPIRJOEdvRW33mzSZDgo7z/YPBVt 1Yw8Oq0q1KQ+q0eBKTcPwZ2cY0WEXGlufxFY9UukH3ZRLOpdpXkzes90 X-Gm-Gg: AZFdTZfxWXLUSbv58P3r3rp5RzxBz1YjpYJDAw02CgjDjgmt66ar1VRHN9Evp8J+Dsw YYs3vHQy06D/KHrADW1v2bdQ9F/8PL5jbaiMWM5zx+1wpZ+7E7UEMvsz5NIlFtRWP467ZeeWNKM TQhy+w/mmVLbhlCLN97mH1QVwi32gszcKfsgcdzntIciAnd4nfcVS6f6gtSgGSyZusP11h1577e NO0lngS+q9SHoxTXqg6OsTkkPSpy/oXHX+CHE91n2n+gtQ/67bk/HduWCq1KoTg3R3Oz42fXcA6 hUmXX5GOVcnIyK0qICZJnrL1beoAsCsyHHbEjd9oRY0HGvuUnQSI0anlVHAkdmMfsnuIBF/c9xk nvxOkpj9HcgrYyjmv5AcqhNRRUr6R82eiA2tsKcTNkIoGqc70tsuTgSaYca1gUg367xokj/iN3J 18tVDFOfmXdsjbql4+qm0hrbJwX3ZTw+CxSp3tTWhMCTyqrATtM+zjuYVmgK5rtFECN53KISqcT 2C0E/1zxqnU8I1xHeJKoKlDRNmxcoDP8KkkVlJx67qXIaAExlgSjNR1QBSXfyr/VR9t2CV2Twfg BkQUT4rCM1FTv/jbmQdjXrOdo8niynzv21iQdKfCrDsuzj+ahDOwKO+RC51Bf0ExH5N5NnfDT6B 2bOqh5a5x8IdJhbYldmg+4EwsdSb6qLAAPeMGjTZcYwM= X-Received: by 2002:a05:7300:c011:20b0:386:1901:d994 with SMTP id 5a478bee46e88-38752091748mr2014935eec.5.1796385338827; Fri, 04 Dec 2026 03:55:38 -0800 (PST) Received: from aster-ThinkPad-X9-14-Gen-1 ([2400:2410:5f2b:700:8c41:4d5e:165c:c15a]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521bdedbsm7810823eec.12.2026.12.04.03.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 03:55:38 -0800 (PST) From: Vishnu Sankar To: Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: 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, linux-kernel@vger.kernel.org, Vishnu Sankar Subject: [PATCH v3 2/2] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1 Date: Fri, 4 Dec 2026 20:54:29 +0900 Message-ID: <20261204115429.177264-2-vishnuocv@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261204115429.177264-1-vishnuocv@gmail.com> References: <20261204115429.177264-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-Transfer-Encoding: 8bit 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. Only report second fan control as enabled at boot when it actually is. 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 --- drivers/platform/x86/lenovo/thinkpad_acpi.c | 59 ++++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c index fbc5a69bc016..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; @@ -8205,10 +8215,27 @@ static int fan_get_status_safe(u8 *status) /* 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; + u8 hi, lo, hi2; + int retries = 3; - if (!acpi_ec_read(offset, &lo) || !acpi_ec_read(offset + 1, &hi)) - return false; + 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; @@ -8261,7 +8288,8 @@ static int fan2_get_speed(unsigned int *speed) if (unlikely(!fan_select_fan2())) return -EIO; - rc = !fan_read_rpm(fan_rpm_offset, &rpm); + rc = !fan_read_rpm(fan2_with_own_rpm_reg ? fan2_rpm_offset : fan_rpm_offset, + &rpm); fan_select_fan1(); /* play it safe */ if (rc) @@ -8888,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), @@ -8923,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) @@ -8974,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"); @@ -9008,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; -- 2.53.0