Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 337592
b: refs/heads/master
c: 1e45cf3
h: refs/heads/master
v: v3
  • Loading branch information
Bryan Freed authored and Jonathan Cameron committed Nov 2, 2012
1 parent 6f5f7b8 commit 213c9e0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ef4f92c064697a66a2a61977dd690af40dc01ff0
refs/heads/master: 1e45cf3c493cb76618558201a8ef6f3a065f9073
45 changes: 45 additions & 0 deletions trunk/drivers/staging/iio/light/isl29018.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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},
{}
Expand All @@ -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,
},
Expand Down

0 comments on commit 213c9e0

Please sign in to comment.