Commit 79de2ee4 authored by Jonathan Cameron's avatar Jonathan Cameron

iio: accel: mma8452: claim direct mode during write raw

Driver was checking for direct mode but not locking it.  Use
claim/release helper functions to guarantee the device stays
in direct mode during all write raw operations.
Signed-off-by: default avatarAlison Schofield <amsfield22@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 4d9b0413
...@@ -666,37 +666,46 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -666,37 +666,46 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
struct mma8452_data *data = iio_priv(indio_dev); struct mma8452_data *data = iio_priv(indio_dev);
int i, ret; int i, ret;
if (iio_buffer_enabled(indio_dev)) ret = iio_device_claim_direct_mode(indio_dev);
return -EBUSY; if (ret)
return ret;
switch (mask) { switch (mask) {
case IIO_CHAN_INFO_SAMP_FREQ: case IIO_CHAN_INFO_SAMP_FREQ:
i = mma8452_get_samp_freq_index(data, val, val2); i = mma8452_get_samp_freq_index(data, val, val2);
if (i < 0) if (i < 0) {
return i; ret = i;
break;
}
data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK; data->ctrl_reg1 &= ~MMA8452_CTRL_DR_MASK;
data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT; data->ctrl_reg1 |= i << MMA8452_CTRL_DR_SHIFT;
return mma8452_change_config(data, MMA8452_CTRL_REG1, ret = mma8452_change_config(data, MMA8452_CTRL_REG1,
data->ctrl_reg1); data->ctrl_reg1);
break;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
i = mma8452_get_scale_index(data, val, val2); i = mma8452_get_scale_index(data, val, val2);
if (i < 0) if (i < 0) {
return i; ret = i;
break;
}
data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK; data->data_cfg &= ~MMA8452_DATA_CFG_FS_MASK;
data->data_cfg |= i; data->data_cfg |= i;
return mma8452_change_config(data, MMA8452_DATA_CFG, ret = mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
break;
case IIO_CHAN_INFO_CALIBBIAS: case IIO_CHAN_INFO_CALIBBIAS:
if (val < -128 || val > 127) if (val < -128 || val > 127) {
return -EINVAL; ret = -EINVAL;
break;
}
return mma8452_change_config(data, ret = mma8452_change_config(data,
MMA8452_OFF_X + chan->scan_index, MMA8452_OFF_X + chan->scan_index,
val); val);
break;
case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY: case IIO_CHAN_INFO_HIGH_PASS_FILTER_3DB_FREQUENCY:
if (val == 0 && val2 == 0) { if (val == 0 && val2 == 0) {
...@@ -705,23 +714,30 @@ static int mma8452_write_raw(struct iio_dev *indio_dev, ...@@ -705,23 +714,30 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
data->data_cfg |= MMA8452_DATA_CFG_HPF_MASK; data->data_cfg |= MMA8452_DATA_CFG_HPF_MASK;
ret = mma8452_set_hp_filter_frequency(data, val, val2); ret = mma8452_set_hp_filter_frequency(data, val, val2);
if (ret < 0) if (ret < 0)
return ret; break;
} }
return mma8452_change_config(data, MMA8452_DATA_CFG, ret = mma8452_change_config(data, MMA8452_DATA_CFG,
data->data_cfg); data->data_cfg);
break;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO: case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
ret = mma8452_get_odr_index(data); ret = mma8452_get_odr_index(data);
for (i = 0; i < ARRAY_SIZE(mma8452_os_ratio); i++) { for (i = 0; i < ARRAY_SIZE(mma8452_os_ratio); i++) {
if (mma8452_os_ratio[i][ret] == val) if (mma8452_os_ratio[i][ret] == val) {
return mma8452_set_power_mode(data, i); ret = mma8452_set_power_mode(data, i);
break;
} }
}
break;
default: default:
return -EINVAL; ret = -EINVAL;
break;
} }
iio_device_release_direct_mode(indio_dev);
return ret;
} }
static int mma8452_read_thresh(struct iio_dev *indio_dev, static int mma8452_read_thresh(struct iio_dev *indio_dev,
......
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