From patchwork Tue Dec 1 01:13:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 7731751 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E4B899F39B for ; Tue, 1 Dec 2015 01:14:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02CD020641 for ; Tue, 1 Dec 2015 01:14:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2358220663 for ; Tue, 1 Dec 2015 01:14:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754890AbbLABOA (ORCPT ); Mon, 30 Nov 2015 20:14:00 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:34932 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754254AbbLABN7 (ORCPT ); Mon, 30 Nov 2015 20:13:59 -0500 Received: by pacej9 with SMTP id ej9so202497067pac.2 for ; Mon, 30 Nov 2015 17:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1B6prZVamPIpwwhlP/uLqWEKIDLpdBcke/mp46xGfvM=; b=ukeWG5OnnYB/D1JYAW1bOg+XWHh8klk/k3ZJe+aos69nP/e01ZUh10/wFplLsjrKZG 9Xh2Ullp3snqmib+8u94OExoaoqb8yeSdyToKA+SDdJL35vLEmwOe+s4j1wRDfPnVsNO MxVE8cs8fBrv+YL76NC8no7x2mbXebUSE/EsCMJLMUHdDhwREOui0llbojPTtn1/i39j BPFckW0It15pSAyu9QGePreQ/30lkPk9qyBGYtdl1q2R43+xn+DQf9fXhCzVjpg/UscF eu4Byyw/FN/aZdx84GJQPE/BEGT0urIanvF8zrlnX1/aTCrysFsvJS5FZxu+X0tKUeOd gsyQ== X-Received: by 10.98.12.151 with SMTP id 23mr76090059pfm.60.1448932439334; Mon, 30 Nov 2015 17:13:59 -0800 (PST) Received: from wacom-arch2.corp.onewacom.com ([67.51.163.2]) by smtp.gmail.com with ESMTPSA id vq2sm10654740pab.42.2015.11.30.17.13.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Nov 2015 17:13:58 -0800 (PST) From: Jason Gerecke To: linux-input@vger.kernel.org Cc: Jiri Kosina , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH 6/7] HID: wacom: Clean up value reading Date: Mon, 30 Nov 2015 17:13:51 -0800 Message-Id: <1448932432-10115-6-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1448932432-10115-1-git-send-email-killertofu@gmail.com> References: <1448932432-10115-1-git-send-email-killertofu@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the logic for reading X, Y, distance, and pressure a bit more clear. An additional bit was stuffed into the packet format many models back, and /most/ devices in use will use it. If we happen to be dealing with a particularly old tablet, just shift it off the end to pretend we never read it. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index ce3afab..0008650 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -887,21 +887,23 @@ static int wacom_intuos_general(struct wacom_wac *wacom) struct input_dev *input = wacom->pen_input; int idx = (features->type == INTUOS) ? (data[1] & 0x01) : 0; unsigned char type = (data[1] >> 1) & 0x0F; - unsigned int t; + unsigned int x, y, distance, t; if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && data[0] != WACOM_REPORT_INTUOS_PEN) return 0; - if (features->type >= INTUOS3S) { - input_report_abs(input, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); - input_report_abs(input, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); - } else { - input_report_abs(input, ABS_X, be16_to_cpup((__be16 *)&data[2])); - input_report_abs(input, ABS_Y, be16_to_cpup((__be16 *)&data[4])); - input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); + x = (be16_to_cpup((__be16 *)&data[2]) << 1) | ((data[9] >> 1) & 1); + y = (be16_to_cpup((__be16 *)&data[4]) << 1) | (data[9] & 1); + distance = data[9] >> 2; + if (features->type < INTUOS3S) { + x >>= 1; + y >>= 1; + distance >>= 1; } + input_report_abs(input, ABS_X, x); + input_report_abs(input, ABS_Y, y); + input_report_abs(input, ABS_DISTANCE, distance); switch (type) { case 0x00: @@ -909,10 +911,9 @@ static int wacom_intuos_general(struct wacom_wac *wacom) case 0x02: case 0x03: /* general pen packet */ - t = (data[6] << 2) | ((data[7] >> 6) & 3); - if (features->pressure_max == 2047) { - t = (t << 1) | (data[1] & 1); - } + t = (data[6] << 3) | ((data[7] & 0xC0) >> 5) | (data[1] & 1); + if (features->pressure_max < 2047) + t >>= 1; input_report_abs(input, ABS_PRESSURE, t); if (features->type != INTUOSHT2) { input_report_abs(input, ABS_TILT_X,