f10b01d
From c25d877f4ee97deb92170129eee4777a5d5997d9 Mon Sep 17 00:00:00 2001
f10b01d
From: Hans de Goede <hdegoede@redhat.com>
f10b01d
Date: Wed, 22 Nov 2017 12:57:09 +0100
f10b01d
Subject: [PATCH v2 2/3] HID: multitouch: Only look at non touch fields in
f10b01d
 first packet of a frame
f10b01d
f10b01d
Devices in "single finger hybrid mode" will send one report per finger,
f10b01d
on some devices only the first report of such a multi-packet frame will
f10b01d
contain a value for BTN_LEFT, in subsequent reports (if multiple fingers
f10b01d
are down) the value is always 0, causing hid-mt to report BTN_LEFT going
f10b01d
1 - 0 - 1 - 0 when pressing a clickpad and putting down a second finger.
f10b01d
This happens for example on USB 0603:0002 mt touchpads.
f10b01d
f10b01d
This commit fixes this by only reporting non touch fields for the first
f10b01d
packet of a (possibly) multi-packet frame.
f10b01d
f10b01d
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
f10b01d
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
f10b01d
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
f10b01d
---
f10b01d
 drivers/hid/hid-multitouch.c | 17 +++++++++++++++--
f10b01d
 1 file changed, 15 insertions(+), 2 deletions(-)
f10b01d
f10b01d
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
f10b01d
index d8b1cad74faf..760c4a042e6a 100644
f10b01d
--- a/drivers/hid/hid-multitouch.c
f10b01d
+++ b/drivers/hid/hid-multitouch.c
f10b01d
@@ -787,9 +787,11 @@ static int mt_touch_event(struct hid_device *hid, struct hid_field *field,
f10b01d
 }
f10b01d
 
f10b01d
 static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
f10b01d
-				struct hid_usage *usage, __s32 value)
f10b01d
+				struct hid_usage *usage, __s32 value,
f10b01d
+				bool first_packet)
f10b01d
 {
f10b01d
 	struct mt_device *td = hid_get_drvdata(hid);
f10b01d
+	__s32 cls = td->mtclass.name;
f10b01d
 	__s32 quirks = td->mtclass.quirks;
f10b01d
 	struct input_dev *input = field->hidinput->input;
f10b01d
 
f10b01d
@@ -846,6 +848,15 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field,
f10b01d
 			break;
f10b01d
 
f10b01d
 		default:
f10b01d
+			/*
f10b01d
+			 * For Win8 PTP touchpads we should only look at
f10b01d
+			 * non finger/touch events in the first_packet of
f10b01d
+			 * a (possible) multi-packet frame.
f10b01d
+			 */
f10b01d
+			if ((cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) &&
f10b01d
+			    !first_packet)
f10b01d
+				return;
f10b01d
+
f10b01d
 			if (usage->type)
f10b01d
 				input_event(input, usage->type, usage->code,
f10b01d
 						value);
f10b01d
@@ -866,6 +877,7 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
f10b01d
 	struct mt_device *td = hid_get_drvdata(hid);
f10b01d
 	__s32 cls = td->mtclass.name;
f10b01d
 	struct hid_field *field;
f10b01d
+	bool first_packet;
f10b01d
 	unsigned count;
f10b01d
 	int r, n, scantime = 0;
f10b01d
 
f10b01d
@@ -901,6 +913,7 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
f10b01d
 	}
f10b01d
 	td->prev_scantime = scantime;
f10b01d
 
f10b01d
+	first_packet = td->num_received == 0;
f10b01d
 	for (r = 0; r < report->maxfield; r++) {
f10b01d
 		field = report->field[r];
f10b01d
 		count = field->report_count;
f10b01d
@@ -910,7 +923,7 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
f10b01d
 
f10b01d
 		for (n = 0; n < count; n++)
f10b01d
 			mt_process_mt_event(hid, field, &field->usage[n],
f10b01d
-					field->value[n]);
f10b01d
+					    field->value[n], first_packet);
f10b01d
 	}
f10b01d
 
f10b01d
 	if (td->num_received >= td->num_expected)
f10b01d
-- 
f10b01d
2.14.3
f10b01d