From patchwork Sun Mar 5 00:50:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matjaz Hegedic X-Patchwork-Id: 9604373 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 834406016C for ; Sun, 5 Mar 2017 00:51:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 779B52833B for ; Sun, 5 Mar 2017 00:51:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6893728365; Sun, 5 Mar 2017 00:51:31 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 B8A2A2833B for ; Sun, 5 Mar 2017 00:51:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752317AbdCEAva (ORCPT ); Sat, 4 Mar 2017 19:51:30 -0500 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35760 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752186AbdCEAv3 (ORCPT ); Sat, 4 Mar 2017 19:51:29 -0500 Received: by mail-wr0-f195.google.com with SMTP id u108so13545010wrb.2 for ; Sat, 04 Mar 2017 16:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=u2jmZk+POOD8c7qZW0sVmyaK+dnulDdB9KrjlrU+oRw=; b=h5HfMtJ4/Q6wSWs3cHoxMob/lpaDuENjbJW79VaW3vUYxCNSHLFQRegeHH8KIIgSZj mFdyS6ZSNtPA4FcOVZ1CV3X1dIpqXRZtdVcIb/vhEWvbM9/jLt+0c3xnyOf7iybQ3N5E eWkOUGx0libSOVSQU137rpVECOAc8eZC+L3HvkjVN+34VCacdVrNZADxx2Kld/t8zx2h GzU835J518TgNQZUsG3VjWW9W0fp9mNODRoNzWZPSOX8affXajfBtIvxzFWWMXxpDopC VB3QUYtkpgbdLhnEHhq58gRG4+IS3FEawzC/ST4226usIiXGOWemnjvBIYO1cdAjcoi0 PnJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=u2jmZk+POOD8c7qZW0sVmyaK+dnulDdB9KrjlrU+oRw=; b=ohrY5pii+/jmAvGRTk+rs0HOIbSBjeeSBN8KbMWvbRzVY59bzU2linEroRnPnr0NH8 OSXmI5GaR82/hqDq6Ad8sjN+bV98bP9SllrVdlgKREHEkTwu+um3hNhXxRjNv6CBABpA QHaCDpYT/WIPtQofWmQAGiFXMTSnhgjX94uViDJqT94XiGH7MlqI1RaX317aL4QuRibI lVeHFcAEc6f0C6Qxy50AeTJzsg7opRESL858MdvV9BS4jmCNP5oME0BWXWEBchKCBDdE VHndk+xGflh5UGCmxJr+VDVUMuL/rEO3LL8S/Q+UMqR2+ohlxyKbT1K0uOONlT4AExMH 8cUQ== X-Gm-Message-State: AMke39lIgweuGlTcYQUTjdZV4LwSl5LKjJb//LVUlYT+lvVE4XHifbG0JyO63XeclZYxHA== X-Received: by 10.223.135.215 with SMTP id c23mr8171140wrc.135.1488675087170; Sat, 04 Mar 2017 16:51:27 -0800 (PST) Received: from X205TA.upc.at (213-47-29-34.cable.dynamic.surfer.at. [213.47.29.34]) by smtp.gmail.com with ESMTPSA id d42sm21022053wrd.7.2017.03.04.16.51.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 04 Mar 2017 16:51:25 -0800 (PST) From: Matjaz Hegedic To: jikos@kernel.org Cc: benjamin.tissoires@redhat.com, linux-input@vger.kernel.org, Matjaz Hegedic Subject: [PATCH] HID: asus: fix special key support for ASUS I2C keyboards Date: Sun, 5 Mar 2017 01:50:34 +0100 Message-Id: <1488675034-7220-1-git-send-email-matjaz.hegedic@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On some ASUS notebooks (EeeBook X205TA, VivoBook E200HA) the built-in keyboard uses a vendor-specific HID Usage Page for its special keys (airplane mode, brightness, volume, etc.) which require remapping. This cannot be resolved without a kernel driver (eg. udev/hwdb). In addition, sloppy vendor implementation produces two tables almost full of dummy usages, which misrepresent this devices' capabilities and causes X to see it as a pointer/joystick device. This patch adds the appropriate re-mappings and ignores the incorrect dummy values. Signed-off-by: Matjaz Hegedic --- drivers/hid/hid-asus.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index 70b12f8..a6492ec 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -1,12 +1,14 @@ /* * HID driver for Asus notebook built-in keyboard. - * Fixes small logical maximum to match usage maximum. + * Fixes small logical maximum to match usage maximum, + * adds special key support, and ignores dummy usages. * * Currently supported devices are: * EeeBook X205TA * VivoBook E200HA * * Copyright (c) 2016 Yusuke Fujimaki + * Copyright (c) 2017 Matjaz Hegedic * * This module based on hid-ortek by * Copyright (c) 2010 Johnathon Harris @@ -36,8 +38,11 @@ MODULE_AUTHOR("Yusuke Fujimaki "); MODULE_AUTHOR("Brendan McGrath "); MODULE_AUTHOR("Victor Vlasenko "); MODULE_AUTHOR("Frederik Wenigwieser "); +MODULE_AUTHOR("Matjaz Hegedic "); MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); +#define HID_UP_ASUSVENDOR 0xff310000 + #define FEATURE_REPORT_ID 0x0d #define INPUT_REPORT_ID 0x5d @@ -63,15 +68,20 @@ MODULE_DESCRIPTION("Asus HID Keyboard and TouchPad"); #define QUIRK_NO_INIT_REPORTS BIT(1) #define QUIRK_SKIP_INPUT_MAPPING BIT(2) #define QUIRK_IS_MULTITOUCH BIT(3) +#define QUIRK_NO_CONSUMER_USAGES BIT(4) #define KEYBOARD_QUIRKS (QUIRK_FIX_NOTEBOOK_REPORT | \ - QUIRK_NO_INIT_REPORTS) + QUIRK_NO_INIT_REPORTS | \ + QUIRK_NO_CONSUMER_USAGES) #define TOUCHPAD_QUIRKS (QUIRK_NO_INIT_REPORTS | \ QUIRK_SKIP_INPUT_MAPPING | \ QUIRK_IS_MULTITOUCH) #define TRKID_SGN ((TRKID_MAX + 1) >> 1) +#define asus_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, \ + max, EV_KEY, (c)) + struct asus_drvdata { unsigned long quirks; struct input_dev *input; @@ -213,6 +223,42 @@ static int asus_input_mapping(struct hid_device *hdev, return -1; } + if ((usage->hid & HID_USAGE_PAGE) == HID_UP_ASUSVENDOR) { + switch (usage->hid & HID_USAGE) { + case 0x10: + asus_map_key_clear(KEY_BRIGHTNESSDOWN); break; + case 0x20: + asus_map_key_clear(KEY_BRIGHTNESSUP); break; + case 0x35: + asus_map_key_clear(KEY_DISPLAY_OFF); break; + case 0x6b: + asus_map_key_clear(KEY_F21); break; + case 0x6c: + asus_map_key_clear(KEY_SLEEP); break; + case 0x88: + asus_map_key_clear(KEY_RFKILL); break; + default: + /* ASUS lazily declares 256 usages, ignore the rest */ + return -1; + } + return 1; + } + + if (drvdata->quirks & QUIRK_NO_CONSUMER_USAGES && + (usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) { + switch (usage->hid & HID_USAGE) { + case 0xe2: /* Mute */ + case 0xe9: /* Volume up */ + case 0xea: /* Volume down */ + return 0; + default: + /* Ignore dummy Consumer usages which make the + * keyboard incorrectly appear as a pointer device. + */ + return -1; + } + } + return 0; }