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