Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cba87a6d authored by zoro's avatar zoro Committed by Saravana Kannan
Browse files

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



when the VIR_LDO1 regulator supplier is it's brother,
we can't find the 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>;
	};
	...
}

so we add the child ptah to find the suppier.

Signed-off-by: default avatarzoro <long17.cool@163.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
(cherry picked from commit fe06051dbf8abf5962d9258c4a863056bdfa6eae)
Bug: 146234416
Signed-off-by: default avatarSaravana Kannan <saravanak@google.com>
Change-Id: I660b64b9738d6dd2e2bc224bd18560d755c4baae
parent b99814ce
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -227,6 +227,37 @@ static void regulator_unlock_supply(struct regulator_dev *rdev)
	}
}

/**
 * of_get_child_regulator - get a child regulator device node
 * based on supply name
 * @parent: Parent device node
 * @prop_name: Combination regulator supply name and "-supply"
 *
 * Traverse all child nodes.
 * Extract the child regulator device node corresponding to the supply name.
 * returns the device node corresponding to the regulator if found, else
 * returns NULL.
 */
static struct device_node *of_get_child_regulator(struct device_node *parent,
						  const char *prop_name)
{
	struct device_node *regnode = NULL;
	struct device_node *child = NULL;

	for_each_child_of_node(parent, child) {
		regnode = of_parse_phandle(child, prop_name, 0);

		if (!regnode) {
			regnode = of_get_child_regulator(child, prop_name);
			if (regnode)
				return regnode;
		} else {
			return regnode;
		}
	}
	return NULL;
}

/**
 * of_get_regulator - get a regulator device node based on supply name
 * @dev: Device pointer for the consumer (of regulator) device
@@ -247,6 +278,10 @@ 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) {
		regnode = of_get_child_regulator(dev->of_node, prop_name);
		if (regnode)
			return regnode;

		dev_dbg(dev, "Looking up %s property in node %pOF failed\n",
				prop_name, dev->of_node);
		return NULL;