Skip to content

Commit dd7de4c

Browse files
alexandrebellonijic23
authored andcommitted
iio: adc: ti-ads8344: properly byte swap value
The first received byte is the MSB, followed by the LSB so the value needs to be byte swapped. Also, the ADC actually has a delay of one clock on the SPI bus. Read three bytes to get the last bit. Fixes: 8dd2d7c ("iio: adc: Add driver for the TI ADS8344 A/DC chips") Signed-off-by: Alexandre Belloni <[email protected]> Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 0a2bf92 commit dd7de4c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/iio/adc/ti-ads8344.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct ads8344 {
2929
struct mutex lock;
3030

3131
u8 tx_buf ____cacheline_aligned;
32-
u16 rx_buf;
32+
u8 rx_buf[3];
3333
};
3434

3535
#define ADS8344_VOLTAGE_CHANNEL(chan, si) \
@@ -89,11 +89,11 @@ static int ads8344_adc_conversion(struct ads8344 *adc, int channel,
8989

9090
udelay(9);
9191

92-
ret = spi_read(spi, &adc->rx_buf, 2);
92+
ret = spi_read(spi, adc->rx_buf, sizeof(adc->rx_buf));
9393
if (ret)
9494
return ret;
9595

96-
return adc->rx_buf;
96+
return adc->rx_buf[0] << 9 | adc->rx_buf[1] << 1 | adc->rx_buf[2] >> 7;
9797
}
9898

9999
static int ads8344_read_raw(struct iio_dev *iio,

0 commit comments

Comments
 (0)