Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4304517pxu; Tue, 1 Dec 2020 01:23:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/TFB6xbH+AkFBhUzMh7H2+kelx/gsDuDG1Z/bp6woG28f7AVAl9zfDDcCr59LGoNhSuCS X-Received: by 2002:a17:906:b53:: with SMTP id v19mr2141420ejg.250.1606814599886; Tue, 01 Dec 2020 01:23:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606814599; cv=none; d=google.com; s=arc-20160816; b=0QkwdWsvs5kUStPdvVMrIF/GEtUT/YrSmpoD3UFk28+OVxvy+s0Xmhl4Gs9+oY2e6m 9PVj8B1w58PSwjH9YXZdC4GsjU+Lb+N88hvg6YfVu1lOYCOiPD2uewwmDd5hbX6vUGT8 Keu6feqfZl9Ye3sTERFysbZRlEF2poAYCTDco6igCuK5gep5P7BADX5qi9+4lKTC1oeJ MPNB6AnUlZehI+5t0cg8Pue0PbYZ0r7+ZYLERC+9x8f7ebt1hA5/EQKvxpIZExGRYZG+ ftvWz8UdnDtoJo/LOuu+CF0L1oJDYax78nk1IQn+U1PWLMg9mnTnmQIMD+ZNlraYZFgQ Iyaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5sBP40PzurCoBT1kuAM9G4tPHABDgcGfAD0xyekkils=; b=OvtGEKmRXDZG2uuKIu3vpkxaHmOYsB5xFGPOai5HQK1gKp5eOXhDQECDZ9GYZshxEW krQbITLWMR9KQ77ZniRTvspsmRbkXVupur2D9S7GOH+yC3M8klEAi6UqwvfXBuqMHeKF ZR/qDn9dhMLZmqDBi5fDGOxREw/YGXPLLncjpZUfMF0KRxHUb8pS9oDjltrvieSzcagI ziPmMxrvgT94QKxV2pjz2+pFRCXq7xtuvOj1kj8RA9oV+XAK8Y70c0yF4xuhb2FgAxyI RpLKR6aExCuedsVQGhJYykQkKH7HQ+xwleNxVOKen2KU+Bvf7yYrA/jXxAxCo9OL0I37 vHtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sgRj736k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i7si743230eds.423.2020.12.01.01.22.57; Tue, 01 Dec 2020 01:23:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sgRj736k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390388AbgLAJUC (ORCPT + 99 others); Tue, 1 Dec 2020 04:20:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:47086 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389580AbgLAJJg (ORCPT ); Tue, 1 Dec 2020 04:09:36 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B41C720809; Tue, 1 Dec 2020 09:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813736; bh=PhV5uaDhmqHw5CUW204MCd55v6G2ULGtBNvW9ZgaP6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sgRj736ksQ8AF/3wnJaFDanXg736t4QYoAlmWp5clVYqgx2i4aFExbjksMeX5WWN0 VGxIYJeEJL2DlMXgmmWPZnDhhTSYTr196ckF/DHM14CWCfOn+REdojJMlvtagFT7WX 79TPdOoOteLL5Nh48igf/5P8EDP0jCNmT/WgPRP8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hans de Goede , Jiri Kosina , Sasha Levin Subject: [PATCH 5.9 040/152] HID: ite: Replace ABS_MISC 120/121 events with touchpad on/off keypresses Date: Tue, 1 Dec 2020 09:52:35 +0100 Message-Id: <20201201084717.090190335@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084711.707195422@linuxfoundation.org> References: <20201201084711.707195422@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede [ Upstream commit 3c785a06dee99501a17f8e8cf29b2b7e3f1e94ea ] The usb-hid keyboard-dock for the Acer Switch 10 SW5-012 model declares an application and hid-usage page of 0x0088 for the INPUT(4) report which it sends. This reports contains 2 8-bit fields which are declared as HID_MAIN_ITEM_VARIABLE. The keyboard-touchpad combo never actually generates this report, except when the touchpad is toggled on/off with the Fn + F7 hotkey combo. The toggle on/off is handled inside the keyboard-dock, when the touchpad is toggled off it simply stops sending events. When the touchpad is toggled on/off an INPUT(4) report is generated with the first content byte set to 120/121, before this commit the kernel would report this as ABS_MISC 120/121 events. Patch the descriptor to replace the HID_MAIN_ITEM_VARIABLE with HID_MAIN_ITEM_RELATIVE (because no key-presss release events are send) and add mappings for the 0x00880078 and 0x00880079 usages to generate touchpad on/off key events when the touchpad is toggled on/off. Signed-off-by: Hans de Goede Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-ite.c | 61 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-ite.c b/drivers/hid/hid-ite.c index 044a93f3c1178..742c052b0110a 100644 --- a/drivers/hid/hid-ite.c +++ b/drivers/hid/hid-ite.c @@ -11,6 +11,48 @@ #include "hid-ids.h" +#define QUIRK_TOUCHPAD_ON_OFF_REPORT BIT(0) + +static __u8 *ite_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) +{ + unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + + if (quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) { + if (*rsize == 188 && rdesc[162] == 0x81 && rdesc[163] == 0x02) { + hid_info(hdev, "Fixing up ITE keyboard report descriptor\n"); + rdesc[163] = HID_MAIN_ITEM_RELATIVE; + } + } + + return rdesc; +} + +static int ite_input_mapping(struct hid_device *hdev, + struct hid_input *hi, struct hid_field *field, + struct hid_usage *usage, unsigned long **bit, + int *max) +{ + + unsigned long quirks = (unsigned long)hid_get_drvdata(hdev); + + if ((quirks & QUIRK_TOUCHPAD_ON_OFF_REPORT) && + (usage->hid & HID_USAGE_PAGE) == 0x00880000) { + if (usage->hid == 0x00880078) { + /* Touchpad on, userspace expects F22 for this */ + hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F22); + return 1; + } + if (usage->hid == 0x00880079) { + /* Touchpad off, userspace expects F23 for this */ + hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_F23); + return 1; + } + return -1; + } + + return 0; +} + static int ite_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { @@ -37,13 +79,27 @@ static int ite_event(struct hid_device *hdev, struct hid_field *field, return 0; } +static int ite_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ + int ret; + + hid_set_drvdata(hdev, (void *)id->driver_data); + + ret = hid_open_report(hdev); + if (ret) + return ret; + + return hid_hw_start(hdev, HID_CONNECT_DEFAULT); +} + static const struct hid_device_id ite_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_ITE, USB_DEVICE_ID_ITE8595) }, { HID_USB_DEVICE(USB_VENDOR_ID_258A, USB_DEVICE_ID_258A_6A88) }, /* ITE8595 USB kbd ctlr, with Synaptics touchpad connected to it. */ { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_SYNAPTICS, - USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012) }, + USB_DEVICE_ID_SYNAPTICS_ACER_SWITCH5_012), + .driver_data = QUIRK_TOUCHPAD_ON_OFF_REPORT }, /* ITE8910 USB kbd ctlr, with Synaptics touchpad connected to it. */ { HID_DEVICE(BUS_USB, HID_GROUP_GENERIC, USB_VENDOR_ID_SYNAPTICS, @@ -55,6 +111,9 @@ MODULE_DEVICE_TABLE(hid, ite_devices); static struct hid_driver ite_driver = { .name = "itetech", .id_table = ite_devices, + .probe = ite_probe, + .report_fixup = ite_report_fixup, + .input_mapping = ite_input_mapping, .event = ite_event, }; module_hid_driver(ite_driver); -- 2.27.0