[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230402200951.1032513-6-dario.binacchi@amarulasolutions.com>
Date: Sun, 2 Apr 2023 22:09:47 +0200
From: Dario Binacchi <dario.binacchi@...rulasolutions.com>
To: linux-kernel@...r.kernel.org
Cc: michael@...rulasolutions.com, linux-amarula@...rulasolutions.com,
Dario Binacchi <dario.binacchi@...rulasolutions.com>,
Dmitry Torokhov <dmitry.torokhov@...il.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Oliver Graute <oliver.graute@...oconnector.com>,
Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>,
Wolfram Sang <wsa+renesas@...g-engineering.com>,
linux-input@...r.kernel.org
Subject: [PATCH 5/9] Input: edt-ft5x06 - remove code duplication
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 <dario.binacchi@...rulasolutions.com>
---
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
Powered by blists - more mailing lists