From: Andre Przywara <andre.przywara@arm.com>
To: wens@kernel.org, Michal Piekos <michal.piekos@mmpsystems.pl>
Cc: Linus Walleij <linusw@kernel.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>,
linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown
Date: Thu, 19 Mar 2026 17:55:11 +0100 [thread overview]
Message-ID: <de634edc-0fc6-4a32-b0f9-77d87df2bbb3@arm.com> (raw)
In-Reply-To: <CAGb2v65c7A7V05ih-GkHxs1tik892Fgt8HhT49_2xHeL91Sh_g@mail.gmail.com>
Hi Michal,
thanks for the very quick turnaround!
On 3/19/26 17:44, Chen-Yu Tsai wrote:
> On Fri, Mar 20, 2026 at 12:10 AM 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_lock_as_irq() which is failing when gpio
>> is in unitialized state.
>
> ^ uninitialized
>
>>
>> Solution is to set pinmux to GPIO INPUT in
>> sunxi_pinctrl_irq_request_resources() if it wasn't initialized
>> earlier.
>>
>> Tested on Orange Pi Zero 3.
>>
>> Fixes: 01e10d0272b9 ("pinctrl: sunxi: Implement gpiochip::get_direction()")
>> Signed-off-by: Michal Piekos <michal.piekos@mmpsystems.pl>
>> ---
>> drivers/pinctrl/sunxi/pinctrl-sunxi.c | 19 +++++++++++++++++++
>> drivers/pinctrl/sunxi/pinctrl-sunxi.h | 2 ++
>> 2 files changed, 21 insertions(+)
>>
>> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
>> index 685b79fc0bf8..321ee97f5745 100644
>> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
>> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
>> @@ -1092,13 +1092,32 @@ static int sunxi_pinctrl_irq_request_resources(struct irq_data *d)
>> {
>> struct sunxi_pinctrl *pctl = irq_data_get_irq_chip_data(d);
>> struct sunxi_desc_function *func;
>> + unsigned int offset;
>> + u32 reg, shift, mask;
>> + u8 muxval;
>> int ret;
>> + bool is_new_layout;
>> + bool is_reset_mux;
>>
>> func = sunxi_pinctrl_desc_find_function_by_pin(pctl,
>> pctl->irq_array[d->hwirq], "irq");
>> if (!func)
>> return -EINVAL;
>>
>> + offset = pctl->irq_array[d->hwirq] - pctl->desc->pin_base;
>> + sunxi_mux_reg(pctl, offset, ®, &shift, &mask);
>> + muxval = (readl(pctl->membase + reg) & mask) >> shift;
>> +
>> + /* Change muxing to GPIO INPUT mode if at reset value */
>> + is_new_layout = pctl->flags & SUNXI_PINCTRL_NEW_REG_LAYOUT;
>
> You would want
>
> !!(pctl->flags & SUNXI_PINCTRL_NEW_REG_LAYOUT)
>
> here to normalize it to a bool value. This is quite common in kernel code.
The whole expression above is a bit cumbersome (though correct). And
since is_reset_mux isn't really needed, I'd suggest something like:
u8 disabled_mux;
....
if (pctl->flags & SUNXI_PINCTRL_NEW_REG_LAYOUT)
disabled_mux = SUN4I_FUNC_DISABLED_NEW;
else
disabled_mux = SUN4I_FUNC_DISABLED_OLD;
if (muxval == disabled_mux)
....
But yeah, in general this was what I had in mind.
Cheers,
Andre
>
>> + is_reset_mux = (!is_new_layout && muxval == SUN4I_FUNC_DISABLED_OLD) ||
>> + (is_new_layout && muxval == SUN4I_FUNC_DISABLED_NEW);
>> +
>> + if (is_reset_mux) {
>> + sunxi_pmx_set(pctl->pctl_dev, pctl->irq_array[d->hwirq],
>> + SUN4I_FUNC_INPUT);
>> + }
>
> Nit: the curly braces aren't needed.
>
>> +
>> ret = gpiochip_lock_as_irq(pctl->chip,
>> pctl->irq_array[d->hwirq] - pctl->desc->pin_base);
>
> Nit: you probably want to replace this with "offset" as well.
>
>
> Just minor issues, otherwise
>
> Reviewed-by: Chen-Yu Tsai <wens@kernel.org>
>
>> if (ret) {
>> diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.h b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
>> index 22bffac1c3f0..0daf7600e2fb 100644
>> --- a/drivers/pinctrl/sunxi/pinctrl-sunxi.h
>> +++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
>> @@ -86,6 +86,8 @@
>>
>> #define SUN4I_FUNC_INPUT 0
>> #define SUN4I_FUNC_IRQ 6
>> +#define SUN4I_FUNC_DISABLED_OLD 7
>> +#define SUN4I_FUNC_DISABLED_NEW 15
>>
>> #define SUNXI_PINCTRL_VARIANT_MASK GENMASK(7, 0)
>> #define SUNXI_PINCTRL_NEW_REG_LAYOUT BIT(8)
>>
>> --
>> 2.43.0
>>
>>
>
prev parent reply other threads:[~2026-03-19 16:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-19 16:09 [PATCH v4 0/2] fix gpiochip_lock_as_irq() failure when pinmux is unknown michal.piekos
2026-03-19 16:09 ` [PATCH v4 1/2] pinctrl: sunxi: pass down flags to pinctrl routines michal.piekos
2026-03-19 16:37 ` Chen-Yu Tsai
2026-03-19 16:09 ` [PATCH v4 2/2] pinctrl: sunxi: fix gpiochip_lock_as_irq() failure when pinmux is unknown Michal Piekos
2026-03-19 16:44 ` Chen-Yu Tsai
2026-03-19 16:55 ` Andre Przywara [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=de634edc-0fc6-4a32-b0f9-77d87df2bbb3@arm.com \
--to=andre.przywara@arm.com \
--cc=jernej.skrabec@gmail.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=michal.piekos@mmpsystems.pl \
--cc=samuel@sholland.org \
--cc=wens@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox