Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp375940pxh; Tue, 9 Nov 2021 12:10:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJxhn9lZUx4T52bvcnN+CVf5sVqdgJWXhHkYzSJ0JVNCTkbqOurl7oLKVF23lX6uSPe8YNR/ X-Received: by 2002:a05:6e02:1aac:: with SMTP id l12mr6869309ilv.268.1636488611765; Tue, 09 Nov 2021 12:10:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636488611; cv=none; d=google.com; s=arc-20160816; b=QmrOHT5KlzYv09tOo0U09kb6J9mnvVsf0dEbi0kK3CLMUoCfDJH6UEEXmSeNqka7nL +3J6f6f4zFlmZfZMg28j/pRx8E8A2bWEIOHEIM8rVVmc4LucgYhIizs74moaSPUpt0vM 1z2DRdjyqU1n5vuEyFvSO16G7uIm0bBXhVtqHwLK2y8rByflSmd1j4kW0zPZKhzZ+tfc 9bTTSSmc08xMIHPky4AmZ7P0rT0Pd2XnQBRIXfgianft20OL+OS67hB6fNjcLogxi7/n IRo+hl8ifiAU+tOpkrGaH0Q5GrUFDmBG1Hani2MRXxsU2w1lDRHWG7fWpdxw7Cewvbq/ mqcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ocne8Jf+CRaD/PTxWbJMJ6anZESoWIg8oVwu3VA3RFU=; b=x5BWLkKdyAcwxnt+JCVHZBzTaOC+k5cDgbCQHha6Ym4LZc1jY2QLgNGy4mfZRkZQ1n idiPdgf8ni6KXGLdZzkYblcpZuVn1Yf+Mm/3UL6gcUGki2DR+wPOShGIZlYZ2Lt5KKIv nxQIiDZiE879zLtyst1PALRqaZJx2046GKQfQ5XuMLrc0XMx716iMiXrYstvL8kS2HFw IZeKJHj+ZYa3FUg+bcbrpUjumecLZJn4wxAvbGPWVTciBvXiTq9Y2dy+bg+jH45TStGF 95GDZ0dIgqce6vXnP/J610L+I62P6TnCpidRr1X2giCib8hA0e4aCp8bAx1qIgubvLQo hYVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YAxtZaFH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si39655776ilv.137.2021.11.09.12.09.57; Tue, 09 Nov 2021 12:10:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=YAxtZaFH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245102AbhKIKBx (ORCPT + 99 others); Tue, 9 Nov 2021 05:01:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242969AbhKIKBw (ORCPT ); Tue, 9 Nov 2021 05:01:52 -0500 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D74DC061764; Tue, 9 Nov 2021 01:59:06 -0800 (PST) Received: by mail-io1-xd29.google.com with SMTP id e144so22354288iof.3; Tue, 09 Nov 2021 01:59:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ocne8Jf+CRaD/PTxWbJMJ6anZESoWIg8oVwu3VA3RFU=; b=YAxtZaFHOVYY7fKxi+LYJgQHvvmv0hAuyglZVjIjIwHLY+bCP6iAExqHKMLrrp8slV QuilRboUyRYpGQiG3nMxSn3a3HzVb9NpMiDGEBMKyFaX4tH/YTWgr1wnbqpgmRzqubUq RtrHw0uVxvmoCTTm0JH09lOIbdXkN7saP+ygMEjmaKDVNq24tjoUSWv9KxnZsyV1D9xQ qVKKgMSapT+nFxt92e8pOCcIngXqlBz8aYfs7aJb5VnvExou7xV5+sSJFckDrXaSQSPO aB5ar8PN47ouJNHYA0/3f1c5NfpM0eBTEexV1zFFSIcecu+U/sQSlzhFmKA6PGHbOfF/ KLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ocne8Jf+CRaD/PTxWbJMJ6anZESoWIg8oVwu3VA3RFU=; b=LUTalVAHNTA2O3mWIDHT4vvbXL/gT9QVAFQ/E7r10Ah1kRL2mjzU76keDZMPS/mRwT CHN0YdioK/2ZZMA2J0d1/4+h2+NZrAhhUHkR1sUcUQK5kfGsEcAqOstWuBht2j4WRLXa VAkcJyt/msx+FxfdSS2DrF6PX1aDkPPfccBFLGeErcoWOorDh8lac30t9W+E/JkGMUW5 jv+r5zH6G0hozeqy2N300ahBGjLYGr7sqG/QfRuWopII0isOQfZiWlFRUqFrnrUOleI8 CViCLe8o5W8LmDIy1oLVyzbp4tSOljB8o7luRMifmiJmmMrDuh6ARSvDLyCeY4S4uVEa 2KTg== X-Gm-Message-State: AOAM532r3hOyu8cx999tzNXdHnbdb/uA89qXexM8OkDAtC5kNaXfxuP8 SuGWPdJAAbJiHYmJwKYIP9jKIOVQN6myvgw1Jc9ISZJeTWcWtA== X-Received: by 2002:a05:6638:d16:: with SMTP id q22mr4535814jaj.35.1636451945942; Tue, 09 Nov 2021 01:59:05 -0800 (PST) MIME-Version: 1.0 References: <20211009113707.17568-1-alistair@alistair23.me> <20211009113707.17568-2-alistair@alistair23.me> In-Reply-To: From: Alistair Francis Date: Tue, 9 Nov 2021 19:58:00 +1000 Message-ID: Subject: Re: [PATCH 2/2] Input: wacom_i2c - Use macros for the bit masks To: Dmitry Torokhov Cc: Alistair Francis , linux-input , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 11:04 PM Alistair Francis wrote: > > On Wed, Oct 13, 2021 at 1:56 PM Dmitry Torokhov > wrote: > > > > Hi Alistair, > > > > On Sat, Oct 09, 2021 at 09:37:07PM +1000, Alistair Francis wrote: > > > To make the code easier to read use macros for the bit masks. > > > > > > Signed-off-by: Alistair Francis > > > --- > > > drivers/input/touchscreen/wacom_i2c.c | 14 ++++++++++---- > > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c > > > index 8d7267ccc661..6865342db659 100644 > > > --- a/drivers/input/touchscreen/wacom_i2c.c > > > +++ b/drivers/input/touchscreen/wacom_i2c.c > > > @@ -14,6 +14,12 @@ > > > #include > > > #include > > > > > > +// Bitmasks (for data[3]) > > > +#define WACOM_TIP_SWITCH_bm (1 << 0) > > > +#define WACOM_BARREL_SWITCH_bm (1 << 1) > > > +#define WACOM_ERASER_bm (1 << 2) > > > +#define WACOM_BARREL_SWITCH_2_bm (1 << 4) > > > > We have BIT() for that. > > > > By the way, do you know what is the good name for bit 3? I see it is > > being used in: > > I have this for bit 3: > > #define WACOM_INVERT_bm (1 << 3) > > > > > > if (!wac_i2c->prox) > > wac_i2c->tool = (data[3] & 0x0c) ? > > BTN_TOOL_RUBBER : BTN_TOOL_PEN; > > > > wac_i2c->prox = data[3] & WACOM_IN_PROXIMITY; > > > > 0x0c is (WACOM_ERASER | ). > > > > Also, I am a bit confused by this code, now that I look at it closer. > > Are we saying that the tool type (eraser or something else) is set only > > in first packet for contact/touch? > > I'm not sure, you would have to check with the wacom people. > > > > > > + > > > // Registers > > > #define WACOM_COMMAND_LSB 0x04 > > > #define WACOM_COMMAND_MSB 0x00 > > > @@ -110,10 +116,10 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id) > > > if (error < 0) > > > goto out; > > > > > > - tsw = data[3] & 0x01; > > > - ers = data[3] & 0x04; > > > - f1 = data[3] & 0x02; > > > - f2 = data[3] & 0x10; > > > + tsw = data[3] & WACOM_TIP_SWITCH_bm; > > > + ers = data[3] & WACOM_ERASER_bm; > > > + f1 = data[3] & WACOM_BARREL_SWITCH_bm; > > > + f2 = data[3] & WACOM_BARREL_SWITCH_2_bm; > > > x = le16_to_cpup((__le16 *)&data[4]); > > > y = le16_to_cpup((__le16 *)&data[6]); > > > pressure = le16_to_cpup((__le16 *)&data[8]); > > > -- > > > 2.31.1 > > > > > > > How about the version of the patch below? > > Looks good to me! > > Alistair > > > > > -- > > Dmitry > > > > Input: wacom_i2c - use macros for the bit masks > > > > From: Alistair Francis > > > > To make the code easier to read use macros for the bit masks. > > > > Signed-off-by: Alistair Francis > > Link: https://lore.kernel.org/r/20211009113707.17568-2-alistair@alistair23.me > > Patchwork-Id: 12547519 > > Signed-off-by: Dmitry Torokhov I'm assuming you don't need me to re-send this. Let me know if you want me to though. Alistair > > --- > > drivers/input/touchscreen/wacom_i2c.c | 19 ++++++++++++++----- > > 1 file changed, 14 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/input/touchscreen/wacom_i2c.c b/drivers/input/touchscreen/wacom_i2c.c > > index 22826c387da5..d3ea9aa8a98c 100644 > > --- a/drivers/input/touchscreen/wacom_i2c.c > > +++ b/drivers/input/touchscreen/wacom_i2c.c > > @@ -6,6 +6,7 @@ > > * > > */ > > > > +#include > > #include > > #include > > #include > > @@ -14,6 +15,14 @@ > > #include > > #include > > > > +// Bitmasks (for data[3]) > > +#define WACOM_TIP_SWITCH BIT(0) > > +#define WACOM_BARREL_SWITCH BIT(1) > > +#define WACOM_ERASER BIT(2) > > +#define WACOM_BARREL_SWITCH_2 BIT(4) > > +#define WACOM_IN_PROXIMITY BIT(5) > > + > > +// Registers > > #define WACOM_CMD_QUERY0 0x04 > > #define WACOM_CMD_QUERY1 0x00 > > #define WACOM_CMD_QUERY2 0x33 > > @@ -99,10 +108,10 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id) > > if (error < 0) > > goto out; > > > > - tsw = data[3] & 0x01; > > - ers = data[3] & 0x04; > > - f1 = data[3] & 0x02; > > - f2 = data[3] & 0x10; > > + tsw = data[3] & WACOM_TIP_SWITCH; > > + ers = data[3] & WACOM_ERASER; > > + f1 = data[3] & WACOM_BARREL_SWITCH; > > + f2 = data[3] & WACOM_BARREL_SWITCH_2; > > x = le16_to_cpup((__le16 *)&data[4]); > > y = le16_to_cpup((__le16 *)&data[6]); > > pressure = le16_to_cpup((__le16 *)&data[8]); > > @@ -111,7 +120,7 @@ static irqreturn_t wacom_i2c_irq(int irq, void *dev_id) > > wac_i2c->tool = (data[3] & 0x0c) ? > > BTN_TOOL_RUBBER : BTN_TOOL_PEN; > > > > - wac_i2c->prox = data[3] & 0x20; > > + wac_i2c->prox = data[3] & WACOM_IN_PROXIMITY; > > > > input_report_key(input, BTN_TOUCH, tsw || ers); > > input_report_key(input, wac_i2c->tool, wac_i2c->prox);