platform/x86: thinkpad_acpi: Add hotkey_notify_extended_hotkey() helper
authorHans de Goede <hdegoede@redhat.com>
Tue, 5 Oct 2021 20:23:18 +0000 (22:23 +0200)
committerHans de Goede <hdegoede@redhat.com>
Thu, 14 Oct 2021 11:16:57 +0000 (13:16 +0200)
Factor the extended hotkey handling out of hotkey_notify_hotkey() and
into a new hotkey_notify_extended_hotkey() helper.

This is a preparation patch for adding support the privacy-screen hotkey
toggle (which needs some special handling, it should NOT send an evdev
key-event to userspace...).

Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Mark Pearson <markpearson@lenovo.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211005202322.700909-7-hdegoede@redhat.com
drivers/platform/x86/thinkpad_acpi.c

index 50ff04c84650cddae9fc099eb56f994ff5e94912..83c88a8ebaf2d05b7aabef701bffdd8da8e8f7bd 100644 (file)
@@ -3885,6 +3885,24 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
        }
 }
 
+static bool hotkey_notify_extended_hotkey(const u32 hkey)
+{
+       unsigned int scancode;
+
+       /* Extended keycodes start at 0x300 and our offset into the map
+        * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
+        * will be positive, but might not be in the correct range.
+        */
+       scancode = (hkey & 0xfff) - (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
+       if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
+           scancode < TPACPI_HOTKEY_MAP_LEN) {
+               tpacpi_input_send_key(scancode);
+               return true;
+       }
+
+       return false;
+}
+
 static bool hotkey_notify_hotkey(const u32 hkey,
                                 bool *send_acpi_ev,
                                 bool *ignore_acpi_ev)
@@ -3919,17 +3937,7 @@ static bool hotkey_notify_hotkey(const u32 hkey,
                return adaptive_keyboard_hotkey_notify_hotkey(scancode);
 
        case 3:
-               /* Extended keycodes start at 0x300 and our offset into the map
-                * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
-                * will be positive, but might not be in the correct range.
-                */
-               scancode -= (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
-               if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
-                   scancode < TPACPI_HOTKEY_MAP_LEN) {
-                       tpacpi_input_send_key(scancode);
-                       return true;
-               }
-               break;
+               return hotkey_notify_extended_hotkey(hkey);
        }
 
        return false;