The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Neel Bullywon <neelb2403@gmail.com>
Cc: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org,
	dlechner@baylibre.com, nuno.sa@analog.com, andy@kernel.org,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: frequency: adf4350: replace loop with order_base_2()
Date: Wed, 11 Mar 2026 14:07:16 +0200	[thread overview]
Message-ID: <abFa9G81Bj4YTZqq@ashevche-desk.local> (raw)
In-Reply-To: <20260311020115.56321-1-neelb2403@gmail.com>

On Tue, Mar 10, 2026 at 10:01:15PM -0400, Neel Bullywon wrote:
> Address the TODO in adf4350_set_freq() by replacing the iterative
> power-of-2 shift loop with the standard order_base_2() macro.
> 
> By utilizing DIV_ROUND_UP_ULL(), we
> can calculate the required RF divider selection in a single step.
> 
> This ensures freq is properly shifted to meet or exceed the minimum
> VCO frequency.

Thanks! My comments below.

...

> -	st->r4_rf_div_sel = 0;
> -
>  	/*
> -	 * !\TODO: The below computation is making sure we get a power of 2
> -	 * shift (st->r4_rf_div_sel) so that freq becomes higher or equal to
> -	 * ADF4350_MIN_VCO_FREQ. This might be simplified with fls()/fls_long()
> -	 * and friends.
> +	 * Calculate the required RF divider selection (power of 2 shift)
> +	 * to ensure the VCO frequency is >= ADF4350_MIN_VCO_FREQ.
>  	 */
> -	while (freq < ADF4350_MIN_VCO_FREQ) {
> -		freq <<= 1;
> -		st->r4_rf_div_sel++;
> -	}
> +	st->r4_rf_div_sel = order_base_2(DIV_ROUND_UP_ULL(ADF4350_MIN_VCO_FREQ, freq));

We don't need 64-bit division even with your approach as values are 32-bit for
this case (yeah, I know that they have 64-bit types).

What you need is to do as suggested by comment: use fls_long() against the
constant and freq to see the difference in value, if there is none the while
will become just a check and a single shift.

Or consider it as the opposite problem: "How much the given constant is now
bigger than freq?" With that it might be more obvious solution.

I.o.w. think about this a bit more.

> +	freq <<= st->r4_rf_div_sel;
>  

I would move this blank line to be before freq shift, this will associate it
with the check below.

>  	if (freq > ADF4350_MAX_FREQ_45_PRESC) {
>  		prescaler = ADF4350_REG1_PRESCALER;

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-03-11 12:07 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-11  2:01 [PATCH] iio: frequency: adf4350: replace loop with order_base_2() Neel Bullywon
2026-03-11 12:07 ` Andy Shevchenko [this message]
2026-03-14 17:20 ` [PATCH v2] iio: frequency: adf4350: replace loop with fls_long() Neel Bullywon
2026-03-15 13:00   ` Jonathan Cameron
2026-03-16 12:40   ` Andy Shevchenko
2026-03-22 11:51     ` Jonathan Cameron
2026-03-16 13:51   ` David Laight
2026-03-16 14:07     ` Andy Shevchenko
2026-03-23 11:08       ` Nuno Sá
2026-03-23 13:31         ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abFa9G81Bj4YTZqq@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=neelb2403@gmail.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox