lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aB0IdPcjtcGFp6o-@smile.fi.intel.com>
Date: Thu, 8 May 2025 22:39:32 +0300
From: Andy Shevchenko <andy@...nel.org>
To: Jonathan Santos <Jonathan.Santos@...log.com>
Cc: linux-iio@...r.kernel.org, devicetree@...r.kernel.org,
	linux-kernel@...r.kernel.org, linux-gpio@...r.kernel.org,
	nuno.sa@...log.com, Michael.Hennerich@...log.com,
	marcelo.schmitt@...log.com, jic23@...nel.org, robh@...nel.org,
	krzk+dt@...nel.org, conor+dt@...nel.org, marcelo.schmitt1@...il.com,
	linus.walleij@...aro.org, brgl@...ev.pl, lgirdwood@...il.com,
	broonie@...nel.org, jonath4nns@...il.com, dlechner@...libre.com,
	Pop Paul <paul.pop@...log.com>
Subject: Re: [PATCH v7 11/12] iio: adc: ad7768-1: add filter type and
 oversampling ratio attributes

On Thu, May 08, 2025 at 02:05:26PM -0300, Jonathan Santos wrote:
> Separate filter type and decimation rate from the sampling frequency
> attribute. The new filter type attribute enables sinc3, sinc3+rej60
> 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 an oversampling
> attribute, which controls the decimation, users gain finer control
> over performance.
> 
> The addition of those attributes allows a wider range of sampling
> frequencies and more access to the device features. Sampling frequency
> table is updated after every digital filter parameter change.
> 
> Changes in the sampling frequency are not allowed anymore while in
> buffered mode.

...

>  static void ad7768_fill_samp_freq_tbl(struct ad7768_state *st)
>  {
> -	unsigned int i;
> +	unsigned int i, freq_filtered, len = 0;
> +
> +	freq_filtered = DIV_ROUND_CLOSEST(st->mclk_freq, st->oversampling_ratio);
> +	for (i = 0; i < ARRAY_SIZE(ad7768_mclk_div_rates); i++) {

> +		st->samp_freq_avail[len] = DIV_ROUND_CLOSEST(freq_filtered,
> +							     ad7768_mclk_div_rates[i]);

Same comment as per previous patch.

> +		/* Sampling frequency cannot be lower than the minimum of 50 SPS */
> +		if (st->samp_freq_avail[len] >= 50)
> +			len++;

Actually I would rather see the assignment once.

	... samp_freq_avail;

	for (i = 0; i < ARRAY_SIZE(ad7768_mclk_div_rates); i++) {
		/* Sampling frequency cannot be lower than the minimum of 50 SPS */
		samp_freq_avail = DIV_ROUND_CLOSEST(freq_filtered, ad7768_mclk_div_rates[i]);
		if (samp_freq_avail < 50)
			continue;

		st->samp_freq_avail[len++] = samp_freq_avail;
	}

> +	}
> +
> +	st->samp_freq_avail_len = len;
> +}

...

> +	res = DIV_ROUND_CLOSEST(st->mclk_freq, freq * st->oversampling_ratio);
>  
>  	/* Find the closest match for the desired sampling frequency */
> +	for (i = 0; i < ARRAY_SIZE(ad7768_mclk_div_rates); i++) {
> +		diff_new = abs(res - ad7768_mclk_div_rates[i]);
>  		if (diff_new < diff_old) {
>  			diff_old = diff_new;
>  			idx = i;
>  		}
>  	}

Hmm... Wasn't the point to include util_macros.h to replace the above?

-- 
With Best Regards,
Andy Shevchenko



Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ