platform/x86: dell-*: Call new led hw_changed API on kbd brightness change
authorHans de Goede <hdegoede@redhat.com>
Thu, 16 Mar 2017 10:55:35 +0000 (11:55 +0100)
committerDarren Hart (VMware) <dvhart@infradead.org>
Thu, 13 Apr 2017 17:12:46 +0000 (10:12 -0700)
Make dell-wmi notify on hotkey kbd brightness changes, listen for this
in dell-laptop and call led_classdev_notify_brightness_hw_changed.

This will allow userspace to monitor (poll) for brightness changes on
these LEDs caused by the hotkey.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Pali Rohár <pali.rohar@gmail.com>
Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
drivers/platform/x86/dell-laptop.c
drivers/platform/x86/dell-wmi.c

index da185fb2a621a7a2ab516c2ff0df0c4497761fd4..1cd258b790e8340a312830197d1c6ecd1711117e 100644 (file)
@@ -1984,6 +1984,7 @@ out:
 
 static struct led_classdev kbd_led = {
        .name           = "dell::kbd_backlight",
+       .flags          = LED_BRIGHT_HW_CHANGED,
        .brightness_set_blocking = kbd_led_level_set,
        .brightness_get = kbd_led_level_get,
        .groups         = kbd_led_groups,
@@ -1991,6 +1992,8 @@ static struct led_classdev kbd_led = {
 
 static int __init kbd_led_init(struct device *dev)
 {
+       int ret;
+
        kbd_init();
        if (!kbd_led_present)
                return -ENODEV;
@@ -2002,7 +2005,11 @@ static int __init kbd_led_init(struct device *dev)
                if (kbd_led.max_brightness)
                        kbd_led.max_brightness--;
        }
-       return led_classdev_register(dev, &kbd_led);
+       ret = led_classdev_register(dev, &kbd_led);
+       if (ret)
+               kbd_led_present = false;
+
+       return ret;
 }
 
 static void brightness_set_exit(struct led_classdev *led_cdev,
@@ -2019,6 +2026,26 @@ static void kbd_led_exit(void)
        led_classdev_unregister(&kbd_led);
 }
 
+static int dell_laptop_notifier_call(struct notifier_block *nb,
+                                    unsigned long action, void *data)
+{
+       switch (action) {
+       case DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED:
+               if (!kbd_led_present)
+                       break;
+
+               led_classdev_notify_brightness_hw_changed(&kbd_led,
+                                               kbd_led_level_get(&kbd_led));
+               break;
+       }
+
+       return NOTIFY_OK;
+}
+
+static struct notifier_block dell_laptop_notifier = {
+       .notifier_call = dell_laptop_notifier_call,
+};
+
 static int __init dell_init(void)
 {
        struct calling_interface_buffer *buffer;
@@ -2062,6 +2089,8 @@ static int __init dell_init(void)
                debugfs_create_file("rfkill", 0444, dell_laptop_dir, NULL,
                                    &dell_debugfs_fops);
 
+       dell_laptop_register_notifier(&dell_laptop_notifier);
+
        if (acpi_video_get_backlight_type() != acpi_backlight_vendor)
                return 0;
 
@@ -2113,6 +2142,7 @@ fail_platform_driver:
 
 static void __exit dell_exit(void)
 {
+       dell_laptop_unregister_notifier(&dell_laptop_notifier);
        debugfs_remove_recursive(dell_laptop_dir);
        if (quirks && quirks->touchpad_led)
                touchpad_led_exit();
index d921b26267e95aee293cc3122e37ced9ff82cff6..8a64c7967753c472e66b7f5de6344a81c3545a37 100644 (file)
@@ -329,6 +329,10 @@ static void dell_wmi_process_key(int type, int code)
        if (type == 0x0000 && code == 0xe025 && !wmi_requires_smbios_request)
                return;
 
+       if (key->keycode == KEY_KBDILLUMTOGGLE)
+               dell_laptop_call_notifier(
+                       DELL_LAPTOP_KBD_BACKLIGHT_BRIGHTNESS_CHANGED, NULL);
+
        sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true);
 }