Re: [PATCH 03/16] iio: frequency: ad9523: fix the M2 divider selection
From: Andy Shevchenko
Date: Thu Dec 03 2026 - 07:17:34 EST
On Mon, Nov 30, 2026 at 05:37:01PM +0000, Nuno Sá wrote:
> For channels 4 to 9, the M2 divider is used if it looks closer to the
> requested frequency than M1. However, the comparison is done on the
> largest multiple of the requested frequency below each source, which
> does not tell how close the resulting output is. For example, with a
> 3000 MHz VCO, M1 = 3 and M2 = 4, asking for 500 MHz selects M2 and gives
> 750 MHz, while asking for 375 MHz selects M1 and gives 500 MHz.
>
> Compare the output frequencies each source actually gives instead, and
> only use M2 if it gets closer to the requested frequency.
...
> +static unsigned long ad9523_chan_freq(struct ad9523_state *st, unsigned int src,
> + unsigned long freq)
> +{
> + return st->vco_out_freq[src] /
> + clamp(st->vco_out_freq[src] / freq, 1, 1024);
Better to have a temporary variable for clamped value.
Also are 1 and 1024 because of the width of bit field? Maybe BIT(0), BIT(10)?
> +}
--
With Best Regards,
Andy Shevchenko