From: "Bedel, Alban" <alban.bedel@aerq.com>
To: "linux@roeck-us.net" <linux@roeck-us.net>,
"linux-hwmon@vger.kernel.org" <linux-hwmon@vger.kernel.org>
Cc: "lgirdwood@gmail.com" <lgirdwood@gmail.com>,
"broonie@kernel.org" <broonie@kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jdelvare@suse.com" <jdelvare@suse.com>,
"robh+dt@kernel.org" <robh+dt@kernel.org>
Subject: Re: [PATCH 3/3] hwmon: (lm75) Add regulator support
Date: Mon, 28 Sep 2020 15:13:53 +0000 [thread overview]
Message-ID: <d3c7959cd1e775ae4680a446328f271e7d6c42c6.camel@aerq.com> (raw)
In-Reply-To: <7986c014-b826-bad1-f19c-cdda31d20804@roeck-us.net>
[-- Attachment #1: Type: text/plain, Size: 3059 bytes --]
On Thu, 2020-09-17 at 22:33 -0700, Guenter Roeck wrote:
> On 9/17/20 3:18 AM, Alban Bedel wrote:
> > Add regulator support for boards where the sensor first need to be
> > powered up before it can be used.
> >
> > Signed-off-by: Alban Bedel <alban.bedel@aerq.com>
> > ---
> > drivers/hwmon/lm75.c | 31 +++++++++++++++++++++++++++++--
> > 1 file changed, 29 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
> > index ba0be48aeadd..b673f8d2ef20 100644
> > --- a/drivers/hwmon/lm75.c
> > +++ b/drivers/hwmon/lm75.c
> > @@ -17,6 +17,7 @@
> > #include <linux/of.h>
> > #include <linux/regmap.h>
> > #include <linux/util_macros.h>
> > +#include <linux/regulator/consumer.h>
> > #include "lm75.h"
> >
> > /*
> > @@ -101,6 +102,7 @@ static const unsigned short normal_i2c[] = {
> > 0x48, 0x49, 0x4a, 0x4b, 0x4c,
> > struct lm75_data {
> > struct i2c_client *client;
> > struct regmap *regmap;
> > + struct regulator *vs;
> > u8 orig_conf;
> > u8 current_conf;
> > u8 resolution; /* In bits, 9 to 16 */
> > @@ -540,6 +542,8 @@ static void lm75_remove(void *data)
> > struct i2c_client *client = lm75->client;
> >
> > i2c_smbus_write_byte_data(client, LM75_REG_CONF, lm75->orig_conf);
> > + if (lm75->vs)
> > + regulator_disable(lm75->vs);
> > }
> >
> > static int
> > @@ -567,6 +571,14 @@ lm75_probe(struct i2c_client *client, const
> > struct i2c_device_id *id)
> > data->client = client;
> > data->kind = kind;
> >
> > + data->vs = devm_regulator_get_optional(dev, "vs");
>
> Looking into the regulator API, it may be better if you use
> devm_regulator_get().
> AFAICS it returns a dummy regulator if there is none, and NULL if the
> regulator subsystem is disabled. So
> data->vs = devm_regulator_get(dev, "vs");
> if (IS_ERR(data->vs))
> return PTR_ERR(data->vs);
> should work and would be less messy.
Ok, I'll change that in the next version.
> > + if (IS_ERR(data->vs)) {
> > + if (PTR_ERR(data->vs) == -ENODEV)
> > + data->vs = NULL;
> > + else
> > + return PTR_ERR(data->vs);
> > + }
> > +
> > data->regmap = devm_regmap_init_i2c(client,
> > &lm75_regmap_config);
> > if (IS_ERR(data->regmap))
> > return PTR_ERR(data->regmap);
> > @@ -581,11 +593,21 @@ lm75_probe(struct i2c_client *client, const
> > struct i2c_device_id *id)
> > data->sample_time = data->params->default_sample_time;
> > data->resolution = data->params->default_resolution;
> >
> > + /* Enable the power */
> > + if (data->vs) {
> > + err = regulator_enable(data->vs);
> > + if (err) {
> > + dev_err(dev, "failed to enable regulator:
> > %d\n", err);
> > + return err;
> > + }
> > + }
> > +
>
> How about device removal ? Don't you have to call regulator_disable()
> there as well ? If so, it might be best to use
> devm_add_action_or_reset() to register a disable function.
This is handled in lm75_remove() where I added the regulator_disable()
call.
Alban
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-09-28 15:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-17 10:18 [PATCH 0/3] hwmon: (lm75) Add regulator support Alban Bedel
2020-09-17 10:18 ` [PATCH 1/3] dt-bindings: hwmon: Convert lm75 bindings to yaml Alban Bedel
2020-09-18 17:28 ` Rob Herring
2020-09-17 10:18 ` [PATCH 2/3] dt-bindings: hwmon: Add the +vs supply to the lm75 bindings Alban Bedel
2020-09-23 20:16 ` Rob Herring
2020-09-17 10:18 ` [PATCH 3/3] hwmon: (lm75) Add regulator support Alban Bedel
2020-09-17 11:00 ` Mark Brown
2020-09-18 2:04 ` Guenter Roeck
2020-09-18 10:03 ` Mark Brown
2020-09-18 5:33 ` Guenter Roeck
2020-09-18 10:04 ` Mark Brown
2020-09-28 15:13 ` Bedel, Alban [this message]
2020-09-28 16:29 ` Guenter Roeck
2020-09-28 16:31 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d3c7959cd1e775ae4680a446328f271e7d6c42c6.camel@aerq.com \
--to=alban.bedel@aerq.com \
--cc=broonie@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=lgirdwood@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).