¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

[PATCH v2 1/5] power: regulator: Trigger probe of regulators which are always-on or boot-on


Marek Vasut
 

In case a regulator DT node contains regulator-always-on or regulator-boo=
t-on
property, make sure the regulator gets correctly configured by U-Boot on =
start
up. Unconditionally probe such regulator drivers. This is a preparatory p=
atch
for introduction of .regulator_post_probe() which would trigger the regul=
ator
configuration.

Parsing of regulator-always-on and regulator-boot-on DT property has been
moved to regulator_post_bind() as the information is required early, the
rest of the DT parsing has been kept in regulator_pre_probe() to avoid
slowing down the boot process.

Signed-off-by: Marek Vasut <marex@...>
---
Cc: Ben Wolsieffer <benwolsieffer@...>
Cc: Caleb Connolly <caleb.connolly@...>
Cc: Chris Morgan <macromorgan@...>
Cc: Dragan Simic <dsimic@...>
Cc: Eugen Hristev <eugen.hristev@...>
Cc: Francesco Dolcini <francesco.dolcini@...>
Cc: Heinrich Schuchardt <xypron.glpk@...>
Cc: Jaehoon Chung <jh80.chung@...>
Cc: Jagan Teki <jagan@...>
Cc: Jonas Karlman <jonas@...>
Cc: Kever Yang <kever.yang@...>
Cc: Kostya Porotchkin <kostap@...>
Cc: Matteo Lisi <matteo.lisi@...>
Cc: Mattijs Korpershoek <mkorpershoek@...>
Cc: Max Krummenacher <max.krummenacher@...>
Cc: Neil Armstrong <neil.armstrong@...>
Cc: Patrice Chotard <patrice.chotard@...>
Cc: Patrick Delaunay <patrick.delaunay@...>
Cc: Philipp Tomsich <philipp.tomsich@...>
Cc: Quentin Schulz <quentin.schulz@...>
Cc: Sam Day <me@...>
Cc: Simon Glass <sjg@...>
Cc: Sumit Garg <sumit.garg@...>
Cc: Svyatoslav Ryhel <clamor95@...>
Cc: Thierry Reding <treding@...>
Cc: Tom Rini <trini@...>
Cc: Volodymyr Babchuk <Volodymyr_Babchuk@...>
Cc: [email protected]
Cc: [email protected]
Cc: u-boot@...
Cc: u-boot@...
Cc: uboot-stm32@...
---
V2: - Rebase on current u-boot/next
- Update test cases to handle already started regulators correctly
---
drivers/power/regulator/regulator-uclass.c | 22 +++++++++++++++-------
test/dm/panel.c | 2 +-
test/dm/regulator.c | 4 ++--
3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/r=
egulator/regulator-uclass.c
index 88a8525b3c4..e2f703702e3 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -433,6 +433,8 @@ static int regulator_post_bind(struct udevice *dev)
const char *property =3D "regulator-name";
=20
uc_pdata =3D dev_get_uclass_plat(dev);
+ uc_pdata->always_on =3D dev_read_bool(dev, "regulator-always-on");
+ uc_pdata->boot_on =3D dev_read_bool(dev, "regulator-boot-on");
=20
/* Regulator's mandatory constraint */
uc_pdata->name =3D dev_read_string(dev, property);
@@ -444,13 +446,21 @@ static int regulator_post_bind(struct udevice *dev)
return -EINVAL;
}
=20
- if (regulator_name_is_unique(dev, uc_pdata->name))
- return 0;
+ if (!regulator_name_is_unique(dev, uc_pdata->name)) {
+ debug("'%s' of dev: '%s', has nonunique value: '%s\n",
+ property, dev->name, uc_pdata->name);
+ return -EINVAL;
+ }
=20
- debug("'%s' of dev: '%s', has nonunique value: '%s\n",
- property, dev->name, uc_pdata->name);
+ /*
+ * In case the regulator has regulator-always-on or
+ * regulator-boot-on DT property, trigger probe() to
+ * configure its default state during startup.
+ */
+ if (uc_pdata->always_on && uc_pdata->boot_on)
+ dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
=20
- return -EINVAL;
+ return 0;
}
=20
static int regulator_pre_probe(struct udevice *dev)
@@ -473,8 +483,6 @@ static int regulator_pre_probe(struct udevice *dev)
-ENODATA);
uc_pdata->max_uA =3D dev_read_u32_default(dev, "regulator-max-microamp"=
,
-ENODATA);
- uc_pdata->always_on =3D dev_read_bool(dev, "regulator-always-on");
- uc_pdata->boot_on =3D dev_read_bool(dev, "regulator-boot-on");
uc_pdata->ramp_delay =3D dev_read_u32_default(dev, "regulator-ramp-dela=
y",
0);
uc_pdata->force_off =3D dev_read_bool(dev, "regulator-force-boot-off");
diff --git a/test/dm/panel.c b/test/dm/panel.c
index ce835c96ed0..ec85a9b1e6e 100644
--- a/test/dm/panel.c
+++ b/test/dm/panel.c
@@ -33,7 +33,7 @@ static int dm_test_panel(struct unit_test_state *uts)
ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
&enable, &polarity));
ut_asserteq(false, enable);
- ut_asserteq(false, regulator_get_enable(reg));
+ ut_asserteq(true, regulator_get_enable(reg));
=20
ut_assertok(panel_enable_backlight(dev));
ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
diff --git a/test/dm/regulator.c b/test/dm/regulator.c
index 532bbd82376..449748ad52f 100644
--- a/test/dm/regulator.c
+++ b/test/dm/regulator.c
@@ -186,7 +186,7 @@ int dm_test_power_regulator_set_enable_if_allowed(str=
uct unit_test_state *uts)
=20
/* Get BUCK1 - always on regulator */
platname =3D regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
+ ut_asserteq(-EALREADY, regulator_autoset_by_name(platname, &dev_autoset=
));
ut_assertok(regulator_get_by_platname(platname, &dev));
=20
/* Try disabling always-on regulator */
@@ -288,7 +288,7 @@ static int dm_test_power_regulator_autoset(struct uni=
t_test_state *uts)
* Expected output state: uV=3D1200000; uA=3D200000; output enabled
*/
platname =3D regulator_names[BUCK1][PLATNAME];
- ut_assertok(regulator_autoset_by_name(platname, &dev_autoset));
+ ut_asserteq(-EALREADY, regulator_autoset_by_name(platname, &dev_autoset=
));
=20
/* Check, that the returned device is proper */
ut_assertok(regulator_get_by_platname(platname, &dev));
--=20
2.45.2


Jonas Karlman
 

Hi Marek,

On 2024-09-25 04:21, Marek Vasut wrote:
In case a regulator DT node contains regulator-always-on or regulator-boot-on
property, make sure the regulator gets correctly configured by U-Boot on start
up. Unconditionally probe such regulator drivers. This is a preparatory patch
for introduction of .regulator_post_probe() which would trigger the regulator
configuration.

Parsing of regulator-always-on and regulator-boot-on DT property has been
moved to regulator_post_bind() as the information is required early, the
rest of the DT parsing has been kept in regulator_pre_probe() to avoid
slowing down the boot process.

Signed-off-by: Marek Vasut <marex@...>
[snip]


- debug("'%s' of dev: '%s', has nonunique value: '%s\n",
- property, dev->name, uc_pdata->name);
+ /*
+ * In case the regulator has regulator-always-on or
+ * regulator-boot-on DT property, trigger probe() to
+ * configure its default state during startup.
+ */
+ if (uc_pdata->always_on && uc_pdata->boot_on)
This check for always_on _and_ boot_on does not fully match the commit
message, comment or the old behavior of regulators_enable_boot_on()
where any always_on _or_ boot_on would trigger autoset().

Regards,
Jonas

+ dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);

- return -EINVAL;
+ return 0;
}
[snip]


Marek Vasut
 

On 9/26/24 5:05 PM, Jonas Karlman wrote:
Hi Marek,
Hi,

On 2024-09-25 04:21, Marek Vasut wrote:
In case a regulator DT node contains regulator-always-on or regulator-boot-on
property, make sure the regulator gets correctly configured by U-Boot on start
up. Unconditionally probe such regulator drivers. This is a preparatory patch
for introduction of .regulator_post_probe() which would trigger the regulator
configuration.

Parsing of regulator-always-on and regulator-boot-on DT property has been
moved to regulator_post_bind() as the information is required early, the
rest of the DT parsing has been kept in regulator_pre_probe() to avoid
slowing down the boot process.

Signed-off-by: Marek Vasut <marex@...>
[snip]

- debug("'%s' of dev: '%s', has nonunique value: '%s\n",
- property, dev->name, uc_pdata->name);
+ /*
+ * In case the regulator has regulator-always-on or
+ * regulator-boot-on DT property, trigger probe() to
+ * configure its default state during startup.
+ */
+ if (uc_pdata->always_on && uc_pdata->boot_on)
This check for always_on _and_ boot_on does not fully match the commit
message, comment or the old behavior of regulators_enable_boot_on()
where any always_on _or_ boot_on would trigger autoset().
This should be ORR, thanks for spotting this, fixed in V3.