[PATCH v5 12/20] iio: adc: ad7768: Wait for digital filters to settle

From: Janani Sunil

Date: Fri Aug 28 2026 - 11:35:35 EST


After synchronizing the channel mode configuration, wait for the longest
settling period required by the active profiles. Derive the delay from
the selected output data rate and the datasheet filter-settling limits.

Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/ad7768.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7768.c b/drivers/iio/adc/ad7768.c
index 4c67f692861e..84b96b1fab09 100644
--- a/drivers/iio/adc/ad7768.c
+++ b/drivers/iio/adc/ad7768.c
@@ -112,6 +112,8 @@
#define AD7768_MAX_FREQ_PER_MODE 6
#define AD7768_MAX_CHANNEL 8
#define AD7768_NUM_CHANNEL_MODES 2
+#define AD7768_WIDEBAND_SETTLING_SAMPLES 68
+#define AD7768_SINC5_SETTLING_SAMPLES 7

enum ad7768_filter_type {
AD7768_FILTER_TYPE_WIDEBAND,
@@ -592,6 +594,33 @@ static int ad7768_find_matching_mode(const bool *mode_used,
return -EINVAL;
}

+static void ad7768_filter_wait(const unsigned int *mode_freq,
+ const enum ad7768_filter_type *mode_filter,
+ const bool *mode_used)
+{
+ unsigned int t_settle_us = 0;
+
+ for (unsigned int mode = 0; mode < AD7768_NUM_CHANNEL_MODES; mode++) {
+ unsigned int settling_samples;
+ unsigned int t_mode_us;
+
+ if (!mode_used[mode] || !mode_freq[mode])
+ continue;
+
+ if (mode_filter[mode] == AD7768_FILTER_TYPE_SINC5)
+ settling_samples = AD7768_SINC5_SETTLING_SAMPLES;
+ else
+ settling_samples = AD7768_WIDEBAND_SETTLING_SAMPLES;
+
+ t_mode_us = DIV_ROUND_UP(settling_samples * USEC_PER_SEC,
+ mode_freq[mode]);
+ t_settle_us = max(t_settle_us, t_mode_us);
+ }
+
+ if (t_settle_us)
+ fsleep(t_settle_us);
+}
+
static int ad7768_apply_channel_modes(struct iio_dev *indio_dev,
const unsigned long *scan_mask)
{
@@ -674,7 +703,14 @@ static int ad7768_apply_channel_modes(struct iio_dev *indio_dev,
if (ret)
return ret;

- return ad7768_sync(st);
+ ret = ad7768_sync(st);
+ if (ret)
+ return ret;
+
+ /* Apply a filter settling time (datasheet Tables 28 and 29). */
+ ad7768_filter_wait(mode_freq, mode_filter, mode_used);
+
+ return 0;
}

static int ad7768_update_scan_mode(struct iio_dev *indio_dev,

--
2.43.0