Skip to content

Commit

Permalink
iio: light: gp2ap002: Take runtime PM reference on light read
Browse files Browse the repository at this point in the history
The light sensor needs the regulators to be enabled which means
the runtime PM needs to be on.  This only happened when the
proximity part of the chip was enabled.

As fallout from this change, only report changes to the prox
state in the interrupt handler when it is explicitly enabled.

Fixes: 97d642e ("iio: light: Add a driver for Sharp GP2AP002x00F")
Signed-off-by: Jonathan Bakker <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
xc-racer99 authored and jic23 committed May 22, 2020
1 parent 1ecca8a commit f6dbf83
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions drivers/iio/light/gp2ap002.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ static irqreturn_t gp2ap002_prox_irq(int irq, void *d)
int val;
int ret;

if (!gp2ap002->enabled)
goto err_retrig;

ret = regmap_read(gp2ap002->map, GP2AP002_PROX, &val);
if (ret) {
dev_err(gp2ap002->dev, "error reading proximity\n");
Expand Down Expand Up @@ -247,6 +250,8 @@ static int gp2ap002_read_raw(struct iio_dev *indio_dev,
struct gp2ap002 *gp2ap002 = iio_priv(indio_dev);
int ret;

pm_runtime_get_sync(gp2ap002->dev);

switch (mask) {
case IIO_CHAN_INFO_RAW:
switch (chan->type) {
Expand All @@ -255,13 +260,21 @@ static int gp2ap002_read_raw(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
*val = ret;
return IIO_VAL_INT;
ret = IIO_VAL_INT;
goto out;
default:
return -EINVAL;
ret = -EINVAL;
goto out;
}
default:
return -EINVAL;
ret = -EINVAL;
}

out:
pm_runtime_mark_last_busy(gp2ap002->dev);
pm_runtime_put_autosuspend(gp2ap002->dev);

return ret;
}

static int gp2ap002_init(struct gp2ap002 *gp2ap002)
Expand Down

0 comments on commit f6dbf83

Please sign in to comment.