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 3/3] gpio: mmio: add port-mapped support for gpio_generic_chip
Date: Mon, 13 Apr 2026 12:23:26 +0200	[thread overview]
Message-ID: <20260413102326.59343-4-dev-josejavier.rodriguez@duagon.com> (raw)
In-Reply-To: <20260413102326.59343-1-dev-josejavier.rodriguez@duagon.com>

Add a new structure gpio_generic_chip_port_config for configuring
PMIO chips. A new function gpio_generic_chip_port_init() allows to
configure them.

Add an io_port field to struct gpio_generic_chip to distinguish PMIO
from MMIO chips during initialization and select the proper register
accessors.

Signed-off-by: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@duagon.com>
---
 drivers/gpio/gpio-mmio.c     | 30 ++++++++++++++++++++++++--
 include/linux/gpio/generic.h | 41 ++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c
index d23c5d275e6b..01e2afd8d6f1 100644
--- a/drivers/gpio/gpio-mmio.c
+++ b/drivers/gpio/gpio-mmio.c
@@ -740,8 +740,12 @@ static int gpio_generic_chip_init_common(struct gpio_generic_chip *chip,
 	if (ret)
 		return ret;
 
-	ret = gpio_mmio_setup_accessors(dev, chip,
-				flags & GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER);
+	if (chip->io_port)
+		ret = gpio_port_setup_accessors(dev, chip,
+					flags & GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER);
+	else
+		ret = gpio_mmio_setup_accessors(dev, chip,
+					flags & GPIO_GENERIC_BIG_ENDIAN_BYTE_ORDER);
 	if (ret)
 		return ret;
 
@@ -801,11 +805,33 @@ int gpio_generic_chip_init(struct gpio_generic_chip *chip,
 	chip->reg_clr.mmio = cfg->clr;
 	chip->reg_dir_in.mmio = cfg->dirin;
 	chip->reg_dir_out.mmio = cfg->dirout;
+	chip->io_port = true;
 
 	return gpio_generic_chip_init_common(chip, cfg->sz, cfg->flags, cfg->dev);
 }
 EXPORT_SYMBOL_GPL(gpio_generic_chip_init);
 
+/**
+ * gpio_generic_chip_port_init() - Initialize a generic GPIO chip for I/O port devices
+ * @chip: Generic GPIO chip to set up.
+ * @cfg: Generic GPIO chip configuration.
+ *
+ * Returns 0 on success, negative error number on failure.
+ */
+int gpio_generic_chip_port_init(struct gpio_generic_chip *chip,
+			   const struct gpio_generic_chip_port_config *cfg)
+{
+	chip->reg_dat.port = cfg->dat;
+	chip->reg_set.port = cfg->set;
+	chip->reg_clr.port = cfg->clr;
+	chip->reg_dir_in.port = cfg->dirin;
+	chip->reg_dir_out.port = cfg->dirout;
+	chip->io_port = true;
+
+	return gpio_generic_chip_init_common(chip, cfg->sz, cfg->flags, cfg->dev);
+}
+EXPORT_SYMBOL_GPL(gpio_generic_chip_port_init);
+
 #if IS_ENABLED(CONFIG_GPIO_GENERIC_PLATFORM)
 
 static void __iomem *gpio_mmio_map(struct platform_device *pdev,
diff --git a/include/linux/gpio/generic.h b/include/linux/gpio/generic.h
index 30f0d87422e9..93ce5f09c0d3 100644
--- a/include/linux/gpio/generic.h
+++ b/include/linux/gpio/generic.h
@@ -56,6 +56,43 @@ struct gpio_generic_chip_config {
 	unsigned long flags;
 };
 
+/**
+ * struct gpio_generic_chip_port_config - Generic GPIO chip configuration data for I/O port devices
+ * @dev: Parent device of the new GPIO chip (compulsory).
+ * @sz: Size (width) of the PMIO registers in bytes, typically 1, 2 or 4.
+ * @dat: PMIO address for the register to READ the value of the GPIO lines, it
+ *       is expected that a 1 in the corresponding bit in this register means
+ *       the line is asserted.
+ * @set: PMIO address for the register to SET the value of the GPIO lines, it
+ *       is expected that we write the line with 1 in this register to drive
+ *       the GPIO line high.
+ * @clr: PMIO address for the register to CLEAR the value of the GPIO lines,
+ *       it is expected that we write the line with 1 in this register to
+ *       drive the GPIO line low. It is allowed to leave this address as NULL,
+ *       in that case the SET register will be assumed to also clear the GPIO
+ *       lines, by actively writing the line with 0.
+ * @dirout: PMIO address for the register to set the line as OUTPUT. It is
+ *          assumed that setting a line to 1 in this register will turn that
+ *          line into an output line. Conversely, setting the line to 0 will
+ *          turn that line into an input.
+ * @dirin: PMIO address for the register to set this line as INPUT. It is
+ *         assumed that setting a line to 1 in this register will turn that
+ *         line into an input line. Conversely, setting the line to 0 will
+ *         turn that line into an output.
+ * @flags: Different flags that will affect the behaviour of the device, such
+ *         as endianness etc.
+ */
+struct gpio_generic_chip_port_config {
+	struct device *dev;
+	unsigned long sz;
+	unsigned long dat;
+	unsigned long set;
+	unsigned long clr;
+	unsigned long dirout;
+	unsigned long dirin;
+	unsigned long flags;
+};
+
 /**
  * union gpio_chip_reg - Generic GPIO chip register descriptor for MMIO or port-mapped I/O
  * @mmio: MMIO register address.
@@ -79,6 +116,7 @@ union gpio_chip_reg {
  *           representing line 0, bit 30 is line 1 ... bit 0 is line 31) this
  *           is set to true by the generic GPIO core. It is for internal
  *           housekeeping only.
+ * @io_port: indicates that the device is I/O port-mapped
  * @reg_dat: data (in) register for generic GPIO
  * @reg_set: output set register (out=high) for generic GPIO
  * @reg_clr: output clear register (out=low) for generic GPIO
@@ -100,6 +138,7 @@ struct gpio_generic_chip {
 	unsigned long (*read_reg)(union gpio_chip_reg *reg);
 	void (*write_reg)(union gpio_chip_reg *reg, unsigned long data);
 	bool be_bits;
+	bool io_port;
 	union gpio_chip_reg reg_dat;
 	union gpio_chip_reg reg_set;
 	union gpio_chip_reg reg_clr;
@@ -122,6 +161,8 @@ to_gpio_generic_chip(struct gpio_chip *gc)
 int gpio_generic_chip_init(struct gpio_generic_chip *chip,
 			   const struct gpio_generic_chip_config *cfg);
 
+int gpio_generic_chip_port_init(struct gpio_generic_chip *chip,
+				const struct gpio_generic_chip_port_config *cfg);
 /**
  * gpio_generic_chip_set() - Set the GPIO line value of the generic GPIO chip.
  * @chip: Generic GPIO chip to use.
-- 
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 ` [RFC PATCH v2 2/3] gpio: mmio: add port-mapped read/write callbacks Jose Javier Rodriguez Barbarin
2026-04-22 16:42   ` Linus Walleij
2026-04-13 10:23 ` Jose Javier Rodriguez Barbarin [this message]
2026-04-22 16:43   ` [RFC PATCH v2 3/3] gpio: mmio: add port-mapped support for gpio_generic_chip 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-4-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®