From patchwork Thu Aug 24 23:09:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 9921079 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 6E6D8603FA for ; Thu, 24 Aug 2017 23:09:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 604A91FF83 for ; Thu, 24 Aug 2017 23:09:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5519E1FFDA; Thu, 24 Aug 2017 23:09:56 +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 B5D5F1FF83 for ; Thu, 24 Aug 2017 23:09:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753868AbdHXXJU (ORCPT ); Thu, 24 Aug 2017 19:09:20 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:36817 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753566AbdHXXJT (ORCPT ); Thu, 24 Aug 2017 19:09:19 -0400 Received: by mail-qk0-f193.google.com with SMTP id p67so850184qkd.3; Thu, 24 Aug 2017 16:09:19 -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=80KpfiCza7VFfNCY/3YizeDz6zUzIihQCgvNOo0dI0Q=; b=Ws+NuCs1QTESMXE+AF3b3DzRtfHNNlsewtbp4gkWrhN56B5EeBMw92rAXkwmECEKQq zSZVVQU85axeQR/RcTgAin/vi/hyF20OUVy99EjwME5bmjX3SSgvUCfQ5SfTWbjdaCE0 X1XsGCFJW/6Kf3ZteVslGy1JXquZ9lvOJhp5w9cJPPiZnu8JnzzeYGQxc2uyPycpS1MH PbDMsaVrTd8FXKn8zJ+ESIkStNWq4sSx3+XgDtnW7C6A6OxQp7MspDBsdIWVNAauWlp8 yG2NQaQ29QYrJ/3rX+zxz2j1U/J+by68m4ousf6uEVOZ23dSeq508rbIKAusFLzsudpG dlug== 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=80KpfiCza7VFfNCY/3YizeDz6zUzIihQCgvNOo0dI0Q=; b=cyRDXWwHflczGiMYfduO4EeruQ6nL7ln7lcTxi+DsN5oiOJjE+eSkwB+6Kom8XF/7S 1LYK8VfXtuKsJaYmxYOyefEo/qh8WTceqcOQcvR5Syzpt2nZI+cSzybTnCmoDHOiwm1P o8B9SeGTwgMp2srbu15lbuKg+uKSAjk/KRvAW5jJ5vYpuc2rMr6DZIeZtc9+tUtlUNUh fbWLGIPdApHt6siodg1a+xXtttFH2/AlbgekEX1LmpYq6bYDCYqx/XnBVh8HF+T9MDI4 WsUiQ+r9Io0lC324zAHaA+I0ipyAU5AAfk4rfsFVU2nmU+ZjT57bkE6rztdEGJPJSJsJ YQLA== X-Gm-Message-State: AHYfb5jcop/jAsHZkN4EXtng5jrjyj2JQAqf3sq1SL90JuMzhdLpzE5T QWE5CbucDDtmxAcHOko= X-Received: by 10.55.190.134 with SMTP id o128mr11220083qkf.58.1503616158497; Thu, 24 Aug 2017 16:09:18 -0700 (PDT) Received: from wacom-arch2.corp.onewacom.com ([50.225.60.4]) by smtp.gmail.com with ESMTPSA id p205sm3182179qke.42.2017.08.24.16.09.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Aug 2017 16:09:18 -0700 (PDT) From: Jason Gerecke To: linux-input@vger.kernel.org, Jiri Kosina Cc: Ping Cheng , Aaron Skomra , Benjamin Tissoires , Jason Gerecke , stable@vger.kernel.org, Jason Gerecke Subject: [PATCH] HID: wacom: Correct coordinate system of touchring and pen twist Date: Thu, 24 Aug 2017 16:09:02 -0700 Message-Id: <20170824230902.4381-1-killertofu@gmail.com> X-Mailer: git-send-email 2.14.1 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 MobileStudio Pro, Cintiq Pro, and 2nd-gen Intuos Pro devices use a different coordinate system for their touchring and pen twist than prior devices. Prior devices had zero aligned to the tablet's left and would increase clockwise. Userspace expects data from the kernel to be in this old coordinate space, so adjustments are necessary. While the coordinate system for pen twist is formally defined by the HID standard, no such definition existed for the touchring at the time these tablets were introduced. Future tablets are expected to report touchring data using the same "zero-up clockwise-increasing" coordinate system defined for twist. Fixes: 60a2218698 ("HID: wacom: generic: add support for touchring") Fixes: 50066a042d ("HID: wacom: generic: Add support for height, tilt, and twist usages") Cc: stable@vger.kernel.org Signed-off-by: Jason Gerecke Reviewed-by: Ping Cheng --- drivers/hid/wacom_wac.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index bb17d7bbefd3..7f0b3d497ecb 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -1616,6 +1616,20 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, size_t len) return 0; } +static int wacom_offset_rotation(struct input_dev *input, struct hid_usage *usage, + int value, int num, int denom) +{ + struct input_absinfo *abs = &input->absinfo[usage->code]; + int range = (abs->maximum - abs->minimum + 1); + + value += num*range/denom; + if (value > abs->maximum) + value -= range; + else if (value < abs->minimum) + value += range; + return value; +} + int wacom_equivalent_usage(int usage) { if ((usage & HID_USAGE_PAGE) == WACOM_HID_UP_WACOMDIGITIZER) { @@ -1898,6 +1912,7 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field unsigned equivalent_usage = wacom_equivalent_usage(usage->hid); int i; bool is_touch_on = value; + bool do_report = false; /* * Avoid reporting this event and setting inrange_state if this usage @@ -1912,6 +1927,29 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field } switch (equivalent_usage) { + case WACOM_HID_WD_TOUCHRING: + /* + * Userspace expects touchrings to increase in value with + * clockwise gestures and have their zero point at the + * tablet's left. HID events "should" be clockwise- + * increasing and zero at top, though the MobileStudio + * Pro and 2nd-gen Intuos Pro don't do this... + */ + if (hdev->vendor == 0x56a && + (hdev->product == 0x34d || hdev->product == 0x34e || /* MobileStudio Pro */ + hdev->product == 0x357 || hdev->product == 0x358)) { /* Intuos Pro 2 */ + value = (field->logical_maximum - value); + + if (hdev->product == 0x357 || hdev->product == 0x358) + value = wacom_offset_rotation(input, usage, value, 3, 16); + else if (hdev->product == 0x34d || hdev->product == 0x34e) + value = wacom_offset_rotation(input, usage, value, 1, 2); + } + else { + value = wacom_offset_rotation(input, usage, value, 1, 4); + } + do_report = true; + break; case WACOM_HID_WD_TOUCHRINGSTATUS: if (!value) input_event(input, usage->type, usage->code, 0); @@ -1945,10 +1983,14 @@ static void wacom_wac_pad_event(struct hid_device *hdev, struct hid_field *field value, i); /* fall through*/ default: + do_report = true; + break; + } + + if (do_report) { input_event(input, usage->type, usage->code, value); if (value) wacom_wac->hid_data.pad_input_event_flag = true; - break; } } @@ -2089,6 +2131,14 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field wacom_wac->serial[0] = (wacom_wac->serial[0] & ~0xFFFFFFFFULL); wacom_wac->serial[0] |= (__u32)value; return; + case HID_DG_TWIST: + /* + * Userspace expects pen twist to have its zero point when + * the buttons/finger is on the tablet's left. HID values + * are zero when buttons are toward the top. + */ + value = wacom_offset_rotation(input, usage, value, 1, 4); + break; case WACOM_HID_WD_SENSE: wacom_wac->hid_data.sense_state = value; return;