* [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 7:53 ` Rong Zhang
2026-11-14 17:48 ` [PATCH v3 2/7] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers Qiling Zhu
` (6 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
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: UPower 1.91.x treats the out-of-range value as
invalid and stops watching brightness_hw_changed altogether, so the desktop
stops following the Fn+Space hotkey once auto mode has been entered.
The auto mode is not a brightness level. Map it to 0, the value it is
reported as most of the time anyway, in line with what ideapad-laptop
already 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>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 4f81855ad..2c3f8cf32 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);
@@ -5191,7 +5194,8 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
int level;
level = kbdlight_get_level();
- if (level < 0)
+ /* Auto mode is not a brightness level; report it as off. */
+ if (level < 0 || level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
return 0;
return level;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off
2026-11-14 17:48 ` [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
@ 2026-11-15 7:53 ` Rong Zhang
2026-11-15 21:58 ` Mark Pearson
0 siblings, 1 reply; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 7:53 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> 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: UPower 1.91.x treats the out-of-range value as
> invalid and stops watching brightness_hw_changed altogether, so the desktop
> stops following the Fn+Space hotkey once auto mode has been entered.
>
> The auto mode is not a brightness level. Map it to 0, the value it is
> reported as most of the time anyway, in line with what ideapad-laptop
> already 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>
Thanks,
Rong
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 4f81855ad..2c3f8cf32 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);
>
> @@ -5191,7 +5194,8 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
> int level;
>
> level = kbdlight_get_level();
> - if (level < 0)
> + /* Auto mode is not a brightness level; report it as off. */
> + if (level < 0 || level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
> return 0;
>
> return level;
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off
2026-11-15 7:53 ` Rong Zhang
@ 2026-11-15 21:58 ` Mark Pearson
0 siblings, 0 replies; 32+ messages in thread
From: Mark Pearson @ 2026-11-15 21:58 UTC (permalink / raw)
To: Rong Zhang, Qiling Zhu, Derek J . Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, Vishnu Sankar, Vishnu Sankar,
platform-driver-x86@vger.kernel.org, ibm-acpi-devel, linux-leds,
linux-kernel
On Sun, Nov 15, 2026, at 2:53 AM, Rong Zhang wrote:
> Hi Qiling,
>
> On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
>> 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: UPower 1.91.x treats the out-of-range value as
>> invalid and stops watching brightness_hw_changed altogether, so the desktop
>> stops following the Fn+Space hotkey once auto mode has been entered.
>>
>> The auto mode is not a brightness level. Map it to 0, the value it is
>> reported as most of the time anyway, in line with what ideapad-laptop
>> already 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>
>
> Thanks,
> Rong
>
>> ---
>> drivers/platform/x86/lenovo/thinkpad_acpi.c | 6 +++++-
>> 1 file changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
>> index 4f81855ad..2c3f8cf32 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);
>>
>> @@ -5191,7 +5194,8 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
>> int level;
>>
>> level = kbdlight_get_level();
>> - if (level < 0)
>> + /* Auto mode is not a brightness level; report it as off. */
>> + if (level < 0 || level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
>> return 0;
>>
>> return level;
Looks good to me
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 2/7] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
2026-11-14 17:48 ` [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 7:53 ` Rong Zhang
2026-11-14 17:48 ` [PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes Qiling Zhu
` (5 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the EC
level, updates the cached brightness and notifies the LED core inline.
Extract this block into separate kbdlight_notify_level() and
kbdlight_notify_change() helpers, in preparation for reusing the former
when writing a level through the proc interface in a subsequent change.
kbdlight_notify_level() expects the caller to hold kbdlight_mutex;
kbdlight_notify_change() queries the EC and notifies under the same
mutex, like the original inline code did.
No functional change intended.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 40 +++++++++++++--------
1 file changed, 26 insertions(+), 14 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 2c3f8cf32..c8098f317 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5317,6 +5317,31 @@ static void kbdlight_resume(void)
led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
}
+/*
+ * Caller must hold kbdlight_mutex.
+ */
+static void kbdlight_notify_level(int level)
+{
+ struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+
+ /*
+ * Check the brightness actually changed, setting the brightness
+ * through kbdlight_set_level() also triggers this event.
+ */
+ if (level == kbdlight_brightness)
+ return;
+
+ kbdlight_brightness = level;
+ led_classdev_notify_brightness_hw_changed(led_cdev, level);
+}
+
+static void kbdlight_notify_change(void)
+{
+ guard(mutex)(&kbdlight_mutex);
+
+ kbdlight_notify_level(kbdlight_sysfs_get(NULL));
+}
+
static struct ibm_struct kbdlight_driver_data = {
.name = "kbdlight",
.read = kbdlight_read,
@@ -11586,20 +11611,7 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
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);
- }
+ kbdlight_notify_change();
}
/* Key events are suppressed by default hotkey_user_mask */
return false;
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 2/7] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers
2026-11-14 17:48 ` [PATCH v3 2/7] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers Qiling Zhu
@ 2026-11-15 7:53 ` Rong Zhang
0 siblings, 0 replies; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 7:53 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
You are extracting two helpers with different names. Let's retitle:
Extract kbdlight notify helpers
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the EC
> level, updates the cached brightness and notifies the LED core inline.
> Extract this block into separate kbdlight_notify_level() and
> kbdlight_notify_change() helpers, in preparation for reusing the former
> when writing a level through the proc interface in a subsequent change.
>
> kbdlight_notify_level() expects the caller to hold kbdlight_mutex;
> kbdlight_notify_change() queries the EC and notifies under the same
> mutex, like the original inline code did.
>
> No functional change intended.
>
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 40 +++++++++++++--------
> 1 file changed, 26 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 2c3f8cf32..c8098f317 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5317,6 +5317,31 @@ static void kbdlight_resume(void)
> led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
> }
>
> +/*
> + * Caller must hold kbdlight_mutex.
Annotate it with lockdep instead of comments.
> + */
> +static void kbdlight_notify_level(int level)
> +{
> + struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
> +
> + /*
> + * Check the brightness actually changed, setting the brightness
> + * through kbdlight_set_level() also triggers this event.
> + */
> + if (level == kbdlight_brightness)
> + return;
> +
> + kbdlight_brightness = level;
> + led_classdev_notify_brightness_hw_changed(led_cdev, level);
> +}
> +
> +static void kbdlight_notify_change(void)
> +{
> + guard(mutex)(&kbdlight_mutex);
> +
> + kbdlight_notify_level(kbdlight_sysfs_get(NULL));
> +}
> +
> static struct ibm_struct kbdlight_driver_data = {
> .name = "kbdlight",
> .read = kbdlight_read,
> @@ -11586,20 +11611,7 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
> 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);
> - }
> + kbdlight_notify_change();
> }
Remove the {}.
With them fixed,
Reviewed-by: Rong Zhang <i@rong.moe>
Thanks,
Rong
> /* Key events are suppressed by default hotkey_user_mask */
> return false;
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
2026-11-14 17:48 ` [PATCH v3 1/7] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-11-14 17:48 ` [PATCH v3 2/7] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 8:05 ` Rong Zhang
2026-11-14 17:48 ` [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
` (4 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
kbdlight_set_level_and_update() pokes the led_classdev brightness cache
directly after writing the new EC level, without notifying userspace and
without any locking. 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.
Move the LED core state update into kbdlight_notify_level(): stop
updating the cached level in kbdlight_set_level() and have both the
sysfs and the proc write paths go through kbdlight_set_level_and_update(),
which writes the EC level and updates the cache under kbdlight_mutex,
and reports the new level through the LED core, like commit
07f48f668fac ("platform/x86: ideapad-laptop: add FnLock LED class
device") did for the ideapad FnLock LED.
As a result, writing a level through either interface now emits a
brightness_hw_changed notification, so userspace listeners see level
changes from both of them.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 23 +++++++++++++--------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index c8098f317..657a19d11 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5108,17 +5108,17 @@ static struct ibm_struct video_driver_data = {
static enum led_brightness kbdlight_brightness;
static DEFINE_MUTEX(kbdlight_mutex);
+/*
+ * Caller must hold kbdlight_mutex.
+ */
static int kbdlight_set_level(int level)
{
if (!hkey_handle)
return -ENXIO;
- guard(mutex)(&kbdlight_mutex);
-
if (!acpi_evalf(hkey_handle, NULL, "MLCS", "dd", level))
return -EIO;
- kbdlight_brightness = level;
return 0;
}
@@ -5183,10 +5183,12 @@ static bool kbdlight_is_supported(void)
return status & BIT(9);
}
+static int kbdlight_set_level_and_update(int level);
+
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)
@@ -5245,18 +5247,21 @@ static void kbdlight_exit(void)
led_classdev_unregister(&tpacpi_led_kbdlight.led_classdev);
}
+static void kbdlight_notify_level(int level);
+
static int kbdlight_set_level_and_update(int level)
{
int ret;
- struct led_classdev *led_cdev;
+
+ guard(mutex)(&kbdlight_mutex);
ret = kbdlight_set_level(level);
- led_cdev = &tpacpi_led_kbdlight.led_classdev;
+ if (ret)
+ return ret;
- if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED))
- led_cdev->brightness = level;
+ kbdlight_notify_level(level);
- return ret;
+ return 0;
}
static int kbdlight_read(struct seq_file *m)
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes
2026-11-14 17:48 ` [PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes Qiling Zhu
@ 2026-11-15 8:05 ` Rong Zhang
0 siblings, 0 replies; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 8:05 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
The title is confusing. How about:
Don't poke keyboard backlight's LED core brightness
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> kbdlight_set_level_and_update() pokes the led_classdev brightness cache
> directly after writing the new EC level, without notifying userspace and
> without any locking. 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.
>
> Move the LED core state update into kbdlight_notify_level(): stop
> updating the cached level in kbdlight_set_level() and have both the
> sysfs and the proc write paths go through kbdlight_set_level_and_update(),
> which writes the EC level and updates the cache under kbdlight_mutex,
> and reports the new level through the LED core, like commit
> 07f48f668fac ("platform/x86: ideapad-laptop: add FnLock LED class
> device") did for the ideapad FnLock LED.
>
> As a result, writing a level through either interface now emits a
> brightness_hw_changed notification, so userspace listeners see level
> changes from both of them.
>
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Sashiko complains:
Does replacing the led_cdev->brightness update with
kbdlight_notify_level() leave tpacpi_led_kbdlight.led_classdev.brightness
stale after writes to /proc/acpi/ibm/kbdlight?
kbdlight_notify_level() calls
led_classdev_notify_brightness_hw_changed(), which only sets led_cdev-
>brightness_hw_changed and never updates led_cdev->brightness. When
kbdlight_write() changes the level via procfs, in-kernel consumers that
read led_cdev->brightness without calling led_update_brightness(), such
as led_set_software_blink(), will see the old brightness value.
IMO this is acceptable. Please add a section separated with `---' after
your Signed-off-by, explaining why this is acceptable.
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 23 +++++++++++++--------
> 1 file changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index c8098f317..657a19d11 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5108,17 +5108,17 @@ static struct ibm_struct video_driver_data = {
> static enum led_brightness kbdlight_brightness;
> static DEFINE_MUTEX(kbdlight_mutex);
>
> +/*
> + * Caller must hold kbdlight_mutex.
> + */
Annotate it with lockdep.
> static int kbdlight_set_level(int level)
> {
> if (!hkey_handle)
> return -ENXIO;
>
> - guard(mutex)(&kbdlight_mutex);
> -
> if (!acpi_evalf(hkey_handle, NULL, "MLCS", "dd", level))
> return -EIO;
>
> - kbdlight_brightness = level;
> return 0;
> }
>
> @@ -5183,10 +5183,12 @@ static bool kbdlight_is_supported(void)
> return status & BIT(9);
> }
>
> +static int kbdlight_set_level_and_update(int level);
The function is modified a lot. Let's simply move it.
> +
> 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)
> @@ -5245,18 +5247,21 @@ static void kbdlight_exit(void)
> led_classdev_unregister(&tpacpi_led_kbdlight.led_classdev);
> }
>
> +static void kbdlight_notify_level(int level);
What not add it to the right position in PATCH 2?
> +
> static int kbdlight_set_level_and_update(int level)
> {
> int ret;
> - struct led_classdev *led_cdev;
> +
> + guard(mutex)(&kbdlight_mutex);
>
> ret = kbdlight_set_level(level);
> - led_cdev = &tpacpi_led_kbdlight.led_classdev;
> + if (ret)
> + return ret;
>
> - if (ret == 0 && !(led_cdev->flags & LED_SUSPENDED))
> - led_cdev->brightness = level;
> + kbdlight_notify_level(level);
Nah. I didn't mean this. We only want to notify brightness_hw_changed on
procfs kbdlight writes, but you are notifying it on sysfs LEDs writes.
Please call kbdlight_notify_level() in kbdlight_write() instead of
messing up with this function.
This function should only update kbdlight_brightness (when
!LED_SUSPENDED).
Thanks,
Rong
>
> - return ret;
> + return 0;
> }
>
> static int kbdlight_read(struct seq_file *m)
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
` (2 preceding siblings ...)
2026-11-14 17:48 ` [PATCH v3 3/7] platform/x86: thinkpad_acpi: Sync LED core state on level writes Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 8:05 ` Rong Zhang
2026-11-15 22:06 ` Mark Pearson
2026-11-14 17:48 ` [PATCH v3 5/7] platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines Qiling Zhu
` (3 subsequent siblings)
7 siblings, 2 replies; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
The upper bits of the MLCG return value carry capability information.
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, in preparation for using it to
gate the auto-mode trigger registration and the LED suspend/resume
skipping in subsequent changes.
Link: https://lore.kernel.org/r/CABxCQKuEP5wMSstO0MK1MhaqXTKrPhUSN3V2mrE_42j4cXsXZQ@mail.gmail.com
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 657a19d11..681b340a1 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;
@@ -5161,6 +5162,13 @@ static bool kbdlight_is_supported(void)
}
vdbg_printk(TPACPI_DBG_INIT, "kbdlight MLCG returned 0x%x\n", status);
+
+ /*
+ * MLCG bit 20 indicates auto mode support: 0 = manual levels only,
+ * 1 = auto mode available (per the firmware definition).
+ */
+ tp_features.kbdlight_auto = !!(status & BIT(20));
+
/*
* Guessed test for keyboard backlight:
*
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
2026-11-14 17:48 ` [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
@ 2026-11-15 8:05 ` Rong Zhang
2026-11-15 22:06 ` Mark Pearson
1 sibling, 0 replies; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 8:05 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> The upper bits of the MLCG return value carry capability information.
> 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, in preparation for using it to
> gate the auto-mode trigger registration and the LED suspend/resume
> skipping in subsequent changes.
>
> Link: https://lore.kernel.org/r/CABxCQKuEP5wMSstO0MK1MhaqXTKrPhUSN3V2mrE_42j4cXsXZQ@mail.gmail.com
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 657a19d11..681b340a1 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;
> @@ -5161,6 +5162,13 @@ static bool kbdlight_is_supported(void)
> }
>
> vdbg_printk(TPACPI_DBG_INIT, "kbdlight MLCG returned 0x%x\n", status);
> +
> + /*
> + * MLCG bit 20 indicates auto mode support: 0 = manual levels only,
> + * 1 = auto mode available (per the firmware definition).
> + */
> + tp_features.kbdlight_auto = !!(status & BIT(20));
Add a symbolic macro for 20.
With it fixed,
Reviewed-by: Rong Zhang <i@rong.moe>
Thanks,
Rong
> +
> /*
> * Guessed test for keyboard backlight:
> *
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
2026-11-14 17:48 ` [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-11-15 8:05 ` Rong Zhang
@ 2026-11-15 22:06 ` Mark Pearson
1 sibling, 0 replies; 32+ messages in thread
From: Mark Pearson @ 2026-11-15 22:06 UTC (permalink / raw)
To: Qiling Zhu, Derek J . Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, Vishnu Sankar, Vishnu Sankar,
platform-driver-x86@vger.kernel.org, ibm-acpi-devel, linux-leds,
linux-kernel
On Sat, Nov 14, 2026, at 12:48 PM, Qiling Zhu wrote:
> The upper bits of the MLCG return value carry capability information.
> 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, in preparation for using it to
> gate the auto-mode trigger registration and the LED suspend/resume
> skipping in subsequent changes.
>
> Link:
> https://lore.kernel.org/r/CABxCQKuEP5wMSstO0MK1MhaqXTKrPhUSN3V2mrE_42j4cXsXZQ@mail.gmail.com
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 657a19d11..681b340a1 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;
> @@ -5161,6 +5162,13 @@ static bool kbdlight_is_supported(void)
> }
>
> vdbg_printk(TPACPI_DBG_INIT, "kbdlight MLCG returned 0x%x\n", status);
> +
> + /*
> + * MLCG bit 20 indicates auto mode support: 0 = manual levels only,
> + * 1 = auto mode available (per the firmware definition).
> + */
> + tp_features.kbdlight_auto = !!(status & BIT(20));
> +
> /*
> * Guessed test for keyboard backlight:
> *
> --
> 2.56.1
Looks good to me.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 5/7] platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
` (3 preceding siblings ...)
2026-11-14 17:48 ` [PATCH v3 4/7] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 22:08 ` Mark Pearson
2026-11-14 17:48 ` [PATCH v3 6/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Qiling Zhu
` (2 subsequent siblings)
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
On machines whose EC supports the auto mode (MLCG bit 20) the firmware
takes care of the keyboard backlight across suspend by itself: on a
ThinkPad X1 Carbon Gen 14 it turns the backlight off on suspend and
restores the previous level on resume for the manual levels, and keeps
auto mode across suspend; after hibernation from auto mode the
backlight comes back off.
Skip led_classdev_suspend() and led_classdev_resume() entirely on those
machines: the LED core no longer enters the suspended state, which also
removes the window in which userspace writes and pending
set_brightness work would race against a suspended LED.
Machines without auto-mode support keep the existing behavior.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 681b340a1..f9e2d324d 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5317,6 +5317,14 @@ static void kbdlight_suspend(void)
if (!tp_features.kbdlight)
return;
+ /*
+ * On machines with auto-mode support the firmware takes care of
+ * the keyboard backlight across suspend by itself; keep the LED
+ * core out of it.
+ */
+ if (tp_features.kbdlight_auto)
+ return;
+
led_cdev = &tpacpi_led_kbdlight.led_classdev;
led_update_brightness(led_cdev);
led_classdev_suspend(led_cdev);
@@ -5327,6 +5335,9 @@ static void kbdlight_resume(void)
if (!tp_features.kbdlight)
return;
+ if (tp_features.kbdlight_auto)
+ return;
+
led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 5/7] platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines
2026-11-14 17:48 ` [PATCH v3 5/7] platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines Qiling Zhu
@ 2026-11-15 22:08 ` Mark Pearson
0 siblings, 0 replies; 32+ messages in thread
From: Mark Pearson @ 2026-11-15 22:08 UTC (permalink / raw)
To: Qiling Zhu, Derek J . Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, Vishnu Sankar, Vishnu Sankar,
platform-driver-x86@vger.kernel.org, ibm-acpi-devel, linux-leds,
linux-kernel
On Sat, Nov 14, 2026, at 12:48 PM, Qiling Zhu wrote:
> On machines whose EC supports the auto mode (MLCG bit 20) the firmware
> takes care of the keyboard backlight across suspend by itself: on a
> ThinkPad X1 Carbon Gen 14 it turns the backlight off on suspend and
> restores the previous level on resume for the manual levels, and keeps
> auto mode across suspend; after hibernation from auto mode the
> backlight comes back off.
>
> Skip led_classdev_suspend() and led_classdev_resume() entirely on those
> machines: the LED core no longer enters the suspended state, which also
> removes the window in which userspace writes and pending
> set_brightness work would race against a suspended LED.
>
> Machines without auto-mode support keep the existing behavior.
>
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index 681b340a1..f9e2d324d 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5317,6 +5317,14 @@ static void kbdlight_suspend(void)
> if (!tp_features.kbdlight)
> return;
>
> + /*
> + * On machines with auto-mode support the firmware takes care of
> + * the keyboard backlight across suspend by itself; keep the LED
> + * core out of it.
> + */
> + if (tp_features.kbdlight_auto)
> + return;
> +
> led_cdev = &tpacpi_led_kbdlight.led_classdev;
> led_update_brightness(led_cdev);
> led_classdev_suspend(led_cdev);
> @@ -5327,6 +5335,9 @@ static void kbdlight_resume(void)
> if (!tp_features.kbdlight)
> return;
>
> + if (tp_features.kbdlight_auto)
> + return;
> +
> led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
> }
>
> --
> 2.56.1
Looks good to me.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Mark
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 6/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
` (4 preceding siblings ...)
2026-11-14 17:48 ` [PATCH v3 5/7] platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 8:17 ` Rong Zhang
2026-11-14 17:48 ` [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume Qiling Zhu
2026-11-15 7:52 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Rong Zhang
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
Wire the EC keyboard backlight auto mode (level 3) up as a private
hardware control trigger, named "tpacpi-kbd-auto", on top of the LED
hw control trigger framework. On machines that support auto mode
(MLCG bit 20) the trigger is registered and set as the LED's trigger
type.
Selecting the trigger switches the backlight to auto mode; the
offloaded state is derived from the cached EC level. When Fn+Space
cycles into or out of auto mode, the driver notifies the trigger core,
so the trigger state shown in the trigger sysfs attribute follows
hardware-initiated transitions. If the EC is already in auto mode at
driver initialization, the trigger is set as the default one. Writing
a regular level through either sysfs or proc leaves auto mode, and the
trigger is dropped by the LED core.
Registering the trigger is allowed to fail; basic backlight control
keeps working in that case.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/Kconfig | 1 +
drivers/platform/x86/lenovo/thinkpad_acpi.c | 95 +++++++++++++++++++--
2 files changed, 89 insertions(+), 7 deletions(-)
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 f9e2d324d..f11e61417 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5106,7 +5106,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);
/*
@@ -5191,6 +5196,38 @@ static bool kbdlight_is_supported(void)
return status & BIT(9);
}
+static struct led_hw_trigger_type kbdlight_auto_trigger_type;
+
+static enum led_brightness 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 int kbdlight_auto_trigger_activate(struct led_classdev *led_cdev)
+{
+ guard(mutex)(&kbdlight_mutex);
+
+ return kbdlight_set_level(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_set_level_and_update(int level);
static int kbdlight_sysfs_set(struct led_classdev *led_cdev,
@@ -5204,11 +5241,11 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
int level;
level = kbdlight_get_level();
- /* Auto mode is not a brightness level; report it as off. */
- if (level < 0 || level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
+
+ if (level < 0)
return 0;
- return level;
+ return kbdlight_level_to_brightness(level);
}
static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
@@ -5235,9 +5272,37 @@ 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;
+ if (tp_features.kbdlight_auto) {
+ 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");
+ } else {
+ struct led_classdev *led_cdev =
+ &tpacpi_led_kbdlight.led_classdev;
+
+ led_cdev->flags |= LED_TRIG_HW_CHANGED;
+ led_cdev->trigger_type = &kbdlight_auto_trigger_type;
+ led_cdev->hw_control_trigger =
+ kbdlight_auto_trigger.name;
+
+ if (kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL)
+ led_cdev->default_trigger =
+ kbdlight_auto_trigger.name;
+ }
+ }
+
rc = led_classdev_register(&tpacpi_pdev->dev,
&tpacpi_led_kbdlight.led_classdev);
if (rc < 0) {
@@ -5347,6 +5412,8 @@ static void kbdlight_resume(void)
static void kbdlight_notify_level(int level)
{
struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+ bool is_auto, was_auto;
+ int brightness;
/*
* Check the brightness actually changed, setting the brightness
@@ -5355,15 +5422,29 @@ static void kbdlight_notify_level(int level)
if (level == kbdlight_brightness)
return;
+ is_auto = level == TPACPI_KBD_LIGHT_AUTO_LEVEL;
+ was_auto = kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL;
+
+ if (is_auto != was_auto)
+ led_trigger_notify_hw_control_changed(led_cdev, is_auto);
+
kbdlight_brightness = level;
- led_classdev_notify_brightness_hw_changed(led_cdev, level);
+ brightness = kbdlight_level_to_brightness(level);
+
+ led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
}
static void kbdlight_notify_change(void)
{
+ int level;
+
guard(mutex)(&kbdlight_mutex);
- kbdlight_notify_level(kbdlight_sysfs_get(NULL));
+ level = kbdlight_get_level();
+ if (level < 0)
+ return;
+
+ kbdlight_notify_level(level);
}
static struct ibm_struct kbdlight_driver_data = {
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 6/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
2026-11-14 17:48 ` [PATCH v3 6/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Qiling Zhu
@ 2026-11-15 8:17 ` Rong Zhang
0 siblings, 0 replies; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 8:17 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> Wire the EC keyboard backlight auto mode (level 3) up as a private
> hardware control trigger, named "tpacpi-kbd-auto", on top of the LED
> hw control trigger framework. On machines that support auto mode
> (MLCG bit 20) the trigger is registered and set as the LED's trigger
> type.
>
> Selecting the trigger switches the backlight to auto mode; the
> offloaded state is derived from the cached EC level. When Fn+Space
> cycles into or out of auto mode, the driver notifies the trigger core,
> so the trigger state shown in the trigger sysfs attribute follows
> hardware-initiated transitions. If the EC is already in auto mode at
> driver initialization, the trigger is set as the default one. Writing
> a regular level through either sysfs or proc leaves auto mode, and the
> trigger is dropped by the LED core.
>
> Registering the trigger is allowed to fail; basic backlight control
> keeps working in that case.
>
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/Kconfig | 1 +
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 95 +++++++++++++++++++--
> 2 files changed, 89 insertions(+), 7 deletions(-)
>
> 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 f9e2d324d..f11e61417 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5106,7 +5106,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);
>
> /*
> @@ -5191,6 +5196,38 @@ static bool kbdlight_is_supported(void)
> return status & BIT(9);
> }
>
> +static struct led_hw_trigger_type kbdlight_auto_trigger_type;
> +
> +static enum led_brightness 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;
> +}
Please move the helper to PATCH 1 and use it there.
Meanwhile, the return type can be int.
> +
> +static int kbdlight_auto_trigger_activate(struct led_classdev *led_cdev)
> +{
> + guard(mutex)(&kbdlight_mutex);
> +
> + return kbdlight_set_level(TPACPI_KBD_LIGHT_AUTO_LEVEL);
This does not update kbdlight_brightness. See also my reply to PATCH 3.
> +}
> +
> +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_set_level_and_update(int level);
>
> static int kbdlight_sysfs_set(struct led_classdev *led_cdev,
> @@ -5204,11 +5241,11 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
> int level;
>
> level = kbdlight_get_level();
> - /* Auto mode is not a brightness level; report it as off. */
> - if (level < 0 || level == TPACPI_KBD_LIGHT_AUTO_LEVEL)
> +
> + if (level < 0)
> return 0;
>
> - return level;
> + return kbdlight_level_to_brightness(level);
What a back-and-forth change! That's why you should really move
kbdlight_level_to_brightness() to PATCH 1 and use it there.
> }
>
> static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
> @@ -5235,9 +5272,37 @@ 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;
>
> + if (tp_features.kbdlight_auto) {
> + 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");
> + } else {
> + struct led_classdev *led_cdev =
> + &tpacpi_led_kbdlight.led_classdev;
> +
> + led_cdev->flags |= LED_TRIG_HW_CHANGED;
> + led_cdev->trigger_type = &kbdlight_auto_trigger_type;
> + led_cdev->hw_control_trigger =
> + kbdlight_auto_trigger.name;
> +
> + if (kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL)
If it can't preserve across hibernation, how can it preserve across
boots?
If it does preserve, you'll need to take extra care to prevent the LED
core from resetting it on exit, or else this is always a no-op. Note that
setting LED_RETAIN_AT_SHUTDOWN is not sufficient as the teardown routine
of hw control trigger emits LED_OFF.
I am also thinking about enhancing the LED core to properly handle
LED_RETAIN_AT_SHUTDOWN for hw control trigger. That being said, please go
ahead without my enhancement in this cycle by implementing a similar
mechanism like ideapad-laptop, as cross-subsystem coordination takes much
more time.
> + led_cdev->default_trigger =
> + kbdlight_auto_trigger.name;
Lines can go up to 100 characters.
> + }
> + }
Add a helper function to reduce indentation and improve readability.
> +
> rc = led_classdev_register(&tpacpi_pdev->dev,
> &tpacpi_led_kbdlight.led_classdev);
> if (rc < 0) {
> @@ -5347,6 +5412,8 @@ static void kbdlight_resume(void)
> static void kbdlight_notify_level(int level)
> {
> struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
> + bool is_auto, was_auto;
> + int brightness;
>
> /*
> * Check the brightness actually changed, setting the brightness
> @@ -5355,15 +5422,29 @@ static void kbdlight_notify_level(int level)
> if (level == kbdlight_brightness)
> return;
>
> + is_auto = level == TPACPI_KBD_LIGHT_AUTO_LEVEL;
> + was_auto = kbdlight_brightness == TPACPI_KBD_LIGHT_AUTO_LEVEL;
> +
> + if (is_auto != was_auto)
> + led_trigger_notify_hw_control_changed(led_cdev, is_auto);
Skip when trigger registration has failed.
> +
> kbdlight_brightness = level;
> - led_classdev_notify_brightness_hw_changed(led_cdev, level);
> + brightness = kbdlight_level_to_brightness(level);
Let's inline it into the next line.
Thanks,
Rong
> +
> + led_classdev_notify_brightness_hw_changed(led_cdev, brightness);
> }
>
> static void kbdlight_notify_change(void)
> {
> + int level;
> +
> guard(mutex)(&kbdlight_mutex);
>
> - kbdlight_notify_level(kbdlight_sysfs_get(NULL));
> + level = kbdlight_get_level();
> + if (level < 0)
> + return;
> +
> + kbdlight_notify_level(level);
> }
>
> static struct ibm_struct kbdlight_driver_data = {
^ permalink raw reply [flat|nested] 32+ messages in thread
* [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
` (5 preceding siblings ...)
2026-11-14 17:48 ` [PATCH v3 6/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Qiling Zhu
@ 2026-11-14 17:48 ` Qiling Zhu
2026-11-15 8:20 ` Rong Zhang
2026-11-15 7:52 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Rong Zhang
7 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-14 17:48 UTC (permalink / raw)
To: Mark Pearson, Derek J. Clark, Rong Zhang, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel, Qiling Zhu
The firmware does not always restore the keyboard backlight level across
sleep: after hibernation from auto mode the EC comes back with the
backlight off, without emitting a notification. The cached level and a
possibly still-active auto trigger then desynchronize from the hardware
until the next user action.
Check the EC level on resume on auto-mode machines and route it through
the regular notification path, which also deactivates the auto trigger
if the firmware left auto mode.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index f11e61417..802e0d53b 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5395,13 +5395,22 @@ static void kbdlight_suspend(void)
led_classdev_suspend(led_cdev);
}
+static void kbdlight_notify_change(void);
+
static void kbdlight_resume(void)
{
if (!tp_features.kbdlight)
return;
- if (tp_features.kbdlight_auto)
+ if (tp_features.kbdlight_auto) {
+ /*
+ * The firmware may not restore auto mode: after hibernation
+ * from level 3 it comes back with the backlight off. Check
+ * the EC level and reconcile.
+ */
+ kbdlight_notify_change();
return;
+ }
led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
}
--
2.56.1
^ permalink raw reply related [flat|nested] 32+ messages in thread* Re: [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume
2026-11-14 17:48 ` [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume Qiling Zhu
@ 2026-11-15 8:20 ` Rong Zhang
2026-11-15 22:11 ` Mark Pearson
0 siblings, 1 reply; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 8:20 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> The firmware does not always restore the keyboard backlight level across
> sleep: after hibernation from auto mode the EC comes back with the
> backlight off, without emitting a notification. The cached level and a
> possibly still-active auto trigger then desynchronize from the hardware
> until the next user action.
>
> Check the EC level on resume on auto-mode machines and route it through
> the regular notification path, which also deactivates the auto trigger
> if the firmware left auto mode.
>
> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
> ---
> drivers/platform/x86/lenovo/thinkpad_acpi.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> index f11e61417..802e0d53b 100644
> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
> @@ -5395,13 +5395,22 @@ static void kbdlight_suspend(void)
> led_classdev_suspend(led_cdev);
> }
>
> +static void kbdlight_notify_change(void);
Nooooo. Add it to the right position in PATCH 2.
> +
> static void kbdlight_resume(void)
> {
> if (!tp_features.kbdlight)
> return;
>
> - if (tp_features.kbdlight_auto)
> + if (tp_features.kbdlight_auto) {
> + /*
> + * The firmware may not restore auto mode: after hibernation
> + * from level 3 it comes back with the backlight off. Check
> + * the EC level and reconcile.
> + */
> + kbdlight_notify_change();
If the LED core doesn't detach the trigger before hibernation, please
restore the last hw brightness instead of notifying any change.
If using led_classdev_{suspend,resume}() causes pain when it comes to hw
control trigger, we can get rid of them completely (i.e., on all models)
by tracking the suspend status and restoring hw brightness properly
ourselves. With your previous changes to kbdlight_brightness, doing so
should be easy.
I am also thinking about enhancing the LED core to properly handle hw
control trigger on resume. As said in my reply to PATCH 6, please go
ahead without my enhancement in this cycle.
Thanks,
Rong
> return;
> + }
>
> led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
> }
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume
2026-11-15 8:20 ` Rong Zhang
@ 2026-11-15 22:11 ` Mark Pearson
0 siblings, 0 replies; 32+ messages in thread
From: Mark Pearson @ 2026-11-15 22:11 UTC (permalink / raw)
To: Rong Zhang, Qiling Zhu, Derek J . Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, Vishnu Sankar, Vishnu Sankar,
platform-driver-x86@vger.kernel.org, ibm-acpi-devel, linux-leds,
linux-kernel
On Sun, Nov 15, 2026, at 3:20 AM, Rong Zhang wrote:
> Hi Qiling,
>
> On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
>> The firmware does not always restore the keyboard backlight level across
>> sleep: after hibernation from auto mode the EC comes back with the
>> backlight off, without emitting a notification. The cached level and a
>> possibly still-active auto trigger then desynchronize from the hardware
>> until the next user action.
>>
>> Check the EC level on resume on auto-mode machines and route it through
>> the regular notification path, which also deactivates the auto trigger
>> if the firmware left auto mode.
>>
>> Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
>> ---
>> drivers/platform/x86/lenovo/thinkpad_acpi.c | 11 ++++++++++-
>> 1 file changed, 10 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
>> index f11e61417..802e0d53b 100644
>> --- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
>> +++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
>> @@ -5395,13 +5395,22 @@ static void kbdlight_suspend(void)
>> led_classdev_suspend(led_cdev);
>> }
>>
>> +static void kbdlight_notify_change(void);
>
> Nooooo. Add it to the right position in PATCH 2.
>
>> +
>> static void kbdlight_resume(void)
>> {
>> if (!tp_features.kbdlight)
>> return;
>>
>> - if (tp_features.kbdlight_auto)
>> + if (tp_features.kbdlight_auto) {
>> + /*
>> + * The firmware may not restore auto mode: after hibernation
>> + * from level 3 it comes back with the backlight off. Check
>> + * the EC level and reconcile.
>> + */
>> + kbdlight_notify_change();
>
> If the LED core doesn't detach the trigger before hibernation, please
> restore the last hw brightness instead of notifying any change.
>
> If using led_classdev_{suspend,resume}() causes pain when it comes to hw
> control trigger, we can get rid of them completely (i.e., on all models)
> by tracking the suspend status and restoring hw brightness properly
> ourselves. With your previous changes to kbdlight_brightness, doing so
> should be easy.
>
I was wondering the same. I can bet we'll end up with FW 'bugs' where some platforms don't put it back as they should.
I'll get those fixed whenever possible....but I'm thinking maybe if we just check/set in SW anyway that's not a bad thing.
Mark
^ permalink raw reply [flat|nested] 32+ messages in thread
* Re: [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
2026-11-14 17:48 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: " Qiling Zhu
` (6 preceding siblings ...)
2026-11-14 17:48 ` [PATCH v3 7/7] platform/x86: thinkpad_acpi: Reconcile EC level on resume Qiling Zhu
@ 2026-11-15 7:52 ` Rong Zhang
2026-11-18 11:02 ` Qiling Zhu
7 siblings, 1 reply; 32+ messages in thread
From: Rong Zhang @ 2026-11-15 7:52 UTC (permalink / raw)
To: Qiling Zhu, Mark Pearson, Derek J. Clark, Hans de Goede,
Ilpo Järvinen, Henrique de Moraes Holschuh
Cc: Andrea Rabbaglietti, Lee Jones, Pavel Machek,
Griffin Kroah-Hartman, vishnuocv, vsankar, platform-driver-x86,
ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
Thanks for working on this.
On Sun, 2026-11-15 at 01:48 +0800, Qiling Zhu wrote:
> Hi all,
>
> Thanks, Rong, for the two rounds of detailed review, Vishnu and Mark
> for the firmware-side answers, and Andrea for the bug report that
> became the first patch. This v3 addresses the feedback in full; the
> series grew from two to seven patches to pick up the suggested
> structure and to make the fixes independently backportable.
The next time when you send a series (i.e., PATCH x/n, n > 1), please do
not reply to the previous thread to keep it tidy.
>
> The series in short:
>
> 1/7 Report auto mode as brightness 0 instead of 3 (stable fix)
> 2/7 Extract kbdlight_notify_change() helpers (refactor)
> 3/7 Sync LED core state on level writes (write-path sync)
> 4/7 Detect auto-mode capability via MLCG bit 20 (groundwork)
> 5/7 Skip LED suspend/resume on auto-mode machines
> 6/7 Add support for auto keyboard backlight (the feature)
> 7/7 Reconcile EC level on resume
>
> Changes since v2, by comment:
>
> * The notification path is now split as suggested: a helper that accepts
> a level and a wrapper that queries the EC (2/7), and the proc write
> path goes through it (3/7), like commit 07f48f668fac did for the
> ideapad FnLock LED. The manual check-then-act trigger removal is gone
> entirely; leaving auto mode through either interface now drops the
> trigger through the LED core.
>
> * LED suspend/resume is skipped entirely on machines that support auto
> mode, keyed on the capability bit rather than the current level (5/7),
> as suggested. My testing confirms the firmware restores the previous
> level on its own in all cases except auto mode across hibernation;
> less state remains in the driver, and the class of races around
> LED_SUSPENDED disappears.
>
> * activate() is now a one-liner with no read-back verification (6/7);
> it only writes the level, using the plain set helper. I did not use
> the updating wrapper there on purpose: the trigger core is in the
> middle of its own activation flow at that point, and the 0x1012 event
> that follows the level change is expected to bring the state back in
> sync through the regular notify path.
>
> * Trigger registration is gated on MLCG bit 20 as per Vishnu's
> confirmation (4/7 + 6/7).
>
> * Andrea's report is fixed by 1/7, which reports auto mode as 0 to the
> LED classdev and is marked for stable. It is deliberately minimal -
> a single check, no further splitting - to keep backporting easy.
>
> * On the proc attribute deprecation: I support the idea, deferring to
> the thinkpad_acpi maintainers.
>
> One addition that was not in v2: testing showed that the firmware does
> not restore auto mode across hibernation
>
How about s2idle? And what if hw brightness = [0,2] before hibernation?
Meanwhile, could you test s2idle, hibernation and cold boots with
thinkpad_acpi blacklisted to see if hw brightness ([0,2] and 3) is
preserved? We need the raw behavior to determine our strategy.
> - the EC comes back with the
> backlight off, without an event. Rather than re-attaching the trigger
> from the pre-suspend state,
>
"re-attaching"
I am not familiar with hibernation, so I am not sure if the LED core
would detach the trigger before entering hibernation. If not, why did you
say that?
Thanks,
Rong
> 7/7 simply re-reads the EC level on resume
> and routes it through the regular notification path. If the firmware
> exits auto mode across hibernation, the driver simply reflects the
> resulting EC state rather than restoring the previous mode: it stays
> out of the firmware's way and only synchronizes, which keeps the code
> simple. Happy to hear opinions.
>
> A few notes on the result:
>
> * Writing a level through either interface now also emits
> brightness_hw_changed: both write paths share the same notify helper,
> which keeps the LED core and userspace listeners consistent with the
> new level no matter which interface was used. Rewriting the current
> level emits nothing, matching the firmware's own
> no-event-on-same-level semantics. Extending the notification to
> userspace-initiated changes seemed reasonable to me - the OSD then
> also reflects echo-based changes - but I'm happy to restrict it to
> hardware-initiated transitions if that is considered the better
> semantics.
>
> * All state transitions now run under kbdlight_mutex in single
> critical sections (query + reconcile, write + reconcile), with the
> set and notify helpers expecting the caller to hold it. On the
> ordering with the LED core's trigger_lock, my reasoning is that the
> trigger callbacks (activate, hw_offloaded) are reached with
> trigger_lock held and then take kbdlight_mutex, while the
> notification helper is lock-free (it only queues the worker), so I
> don't see a reverse nesting. Extra eyes on this are welcome.
>
> * The cached level is now the raw EC level including auto mode, so the
> kbdlight_brightness name has drifted a bit from what it holds.
> Renaming it would touch quite a few places; I left it as is for now
> and can do the rename as a follow-up if preferred.
>
> One open question, mainly for Mark and Vishnu: the skip of LED
> suspend/resume assumes the firmware turns the backlight off on suspend
> and restores it on resume on all auto-mode capable machines, which is
> what I observed here for manual levels (suspend and hibernation), auto
> across suspend, and auto across hibernation coming back off. My belief
> is that most machines handle this fine, but more testing on other
> models or a look at the EC documentation from the Lenovo side would be
> needed to be sure; if an exception turns up, a DMI quirk could restore
> the old path for that machine.
>
> Tested on my ThinkPad X1 Carbon Gen 14 (linux-next next-20261030).
>
> I'm still learning the ways of upstream; thank you all for your time
> and reviews, and any further comments are most welcome.
>
> This series was developed with LLM assistance; I reviewed every design
> decision against the framework sources and validated the behavior on
> real hardware myself.
>
> Regards,
> Qiling Zhu
>
> Qiling Zhu (7):
> platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off
> platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helpers
> platform/x86: thinkpad_acpi: Sync LED core state on level writes
> platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG
> platform/x86: thinkpad_acpi: Skip LED suspend/resume on auto-mode machines
> platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
> platform/x86: thinkpad_acpi: Reconcile EC level on resume
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
2026-11-15 7:52 ` [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Rong Zhang
@ 2026-11-18 11:02 ` Qiling Zhu
2026-11-19 14:21 ` Rong Zhang
0 siblings, 1 reply; 32+ messages in thread
From: Qiling Zhu @ 2026-11-18 11:02 UTC (permalink / raw)
To: Rong Zhang
Cc: Mark Pearson, Derek J. Clark, Hans de Goede, Ilpo Järvinen,
Henrique de Moraes Holschuh, Andrea Rabbaglietti, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, vishnuocv, vsankar,
platform-driver-x86, ibm-acpi-devel, linux-leds, linux-kernel
Hi Rong, Mark,
On Sun, Nov 15, 2026 at 03:52:36PM +0800, Rong Zhang wrote:
> The next time when you send a series (i.e., PATCH x/n, n > 1), please do
> not reply to the previous thread to keep it tidy.
First, my apologies for sending v3 as a reply to the v2 thread. I caught
that mistake shortly after sending it out, and I will make sure v4 starts
a clean thread. Please do let me know if I am getting anything else wrong
with the workflow; I am still learning the process and really appreciate
your guidance.
Thank you both for the reviews, Rong for another patient and detailed
round, and Mark for the Reviewed-by tags and the sleep/wake input. I will
apply all the requested changes in v4 (including moving
kbdlight_level_to_brightness() with an int return type into 1/7, adding
the lockdep annotations and symbolic macro, fixing the helper placements
and indentation, updating kbdlight_brightness in
kbdlight_set_level_and_update() and using it in
kbdlight_auto_trigger_activate(), and adding the note below '---' for
Sashiko's report).
> > One addition that was not in v2: testing showed that the firmware does
> > not restore auto mode across hibernation
>
> How about s2idle? And what if hw brightness = [0,2] before hibernation?
>
> Meanwhile, could you test s2idle, hibernation and cold boots with
> thinkpad_acpi blacklisted to see if hw brightness ([0,2] and 3) is
> preserved? We need the raw behavior to determine our strategy.
Here is the raw hardware behavior data you asked for.
Test setup:
- Machine: ThinkPad X1 Carbon Gen 14 (21V8A028CD), BIOS N4OET53W (1.16),
EC N4OHT42W.
- Kernels: 7.3.4-arch1-2 and 7.3.0-next-20261030 (identical results).
- Method: For the s2idle and hibernation cycles, thinkpad_acpi was
unloaded with rmmod before each cycle so the driver was absent
throughout sleep and wakeup (my kernels are built as UKIs with a
baked-in cmdline, so I used rmmod rather than a boot-time blacklist).
Backlight levels were cycled only via Fn+Space and read back by
evaluating MLCG directly via acpi_call. This machine only exposes
s2idle (no S3), so "suspend" below means s2idle/S0ix.
Results without the driver loaded:
- s2idle: The firmware turns the backlight off on suspend and restores the
previous level on resume across all levels (0, 1, 2, and 3/auto).
- Hibernation (S4): The firmware turns the backlight off on entry, and on
resume the EC comes back at level 0 for every pre-sleep level, manual
levels 1 and 2 included. My apologies for the wrong statement in the v3
cover letter where I said manual levels survived S4 on their own; my
earlier test was likely interfered with when the driver/userspace was
still active. Please take this clean test as the accurate result, which
also aligns with the concerns you both raised.
- Cold boot and warm reboot: The EC always initializes to level 0. Since
kbdlight_init() only reads MLCG without writing MLCS, and the pre-resume
hibernation logs show the same reset to 0, this is firmware behavior.
So on this machine, the firmware handles s2idle by itself, and S4 resume
is the case where the driver needs to restore the pre-sleep level.
Regarding S3: as far as I could find in public sources, modern ThinkPads
essentially only support s2idle and S4 (ThinkPads moved to S0ix-only
around Gen 11 in 2023). I do not have an older S3-capable machine to
test, so I can only speak for this platform.
(One small side observation from logging raw MLCG values: bit 22 was 1
whenever level 3/auto was active and 0 across manual levels 0-2 on this
machine. Just sharing as a single-machine data point in case it is useful.)
> > - the EC comes back with the
> > backlight off, without an event. Rather than re-attaching the trigger
> > from the pre-suspend state,
>
> "re-attaching"
>
> I am not familiar with hibernation, so I am not sure if the LED core
> would detach the trigger before entering hibernation. If not, why did you
> say that?
Sorry for the poor wording in my cover letter. The LED core does not
detach the trigger across hibernation; what I meant to say was "writing
level 3 back to the EC", not re-attaching the trigger in the LED core.
Following the comments from you and Mark on 7/7, I agree that restoring the
cached level in the driver on resume is the right approach: calling
kbdlight_set_level(kbdlight_brightness) in kbdlight_resume() without
emitting notifications. Since the LED core's own brightness cache only
stores the translated brightness (where auto mode is 0), restoring from
kbdlight_brightness in the driver handles both manual and auto modes
cleanly. I prototype-tested this on my machine: after S4 resume the EC
was restored to the pre-hibernation level for both manual levels and
auto mode; when the pre-sleep level was auto, the auto trigger stayed
attached across the whole cycle; and on s2idle resume, rewriting the
unchanged level was a harmless no-op.
Regarding your suggestion on 7/7 about dropping led_classdev_suspend() and
led_classdev_resume() across all models: since I only have this one
machine to test, my tentative plan is to keep the new behavior gated on
tp_features.kbdlight_auto (so non-auto machines stay on
led_classdev_{suspend,resume}(), while auto-capable machines skip
kbdlight_suspend() and restore kbdlight_brightness in kbdlight_resume()).
If you and Mark prefer replacing led_classdev_{suspend,resume}() across
all models and handling suspend/resume in the driver ourselves, I am happy
to widen it.
Lastly, I have two small questions on 3/7 and 6/7 to make sure I
understand everything properly:
1. Calling kbdlight_notify_level() in kbdlight_write() vs. sysfs writes
(patch 3/7):
I will change kbdlight_write() to call kbdlight_notify_level() and have
kbdlight_set_level_and_update() only update kbdlight_brightness as
requested. Just for my own understanding of the design principle here
(and in commit 07f48f668fac): since leds-class.rst describes
brightness_hw_changed as being for hardware-initiated changes, is the
idea that a legacy out-of-band interface like /proc/acpi/ibm/kbdlight
changes the level behind the LED core's back (so the LED core and
UPower need to be notified to stay in sync), whereas sysfs writes
already go through the LED core and shouldn't echo a notification back
to userspace?
2. Keeping the default_trigger check in kbdlight_init() (patch 6/7):
Since the EC resets to 0 on cold and warm boots on my machine, I agree
that no LED_RETAIN_AT_SHUTDOWN / exit-retention logic is needed.
However, if a user presses Fn+Space into auto mode before the driver
loads (for example, at the BIOS or disk-encryption password prompt, or
while the module is unloaded between rmmod and modprobe, which I hit
during testing), setting default_trigger keeps the initial trigger
state synchronized with the EC. Would it be okay to keep that check in
kbdlight_init() for those cases, or would you prefer dropping it?
(One minor hardware note: occasionally my unit retries entering S4 a few
times before succeeding, and resumes after those aborted attempts can show
timing oddities. All data above comes from clean hibernate cycles, but I
am happy to dig into the retry case if it is of interest.)
Thanks again to both of you for your time and patience; I have learned a
lot from your reviews.
Best regards,
Qiling
^ permalink raw reply [flat|nested] 32+ messages in thread* Re: [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
2026-11-18 11:02 ` Qiling Zhu
@ 2026-11-19 14:21 ` Rong Zhang
0 siblings, 0 replies; 32+ messages in thread
From: Rong Zhang @ 2026-11-19 14:21 UTC (permalink / raw)
To: Qiling Zhu
Cc: Mark Pearson, Derek J. Clark, Hans de Goede, Ilpo Järvinen,
Henrique de Moraes Holschuh, Andrea Rabbaglietti, Lee Jones,
Pavel Machek, Griffin Kroah-Hartman, vishnuocv, vsankar,
platform-driver-x86, ibm-acpi-devel, linux-leds, linux-kernel
Hi Qiling,
On Wed, 2026-11-18 at 19:02 +0800, Qiling Zhu wrote:
> Hi Rong, Mark,
>
> On Sun, Nov 15, 2026 at 03:52:36PM +0800, Rong Zhang wrote:
> > The next time when you send a series (i.e., PATCH x/n, n > 1), please do
> > not reply to the previous thread to keep it tidy.
>
> First, my apologies for sending v3 as a reply to the v2 thread. I caught
> that mistake shortly after sending it out, and I will make sure v4 starts
> a clean thread. Please do let me know if I am getting anything else wrong
> with the workflow; I am still learning the process and really appreciate
> your guidance.
>
> Thank you both for the reviews, Rong for another patient and detailed
> round, and Mark for the Reviewed-by tags and the sleep/wake input. I will
> apply all the requested changes in v4 (including moving
> kbdlight_level_to_brightness() with an int return type into 1/7, adding
> the lockdep annotations and symbolic macro, fixing the helper placements
> and indentation, updating kbdlight_brightness in
> kbdlight_set_level_and_update() and using it in
> kbdlight_auto_trigger_activate(), and adding the note below '---' for
> Sashiko's report).
>
> > > One addition that was not in v2: testing showed that the firmware does
> > > not restore auto mode across hibernation
> >
> > How about s2idle? And what if hw brightness = [0,2] before hibernation?
> >
> > Meanwhile, could you test s2idle, hibernation and cold boots with
> > thinkpad_acpi blacklisted to see if hw brightness ([0,2] and 3) is
> > preserved? We need the raw behavior to determine our strategy.
>
> Here is the raw hardware behavior data you asked for.
>
> Test setup:
> - Machine: ThinkPad X1 Carbon Gen 14 (21V8A028CD), BIOS N4OET53W (1.16),
> EC N4OHT42W.
> - Kernels: 7.3.4-arch1-2 and 7.3.0-next-20261030 (identical results).
> - Method: For the s2idle and hibernation cycles, thinkpad_acpi was
> unloaded with rmmod before each cycle so the driver was absent
> throughout sleep and wakeup (my kernels are built as UKIs with a
> baked-in cmdline, so I used rmmod rather than a boot-time blacklist).
> Backlight levels were cycled only via Fn+Space and read back by
> evaluating MLCG directly via acpi_call. This machine only exposes
> s2idle (no S3), so "suspend" below means s2idle/S0ix.
>
> Results without the driver loaded:
>
> - s2idle: The firmware turns the backlight off on suspend and restores the
> previous level on resume across all levels (0, 1, 2, and 3/auto).
>
> - Hibernation (S4): The firmware turns the backlight off on entry, and on
> resume the EC comes back at level 0 for every pre-sleep level, manual
> levels 1 and 2 included. My apologies for the wrong statement in the v3
> cover letter where I said manual levels survived S4 on their own; my
> earlier test was likely interfered with when the driver/userspace was
> still active. Please take this clean test as the accurate result, which
> also aligns with the concerns you both raised.
>
> - Cold boot and warm reboot: The EC always initializes to level 0. Since
> kbdlight_init() only reads MLCG without writing MLCS, and the pre-resume
> hibernation logs show the same reset to 0, this is firmware behavior.
>
> So on this machine, the firmware handles s2idle by itself, and S4 resume
> is the case where the driver needs to restore the pre-sleep level.
>
> Regarding S3: as far as I could find in public sources, modern ThinkPads
> essentially only support s2idle and S4 (ThinkPads moved to S0ix-only
> around Gen 11 in 2023). I do not have an older S3-capable machine to
> test, so I can only speak for this platform.
>
> (One small side observation from logging raw MLCG values: bit 22 was 1
> whenever level 3/auto was active and 0 across manual levels 0-2 on this
> machine. Just sharing as a single-machine data point in case it is useful.)
Let me conclude in short:
- S0ix preserves everything
- S4/S5 resets everything
>
> > > - the EC comes back with the
> > > backlight off, without an event. Rather than re-attaching the trigger
> > > from the pre-suspend state,
> >
> > "re-attaching"
> >
> > I am not familiar with hibernation, so I am not sure if the LED core
> > would detach the trigger before entering hibernation. If not, why did you
> > say that?
>
> Sorry for the poor wording in my cover letter. The LED core does not
> detach the trigger across hibernation; what I meant to say was "writing
> level 3 back to the EC", not re-attaching the trigger in the LED core.
>
> Following the comments from you and Mark on 7/7, I agree that restoring the
> cached level in the driver on resume is the right approach: calling
> kbdlight_set_level(kbdlight_brightness) in kbdlight_resume() without
> emitting notifications. Since the LED core's own brightness cache only
> stores the translated brightness (where auto mode is 0), restoring from
> kbdlight_brightness in the driver handles both manual and auto modes
> cleanly. I prototype-tested this on my machine: after S4 resume the EC
> was restored to the pre-hibernation level for both manual levels and
> auto mode; when the pre-sleep level was auto, the auto trigger stayed
> attached across the whole cycle; and on s2idle resume, rewriting the
> unchanged level was a harmless no-op.
Yeah, we don't need to differentiate S0ix and S4, but simply restore hw
brightness regardless.
>
> Regarding your suggestion on 7/7 about dropping led_classdev_suspend() and
> led_classdev_resume() across all models: since I only have this one
> machine to test, my tentative plan is to keep the new behavior gated on
> tp_features.kbdlight_auto (so non-auto machines stay on
> led_classdev_{suspend,resume}(), while auto-capable machines skip
> kbdlight_suspend() and restore kbdlight_brightness in kbdlight_resume()).
> If you and Mark prefer replacing led_classdev_{suspend,resume}() across
> all models and handling suspend/resume in the driver ourselves, I am happy
> to widen it.
AFAICS, the reason why thinkpad_acpi's current implementation needs to
call led_update_brightness() and led_classdev_{suspend,resume}() is
exactly because it pokes led_cdev->brightness.
Since your series will remove the fragile behavior and track hw
brightness using kbdlight_brightness, we no longer need to rely on the
LED core to store and resume the last brightness for us. That's why I
prefer to unify the routine among all models.
You might still call led_classdev_{suspend,resume}() to set/clear
LED_SUSPENDED if you would like to gate brightness changes from the LED
core somehow to make our jobs undisturbed. But I am very unsure if we
really need to gate changes from the LED core like that...
>
> Lastly, I have two small questions on 3/7 and 6/7 to make sure I
> understand everything properly:
>
> 1. Calling kbdlight_notify_level() in kbdlight_write() vs. sysfs writes
> (patch 3/7):
> I will change kbdlight_write() to call kbdlight_notify_level() and have
> kbdlight_set_level_and_update() only update kbdlight_brightness as
> requested. Just for my own understanding of the design principle here
> (and in commit 07f48f668fac): since leds-class.rst describes
> brightness_hw_changed as being for hardware-initiated changes, is the
> idea that a legacy out-of-band interface like /proc/acpi/ibm/kbdlight
> changes the level behind the LED core's back (so the LED core and
> UPower need to be notified to stay in sync), whereas sysfs writes
> already go through the LED core and shouldn't echo a notification back
> to userspace?
Exactly.
>
> 2. Keeping the default_trigger check in kbdlight_init() (patch 6/7):
> Since the EC resets to 0 on cold and warm boots on my machine, I agree
> that no LED_RETAIN_AT_SHUTDOWN / exit-retention logic is needed.
> However, if a user presses Fn+Space into auto mode before the driver
> loads (for example, at the BIOS or disk-encryption password prompt, or
> while the module is unloaded between rmmod and modprobe, which I hit
> during testing), setting default_trigger keeps the initial trigger
> state synchronized with the EC. Would it be okay to keep that check in
> kbdlight_init() for those cases, or would you prefer dropping it?
Makes sense. For this specific use case you can keep the default_trigger
probing routine, with a brief comment explaining the purpose.
Thanks,
Rong
>
> (One minor hardware note: occasionally my unit retries entering S4 a few
> times before succeeding, and resumes after those aborted attempts can show
> timing oddities. All data above comes from clean hibernate cycles, but I
> am happy to dig into the retry case if it is of interest.)
>
> Thanks again to both of you for your time and patience; I have learned a
> lot from your reviews.
>
> Best regards,
> Qiling
^ permalink raw reply [flat|nested] 32+ messages in thread