mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] regulator/of_get_regulator: add child path to find the regulator supplier
@ 2018-11-08  5:40 zoro
  2018-12-13 17:53 ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: zoro @ 2018-11-08  5:40 UTC (permalink / raw)
  To: lgirdwood; +Cc: broonie, linux-kernel, zoro

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.

Signed-off-by: zoro <long17.cool@163.com>
---
 drivers/regulator/core.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2c66b52..5dbfdba 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -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;
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] regulator/of_get_regulator: add child path to find the regulator supplier
  2018-11-08  5:40 [PATCH] regulator/of_get_regulator: add child path to find the regulator supplier zoro
@ 2018-12-13 17:53 ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2018-12-13 17:53 UTC (permalink / raw)
  To: zoro; +Cc: lgirdwood, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1234 bytes --]

On Thu, Nov 08, 2018 at 01:40:35PM +0800, zoro wrote:

>             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>;

> 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.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] regulator/of_get_regulator: add child path to find the regulator supplier
@ 2018-11-14  9:38 zoro
  0 siblings, 0 replies; 3+ messages in thread
From: zoro @ 2018-11-14  9:38 UTC (permalink / raw)
  To: broonie; +Cc: lgirdwood, linux-kernel, zoro

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: zoro <long17.cool@163.com>
---
 drivers/regulator/core.c |   35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 2c66b52..5520726 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -228,6 +228,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
  * @supply: regulator supply name
@@ -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;
-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-13 17:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-08  5:40 [PATCH] regulator/of_get_regulator: add child path to find the regulator supplier zoro
2018-12-13 17:53 ` Mark Brown
2018-11-14  9:38 zoro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®