platform/arm64: Lenovo Yoga Slim 7x Gen 11 embedded controller
Subsystems (6)
v5 cover platform/arm64: Lenovo Yoga Slim 7x Gen 11 embedded controller
The Lenovo Yoga Slim 7x Gen 11 is a Qualcomm Snapdragon X2 Elite (glymur) laptop. It carries a Compal EF06 embedded controller on I2C at address 0x70, which is the only source on this machine for the board thermistors, the fan tachometer, the keyboard backlight, Fn-lock, and the mic-mute and airplane-mode keys.
Patch 1 documents the binding, patch 2 adds the driver, patch 3 adds the node to the board.
Why one driver
--------------
The automated review of v2 asked for the hwmon part to become an auxiliary driver under drivers/hwmon/. The hwmon channels, the LED and the input device all sit behind one command mailbox and one interrupt, so the driver stays in one file, like huawei-gaokun-ec, lenovo-thinkpad-t14s and qcom-hamoa-ec next to it. It is documented under Documentation/ABI only.
Notes
-----
Fan speed is reported but not controlled, deliberately - the EC enforces no thermal floor over a manual setpoint. Patch 2 has the measurement.
Tested on a Lenovo Yoga Slim 7x Gen 11 (DMI 83QR, "Yoga Slim 7 14Q8Y11").
Changes in v5:
- Patch 2: drop the battery cell voltages. They live in an EC bank shared with other EC activity, and 43-79% of reads failed the signature check across runs; retries, a cache and a stale window only hid that.
- Patch 2: fn_lock had the polarity inverted: 1 left the multimedia keys primary and the Fn-lock LED off. SCUK bit 7 selects the multimedia keys and bit 5 turns the LED off, as the vendor ACPI FNUS method reports it; 1 now means F1..F12, as documented and as in ideapad-laptop.
- Patch 2: FIELD_MODIFY() for the backlight level; notify fn_lock when the EC toggles it on Fn+Esc; Kconfig help updated; the ABI entry dated October 2026 for 7.5.
- Patch 3: pick up Reviewed-by from Konrad and Abel.
- Link to v4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- Patch 2, after Ilpo's review: the missing includes added where the symbols are used; the cache and stale periods defined in milliseconds with the unit in the name and converted to jiffies at the call; lockdep_assert_held() in the command path every EC access goes through; each EC read checked right after the call; ARRAY_SIZE() for the cell loop; MILLIDEGREE_PER_DEGREE from units.h; braces on the multi-line returns; the ABI entry dated September 2026 for 7.4.
- Patch 2: the i2c id was 20 characters, the size of i2c_device_id.name, leaving no room for the terminator; now "slim7x-gen11-ec".
- Patch 2: symbol prefix renamed from yoga_ec to slim7x11_ec, naming the machine like the driver does. No user-visible name changes.
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in v3:
- Add the board DT node as patch 3. It was posted on its own [1], and a node cannot be merged before its binding (Konrad).
- Add the "Why one driver" section above.
- Patch 2: name the driver after the module, and the i2c id after the compatible.
- Patch 2: spell out both SCUK bits the Fn-lock toggle moves instead of the 0xa0/0x5f masks.
- Patch 2: return -ENODATA for a thermistor reading of 0, as probe already treats 0 as "not fitted".
- Patch 2: ten tries for a cell-voltage sample instead of thirty.
- Patch 2: include what is used directly, devm_mutex_init(), comment the mutex, fix the address in MODULE_AUTHOR, say in the commit message that results cannot be matched to commands.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Patch 2: drop #include <linux/mod_devicetable.h>; <linux/i2c.h> already provides both of_device_id (via linux/of.h) and i2c_device_id (via linux/device-id/i2c.h), and the header is on its way out.
- Patch 2: add "depends on INPUT" to EC_LENOVO_YOGA_SLIM7X_GEN11; the driver registers an input device unconditionally, so a config with INPUT=n did not link.
- Patch 1: pick up Conor Dooley's Acked-by.
- Link to v1: https://lore.kernel.org/all/[email protected]/
[1] https://lore.kernel.org/all/[email protected]/
Oleg Keri (3):
dt-bindings: embedded-controller: add Lenovo Yoga Slim 7x Gen 11 EC platform/arm64: add Lenovo Yoga Slim 7x Gen 11 EC driver
arm64: dts: qcom: glymur-lenovo-yoga-slim7x: add the embedded
controller
.../sysfs-driver-lenovo-yoga-slim7x-gen11-ec | 22 + .../lenovo,yoga-slim7x-gen11-ec.yaml | 56 ++ MAINTAINERS | 8 + .../dts/qcom/glymur-lenovo-yoga-slim7x.dts | 12 +- drivers/platform/arm64/Kconfig | 23 + drivers/platform/arm64/Makefile | 1 + .../arm64/lenovo-yoga-slim7x-gen11-ec.c | 547 ++++++++++++++++++ 7 files changed, 667 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec create mode 100644 Documentation/devicetree/bindings/embedded-controller/lenovo,yoga-slim7x-gen11-ec.yaml create mode 100644 drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c
base-commit: f0406245cb9855e6318335a8a223551354291a46
Signature · 1 line
2.55.0
PATCH v5 1/3 dt-bindings: embedded-controller: add Lenovo Yoga Slim 7x Gen 11 EC
Document the Compal embedded controller found on the Lenovo Yoga Slim 7x Gen 11, a Qualcomm Snapdragon X2 Elite (glymur) laptop. It sits on I2C at address 0x70 and is distinct from the Qualcomm reference EC that the reference designs place at 0x76.
--- .../lenovo,yoga-slim7x-gen11-ec.yaml | 56 +++++++++++++++++++ MAINTAINERS | 8 +++ 2 files changed, 64 insertions(+) create mode 100644 Documentation/devicetree/bindings/embedded-controller/lenovo,yoga-slim7x-gen11-ec.yaml
Documentation/devicetree/bindings/embedded-controller/lenovo,yoga-slim7x-gen11-ec.yaml new file +56 -0
@@ -0,0 +1,56 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/embedded-controller/lenovo,yoga-slim7x-gen11-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Lenovo Yoga Slim 7x Gen 11 Embedded Controller + +maintainers: + - Oleg Keri <[email protected]> + +description: + The Lenovo Yoga Slim 7x Gen 11, a Qualcomm Snapdragon X2 Elite (glymur) + laptop, has a Compal embedded controller on I2C. It reports board + thermistors, battery cell voltages and CPU fan speed, and drives the + keyboard backlight. + + This controller is not the Qualcomm reference EC that the Snapdragon + reference designs place at address 0x76; it speaks a different command + set and answers at 0x70. + +properties: + compatible: + const: lenovo,yoga-slim7x-gen11-ec + + reg: + const: 0x70 + + interrupts: + maxItems: 1 + description: + The controller pulses this line while it has events queued. + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + embedded-controller@70 { + compatible = "lenovo,yoga-slim7x-gen11-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 66 IRQ_TYPE_EDGE_FALLING>; + }; + }; +...
MAINTAINERS +8 -0
@@ -15063,6 +15063,14 @@ S: Maintained F: Documentation/ABI/testing/sysfs-driver-lenovo-yb9-kbdock F: drivers/platform/x86/lenovo/yb9-kbdock.c +LENOVO YOGA SLIM 7X GEN 11 EMBEDDED CONTROLLER DRIVER +M: Oleg Keri <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec +F: Documentation/devicetree/bindings/embedded-controller/lenovo,yoga-slim7x-gen11-ec.yaml +F: drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c + LETSKETCH HID TABLET DRIVER M: Hans de Goede <[email protected]> L: [email protected]
Signature · 1 line
2.55.0
PATCH v5 2/3 platform/arm64: add Lenovo Yoga Slim 7x Gen 11 EC driver
In reply to Oleg KeriThe Lenovo Yoga Slim 7x Gen 11 (Qualcomm glymur / Snapdragon X2 Elite) carries a Compal EF06 embedded controller on I2C at address 0x70. The platform firmware describes it as an ACPI GenericSerialBus region, but the machine boots from device tree, so nothing otherwise talks to it.
Commands are exchanged with two raw I2C block transfers: a 7 byte write to register 0x02 carrying the command and up to six arguments, then a 6 byte read of register 0x01 for the result, with a short delay in between before the result register is valid. The EC offers no way to match a result to its command; the delay is the one the vendor ACPI code uses.
Expose what the EC offers that the rest of the kernel does not already provide:
- five board thermistors as hwmon temperature channels. These are charger, CPU voltage regulator, 5 V rail and ambient sensors, not die sensors, and read considerably cooler than tsens
- CPU fan speed in RPM
- the keyboard backlight as an LED, off/low/high
- Fn-lock as a read/write sysfs attribute, matching the ideapad-laptop interface. The EC reports Fn+Esc as an event but keeps no state of its own, so the driver owns the bit and toggles it on the key
- the mic-mute and airplane-mode keys as KEY_MICMUTE and KEY_RFKILL. These reach the host only as EC events; they are not on the keyboard's HID interface and have no GPIO of their own
The EC signals pending events on a dedicated line, and keeps pulsing it until they are read - so the queue must be drained completely on every interrupt, including codes this driver ignores. Leaving one behind makes the controller pulse indefinitely.
Fan speed is reported but not controlled. The EC accepts a manual setpoint, however it enforces no thermal floor over it: with the fan pinned at roughly 2000 RPM under full load the SoC rose from 69 to 91 degrees in 30 seconds without the EC ever overriding. Exposing pwm1_enable or fan1_target would therefore let userspace overheat the machine, so neither is implemented.
Note this is the Gen 11 machine specifically. Its EC differs from the Qualcomm reference EC that the reference designs place at address 0x76, which is not populated here, and so EC_QCOM_HAMOA does not drive it.
--- .../sysfs-driver-lenovo-yoga-slim7x-gen11-ec | 22 + drivers/platform/arm64/Kconfig | 23 + drivers/platform/arm64/Makefile | 1 + .../arm64/lenovo-yoga-slim7x-gen11-ec.c | 547 ++++++++++++++++++ 4 files changed, 593 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec create mode 100644 drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c
Documentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec new file +22 -0
@@ -0,0 +1,22 @@ +What: /sys/bus/i2c/devices/*/fn_lock +Date: October 2026 +KernelVersion: 7.5 +Contact: Oleg Keri <[email protected]> +Description: + Control fn-lock mode. + + * 1 -> Switched On + * 0 -> Switched Off + + When switched on, the function keys act as F1..F12 and the + multimedia functions require the Fn modifier. + + The embedded controller reports the Fn+Esc key as an event but + keeps no state of its own, so this attribute is the state: the + driver toggles it when the key is pressed, and writing it takes + effect immediately. A toggle from the key is signalled with + sysfs_notify(), so the attribute can be polled. + + For example:: + + # echo "0" > /sys/bus/i2c/devices/9-0070/fn_lock
drivers/platform/arm64/Kconfig +23 -0
@@ -90,6 +90,29 @@ config EC_LENOVO_THINKPAD_T14S Say M or Y here to include this support. +config EC_LENOVO_YOGA_SLIM7X_GEN11 + tristate "Lenovo Yoga Slim 7x Gen 11 Embedded Controller driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on I2C + depends on INPUT + depends on HWMON + select NEW_LEDS + select LEDS_CLASS + help + Say Y here to enable the EC driver for the (Snapdragon X2 Elite, + glymur-based) Lenovo Yoga Slim 7x Gen 11 laptop. The EC provides + thermistors and CPU fan speed as hwmon channels, and the keyboard + backlight as an LED. + + This is the Gen 11 (glymur) machine specifically. Its EC is a Compal + design at i2c address 0x70 and speaks a different protocol from the + Qualcomm reference EC that the reference designs place at 0x76, so + EC_QCOM_HAMOA does not drive it - and conversely this driver does not + cover the X1E-based Yoga Slim 7x Gen 9. + + To compile this driver as a module, choose M here: the module will + be called lenovo-yoga-slim7x-gen11-ec. + 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_YOGA_SLIM7X_GEN11) += lenovo-yoga-slim7x-gen11-ec.o obj-$(CONFIG_EC_QCOM_HAMOA) += qcom-hamoa-ec.o
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +547 -0
547 lines not on this page · raw message
Signature · 1 line
2.55.0
PATCH v5 3/3 arm64: dts: qcom: glymur-lenovo-yoga-slim7x: add the embedded controller
In reply to Oleg KeriDescribe the Compal embedded controller on I2C at address 0x70. It provides the board thermistors and the CPU fan speed, and drives the keyboard backlight. Its interrupt line is TLMM gpio66, falling edge, for which the file already carries a pin state.
That state leaves the pin without a bias. gpio66 has no external pull and floats when the EC is not driving it, which shows up as a steady stream of spurious edges; the vendor ACPI tables describe the same pin as GpioInt(Edge, ActiveLow, Exclusive, PullUp). Enable the pull-up.
--- .../boot/dts/qcom/glymur-lenovo-yoga-slim7x.dts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/qcom/glymur-lenovo-yoga-slim7x.dts +10 -2
@@ -659,7 +659,15 @@ &i2c9 { status = "okay"; - /* EC @ 0x70, irq = TLMM 66 */ + embedded-controller@70 { + compatible = "lenovo,yoga-slim7x-gen11-ec"; + reg = <0x70>; + + interrupts-extended = <&tlmm 66 IRQ_TYPE_EDGE_FALLING>; + + pinctrl-0 = <&ec_int_n_default>; + pinctrl-names = "default"; + }; }; &lpass_vamacro {
@@ -990,7 +998,7 @@ reset-n-pins { ec_int_n_default: ec-int-n-state { pins = "gpio66"; function = "gpio"; - bias-disable; + bias-pull-up; }; kybd_default: kybd-default-state {
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v5 3/3] arm64: dts: qcom: glymur-lenovo-yoga-slim7x: add the embedded controller
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
Describe the Compal embedded controller on I2C at address
0x70. It provides the board thermistors and the CPU fan speed, and drives the keyboard backlight. Its interrupt line is TLMM gpio66, falling edge, for which the file already carries a pin state.That state leaves the pin without a bias. gpio66 has no external pull and floats when the EC is not driving it, which shows up as a steady stream of spurious edges; the vendor ACPI tables describe the same pin as
GpioInt(Edge, ActiveLow, Exclusive, PullUp). Enable the pull-up.Signed-off-by Oleg Keri <[email protected]>
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
[email protected]
AI reviewRe: [PATCH v5 1/3] dt-bindings: embedded-controller: add Lenovo Yoga Slim 7x Gen 11 EC
In reply to Oleg KeriSashiko has reviewed this patch and found no issues. It looks great!
Quoted 6 lines
Document the Compal embedded controller found on the Lenovo Yoga Slim 7x Gen 11, a Qualcomm Snapdragon X2 Elite (glymur) laptop. It sits on I2C at address
0x70and is distinct from the Qualcomm reference EC that the reference designs place at0x76.Signed-off-by Oleg Keri <[email protected]>
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
[email protected]
AI reviewRe: [PATCH v5 2/3] platform/arm64: add Lenovo Yoga Slim 7x Gen 11 EC driver
In reply to Oleg KeriThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] hwmon: hardware monitoring registration outside drivers/hwmon/ --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] hwmon: hardware monitoring registration outside drivers/hwmon/
--
commit 1e4db7708b954def668e65b4325f61905437ade8
Author: Oleg Keri <[email protected]>
platform/arm64: add Lenovo Yoga Slim 7x Gen 11 EC driver
This commit introduces a new embedded controller driver for the Lenovo Yoga Slim 7x Gen 11. It exposes board thermistors and CPU fan speed through the hardware monitoring subsystem, as well as a keyboard backlight via the LED subsystem.
Quoted 5 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +0
-0
[ ... ]
Quoted 2 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +2
-0+static int slim7x11_ec_probe (struct i2c_client *client) +{
[ ... ]
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c line 457
Quoted 9 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +9
-0+if (!ec->temp_present) { +return dev_err_probe (dev, -ENODEV , +"no thermistor reported a usable value\n" ); + } + +dev_dbg (dev,"thermistors present: %#lx\n" , ec->temp_present); + + hwmon =devm_hwmon_device_register_with_info (dev,"yoga_slim7x_ec" , ec, + &slim7x11_ec_chip_info,NULL );
[Severity: Low]
Does this hardware monitoring registration bypass the hwmon subsystem architectural layering rules?
According to the hwmon subsystem guidelines, hardware monitoring devices should reside in the drivers/hwmon/ directory. If a device has secondary functionality or its main functionality isn't hardware monitoring, the hwmon features should be implemented as an auxiliary device driver, and that driver should reside in drivers/hwmon/.
Registering the hwmon device directly from drivers/platform/arm64/ increases driver complexity and bypasses hwmon maintainer review.
Quoted 4 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +4
-0+if (IS_ERR (hwmon)) +return PTR_ERR (hwmon); + + ec->kbd_led.name ="platform::kbd_backlight" ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Ilpo Järvinen
maintainerRe: [PATCH v5 2/3] platform/arm64: add Lenovo Yoga Slim 7x Gen 11 EC driver
In reply to Oleg KeriQuoted 38 lines · Oleg Keri
The Lenovo Yoga Slim 7x Gen 11 (Qualcomm glymur / Snapdragon X2 Elite) carries a Compal EF06 embedded controller on I2C at address
0x70. The platform firmware describes it as an ACPI GenericSerialBus region, but the machine boots from device tree, so nothing otherwise talks to it.Commands are exchanged with two raw I2C block transfers: a 7 byte write to register
0x02carrying the command and up to six arguments, then a 6 byte read of register0x01for the result, with a short delay in between before the result register is valid. The EC offers no way to match a result to its command; the delay is the one the vendor ACPI code uses.Expose what the EC offers that the rest of the kernel does not already provide:
- five board thermistors as hwmon temperature channels. These are charger, CPU voltage regulator, 5 V rail and ambient sensors, not die sensors, and read considerably cooler than tsens
- CPU fan speed in RPM
- the keyboard backlight as an LED, off/low/high
- Fn-lock as a read/write sysfs attribute, matching the ideapad-laptop interface. The EC reports Fn+Esc as an event but keeps no state of its own, so the driver owns the bit and toggles it on the key
- the mic-mute and airplane-mode keys asKEY_MICMUTEandKEY_RFKILL. These reach the host only as EC events; they are not on the keyboard's HID interface and have no GPIO of their ownThe EC signals pending events on a dedicated line, and keeps pulsing it until they are read - so the queue must be drained completely on every interrupt, including codes this driver ignores. Leaving one behind makes the controller pulse indefinitely.
Fan speed is reported but not controlled. The EC accepts a manual setpoint, however it enforces no thermal floor over it: with the fan pinned at roughly 2000 RPM under full load the SoC rose from 69 to 91 degrees in 30 seconds without the EC ever overriding. Exposing
pwm1_enableorfan1_targetwould therefore let userspace overheat the machine, so neither is implemented.
Quoted 5 lines
Note this is the Gen 11 machine specifically. Its EC differs from the Qualcomm reference EC that the reference designs place at address
0x76, which is not populated here, and soEC_QCOM_HAMOAdoes not drive it.Signed-off-by Oleg Keri <[email protected]>
Hi,
A few style nits below.
Quoted 442 lines
--- .../sysfs-driver-lenovo-yoga-slim7x-gen11-ec | 22 + drivers/platform/arm64/Kconfig | 23 + drivers/platform/arm64/Makefile | 1 + .../arm64/lenovo-yoga-slim7x-gen11-ec.c | 547 ++++++++++++++++++ 4 files changed, 593 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec create mode 100644 drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.cDocumentation/ABI/testing/sysfs-driver-lenovo-yoga-slim7x-gen11-ec new file +22
-0@@ -0,0 +1,22 @@ +What: /sys/bus/i2c/devices/*/fn_lock +Date: October 2026 +KernelVersion: 7.5 +Contact: Oleg Keri <[email protected]> +Description: + Control fn-lock mode. + + * 1 -> Switched On + * 0 -> Switched Off + + When switched on, the function keys act as F1..F12 and the + multimedia functions require the Fn modifier. + + The embedded controller reports the Fn+Esc key as an event but + keeps no state of its own, so this attribute is the state: the + driver toggles it when the key is pressed, and writing it takes + effect immediately. A toggle from the key is signalled with + sysfs_notify(), so the attribute can be polled. + + For example:: + + # echo "0" > /sys/bus/i2c/devices/9-0070/fn_lockdrivers/platform/arm64/Kconfig +23
-0@@ -90,6 +90,29 @@ config EC_LENOVO_THINKPAD_T14S Say M or Y here to include this support. +config EC_LENOVO_YOGA_SLIM7X_GEN11 + tristate "Lenovo Yoga Slim 7x Gen 11 Embedded Controller driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on I2C + depends on INPUT + depends on HWMON + select NEW_LEDS + select LEDS_CLASS + help + Say Y here to enable the EC driver for the (Snapdragon X2 Elite, + glymur-based) Lenovo Yoga Slim 7x Gen 11 laptop. The EC provides + thermistors and CPU fan speed as hwmon channels, and the keyboard + backlight as an LED. + + This is the Gen 11 (glymur) machine specifically. Its EC is a Compal + design at i2c address 0x70 and speaks a different protocol from the + Qualcomm reference EC that the reference designs place at 0x76, so + EC_QCOM_HAMOA does not drive it - and conversely this driver does not + cover the X1E-based Yoga Slim 7x Gen 9. + + To compile this driver as a module, choose M here: the module will + be called lenovo-yoga-slim7x-gen11-ec. + config EC_QCOM_HAMOA tristate "Embedded Controller driver for Qualcomm Hamoa/Glymur reference devices" depends on ARCH_QCOM || COMPILE_TESTdrivers/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_YOGA_SLIM7X_GEN11) += lenovo-yoga-slim7x-gen11-ec.o obj-$(CONFIG_EC_QCOM_HAMOA) += qcom-hamoa-ec.odrivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +355
-0@@ -0,0 +1,547 @@ +// SPDX-License-Identifier: GPL-2.0-only + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/container_of.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/errno.h> +#include <linux/gfp_types.h> +#include <linux/hwmon.h> +#include <linux/i2c.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/kstrtox.h> +#include <linux/leds.h> +#include <linux/lockdep.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm.h> +#include <linux/sysfs.h> +#include <linux/types.h> +#include <linux/units.h> + +#define SLIM7X11_EC_BLOCK_READ 0x01 +#define SLIM7X11_EC_BLOCK_WRITE 0x02 +#define SLIM7X11_EC_RESP_LEN 6 +#define SLIM7X11_EC_REQ_LEN 7 + +#define SLIM7X11_EC_CMD_RAM_READ 0xb0 +#define SLIM7X11_EC_CMD_RAM_WRITE 0xb1 +#define SLIM7X11_EC_CMD_FAN 0x46 +#define SLIM7X11_EC_FAN_GET_SPEED 0x81 + +#define SLIM7X11_EC_CMD_EVENT 0x84 +#define SLIM7X11_EC_EVT_MAX_DRAIN 64 +#define SLIM7X11_EC_EVT_FN_LOCK 0x0f +#define SLIM7X11_EC_EVT_MIC_MUTE 0x18 +#define SLIM7X11_EC_EVT_FLIGHT_MODE 0x19 + +#define SLIM7X11_EC_SCUK 0x1c +#define SLIM7X11_EC_SCUK_MEDIA BIT(7) +#define SLIM7X11_EC_SCUK_LED_OFF BIT(5) +#define SLIM7X11_EC_SCUK_MEDIA_MASK (SLIM7X11_EC_SCUK_MEDIA | SLIM7X11_EC_SCUK_LED_OFF) + +#define SLIM7X11_EC_KBLT 0x03 +#define SLIM7X11_EC_KBLT_LEVEL GENMASK(1, 0) +#define SLIM7X11_EC_KBLT_AUTO 3 +#define SLIM7X11_EC_KBLT_MAX 2 + +#define SLIM7X11_EC_TEMP_FIRST 0x12 +#define SLIM7X11_EC_NUM_TEMP 6 +#define SLIM7X11_EC_TEMP_MAX 120 + +struct slim7x11_ec { +struct i2c_client *client; +/* serializes all EC access */ +struct mutex lock; +unsigned long temp_present; +struct led_classdev kbd_led; +u8 kblt_level; +bool kblt_restore; +struct input_dev *keys; +}; + +static int slim7x11_ec_command (struct slim7x11_ec *ec,u8 cmd,u8 arg0,u8 arg1, +u8 resp[SLIM7X11_EC_RESP_LEN ]) +{ +u8 req[SLIM7X11_EC_REQ_LEN ] = { cmd, arg0, arg1 }; +int ret; + +lockdep_assert_held (&ec->lock); + + ret =i2c_smbus_write_i2c_block_data (ec->client,SLIM7X11_EC_BLOCK_WRITE , +sizeof (req), req); +if (ret <0 ) +return ret; + +usleep_range (2000 ,3000 ); + + ret =i2c_smbus_read_i2c_block_data (ec->client,SLIM7X11_EC_BLOCK_READ , +SLIM7X11_EC_RESP_LEN , resp); +if (ret <0 ) +return ret; +if (ret !=SLIM7X11_EC_RESP_LEN ) +return -EIO ; + +return 0 ; +} + +static int slim7x11_ec_ram_read (struct slim7x11_ec *ec,u8 addr,u8 *val) +{ +u8 resp[SLIM7X11_EC_RESP_LEN ]; +int ret; + + ret =slim7x11_ec_command (ec,SLIM7X11_EC_CMD_RAM_READ , addr,0 , resp); +if (ret) +return ret; + + *val = resp[0 ]; +return 0 ; +} + +static int slim7x11_ec_ram_write (struct slim7x11_ec *ec,u8 addr,u8 val) +{ +u8 resp[SLIM7X11_EC_RESP_LEN ]; + +return slim7x11_ec_command (ec,SLIM7X11_EC_CMD_RAM_WRITE , addr, val, resp); +} + +static int slim7x11_ec_fan_read (struct slim7x11_ec *ec,long *rpm) +{ +u8 resp[SLIM7X11_EC_RESP_LEN ]; +int ret; + + ret =slim7x11_ec_command (ec,SLIM7X11_EC_CMD_FAN ,SLIM7X11_EC_FAN_GET_SPEED ,0 , + resp); +if (ret) +return ret; + + *rpm = resp[0 ] *100 ; +return 0 ; +} + +static umode_t slim7x11_ec_is_visible (const void *drvdata, +enum hwmon_sensor_types type, +u32 attr,int channel) +{ +const struct slim7x11_ec *ec = drvdata; + +switch (type) { +case hwmon_temp: +if (!(ec->temp_present &BIT (channel))) +return 0 ; +return 0444 ; +case hwmon_fan: +return 0444 ; +default : +return 0 ; + } +} + +static int slim7x11_ec_read (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,long *val) +{ +struct slim7x11_ec *ec =dev_get_drvdata (dev); +int ret; +u8 raw; + +guard (mutex)(&ec->lock); + +switch (type) { +case hwmon_temp: + ret =slim7x11_ec_ram_read (ec,SLIM7X11_EC_TEMP_FIRST + channel, &raw); +if (ret) +return ret; +if (!raw) +return -ENODATA ; +if (raw >SLIM7X11_EC_TEMP_MAX ) +return -EIO ; + *val = raw *MILLIDEGREE_PER_DEGREE ; +return 0 ; +case hwmon_fan: +return slim7x11_ec_fan_read (ec, val); +default : +return -EOPNOTSUPP ; + } +} + +static const char *const slim7x11_ec_temp_labels[SLIM7X11_EC_NUM_TEMP ] = { +"Charger A" , +"CPU VR" , +"5V rail" , +"Ambient" , +"Charger B" , +"Thermistor 6" , +}; + +static int slim7x11_ec_read_string (struct device *dev,enum hwmon_sensor_types type, +u32 attr,int channel,const char **str) +{ +switch (type) { +case hwmon_temp: + *str = slim7x11_ec_temp_labels[channel]; +return 0 ; +case hwmon_fan: + *str ="CPU fan" ; +return 0 ; +default : +return -EOPNOTSUPP ; + } +} + +static enum led_brightness slim7x11_ec_kbd_led_get (struct led_classdev *led) +{ + struct slim7x11_ec *ec = container_of(led, struct slim7x11_ec, kbd_led); +u8 raw; + +guard (mutex)(&ec->lock); + +if (slim7x11_ec_ram_read (ec,SLIM7X11_EC_KBLT , &raw)) +return 0 ; + + raw =FIELD_GET (SLIM7X11_EC_KBLT_LEVEL , raw); + +if (raw ==SLIM7X11_EC_KBLT_AUTO ) +return SLIM7X11_EC_KBLT_MAX ; + +return raw; +} + +static int slim7x11_ec_kbd_led_level (struct slim7x11_ec *ec,u8 level,u8 *old) +{ +u8 raw; +int ret; + + ret =slim7x11_ec_ram_read (ec,SLIM7X11_EC_KBLT , &raw); +if (ret) +return ret; + +if (old) + *old =FIELD_GET (SLIM7X11_EC_KBLT_LEVEL , raw); + +FIELD_MODIFY (SLIM7X11_EC_KBLT_LEVEL , &raw, level); + +return slim7x11_ec_ram_write (ec,SLIM7X11_EC_KBLT , raw); +} + +static int slim7x11_ec_kbd_led_set (struct led_classdev *led, +enum led_brightness brightness) +{ + struct slim7x11_ec *ec = container_of(led, struct slim7x11_ec, kbd_led); + +guard (mutex)(&ec->lock); + +return slim7x11_ec_kbd_led_level (ec, brightness,NULL ); +} + +static const struct hwmon_ops slim7x11_ec_hwmon_ops = { + .is_visible = slim7x11_ec_is_visible, + .read = slim7x11_ec_read, + .read_string = slim7x11_ec_read_string, +}; + +static const struct hwmon_channel_info *const slim7x11_ec_hwmon_info[] = { +HWMON_CHANNEL_INFO (temp, +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL , +HWMON_T_INPUT |HWMON_T_LABEL ), +HWMON_CHANNEL_INFO (fan, +HWMON_F_INPUT |HWMON_F_LABEL ), +NULL +}; + +static const struct hwmon_chip_info slim7x11_ec_chip_info = { + .ops = &slim7x11_ec_hwmon_ops, + .info = slim7x11_ec_hwmon_info, +}; + +static int slim7x11_ec_fn_lock_toggle (struct slim7x11_ec *ec) +{ +u8 raw; +int ret; + + ret =slim7x11_ec_ram_read (ec,SLIM7X11_EC_SCUK , &raw); +if (ret) +return ret; + +if (raw &SLIM7X11_EC_SCUK_MEDIA ) + raw &= ~SLIM7X11_EC_SCUK_MEDIA_MASK ; +else + raw |=SLIM7X11_EC_SCUK_MEDIA_MASK ; + +return slim7x11_ec_ram_write (ec,SLIM7X11_EC_SCUK , raw); +} + +static void slim7x11_ec_report_key (struct slim7x11_ec *ec,unsigned int code) +{ +if (!ec->keys) +return ; + +input_report_key (ec->keys, code,1 ); +input_sync (ec->keys); +input_report_key (ec->keys, code,0 ); +input_sync (ec->keys); +} + +static irqreturn_t slim7x11_ec_irq (int irq,void *data) +{ +struct slim7x11_ec *ec = data; +unsigned int i; + +guard (mutex)(&ec->lock); + +for (i =0 ; i <SLIM7X11_EC_EVT_MAX_DRAIN ; i++) { +u8 resp[SLIM7X11_EC_RESP_LEN ]; + +if (slim7x11_ec_command (ec,SLIM7X11_EC_CMD_EVENT ,0 ,0 , resp)) +break ; +if (!resp[0 ]) +break ; + +switch (resp[0 ]) { +case SLIM7X11_EC_EVT_FN_LOCK : +if (!slim7x11_ec_fn_lock_toggle (ec)) +sysfs_notify (&ec->client->dev.kobj,NULL ,"fn_lock" ); +break ; +case SLIM7X11_EC_EVT_MIC_MUTE : +slim7x11_ec_report_key (ec,KEY_MICMUTE ); +break ; +case SLIM7X11_EC_EVT_FLIGHT_MODE : +slim7x11_ec_report_key (ec,KEY_RFKILL ); +break ; +default : +break ; + } + } + +return IRQ_HANDLED ; +} + +static void slim7x11_ec_register_keys (struct slim7x11_ec *ec) +{ +struct device *dev = &ec->client->dev; +struct input_dev *input; +int ret; + + input =devm_input_allocate_device (dev); +if (!input) { +dev_warn (dev,"no memory for the hotkey device\n" ); +return ; + } + + input->name ="Lenovo Yoga Slim 7x hotkeys" ; + input->phys ="lenovo-yoga-slim7x-gen11-ec/input0" ; + input->id.bustype =BUS_I2C ; +input_set_capability (input,EV_KEY ,KEY_MICMUTE ); +input_set_capability (input,EV_KEY ,KEY_RFKILL ); + + ret =input_register_device (input); +if (ret) { +dev_warn (dev,"cannot register the hotkey device: %d\n" , ret); +return ; + } + + ec->keys = input; +} + +static ssize_t fn_lock_show (struct device *dev,struct device_attribute *attr, +char *buf)
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c line 365
Quoted 10 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +10
-0+{ +struct slim7x11_ec *ec =dev_get_drvdata (dev); +u8 raw; +int ret; + +scoped_guard (mutex, &ec->lock) + ret = slim7x11_ec_ram_read(ec, SLIM7X11_EC_SCUK, &raw); + +if (ret) +return ret;
Please put this inside scoped_guard(). There's little reason to do "optimization" like this at the cost of error handling clarity.
Quoted 41 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +41
-0+ +return sysfs_emit (buf,"%u\n" , !(raw &SLIM7X11_EC_SCUK_MEDIA )); +} + +static ssize_t fn_lock_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct slim7x11_ec *ec =dev_get_drvdata (dev); +bool enable; +u8 raw; +int ret; + + ret =kstrtobool (buf, &enable); +if (ret) +return ret; + +guard (mutex)(&ec->lock); + + ret =slim7x11_ec_ram_read (ec,SLIM7X11_EC_SCUK , &raw); +if (ret) +return ret; + +if (enable) + raw &= ~SLIM7X11_EC_SCUK_MEDIA_MASK ; +else + raw |=SLIM7X11_EC_SCUK_MEDIA_MASK ; + + ret =slim7x11_ec_ram_write (ec,SLIM7X11_EC_SCUK , raw); +if (ret) +return ret; + +return count; +} +static DEVICE_ATTR_RW (fn_lock); + +static struct attribute *slim7x11_ec_attrs[] = { + &dev_attr_fn_lock.attr, +NULL +}; +ATTRIBUTE_GROUPS (slim7x11_ec); +
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c line 416
Quoted 10 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +10
-0+static int slim7x11_ec_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct device *hwmon; +struct slim7x11_ec *ec; +unsigned int i; +int ret; + +if (!i2c_check_functionality (client->adapter, +I2C_FUNC_SMBUS_I2C_BLOCK )) {
Use just one line?
Quoted 11 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +11
-0+return dev_err_probe (dev, -ENODEV , +"adapter does not support SMBus block transfers\n" ); + } + + ec =devm_kzalloc (dev,sizeof (*ec),GFP_KERNEL ); +if (!ec) +return -ENOMEM ; + + ec->client = client; +i2c_set_clientdata (client, ec); +
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c line 437
Quoted 10 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +10
-0+ ret =devm_mutex_init (dev, &ec->lock); +if (ret) +return ret; + + scoped_guard(mutex, &ec->lock) { +for (i =0 ; i <SLIM7X11_EC_NUM_TEMP ; i++) { +u8 raw; + + ret =slim7x11_ec_ram_read (ec,SLIM7X11_EC_TEMP_FIRST + i, + &raw);
I don't know why this line in particular is split at this point, you have much longer code lines below.
It's generally okay to have code lines go up to 100 chars as long as one doesn't hide key logic to the very end of a line. Taking advantage of that is most useful to avoid breaking function calls with many args excessively and other boilerplatey stuff.
Quoted 22 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +22
-0+if (ret) { +return dev_err_probe (dev, ret, +"failed to read thermistor %u\n" , + i); + } + +if (raw >0 && raw <=SLIM7X11_EC_TEMP_MAX ) + ec->temp_present |=BIT (i); + } + } + +if (!ec->temp_present) { +return dev_err_probe (dev, -ENODEV , +"no thermistor reported a usable value\n" ); + } + +dev_dbg (dev,"thermistors present: %#lx\n" , ec->temp_present); + + hwmon =devm_hwmon_device_register_with_info (dev,"yoga_slim7x_ec" , ec, + &slim7x11_ec_chip_info,NULL ); +if (IS_ERR (hwmon)) +return PTR_ERR (hwmon);
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c line 469
Quoted 10 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +10
-0+ + ec->kbd_led.name ="platform::kbd_backlight" ; + ec->kbd_led.max_brightness =SLIM7X11_EC_KBLT_MAX ; + ec->kbd_led.brightness_get = slim7x11_ec_kbd_led_get; + ec->kbd_led.brightness_set_blocking = slim7x11_ec_kbd_led_set; + + ret =devm_led_classdev_register (dev, &ec->kbd_led); +if (ret) { +return dev_err_probe (dev, ret, +"failed to register keyboard backlight\n" );
I don't get why you split this, you've a longer dev_err_probe() line below.
Quoted 79 lines
drivers/platform/arm64/lenovo-yoga-slim7x-gen11-ec.c new file +78
-0+ } + +if (client->irq) { +slim7x11_ec_register_keys (ec); + + ret =devm_request_threaded_irq (dev, client->irq,NULL , + slim7x11_ec_irq,IRQF_ONESHOT , +"lenovo-yoga-slim7x-gen11-ec" , ec); +if (ret) +return dev_err_probe (dev, ret,"cannot request the EC interrupt\n" ); + + scoped_guard(mutex, &ec->lock) { +for (i =0 ; i <SLIM7X11_EC_EVT_MAX_DRAIN ; i++) { +u8 resp[SLIM7X11_EC_RESP_LEN ]; + +if (slim7x11_ec_command (ec,SLIM7X11_EC_CMD_EVENT ,0 ,0 , resp)) +break ; +if (!resp[0 ]) +break ; + } + } + } + +return 0 ; +} + +static int slim7x11_ec_suspend (struct device *dev) +{ +struct slim7x11_ec *ec =dev_get_drvdata (dev); + +guard (mutex)(&ec->lock); + ec->kblt_restore = !slim7x11_ec_kbd_led_level (ec,0 , &ec->kblt_level); + +return 0 ; +} + +static int slim7x11_ec_resume (struct device *dev) +{ +struct slim7x11_ec *ec =dev_get_drvdata (dev); + +guard (mutex)(&ec->lock); +if (ec->kblt_restore) { + ec->kblt_restore = false; +slim7x11_ec_kbd_led_level (ec, ec->kblt_level,NULL ); + } + +return 0 ; +} + +static DEFINE_SIMPLE_DEV_PM_OPS(slim7x11_ec_pm_ops, slim7x11_ec_suspend, slim7x11_ec_resume); + +static const struct of_device_id slim7x11_ec_of_match[] = { + { .compatible ="lenovo,yoga-slim7x-gen11-ec" }, + { } +}; +MODULE_DEVICE_TABLE (of, slim7x11_ec_of_match); + +static const struct i2c_device_id slim7x11_ec_i2c_id[] = { + {"slim7x-gen11-ec" }, + { } +}; +MODULE_DEVICE_TABLE (i2c, slim7x11_ec_i2c_id); + +static struct i2c_driver slim7x11_ec_driver = { + .driver = { + .name ="lenovo-yoga-slim7x-gen11-ec" , + .of_match_table = slim7x11_ec_of_match, + .dev_groups = slim7x11_ec_groups, + .pm =pm_sleep_ptr (&slim7x11_ec_pm_ops), + }, + .probe = slim7x11_ec_probe, + .id_table = slim7x11_ec_i2c_id, +}; +module_i2c_driver (slim7x11_ec_driver); + +MODULE_AUTHOR ("Oleg Keri <[email protected]>" ); +MODULE_DESCRIPTION ("Lenovo Yoga Slim 7x Gen 11 embedded controller" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
i.