From patchwork Wed Apr 24 22:12:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10915819 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 126021515 for ; Wed, 24 Apr 2019 22:13:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 008AA28B81 for ; Wed, 24 Apr 2019 22:13:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E79EC28B86; Wed, 24 Apr 2019 22:13:26 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 885C228B81 for ; Wed, 24 Apr 2019 22:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731945AbfDXWN0 (ORCPT ); Wed, 24 Apr 2019 18:13:26 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:43669 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfDXWNZ (ORCPT ); Wed, 24 Apr 2019 18:13:25 -0400 Received: by mail-pg1-f195.google.com with SMTP id z9so10073058pgu.10; Wed, 24 Apr 2019 15:13:25 -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:mime-version :content-transfer-encoding; bh=YzX3Aq6PqWF1zFfvKYeYCVTOF+ll2slIYCUeLOvHmQc=; b=vB4zpdPLBeD8m+/sa0/u9CCXbSoU4jHeuA+fIRMq2/xf3Ma/BckyNb/Z4JDIdyDCSG 2bB8ps7k3+3GThOjkwebnoCBj1AIAu4PVAGgbAxwbO4SO67IkqXJPcBc+WaOBGbhgyRs lNKV+mozPU7eCRGb+PXriEIh85dnxIR7B5sfN/zj617Fw+DYOmTafPDDF/VxiiTWzO9w A5rsUa60Q9i0OuQmmzmSVC9AdreYAOoQ/zKTxFEPGHGzEFpFLQdZpnwMxPouZ9jYCls5 rVFMqvE9HSeEQFmhfnJ9WlgOzS6VGOR0y47M8vTrDfcX4w/oAnwpbiwrvhymm+EfymtP qQrA== 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:mime-version :content-transfer-encoding; bh=YzX3Aq6PqWF1zFfvKYeYCVTOF+ll2slIYCUeLOvHmQc=; b=UyhdJHSJ4pSxzQXUWjpkySwOQ24XlB9as7cV+0uPGyGJ8MuzXqSNdTwdNulBpt++n6 kBffYRDg9nyRSmhsJlcPcwlWIznLQ9EUkuNfDT4BFt2xY9JrJ6E+wQJcAhAetHAeCpGN LYRhYRSdeXHEEoak8CvNc3LAv30g4xrkByYlQ+Hi4ZxOzSPeBYWG2PsVp0TA8OBg7nbr gGvaohLoB/DnE8cjB6CweLTXjZfq0OYFvndGbKvTancv3Qz3iwBsQbIg2HABMU6g/ygH WIJI5MdWPYrGRlxxjGUDmEWd3k0p8ytyRvCPw333baGm5DVCxrLPNlw5dbl5cf7MHbam myQA== X-Gm-Message-State: APjAAAUATtIic9LbXp/Kk/1xMOAh/3wnLA7fEcU3aCvsHgsgJsm92wgi XT5BNwvCo9vCuz/VTzxOuG36Z7bR X-Google-Smtp-Source: APXvYqxuj2E0EA0amQ0H8S+l2UWzM+yvTFaScFGNQAId1stM/kJasD6Un0mCRz1iI8wvKEg2a779mw== X-Received: by 2002:aa7:9116:: with SMTP id 22mr28850827pfh.165.1556144004365; Wed, 24 Apr 2019 15:13:24 -0700 (PDT) Received: from US-191-ENG0002.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id l15sm23929427pfi.79.2019.04.24.15.13.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 15:13:22 -0700 (PDT) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: linux-input@vger.kernel.org, Benjamin Tissoires Cc: Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , stable@vger.kernel.org, Aaron Armstrong Skomra Subject: [PATCH 1/2] HID: wacom: Don't set tool type until we're in range Date: Wed, 24 Apr 2019 15:12:57 -0700 Message-Id: <20190424221258.19992-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 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 serial number and tool type information that is reported by the tablet while a pen is merely "in prox" instead of fully "in range" can be stale and cause us to report incorrect tool information. Serial number, tool type, and other information is only valid once the pen comes fully in range so we should be careful to not use this information until that point. In particular, this issue may cause the driver to incorectly report BTN_TOOL_RUBBER after switching from the eraser tool back to the pen. Fixes: a48324de6d ("HID: wacom: Bluetooth IRQ for Intuos Pro should handle prox/range") Cc: # 4.11+ Signed-off-by: Jason Gerecke Reviewed-by: Aaron Armstrong Skomra --- drivers/hid/wacom_wac.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 747730d32ab6..4c1bc239207e 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1236,13 +1236,13 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) /* Add back in missing bits of ID for non-USI pens */ wacom->id[0] |= (wacom->serial[0] >> 32) & 0xFFFFF; } - wacom->tool[0] = wacom_intuos_get_tool_type(wacom_intuos_id_mangle(wacom->id[0])); for (i = 0; i < pen_frames; i++) { unsigned char *frame = &data[i*pen_frame_len + 1]; bool valid = frame[0] & 0x80; bool prox = frame[0] & 0x40; bool range = frame[0] & 0x20; + bool invert = frame[0] & 0x10; if (!valid) continue; @@ -1251,9 +1251,24 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) wacom->shared->stylus_in_proximity = false; wacom_exit_report(wacom); input_sync(pen_input); + + wacom->tool[0] = 0; + wacom->id[0] = 0; + wacom->serial[0] = 0; return; } + if (range) { + if (!wacom->tool[0]) { /* first in range */ + /* Going into range select tool */ + if (invert) + wacom->tool[0] = BTN_TOOL_RUBBER; + else if (wacom->id[0]) + wacom->tool[0] = wacom_intuos_get_tool_type(wacom->id[0]); + else + wacom->tool[0] = BTN_TOOL_PEN; + } + input_report_abs(pen_input, ABS_X, get_unaligned_le16(&frame[1])); input_report_abs(pen_input, ABS_Y, get_unaligned_le16(&frame[3])); From patchwork Wed Apr 24 22:12:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10915821 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E2297922 for ; Wed, 24 Apr 2019 22:13:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D002528B81 for ; Wed, 24 Apr 2019 22:13:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C45D628B86; Wed, 24 Apr 2019 22:13:27 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 6351A28B81 for ; Wed, 24 Apr 2019 22:13:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732370AbfDXWN0 (ORCPT ); Wed, 24 Apr 2019 18:13:26 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:36080 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfDXWN0 (ORCPT ); Wed, 24 Apr 2019 18:13:26 -0400 Received: by mail-pg1-f195.google.com with SMTP id 85so10100657pgc.3; Wed, 24 Apr 2019 15:13:26 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=jnbYhUxzQuCjZ18WmWgdJZMr0kvcvWmIQwnzOA5hoo0=; b=pfyiFXzc2aO3jB4GrbTrMzUj53VQU0dqcpYamsHRQQtmD/LY7jW8VT6UKerfj90JVe iTdW3/bx87sQC2eaNWqo8q3gaC20cAWWtNrOkSEisW3pLA2zK0MyHHe4MYDsmGLpZJwZ KrHstDp6iPsyXqdRuji0kWrjQdA4BcTDeT9VAQKijp9sWc6jrcithh53CYP8ZJErZ3Q1 BPmvexJHiz36eys04C4cWhXtpVmSO+enarztr9h4llbl2xa21pLlhcwSUSsvsOfOL6Tc pAVYFwNA/0nzJSdTSvDRoeVLN4D5iJ5rfVWrGX+5+19R+h8C5NevGrO/TtUjj8GmNV4m FTxQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=jnbYhUxzQuCjZ18WmWgdJZMr0kvcvWmIQwnzOA5hoo0=; b=J5dbCdeCYrA1N6ccv8M/g9ME+Z3d8O/dEY0l7JeBsGp+m5Y//41md5KsFX64A7/1WO vfVSk8BlPYjShogbWJIYPCH9iwZ6f+xpin1SJvsjCdA9rPP15GUZsj7SrvPc6huaTmc2 P56HcStdswj/5l5ZQNN+LzC6JxahyZ3JAykeYoPW/HnHMKDV2u/A5iLkySpdcKoMifzA a3o9vIF2Fx/HWaV5J0svZhgcp/Xhs6jaqN7FFeDt0EV+UM606U9ZK/x8CSA5jLuA8Jka 49fyuxhspaUTJYWaUwrLqBphuACp/XONUGmnRYPEUo9x5NnBC+HT4TlAdkQCtOToYxM6 q14g== X-Gm-Message-State: APjAAAWYcIO3GPqIqFG9b+XiaUhR8y6fZB80dTnj51fez5G9ecHJvPlw 9U9IaZ0ha8qQl0zfaE8ZxiIiBSSb X-Google-Smtp-Source: APXvYqwmExcm9c7SD5pUQDaUCNI96aA+TGZTd0jp9WdRf8JNu+KqL7JdYrlvicVXWXpc4BRkj2WRZg== X-Received: by 2002:a62:5797:: with SMTP id i23mr36055454pfj.12.1556144005479; Wed, 24 Apr 2019 15:13:25 -0700 (PDT) Received: from US-191-ENG0002.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id l15sm23929427pfi.79.2019.04.24.15.13.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Apr 2019 15:13:24 -0700 (PDT) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: linux-input@vger.kernel.org, Benjamin Tissoires Cc: Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , stable@vger.kernel.org, Aaron Armstrong Skomra Subject: [PATCH 2/2] HID: wacom: Don't report anything prior to the tool entering range Date: Wed, 24 Apr 2019 15:12:58 -0700 Message-Id: <20190424221258.19992-2-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190424221258.19992-1-jason.gerecke@wacom.com> References: <20190424221258.19992-1-jason.gerecke@wacom.com> MIME-Version: 1.0 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 If the tool spends some time in prox before entering range, a series of events (e.g. ABS_DISTANCE, MSC_SERIAL) can be sent before we or userspace have any clue about the pen whose data is being reported. We need to hold off on reporting anything until the pen has entered range. Since we still want to report events that occur "in prox" after the pen has *left* range we use 'wacom-tool[0]' as the indicator that the pen did at one point enter range and provide us/userspace with tool type and serial number information. Fixes: a48324de6d ("HID: wacom: Bluetooth IRQ for Intuos Pro should handle prox/range") Cc: # 4.11+ Signed-off-by: Jason Gerecke Reviewed-by: Aaron Armstrong Skomra --- drivers/hid/wacom_wac.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 4c1bc239207e..613342bb9d6b 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1290,23 +1290,26 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) get_unaligned_le16(&frame[11])); } } - input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5])); - if (wacom->features.type == INTUOSP2_BT) { - input_report_abs(pen_input, ABS_DISTANCE, - range ? frame[13] : wacom->features.distance_max); - } else { - input_report_abs(pen_input, ABS_DISTANCE, - range ? frame[7] : wacom->features.distance_max); - } - input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x01); - input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02); - input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04); + if (wacom->tool[0]) { + input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5])); + if (wacom->features.type == INTUOSP2_BT) { + input_report_abs(pen_input, ABS_DISTANCE, + range ? frame[13] : wacom->features.distance_max); + } else { + input_report_abs(pen_input, ABS_DISTANCE, + range ? frame[7] : wacom->features.distance_max); + } + + input_report_key(pen_input, BTN_TOUCH, frame[0] & 0x01); + input_report_key(pen_input, BTN_STYLUS, frame[0] & 0x02); + input_report_key(pen_input, BTN_STYLUS2, frame[0] & 0x04); - input_report_key(pen_input, wacom->tool[0], prox); - input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]); - input_report_abs(pen_input, ABS_MISC, - wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */ + input_report_key(pen_input, wacom->tool[0], prox); + input_event(pen_input, EV_MSC, MSC_SERIAL, wacom->serial[0]); + input_report_abs(pen_input, ABS_MISC, + wacom_intuos_id_mangle(wacom->id[0])); /* report tool id */ + } wacom->shared->stylus_in_proximity = prox;