Skip to content

Commit 86a8eeb

Browse files
andredbroonie
authored andcommitted
regulator: core: move supply check earlier in set_machine_constraints()
Since commit 98e48cd ("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 8a866d5 ("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: 98e48cd ("regulator: core: resolve supply for boot-on/always-on regulators") Signed-off-by: André Draszik <andre.draszik@linaro.org> Link: https://patch.msgid.link/20260109-regulators-defer-v2-3-1a25dc968e60@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 497330b commit 86a8eeb

1 file changed

Lines changed: 30 additions & 25 deletions

File tree

drivers/regulator/core.c

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,33 @@ static int set_machine_constraints(struct regulator_dev *rdev)
14441444
int ret = 0;
14451445
const struct regulator_ops *ops = rdev->desc->ops;
14461446

1447+
/*
1448+
* If there is no mechanism for controlling the regulator then
1449+
* flag it as always_on so we don't end up duplicating checks
1450+
* for this so much. Note that we could control the state of
1451+
* a supply to control the output on a regulator that has no
1452+
* direct control.
1453+
*/
1454+
if (!rdev->ena_pin && !ops->enable) {
1455+
if (rdev->supply_name && !rdev->supply)
1456+
return -EPROBE_DEFER;
1457+
1458+
if (rdev->supply)
1459+
rdev->constraints->always_on =
1460+
rdev->supply->rdev->constraints->always_on;
1461+
else
1462+
rdev->constraints->always_on = true;
1463+
}
1464+
1465+
/*
1466+
* If we want to enable this regulator, make sure that we know the
1467+
* supplying regulator.
1468+
*/
1469+
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
1470+
if (rdev->supply_name && !rdev->supply)
1471+
return -EPROBE_DEFER;
1472+
}
1473+
14471474
ret = machine_constraints_voltage(rdev, rdev->constraints);
14481475
if (ret != 0)
14491476
return ret;
@@ -1609,37 +1636,15 @@ static int set_machine_constraints(struct regulator_dev *rdev)
16091636
}
16101637
}
16111638

1612-
/*
1613-
* If there is no mechanism for controlling the regulator then
1614-
* flag it as always_on so we don't end up duplicating checks
1615-
* for this so much. Note that we could control the state of
1616-
* a supply to control the output on a regulator that has no
1617-
* direct control.
1618-
*/
1619-
if (!rdev->ena_pin && !ops->enable) {
1620-
if (rdev->supply_name && !rdev->supply)
1621-
return -EPROBE_DEFER;
1622-
1623-
if (rdev->supply)
1624-
rdev->constraints->always_on =
1625-
rdev->supply->rdev->constraints->always_on;
1626-
else
1627-
rdev->constraints->always_on = true;
1628-
}
1629-
16301639
/* If the constraints say the regulator should be on at this point
16311640
* and we have control then make sure it is enabled.
16321641
*/
16331642
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
16341643
bool supply_enabled = false;
16351644

1636-
/* If we want to enable this regulator, make sure that we know
1637-
* the supplying regulator.
1638-
*/
1639-
if (rdev->supply_name && !rdev->supply)
1640-
return -EPROBE_DEFER;
1641-
1642-
/* If supplying regulator has already been enabled,
1645+
/* We have ensured a potential supply has been resolved above.
1646+
*
1647+
* If supplying regulator has already been enabled,
16431648
* it's not intended to have use_count increment
16441649
* when rdev is only boot-on.
16451650
*/

0 commit comments

Comments
 (0)