From patchwork Tue Jul 21 18:07:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 6837431 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 76F2A9F818 for ; Tue, 21 Jul 2015 18:07:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87864205CD for ; Tue, 21 Jul 2015 18:07:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B497206BE for ; Tue, 21 Jul 2015 18:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933339AbbGUSHn (ORCPT ); Tue, 21 Jul 2015 14:07:43 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:33619 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933274AbbGUSHm (ORCPT ); Tue, 21 Jul 2015 14:07:42 -0400 Received: by padck2 with SMTP id ck2so123570479pad.0 for ; Tue, 21 Jul 2015 11:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZEZkxFnNT1sTJQRQtpwrTRKmw5rB4HybwIYLMCAt3ek=; b=W9S4YF6BjNraOZFnYvRx8I1aoBCU0N4njG/zid366iQexU/BP6S0F5o3mi08bB073Z bV6h6TjNYdJcT2YXvPSdDeYR7OYbJzTqUc1LaqOPtHONogNtQPYzgs5X4uB1k+rXb1u4 /U4mf5EtQwSS0RnxOsSd/To5GtjBbuZwodG9MJIUAzjNif6X/yhWP/Kib7s7M4OEqztW J3QMFadqj5bPJctuOpjoI7shscuMEgVOVW1LUo+ZkaUBsSMcbnYxspGrRvG5mbAkrdaD peejso3RaZoxHnJ9zuH7y0py70uIZZgE+iv22zqOQOVsN09XW0tmtgNZq2/0OtqjU6vN 3RKA== X-Received: by 10.66.119.239 with SMTP id kx15mr76522343pab.156.1437502061866; Tue, 21 Jul 2015 11:07:41 -0700 (PDT) Received: from wacom-arch2.localdomain ([67.51.163.2]) by smtp.gmail.com with ESMTPSA id i5sm28872098pat.42.2015.07.21.11.07.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 21 Jul 2015 11:07:40 -0700 (PDT) From: Jason Gerecke To: Jiri Kosina , Ping Cheng , Benjamin Tissoires Cc: Aaron Skomra , linux-input@vger.kernel.org, Jason Gerecke , Jason Gerecke Subject: [PATCH 2/3] HID: wacom: Ignore contacts in excess of declared contact count Date: Tue, 21 Jul 2015 11:07:24 -0700 Message-Id: <1437502045-29927-2-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.4.6 In-Reply-To: <1437502045-29927-1-git-send-email-killertofu@gmail.com> References: <1437502045-29927-1-git-send-email-killertofu@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The reports sent from some touch devices (e.g. the Cintiq 24HDT) contain junk data in the contact slots which follow the final "valid" contact. To avoid forwarding it to usrspace, we store the reported contact count during the pre-process phase and then only process that many contacts. If a device sends its contacts across multiple reports (what Microsoft refers to as "hybrid" mode) then the contact count will be zero for reports other than the first. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 30 +++++++++++++++++++++++++++++- drivers/hid/wacom_wac.h | 4 ++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 1d9d5d1..09fe5d6 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1510,6 +1510,10 @@ static void wacom_wac_finger_usage_mapping(struct hid_device *hdev, features->last_slot_field = usage->hid; wacom_map_usage(input, usage, field, EV_KEY, BTN_TOUCH, 0); break; + case HID_DG_CONTACTCOUNT: + wacom_wac->hid_data.cc_index = field->index; + wacom_wac->hid_data.cc_value_index = usage->usage_index; + break; } } @@ -1521,6 +1525,10 @@ static void wacom_wac_finger_slot(struct wacom_wac *wacom_wac, bool prox = hid_data->tipswitch && !wacom_wac->shared->stylus_in_proximity; + wacom_wac->hid_data.num_received++; + if (wacom_wac->hid_data.num_received > wacom_wac->hid_data.num_expected) + return; + if (mt) { int slot; @@ -1573,7 +1581,19 @@ static int wacom_wac_finger_event(struct hid_device *hdev, static void wacom_wac_finger_pre_report(struct hid_device *hdev, struct hid_report *report) { - return; + struct wacom *wacom = hid_get_drvdata(hdev); + struct wacom_wac *wacom_wac = &wacom->wacom_wac; + struct hid_data* hid_data = &wacom_wac->hid_data; + + if (hid_data->cc_index >= 0) { + struct hid_field *field = report->field[hid_data->cc_index]; + int value = field->value[hid_data->cc_value_index]; + if (value) + hid_data->num_expected = value; + } + else { + hid_data->num_expected = wacom_wac->features.touch_max; + } } static void wacom_wac_finger_report(struct hid_device *hdev, @@ -1584,10 +1604,18 @@ static void wacom_wac_finger_report(struct hid_device *hdev, struct input_dev *input = wacom_wac->touch_input; unsigned touch_max = wacom_wac->features.touch_max; + /* If more packets of data are expected, give us a chance to + * process them rather than immediately syncing a partial + * update. + */ + if (wacom_wac->hid_data.num_received < wacom_wac->hid_data.num_expected) + return; + if (touch_max > 1) input_mt_sync_frame(input); input_sync(input); + wacom_wac->hid_data.num_received = 0; /* keep touch state for pen event */ wacom_wac->shared->touch_down = wacom_wac_finger_count_touches(wacom_wac); diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h index 2978c30..c245a66 100644 --- a/drivers/hid/wacom_wac.h +++ b/drivers/hid/wacom_wac.h @@ -193,6 +193,10 @@ struct hid_data { int width; int height; int id; + int cc_index; + int cc_value_index; + int num_expected; + int num_received; }; struct wacom_wac {