Commit 218e95e9 authored by Alison Schofield's avatar Alison Schofield Committed by Jonathan Cameron

iio: light: ltr501: claim direct mode during select raw reads

Driver was checking for direct mode but not locking it.  Use
claim/release helper functions to guarantee the device stays
in direct mode during required raw read cases.
Signed-off-by: default avatarAlison Schofield <amsfield22@gmail.com>
Acked-by: default avatarPeter Meerwald-Stadler <pmeerw@pmeerw.net>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent d62e5fee
...@@ -631,14 +631,16 @@ static int ltr501_read_raw(struct iio_dev *indio_dev, ...@@ -631,14 +631,16 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_PROCESSED: case IIO_CHAN_INFO_PROCESSED:
if (iio_buffer_enabled(indio_dev))
return -EBUSY;
switch (chan->type) { switch (chan->type) {
case IIO_LIGHT: case IIO_LIGHT:
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
return ret;
mutex_lock(&data->lock_als); mutex_lock(&data->lock_als);
ret = ltr501_read_als(data, buf); ret = ltr501_read_als(data, buf);
mutex_unlock(&data->lock_als); mutex_unlock(&data->lock_als);
iio_device_release_direct_mode(indio_dev);
if (ret < 0) if (ret < 0)
return ret; return ret;
*val = ltr501_calculate_lux(le16_to_cpu(buf[1]), *val = ltr501_calculate_lux(le16_to_cpu(buf[1]),
...@@ -648,8 +650,9 @@ static int ltr501_read_raw(struct iio_dev *indio_dev, ...@@ -648,8 +650,9 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
return -EINVAL; return -EINVAL;
} }
case IIO_CHAN_INFO_RAW: case IIO_CHAN_INFO_RAW:
if (iio_buffer_enabled(indio_dev)) ret = iio_device_claim_direct_mode(indio_dev);
return -EBUSY; if (ret)
return ret;
switch (chan->type) { switch (chan->type) {
case IIO_INTENSITY: case IIO_INTENSITY:
...@@ -657,21 +660,28 @@ static int ltr501_read_raw(struct iio_dev *indio_dev, ...@@ -657,21 +660,28 @@ static int ltr501_read_raw(struct iio_dev *indio_dev,
ret = ltr501_read_als(data, buf); ret = ltr501_read_als(data, buf);
mutex_unlock(&data->lock_als); mutex_unlock(&data->lock_als);
if (ret < 0) if (ret < 0)
return ret; break;
*val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ? *val = le16_to_cpu(chan->address == LTR501_ALS_DATA1 ?
buf[0] : buf[1]); buf[0] : buf[1]);
return IIO_VAL_INT; ret = IIO_VAL_INT;
break;
case IIO_PROXIMITY: case IIO_PROXIMITY:
mutex_lock(&data->lock_ps); mutex_lock(&data->lock_ps);
ret = ltr501_read_ps(data); ret = ltr501_read_ps(data);
mutex_unlock(&data->lock_ps); mutex_unlock(&data->lock_ps);
if (ret < 0) if (ret < 0)
return ret; break;
*val = ret & LTR501_PS_DATA_MASK; *val = ret & LTR501_PS_DATA_MASK;
return IIO_VAL_INT; ret = IIO_VAL_INT;
break;
default: default:
return -EINVAL; ret = -EINVAL;
break;
} }
iio_device_release_direct_mode(indio_dev);
return ret;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
switch (chan->type) { switch (chan->type) {
case IIO_INTENSITY: case IIO_INTENSITY:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment