diff options
author | Alban Bedel <alban.bedel@aerq.com> | 2020-10-01 16:57:38 +0200 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2020-10-04 08:40:10 -0700 |
commit | 707d151bd1ac4062796b95f9f6c32309ce69888c (patch) | |
tree | b357dc78b31ca03b52473af60cb83ba44beb032c | |
parent | 865e4fc013ba58cc3245fc1180033ee52e9c426e (diff) |
hwmon: (lm75) Add regulator support
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>
Link: https://lore.kernel.org/r/20201001145738.17326-4-alban.bedel@aerq.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/lm75.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c index e22f977942b4..e447febd121a 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 */ @@ -534,6 +536,13 @@ static const struct regmap_config lm75_regmap_config = { .use_single_write = true, }; +static void lm75_disable_regulator(void *data) +{ + struct lm75_data *lm75 = data; + + regulator_disable(lm75->vs); +} + static void lm75_remove(void *data) { struct lm75_data *lm75 = data; @@ -568,6 +577,10 @@ static int lm75_probe(struct i2c_client *client) data->client = client; data->kind = kind; + data->vs = devm_regulator_get(dev, "vs"); + if (IS_ERR(data->vs)) + 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); @@ -582,6 +595,17 @@ static int lm75_probe(struct i2c_client *client) data->sample_time = data->params->default_sample_time; data->resolution = data->params->default_resolution; + /* Enable the power */ + err = regulator_enable(data->vs); + if (err) { + dev_err(dev, "failed to enable regulator: %d\n", err); + return err; + } + + err = devm_add_action_or_reset(dev, lm75_disable_regulator, data); + if (err) + return err; + /* Cache original configuration */ status = i2c_smbus_read_byte_data(client, LM75_REG_CONF); if (status < 0) { |