Commit ac139805 authored by Alison Schofield's avatar Alison Schofield Committed by Jonathan Cameron

iio: pressure: mpl3115: claim direct mode during 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 raw reads.
Signed-off-by: default avatarAlison Schofield <amsfield22@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 79de2ee4
...@@ -82,8 +82,9 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, ...@@ -82,8 +82,9 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
switch (mask) { switch (mask) {
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_PRESSURE: /* in 0.25 pascal / LSB */ case IIO_PRESSURE: /* in 0.25 pascal / LSB */
...@@ -91,32 +92,39 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev, ...@@ -91,32 +92,39 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
ret = mpl3115_request(data); ret = mpl3115_request(data);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return ret; break;
} }
ret = i2c_smbus_read_i2c_block_data(data->client, ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_PRESS, 3, (u8 *) &tmp); MPL3115_OUT_PRESS, 3, (u8 *) &tmp);
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
if (ret < 0) if (ret < 0)
return ret; break;
*val = be32_to_cpu(tmp) >> 12; *val = be32_to_cpu(tmp) >> 12;
return IIO_VAL_INT; ret = IIO_VAL_INT;
break;
case IIO_TEMP: /* in 0.0625 celsius / LSB */ case IIO_TEMP: /* in 0.0625 celsius / LSB */
mutex_lock(&data->lock); mutex_lock(&data->lock);
ret = mpl3115_request(data); ret = mpl3115_request(data);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
return ret; break;
} }
ret = i2c_smbus_read_i2c_block_data(data->client, ret = i2c_smbus_read_i2c_block_data(data->client,
MPL3115_OUT_TEMP, 2, (u8 *) &tmp); MPL3115_OUT_TEMP, 2, (u8 *) &tmp);
mutex_unlock(&data->lock); mutex_unlock(&data->lock);
if (ret < 0) if (ret < 0)
return ret; break;
*val = sign_extend32(be32_to_cpu(tmp) >> 20, 11); *val = sign_extend32(be32_to_cpu(tmp) >> 20, 11);
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_PRESSURE: case IIO_PRESSURE:
......
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