From patchwork Fri May 18 14:16:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 10410873 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 053DD602C2 for ; Fri, 18 May 2018 14:16:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E654E289AB for ; Fri, 18 May 2018 14:16:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA7A4289B3; Fri, 18 May 2018 14:16:42 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, 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 66653289B1 for ; Fri, 18 May 2018 14:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751156AbeEROQk (ORCPT ); Fri, 18 May 2018 10:16:40 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:35760 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750977AbeEROQj (ORCPT ); Fri, 18 May 2018 10:16:39 -0400 Received: by mail-pf0-f194.google.com with SMTP id x9-v6so3840627pfm.2 for ; Fri, 18 May 2018 07:16:39 -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=aezGo9cLaPKW14Votp4us2AsMpO1H0pkH3pb2f2/ZrQ=; b=R/AsA5q2MBHuQ+HR37T/UB1huj7RIco+j4h9+em1uJf7IabxSrjAAXtdgWecxac8ui xq56wOcXf9RXWPrC0aS783JcVIOKc3ef5lo7qAfAUefENKI9Vw2ArkIkERlKrPYGMv3A bWXCt5SFlAb36YxVIuFbEQmBBTURgrfJ9XD7T8JowxXNOevnz/XSgmV5ww4wGiPCucwL SCmdYEzvGdPetCOOF9hMEWJp8VCJzM/aKtECafARu5cofNlu1raqMBM6mUDmwxe19fk6 1qN4YDuGe+51GmN1/ggUOhIvSXd6A+KoyNGXOualLLzFJdxHBBw1hxeeZEXl/Dy1lB5s H7NA== 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=aezGo9cLaPKW14Votp4us2AsMpO1H0pkH3pb2f2/ZrQ=; b=Q4kxZkBNM4MakKYTuGHNCxAxM1WQmLS5QKmFxgr+P98Y3bdSQ5WcruBN9Qc5wN8ocO rkZ3P2M0OG4T3PJJUIIeFev0i40byFJfE3OB3bwG4ZEOrLcTnYCqUFcp1ZcLUkWl9bh+ Kv8m48mFYLTkc1ZSOPncNTQ3a6HetiivDRbzO26mEdETu/e/VH/R9uV0UqouROMAXju6 vWcJU9ciVuFDXZZa/+CcHHTOmEN6dfEWg+tBQbE6/lLmQBcMk4lTkHmBC4YyiWYFNFnu 76KvkVADt84NTc+3zxf0aRh23Gy3RDEDKLH52KimgHG/ldbwPYS0uhDnTnQStmd3J2qC rGFg== X-Gm-Message-State: ALKqPwdk7lb4BGNtRWg0ws60IKEDcYvYYGtaaDZHOuwX07BGOazG7WJP 6cmLlSpwtkZz+XjmJWhkrUnMSuLE X-Google-Smtp-Source: AB8JxZpCmjUu8BFk0UmnxhXzq9vXKVXZ3nAz5u018z22YiXQvNVA+J+qrgMPHGBD+my7icg0m4ooqg== X-Received: by 2002:a63:b046:: with SMTP id z6-v6mr7550609pgo.16.1526652998676; Fri, 18 May 2018 07:16:38 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id o70-v6sm13396102pfo.49.2018.05.18.07.16.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 May 2018 07:16:37 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Ping Cheng , Aaron Skomra , Benjamin Tissoires , Jason Gerecke , Jason Gerecke Subject: [PATCH] HID: wacom: Support "in range" for Bamboo tablets where possible Date: Fri, 18 May 2018 07:16:24 -0700 Message-Id: <20180518141624.25347-1-killertofu@gmail.com> X-Mailer: git-send-email 2.17.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 The 1st-generation Intuos tablets (CTL-X80) include an "in range" flag like some professional tablets. To ensure the pen remains usable at as large as distance as possible (and to preemptively disable touch when it is nearby) we need to ensure that we handle these "in range" events. Handling of tool type identification has been moved to occur only when the pen is fully in prox rather than any time the "stylus_in_proximity" flag changes (which is controlled by the further-out "in range" flag). Ref: https://sourceforge.net/p/linuxwacom/bugs/358/ Ref: https://github.com/linuxwacom/xf86-input-wacom/issues/14 Ref: https://github.com/linuxwacom/xf86-input-wacom/issues/17 Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 74 ++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 5f947ec20dcb..0bb44d0088ed 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -2894,24 +2894,31 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) struct wacom_features *features = &wacom->features; struct input_dev *input = wacom->pen_input; unsigned char *data = wacom->data; - int prox = 0, x = 0, y = 0, p = 0, d = 0, pen = 0, btn1 = 0, btn2 = 0; + int x = 0, y = 0, p = 0, d = 0; + bool pen = false, btn1 = false, btn2 = false; + bool range, prox, rdy; if (data[0] != WACOM_REPORT_PENABLED) return 0; - prox = (data[1] & 0x20) == 0x20; + range = (data[1] & 0x80) == 0x80; + prox = (data[1] & 0x40) == 0x40; + rdy = (data[1] & 0x20) == 0x20; + + wacom->shared->stylus_in_proximity = range; + if (delay_pen_events(wacom)) + return 0; + + if (rdy) { + p = le16_to_cpup((__le16 *)&data[6]); + pen = data[1] & 0x01; + btn1 = data[1] & 0x02; + btn2 = data[1] & 0x04; + } + if (prox) { + x = le16_to_cpup((__le16 *)&data[2]); + y = le16_to_cpup((__le16 *)&data[4]); - /* - * All reports shared between PEN and RUBBER tool must be - * forced to a known starting value (zero) when transitioning to - * out-of-prox. - * - * If not reset then, to userspace, it will look like lost events - * if new tool comes in-prox with same values as previous tool sent. - * - * Hardware does report zero in most out-of-prox cases but not all. - */ - if (!wacom->shared->stylus_in_proximity) { if (data[1] & 0x08) { wacom->tool[0] = BTN_TOOL_RUBBER; wacom->id[0] = ERASER_DEVICE_ID; @@ -2919,16 +2926,9 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) wacom->tool[0] = BTN_TOOL_PEN; wacom->id[0] = STYLUS_DEVICE_ID; } + wacom->reporting_data = true; } - - wacom->shared->stylus_in_proximity = prox; - if (delay_pen_events(wacom)) - return 0; - - if (prox) { - x = le16_to_cpup((__le16 *)&data[2]); - y = le16_to_cpup((__le16 *)&data[4]); - p = le16_to_cpup((__le16 *)&data[6]); + if (range) { /* * Convert distance from out prox to distance from tablet. * distance will be greater than distance_max once @@ -2937,25 +2937,29 @@ static int wacom_bpt_pen(struct wacom_wac *wacom) */ if (data[8] <= features->distance_max) d = features->distance_max - data[8]; - - pen = data[1] & 0x01; - btn1 = data[1] & 0x02; - btn2 = data[1] & 0x04; } else { wacom->id[0] = 0; } - input_report_key(input, BTN_TOUCH, pen); - input_report_key(input, BTN_STYLUS, btn1); - input_report_key(input, BTN_STYLUS2, btn2); + if (wacom->reporting_data) { + input_report_key(input, BTN_TOUCH, pen); + input_report_key(input, BTN_STYLUS, btn1); + input_report_key(input, BTN_STYLUS2, btn2); - input_report_abs(input, ABS_X, x); - input_report_abs(input, ABS_Y, y); - input_report_abs(input, ABS_PRESSURE, p); - input_report_abs(input, ABS_DISTANCE, d); + if (prox || !range) { + input_report_abs(input, ABS_X, x); + input_report_abs(input, ABS_Y, y); + } + input_report_abs(input, ABS_PRESSURE, p); + input_report_abs(input, ABS_DISTANCE, d); - input_report_key(input, wacom->tool[0], prox); /* PEN or RUBBER */ - input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ + input_report_key(input, wacom->tool[0], range); /* PEN or RUBBER */ + input_report_abs(input, ABS_MISC, wacom->id[0]); /* TOOL ID */ + } + + if (!range) { + wacom->reporting_data = false; + } return 1; }