From: Qiling Zhu <kmatzkaczor244@gmail.com>
To: "Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Rong Zhang" <i@rong.moe>, "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Henrique de Moraes Holschuh" <hmh@hmh.eng.br>
Cc: platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
ibm-acpi-devel@lists.sourceforge.net, Lee Jones <lee@kernel.org>,
Pavel Machek <pavel@kernel.org>,
Griffin Kroah-Hartman <griffin@kroah.com>,
linux-leds@vger.kernel.org, vishnuocv@gmail.com,
vsankar@lenovo.com,
Andrea Rabbaglietti <rabbagliettiandrea@gmail.com>
Subject: [PATCH v4 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves
Date: Wed, 25 Nov 2026 16:46:41 +0800 [thread overview]
Message-ID: <20261125084644.137506-5-kmatzkaczor244@gmail.com> (raw)
In-Reply-To: <20261125084644.137506-1-kmatzkaczor244@gmail.com>
kbdlight_suspend() and kbdlight_resume() leave the keyboard backlight to
the LED core across sleep: the LED core caches the current brightness
and turns the backlight off on suspend, and writes that brightness back
on resume.
On a ThinkPad X1 Carbon Gen 14 with thinkpad_acpi unloaded, the firmware
turned the backlight off when entering both s2idle and hibernation.
After waking from s2idle the EC was back at its previous level, for each
of the four levels tested; after waking from hibernation it was at 0.
Drop kbdlight_suspend() and leave turning the backlight off to the
firmware. On resume, write the cached level back to the EC on all
models, instead of relying on the LED core: this brings the backlight
back where the firmware came up with it off, and changes nothing
where the EC already has that level. For this to hold for every
mode, have kbdlight_brightness track the EC level itself, 0 to 3,
rather than the brightness reported to the LED core, in which the auto
mode (level 3) shows up as 0; translate it only when reporting a
brightness.
Only s2idle and S4 were available on the test machine; S3-capable
models were not tested.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 38 +++++++++++----------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 16bf2267d..764b1efa6 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5105,7 +5105,12 @@ static struct ibm_struct video_driver_data = {
/* EC level that selects the auto mode for the keyboard backlight */
#define TPACPI_KBD_LIGHT_AUTO_LEVEL 3
-static enum led_brightness kbdlight_brightness;
+/*
+ * Cached EC level, including TPACPI_KBD_LIGHT_AUTO_LEVEL. All state
+ * tracking compares EC levels; the auto mode is translated to a
+ * brightness value only when reporting to the LED core.
+ */
+static int kbdlight_brightness;
static DEFINE_MUTEX(kbdlight_mutex);
static int kbdlight_set_level(int level)
@@ -5247,7 +5252,10 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
return -ENODEV;
}
- kbdlight_brightness = kbdlight_sysfs_get(NULL);
+ kbdlight_brightness = kbdlight_get_level();
+ if (kbdlight_brightness < 0)
+ kbdlight_brightness = 0;
+
tp_features.kbdlight = 1;
rc = led_classdev_register(&tpacpi_pdev->dev,
@@ -5281,14 +5289,20 @@ static void kbdlight_notify_level(int level)
return;
kbdlight_brightness = level;
- led_classdev_notify_brightness_hw_changed(led_cdev, level);
+ led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level));
}
static void kbdlight_notify_change(void)
{
+ int level;
+
guard(mutex)(&kbdlight_mutex);
- kbdlight_notify_level(kbdlight_sysfs_get(NULL));
+ level = kbdlight_get_level();
+ if (level < 0)
+ return;
+
+ kbdlight_notify_level(level);
}
static int kbdlight_read(struct seq_file *m)
@@ -5337,31 +5351,19 @@ static int kbdlight_write(char *buf)
return 0;
}
-static void kbdlight_suspend(void)
-{
- struct led_classdev *led_cdev;
-
- if (!tp_features.kbdlight)
- return;
-
- led_cdev = &tpacpi_led_kbdlight.led_classdev;
- led_update_brightness(led_cdev);
- led_classdev_suspend(led_cdev);
-}
-
static void kbdlight_resume(void)
{
if (!tp_features.kbdlight)
return;
- led_classdev_resume(&tpacpi_led_kbdlight.led_classdev);
+ guard(mutex)(&kbdlight_mutex);
+ kbdlight_set_level(kbdlight_brightness);
}
static struct ibm_struct kbdlight_driver_data = {
.name = "kbdlight",
.read = kbdlight_read,
.write = kbdlight_write,
- .suspend = kbdlight_suspend,
.resume = kbdlight_resume,
.exit = kbdlight_exit,
};
--
2.56.1
next prev parent reply other threads:[~2026-11-25 8:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 8:46 [PATCH v4 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-11-25 8:46 ` [PATCH v4 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-11-25 8:46 ` [PATCH v4 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers Qiling Zhu
2026-11-25 8:46 ` [PATCH v4 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
2026-11-25 8:46 ` Qiling Zhu [this message]
2026-11-25 8:46 ` [PATCH v4 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-11-25 8:46 ` [PATCH v4 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
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=20261125084644.137506-5-kmatzkaczor244@gmail.com \
--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®