All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maria Garcia <mariagarcia7293@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: "Linus Walleij" <linus.walleij@linaro.org>,
	"Bartosz Golaszewski" <brgl@bgdev.pl>,
	"Guy Morand" <guy.morand@bytesatwork.ch>,
	"Theo Lébrun" <theo.lebrun@bootlin.com>,
	"Maria Garcia" <mariagarcia7293@gmail.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] gpio: pca953x: Fix TCA6418 bulk transfers and input caching
Date: Mon, 23 Nov 2026 12:32:33 +0100	[thread overview]
Message-ID: <20261123113234.197852-2-mariagarcia7293@gmail.com> (raw)
In-Reply-To: <20261123113234.197852-1-mariagarcia7293@gmail.com>

The TCA6418E does not support PCA-style 0x80 auto-increment on the
command byte, uses MSB-first bit ordering in Bank 0, and requires
input registers to be marked volatile so regmap does not return
stale cached values.

Disable REG_ADDR_AI for TCA6418_TYPE, apply bitrev8() to Bank 0
in bulk read/write helpers, and mark TCA6418_INPUT volatile.

Also, add IRQ-related registers to the tca6418_check_register
function for the sake of completion: GPIO_INT_EN, GPIO_INT_LVL,
GPIO_INT_STAT, INT_STAT

Fixes: 6c99a046edfa ("gpio: pca953x: Add support for TI TCA6418")
Reported-by: Guy Morand <guy.morand@bytesatwork.ch>
Closes: https://lore.kernel.org/linux-gpio/CAFOBSkSHt5nwdqsf=V0esBh23oTkOzy--9-vBQFPBoroGK3-HA@mail.gmail.com/
Tested-by: Guy Morand <guy.morand@bytesatwork.ch>
Signed-off-by: Maria Garcia <mariagarcia7293@gmail.com>
---
 drivers/gpio/gpio-pca953x.c | 41 +++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 3b2407690281..10a6fbdcb64d 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -10,6 +10,7 @@
 
 #include <linux/atomic.h>
 #include <linux/bitmap.h>
+#include <linux/bitrev.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/errno.h>
@@ -37,9 +38,14 @@
 #define PCA953X_INVERT		0x02
 #define PCA953X_DIRECTION	0x03
 
+#define TCA6418_INT_STAT	0x02
+#define TCA6418_INT_STAT_GPI	BIT(1)
+#define TCA6418_GPIO_INT_STAT	0x11
 #define TCA6418_INPUT		0x14
 #define TCA6418_OUTPUT		0x17
+#define TCA6418_GPIO_INT_EN	0x1a
 #define TCA6418_DIRECTION	0x23
+#define TCA6418_GPIO_INT_LVL	0x26
 
 #define REG_ADDR_MASK		GENMASK(5, 0)
 #define REG_ADDR_EXT		BIT(6)
@@ -384,22 +390,37 @@ static bool pcal6534_check_register(struct pca953x_chip *chip, unsigned int reg,
 	return true;
 }
 
-/* TCA6418 breaks the PCA953x register order rule */
+/*
+ * TCA6418 breaks the PCA953x register order rule
+ * Access masks: BIT(0) readable, BIT(1) writeable, BIT(2) volatile
+ */
 static bool tca6418_check_register(struct pca953x_chip *chip, unsigned int reg,
 				   u32 access_type_mask)
 {
-	/*  Valid Input Registers - BIT(0) for readable access */
+	if (reg == TCA6418_INT_STAT)
+		return access_type_mask & (BIT(0) | BIT(1) | BIT(2));
+
+	if (reg >= TCA6418_GPIO_INT_STAT &&
+	    reg < (TCA6418_GPIO_INT_STAT + NBANK(chip)))
+		return access_type_mask & (BIT(0) | BIT(2));
+
 	if (reg >= TCA6418_INPUT && reg < (TCA6418_INPUT + NBANK(chip)))
-		return (access_type_mask & BIT(0));
+		return (access_type_mask & (BIT(0) | BIT(2)));
 
-	/*  Valid Output Registers - BIT(1) for writeable access */
 	if (reg >= TCA6418_OUTPUT && reg < (TCA6418_OUTPUT + NBANK(chip)))
 		return (access_type_mask & (BIT(0) | BIT(1)));
 
-	/*  Valid Direction Registers - BIT(2) for volatile access */
+	if (reg >= TCA6418_GPIO_INT_EN &&
+	    reg < (TCA6418_GPIO_INT_EN + NBANK(chip)))
+		return access_type_mask & (BIT(0) | BIT(1));
+
 	if (reg >= TCA6418_DIRECTION && reg < (TCA6418_DIRECTION + NBANK(chip)))
 		return (access_type_mask & (BIT(0) | BIT(1)));
 
+	if (reg >= TCA6418_GPIO_INT_LVL &&
+	    reg < (TCA6418_GPIO_INT_LVL + NBANK(chip)))
+		return access_type_mask & (BIT(0) | BIT(1));
+
 	return false;
 }
 
@@ -577,6 +598,9 @@ static int pca953x_write_regs(struct pca953x_chip *chip, int reg, unsigned long
 	for (i = 0; i < NBANK(chip); i++)
 		value[i] = bitmap_get_value8(val, i * BANK_SZ);
 
+	if (PCA_CHIP_TYPE(chip->driver_data) == TCA6418_TYPE)
+		value[0] = bitrev8(value[0]);
+
 	ret = regmap_bulk_write(chip->regmap, regaddr, value, NBANK(chip));
 	if (ret < 0) {
 		dev_err(&chip->client->dev, "failed writing register: %d\n", ret);
@@ -598,6 +622,9 @@ static int pca953x_read_regs(struct pca953x_chip *chip, int reg, unsigned long *
 		return ret;
 	}
 
+	if (PCA_CHIP_TYPE(chip->driver_data) == TCA6418_TYPE)
+		value[0] = bitrev8(value[0]);
+
 	for (i = 0; i < NBANK(chip); i++)
 		bitmap_set_value8(val, value[i], i * BANK_SZ);
 
@@ -1251,7 +1278,9 @@ static int pca953x_probe(struct i2c_client *client)
 
 	pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK);
 
-	if (NBANK(chip) > 2 || PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE) {
+	if (PCA_CHIP_TYPE(chip->driver_data) != TCA6418_TYPE &&
+	    (NBANK(chip) > 2 ||
+	     PCA_CHIP_TYPE(chip->driver_data) == PCA957X_TYPE)) {
 		dev_info(dev, "using auto increment\n");
 		regmap_config = &pca953x_ai_i2c_regmap;
 	} else {
-- 
2.52.0


  reply	other threads:[~2026-11-23 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 11:32 [PATCH 0/2] gpio: pca953x: Fix TCA6418 multi-bank I/O, caching, and IRQs Maria Garcia
2026-11-23 11:32 ` Maria Garcia [this message]
2026-11-23 11:48   ` [PATCH 1/2] gpio: pca953x: Fix TCA6418 bulk transfers and input caching sashiko-bot
2026-11-23 11:32 ` [PATCH 2/2] gpio: pca953x: Fix TCA6418 interrupt handling Maria Garcia
2026-11-23 11:47   ` sashiko-bot
2026-11-23 11:42 ` [PATCH 0/2] gpio: pca953x: Fix TCA6418 multi-bank I/O, caching, and IRQs María García Fernández

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123113234.197852-2-mariagarcia7293@gmail.com \
    --to=mariagarcia7293@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=guy.morand@bytesatwork.ch \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=theo.lebrun@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.