[PATCH v4] pinctrl: sunxi: request the per-bank supply optionally

From: Yang Siyuan

Date: Tue Nov 17 2026 - 18:18:59 EST


The per-bank "vcc-pX" supplies are optional in the device tree: the
binding documents them, but notes that many boards do not describe them.
sunxi_pmx_request() uses regulator_get() anyway, so the regulator core
falls back to a dummy regulator and warns for every bank that has no
supply:

sun50i-h616-r-pinctrl 7022000.pinctrl: supply vcc-pl not found, using
dummy regulator

The H616 R_PIO is such a controller, and its PL0/PL1 pins drive the
R_I2C bus, so every H616 board hits the warning during boot.

Use of_regulator_get_optional() instead. A bank supply that is described
in the device tree is still acquired and enabled, as it powers the
physical VCC-Px rail, but one that is absent is skipped without a
warning.

The OF-only lookup matters here: regulator_get_optional() also falls back
to a global regulator-name lookup, which could bind a regulator that
merely shares the name with an absent bank supply and is not the supply
of this bank.

Skip the free path for a bank that never obtained a supply, so the
refcount is only decremented when it was incremented.

Signed-off-by: Yang Siyuan <hsyysy@xxxxxxx>
---
Changes in v4:
- Drop the supply_absent flag and the early return that tested it. The
result of the OF lookup cannot change at runtime, so repeating it for
every pin request is harmless and caching it only complicated the code.
Suggested by Jernej Skrabec.
- Link to v3: https://lore.kernel.org/linux-gpio/20261117091944.12082-1-hsyysy@xxxxxxx/

drivers/pinctrl/sunxi/pinctrl-sunxi.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/pinctrl/sunxi/pinctrl-sunxi.c b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
index 31cd142..1fcab0d 100644
--- a/drivers/pinctrl/sunxi/pinctrl-sunxi.c
+++ b/drivers/pinctrl/sunxi/pinctrl-sunxi.c
@@ -912,6 +912,7 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
unsigned short bank_offset = bank - pctl->desc->pin_base /
PINS_PER_BANK;
struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset];
+ struct device_node *np = dev_of_node(pctl->dev);
struct regulator *reg = s_reg->regulator;
char supply[16];
int ret;
@@ -924,12 +925,24 @@ static int sunxi_pmx_request(struct pinctrl_dev *pctldev, unsigned offset)
return 0;
}

+ if (!np)
+ return 0;
+
snprintf(supply, sizeof(supply), "vcc-p%c", 'a' + bank);
- reg = regulator_get(pctl->dev, supply);
- if (IS_ERR(reg))
+ /*
+ * Use the OF-only lookup: regulator_get_optional() also falls back to
+ * a global regulator-name lookup and could bind a same-named
+ * regulator that is not the supply of this bank.
+ */
+ reg = of_regulator_get_optional(pctl->dev, np, supply);
+ if (IS_ERR(reg)) {
+ if (PTR_ERR(reg) == -ENODEV)
+ return 0;
+
return dev_err_probe(pctl->dev, PTR_ERR(reg),
"Couldn't get bank P%c regulator\n",
'A' + bank);
+ }

ret = regulator_enable(reg);
if (ret) {
@@ -959,6 +972,10 @@ static int sunxi_pmx_free(struct pinctrl_dev *pctldev, unsigned offset)
PINS_PER_BANK;
struct sunxi_pinctrl_regulator *s_reg = &pctl->regulators[bank_offset];

+ /* The per-bank supply is optional, so this bank may not have one. */
+ if (!s_reg->regulator)
+ return 0;
+
if (!refcount_dec_and_test(&s_reg->refcount))
return 0;

base-commit: 091b06388b117fefdcb63336ac09956a4914b961
--
2.56.1