From patchwork Tue Dec 1 01:13:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 7731731 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 25135BEEE1 for ; Tue, 1 Dec 2015 01:14:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0AE9A20641 for ; Tue, 1 Dec 2015 01:14:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DE31820648 for ; Tue, 1 Dec 2015 01:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754492AbbLABN6 (ORCPT ); Mon, 30 Nov 2015 20:13:58 -0500 Received: from mail-pa0-f54.google.com ([209.85.220.54]:32943 "EHLO mail-pa0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754254AbbLABN6 (ORCPT ); Mon, 30 Nov 2015 20:13:58 -0500 Received: by pabfh17 with SMTP id fh17so208550955pab.0 for ; Mon, 30 Nov 2015 17:13:57 -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=EWCyDKmzk/ZhqJwpsEK/MFlhOB4LtJPSGk550mmN8pY=; b=kHfxPSQ07tb8xmmmrR+YjcezVzDI4IHic0DQ1wFzHPAzNRzAZ97G/XPMDolWr43Zsa Ka3rvNwI7fZYnnpAVaQPf4AjmCbvVIPS0x18QBcFYM5ds+hswGB1kdmA99udUyaTzD8E PGNdPNQqeqOmu2A3yjP/GRT1rm8gkIU5jGW1+Zdn8fGn/GVI8TDo9K7sFmdb+sWQFNKb CwVVjfAL8gHq9gogzo4oJgbb/iiDW7eFFAeaRMPdJOFtgrll3T2Ro+PQvVYwkY4WYm47 6YcuNkIGC2vJ1G2w1BGZ2TH5oF7igGtVqajpp1utitC8aDZKlOFJUNJVbfRPydSY+b/X U31g== X-Received: by 10.98.13.154 with SMTP id 26mr75892827pfn.149.1448932437711; Mon, 30 Nov 2015 17:13:57 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Nov 2015 17:13:57 -0800 (PST) From: Jason Gerecke To: linux-input@vger.kernel.org Cc: Jiri Kosina , Ping Cheng , Aaron Skomra , Jason Gerecke , Jason Gerecke Subject: [PATCH 4/7] HID: wacom: Replace magic masks and comparisons with switch cases Date: Mon, 30 Nov 2015 17:13:49 -0800 Message-Id: <1448932432-10115-4-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 Reasoning through the conditions under which a particular block of code in 'wacom_intuos_general' will be reached is not at all easy due to the sheer number of magic masks and comparisons. Remove these and replace them with a switch statement over the various 'types' of packets that will be encountered. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 79 ++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index e395688..a426cb2 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -886,6 +886,7 @@ static int wacom_intuos_general(struct wacom_wac *wacom) unsigned char *data = wacom->data; 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; if (data[0] != WACOM_REPORT_PENABLED && data[0] != WACOM_REPORT_CINTIQ && @@ -902,8 +903,12 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_abs(input, ABS_DISTANCE, ((data[9] >> 3) & 0x1f)); } - /* general pen packet */ - if ((data[1] & 0xb8) == 0xa0) { + switch (type) { + case 0x00: + case 0x01: + 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); @@ -917,36 +922,40 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_STYLUS, data[1] & 2); input_report_key(input, BTN_STYLUS2, data[1] & 4); input_report_key(input, BTN_TOUCH, t > 10); - } + break; - /* airbrush second packet */ - if ((data[1] & 0xbc) == 0xb4) { + case 0x0a: + case 0x0b: + /* airbrush second packet */ input_report_abs(input, ABS_WHEEL, (data[6] << 2) | ((data[7] >> 6) & 3)); input_report_abs(input, ABS_TILT_X, (((data[7] << 1) & 0x7e) | (data[8] >> 7)) - 64); input_report_abs(input, ABS_TILT_Y, (data[8] & 0x7f) - 64); - } + break; - /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ - if ((data[1] & 0xbc) == 0xa8 || (data[1] & 0xbe) == 0xb0 || (data[1] & 0xbc) == 0xac) { - - if (data[1] & 0x02) { - /* Rotation packet */ - if (features->type >= INTUOS3S) { - /* I3 marker pen rotation */ - t = (data[6] << 3) | ((data[7] >> 5) & 7); - t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : - ((t-1) / 2 + 450)) : (450 - t / 2) ; - input_report_abs(input, ABS_Z, t); - } else { - /* 4D mouse rotation packet */ - t = (data[6] << 3) | ((data[7] >> 5) & 7); - input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? - ((t - 1) / 2) : -t / 2); - } + case 0x05: + case 0x07: + /* Rotation packet */ + if (features->type >= INTUOS3S) { + /* I3 marker pen rotation */ + t = (data[6] << 3) | ((data[7] >> 5) & 7); + t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : + ((t-1) / 2 + 450)) : (450 - t / 2) ; + input_report_abs(input, ABS_Z, t); + } else { + /* 4D mouse rotation packet */ + t = (data[6] << 3) | ((data[7] >> 5) & 7); + input_report_abs(input, ABS_RZ, (data[7] & 0x20) ? + ((t - 1) / 2) : -t / 2); + } + break; - } else if (!(data[1] & 0x10) && features->type < INTUOS3S) { + /* 4D mouse, 2D mouse, marker pen rotation, tilt mouse, or Lens cursor packets */ + case 0x04: + case 0x06: + case 0x08: + if (features->type < INTUOS3S && type != 0x08) { /* 4D mouse packet */ input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_MIDDLE, data[8] & 0x02); @@ -956,8 +965,8 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_EXTRA, data[8] & 0x10); t = (data[6] << 2) | ((data[7] >> 6) & 3); input_report_abs(input, ABS_THROTTLE, (data[8] & 0x08) ? -t : t); - - } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { + } + else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { /* I4 mouse */ if (features->type >= INTUOS4S && features->type <= INTUOSPL) { input_report_key(input, BTN_LEFT, data[6] & 0x01); @@ -985,10 +994,11 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_EXTRA, data[8] & 0x20); } } - } else if ((features->type < INTUOS3S || features->type == INTUOS3L || - features->type == INTUOS4L || features->type == INTUOS5L || - features->type == INTUOSPL) && - wacom->tool[idx] == BTN_TOOL_LENS) { + } + else if ((features->type < INTUOS3S || features->type == INTUOS3L || + features->type == INTUOS4L || features->type == INTUOS5L || + features->type == INTUOSPL) && + wacom->tool[idx] == BTN_TOOL_LENS) { /* Lens cursor packets */ input_report_key(input, BTN_LEFT, data[8] & 0x01); input_report_key(input, BTN_MIDDLE, data[8] & 0x02); @@ -996,6 +1006,15 @@ static int wacom_intuos_general(struct wacom_wac *wacom) input_report_key(input, BTN_SIDE, data[8] & 0x10); input_report_key(input, BTN_EXTRA, data[8] & 0x08); } + break; + + case 0x09: + case 0x0c: + case 0x0d: + case 0x0e: + case 0x0f: + /* unhandled */ + break; } input_report_abs(input, ABS_MISC, wacom->id[idx]); /* report tool id */