Skip to contentSkip to conversation

regulator: sgm3804: register rails with their DT nodes

PATCH In review [email protected] 2 participants 2 messages Jul 20 Voltage and current regulator framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: sgm3804: register rails with their DT nodes

From: surendra <[email protected]>

The driver locates the pos and neg child nodes to obtain their enable GPIOs, but registers both regulators with the parent node. As a result, the regulator core does not parse per-rail DT constraints or supplies.

Pass each matching child node in regulator_config.of_node.

Fixes 0c47e1a8cf5d ("regulator: add SGM3804 Dual Output driver")
---
 drivers/regulator/sgm3804-regulator.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/regulator/sgm3804-regulator.c +11 -3
index c3406cfb73d0..531b98460ee3 100644
@@ -9,6 +9,7 @@
 #include <linux/err.h>
 #include <linux/i2c.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/regmap.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/of_regulator.h>
@@ -268,14 +269,21 @@ static int sgm3804_probe(struct i2c_client *i2c)
 
 	for (i = 0; i < ARRAY_SIZE(sgm3804_regulator_desc); i++) {
 		struct regulator_config config = { };
+		const struct regulator_desc *reg = &sgm3804_regulator_desc[i];
 		struct regulator_dev *rdev;
+		struct device_node *child;
+
+		child = of_get_child_by_name(dev_of_node(dev), reg->of_match);
+		if (!child)
+			return dev_err_probe(dev, -EINVAL, "missing child '%s'\n",
+					     reg->of_match);
 
 		config.dev = dev;
 		config.regmap = ctx->regmap;
-		config.of_node = dev_of_node(dev);
+		config.of_node = child;
 		config.driver_data = ctx;
-		rdev = devm_regulator_register(dev, &sgm3804_regulator_desc[i],
-					       &config);
+		rdev = devm_regulator_register(dev, reg, &config);
+		of_node_put(child);
 		if (IS_ERR(rdev))
 			return dev_err_probe(dev, PTR_ERR(rdev),
 					     "failed to register regulator %d\n", i);
Signature · 1 line
2.55.0
#1 lore raw
Quoted 5 lines · On 7/20/26 12:59, [email protected] wrote:

From: surendra <[email protected]>

The driver locates the pos and neg child nodes to obtain their enable GPIOs, but registers both regulators with the parent node. As a result, the regulator core does not parse per-rail DT constraints or supplies.

Hmmm, no it does get the constraints properly because the regulator core will fetch the associated subnodes with the of_match desc property in regulator_of_get_init_node().

This patch solves nothing and duplicates the regulator core behaviour.

Neil

Quoted 46 lines

Pass each matching child node in regulator_config.of_node.

Fixes 0c47e1a8cf5d ("regulator: add SGM3804 Dual Output driver")
---
  drivers/regulator/sgm3804-regulator.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
drivers/regulator/sgm3804-regulator.c +11 -3
index c3406cfb73d0..531b98460ee3 100644
@@ -9,6 +9,7 @@
  #include <linux/err.h>
  #include <linux/i2c.h>
  #include <linux/module.h>
+#include <linux/of.h>
  #include <linux/regmap.h>
  #include <linux/regulator/driver.h>
  #include <linux/regulator/of_regulator.h>
@@ -268,14 +269,21 @@ static int sgm3804_probe(struct i2c_client *i2c)
 
  	for (i = 0; i < ARRAY_SIZE(sgm3804_regulator_desc); i++) {
  		struct regulator_config config = { };
+		const struct regulator_desc *reg = &sgm3804_regulator_desc[i];
  		struct regulator_dev *rdev;
+		struct device_node *child;
+
+		child = of_get_child_by_name(dev_of_node(dev), reg->of_match);
+		if (!child)
+			return dev_err_probe(dev, -EINVAL, "missing child '%s'\n",
+					     reg->of_match);
 
  		config.dev = dev;
  		config.regmap = ctx->regmap;
-		config.of_node = dev_of_node(dev);
+		config.of_node = child;
  		config.driver_data = ctx;
-		rdev = devm_regulator_register(dev, &sgm3804_regulator_desc[i],
-					       &config);
+		rdev = devm_regulator_register(dev, reg, &config);
+		of_node_put(child);
  		if (IS_ERR(rdev))
  			return dev_err_probe(dev, PTR_ERR(rdev),
  					     "failed to register regulator %d\n", i);