From: "André Draszik" <andre.draszik@linaro.org>
To: Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Javier Martinez Canillas <javier@osg.samsung.com>,
Jon Hunter <jonathanh@nvidia.com>,
Dmitry Baryshkov <lumag@kernel.org>,
Oleksij Rempel <o.rempel@pengutronix.de>
Cc: "Peter Griffin" <peter.griffin@linaro.org>,
"Tudor Ambarus" <tudor.ambarus@linaro.org>,
"Will McVicker" <willmcvicker@google.com>,
"Juan Yescas" <jyescas@google.com>,
kernel-team@android.com, linux-kernel@vger.kernel.org,
"André Draszik" <andre.draszik@linaro.org>
Subject: [PATCH v2 3/8] regulator: core: move supply check earlier in set_machine_constraints()
Date: Fri, 09 Jan 2026 08:38:39 +0000 [thread overview]
Message-ID: <20260109-regulators-defer-v2-3-1a25dc968e60@linaro.org> (raw)
In-Reply-To: <20260109-regulators-defer-v2-0-1a25dc968e60@linaro.org>
Since commit 98e48cd9283d ("regulator: core: resolve supply for
boot-on/always-on regulators"), set_machine_constraints() can return
-EPROBE_DEFER very late, after it has done a lot of work and
configuration of the regulator.
This means that configuration will happen multiple times for no
benefit in that case. Furthermore, this can lead to timing-dependent
voltage glitches as mentioned e.g. in commit 8a866d527ac0 ("regulator:
core: Resolve supply name earlier to prevent double-init").
We can know that it's going to fail very early, in particular before
going through the complete regulator configuration by moving some code
around a little.
Do so to avoid re-configuring the regulator multiple times, also
avoiding the voltage glitches if we can.
Fixes: 98e48cd9283d ("regulator: core: resolve supply for boot-on/always-on regulators")
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/regulator/core.c | 55 ++++++++++++++++++++++++++----------------------
1 file changed, 30 insertions(+), 25 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 48c091de68d81e3e89eacecd8526255ab9a446b2..9ce0eef1dcfcb39a072675e44a5577ae85d51982 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1444,6 +1444,33 @@ static int set_machine_constraints(struct regulator_dev *rdev)
int ret = 0;
const struct regulator_ops *ops = rdev->desc->ops;
+ /*
+ * If there is no mechanism for controlling the regulator then
+ * flag it as always_on so we don't end up duplicating checks
+ * for this so much. Note that we could control the state of
+ * a supply to control the output on a regulator that has no
+ * direct control.
+ */
+ if (!rdev->ena_pin && !ops->enable) {
+ if (rdev->supply_name && !rdev->supply)
+ return -EPROBE_DEFER;
+
+ if (rdev->supply)
+ rdev->constraints->always_on =
+ rdev->supply->rdev->constraints->always_on;
+ else
+ rdev->constraints->always_on = true;
+ }
+
+ /*
+ * If we want to enable this regulator, make sure that we know the
+ * supplying regulator.
+ */
+ if (rdev->constraints->always_on || rdev->constraints->boot_on) {
+ if (rdev->supply_name && !rdev->supply)
+ return -EPROBE_DEFER;
+ }
+
ret = machine_constraints_voltage(rdev, rdev->constraints);
if (ret != 0)
return ret;
@@ -1609,37 +1636,15 @@ static int set_machine_constraints(struct regulator_dev *rdev)
}
}
- /*
- * If there is no mechanism for controlling the regulator then
- * flag it as always_on so we don't end up duplicating checks
- * for this so much. Note that we could control the state of
- * a supply to control the output on a regulator that has no
- * direct control.
- */
- if (!rdev->ena_pin && !ops->enable) {
- if (rdev->supply_name && !rdev->supply)
- return -EPROBE_DEFER;
-
- if (rdev->supply)
- rdev->constraints->always_on =
- rdev->supply->rdev->constraints->always_on;
- else
- rdev->constraints->always_on = true;
- }
-
/* If the constraints say the regulator should be on at this point
* and we have control then make sure it is enabled.
*/
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
bool supply_enabled = false;
- /* If we want to enable this regulator, make sure that we know
- * the supplying regulator.
- */
- if (rdev->supply_name && !rdev->supply)
- return -EPROBE_DEFER;
-
- /* If supplying regulator has already been enabled,
+ /* We have ensured a potential supply has been resolved above.
+ *
+ * If supplying regulator has already been enabled,
* it's not intended to have use_count increment
* when rdev is only boot-on.
*/
--
2.52.0.457.g6b5491de43-goog
next prev parent reply other threads:[~2026-01-09 8:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 8:38 [PATCH v2 0/8] regulator: core: allow regulator_register() with missing required supply André Draszik
2026-01-09 8:38 ` [PATCH v2 1/8] regulator: core: update two debug messages André Draszik
2026-01-09 8:38 ` [PATCH v2 2/8] regulator: core: fix locking in regulator_resolve_supply() error path André Draszik
2026-01-09 8:38 ` André Draszik [this message]
2026-01-09 8:38 ` [PATCH v2 4/8] regulator: core: streamline supply resolution for always-on/boot-on regulators André Draszik
2026-01-09 8:38 ` [PATCH v2 5/8] regulator: core: remove dead code in regulator_resolve_supply() André Draszik
2026-01-09 8:38 ` [PATCH v2 6/8] regulator: core: don't ignore errors from event forwarding setup André Draszik
2026-01-09 8:38 ` [PATCH v2 7/8] regulator: core: reresolve unresolved supplies when available André Draszik
2026-01-09 8:38 ` [PATCH v2 8/8] regulator: core: don't fail regulator_register() with missing required supply André Draszik
2026-01-12 14:31 ` [PATCH v2 0/8] regulator: core: allow " Mark Brown
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=20260109-regulators-defer-v2-3-1a25dc968e60@linaro.org \
--to=andre.draszik@linaro.org \
--cc=broonie@kernel.org \
--cc=javier@osg.samsung.com \
--cc=jonathanh@nvidia.com \
--cc=jyescas@google.com \
--cc=kernel-team@android.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lumag@kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=peter.griffin@linaro.org \
--cc=tudor.ambarus@linaro.org \
--cc=willmcvicker@google.com \
/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
all inboxes | Powered by JetHome®