Re: [RFC PATCH] gpio: mt7621: fix interrupt banks mapping on gpio chips
From: Sergio Paracuellos
Date: Tue May 26 2026 - 07:57:50 EST
Hi Bartosz,
On Tue, May 26, 2026 at 1:38 PM Bartosz Golaszewski <brgl@xxxxxxxxxx> wrote:
>
> On Fri, May 22, 2026 at 9:29 AM Sergio Paracuellos
> <sergio.paracuellos@xxxxxxxxx> wrote:
> >
> > Regarding the issue reported by Vicente[0], we have been trying different
> > things and we are still having issues to make this work. I have noticed
> > that the gpio-brcmstb is similar to our use case sharing one interrupt
> > for all the banks and also using gpio chips instances with 32 pins each.
> > That said, I tried to setup mt7621 driver in the same way as you can see
> > on the following proposed code. With these changes, we are able to make
> > properly working the previous problem with the touchscreen that was
> > registered on bank 2 instead of bank 0. Now it is properly registered
> > on bank 0 and interrupts works perfect and the device is properly
> > working. However, every single gpio-keys fail to claim the IRQ HW as
> > follows:
> >
> > mt7621_gpio 10000600.gpio: Mapping irq 41 for gpio line 38 (bank 1)
> > gpio gpiochip1: (10000600.gpio-bank1): unable to lock HW IRQ 38 for IRQ
>
> At which line in gpiolib.c does this fail exactly?
This was failing because of using a linear domain with 96 pins in
total but having three gpio chip instances with
32 pins each so it looks gpiolib found hwirq number out of range 0-32
for the chip and refused to mark the pin as IRQ capable.
If I get rid of GPIOCHIP_IRQ_RESOURCE_HELPERS and add my owns
converting irq into the proper pin within the chip
as follows, gpio-keys are properly registered and also properly working:
static int
mt7621_gpio_irq_reqres(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct mtk_gc *rg = gpiochip_get_data(gc);
unsigned int irq = mt7621_gpio_hwirq_to_offset(d->hwirq, rg);
return gpiochip_reqres_irq(gc, irq);
}
static void
mt7621_gpio_irq_relres(struct irq_data *d)
{
struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
struct mtk_gc *rg = gpiochip_get_data(gc);
unsigned int irq = mt7621_gpio_hwirq_to_offset(d->hwirq, rg);
gpiochip_relres_irq(gc, irq);
}
We are still testing but I will send a proper working patch for you to
review and comment during this week.
Thanks,
Sergio Paracuellos
>
> > genirq: Failed to request resources for S3 (irq 41) on irqchip mt7621-gpio
> > gpio-keys keys: error -EINVAL: request_irq(41) gpio_keys_gpio_isr 0x0 S3
> > gpio-keys keys: Unable to claim irq 41; error -22
> > gpio-keys keys: probe with driver gpio-keys failed with error -22
> >
> > So IIUC the kernel is saying that the gpio chip is not IRQ-capable somehow.
> >
> > Once I touch the irq field just setting up the irq_chip_ops on gpio chip to bypass
> > this issue:
> >
> > gpio_irq_chip_set_chip(&rg->chip.gc.irq, &mt7621_irq_chip);
> >
> > the kernel stops calling our custom to_irq callback and calls gpiochip_to_irq
> > callback instead and also warning as follows:
> >
> > gpio gpiochip0: (10000600.gpio-bank0): to_irq is redefined in
> > gpiochip_irqchip_add_allocated_domain and you shouldn't rely on it
> > gpio gpiochip1: (10000600.gpio-bank1): to_irq is redefined in
> > gpiochip_irqchip_add_allocated_domain and you shouldn't rely on it
> > gpio gpiochip2: (10000600.gpio-bank2): to_irq is redefined in
> > gpiochip_irqchip_add_allocated_domain and you shouldn't rely on it
> >
>
> Are you calling gpiochip_add_irqchip() in your changes?
>
> Bart