ee81a40
From 82e71b57b1b4347126b1ffd7b2beed2bc8b795bd Mon Sep 17 00:00:00 2001
ee81a40
From: Christian Kellner <christian@kellner.me>
ee81a40
Date: Tue, 28 Feb 2017 17:10:57 +0100
ee81a40
Subject: [PATCH 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys
ee81a40
ee81a40
The T470, X270 emits new hkey events in the 0x1311 - 0x1315 range.
ee81a40
According to the user manual they should launch a user selected
ee81a40
favorite application (star icon, 0x1311), snipping tool (0x1312,
ee81a40
currently ignored), enable/disable bluetooth (0x1314) and open they
ee81a40
keyboard settings (0x1315).
ee81a40
ee81a40
The third nibble (0xf00) is used to differentiate between the original
ee81a40
hotkeys, the adaptive keyboard codes and the new, additional ones.
ee81a40
ee81a40
Signed-off-by: Christian Kellner <ckellner@redhat.com>
ee81a40
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
ee81a40
Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
ee81a40
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
ee81a40
---
ee81a40
 drivers/platform/x86/thinkpad_acpi.c | 91 +++++++++++++++++++++++++++++++-----
ee81a40
 1 file changed, 79 insertions(+), 12 deletions(-)
ee81a40
ee81a40
diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
ee81a40
index e2b962f..7b6cb0c 100644
ee81a40
--- a/drivers/platform/x86/thinkpad_acpi.c
ee81a40
+++ b/drivers/platform/x86/thinkpad_acpi.c
ee81a40
@@ -1945,6 +1945,15 @@ enum {	/* hot key scan codes (derived from ACPI DSDT) */
ee81a40
 	TP_ACPI_HOTKEYSCAN_CAMERA_MODE,
ee81a40
 	TP_ACPI_HOTKEYSCAN_ROTATE_DISPLAY,
ee81a40
 
ee81a40
+	/* Lenovo extended keymap, starting at 0x1300 */
ee81a40
+	TP_ACPI_HOTKEYSCAN_EXTENDED_START,
ee81a40
+	/* first new observed key (star, favorites) is 0x1311 */
ee81a40
+	TP_ACPI_HOTKEYSCAN_STAR = 69,
ee81a40
+	TP_ACPI_HOTKEYSCAN_CLIPPING_TOOL2,
ee81a40
+	TP_ACPI_HOTKEYSCAN_UNK25,
ee81a40
+	TP_ACPI_HOTKEYSCAN_BLUETOOTH,
ee81a40
+	TP_ACPI_HOTKEYSCAN_KEYBOARD,
ee81a40
+
ee81a40
 	/* Hotkey keymap size */
ee81a40
 	TPACPI_HOTKEY_MAP_LEN
ee81a40
 };
ee81a40
@@ -3252,6 +3261,15 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
ee81a40
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
 		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+
ee81a40
+		/* No assignment, used for newer Lenovo models */
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN
ee81a40
+
ee81a40
 		},
ee81a40
 
ee81a40
 	/* Generic keymap for Lenovo ThinkPads */
ee81a40
@@ -3337,6 +3355,29 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
ee81a40
 		KEY_RESERVED,        /* Microphone cancellation */
ee81a40
 		KEY_RESERVED,        /* Camera mode */
ee81a40
 		KEY_RESERVED,        /* Rotate display, 0x116 */
ee81a40
+
ee81a40
+		/*
ee81a40
+		 * These are found in 2017 models (e.g. T470s, X270).
ee81a40
+		 * The lowest known value is 0x311, which according to
ee81a40
+		 * the manual should launch a user defined favorite
ee81a40
+		 * application.
ee81a40
+		 *
ee81a40
+		 * The offset for these is TP_ACPI_HOTKEYSCAN_EXTENDED_START,
ee81a40
+		 * corresponding to 0x34.
ee81a40
+		 */
ee81a40
+
ee81a40
+		/* (assignments unknown, please report if found) */
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN,
ee81a40
+		KEY_UNKNOWN,
ee81a40
+
ee81a40
+		KEY_FAVORITES,       /* Favorite app, 0x311 */
ee81a40
+		KEY_RESERVED,        /* Clipping tool */
ee81a40
+		KEY_RESERVED,
ee81a40
+		KEY_BLUETOOTH,       /* Bluetooth */
ee81a40
+		KEY_KEYBOARD         /* Keyboard, 0x315 */
ee81a40
 		},
ee81a40
 	};
ee81a40
 
ee81a40
@@ -3747,8 +3788,9 @@ static bool adaptive_keyboard_hotkey_notify_hotkey(unsigned int scancode)
ee81a40
 
ee81a40
 	default:
ee81a40
 		if (scancode < FIRST_ADAPTIVE_KEY ||
ee81a40
-		    scancode >= FIRST_ADAPTIVE_KEY + TPACPI_HOTKEY_MAP_LEN -
ee81a40
-				TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
ee81a40
+		    scancode >= FIRST_ADAPTIVE_KEY +
ee81a40
+		    TP_ACPI_HOTKEYSCAN_EXTENDED_START -
ee81a40
+		    TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
ee81a40
 			pr_info("Unhandled adaptive keyboard key: 0x%x\n",
ee81a40
 					scancode);
ee81a40
 			return false;
ee81a40
@@ -3779,19 +3821,44 @@ static bool hotkey_notify_hotkey(const u32 hkey,
ee81a40
 	*send_acpi_ev = true;
ee81a40
 	*ignore_acpi_ev = false;
ee81a40
 
ee81a40
-	/* HKEY event 0x1001 is scancode 0x00 */
ee81a40
-	if (scancode > 0 && scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
ee81a40
-		scancode--;
ee81a40
-		if (!(hotkey_source_mask & (1 << scancode))) {
ee81a40
-			tpacpi_input_send_key_masked(scancode);
ee81a40
-			*send_acpi_ev = false;
ee81a40
-		} else {
ee81a40
-			*ignore_acpi_ev = true;
ee81a40
+	/*
ee81a40
+	 * Original events are in the 0x10XX range, the adaptive keyboard
ee81a40
+	 * found in 2014 X1 Carbon emits events are of 0x11XX. In 2017
ee81a40
+	 * models, additional keys are emitted through 0x13XX.
ee81a40
+	 */
ee81a40
+	switch ((hkey >> 8) & 0xf) {
ee81a40
+	case 0:
ee81a40
+		if (scancode > 0 &&
ee81a40
+		    scancode <= TP_ACPI_HOTKEYSCAN_ADAPTIVE_START) {
ee81a40
+			/* HKEY event 0x1001 is scancode 0x00 */
ee81a40
+			scancode--;
ee81a40
+			if (!(hotkey_source_mask & (1 << scancode))) {
ee81a40
+				tpacpi_input_send_key_masked(scancode);
ee81a40
+				*send_acpi_ev = false;
ee81a40
+			} else {
ee81a40
+				*ignore_acpi_ev = true;
ee81a40
+			}
ee81a40
+			return true;
ee81a40
 		}
ee81a40
-		return true;
ee81a40
-	} else {
ee81a40
+		break;
ee81a40
+
ee81a40
+	case 1:
ee81a40
 		return adaptive_keyboard_hotkey_notify_hotkey(scancode);
ee81a40
+
ee81a40
+	case 3:
ee81a40
+		/* Extended keycodes start at 0x300 and our offset into the map
ee81a40
+		 * TP_ACPI_HOTKEYSCAN_EXTENDED_START. The calculated scancode
ee81a40
+		 * will be positive, but might not be in the correct range.
ee81a40
+		 */
ee81a40
+		scancode -= (0x300 - TP_ACPI_HOTKEYSCAN_EXTENDED_START);
ee81a40
+		if (scancode >= TP_ACPI_HOTKEYSCAN_EXTENDED_START &&
ee81a40
+		    scancode < TPACPI_HOTKEY_MAP_LEN) {
ee81a40
+			tpacpi_input_send_key(scancode);
ee81a40
+			return true;
ee81a40
+		}
ee81a40
+		break;
ee81a40
 	}
ee81a40
+
ee81a40
 	return false;
ee81a40
 }
ee81a40
 
ee81a40
-- 
ee81a40
2.9.4
ee81a40