Re: [PATCH v4] pinctrl: sunxi: request the per-bank supply optionally
From: Yang Siyuan
Date: Sun Nov 29 2026 - 19:37:14 EST
Hi Linus,
thanks for the review.
> > + /*
> > + * 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.
> > + */
>
> Is that a real problem or a theoretical one?
It is a real code path, and the concrete failure is a refcount imbalance
rather than just picking the wrong rail.
regulator_dev_lookup() falls back to regulator_lookup_by_name() only when
the DT lookup fails, i.e. exactly when vcc-pX-supply is absent. With
regulator_get_optional() "this bank has no supply" is not a permanent
answer: if a regulator named "vcc-pX" is registered later (deferred probe
of a provider, module load), pin requests made before that point return
early, while later ones acquire the regulator and start the bank refcount
at 1. sunxi_pmx_free() then disables the rail when the last counted pin
is freed, although the pins requested earlier are still active.
With the OF-only lookup an absent supply property stays absent, so the
refcount is consistent for the lifetime of the bank.
of_regulator_get_optional() was added by Chen-Yu in 5441b6975adc
("regulator: Add of_regulator_get_optional() for pure DT regulator
lookup") and is already used by i2c-core-of-prober, mtk-pm-domains and
tcpm.
One caveat I found while checking: a few DTS files name a regulator
"vcc-pX" without wiring it as vcc-pX-supply on the pinctrl node. On
sun7i-a20-olimex-som204-evb.dts for example ®_ldo4 is named "vcc-pg",
the &pio node has no vcc-pg-supply, and UART3 (Bluetooth) uses PG pins,
so today that rail is enabled through the name match. With the OF-only
lookup it would not be. I see that as a DT description gap, but if you
would rather keep the existing behaviour, a v5 can use
regulator_get_optional() (with the absent result remembered, so the
refcount problem above cannot happen).
Mark, are you happy with the OF-only lookup here?
Thanks,
Yang