linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: isl29018: Support suspend and resume.
@ 2012-10-24 23:39 Bryan Freed
  2012-11-02  9:53 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Bryan Freed @ 2012-10-24 23:39 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-iio, jic23, gregkh, lars, Bryan Freed

The driver leaves the device in power-down state anyway,
so there is nothing to do on suspend.
On resume, we just have to make sure the range and ADC
values are updated in the device since it may have been
powered down in suspend.

Signed-off-by: Bryan Freed <bfreed@chromium.org>
---
 drivers/staging/iio/light/isl29018.c |   45 ++++++++++++++++++++++++++++++++++
 1 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
index 6ee5567..3b03f6f 100644
--- a/drivers/staging/iio/light/isl29018.c
+++ b/drivers/staging/iio/light/isl29018.c
@@ -67,6 +67,7 @@ struct isl29018_chip {
 	unsigned int		range;
 	unsigned int		adc_bit;
 	int			prox_scheme;
+	bool			suspended;
 };
 
 static int isl29018_set_range(struct isl29018_chip *chip, unsigned long range,
@@ -368,6 +369,10 @@ static int isl29018_read_raw(struct iio_dev *indio_dev,
 	struct isl29018_chip *chip = iio_priv(indio_dev);
 
 	mutex_lock(&chip->lock);
+	if (chip->suspended) {
+		mutex_unlock(&chip->lock);
+		return -EBUSY;
+	}
 	switch (mask) {
 	case IIO_CHAN_INFO_RAW:
 	case IIO_CHAN_INFO_PROCESSED:
@@ -561,6 +566,7 @@ static int __devinit isl29018_probe(struct i2c_client *client,
 	chip->lux_scale = 1;
 	chip->range = 1000;
 	chip->adc_bit = 16;
+	chip->suspended = false;
 
 	chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config);
 	if (IS_ERR(chip->regmap)) {
@@ -603,6 +609,44 @@ static int __devexit isl29018_remove(struct i2c_client *client)
 	return 0;
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int isl29018_suspend(struct device *dev)
+{
+	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
+
+	mutex_lock(&chip->lock);
+
+	/* Since this driver uses only polling commands, we are by default in
+	 * auto shutdown (ie, power-down) mode.
+	 * So we do not have much to do here.
+	 */
+	chip->suspended = true;
+
+	mutex_unlock(&chip->lock);
+	return 0;
+}
+
+static int isl29018_resume(struct device *dev)
+{
+	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
+	int err;
+
+	mutex_lock(&chip->lock);
+
+	err = isl29018_chip_init(chip);
+	if (!err)
+		chip->suspended = false;
+
+	mutex_unlock(&chip->lock);
+	return err;
+}
+
+static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume);
+#define ISL29018_PM_OPS (&isl29018_pm_ops)
+#else
+#define ISL29018_PM_OPS NULL
+#endif
+
 static const struct i2c_device_id isl29018_id[] = {
 	{"isl29018", 0},
 	{}
@@ -620,6 +664,7 @@ static struct i2c_driver isl29018_driver = {
 	.class	= I2C_CLASS_HWMON,
 	.driver	 = {
 			.name = "isl29018",
+			.pm = ISL29018_PM_OPS,
 			.owner = THIS_MODULE,
 			.of_match_table = isl29018_of_match,
 		    },
-- 
1.7.7.3


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

* Re: [PATCH] iio: isl29018: Support suspend and resume.
  2012-10-24 23:39 [PATCH] iio: isl29018: Support suspend and resume Bryan Freed
@ 2012-11-02  9:53 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2012-11-02  9:53 UTC (permalink / raw)
  To: Bryan Freed; +Cc: linux-kernel, linux-iio, jic23, gregkh, lars

On 10/25/2012 12:39 AM, Bryan Freed wrote:
> The driver leaves the device in power-down state anyway,
> so there is nothing to do on suspend.
> On resume, we just have to make sure the range and ADC
> values are updated in the device since it may have been
> powered down in suspend.
> 
> Signed-off-by: Bryan Freed <bfreed@chromium.org>
Added to togreg branch of iio.git
though the various uses of power down in the description had
me scratching my head for a second.

I'm guessing auto power-down means the chip is locally disabled
but in suspend it's possible the power supply will be cut
to the chip rather than it simply powering down internally...
> ---
>  drivers/staging/iio/light/isl29018.c |   45 ++++++++++++++++++++++++++++++++++
>  1 files changed, 45 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/staging/iio/light/isl29018.c b/drivers/staging/iio/light/isl29018.c
> index 6ee5567..3b03f6f 100644
> --- a/drivers/staging/iio/light/isl29018.c
> +++ b/drivers/staging/iio/light/isl29018.c
> @@ -67,6 +67,7 @@ struct isl29018_chip {
>  	unsigned int		range;
>  	unsigned int		adc_bit;
>  	int			prox_scheme;
> +	bool			suspended;
>  };
>  
>  static int isl29018_set_range(struct isl29018_chip *chip, unsigned long range,
> @@ -368,6 +369,10 @@ static int isl29018_read_raw(struct iio_dev *indio_dev,
>  	struct isl29018_chip *chip = iio_priv(indio_dev);
>  
>  	mutex_lock(&chip->lock);
> +	if (chip->suspended) {
> +		mutex_unlock(&chip->lock);
> +		return -EBUSY;
> +	}
>  	switch (mask) {
>  	case IIO_CHAN_INFO_RAW:
>  	case IIO_CHAN_INFO_PROCESSED:
> @@ -561,6 +566,7 @@ static int __devinit isl29018_probe(struct i2c_client *client,
>  	chip->lux_scale = 1;
>  	chip->range = 1000;
>  	chip->adc_bit = 16;
> +	chip->suspended = false;
>  
>  	chip->regmap = devm_regmap_init_i2c(client, &isl29018_regmap_config);
>  	if (IS_ERR(chip->regmap)) {
> @@ -603,6 +609,44 @@ static int __devexit isl29018_remove(struct i2c_client *client)
>  	return 0;
>  }
>  
> +#ifdef CONFIG_PM_SLEEP
> +static int isl29018_suspend(struct device *dev)
> +{
> +	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
> +
> +	mutex_lock(&chip->lock);
> +
> +	/* Since this driver uses only polling commands, we are by default in
> +	 * auto shutdown (ie, power-down) mode.
> +	 * So we do not have much to do here.
> +	 */
> +	chip->suspended = true;
> +
> +	mutex_unlock(&chip->lock);
> +	return 0;
> +}
> +
> +static int isl29018_resume(struct device *dev)
> +{
> +	struct isl29018_chip *chip = iio_priv(dev_get_drvdata(dev));
> +	int err;
> +
> +	mutex_lock(&chip->lock);
> +
> +	err = isl29018_chip_init(chip);
> +	if (!err)
> +		chip->suspended = false;
> +
> +	mutex_unlock(&chip->lock);
> +	return err;
> +}
> +
> +static SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume);
> +#define ISL29018_PM_OPS (&isl29018_pm_ops)
> +#else
> +#define ISL29018_PM_OPS NULL
> +#endif
> +
>  static const struct i2c_device_id isl29018_id[] = {
>  	{"isl29018", 0},
>  	{}
> @@ -620,6 +664,7 @@ static struct i2c_driver isl29018_driver = {
>  	.class	= I2C_CLASS_HWMON,
>  	.driver	 = {
>  			.name = "isl29018",
> +			.pm = ISL29018_PM_OPS,
>  			.owner = THIS_MODULE,
>  			.of_match_table = isl29018_of_match,
>  		    },
> 

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

end of thread, other threads:[~2012-11-02  9:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-24 23:39 [PATCH] iio: isl29018: Support suspend and resume Bryan Freed
2012-11-02  9:53 ` Jonathan Cameron

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