Commit 8b462a32 authored by Jean-Baptiste Maneyrol's avatar Jean-Baptiste Maneyrol Committed by Greg Kroah-Hartman

iio: imu: inv_mpu6050: fix temperature reporting using bad unit

commit 53eaa9c2 upstream.

Temperature should be reported in milli-degrees, not degrees. Fix
scale and offset values to use the correct unit.

This is a fix for an issue that has been present for a long time.
The fixes tag reflects the point at which the code last changed in a
fashion that would make this fix patch no longer apply.  Backports
will be necessary to fix those elements that predate that patch.

Fixes: 1615fe41 ("iio: imu: mpu6050: Fix FIFO layout for ICM20602")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarJean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 299f9959
...@@ -122,6 +122,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -122,6 +122,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6050, .reg = &reg_set_6050,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 1024, .fifo_size = 1024,
.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU6500_WHOAMI_VALUE, .whoami = INV_MPU6500_WHOAMI_VALUE,
...@@ -129,6 +130,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -129,6 +130,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 512, .fifo_size = 512,
.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU6515_WHOAMI_VALUE, .whoami = INV_MPU6515_WHOAMI_VALUE,
...@@ -136,6 +138,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -136,6 +138,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 512, .fifo_size = 512,
.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU6000_WHOAMI_VALUE, .whoami = INV_MPU6000_WHOAMI_VALUE,
...@@ -143,6 +146,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -143,6 +146,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6050, .reg = &reg_set_6050,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 1024, .fifo_size = 1024,
.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU9150_WHOAMI_VALUE, .whoami = INV_MPU9150_WHOAMI_VALUE,
...@@ -150,6 +154,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -150,6 +154,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6050, .reg = &reg_set_6050,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 1024, .fifo_size = 1024,
.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU9250_WHOAMI_VALUE, .whoami = INV_MPU9250_WHOAMI_VALUE,
...@@ -157,6 +162,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -157,6 +162,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 512, .fifo_size = 512,
.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
}, },
{ {
.whoami = INV_MPU9255_WHOAMI_VALUE, .whoami = INV_MPU9255_WHOAMI_VALUE,
...@@ -164,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -164,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 512, .fifo_size = 512,
.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
}, },
{ {
.whoami = INV_ICM20608_WHOAMI_VALUE, .whoami = INV_ICM20608_WHOAMI_VALUE,
...@@ -171,6 +178,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -171,6 +178,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_6500, .reg = &reg_set_6500,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 512, .fifo_size = 512,
.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
}, },
{ {
.whoami = INV_ICM20602_WHOAMI_VALUE, .whoami = INV_ICM20602_WHOAMI_VALUE,
...@@ -178,6 +186,7 @@ static const struct inv_mpu6050_hw hw_info[] = { ...@@ -178,6 +186,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
.reg = &reg_set_icm20602, .reg = &reg_set_icm20602,
.config = &chip_config_6050, .config = &chip_config_6050,
.fifo_size = 1008, .fifo_size = 1008,
.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
}, },
}; };
...@@ -478,12 +487,8 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, ...@@ -478,12 +487,8 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP: case IIO_TEMP:
*val = 0; *val = st->hw->temp.scale / 1000000;
if (st->chip_type == INV_ICM20602) *val2 = st->hw->temp.scale % 1000000;
*val2 = INV_ICM20602_TEMP_SCALE;
else
*val2 = INV_MPU6050_TEMP_SCALE;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
default: default:
return -EINVAL; return -EINVAL;
...@@ -491,11 +496,7 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev, ...@@ -491,11 +496,7 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OFFSET: case IIO_CHAN_INFO_OFFSET:
switch (chan->type) { switch (chan->type) {
case IIO_TEMP: case IIO_TEMP:
if (st->chip_type == INV_ICM20602) *val = st->hw->temp.offset;
*val = INV_ICM20602_TEMP_OFFSET;
else
*val = INV_MPU6050_TEMP_OFFSET;
return IIO_VAL_INT; return IIO_VAL_INT;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -109,6 +109,7 @@ struct inv_mpu6050_chip_config { ...@@ -109,6 +109,7 @@ struct inv_mpu6050_chip_config {
* @reg: register map of the chip. * @reg: register map of the chip.
* @config: configuration of the chip. * @config: configuration of the chip.
* @fifo_size: size of the FIFO in bytes. * @fifo_size: size of the FIFO in bytes.
* @temp: offset and scale to apply to raw temperature.
*/ */
struct inv_mpu6050_hw { struct inv_mpu6050_hw {
u8 whoami; u8 whoami;
...@@ -116,6 +117,10 @@ struct inv_mpu6050_hw { ...@@ -116,6 +117,10 @@ struct inv_mpu6050_hw {
const struct inv_mpu6050_reg_map *reg; const struct inv_mpu6050_reg_map *reg;
const struct inv_mpu6050_chip_config *config; const struct inv_mpu6050_chip_config *config;
size_t fifo_size; size_t fifo_size;
struct {
int offset;
int scale;
} temp;
}; };
/* /*
...@@ -224,16 +229,19 @@ struct inv_mpu6050_state { ...@@ -224,16 +229,19 @@ struct inv_mpu6050_state {
#define INV_MPU6050_REG_UP_TIME_MIN 5000 #define INV_MPU6050_REG_UP_TIME_MIN 5000
#define INV_MPU6050_REG_UP_TIME_MAX 10000 #define INV_MPU6050_REG_UP_TIME_MAX 10000
#define INV_MPU6050_TEMP_OFFSET 12421 #define INV_MPU6050_TEMP_OFFSET 12420
#define INV_MPU6050_TEMP_SCALE 2941 #define INV_MPU6050_TEMP_SCALE 2941176
#define INV_MPU6050_MAX_GYRO_FS_PARAM 3 #define INV_MPU6050_MAX_GYRO_FS_PARAM 3
#define INV_MPU6050_MAX_ACCL_FS_PARAM 3 #define INV_MPU6050_MAX_ACCL_FS_PARAM 3
#define INV_MPU6050_THREE_AXIS 3 #define INV_MPU6050_THREE_AXIS 3
#define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT 3 #define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT 3
#define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT 3 #define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT 3
#define INV_ICM20602_TEMP_OFFSET 8170 #define INV_MPU6500_TEMP_OFFSET 7011
#define INV_ICM20602_TEMP_SCALE 3060 #define INV_MPU6500_TEMP_SCALE 2995178
#define INV_ICM20608_TEMP_OFFSET 8170
#define INV_ICM20608_TEMP_SCALE 3059976
/* 6 + 6 round up and plus 8 */ /* 6 + 6 round up and plus 8 */
#define INV_MPU6050_OUTPUT_DATA_SIZE 24 #define INV_MPU6050_OUTPUT_DATA_SIZE 24
......
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