Skip to content

Commit c3ad22a

Browse files
kmaincentbroonie
authored andcommitted
regulator: core: Resolve supply using of_node from regulator_config
Previously, the regulator core resolved its supply only from the parent device or its children, ignoring the of_node specified in the regulator_config structure. This behavior causes issues in scenarios where multiple regulator devices are registered for components described as children of a controller, each with their own specific regulator supply. For instance, in a PSE controller with multiple PIs (Power Interfaces), each PI may have a distinct regulator supply. However, the regulator core would incorrectly use the PSE controller node or its first child to look up the regulator supply, rather than the node specified by the regulator_config->of_node for the PI. This update modifies the behavior to prioritize the of_node in regulator_config for resolving the supply. This ensures correct resolution of the power supply for each device. If no supply is found in the provided of_node, the core falls back to searching within the parent device as before. Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com> Link: https://patch.msgid.link/20250109-b4-feature_poe_arrange-v2-13-55ded947b510@bootlin.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent dddca3b commit c3ad22a

File tree

1 file changed

+28
-11
lines changed

1 file changed

+28
-11
lines changed

drivers/regulator/core.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,20 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
19361936
return dev ? dev_to_rdev(dev) : NULL;
19371937
}
19381938

1939+
static struct regulator_dev *regulator_dt_lookup(struct device *dev,
1940+
const char *supply)
1941+
{
1942+
struct regulator_dev *r = NULL;
1943+
1944+
if (dev_of_node(dev)) {
1945+
r = of_regulator_dev_lookup(dev, dev_of_node(dev), supply);
1946+
if (PTR_ERR(r) == -ENODEV)
1947+
r = NULL;
1948+
}
1949+
1950+
return r;
1951+
}
1952+
19391953
/**
19401954
* regulator_dev_lookup - lookup a regulator device.
19411955
* @dev: device for regulator "consumer".
@@ -1960,16 +1974,9 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
19601974
regulator_supply_alias(&dev, &supply);
19611975

19621976
/* first do a dt based lookup */
1963-
if (dev_of_node(dev)) {
1964-
r = of_regulator_dev_lookup(dev, dev_of_node(dev), supply);
1965-
if (!IS_ERR(r))
1966-
return r;
1967-
if (PTR_ERR(r) == -EPROBE_DEFER)
1968-
return r;
1969-
1970-
if (PTR_ERR(r) == -ENODEV)
1971-
r = NULL;
1972-
}
1977+
r = regulator_dt_lookup(dev, supply);
1978+
if (r)
1979+
return r;
19731980

19741981
/* if not found, try doing it non-dt way */
19751982
if (dev)
@@ -2015,7 +2022,17 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
20152022
if (rdev->supply)
20162023
return 0;
20172024

2018-
r = regulator_dev_lookup(dev, rdev->supply_name);
2025+
/* first do a dt based lookup on the node described in the virtual
2026+
* device.
2027+
*/
2028+
r = regulator_dt_lookup(&rdev->dev, rdev->supply_name);
2029+
2030+
/* If regulator not found use usual search path in the parent
2031+
* device.
2032+
*/
2033+
if (!r)
2034+
r = regulator_dev_lookup(dev, rdev->supply_name);
2035+
20192036
if (IS_ERR(r)) {
20202037
ret = PTR_ERR(r);
20212038

0 commit comments

Comments
 (0)