mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@duagon.com>
To: linusw@kernel.org, brgl@kernel.org, wbg@kernel.org
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jose Javier Rodriguez Barbarin
	<dev-josejavier.rodriguez@duagon.com>
Subject: [RFC PATCH v2 2/3] gpio: mmio: add port-mapped read/write callbacks
Date: Mon, 13 Apr 2026 12:23:25 +0200	[thread overview]
Message-ID: <20260413102326.59343-3-dev-josejavier.rodriguez@duagon.com> (raw)
In-Reply-To: <20260413102326.59343-1-dev-josejavier.rodriguez@duagon.com>

Implement PMIO read and write callbacks for 8-, 16- and 32-bit
register accesses using the corresponding port I/O helpers.

Signed-off-by: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@duagon.com>
---
 drivers/gpio/gpio-mmio.c | 94 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index 39326ab7e494..d23c5d275e6b 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -124,6 +124,60 @@ static unsigned long gpio_mmio_read32be(union gpio_chip_reg *reg)
 	return ioread32be(reg->mmio);
 }
 
+#ifdef CONFIG_HAS_IOPORT
+
+static void gpio_port_write8(union gpio_chip_reg *reg, unsigned long data)
+{
+	outb(data, reg->port);
+}
+
+static unsigned long gpio_port_read8(union gpio_chip_reg *reg)
+{
+	return inb(reg->port);
+}
+
+static void gpio_port_write16(union gpio_chip_reg *reg, unsigned long data)
+{
+	outw(data, reg->port);
+}
+
+static unsigned long gpio_port_read16(union gpio_chip_reg *reg)
+{
+	return inw(reg->port);
+}
+
+static void gpio_port_write32(union gpio_chip_reg *reg, unsigned long data)
+{
+	outl(data, reg->port);
+}
+
+static unsigned long gpio_port_read32(union gpio_chip_reg *reg)
+{
+	return inl(reg->port);
+}
+
+static void gpio_port_write16be(union gpio_chip_reg *reg, unsigned long data)
+{
+	outw(swab16(data), reg->port);
+}
+
+static unsigned long gpio_port_read16be(union gpio_chip_reg *reg)
+{
+	return swab16(inw(reg->port));
+}
+
+static void gpio_port_write32be(union gpio_chip_reg *reg, unsigned long data)
+{
+	outl(swab32(data), reg->port);
+}
+
+static unsigned long gpio_port_read32be(union gpio_chip_reg *reg)
+{
+	return swab32(inl(reg->port));
+}
+
+#endif /* CONFIG_HAS_IOPORT */
+
 static inline bool gpio_chip_reg_is_set(union gpio_chip_reg *reg)
 {
 	return reg->port != 0;
@@ -462,6 +516,46 @@ static int gpio_mmio_dir_out_val_first(struct gpio_chip *gc, unsigned int gpio,
 	return gpio_mmio_dir_return(gc, gpio, true);
 }
 
+static int gpio_port_setup_accessors(struct device *dev,
+				     struct gpio_generic_chip *chip,
+				     bool byte_be)
+{
+#ifdef CONFIG_HAS_IOPORT
+	switch (chip->bits) {
+	case 8:
+		chip->read_reg	= gpio_port_read8;
+		chip->write_reg	= gpio_port_write8;
+		break;
+	case 16:
+		if (byte_be) {
+			chip->read_reg	= gpio_port_read16be;
+			chip->write_reg	= gpio_port_write16be;
+		} else {
+			chip->read_reg	= gpio_port_read16;
+			chip->write_reg	= gpio_port_write16;
+		}
+		break;
+	case 32:
+		if (byte_be) {
+			chip->read_reg	= gpio_port_read32be;
+			chip->write_reg	= gpio_port_write32be;
+		} else {
+			chip->read_reg	= gpio_port_read32;
+			chip->write_reg	= gpio_port_write32;
+		}
+		break;
+	default:
+		dev_err(dev, "unsupported data width %u bits\n", chip->bits);
+		return -EINVAL;
+	}
+
+	return 0;
+#else
+	dev_err(dev, "not supported because of missing I/O resource\n");
+	return -ENXIO;
+#endif /* CONFIG_HAS_IOPORT */
+}
+
 static int gpio_mmio_setup_accessors(struct device *dev,
 				     struct gpio_generic_chip *chip,
 				     bool byte_be)
-- 
2.53.0

  parent reply	other threads:[~2026-04-13 10:24 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-13 10:23 [RFC PATCH v2 0/3] gpio: add PMIO support to gpio-mmio Jose Javier Rodriguez Barbarin
2026-04-13 10:23 ` [RFC PATCH v2 1/3] gpio: mmio: convert accessors to generic register descriptors Jose Javier Rodriguez Barbarin
2026-04-22 16:41   ` Linus Walleij
2026-04-13 10:23 ` Jose Javier Rodriguez Barbarin [this message]
2026-04-22 16:42   ` [RFC PATCH v2 2/3] gpio: mmio: add port-mapped read/write callbacks Linus Walleij
2026-04-13 10:23 ` [RFC PATCH v2 3/3] gpio: mmio: add port-mapped support for gpio_generic_chip Jose Javier Rodriguez Barbarin
2026-04-22 16:43   ` Linus Walleij
2026-04-22 16:44 ` [RFC PATCH v2 0/3] gpio: add PMIO support to gpio-mmio Linus Walleij
2026-04-23  8:00   ` Bartosz Golaszewski
2026-04-23 15:14   ` Jose Javier Rodriguez Barbarin
2026-04-23 16:26     ` Bartosz Golaszewski
2026-04-28  9:56     ` Linus Walleij

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=20260413102326.59343-3-dev-josejavier.rodriguez@duagon.com \
    --to=dev-josejavier.rodriguez@duagon.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wbg@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®