[PATCH v7 09/15] gpiolib: regmap: add gpio_regmap_get_chip()

From: Long Zhao via B4 Relay

Date: Tue Sep 15 2026 - 07:19:46 EST


From: Long Zhao <longzhao@xxxxxxxxxxxxx>

Let drivers that implement a custom irqchip retrieve the gpio_chip
after registration. Attach a caller-provided irq_domain only when it
is present.

Signed-off-by: Long Zhao <longzhao@xxxxxxxxxxxxx>
---
drivers/gpio/gpio-regmap.c | 20 +++++++++++++++-----
include/linux/gpio/regmap.h | 1 +
2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index dfcc1f1122ec..56c2c873cbfa 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -296,6 +296,12 @@ void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio)
}
EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);

+struct gpio_chip *gpio_regmap_get_chip(struct gpio_regmap *gpio)
+{
+ return &gpio->gpio_chip;
+}
+EXPORT_SYMBOL_GPL(gpio_regmap_get_chip);
+
/**
* gpio_regmap_register() - Register a generic regmap GPIO controller
* @config: configuration for gpio_regmap
@@ -304,7 +310,6 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
*/
struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
{
- struct irq_domain *irq_domain;
struct gpio_regmap *gpio;
struct gpio_chip *chip;
int ret;
@@ -412,6 +417,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config

#ifdef CONFIG_REGMAP_IRQ
if (config->regmap_irq_chip) {
+ struct irq_domain *irq_domain;
+
gpio->regmap_irq_line = config->regmap_irq_line;
ret = regmap_add_irq_chip_fwnode(dev_fwnode(config->parent), config->regmap,
config->regmap_irq_line, config->regmap_irq_flags,
@@ -420,12 +427,15 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
goto err_remove_gpiochip;

irq_domain = regmap_irq_get_domain(gpio->irq_chip_data);
+ if (irq_domain) {
+ ret = gpiochip_irqchip_add_domain(chip, irq_domain);
+ if (ret)
+ goto err_remove_gpiochip;
+ }
} else
#endif
- irq_domain = config->irq_domain;
-
- if (irq_domain) {
- ret = gpiochip_irqchip_add_domain(chip, irq_domain);
+ if (config->irq_domain) {
+ ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
if (ret)
goto err_remove_gpiochip;
}
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index d7ffc12b00a2..6bc00b9775a5 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -128,5 +128,6 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio);
struct gpio_regmap *devm_gpio_regmap_register(struct device *dev,
const struct gpio_regmap_config *config);
void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio);
+struct gpio_chip *gpio_regmap_get_chip(struct gpio_regmap *gpio);

#endif /* _LINUX_GPIO_REGMAP_H */

--
2.34.1