[PATCH v3 1/2] platform/x86: thinkpad_acpi: Add helper to read fan RPM registers
From: Vishnu Sankar
Date: Fri Dec 04 2026 - 06:55:40 EST
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@xxxxxxxxxx>
Reviewed-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
Reviewed-by: Rong Zhang <i@xxxxxxxx>
Signed-off-by: Vishnu Sankar <vishnuocv@xxxxxxxxx>
---
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