mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [ibm-acpi-devel] [PATCH] thinkpad_acpi: Add Auto mode support with dynamic max_brightness
@ 2026-11-07 13:23 Andrea Rabbaglietti
  2026-11-07 15:11 ` Rong Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Andrea Rabbaglietti @ 2026-11-07 13:23 UTC (permalink / raw)
  To: mpearson-lenovo
  Cc: Derek John Clark, hansg, hmh, i, ibm-acpi-devel, ilpo.jarvinen,
	linux-kernel, platform-driver-x86, vishnuocv, vsankar

On Mon, Feb 23, 2026, at 6:19 PM, Mark Pearson wrote:
> Hi Hans - do you have an opinion on the path forwards?

Hi all,

a data point from a user, since this thread seems to have stalled.

On a ThinkPad X9-14 Gen 1 (21QA, BIOS 1.25) running 7.2.15, the
firmware already enters Auto mode on its own: Fn+Space cycles

  0 -> 3 (Auto) -> 1 -> 2 -> 0 -> ...

so with the current driver tpacpi::kbd_backlight reports brightness 3
while max_brightness is 2, and brightness_hw_changed emits 3 as well.

This is not only cosmetic. UPower 1.91.x treats 3 as out of range and
stops watching brightness_hw_changed altogether, so the desktop no
longer follows the hotkey at all after the first time Auto is reached:
https://gitlab.freedesktop.org/upower/upower/-/work_items/367

Whatever interface is chosen for exposing Auto mode (separate attribute
or hw-control trigger), would a minimal fix in the meantime be
acceptable? Following Hans' suggestion earlier in the thread, the driver
would report max_brightness (2) in brightness and brightness_hw_changed
while MLCG says Auto, and leave the ABI otherwise unchanged. That keeps
the 0-2 contract userspace relies on and is easy to backport to stable.

I am happy to write and test such a patch on this machine, or to test
a v2 of this series, whichever you prefer.

Thanks,
Andrea Rabbaglietti

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [PATCH] thinkpad_acpi: Add Auto mode support with dynamic max_brightness
@ 2026-02-03 23:22 Vishnu Sankar
  2026-02-08 10:54 ` Hans de Goede
  0 siblings, 1 reply; 3+ messages in thread
From: Vishnu Sankar @ 2026-02-03 23:22 UTC (permalink / raw)
  To: hmh, derekjohn.clark, hansg, ilpo.jarvinen, mpearson-lenovo
  Cc: ibm-acpi-devel, platform-driver-x86, linux-kernel, vsankar,
	Vishnu Sankar

Dynamically detect keyboard backlight capabilities and set
max_brightness correctly (2 for old models, 3 for new models
with Auto mode).

Suggested-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Vishnu Sankar <vishnuocv@gmail.com>
---
 drivers/platform/x86/lenovo/thinkpad_acpi.c | 33 ++++++++++++++++++---
 1 file changed, 29 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index cc19fe520ea9..f670cdd1791e 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -5043,6 +5043,9 @@ static struct ibm_struct video_driver_data = {
 static enum led_brightness kbdlight_brightness;
 static DEFINE_MUTEX(kbdlight_mutex);
 
+/* Maximum level supported by hardware, will be updated in init */
+static int kbdlight_max_level = 2;
+
 static int kbdlight_set_level(int level)
 {
 	int ret = 0;
@@ -5050,6 +5053,10 @@ static int kbdlight_set_level(int level)
 	if (!hkey_handle)
 		return -ENXIO;
 
+	/* Validate against detected max level */
+	if (level < 0 || level > kbdlight_max_level)
+		return -EINVAL;
+
 	mutex_lock(&kbdlight_mutex);
 
 	if (!acpi_evalf(hkey_handle, NULL, "MLCS", "dd", level))
@@ -5075,6 +5082,7 @@ static int kbdlight_get_level(void)
 	if (status < 0)
 		return status;
 
+	/* Status can be 0, 1, 2, or 3 (Auto) */
 	return status & 0x3;
 }
 
@@ -5143,7 +5151,7 @@ static enum led_brightness kbdlight_sysfs_get(struct led_classdev *led_cdev)
 static struct tpacpi_led_classdev tpacpi_led_kbdlight = {
 	.led_classdev = {
 		.name		= "tpacpi::kbd_backlight",
-		.max_brightness	= 2,
+		.max_brightness	= 2,	/*Initial value, will be updated in init*/
 		.flags		= LED_BRIGHT_HW_CHANGED,
 		.brightness_set_blocking = &kbdlight_sysfs_set,
 		.brightness_get	= &kbdlight_sysfs_get,
@@ -5167,6 +5175,17 @@ static int __init kbdlight_init(struct ibm_init_struct *iibm)
 	kbdlight_brightness = kbdlight_sysfs_get(NULL);
 	tp_features.kbdlight = 1;
 
+	/* Detect hardware capabilities and set max_brightness */
+	if (acpi_evalf(hkey_handle, NULL, "MLCS", "dd", 3)) {
+		/* MLCS accepts level 3 - new ThinkPad with Auto mode */
+		kbdlight_max_level = 3;
+		tpacpi_led_kbdlight.led_classdev.max_brightness = 3;
+	} else {
+		/* MLCS rejects level 3 - old ThinkPad */
+		kbdlight_max_level = 2;
+		tpacpi_led_kbdlight.led_classdev.max_brightness = 2;
+	}
+
 	rc = led_classdev_register(&tpacpi_pdev->dev,
 				   &tpacpi_led_kbdlight.led_classdev);
 	if (rc < 0) {
@@ -5201,6 +5220,7 @@ static int kbdlight_set_level_and_update(int level)
 static int kbdlight_read(struct seq_file *m)
 {
 	int level;
+	int i;
 
 	if (!tp_features.kbdlight) {
 		seq_printf(m, "status:\t\tnot supported\n");
@@ -5210,9 +5230,13 @@ static int kbdlight_read(struct seq_file *m)
 			seq_printf(m, "status:\t\terror %d\n", level);
 		else
 			seq_printf(m, "status:\t\t%d\n", level);
-		seq_printf(m, "commands:\t0, 1, 2\n");
-	}
 
+		/* Show available commands based on hardware */
+		seq_puts(m, "commands:\t0");
+		for (i = 1; i <= tpacpi_led_kbdlight.led_classdev.max_brightness; i++)
+			seq_printf(m, ", %d", i);
+		seq_puts(m, "\n");
+	}
 	return 0;
 }
 
@@ -5230,7 +5254,8 @@ static int kbdlight_write(char *buf)
 			return res;
 	}
 
-	if (level >= 3 || level < 0)
+	/* Validate against max level */
+	if (level < 0 || level > tpacpi_led_kbdlight.led_classdev.max_brightness)
 		return -EINVAL;
 
 	return kbdlight_set_level_and_update(level);
-- 
2.51.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-07 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-07 13:23 [ibm-acpi-devel] [PATCH] thinkpad_acpi: Add Auto mode support with dynamic max_brightness Andrea Rabbaglietti
2026-11-07 15:11 ` Rong Zhang
  -- strict thread matches above, loose matches on Subject: below --
2026-02-03 23:22 Vishnu Sankar
2026-02-08 10:54 ` Hans de Goede
2026-02-08 20:58   ` Rong Zhang
2026-02-09 15:46     ` Mark Pearson
2026-02-09 18:14       ` Rong Zhang
2026-02-09 18:44         ` Mark Pearson
2026-02-10 10:31           ` Hans de Goede
2026-02-10 16:11             ` Rong Zhang
2026-02-10 21:17               ` Mark Pearson
2026-02-23 18:19                 ` [ibm-acpi-devel] " Mark Pearson

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®