Commit 7dd04eb0 authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

IIO: GYRO: ADXRS450: Fix sign issues, properly shift results and limit values

RATE and QUADRATURE_CORRECTION data is formatted as a twos complement number,
and therefore must be handled as type signed short.

TEMP result should be properly shifted.

Dynamic Null Correction is a 10-bit signed number.
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8ffc4e72
...@@ -126,7 +126,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev, ...@@ -126,7 +126,7 @@ static int adxrs450_spi_write_reg_16(struct device *dev,
* @dev: device associated with child of actual iio_dev * @dev: device associated with child of actual iio_dev
* @val: somewhere to pass back the value read * @val: somewhere to pass back the value read
**/ **/
static int adxrs450_spi_sensor_data(struct device *dev, u16 *val) static int adxrs450_spi_sensor_data(struct device *dev, s16 *val)
{ {
struct spi_message msg; struct spi_message msg;
struct iio_dev *indio_dev = dev_get_drvdata(dev); struct iio_dev *indio_dev = dev_get_drvdata(dev);
...@@ -217,7 +217,7 @@ static ssize_t adxrs450_read_temp(struct device *dev, ...@@ -217,7 +217,7 @@ static ssize_t adxrs450_read_temp(struct device *dev,
&t); &t);
if (ret) if (ret)
return ret; return ret;
return sprintf(buf, "%d\n", t); return sprintf(buf, "%d\n", t >> 7);
} }
static ssize_t adxrs450_read_quad(struct device *dev, static ssize_t adxrs450_read_quad(struct device *dev,
...@@ -225,7 +225,7 @@ static ssize_t adxrs450_read_quad(struct device *dev, ...@@ -225,7 +225,7 @@ static ssize_t adxrs450_read_quad(struct device *dev,
char *buf) char *buf)
{ {
int ret; int ret;
u16 t; s16 t;
ret = adxrs450_spi_read_reg_16(dev, ret = adxrs450_spi_read_reg_16(dev,
ADXRS450_QUAD1, ADXRS450_QUAD1,
&t); &t);
...@@ -247,7 +247,7 @@ static ssize_t adxrs450_write_dnc(struct device *dev, ...@@ -247,7 +247,7 @@ static ssize_t adxrs450_write_dnc(struct device *dev,
goto error_ret; goto error_ret;
ret = adxrs450_spi_write_reg_16(dev, ret = adxrs450_spi_write_reg_16(dev,
ADXRS450_DNC1, ADXRS450_DNC1,
val); val & 0x3FF);
error_ret: error_ret:
return ret ? ret : len; return ret ? ret : len;
} }
...@@ -257,7 +257,7 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev, ...@@ -257,7 +257,7 @@ static ssize_t adxrs450_read_sensor_data(struct device *dev,
char *buf) char *buf)
{ {
int ret; int ret;
u16 t; s16 t;
ret = adxrs450_spi_sensor_data(dev, &t); ret = adxrs450_spi_sensor_data(dev, &t);
if (ret) if (ret)
......
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