Lenovo ThinkPad X13s embedded controller support
Subsystems (5)
v6 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 v6:
- Retry failed low-power entry and exit writes once, matching the X13s DSDT's two-attempt ECWS(..., 3) loop without repeating GPIO transitions or changing ordinary EC writes.
- Include linux/irq.h explicitly for irq_get_trigger_type() and IRQ_TYPE_EDGE_FALLING, addressing the reported s390 build errors.
- Carry Krzysztof Kozlowski's Reviewed-by from v3; the binding is unchanged.
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.
Build and software testing (revised v6):
- Rebuilt the revised power-state retry code as an ARM64 driver object with W=1 and GCC 16.2.1, without warnings.
- Passed 15 mocked tests using the actual write helper and PM function bodies, covering success, retry-success, retry-failure, and short writes. Verified attempt counts, error results, GPIO ordering, and requested 10 ms delays with AddressSanitizer and UndefinedBehaviorSanitizer enabled. These tests verify software behavior, not physical timing.
- Applied all three patches to clean Linux v7.3-rc4, without the separate PCI workaround, using both git apply and patch -Np1 --fuzz=0. Both produced identical source files, with no offsets or fuzz.
- Checkpatch reported no errors; its only warnings were the generic MAINTAINERS reminders (the series includes an entry).
Earlier validation of unchanged DT content:
- Before the retry change, compiled the ARM64 driver object and X13s DTB with W=1 using GCC 16.2.1 and the package's config.aarch64 after olddefconfig. The driver compiled without warnings; the DTB build reported four avoid_unnecessary_addr_size warnings in sc8280xp.dtsi DSI nodes outside this series.
- Before the retry change, passed dt_binding_check for the unchanged lenovo,thinkpad-x13s-ec.yaml binding and its example, and targeted validation of the built X13s DTB against that binding.
Hardware testing on a Lenovo ThinkPad X13s booted with revised v6, including the power-state retry helper:
- Passed manual s2idle suspend/resume.
- Passed lid-close s2idle suspend and lid-open wake.
- Keyboard-backlight level 2 was restored correctly after both cycles.
- Sysfs brightness reported 2 after manual resume.
- No unexpected keyboard-backlight OSD appeared.
- Kernel logs confirmed suspend/resume cycles at 09:29:19-09:29:36 and 09:35:07-09:35:29.
- No EC, I2C, or GPIO errors appeared in the filtered logs.
Additional hardware testing before the power-state retry change verified keyboard-backlight levels 0, 1, and 2, including physical brightness, and Fn+Space firmware-driven changes with correct userspace OSD notifications and brightness levels.
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
PATCH v6 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.
---
Documentation/devicetree/bindings/embedded-controller/lenovo,thinkpad-x13s-ec.yaml new file +65 -0
@@ -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; + }; + }; +...
PATCH v6 2/3 platform: arm64: Add Lenovo ThinkPad X13s EC driver
In reply to Alex RobinsonAdd 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.
Retry failed power-state writes once on both entry and exit. The X13s DSDT's ECWS(..., 3) makes at most two attempts and stops on success. Keep the GPIO transitions outside the retry sequence and retain the existing write helper's 10 ms settling delay, including on failure.
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.
---
Changes in v6:
- Include irq.h explicitly for the IRQ trigger validation.
- Retry failed low-power entry and exit writes once, matching the X13s ECWS(..., 3) loop without changing ordinary EC writes or GPIO sequencing.
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
@@ -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
@@ -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
@@ -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 +424 -0
424 lines not on this page · raw message
Re: [PATCH v6 2/3] platform: arm64: Add Lenovo ThinkPad X13s EC driver
Quoted 4 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.
I think you should poke the agent some more to get:
- privacy keys (cam, mic)
- fnlock get/set
- thermal sensors
- thermal trips
- associated irq events
quite easily
Konrad
PATCH v6 3/3 arm64: dts: qcom: sc8280xp-x13s: Add embedded controller
In reply to Alex RobinsonEnable 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.
---
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
@@ -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";
[email protected]
AI reviewRe: [PATCH v6 3/3] arm64: dts: qcom: sc8280xp-x13s: Add embedded controller
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dts: dtbs_check validation failure due to forbidden input-enable property --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dts: dtbs_check validation failure due to forbidden input-enable property --
commit a33aecbbb5f75c5311ccdc6af88f07e6aaed6105
Author: Alex Robinson <[email protected]>
arm64: dts: qcom: sc8280xp-x13s: Add embedded controller
This commit enables the ThinkPad X13s embedded controller to provide keyboard backlight support when booting with Device Tree. It also configures the necessary interrupt lines and pinctrl states.
Quoted 4 lines
arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts +0
-0
[ ... ]
arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts sc-rgb-xshut-n-pins { · line 1596
Quoted 8 lines
arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts +4
-0@@ -1571,6 +1590,20 @@ sc-rgb-xshut-n-pins { }; }; + ec_int_n: ec-int-n-state { + pins = "gpio103"; + function = "gpio"; + input-enable;
[Severity: Low]
Will this property trigger a device tree schema validation regression during make dtbs_check?
The DT binding schema in Documentation/devicetree/bindings/pinctrl/qcom,tlmm-common.yaml, which is inherited by qcom,sc8280xp-tlmm.yaml, explicitly forbids its use by setting input-enable: false for qcom-tlmm-state nodes.
Quoted 10 lines
arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts +10
-0+ bias-pull-up; + }; + + ec_power_state: ec-power-state { + pins = "gpio176"; + function = "gpio"; + drive-strength = <2>; + bias-disable; + }; +
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3