aboutsummaryrefslogtreecommitdiff
path: root/drivers/iio/adc/stm32-dfsdm.h
diff options
context:
space:
mode:
authorOlivier Moysan <olivier.moysan@st.com>2019-06-19 15:03:47 +0200
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2019-06-22 10:18:51 +0100
commit12c8398d8012ead3d3d68422067ab2f9a66ae76a (patch)
treeb584c48350b74af2f997051d6e77fa5a382281a7 /drivers/iio/adc/stm32-dfsdm.h
parentc2a0ffdc255101fccae1c5daa4459292d6fc8dd2 (diff)
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>
Diffstat (limited to 'drivers/iio/adc/stm32-dfsdm.h')
-rw-r--r--drivers/iio/adc/stm32-dfsdm.h24
1 files changed, 19 insertions, 5 deletions
diff --git a/drivers/iio/adc/stm32-dfsdm.h b/drivers/iio/adc/stm32-dfsdm.h
index 8708394b0725..18b06ee6ed7b 100644
--- a/drivers/iio/adc/stm32-dfsdm.h
+++ b/drivers/iio/adc/stm32-dfsdm.h
@@ -243,19 +243,33 @@ enum stm32_dfsdm_sinc_order {
};
/**
- * struct stm32_dfsdm_filter - structure relative to stm32 FDSDM filter
+ * struct stm32_dfsdm_filter_osr - DFSDM filter settings linked to oversampling
* @iosr: integrator oversampling
* @fosr: filter oversampling
- * @ford: filter order
+ * @rshift: output sample right shift (hardware shift)
+ * @lshift: output sample left shift (software shift)
* @res: output sample resolution
+ * @max: output sample maximum positive value
+ */
+struct stm32_dfsdm_filter_osr {
+ unsigned int iosr;
+ unsigned int fosr;
+ unsigned int rshift;
+ unsigned int lshift;
+ u64 res;
+ s32 max;
+};
+
+/**
+ * struct stm32_dfsdm_filter - structure relative to stm32 FDSDM filter
+ * @ford: filter order
+ * @flo: filter oversampling structure
* @sync_mode: filter synchronized with filter 0
* @fast: filter fast mode
*/
struct stm32_dfsdm_filter {
- unsigned int iosr;
- unsigned int fosr;
enum stm32_dfsdm_sinc_order ford;
- u64 res;
+ struct stm32_dfsdm_filter_osr flo;
unsigned int sync_mode;
unsigned int fast;
};