Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3697474rwl; Sun, 2 Apr 2023 13:13:09 -0700 (PDT) X-Google-Smtp-Source: AKy350bkr6lbbRKvwnMl7n74O+JFIIc/Ltbf7B51QhiQW9PP4LLGD1vCfgp75OXhg5TtoPgs41DF X-Received: by 2002:a17:907:1905:b0:8b1:3467:d71b with SMTP id ll5-20020a170907190500b008b13467d71bmr35437272ejc.48.1680466389699; Sun, 02 Apr 2023 13:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680466389; cv=none; d=google.com; s=arc-20160816; b=m4Waj3NaifHsF6sMVhom8dtLTha+QHNgSk4BNA0SMUPDh34918n7dyNduqR/mjqQJe XIkdxGJ/zkFMscQWGEDMLVoWBoRbS0SjimJzO5EtstdIfTmyKUlkZh25SMwSTXf3Qz43 9qNpB1hWpgrELRXlDp2URPRsoih/wemEBKHqTdu7RU9DScHmwI7Qf53SZZBga+ou1XiV 5hwb1fPBi3LNKBfeGnQ1odjtsngQyeS5Cf8GiIGAz/JN66J8faqDi5Yjc5KMEfo9gJGo iBtEPPo/B6zZGzjmekyS3HqxUbHiMKMuysV+ecRu+k6KUAtWoermgaWcKJzeK3wOCqja kLpA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id de44-20020a1709069bec00b009281f44dc1fsi2167682ejc.270.2023.04.02.13.12.45; Sun, 02 Apr 2023 13:13:09 -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 S230283AbjDBUKd (ORCPT + 99 others); Sun, 2 Apr 2023 16:10:33 -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=20Kleine-K=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 Content-Transfer-Encoding: 8bit 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 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, -- 2.32.0