From patchwork Mon Mar 8 17:42:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 12123085 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 675B6C4332B for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 446AB652AE for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbhCHRmQ (ORCPT ); Mon, 8 Mar 2021 12:42:16 -0500 Received: from [139.28.40.42] ([139.28.40.42]:54258 "EHLO tarta.nabijaczleweli.xyz" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S229813AbhCHRmF (ORCPT ); Mon, 8 Mar 2021 12:42:05 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 78CBF360009; Mon, 8 Mar 2021 18:42:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nabijaczleweli.xyz; s=202006; t=1615225324; bh=YnOwl8+70YJN74o6JcKP3I+Z0kVB3n4CoIz0cKVjjB4=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=bOJP0EJmXK7FTiFBUBMaJTRDlbwQBsWkQfRJyMGY1/fBQW/eZIK5G6RF+mvEeuAOl DpwK6GLuy94+v9H9mDVcX3ycSwHBXdPSUIBxMRz3UKAYKbSQp5nua88MD0c/J50fBQ A56xmiWk9icDIWBNcHzJaFDzOmxeDau8IWJKk1VV9SIIoHK4JO8+Qt/MZuEK8gxT/G 5D1ALmtVgoml6jT1Lg9FpNCJnJ5ypE7e7G3VBnGEW5oiDE3/z7F4FJNZGoZBs8IYab Cn1Y/DnVkEnWiGF6mkF3fQc6j5FjVPQinPVo6d9ogMC6iivWiF4g63e/T611gMOyx5 Vauh6lSR0lpcA== Date: Mon, 8 Mar 2021 18:42:03 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Benjamin Tissoires , Peter Hutterer , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] HID: multitouch: require Finger field to mark Win8 reports as MT Message-ID: <019fd182fe7358b14a2f9427572635e518cdb868.1615224800.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20210205 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This effectively changes collection_is_mt from contact ID in report->field to (device is Win8 => collection is finger) && contact ID in report->field Some devices erroneously report Pen for fingers, and Win8 stylus-on-touchscreen devices report contact ID, but mark the accompanying touchscreen device's collection correctly Signed-off-by: Ahelenia Ziemiańska --- drivers/hid/hid-multitouch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 8429ebe7097e..8580ace596c2 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -604,9 +604,13 @@ static struct mt_report_data *mt_allocate_report_data(struct mt_device *td, if (!(HID_MAIN_ITEM_VARIABLE & field->flags)) continue; - for (n = 0; n < field->report_count; n++) { - if (field->usage[n].hid == HID_DG_CONTACTID) - rdata->is_mt_collection = true; + if (field->logical == HID_DG_FINGER || td->hdev->group != HID_GROUP_MULTITOUCH_WIN_8) { + for (n = 0; n < field->report_count; n++) { + if (field->usage[n].hid == HID_DG_CONTACTID) { + rdata->is_mt_collection = true; + break; + } + } } } From patchwork Mon Mar 8 17:42:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 12123087 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69AD0C4332D for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FECD652B5 for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229730AbhCHRmR (ORCPT ); Mon, 8 Mar 2021 12:42:17 -0500 Received: from [139.28.40.42] ([139.28.40.42]:54264 "EHLO tarta.nabijaczleweli.xyz" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S230002AbhCHRmK (ORCPT ); Mon, 8 Mar 2021 12:42:10 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 68EB6360009; Mon, 8 Mar 2021 18:42:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nabijaczleweli.xyz; s=202006; t=1615225329; bh=E2cljsSdwKNhgTqJ7vTZuMRapHpY07TKEviawUFQTN4=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=eMgvfMUbaqR2ghNitae983xZnm+7vCXZaeBGrIkdeRGXiuyzOprXfllIMRZlvpa7x gJIgcjpMJabPZY11CPXlaMptEb1BUQJfH6i4lcE1Xyr1EIQ+PMf08/y2UbyCVAWcIS 5SNsO+HSjec/5tIbxJ5wAYg4IaHotHom7p+yboI1AqGpLXAi0DdgRAZUi722HDrY0L 1Aj5CidgPZL4EBKhkrCe7ZmZ/4OIJGOuk72Nqq/gGaxDg96fCEIxsSMvSissxOxwIc xabHxSIQBAJZqEalF3CaVO/zxXaTyZ+GkWJnyOkTNQNBKXO7cF5rgcVP412QdZFVzy 2j//KVI+IG+MQ== Date: Mon, 8 Mar 2021 18:42:08 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Benjamin Tissoires , Peter Hutterer , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] HID: multitouch: set Stylus suffix for Stylus-application devices, too Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20210205 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org This re-adds the suffix to Win8 stylus-on-touchscreen devices, now that they aren't erroneously marked as MT Signed-off-by: Ahelenia Ziemiańska --- drivers/hid/hid-multitouch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 8580ace596c2..e5a3704b9fe8 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -1580,13 +1580,13 @@ static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) /* we do not set suffix = "Touchscreen" */ hi->input->name = hdev->name; break; - case HID_DG_STYLUS: - /* force BTN_STYLUS to allow tablet matching in udev */ - __set_bit(BTN_STYLUS, hi->input->keybit); - break; case HID_VD_ASUS_CUSTOM_MEDIA_KEYS: suffix = "Custom Media Keys"; break; + case HID_DG_STYLUS: + /* force BTN_STYLUS to allow tablet matching in udev */ + __set_bit(BTN_STYLUS, hi->input->keybit); + fallthrough; case HID_DG_PEN: suffix = "Stylus"; break; From patchwork Mon Mar 8 17:42:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 12123089 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DAD1C43333 for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79FDE652AE for ; Mon, 8 Mar 2021 17:42:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbhCHRmR (ORCPT ); Mon, 8 Mar 2021 12:42:17 -0500 Received: from [139.28.40.42] ([139.28.40.42]:54276 "EHLO tarta.nabijaczleweli.xyz" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S230050AbhCHRmP (ORCPT ); Mon, 8 Mar 2021 12:42:15 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 5F75C360009; Mon, 8 Mar 2021 18:42:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nabijaczleweli.xyz; s=202006; t=1615225334; bh=BYaCJkUhOQoa5P9mbJc0BTz9QByHDKu5+BcbBE3FaPk=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=P6DptIHR+1gLikE+wsuxmKyIwCg+FhMgWgKfcv5jdmRH8XRFd9aKffS8xEygcqYtT Vc28+aZrHepEg9lFeXk/xy5GVj7EtR0DZ3Vz+neOZB57iEsknpXaR3zNWr/EgxiyO7 IpzoiTuUBnm/Y0pH0kV4xRh24t5GbX9S61lzh2X+IIoyioTG+MoKGF/nKT8MQ94ju/ 9fcLO2/BU9efkfCe8yJV3pAq1KfAJ0ZaEgvkOhpwaX2WBLwkm/h8DC0RIYDtGvztQH E7jIdJN5EjDZYjQH8ZZz31HyTk/nk//D033PcLHevFWyW40raLvEpfgdVYeIJFOcRY Pew0GQeju0knQ== Date: Mon, 8 Mar 2021 18:42:13 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Benjamin Tissoires , Peter Hutterer , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] HID: input: replace outdated HID numbers+comments with macros Message-ID: <78bb4e254edc8a7c99b5e9991e84145dbe7407fb.1615224800.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20210205 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org These were untouched since 2.3.99-pre3, and the explanatory comment for HID_DG_TIPPRESSURE is TipPressure in other places Signed-off-by: Ahelenia Ziemiańska --- drivers/hid/hid-input.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index f23027d2795b..a5ba92978473 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1301,12 +1301,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct return; } - if (usage->hid == (HID_UP_DIGITIZER | 0x003c)) { /* Invert */ + if (usage->hid == HID_DG_INVERT) { *quirks = value ? (*quirks | HID_QUIRK_INVERT) : (*quirks & ~HID_QUIRK_INVERT); return; } - if (usage->hid == (HID_UP_DIGITIZER | 0x0032)) { /* InRange */ + if (usage->hid == HID_DG_INRANGE) { if (value) { input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1); return; @@ -1316,7 +1316,7 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct return; } - if (usage->hid == (HID_UP_DIGITIZER | 0x0030) && (*quirks & HID_QUIRK_NOTOUCH)) { /* Pressure */ + if (usage->hid == HID_DG_TIPPRESSURE && (*quirks & HID_QUIRK_NOTOUCH)) { int a = field->logical_minimum; int b = field->logical_maximum; input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3)); From patchwork Mon Mar 8 17:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 12123091 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7295C433E0 for ; Mon, 8 Mar 2021 17:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B247865228 for ; Mon, 8 Mar 2021 17:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbhCHRmt (ORCPT ); Mon, 8 Mar 2021 12:42:49 -0500 Received: from [139.28.40.42] ([139.28.40.42]:54286 "EHLO tarta.nabijaczleweli.xyz" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S230050AbhCHRmV (ORCPT ); Mon, 8 Mar 2021 12:42:21 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 7CA523602D8; Mon, 8 Mar 2021 18:42:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nabijaczleweli.xyz; s=202006; t=1615225339; bh=O3opi9rvyEpgs9nlMtb3A5XUwC6OHkH6ahCapGdL/hs=; h=Date:From:Cc:Subject:References:In-Reply-To:From; b=SvwdSa3yVVW9ZP1ubMdmgBQmmi+ZhxESnXAc6EpAR2uqicG0VC850oEvsoimg9QXf lM4Y2S+xcTVYVjAoqCzfCyRIJ+9vVOb46onYgcoKyJFL0kxQOe1oIgacJVDr6fScFJ OKiEjbs+nF/CL0U241YHYE91ZEkmfzAe5nif4FGNGmZkqh0aE00g2YYsa2ADammlot GUIk66QxtRIWAunV8NMrFqhpoMO2JwW4e5/Pdn2L47f3cWmTp6l5YDgcohRVPPUUAl CPMB69qkBaa1zh2sPXbROOZ2Huty3/jYnpR/DL6CGr3draWJce1zlJ2vkFYTBHMyr6 M7QQesQhqmtTg== Date: Mon, 8 Mar 2021 18:42:18 +0100 From: Ahelenia =?utf-8?q?Ziemia=C5=84ska?= Cc: Benjamin Tissoires , Peter Hutterer , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] HID: input: work around Win8 stylus-on-touchscreen reporting Message-ID: <2ca91ac7cf92e3048a236db3cd519f04e12c1e61.1615224800.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20210205 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org With this, these devices now behave as tablets as expected by userspace The search in hidinput_is_win8_touching() terminates at f=0, u=0 on Goodix screens (27C6:0111, 27C6:0113), but I expect it to have negligible impact on devices that don't have TipSwitch as the first report as well Signed-off-by: Ahelenia Ziemiańska --- Notes: changes in v2: * hidinput_fixup_win8_inrange() became hidinput_is_win8_touching() * BarrelSwitch now anded with TipSwitch drivers/hid/hid-input.c | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index a5ba92978473..aee1f1283c1d 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1273,6 +1273,42 @@ static void hidinput_handle_scroll(struct hid_usage *usage, input_event(input, EV_REL, usage->code, hi_res); } +/* + * Win8 tablet stylus devices send, in order: + * HID_DG_TIPSWITCH (BTN_TOUCH) + * HID_DG_INVERT (BTN_TOOL_RUBBER) + * HID_DG_ERASER (BTN_TOUCH) + * HID_DG_INRANGE (BTN_TOOL_PEN) + * + * For each of these states: + * hover : INRANGE + * touching : TIPSWITCH + * hover+2 : INVERT INRANGE + * touching+2: ERASER INRANGE + * + * Which means we'd send BTN_TOUCH=0 + BTN_TOOL_PEN=1 on proximity, + * then BTN_TOUCH=1 and BTN_TOOL_PEN=0 in consecutive groups when touched, + * indicating the stylus leaving the screen as soon as the two meet. + * + * Additionally, HID_DG_BARRELSWITCH corresponds directly to the button, + * regardless of the tip switch, making it borderline impossible to use precisely. + */ +static bool hidinput_is_win8_touching(struct hid_device *hid, struct hid_field *field) +{ + unsigned f, u; + struct hid_field *rfield; + + for (f = 0; f < field->report->maxfield; ++f) { + rfield = field->report->field[f]; + for (u = 0; u < rfield->maxusage; ++u) { + if (rfield->usage[u].hid == HID_DG_TIPSWITCH) + return rfield->value[u]; + } + } + + return false; +} + void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value) { struct input_dev *input; @@ -1306,7 +1342,13 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct return; } + if (usage->hid == HID_DG_ERASER && value) + *quirks |= HID_QUIRK_INVERT; + if (usage->hid == HID_DG_INRANGE) { + if (hid->group == HID_GROUP_MULTITOUCH_WIN_8) + value = value || hidinput_is_win8_touching(hid, field); + if (value) { input_event(input, usage->type, (*quirks & HID_QUIRK_INVERT) ? BTN_TOOL_RUBBER : usage->code, 1); return; @@ -1322,6 +1364,12 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct input_event(input, EV_KEY, BTN_TOUCH, value > a + ((b - a) >> 3)); } + if (usage->hid == HID_DG_BARRELSWITCH && hid->group == HID_GROUP_MULTITOUCH_WIN_8) { + value = value && hidinput_is_win8_touching(hid, field); + input_event(input, usage->type, usage->code, value); + return; + } + if (usage->hid == (HID_UP_PID | 0x83UL)) { /* Simultaneous Effects Max */ dbg_hid("Maximum Effects - %d\n",value); return;