Skip to content
/ linux Public

Commit a278b77

Browse files
andredSasha Levin
authored andcommitted
regulator: core: move supply check earlier in set_machine_constraints()
[ Upstream commit 86a8eeb ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent aaa4b14 commit a278b77

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

drivers/regulator/core.c

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

1476+
/*
1477+
* If there is no mechanism for controlling the regulator then
1478+
* flag it as always_on so we don't end up duplicating checks
1479+
* for this so much. Note that we could control the state of
1480+
* a supply to control the output on a regulator that has no
1481+
* direct control.
1482+
*/
1483+
if (!rdev->ena_pin && !ops->enable) {
1484+
if (rdev->supply_name && !rdev->supply)
1485+
return -EPROBE_DEFER;
1486+
1487+
if (rdev->supply)
1488+
rdev->constraints->always_on =
1489+
rdev->supply->rdev->constraints->always_on;
1490+
else
1491+
rdev->constraints->always_on = true;
1492+
}
1493+
1494+
/*
1495+
* If we want to enable this regulator, make sure that we know the
1496+
* supplying regulator.
1497+
*/
1498+
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
1499+
if (rdev->supply_name && !rdev->supply)
1500+
return -EPROBE_DEFER;
1501+
}
1502+
14761503
ret = machine_constraints_voltage(rdev, rdev->constraints);
14771504
if (ret != 0)
14781505
return ret;
@@ -1638,37 +1665,15 @@ static int set_machine_constraints(struct regulator_dev *rdev)
16381665
}
16391666
}
16401667

1641-
/*
1642-
* If there is no mechanism for controlling the regulator then
1643-
* flag it as always_on so we don't end up duplicating checks
1644-
* for this so much. Note that we could control the state of
1645-
* a supply to control the output on a regulator that has no
1646-
* direct control.
1647-
*/
1648-
if (!rdev->ena_pin && !ops->enable) {
1649-
if (rdev->supply_name && !rdev->supply)
1650-
return -EPROBE_DEFER;
1651-
1652-
if (rdev->supply)
1653-
rdev->constraints->always_on =
1654-
rdev->supply->rdev->constraints->always_on;
1655-
else
1656-
rdev->constraints->always_on = true;
1657-
}
1658-
16591668
/* If the constraints say the regulator should be on at this point
16601669
* and we have control then make sure it is enabled.
16611670
*/
16621671
if (rdev->constraints->always_on || rdev->constraints->boot_on) {
16631672
bool supply_enabled = false;
16641673

1665-
/* If we want to enable this regulator, make sure that we know
1666-
* the supplying regulator.
1667-
*/
1668-
if (rdev->supply_name && !rdev->supply)
1669-
return -EPROBE_DEFER;
1670-
1671-
/* If supplying regulator has already been enabled,
1674+
/* We have ensured a potential supply has been resolved above.
1675+
*
1676+
* If supplying regulator has already been enabled,
16721677
* it's not intended to have use_count increment
16731678
* when rdev is only boot-on.
16741679
*/

0 commit comments

Comments
 (0)