Skip to contentSkip to conversation

platform/x86: asus-wmi: Call led hw_changed API on kbd brightness change

PATCH In review Chris Chiu 2 participants 7 messages Jun 20, 2018 – Aug 15, 2018

Subsystems (2)
lore
Share & tools
lore

Chris Chiu

author
#0 lore raw

PATCH v3 1/2 platform/x86: asus-wmi: Call led hw_changed API on kbd brightness change

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

---
 drivers/platform/x86/asus-wmi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/platform/x86/asus-wmi.c +22 -4
index 1f6e68f0b646..f2b9037f6ded 100644
@@ -460,6 +460,7 @@ static void kbd_led_update(struct work_struct *work)
 		ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
 
 	asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
+	led_classdev_notify_brightness_hw_changed(&asus->kbd_led, asus->kbd_led_wk);
 }
 
 static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
@@ -490,15 +491,16 @@ static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
 	return retval;
 }
 
-static void kbd_led_set(struct led_classdev *led_cdev,
-			enum led_brightness value)
+static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
 {
 	struct asus_wmi *asus;
+	int max_level;
 
 	asus = container_of(led_cdev, struct asus_wmi, kbd_led);
+	max_level = asus->kbd_led.max_brightness;
 
-	if (value > asus->kbd_led.max_brightness)
-		value = asus->kbd_led.max_brightness;
+	if (value > max_level)
+		value = max_level;
 	else if (value < 0)
 		value = 0;
 
@@ -506,6 +508,12 @@ static void kbd_led_set(struct led_classdev *led_cdev,
 	queue_work(asus->led_workqueue, &asus->kbd_led_work);
 }
 
+static void kbd_led_set(struct led_classdev *led_cdev,
+			enum led_brightness value)
+{
+	do_kbd_led_set(led_cdev, value);
+}
+
 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
 {
 	struct asus_wmi *asus;
@@ -656,6 +664,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 
 		asus->kbd_led_wk = led_val;
 		asus->kbd_led.name = "asus::kbd_backlight";
+		asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
 		asus->kbd_led.brightness_set = kbd_led_set;
 		asus->kbd_led.brightness_get = kbd_led_get;
 		asus->kbd_led.max_brightness = 3;
@@ -1745,6 +1754,15 @@ static void asus_wmi_notify(u32 value, void *context)
 		}
 	}
 
+	if (code == NOTIFY_KBD_BRTUP) {
+		do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1);
+		goto exit;
+	}
+	if (code == NOTIFY_KBD_BRTDWN) {
+		do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1);
+		goto exit;
+	}
+
 	if (is_display_toggle(code) &&
 	    asus->driver->quirks->no_display_toggle)
 		goto exit;
Signature · 1 line
2.11.0
author
#1 lore raw

PATCH v3 2/2 platform/x86: asus-wmi: Add keyboard backlight toggle support

Some ASUS laptops like UX550GE has hotkey (Fn+F7) for keyboard backlight toggle which would emit the scan code 0xc7 each keypress. On the UX550GE, the max keyboard brightness level is 3 so the toggle would not be simply on/off the led but need to be cyclic. Per ASUS spec, it should increment the brightness for each keypress, then toggle(off) the LED when it already reached the max level.

---
 drivers/platform/x86/asus-wmi.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/platform/x86/asus-wmi.c +8 -0
index f2b9037f6ded..51dc019fa91d 100644
@@ -67,6 +67,7 @@ MODULE_LICENSE("GPL");
 #define NOTIFY_BRNDOWN_MAX		0x2e
 #define NOTIFY_KBD_BRTUP		0xc4
 #define NOTIFY_KBD_BRTDWN		0xc5
+#define NOTIFY_KBD_BRTTOGGLE		0xc7
 
 /* WMI Methods */
 #define ASUS_WMI_METHODID_SPEC	        0x43455053 /* BIOS SPECification */
@@ -1762,6 +1763,13 @@ static void asus_wmi_notify(u32 value, void *context)
 		do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1);
 		goto exit;
 	}
+	if (code == NOTIFY_KBD_BRTTOGGLE) {
+		if (asus->kbd_led_wk == asus->kbd_led.max_brightness)
+			do_kbd_led_set(&asus->kbd_led, 0);
+		else
+			do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1);
+		goto exit;
+	}
 
 	if (is_display_toggle(code) &&
 	    asus->driver->quirks->no_display_toggle)
Signature · 1 line
2.11.0
author
#2 lore raw
In reply to Chris Chiu
Quoted 85 lines · Chris Chiu

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

---
 drivers/platform/x86/asus-wmi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/platform/x86/asus-wmi.c +22 -5
index 1f6e68f0b646..f2b9037f6ded 100644
@@ -460,6 +460,7 @@ static void kbd_led_update(struct work_struct *work)
                ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
 
        asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
+       led_classdev_notify_brightness_hw_changed(&asus->kbd_led, asus->kbd_led_wk);
 }
 
 static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
@@ -490,15 +491,16 @@ static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
        return retval;
 }
 
-static void kbd_led_set(struct led_classdev *led_cdev,
-                       enum led_brightness value)
+static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
 {
        struct asus_wmi *asus;
+       int max_level;
 
        asus = container_of(led_cdev, struct asus_wmi, kbd_led);
+       max_level = asus->kbd_led.max_brightness;
 
-       if (value > asus->kbd_led.max_brightness)
-               value = asus->kbd_led.max_brightness;
+       if (value > max_level)
+               value = max_level;
        else if (value < 0)
                value = 0;
 
@@ -506,6 +508,12 @@ static void kbd_led_set(struct led_classdev *led_cdev,
        queue_work(asus->led_workqueue, &asus->kbd_led_work);
 }
 
+static void kbd_led_set(struct led_classdev *led_cdev,
+                       enum led_brightness value)
+{
+       do_kbd_led_set(led_cdev, value);
+}
+
 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
 {
        struct asus_wmi *asus;
@@ -656,6 +664,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 
                asus->kbd_led_wk = led_val;
                asus->kbd_led.name = "asus::kbd_backlight";
+               asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
                asus->kbd_led.brightness_set = kbd_led_set;
                asus->kbd_led.brightness_get = kbd_led_get;
                asus->kbd_led.max_brightness = 3;
@@ -1745,6 +1754,15 @@ static void asus_wmi_notify(u32 value, void *context)
                }
        }
 
+       if (code == NOTIFY_KBD_BRTUP) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1);
+               goto exit;
+       }
+       if (code == NOTIFY_KBD_BRTDWN) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1);
+               goto exit;
+       }
+
        if (is_display_toggle(code) &&
            asus->driver->quirks->no_display_toggle)
                goto exit;
--
Quoted 2 lines

2.11.0

Gentle ping. Any comment for the v3 patch?

Chris

#3 lore raw
Quoted 9 lines · Chris Chiu
Quoted 8 lines · Chris Chiu

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

LGTM, I'm about to push it to my review and testing queue, so, we will have 1 day or so time to gather objections if any.
Thanks!

Quoted 83 lines
Quoted 77 lines
---
 drivers/platform/x86/asus-wmi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/platform/x86/asus-wmi.c +22 -5
index 1f6e68f0b646..f2b9037f6ded 100644
@@ -460,6 +460,7 @@ static void kbd_led_update(struct work_struct *work)
                ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
 
        asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
+       led_classdev_notify_brightness_hw_changed(&asus->kbd_led, asus->kbd_led_wk);
 }
 
 static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
@@ -490,15 +491,16 @@ static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
        return retval;
 }
 
-static void kbd_led_set(struct led_classdev *led_cdev,
-                       enum led_brightness value)
+static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
 {
        struct asus_wmi *asus;
+       int max_level;
 
        asus = container_of(led_cdev, struct asus_wmi, kbd_led);
+       max_level = asus->kbd_led.max_brightness;
 
-       if (value > asus->kbd_led.max_brightness)
-               value = asus->kbd_led.max_brightness;
+       if (value > max_level)
+               value = max_level;
        else if (value < 0)
                value = 0;
 
@@ -506,6 +508,12 @@ static void kbd_led_set(struct led_classdev *led_cdev,
        queue_work(asus->led_workqueue, &asus->kbd_led_work);
 }
 
+static void kbd_led_set(struct led_classdev *led_cdev,
+                       enum led_brightness value)
+{
+       do_kbd_led_set(led_cdev, value);
+}
+
 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
 {
        struct asus_wmi *asus;
@@ -656,6 +664,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 
                asus->kbd_led_wk = led_val;
                asus->kbd_led.name = "asus::kbd_backlight";
+               asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
                asus->kbd_led.brightness_set = kbd_led_set;
                asus->kbd_led.brightness_get = kbd_led_get;
                asus->kbd_led.max_brightness = 3;
@@ -1745,6 +1754,15 @@ static void asus_wmi_notify(u32 value, void *context)
                }
        }
 
+       if (code == NOTIFY_KBD_BRTUP) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1);
+               goto exit;
+       }
+       if (code == NOTIFY_KBD_BRTDWN) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1);
+               goto exit;
+       }
+
        if (is_display_toggle(code) &&
            asus->driver->quirks->no_display_toggle)
                goto exit;
--
Quoted 2 lines

2.11.0

Gentle ping. Any comment for the v3 patch?

Chris

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#4 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Chris Chiu
Quoted 5 lines · Chris Chiu

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

LGTM, I'm about to push it to my review and testing queue, so, we will have 1 day or so time to gather objections if any.
Thanks!

Gentle ping. How's the review so far? Maybe need more time for more info?

Chris

Quoted 89 lines
Quoted 82 lines
Quoted 77 lines
---
 drivers/platform/x86/asus-wmi.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/platform/x86/asus-wmi.c +22 -5
index 1f6e68f0b646..f2b9037f6ded 100644
@@ -460,6 +460,7 @@ static void kbd_led_update(struct work_struct *work)
                ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
 
        asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
+       led_classdev_notify_brightness_hw_changed(&asus->kbd_led, asus->kbd_led_wk);
 }
 
 static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
@@ -490,15 +491,16 @@ static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
        return retval;
 }
 
-static void kbd_led_set(struct led_classdev *led_cdev,
-                       enum led_brightness value)
+static void do_kbd_led_set(struct led_classdev *led_cdev, int value)
 {
        struct asus_wmi *asus;
+       int max_level;
 
        asus = container_of(led_cdev, struct asus_wmi, kbd_led);
+       max_level = asus->kbd_led.max_brightness;
 
-       if (value > asus->kbd_led.max_brightness)
-               value = asus->kbd_led.max_brightness;
+       if (value > max_level)
+               value = max_level;
        else if (value < 0)
                value = 0;
 
@@ -506,6 +508,12 @@ static void kbd_led_set(struct led_classdev *led_cdev,
        queue_work(asus->led_workqueue, &asus->kbd_led_work);
 }
 
+static void kbd_led_set(struct led_classdev *led_cdev,
+                       enum led_brightness value)
+{
+       do_kbd_led_set(led_cdev, value);
+}
+
 static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
 {
        struct asus_wmi *asus;
@@ -656,6 +664,7 @@ static int asus_wmi_led_init(struct asus_wmi *asus)
 
                asus->kbd_led_wk = led_val;
                asus->kbd_led.name = "asus::kbd_backlight";
+               asus->kbd_led.flags = LED_BRIGHT_HW_CHANGED;
                asus->kbd_led.brightness_set = kbd_led_set;
                asus->kbd_led.brightness_get = kbd_led_get;
                asus->kbd_led.max_brightness = 3;
@@ -1745,6 +1754,15 @@ static void asus_wmi_notify(u32 value, void *context)
                }
        }
 
+       if (code == NOTIFY_KBD_BRTUP) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk + 1);
+               goto exit;
+       }
+       if (code == NOTIFY_KBD_BRTDWN) {
+               do_kbd_led_set(&asus->kbd_led, asus->kbd_led_wk - 1);
+               goto exit;
+       }
+
        if (is_display_toggle(code) &&
            asus->driver->quirks->no_display_toggle)
                goto exit;
--
Quoted 2 lines

2.11.0

Gentle ping. Any comment for the v3 patch?

Quoted 1 line

Chris

--
With Best Regards,
Andy Shevchenko

#5 lore raw
Quoted 13 lines · Chris Chiu
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Chris Chiu
Quoted 8 lines · Chris Chiu

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

Quoted 6 lines
Quoted 4 lines

LGTM, I'm about to push it to my review and testing queue, so, we will have 1 day or so time to gather objections if any.
Thanks!

Gentle ping. How's the review so far? Maybe need more time for more info?

Sorry, I thought we have no objections and I pushed it to our for-next quite time ago [1].
Should I do something differently?

[1]: http://git.infradead.org/linux-platform-drivers-x86.git/commitdiff/dbb3d78f61badeadc7448f9d88a070a76612860f

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#6 lore raw
Quoted 25 lines · Andy Shevchenko
Quoted 13 lines · Chris Chiu
Quoted 11 lines · Andy Shevchenko
Quoted 9 lines · Chris Chiu
Quoted 8 lines · Chris Chiu

Make asus-wmi notify on hotkey kbd brightness changes, listen for brightness events and update the brightness directly in the driver. Create new do_kbd_led_set function for in-driver update, and leave kbd_led_set for original led_classdev call path.

Update the brightness by led_classdev_notify_brightness_hw_changed. This will allow userspace to monitor (poll) for brightness changes on the LED without reporting via input keymapping.

Quoted 6 lines
Quoted 4 lines

LGTM, I'm about to push it to my review and testing queue, so, we will have 1 day or so time to gather objections if any.
Thanks!

Gentle ping. How's the review so far? Maybe need more time for more info?

Sorry, I thought we have no objections and I pushed it to our for-next quite time ago [1].
Should I do something differently?

Quoted 5 lines

[1]: http://git.infradead.org/linux-platform-drivers-x86.git/commitdiff/dbb3d78f61badeadc7448f9d88a070a76612860f

--
With Best Regards,
Andy Shevchenko

It's good to know. Thank you.

Chris