Re: [PATCH v2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown

From: Michal Piekos

Date: Mon Mar 09 2026 - 01:30:31 EST


On Sun, Mar 08, 2026 at 10:06:42PM +0800, Chen-Yu Tsai wrote:
> On Sun, Mar 8, 2026 at 9:42 PM Michal Piekos
> <michal.piekos@xxxxxxxxxxxxx> wrote:
> >
> > Fixes kernel hang during boot due to inability to set up IRQ on AXP313a.
> >
> > The issue is caused by gpiochip::get_direction() which was returning
> > -ENODEV when gpio is in unitialized state.
> >
> > Instead of failing when the current muxval is at default value, report
> > the line as input.
>
> I don't really like this "fix". It's really lying.
>
> Also, this problem only occurs if the interrupt is taken directly using
> the DT "interrupts" property, as that mostly bypasses the GPIO subsystem,
> especially the gpio request part.
>
> If the consumer does gpiod_request() followed by gpiod_to_irq(), then
> the pin is already muxed to either one of the GPIO functions and this
> won't error out.
>
> I also found that if the interrupt is taken directly through the device
> tree, the pin itself is not locked out (like for GPIOs, on sunxi we also
> don't do pinctrl settings for pins used for interrupts).
>
> I think the proper fix would be to somehow be able to request the pin
> as GPIO if it hasn't been requested already. And then either
> sunxi_pinctrl_irq_request_resources() can use that to request the pin
> and mux the pin before calling gpiochip_lock_as_irq().
>
> Hope Linus and Bartosz have some suggestions.
>
>
> Thanks
> ChenYu
>

I will prepare new version with your suggestion.

Michal

>
> > Tested on Orange Pi Zero 3.
> >
> > Signed-off-by: Michal Piekos <michal.piekos@xxxxxxxxxxxxx>
> > Suggested-by: Andrey Skvortsov <andrej.skvortzov@xxxxxxxxx>
> > ---
> > This fixes a kernel hang during boot on the Orange Pi Zero 3 caused by
> > inability to set up interrupt for the AXP313A PMIC.
> >
> > The issue is caused by gpiochip::get_direction() which was returning
> > -ENODEV when gpio is in unitialized state and its muxval is at default
> > value.
> >
> > Instead of failing, report the line as input.
> >
> > To: Rob Herring <robh@xxxxxxxxxx>
> > To: Krzysztof Kozlowski <krzk+dt@xxxxxxxxxx>
> > To: Conor Dooley <conor+dt@xxxxxxxxxx>
> > To: Chen-Yu Tsai <wens@xxxxxxxxxx>
> > To: Jernej Skrabec <jernej.skrabec@xxxxxxxxx>
> > To: Samuel Holland <samuel@xxxxxxxxxxxx>
> > To: Andre Przywara <andre.przywara@xxxxxxx>
> > To: Linus Walleij <linusw@xxxxxxxxxx>
> > Cc: devicetree@xxxxxxxxxxxxxxx
> > Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
> > Cc: linux-sunxi@xxxxxxxxxxxxxxx
> > Cc: linux-kernel@xxxxxxxxxxxxxxx
> > Cc: linux-gpio@xxxxxxxxxxxxxxx
> >
> > Changes in v2:
> > - Dropped the previous faulty solution which was forcing the axp313 to
> > use r_pio as interrupt controller as pointed out by Jernej Škrabec.
> > - Implemented suggestion from Andrey Skvortsov to return default
> > direction as input
> > - Link to v1: https://lore.kernel.org/r/20260308-rc2-boot-hang-v1-0-d792d1a78dfd@xxxxxxxxxxxxx
> > ---
> > drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> > index c990b6118172..e438cf35ff28 100644
> > --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> > +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
> > @@ -971,7 +971,7 @@ static int sunxi_pinctrl_gpio_get_direction(struct gpio_chip *chip,
> >
> > func = sunxi_pinctrl_desc_find_function_by_pin_and_mux(pctl, pin, muxval);
> > if (!func)
> > - return -ENODEV;
> > + return GPIO_LINE_DIRECTION_IN;
> >
> > if (!strcmp(func->name, "gpio_out"))
> > return GPIO_LINE_DIRECTION_OUT;
> >
> > ---
> > base-commit: 4ae12d8bd9a830799db335ee661d6cbc6597f838
> > change-id: 20260308-rc2-boot-hang-269e8546635b
> >
> > Best regards,
> > --
> > Michal Piekos <michal.piekos@xxxxxxxxxxxxx>
> >
> >