Re: [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight

From: Rong Zhang

Date: Thu Nov 19 2026 - 09:27:25 EST


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