* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
@ 2019-05-31 7:27 Sven Schwermer
2019-05-31 7:49 ` Peng Fan
2019-05-31 9:34 ` Peng Fan
0 siblings, 2 replies; 11+ messages in thread
From: Sven Schwermer @ 2019-05-31 7:27 UTC (permalink / raw)
To: u-boot
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.
Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Peng Fan <peng.fan@nxp.com>
---
drivers/power/regulator/regulator-uclass.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 9118b8eb39..0b99c262ac 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -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;
--
2.17.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 7:27 [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators Sven Schwermer
@ 2019-05-31 7:49 ` Peng Fan
2019-05-31 8:17 ` Sven Schwermer
2019-05-31 9:34 ` Peng Fan
1 sibling, 1 reply; 11+ messages in thread
From: Peng Fan @ 2019-05-31 7:49 UTC (permalink / raw)
To: u-boot
Hi Sven,
> 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.
>
> Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> ---
> drivers/power/regulator/regulator-uclass.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/power/regulator/regulator-uclass.c
> b/drivers/power/regulator/regulator-uclass.c
> index 9118b8eb39..0b99c262ac 100644
> --- a/drivers/power/regulator/regulator-uclass.c
> +++ b/drivers/power/regulator/regulator-uclass.c
> @@ -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.
> ret = regulator_set_enable(dev, true);
>
> return ret;
> --
> 2.17.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 7:49 ` Peng Fan
@ 2019-05-31 8:17 ` Sven Schwermer
2019-05-31 8:23 ` Peng Fan
0 siblings, 1 reply; 11+ messages in thread
From: Sven Schwermer @ 2019-05-31 8:17 UTC (permalink / raw)
To: u-boot
Hi Peng,
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 8:17 ` Sven Schwermer
@ 2019-05-31 8:23 ` Peng Fan
2019-05-31 8:29 ` Sven Schwermer
0 siblings, 1 reply; 11+ messages in thread
From: Peng Fan @ 2019-05-31 8:23 UTC (permalink / raw)
To: u-boot
> Subject: Re: [PATCH] regulator: Allow autosetting fixed regulators
>
> Hi Peng,
>
> > 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;
For fixed regulator, will min_uV/max_uV be set to value other
than -ENODATA? I think no.
Regards,
Peng.
>
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 8:23 ` Peng Fan
@ 2019-05-31 8:29 ` Sven Schwermer
0 siblings, 0 replies; 11+ messages in thread
From: Sven Schwermer @ 2019-05-31 8:29 UTC (permalink / raw)
To: u-boot
> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 7:27 [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators Sven Schwermer
2019-05-31 7:49 ` Peng Fan
@ 2019-05-31 9:34 ` Peng Fan
2019-05-31 10:44 ` Sven Schwermer
1 sibling, 1 reply; 11+ messages in thread
From: Peng Fan @ 2019-05-31 9:34 UTC (permalink / raw)
To: u-boot
> 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.
>
> Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> ---
> drivers/power/regulator/regulator-uclass.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/power/regulator/regulator-uclass.c
> b/drivers/power/regulator/regulator-uclass.c
> index 9118b8eb39..0b99c262ac 100644
> --- a/drivers/power/regulator/regulator-uclass.c
> +++ b/drivers/power/regulator/regulator-uclass.c
> @@ -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
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 9118b8eb39..76be95bcd1 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -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.
>
> return ret;
> --
> 2.17.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 9:34 ` Peng Fan
@ 2019-05-31 10:44 ` Sven Schwermer
2019-06-04 2:34 ` Peng Fan
0 siblings, 1 reply; 11+ messages in thread
From: Sven Schwermer @ 2019-05-31 10:44 UTC (permalink / raw)
To: u-boot
> How about the following patch? not tested
>
> diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
> index 9118b8eb39..76be95bcd1 100644
> --- a/drivers/power/regulator/regulator-uclass.c
> +++ b/drivers/power/regulator/regulator-uclass.c
> @@ -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
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators
2019-05-31 10:44 ` Sven Schwermer
@ 2019-06-04 2:34 ` Peng Fan
2019-06-12 6:32 ` [U-Boot] [PATCH v2] " Sven Schwermer
0 siblings, 1 reply; 11+ messages in thread
From: Peng Fan @ 2019-06-04 2:34 UTC (permalink / raw)
To: u-boot
> -----Original Message-----
> From: Sven Schwermer [mailto:sven at svenschwermer.de]
> Sent: 2019年5月31日 18:44
> To: Peng Fan <peng.fan@nxp.com>
> Cc: u-boot at lists.denx.de; Jaehoon Chung <jh80.chung@samsung.com>
> Subject: Re: [PATCH] regulator: Allow autosetting fixed regulators
>
> > How about the following patch? not tested
> >
> > diff --git a/drivers/power/regulator/regulator-uclass.c
> b/drivers/power/regulator/regulator-uclass.c
> > index 9118b8eb39..76be95bcd1 100644
> > --- a/drivers/power/regulator/regulator-uclass.c
> > +++ b/drivers/power/regulator/regulator-uclass.c
> > @@ -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?
When ret is -ENOSYS, it might be a fixed regulator. So directly use FIXED
regulator check make more sense to me.
Regards,
Peng.
>
> Sven
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH v2] regulator: Allow autosetting fixed regulators
2019-06-04 2:34 ` Peng Fan
@ 2019-06-12 6:32 ` Sven Schwermer
2019-06-22 19:10 ` Simon Glass
2019-07-14 13:08 ` Tom Rini
0 siblings, 2 replies; 11+ messages in thread
From: Sven Schwermer @ 2019-06-12 6:32 UTC (permalink / raw)
To: u-boot
Fixed regulators don't have a set_value method. Therefore, trying to
set their value will always return -ENOSYS.
Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Peng Fan <peng.fan@nxp.com>
---
drivers/power/regulator/regulator-uclass.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/power/regulator/regulator-uclass.c b/drivers/power/regulator/regulator-uclass.c
index 9118b8eb39..76be95bcd1 100644
--- a/drivers/power/regulator/regulator-uclass.c
+++ b/drivers/power/regulator/regulator-uclass.c
@@ -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))
--
2.17.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH v2] regulator: Allow autosetting fixed regulators
2019-06-12 6:32 ` [U-Boot] [PATCH v2] " Sven Schwermer
@ 2019-06-22 19:10 ` Simon Glass
2019-07-14 13:08 ` Tom Rini
1 sibling, 0 replies; 11+ messages in thread
From: Simon Glass @ 2019-06-22 19:10 UTC (permalink / raw)
To: u-boot
On Wed, 12 Jun 2019 at 07:32, Sven Schwermer <sven@svenschwermer.de> wrote:
>
> Fixed regulators don't have a set_value method. Therefore, trying to
> set their value will always return -ENOSYS.
>
> Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> ---
> drivers/power/regulator/regulator-uclass.c | 3 +++
> 1 file changed, 3 insertions(+)
>
Reviewed-by: Simon Glass <sjg@chromium.org>
It should be possible to create a simple test for this in test/dm/regulator.c
^ permalink raw reply [flat|nested] 11+ messages in thread
* [U-Boot] [PATCH v2] regulator: Allow autosetting fixed regulators
2019-06-12 6:32 ` [U-Boot] [PATCH v2] " Sven Schwermer
2019-06-22 19:10 ` Simon Glass
@ 2019-07-14 13:08 ` Tom Rini
1 sibling, 0 replies; 11+ messages in thread
From: Tom Rini @ 2019-07-14 13:08 UTC (permalink / raw)
To: u-boot
On Wed, Jun 12, 2019 at 08:32:38AM +0200, Sven Schwermer wrote:
> Fixed regulators don't have a set_value method. Therefore, trying to
> set their value will always return -ENOSYS.
>
> Signed-off-by: Sven Schwermer <sven@svenschwermer.de>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>
Applied to u-boot/master, thanks!
--
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>
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2019-07-14 13:08 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31 7:27 [U-Boot] [PATCH] regulator: Allow autosetting fixed regulators Sven Schwermer
2019-05-31 7:49 ` Peng Fan
2019-05-31 8:17 ` Sven Schwermer
2019-05-31 8:23 ` Peng Fan
2019-05-31 8:29 ` Sven Schwermer
2019-05-31 9:34 ` Peng Fan
2019-05-31 10:44 ` Sven Schwermer
2019-06-04 2:34 ` Peng Fan
2019-06-12 6:32 ` [U-Boot] [PATCH v2] " Sven Schwermer
2019-06-22 19:10 ` Simon Glass
2019-07-14 13:08 ` Tom Rini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.