Re: [PATCH] platform/x86: thinkpad_acpi: Add Thinkpad Edge E531 fan support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Thanks for the review!

Am 08.08.24 um 15:14 schrieb Ilpo Järvinen:
On Sun, 14 Jul 2024, Matthias Fetzer wrote:

Fan control on the E531 is done using the ACPI methods FANG and
FANW. The correct parameters and register values were found by
analyzing EC firmware as well as DSDT. This has been tested on
my Thinkpad Edge E531 (6885CTO, BIOS HEET52WW 1.33).

Signed-off-by: Matthias Fetzer <kontakt@xxxxxxxxxxxxxxxxxx>
---
  drivers/platform/x86/thinkpad_acpi.c | 159 +++++++++++++++++++++++++++
  1 file changed, 159 insertions(+)

diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
index 397b409064c9..a171a2b39ac9 100644
--- a/drivers/platform/x86/thinkpad_acpi.c
+++ b/drivers/platform/x86/thinkpad_acpi.c
@@ -7751,6 +7751,28 @@ static struct ibm_struct volume_driver_data = {
   * 	EC 0x2f (HFSP) might be available *for reading*, but do not use
   * 	it for writing.
   *
+ * TPACPI_FAN_RD_ACPI_FANG:
+ * 	ACPI FANG method: returns fan control register
+ *
+ *	Takes one parameter which is 0x8100 plus the offset to EC memory
+ *	address 0xf500 and returns the byte at this address.
+ *
+ *	0xf500:
+ *		When the value is less than 9 automatic mode is enabled
+ *	0xf502:
+ *		Contains the current fan speed from 0-100%
+ *	0xf504:
+ *		Bit 7 has to be set in order to enable manual control by
+ *		writing a value >= 9 to 0xf500
+ *
+ * TPACPI_FAN_WR_ACPI_FANW:
+ * 	ACPI FANG method: sets fan control registers
+ *
+ * 	Takes 0x8100 plus the offset to EC memory address 0xf500 and the
+ * 	value to be written there as parameters.
+ *
+ *	see TPACPI_FAN_RD_ACPI_FANG
+ *
   * TPACPI_FAN_WR_TPEC:
   * 	ThinkPad EC register 0x2f (HFSP): fan control loop mode
   * 	Supported on almost all ThinkPads
@@ -7884,6 +7906,7 @@ enum {					/* Fan control constants */
  enum fan_status_access_mode {
  	TPACPI_FAN_NONE = 0,		/* No fan status or control */
  	TPACPI_FAN_RD_ACPI_GFAN,	/* Use ACPI GFAN */
+	TPACPI_FAN_RD_ACPI_FANG,	/* Use ACPI FANG */
  	TPACPI_FAN_RD_TPEC,		/* Use ACPI EC regs 0x2f, 0x84-0x85 */
  	TPACPI_FAN_RD_TPEC_NS,		/* Use non-standard ACPI EC regs (eg: L13 Yoga gen2 etc.) */
  };
@@ -7891,6 +7914,7 @@ enum fan_status_access_mode {
  enum fan_control_access_mode {
  	TPACPI_FAN_WR_NONE = 0,		/* No fan control */
  	TPACPI_FAN_WR_ACPI_SFAN,	/* Use ACPI SFAN */
+	TPACPI_FAN_WR_ACPI_FANW,	/* Use ACPI FANW */
  	TPACPI_FAN_WR_TPEC,		/* Use ACPI EC reg 0x2f */
  	TPACPI_FAN_WR_ACPI_FANS,	/* Use ACPI FANS and EC reg 0x2f */
  };
@@ -7924,9 +7948,13 @@ TPACPI_HANDLE(fans, ec, "FANS");	/* X31, X40, X41 */
  TPACPI_HANDLE(gfan, ec, "GFAN",	/* 570 */
  	   "\\FSPD",		/* 600e/x, 770e, 770x */
  	   );			/* all others */
+TPACPI_HANDLE(fang, ec, "FANG",	/* E531 */
+	   );			/* all others */
  TPACPI_HANDLE(sfan, ec, "SFAN",	/* 570 */
  	   "JFNS",		/* 770x-JL */
  	   );			/* all others */
+TPACPI_HANDLE(fanw, ec, "FANW",	/* E531 */
+	   );			/* all others */
/*
   * Unitialized HFSP quirk: ACPI DSDT and EC fail to initialize the
@@ -8033,6 +8061,23 @@ static int fan_get_status(u8 *status)
break;
  	}
+	case TPACPI_FAN_RD_ACPI_FANG: {
+		/* E531 */
+		int mode, speed;
+
+		if (unlikely(!acpi_evalf(fang_handle, &mode, NULL, "dd", 0x8100)))
+			return -EIO;
+		if (unlikely(!acpi_evalf(fang_handle, &speed, NULL, "dd", 0x8102)))
+			return -EIO;
+
+		if (likely(status)) {
+			*status = speed * 7 / 100;
+			if (mode < 9)
+				*status |= TP_EC_FAN_AUTO;
+		}
+
+		break;
+	}
  	case TPACPI_FAN_RD_TPEC:
  		/* all except 570, 600e/x, 770e, 770x */
  		if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
@@ -8147,6 +8192,17 @@ static int fan2_get_speed(unsigned int *speed)
  		if (speed)
  			*speed = lo ? FAN_RPM_CAL_CONST / lo : 0;
  		break;
+	case TPACPI_FAN_RD_ACPI_FANG: {
+		/* E531 */
+		int speed_tmp;
+
+		if (unlikely(!acpi_evalf(fang_handle, &speed_tmp, NULL, "dd", 0x8102)))
+			return -EIO;
+
+		if (likely(speed))
+			*speed =  speed_tmp * 65535 / 100;
+		break;
+	}
default:
  		return -ENXIO;
@@ -8157,6 +8213,7 @@ static int fan2_get_speed(unsigned int *speed)
static int fan_set_level(int level)
  {
+	int rc;
  	if (!fan_control_allowed)
  		return -EPERM;
@@ -8206,6 +8263,36 @@ static int fan_set_level(int level)
  			tp_features.fan_ctrl_status_undef = 0;
  		break;
+ case TPACPI_FAN_WR_ACPI_FANW:
+		if ((!(level & TP_EC_FAN_AUTO) &&
+		    ((level < 0) || (level > 7))) ||
+		    (level & TP_EC_FAN_FULLSPEED))
+			return -EINVAL;

I'd split this into two to make it more readable:

		if (!(level & TP_EC_FAN_AUTO) && (level < 0 || level > 7))
			return -EINVAL;
		if (level & TP_EC_FAN_FULLSPEED)
			return -EINVAL;

This is much better, thanks.


I'm not sure if -EINVAL is really the right code to return though in these
cases.


I thought that since those are invalid values/parameters the return code of -EINVAL
would be a good choice. What do you suggest to use instead?

+		if (level & TP_EC_FAN_AUTO) {
+			if (!acpi_evalf(fanw_handle, NULL, NULL, "vdd", 0x8106, 0x05)) {

Curiously enough, the comment above doesn't cover offset 0xf506 but the
comment mentions 0xf504 that is never touched anywhere? Is that a typo?


Good catch! This indeed is a typo.





[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux