Skip to content

Commit 6327a93

Browse files
Ian Rayjic23
authored andcommitted
drivers: iio: adc: ltc2497: fix LSB shift
Correct the "sub_lsb" shift for the ltc2497 and drop the sub_lsb element which is now constant. An earlier version of the code shifted by 14 but this was a consequence of reading three bytes into a __be32 buffer and using be32_to_cpu(), so eight extra bits needed to be skipped. Now we use get_unaligned_be24() and thus the additional skip is wrong. Fixes: 2187cfe ("drivers: iio: adc: ltc2497: LTC2499 support") Signed-off-by: Ian Ray <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 701c875 commit 6327a93

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

drivers/iio/adc/ltc2497.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct ltc2497_driverdata {
2828
struct ltc2497core_driverdata common_ddata;
2929
struct i2c_client *client;
3030
u32 recv_size;
31-
u32 sub_lsb;
3231
/*
3332
* DMA (thus cache coherency maintenance) may require the
3433
* transfer buffers to live in their own cache lines.
@@ -65,10 +64,10 @@ static int ltc2497_result_and_measure(struct ltc2497core_driverdata *ddata,
6564
* equivalent to a sign extension.
6665
*/
6766
if (st->recv_size == 3) {
68-
*val = (get_unaligned_be24(st->data.d8) >> st->sub_lsb)
67+
*val = (get_unaligned_be24(st->data.d8) >> 6)
6968
- BIT(ddata->chip_info->resolution + 1);
7069
} else {
71-
*val = (be32_to_cpu(st->data.d32) >> st->sub_lsb)
70+
*val = (be32_to_cpu(st->data.d32) >> 6)
7271
- BIT(ddata->chip_info->resolution + 1);
7372
}
7473

@@ -122,7 +121,6 @@ static int ltc2497_probe(struct i2c_client *client)
122121
st->common_ddata.chip_info = chip_info;
123122

124123
resolution = chip_info->resolution;
125-
st->sub_lsb = 31 - (resolution + 1);
126124
st->recv_size = BITS_TO_BYTES(resolution) + 1;
127125

128126
return ltc2497core_probe(dev, indio_dev);

0 commit comments

Comments
 (0)