From patchwork Mon Aug 3 17:18:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 6932011 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 E6AC89F38B for ; Mon, 3 Aug 2015 17:18:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D757E20386 for ; Mon, 3 Aug 2015 17:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C2AB42037E for ; Mon, 3 Aug 2015 17:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754190AbbHCRST (ORCPT ); Mon, 3 Aug 2015 13:18:19 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:34243 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753639AbbHCRSS (ORCPT ); Mon, 3 Aug 2015 13:18:18 -0400 Received: by pdbbo16 with SMTP id bo16so18887077pdb.1 for ; Mon, 03 Aug 2015 10:18:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=6LKnf0k9L+tOlABruX+Jgjl28INjYzVWvQVAzYF+CfI=; b=yUo8wlIS6Qozzcl2xqVbXEobGnw6a7eTH5M/8bwsZjKcgOhjS5kwJqjOGG/LHGsX1R MgUYzIazCG4t4or3KIhfiIsENypE8vHZyl0h2gkAuPN/9If8rjrzByRARcKfoe63V/q0 kbEjweWhDnRpVV+HjIRISi6QDNnoTU0JtKXIvvNRcsNfAODGC5H0mvMlivYLvsYx6Dpb QDNyoosTieg4Cv0GnTIL9SNOG6R60KHb2/DtY31IURX9syylyWOeEL4tlmxLnADTt40w geuoW8SlmLD54IBGb7z5iBqdgDAjD5OZqDmckWIms5s74b6PXtQoxVMOcdE9CMEcFfbk 9BUA== X-Received: by 10.70.129.102 with SMTP id nv6mr38232193pdb.55.1438622298222; Mon, 03 Aug 2015 10:18:18 -0700 (PDT) Received: from wacom-arch2.localdomain ([67.51.163.2]) by smtp.gmail.com with ESMTPSA id em1sm8525237pbd.42.2015.08.03.10.18.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Aug 2015 10:18:17 -0700 (PDT) From: Jason Gerecke To: Jiri Kosina , Benjamin Tissoires Cc: Aaron Skomra , Ping Cheng , linux-input@vger.kernel.org, Jason Gerecke , Jason Gerecke Subject: [PATCH] HID: wacom: Simplify 'wacom_pl_irq' Date: Mon, 3 Aug 2015 10:18:10 -0700 Message-Id: <1438622290-6844-1-git-send-email-killertofu@gmail.com> X-Mailer: git-send-email 2.4.6 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 Unlike other IRQ functions, 'wacom_pl_irq' uses the second element of the 'tool' array to store information about its single pen. This makes the function more difficult to understand (since it doesn't follow the general pattern of other IRQ functions) and prevents the possibility of refactoring how pen state is stored. This patch rewrites 'wacom_pl_irq' to follow the usual IRQ conventions, including storing tool type in 'tool[0]' and implicitly tracking prox with the 'id[0]' variable. Signed-off-by: Jason Gerecke --- drivers/hid/wacom_wac.c | 84 +++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 4d11c78..fe164df 100644 --- a/drivers/hid/wacom_wac.c +++ b/drivers/hid/wacom_wac.c @@ -125,61 +125,47 @@ static int wacom_pl_irq(struct wacom_wac *wacom) prox = data[1] & 0x40; - if (prox) { - wacom->id[0] = ERASER_DEVICE_ID; - pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); - if (features->pressure_max > 255) - pressure = (pressure << 1) | ((data[4] >> 6) & 1); - pressure += (features->pressure_max + 1) / 2; - - /* - * if going from out of proximity into proximity select between the eraser - * and the pen based on the state of the stylus2 button, choose eraser if - * pressed else choose pen. if not a proximity change from out to in, send - * an out of proximity for previous tool then a in for new tool. - */ - if (!wacom->tool[0]) { - /* Eraser bit set for DTF */ - if (data[1] & 0x10) - wacom->tool[1] = BTN_TOOL_RUBBER; - else - /* Going into proximity select tool */ - wacom->tool[1] = (data[4] & 0x20) ? BTN_TOOL_RUBBER : BTN_TOOL_PEN; - } else { - /* was entered with stylus2 pressed */ - if (wacom->tool[1] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) { - /* report out proximity for previous tool */ - input_report_key(input, wacom->tool[1], 0); - input_sync(input); - wacom->tool[1] = BTN_TOOL_PEN; - return 0; - } + if (!wacom->id[0]) { + if ((data[0] & 0x10) || (data[4] & 0x20)) { + wacom->tool[0] = BTN_TOOL_RUBBER; + wacom->id[0] = ERASER_DEVICE_ID; } - if (wacom->tool[1] != BTN_TOOL_RUBBER) { - /* Unknown tool selected default to pen tool */ - wacom->tool[1] = BTN_TOOL_PEN; + else { + wacom->tool[0] = BTN_TOOL_PEN; wacom->id[0] = STYLUS_DEVICE_ID; } - input_report_key(input, wacom->tool[1], prox); /* report in proximity for tool */ - input_report_abs(input, ABS_MISC, wacom->id[0]); /* report tool id */ - input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); - input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); - input_report_abs(input, ABS_PRESSURE, pressure); + } - input_report_key(input, BTN_TOUCH, data[4] & 0x08); - input_report_key(input, BTN_STYLUS, data[4] & 0x10); - /* Only allow the stylus2 button to be reported for the pen tool. */ - input_report_key(input, BTN_STYLUS2, (wacom->tool[1] == BTN_TOOL_PEN) && (data[4] & 0x20)); - } else { - /* report proximity-out of a (valid) tool */ - if (wacom->tool[1] != BTN_TOOL_RUBBER) { - /* Unknown tool selected default to pen tool */ - wacom->tool[1] = BTN_TOOL_PEN; - } - input_report_key(input, wacom->tool[1], prox); + /* If the eraser is in prox, STYLUS2 is always set. If we + * mis-detected the type and notice that STYLUS2 isn't set + * then force the eraser out of prox and let the pen in. + */ + if (wacom->tool[0] == BTN_TOOL_RUBBER && !(data[4] & 0x20)) { + input_report_key(input, BTN_TOOL_RUBBER, 0); + input_report_abs(input, ABS_MISC, 0); + input_sync(input); + wacom->tool[0] = BTN_TOOL_PEN; + wacom->id[0] = STYLUS_DEVICE_ID; } - wacom->tool[0] = prox; /* Save proximity state */ + pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); + if (features->pressure_max > 255) + pressure = (pressure << 1) | ((data[4] >> 6) & 1); + pressure += (features->pressure_max + 1) / 2; + + input_report_abs(input, ABS_X, data[3] | (data[2] << 7) | ((data[1] & 0x03) << 14)); + input_report_abs(input, ABS_Y, data[6] | (data[5] << 7) | ((data[4] & 0x03) << 14)); + input_report_abs(input, ABS_PRESSURE, pressure); + + input_report_key(input, BTN_TOUCH, data[4] & 0x08); + input_report_key(input, BTN_STYLUS, data[4] & 0x10); + /* Only allow the stylus2 button to be reported for the pen tool. */ + input_report_key(input, BTN_STYLUS2, (wacom->tool[0] == BTN_TOOL_PEN) && (data[4] & 0x20)); + + if (!prox) + wacom->id[0] = 0; + input_report_key(input, wacom->tool[0], prox); + input_report_abs(input, ABS_MISC, wacom->id[0]); return 1; }