Skip to contentSkip to conversation

power: regulator: Add support for regulator-force-boot-off

PATCH New Stefan Roese 2 participants 6 messages Apr 8, 2021 – Apr 10, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
 drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++
 include/power/regulator.h                  | 23 +++++++++++++
 2 files changed, 61 insertions(+)
drivers/power/regulator/regulator-uclass.c +38 -0
index 4d2e730271f9..423867edced8 100644
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
 	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->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;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
 	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
 	uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
 						    0);
+	uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 
 	node = dev_read_subnode(dev, "regulator-state-mem");
 	if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
 	return ret;
 }
 
+int regulators_enable_boot_off(bool verbose)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	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_unset(dev);
+		if (ret == -EMEDIUMTYPE) {
+			ret = 0;
+			continue;
+		}
+		if (verbose)
+			regulator_show(dev, ret);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+
+	return ret;
+}
+
 UCLASS_DRIVER(regulator) = {
 	.id		= UCLASS_REGULATOR,
 	.name		= "regulator",
include/power/regulator.h +23 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
  * @max_uA*    - maximum amperage (micro Amps)
  * @always_on* - bool type, true or false
  * @boot_on*   - bool type, true or false
+ * @force_off* - bool type, true or false
  * TODO(sjg at chromium.org): Consider putting the above two into @flags
  * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
  * @flags:     - flags value (see REGULATOR_FLAG_...)
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
 	unsigned int ramp_delay;
 	bool always_on;
 	bool boot_on;
+	bool force_off;
 	const char *name;
 	int flags;
 	u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
  */
 int regulators_enable_boot_on(bool verbose);
 
+/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */
+int regulators_enable_boot_off(bool verbose);
+
 /**
  * regulator_autoset: setup the voltage/current on a regulator
  *
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);
  */
 int regulator_autoset(struct udevice *dev);
 
+/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):
+ *
+ * - Disable - will set - if  'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */
+int regulator_unset(struct udevice *dev);
+
 /**
  * regulator_autoset_by_name: setup the regulator given by its uclass's
  * platform data name field. The setup depends on constraints found in device's
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

Hi Stefan,

Quoted 21 lines · Stefan Roese

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
 drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++
 include/power/regulator.h                  | 23 +++++++++++++
 2 files changed, 61 insertions(+)
drivers/power/regulator/regulator-uclass.c +0 -0
index 4d2e730271f9..423867edced8 100644

drivers/power/regulator/regulator-uclass.c int regulator_autoset(struct udevice *dev) · line 319

Quoted 9 lines
drivers/power/regulator/regulator-uclass.c +6 -0
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
 	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->force_off)

Could you check whether uc_pdata is NULL or not?
It can be returned to NULL.

Quoted 21 lines
drivers/power/regulator/regulator-uclass.c +7 -0
+		return regulator_set_enable(dev, false);
+
+	return -EMEDIUMTYPE;
+}
+
 static void regulator_show(struct udevice *dev, int ret)
 {
 	struct dm_regulator_uclass_plat *uc_pdata;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
 	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
 	uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
 						    0);
+	uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 
 	node = dev_read_subnode(dev, "regulator-state-mem");
 	if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
 	return ret;
 }
 
+int regulators_enable_boot_off(bool verbose)

drivers/power/regulator/regulator-uclass.c int regulators_enable_boot_on(bool verbose) · line 520

Quoted 10 lines
drivers/power/regulator/regulator-uclass.c +10 -0
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_REGULATOR, &uc);
+	if (ret)
+		return ret;
+	for (uclass_first_device(UCLASS_REGULATOR, &dev);
+	     dev;

typo?

Best Regards,
Jaehoon Chung

Quoted 74 lines
drivers/power/regulator/regulator-uclass.c +15 -0
+	     uclass_next_device(&dev)) {
+		ret = regulator_unset(dev);
+		if (ret == -EMEDIUMTYPE) {
+			ret = 0;
+			continue;
+		}
+		if (verbose)
+			regulator_show(dev, ret);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+
+	return ret;
+}
+
 UCLASS_DRIVER(regulator) = {
 	.id		= UCLASS_REGULATOR,
 	.name		= "regulator",
include/power/regulator.h +23 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
  * @max_uA*    - maximum amperage (micro Amps)
  * @always_on* - bool type, true or false
  * @boot_on*   - bool type, true or false
+ * @force_off* - bool type, true or false
  * TODO(sjg at chromium.org): Consider putting the above two into @flags
  * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
  * @flags:     - flags value (see REGULATOR_FLAG_...)
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
 	unsigned int ramp_delay;
 	bool always_on;
 	bool boot_on;
+	bool force_off;
 	const char *name;
 	int flags;
 	u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
  */
 int regulators_enable_boot_on(bool verbose);
 
+/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */
+int regulators_enable_boot_off(bool verbose);
+
 /**
  * regulator_autoset: setup the voltage/current on a regulator
  *
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);
  */
 int regulator_autoset(struct udevice *dev);
 
+/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):
+ *
+ * - Disable - will set - if  'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */
+int regulator_unset(struct udevice *dev);
+
 /**
  * regulator_autoset_by_name: setup the regulator given by its uclass's
  * platform data name field. The setup depends on constraints found in device's
#2 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

Quoted 57 lines · Jaehoon Chung

Hi Stefan,

Quoted 21 lines · Stefan Roese

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
 drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++
 include/power/regulator.h                  | 23 +++++++++++++
 2 files changed, 61 insertions(+)
drivers/power/regulator/regulator-uclass.c +0 -0
index 4d2e730271f9..423867edced8 100644

drivers/power/regulator/regulator-uclass.c int regulator_autoset(struct udevice *dev) · line 319

Quoted 9 lines
drivers/power/regulator/regulator-uclass.c +6 -0
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
 	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->force_off)

Could you check whether uc_pdata is NULL or not?
It can be returned to NULL.

Quoted 20 lines
drivers/power/regulator/regulator-uclass.c +6 -0
+		return regulator_set_enable(dev, false);
+
+	return -EMEDIUMTYPE;
+}
+
 static void regulator_show(struct udevice *dev, int ret)
 {
 	struct dm_regulator_uclass_plat *uc_pdata;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
 	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
 	uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
 						    0);
+	uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 
 	node = dev_read_subnode(dev, "regulator-state-mem");
 	if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
 	return ret;
 }
 
Quoted 13 lines

drivers/power/regulator/regulator-uclass.c int regulators_enable_boot_on(bool verbose) · line 520

Quoted 11 lines
drivers/power/regulator/regulator-uclass.c +11 -0
+int regulators_enable_boot_off(bool verbose)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_REGULATOR, &uc);
+	if (ret)
+		return ret;
+	for (uclass_first_device(UCLASS_REGULATOR, &dev);
+	     dev;

typo?

I have checked that it was not typo. :)
how about making one line?

Best Regards,
Jaehoo Chung

Quoted 80 lines

Best Regards,
Jaehoon Chung

Quoted 74 lines
drivers/power/regulator/regulator-uclass.c +15 -0
+	     uclass_next_device(&dev)) {
+		ret = regulator_unset(dev);
+		if (ret == -EMEDIUMTYPE) {
+			ret = 0;
+			continue;
+		}
+		if (verbose)
+			regulator_show(dev, ret);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+
+	return ret;
+}
+
 UCLASS_DRIVER(regulator) = {
 	.id		= UCLASS_REGULATOR,
 	.name		= "regulator",
include/power/regulator.h +23 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
  * @max_uA*    - maximum amperage (micro Amps)
  * @always_on* - bool type, true or false
  * @boot_on*   - bool type, true or false
+ * @force_off* - bool type, true or false
  * TODO(sjg at chromium.org): Consider putting the above two into @flags
  * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
  * @flags:     - flags value (see REGULATOR_FLAG_...)
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
 	unsigned int ramp_delay;
 	bool always_on;
 	bool boot_on;
+	bool force_off;
 	const char *name;
 	int flags;
 	u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
  */
 int regulators_enable_boot_on(bool verbose);
 
+/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */
+int regulators_enable_boot_off(bool verbose);
+
 /**
  * regulator_autoset: setup the voltage/current on a regulator
  *
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);
  */
 int regulator_autoset(struct udevice *dev);
 
+/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):
+ *
+ * - Disable - will set - if  'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */
+int regulator_unset(struct udevice *dev);
+
 /**
  * regulator_autoset_by_name: setup the regulator given by its uclass's
  * platform data name field. The setup depends on constraints found in device's
#3 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

Hi Jaehoon,

Quoted 72 lines · Jaehoon Chung
Quoted 57 lines · Jaehoon Chung

Hi Stefan,

Quoted 21 lines · Stefan Roese

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
  drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++
  include/power/regulator.h                  | 23 +++++++++++++
  2 files changed, 61 insertions(+)
drivers/power/regulator/regulator-uclass.c +0 -0
index 4d2e730271f9..423867edced8 100644

drivers/power/regulator/regulator-uclass.c int regulator_autoset(struct udevice *dev) · line 319

Quoted 9 lines
drivers/power/regulator/regulator-uclass.c +6 -0
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
  	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->force_off)

Could you check whether uc_pdata is NULL or not?
It can be returned to NULL.

Quoted 20 lines
drivers/power/regulator/regulator-uclass.c +6 -0
+		return regulator_set_enable(dev, false);
+
+	return -EMEDIUMTYPE;
+}
+
  static void regulator_show(struct udevice *dev, int ret)
  {
  	struct dm_regulator_uclass_plat *uc_pdata;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
  	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
  	uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
  						    0);
+	uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 
  	node = dev_read_subnode(dev, "regulator-state-mem");
  	if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
  	return ret;
  }
 
Quoted 13 lines

drivers/power/regulator/regulator-uclass.c int regulators_enable_boot_on(bool verbose) · line 520

Quoted 11 lines
drivers/power/regulator/regulator-uclass.c +11 -0
+int regulators_enable_boot_off(bool verbose)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_REGULATOR, &uc);
+	if (ret)
+		return ret;
+	for (uclass_first_device(UCLASS_REGULATOR, &dev);
+	     dev;

typo?

Quoted 2 lines

I have checked that it was not typo. :)
how about making one line?

I could do this. But this would lead to a quite long line:

	for (uclass_first_device(UCLASS_REGULATOR, &dev); dev; 

uclass_next_device(&dev)) {

Only putting "dev;" into the same line is not appealing, at least not to me. Please note that this style of uclass looping is pretty common. It's also used a few lines above in regulators_enable_boot_on():

int regulators_enable_boot_on(bool verbose)

{
	struct udevice *dev;
	struct uclass *uc;
	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);

...

So I would like to keep it as in v1.

Thanks,
Stefan

Quoted 85 lines

Best Regards,
Jaehoo Chung

Quoted 80 lines

Best Regards,
Jaehoon Chung

Quoted 74 lines
drivers/power/regulator/regulator-uclass.c +15 -0
+	     uclass_next_device(&dev)) {
+		ret = regulator_unset(dev);
+		if (ret == -EMEDIUMTYPE) {
+			ret = 0;
+			continue;
+		}
+		if (verbose)
+			regulator_show(dev, ret);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+
+	return ret;
+}
+
  UCLASS_DRIVER(regulator) = {
  	.id		= UCLASS_REGULATOR,
  	.name		= "regulator",
include/power/regulator.h +23 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
   * @max_uA*    - maximum amperage (micro Amps)
   * @always_on* - bool type, true or false
   * @boot_on*   - bool type, true or false
+ * @force_off* - bool type, true or false
   * TODO(sjg at chromium.org): Consider putting the above two into @flags
   * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
   * @flags:     - flags value (see REGULATOR_FLAG_...)
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
  	unsigned int ramp_delay;
  	bool always_on;
  	bool boot_on;
+	bool force_off;
  	const char *name;
  	int flags;
  	u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
   */
  int regulators_enable_boot_on(bool verbose);
 
+/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */
+int regulators_enable_boot_off(bool verbose);
+
  /**
   * regulator_autoset: setup the voltage/current on a regulator
   *
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);
   */
  int regulator_autoset(struct udevice *dev);
 
+/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):
+ *
+ * - Disable - will set - if  'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */
+int regulator_unset(struct udevice *dev);
+
  /**
   * regulator_autoset_by_name: setup the regulator given by its uclass's
   * platform data name field. The setup depends on constraints found in device's

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de
#4 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

Hi Stefan,

Quoted 98 lines · Stefan Roese

Hi Jaehoon,

Quoted 69 lines · Jaehoon Chung
Quoted 59 lines · Jaehoon Chung

Hi Stefan,

Quoted 21 lines · Stefan Roese

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
? drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++ ? include/power/regulator.h????????????????? | 23 +++++++++++++ ? 2 files changed, 61 insertions(+)

drivers/power/regulator/regulator-uclass.c +0 -0
index 4d2e730271f9..423867edced8 100644

drivers/power/regulator/regulator-uclass.c int regulator_autoset(struct udevice *dev) · line 318

Quoted 8 lines
drivers/power/regulator/regulator-uclass.c +5 -0
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
 ????? 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->force_off)

Could you check whether uc_pdata is NULL or not?
It can be returned to NULL.

Quoted 23 lines
drivers/power/regulator/regulator-uclass.c +10 -0
+??????? return regulator_set_enable(dev, false);
+
+??? return -EMEDIUMTYPE;
+}
+
 ? static void regulator_show(struct udevice *dev, int ret)
 ? {
 ????? struct dm_regulator_uclass_plat *uc_pdata;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
 ????? uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
 ????? uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
 ????????????????????????????? 0);
+??? uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 ? ????? node = dev_read_subnode(dev, "regulator-state-mem");
 ????? if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
 ????? return ret;
 ? }
 ? +int regulators_enable_boot_off(bool verbose)
+{
+??? struct udevice *dev;
+??? struct uclass *uc;
+??? int ret;
Quoted 8 lines

drivers/power/regulator/regulator-uclass.c int regulators_enable_boot_on(bool verbose) · line 519

Quoted 6 lines
drivers/power/regulator/regulator-uclass.c +6 -0
+
+??? ret = uclass_get(UCLASS_REGULATOR, &uc);
+??? if (ret)
+??????? return ret;
+??? for (uclass_first_device(UCLASS_REGULATOR, &dev);
+???????? dev;

typo?

Quoted 2 lines

I have checked that it was not typo. :)
how about making one line?

I could do this. But this would lead to a quite long line:

????for (uclass_first_device(UCLASS_REGULATOR, &dev); dev; uclass_next_device(&dev)) {

Only putting "dev;" into the same line is not appealing, at least not to me. Please note that this style of uclass looping is pretty common. It's also used a few lines above in regulators_enable_boot_on():

int regulators_enable_boot_on(bool verbose)
{
????struct udevice *dev;
????struct uclass *uc;
????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);
...

Quoted 1 line

So I would like to keep it as in v1.

Yes, If you prefer to it, keep it as in v1.
I think that can be changed to below.

for (uclass_first_device(UCLASS_REGULATOR, &dev);
	dev; uclass_next_device(&dev)) {
	ret = reuglator_autoset(dev);
	...
}

But it's not critical thing. Thanks!

Best Regards,
Jaehoon Chung

Quoted 92 lines

Thanks,
Stefan

Quoted 83 lines

Best Regards,
Jaehoo Chung

Quoted 78 lines

Best Regards,
Jaehoon Chung

Quoted 72 lines
drivers/power/regulator/regulator-uclass.c +15 -0
+???????? uclass_next_device(&dev)) {
+??????? ret = regulator_unset(dev);
+??????? if (ret == -EMEDIUMTYPE) {
+??????????? ret = 0;
+??????????? continue;
+??????? }
+??????? if (verbose)
+??????????? regulator_show(dev, ret);
+??????? if (ret == -ENOSYS)
+??????????? ret = 0;
+??? }
+
+??? return ret;
+}
+
 ? UCLASS_DRIVER(regulator) = {
 ????? .id??????? = UCLASS_REGULATOR,
 ????? .name??????? = "regulator",
include/power/regulator.h +0 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
 ?? * @max_uA*??? - maximum amperage (micro Amps)

?? * @always_on* - bool type, true or false
?? * @boot_on*?? - bool type, true or false
+ * @force_off* - bool type, true or false
?? * TODO(sjg at chromium.org): Consider putting the above two into @flags ?? * @ramp_delay - Time to settle down after voltage change (unit: uV/us) ?? * @flags:???? - flags value (see REGULATOR_FLAG_...)

include/power/regulator.h +1 -0
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
 ????? unsigned int ramp_delay;
 ????? bool always_on;
 ????? bool boot_on;
+??? bool force_off;
 ????? const char *name;
 ????? int flags;
 ????? u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);

?? */
? int regulators_enable_boot_on(bool verbose);
? +/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */

include/power/regulator.h +2 -0
+int regulators_enable_boot_off(bool verbose);
+

? /**
?? * regulator_autoset: setup the voltage/current on a regulator ?? *

include/power/regulator.h +0 -0
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);

?? */
? int regulator_autoset(struct udevice *dev);
? +/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):
+ *
+ * - Disable - will set - if? 'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */

include/power/regulator.h +2 -0
+int regulator_unset(struct udevice *dev);
+

? /**
?? * regulator_autoset_by_name: setup the regulator given by its uclass's ?? * platform data name field. The setup depends on constraints found in device's

Viele Gr??e,
Stefan

#5 lore raw

PATCH 1/1 power: regulator: Add support for regulator-force-boot-off

In reply to Jaehoon Chung

Hi Jaehoon,

Quoted 27 lines · Jaehoon Chung

Hi Stefan,

Quoted 24 lines · Stefan Roese

From: Konstantin Porotchkin <[email protected]>

Add support for regulator-force-boot-off DT property. This property can be used by the board/device drivers for turning off regulators on early init stages as pre-requisite for the other components initialization.

---
  drivers/power/regulator/regulator-uclass.c | 38 ++++++++++++++++++++++
  include/power/regulator.h                  | 23 +++++++++++++
  2 files changed, 61 insertions(+)
drivers/power/regulator/regulator-uclass.c +0 -0
index 4d2e730271f9..423867edced8 100644
@@ -311,6 +311,17 @@ int regulator_autoset(struct udevice *dev)
  	return ret;
  }
 
Quoted 9 lines

drivers/power/regulator/regulator-uclass.c int regulator_autoset(struct udevice *dev) · line 319

Quoted 6 lines
drivers/power/regulator/regulator-uclass.c +6 -0
+int regulator_unset(struct udevice *dev)
+{
+	struct dm_regulator_uclass_plat *uc_pdata;
+
+	uc_pdata = dev_get_uclass_plat(dev);
+	if (uc_pdata->force_off)

Could you check whether uc_pdata is NULL or not?
It can be returned to NULL.

Sure. I'll add this check in v2.

Quoted 20 lines
Quoted 20 lines
drivers/power/regulator/regulator-uclass.c +6 -0
+		return regulator_set_enable(dev, false);
+
+	return -EMEDIUMTYPE;
+}
+
  static void regulator_show(struct udevice *dev, int ret)
  {
  	struct dm_regulator_uclass_plat *uc_pdata;
@@ -443,6 +454,7 @@ static int regulator_pre_probe(struct udevice *dev)
  	uc_pdata->boot_on = dev_read_bool(dev, "regulator-boot-on");
  	uc_pdata->ramp_delay = dev_read_u32_default(dev, "regulator-ramp-delay",
  						    0);
+	uc_pdata->force_off = dev_read_bool(dev, "regulator-force-boot-off");
 
  	node = dev_read_subnode(dev, "regulator-state-mem");
  	if (ofnode_valid(node)) {
@@ -495,6 +507,32 @@ int regulators_enable_boot_on(bool verbose)
  	return ret;
  }
 
Quoted 13 lines

drivers/power/regulator/regulator-uclass.c int regulators_enable_boot_on(bool verbose) · line 520

Quoted 11 lines
drivers/power/regulator/regulator-uclass.c +11 -0
+int regulators_enable_boot_off(bool verbose)
+{
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	ret = uclass_get(UCLASS_REGULATOR, &uc);
+	if (ret)
+		return ret;
+	for (uclass_first_device(UCLASS_REGULATOR, &dev);
+	     dev;

typo?

See comment in next mail.

Thanks,
Stefan

Quoted 61 lines

Best Regards,
Jaehoon Chung

Quoted 58 lines
drivers/power/regulator/regulator-uclass.c +15 -0
+	     uclass_next_device(&dev)) {
+		ret = regulator_unset(dev);
+		if (ret == -EMEDIUMTYPE) {
+			ret = 0;
+			continue;
+		}
+		if (verbose)
+			regulator_show(dev, ret);
+		if (ret == -ENOSYS)
+			ret = 0;
+	}
+
+	return ret;
+}
+
  UCLASS_DRIVER(regulator) = {
  	.id		= UCLASS_REGULATOR,
  	.name		= "regulator",
include/power/regulator.h +11 -0
index da9a065bdde0..fad87c99e5db 100644
@@ -151,6 +151,7 @@ enum regulator_flag {
   * @max_uA*    - maximum amperage (micro Amps)
   * @always_on* - bool type, true or false
   * @boot_on*   - bool type, true or false
+ * @force_off* - bool type, true or false
   * TODO(sjg at chromium.org): Consider putting the above two into @flags
   * @ramp_delay - Time to settle down after voltage change (unit: uV/us)
   * @flags:     - flags value (see REGULATOR_FLAG_...)
@@ -176,6 +177,7 @@ struct dm_regulator_uclass_plat {
  	unsigned int ramp_delay;
  	bool always_on;
  	bool boot_on;
+	bool force_off;
  	const char *name;
  	int flags;
  	u8 ctrl_reg;
@@ -420,6 +422,15 @@ int regulator_set_mode(struct udevice *dev, int mode_id);
   */
  int regulators_enable_boot_on(bool verbose);
 
+/**
+ * regulators_enable_boot_off() - disable regulators needed for boot
+ *
+ * This disables all regulators which are marked to be off at boot time.
+ *
+ * This effectively calls regulator_unset() for every regulator.
+ */
+int regulators_enable_boot_off(bool verbose);
+
  /**
   * regulator_autoset: setup the voltage/current on a regulator
   *
@@ -439,6 +450,18 @@ int regulators_enable_boot_on(bool verbose);
   */
  int regulator_autoset(struct udevice *dev);
 
Quoted 17 lines
Quoted 6 lines
include/power/regulator.h +5 -0
+/**
+ * regulator_unset: turn off a regulator
+ *
+ * The setup depends on constraints found in device's uclass's platform data
+ * (struct dm_regulator_uclass_platdata):

include/power/regulator.h int regulators_enable_boot_on(bool verbose); · line 467

Quoted 10 lines
include/power/regulator.h +7 -0
+ *
+ * - Disable - will set - if  'force_off' is set to true,
+ *
+ * The function returns on the first-encountered error.
+ */
+int regulator_unset(struct udevice *dev);
+
  /**
   * regulator_autoset_by_name: setup the regulator given by its uclass's
   * platform data name field. The setup depends on constraints found in device's

Viele Gr??e,
Stefan

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de