Commit 6792b455 authored by Jean-Baptiste Maneyrol's avatar Jean-Baptiste Maneyrol Committed by Jonathan Cameron

iio: imu: inv_mpu6050: clean read raw by factorizing out raw data

Factorize reading channel data in its own function.
Signed-off-by: default avatarJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 57f1677b
...@@ -332,51 +332,45 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg, ...@@ -332,51 +332,45 @@ static int inv_mpu6050_sensor_show(struct inv_mpu6050_state *st, int reg,
return IIO_VAL_INT; return IIO_VAL_INT;
} }
static int static int inv_mpu6050_read_channel_data(struct iio_dev *indio_dev,
inv_mpu6050_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, struct iio_chan_spec const *chan,
int *val, int *val2, long mask) int *val)
{ {
struct inv_mpu6050_state *st = iio_priv(indio_dev); struct inv_mpu6050_state *st = iio_priv(indio_dev);
int ret = 0;
switch (mask) {
case IIO_CHAN_INFO_RAW:
{
int result; int result;
int ret = IIO_VAL_INT;
ret = IIO_VAL_INT;
mutex_lock(&st->lock);
result = iio_device_claim_direct_mode(indio_dev); result = iio_device_claim_direct_mode(indio_dev);
if (result) if (result)
goto error_read_raw_unlock; return result;
result = inv_mpu6050_set_power_itg(st, true); result = inv_mpu6050_set_power_itg(st, true);
if (result) if (result)
goto error_read_raw_release; goto error_release;
switch (chan->type) { switch (chan->type) {
case IIO_ANGL_VEL: case IIO_ANGL_VEL:
result = inv_mpu6050_switch_engine(st, true, result = inv_mpu6050_switch_engine(st, true,
INV_MPU6050_BIT_PWR_GYRO_STBY); INV_MPU6050_BIT_PWR_GYRO_STBY);
if (result) if (result)
goto error_read_raw_power_off; goto error_power_off;
ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro, ret = inv_mpu6050_sensor_show(st, st->reg->raw_gyro,
chan->channel2, val); chan->channel2, val);
result = inv_mpu6050_switch_engine(st, false, result = inv_mpu6050_switch_engine(st, false,
INV_MPU6050_BIT_PWR_GYRO_STBY); INV_MPU6050_BIT_PWR_GYRO_STBY);
if (result) if (result)
goto error_read_raw_power_off; goto error_power_off;
break; break;
case IIO_ACCEL: case IIO_ACCEL:
result = inv_mpu6050_switch_engine(st, true, result = inv_mpu6050_switch_engine(st, true,
INV_MPU6050_BIT_PWR_ACCL_STBY); INV_MPU6050_BIT_PWR_ACCL_STBY);
if (result) if (result)
goto error_read_raw_power_off; goto error_power_off;
ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl, ret = inv_mpu6050_sensor_show(st, st->reg->raw_accl,
chan->channel2, val); chan->channel2, val);
result = inv_mpu6050_switch_engine(st, false, result = inv_mpu6050_switch_engine(st, false,
INV_MPU6050_BIT_PWR_ACCL_STBY); INV_MPU6050_BIT_PWR_ACCL_STBY);
if (result) if (result)
goto error_read_raw_power_off; goto error_power_off;
break; break;
case IIO_TEMP: case IIO_TEMP:
/* wait for stablization */ /* wait for stablization */
...@@ -388,17 +382,31 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, ...@@ -388,17 +382,31 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
error_read_raw_power_off:
error_power_off:
result |= inv_mpu6050_set_power_itg(st, false); result |= inv_mpu6050_set_power_itg(st, false);
error_read_raw_release: error_release:
iio_device_release_direct_mode(indio_dev); iio_device_release_direct_mode(indio_dev);
error_read_raw_unlock:
mutex_unlock(&st->lock);
if (result) if (result)
return result; return result;
return ret; return ret;
} }
static int
inv_mpu6050_read_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int *val, int *val2, long mask)
{
struct inv_mpu6050_state *st = iio_priv(indio_dev);
int ret = 0;
switch (mask) {
case IIO_CHAN_INFO_RAW:
mutex_lock(&st->lock);
ret = inv_mpu6050_read_channel_data(indio_dev, chan, val);
mutex_unlock(&st->lock);
return ret;
case IIO_CHAN_INFO_SCALE: case IIO_CHAN_INFO_SCALE:
switch (chan->type) { switch (chan->type) {
case IIO_ANGL_VEL: case IIO_ANGL_VEL:
......
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