From: Andre Przywara <andre.przywara@arm.com>
To: Linus Walleij <linusw@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Chen-Yu Tsai <wens@csie.org>,
Jernej Skrabec <jernej.skrabec@gmail.com>,
Samuel Holland <samuel@sholland.org>
Cc: Michal Piekos <michal.piekos@mmpsystems.pl>,
linux-gpio@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [PATCH 1/5] pinctrl: sunxi: Rework IRQ remuxing to avoid fixed mux value
Date: Mon, 23 Mar 2026 12:01:47 +0100 [thread overview]
Message-ID: <20260323110151.2352832-2-andre.przywara@arm.com> (raw)
In-Reply-To: <20260323110151.2352832-1-andre.przywara@arm.com>
Some Allwinner SoCs cannot read the state of a GPIO line when the pin is
muxed to the IRQ function. To access that state anyway, we temporarily
mux that pin back to GPIO input, then return it to the IRQ mux
afterwards. This code assumes that the IRQ mux value is 0x6, even though
newer SoCs (D1/T113/A523/...) encode the IRQ mux with 0xe.
Avoid hardcoding the different IRQ mux values by saving the programmed
value before switching to GPIO input, then restoring the saved value
afterwards. This makes the code robust against future changes of the IRQ
mux value. This also avoids calling the sunxi_pmx_set() function twice,
each of which does a read/modify/write operation, fenced in by the pctl
lock. The new code takes the lock around the whole operation, which is
also safer since it avoids (probably theoretical) races against other
code touching the mux register meanwhile.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 23 ++++++++++++++++-------
drivers/pinctrl/sunxi/pinctrl-sunxi.h | 1 -
2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index d3042e0c9712..6a86b7989b25 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -997,18 +997,27 @@ static int sunxi_pinctrl_gpio_get(struct gpio_chip *chip, unsigned offset)
struct sunxi_pinctrl *pctl = gpiochip_get_data(chip);
bool set_mux = pctl->desc->irq_read_needs_mux &&
gpiochip_line_is_irq(chip, offset);
- u32 pin = offset + chip->base;
+ u32 mreg, mshift, mmask, mval;
u32 reg, shift, mask, val;
+ unsigned long flags;
sunxi_data_reg(pctl, offset, ®, &shift, &mask);
+ if (!set_mux)
+ return (readl(pctl->membase + reg) & mask) >> shift;
- if (set_mux)
- sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_INPUT);
-
+ /*
+ * Some SoCs don't read the GPIO value registers correctly
+ * when the pinmux is not set to GPIO_INPUT. Temporarily switch
+ * to that mux, to read the correct value.
+ */
+ sunxi_mux_reg(pctl, offset, &mreg, &mshift, &mmask);
+ raw_spin_lock_irqsave(&pctl->lock, flags);
+ mval = readl(pctl->membase + mreg);
+ writel((mval & ~mmask) | SUN4I_FUNC_INPUT << mshift,
+ pctl->membase + mreg);
val = (readl(pctl->membase + reg) & mask) >> shift;
-
- if (set_mux)
- sunxi_pmx_set(pctl->pctl_dev, pin, SUN4I_FUNC_IRQ);
+ writel(mval, pctl->membase + mreg);
+ raw_spin_unlock_irqrestore(&pctl->lock, flags);
return val;
}
diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.h b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
index 0daf7600e2fb..ec7c977655b5 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.h
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.h
@@ -85,7 +85,6 @@
#define IO_BIAS_MASK GENMASK(3, 0)
#define SUN4I_FUNC_INPUT 0
-#define SUN4I_FUNC_IRQ 6
#define SUN4I_FUNC_DISABLED_OLD 7
#define SUN4I_FUNC_DISABLED_NEW 15
--
2.43.0
next prev parent reply other threads:[~2026-03-23 11:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 11:01 [PATCH 0/5] pinctrl: sunxi: fix A523 GPIO IRQ blunder Andre Przywara
2026-03-23 11:01 ` Andre Przywara [this message]
2026-03-23 17:04 ` [PATCH 1/5] pinctrl: sunxi: Rework IRQ remuxing to avoid fixed mux value Chen-Yu Tsai
2026-03-23 11:01 ` [PATCH 2/5] pinctrl: sunxi: Remove unneeded IRQ remuxing for some SoCs Andre Przywara
2026-03-23 17:07 ` Chen-Yu Tsai
2026-03-23 11:01 ` [PATCH 3/5] dt-bindings: pinctrl: sun55i-a523: increase IRQ bank number Andre Przywara
2026-03-23 17:10 ` Chen-Yu Tsai
2026-04-07 16:14 ` Rob Herring (Arm)
2026-03-23 11:01 ` [PATCH 4/5] arm64: dts: allwinner: a523: Add missing GPIO interrupt Andre Przywara
2026-03-23 17:08 ` Chen-Yu Tsai
2026-03-23 11:01 ` [PATCH 5/5] pinctrl: sunxi: a523: add missing IRQ bank (plus old DT workaround) Andre Przywara
2026-03-23 17:41 ` Chen-Yu Tsai
2026-03-24 14:22 ` Andre Przywara
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=20260323110151.2352832-2-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jernej.skrabec@gmail.com \
--cc=krzk+dt@kernel.org \
--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=robh@kernel.org \
--cc=samuel@sholland.org \
--cc=wens@csie.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