From patchwork Fri Sep 8 00:44:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ping Cheng X-Patchwork-Id: 9943021 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 5F8C46034B for ; Fri, 8 Sep 2017 00:44:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B48727F7F for ; Fri, 8 Sep 2017 00:44:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FE4427F86; Fri, 8 Sep 2017 00:44:38 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 8174227F7F for ; Fri, 8 Sep 2017 00:44:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751328AbdIHAog (ORCPT ); Thu, 7 Sep 2017 20:44:36 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:33889 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750807AbdIHAof (ORCPT ); Thu, 7 Sep 2017 20:44:35 -0400 Received: by mail-pg0-f65.google.com with SMTP id v82so601528pgb.1; Thu, 07 Sep 2017 17:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ECCLYbs4+W8/WLlT/RF53XqOm2d2MIrrIqbpDBHqnss=; b=q12yQubvccquxwRXbqXwCfyU+c1NAEafE+BSOVtE87Hp6AjPsyNQ+AsT28Y6rSVnys SGfPmEnC0uozfXs6D+KYjNIk7fhnKk1rjbYf7CzZhmRyNfAgPEEMGKjl8dR0CP7AfN2F v5Mkyv6iA36dQi9fMZTd3dj2BEnIhB7Qr+Tr2DNVfpIXftJ21TGZQJeqs5o/CdAKPwKE 0uhCnJgl6ER7kTNEmICV8MAOmXdQUd+X5aZ/7EYYKnSTPy7wsDsHHTzVr63gZ/Y1TQI/ v5kYE9YeJwWznkyfAc22qd4DmkpkNXB/2zTa48C0exCsyQBaNGXI5tNOcP+BG/ZglJw+ od6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ECCLYbs4+W8/WLlT/RF53XqOm2d2MIrrIqbpDBHqnss=; b=HLYX/2NcmFNJIOFllyzVSjPcA9mkogpXIlkbpFfcW5zOhX8gnWanqWxnc87MeI/zei Ld6whNISBf/AM5qZbEI22iK51bKcbCiGjk6+Dv0sSxoTxHoewHkDOFoogJzoUup6tyw3 Oa11ZxysXI/1LTUnoblw2guzw68thSnDtvfvxX+M+UNcibDOMlvPElfpOvRDynE88BuQ RRwXMiAtVWVjWyy+9E1CP2bN1ZIVf2OGqQVj+T2CmliCFRhOYV18Xsd9I5+RXT3njTM5 X/I+zZt0lYBg0rBNiCeWnji2KpU5RmJhrCjoJnoN6mNEj8JX04qDdU0i08sfyKFpzwG6 172g== X-Gm-Message-State: AHPjjUitQ7lA2sdRGfzRRPWjOHR/a4gb7Rw1QioJEabVYK2JPL/d3tQP RQb5DoB2PYyPHg== X-Google-Smtp-Source: ADKCNb6gAtez+CEJQWboSdpVaZJiTgbWXggm6Sj7SPXfrHVO/DXTgY5VzIDMn51kCTTc7JhvJoUTNA== X-Received: by 10.101.76.141 with SMTP id m13mr1285423pgt.103.1504831474914; Thu, 07 Sep 2017 17:44:34 -0700 (PDT) Received: from localhost.localdomain (mobile-166-176-185-67.mycingular.net. [166.176.185.67]) by smtp.gmail.com with ESMTPSA id z125sm951456pfz.155.2017.09.07.17.44.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Sep 2017 17:44:34 -0700 (PDT) From: Ping Cheng X-Google-Original-From: Ping Cheng To: jikos@kernel.org Cc: linux-input@vger.kernel.org, Jason Gerecke , "stable # v4 . 10" , Ping Cheng , Jason Gerecke Subject: [PATCH 1/6] HID: wacom: generic: Send MSC_SERIAL and ABS_MISC when leaving prox Date: Thu, 7 Sep 2017 17:44:12 -0700 Message-Id: <20170908004412.2698-1-ping.cheng@wacom.com> X-Mailer: git-send-email 2.9.5 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 From: Jason Gerecke The latest generation of pro devices (MobileStudio Pro, 2nd-gen Intuos Pro, Cintiq Pro) send a serial number of '0' whenever the pen is too far away for reliable communication. Userspace defines that a serial number of '0' is invalid, so we need to be careful not to actually forward this value. Additionally, since EMR ISDv4 devices do not support serial numbers or tool IDs, we'd like to not send these events if they aren't necessary. The existing code achieves these goals by adding a check for a non-zero serial number within the wacom_wac_pen_report function. The MSC_SERIAL and ABS_MISC events are only sent if the serial number is non-zero. This code fails, however when the pen for a pro device leaves proximity. When the pen leaves prox and the tablet sends a serial of 0, wacom_wac_pen_event dutifully clears the serial number. When wacom_wac_pen_report is called, it does not send either the MSC_SERIAL of the exiting tool nor an ABS_MISC event. This patch prevents the wacom_wac_pen_event function from clearing an already-set serial number. This ensures that we have the serial number handy when exiting proximity, but requires us to manually clear it afterwards to ensure the driver does not send stale data (e.g. when switching between AES pens that report a serial nubmer of 0 for the first few fully in-proximity packets). Fixes: f85c9dc678 ("HID: wacom: generic: Support tool ID and additional tool types") Cc: stable # v4.10 Signed-off-by: Ping Cheng Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 78d0398..e2ba36d 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2141,8 +2141,10 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field wacom_wac->hid_data.tipswitch |= value; return; case HID_DG_TOOLSERIALNUMBER: - wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); - wacom_wac->serial[0] |= (__u32)value; + if (value) { + wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); + wacom_wac->serial[0] |= (__u32)value; + } return; case HID_DG_TWIST: /* @@ -2156,15 +2158,17 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field wacom_wac->hid_data.sense_state = value; return; case WACOM_HID_WD_SERIALHI: - wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF); - wacom_wac->serial[0] |= ((__u64)value) << 32; - /* - * Non-USI EMR devices may contain additional tool type - * information here. See WACOM_HID_WD_TOOLTYPE case for - * more details. - */ - if (value >> 20 == 1) { - wacom_wac->id[0] |= value & 0xFFFFF; + if (value) { + wacom_wac->serial[0] = (wacom_wac->serial[0] & 0xFFFFFFFF); + wacom_wac->serial[0] |= ((__u64)value) << 32; + /* + * Non-USI EMR devices may contain additional tool type + * information here. See WACOM_HID_WD_TOOLTYPE case for + * more details. + */ + if (value >> 20 == 1) { + wacom_wac->id[0] |= value & 0xFFFFF; + } } return; case WACOM_HID_WD_TOOLTYPE: @@ -2279,6 +2283,7 @@ static void wacom_wac_pen_report(struct hid_device *hdev, if (!prox) { wacom_wac->tool[0] = 0; wacom_wac->id[0] = 0; + wacom_wac->serial[0] = 0; } }