Return-Path: Received: from mail-by2nam03on0101.outbound.protection.outlook.com ([104.47.42.101]:60008 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932191AbeCCWYS (ORCPT ); Sat, 3 Mar 2018 17:24:18 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Hans de Goede , Jiri Kosina , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 006/102] HID: multitouch: Only look at non touch fields in first packet of a frame Date: Sat, 3 Mar 2018 22:24:12 +0000 Message-ID: <20180303222318.26006-6-alexander.levin@microsoft.com> References: <20180303222318.26006-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222318.26006-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Hans de Goede [ Upstream commit 55746d28d66860bccaae20a67b55b9d5db7c14af ] Devices in "single finger hybrid mode" will send one report per finger, on some devices only the first report of such a multi-packet frame will contain a value for BTN_LEFT, in subsequent reports (if multiple fingers are down) the value is always 0, causing hid-mt to report BTN_LEFT going 1 - 0 - 1 - 0 when pressing a clickpad and putting down a second finger. This happens for example on USB 0603:0002 mt touchpads. This commit fixes this by only reporting non touch fields for the first packet of a (possibly) multi-packet frame. Signed-off-by: Hans de Goede Reviewed-by: Benjamin Tissoires Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-multitouch.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 65ea23be9677..397592959238 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -778,9 +778,11 @@ static int mt_touch_event(struct hid_device *hid, stru= ct hid_field *field, } =20 static void mt_process_mt_event(struct hid_device *hid, struct hid_field *= field, - struct hid_usage *usage, __s32 value) + struct hid_usage *usage, __s32 value, + bool first_packet) { struct mt_device *td =3D hid_get_drvdata(hid); + __s32 cls =3D td->mtclass.name; __s32 quirks =3D td->mtclass.quirks; struct input_dev *input =3D field->hidinput->input; =20 @@ -837,6 +839,15 @@ static void mt_process_mt_event(struct hid_device *hid= , struct hid_field *field, break; =20 default: + /* + * For Win8 PTP touchpads we should only look at + * non finger/touch events in the first_packet of + * a (possible) multi-packet frame. + */ + if ((cls =3D=3D MT_CLS_WIN_8 || cls =3D=3D MT_CLS_WIN_8_DUAL) && + !first_packet) + return; + if (usage->type) input_event(input, usage->type, usage->code, value); @@ -856,6 +867,7 @@ static void mt_touch_report(struct hid_device *hid, str= uct hid_report *report) { struct mt_device *td =3D hid_get_drvdata(hid); struct hid_field *field; + bool first_packet; unsigned count; int r, n; =20 @@ -874,6 +886,7 @@ static void mt_touch_report(struct hid_device *hid, str= uct hid_report *report) td->num_expected =3D value; } =20 + first_packet =3D td->num_received =3D=3D 0; for (r =3D 0; r < report->maxfield; r++) { field =3D report->field[r]; count =3D field->report_count; @@ -883,7 +896,7 @@ static void mt_touch_report(struct hid_device *hid, str= uct hid_report *report) =20 for (n =3D 0; n < count; n++) mt_process_mt_event(hid, field, &field->usage[n], - field->value[n]); + field->value[n], first_packet); } =20 if (td->num_received >=3D td->num_expected) --=20 2.14.1