Skip to content

Commit f73c730

Browse files
digetxjic23
authored andcommitted
iio: gyro: mpu3050: Fix reported temperature value
The raw temperature value is a 16-bit signed integer. The sign casting is missing in the code, which results in a wrong temperature reported by userspace tools, fix it. Cc: [email protected] Fixes: 3904b28 ("iio: gyro: Add driver for the MPU-3050 gyroscope") Datasheet: https://www.cdiweb.com/datasheets/invensense/mpu-3000a.pdf Tested-by: Maxim Schwalm <[email protected]> # Asus TF700T Tested-by: Svyatoslav Ryhel <[email protected]> # Asus TF201 Reported-by: Svyatoslav Ryhel <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: Dmitry Osipenko <[email protected]> Acked-by: Jean-Baptiste Maneyrol <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 7061803 commit f73c730

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/iio/gyro/mpu3050-core.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,16 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
272272
case IIO_CHAN_INFO_OFFSET:
273273
switch (chan->type) {
274274
case IIO_TEMP:
275-
/* The temperature scaling is (x+23000)/280 Celsius */
275+
/*
276+
* The temperature scaling is (x+23000)/280 Celsius
277+
* for the "best fit straight line" temperature range
278+
* of -30C..85C. The 23000 includes room temperature
279+
* offset of +35C, 280 is the precision scale and x is
280+
* the 16-bit signed integer reported by hardware.
281+
*
282+
* Temperature value itself represents temperature of
283+
* the sensor die.
284+
*/
276285
*val = 23000;
277286
return IIO_VAL_INT;
278287
default:
@@ -329,7 +338,7 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
329338
goto out_read_raw_unlock;
330339
}
331340

332-
*val = be16_to_cpu(raw_val);
341+
*val = (s16)be16_to_cpu(raw_val);
333342
ret = IIO_VAL_INT;
334343

335344
goto out_read_raw_unlock;

0 commit comments

Comments
 (0)