From patchwork Sun Apr 2 20:09:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 78296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1901311vqo; Sun, 2 Apr 2023 13:12:21 -0700 (PDT) X-Google-Smtp-Source: AKy350b5BI+tI2+TiiLgEK6uyzNr4Yv1Sj+HCDpZD2DOlLu1An1MWSRbs+sHAXpDxlwDFByJCliR X-Received: by 2002:a17:906:e112:b0:933:1b05:8851 with SMTP id gj18-20020a170906e11200b009331b058851mr31574804ejb.16.1680466341542; Sun, 02 Apr 2023 13:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680466341; cv=none; d=google.com; s=arc-20160816; b=fFdYmvEs7LM6bN4PUT+8JwemyJOynuDKuArh/O4MOKP6+NALwbrPirKbM/izJ4nGdF s0SGdSoxJl+GPwfgWcr9X7XH5zSVw9xJJzHSO1oFpO5aDTOffWgmqwHu8aXqypilJ5Nn Gd/ripDW7GVQ2s3Ru0O9Jo3p0CMoDd76+Ya14QZ/ZKswbBT+P0Hj1b1he2j4Y3wiSQ2T j48QuE8f/l4BeDw6cSwpaOr5JhqFYAJvuwK2klQZpXxzdCk1Vkrp4yoFXbS+eBC3HTxI vGd/L82QEC8krzONkHWcoGsQhQWDJcuhuC5N0reDfIWZC6FLa2Oleur6ayvFpq3PhC6y oPkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kMHERFML/oNzDxt2xRgB06w0p+QqR9zI3HtwO5KrpJg=; b=HAjnaLwJ8LwBCeIh/Q7pfp/8wWw1NkgJZEF13RL2fW3yzkTlfFfdU6/Bbs03O5R7wh /tsgnB2oYedQ0oU5/bOfvjrKcCYkbig+P00CaCjiO0LkApANeufTvRRGnEInmZtGVxUo rEsFMi83FWb6L3V+uK0bzo0vqz3MHsb7SvauJjtcWJZWwyIZtcPEvuPESJCKxdwVtnaF bQN/1JW6GhMt9JCbrTIjc0L6qR5gin27msjWPNNvXbGPjTI9jj84KAfGT+JLSCAlG5+6 4ITM3g4bbMCBrafaDm9uPyXjQMvKYTWy0doajlgo1M5Oo6V13pjwxYhEH0NyeH1uBkyt NPnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BTA0a7k7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020aa7d993000000b004fd2b14ad0asi6716292eds.85.2023.04.02.13.11.58; Sun, 02 Apr 2023 13:12:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=BTA0a7k7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230443AbjDBUKe (ORCPT + 99 others); Sun, 2 Apr 2023 16:10:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbjDBUKW (ORCPT ); Sun, 2 Apr 2023 16:10:22 -0400 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DDAC3586 for ; Sun, 2 Apr 2023 13:10:20 -0700 (PDT) Received: by mail-ed1-x529.google.com with SMTP id eh3so109434009edb.11 for ; Sun, 02 Apr 2023 13:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1680466219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kMHERFML/oNzDxt2xRgB06w0p+QqR9zI3HtwO5KrpJg=; b=BTA0a7k7iFtvaI2JEereURx8iOMHTUOIQcSCoitVWC3sF+WGnPQVeju6CVDc/6tRB2 ZfpEnkmpRBCSppaEZ5OdsY/Oi+Jo32snp7n7puHWzt7bBzxZonHe9cHpKVYQdPMf9Vl7 ZjEVTpQBasomg2sk23RR/gSl5qHGWIR8C9U5c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680466219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kMHERFML/oNzDxt2xRgB06w0p+QqR9zI3HtwO5KrpJg=; b=cnvFworFjtub1Sf05CTd/MmemvOy6+gy83gFLJKqHC6Tl/JKQ0gadZ/cbuF8Kh+7so r1W6sMQCk2Tep5DC4knTxmGSsCMPm01nvdDHQHsurk2aUiN7Io40w19NhEWdINgGC0po PVZ0QKObTDRlmxeWjY5lMipx7djmbbxNeLY4Hh9XlDp7+5vO36KVPtgyt3dlRaVdK4RX djWfysLOqmmiMYiXEcZ7EDuzV+knQ4/P/ubsgCE6TN6MIfmxyzzF7Tc6ZIDeQdAlqeF4 lOwBUTRmef9RMCtoE77gH/L1MR6hwDzig1mK448M70GqzUGj7KX6eBlNGqnSK56AdpjW hpUw== X-Gm-Message-State: AAQBX9dmoUNuONJjCsJx72anaJjmhJ3BEJYDYakD/kzOh5Gfg8mjbTGE dIecZcIJh8o55At1EqfQUbMbjzSKy9unqPARaSY= X-Received: by 2002:a17:906:b049:b0:937:9a24:370b with SMTP id bj9-20020a170906b04900b009379a24370bmr34522323ejb.67.1680466219066; Sun, 02 Apr 2023 13:10:19 -0700 (PDT) Received: from dario-ThinkPad-T14s-Gen-2i.homenet.telecomitalia.it (host-95-248-31-153.retail.telecomitalia.it. [95.248.31.153]) by smtp.gmail.com with ESMTPSA id gl18-20020a170906e0d200b00924d38bbdc0sm3553127ejb.105.2023.04.02.13.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Apr 2023 13:10:18 -0700 (PDT) From: Dario Binacchi To: linux-kernel@vger.kernel.org Cc: michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, Dario Binacchi , Dmitry Torokhov , Jonathan Cameron , Oliver Graute , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?q?=C3=B6nig?= , Wolfram Sang , linux-input@vger.kernel.org Subject: [PATCH 5/9] Input: edt-ft5x06 - remove code duplication Date: Sun, 2 Apr 2023 22:09:47 +0200 Message-Id: <20230402200951.1032513-6-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230402200951.1032513-1-dario.binacchi@amarulasolutions.com> References: <20230402200951.1032513-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762096674898222949?= X-GMAIL-MSGID: =?utf-8?q?1762096674898222949?= The use of the macros M06_REG_ADDR and M06_REG_CMD avoids code duplication without impacting the application load, and reduces the chances of errors or mistakes. Signed-off-by: Dario Binacchi --- drivers/input/touchscreen/edt-ft5x06.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/input/touchscreen/edt-ft5x06.c b/drivers/input/touchscreen/edt-ft5x06.c index d4f39724b259..7d82f412ab15 100644 --- a/drivers/input/touchscreen/edt-ft5x06.c +++ b/drivers/input/touchscreen/edt-ft5x06.c @@ -75,6 +75,9 @@ #define EDT_DEFAULT_NUM_X 1024 #define EDT_DEFAULT_NUM_Y 1024 +#define M06_REG_CMD(factory) ((factory) ? 0xf3 : 0xfc) +#define M06_REG_ADDR(factory, addr) ((factory) ? (addr) & 0x7f : (addr) & 0x3f) + enum edt_pmode { EDT_PMODE_NOT_SUPPORTED, EDT_PMODE_HIBERNATE, @@ -294,8 +297,8 @@ static int edt_ft5x06_register_write(struct edt_ft5x06_ts_data *tsdata, switch (tsdata->version) { case EDT_M06: - wrbuf[0] = tsdata->factory_mode ? 0xf3 : 0xfc; - wrbuf[1] = tsdata->factory_mode ? addr & 0x7f : addr & 0x3f; + wrbuf[0] = M06_REG_CMD(tsdata->factory_mode); + wrbuf[1] = M06_REG_ADDR(tsdata->factory_mode, addr); wrbuf[2] = value; wrbuf[3] = wrbuf[0] ^ wrbuf[1] ^ wrbuf[2]; return edt_ft5x06_ts_readwrite(tsdata->client, 4, @@ -324,8 +327,8 @@ static int edt_ft5x06_register_read(struct edt_ft5x06_ts_data *tsdata, switch (tsdata->version) { case EDT_M06: - wrbuf[0] = tsdata->factory_mode ? 0xf3 : 0xfc; - wrbuf[1] = tsdata->factory_mode ? addr & 0x7f : addr & 0x3f; + wrbuf[0] = M06_REG_CMD(tsdata->factory_mode); + wrbuf[1] = M06_REG_ADDR(tsdata->factory_mode, addr); wrbuf[1] |= tsdata->factory_mode ? 0x80 : 0x40; error = edt_ft5x06_ts_readwrite(tsdata->client, 2, wrbuf, 2,