Skip to content

Commit f6dbf83

Browse files
xc-racer99jic23
authored andcommitted
iio: light: gp2ap002: Take runtime PM reference on light read
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]>
1 parent 1ecca8a commit f6dbf83

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

drivers/iio/light/gp2ap002.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ static irqreturn_t gp2ap002_prox_irq(int irq, void *d)
158158
int val;
159159
int ret;
160160

161+
if (!gp2ap002->enabled)
162+
goto err_retrig;
163+
161164
ret = regmap_read(gp2ap002->map, GP2AP002_PROX, &val);
162165
if (ret) {
163166
dev_err(gp2ap002->dev, "error reading proximity\n");
@@ -247,6 +250,8 @@ static int gp2ap002_read_raw(struct iio_dev *indio_dev,
247250
struct gp2ap002 *gp2ap002 = iio_priv(indio_dev);
248251
int ret;
249252

253+
pm_runtime_get_sync(gp2ap002->dev);
254+
250255
switch (mask) {
251256
case IIO_CHAN_INFO_RAW:
252257
switch (chan->type) {
@@ -255,13 +260,21 @@ static int gp2ap002_read_raw(struct iio_dev *indio_dev,
255260
if (ret < 0)
256261
return ret;
257262
*val = ret;
258-
return IIO_VAL_INT;
263+
ret = IIO_VAL_INT;
264+
goto out;
259265
default:
260-
return -EINVAL;
266+
ret = -EINVAL;
267+
goto out;
261268
}
262269
default:
263-
return -EINVAL;
270+
ret = -EINVAL;
264271
}
272+
273+
out:
274+
pm_runtime_mark_last_busy(gp2ap002->dev);
275+
pm_runtime_put_autosuspend(gp2ap002->dev);
276+
277+
return ret;
265278
}
266279

267280
static int gp2ap002_init(struct gp2ap002 *gp2ap002)

0 commit comments

Comments
 (0)