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>
This commit is contained in:
Kory Maincent (Dent Project) 2025-01-09 11:18:07 +01:00 committed by Mark Brown
parent dddca3b2fc
commit c3ad22ad34
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -1936,6 +1936,20 @@ static struct regulator_dev *regulator_lookup_by_name(const char *name)
return dev ? dev_to_rdev(dev) : NULL;
}
static struct regulator_dev *regulator_dt_lookup(struct device *dev,
const char *supply)
{
struct regulator_dev *r = NULL;
if (dev_of_node(dev)) {
r = of_regulator_dev_lookup(dev, dev_of_node(dev), supply);
if (PTR_ERR(r) == -ENODEV)
r = NULL;
}
return r;
}
/**
* regulator_dev_lookup - lookup a regulator device.
* @dev: device for regulator "consumer".
@ -1960,16 +1974,9 @@ static struct regulator_dev *regulator_dev_lookup(struct device *dev,
regulator_supply_alias(&dev, &supply);
/* first do a dt based lookup */
if (dev_of_node(dev)) {
r = of_regulator_dev_lookup(dev, dev_of_node(dev), supply);
if (!IS_ERR(r))
return r;
if (PTR_ERR(r) == -EPROBE_DEFER)
return r;
if (PTR_ERR(r) == -ENODEV)
r = NULL;
}
r = regulator_dt_lookup(dev, supply);
if (r)
return r;
/* if not found, try doing it non-dt way */
if (dev)
@ -2015,7 +2022,17 @@ static int regulator_resolve_supply(struct regulator_dev *rdev)
if (rdev->supply)
return 0;
r = regulator_dev_lookup(dev, rdev->supply_name);
/* first do a dt based lookup on the node described in the virtual
* device.
*/
r = regulator_dt_lookup(&rdev->dev, rdev->supply_name);
/* If regulator not found use usual search path in the parent
* device.
*/
if (!r)
r = regulator_dev_lookup(dev, rdev->supply_name);
if (IS_ERR(r)) {
ret = PTR_ERR(r);