Skip to contentSkip to conversation

Lenovo ThinkPad X13s embedded controller support

PATCH Superseded Alex Robinson 3 participants 8 messages Oct 2 – Oct 10

Subsystems (5)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Lenovo ThinkPad X13s embedded controller support

Add Device Tree support for the ThinkPad X13s embedded controller, providing keyboard-backlight control and firmware-driven brightness notifications. Its event, backlight and power-management interfaces differ from the T14s EC and require a separate driver.

EC wakeup remains disabled by default because lid closure can trigger an unwanted wakeup and no selective event mask is known. Other EC event mappings remain outside the scope of this series.

This follows earlier X13s EC work by Konrad Dybcio and Steev Klimaszewski. Development was assisted by an LLM, including analysis of the X13s ACPI DSDT and review of the implementation.

Changes in v5:
- Replace the private suspended/access-blocked flag and deferred-event handling with IRQ quiescing and LED class suspend/resume helpers.
- Flush pending LED brightness restoration before re-enabling the EC event IRQ, so pending lid events are handled afterwards.
- Preserve the EC lid-restore brightness during PM blanking/restoration.
- Update the LED brightness cache on lid-open restoration without a hardware-change notification, avoiding a spurious backlight OSD. Retain notifications for firmware-driven changes such as Fn+Space.
- Include dev_printk.h directly for device logging helpers.
- Leave the binding and DTS unchanged from v4.

Changes in v4:
- Set GPIO103 bias-pull-up explicitly, based on its firmware-inherited configuration measured at pinctrl probe before Linux claimed or configured the pin. CTL offset 0x67000 read 0x00000003 (pull field 3). The temporary measurement instrumentation is not included.
- Remove output-high from the GPIO176 pinctrl state. The driver already requests GPIOD_OUT_HIGH at probe and controls the line during sleep.
- Restore the suspend brightness snapshot only if it was successfully captured during that suspend, avoiding restoration of a stale value.
- Use FIELD_MODIFY(), validate brightness against the LED maximum, and simplify transfer error handling and selected mutex-protected paths.
- Include linux/ratelimit.h explicitly and adjust conditional formatting.
- Shorten commit messages to focus on rationale rather than the diff.

Changes in v3:
- Disable EC wakeup by default without disabling runtime IRQ handling.
- Retain wakeup-source as a description of hardware capability.
- Remove the Kconfig help text's claim of wake support.

Changes in v2:
- Make backlight snapshots and EC power-management operations best-effort.
- Save firmware- and software-selected brightness in the EC and restore the EC-saved brightness on lid open.
- Process deferred events after the normal resume brightness restore.
- Add QUP8 pin configuration verified on hardware and fix DT node ordering.

Testing:
- Confirmed GPIO103's firmware-inherited pull-up on a ThinkPad X13s using a vanilla kernel with temporary probe-time instrumentation.
- Verified that all three v5 patches apply in order to Linux v7.3-rc4 without the separate PCI workaround and reproduce the current EC source files byte-for-byte.
- Earlier v2 hardware testing covered keyboard-backlight control, firmware brightness changes, s2idle, lid-close/open brightness restoration, and EC wake events. Those results are historical and do not establish validation of the complete v5 series or its revised PM handling. No v5 build or runtime validation was performed while preparing this submission directory.

Earlier series:
https://lore.kernel.org/all/[email protected]/

Alex Robinson (3):
dt-bindings: embedded-controller: Add Lenovo ThinkPad X13s EC
platform: arm64: Add Lenovo ThinkPad X13s EC driver
arm64: dts: qcom: sc8280xp-x13s: Add embedded controller

base-commit: 93f51579e7df248780214094418f205253383cc5

#1 lore raw

PATCH v5 1/3 dt-bindings: embedded-controller: Add Lenovo ThinkPad X13s EC

The ThinkPad X13s EC uses a command transport similar to the T14s EC, but has different keyboard-backlight, event and power-management interfaces.

Add a separate binding to describe the X13s EC.

Assisted-by LLM

---

Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-x13s-ec.yaml new file +65 -0
new file mode 100644
@@ -0,0 +1,65 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/embedded-controller/lenovo,thinkpad-x13s-ec.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lenovo ThinkPad X13s Embedded Controller
+
+maintainers:
+  - Alex Robinson <[email protected]>
+
+description:
+  The Lenovo ThinkPad X13s has an I2C-connected embedded controller (EC)
+  providing keyboard backlight control and event notifications. In addition
+  to its event interrupt, the EC has a separate host-controlled power-state
+  input used during transitions between normal operation and low power.
+
+properties:
+  compatible:
+    const: lenovo,thinkpad-x13s-ec
+
+  reg:
+    const: 0x28
+
+  interrupts:
+    maxItems: 1
+
+  power-state-gpios:
+    maxItems: 1
+    description:
+      GPIO connected to the EC power-state input, driven by the host.
+      The signal is high during normal operation and low in the low-power
+      state. It is used together with I2C power-state commands, rather than
+      as a power-supply enable or reset signal. The GPIO is active high.
+
+  wakeup-source: true
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - power-state-gpios
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        embedded-controller@28 {
+            compatible = "lenovo,thinkpad-x13s-ec";
+            reg = <0x28>;
+            interrupts-extended = <&gpio 1 IRQ_TYPE_EDGE_FALLING>;
+            power-state-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
+            pinctrl-0 = <&ec_int_n>, <&ec_power_state>;
+            pinctrl-names = "default";
+            wakeup-source;
+        };
+    };
+...
#3 lore raw

PATCH v5 2/3 platform: arm64: Add Lenovo ThinkPad X13s EC driver

In reply to Alex Robinson

Add support for the ThinkPad X13s embedded controller to expose keyboard backlight control and firmware-driven brightness changes when booting with Device Tree. Its backlight, event and power-management interfaces differ from the T14s EC and require separate handling.

Preserve brightness across lid and system-sleep transitions using the sequences described by the X13s ACPI firmware. Keep temporary suspend blanking from overwriting the EC's saved lid-restore brightness.

Report firmware-driven brightness changes such as Fn+Space, but do not report lid-open restoration as a new brightness change, avoiding a spurious keyboard-backlight on-screen display.

Leave EC wakeup disabled by default because the shared interrupt can wake the system on lid closure and no selective event mask is known.

This follows earlier X13s EC work by Konrad Dybcio and Steev Klimaszewski.

Assisted-by LLM

---
Changes in v5:
- Include dev_printk.h directly for device logging helpers.
- Replace the private suspended/access-blocked flag and event deferral with disable_irq()/enable_irq() and LED class suspend/resume helpers.
- Flush the LED resume work before re-enabling the event IRQ.
- Preserve the EC lid-restore brightness across PM blanking/restoration.
- Restore lid-open brightness without a spurious hardware-change notification.

MAINTAINERS +6 -0
index cc3cae2e378b34aeb705cef654c720ca9f2ba223..86ae65ac93e7575815f34dbc7a690042ad9ca3b0 100644
@@ -27177,6 +27177,12 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-t14s-ec.yaml
 F:	drivers/platform/arm64/lenovo-thinkpad-t14s.c
 
+THINKPAD X13S EMBEDDED CONTROLLER DRIVER
+M:	Alex Robinson <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-x13s-ec.yaml
+F:	drivers/platform/arm64/lenovo-thinkpad-x13s.c
+
 THINKPAD LMI DRIVER
 M:	Mark Pearson <[email protected]>
 L:	[email protected]
drivers/platform/arm64/Kconfig +16 -0
index e32e01b2a9bdd970d6f2b2bf6b051472c9a16103..eb0b84e5a93733ca16fc871ea94eda30f5760b3c 100644
@@ -90,6 +90,22 @@ config EC_LENOVO_THINKPAD_T14S
 
 	  Say M or Y here to include this support.
 
+config EC_LENOVO_THINKPAD_X13S
+	tristate "Lenovo ThinkPad X13s Embedded Controller driver"
+	depends on ARCH_QCOM || COMPILE_TEST
+	depends on I2C
+	depends on GPIOLIB
+	select NEW_LEDS
+	select LEDS_CLASS
+	select LEDS_BRIGHTNESS_HW_CHANGED
+	help
+	  Driver for the embedded controller in the Lenovo ThinkPad X13s.
+	  Provides keyboard backlight control, hardware brightness change
+	  notifications and system sleep power sequencing.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called lenovo-thinkpad-x13s.
+
 config EC_QCOM_HAMOA
 	tristate "Embedded Controller driver for Qualcomm Hamoa/Glymur reference devices"
 	depends on ARCH_QCOM || COMPILE_TEST
drivers/platform/arm64/Makefile +1 -0
index 7681be4a46e94e7cb80e50bcc5b724cb0961357b..23ed6eef7ce41a5f45d48f5f83b281ebbca94cbb 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_EC_ACER_ASPIRE1)	+= acer-aspire1-ec.o
 obj-$(CONFIG_EC_HUAWEI_GAOKUN)	+= huawei-gaokun-ec.o
 obj-$(CONFIG_EC_LENOVO_YOGA_C630) += lenovo-yoga-c630.o
 obj-$(CONFIG_EC_LENOVO_THINKPAD_T14S) += lenovo-thinkpad-t14s.o
+obj-$(CONFIG_EC_LENOVO_THINKPAD_X13S) += lenovo-thinkpad-x13s.o
 obj-$(CONFIG_EC_QCOM_HAMOA) += qcom-hamoa-ec.o
drivers/platform/arm64/lenovo-thinkpad-x13s.c new file +408 -0

408 lines not on this page · raw message

#6 lore raw

PATCH v5 3/3 arm64: dts: qcom: sc8280xp-x13s: Add embedded controller

In reply to Alex Robinson

Enable the ThinkPad X13s embedded controller so its driver can provide keyboard backlight support when booting with Device Tree.

Use a pull-up on the EC interrupt line to match the firmware-inherited configuration measured before Linux configured the pin.

Assisted-by LLM

---
Review note: GPIO103 was measured at pinctrl probe before Linux claimed/configured the pin. TLMM CTL offset 0x67000 read 0x00000003; the pull field value of 3 decodes to pull-up on SC8280XP.

arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts +40 -0
index 218573a97785b04528854b03a99c837558a33c1e..1e29bab37de6d192ec49dc407e24e1a3bc9496bd 100644
@@ -806,6 +806,25 @@ &i2c4 {
 	};
 };
 
+&i2c8 {
+	clock-frequency = <400000>;
+
+	pinctrl-0 = <&i2c8_default>;
+	pinctrl-names = "default";
+
+	status = "okay";
+
+	embedded-controller@28 {
+		compatible = "lenovo,thinkpad-x13s-ec";
+		reg = <0x28>;
+		interrupts-extended = <&tlmm 103 IRQ_TYPE_EDGE_FALLING>;
+		power-state-gpios = <&tlmm 176 GPIO_ACTIVE_HIGH>;
+		pinctrl-0 = <&ec_int_n>, <&ec_power_state>;
+		pinctrl-names = "default";
+		wakeup-source;
+	};
+};
+
 &i2c11 {
 	clock-frequency = <400000>;
 
@@ -1571,6 +1590,20 @@ cam_rgb_default: cam-rgb-default-state {
 		};
 	};
 
+	ec_int_n: ec-int-n-state {
+		pins = "gpio103";
+		function = "gpio";
+		input-enable;
+		bias-pull-up;
+	};
+
+	ec_power_state: ec-power-state {
+		pins = "gpio176";
+		function = "gpio";
+		drive-strength = <2>;
+		bias-disable;
+	};
+
 	edp_reg_en: edp-reg-en-state {
 		pins = "gpio25";
 		function = "gpio";
@@ -1591,6 +1624,13 @@ i2c4_default: i2c4-default-state {
 		bias-disable;
 	};
 
+	i2c8_default: i2c8-default-state {
+		pins = "gpio43", "gpio44";
+		function = "qup8";
+		drive-strength = <2>;
+		bias-pull-up;
+	};
+
 	i2c11_default: i2c11-default-state {
 		pins = "gpio18", "gpio19";
 		function = "qup11";
#4 lore raw

Re: [PATCH v5 2/3] platform: arm64: Add Lenovo ThinkPad X13s EC driver

In reply to Alex Robinson
Quoted 13 lines · Alex Robinson

Add support for the ThinkPad X13s embedded controller to expose keyboard backlight control and firmware-driven brightness changes when booting with Device Tree. Its backlight, event and power-management interfaces differ from the T14s EC and require separate handling.

Preserve brightness across lid and system-sleep transitions using the sequences described by the X13s ACPI firmware. Keep temporary suspend blanking from overwriting the EC's saved lid-restore brightness.

Report firmware-driven brightness changes such as Fn+Space, but do not report lid-open restoration as a new brightness change, avoiding a spurious keyboard-backlight on-screen display.

Quoted 8 lines

Leave EC wakeup disabled by default because the shared interrupt can wake the system on lid closure and no selective event mask is known.

This follows earlier X13s EC work by Konrad Dybcio and Steev Klimaszewski.

Assisted-by LLM

I'm mostly just curious, is the input/hotkey functionality in the T14s EC driver not relevant for the X13s or did you omit it because you don't need it and/or to keep the initial driver more simple? It seems to be present in the X13s ACPI similar to the T14s.

Quoted 22 lines

[...]

drivers/platform/arm64/lenovo-thinkpad-x13s.c new file +14 -0
new file mode 100644
index 0000000000000000000000000000000000000000..f1ae4c8e67159ebe04ec7aa6521b0ac9ad07a97c
@@ -0,0 +1,408 @@
[...]
+static int x13s_power_gpio(struct x13s_ec *ec, int value)
+{
+	int ret;
+
+	lockdep_assert_held(&ec->lock);
+	ret = gpiod_set_value_cansleep(ec->power_state, value);
+	if (ret) {
+		dev_err(&ec->client->dev, "Failed to set power-state GPIO to %d: %d\n",
+			value, ret);
+	}
+	return ret;
+}
+
+static void x13s_exit_low_power(struct x13s_ec *ec)

drivers/platform/arm64/lenovo-thinkpad-x13s.c line 335

Quoted 10 lines
drivers/platform/arm64/lenovo-thinkpad-x13s.c new file +10 -0
+{
+	int ret;
+
+	lockdep_assert_held(&ec->lock);
+	x13s_power_gpio(ec, 1);
+	/* DSDT: GPIO176 high, Sleep(10), then register 0x80 <- 0xaa. */
+	fsleep(10000);
+	ret = x13s_write(ec, X13S_EC_REG_POWER_STATE, X13S_EC_POWER_STATE_EXIT);
+	if (ret)
+		dev_err(&ec->client->dev, "Failed to exit low power: %d\n", ret);

AFAICT the ACPI implementation has a retry loop here with 3 retries, similar to t14s_ec_write_sequence() in the T14s EC driver (\_SB.I2C9.ECWS). Did you omit that on purpose?

Quoted 16 lines
drivers/platform/arm64/lenovo-thinkpad-x13s.c new file +16 -0
+}
+
+static int x13s_suspend(struct device *dev)
+{
+	struct x13s_ec *ec = dev_get_drvdata(dev);
+	int ret;
+
+	/* The IRQ handler takes lock, so disable it before taking the mutex. */
+	disable_irq(ec->client->irq);
+
+	/* Capture hardware brightness after completing queued LED updates. */
+	flush_work(&ec->led.set_brightness_work);
+	ret = led_update_brightness(&ec->led);
+	if (ret)
+		dev_err(dev, "Failed to save backlight brightness: %d\n", ret);
+

drivers/platform/arm64/lenovo-thinkpad-x13s.c line 361

Quoted 10 lines
drivers/platform/arm64/lenovo-thinkpad-x13s.c new file +10 -0
+	mutex_lock(&ec->lock);
+	ec->preserve_saved_brightness = true;
+	mutex_unlock(&ec->lock);
+
+	/* This flushes brightness work, which also takes lock. */
+	led_classdev_suspend(&ec->led);
+
+	guard(mutex)(&ec->lock);
+	/* DSDT: register 0x80 <- 0x55, then GPIO176 low. */
+	ret = x13s_write(ec, X13S_EC_REG_POWER_STATE, X13S_EC_POWER_STATE_ENTER);

Same here.

Thanks,
Stephan

#7 lore raw
In reply to Alex Robinson
Quoted 13 lines · Alex Robinson

Add Device Tree support for the ThinkPad X13s embedded controller, providing keyboard-backlight control and firmware-driven brightness notifications. Its event, backlight and power-management interfaces differ from the T14s EC and require a separate driver.

EC wakeup remains disabled by default because lid closure can trigger an unwanted wakeup and no selective event mask is known. Other EC event mappings remain outside the scope of this series.

This follows earlier X13s EC work by Konrad Dybcio and Steev Klimaszewski. Development was assisted by an LLM, including analysis of the X13s ACPI DSDT and review of the implementation.

Quoted 14 lines

[...]
Testing:
- Confirmed GPIO103's firmware-inherited pull-up on a ThinkPad X13s using a vanilla kernel with temporary probe-time instrumentation.
- Verified that all three v5 patches apply in order to Linux v7.3-rc4 without the separate PCI workaround and reproduce the current EC source files byte-for-byte.
- Earlier v2 hardware testing covered keyboard-backlight control, firmware brightness changes, s2idle, lid-close/open brightness restoration, and EC wake events. Those results are historical and do not establish validation of the complete v5 series or its revised PM handling. No v5 build or runtime validation was performed while preparing this submission directory.

Nitpick: I assume your LLM added this bullet point(?), but for submitting a series upstream this is kind of like "shooting yourself in the foot". You haven't tested this series for 3 revisions and your LLM hasn't even build-tested it? Please make sure you test your submissions. :-)

Thanks,
Stephan

maintainer
#2 lore raw

Re: [PATCH v5 1/3] dt-bindings: embedded-controller: Add Lenovo ThinkPad X13s EC

In reply to Alex Robinson
Quoted 8 lines · Alex Robinson

The ThinkPad X13s EC uses a command transport similar to the T14s EC, but has different keyboard-backlight, event and power-management interfaces.

Add a separate binding to describe the X13s EC.

Assisted-by LLM

Missing Krzysztof's Reviewed-by.

author
#5 lore raw

Re: [PATCH v5 2/3] platform: arm64: Add Lenovo ThinkPad X13s EC driver

In reply to Stephan Gerhold
Quoted 4 lines · Stephan Gerhold

I'm mostly just curious, is the input/hotkey functionality in the T14s EC driver not relevant for the X13s or did you omit it because you don't need it and/or to keep the initial driver more simple? It seems to be present in the X13s ACPI similar to the T14s.

The X13s does have EC-generated hotkey events similar to the T14s. I left the input functionality out intentionally to keep the initial driver focused on keyboard-backlight control and power management.

I've identified several X13s event codes in the ACPI DSDT, including the programmable F12 key and call-control keys. I think it makes sense to add input support as a follow-up once the event mappings and expected behavior have been verified on hardware.

Thanks,
Alex