Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH] gpio: menz127: add support for 16Z034 and 16Z037 GPIO controllers
@ 2025-10-31 10:07 Jose Javier Rodriguez Barbarin
  2025-11-05  8:36 ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Jose Javier Rodriguez Barbarin @ 2025-10-31 10:07 UTC (permalink / raw)
  To: linus.walleij, brgl; +Cc: linux-gpio, linux-kernel

From 7655a73f3888a5d164d1f287ba1f2989bb2aadd2 Mon Sep 17 00:00:00 2001
From: Javier Rodriguez <josejavier.rodriguez@duagon.com>
Date: Tue, 28 Oct 2025 17:40:14 +0100
Subject: [PATCH] gpio: menz127: add support for 16Z034 and 16Z037 GPIO
 controllers

The 16Z034 and 16Z037 are 8 bits GPIO controllers that share the
same registers and features of the 16Z127 GPIO controller.

Reviewed-by: Felipe Fensen Casado <felipe.jensen@duagon.com>
Signed-off-by: Javier Rodriguez <josejavier.rodriguez@duagon.com>
---
 drivers/gpio/gpio-menz127.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-menz127.c b/drivers/gpio/gpio-menz127.c
index da2bf9381cc4..ec9228f1e631 100644
--- a/drivers/gpio/gpio-menz127.c
+++ b/drivers/gpio/gpio-menz127.c
@@ -24,6 +24,12 @@
 #define MEN_Z127_ODER	0x1C
 #define GPIO_TO_DBCNT_REG(gpio)	((gpio * 4) + 0x80)
 
+
+/* MEN Z127 supported model ids*/
+#define MEN_Z127_ID	0x7f
+#define MEN_Z034_ID	0x22
+#define MEN_Z037_ID	0x25
+
 #define MEN_Z127_DB_MIN_US	50
 /* 16 bit compare register. Each bit represents 50us */
 #define MEN_Z127_DB_MAX_US	(0xffff * MEN_Z127_DB_MIN_US)
@@ -36,6 +42,25 @@ struct men_z127_gpio {
 	struct resource *mem;
 };
 
+static int men_z127_lookup_gpio_size(struct mcb_device *mdev,
+				     unsigned long *sz)
+{
+	switch (mdev->id) {
+	case MEN_Z127_ID:
+		*sz = 4;
+		break;
+	case MEN_Z034_ID:
+	case MEN_Z037_ID:
+		*sz = 1;
+		break;
+	default:
+		dev_err(&mdev->dev, "no size found for id %d", mdev->id);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int men_z127_debounce(struct gpio_chip *gc, unsigned gpio,
 			     unsigned debounce)
 {
@@ -140,6 +165,7 @@ static int men_z127_probe(struct mcb_device *mdev,
 	struct men_z127_gpio *men_z127_gpio;
 	struct device *dev = &mdev->dev;
 	int ret;
+	unsigned long sz;
 
 	men_z127_gpio = devm_kzalloc(dev, sizeof(struct men_z127_gpio),
 				     GFP_KERNEL);
@@ -163,9 +189,13 @@ static int men_z127_probe(struct mcb_device *mdev,
 
 	mcb_set_drvdata(mdev, men_z127_gpio);
 
+	ret = men_z127_lookup_gpio_size(mdev, &sz);
+	if (ret)
+		return ret;
+
 	config = (struct gpio_generic_chip_config) {
 		.dev = &mdev->dev,
-		.sz = 4,
+		.sz = sz,
 		.dat = men_z127_gpio->reg_base + MEN_Z127_PSR,
 		.set = men_z127_gpio->reg_base + MEN_Z127_CTRL,
 		.dirout = men_z127_gpio->reg_base + MEN_Z127_GPIODR,
@@ -186,7 +216,9 @@ static int men_z127_probe(struct mcb_device *mdev,
 }
 
 static const struct mcb_device_id men_z127_ids[] = {
-	{ .device = 0x7f },
+	{ .device = MEN_Z127_ID },
+	{ .device = MEN_Z034_ID },
+	{ .device = MEN_Z037_ID },
 	{ }
 };
 MODULE_DEVICE_TABLE(mcb, men_z127_ids);
-- 
2.51.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-07 13:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31 10:07 [PATCH] gpio: menz127: add support for 16Z034 and 16Z037 GPIO controllers Jose Javier Rodriguez Barbarin
2025-11-05  8:36 ` Bartosz Golaszewski
2025-11-07 13:25   ` Jose Javier Rodriguez Barbarin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox