From patchwork Mon Nov 13 16:32:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 10056399 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 B3AC360365 for ; Mon, 13 Nov 2017 16:33:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4C8329164 for ; Mon, 13 Nov 2017 16:33:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9946E29172; Mon, 13 Nov 2017 16:33:09 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 2B8BC29164 for ; Mon, 13 Nov 2017 16:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753690AbdKMQdI (ORCPT ); Mon, 13 Nov 2017 11:33:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46576 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753784AbdKMQdI (ORCPT ); Mon, 13 Nov 2017 11:33:08 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DC24325C26; Mon, 13 Nov 2017 16:33:07 +0000 (UTC) Received: from shalem.localdomain.com (ovpn-116-87.ams2.redhat.com [10.36.116.87]) by smtp.corp.redhat.com (Postfix) with ESMTP id 921FA7C767; Mon, 13 Nov 2017 16:33:06 +0000 (UTC) From: Hans de Goede To: Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v4 2/4] HID: multitouch: Properly deal with Win8 PTP reports with 0 touches Date: Mon, 13 Nov 2017 17:32:57 +0100 Message-Id: <20171113163259.18150-2-hdegoede@redhat.com> In-Reply-To: <20171113163259.18150-1-hdegoede@redhat.com> References: <20171113163259.18150-1-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 13 Nov 2017 16:33:07 +0000 (UTC) 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 The Windows Precision Touchpad spec "Figure 4 Button Only Down and Up" and "Table 9 Report Sequence for Button Only Down and Up" indicate that the first packet of a (possibly hybrid mode multi-packet) frame may contain a contact-count of 0 if only a button is pressed and no fingers are detected. This means that a value of 0 for contact-count is a valid value and should be used as expected contact count when it is the first packet (num_received == 0), as extra check to make sure that this is the first packet of a buttons only frame, we also check that the timestamp is different. Signed-off-by: Hans de Goede Reviewed-by: Benjamin Tissoires --- Changes in v2: -New patch in v2 of this patch-set Changes in v3: -Also check timestamps to make sure we're dealing with the first-packet of a frame Changes in v4: -Add Benjamin's Reviewed-by --- drivers/hid/hid-multitouch.c | 34 ++++++++++++++++++++++++++++++++-- include/linux/hid.h | 1 + 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index bb939f6990f1..5d3904d0e89d 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -117,6 +117,9 @@ struct mt_device { unsigned long mt_io_flags; /* mt flags (MT_IO_FLAGS_*) */ int cc_index; /* contact count field index in the report */ int cc_value_index; /* contact count value index in the field */ + int scantime_index; /* scantime field index in the report */ + int scantime_val_index; /* scantime value index in the field */ + int prev_scantime; /* scantime reported in the previous packet */ unsigned last_slot_field; /* the last field of a slot */ unsigned mt_report_id; /* the report ID of the multitouch device */ unsigned long initial_quirks; /* initial quirks state */ @@ -595,6 +598,14 @@ static int mt_touch_input_mapping(struct hid_device *hdev, struct hid_input *hi, /* we don't set td->last_slot_field as contactcount and * contact max are global to the report */ return -1; + case HID_DG_SCANTIME: + /* Ignore if indexes are out of bounds. */ + if (field->index >= field->report->maxfield || + usage->usage_index >= field->report_count) + return 1; + td->scantime_index = field->index; + td->scantime_val_index = usage->usage_index; + return 1; case HID_DG_TOUCH: /* Legacy devices use TIPSWITCH and not TOUCH. * Let's just ignore this field. */ @@ -812,9 +823,10 @@ static void mt_process_mt_event(struct hid_device *hid, struct hid_field *field, static void mt_touch_report(struct hid_device *hid, struct hid_report *report) { struct mt_device *td = hid_get_drvdata(hid); + __s32 cls = td->mtclass.name; struct hid_field *field; unsigned count; - int r, n; + int r, n, scantime = 0; /* sticky fingers release in progress, abort */ if (test_and_set_bit(MT_IO_FLAGS_RUNNING, &td->mt_io_flags)) @@ -824,12 +836,29 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) * Includes multi-packet support where subsequent * packets are sent with zero contactcount. */ + if (td->scantime_index >= 0) { + field = report->field[td->scantime_index]; + scantime = field->value[td->scantime_val_index]; + } if (td->cc_index >= 0) { struct hid_field *field = report->field[td->cc_index]; int value = field->value[td->cc_value_index]; - if (value) + + /* + * For Win8 PTPs the first packet (td->num_received == 0) may + * have a contactcount of 0 if there only is a button event. + * We double check that this is not a continuation packet + * of a possible multi-packet frame be checking that the + * timestamp has changed. + */ + if ((cls == MT_CLS_WIN_8 || cls == MT_CLS_WIN_8_DUAL) && + td->num_received == 0 && td->prev_scantime != scantime) + td->num_expected = value; + /* A non 0 contact count always indicates a first packet */ + else if (value) td->num_expected = value; } + td->prev_scantime = scantime; for (r = 0; r < report->maxfield; r++) { field = report->field[r]; @@ -1285,6 +1314,7 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) td->maxcontact_report_id = -1; td->inputmode_value = MT_INPUTMODE_TOUCHSCREEN; td->cc_index = -1; + td->scantime_index = -1; td->mt_report_id = -1; hid_set_drvdata(hdev, td); diff --git a/include/linux/hid.h b/include/linux/hid.h index ab05a86269dc..47dd962d9a7a 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -289,6 +289,7 @@ struct hid_item { #define HID_DG_DEVICEINDEX 0x000d0053 #define HID_DG_CONTACTCOUNT 0x000d0054 #define HID_DG_CONTACTMAX 0x000d0055 +#define HID_DG_SCANTIME 0x000d0056 #define HID_DG_BUTTONTYPE 0x000d0059 #define HID_DG_BARRELSWITCH2 0x000d005a #define HID_DG_TOOLSERIALNUMBER 0x000d005b