]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
platform/x86: thinkpad_acpi: add mapping for new hotkeys
authorChristian Kellner <christian@kellner.me>
Wed, 19 Jul 2017 04:56:58 +0000 (21:56 -0700)
committerKleber Sacilotto de Souza <kleber.souza@canonical.com>
Wed, 9 Aug 2017 14:38:13 +0000 (16:38 +0200)
BugLink: http://bugs.launchpad.net/bugs/1705169
The T470, X270 emits new hkey events in the 0x1311 - 0x1315 range.
According to the user manual they should launch a user selected
favorite application (star icon, 0x1311), snipping tool (0x1312,
currently ignored), enable/disable bluetooth (0x1314) and open they
keyboard settings (0x1315).

The third nibble (0xf00) is used to differentiate between the original
hotkeys, the adaptive keyboard codes and the new, additional ones.

Signed-off-by: Christian Kellner <ckellner@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
(cherry picked from commit 696c6523ec8f2a8f30f3dffef7e382f0fe5c2010)
Signed-off-by: Alex Hung <alex.hung@canonical.com>
Acked-by: Colin King <colin.king@canonical.com>
Acked-by: Hui Wang <Wang <hui.wang@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
drivers/platform/x86/thinkpad_acpi.c

index 59b704ac38622b02e20860cb39d2830183cc4fb6..4f2b204cefced0ee85fe3c51ddf80f35656b7745 100644 (file)
@@ -1946,6 +1946,15 @@ enum {   /* hot key scan codes (derived from ACPI DSDT) */
        TP_ACPI_HOTKEYSCAN_CAMERA_MODE,
        TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY,
 
+       /* Lenovo extended keymap, starting at 0x1300 */
+       TP_ACPI_HOTKEYSCAN_EXTENDED_START,
+       /* first new observed key (star, favorites) is 0x1311 */
+       TP_ACPI_HOTKEYSCAN_STAR = 69,
+       TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2,
+       TP_ACPI_HOTKEYSCAN_UNK25,
+       TP_ACPI_HOTKEYSCAN_BLUETOOTH,
+       TP_ACPI_HOTKEYSCAN_KEYBOARD,
+
        /* Hotkey keymap size */
        TPACPI_HOTKEY_MAP_LEN
 };
@@ -3253,6 +3262,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
                KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+
+               /* No assignment, used for newer Lenovo models */
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN
+
                },
 
        /* Generic keymap for Lenovo ThinkPads */
@@ -3338,6 +3356,29 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
                KEY_RESERVED,        /* Microphone cancellation */
                KEY_RESERVED,        /* Camera mode */
                KEY_RESERVED,        /* Rotate display, 0x116 */
+
+               /*
+                * These are found in 2017 models (e.g. T470s, X270).
+                * The lowest known value is 0x311, which according to
+                * the manual should launch a user defined favorite
+                * application.
+                *
+                * The offset for these is TP_ACPI_HOTKEYSCAN_EXTENDED_START,
+                * corresponding to 0x34.
+                */
+
+               /* (assignments unknown, please report if found) */
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
+               KEY_UNKNOWN,
+
+               KEY_FAVORITES,       /* Favorite app, 0x311 */
+               KEY_RESERVED,        /* Clipping tool */
+               KEY_RESERVED,
+               KEY_BLUETOOTH,       /* Bluetooth */
+               KEY_KEYBOARD         /* Keyboard, 0x315 */
                },
        };
 
@@ -3748,8 +3789,9 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
 
        default:
                if (scancode < FIRST_ADAPTIVE_KEY ||
-                   scancode >= FIRST_ADAPTIVE_KEY + TPACPI_HOTKEY_MAP_LEN -
-                               TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
+                   scancode >= FIRST_ADAPTIVE_KEY +
+                   TP_ACPI_HOTKEYSCAN_EXTENDED_START -
+                   TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
                        pr_info("Unhandled adaptive keyboard key: 0x%x\n",
                                        scancode);
                        return false;
@@ -3780,19 +3822,44 @@ static bool hotkey_notify_hotkey(const u32 hkey,
        *send_acpi_ev = true;
        *ignore_acpi_ev = false;
 
-       /* HKEY event 0x1001 is scancode 0x00 */
-       if (scancode > 0 && scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
-               scancode--;
-               if (!(hotkey_source_mask & (1 << scancode))) {
-                       tpacpi_input_send_key_masked(scancode);
-                       *send_acpi_ev = false;
-               } else {
-                       *ignore_acpi_ev = true;
+       /*
+        * Original events are in the 0x10XX range, the adaptive keyboard
+        * found in 2014 X1 Carbon emits events are of 0x11XX. In 2017
+        * models, additional keys are emitted through 0x13XX.
+        */
+       switch ((hkey >> 8) & 0xf) {
+       case 0:
+               if (scancode > 0 &&
+                   scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
+                       /* HKEY event 0x1001 is scancode 0x00 */
+                       scancode--;
+                       if (!(hotkey_source_mask & (1 << scancode))) {
+                               tpacpi_input_send_key_masked(scancode);
+                               *send_acpi_ev = false;
+                       } else {
+                               *ignore_acpi_ev = true;
+                       }
+                       return true;
                }
-               return true;
-       } else {
+               break;
+
+       case 1:
                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 false;
 }