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 v5 2/6] platform/x86: thinkpad_acpi: Extract kbdlight notify helpers
Date: Mon, 30 Nov 2026 21:12:48 +0800 [thread overview]
Message-ID: <20261130131252.80436-3-kmatzkaczor244@gmail.com> (raw)
In-Reply-To: <20261130131252.80436-1-kmatzkaczor244@gmail.com>
TP_HKEY_EV_KBD_LIGHT handling in tpacpi_driver_event() reads back the
brightness, compares it with the cached value and notifies the LED core
inline. Extract this block into two helpers: kbdlight_notify_level()
takes an EC level, compares it with the cached value, updates the cache
and notifies the LED core, translating the level to a brightness on the
way, as kbdlight_sysfs_get() does; kbdlight_notify_change() reads the
level back and calls the former under kbdlight_mutex.
kbdlight_notify_level() expects the caller to hold kbdlight_mutex, so
that the proc write path can reuse it with the level it has just
written in a subsequent change.
The helpers work in EC levels rather than brightness values, as the
rest of the series builds on that. This differs from the original code
in two situations: a change from off to the auto mode or back, which
reads back as the same brightness, now produces a notification
reporting 0 when the cached value holds the EC level, where the
original code sent none; and a failed read of the level now sends no
notification and leaves the cached value alone, where the original code
went on with a brightness of 0.
kbdlight_brightness is still an enum led_brightness at this point, and
kbdlight_init() still fills it in from the reported brightness; a later
change in this series makes it an int that tracks the EC level from
init on.
Signed-off-by: Qiling Zhu <kmatzkaczor244@gmail.com>
Reviewed-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 48 ++++++++++++++-------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 31d3721bb..3ef857542 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5267,6 +5267,36 @@ static int kbdlight_set_level_and_update(int level)
return ret;
}
+static void kbdlight_notify_level(int level)
+{
+ struct led_classdev *led_cdev = &tpacpi_led_kbdlight.led_classdev;
+
+ lockdep_assert_held(&kbdlight_mutex);
+
+ /*
+ * Check the level actually changed, setting the level
+ * through kbdlight_set_level() also triggers this event.
+ */
+ if (level == kbdlight_brightness)
+ return;
+
+ kbdlight_brightness = level;
+ led_classdev_notify_brightness_hw_changed(led_cdev, kbdlight_level_to_brightness(level));
+}
+
+static void kbdlight_notify_change(void)
+{
+ int level;
+
+ guard(mutex)(&kbdlight_mutex);
+
+ level = kbdlight_get_level();
+ if (level < 0)
+ return;
+
+ kbdlight_notify_level(level);
+}
+
static int kbdlight_read(struct seq_file *m)
{
int level;
@@ -11593,22 +11623,8 @@ static bool tpacpi_driver_event(const unsigned int hkey_event)
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_KBD_LIGHT:
- if (tp_features.kbdlight) {
- enum led_brightness brightness;
-
- guard(mutex)(&kbdlight_mutex);
-
- /*
- * Check the brightness actually changed, setting the brightness
- * through kbdlight_set_level() also triggers this event.
- */
- brightness = kbdlight_sysfs_get(NULL);
- if (kbdlight_brightness != brightness) {
- kbdlight_brightness = brightness;
- led_classdev_notify_brightness_hw_changed(
- &tpacpi_led_kbdlight.led_classdev, brightness);
- }
- }
+ if (tp_features.kbdlight)
+ kbdlight_notify_change();
/* Key events are suppressed by default hotkey_user_mask */
return false;
case TP_HKEY_EV_DFR_CHANGE_ROW:
--
2.56.1
next prev parent reply other threads:[~2026-11-30 13:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 13:12 [PATCH v5 0/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-11-30 13:12 ` [PATCH v5 1/6] platform/x86: thinkpad_acpi: Report auto keyboard backlight mode as off Qiling Zhu
2026-11-30 13:12 ` Qiling Zhu [this message]
2026-11-30 13:12 ` [PATCH v5 3/6] platform/x86: thinkpad_acpi: Don't poke keyboard backlight's LED core brightness Qiling Zhu
2026-11-30 13:12 ` [PATCH v5 4/6] platform/x86: thinkpad_acpi: Restore keyboard backlight level ourselves Qiling Zhu
2026-11-30 13:12 ` [PATCH v5 5/6] platform/x86: thinkpad_acpi: Detect auto-mode capability via MLCG Qiling Zhu
2026-11-30 13:12 ` [PATCH v5 6/6] platform/x86: thinkpad_acpi: Add a keyboard backlight auto-mode trigger Qiling Zhu
2026-11-30 15:04 ` [PATCH v5 0/6] " Lee Jones
2026-11-30 15:46 ` 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=20261130131252.80436-3-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®