From patchwork Tue Feb 28 16:10:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Kellner X-Patchwork-Id: 9596131 X-Patchwork-Delegate: andy.shevchenko@gmail.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7DA7660574 for ; Tue, 28 Feb 2017 16:11:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6F7CD27D85 for ; Tue, 28 Feb 2017 16:11:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6435D2853E; Tue, 28 Feb 2017 16:11:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8ABE27F90 for ; Tue, 28 Feb 2017 16:11:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751709AbdB1QLd (ORCPT ); Tue, 28 Feb 2017 11:11:33 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16109 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752029AbdB1QLc (ORCPT ); Tue, 28 Feb 2017 11:11:32 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AB3181239; Tue, 28 Feb 2017 16:11:25 +0000 (UTC) Received: from localhost.localdomain (dhcp-64-73.muc.redhat.com [10.32.64.73]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1SGBJuW022509; Tue, 28 Feb 2017 11:11:23 -0500 From: Christian Kellner To: Henrique de Moraes Holschuh , Darren Hart , Andy Shevchenko , ibm-acpi-devel@lists.sourceforge.net, platform-driver-x86@vger.kernel.org Cc: Christian Kellner , Christian Kellner Subject: [PATCH v2 2/2] platform/x86: thinkpad_acpi: add mapping for new hotkeys Date: Tue, 28 Feb 2017 17:10:57 +0100 Message-Id: <20170228161057.28394-2-ckellner@redhat.com> In-Reply-To: <20170228161057.28394-1-ckellner@redhat.com> References: <20170228161057.28394-1-ckellner@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 28 Feb 2017 16:11:25 +0000 (UTC) Sender: platform-driver-x86-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: platform-driver-x86@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christian Kellner 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 Reviewed-by: Hans de Goede Acked-by: Henrique de Moraes Holschuh --- Changes in v2: -Reword comments to also mention the X270 -No need to initialize TP_ACPI_HOTKEYSCAN_EXTENDED_START to '52' --- drivers/platform/x86/thinkpad_acpi.c | 91 +++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 12 deletions(-) diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c index e2b962f0fdc4..7b6cb0c69b02 100644 --- a/drivers/platform/x86/thinkpad_acpi.c +++ b/drivers/platform/x86/thinkpad_acpi.c @@ -1945,6 +1945,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 }; @@ -3252,6 +3261,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 */ @@ -3337,6 +3355,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 */ }, }; @@ -3747,8 +3788,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; @@ -3779,19 +3821,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; }