mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 1/2] platform/x86: thinkpad_acpi: Add helper to read fan RPM registers
@ 2026-12-04 11:54 Vishnu Sankar
  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
  0 siblings, 2 replies; 3+ messages in thread
From: Vishnu Sankar @ 2026-12-04 11:54 UTC (permalink / raw)
  To: Hans de Goede, Ilpo Järvinen
  Cc: Mark Pearson, Derek J . Clark, Rong Zhang,
	Henrique de Moraes Holschuh, Huang Wei, platform-driver-x86,
	ibm-acpi-devel, linux-kernel, Vishnu Sankar

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04 18:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-04 11:54 [PATCH v3 1/2] platform/x86: thinkpad_acpi: Add helper to read fan RPM registers Vishnu Sankar
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

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®