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@xxxxxxxxxx> > Signed-off-by: PopPaul2021 <paul.pop@xxxxxxxxxx> > Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx> > --- > 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; > +} > +