* [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger
@ 2026-12-03 12:06 Qiling Zhu
2026-12-03 12:06 ` [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:06 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
Hi all,
On supported ThinkPads, Fn+Space can select automatic keyboard
backlight control. This series exposes that mode through the private
LED trigger "tpacpi-kbd-auto", following the hw control trigger
framework and its ideapad-laptop example. The first patch fixes an
out-of-range brightness value that was reported to make UPower stop
tracking hotkey changes on a ThinkPad X9-14 Gen 1.
The patches:
1/6 Report auto keyboard backlight mode as off (stable)
2/6 Extract kbdlight notify helpers (refactor)
3/6 Don't poke keyboard backlight's LED core brightness (writes)
4/6 Restore keyboard backlight level ourselves (sleep/wake)
5/6 Detect auto-mode capability via MLCG (groundwork)
6/6 Add a keyboard backlight auto-mode trigger (feature)
A few notes on the design:
- The auto mode is EC level 3 and not a brightness, so it is reported
as 0 to the LED core. The trigger is registered when MLCG bit 20
says the EC supports the auto mode, and it is attached by default if
the EC is already in auto mode when the driver loads.
- 4/6 drops kbdlight_suspend() and has kbdlight_resume() write the
cached EC level back on every model: with thinkpad_acpi unloaded,
the firmware turned the backlight off for s2idle and hibernation on
my machine, and the EC came back at its previous level after s2idle
and at 0 after hibernation. No LED_SUSPENDED gate is kept: this LED
does not set LED_CORE_SUSPENDRESUME, and with the suspend callback
gone I do not see what would set the flag for it. With 1/6 on its
own, a backlight that went to sleep in auto mode comes back off
after resume on kernels that still use the LED core suspend/resume
path; the rest of the series restores the level the EC had.
- kbdlight_brightness now holds the raw EC level, including the auto
mode, rather than a brightness; a comment above the variable says
so, and the name is unchanged.
Changes since v5:
- 5/6 defines TPACPI_KBD_LIGHT_AUTO_CAPABLE_BIT with BIT(), as Ilpo
suggested; the name is kept. No other code change, and the
Reviewed-by tags are unchanged. Sent following Ilpo's suggestion on
the timing.
Changes since v4, in short: 2/6 now contains the changes to the notify
helpers that 4/6 used to make, 4/6 shrank accordingly, and 5/6 dropped
a redundant comment. Details are in the v5 thread:
https://lore.kernel.org/r/20261130131252.80436-1-kmatzkaczor244@gmail.com/
Testing was done on a ThinkPad X1 Carbon Gen 14 (linux-next
next-20261030): the software paths, the trigger following Fn+Space in
and out of auto mode, and suspend/resume from manual levels and from
auto mode. S3-capable models and other models are still untested, and
testing there would be very welcome. One observation from testing
with a desktop session: KDE's power management can write back the
keyboard brightness it last knew about after resume, so a level
written directly through sysfs may be replaced by it. The series also
applies cleanly to the current linux-next.
The checkpatch.pl --strict warnings I see are for three commit IDs that
are missing from my shallow clone.
This series was developed with LLM assistance; I reviewed every design
decision against the framework sources and validated the behavior on
real hardware myself.
Thank you all for your time and for the reviews of the earlier
versions.
Regards,
Qiling Zhu
Qiling Zhu (6):
platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as
off
platform/x86: thinkpad_acpi: Extract kbdlight notify helpers
platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core
brightness
platform/x86: thinkpad_acpi: Restore keyboard backlight level
ourselves
platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode
trigger
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/thinkpad_acpi.c | 183 +++++++++++++++-----
2 files changed, 142 insertions(+), 42 deletions(-)
base-commit: 7649ba73f9e7e1e04d0b46213e39c79ae09dd55c
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
@ 2026-12-03 12:06 ` Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Qiling Zhu
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:06 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
The EC keyboard backlight level 3, which selects the auto mode, is
passed to the LED classdev verbatim by kbdlight_sysfs_get(). The LED
then reports a brightness of 3 with max_brightness 2, both through the
brightness sysfs attribute and through brightness_hw_changed
notifications.
This is not only cosmetic. According to a report on a ThinkPad X9-14
Gen 1, UPower 1.91.x treats the out-of-range value as invalid and stops
watching brightness_hw_changed, so the desktop no longer follows the
Fn+Space hotkey after auto mode has been entered.
The auto mode is not a brightness level. Report it as 0, which is
within the exported brightness range, in a new helper,
kbdlight_level_to_brightness(), as ideapad-laptop does for its auto
mode.
Fixes: bb28f3d51ff5 ("thinkpad_acpi: Add support for keyboard backlight")
Reported-by: Andrea Rabbaglietti <rabbagliettiandrea@gmail.com>
Closes: https://lore.kernel.org/r/CAENjc+w0Rqy=kDSew7XtNJCSvyPiXPJ5faWdmCr5RGYFhpunCA@mail.gmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
With this patch on its own, on kernels that still use the LED core
suspend/resume path, a backlight that went to sleep in auto mode comes
back off after resume; before, it came back in auto mode, since that
path wrote the unmapped value back. The rest of this series restores
the level the EC had.
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad..31d3721bb 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5102,6 +5102,9 @@ static struct ibm_struct video_driver_data = {
* Keyboard backlight subdriver
*/
+/* EC level that selects the auto mode for the keyboard backlight */
+#define TPACPI_KBD_LIGHT_AUTO_LEVEL 3
+
static enum led_brightness kbdlight_brightness;
static DEFINE_MUTEX(kbdlight_mutex);
@@ -5135,6 +5138,15 @@ static int kbdlight_get_level(void)
return status & 0x3;
}
+static int kbdlight_level_to_brightness(int level)
+{
+ /* Auto mode is not a brightness level; report it as off. */
+ if (level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
+ return 0;
+
+ return level;
+}
+
static bool kbdlight_is_supported(void)
{
int status = 0;
@@ -5194,7 +5206,7 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
if (level < 0)
return 0;
- return level;
+ return kbdlight_level_to_brightness(level);
}
static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-12-03 12:06 ` [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
@ 2026-12-03 12:07 ` Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:07 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the
brightness, compares it with the cached value and notifies the LED core
inline. Extract this block into two helpers: kbdlight_notify_level()
takes an EC level, compares it with the cached value, updates the cache
and notifies the LED core, translating the level to a brightness on the
way, as kbdlight_sysfs_get() does; kbdlight_notify_change() reads the
level back and calls the former under kbdlight_mutex.
kbdlight_notify_level() expects the caller to hold kbdlight_mutex, so
that the proc write path can reuse it with the level it has just
written in a subsequent change.
The helpers work in EC levels rather than brightness values, as the
rest of the series builds on that. This differs from the original code
in two situations: a change from off to the auto mode or back, which
reads back as the same brightness, now produces a notification
reporting 0 when the cached value holds the EC level, where the
original code sent none; and a failed read of the level now sends no
notification and leaves the cached value alone, where the original code
went on with a brightness of 0.
kbdlight_brightness is still an enum led_brightness at this point, and
kbdlight_init() still fills it in from the reported brightness; a later
change in this series makes it an int that tracks the EC level from
init on.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 48 ++++++++++++++-------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 31d3721bb..3ef857542 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5267,6 +5267,36 @@ static int kbdlight_set_level_and_update(int level)
return ret;
}
+static void kbdlight_notify_level(int level)
+{
+ struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+
+ lockdep_assert_held(&kbdlight_mutex);
+
+ /*
+ * Check the level actually changed, setting the level
+ * through kbdlight_set_level() also triggers this event.
+ */
+ if (level == kbdlight_brightness)
+ return;
+
+ kbdlight_brightness = level;
+ led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level));
+}
+
+static void kbdlight_notify_change(void)
+{
+ int level;
+
+ guard(mutex)(&kbdlight_mutex);
+
+ level = kbdlight_get_level();
+ if (level < 0)
+ return;
+
+ kbdlight_notify_level(level);
+}
+
static int kbdlight_read(struct seq_file *m)
{
int level;
@@ -11593,22 +11623,8 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_KBD_LIGHT:
- if (tp_features.kbdlight) {
- enum led_brightness brightness;
-
- guard(mutex)(&kbdlight_mutex);
-
- /*
- * Check the brightness actually changed, setting the brightness
- * through kbdlight_set_level() also triggers this event.
- */
- brightness = kbdlight_sysfs_get(NULL);
- if (kbdlight_brightness != brightness) {
- kbdlight_brightness = brightness;
- led_classdev_notify_brightness_hw_changed(
- &tpacpi_led_kbdlight.led_classdev, brightness);
- }
- }
+ if (tp_features.kbdlight)
+ kbdlight_notify_change();
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_DFR_CHANGE_ROW:
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-12-03 12:06 ` [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Qiling Zhu
@ 2026-12-03 12:07 ` Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves Qiling Zhu
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:07 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
A write to /proc/acpi/ibm/kbdlight writes the EC level and updates the
cached level under kbdlight_mutex, but then assigns led_cdev->brightness
directly after releasing the lock, without telling the LED core.
Commit 06da5325d02e ("platform/x86: thinkpad_acpi: Stop setting
led_classdev brightness directly") already removed this pattern from the
sysfs path but had to keep it for the proc interface, which has no LED
core path of its own.
Stop writing to that cache. kbdlight_set_level_and_update() now only
writes the EC level and updates the cached level, under kbdlight_mutex;
the sysfs path uses it, as a write that already goes through the LED core
does not need to be reported back to it. The proc write path instead
calls kbdlight_notify_level(), which updates the cached level and reports
the new one through brightness_hw_changed, like commit 07f48f668fac
("platform/x86: ideapad-laptop: add FnLock LED class device") did for
the ideapad FnLock LED.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
---
After a procfs write, led_cdev->brightness can retain its previous
value. This is acceptable:
- Reading the brightness attribute calls brightness_get(), which reads
the level back from the EC and refreshes the cache.
- At this point in the series, kbdlight_suspend() also refreshes the
cache before suspend, so led_classdev_resume() does not write a stale
value back.
- Software blinking may pick up the old value as its "on" level, as it
can after a Fn+Space change.
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 44 ++++++++++++---------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 3ef857542..80601ed2c 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5113,12 +5113,11 @@ static int kbdlight_set_level(int level)
if (!hkey_handle)
return -ENXIO;
- guard(mutex)(&kbdlight_mutex);
+ lockdep_assert_held(&kbdlight_mutex);
if (!acpi_evalf(hkey_handle, NULL, "MLCS", "dd", level))
return -EIO;
- kbdlight_brightness = level;
return 0;
}
@@ -5147,6 +5146,21 @@ static int kbdlight_level_to_brightness(int level)
return level;
}
+static int kbdlight_set_level_and_update(int level)
+{
+ int ret;
+
+ guard(mutex)(&kbdlight_mutex);
+
+ ret = kbdlight_set_level(level);
+ if (ret)
+ return ret;
+
+ kbdlight_brightness = level;
+
+ return 0;
+}
+
static bool kbdlight_is_supported(void)
{
int status = 0;
@@ -5195,7 +5209,7 @@ static bool kbdlight_is_supported(void)
static int kbdlight_sysfs_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
- return kbdlight_set_level(brightness);
+ return kbdlight_set_level_and_update(brightness);
}
static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
@@ -5253,20 +5267,6 @@ static void kbdlight_exit(void)
led_classdev_unregister(&tpacpi_led_kbdlight.led_classdev);
}
-static int kbdlight_set_level_and_update(int level)
-{
- int ret;
- struct led_classdev *led_cdev;
-
- ret = kbdlight_set_level(level);
- led_cdev = &tpacpi_led_kbdlight.led_classdev;
-
- if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED))
- led_cdev->brightness = level;
-
- return ret;
-}
-
static void kbdlight_notify_level(int level)
{
struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
@@ -5332,7 +5332,15 @@ static int kbdlight_write(char *buf)
if (level >= 3 || level < 0)
return -EINVAL;
- return kbdlight_set_level_and_update(level);
+ guard(mutex)(&kbdlight_mutex);
+
+ res = kbdlight_set_level(level);
+ if (res)
+ return res;
+
+ kbdlight_notify_level(level);
+
+ return 0;
}
static void kbdlight_suspend(void)
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
` (2 preceding siblings ...)
2026-12-03 12:07 ` [PATCH v6 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
@ 2026-12-03 12:07 ` Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:07 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
kbdlight_suspend() and kbdlight_resume() leave the keyboard backlight to
the LED core across sleep: the LED core caches the current brightness
and turns the backlight off on suspend, and writes that brightness back
on resume.
On a ThinkPad X1 Carbon Gen 14 with thinkpad_acpi unloaded, the firmware
turned the backlight off when entering both s2idle and hibernation.
After waking from s2idle the EC was back at its previous level, for each
of the four levels tested; after waking from hibernation it was at 0.
Drop kbdlight_suspend() and leave turning the backlight off to the
firmware. On resume, write the cached level back to the EC on all
models, instead of relying on the LED core: this brings the backlight
back where the firmware came up with it off, and changes nothing
where the EC already has that level. For this to hold for every
mode, have kbdlight_brightness track the EC level itself, 0 to 3,
rather than the brightness reported to the LED core, in which the auto
mode (level 3) shows up as 0. kbdlight_init() accordingly reads the
level from the EC instead of the brightness; the notify helpers already
work in terms of EC levels.
Only s2idle and S4 were available on the test machine; S3-capable
models were not tested.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 28 +++++++++------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 80601ed2c..764b1efa6 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5105,7 +5105,12 @@ static struct ibm_struct video_driver_data = {
/* EC level that selects the auto mode for the keyboard backlight */
#define TPACPI_KBD_LIGHT_AUTO_LEVEL 3
-static enum led_brightness kbdlight_brightness;
+/*
+ * Cached EC level, including TPACPI_KBD_LIGHT_AUTO_LEVEL. All state
+ * tracking compares EC levels; the auto mode is translated to a
+ * brightness value only when reporting to the LED core.
+ */
+static int kbdlight_brightness;
static DEFINE_MUTEX(kbdlight_mutex);
static int kbdlight_set_level(int level)
@@ -5247,7 +5252,10 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
return -ENODEV;
}
- kbdlight_brightness = kbdlight_sysfs_get(NULL);
+ kbdlight_brightness = kbdlight_get_level();
+ if (kbdlight_brightness < 0)
+ kbdlight_brightness = 0;
+
tp_features.kbdlight = 1;
rc = led_classdev_register(&tpacpi_pdev->dev,
@@ -5343,31 +5351,19 @@ static int kbdlight_write(char *buf)
return 0;
}
-static void kbdlight_suspend(void)
-{
- struct led_classdev *led_cdev;
-
- if (!tp_features.kbdlight)
- return;
-
- led_cdev = &tpacpi_led_kbdlight.led_classdev;
- led_update_brightness(led_cdev);
- led_classdev_suspend(led_cdev);
-}
-
static void kbdlight_resume(void)
{
if (!tp_features.kbdlight)
return;
- led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
+ guard(mutex)(&kbdlight_mutex);
+ kbdlight_set_level(kbdlight_brightness);
}
static struct ibm_struct kbdlight_driver_data = {
.name = "kbdlight",
.read = kbdlight_read,
.write = kbdlight_write,
- .suspend = kbdlight_suspend,
.resume = kbdlight_resume,
.exit = kbdlight_exit,
};
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
` (3 preceding siblings ...)
2026-12-03 12:07 ` [PATCH v6 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves Qiling Zhu
@ 2026-12-03 12:07 ` Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:07 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
MLCG bit 20 indicates whether the EC supports the auto mode of the
keyboard backlight (0 = manual levels only, 1 = auto mode available), as
defined by the firmware.
Record it in tp_features.kbdlight_auto, for use when registering the
auto-mode trigger in a subsequent change.
Link: https://lore.kernel.org/r/CABxCQKuEP5wMSstO0MK1MhaqXTKrPhUSN3V2mrE_42j4cXsXZQ@mail.gmail.com
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 764b1efa6..8f73f87e9 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -363,6 +363,7 @@ static struct {
TP_HOTKEY_TABLET_USES_GMMS,
} hotkey_tablet;
u32 kbdlight:1;
+ u32 kbdlight_auto:1;
u32 light:1;
u32 light_status:1;
u32 bright_acpimode:1;
@@ -5105,6 +5106,9 @@ static struct ibm_struct video_driver_data = {
/* EC level that selects the auto mode for the keyboard backlight */
#define TPACPI_KBD_LIGHT_AUTO_LEVEL 3
+/* MLCG bit that indicates whether the EC supports the auto mode */
+#define TPACPI_KBD_LIGHT_AUTO_CAPABLE_BIT BIT(20)
+
/*
* Cached EC level, including TPACPI_KBD_LIGHT_AUTO_LEVEL. All state
* tracking compares EC levels; the auto mode is translated to a
@@ -5189,6 +5193,9 @@ static bool kbdlight_is_supported(void)
}
vdbg_printk(TPACPI_DBG_INIT, "kbdlight MLCG returned 0x%x\n", status);
+
+ tp_features.kbdlight_auto = !!(status & TPACPI_KBD_LIGHT_AUTO_CAPABLE_BIT);
+
/*
* Guessed test for keyboard backlight:
*
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
` (4 preceding siblings ...)
2026-12-03 12:07 ` [PATCH v6 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
@ 2026-12-03 12:07 ` Qiling Zhu
5 siblings, 0 replies; 7+ messages in thread
From: Qiling Zhu @ 2026-12-03 12:07 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: platform-driver-x86, linux-kernel, ibm-acpi-devel, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, linux-leds, vishnuocv,
vsankar, Andrea Rabbaglietti
On ThinkPads that advertise the auto mode in MLCG bit 20, expose EC
level 3 as a private LED trigger named "tpacpi-kbd-auto". Select
LEDS_TRIGGERS so that the trigger is available in stripped-down
configurations. If registering the trigger fails, register the
keyboard backlight LED as before.
Activating the trigger writes EC level 3 and records it in the cached
level; whether the LED is hardware-controlled is derived from that
cached level, so reading brightness returns -ENODATA while the trigger
is active and the EC is in auto mode. If the EC is already in auto
mode when the driver loads, make the trigger the default one, to
reflect a selection made before the driver was loaded.
A sysfs brightness write leaves auto mode through the LED core's own
trigger removal. With CONFIG_LEDS_TRIGGERS_HW_CHANGED enabled, the LED
core also switches between "none" and the trigger in response to
Fn+Space, or to a procfs write that leaves auto mode.
Deliberately unchanged: max_brightness stays 2.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
---
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/thinkpad_acpi.c | 60 +++++++++++++++++++++
2 files changed, 61 insertions(+)
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index 516594993..77d159a3a 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -83,6 +83,7 @@ config THINKPAD_ACPI
select NVRAM
select NEW_LEDS
select LEDS_CLASS
+ select LEDS_TRIGGERS
select INPUT_SPARSEKMAP
help
This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 8f73f87e9..af53117d5 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5218,6 +5218,27 @@ static bool kbdlight_is_supported(void)
return status & BIT(9);
}
+static struct led_hw_trigger_type kbdlight_auto_trigger_type;
+
+static int kbdlight_auto_trigger_activate(struct led_classdev *led_cdev)
+{
+ return kbdlight_set_level_and_update(TPACPI_KBD_LIGHT_AUTO_LEVEL);
+}
+
+static bool kbdlight_auto_trigger_hw_offloaded(struct led_classdev *led_cdev)
+{
+ guard(mutex)(&kbdlight_mutex);
+
+ return kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL;
+}
+
+static struct led_trigger kbdlight_auto_trigger = {
+ .name = "tpacpi-kbd-auto",
+ .trigger_type = &kbdlight_auto_trigger_type,
+ .activate = kbdlight_auto_trigger_activate,
+ .hw_offloaded = kbdlight_auto_trigger_hw_offloaded,
+};
+
static int kbdlight_sysfs_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
@@ -5245,6 +5266,35 @@ static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
}
};
+static void __init kbdlight_init_auto_trigger(void)
+{
+ struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+ int rc;
+
+ rc = devm_led_trigger_register(&tpacpi_pdev->dev, &kbdlight_auto_trigger);
+ if (rc) {
+ /*
+ * Auto-mode trigger unavailable; basic backlight
+ * control keeps working.
+ */
+ dev_warn(&tpacpi_pdev->dev, "auto-mode trigger unavailable\n");
+ return;
+ }
+
+ led_cdev->flags |= LED_TRIG_HW_CHANGED;
+ led_cdev->trigger_type = &kbdlight_auto_trigger_type;
+ led_cdev->hw_control_trigger = kbdlight_auto_trigger.name;
+
+ /*
+ * The EC does not keep the level across boots, but it may already
+ * be in auto mode when the driver loads: Fn+Space works at the
+ * BIOS or disk-encryption prompt, and while the module is
+ * unloaded. Sync the initial trigger state with the EC then.
+ */
+ if (kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL)
+ led_cdev->default_trigger = kbdlight_auto_trigger.name;
+}
+
static int __init kbdlight_init(struct ibm_init_struct *iibm)
{
int rc;
@@ -5265,6 +5315,9 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
tp_features.kbdlight = 1;
+ if (tp_features.kbdlight_auto)
+ kbdlight_init_auto_trigger();
+
rc = led_classdev_register(&tpacpi_pdev->dev,
&tpacpi_led_kbdlight.led_classdev);
if (rc < 0) {
@@ -5285,6 +5338,7 @@ static void kbdlight_exit(void)
static void kbdlight_notify_level(int level)
{
struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+ bool was_auto, is_auto;
lockdep_assert_held(&kbdlight_mutex);
@@ -5295,6 +5349,12 @@ static void kbdlight_notify_level(int level)
if (level == kbdlight_brightness)
return;
+ was_auto = kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL;
+ is_auto = level == TPACPI_KBD_LIGHT_AUTO_LEVEL;
+
+ if (is_auto != was_auto && led_cdev->hw_control_trigger)
+ led_trigger_notify_hw_control_changed(led_cdev, is_auto);
+
kbdlight_brightness = level;
led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level));
}
--
2.56.1
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-03 12:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 12:06 [PATCH v6 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-12-03 12:06 ` [PATCH v6 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-12-03 12:07 ` [PATCH v6 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®