iio: adc: stm32-dfsdm: fix output resolution
authorOlivier Moysan <olivier.moysan@st.com>
Wed, 19 Jun 2019 13:03:47 +0000 (15:03 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 22 Jun 2019 09:18:51 +0000 (10:18 +0100)
commit12c8398d8012ead3d3d68422067ab2f9a66ae76a
treeb584c48350b74af2f997051d6e77fa5a382281a7
parentc2a0ffdc255101fccae1c5daa4459292d6fc8dd2
iio: adc: stm32-dfsdm: fix output resolution

In buffered mode, output samples are shifted left
unconditionally. This works for filter order 3,
but this shift is not adapted for other filter orders.
Compute required shift, left or right, and shift
output data accordingly.
Add also saturation management to avoid wrap-around
when maximum positive sample is reached.

Signed-off-by: Olivier Moysan <olivier.moysan@st.com>
Fixes: eca949800d2d ("IIO: ADC: add stm32 DFSDM support for PDM microphone")
Acked-by: Fabrice Gasnier <fabrice.gasnier@st.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/stm32-dfsdm-adc.c
drivers/iio/adc/stm32-dfsdm.h