[PATCH 1/3] platform/x86: uniwill-laptop: Optionally apply keyboard backlight levels
From: Farhan via B4 Relay
Date: Sat Dec 05 2026 - 03:10:58 EST
From: Farhan <khan.10.0412@xxxxxxxxx>
Once the driver has enabled manual control, the EC on some devices keeps
reporting UNIWILL_OSD_KB_LED_LEVEL* events when the keyboard backlight
keys are pressed, but no longer changes the backlight itself. The driver
then only notifies userspace about a brightness change that never
happened, so the keys appear to do nothing: brightness_hw_changed shows
the new level while the brightness attribute keeps the old one.
Add a device descriptor flag for such devices which makes the driver
write the reported level to the EC before notifying userspace.
Assisted-by: LLM
Signed-off-by: Farhan <khan.10.0412@xxxxxxxxx>
---
drivers/platform/x86/uniwill/uniwill-acpi.c | 36 ++++++++++++++++++++---------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/drivers/platform/x86/uniwill/uniwill-acpi.c b/drivers/platform/x86/uniwill/uniwill-acpi.c
index e2a6a704e..1f1d62c39 100644
--- a/drivers/platform/x86/uniwill/uniwill-acpi.c
+++ b/drivers/platform/x86/uniwill/uniwill-acpi.c
@@ -408,6 +408,7 @@ struct uniwill_data {
struct mc_subled led_mc_subled_info[LED_CHANNELS];
bool kbd_led_single_color;
u8 kbd_led_max_brightness;
+ bool kbd_led_apply_level;
unsigned int last_kbd_status;
union {
struct {
@@ -434,6 +435,12 @@ struct uniwill_device_descriptor {
unsigned int features;
bool kbd_led_single_color;
u8 kbd_led_max_brightness;
+ /*
+ * Some ECs only report the new keyboard backlight level when the
+ * brightness keys are pressed while the driver controls the EC,
+ * but do not apply it themselves.
+ */
+ bool kbd_led_apply_level;
u8 lightbar_max_intensity;
/* Executed during driver probing */
int (*probe)(struct uniwill_data *data);
@@ -1670,6 +1677,17 @@ static int uniwill_led_init(struct uniwill_data *data)
&init_data);
}
+#define KBD_LED_MASK (KBD_BRIGHTNESS_MASK | KBD_APPLY | KBD_POWER_OFF)
+
+static int uniwill_kbd_led_write_brightness(struct uniwill_data *data, int brightness)
+{
+ /* KBD_POWER_OFF is always implicitly cleared */
+ unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, brightness) | KBD_APPLY;
+
+ /* We must ensure that the "apply" bit is always written */
+ return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, KBD_LED_MASK, regval);
+}
+
static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
{
struct led_classdev *led_cdev;
@@ -1708,6 +1726,12 @@ static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
guard(mutex)(&led_cdev->led_access);
+ if (data->kbd_led_apply_level) {
+ ret = uniwill_kbd_led_write_brightness(data, brightness);
+ if (ret < 0)
+ return ret;
+ }
+
/* Sync the LED brightness with the actual hardware state */
ret = led_update_brightness(led_cdev);
if (ret < 0)
@@ -1718,17 +1742,6 @@ static int uniwill_notify_kbd_led(struct uniwill_data *data, int brightness)
return 0;
}
-#define KBD_LED_MASK (KBD_BRIGHTNESS_MASK | KBD_APPLY | KBD_POWER_OFF)
-
-static int uniwill_kbd_led_write_brightness(struct uniwill_data *data, int brightness)
-{
- /* KBD_POWER_OFF is always implicitly cleared */
- unsigned int regval = FIELD_PREP(KBD_BRIGHTNESS_MASK, brightness) | KBD_APPLY;
-
- /* We must ensure that the "apply" bit is always written */
- return regmap_write_bits(data->regmap, EC_ADDR_KBD_STATUS, KBD_LED_MASK, regval);
-}
-
static int uniwill_kbd_led_read_brightness(struct uniwill_data *data)
{
unsigned int regval;
@@ -2442,6 +2455,7 @@ static int uniwill_probe(struct platform_device *pdev)
data->features = device_descriptor.features;
data->kbd_led_single_color = device_descriptor.kbd_led_single_color;
data->kbd_led_max_brightness = device_descriptor.kbd_led_max_brightness;
+ data->kbd_led_apply_level = device_descriptor.kbd_led_apply_level;
data->lightbar_max_intensity = device_descriptor.lightbar_max_intensity;
/*
--
2.53.0