Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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



commit 53eaa9c27fdc01b4f4d885223e29f97393409e7e 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: 1615fe41a195 ("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
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -122,6 +122,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6050,
		.config = &chip_config_6050,
		.fifo_size = 1024,
		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU6500_WHOAMI_VALUE,
@@ -129,6 +130,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6500,
		.config = &chip_config_6050,
		.fifo_size = 512,
		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU6515_WHOAMI_VALUE,
@@ -136,6 +138,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6500,
		.config = &chip_config_6050,
		.fifo_size = 512,
		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU6000_WHOAMI_VALUE,
@@ -143,6 +146,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6050,
		.config = &chip_config_6050,
		.fifo_size = 1024,
		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU9150_WHOAMI_VALUE,
@@ -150,6 +154,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6050,
		.config = &chip_config_6050,
		.fifo_size = 1024,
		.temp = {INV_MPU6050_TEMP_OFFSET, INV_MPU6050_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU9250_WHOAMI_VALUE,
@@ -157,6 +162,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6500,
		.config = &chip_config_6050,
		.fifo_size = 512,
		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
	},
	{
		.whoami = INV_MPU9255_WHOAMI_VALUE,
@@ -164,6 +170,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6500,
		.config = &chip_config_6050,
		.fifo_size = 512,
		.temp = {INV_MPU6500_TEMP_OFFSET, INV_MPU6500_TEMP_SCALE},
	},
	{
		.whoami = INV_ICM20608_WHOAMI_VALUE,
@@ -171,6 +178,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_6500,
		.config = &chip_config_6050,
		.fifo_size = 512,
		.temp = {INV_ICM20608_TEMP_OFFSET, INV_ICM20608_TEMP_SCALE},
	},
	{
		.whoami = INV_ICM20602_WHOAMI_VALUE,
@@ -178,6 +186,7 @@ static const struct inv_mpu6050_hw hw_info[] = {
		.reg = &reg_set_icm20602,
		.config = &chip_config_6050,
		.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,

			return IIO_VAL_INT_PLUS_MICRO;
		case IIO_TEMP:
			*val = 0;
			if (st->chip_type == INV_ICM20602)
				*val2 = INV_ICM20602_TEMP_SCALE;
			else
				*val2 = INV_MPU6050_TEMP_SCALE;

			*val = st->hw->temp.scale / 1000000;
			*val2 = st->hw->temp.scale % 1000000;
			return IIO_VAL_INT_PLUS_MICRO;
		default:
			return -EINVAL;
@@ -491,11 +496,7 @@ inv_mpu6050_read_raw(struct iio_dev *indio_dev,
	case IIO_CHAN_INFO_OFFSET:
		switch (chan->type) {
		case IIO_TEMP:
			if (st->chip_type == INV_ICM20602)
				*val = INV_ICM20602_TEMP_OFFSET;
			else
				*val = INV_MPU6050_TEMP_OFFSET;

			*val = st->hw->temp.offset;
			return IIO_VAL_INT;
		default:
			return -EINVAL;
+12 −4
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ struct inv_mpu6050_chip_config {
 *  @reg:   register map of the chip.
 *  @config:    configuration of the chip.
 *  @fifo_size:	size of the FIFO in bytes.
 *  @temp:	offset and scale to apply to raw temperature.
 */
struct inv_mpu6050_hw {
	u8 whoami;
@@ -116,6 +117,10 @@ struct inv_mpu6050_hw {
	const struct inv_mpu6050_reg_map *reg;
	const struct inv_mpu6050_chip_config *config;
	size_t fifo_size;
	struct {
		int offset;
		int scale;
	} temp;
};

/*
@@ -224,16 +229,19 @@ struct inv_mpu6050_state {
#define INV_MPU6050_REG_UP_TIME_MIN          5000
#define INV_MPU6050_REG_UP_TIME_MAX          10000

#define INV_MPU6050_TEMP_OFFSET	             12421
#define INV_MPU6050_TEMP_SCALE               2941
#define INV_MPU6050_TEMP_OFFSET	             12420
#define INV_MPU6050_TEMP_SCALE               2941176
#define INV_MPU6050_MAX_GYRO_FS_PARAM        3
#define INV_MPU6050_MAX_ACCL_FS_PARAM        3
#define INV_MPU6050_THREE_AXIS               3
#define INV_MPU6050_GYRO_CONFIG_FSR_SHIFT    3
#define INV_MPU6050_ACCL_CONFIG_FSR_SHIFT    3

#define INV_ICM20602_TEMP_OFFSET	     8170
#define INV_ICM20602_TEMP_SCALE		     3060
#define INV_MPU6500_TEMP_OFFSET              7011
#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 */
#define INV_MPU6050_OUTPUT_DATA_SIZE         24