From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BACEE3932E4 for ; Mon, 16 Mar 2026 13:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773669116; cv=none; b=BOEd82bY7omAspcxQcSxWnwJQgA4bKanTQQBnofz1K9Yi5Pb1osy2f+T45l1Y5N2xxssylQiXrKlJf/C47csW3wAIRrdQOAycs+cov01NxyhYIncYdulT/LL2NFLILacMD54/+MCOMMHfujZ9R2deoIIXZy5s40J+y65sLNqYK8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773669116; c=relaxed/simple; bh=7/GisGeAb0QSGDWThezPsL6NT32IDJfl0jkfyfEFnmk=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=E82Py0w9rFS6rOhCd3xaIDLZLLZzuuEhtPVyo9aoHc+9cBwP+KV+WaGG/lnTJR9QOQdaV9cZJEp4joyotS+du2crCzn312WA6Xv4EFUrNer2R6ShkAvVJMd4ErtH1LNLCbpVSSuJBoUsQDzXSIxmUcJgFb8ole8KpD+wf7Xhug0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Smq0+ts+; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Smq0+ts+" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-48374014a77so47405855e9.3 for ; Mon, 16 Mar 2026 06:51:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773669113; x=1774273913; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=ZGSmU9dcqf1LyB14ADER64gtrG8X3mhhv3QkYvPKxRE=; b=Smq0+ts+PQU+UAoDD80Sxv2YPOmBYBgM3+IE5onrIdqPbhhmm5UCVb3XnYvcNfZkDn dsqegAvNeDkM9SvkbhZwAdswvYIRF1ZYBMc3cJA5u4gKvDQ8J7ubGYPslA9IWmxQ4oVT CW2JvdbQPbl82f0ioR9Mb/l2UVCf7GClVN3WoBZHrmzXqwdkZmgXKjmQAQy6iUznO2wY vDwuNmVOlWZ1h+Qi/naUg6KwHstqsNZDnj5nEv9ir1tmFHCp2FKi5aG1ex9YyURzduCu 1W5ZXlGOTi3au2Iv1OZw927/HNJP7pxe55jlAMiW1N35V1Lh+yLS/nt3B0RP0m9pS/3X I8gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773669113; x=1774273913; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=ZGSmU9dcqf1LyB14ADER64gtrG8X3mhhv3QkYvPKxRE=; b=c9TSdfYQBQsfiekU1qqPoyrOZLUvJVv4RNdCTlHIbGWXF/Qo5DS3vSwfXVNfU0pvis PMTPs5HbXN4jHGXELeDQL7fXRQW2279z5++Ngk8p0kSOiTE/YY7o1HIvVDir9wji5xkc Hy7aeEdvVwcMXYx7apB2lonu8OHwYICqpdtvtDQbzIHb4S1Gg6iXoqfntspYwYvlnCob QbLjFhvsHOlt+ygdkaPg2AsqgJNLx3Ckl58Hktf+cwkOqK6umknksYtzt428g3liSdES L/cWz3nLvtnZXJ1PIMbMw380+JrZCSqXTEGPbt8/vzxQubnBsL+dA57lCZZUPxbxo1IK IozA== X-Forwarded-Encrypted: i=1; AJvYcCVfQzlXSyUr6Jf6r25x1yIAsL/Z3eB59fndsqASQvZbugu9yMLuON89iL7h7ApS93eVVoJ6morlNPBWOks=@vger.kernel.org X-Gm-Message-State: AOJu0Yy880zXAi10Vyyq0yv4IUbFaK9giWZTwCtALaRmhpagt8jLbMtn jPN5h96SPtto1nll97d8UxjFxA6DmbXlWrW/ibS9FqIHH6fJnBbIXfrJ X-Gm-Gg: ATEYQzyVlVRWvV0HZTHiySBdvSa6Z4NJiOUHGm0835qxnXtXuzl/5RmedibYgTN1l6f Cu8GzwIVaCC7rsutfJhY/oiAjHOXpttTXY8SPcQ14PTyFwVaJppDQaFbr02tS73aVZUnn3yzguz Hn3nZSFkvXd/WvBbMwBSYllDETTTjYiciXeIjanRzpT68c5gM8qPAF17vmLXJjYA7CL1lCY5Zfk OBELwqYUtuwcJSJijHWXJPw38f2w9AWzpD2sa+B3Yh0vLPJVfUneOi+0jHN6iu2KpllRFU3oFTP +PfrAwwxYDJXDPsZnzg2YfTKsHcEjetGShtK2EnfoMUJQXvzUhH6FO0cwPwPVTrbft2fW/Iu3bq OLuLWuJ7SrhBFQlNdyvxqAQdAP82Kn+ZWd07k6Jikvc/do9woIiGND5CJQfR2hN4KUbC5rOgE5t AvNRzSTzPs6E59FcEEkVHpB4RjqP+w49UoMP9AeeBCYjXEoZRtNBKCrgZreC3AWpcO X-Received: by 2002:a05:600c:c4ac:b0:485:40a4:364 with SMTP id 5b1f17b1804b1-4855670c2a5mr215981665e9.26.1773669112806; Mon, 16 Mar 2026 06:51:52 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4854b65fed7sm398747335e9.11.2026.03.16.06.51.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2026 06:51:52 -0700 (PDT) Date: Mon, 16 Mar 2026 13:51:51 +0000 From: David Laight To: Neel Bullywon 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 v2] iio: frequency: adf4350: replace loop with fls_long() Message-ID: <20260316135151.309207ae@pumpkin> In-Reply-To: <20260314172006.69744-1-neelb2403@gmail.com> References: <20260311020115.56321-1-neelb2403@gmail.com> <20260314172006.69744-1-neelb2403@gmail.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 14 Mar 2026 13:20:06 -0400 Neel Bullywon wrote: > Address the TODO in adf4350_set_freq() by replacing the iterative > power-of-2 shift loop with a constant-time bitwise calculation. > > By comparing the highest set bits of the target constant and freq > using fls_long(), we can calculate the required RF divider selection > in a single step without relying on expensive 64-bit division. Where is the 64bit division? (apart from in v1) Indeed where are the 64bit values at all. If this code is used on 32bit it has to work with a 32bit long. Which makes be think that the 'freq' variable should be u32 (or possibly u64 if frequencies above 4GHz are likely - which I doubt). In any case this looks like initialisation code and the existing loop has the advantage of being 'obviously correct' and small. David > > This ensures freq is properly shifted to meet or exceed the minimum > VCO frequency. > > Signed-off-by: Neel Bullywon > --- > Changes in v2: > - Use fls_long() instead of order_base_2(DIV_ROUND_UP_ULL()) to avoid > unnecessary 64-bit division (Andy Shevchenko) > - Add correction check for mantissa edge case > - Adjust whitespace per review feedback > > drivers/iio/frequency/adf4350.c | 16 +++++++--------- > 1 file changed, 7 insertions(+), 9 deletions(-) > > diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c > index ed1741165f55..2183deec179d 100644 > --- a/drivers/iio/frequency/adf4350.c > +++ b/drivers/iio/frequency/adf4350.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -151,17 +152,14 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq) > > 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. > - */ > - while (freq < ADF4350_MIN_VCO_FREQ) { > - freq <<= 1; > - st->r4_rf_div_sel++; > + if (freq < ADF4350_MIN_VCO_FREQ) { > + st->r4_rf_div_sel = fls_long(ADF4350_MIN_VCO_FREQ - 1) - fls_long(freq); > + if ((freq << st->r4_rf_div_sel) < ADF4350_MIN_VCO_FREQ) > + st->r4_rf_div_sel++; > } > > + freq <<= st->r4_rf_div_sel; > + > if (freq > ADF4350_MAX_FREQ_45_PRESC) { > prescaler = ADF4350_REG1_PRESCALER; > mdiv = 75;