mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiling Zhu <kmatzkaczor244@gmail.com>
To: Rong Zhang <i@rong.moe>
Cc: "Mark Pearson" <mpearson-lenovo@squebb.ca>,
	"Derek J. Clark" <derekjohn.clark@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
	"Andrea Rabbaglietti" <rabbagliettiandrea@gmail.com>,
	"Lee Jones" <lee@kernel.org>, "Pavel Machek" <pavel@kernel.org>,
	"Griffin Kroah-Hartman" <griffin@kroah.com>,
	vishnuocv@gmail.com, vsankar@lenovo.com,
	platform-driver-x86@vger.kernel.org,
	ibm-acpi-devel@lists.sourceforge.net, linux-leds@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/7] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight
Date: Wed, 18 Nov 2026 19:02:26 +0800	[thread overview]
Message-ID: <av14Sp6_nKwU5F-i@ThinkPad> (raw)
In-Reply-To: <230263171c25c322d97fa29439a01922db47f913.camel@rong.moe>

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

      reply	other threads:[~2026-11-18 11:02 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01 10:01 [RFC PATCH 0/1] " Qiling Zhu
2026-11-01 10:01 ` [RFC PATCH 1/1] " Qiling Zhu
2026-11-01 18:24   ` Rong Zhang
2026-11-01 17:57 ` [RFC PATCH 0/1] " Rong Zhang
2026-11-04  4:57   ` Vishnu Sankar
2026-11-02 15:10 ` [RFC PATCH v2 0/2] " Qiling Zhu
2026-11-02 15:10   ` [RFC PATCH v2 1/2] platform/x86: thinkpad_acpi: Extract kbdlight_notify_change() helper Qiling Zhu
2026-11-02 15:10   ` [RFC PATCH v2 2/2] platform/x86: thinkpad_acpi: Add support for auto keyboard backlight Qiling Zhu
2026-11-02 18:32     ` Rong Zhang
2026-11-02 18:13   ` [RFC PATCH v2 0/2] " Rong Zhang
2026-11-05 13:18     ` Qiling Zhu
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-15  7:53       ` Rong Zhang
2026-11-15 21:58         ` Mark Pearson
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
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
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
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
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
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
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 [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av14Sp6_nKwU5F-i@ThinkPad \
    --to=kmatzkaczor244@gmail.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=griffin@kroah.com \
    --cc=hansg@kernel.org \
    --cc=hmh@hmh.eng.br \
    --cc=i@rong.moe \
    --cc=ibm-acpi-devel@lists.sourceforge.net \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=lee@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=pavel@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=rabbagliettiandrea@gmail.com \
    --cc=vishnuocv@gmail.com \
    --cc=vsankar@lenovo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®