diff options
author | Guenter Roeck <linux@roeck-us.net> | 2013-01-31 21:43:00 +0000 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2013-02-02 10:08:23 +0000 |
commit | 482bb4e6c648a68598cde9d4a56b066df26d5ae6 (patch) | |
tree | 04fe848f0b03e4e022dba2abc73fe35f1c24ed49 /drivers/iio/adc/max1363.c | |
parent | dcb9ca0a25e1ccab9ad6827887c08e2b6b65f38e (diff) | |
download | op-kernel-dev-482bb4e6c648a68598cde9d4a56b066df26d5ae6.zip op-kernel-dev-482bb4e6c648a68598cde9d4a56b066df26d5ae6.tar.gz |
iio/adc: (max1363) Fix data conversion problems
For chips with more than 8 bit ADC resolution, received data was always
masked against 0xfff, ie with a 12 bit mask. This can result in bad data
for chips with 10 bit resolution if those chips have higher bits set
(seen with MAX1139).
The receive buffer was defined as char array. This could result in
unintentional sign extensions if the upper bit in a received byte
was set. Since the chip is configured for unipolar mode, we never
have to handle negative values, and sign extensions are never needed.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/adc/max1363.c')
-rw-r--r-- | drivers/iio/adc/max1363.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/drivers/iio/adc/max1363.c b/drivers/iio/adc/max1363.c index 77c123f..4673238 100644 --- a/drivers/iio/adc/max1363.c +++ b/drivers/iio/adc/max1363.c @@ -335,7 +335,7 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, { int ret = 0; s32 data; - char rxbuf[2]; + u8 rxbuf[2]; struct max1363_state *st = iio_priv(indio_dev); struct i2c_client *client = st->client; @@ -367,7 +367,8 @@ static int max1363_read_single_chan(struct iio_dev *indio_dev, ret = data; goto error_ret; } - data = (s32)(rxbuf[1]) | ((s32)(rxbuf[0] & 0x0F)) << 8; + data = (rxbuf[1] | rxbuf[0] << 8) & + ((1 << st->chip_info->bits) - 1); } else { /* Get reading */ data = i2c_master_recv(client, rxbuf, 1); |