2013-09-09 10:28:53

by Wei Ni

[permalink] [raw]
Subject: [PATCH v3 0/2] Add power control for lm90

The device lm90 can be controlled by the vcc rail.
Add function to power on/off the vcc.

This series is v3, previous version patches are:
[v2]: http://www.spinics.net/lists/arm-kernel/msg265373.html
[v1]: http://www.mail-archive.com/[email protected]/msg12034.html

Changes from v2:
1. use devm_regulator_get_optional(), as suggested by Mark.
2. remove the lm90_power_control(), enable the regulator in the probe()
directly, so the codes are more clear, as suggested by Alexander and Guenter.
3. change the binding documentation, as per Stephen suggestion.
4. couple of changes, as per previous review.

Changes from v1:
1. if get regulator failed, we should continue to run probe function,
not return fail.
2. call regulator_put() in error handler and remove function.
3. add LM90 DT binding document.

Wei Ni (2):
hwmon: (lm90) Add power control
Documentation: dt: hwmon: add OF document for LM90

Documentation/devicetree/bindings/hwmon/lm90.txt | 44 ++++++++++++++++++++++
drivers/hwmon/lm90.c | 25 ++++++++++++
2 files changed, 69 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/lm90.txt

--
1.7.9.5


2013-09-09 10:29:15

by Wei Ni

[permalink] [raw]
Subject: [PATCH v3 1/2] hwmon: (lm90) Add power control

The device lm90 can be controlled by the vcc rail.
Adding the regulator support to power on/off the vcc rail.
Enable the "vcc" regulator before accessing the device.

Signed-off-by: Wei Ni <[email protected]>
---
drivers/hwmon/lm90.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)

diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index cdff742..bd313f4 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -89,6 +89,8 @@
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
+#include <linux/regulator/consumer.h>
+#include <linux/delay.h>

/*
* Addresses to scan
@@ -302,6 +304,7 @@ static const struct lm90_params lm90_params[] = {
struct lm90_data {
struct device *hwmon_dev;
struct mutex update_lock;
+ struct regulator *lm90_reg;
char valid; /* zero until following fields are valid */
unsigned long last_updated; /* in jiffies */
int kind;
@@ -1397,8 +1400,23 @@ static int lm90_probe(struct i2c_client *client,
struct device *dev = &client->dev;
struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
struct lm90_data *data;
+ struct regulator *reg;
int err;

+ reg = devm_regulator_get_optional(dev, "vcc");
+ if (!IS_ERR(reg)) {
+ err = regulator_enable(reg);
+ if (err < 0) {
+ dev_err(&client->dev,
+ "Failed to enable regulator: %d\n", err);
+ return err;
+ }
+ msleep(25);
+ } else {
+ if (PTR_ERR(reg) == -EPROBE_DEFER)
+ return -EPROBE_DEFER;
+ }
+
data = devm_kzalloc(&client->dev, sizeof(struct lm90_data), GFP_KERNEL);
if (!data)
return -ENOMEM;
@@ -1406,6 +1424,8 @@ static int lm90_probe(struct i2c_client *client,
i2c_set_clientdata(client, data);
mutex_init(&data->update_lock);

+ data->lm90_reg = reg;
+
/* Set the device type */
data->kind = id->driver_data;
if (data->kind == adm1032) {
@@ -1473,6 +1493,9 @@ exit_remove_files:
lm90_remove_files(client, data);
exit_restore:
lm90_restore_conf(client, data);
+ if (!IS_ERR(data->lm90_reg))
+ regulator_disable(data->lm90_reg);
+
return err;
}

@@ -1483,6 +1506,8 @@ static int lm90_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev);
lm90_remove_files(client, data);
lm90_restore_conf(client, data);
+ if (!IS_ERR(data->lm90_reg))
+ regulator_disable(data->lm90_reg);

return 0;
}
--
1.7.9.5

2013-09-09 10:29:18

by Wei Ni

[permalink] [raw]
Subject: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

Add OF document for LM90 in Documentation/devicetree/.

Signed-off-by: Wei Ni <[email protected]>
---
Documentation/devicetree/bindings/hwmon/lm90.txt | 44 ++++++++++++++++++++++
1 file changed, 44 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/lm90.txt

diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
new file mode 100644
index 0000000..5570875
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/lm90.txt
@@ -0,0 +1,44 @@
+* LM90 series thermometer.
+
+Required node properties:
+- compatible: manufacture and chip name, one of
+ "<manufacture>,adm1032"
+ "<manufacture>,adt7461"
+ "<manufacture>,adt7461a"
+ "<manufacture>,g781"
+ "<manufacture>,lm90"
+ "<manufacture>,lm86"
+ "<manufacture>,lm89"
+ "<manufacture>,lm99"
+ "<manufacture>,max6646"
+ "<manufacture>,max6647"
+ "<manufacture>,max6649"
+ "<manufacture>,max6657"
+ "<manufacture>,max6658"
+ "<manufacture>,max6659"
+ "<manufacture>,max6680"
+ "<manufacture>,max6681"
+ "<manufacture>,max6695"
+ "<manufacture>,max6696"
+ "<manufacture>,nct1008"
+ "<manufacture>,w83l771"
+ "<manufacture>,sa56004"
+
+- reg: I2C bus address of the device
+
+Optional properties:
+- vcc-supply: vcc regulator for the supply voltage.
+ If this is not set, assuming vdd is always powered.
+- interrupts: Contains a single interrupt specifier which describes the
+ LM90 pin6 output.
+ See interrupt-controller/interrupts.txt for the format.
+
+Example LM90 node:
+
+temp-sensor {
+ compatible = "onnn,nct1008";
+ reg = <0x4c>;
+ vcc-supply = <&palmas_ldo6_reg>;
+ interrupt-parent = <&gpio>;
+ interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
+}
--
1.7.9.5

2013-09-09 10:52:31

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/09/2013 03:29 AM, Wei Ni wrote:
> Add OF document for LM90 in Documentation/devicetree/.
>
> Signed-off-by: Wei Ni <[email protected]>
> ---
> Documentation/devicetree/bindings/hwmon/lm90.txt | 44 ++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/lm90.txt
>
> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
> new file mode 100644
> index 0000000..5570875
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/lm90.txt
> @@ -0,0 +1,44 @@
> +* LM90 series thermometer.
> +
> +Required node properties:
> +- compatible: manufacture and chip name, one of

manufacturer

> + "<manufacture>,adm1032"
> + "<manufacture>,adt7461"
> + "<manufacture>,adt7461a"
> + "<manufacture>,g781"
> + "<manufacture>,lm90"
> + "<manufacture>,lm86"
> + "<manufacture>,lm89"
> + "<manufacture>,lm99"
> + "<manufacture>,max6646"
> + "<manufacture>,max6647"
> + "<manufacture>,max6649"
> + "<manufacture>,max6657"
> + "<manufacture>,max6658"
> + "<manufacture>,max6659"
> + "<manufacture>,max6680"
> + "<manufacture>,max6681"
> + "<manufacture>,max6695"
> + "<manufacture>,max6696"
> + "<manufacture>,nct1008"
> + "<manufacture>,w83l771"
> + "<manufacture>,sa56004"
> +
Shouldn't the manufacturers be listed explicitly ?

> +- reg: I2C bus address of the device
> +
> +Optional properties:
> +- vcc-supply: vcc regulator for the supply voltage.
> + If this is not set, assuming vdd is always powered.

s/assuming/assume/

> +- interrupts: Contains a single interrupt specifier which describes the
> + LM90 pin6 output.
> + See interrupt-controller/interrupts.txt for the format.
> +
> +Example LM90 node:
> +
> +temp-sensor {
> + compatible = "onnn,nct1008";
> + reg = <0x4c>;
> + vcc-supply = <&palmas_ldo6_reg>;
> + interrupt-parent = <&gpio>;

List above as optional property.

> + interrupts = <TEGRA_GPIO(O, 4) IRQ_TYPE_LEVEL_LOW>;
> +}
>

2013-09-09 10:57:59

by Ramkumar Ramachandra

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

Wei Ni wrote:
> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
> new file mode 100644
> index 0000000..5570875
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/lm90.txt

While at it, please update and rename ads1015.txt.

> @@ -0,0 +1,44 @@
> +* LM90 series thermometer.
> +
> +Required node properties:
> +- compatible: manufacture and chip name, one of
> + "<manufacture>,adm1032"
> + "<manufacture>,adt7461"
> + "<manufacture>,adt7461a"
> + "<manufacture>,g781"
> + "<manufacture>,lm90"
> + "<manufacture>,lm86"
> + "<manufacture>,lm89"
> + "<manufacture>,lm99"

More versions of this of different ages are required.

> + "<manufacture>,max6646"
> + "<manufacture>,max6647"
> + "<manufacture>,max6649"
> + "<manufacture>,max6657"
> + "<manufacture>,max6658"
> + "<manufacture>,max6659"
> + "<manufacture>,max6680"
> + "<manufacture>,max6681"
> + "<manufacture>,max6695"
> + "<manufacture>,max6696"

SSDNow devices are required.

2013-09-09 11:13:39

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:

> + reg = devm_regulator_get_optional(dev, "vcc");
> + if (!IS_ERR(reg)) {
> + err = regulator_enable(reg);
> + if (err < 0) {
> + dev_err(&client->dev,
> + "Failed to enable regulator: %d\n", err);
> + return err;
> + }
> + msleep(25);
> + } else {
> + if (PTR_ERR(reg) == -EPROBE_DEFER)
> + return -EPROBE_DEFER;
> + }

This doesn't look good, it is going to ignore actual errors - I *really*
doubt that vcc is optional, it looks like it's the main power supply for
the device. You should use normal regulator_get(), _optional() is for
supplies which could physically not be provided in a system (eg, if the
device can generate them internally if required).

Also do you really need 25ms after power on?


Attachments:
(No filename) (778.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-09 11:34:47

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 04:12 AM, Mark Brown wrote:
> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>
>> + reg = devm_regulator_get_optional(dev, "vcc");
>> + if (!IS_ERR(reg)) {
>> + err = regulator_enable(reg);
>> + if (err < 0) {
>> + dev_err(&client->dev,
>> + "Failed to enable regulator: %d\n", err);
>> + return err;
>> + }
>> + msleep(25);
>> + } else {
>> + if (PTR_ERR(reg) == -EPROBE_DEFER)
>> + return -EPROBE_DEFER;
>> + }
>
> This doesn't look good, it is going to ignore actual errors - I *really*
> doubt that vcc is optional, it looks like it's the main power supply for
> the device. You should use normal regulator_get(), _optional() is for
> supplies which could physically not be provided in a system (eg, if the
> device can generate them internally if required).
>
Then he'll have to make sure that all devicetree files in the system contain references
to this regulator.

> Also do you really need 25ms after power on?
>
I had not noticed, but I recommend to reject the patch because of it. If we add 25ms delay to each driver,
booting the system will take as long as booting windows. If enabling the regulator needs time,
the regulator subsystem should do it.

Guenter

2013-09-09 13:50:37

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
> On 09/09/2013 04:12 AM, Mark Brown wrote:
> >On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:

> >This doesn't look good, it is going to ignore actual errors - I *really*
> >doubt that vcc is optional, it looks like it's the main power supply for
> >the device. You should use normal regulator_get(), _optional() is for
> >supplies which could physically not be provided in a system (eg, if the
> >device can generate them internally if required).

> Then he'll have to make sure that all devicetree files in the system
> contain references to this regulator.

Or get the patches applied on top of the code that'll be going in this
cycle implementing get_optional() properly - when that's done the
default will be to provide a dummy supply for regulator_get(). If you
ack the patch I'd be happy to carry it.

> >Also do you really need 25ms after power on?

> I had not noticed, but I recommend to reject the patch because of it.
> If we add 25ms delay to each driver, booting the system will take as
> long as booting windows. If enabling the regulator needs time, the
> regulator subsystem should do it.

And indeed it does this (well, it does whatever the driver says in terms
of delay). However it is possible that the lm90 needs this time for
itself - if it's doing some sort of initialisation or callibration
sequence then that'll happen after the supplies come up. 25ms did seem
rather long, especially for such simple devices, but it's not beyond the
bounds of possibility.


Attachments:
(No filename) (1.52 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-09 15:50:49

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
> > On 09/09/2013 04:12 AM, Mark Brown wrote:
> > >On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>
> > >This doesn't look good, it is going to ignore actual errors - I *really*
> > >doubt that vcc is optional, it looks like it's the main power supply for
> > >the device. You should use normal regulator_get(), _optional() is for
> > >supplies which could physically not be provided in a system (eg, if the
> > >device can generate them internally if required).
>
> > Then he'll have to make sure that all devicetree files in the system
> > contain references to this regulator.
>
> Or get the patches applied on top of the code that'll be going in this
> cycle implementing get_optional() properly - when that's done the
> default will be to provide a dummy supply for regulator_get(). If you
> ack the patch I'd be happy to carry it.
>
Jean will have to ack it.

> > >Also do you really need 25ms after power on?
>
> > I had not noticed, but I recommend to reject the patch because of it.
> > If we add 25ms delay to each driver, booting the system will take as
> > long as booting windows. If enabling the regulator needs time, the
> > regulator subsystem should do it.
>
> And indeed it does this (well, it does whatever the driver says in terms
> of delay). However it is possible that the lm90 needs this time for
> itself - if it's doing some sort of initialisation or callibration
> sequence then that'll happen after the supplies come up. 25ms did seem
> rather long, especially for such simple devices, but it's not beyond the
> bounds of possibility.

Even then it would be unreasonable to enforce such a delay for every instance
of this driver, even if the regulator is a dummy one and/or has been enabled
already. Many if not almost all users of the driver work just fine as-is,
without additional enforced delay (and, for that matter, without regulator ;).

If there is a delay, it would have to be optional: Only wait if the regulator
was really turned on by the call and not already active. I don't know if the
regulator subsystem has this capability; if not, maybe it should.

On a higher level, I wonder if such functionality should be added in the i2c
subsystem and not in i2c client drivers. Has anyone thought about this ?

Guenter

2013-09-09 16:03:38

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 08:50:43AM -0700, Guenter Roeck wrote:
> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:

> > And indeed it does this (well, it does whatever the driver says in terms
> > of delay). However it is possible that the lm90 needs this time for
> > itself - if it's doing some sort of initialisation or callibration
> > sequence then that'll happen after the supplies come up. 25ms did seem
> > rather long, especially for such simple devices, but it's not beyond the
> > bounds of possibility.

> Even then it would be unreasonable to enforce such a delay for every instance
> of this driver, even if the regulator is a dummy one and/or has been enabled
> already. Many if not almost all users of the driver work just fine as-is,
> without additional enforced delay (and, for that matter, without regulator ;).

> If there is a delay, it would have to be optional: Only wait if the regulator
> was really turned on by the call and not already active. I don't know if the
> regulator subsystem has this capability; if not, maybe it should.

It does, though it gets complicated trying to use it for a case like
this since you can't really tell if the regulator was powered on
immediately before the device got probed by another device on the bus.

> On a higher level, I wonder if such functionality should be added in the i2c
> subsystem and not in i2c client drivers. Has anyone thought about this ?

I'm not sure what the subsystem would do for such delays? It's fairly
common for things that need this to also want to do things like
manipulate GPIOs as part of the power on sequence so the applicability
is relatively limited, plus it's not even I2C specific, the same applies
to other buses so it ought to be a driver core thing.

There was some work on a generic helper for power on sequences but it
stalled since it wasn't accepted for the original purpose (LCD panel
power ons IIRC).


Attachments:
(No filename) (1.88 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-09 16:17:41

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
> On Mon, Sep 09, 2013 at 08:50:43AM -0700, Guenter Roeck wrote:
> > On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>
> > > And indeed it does this (well, it does whatever the driver says in terms
> > > of delay). However it is possible that the lm90 needs this time for
> > > itself - if it's doing some sort of initialisation or callibration
> > > sequence then that'll happen after the supplies come up. 25ms did seem
> > > rather long, especially for such simple devices, but it's not beyond the
> > > bounds of possibility.
>
> > Even then it would be unreasonable to enforce such a delay for every instance
> > of this driver, even if the regulator is a dummy one and/or has been enabled
> > already. Many if not almost all users of the driver work just fine as-is,
> > without additional enforced delay (and, for that matter, without regulator ;).
>
> > If there is a delay, it would have to be optional: Only wait if the regulator
> > was really turned on by the call and not already active. I don't know if the
> > regulator subsystem has this capability; if not, maybe it should.
>
> It does, though it gets complicated trying to use it for a case like
> this since you can't really tell if the regulator was powered on
> immediately before the device got probed by another device on the bus.
>
Why not ? Just keep a timestamp.

> > On a higher level, I wonder if such functionality should be added in the i2c
> > subsystem and not in i2c client drivers. Has anyone thought about this ?
>
> I'm not sure what the subsystem would do for such delays? It's fairly
> common for things that need this to also want to do things like
> manipulate GPIOs as part of the power on sequence so the applicability
> is relatively limited, plus it's not even I2C specific, the same applies
> to other buses so it ought to be a driver core thing.
>
Possibly. I just thought about i2c since it also takes care of basic
devicetree bindings. Something along the line of
if devicetree bindings for this device declare one or more
regulators, enable those regulators before calling the driver
probe function.

That was not intended to solve the delay problem, though. The delay problem
seems to be more of a generic regulator problem and, as I suggested, should
be solved in the regulator subsystem.
if the regulator is enabled and the device specifies a poweron delay,
wait for the specified amount of time after (and only after) enabling
the regulator.

> There was some work on a generic helper for power on sequences but it
> stalled since it wasn't accepted for the original purpose (LCD panel
> power ons IIRC).

Too bad. I think it could be kept quite simple, though, by handling it
through the regulator subsystem as suggested above. A generic binding
for a per-regulator and per-device poweron delay should solve that
and possibly even make it transparent to the actual driver code.

Guenter

2013-09-09 20:40:05

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:

> > It does, though it gets complicated trying to use it for a case like
> > this since you can't really tell if the regulator was powered on
> > immediately before the device got probed by another device on the bus.

> Why not ? Just keep a timestamp.

The support is a callback on state changes; we could keep a timestamp
but there's still going to be race conditions around bootloaders. It's
doable though.

> > > On a higher level, I wonder if such functionality should be added in the i2c
> > > subsystem and not in i2c client drivers. Has anyone thought about this ?

> > I'm not sure what the subsystem would do for such delays? It's fairly
> > common for things that need this to also want to do things like
> > manipulate GPIOs as part of the power on sequence so the applicability
> > is relatively limited, plus it's not even I2C specific, the same applies
> > to other buses so it ought to be a driver core thing.

> Possibly. I just thought about i2c since it also takes care of basic
> devicetree bindings. Something along the line of
> if devicetree bindings for this device declare one or more
> regulators, enable those regulators before calling the driver
> probe function.

That's definitely a driver core thing, not I2C - there's nothing
specific to I2C in there at all, needing power is pretty generic. I
have considered this before, something along the lines of what we have
for pinctrl, but unfortunately the generic case isn't quite generic
enough to make it easy. It'd need to be an explicit list of regulators
(partly just to make it opt in and avoid breaking things) and you'd want
to have a way of handling the different suspend/resume behaviour that
devices want. There's a few patterns there.

It's definitely something I think about from time to time and it would
be useful to factor things out, the issue is getting a good enough model
of what's going on.

> > There was some work on a generic helper for power on sequences but it
> > stalled since it wasn't accepted for the original purpose (LCD panel
> > power ons IIRC).

> Too bad. I think it could be kept quite simple, though, by handling it
> through the regulator subsystem as suggested above. A generic binding
> for a per-regulator and per-device poweron delay should solve that
> and possibly even make it transparent to the actual driver code.

Lots of things have a GPIO for reset too, and some want clocks too. For
maximum usefulness this should be cross subsystem. I suspect the reset
controller API may be able to handle some of it.

The regulator power on delays are already handled transparently, by the
time regulator_enable() returns the ramp should be finished.


Attachments:
(No filename) (2.74 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-09 22:14:48

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/09/2013 04:52 AM, Guenter Roeck wrote:
> On 09/09/2013 03:29 AM, Wei Ni wrote:
>> Add OF document for LM90 in Documentation/devicetree/.

>> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt

>> +* LM90 series thermometer.
>> +
>> +Required node properties:
>> +- compatible: manufacture and chip name, one of
>
> manufacturer
>
>> + "<manufacture>,adm1032"
...
>> + "<manufacture>,sa56004"
>
> Shouldn't the manufacturers be listed explicitly ?

Yes, and they must all be present in
Documentation/devicetree/bindings/vendor-prefixes.txt.

>> +Example LM90 node:
>> +
>> +temp-sensor {
>> + compatible = "onnn,nct1008";
>> + reg = <0x4c>;
>> + vcc-supply = <&palmas_ldo6_reg>;
>> + interrupt-parent = <&gpio>;
>
> List above as optional property.

I believe it's common not to document this, since it's implicitly
supported as part of any node that is an interrupt source.

2013-09-09 22:16:01

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/09/2013 04:29 AM, Wei Ni wrote:
> Add OF document for LM90 in Documentation/devicetree/.

> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt
> b/Documentation/devicetree/bindings/hwmon/lm90.txt

> +Optional properties:

> +- interrupts: Contains a single interrupt specifier which
> describes the + LM90 pin6 output.

Does the pin also have a standard name you could include here, rather
than (or in addition to) just the pin number?

2013-09-09 22:23:35

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On Mon, Sep 09, 2013 at 04:15:57PM -0600, Stephen Warren wrote:
> On 09/09/2013 04:29 AM, Wei Ni wrote:
> > Add OF document for LM90 in Documentation/devicetree/.
>
> > diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt
> > b/Documentation/devicetree/bindings/hwmon/lm90.txt
>
> > +Optional properties:
>
> > +- interrupts: Contains a single interrupt specifier which
> > describes the + LM90 pin6 output.
>
> Does the pin also have a standard name you could include here, rather
> than (or in addition to) just the pin number?
>
This is the "ALERT" pin (or maybe "-ALERT" to reflect that it is low-active).

Guenter

2013-09-10 03:21:33

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 11:50 PM, Guenter Roeck wrote:
> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
>>> On 09/09/2013 04:12 AM, Mark Brown wrote:
>>>> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>>
>>>> This doesn't look good, it is going to ignore actual errors - I *really*
>>>> doubt that vcc is optional, it looks like it's the main power supply for
>>>> the device. You should use normal regulator_get(), _optional() is for
>>>> supplies which could physically not be provided in a system (eg, if the
>>>> device can generate them internally if required).
>>
>>> Then he'll have to make sure that all devicetree files in the system
>>> contain references to this regulator.
>>
>> Or get the patches applied on top of the code that'll be going in this
>> cycle implementing get_optional() properly - when that's done the
>> default will be to provide a dummy supply for regulator_get(). If you
>> ack the patch I'd be happy to carry it.
>>
> Jean will have to ack it.
>
I think it's better to use get_optional(), and ignore the errors except
-EPROBE_DEFER. Because many platform may always power on this device,
and will not provide regulator for it, so if we get errors from
regulator subsystem and return it directly, then the probe() can't be
implemented, this driver can't work properly, even though it can work
without regulator support.
Mark, do you mean you have patches for regulator_get_optional() and
regulator_get()?

Wei.

2013-09-10 03:36:58

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 08:22 PM, Wei Ni wrote:
> On 09/09/2013 11:50 PM, Guenter Roeck wrote:
>> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>>> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
>>>> On 09/09/2013 04:12 AM, Mark Brown wrote:
>>>>> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>>>
>>>>> This doesn't look good, it is going to ignore actual errors - I *really*
>>>>> doubt that vcc is optional, it looks like it's the main power supply for
>>>>> the device. You should use normal regulator_get(), _optional() is for
>>>>> supplies which could physically not be provided in a system (eg, if the
>>>>> device can generate them internally if required).
>>>
>>>> Then he'll have to make sure that all devicetree files in the system
>>>> contain references to this regulator.
>>>
>>> Or get the patches applied on top of the code that'll be going in this
>>> cycle implementing get_optional() properly - when that's done the
>>> default will be to provide a dummy supply for regulator_get(). If you
>>> ack the patch I'd be happy to carry it.
>>>
>> Jean will have to ack it.
>>
> I think it's better to use get_optional(), and ignore the errors except
> -EPROBE_DEFER. Because many platform may always power on this device,
> and will not provide regulator for it, so if we get errors from
> regulator subsystem and return it directly, then the probe() can't be
> implemented, this driver can't work properly, even though it can work
> without regulator support.
> Mark, do you mean you have patches for regulator_get_optional() and
> regulator_get()?
>

My understanding is that by adding regulator support you essentially
committed to adding regulators (if necessary dummy ones) for this driver
to all those platforms. This is quite similar to other drivers in the
same situation. Once you start along that route, you'll have to go it
all the way.

Guenter

2013-09-10 03:40:35

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 09:36 PM, Guenter Roeck wrote:
> On 09/09/2013 08:22 PM, Wei Ni wrote:
>> On 09/09/2013 11:50 PM, Guenter Roeck wrote:
>>> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>>>> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
>>>>> On 09/09/2013 04:12 AM, Mark Brown wrote:
>>>>>> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>>>>
>>>>>> This doesn't look good, it is going to ignore actual errors - I
>>>>>> *really*
>>>>>> doubt that vcc is optional, it looks like it's the main power
>>>>>> supply for
>>>>>> the device. You should use normal regulator_get(), _optional() is
>>>>>> for
>>>>>> supplies which could physically not be provided in a system (eg,
>>>>>> if the
>>>>>> device can generate them internally if required).
>>>>
>>>>> Then he'll have to make sure that all devicetree files in the system
>>>>> contain references to this regulator.
>>>>
>>>> Or get the patches applied on top of the code that'll be going in this
>>>> cycle implementing get_optional() properly - when that's done the
>>>> default will be to provide a dummy supply for regulator_get(). If you
>>>> ack the patch I'd be happy to carry it.
>>>>
>>> Jean will have to ack it.
>>>
>> I think it's better to use get_optional(), and ignore the errors except
>> -EPROBE_DEFER. Because many platform may always power on this device,
>> and will not provide regulator for it, so if we get errors from
>> regulator subsystem and return it directly, then the probe() can't be
>> implemented, this driver can't work properly, even though it can work
>> without regulator support.
>> Mark, do you mean you have patches for regulator_get_optional() and
>> regulator_get()?
>>
>
> My understanding is that by adding regulator support you essentially
> committed to adding regulators (if necessary dummy ones) for this driver
> to all those platforms. This is quite similar to other drivers in the
> same situation. Once you start along that route, you'll have to go it
> all the way.

By using regulator_get_optional(), the regulator should be optional,
hence you only have to add it to platforms that need it.

2013-09-10 03:53:55

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 08:40 PM, Stephen Warren wrote:
> On 09/09/2013 09:36 PM, Guenter Roeck wrote:
>> On 09/09/2013 08:22 PM, Wei Ni wrote:
>>> On 09/09/2013 11:50 PM, Guenter Roeck wrote:
>>>> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>>>>> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
>>>>>> On 09/09/2013 04:12 AM, Mark Brown wrote:
>>>>>>> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>>>>>
>>>>>>> This doesn't look good, it is going to ignore actual errors - I
>>>>>>> *really*
>>>>>>> doubt that vcc is optional, it looks like it's the main power
>>>>>>> supply for
>>>>>>> the device. You should use normal regulator_get(), _optional() is
>>>>>>> for
>>>>>>> supplies which could physically not be provided in a system (eg,
>>>>>>> if the
>>>>>>> device can generate them internally if required).
>>>>>
>>>>>> Then he'll have to make sure that all devicetree files in the system
>>>>>> contain references to this regulator.
>>>>>
>>>>> Or get the patches applied on top of the code that'll be going in this
>>>>> cycle implementing get_optional() properly - when that's done the
>>>>> default will be to provide a dummy supply for regulator_get(). If you
>>>>> ack the patch I'd be happy to carry it.
>>>>>
>>>> Jean will have to ack it.
>>>>
>>> I think it's better to use get_optional(), and ignore the errors except
>>> -EPROBE_DEFER. Because many platform may always power on this device,
>>> and will not provide regulator for it, so if we get errors from
>>> regulator subsystem and return it directly, then the probe() can't be
>>> implemented, this driver can't work properly, even though it can work
>>> without regulator support.
>>> Mark, do you mean you have patches for regulator_get_optional() and
>>> regulator_get()?
>>>
>>
>> My understanding is that by adding regulator support you essentially
>> committed to adding regulators (if necessary dummy ones) for this driver
>> to all those platforms. This is quite similar to other drivers in the
>> same situation. Once you start along that route, you'll have to go it
>> all the way.
>
> By using regulator_get_optional(), the regulator should be optional,
> hence you only have to add it to platforms that need it.
>

Earlier comments suggest that this is not the intended use case for
regulator_get_optional().

Guenter

2013-09-10 04:04:43

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 04:39 AM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
>> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
>
>>> It does, though it gets complicated trying to use it for a case like
>>> this since you can't really tell if the regulator was powered on
>>> immediately before the device got probed by another device on the bus.
>
>> Why not ? Just keep a timestamp.
>
> The support is a callback on state changes; we could keep a timestamp
> but there's still going to be race conditions around bootloaders. It's
> doable though.
>
>>>> On a higher level, I wonder if such functionality should be added in the i2c
>>>> subsystem and not in i2c client drivers. Has anyone thought about this ?
>
>>> I'm not sure what the subsystem would do for such delays? It's fairly
>>> common for things that need this to also want to do things like
>>> manipulate GPIOs as part of the power on sequence so the applicability
>>> is relatively limited, plus it's not even I2C specific, the same applies
>>> to other buses so it ought to be a driver core thing.
>
>> Possibly. I just thought about i2c since it also takes care of basic
>> devicetree bindings. Something along the line of
>> if devicetree bindings for this device declare one or more
>> regulators, enable those regulators before calling the driver
>> probe function.
>
> That's definitely a driver core thing, not I2C - there's nothing
> specific to I2C in there at all, needing power is pretty generic. I
> have considered this before, something along the lines of what we have
> for pinctrl, but unfortunately the generic case isn't quite generic
> enough to make it easy. It'd need to be an explicit list of regulators
> (partly just to make it opt in and avoid breaking things) and you'd want
> to have a way of handling the different suspend/resume behaviour that
> devices want. There's a few patterns there.
>
> It's definitely something I think about from time to time and it would
> be useful to factor things out, the issue is getting a good enough model
> of what's going on.
>
>>> There was some work on a generic helper for power on sequences but it
>>> stalled since it wasn't accepted for the original purpose (LCD panel
>>> power ons IIRC).
>
>> Too bad. I think it could be kept quite simple, though, by handling it
>> through the regulator subsystem as suggested above. A generic binding
>> for a per-regulator and per-device poweron delay should solve that
>> and possibly even make it transparent to the actual driver code.
>
> Lots of things have a GPIO for reset too, and some want clocks too. For
> maximum usefulness this should be cross subsystem. I suspect the reset
> controller API may be able to handle some of it.
>
> The regulator power on delays are already handled transparently, by the
> time regulator_enable() returns the ramp should be finished.

I think the regulator should encoded its own startup delay. Each
individual device should handle its own requirements for delay after
power is stable.
The regulator_enable() will handle the delays for the regulator device.
And adding the msleep(25) is for lm90 device. If without delay,
sometimes the device can't work properly. If read lm90 register
immediately after enabling regulator, the reading may be failed.
I'm not sure if 25ms is the right value, I read the LM90 SPEC, the max
of "SMBus Clock Low Time" is 25ms, so I supposed that it may need about
25ms to stable after power on.

Thanks.
Wei.

>
> * Unknown Key
> * 0x7EA229BD
>

2013-09-10 04:12:06

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 11:53 AM, Guenter Roeck wrote:
> On 09/09/2013 08:40 PM, Stephen Warren wrote:
>> On 09/09/2013 09:36 PM, Guenter Roeck wrote:
>>> On 09/09/2013 08:22 PM, Wei Ni wrote:
>>>> On 09/09/2013 11:50 PM, Guenter Roeck wrote:
>>>>> On Mon, Sep 09, 2013 at 02:50:22PM +0100, Mark Brown wrote:
>>>>>> On Mon, Sep 09, 2013 at 04:34:43AM -0700, Guenter Roeck wrote:
>>>>>>> On 09/09/2013 04:12 AM, Mark Brown wrote:
>>>>>>>> On Mon, Sep 09, 2013 at 06:29:11PM +0800, Wei Ni wrote:
>>>>>>
>>>>>>>> This doesn't look good, it is going to ignore actual errors - I
>>>>>>>> *really*
>>>>>>>> doubt that vcc is optional, it looks like it's the main power
>>>>>>>> supply for
>>>>>>>> the device. You should use normal regulator_get(), _optional() is
>>>>>>>> for
>>>>>>>> supplies which could physically not be provided in a system (eg,
>>>>>>>> if the
>>>>>>>> device can generate them internally if required).
>>>>>>
>>>>>>> Then he'll have to make sure that all devicetree files in the system
>>>>>>> contain references to this regulator.
>>>>>>
>>>>>> Or get the patches applied on top of the code that'll be going in this
>>>>>> cycle implementing get_optional() properly - when that's done the
>>>>>> default will be to provide a dummy supply for regulator_get(). If you
>>>>>> ack the patch I'd be happy to carry it.
>>>>>>
>>>>> Jean will have to ack it.
>>>>>
>>>> I think it's better to use get_optional(), and ignore the errors except
>>>> -EPROBE_DEFER. Because many platform may always power on this device,
>>>> and will not provide regulator for it, so if we get errors from
>>>> regulator subsystem and return it directly, then the probe() can't be
>>>> implemented, this driver can't work properly, even though it can work
>>>> without regulator support.
>>>> Mark, do you mean you have patches for regulator_get_optional() and
>>>> regulator_get()?
>>>>
>>>
>>> My understanding is that by adding regulator support you essentially
>>> committed to adding regulators (if necessary dummy ones) for this driver
>>> to all those platforms. This is quite similar to other drivers in the
>>> same situation. Once you start along that route, you'll have to go it
>>> all the way.
>>
>> By using regulator_get_optional(), the regulator should be optional,
>> hence you only have to add it to platforms that need it.
>>
>
> Earlier comments suggest that this is not the intended use case for
> regulator_get_optional().

So I just need to use the regulator_get() instead, is it right?

>
> Guenter
>

2013-09-10 04:14:00

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 09:53 PM, Guenter Roeck wrote:
> On 09/09/2013 08:40 PM, Stephen Warren wrote:
>> On 09/09/2013 09:36 PM, Guenter Roeck wrote:
...
>>> My understanding is that by adding regulator support you essentially
>>> committed to adding regulators (if necessary dummy ones) for this driver
>>> to all those platforms. This is quite similar to other drivers in the
>>> same situation. Once you start along that route, you'll have to go it
>>> all the way.
>>
>> By using regulator_get_optional(), the regulator should be optional,
>> hence you only have to add it to platforms that need it.
>>
>
> Earlier comments suggest that this is not the intended use case for
> regulator_get_optional().

Isn't the issue only whether the optional aspect of the regulator is
implemented by:

a) regulator_get_optional() returning failure, then the driver having to
check for that and either using or not-using the regulator.

b) regulator_get_optional() returning a dummy regulator automatically
when none is specified in DT or the regulator lookup table, and hence
the driver can always call regulator_enable/disable on the returned value.

2013-09-10 04:24:50

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/10/2013 06:14 AM, Stephen Warren wrote:
> On 09/09/2013 04:52 AM, Guenter Roeck wrote:
>> On 09/09/2013 03:29 AM, Wei Ni wrote:
>>> Add OF document for LM90 in Documentation/devicetree/.
>
>>> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt
>
>>> +* LM90 series thermometer.
>>> +
>>> +Required node properties:
>>> +- compatible: manufacture and chip name, one of
>>
>> manufacturer
>>
>>> + "<manufacture>,adm1032"
> ...
>>> + "<manufacture>,sa56004"
>>
>> Shouldn't the manufacturers be listed explicitly ?
>
> Yes, and they must all be present in
> Documentation/devicetree/bindings/vendor-prefixes.txt.

Oh, got it, I will update it, thanks.

>
>>> +Example LM90 node:
>>> +
>>> +temp-sensor {
>>> + compatible = "onnn,nct1008";
>>> + reg = <0x4c>;
>>> + vcc-supply = <&palmas_ldo6_reg>;
>>> + interrupt-parent = <&gpio>;
>>
>> List above as optional property.
>
> I believe it's common not to document this, since it's implicitly
> supported as part of any node that is an interrupt source.
>

2013-09-10 04:25:10

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/10/2013 06:23 AM, Guenter Roeck wrote:
> On Mon, Sep 09, 2013 at 04:15:57PM -0600, Stephen Warren wrote:
>> On 09/09/2013 04:29 AM, Wei Ni wrote:
>>> Add OF document for LM90 in Documentation/devicetree/.
>>
>>> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt
>>> b/Documentation/devicetree/bindings/hwmon/lm90.txt
>>
>>> +Optional properties:
>>
>>> +- interrupts: Contains a single interrupt specifier which
>>> describes the + LM90 pin6 output.
>>
>> Does the pin also have a standard name you could include here, rather
>> than (or in addition to) just the pin number?
>>
> This is the "ALERT" pin (or maybe "-ALERT" to reflect that it is low-active).

Thanks, Guenter, I will update it.
>
> Guenter
>

2013-09-10 04:34:20

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/09/2013 06:57 PM, Ramkumar Ramachandra wrote:
> Wei Ni wrote:
>> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
>> new file mode 100644
>> index 0000000..5570875
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/hwmon/lm90.txt
>
> While at it, please update and rename ads1015.txt.

This series is for lm90 compatible devices, it seems ads1015 is not
register-compatible with lm90.

>
>> @@ -0,0 +1,44 @@
>> +* LM90 series thermometer.
>> +
>> +Required node properties:
>> +- compatible: manufacture and chip name, one of
>> + "<manufacture>,adm1032"
>> + "<manufacture>,adt7461"
>> + "<manufacture>,adt7461a"
>> + "<manufacture>,g781"
>> + "<manufacture>,lm90"
>> + "<manufacture>,lm86"
>> + "<manufacture>,lm89"
>> + "<manufacture>,lm99"
>
> More versions of this of different ages are required.

In here, the chip names, such as "lm99", come from lm90.c id_table, the
i2c subsystem want to use it to load driver, so we can add any other names.

>
>> + "<manufacture>,max6646"
>> + "<manufacture>,max6647"
>> + "<manufacture>,max6649"
>> + "<manufacture>,max6657"
>> + "<manufacture>,max6658"
>> + "<manufacture>,max6659"
>> + "<manufacture>,max6680"
>> + "<manufacture>,max6681"
>> + "<manufacture>,max6695"
>> + "<manufacture>,max6696"
>
> SSDNow devices are required.
What's the SSDNow device? It seems the lm90.c doesn't support it.

Thanks.
Wei.

>

2013-09-10 04:35:50

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 2/2] Documentation: dt: hwmon: add OF document for LM90

On 09/10/2013 12:35 PM, Wei Ni wrote:
> On 09/09/2013 06:57 PM, Ramkumar Ramachandra wrote:
>> Wei Ni wrote:
>>> diff --git a/Documentation/devicetree/bindings/hwmon/lm90.txt b/Documentation/devicetree/bindings/hwmon/lm90.txt
>>> new file mode 100644
>>> index 0000000..5570875
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/hwmon/lm90.txt
>>
>> While at it, please update and rename ads1015.txt.
>
> This series is for lm90 compatible devices, it seems ads1015 is not
> register-compatible with lm90.
>
>>
>>> @@ -0,0 +1,44 @@
>>> +* LM90 series thermometer.
>>> +
>>> +Required node properties:
>>> +- compatible: manufacture and chip name, one of
>>> + "<manufacture>,adm1032"
>>> + "<manufacture>,adt7461"
>>> + "<manufacture>,adt7461a"
>>> + "<manufacture>,g781"
>>> + "<manufacture>,lm90"
>>> + "<manufacture>,lm86"
>>> + "<manufacture>,lm89"
>>> + "<manufacture>,lm99"
>>
>> More versions of this of different ages are required.
>
> In here, the chip names, such as "lm99", come from lm90.c id_table, the
> i2c subsystem want to use it to load driver, so we can add any other names.

Sorry, it's typo, it should be "can't add any other names".

>
>>
>>> + "<manufacture>,max6646"
>>> + "<manufacture>,max6647"
>>> + "<manufacture>,max6649"
>>> + "<manufacture>,max6657"
>>> + "<manufacture>,max6658"
>>> + "<manufacture>,max6659"
>>> + "<manufacture>,max6680"
>>> + "<manufacture>,max6681"
>>> + "<manufacture>,max6695"
>>> + "<manufacture>,max6696"
>>
>> SSDNow devices are required.
> What's the SSDNow device? It seems the lm90.c doesn't support it.
>
> Thanks.
> Wei.
>
>>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2013-09-10 04:44:28

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 09:13 PM, Stephen Warren wrote:
> On 09/09/2013 09:53 PM, Guenter Roeck wrote:
>> On 09/09/2013 08:40 PM, Stephen Warren wrote:
>>> On 09/09/2013 09:36 PM, Guenter Roeck wrote:
> ...
>>>> My understanding is that by adding regulator support you essentially
>>>> committed to adding regulators (if necessary dummy ones) for this driver
>>>> to all those platforms. This is quite similar to other drivers in the
>>>> same situation. Once you start along that route, you'll have to go it
>>>> all the way.
>>>
>>> By using regulator_get_optional(), the regulator should be optional,
>>> hence you only have to add it to platforms that need it.
>>>
>>
>> Earlier comments suggest that this is not the intended use case for
>> regulator_get_optional().
>
> Isn't the issue only whether the optional aspect of the regulator is
> implemented by:
>
> a) regulator_get_optional() returning failure, then the driver having to
> check for that and either using or not-using the regulator.
>
> b) regulator_get_optional() returning a dummy regulator automatically
> when none is specified in DT or the regulator lookup table, and hence
> the driver can always call regulator_enable/disable on the returned value.
>

I don't know. The regulator folks would have to answer that.

Guenter

2013-09-10 04:50:42

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 09:05 PM, Wei Ni wrote:
> On 09/10/2013 04:39 AM, Mark Brown wrote:
>> * PGP Signed by an unknown key
>>
>> On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
>>> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
>>
>>>> It does, though it gets complicated trying to use it for a case like
>>>> this since you can't really tell if the regulator was powered on
>>>> immediately before the device got probed by another device on the bus.
>>
>>> Why not ? Just keep a timestamp.
>>
>> The support is a callback on state changes; we could keep a timestamp
>> but there's still going to be race conditions around bootloaders. It's
>> doable though.
>>
>>>>> On a higher level, I wonder if such functionality should be added in the i2c
>>>>> subsystem and not in i2c client drivers. Has anyone thought about this ?
>>
>>>> I'm not sure what the subsystem would do for such delays? It's fairly
>>>> common for things that need this to also want to do things like
>>>> manipulate GPIOs as part of the power on sequence so the applicability
>>>> is relatively limited, plus it's not even I2C specific, the same applies
>>>> to other buses so it ought to be a driver core thing.
>>
>>> Possibly. I just thought about i2c since it also takes care of basic
>>> devicetree bindings. Something along the line of
>>> if devicetree bindings for this device declare one or more
>>> regulators, enable those regulators before calling the driver
>>> probe function.
>>
>> That's definitely a driver core thing, not I2C - there's nothing
>> specific to I2C in there at all, needing power is pretty generic. I
>> have considered this before, something along the lines of what we have
>> for pinctrl, but unfortunately the generic case isn't quite generic
>> enough to make it easy. It'd need to be an explicit list of regulators
>> (partly just to make it opt in and avoid breaking things) and you'd want
>> to have a way of handling the different suspend/resume behaviour that
>> devices want. There's a few patterns there.
>>
>> It's definitely something I think about from time to time and it would
>> be useful to factor things out, the issue is getting a good enough model
>> of what's going on.
>>
>>>> There was some work on a generic helper for power on sequences but it
>>>> stalled since it wasn't accepted for the original purpose (LCD panel
>>>> power ons IIRC).
>>
>>> Too bad. I think it could be kept quite simple, though, by handling it
>>> through the regulator subsystem as suggested above. A generic binding
>>> for a per-regulator and per-device poweron delay should solve that
>>> and possibly even make it transparent to the actual driver code.
>>
>> Lots of things have a GPIO for reset too, and some want clocks too. For
>> maximum usefulness this should be cross subsystem. I suspect the reset
>> controller API may be able to handle some of it.
>>
>> The regulator power on delays are already handled transparently, by the
>> time regulator_enable() returns the ramp should be finished.
>
> I think the regulator should encoded its own startup delay. Each
> individual device should handle its own requirements for delay after
> power is stable.
> The regulator_enable() will handle the delays for the regulator device.
> And adding the msleep(25) is for lm90 device. If without delay,
> sometimes the device can't work properly. If read lm90 register
> immediately after enabling regulator, the reading may be failed.
> I'm not sure if 25ms is the right value, I read the LM90 SPEC, the max
> of "SMBus Clock Low Time" is 25ms, so I supposed that it may need about
> 25ms to stable after power on.
>

Problem is that you are always waiting, even if the same regulator was
turned on already, and even if it is a dummy regulator.

Imagine every driver doing that. Booting would take forever, just because of
unnecessary delays all over the place. There has to be a better solution
which does not include a mandatory and potentially unnecessary wait time
in the driver. At a previous company we had a design with literally dozens
of those chip. You really want to force such a boot delay on every user ?

But essentially you don't even know if it is needed; you are just guessing.
That is not an acceptable reason to add such a delay, mandatory or not.

Guenter

2013-09-10 05:39:17

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 12:50 PM, Guenter Roeck wrote:
> On 09/09/2013 09:05 PM, Wei Ni wrote:
>> On 09/10/2013 04:39 AM, Mark Brown wrote:
>>> * PGP Signed by an unknown key
>>>
>>> On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
>>>> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
>>>
>>>>> It does, though it gets complicated trying to use it for a case like
>>>>> this since you can't really tell if the regulator was powered on
>>>>> immediately before the device got probed by another device on the bus.
>>>
>>>> Why not ? Just keep a timestamp.
>>>
>>> The support is a callback on state changes; we could keep a timestamp
>>> but there's still going to be race conditions around bootloaders. It's
>>> doable though.
>>>
>>>>>> On a higher level, I wonder if such functionality should be added in the i2c
>>>>>> subsystem and not in i2c client drivers. Has anyone thought about this ?
>>>
>>>>> I'm not sure what the subsystem would do for such delays? It's fairly
>>>>> common for things that need this to also want to do things like
>>>>> manipulate GPIOs as part of the power on sequence so the applicability
>>>>> is relatively limited, plus it's not even I2C specific, the same applies
>>>>> to other buses so it ought to be a driver core thing.
>>>
>>>> Possibly. I just thought about i2c since it also takes care of basic
>>>> devicetree bindings. Something along the line of
>>>> if devicetree bindings for this device declare one or more
>>>> regulators, enable those regulators before calling the driver
>>>> probe function.
>>>
>>> That's definitely a driver core thing, not I2C - there's nothing
>>> specific to I2C in there at all, needing power is pretty generic. I
>>> have considered this before, something along the lines of what we have
>>> for pinctrl, but unfortunately the generic case isn't quite generic
>>> enough to make it easy. It'd need to be an explicit list of regulators
>>> (partly just to make it opt in and avoid breaking things) and you'd want
>>> to have a way of handling the different suspend/resume behaviour that
>>> devices want. There's a few patterns there.
>>>
>>> It's definitely something I think about from time to time and it would
>>> be useful to factor things out, the issue is getting a good enough model
>>> of what's going on.
>>>
>>>>> There was some work on a generic helper for power on sequences but it
>>>>> stalled since it wasn't accepted for the original purpose (LCD panel
>>>>> power ons IIRC).
>>>
>>>> Too bad. I think it could be kept quite simple, though, by handling it
>>>> through the regulator subsystem as suggested above. A generic binding
>>>> for a per-regulator and per-device poweron delay should solve that
>>>> and possibly even make it transparent to the actual driver code.
>>>
>>> Lots of things have a GPIO for reset too, and some want clocks too. For
>>> maximum usefulness this should be cross subsystem. I suspect the reset
>>> controller API may be able to handle some of it.
>>>
>>> The regulator power on delays are already handled transparently, by the
>>> time regulator_enable() returns the ramp should be finished.
>>
>> I think the regulator should encoded its own startup delay. Each
>> individual device should handle its own requirements for delay after
>> power is stable.
>> The regulator_enable() will handle the delays for the regulator device.
>> And adding the msleep(25) is for lm90 device. If without delay,
>> sometimes the device can't work properly. If read lm90 register
>> immediately after enabling regulator, the reading may be failed.
>> I'm not sure if 25ms is the right value, I read the LM90 SPEC, the max
>> of "SMBus Clock Low Time" is 25ms, so I supposed that it may need about
>> 25ms to stable after power on.
>>
>
> Problem is that you are always waiting, even if the same regulator was
> turned on already, and even if it is a dummy regulator.
>
> Imagine every driver doing that. Booting would take forever, just because of
> unnecessary delays all over the place. There has to be a better solution
> which does not include a mandatory and potentially unnecessary wait time
> in the driver. At a previous company we had a design with literally dozens
> of those chip. You really want to force such a boot delay on every user ?
>
> But essentially you don't even know if it is needed; you are just guessing.
> That is not an acceptable reason to add such a delay, mandatory or not.
I think the device need time to wait stable after power on, but it's
difficult to get an exact delay value, and this delay may also relate
with platform design, so how about to add a optional property in the DT
node, such as "power-on-delay-ms" ?

>
> Guenter
>

2013-09-10 05:54:43

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/09/2013 10:39 PM, Wei Ni wrote:
> On 09/10/2013 12:50 PM, Guenter Roeck wrote:
>> On 09/09/2013 09:05 PM, Wei Ni wrote:
>>> On 09/10/2013 04:39 AM, Mark Brown wrote:
>>>> * PGP Signed by an unknown key
>>>>
>>>> On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
>>>>> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
>>>>
>>>>>> It does, though it gets complicated trying to use it for a case like
>>>>>> this since you can't really tell if the regulator was powered on
>>>>>> immediately before the device got probed by another device on the bus.
>>>>
>>>>> Why not ? Just keep a timestamp.
>>>>
>>>> The support is a callback on state changes; we could keep a timestamp
>>>> but there's still going to be race conditions around bootloaders. It's
>>>> doable though.
>>>>
>>>>>>> On a higher level, I wonder if such functionality should be added in the i2c
>>>>>>> subsystem and not in i2c client drivers. Has anyone thought about this ?
>>>>
>>>>>> I'm not sure what the subsystem would do for such delays? It's fairly
>>>>>> common for things that need this to also want to do things like
>>>>>> manipulate GPIOs as part of the power on sequence so the applicability
>>>>>> is relatively limited, plus it's not even I2C specific, the same applies
>>>>>> to other buses so it ought to be a driver core thing.
>>>>
>>>>> Possibly. I just thought about i2c since it also takes care of basic
>>>>> devicetree bindings. Something along the line of
>>>>> if devicetree bindings for this device declare one or more
>>>>> regulators, enable those regulators before calling the driver
>>>>> probe function.
>>>>
>>>> That's definitely a driver core thing, not I2C - there's nothing
>>>> specific to I2C in there at all, needing power is pretty generic. I
>>>> have considered this before, something along the lines of what we have
>>>> for pinctrl, but unfortunately the generic case isn't quite generic
>>>> enough to make it easy. It'd need to be an explicit list of regulators
>>>> (partly just to make it opt in and avoid breaking things) and you'd want
>>>> to have a way of handling the different suspend/resume behaviour that
>>>> devices want. There's a few patterns there.
>>>>
>>>> It's definitely something I think about from time to time and it would
>>>> be useful to factor things out, the issue is getting a good enough model
>>>> of what's going on.
>>>>
>>>>>> There was some work on a generic helper for power on sequences but it
>>>>>> stalled since it wasn't accepted for the original purpose (LCD panel
>>>>>> power ons IIRC).
>>>>
>>>>> Too bad. I think it could be kept quite simple, though, by handling it
>>>>> through the regulator subsystem as suggested above. A generic binding
>>>>> for a per-regulator and per-device poweron delay should solve that
>>>>> and possibly even make it transparent to the actual driver code.
>>>>
>>>> Lots of things have a GPIO for reset too, and some want clocks too. For
>>>> maximum usefulness this should be cross subsystem. I suspect the reset
>>>> controller API may be able to handle some of it.
>>>>
>>>> The regulator power on delays are already handled transparently, by the
>>>> time regulator_enable() returns the ramp should be finished.
>>>
>>> I think the regulator should encoded its own startup delay. Each
>>> individual device should handle its own requirements for delay after
>>> power is stable.
>>> The regulator_enable() will handle the delays for the regulator device.
>>> And adding the msleep(25) is for lm90 device. If without delay,
>>> sometimes the device can't work properly. If read lm90 register
>>> immediately after enabling regulator, the reading may be failed.
>>> I'm not sure if 25ms is the right value, I read the LM90 SPEC, the max
>>> of "SMBus Clock Low Time" is 25ms, so I supposed that it may need about
>>> 25ms to stable after power on.
>>>
>>
>> Problem is that you are always waiting, even if the same regulator was
>> turned on already, and even if it is a dummy regulator.
>>
>> Imagine every driver doing that. Booting would take forever, just because of
>> unnecessary delays all over the place. There has to be a better solution
>> which does not include a mandatory and potentially unnecessary wait time
>> in the driver. At a previous company we had a design with literally dozens
>> of those chip. You really want to force such a boot delay on every user ?
>>
>> But essentially you don't even know if it is needed; you are just guessing.
>> That is not an acceptable reason to add such a delay, mandatory or not.
> I think the device need time to wait stable after power on, but it's
> difficult to get an exact delay value, and this delay may also relate
> with platform design, so how about to add a optional property in the DT
> node, such as "power-on-delay-ms" ?
>

Possibly, but that still doesn't solve the problem that you are going
to wait even if the regulator was already turned on. Simple example:
A system with two sensors, both of which share the same regulator.
Each of them will require a delay after turning on power,
but only if it was just turned on and not if it was already active.

Guenter

2013-09-10 06:29:32

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 01:54 PM, Guenter Roeck wrote:
> On 09/09/2013 10:39 PM, Wei Ni wrote:
>> On 09/10/2013 12:50 PM, Guenter Roeck wrote:
>>> On 09/09/2013 09:05 PM, Wei Ni wrote:
>>>> On 09/10/2013 04:39 AM, Mark Brown wrote:
>>>>> * PGP Signed by an unknown key
>>>>>
>>>>> On Mon, Sep 09, 2013 at 09:17:35AM -0700, Guenter Roeck wrote:
>>>>>> On Mon, Sep 09, 2013 at 05:02:37PM +0100, Mark Brown wrote:
>>>>>
>>>>>>> It does, though it gets complicated trying to use it for a case like
>>>>>>> this since you can't really tell if the regulator was powered on
>>>>>>> immediately before the device got probed by another device on the bus.
>>>>>
>>>>>> Why not ? Just keep a timestamp.
>>>>>
>>>>> The support is a callback on state changes; we could keep a timestamp
>>>>> but there's still going to be race conditions around bootloaders. It's
>>>>> doable though.
>>>>>
>>>>>>>> On a higher level, I wonder if such functionality should be added in the i2c
>>>>>>>> subsystem and not in i2c client drivers. Has anyone thought about this ?
>>>>>
>>>>>>> I'm not sure what the subsystem would do for such delays? It's fairly
>>>>>>> common for things that need this to also want to do things like
>>>>>>> manipulate GPIOs as part of the power on sequence so the applicability
>>>>>>> is relatively limited, plus it's not even I2C specific, the same applies
>>>>>>> to other buses so it ought to be a driver core thing.
>>>>>
>>>>>> Possibly. I just thought about i2c since it also takes care of basic
>>>>>> devicetree bindings. Something along the line of
>>>>>> if devicetree bindings for this device declare one or more
>>>>>> regulators, enable those regulators before calling the driver
>>>>>> probe function.
>>>>>
>>>>> That's definitely a driver core thing, not I2C - there's nothing
>>>>> specific to I2C in there at all, needing power is pretty generic. I
>>>>> have considered this before, something along the lines of what we have
>>>>> for pinctrl, but unfortunately the generic case isn't quite generic
>>>>> enough to make it easy. It'd need to be an explicit list of regulators
>>>>> (partly just to make it opt in and avoid breaking things) and you'd want
>>>>> to have a way of handling the different suspend/resume behaviour that
>>>>> devices want. There's a few patterns there.
>>>>>
>>>>> It's definitely something I think about from time to time and it would
>>>>> be useful to factor things out, the issue is getting a good enough model
>>>>> of what's going on.
>>>>>
>>>>>>> There was some work on a generic helper for power on sequences but it
>>>>>>> stalled since it wasn't accepted for the original purpose (LCD panel
>>>>>>> power ons IIRC).
>>>>>
>>>>>> Too bad. I think it could be kept quite simple, though, by handling it
>>>>>> through the regulator subsystem as suggested above. A generic binding
>>>>>> for a per-regulator and per-device poweron delay should solve that
>>>>>> and possibly even make it transparent to the actual driver code.
>>>>>
>>>>> Lots of things have a GPIO for reset too, and some want clocks too. For
>>>>> maximum usefulness this should be cross subsystem. I suspect the reset
>>>>> controller API may be able to handle some of it.
>>>>>
>>>>> The regulator power on delays are already handled transparently, by the
>>>>> time regulator_enable() returns the ramp should be finished.
>>>>
>>>> I think the regulator should encoded its own startup delay. Each
>>>> individual device should handle its own requirements for delay after
>>>> power is stable.
>>>> The regulator_enable() will handle the delays for the regulator device.
>>>> And adding the msleep(25) is for lm90 device. If without delay,
>>>> sometimes the device can't work properly. If read lm90 register
>>>> immediately after enabling regulator, the reading may be failed.
>>>> I'm not sure if 25ms is the right value, I read the LM90 SPEC, the max
>>>> of "SMBus Clock Low Time" is 25ms, so I supposed that it may need about
>>>> 25ms to stable after power on.
>>>>
>>>
>>> Problem is that you are always waiting, even if the same regulator was
>>> turned on already, and even if it is a dummy regulator.
>>>
>>> Imagine every driver doing that. Booting would take forever, just because of
>>> unnecessary delays all over the place. There has to be a better solution
>>> which does not include a mandatory and potentially unnecessary wait time
>>> in the driver. At a previous company we had a design with literally dozens
>>> of those chip. You really want to force such a boot delay on every user ?
>>>
>>> But essentially you don't even know if it is needed; you are just guessing.
>>> That is not an acceptable reason to add such a delay, mandatory or not.
>> I think the device need time to wait stable after power on, but it's
>> difficult to get an exact delay value, and this delay may also relate
>> with platform design, so how about to add a optional property in the DT
>> node, such as "power-on-delay-ms" ?
>>
>
> Possibly, but that still doesn't solve the problem that you are going
> to wait even if the regulator was already turned on. Simple example:
> A system with two sensors, both of which share the same regulator.
> Each of them will require a delay after turning on power,
> but only if it was just turned on and not if it was already active.

Yes, but as Mark said, the regulator subsystem still can't know if the
regulator was powered on.
Do you have any suggestions?

>
> Guenter
>

2013-09-10 10:10:55

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Mon, Sep 09, 2013 at 10:13:56PM -0600, Stephen Warren wrote:
> On 09/09/2013 09:53 PM, Guenter Roeck wrote:

> > Earlier comments suggest that this is not the intended use case for
> > regulator_get_optional().

That's right.

> Isn't the issue only whether the optional aspect of the regulator is
> implemented by:

> a) regulator_get_optional() returning failure, then the driver having to
> check for that and either using or not-using the regulator.

> b) regulator_get_optional() returning a dummy regulator automatically
> when none is specified in DT or the regulator lookup table, and hence
> the driver can always call regulator_enable/disable on the returned value.

No. There are a couple of issues here. One is that we don't want to
litter all drivers with conditional code to check if they actually got
the regulator and so on, that's just pointless make work on the part of
consumers. The other is that just ignoring errors is generally terrible
practice which we don't want to encourage - ignoring the specific case
where nothing is provided and the system has control of that is one
thing but just ignoring any error is another.


Attachments:
(No filename) (1.12 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 10:14:27

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 01:39:59PM +0800, Wei Ni wrote:

> I think the device need time to wait stable after power on, but it's
> difficult to get an exact delay value, and this delay may also relate
> with platform design, so how about to add a optional property in the DT
> node, such as "power-on-delay-ms" ?

This is something you should *really* be able to get from the datasheet
for the part - this sort of stuff has to be documented for hardware to
be used robustly. It seems entirely possible that you are working
around an issue with the regulator driver you are using not correctly
providing its ramp time here.


Attachments:
(No filename) (623.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 11:28:57

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 06:13 PM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Tue, Sep 10, 2013 at 01:39:59PM +0800, Wei Ni wrote:
>
>> I think the device need time to wait stable after power on, but it's
>> difficult to get an exact delay value, and this delay may also relate
>> with platform design, so how about to add a optional property in the DT
>> node, such as "power-on-delay-ms" ?
>
> This is something you should *really* be able to get from the datasheet
> for the part - this sort of stuff has to be documented for hardware to
> be used robustly. It seems entirely possible that you are working
> around an issue with the regulator driver you are using not correctly
> providing its ramp time here.

On my platform, it use palmas-regulator.c, ldo6 for this lm90 power
rail. I checked this driver, it will handle ramp_delay except LDOx.
Since I'm not familiar with this palmas device and driver, so do you
mean I can set regulator-ramp-delay property in the DT for ldo6, but I
really don't know what value should I set :(

Thanks.
Wei.

>
> * Unknown Key
> * 0x7EA229BD
>

2013-09-10 12:12:47

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 07:29:40PM +0800, Wei Ni wrote:

> On my platform, it use palmas-regulator.c, ldo6 for this lm90 power
> rail. I checked this driver, it will handle ramp_delay except LDOx.
> Since I'm not familiar with this palmas device and driver, so do you
> mean I can set regulator-ramp-delay property in the DT for ldo6, but I
> really don't know what value should I set :(

Laxman just submitted a patch adding the ramp delay information which I
applied. It seems like this is just a hack for your board and can
therefore be removed?


Attachments:
(No filename) (550.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 15:07:50

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 04:09 AM, Mark Brown wrote:
> On Mon, Sep 09, 2013 at 10:13:56PM -0600, Stephen Warren wrote:
>> On 09/09/2013 09:53 PM, Guenter Roeck wrote:
>
>>> Earlier comments suggest that this is not the intended use case
>>> for regulator_get_optional().
>
> That's right.
>
>> Isn't the issue only whether the optional aspect of the regulator
>> is implemented by:
>
>> a) regulator_get_optional() returning failure, then the driver
>> having to check for that and either using or not-using the
>> regulator.
>
>> b) regulator_get_optional() returning a dummy regulator
>> automatically when none is specified in DT or the regulator
>> lookup table, and hence the driver can always call
>> regulator_enable/disable on the returned value.
>
> No. There are a couple of issues here. One is that we don't want
> to litter all drivers with conditional code to check if they
> actually got the regulator and so on, that's just pointless make
> work on the part of consumers.

So that's exactly the difference between (a) and (b) above.

> The other is that just ignoring errors is generally terrible
> practice which we don't want to encourage - ignoring the specific
> case where nothing is provided and the system has control of that
> is one thing but just ignoring any error is another.

Yes, obviously the code somewhere needs to distinguish between
missing-so-use-a-dummy, and specified-but-in-a-broken-way. Doesn't
regulator_get_optional() already distinguish those two cases? Perhaps
that's the enhancement to regulator_get_optional() that you were
requesting.

2013-09-10 17:05:58

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 09:07:43AM -0600, Stephen Warren wrote:
> On 09/10/2013 04:09 AM, Mark Brown wrote:

> > No. There are a couple of issues here. One is that we don't want
> > to litter all drivers with conditional code to check if they
> > actually got the regulator and so on, that's just pointless make
> > work on the part of consumers.

> So that's exactly the difference between (a) and (b) above.

Right, but the idea is that we just only ignore a failure to get a
supply if we can usefully run without that supply being present and
there's more code there than simply ignoring the error - if the driver
can genuinely just ignore all errors and otherwise not do anything
different then requesting the regulator in the first place is clearly a
waste of time and enabling it would be a waste of power.

A driver should only be carrying code for a missing regulator if it can
usefully work without it, like the cases where devices can use an
internal reference if one is not available.

> > The other is that just ignoring errors is generally terrible
> > practice which we don't want to encourage - ignoring the specific
> > case where nothing is provided and the system has control of that
> > is one thing but just ignoring any error is another.

> Yes, obviously the code somewhere needs to distinguish between
> missing-so-use-a-dummy, and specified-but-in-a-broken-way. Doesn't
> regulator_get_optional() already distinguish those two cases? Perhaps
> that's the enhancement to regulator_get_optional() that you were
> requesting.

Both calls are identical in terms of handling genuine errors. If the
driver is just trying to ignore errors it will be more work to use
_optional() since it has to cope with the regulator not being present in
a system.


Attachments:
(No filename) (1.73 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 17:06:27

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 11:22:01AM +0800, Wei Ni wrote:

> Mark, do you mean you have patches for regulator_get_optional() and
> regulator_get()?

Not yet but they'll be there by the time the next merge window comes.


Attachments:
(No filename) (217.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 17:44:12

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 11:04 AM, Mark Brown wrote:
> On Tue, Sep 10, 2013 at 09:07:43AM -0600, Stephen Warren wrote:
>> On 09/10/2013 04:09 AM, Mark Brown wrote:
>
>>> No. There are a couple of issues here. One is that we don't want
>>> to litter all drivers with conditional code to check if they
>>> actually got the regulator and so on, that's just pointless make
>>> work on the part of consumers.
>
>> So that's exactly the difference between (a) and (b) above.
>
> Right, but the idea is that we just only ignore a failure to get a
> supply if we can usefully run without that supply being present and
> there's more code there than simply ignoring the error - if the driver
> can genuinely just ignore all errors and otherwise not do anything
> different then requesting the regulator in the first place is clearly a
> waste of time and enabling it would be a waste of power.
>
> A driver should only be carrying code for a missing regulator if it can
> usefully work without it, like the cases where devices can use an
> internal reference if one is not available.

OK, so I believe you're saying that the case of a chip with just a
single power source, which absolutely must be present in HW for the chip
to be powered, isn't appropriate for regulator_get_optional(). Something
must always define a regulator for that power source, even if there is
no external SW control over that power source.

If so, how does a driver (or binding) that's been written without any
support for a regulator (since so far all boards have had no SW control
over that power source; it's always on) get enhanced to support boards
where there is SW control over the power source?

We either allow the regulator to be optional (since SW control over the
regulator is optional), or go back to every board file and DT and add a
dummy regulator in (which then breaks DT ABI, and even ignoring that is
a pain).

And note that when I say "optional" at the start of the previous
paragraph, I'm talking about probe-time regulator_get() operations and
DT content. Clearly as far as the rest of the driver is concerned,
something can always provide a dummy regulator so that e.g.
regulator_enable/disable() elsewhere always have something to operate
on. However, probe() either needs to call an API that automatically
provides such a dummy regulator, or open-code that itself. I'm still not
clear which option you think should be used.

2013-09-10 18:07:52

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 11:44:05AM -0600, Stephen Warren wrote:
> On 09/10/2013 11:04 AM, Mark Brown wrote:
> > On Tue, Sep 10, 2013 at 09:07:43AM -0600, Stephen Warren wrote:
> >> On 09/10/2013 04:09 AM, Mark Brown wrote:
> >
> >>> No. There are a couple of issues here. One is that we don't want
> >>> to litter all drivers with conditional code to check if they
> >>> actually got the regulator and so on, that's just pointless make
> >>> work on the part of consumers.
> >
> >> So that's exactly the difference between (a) and (b) above.
> >
> > Right, but the idea is that we just only ignore a failure to get a
> > supply if we can usefully run without that supply being present and
> > there's more code there than simply ignoring the error - if the driver
> > can genuinely just ignore all errors and otherwise not do anything
> > different then requesting the regulator in the first place is clearly a
> > waste of time and enabling it would be a waste of power.
> >
> > A driver should only be carrying code for a missing regulator if it can
> > usefully work without it, like the cases where devices can use an
> > internal reference if one is not available.
>
> OK, so I believe you're saying that the case of a chip with just a
> single power source, which absolutely must be present in HW for the chip
> to be powered, isn't appropriate for regulator_get_optional(). Something
> must always define a regulator for that power source, even if there is
> no external SW control over that power source.
>
I think you are supposed to use a dummy regulator in that case.

Guenter

> If so, how does a driver (or binding) that's been written without any
> support for a regulator (since so far all boards have had no SW control
> over that power source; it's always on) get enhanced to support boards
> where there is SW control over the power source?
>
> We either allow the regulator to be optional (since SW control over the
> regulator is optional), or go back to every board file and DT and add a
> dummy regulator in (which then breaks DT ABI, and even ignoring that is
> a pain).
>
> And note that when I say "optional" at the start of the previous
> paragraph, I'm talking about probe-time regulator_get() operations and
> DT content. Clearly as far as the rest of the driver is concerned,
> something can always provide a dummy regulator so that e.g.
> regulator_enable/disable() elsewhere always have something to operate
> on. However, probe() either needs to call an API that automatically
> provides such a dummy regulator, or open-code that itself. I'm still not
> clear which option you think should be used.
>

2013-09-10 18:18:45

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 11:44:05AM -0600, Stephen Warren wrote:

> OK, so I believe you're saying that the case of a chip with just a
> single power source, which absolutely must be present in HW for the chip
> to be powered, isn't appropriate for regulator_get_optional(). Something
> must always define a regulator for that power source, even if there is
> no external SW control over that power source.

Well, it really should be mandatory - personally I don't think it's
sensible to add off-SoC chips without defining their regulators, it's
more trouble than it's worth to have to add them later for all the time
it takes to define the bindings. In IETF terms it's a should.

> We either allow the regulator to be optional (since SW control over the
> regulator is optional), or go back to every board file and DT and add a
> dummy regulator in (which then breaks DT ABI, and even ignoring that is
> a pain).

The whole point of the way I'm changing the dummy support is to allow
us to gracefully cope with errors here so there's no mandatory update
even though strictly there should be one.

> And note that when I say "optional" at the start of the previous
> paragraph, I'm talking about probe-time regulator_get() operations and
> DT content. Clearly as far as the rest of the driver is concerned,
> something can always provide a dummy regulator so that e.g.
> regulator_enable/disable() elsewhere always have something to operate
> on. However, probe() either needs to call an API that automatically
> provides such a dummy regulator, or open-code that itself. I'm still not
> clear which option you think should be used.

Clearly open coding this in every single driver is just not sane, you're
immediately in the situation where every single driver has to implement
the same thing at which point no driver ought to be doing it.


Attachments:
(No filename) (1.80 kB)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-10 18:37:52

by Stephen Warren

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 12:18 PM, Mark Brown wrote:
> On Tue, Sep 10, 2013 at 11:44:05AM -0600, Stephen Warren wrote:
>
>> OK, so I believe you're saying that the case of a chip with just
>> a single power source, which absolutely must be present in HW for
>> the chip to be powered, isn't appropriate for
>> regulator_get_optional(). Something must always define a
>> regulator for that power source, even if there is no external SW
>> control over that power source.
>
> Well, it really should be mandatory - personally I don't think
> it's sensible to add off-SoC chips without defining their
> regulators, it's more trouble than it's worth to have to add them
> later for all the time it takes to define the bindings. In IETF
> terms it's a should.
>
>> We either allow the regulator to be optional (since SW control
>> over the regulator is optional), or go back to every board file
>> and DT and add a dummy regulator in (which then breaks DT ABI,
>> and even ignoring that is a pain).
>
> The whole point of the way I'm changing the dummy support is to
> allow us to gracefully cope with errors here so there's no
> mandatory update even though strictly there should be one.

OK, so for the DT binding we should make vcc-supply a required
property, yet the driver will still work OK if that property just
happens to be missing (or e.g. when instantiated from a board file,
and there's no regulator).

2013-09-10 18:53:45

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On Tue, Sep 10, 2013 at 12:37:47PM -0600, Stephen Warren wrote:

> OK, so for the DT binding we should make vcc-supply a required
> property, yet the driver will still work OK if that property just
> happens to be missing (or e.g. when instantiated from a board file,
> and there's no regulator).

Yup. That way we've got both the binding and code trying to make things
work, hopefully that'll maximise robustness.


Attachments:
(No filename) (416.00 B)
signature.asc (836.00 B)
Digital signature
Download all attachments

2013-09-11 09:39:39

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/10/2013 08:11 PM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Tue, Sep 10, 2013 at 07:29:40PM +0800, Wei Ni wrote:
>
>> On my platform, it use palmas-regulator.c, ldo6 for this lm90 power
>> rail. I checked this driver, it will handle ramp_delay except LDOx.
>> Since I'm not familiar with this palmas device and driver, so do you
>> mean I can set regulator-ramp-delay property in the DT for ldo6, but I
>> really don't know what value should I set :(
>
> Laxman just submitted a patch adding the ramp delay information which I
> applied. It seems like this is just a hack for your board and can
> therefore be removed?

Oh, yes, it seems the patches is Laxman's [PATCH 1/2] regulator: palmas:
configure enable time for LDOs.
Thanks, I will check it, and remove the delay in my next patch.

Wei.

>
> * Unknown Key
> * 0x7EA229BD
>

2013-09-11 11:34:50

by Wei Ni

[permalink] [raw]
Subject: Re: [PATCH v3 1/2] hwmon: (lm90) Add power control

On 09/11/2013 02:52 AM, Mark Brown wrote:
> * PGP Signed by an unknown key
>
> On Tue, Sep 10, 2013 at 12:37:47PM -0600, Stephen Warren wrote:
>
>> OK, so for the DT binding we should make vcc-supply a required
>> property, yet the driver will still work OK if that property just
>> happens to be missing (or e.g. when instantiated from a board file,
>> and there's no regulator).
>
> Yup. That way we've got both the binding and code trying to make things
> work, hopefully that'll maximise robustness.

Ok, it looks like regulator_get will handle all things, looking forward
to your patches :)
Then I think my changes will be simple, just something like:
+ reg = devm_regulator_get(dev, "vcc");
+ if (!IS_ERR(reg)) {
+ err = regulator_enable(reg);
+ if (err < 0)
+ return err;
+ } else {
+ return PTR_ERR(reg);
+ }

Wei.

>
> * Unknown Key
> * 0x7EA229BD
>