iio:inv-mpu6050: Fix inconsistency for the scale channel
Fix inconsistency in the semantics of the scale attribute. For scale the write_raw function was considering the scale table index and writing the appropriate value into the range register, while for read_raw it was outputting the actual scale. Fix this behaviour and adhere to the iio ABI specification. Signed-off-by: Adriana Reus <adriana.reus@intel.com> Reviewed-by: Viorel Suman <viorel.suman@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
ed170dedd1
commit
af5e1a6831
|
@ -410,42 +410,46 @@ error_read_raw:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inv_mpu6050_write_fsr(struct inv_mpu6050_state *st, int fsr)
|
static int inv_mpu6050_write_gyro_scale(struct inv_mpu6050_state *st, int val)
|
||||||
{
|
{
|
||||||
int result;
|
int result, i;
|
||||||
u8 d;
|
u8 d;
|
||||||
|
|
||||||
if (fsr < 0 || fsr > INV_MPU6050_MAX_GYRO_FS_PARAM)
|
for (i = 0; i < ARRAY_SIZE(gyro_scale_6050); ++i) {
|
||||||
return -EINVAL;
|
if (gyro_scale_6050[i] == val) {
|
||||||
if (fsr == st->chip_config.fsr)
|
d = (i << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
|
||||||
return 0;
|
result = inv_mpu6050_write_reg(st,
|
||||||
|
st->reg->gyro_config, d);
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
d = (fsr << INV_MPU6050_GYRO_CONFIG_FSR_SHIFT);
|
st->chip_config.fsr = i;
|
||||||
result = inv_mpu6050_write_reg(st, st->reg->gyro_config, d);
|
return 0;
|
||||||
if (result)
|
}
|
||||||
return result;
|
}
|
||||||
st->chip_config.fsr = fsr;
|
|
||||||
|
|
||||||
return 0;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inv_mpu6050_write_accel_fs(struct inv_mpu6050_state *st, int fs)
|
static int inv_mpu6050_write_accel_scale(struct inv_mpu6050_state *st, int val)
|
||||||
{
|
{
|
||||||
int result;
|
int result, i;
|
||||||
u8 d;
|
u8 d;
|
||||||
|
|
||||||
if (fs < 0 || fs > INV_MPU6050_MAX_ACCL_FS_PARAM)
|
for (i = 0; i < ARRAY_SIZE(accel_scale); ++i) {
|
||||||
return -EINVAL;
|
if (accel_scale[i] == val) {
|
||||||
if (fs == st->chip_config.accl_fs)
|
d = (i << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
|
||||||
return 0;
|
result = inv_mpu6050_write_reg(st,
|
||||||
|
st->reg->accl_config, d);
|
||||||
|
if (result)
|
||||||
|
return result;
|
||||||
|
|
||||||
d = (fs << INV_MPU6050_ACCL_CONFIG_FSR_SHIFT);
|
st->chip_config.accl_fs = i;
|
||||||
result = inv_mpu6050_write_reg(st, st->reg->accl_config, d);
|
return 0;
|
||||||
if (result)
|
}
|
||||||
return result;
|
}
|
||||||
st->chip_config.accl_fs = fs;
|
|
||||||
|
|
||||||
return 0;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
|
static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
|
||||||
|
@ -471,10 +475,10 @@ static int inv_mpu6050_write_raw(struct iio_dev *indio_dev,
|
||||||
case IIO_CHAN_INFO_SCALE:
|
case IIO_CHAN_INFO_SCALE:
|
||||||
switch (chan->type) {
|
switch (chan->type) {
|
||||||
case IIO_ANGL_VEL:
|
case IIO_ANGL_VEL:
|
||||||
result = inv_mpu6050_write_fsr(st, val);
|
result = inv_mpu6050_write_gyro_scale(st, val2);
|
||||||
break;
|
break;
|
||||||
case IIO_ACCEL:
|
case IIO_ACCEL:
|
||||||
result = inv_mpu6050_write_accel_fs(st, val);
|
result = inv_mpu6050_write_accel_scale(st, val2);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result = -EINVAL;
|
result = -EINVAL;
|
||||||
|
|
Loading…
Reference in a new issue