bool hysteresis;
u8 resolution;
enum ad2s1210_mode mode;
- u8 rx[2] __aligned(IIO_DMA_MINALIGN);
+ /** For reading raw sample value via SPI. */
+ __be16 sample __aligned(IIO_DMA_MINALIGN);
+ /** SPI transmit buffer. */
+ u8 rx[2];
+ /** SPI receive buffer. */
u8 tx[2];
};
long m)
{
struct ad2s1210_state *st = iio_priv(indio_dev);
- u16 negative;
int ret = 0;
- u16 pos;
- s16 vel;
mutex_lock(&st->lock);
gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0);
}
if (ret < 0)
goto error_ret;
- ret = spi_read(st->sdev, st->rx, 2);
+ ret = spi_read(st->sdev, &st->sample, 2);
if (ret < 0)
goto error_ret;
switch (chan->type) {
case IIO_ANGL:
- pos = be16_to_cpup((__be16 *)st->rx);
- if (st->hysteresis)
- pos >>= 16 - st->resolution;
- *val = pos;
+ *val = be16_to_cpu(st->sample);
ret = IIO_VAL_INT;
break;
case IIO_ANGL_VEL:
- vel = be16_to_cpup((__be16 *)st->rx);
- vel >>= 16 - st->resolution;
- if (vel & 0x8000) {
- negative = (0xffff >> st->resolution) << st->resolution;
- vel |= negative;
- }
- *val = vel;
+ *val = (s16)be16_to_cpu(st->sample);
ret = IIO_VAL_INT;
break;
default: