From patchwork Fri Apr 26 16:34:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10919373 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 D6E771390 for ; Fri, 26 Apr 2019 16:35:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3D491FF87 for ; Fri, 26 Apr 2019 16:35:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B667628A16; Fri, 26 Apr 2019 16:35:04 +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 B04271FF87 for ; Fri, 26 Apr 2019 16:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726173AbfDZQfD (ORCPT ); Fri, 26 Apr 2019 12:35:03 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36767 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfDZQfD (ORCPT ); Fri, 26 Apr 2019 12:35:03 -0400 Received: by mail-pg1-f194.google.com with SMTP id 85so1885625pgc.3; Fri, 26 Apr 2019 09:35:02 -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=QBc1ERbBKPa3hvlajbdfe0XwmY0xuJb+gPy+6oRP6mc=; b=hmXVjHcuYvumSP/rJf93rmTAxapKisfm52zGMM1FInfg3VGyr79u4QlzBo8HF+Cpgh 2YWmN2NuJn3pD7h/jNFmko1IhpazXMEF3HrBI/W56lVmNl8xLrpUoXukruyw9D15gGPO 7GfengEHT7x43rsUOuOyi6XouBmISeUT1TOyaIIQdzxot2ymlUwXAeJVZQ+Pn+Zma392 Ha9fIanInkT1MZKWwBrB9du46KLg+ZNCjIiMzUhbc++JZDvvboCRKTo693J30dB6iadg 6g0sEIvG0DM9av5uq+kqFoR+YGynpLvYqfp3Zmzg5Z36dJ/fkFRSscUo2tKwwgSqqwUQ YiSQ== 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=QBc1ERbBKPa3hvlajbdfe0XwmY0xuJb+gPy+6oRP6mc=; b=HKxv450unBYddcxZ6y6twsESFjWlslRc8wEXHv0vv7G3UAnKhymB86yyore57rXG5g hoeINX6Lt1kv1aZ5z4420smnkZ9TdGc08uL2d2D2VKKfkGxWZHLcbbixFGVGYRlLoO57 jBBrOnj50ibD5/28R1CV+zsQIMgrK2WoGGDiqlf0p2JlLJ1ra79KDYjXFAGgfHfOvyK+ jGfr9u3bbn00lfn1DAhmxTSt1y0xF/KBs5d49YXeAtyz469Dv54jyP0X7CSzabSK+yRU zqddumf2wOTc2z6r+KQiHFcyxcwfdZAPgmEHul4IdWUFOEZdbfaW5EuB7CHhORTLVVhc a+mg== X-Gm-Message-State: APjAAAUapzrvykZIDxjHPWcSXYzH5tGXg7QvTywNBHUkV/U0fZw3sr6W UirbgktNWPnTpee3/lWfiiYP5Bl9 X-Google-Smtp-Source: APXvYqwBhgqe+LTKypDtNNnpXIf11dQD8EVY3yQkCUSApOtTuWJexfricuuceERur1ozUfN9g3PYyg== X-Received: by 2002:a63:a441:: with SMTP id c1mr42342289pgp.307.1556296501789; Fri, 26 Apr 2019 09:35:01 -0700 (PDT) Received: from US-191-ENG0002.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id j5sm7786981pfg.186.2019.04.26.09.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 09:35:00 -0700 (PDT) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: "# v3.17+" , Sasha Levin Cc: linux-input@vger.kernel.org, Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , Aaron Armstrong Skomra Subject: [PATCH 1/2] HID: wacom: Don't set tool type until we're in range Date: Fri, 26 Apr 2019 09:34:08 -0700 Message-Id: <20190426163408.9676-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190426033328.GB17719@sasha-vm> References: <20190426033328.GB17719@sasha-vm> 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 --- Version of patch specifically targeted to stable v4.14.113 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 4c72e68637c2..03b04bc742dd 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1225,13 +1225,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; @@ -1240,9 +1240,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; + } + /* Fix rotation alignment: userspace expects zero at left */ int16_t rotation = (int16_t)get_unaligned_le16(&frame[9]); rotation += 1800/4; From patchwork Fri Apr 26 16:35:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10919375 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 9EA3714C0 for ; Fri, 26 Apr 2019 16:35:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8802E28DBD for ; Fri, 26 Apr 2019 16:35:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 74F3A28DE6; Fri, 26 Apr 2019 16:35: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=-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 F06FA28DBD for ; Fri, 26 Apr 2019 16:35:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726247AbfDZQfh (ORCPT ); Fri, 26 Apr 2019 12:35:37 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34123 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbfDZQfh (ORCPT ); Fri, 26 Apr 2019 12:35:37 -0400 Received: by mail-pl1-f193.google.com with SMTP id d5so1241017plr.1; Fri, 26 Apr 2019 09:35:37 -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=9kv4cdodf28qp42wRXJBFmfl4ULKCvZduNTxfaB0uBA=; b=ckT9dZlNet6Dzqv0VqKZd73zkL+fm6fb7/9nOuZG7wLaUE8FcBJW9Yqqqa3RQn9xvh TK0TnaV8Q0RP0Yf313tF4bGS7aaH+lCl45Maqeo/GpUFTn3X68zM58WcrGCJLOe6Hp2X mTmxnjG5l8PEgOO4clzOn0RgIzlMWIoHTgwmdbkfUcOS5fMFckTfQHa5+4a/maejfdb+ UNgIYk3+P4PXbp8hvmAC4BmDdFUvrgrImZDIj2jOmhapqEZKVNb9Mhrg4PSo3Ougv9cj Aozqx9K5+McjimvnTKrWNTb8XHg0E/O58/ZEYr3fhAcJ1D8rp2q1aTr0lZjrd3k8pM6m ASXQ== 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=9kv4cdodf28qp42wRXJBFmfl4ULKCvZduNTxfaB0uBA=; b=tsD2j2s1iOaN6TPKk7rrDPfRkd7XlN43ktQbWW8P/r4DF9Mx0q84x/auyL5nXYNwvq on83AD2f16s8lv5m9addZLoKawTMY1ieWTO+BFGNzi0kkfDHES+W6DuFSyVX4D9FFxih fkBh/9uP3qM2jh+DPvTKiALYT+O/7xdCc2cj6PfWYwWG8Ibw+19Z51M2i74NuLPt12S/ RXfzGdf6zRlQHUnsxPQ58ih3YtrHBn3Imnv/2+TXeC6Bag0Hm5+rRkw1LkvYrOLO7u5m 16QorulKKXRQQZTFixSSI2QPDVRBEMk6e4w+X+5DTiLL4WXTI2uKZdjThqW184fH0BVg TPcw== X-Gm-Message-State: APjAAAU0Dj/5HKZoB/lUZrHESUGyn20o5q72TA1oOTXvzMAD6P4zZ/RN iu0R4wtt6uFcQq75UYA/5Ogn/2Hc X-Google-Smtp-Source: APXvYqxHFTJmuqirxykqDIIs39UU4PsQDOTx9DBZuhmrlilb6qUerEMapOXofKjP8Q1oXSio6WJxJg== X-Received: by 2002:a17:902:e48b:: with SMTP id cj11mr4523636plb.223.1556296536235; Fri, 26 Apr 2019 09:35:36 -0700 (PDT) Received: from US-191-ENG0002.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id q128sm40638081pga.60.2019.04.26.09.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Apr 2019 09:35:35 -0700 (PDT) From: "Gerecke, Jason" X-Google-Original-From: "Gerecke, Jason" To: "# v3.17+" , Sasha Levin Cc: linux-input@vger.kernel.org, Ping Cheng , Aaron Armstrong Skomra , Jason Gerecke , Aaron Armstrong Skomra Subject: [PATCH 2/2] HID: wacom: Don't report anything prior to the tool entering range Date: Fri, 26 Apr 2019 09:35:31 -0700 Message-Id: <20190426163531.9782-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: References: 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 --- Version of patch specifically targeted to stable v4.14.113 drivers/hid/wacom_wac.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 03b04bc742dd..e4aeffa56018 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1271,17 +1271,20 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom) input_report_abs(pen_input, ABS_Z, rotation); input_report_abs(pen_input, ABS_WHEEL, get_unaligned_le16(&frame[11])); } - input_report_abs(pen_input, ABS_PRESSURE, get_unaligned_le16(&frame[5])); - input_report_abs(pen_input, ABS_DISTANCE, range ? frame[13] : 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])); + input_report_abs(pen_input, ABS_DISTANCE, range ? frame[13] : wacom->features.distance_max); - 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, 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 */ + } wacom->shared->stylus_in_proximity = prox;