Commit 0bd3d338 authored by David Veenstra's avatar David Veenstra Committed by Jonathan Cameron

staging: iio: ad2s1200: Improve readability with be16_to_cpup

The manual states that the data is contained in the upper 12 bits
of the 16 bits read by spi. The code that extracts these 12 bits
is correct for both be and le machines, but this is not clear
from a first glance.

To improve readability the relevant expressions are replaced
with equivalent expressions that use be16_to_cpup.
Signed-off-by: default avatarDavid Veenstra <davidjulianveenstra@gmail.com>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 8b74816b
...@@ -38,7 +38,7 @@ struct ad2s1200_state { ...@@ -38,7 +38,7 @@ struct ad2s1200_state {
struct spi_device *sdev; struct spi_device *sdev;
int sample; int sample;
int rdvel; int rdvel;
u8 rx[2] ____cacheline_aligned; __be16 rx ____cacheline_aligned;
}; };
static int ad2s1200_read_raw(struct iio_dev *indio_dev, static int ad2s1200_read_raw(struct iio_dev *indio_dev,
...@@ -49,7 +49,6 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, ...@@ -49,7 +49,6 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
{ {
struct ad2s1200_state *st = iio_priv(indio_dev); struct ad2s1200_state *st = iio_priv(indio_dev);
int ret = 0; int ret = 0;
s16 vel;
mutex_lock(&st->lock); mutex_lock(&st->lock);
gpio_set_value(st->sample, 0); gpio_set_value(st->sample, 0);
...@@ -59,7 +58,7 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, ...@@ -59,7 +58,7 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
gpio_set_value(st->sample, 1); gpio_set_value(st->sample, 1);
gpio_set_value(st->rdvel, !!(chan->type == IIO_ANGL)); gpio_set_value(st->rdvel, !!(chan->type == IIO_ANGL));
ret = spi_read(st->sdev, st->rx, 2); ret = spi_read(st->sdev, &st->rx, 2);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
return ret; return ret;
...@@ -67,12 +66,10 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev, ...@@ -67,12 +66,10 @@ static int ad2s1200_read_raw(struct iio_dev *indio_dev,
switch (chan->type) { switch (chan->type) {
case IIO_ANGL: case IIO_ANGL:
*val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); *val = be16_to_cpup(&st->rx) >> 4;
break; break;
case IIO_ANGL_VEL: case IIO_ANGL_VEL:
vel = (((s16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); *val = sign_extend32(be16_to_cpup(&st->rx) >> 4, 11);
vel = sign_extend32(vel, 11);
*val = vel;
break; break;
default: default:
mutex_unlock(&st->lock); mutex_unlock(&st->lock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment