[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z4GgABhZUG4Aacjw@debian-BULLSEYE-live-builder-AMD64>
Date: Fri, 10 Jan 2025 19:32:32 -0300
From: Marcelo Schmitt <marcelo.schmitt1@...il.com>
To: Jonathan Santos <Jonathan.Santos@...log.com>
Cc: linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, lars@...afoo.de,
Michael.Hennerich@...log.com, jic23@...nel.org, robh@...nel.org,
krzk+dt@...nel.org, conor+dt@...nel.org,
PopPaul2021 <paul.pop@...log.com>
Subject: Re: [PATCH v1 15/15] iio: adc: ad7768-1: add filter type and
decimation rate attributes
On 01/07, Jonathan Santos wrote:
> Separate filter type and decimation rate from the sampling frequency
> attribute. The new filter type attribute enables SINC3 and WIDEBAND
> filters, which were previously unavailable.
>
> Previously, combining decimation and MCLK divider in the sampling
> frequency obscured performance trade-offs. Lower MCLK divider
> settings increase power usage, while lower decimation rates reduce
> precision by decreasing averaging. By creating a decimation attribute,
> users gain finer control over performance.
If not going to use -3dB ABI instead of decimation rate thing, maybe throw the
formula for the sampling frequency here (or near its use in the code) to help
make the relation between samp_freq, master clock divider, and decimation rate
clearer?
Is it samp_freq = mclk / (mclk_div * dec_rate) ?
>
> The addition of those attributes allows a wider range of sampling
> frequencies and more access to the device features.
>
> Co-developed-by: PopPaul2021 <paul.pop@...log.com>
> Signed-off-by: PopPaul2021 <paul.pop@...log.com>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@...log.com>
> ---
> drivers/iio/adc/ad7768-1.c | 429 +++++++++++++++++++++++++++++++------
...
> +static const int dec_rate_values[6] = {
> + 32, 64, 128, 256, 512, 1024,
> +};
> +
> +static const int sinc3_dec_rate_max_values[4] = {
> + 20480, 40960, 81920, 163840,
> +};
sinc3_dec_rate_max_values unused?
> +
> +static const char * const ad7768_filter_enum[] = {
> + "sinc5", "sinc3", "wideband"
> };
>
...
> +static int ad7768_configure_dig_fil(struct iio_dev *dev,
> + enum ad7768_flt_type filter_type,
> + unsigned int dec_rate)
> +{
> + struct ad7768_state *st = iio_priv(dev);
> + int ret;
> +
> + if (filter_type == SINC3) {
neat: switch (filter_type) { ?
> + ret = ad7768_set_filter_type(dev, SINC3);
> + if (ret)
> + return ret;
> +
> + /* recalculate the decimation for this filter mode */
> + ret = ad7768_set_sinc3_dec_rate(st, dec_rate);
> + } else if (filter_type == WIDEBAND) {
> + ret = ad7768_set_filter_type(dev, filter_type);
> + if (ret)
> + return ret;
> +
> + /* recalculate the decimation rate */
> + ret = ad7768_set_dec_rate(st, dec_rate);
> + } else {
> + /* For SINC5 filter */
> + /* Decimation 8 and 16 are set in the digital filter field */
> + if (dec_rate <= 8) {
> + ret = ad7768_set_filter_type(dev, SINC5_DEC_X8);
> + if (ret)
> + return ret;
> +
> + st->dec_rate = 8;
> + } else if (dec_rate <= 16) {
> + ret = ad7768_set_filter_type(dev, SINC5_DEC_X16);
> + if (ret)
> + return ret;
> +
> + st->dec_rate = 16;
> + } else {
> + ret = ad7768_set_filter_type(dev, SINC5);
> + if (ret)
> + return ret;
> +
> + ret = ad7768_set_dec_rate(st, dec_rate);
> + }
> + }
> +
> + /* Update scale table: scale values vary according to the precision */
> + ad7768_fill_scale_tbl(dev);
> +
> + return ret;
> +}
> +
...
> +static ssize_t decimation_rate_available_show(struct device *dev,
> + struct device_attribute *attr,
> + char *buf)
> +{
> + struct iio_dev *indio_dev = dev_to_iio_dev(dev);
> + struct ad7768_state *st = iio_priv(indio_dev);
> + int len = 0;
> +
> + /* Return decimation rate available in range format */
> + buf[len++] = '[';
> + if (st->filter_type == SINC3) {
switch (st->filter_type) { ?
> + len += sysfs_emit_at(buf, len, "%d ", SINC3_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", SINC3_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", SINC3_DEC_RATE_MAX);
> + } else if (st->filter_type == WIDEBAND) {
> + len += sysfs_emit_at(buf, len, "%d ", WIDEBAND_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", WIDEBAND_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", WIDEBAND_DEC_RATE_MAX);
> + } else {
> + len += sysfs_emit_at(buf, len, "%d ", SINC5_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", SINC5_DEC_RATE_MIN);
> + len += sysfs_emit_at(buf, len, "%d ", SINC5_DEC_RATE_MAX);
> + }
> +
> + buf[len - 1] = ']';
> + buf[len++] = '\n';
> +
> + return len;
> +}
> +
Powered by blists - more mailing lists