iio: light: isl29018: add vcc regulator operation support
PATCH v9 1/1 iio: light: isl29018: add vcc regulator operation support
The light sensor's power supply could be controllable by regulator on some platforms, such as i.MX6Q-SABRESD board, the light sensor isl29023's power supply is controlled by a GPIO fixed regulator, need to make sure the regulator is enabled before any operation of sensor, this patch adds vcc regulator operation support.
---
ChangeLog since V8:
- use devm_add_action_or_reset instead of devm_add_action to avoid calling regulator disable when failed;
--- drivers/iio/light/isl29018.c | 46 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
drivers/iio/light/isl29018.c +45 -1
@@ -23,6 +23,7 @@#include <linux/mutex.h> #include <linux/delay.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h>
@@ -95,6 +96,7 @@ struct isl29018_chip {struct isl29018_scale scale;int prox_scheme;bool suspended; +struct regulator *vcc_reg; }; static int isl29018_set_integration_time(struct isl29018_chip *chip,
@@ -708,6 +710,16 @@ static const char *isl29018_match_acpi_device(struct device *dev, int *data)return dev_name (dev); } +static void isl29018_disable_regulator_action (void *_data) +{ +struct isl29018_chip *chip = _data; +int err; + + err =regulator_disable (chip->vcc_reg); +if (err) +pr_err ("failed to disable isl29018's VCC regulator!\n" ); +} +static int isl29018_probe (struct i2c_client *client,const struct i2c_device_id *id) {
@@ -742,6 +754,27 @@ static int isl29018_probe(struct i2c_client *client, chip->scale = isl29018_scales[chip->int_time][0 ]; chip->suspended = false; + chip->vcc_reg =devm_regulator_get (&client->dev,"vcc" ); +if (IS_ERR (chip->vcc_reg)) { + err =PTR_ERR (chip->vcc_reg); +if (err != -EPROBE_DEFER ) +dev_err (&client->dev,"failed to get VCC regulator!\n" ); +return err; + } + + err =regulator_enable (chip->vcc_reg); +if (err) { +dev_err (&client->dev,"failed to enable VCC regulator!\n" ); +return err; + } + + err =devm_add_action_or_reset (&client->dev, isl29018_disable_regulator_action, + chip); +if (err) { +dev_err (&client->dev,"failed to setup regulator cleanup action!\n" ); +return err; + } + chip->regmap =devm_regmap_init_i2c (client, isl29018_chip_info_tbl[dev_id].regmap_cfg);if (IS_ERR (chip->regmap)) {
@@ -768,6 +801,7 @@ static int isl29018_probe(struct i2c_client *client,static int isl29018_suspend (struct device *dev) {struct isl29018_chip *chip =iio_priv (dev_get_drvdata (dev)); +int ret;mutex_lock (&chip->lock);
@@ -777,10 +811,13 @@ static int isl29018_suspend(struct device *dev)* So we do not have much to do here. */ chip->suspended = true; + ret =regulator_disable (chip->vcc_reg); +if (ret) +dev_err (dev,"failed to disable VCC regulator\n" );mutex_unlock (&chip->lock); -return 0 ; +return ret; }static int isl29018_resume (struct device *dev)
@@ -790,6 +827,13 @@ static int isl29018_resume(struct device *dev)mutex_lock (&chip->lock); + err =regulator_enable (chip->vcc_reg); +if (err) { +dev_err (dev,"failed to enable VCC regulator\n" ); +mutex_unlock (&chip->lock); +return err; + } + err =isl29018_chip_init (chip);if (!err) chip->suspended = false;
Signature · 1 line
2.7.4
Jonathan Cameron
maintainerQuoted 7 lines · On Tue, 8 Jan 2019 09:09:39 +0000 Anson Huang <[email protected]> wrote:
The light sensor's power supply could be controllable by regulator on some platforms, such as i.MX6Q-SABRESD board, the light sensor isl29023's power supply is controlled by a GPIO fixed regulator, need to make sure the regulator is enabled before any operation of sensor, this patch adds vcc regulator operation support.
Signed-off-by Anson Huang <[email protected]>
Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 109 lines
---
ChangeLog since V8:
- usedevm_add_action_or_resetinstead ofdevm_add_actionto avoid calling regulator disable when failed;--- drivers/iio/light/isl29018.c | 46 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)drivers/iio/light/isl29018.c +45
-1@@ -23,6 +23,7 @@#include <linux/mutex.h> #include <linux/delay.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <linux/slab.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -95,6 +96,7 @@ struct isl29018_chip {struct isl29018_scale scale;int prox_scheme;bool suspended; +struct regulator *vcc_reg; }; static int isl29018_set_integration_time(struct isl29018_chip *chip,@@ -708,6 +710,16 @@ static const char *isl29018_match_acpi_device(struct device *dev, int *data)return dev_name (dev); } +static void isl29018_disable_regulator_action (void *_data) +{ +struct isl29018_chip *chip = _data; +int err; + + err =regulator_disable (chip->vcc_reg); +if (err) +pr_err ("failed to disable isl29018's VCC regulator!\n" ); +} +static int isl29018_probe (struct i2c_client *client,const struct i2c_device_id *id) {@@ -742,6 +754,27 @@ static int isl29018_probe(struct i2c_client *client, chip->scale = isl29018_scales[chip->int_time][0 ]; chip->suspended = false; + chip->vcc_reg =devm_regulator_get (&client->dev,"vcc" ); +if (IS_ERR (chip->vcc_reg)) { + err =PTR_ERR (chip->vcc_reg); +if (err != -EPROBE_DEFER ) +dev_err (&client->dev,"failed to get VCC regulator!\n" ); +return err; + } + + err =regulator_enable (chip->vcc_reg); +if (err) { +dev_err (&client->dev,"failed to enable VCC regulator!\n" ); +return err; + } + + err =devm_add_action_or_reset (&client->dev, isl29018_disable_regulator_action, + chip); +if (err) { +dev_err (&client->dev,"failed to setup regulator cleanup action!\n" ); +return err; + } + chip->regmap =devm_regmap_init_i2c (client, isl29018_chip_info_tbl[dev_id].regmap_cfg);if (IS_ERR (chip->regmap)) {@@ -768,6 +801,7 @@ static int isl29018_probe(struct i2c_client *client,static int isl29018_suspend (struct device *dev) {struct isl29018_chip *chip =iio_priv (dev_get_drvdata (dev)); +int ret;mutex_lock (&chip->lock);@@ -777,10 +811,13 @@ static int isl29018_suspend(struct device *dev)* So we do not have much to do here. */ chip->suspended = true; + ret =regulator_disable (chip->vcc_reg); +if (ret) +dev_err (dev,"failed to disable VCC regulator\n" );mutex_unlock (&chip->lock); -return 0 ; +return ret; }static int isl29018_resume (struct device *dev)@@ -790,6 +827,13 @@ static int isl29018_resume(struct device *dev)mutex_lock (&chip->lock); + err =regulator_enable (chip->vcc_reg); +if (err) { +dev_err (dev,"failed to enable VCC regulator\n" ); +mutex_unlock (&chip->lock); +return err; + } + err =isl29018_chip_init (chip);if (!err) chip->suspended = false;