diff mbox series

[v3,2/2] gpiolib: support parsing gpio three-cell interrupts scheme

Message ID 20250326-04-gpio-irq-threecell-v3-2-aab006ab0e00@gentoo.org
State New
Headers show
Series gpio: irq: support describing three-cell interrupts | expand

Commit Message

Yixun Lan March 25, 2025, 10:06 p.m. UTC
gpio irq which using three-cell scheme should always call
instance_match() function to find the correct irqdomain.

The select() function will be called with !DOMAIN_BUS_ANY,
so for specific gpio irq driver, it need to set bus token
explicitly, something like:
  irq_domain_update_bus_token(girq->domain, DOMAIN_BUS_WIRED);

Signed-off-by: Yixun Lan <dlan@gentoo.org>
---
 drivers/gpio/gpiolib-of.c |  8 ++++++++
 drivers/gpio/gpiolib-of.h |  6 ++++++
 drivers/gpio/gpiolib.c    | 22 ++++++++++++++++++----
 3 files changed, 32 insertions(+), 4 deletions(-)

Comments

Yixun Lan April 7, 2025, 10:33 a.m. UTC | #1
Hi Linus Walleij:

On 06:06 Wed 26 Mar     , Yixun Lan wrote:
> gpio irq which using three-cell scheme should always call
> instance_match() function to find the correct irqdomain.
> 
> The select() function will be called with !DOMAIN_BUS_ANY,
> so for specific gpio irq driver, it need to set bus token
> explicitly, something like:
>   irq_domain_update_bus_token(girq->domain, DOMAIN_BUS_WIRED);
> 
> Signed-off-by: Yixun Lan <dlan@gentoo.org>
> ---
>  drivers/gpio/gpiolib-of.c |  8 ++++++++
>  drivers/gpio/gpiolib-of.h |  6 ++++++
>  drivers/gpio/gpiolib.c    | 22 ++++++++++++++++++----
>  3 files changed, 32 insertions(+), 4 deletions(-)
> 

  I'd assume this patch [2/2] will go via pinctrl's tree?
as patch [1/2] has been accepted by Thomas into tip tree [1]..
  Additonally need to pull that commit first? since it's a dependency

[1] https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=irq/core&id=0a02e1f4a54ace747304687ced3b76d159e58914
Bartosz Golaszewski April 7, 2025, 11:26 a.m. UTC | #2
On Mon, Apr 7, 2025 at 12:33 PM Yixun Lan <dlan@gentoo.org> wrote:
>
> Hi Linus Walleij:
>
> On 06:06 Wed 26 Mar     , Yixun Lan wrote:
> > gpio irq which using three-cell scheme should always call
> > instance_match() function to find the correct irqdomain.
> >
> > The select() function will be called with !DOMAIN_BUS_ANY,
> > so for specific gpio irq driver, it need to set bus token
> > explicitly, something like:
> >   irq_domain_update_bus_token(girq->domain, DOMAIN_BUS_WIRED);
> >
> > Signed-off-by: Yixun Lan <dlan@gentoo.org>
> > ---
> >  drivers/gpio/gpiolib-of.c |  8 ++++++++
> >  drivers/gpio/gpiolib-of.h |  6 ++++++
> >  drivers/gpio/gpiolib.c    | 22 ++++++++++++++++++----
> >  3 files changed, 32 insertions(+), 4 deletions(-)
> >
>
>   I'd assume this patch [2/2] will go via pinctrl's tree?
> as patch [1/2] has been accepted by Thomas into tip tree [1]..
>   Additonally need to pull that commit first? since it's a dependency
>

No, this should go through the GPIO tree but for that I'd need an
immutable tag with patch 1/2.

Bart
Bartosz Golaszewski April 8, 2025, 8:59 a.m. UTC | #3
On Tue, Apr 8, 2025 at 10:47 AM Thomas Gleixner <tglx@linutronix.de> wrote:
>
> On Mon, Apr 07 2025 at 13:26, Bartosz Golaszewski wrote:
> > On Mon, Apr 7, 2025 at 12:33 PM Yixun Lan <dlan@gentoo.org> wrote:
> >> On 06:06 Wed 26 Mar     , Yixun Lan wrote:
> >>   I'd assume this patch [2/2] will go via pinctrl's tree?
> >> as patch [1/2] has been accepted by Thomas into tip tree [1]..
> >>   Additonally need to pull that commit first? since it's a dependency
> >>
> >
> > No, this should go through the GPIO tree but for that I'd need an
> > immutable tag with patch 1/2.
>
> Here you go:
>
>    git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irqdomain-04-08-25
>
> Thanks,
>
>         tglx

Thanks, pulled.

Bartosz
Yixun Lan April 8, 2025, 11:53 a.m. UTC | #4
Hi Bartosz:

On 11:03 Tue 08 Apr     , Bartosz Golaszewski wrote:
> On Tue, Mar 25, 2025 at 11:08 PM Yixun Lan <dlan@gentoo.org> wrote:
> >
> > gpio irq which using three-cell scheme should always call
> > instance_match() function to find the correct irqdomain.
> >
> > The select() function will be called with !DOMAIN_BUS_ANY,
> > so for specific gpio irq driver, it need to set bus token
> > explicitly, something like:
> >   irq_domain_update_bus_token(girq->domain, DOMAIN_BUS_WIRED);
> >
> > Signed-off-by: Yixun Lan <dlan@gentoo.org>
> > ---
> 
> This doesn't apply on top of my gpio/for-next branch. Please rebase
> your patch and resend. Patch 1/2 is already on that branch.
> 
Ok, will do, thanks
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c
index 2e537ee979f3e2b6e8d5f86f3e121a66f2a8e083..e19904569fb1b71c1fff237132d17050ef02b074 100644
--- a/drivers/gpio/gpiolib-of.c
+++ b/drivers/gpio/gpiolib-of.c
@@ -1187,3 +1187,11 @@  void of_gpiochip_remove(struct gpio_chip *chip)
 {
 	of_node_put(dev_of_node(&chip->gpiodev->dev));
 }
+
+bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index)
+{
+	if (gc->of_node_instance_match)
+		return gc->of_node_instance_match(gc, index);
+
+	return false;
+}
diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h
index 16d6ac8cb156c02232ea868b755bbdc46c78e3c7..3eebfac290c571e3b90e4437295db8eaacb021a3 100644
--- a/drivers/gpio/gpiolib-of.h
+++ b/drivers/gpio/gpiolib-of.h
@@ -22,6 +22,7 @@  struct gpio_desc *of_find_gpio(struct device_node *np,
 			       unsigned long *lookupflags);
 int of_gpiochip_add(struct gpio_chip *gc);
 void of_gpiochip_remove(struct gpio_chip *gc);
+bool of_gpiochip_instance_match(struct gpio_chip *gc, unsigned int index);
 int of_gpio_count(const struct fwnode_handle *fwnode, const char *con_id);
 #else
 static inline struct gpio_desc *of_find_gpio(struct device_node *np,
@@ -33,6 +34,11 @@  static inline struct gpio_desc *of_find_gpio(struct device_node *np,
 }
 static inline int of_gpiochip_add(struct gpio_chip *gc) { return 0; }
 static inline void of_gpiochip_remove(struct gpio_chip *gc) { }
+static inline bool of_gpiochip_instance_match(struct gpio_chip *gc,
+					      unsigned int index)
+{
+	return false;
+}
 static inline int of_gpio_count(const struct fwnode_handle *fwnode,
 				const char *con_id)
 {
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 679ed764cb143c4b3357106de1570e8d38441372..0729d951ef1fb8431f80f98d09cfbb383c7dffab 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1450,9 +1450,8 @@  static int gpiochip_hierarchy_irq_domain_translate(struct irq_domain *d,
 						   unsigned int *type)
 {
 	/* We support standard DT translation */
-	if (is_of_node(fwspec->fwnode) && fwspec->param_count == 2) {
-		return irq_domain_translate_twocell(d, fwspec, hwirq, type);
-	}
+	if (is_of_node(fwspec->fwnode))
+		return irq_domain_translate_twothreecell(d, fwspec, hwirq, type);
 
 	/* This is for board files and others not using DT */
 	if (is_fwnode_irqchip(fwspec->fwnode)) {
@@ -1754,11 +1753,26 @@  static void gpiochip_irq_unmap(struct irq_domain *d, unsigned int irq)
 	irq_set_chip_data(irq, NULL);
 }
 
+static int gpiochip_irq_select(struct irq_domain *d, struct irq_fwspec *fwspec,
+			       enum irq_domain_bus_token bus_token)
+{
+	struct fwnode_handle *fwnode = fwspec->fwnode;
+	struct gpio_chip *gc = d->host_data;
+	unsigned int index = fwspec->param[0];
+
+	if (fwspec->param_count == 3 && is_of_node(fwnode))
+		return of_gpiochip_instance_match(gc, index);
+
+	/* Fallback for twocells */
+	return (fwnode && (d->fwnode == fwnode) && (d->bus_token == bus_token));
+}
+
 static const struct irq_domain_ops gpiochip_domain_ops = {
 	.map	= gpiochip_irq_map,
 	.unmap	= gpiochip_irq_unmap,
+	.select	= gpiochip_irq_select,
 	/* Virtually all GPIO irqchips are twocell:ed */
-	.xlate	= irq_domain_xlate_twocell,
+	.xlate	= irq_domain_xlate_twothreecell,
 };
 
 static struct irq_domain *gpiochip_simple_create_domain(struct gpio_chip *gc)