linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V8] iio: light: isl29018: add vcc regulator operation support
@ 2018-12-23  6:46 Anson Huang
  2019-01-05 17:42 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Anson Huang @ 2018-12-23  6:46 UTC (permalink / raw)
  To: jic23, knaack.h, lars, pmeerw, linux-iio, linux-kernel; +Cc: dl-linux-imx

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 <Anson.Huang@nxp.com>
---
ChangeLog Since V7:
    - move devm_add_action to before devm_regmap_init_i2c call to save code of disabling regulator;
    - simply the error check logic in isl29018_suspend.
---
 drivers/iio/light/isl29018.c | 47 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c
index b45400f..ec6ce89 100644
--- a/drivers/iio/light/isl29018.c
+++ b/drivers/iio/light/isl29018.c
@@ -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,28 @@ 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(&client->dev, isl29018_disable_regulator_action,
+				 chip);
+	if (err) {
+		isl29018_disable_regulator_action(chip);
+		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 +802,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 +812,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 +828,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;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH V8] iio: light: isl29018: add vcc regulator operation support
  2018-12-23  6:46 [PATCH V8] iio: light: isl29018: add vcc regulator operation support Anson Huang
@ 2019-01-05 17:42 ` Jonathan Cameron
  2019-01-08  9:16   ` Anson Huang
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2019-01-05 17:42 UTC (permalink / raw)
  To: Anson Huang; +Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, dl-linux-imx

On Sun, 23 Dec 2018 06:46:32 +0000
Anson Huang <anson.huang@nxp.com> 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 <Anson.Huang@nxp.com>

One comment inline on handling the error from devm_add_action.

Jonathan

> ---
> ChangeLog Since V7:
>     - move devm_add_action to before devm_regmap_init_i2c call to save code of disabling regulator;
>     - simply the error check logic in isl29018_suspend.
> ---
>  drivers/iio/light/isl29018.c | 47 +++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 46 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/light/isl29018.c b/drivers/iio/light/isl29018.c
> index b45400f..ec6ce89 100644
> --- a/drivers/iio/light/isl29018.c
> +++ b/drivers/iio/light/isl29018.c
> @@ -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,28 @@ 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(&client->dev, isl29018_disable_regulator_action,
> +				 chip);

Use devm_add_action_or_reset, then you don't need to call
the disable if an error occurs in the add_action part...

> +	if (err) {
> +		isl29018_disable_regulator_action(chip);

(will get rid of the line above).

> +		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 +802,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 +812,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 +828,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;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH V8] iio: light: isl29018: add vcc regulator operation support
  2019-01-05 17:42 ` Jonathan Cameron
@ 2019-01-08  9:16   ` Anson Huang
  0 siblings, 0 replies; 3+ messages in thread
From: Anson Huang @ 2019-01-08  9:16 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: knaack.h, lars, pmeerw, linux-iio, linux-kernel, dl-linux-imx

Hi, Jonathan

Best Regards!
Anson Huang

> -----Original Message-----
> From: Jonathan Cameron [mailto:jic23@kernel.org]
> Sent: 2019年1月6日 1:43
> To: Anson Huang <anson.huang@nxp.com>
> Cc: knaack.h@gmx.de; lars@metafoo.de; pmeerw@pmeerw.net;
> linux-iio@vger.kernel.org; linux-kernel@vger.kernel.org; dl-linux-imx
> <linux-imx@nxp.com>
> Subject: Re: [PATCH V8] iio: light: isl29018: add vcc regulator operation
> support
> 
> On Sun, 23 Dec 2018 06:46:32 +0000
> Anson Huang <anson.huang@nxp.com> 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 <Anson.Huang@nxp.com>
> 
> One comment inline on handling the error from devm_add_action.
> 
> Jonathan
> 
> > ---
> > ChangeLog Since V7:
> >     - move devm_add_action to before devm_regmap_init_i2c call to save
> code of disabling regulator;
> >     - simply the error check logic in isl29018_suspend.
> > ---
> >  drivers/iio/light/isl29018.c | 47
> > +++++++++++++++++++++++++++++++++++++++++++-
> >  1 file changed, 46 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/iio/light/isl29018.c
> > b/drivers/iio/light/isl29018.c index b45400f..ec6ce89 100644
> > --- a/drivers/iio/light/isl29018.c
> > +++ b/drivers/iio/light/isl29018.c
> > @@ -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,28 @@ 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(&client->dev, isl29018_disable_regulator_action,
> > +				 chip);
> 
> Use devm_add_action_or_reset, then you don't need to call the disable if an
> error occurs in the add_action part...
> 
> > +	if (err) {
> > +		isl29018_disable_regulator_action(chip);
> 
> (will get rid of the line above).

Done in V9 patch, please help review, thanks.

Anson.

> 
> > +		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 +802,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 +812,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 +828,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;


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-08  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-23  6:46 [PATCH V8] iio: light: isl29018: add vcc regulator operation support Anson Huang
2019-01-05 17:42 ` Jonathan Cameron
2019-01-08  9:16   ` Anson Huang

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).