mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-10 05:39:42 -04:00
iio: adc: ti-adc128s052: Simplify using be16_to_cpu()
The register data is 12-bit big-endian data. Use be16_to_cpu() to do the conversion, and simple bitwise AND for masking to make it more obvious. Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com> Link: https://patch.msgid.link/8202060d90221beb9b8cf467606641349ad47fe9.1744022065.git.mazziesaccount@gmail.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
committed by
Jonathan Cameron
parent
085831cfce
commit
7af2ea72d6
@@ -28,7 +28,10 @@ struct adc128 {
|
||||
struct regulator *reg;
|
||||
struct mutex lock;
|
||||
|
||||
u8 buffer[2] __aligned(IIO_DMA_MINALIGN);
|
||||
union {
|
||||
__be16 buffer16;
|
||||
u8 buffer[2];
|
||||
} __aligned(IIO_DMA_MINALIGN);
|
||||
};
|
||||
|
||||
static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
|
||||
@@ -40,20 +43,18 @@ static int adc128_adc_conversion(struct adc128 *adc, u8 channel)
|
||||
adc->buffer[0] = channel << 3;
|
||||
adc->buffer[1] = 0;
|
||||
|
||||
ret = spi_write(adc->spi, &adc->buffer, 2);
|
||||
ret = spi_write(adc->spi, &adc->buffer, sizeof(adc->buffer));
|
||||
if (ret < 0) {
|
||||
mutex_unlock(&adc->lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = spi_read(adc->spi, &adc->buffer, 2);
|
||||
|
||||
ret = spi_read(adc->spi, &adc->buffer16, sizeof(adc->buffer16));
|
||||
mutex_unlock(&adc->lock);
|
||||
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return ((adc->buffer[0] << 8 | adc->buffer[1]) & 0xFFF);
|
||||
return be16_to_cpu(adc->buffer16) & 0xFFF;
|
||||
}
|
||||
|
||||
static int adc128_read_raw(struct iio_dev *indio_dev,
|
||||
|
||||
Reference in New Issue
Block a user