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

Michal Piekos posted 1 patch 1 month ago
There is a newer version of this series
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH v2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown
Posted by Michal Piekos 1 month ago
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.

Tested on Orange Pi Zero 3.

Signed-off-by: Michal Piekos <michal.piekos@mmpsystems.pl>
Suggested-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
---
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@kernel.org>
To: Krzysztof Kozlowski <krzk+dt@kernel.org>
To: Conor Dooley <conor+dt@kernel.org>
To: Chen-Yu Tsai <wens@kernel.org>
To: Jernej Skrabec <jernej.skrabec@gmail.com>
To: Samuel Holland <samuel@sholland.org>
To: Andre Przywara <andre.przywara@arm.com>
To: Linus Walleij <linusw@kernel.org>
Cc: devicetree@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-sunxi@lists.linux.dev
Cc: linux-kernel@vger.kernel.org
Cc: linux-gpio@vger.kernel.org

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@mmpsystems.pl
---
 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@mmpsystems.pl>

Re: [PATCH v2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown
Posted by Chen-Yu Tsai 1 month ago
On Sun, Mar 8, 2026 at 9:42 PM Michal Piekos
<michal.piekos@mmpsystems.pl> 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


> Tested on Orange Pi Zero 3.
>
> Signed-off-by: Michal Piekos <michal.piekos@mmpsystems.pl>
> Suggested-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
> ---
> 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@kernel.org>
> To: Krzysztof Kozlowski <krzk+dt@kernel.org>
> To: Conor Dooley <conor+dt@kernel.org>
> To: Chen-Yu Tsai <wens@kernel.org>
> To: Jernej Skrabec <jernej.skrabec@gmail.com>
> To: Samuel Holland <samuel@sholland.org>
> To: Andre Przywara <andre.przywara@arm.com>
> To: Linus Walleij <linusw@kernel.org>
> Cc: devicetree@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-sunxi@lists.linux.dev
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-gpio@vger.kernel.org
>
> 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@mmpsystems.pl
> ---
>  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@mmpsystems.pl>
>
>
Re: [PATCH v2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown
Posted by Michal Piekos 1 month ago
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@mmpsystems.pl> 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@mmpsystems.pl>
> > Suggested-by: Andrey Skvortsov <andrej.skvortzov@gmail.com>
> > ---
> > 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@kernel.org>
> > To: Krzysztof Kozlowski <krzk+dt@kernel.org>
> > To: Conor Dooley <conor+dt@kernel.org>
> > To: Chen-Yu Tsai <wens@kernel.org>
> > To: Jernej Skrabec <jernej.skrabec@gmail.com>
> > To: Samuel Holland <samuel@sholland.org>
> > To: Andre Przywara <andre.przywara@arm.com>
> > To: Linus Walleij <linusw@kernel.org>
> > Cc: devicetree@vger.kernel.org
> > Cc: linux-arm-kernel@lists.infradead.org
> > Cc: linux-sunxi@lists.linux.dev
> > Cc: linux-kernel@vger.kernel.org
> > Cc: linux-gpio@vger.kernel.org
> >
> > 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@mmpsystems.pl
> > ---
> >  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@mmpsystems.pl>
> >
> >