From: Vishnu Sankar <vishnuocv@gmail.com>
To: "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: 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,
linux-kernel@vger.kernel.org, Vishnu Sankar <vishnuocv@gmail.com>
Subject: [PATCH v3 1/2] platform/x86: thinkpad_acpi: Add helper to read fan RPM registers
Date: Fri, 4 Dec 2026 20:54:28 +0900 [thread overview]
Message-ID: <20261204115429.177264-1-vishnuocv@gmail.com> (raw)
fan_get_speed() and fan2_get_speed() both open-code reading the 16-bit
fan RPM value from an EC register pair. Move this into a fan_read_rpm()
helper that takes the register offset, so the following change can add
another register pair and a different read method in one place.
No functional change intended.
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>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 31 +++++++++++++++------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad721..fbc5a69bc016 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -8202,21 +8202,34 @@ static int fan_get_status_safe(u8 *status)
return 0;
}
-static int fan_get_speed(unsigned int *speed)
+/* 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;
+ 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)
+{
+ 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 +8251,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 +8260,15 @@ 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(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;
}
--
2.53.0
next reply other threads:[~2026-12-04 11:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:54 Vishnu Sankar [this message]
2026-12-04 11:54 ` [PATCH v3 2/2] platform/x86: thinkpad_acpi: Fix fan speed reporting on X9 Gen 1 Vishnu Sankar
2026-12-04 18:42 ` [PATCH v3 1/2] platform/x86: thinkpad_acpi: Add helper to read fan RPM registers Ilpo Järvinen
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=20261204115429.177264-1-vishnuocv@gmail.com \
--to=vishnuocv@gmail.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=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
/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
all inboxes | Powered by JetHome®