[PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute

Jonathan Santos posted 11 patches 4 months ago
[PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute
Posted by Jonathan Santos 4 months ago
Ad7768-1 has a different -3db frequency multiplier depending on
the filter type configured. The cutoff frequency also varies according
to the current ODR.

Add a readonly low pass -3dB frequency cutoff attribute to clarify to
the user which bandwidth is being allowed depending on the filter
configurations.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
---
v11 Changes:
* Applied suggestions from Andy.

v10 Changes:
* None

v9 Changes:
* Rearranged new BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) to
  make the diff look cleaner.

v8 Changes:
* None

v7 Changes:
* None

v6 Changes:
* None

v5 Changes:
* None

v4 Changes:
* None

v3 Changes:
* None

v2 Changes:
* New patch in v2.
---
 drivers/iio/adc/ad7768-1.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/ad7768-1.c b/drivers/iio/adc/ad7768-1.c
index 291ed801a8a0..e4716e20fcdf 100644
--- a/drivers/iio/adc/ad7768-1.c
+++ b/drivers/iio/adc/ad7768-1.c
@@ -152,6 +152,14 @@ enum ad7768_scan_type {
 	AD7768_SCAN_TYPE_HIGH_SPEED,
 };
 
+/* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */
+static const int ad7768_filter_3db_odr_multiplier[] = {
+	[AD7768_FILTER_SINC5] = 204,		/* 0.204 */
+	[AD7768_FILTER_SINC3] = 262,		/* 0.2617 */
+	[AD7768_FILTER_SINC3_REJ60] = 262,	/* 0.2617 */
+	[AD7768_FILTER_WIDEBAND] = 433,		/* 0.433 */
+};
+
 static const int ad7768_mclk_div_rates[] = {
 	16, 8, 4, 2,
 };
@@ -746,6 +754,7 @@ static const struct iio_chan_spec ad7768_channels[] = {
 		.type = IIO_VOLTAGE,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) |
+					    BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |
 					    BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
 		.info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO),
 		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
@@ -766,7 +775,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
 {
 	struct ad7768_state *st = iio_priv(indio_dev);
 	const struct iio_scan_type *scan_type;
-	int scale_uv, ret;
+	int scale_uv, ret, temp;
 
 	scan_type = iio_get_current_scan_type(indio_dev, chan);
 	if (IS_ERR(scan_type))
@@ -804,6 +813,12 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
 		*val = st->oversampling_ratio;
 
+		return IIO_VAL_INT;
+
+	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
+		temp = st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_type];
+		*val = DIV_ROUND_CLOSEST(temp, 1000);
+
 		return IIO_VAL_INT;
 	}
 
-- 
2.34.1
Re: [PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute
Posted by Andy Shevchenko 3 months, 4 weeks ago
On Wed, Jun 11, 2025 at 08:52:03AM -0300, Jonathan Santos wrote:
> Ad7768-1 has a different -3db frequency multiplier depending on
> the filter type configured. The cutoff frequency also varies according
> to the current ODR.
> 
> Add a readonly low pass -3dB frequency cutoff attribute to clarify to
> the user which bandwidth is being allowed depending on the filter
> configurations.

> +/* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */
> +static const int ad7768_filter_3db_odr_multiplier[] = {
> +	[AD7768_FILTER_SINC5] = 204,		/* 0.204 */
> +	[AD7768_FILTER_SINC3] = 262,		/* 0.2617 */
> +	[AD7768_FILTER_SINC3_REJ60] = 262,	/* 0.2617 */
> +	[AD7768_FILTER_WIDEBAND] = 433,		/* 0.433 */

Just to be sure, is it 0.433 or 0.4333(3) actually? Sometimes datasheets have
rounding that even may lead to problems (see TSC issues for some of the Intel
CPUs in the past). That's behind my question.

> +};

...

> +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> +		temp = st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_type];
> +		*val = DIV_ROUND_CLOSEST(temp, 1000);

MILLI? KILO/ MICRO/MILLI? ...?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute
Posted by Jonathan Santos 3 months, 3 weeks ago
On 06/13, Andy Shevchenko wrote:
> On Wed, Jun 11, 2025 at 08:52:03AM -0300, Jonathan Santos wrote:
> > Ad7768-1 has a different -3db frequency multiplier depending on
> > the filter type configured. The cutoff frequency also varies according
> > to the current ODR.
> > 
> > Add a readonly low pass -3dB frequency cutoff attribute to clarify to
> > the user which bandwidth is being allowed depending on the filter
> > configurations.
> 
> > +/* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */
> > +static const int ad7768_filter_3db_odr_multiplier[] = {
> > +	[AD7768_FILTER_SINC5] = 204,		/* 0.204 */
> > +	[AD7768_FILTER_SINC3] = 262,		/* 0.2617 */
> > +	[AD7768_FILTER_SINC3_REJ60] = 262,	/* 0.2617 */
> > +	[AD7768_FILTER_WIDEBAND] = 433,		/* 0.433 */
> 
> Just to be sure, is it 0.433 or 0.4333(3) actually? Sometimes datasheets have
> rounding that even may lead to problems (see TSC issues for some of the Intel
> CPUs in the past). That's behind my question.
> 

Every reference I have specifies it as 0.433, so I believe that is it.

> > +};
> 
> ...
> 
> > +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> > +		temp = st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_type];
> > +		*val = DIV_ROUND_CLOSEST(temp, 1000);
> 
> MILLI? KILO/ MICRO/MILLI? ...?
> 

Yes, MILLI.

Thanks,
Jonathan S.

> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Re: [PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute
Posted by Jonathan Cameron 3 months ago
On Tue, 17 Jun 2025 13:17:05 -0300
Jonathan Santos <jonath4nns@gmail.com> wrote:

> On 06/13, Andy Shevchenko wrote:
> > On Wed, Jun 11, 2025 at 08:52:03AM -0300, Jonathan Santos wrote:  
> > > Ad7768-1 has a different -3db frequency multiplier depending on
> > > the filter type configured. The cutoff frequency also varies according
> > > to the current ODR.
> > > 
> > > Add a readonly low pass -3dB frequency cutoff attribute to clarify to
> > > the user which bandwidth is being allowed depending on the filter
> > > configurations.  
> >   
> > > +/* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */
> > > +static const int ad7768_filter_3db_odr_multiplier[] = {
> > > +	[AD7768_FILTER_SINC5] = 204,		/* 0.204 */
> > > +	[AD7768_FILTER_SINC3] = 262,		/* 0.2617 */
> > > +	[AD7768_FILTER_SINC3_REJ60] = 262,	/* 0.2617 */
> > > +	[AD7768_FILTER_WIDEBAND] = 433,		/* 0.433 */  
> > 
> > Just to be sure, is it 0.433 or 0.4333(3) actually? Sometimes datasheets have
> > rounding that even may lead to problems (see TSC issues for some of the Intel
> > CPUs in the past). That's behind my question.
> >   
> 
> Every reference I have specifies it as 0.433, so I believe that is it.
> 
> > > +};  
> > 
> > ...
> >   
> > > +	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
> > > +		temp = st->samp_freq * ad7768_filter_3db_odr_multiplier[st->filter_type];
> > > +		*val = DIV_ROUND_CLOSEST(temp, 1000);  
> > 
> > MILLI? KILO/ MICRO/MILLI? ...?
> >   
> 
> Yes, MILLI.
I fixed this up and added units.h include and applied.


> 
> Thanks,
> Jonathan S.
> 
> > -- 
> > With Best Regards,
> > Andy Shevchenko
> > 
> >   
>
Re: [PATCH v11 11/11] iio: adc: ad7768-1: add low pass -3dB cutoff attribute
Posted by Andy Shevchenko 3 months, 3 weeks ago
On Tue, Jun 17, 2025 at 7:17 PM Jonathan Santos <jonath4nns@gmail.com> wrote:
> On 06/13, Andy Shevchenko wrote:
> > On Wed, Jun 11, 2025 at 08:52:03AM -0300, Jonathan Santos wrote:
> > > Ad7768-1 has a different -3db frequency multiplier depending on
> > > the filter type configured. The cutoff frequency also varies according
> > > to the current ODR.
> > >
> > > Add a readonly low pass -3dB frequency cutoff attribute to clarify to
> > > the user which bandwidth is being allowed depending on the filter
> > > configurations.
> >
> > > +/* -3dB cutoff frequency multipliers (relative to ODR) for each filter type. */
> > > +static const int ad7768_filter_3db_odr_multiplier[] = {
> > > +   [AD7768_FILTER_SINC5] = 204,            /* 0.204 */
> > > +   [AD7768_FILTER_SINC3] = 262,            /* 0.2617 */
> > > +   [AD7768_FILTER_SINC3_REJ60] = 262,      /* 0.2617 */
> > > +   [AD7768_FILTER_WIDEBAND] = 433,         /* 0.433 */
> >
> > Just to be sure, is it 0.433 or 0.4333(3) actually? Sometimes datasheets have
> > rounding that even may lead to problems (see TSC issues for some of the Intel
> > CPUs in the past). That's behind my question.
>
> Every reference I have specifies it as 0.433, so I believe that is it.

Yeah, I see now. The base is 0.10825, which is multiplied by 4 in this case.

> > > +};

-- 
With Best Regards,
Andy Shevchenko