Skip to contentSkip to conversation

regulator: Allow autosetting fixed regulators

PATCH New Sven Schwermer 4 participants 11 messages May 31, 2019 – Jul 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Fixed regulators don't have a set_value method. Therefore, regulator_set_value will return -ENOSYS when called from regulator_autoset.

Accepting this return value allows autosetting fixed regulators.

---
 drivers/power/regulator/regulator-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/regulator/regulator-uclass.c +1 -1
index 9118b8eb39..0b99c262ac 100644
@@ -243,7 +243,7 @@ int regulator_autoset(struct udevice *dev)
 	if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
 		ret = regulator_set_current(dev, uc_pdata->min_uA);
 
-	if (!ret)
+	if (!ret || ret == -ENOSYS)
 		ret = regulator_set_enable(dev, true);
 
 	return ret;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Hi Sven,

Quoted 20 lines

Subject: [PATCH] regulator: Allow autosetting fixed regulators

Fixed regulators don't have a set_value method. Therefore, regulator_set_value will return -ENOSYS when called from regulator_autoset.

Accepting this return value allows autosetting fixed regulators.

---
 drivers/power/regulator/regulator-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/regulator/regulator-uclass.c +0 -0
index 9118b8eb39..0b99c262ac 100644

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

Quoted 5 lines
drivers/power/regulator/regulator-uclass.c +1 -1
@@ -243,7 +243,7 @@ int regulator_autoset(struct udevice *dev)
 	if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
 		ret = regulator_set_current(dev, uc_pdata->min_uA);
 
-	if (!ret)
+	if (!ret || ret == -ENOSYS)

According to code:

        if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
                ret = regulator_set_value(dev, uc_pdata->min_uV);
        if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
                ret = regulator_set_current(dev, uc_pdata->min_uA);

So you get -ENOSYS from the upper code?

Regards,
Peng.

Quoted 5 lines
drivers/power/regulator/regulator-uclass.c +0 -1
 		ret = regulator_set_enable(dev, true);
 
 	return ret;
--

2.17.1

#2 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Hi Peng,

Quoted 7 lines

According to code:

       if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
               ret = regulator_set_value(dev, uc_pdata->min_uV);
       if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
               ret = regulator_set_current(dev, uc_pdata->min_uA);

So you get -ENOSYS from the upper code?

Yes, for fixed regulators, the following if clause evaluates to true in regulator_pre_probe:

	/* Those values are optional (-ENODATA if unset) */
	if ((uc_pdata->min_uV != -ENODATA) &&
	    (uc_pdata->max_uV != -ENODATA) &&
	    (uc_pdata->min_uV == uc_pdata->max_uV))
		uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_UV;

However, in regulator_set_value, there is this section:

	if (!ops || !ops->set_value)
		return -ENOSYS;

So for fixed regulators, which don’t have a set_value, we’ll always get a -ENOSYS.

Sven

#3 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Quoted 12 lines

Subject: Re: [PATCH] regulator: Allow autosetting fixed regulators

Hi Peng,

Quoted 7 lines

According to code:

       if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
               ret = regulator_set_value(dev, uc_pdata->min_uV);
       if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
               ret = regulator_set_current(dev, uc_pdata->min_uA);

So you get -ENOSYS from the upper code?

Quoted 8 lines

Yes, for fixed regulators, the following if clause evaluates to true in regulator_pre_probe:

	/* Those values are optional (-ENODATA if unset) */
	if ((uc_pdata->min_uV != -ENODATA) &&
	    (uc_pdata->max_uV != -ENODATA) &&
	    (uc_pdata->min_uV == uc_pdata->max_uV))
		uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_UV;

For fixed regulator, will min_uV/max_uV be set to value other than -ENODATA? I think no.

Regards,
Peng.

Quoted 10 lines

However, in regulator_set_value, there is this section:

	if (!ops || !ops->set_value)
		return -ENOSYS;

So for fixed regulators, which don’t have a set_value, we’ll always get a -ENOSYS.

Sven

#4 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Quoted 3 lines

For fixed regulator, will min_uV/max_uV be set to value other than -ENODATA? I think no.

I see this commonly done (see Linux device trees as well as the u-boot device trees) and the kernel documentation seems to encourage it:
https://www.kernel.org/doc/Documentation/devicetree/bindings/regulator/fixed-regulator.txt <https://www.kernel.org/doc/Documentation/devicetree/bindings/regulator/fixed-regulator.txt>

Sven

#5 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

In reply to Sven Schwermer
Quoted 20 lines

Subject: [PATCH] regulator: Allow autosetting fixed regulators

Fixed regulators don't have a set_value method. Therefore, regulator_set_value will return -ENOSYS when called from regulator_autoset.

Accepting this return value allows autosetting fixed regulators.

---
 drivers/power/regulator/regulator-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/power/regulator/regulator-uclass.c +0 -0
index 9118b8eb39..0b99c262ac 100644

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

Quoted 6 lines
drivers/power/regulator/regulator-uclass.c +1 -1
@@ -243,7 +243,7 @@ int regulator_autoset(struct udevice *dev)
 	if (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
 		ret = regulator_set_current(dev, uc_pdata->min_uA);
 
-	if (!ret)
+	if (!ret || ret == -ENOSYS)
 		ret = regulator_set_enable(dev, true);

How about the following patch? not tested

drivers/power/regulator/regulator-uclass.c +3 -0
index 9118b8eb39..76be95bcd1 100644
@@ -238,6 +238,9 @@ int regulator_autoset(struct udevice *dev)
        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 (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))

Regards,
Peng.

Quoted 4 lines
drivers/power/regulator/regulator-uclass.c +0 -1
 	return ret;
--

2.17.1

#6 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Quoted 7 lines

How about the following patch? not tested

drivers/power/regulator/regulator-uclass.c +0 -0
index 9118b8eb39..76be95bcd1 100644

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

Quoted 9 lines
drivers/power/regulator/regulator-uclass.c +3 -0
@@ -238,6 +238,9 @@ int regulator_autoset(struct udevice *dev)
       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 (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))

That will probably work as well. It does, however, feel a little like a hack. What if there are other regulator types that require a similar workaround?

Sven

#7 lore raw

PATCH 1/1 regulator: Allow autosetting fixed regulators

Quoted 20 lines

-----Original Message-----
From: Sven Schwermer [mailto:sven at svenschwermer.de]
Sent: 2019年5月31日 18:44
To: Peng Fan <[email protected]>
Cc: u-boot at lists.denx.de; Jaehoon Chung <[email protected]>
Subject: Re: [PATCH] regulator: Allow autosetting fixed regulators

Review

Quoted 3 lines

How about the following patch? not tested

(quoted diff) +0 -0

b/drivers/power/regulator/regulator-uclass.c

Quoted 7 lines

index 9118b8eb39..76be95bcd1 100644

drivers/power/regulator/regulator-uclass.c +0 -0
@@ -238,6 +238,9 @@ int regulator_autoset(struct udevice *dev)
       if (!uc_pdata->always_on && !uc_pdata->boot_on)
               return -EMEDIUMTYPE;
 
Quoted 9 lines

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

Quoted 6 lines
drivers/power/regulator/regulator-uclass.c +3 -0
+       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 (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))

That will probably work as well. It does, however, feel a little like a hack. What if there are other regulator types that require a similar workaround?

When ret is -ENOSYS, it might be a fixed regulator. So directly use FIXED regulator check make more sense to me.

Regards,
Peng.

Quoted 2 lines

Sven

#8 lore raw

PATCH v2 1/1 regulator: Allow autosetting fixed regulators

Fixed regulators don't have a set_value method. Therefore, trying to set their value will always return -ENOSYS.

---
 drivers/power/regulator/regulator-uclass.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/power/regulator/regulator-uclass.c +3 -0
index 9118b8eb39..76be95bcd1 100644
@@ -238,6 +238,9 @@ int regulator_autoset(struct udevice *dev)
 	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 (!ret && (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UA))
Signature · 1 line
2.17.1
#9 lore raw

PATCH v2 1/1 regulator: Allow autosetting fixed regulators

Quoted 11 lines · Sven Schwermer

Fixed regulators don't have a set_value method. Therefore, trying to set their value will always return -ENOSYS.

---
 drivers/power/regulator/regulator-uclass.c | 3 +++
 1 file changed, 3 insertions(+)

It should be possible to create a simple test for this in test/dm/regulator.c

#10 lore raw

PATCH v2 1/1 regulator: Allow autosetting fixed regulators

In reply to Sven Schwermer
Quoted 7 lines · Sven Schwermer

Fixed regulators don't have a set_value method. Therefore, trying to set their value will always return -ENOSYS.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190714/8bf3a103/attachment.sig>