Skip to contentSkip to conversation

regulator/of_get_regulator: add child path to find the regulator supplier

PATCH In review zoro 2 participants 2 messages Nov 8, 2018 – Dec 13, 2018 Voltage and current regulator framework

lore
Share & tools
lore

zoro

author
#0 lore raw

PATCH 1/1 regulator/of_get_regulator: add child path to find the regulator supplier

example code :

	&vir_regulator {
            ldo0_vir: ldo0-virtual {
                regulator-compatible = "VIR_LDO0";
                regulator-name= "VIR_LDO0";
                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <2000000>;
            };
            ldo1_vir: ldo1-virtual {
                regulator-compatible = "VIR_LDO1";
                regulator-name= "VIR_LDO1";
                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <3000000>;
                ldo1-supply = <&ldo0_vir>;
            };
            ...
        };

when the VIR_LDO1 regulator supplier is it's brother, we can't find the supplier.
so we add the child ptah to find the suppier.

---
 drivers/regulator/core.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/regulator/core.c +6 -0
index 2c66b52..5dbfdba 100644
@@ -239,6 +239,7 @@ static void regulator_unlock_supply(struct regulator_dev *rdev)
 static struct device_node *of_get_regulator(struct device *dev, const char *supply)
 {
 	struct device_node *regnode = NULL;
+	struct device_node *child = NULL;
 	char prop_name[32]; /* 32 is max size of property name */
 
 	dev_dbg(dev, "Looking up %s-supply from device tree\n", supply);
@@ -247,6 +248,11 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp
 	regnode = of_parse_phandle(dev->of_node, prop_name, 0);
 
 	if (!regnode) {
+		for_each_child_of_node(dev->of_node, child) {
+			regnode = of_parse_phandle(child, prop_name, 0);
+			if (regnode)
+				return regnode;
+		}
 		dev_dbg(dev, "Looking up %s property in node %pOF failed\n",
 				prop_name, dev->of_node);
 		return NULL;
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 9 lines · zoro
            ldo0_vir: ldo0-virtual {

            ldo1_vir: ldo1-virtual {
                regulator-compatible = "VIR_LDO1";
                regulator-name= "VIR_LDO1";
                regulator-min-microvolt = <1000000>;
                regulator-max-microvolt = <3000000>;
                ldo1-supply = <&ldo0_vir>;
Quoted 3 lines

when the VIR_LDO1 regulator supplier is it's brother, we can't find the supplier.
so we add the child ptah to find the suppier.

The supplies for the chip (even if they happen to be supplies for a regulator on the chip) are supposed to be defined at the chip level so your ldo1-supply property ought to be at the top level for the chip, not in the individual regulator node. This keeps the regulator supplies consistent with other supplies and is especially useful if a single physical input is used by multiple things. As far as I can tell the issue isn't the fact that the parent regulator is defined as part of the same chip, it's where the supply property that LDO1 is looking up has been placed in the DT.

Sorry for the delayed response here, I had some travel and it took a while to figure out what was going on with this change.