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@analog.com>
---
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 ac236e5c74c7..f2c762688fb3 100644
--- a/drivers/iio/adc/ad7768.c
+++ b/drivers/iio/adc/ad7768.c
@@ -107,6 +107,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,@@ -596,6 +598,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 t_mode_us;
+ u8 settling_samples;
+
+ 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)
{@@ -679,7 +708,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