Skip to contentSkip to conversation

General regulator and pmic uclass improvements

PATCH Superseded Svyatoslav Ryhel 3 participants 8 messages Jul 18, 2023 – Jul 19, 2023

Subsystems (6)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover General regulator and pmic uclass improvements

This patchset derives from discussion of TPS65913 bringup and aims to cycle all regulator management inside uclass removing need of any board calls for regulators.

My hw setup is Tegra 3 LG Optimus Vu P895 (PMIC is MAX77663) with native spl u-boot build.

power: regulator: expand basic reference counter onto all uclass Commit is basically expansion of 4fcba5d ("regulator: implement basic reference counter") onto all regulators.
- my testing on hw has shown no issues so far with both pmic regulators and fixed regulators. Counting works as expected.

power: regulator-uclass: perform regulator setup inside uclass All self-sufficient regulators are set to probe after bind to perform initial setup later in post-probe with pdata from device tree.
- self-sufficient regulator is one that is not dependent on any other device (this category does not include pmic regulators for example). I have tested fixed regulators and got correct probing and setup according to device tree.

power: pmic-uclass: probe every child on pmic_post_probe
All non self-sufficient regulators must be probed after main device is probed (in this case it is pmic_post_probe). In all other aspects pmic regulators behave same.
- tested with MAX77663 ldo and sd regulators, no errors or inconsistencies were tracked, regulator props (boot-on, always-on etc) and consumer calls work as expected.

power: regulator-uclass: remove all deprecated API use
This is where everything gets tricky. All board dedicated API of regulators has to be removed. System presented above should cover all regulators setup but non the less this should be disscussed with maintainers and tested on affected boards. This commit removes and cleans most of those API traces, except tests, I am still a bit confused how to setup testing since this is interference into framework itself.

Svyatoslav Ryhel (4):
power: regulator: expand basic reference counter onto all uclass
power: regulator-uclass: perform regulator setup inside uclass
power: pmic-uclass: probe every child on pmic_post_probe
power: regulator-uclass: remove all deprecated API use

 arch/arm/mach-rockchip/board.c                |   8 -
 arch/arm/mach-rockchip/rk3399/rk3399.c        |  10 -
 board/Marvell/octeontx2_cn913x/board.c        |   5 -
 .../amlogic/odroid-go-ultra/odroid-go-ultra.c |   2 -
 board/dhelectronics/dh_stm32mp1/board.c       |   2 -
 board/engicam/stm32mp1/stm32mp1.c             |   3 -
 board/google/veyron/veyron.c                  |   6 -
 board/samsung/common/exynos5-dt.c             |   4 -
 board/samsung/odroid/odroid.c                 |  10 -
 board/st/stm32mp1/stm32mp1.c                  |   9 -
 drivers/power/pmic/pmic-uclass.c              |  10 +
 drivers/power/regulator/regulator-uclass.c    | 234 +++++++-----------
 drivers/power/regulator/regulator_common.c    |  22 --
 drivers/power/regulator/regulator_common.h    |  21 --
 drivers/video/bridge/ps862x.c                 |  12 +-
 drivers/video/rockchip/rk_vop.c               |   6 +-
 include/power/regulator.h                     | 121 +--------
 17 files changed, 106 insertions(+), 379 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/4 power: regulator: expand basic reference counter onto all uclass

Commit is based on 4fcba5d ("regulator: implement basic reference counter") but expands the idea to all regulators instead of just fixed/gpio regulators.

---
 drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
 drivers/power/regulator/regulator_common.c | 22 ----------------------
 drivers/power/regulator/regulator_common.h | 21 ---------------------
 include/power/regulator.h                  |  2 ++
 4 files changed, 24 insertions(+), 43 deletions(-)
drivers/power/regulator/regulator-uclass.c +22 -0
index 3a6ba69f6d..c9194fe95c 100644
@@ -172,6 +172,23 @@ int regulator_set_enable(struct udevice *dev, bool enable)
 	if (!enable && uc_pdata->always_on)
 		return -EACCES;
 
+	/* If previously enabled, increase count */
+	if (enable && uc_pdata->enable_count > 0) {
+		uc_pdata->enable_count++;
+		return -EALREADY;
+	}
+
+	if (!enable) {
+		if (uc_pdata->enable_count > 1) {
+			/* If enabled multiple times, decrease count */
+			uc_pdata->enable_count--;
+			return -EBUSY;
+		} else if (!uc_pdata->enable_count) {
+			/* If already disabled, do nothing */
+			return -EALREADY;
+		}
+	}
+
 	if (uc_pdata->ramp_delay)
 		old_enable = regulator_get_enable(dev);
 
@@ -187,6 +204,11 @@ int regulator_set_enable(struct udevice *dev, bool enable)
 		}
 	}
 
+	if (enable)
+		uc_pdata->enable_count++;
+	else
+		uc_pdata->enable_count--;
+
 	return ret;
 }
 
drivers/power/regulator/regulator_common.c +0 -22
index e26f5ebec3..d88bc6f6de 100644
@@ -72,23 +72,6 @@ int regulator_common_set_enable(const struct udevice *dev,
 		return 0;
 	}
 
-	/* If previously enabled, increase count */
-	if (enable && plat->enable_count > 0) {
-		plat->enable_count++;
-		return -EALREADY;
-	}
-
-	if (!enable) {
-		if (plat->enable_count > 1) {
-			/* If enabled multiple times, decrease count */
-			plat->enable_count--;
-			return -EBUSY;
-		} else if (!plat->enable_count) {
-			/* If already disabled, do nothing */
-			return -EALREADY;
-		}
-	}
-
 	ret = dm_gpio_set_value(&plat->gpio, enable);
 	if (ret) {
 		pr_err("Can't set regulator : %s gpio to: %d\n", dev->name,
@@ -103,10 +86,5 @@ int regulator_common_set_enable(const struct udevice *dev,
 	if (!enable && plat->off_on_delay_us)
 		udelay(plat->off_on_delay_us);
 
-	if (enable)
-		plat->enable_count++;
-	else
-		plat->enable_count--;
-
 	return 0;
 }
drivers/power/regulator/regulator_common.h +0 -21
index d4962899d8..15f1fa4c93 100644
@@ -13,7 +13,6 @@ struct regulator_common_plat {
 	struct gpio_desc gpio; /* GPIO for regulator enable control */
 	unsigned int startup_delay_us;
 	unsigned int off_on_delay_us;
-	unsigned int enable_count;
 };
 
 int regulator_common_of_to_plat(struct udevice *dev,
@@ -21,26 +20,6 @@ int regulator_common_of_to_plat(struct udevice *dev,
 				char *enable_gpio_name);
 int regulator_common_get_enable(const struct udevice *dev,
 	struct regulator_common_plat *plat);
-/*
- * Enable or Disable a regulator
- *
- * This is a reentrant function and subsequent calls that enable will
- * increase an internal counter, and disable calls will decrease the counter.
- * The actual resource will be enabled when the counter gets to 1 coming from 0,
- * and disabled when it reaches 0 coming from 1.
- *
- * @dev: regulator device
- * @plat: Platform data
- * @enable: bool indicating whether to enable or disable the regulator
- * @return:
- * 0 on Success
- * -EBUSY if the regulator cannot be disabled because it's requested by
- *        another device
- * -EALREADY if the regulator has already been enabled or has already been
- *        disabled
- * -EACCES if there is no possibility to enable/disable the regulator
- * -ve on different error situation
- */
 int regulator_common_set_enable(const struct udevice *dev,
 	struct regulator_common_plat *plat, bool enable);
 
include/power/regulator.h +2 -0
index ff1bfc2435..727776a8cf 100644
@@ -158,6 +158,7 @@ enum regulator_flag {
  * @name**     - fdt regulator name - should be taken from the device tree
  * ctrl_reg:   - Control register offset used to enable/disable regulator
  * volt_reg:   - register offset for writing voltage vsel values
+ * enable_count - counter of enable calls for this regulator
  *
  * Note:
  * *  - set automatically on device probe by the uclass's '.pre_probe' method.
@@ -184,6 +185,7 @@ struct dm_regulator_uclass_plat {
 	u8 volt_reg;
 	bool suspend_on;
 	u32 suspend_uV;
+	u32 enable_count;
 };
 
 /* Regulator device operations */
Signature · 1 line
2.39.2
#2 lore raw

Re: [PATCH v1 1/4] power: regulator: expand basic reference counter onto all uclass

Hi Svyatoslav,

Quoted 117 lines · Svyatoslav Ryhel

Commit is based on 4fcba5d ("regulator: implement basic reference counter") but expands the idea to all regulators instead of just fixed/gpio regulators.

---
  drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
  drivers/power/regulator/regulator_common.c | 22 ----------------------
  drivers/power/regulator/regulator_common.h | 21 ---------------------
  include/power/regulator.h                  |  2 ++
  4 files changed, 24 insertions(+), 43 deletions(-)
drivers/power/regulator/regulator-uclass.c +22 -0
index 3a6ba69f6d..c9194fe95c 100644
@@ -172,6 +172,23 @@ int regulator_set_enable(struct udevice *dev, bool enable)
  	if (!enable && uc_pdata->always_on)
  		return -EACCES;
 
+	/* If previously enabled, increase count */
+	if (enable && uc_pdata->enable_count > 0) {
+		uc_pdata->enable_count++;
+		return -EALREADY;
+	}
+
+	if (!enable) {
+		if (uc_pdata->enable_count > 1) {
+			/* If enabled multiple times, decrease count */
+			uc_pdata->enable_count--;
+			return -EBUSY;
+		} else if (!uc_pdata->enable_count) {
+			/* If already disabled, do nothing */
+			return -EALREADY;
+		}
+	}
+
  	if (uc_pdata->ramp_delay)
  		old_enable = regulator_get_enable(dev);
 
@@ -187,6 +204,11 @@ int regulator_set_enable(struct udevice *dev, bool enable)
  		}
  	}
 
+	if (enable)
+		uc_pdata->enable_count++;
+	else
+		uc_pdata->enable_count--;
+
  	return ret;
  }
 
drivers/power/regulator/regulator_common.c +0 -22
index e26f5ebec3..d88bc6f6de 100644
@@ -72,23 +72,6 @@ int regulator_common_set_enable(const struct udevice *dev,
  		return 0;
  	}
 
-	/* If previously enabled, increase count */
-	if (enable && plat->enable_count > 0) {
-		plat->enable_count++;
-		return -EALREADY;
-	}
-
-	if (!enable) {
-		if (plat->enable_count > 1) {
-			/* If enabled multiple times, decrease count */
-			plat->enable_count--;
-			return -EBUSY;
-		} else if (!plat->enable_count) {
-			/* If already disabled, do nothing */
-			return -EALREADY;
-		}
-	}
-
  	ret = dm_gpio_set_value(&plat->gpio, enable);
  	if (ret) {
  		pr_err("Can't set regulator : %s gpio to: %d\n", dev->name,
@@ -103,10 +86,5 @@ int regulator_common_set_enable(const struct udevice *dev,
  	if (!enable && plat->off_on_delay_us)
  		udelay(plat->off_on_delay_us);
 
-	if (enable)
-		plat->enable_count++;
-	else
-		plat->enable_count--;
-
  	return 0;
  }
drivers/power/regulator/regulator_common.h +0 -11
index d4962899d8..15f1fa4c93 100644
@@ -13,7 +13,6 @@ struct regulator_common_plat {
  	struct gpio_desc gpio; /* GPIO for regulator enable control */
  	unsigned int startup_delay_us;
  	unsigned int off_on_delay_us;
-	unsigned int enable_count;
  };
 
  int regulator_common_of_to_plat(struct udevice *dev,
@@ -21,26 +20,6 @@ int regulator_common_of_to_plat(struct udevice *dev,
  				char *enable_gpio_name);
  int regulator_common_get_enable(const struct udevice *dev,
  	struct regulator_common_plat *plat);
-/*
- * Enable or Disable a regulator
- *
- * This is a reentrant function and subsequent calls that enable will
- * increase an internal counter, and disable calls will decrease the counter.
- * The actual resource will be enabled when the counter gets to 1 coming from 0,
- * and disabled when it reaches 0 coming from 1.
- *
- * @dev: regulator device
- * @plat: Platform data

drivers/power/regulator/regulator_common.h int regulator_common_of_to_plat(struct udevice *dev, · line 43

Quoted 10 lines
drivers/power/regulator/regulator_common.h +0 -10
- * @enable: bool indicating whether to enable or disable the regulator
- * @return:
- * 0 on Success
- * -EBUSY if the regulator cannot be disabled because it's requested by
- *        another device
- * -EALREADY if the regulator has already been enabled or has already been
- *        disabled
- * -EACCES if there is no possibility to enable/disable the regulator
- * -ve on different error situation
- */

Can't this whole documentation that you are removing be in fact integrated into the documentation for the function you moved the reference counter housekeeping to ?

Quoted 23 lines
drivers/power/regulator/regulator_common.h +0 -0
  int regulator_common_set_enable(const struct udevice *dev,
  	struct regulator_common_plat *plat, bool enable);
 
include/power/regulator.h +2 -0
index ff1bfc2435..727776a8cf 100644
@@ -158,6 +158,7 @@ enum regulator_flag {
   * @name**     - fdt regulator name - should be taken from the device tree
   * ctrl_reg:   - Control register offset used to enable/disable regulator
   * volt_reg:   - register offset for writing voltage vsel values
+ * enable_count - counter of enable calls for this regulator
   *
   * Note:
   * *  - set automatically on device probe by the uclass's '.pre_probe' method.
@@ -184,6 +185,7 @@ struct dm_regulator_uclass_plat {
  	u8 volt_reg;
  	bool suspend_on;
  	u32 suspend_uV;
+	u32 enable_count;
  };
 
  /* Regulator device operations */
#3 lore raw

Re: [PATCH v1 1/4] power: regulator: expand basic reference counter onto all uclass

вт, 18 лип. 2023 р. о 10:36 Eugen Hristev <[email protected]> пише:

Quoted 128 lines

Hi Svyatoslav,

Quoted 123 lines · Svyatoslav Ryhel

Commit is based on 4fcba5d ("regulator: implement basic reference counter") but expands the idea to all regulators instead of just fixed/gpio regulators.

---
  drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
  drivers/power/regulator/regulator_common.c | 22 ----------------------
  drivers/power/regulator/regulator_common.h | 21 ---------------------
  include/power/regulator.h                  |  2 ++
  4 files changed, 24 insertions(+), 43 deletions(-)
drivers/power/regulator/regulator-uclass.c +22 -0
index 3a6ba69f6d..c9194fe95c 100644
@@ -172,6 +172,23 @@ int regulator_set_enable(struct udevice *dev, bool enable)
      if (!enable && uc_pdata->always_on)
              return -EACCES;
 
+     /* If previously enabled, increase count */
+     if (enable && uc_pdata->enable_count > 0) {
+             uc_pdata->enable_count++;
+             return -EALREADY;
+     }
+
+     if (!enable) {
+             if (uc_pdata->enable_count > 1) {
+                     /* If enabled multiple times, decrease count */
+                     uc_pdata->enable_count--;
+                     return -EBUSY;
+             } else if (!uc_pdata->enable_count) {
+                     /* If already disabled, do nothing */
+                     return -EALREADY;
+             }
+     }
+
      if (uc_pdata->ramp_delay)
              old_enable = regulator_get_enable(dev);
 
@@ -187,6 +204,11 @@ int regulator_set_enable(struct udevice *dev, bool enable)
              }
      }
 
+     if (enable)
+             uc_pdata->enable_count++;
+     else
+             uc_pdata->enable_count--;
+
      return ret;
  }
 
drivers/power/regulator/regulator_common.c +0 -22
index e26f5ebec3..d88bc6f6de 100644
@@ -72,23 +72,6 @@ int regulator_common_set_enable(const struct udevice *dev,
              return 0;
      }
 
-     /* If previously enabled, increase count */
-     if (enable && plat->enable_count > 0) {
-             plat->enable_count++;
-             return -EALREADY;
-     }
-
-     if (!enable) {
-             if (plat->enable_count > 1) {
-                     /* If enabled multiple times, decrease count */
-                     plat->enable_count--;
-                     return -EBUSY;
-             } else if (!plat->enable_count) {
-                     /* If already disabled, do nothing */
-                     return -EALREADY;
-             }
-     }
-
      ret = dm_gpio_set_value(&plat->gpio, enable);
      if (ret) {
              pr_err("Can't set regulator : %s gpio to: %d\n", dev->name,
@@ -103,10 +86,5 @@ int regulator_common_set_enable(const struct udevice *dev,
      if (!enable && plat->off_on_delay_us)
              udelay(plat->off_on_delay_us);
 
-     if (enable)
-             plat->enable_count++;
-     else
-             plat->enable_count--;
-
      return 0;
  }
drivers/power/regulator/regulator_common.h +0 -17
index d4962899d8..15f1fa4c93 100644
@@ -13,7 +13,6 @@ struct regulator_common_plat {
      struct gpio_desc gpio; /* GPIO for regulator enable control */
      unsigned int startup_delay_us;
      unsigned int off_on_delay_us;
-     unsigned int enable_count;
  };
 
  int regulator_common_of_to_plat(struct udevice *dev,
@@ -21,26 +20,6 @@ int regulator_common_of_to_plat(struct udevice *dev,
                              char *enable_gpio_name);
  int regulator_common_get_enable(const struct udevice *dev,
      struct regulator_common_plat *plat);
-/*
- * Enable or Disable a regulator
- *
- * This is a reentrant function and subsequent calls that enable will
- * increase an internal counter, and disable calls will decrease the counter.
- * The actual resource will be enabled when the counter gets to 1 coming from 0,
- * and disabled when it reaches 0 coming from 1.
- *
- * @dev: regulator device
- * @plat: Platform data
- * @enable: bool indicating whether to enable or disable the regulator
- * @return:
- * 0 on Success
- * -EBUSY if the regulator cannot be disabled because it's requested by
- *        another device
- * -EALREADY if the regulator has already been enabled or has already been
Quoted 8 lines

drivers/power/regulator/regulator_common.h int regulator_common_of_to_plat(struct udevice *dev, · line 43

Quoted 4 lines
drivers/power/regulator/regulator_common.h +0 -4
- *        disabled
- * -EACCES if there is no possibility to enable/disable the regulator
- * -ve on different error situation
- */

Can't this whole documentation that you are removing be in fact integrated into the documentation for the function you moved the reference counter housekeeping to ?

Yes sure, I was not quite sure where to insert it.

Quoted 24 lines
Quoted 23 lines
drivers/power/regulator/regulator_common.h +0 -0
  int regulator_common_set_enable(const struct udevice *dev,
      struct regulator_common_plat *plat, bool enable);
 
include/power/regulator.h +2 -0
index ff1bfc2435..727776a8cf 100644
@@ -158,6 +158,7 @@ enum regulator_flag {
   * @name**     - fdt regulator name - should be taken from the device tree
   * ctrl_reg:   - Control register offset used to enable/disable regulator
   * volt_reg:   - register offset for writing voltage vsel values
+ * enable_count - counter of enable calls for this regulator
   *
   * Note:
   * *  - set automatically on device probe by the uclass's '.pre_probe' method.
@@ -184,6 +185,7 @@ struct dm_regulator_uclass_plat {
      u8 volt_reg;
      bool suspend_on;
      u32 suspend_uV;
+     u32 enable_count;
  };
 
  /* Regulator device operations */
#4 lore raw

Re: [PATCH v1 1/4] power: regulator: expand basic reference counter onto all uclass

Hi,

Quoted 18 lines · Svyatoslav Ryhel

вт, 18 лип. 2023 р. о 10:36 Eugen Hristev <[email protected]> пише:

Quoted 16 lines

Hi Svyatoslav,

Quoted 11 lines · Svyatoslav Ryhel

Commit is based on 4fcba5d ("regulator: implement basic reference counter") but expands the idea to all regulators instead of just fixed/gpio regulators.

---
  drivers/power/regulator/regulator-uclass.c | 22 ++++++++++++++++++++++
  drivers/power/regulator/regulator_common.c | 22 ----------------------
  drivers/power/regulator/regulator_common.h | 21 ---------------------
  include/power/regulator.h                  |  2 ++
  4 files changed, 24 insertions(+), 43 deletions(-)

Does this affect tests? Can you make sure that there is test coverage in test/dm/...

Regards,
Simon

#5 lore raw

PATCH 2/4 power: regulator-uclass: perform regulator setup inside uclass

In reply to Svyatoslav Ryhel

Regulators initial setup was previously dependent on board call. To move from this behaviour were introduced two steps. First is that all individual regulators will be probed just after binding which ensures that regulator pdata is filled and second is setting up regulator in post probe which enseres that correct regulator state according to pdata is reached.

---
 drivers/power/regulator/regulator-uclass.c | 212 ++++++---------------
 include/power/regulator.h                  | 119 ------------
 2 files changed, 62 insertions(+), 269 deletions(-)
drivers/power/regulator/regulator-uclass.c +62 -150
index c9194fe95c..8edc983eae 100644
@@ -308,112 +308,6 @@ int device_get_supply_regulator(struct udevice *dev, const char *supply_name,
 					    supply_name, devp);
 }
 
-int regulator_autoset(struct udevice *dev)
-{
-	struct dm_regulator_uclass_plat *uc_pdata;
-	int ret = 0;
-
-	uc_pdata = dev_get_uclass_plat(dev);
-
-	ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
-	if (ret == -ENOSYS)
-		ret = 0;
-
-	if (!ret && uc_pdata->suspend_on) {
-		ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
-		if (ret == -ENOSYS)
-			ret = 0;
-
-		if (ret)
-			return ret;
-	}
-
-	if (!uc_pdata->always_on && !uc_pdata->boot_on)
-		return -EMEDIUMTYPE;
-
-	if (uc_pdata->type == REGULATOR_TYPE_FIXED)
-		return regulator_set_enable(dev, true);
-
-	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
-		ret = regulator_set_value(dev, uc_pdata->min_uV);
-	if (uc_pdata->init_uV > 0)
-		ret = regulator_set_value(dev, uc_pdata->init_uV);
-	if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
-		ret = regulator_set_current(dev, uc_pdata->min_uA);
-
-	if (!ret)
-		ret = regulator_set_enable(dev, true);
-
-	return ret;
-}
-
-int regulator_unset(struct udevice *dev)
-{
-	struct dm_regulator_uclass_plat *uc_pdata;
-
-	uc_pdata = dev_get_uclass_plat(dev);
-	if (uc_pdata && uc_pdata->force_off)
-		return regulator_set_enable(dev, false);
-
-	return -EMEDIUMTYPE;
-}
-
-static void regulator_show(struct udevice *dev, int ret)
-{
-	struct dm_regulator_uclass_plat *uc_pdata;
-
-	uc_pdata = dev_get_uclass_plat(dev);
-
-	printf("%s@%s: ", dev->name, uc_pdata->name);
-	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
-		printf("set %d uV", uc_pdata->min_uV);
-	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA)
-		printf("; set %d uA", uc_pdata->min_uA);
-	printf("; enabling");
-	if (ret)
-		printf(" (ret: %d)", ret);
-	printf("\n");
-}
-
-int regulator_autoset_by_name(const char *platname, struct udevice **devp)
-{
-	struct udevice *dev;
-	int ret;
-
-	ret = regulator_get_by_platname(platname, &dev);
-	if (devp)
-		*devp = dev;
-	if (ret) {
-		debug("Can get the regulator: %s (err=%d)\n", platname, ret);
-		return ret;
-	}
-
-	return regulator_autoset(dev);
-}
-
-int regulator_list_autoset(const char *list_platname[],
-			   struct udevice *list_devp[],
-			   bool verbose)
-{
-	struct udevice *dev;
-	int error = 0, i = 0, ret;
-
-	while (list_platname[i]) {
-		ret = regulator_autoset_by_name(list_platname[i], &dev);
-		if (ret != -EMEDIUMTYPE && verbose)
-			regulator_show(dev, ret);
-		if (ret & !error)
-			error = ret;
-
-		if (list_devp)
-			list_devp[i] = dev;
-
-		i++;
-	}
-
-	return error;
-}
-
 static bool regulator_name_is_unique(struct udevice *check_dev,
 				     const char *check_name)
 {
@@ -444,6 +338,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);
 
@@ -457,13 +352,28 @@ 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);
+	switch (device_get_uclass_id(dev->parent)) {
+	/* In case class can have regulator child add it here */
+	case UCLASS_PMIC:
+		break;
+
+	default:
+		/*
+		 * Trigger probe() to configure default
+		 * regulators state during startup.
+		 */
+		dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
+		break;
+	}
 
-	return -EINVAL;
+	return 0;
 }
 
 static int regulator_pre_probe(struct udevice *dev)
@@ -517,55 +427,56 @@ static int regulator_pre_probe(struct udevice *dev)
 	return 0;
 }
 
-int regulators_enable_boot_on(bool verbose)
+static int regulator_post_probe(struct udevice *dev)
 {
-	struct udevice *dev;
-	struct uclass *uc;
+	struct dm_regulator_uclass_plat *uc_pdata =
+					 dev_get_uclass_plat(dev);
 	int ret;
 
-	ret = uclass_get(UCLASS_REGULATOR, &uc);
-	if (ret)
-		return ret;
-	for (uclass_first_device(UCLASS_REGULATOR, &dev);
-	     dev;
-	     uclass_next_device(&dev)) {
-		ret = regulator_autoset(dev);
-		if (ret == -EMEDIUMTYPE) {
-			ret = 0;
-			continue;
-		}
-		if (verbose)
-			regulator_show(dev, ret);
-		if (ret == -ENOSYS)
-			ret = 0;
-	}
+	/*
+	 * Disable is performed in case regulator was somehow
+	 * active, for example it is active by PMIC design etc.
+	 */
+	uc_pdata->enable_count = 1;
+	regulator_set_enable_if_allowed(dev, false);
 
-	return ret;
-}
+	/*
+	 * Always-on regulator can not be disabled so zero out
+	 * enable_count in case regulator has this property.
+	 */
+	uc_pdata->enable_count = 0;
 
-int regulators_enable_boot_off(bool verbose)
-{
-	struct udevice *dev;
-	struct uclass *uc;
-	int ret;
+	if (uc_pdata->force_off && uc_pdata->enable_count)
+		return 0;
 
-	ret = uclass_get(UCLASS_REGULATOR, &uc);
-	if (ret)
-		return ret;
-	for (uclass_first_device(UCLASS_REGULATOR, &dev);
-	     dev;
-	     uclass_next_device(&dev)) {
-		ret = regulator_unset(dev);
-		if (ret == -EMEDIUMTYPE) {
-			ret = 0;
-			continue;
-		}
-		if (verbose)
-			regulator_show(dev, ret);
+	ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
+	if (ret == -ENOSYS)
+		ret = 0;
+
+	if (!ret && uc_pdata->suspend_on) {
+		ret = regulator_set_suspend_value(dev, uc_pdata->suspend_uV);
 		if (ret == -ENOSYS)
 			ret = 0;
+
+		if (ret)
+			return ret;
+	}
+
+	if (uc_pdata->type != REGULATOR_TYPE_FIXED) {
+		if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
+			ret = regulator_set_value(dev, uc_pdata->min_uV);
+		if (uc_pdata->init_uV > 0)
+			ret = regulator_set_value(dev, uc_pdata->init_uV);
+		if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
+			ret = regulator_set_current(dev, uc_pdata->min_uA);
 	}
 
+	if (!uc_pdata->always_on && !uc_pdata->boot_on)
+		return 0;
+
+	if (!ret)
+		ret = regulator_set_enable_if_allowed(dev, true);
+
 	return ret;
 }
 
@@ -574,5 +485,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),
 };
include/power/regulator.h +0 -119

131 lines not on this page · raw message

Signature · 1 line
2.39.2
#6 lore raw

PATCH 3/4 power: pmic-uclass: probe every child on pmic_post_probe

In reply to Svyatoslav Ryhel

Main goal is to probe all regulator childrens for their proper setup but if pmic has non regulator children they should not suffer from this either.

---
 drivers/power/pmic/pmic-uclass.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/power/pmic/pmic-uclass.c +10 -0
index 0e2f5e1f41..8ca717bd5e 100644
@@ -16,6 +16,7 @@
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
 #include <power/pmic.h>
+#include <power/regulator.h>
 #include <linux/ctype.h>
 
 #if CONFIG_IS_ENABLED(PMIC_CHILDREN)
@@ -198,9 +199,18 @@ static int pmic_pre_probe(struct udevice *dev)
 	return 0;
 }
 
+static int pmic_post_probe(struct udevice *dev)
+{
+	struct udevice *child;
+
+	device_foreach_child_probe(child, dev);
+	return 0;
+}
+
 UCLASS_DRIVER(pmic) = {
 	.id		= UCLASS_PMIC,
 	.name		= "pmic",
 	.pre_probe	= pmic_pre_probe,
+	.post_probe	= pmic_post_probe,
 	.per_device_auto	= sizeof(struct uc_pmic_priv),
 };
Signature · 1 line
2.39.2
#7 lore raw

PATCH 4/4 power: regulator-uclass: remove all deprecated API use

In reply to Svyatoslav Ryhel

THIS REQUIRES PRECISE TESTING!

---
 arch/arm/mach-rockchip/board.c                  |  8 --------
 arch/arm/mach-rockchip/rk3399/rk3399.c          | 10 ----------
 board/Marvell/octeontx2_cn913x/board.c          |  5 -----
 board/amlogic/odroid-go-ultra/odroid-go-ultra.c |  2 --
 board/dhelectronics/dh_stm32mp1/board.c         |  2 --
 board/engicam/stm32mp1/stm32mp1.c               |  3 ---
 board/google/veyron/veyron.c                    |  6 ------
 board/samsung/common/exynos5-dt.c               |  4 ----
 board/samsung/odroid/odroid.c                   | 10 ----------
 board/st/stm32mp1/stm32mp1.c                    |  9 ---------
 drivers/video/bridge/ps862x.c                   | 12 ++++++++----
 drivers/video/rockchip/rk_vop.c                 |  6 ++----
 12 files changed, 10 insertions(+), 67 deletions(-)
arch/arm/mach-rockchip/board.c +0 -8
index 8d7b39ba15..3eaea4b04a 100644
@@ -189,14 +189,6 @@ int board_late_init(void)
 
 int board_init(void)
 {
-	int ret;
-
-#ifdef CONFIG_DM_REGULATOR
-	ret = regulators_enable_boot_on(false);
-	if (ret)
-		debug("%s: Cannot enable boot on regulator\n", __func__);
-#endif
-
 	return 0;
 }
 
arch/arm/mach-rockchip/rk3399/rk3399.c +0 -10
index a7cc91a952..cbd2ea047d 100644
@@ -280,15 +280,5 @@ void spl_board_init(void)
 		if (cru->glb_rst_st != 0)
 			rk3399_force_power_on_reset();
 	}
-
-	if (IS_ENABLED(CONFIG_SPL_DM_REGULATOR)) {
-		/*
-		 * Turning the eMMC and SPI back on (if disabled via the Qseven
-		 * BIOS_ENABLE) signal is done through a always-on regulator).
-		 */
-		if (regulators_enable_boot_on(false))
-			debug("%s: Cannot enable boot on regulator\n",
-			      __func__);
-	}
 }
 #endif
board/Marvell/octeontx2_cn913x/board.c +0 -5
index 3d20cfb2fa..3ffe15d42b 100644
@@ -23,11 +23,6 @@ int board_early_init_f(void)
 
 int board_early_init_r(void)
 {
-	if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
-		/* Check if any existing regulator should be turned down */
-		regulators_enable_boot_off(false);
-	}
-
 	return 0;
 }
 
board/amlogic/odroid-go-ultra/odroid-go-ultra.c +0 -2
index bbd23e20fc..fa6105a071 100644
@@ -16,7 +16,5 @@ int mmc_get_env_dev(void)
 
 int board_init(void)
 {
-	regulators_enable_boot_on(_DEBUG);
-
 	return 0;
 }
board/dhelectronics/dh_stm32mp1/board.c +0 -2
index f9cfabe242..a8ad5a1620 100644
@@ -615,8 +615,6 @@ static void board_init_regulator_av96(void)
 static void board_init_regulator(void)
 {
 	board_init_regulator_av96();
-
-	regulators_enable_boot_on(_DEBUG);
 }
 #else
 static inline int board_get_regulator_buck3_nvm_uv_av96(int *uv)
board/engicam/stm32mp1/stm32mp1.c +0 -3
index 5223e9bae8..c98bbdc71b 100644
@@ -38,9 +38,6 @@ int checkboard(void)
 /* board dependent setup after realloc */
 int board_init(void)
 {
-	if (IS_ENABLED(CONFIG_DM_REGULATOR))
-		regulators_enable_boot_on(_DEBUG);
-
 	return 0;
 }
 
board/google/veyron/veyron.c +0 -6
index 32dbcdc4d1..527e9d4b0e 100644
@@ -62,12 +62,6 @@ static int veyron_init(void)
 	if (ret)
 		return ret;
 
-	ret = regulators_enable_boot_on(false);
-	if (ret) {
-		debug("%s: Cannot enable boot on regulators\n", __func__);
-		return ret;
-	}
-
 	return 0;
 }
 #endif
board/samsung/common/exynos5-dt.c +0 -4
index cde77d79a0..45d34d838d 100644
@@ -92,10 +92,6 @@ int exynos_power_init(void)
 	if (ret == -ENODEV)
 		return 0;
 
-	ret = regulators_enable_boot_on(false);
-	if (ret)
-		return ret;
-
 	ret = exynos_set_regulator("vdd_mif", 1100000);
 	if (ret)
 		return ret;
board/samsung/odroid/odroid.c +0 -10
index 39a60e4ad2..28086ee92e 100644
@@ -431,16 +431,6 @@ int exynos_init(void)
 
 int exynos_power_init(void)
 {
-	const char *mmc_regulators[] = {
-		"VDDQ_EMMC_1.8V",
-		"VDDQ_EMMC_2.8V",
-		"TFLASH_2.8V",
-		NULL,
-	};
-
-	if (regulator_list_autoset(mmc_regulators, NULL, true))
-		pr_err("Unable to init all mmc regulators\n");
-
 	return 0;
 }
 
board/st/stm32mp1/stm32mp1.c +0 -9
index 3205a31c6d..7e425edefd 100644
@@ -602,13 +602,6 @@ static int board_stm32mp15x_dk2_init(void)
 		goto error;
 	}
 
-	/* power-up audio IC */
-	regulator_autoset_by_name("v1v8_audio", NULL);
-
-	/* power-up HDMI IC */
-	regulator_autoset_by_name("v1v2_hdmi", NULL);
-	regulator_autoset_by_name("v3v3_hdmi", NULL);
-
 error:
 	return ret;
 }
@@ -665,8 +658,6 @@ int board_init(void)
 	if (board_is_stm32mp15x_dk2())
 		board_stm32mp15x_dk2_init();
 
-	regulators_enable_boot_on(_DEBUG);
-
 	/*
 	 * sysconf initialisation done only when U-Boot is running in secure
 	 * done in TF-A for TFABOOT.
drivers/video/bridge/ps862x.c +8 -4
index d1d22a6e23..52a343bde2 100644
@@ -77,13 +77,17 @@ static int ps8622_attach(struct udevice *dev)
 	/* set the LDO providing the 1.2V rail to the Parade bridge */
 	ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
 					   "power-supply", &reg);
-	if (!ret) {
-		ret = regulator_autoset(reg);
-	} else if (ret != -ENOENT) {
-		debug("%s: Failed to enable power: ret=%d\n", __func__, ret);
+	if (ret) {
+		debug("%s: Failed to get power: ret=%d\n", __func__, ret);
 		return ret;
 	}
 
+	if (reg) {
+		ret = regulator_set_enable(reg, true);
+		if (ret)
+			return ret;
+	}
+
 	ret = video_bridge_set_active(dev, true);
 	if (ret)
 		return ret;
drivers/video/rockchip/rk_vop.c +2 -4
index c514e2a0e4..e81eed5ffa 100644
@@ -397,7 +397,7 @@ static int rk_display_init(struct udevice *dev, ulong fbbase, ofnode ep_node)
 void rk_vop_probe_regulators(struct udevice *dev,
 			     const char * const *names, int cnt)
 {
-	int i, ret;
+	int i;
 	const char *name;
 	struct udevice *reg;
 
@@ -405,9 +405,7 @@ void rk_vop_probe_regulators(struct udevice *dev,
 		name = names[i];
 		debug("%s: probing regulator '%s'\n", dev->name, name);
 
-		ret = regulator_autoset_by_name(name, &reg);
-		if (!ret)
-			ret = regulator_set_enable(reg, true);
+		regulator_set_enable(reg, true);
 	}
 }
 
Signature · 1 line
2.39.2