Skip to content

Commit

Permalink
staging:iio:adis16080: Perform sign extension
Browse files Browse the repository at this point in the history
The adis16080 reports sample values in twos complement. So we need to perform a
sign extension on the result, otherwise negative values will be reported
incorrectly as large positive values.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
  • Loading branch information
Lars-Peter Clausen authored and Jonathan Cameron committed Jan 9, 2013
1 parent 7b7a4ef commit a02a8c4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/staging/iio/gyro/adis16080_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static int adis16080_spi_read(struct iio_dev *indio_dev,
ret = spi_read(st->us, st->buf, 2);

if (ret == 0)
*val = ((st->buf[0] & 0xF) << 8) | st->buf[1];
*val = sign_extend32(((st->buf[0] & 0xF) << 8) | st->buf[1], 11);
mutex_unlock(&st->buf_lock);

return ret;
Expand Down

0 comments on commit a02a8c4

Please sign in to comment.