[PATCH v3 3/4] power: regulator: Perform regulator setup inside uclass

Svyatoslav Ryhel clamor95 at gmail.com
Sun Aug 6 19:52:23 CEST 2023


Regulators initial setup was previously dependent on board call.
To move from this behaviour next solution is proposed: on post_bind
boot-on/always-on properties are checked, all regulators with
such props will be probed just after binding which ensures that
essential regulators are set, then in the post probe regulator
autoset is called so that correct regulator state according to
device tree is reached.

Signed-off-by: Svyatoslav Ryhel <clamor95 at gmail.com>
[jonas at kwiboo.se: use autoset func, only probe with always/boot-on prop]
Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
---
 drivers/power/regulator/regulator-uclass.c | 30 ++++++++++++++++++----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 4b2c6c2964..69d6d6428d 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -473,6 +473,7 @@ static int regulator_post_bind(struct udevice *dev)
 {
 	struct dm_regulator_uclass_plat *uc_pdata;
 	const char *property = "regulator-name";
+	int ret;
 
 	uc_pdata = dev_get_uclass_plat(dev);
 
@@ -486,13 +487,20 @@ static int regulator_post_bind(struct udevice *dev)
 			return -EINVAL;
 	}
 
-	if (regulator_name_is_unique(dev, uc_pdata->name))
-		return 0;
+	ret = regulator_name_is_unique(dev, uc_pdata->name);
+	if (!ret) {
+		debug("'%s' of dev: '%s', has nonunique value: '%s'\n",
+		      property, dev->name, uc_pdata->name);
+		return -EINVAL;
+	}
 
-	debug("'%s' of dev: '%s', has nonunique value: '%s\n",
-	      property, dev->name, uc_pdata->name);
+	uc_pdata->always_on = dev_read_bool(dev, "regulator-always-on");
+	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
 
-	return -EINVAL;
+	if (uc_pdata->always_on || uc_pdata->boot_on)
+		dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
+
+	return 0;
 }
 
 static int regulator_pre_probe(struct udevice *dev)
@@ -546,6 +554,17 @@ static int regulator_pre_probe(struct udevice *dev)
 	return 0;
 }
 
+static int regulator_post_probe(struct udevice *dev)
+{
+	int ret;
+
+	ret = regulator_autoset(dev);
+	if (ret == -EMEDIUMTYPE || ret == -ENOSYS)
+		return 0;
+
+	return ret;
+}
+
 int regulators_enable_boot_on(bool verbose)
 {
 	struct udevice *dev;
@@ -603,5 +622,6 @@ UCLASS_DRIVER(regulator) = {
 	.name		= "regulator",
 	.post_bind	= regulator_post_bind,
 	.pre_probe	= regulator_pre_probe,
+	.post_probe	= regulator_post_probe,
 	.per_device_plat_auto	= sizeof(struct dm_regulator_uclass_plat),
 };
-- 
2.39.2



More information about the U-Boot mailing list