Skip to contentSkip to conversation

dt-bindings: regulator: regulator-output: Multiple supplies

PATCH Superseded Naresh Solanki 4 participants 7 messages Oct 4, 2023 – Oct 5, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dt-bindings: regulator: regulator-output: Multiple supplies

Add support for multiple supplies.

---
 .../devicetree/bindings/regulator/regulator-output.yaml  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/regulator/regulator-output.yaml +7 -2
index 078b37a1a71a..6d077f123729 100644
@@ -21,13 +21,13 @@ properties:
   compatible:
     const: regulator-output
 
-  vout-supply:
+patternProperties:
+  ".*-supply":
     description:
       Phandle of the regulator supplying the output.
 
 required:
   - compatible
-  - vout-supply
 
 additionalProperties: false
 
@@ -37,3 +37,8 @@ examples:
           compatible = "regulator-output";
           vout-supply = <&output_reg>;
       };
+      output1 {
+          compatible = "regulator-output";
+          sw0-supply = <&output_reg0>;
+          sw1-supply = <&output_reg2>;
+      };

base-commit: f9a1d31874c383f58bb4f89bfe79b764682cd026

Signature · 1 line
2.41.0
#1 lore raw

PATCH 2/3 regulator: userspace-consumer: Retrieve supplies from DT

From: Naresh Solanki <[email protected]>

Instead of hardcoding a single supply, retrieve supplies from DT.

---
Changes in V2:
- Use strlen for SUPPLY_SUFFIX_LEN,
- Remove bracket for single line statements in if statement.
- Remove extra space in variable declaration.
- Simplify multi line statement by calculating size in seperate variable.
- Add function prop_supply_name & simplify code.
- Use devm_kstrdup instead to simplify code further.
- Update DT binding to align with changes.

---
 drivers/regulator/userspace-consumer.c | 51 ++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 4 deletions(-)
drivers/regulator/userspace-consumer.c +47 -4
index 97f075ed68c9..13c0a86ab32c 100644
@@ -115,12 +115,41 @@ static const struct attribute_group attr_group = {
 	.is_visible =  attr_visible,
 };
 
+#define SUPPLY_SUFFIX "-supply"
+#define SUPPLY_SUFFIX_LEN strlen(SUPPLY_SUFFIX)
+
+static size_t prop_supply_name(char *prop_name)
+{
+	int len = strlen(prop_name);
+
+	if (len <= SUPPLY_SUFFIX_LEN)
+		return 0;
+
+	if (strcmp(prop_name + len - SUPPLY_SUFFIX_LEN, SUPPLY_SUFFIX) == 0)
+		return len - SUPPLY_SUFFIX_LEN;
+
+	return 0;
+}
+
+static int get_num_supplies(struct platform_device *pdev)
+{
+	struct  property *prop;
+	int num_supplies = 0;
+
+	for_each_property_of_node(pdev->dev.of_node, prop) {
+		if (prop_supply_name(prop->name))
+			num_supplies++;
+	}
+	return num_supplies;
+}
+
 static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 {
 	struct regulator_userspace_consumer_data tmpdata;
 	struct regulator_userspace_consumer_data *pdata;
 	struct userspace_consumer_data *drvdata;
-	int ret;
+	struct property *prop;
+	int ret, supplies_size;
 
 	pdata = dev_get_platdata(&pdev->dev);
 	if (!pdata) {
@@ -131,11 +160,25 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 		memset(pdata, 0, sizeof(*pdata));
 
 		pdata->no_autoswitch = true;
-		pdata->num_supplies = 1;
-		pdata->supplies = devm_kzalloc(&pdev->dev, sizeof(*pdata->supplies), GFP_KERNEL);
+		pdata->num_supplies = get_num_supplies(pdev);
+
+		supplies_size = pdata->num_supplies * sizeof(*pdata->supplies);
+		pdata->supplies = devm_kzalloc(&pdev->dev, supplies_size, GFP_KERNEL);
 		if (!pdata->supplies)
 			return -ENOMEM;
-		pdata->supplies[0].supply = "vout";
+
+		for_each_property_of_node(pdev->dev.of_node, prop) {
+			const char *prop_name = prop->name;
+			size_t supply_len = prop_supply_name(prop->name);
+
+			if (!supply_len)
+				continue;
+
+			char *supply_name = devm_kstrdup(&pdev->dev, prop_name, GFP_KERNEL);
+
+			supply_name[supply_len] = '\0';
+			pdata->supplies[0].supply = supply_name;
+		}
 	}
 
 	if (pdata->num_supplies < 1) {
Signature · 1 line
2.41.0
#2 lore raw

PATCH 3/3 regulator: userspace-consumer: Update name

In reply to Naresh Solanki

Set name to dt node name.

---
 drivers/regulator/userspace-consumer.c | 1 +
 1 file changed, 1 insertion(+)
drivers/regulator/userspace-consumer.c +1 -0
index 13c0a86ab32c..9030e1d9ce3c 100644
@@ -159,6 +159,7 @@ static int regulator_userspace_consumer_probe(struct platform_device *pdev)
 		pdata = &tmpdata;
 		memset(pdata, 0, sizeof(*pdata));
 
+		pdata->name = devm_kstrdup(&pdev->dev, pdev->dev.of_node->name, GFP_KERNEL);
 		pdata->no_autoswitch = true;
 		pdata->num_supplies = get_num_supplies(pdev);
 
Signature · 1 line
2.41.0
maintainer
#3 lore raw
In reply to Naresh Solanki
Quoted 1 line · Naresh Solanki

Add support for multiple supplies.

Why?

Quoted 40 lines
---
 .../devicetree/bindings/regulator/regulator-output.yaml  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/regulator/regulator-output.yaml +7 -2
index 078b37a1a71a..6d077f123729 100644
@@ -21,13 +21,13 @@ properties:
   compatible:
     const: regulator-output
 
-  vout-supply:
+patternProperties:
+  ".*-supply":
     description:
       Phandle of the regulator supplying the output.
 
 required:
   - compatible
-  - vout-supply
 
 additionalProperties: false
 
@@ -37,3 +37,8 @@ examples:
           compatible = "regulator-output";
           vout-supply = <&output_reg>;
       };
+      output1 {
+          compatible = "regulator-output";
+          sw0-supply = <&output_reg0>;
+          sw1-supply = <&output_reg2>;
+      };

base-commit: f9a1d31874c383f58bb4f89bfe79b764682cd026

Signature · 1 line
2.41.0
#4 lore raw

Hi Rob,

Quoted 5 lines · Rob Herring
Quoted 1 line · Naresh Solanki

Add support for multiple supplies.

Why?

1. Driver is already capable of that using platform data. Hence added support to read DT property & initialize the same for multiple supplies instead of being limited to one.
2. This is particularly useful in cases wherein 2 or more regulators are coupled together, for example in a PCIe connector having 3.3V & 12V.

Regards,
Naresh

Quoted 41 lines
Quoted 41 lines
---
 .../devicetree/bindings/regulator/regulator-output.yaml  | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/regulator/regulator-output.yaml +7 -2
index 078b37a1a71a..6d077f123729 100644
@@ -21,13 +21,13 @@ properties:
   compatible:
     const: regulator-output
 
-  vout-supply:
+patternProperties:
+  ".*-supply":
     description:
       Phandle of the regulator supplying the output.
 
 required:
   - compatible
-  - vout-supply
 
 additionalProperties: false
 
@@ -37,3 +37,8 @@ examples:
           compatible = "regulator-output";
           vout-supply = <&output_reg>;
       };
+      output1 {
+          compatible = "regulator-output";
+          sw0-supply = <&output_reg0>;
+          sw1-supply = <&output_reg2>;
+      };

base-commit: f9a1d31874c383f58bb4f89bfe79b764682cd026 --
2.41.0

#5 lore raw
Quoted 5 lines · Naresh Solanki

Hi Rob,

Quoted 1 line · Rob Herring
Quoted 7 lines
Quoted 4 lines · Naresh Solanki
Quoted 1 line

Add support for multiple supplies.

Why?

1. Driver is already capable of that using platform data. Hence added support to read DT property & initialize the same for multiple supplies instead of being limited to one.

I am not sure that's a valid reason. Bindings focus on the hardware. We do not describe here driver capabilities.

Quoted 3 lines

2. This is particularly useful in cases wherein 2 or more regulators are coupled together, for example in a PCIe connector having 3.3V & 12V.

Commit message should explain this. Each commit, when not obvious, should say why you are doing things.

Best regards,
Krzysztof

#6 lore raw
In reply to Naresh Solanki
Quoted 8 lines · Naresh Solanki

Hi Rob,

Quoted 4 lines · Rob Herring
Quoted 1 line · Naresh Solanki

Add support for multiple supplies.

Quoted 8 lines
Quoted 1 line

Why?

1. Driver is already capable of that using platform data. Hence added support to read DT property & initialize the same for multiple supplies instead of being limited to one.
2. This is particularly useful in cases wherein 2 or more regulators are coupled together, for example in a PCIe connector having 3.3V & 12V.

Hmm -- apologies if I pointed you in the wrong direction here on the last revision (or should have considered this earlier), but is there a particular need for this arrangement to be described by a single regulator-output DT node instead of just having one node per supply? If they're independently-controlled voltage outputs, treating them as two separate things instead of a single ganged one seems like it might be more appropriate anyway...

Zev