Skip to contentSkip to conversation

Lenovo ThinkPad T14s EC thermal monitoring and thermal zone integration

PATCH Superseded Daniel Lezcano 4 participants 14 messages Jul 6 – Jul 7

Subsystems (7)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Lenovo ThinkPad T14s EC thermal monitoring and thermal zone integration

Hi,

This series extends the Lenovo ThinkPad T14s embedded controller driver with environmental monitoring capabilities and integrates the exposed sensors into the Linux thermal framework.

The EC provides access to several platform temperature sensors covering the SoC, keyboard area, bottom cover, charging circuitry, QTM module and SSD. These sensors are currently used by the firmware for thermal management but are not exposed to Linux.

The first patch adds hwmon support for the EC temperature sensors.

The second patch exposes the EC as a thermal sensor provider in the device tree and defines thermal zones for the keyboard skin temperature and the charging circuitry temperature. This allows the generic thermal framework to react to EC-reported temperatures and apply standard Linux thermal mitigation policies.

As the EC protocol is not fully decoded, the passive trip points get/set actions are missing, so it is not possible to program a threshold and receive an interrupt when crossed the way up or down. Consequently, the thermal zone related to the charging circuitry is polled every two seconds until we can set the trip points in the EC.

This series fixes critical thermal issues happening on this platform where a kernel compilation, or heavy workloads, lead to a system reboot.

Tested on a Lenovo ThinkPad T14s Gen 6 (Snapdragon X Elite).

Please make sure scmi-cpufreq.ko is loaded before testing

Thanks,

Daniel

---
Changelog:

	v5:
	 - Added Reviewed-by tag (Ilpo Järvinen)
	 - Added the '#thermal-sensor-cells' property DT binding (Sashiko)
	v4:

- Added the missing HWMON_C_REGISTER_TZ attribute (Sashiko)
- Fixed dependency with HWMON (Sashiko)
- Added tags
v3:
- Removed event based because trip point are not yet well supported
- Added an empty line after variable declaration (Ilpo Järvinen)
- Used MILLIDEGREE_PER_DEGREE from units.h (Ilpo Järvinen)
- Made switch consistent (Ilpo Järvinen)
v2:
- Fixed patch 1 subject prefix
- Removed the fan information part
- Added HWMON_T_ALARM
- Fixed DT change description to reflect what it does really

Daniel Lezcano (3):
dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal
sensor provider support
platform: arm64: lenovo-thinkpad-t14s-ec: Add hwmon support for
temperatures
arm64: dts: qcom: x1e78100-t14s: Add thermal zones for keyboard skin
and charging sensors

 .../lenovo,thinkpad-t14s-ec.yaml              |   5 +
 .../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi   |  67 ++++++++-
 drivers/platform/arm64/Kconfig                |   1 +
 drivers/platform/arm64/lenovo-thinkpad-t14s.c | 131 ++++++++++++++++++
 4 files changed, 203 insertions(+), 1 deletion(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v5 1/3 dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

---
 .../embedded-controller/lenovo,thinkpad-t14s-ec.yaml         | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +5 -0
index c87ccb5b3086..0d049979e35b 100644
@@ -26,10 +26,14 @@ properties:
 
   wakeup-source: true
 
+  "#thermal-sensor-cells":
+    const: 1
+
 required:
   - compatible
   - reg
   - interrupts
+  - "#thermal-sensor-cells"
 
 additionalProperties: false
 
@@ -45,6 +49,7 @@ examples:
             reg = <0x28>;
             interrupts-extended = <&tlmm 66 IRQ_TYPE_LEVEL_LOW>;
             wakeup-source;
+            #thermal-sensor-cells = <1>;
         };
     };
 ...
Signature · 1 line
2.53.0
#7 lore raw

PATCH v5 2/3 platform: arm64: lenovo-thinkpad-t14s-ec: Add hwmon support for temperatures

In reply to Daniel Lezcano

Expose the Lenovo ThinkPad T14s EC environmental sensors through the hwmon subsystem.

The driver now registers a hwmon device providing access to six EC temperature sensors corresponding to the SoC, keyboard area, base cover, PMIC/charging circuitry, QTM module and SSD. Sensor labels are exported to allow user space to identify each measurement.

This allows standard monitoring tools such as lm-sensors to report platform temperatures.

---
 drivers/platform/arm64/Kconfig                |   1 +
 drivers/platform/arm64/lenovo-thinkpad-t14s.c | 131 ++++++++++++++++++
 2 files changed, 132 insertions(+)
drivers/platform/arm64/Kconfig +1 -0
index 10f905d7d6bf..121043348740 100644
@@ -75,6 +75,7 @@ config EC_LENOVO_THINKPAD_T14S
 	depends on ARCH_QCOM || COMPILE_TEST
 	depends on I2C
 	depends on INPUT
+	depends on HWMON
 	select INPUT_SPARSEKMAP
 	select LEDS_CLASS
 	select NEW_LEDS
drivers/platform/arm64/lenovo-thinkpad-t14s.c +131 -0

170 lines not on this page · raw message

Signature · 1 line
2.53.0
#11 lore raw

PATCH v5 3/3 arm64: dts: qcom: x1e78100-t14s: Add thermal zones for keyboard skin and charging sensors

In reply to Daniel Lezcano

The Lenovo ThinkPad T14s embedded controller exposes several platform temperature sensors that are already used by the firmware for thermal management.

Expose the EC as a thermal sensor provider and describe the keyboard skin and charging circuitry sensors as thermal zones in the device tree.

The keyboard thermal zone defines passive and hot trip points, while the charging thermal zone also associates a cooling map with the CPU clusters, allowing the generic thermal framework to apply CPU throttling when the charging circuitry temperature exceeds the passive threshold.

This integrates the EC temperature sensors with the Linux thermal framework and enables platform thermal management using standard thermal zone definitions.

The EC protocol currently does not provide a mechanism to program trip points from Linux. Consequently, the thermal zones rely on periodic polling to detect threshold crossings.

Using the charging circuitry temperature for thermal mitigation provides a conservative approximation of the platform thermal state and prevents the platform from reaching critical temperatures under sustained heavy CPU load.

Without this change the platform reaches a critical thermal condition and resets under heavy load.

---
 .../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi   | 67 ++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)
arch/arm64/boot/dts/qcom/x1e78100-lenovo-thinkpad-t14s.dtsi +66 -1
index 5d49df41be02..ed5ba3a428a8 100644
@@ -979,7 +979,7 @@ &i2c6 {
 
 	status = "okay";
 
-	embedded-controller@28 {
+	ec: embedded-controller@28 {
 		compatible = "lenovo,thinkpad-t14s-ec";
 		reg = <0x28>;
 
@@ -988,6 +988,8 @@ embedded-controller@28 {
 		pinctrl-0 = <&ec_int_n_default>;
 		pinctrl-names = "default";
 
+		#thermal-sensor-cells = <1>;
+
 		wakeup-source;
 	};
 };
@@ -1729,3 +1731,66 @@ &usb_mp_qmpphy1 {
 
 	status = "okay";
 };
+
+&thermal_zones {
+	ec-keyboard-thermal {
+		polling-delay = <5000>;
+		polling-delay-passive = <1000>;
+
+		thermal-sensors = <&ec 1>;
+
+		trips {
+			trip-point0 {
+				temperature = <55000>;
+				hysteresis = <2000>;
+				type = "passive";
+			};
+
+			trip-point1 {
+				temperature = <62000>;
+				hysteresis = <0>;
+				type = "hot";
+			};
+		};
+	};
+
+	ec-charging-thermal {
+		/* EC trip points cannot yet be programmed. */
+		polling-delay = <5000>;
+		polling-delay-passive = <2000>;
+
+		thermal-sensors = <&ec 3>;
+
+		trips {
+			ec_charging_psv0: trip-point0 {
+				temperature = <55000>;
+				hysteresis = <0>;
+				type = "passive";
+			};
+
+			ec_charging_alrt0: trip-point1 {
+				temperature = <63000>;
+				hysteresis = <0>;
+				type = "hot";
+			};
+		};
+
+		cooling-maps {
+			map0 {
+				trip = <&ec_charging_psv0>;
+				cooling-device = <&cpu0 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu1 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu2 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu3 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu4 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu5 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu6 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu7 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu8 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu9 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu10 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>,
+						 <&cpu11 THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+			};
+		};
+	};
+};
Signature · 1 line
2.53.0
#12 lore raw

Re: [PATCH v5 3/3] arm64: dts: qcom: x1e78100-t14s: Add thermal zones for keyboard skin and charging sensors

Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 14 lines

The Lenovo ThinkPad T14s embedded controller exposes several platform temperature sensors that are already used by the firmware for thermal management.

Expose the EC as a thermal sensor provider and describe the keyboard skin and charging circuitry sensors as thermal zones in the device tree.

The keyboard thermal zone defines passive and hot trip points, while the charging thermal zone also associates a cooling map with the CPU clusters, allowing the generic thermal framework to apply CPU throttling when the charging circuitry temperature exceeds the passive threshold.

Quoted 7 lines

This integrates the EC temperature sensors with the Linux thermal [ ... ]
and resets under heavy load.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#8 lore raw

Re: [PATCH v5 2/3] platform: arm64: lenovo-thinkpad-t14s-ec: Add hwmon support for temperatures

In reply to Daniel Lezcano
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

Expose the Lenovo ThinkPad T14s EC environmental sensors through the hwmon subsystem.

The driver now registers a hwmon device providing access to six EC temperature sensors corresponding to the SoC, keyboard area, base cover, PMIC/charging circuitry, QTM module and SSD. Sensor labels are exported to allow user space to identify each measurement.

Quoted 6 lines

This allows standard monitoring tools such as lm-sensors to report platform temperatures.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#2 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

In reply to Daniel Lezcano
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Reviewed-by on v5 3/3
#13 lore raw

Re: [PATCH v5 3/3] arm64: dts: qcom: x1e78100-t14s: Add thermal zones for keyboard skin and charging sensors

In reply to Daniel Lezcano
Quoted 30 lines · Daniel Lezcano

The Lenovo ThinkPad T14s embedded controller exposes several platform temperature sensors that are already used by the firmware for thermal management.

Expose the EC as a thermal sensor provider and describe the keyboard skin and charging circuitry sensors as thermal zones in the device tree.

The keyboard thermal zone defines passive and hot trip points, while the charging thermal zone also associates a cooling map with the CPU clusters, allowing the generic thermal framework to apply CPU throttling when the charging circuitry temperature exceeds the passive threshold.

This integrates the EC temperature sensors with the Linux thermal framework and enables platform thermal management using standard thermal zone definitions.

The EC protocol currently does not provide a mechanism to program trip points from Linux. Consequently, the thermal zones rely on periodic polling to detect threshold crossings.

Using the charging circuitry temperature for thermal mitigation provides a conservative approximation of the platform thermal state and prevents the platform from reaching critical temperatures under sustained heavy CPU load.

Without this change the platform reaches a critical thermal condition and resets under heavy load.

Quoted 6 lines
---
 .../qcom/x1e78100-lenovo-thinkpad-t14s.dtsi   | 67 ++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)
Quoted 1 line
Signature · 2 lines
With best wishes
Dmitry
Reviewed-by on v5 2/3
#9 lore raw

Re: [PATCH v5 2/3] platform: arm64: lenovo-thinkpad-t14s-ec: Add hwmon support for temperatures

In reply to Daniel Lezcano
Quoted 11 lines · Daniel Lezcano

Expose the Lenovo ThinkPad T14s EC environmental sensors through the hwmon subsystem.

The driver now registers a hwmon device providing access to six EC temperature sensors corresponding to the SoC, keyboard area, base cover, PMIC/charging circuitry, QTM module and SSD. Sensor labels are exported to allow user space to identify each measurement.

This allows standard monitoring tools such as lm-sensors to report platform temperatures.

Quoted 8 lines
---
 drivers/platform/arm64/Kconfig                |   1 +
 drivers/platform/arm64/lenovo-thinkpad-t14s.c | 131 ++++++++++++++++++
 2 files changed, 132 insertions(+)
Signature · 2 lines
With best wishes
Dmitry
#3 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

In reply to Daniel Lezcano
Quoted 17 lines · Daniel Lezcano

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

---
 .../embedded-controller/lenovo,thinkpad-t14s-ec.yaml         | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +0 -0
index c87ccb5b3086..0d049979e35b 100644
@@ -26,10 +26,14 @@ properties:
 

Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml properties: · line 36

Quoted 10 lines
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +4 -0
   wakeup-source: true
 
+  "#thermal-sensor-cells":
+    const: 1
+
 required:
   - compatible
   - reg
   - interrupts
+  - "#thermal-sensor-cells"

This looks like ABI break without explanation.

Best regards,
Krzysztof

#10 lore raw

Re: [PATCH v5 2/3] platform: arm64: lenovo-thinkpad-t14s-ec: Add hwmon support for temperatures

In reply to Daniel Lezcano
Quoted 12 lines · Daniel Lezcano
drivers/platform/arm64/lenovo-thinkpad-t14s.c +12 -0
+static int t14s_ec_hwmon_probe(struct t14s_ec *ec)
+{
+	struct device *dev;
+	struct t14s_ec_hwmon_sys_thermx sys_thermx[] = {
+		{ .label = "soc",	.reg = T14S_EC_SYS_THERM0 },
+		{ .label = "keyboard",	.reg = T14S_EC_SYS_THERM1 },
+		{ .label = "base",	.reg = T14S_EC_SYS_THERM2 },
+		{ .label = "charging",	.reg = T14S_EC_SYS_THERM3 },
+		{ .label = "qtm",	.reg = T14S_EC_SYS_THERM6 },
+		{ .label = "ssd",	.reg = T14S_EC_SYS_THERM7 },
+	};
+

drivers/platform/arm64/lenovo-thinkpad-t14s.c static irqreturn_t t14s_ec_irq_handler(int irq, void *data) · line 682

Quoted 10 lines
drivers/platform/arm64/lenovo-thinkpad-t14s.c +10 -0
+	ec->ec_hwmon.sys_thermx = devm_kmemdup_array(ec->dev, sys_thermx,
+						     ARRAY_SIZE(sys_thermx),
+						     sizeof(sys_thermx[0]), GFP_KERNEL);
+	if (!ec->ec_hwmon.sys_thermx)
+		return -ENOMEM;
+
+	dev = devm_hwmon_device_register_with_info(ec->dev, "t14s_ec", ec,
+						   &t14s_ec_chip_info, NULL);
+
+	return PTR_ERR_OR_ZERO(dev);

... and this ...

drivers/platform/arm64/lenovo-thinkpad-t14s.c static int t14s_ec_probe(struct i2c_client *client) · line 722

Quoted 12 lines
drivers/platform/arm64/lenovo-thinkpad-t14s.c +5 -0
+}
+
 static int t14s_ec_probe(struct i2c_client *client)
 {
 	struct device *dev = &client->dev;
@@ -590,6 +717,10 @@ static int t14s_ec_probe(struct i2c_client *client)
 	if (ret < 0)
 		return ret;
 
+	ret = t14s_ec_hwmon_probe(ec);
+	if (ret < 0)
+		return ret;

... and this is actual implemented ABI break, if I understood hwmon and thermal code correctly.

drivers/platform/arm64/lenovo-thinkpad-t14s.c static int t14s_ec_probe(struct i2c_client *client) · line 726

Quoted 4 lines
drivers/platform/arm64/lenovo-thinkpad-t14s.c +1 -0
+
 	ret = devm_request_threaded_irq(dev, client->irq, NULL,
 					t14s_ec_irq_handler,
 					IRQF_ONESHOT, dev_name(dev), ec);

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

In reply to Krzysztof Kozlowski
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Daniel Lezcano

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

---
  .../embedded-controller/lenovo,thinkpad-t14s-ec.yaml         | 5 +++++
  1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +0 -0
index c87ccb5b3086..0d049979e35b 100644
@@ -26,10 +26,14 @@ properties:
 
    wakeup-source: true
 
Quoted 10 lines

Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml properties: · line 36

Quoted 8 lines
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +4 -0
+  "#thermal-sensor-cells":
+    const: 1
+
  required:
    - compatible
    - reg
    - interrupts
+  - "#thermal-sensor-cells"

This looks like ABI break without explanation.

What would you suggest ? explanation or removed from required properties?

#5 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

Quoted 32 lines · Daniel Lezcano
Quoted 20 lines · Krzysztof Kozlowski
Quoted 19 lines · Daniel Lezcano

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

---
  .../embedded-controller/lenovo,thinkpad-t14s-ec.yaml         | 5 +++++
  1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +0 -0
index c87ccb5b3086..0d049979e35b 100644
@@ -26,10 +26,14 @@ properties:
 
    wakeup-source: true
 
Quoted 10 lines

Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml properties: · line 36

Quoted 8 lines
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +4 -0
+  "#thermal-sensor-cells":
+    const: 1
+
  required:
    - compatible
    - reg
    - interrupts
+  - "#thermal-sensor-cells"

This looks like ABI break without explanation.

Quoted 1 line

What would you suggest ? explanation or removed from required properties?

I don't know what is the explanation. If this is actual ABI break as I read Linux code, what is the rationale behind breaking real users?

Best regards,
Krzysztof

#6 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad T14s thermal sensor provider support

Quoted 33 lines · Krzysztof Kozlowski
Quoted 32 lines · Daniel Lezcano
Quoted 30 lines · Krzysztof Kozlowski
Quoted 17 lines · Daniel Lezcano

Document the Lenovo ThinkPad T14s Embedded Controller as a thermal sensor provider by adding the '#thermal-sensor-cells' property.

This allows the EC temperature sensors to be referenced from thermal zones in the device tree.

---
   .../embedded-controller/lenovo,thinkpad-t14s-ec.yaml         | 5 +++++
   1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +0 -0
index c87ccb5b3086..0d049979e35b 100644
@@ -26,10 +26,14 @@ properties:
 

Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml properties: · line 36

Quoted 10 lines
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml +4 -0
     wakeup-source: true
 
+  "#thermal-sensor-cells":
+    const: 1
+
   required:
     - compatible
     - reg
     - interrupts
+  - "#thermal-sensor-cells"

This looks like ABI break without explanation.

Quoted 4 lines
Quoted 1 line

What would you suggest ? explanation or removed from required properties?

I don't know what is the explanation. If this is actual ABI break as I read Linux code, what is the rationale behind breaking real users?

IIUC, if the DT has not #thermal-sensor-cells, but the code has the patch 2/3 then the hwmon fails to initialize as well as the EC controller, right ?