aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc/stm32-adc-core.h
diff options
context:
space:
mode:
authorOlivier Moysan <olivier.moysan@foss.st.com>2025-04-24 17:16:03 +0200
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2025-05-21 14:20:28 +0100
commitdadf2477e3d67bb8b53ca8b7c2ace720dc5c440f (patch)
tree1b594425f49a05ecac0750bd9d9bcd340ee35f26 /drivers/iio/adc/stm32-adc-core.h
parentstaging: iio: ad5933: Correct settling cycles encoding per datasheet (diff)
downloadlinux-dadf2477e3d67bb8b53ca8b7c2ace720dc5c440f.tar.gz
linux-dadf2477e3d67bb8b53ca8b7c2ace720dc5c440f.zip
iio: adc: stm32: add oversampling support
Add oversampling support for STM32H7, STM32MP15 & STM32MP13. STM32F4 ADC has no oversampling feature. The current support of the oversampling feature aims at increasing the data SNR, without changing the data resolution. As the oversampling by itself increases data resolution, a right shift is applied to keep the initial resolution. Only the oversampling ratio corresponding to a power of two are supported here, to get a direct link between right shift and oversampling ratio. (2^n ratio <=> n right shift) The oversampling ratio is shared by all channels, whatever channel type. (e.g. single ended or differential). Oversampling can be configured using IIO ABI: - oversampling_ratio_available - oversampling_ratio Co-developed-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@foss.st.com> Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com> Reviewed-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Andy Shevchenko <andy@kernel.org> Link: https://patch.msgid.link/20250424151604.626758-1-olivier.moysan@foss.st.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc/stm32-adc-core.h')
-rw-r--r--drivers/iio/adc/stm32-adc-core.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/drivers/iio/adc/stm32-adc-core.h b/drivers/iio/adc/stm32-adc-core.h
index 73b2c2e91c08..db50a9f3b922 100644
--- a/drivers/iio/adc/stm32-adc-core.h
+++ b/drivers/iio/adc/stm32-adc-core.h
@@ -10,6 +10,9 @@
#ifndef __STM32_ADC_H
#define __STM32_ADC_H
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+
/*
* STM32 - ADC global register map
* ________________________________________________________
@@ -91,6 +94,7 @@
#define STM32H7_ADC_IER 0x04
#define STM32H7_ADC_CR 0x08
#define STM32H7_ADC_CFGR 0x0C
+#define STM32H7_ADC_CFGR2 0x10
#define STM32H7_ADC_SMPR1 0x14
#define STM32H7_ADC_SMPR2 0x18
#define STM32H7_ADC_PCSEL 0x1C
@@ -160,6 +164,13 @@
#define STM32H7_DMNGT_SHIFT 0
#define STM32H7_DMNGT_MASK GENMASK(1, 0)
+/* STM32H7_ADC_CFGR2 bit fields */
+#define STM32H7_OVSR_MASK GENMASK(25, 16) /* Correspond to OSVR field in datasheet */
+#define STM32H7_OVSR(v) FIELD_PREP(STM32H7_OVSR_MASK, v)
+#define STM32H7_OVSS_MASK GENMASK(8, 5)
+#define STM32H7_OVSS(v) FIELD_PREP(STM32H7_OVSS_MASK, v)
+#define STM32H7_ROVSE BIT(0)
+
enum stm32h7_adc_dmngt {
STM32H7_DMNGT_DR_ONLY, /* Regular data in DR only */
STM32H7_DMNGT_DMA_ONESHOT, /* DMA one shot mode */
@@ -226,6 +237,12 @@ enum stm32h7_adc_dmngt {
#define STM32MP13_RES_SHIFT 3
#define STM32MP13_RES_MASK GENMASK(4, 3)
+/* STM32MP13_ADC_CFGR2 bit fields */
+#define STM32MP13_OVSR_MASK GENMASK(4, 2)
+#define STM32MP13_OVSR(v) FIELD_PREP(STM32MP13_OVSR_MASK, v)
+#define STM32MP13_OVSS_MASK GENMASK(8, 5)
+#define STM32MP13_OVSS(v) FIELD_PREP(STM32MP13_OVSS_MASK, v)
+
/* STM32MP13_ADC_DIFSEL - bit fields */
#define STM32MP13_DIFSEL_MASK GENMASK(18, 0)