linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] iio_ frequency: adf4350: prescaler and register map fixes
@ 2025-08-29 11:25 Nuno Sá via B4 Relay
  2025-08-29 11:25 ` [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage Nuno Sá via B4 Relay
  2025-08-29 11:25 ` [PATCH v2 2/2] iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE Nuno Sá via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-08-29 11:25 UTC (permalink / raw)
  To: linux-iio
  Cc: Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko

Add some outstading fixes (that lived in ADI fork) for the ad4350 fixes.

---
Michael Hennerich (2):
      iio: frequency: adf4350: Fix prescaler usage.
      iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE

 drivers/iio/frequency/adf4350.c       | 20 +++++++++++++-------
 include/linux/iio/frequency/adf4350.h |  2 +-
 2 files changed, 14 insertions(+), 8 deletions(-)
---
base-commit: 6408dba154079656d069a6a25fb3a8954959474c
change-id: 20250808-adf4350-fix-3e0b9b7c3420
--

Thanks!
- Nuno Sá



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage.
  2025-08-29 11:25 [PATCH v2 0/2] iio_ frequency: adf4350: prescaler and register map fixes Nuno Sá via B4 Relay
@ 2025-08-29 11:25 ` Nuno Sá via B4 Relay
  2025-08-30  7:58   ` Andy Shevchenko
  2025-08-29 11:25 ` [PATCH v2 2/2] iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE Nuno Sá via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-08-29 11:25 UTC (permalink / raw)
  To: linux-iio
  Cc: Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko

From: Michael Hennerich <michael.hennerich@analog.com>

The ADF4350/1 features a programmable dual-modulus prescaler of 4/5 or 8/9.
When set to 4/5, the maximum RF frequency allowed is 3 GHz.
Therefore, when operating the ADF4351 above 3 GHz, this must be set to 8/9.
In this context not the RF output frequency is meant
- it's the VCO frequency.

Therefore move the prescaler selection after we derived the VCO frequency
from the desired RF output frequency.

This BUG may have caused PLL lock instabilities when operating the VCO at
the very high range close to 4.4 GHz.

Fixes: e31166f0fd48 ("iio: frequency: New driver for Analog Devices ADF4350/ADF4351 Wideband Synthesizers")
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>

---
v2:
 * Added fixes tag;
 * Added TODO (suggested by Andy).
---
 drivers/iio/frequency/adf4350.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/frequency/adf4350.c b/drivers/iio/frequency/adf4350.c
index 47f1c7e9efa9f425a4c7cf82be930234e2c18434..475a7a653bfb52174a258662dcb64c9727f0897c 100644
--- a/drivers/iio/frequency/adf4350.c
+++ b/drivers/iio/frequency/adf4350.c
@@ -149,6 +149,19 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq)
 	if (freq > ADF4350_MAX_OUT_FREQ || freq < st->min_out_freq)
 		return -EINVAL;
 
+	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_MAX_FREQ_45_PRESC) {
 		prescaler = ADF4350_REG1_PRESCALER;
 		mdiv = 75;
@@ -157,13 +170,6 @@ static int adf4350_set_freq(struct adf4350_state *st, unsigned long long freq)
 		mdiv = 23;
 	}
 
-	st->r4_rf_div_sel = 0;
-
-	while (freq < ADF4350_MIN_VCO_FREQ) {
-		freq <<= 1;
-		st->r4_rf_div_sel++;
-	}
-
 	/*
 	 * Allow a predefined reference division factor
 	 * if not set, compute our own

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE
  2025-08-29 11:25 [PATCH v2 0/2] iio_ frequency: adf4350: prescaler and register map fixes Nuno Sá via B4 Relay
  2025-08-29 11:25 ` [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage Nuno Sá via B4 Relay
@ 2025-08-29 11:25 ` Nuno Sá via B4 Relay
  1 sibling, 0 replies; 5+ messages in thread
From: Nuno Sá via B4 Relay @ 2025-08-29 11:25 UTC (permalink / raw)
  To: linux-iio
  Cc: Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko

From: Michael Hennerich <michael.hennerich@analog.com>

The clk div bits (2 bits wide) do not start in bit 16 but in bit 15. Fix it
accordingly.

Fixes: e31166f0fd48 ("iio: frequency: New driver for Analog Devices ADF4350/ADF4351 Wideband Synthesizers")
Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
Signed-off-by: Nuno Sá <nuno.sa@analog.com>

---
v2:
 * New patch.
---
 include/linux/iio/frequency/adf4350.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/iio/frequency/adf4350.h b/include/linux/iio/frequency/adf4350.h
index de45cf2ee1e4f8278a02cb2efb1540662023d9fb..ce2086f97e3fcf609d77de0bc2c15d5d47f7baae 100644
--- a/include/linux/iio/frequency/adf4350.h
+++ b/include/linux/iio/frequency/adf4350.h
@@ -51,7 +51,7 @@
 
 /* REG3 Bit Definitions */
 #define ADF4350_REG3_12BIT_CLKDIV(x)		((x) << 3)
-#define ADF4350_REG3_12BIT_CLKDIV_MODE(x)	((x) << 16)
+#define ADF4350_REG3_12BIT_CLKDIV_MODE(x)	((x) << 15)
 #define ADF4350_REG3_12BIT_CSR_EN		(1 << 18)
 #define ADF4351_REG3_CHARGE_CANCELLATION_EN	(1 << 21)
 #define ADF4351_REG3_ANTI_BACKLASH_3ns_EN	(1 << 22)

-- 
2.51.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage.
  2025-08-29 11:25 ` [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage Nuno Sá via B4 Relay
@ 2025-08-30  7:58   ` Andy Shevchenko
  2025-08-31 15:47     ` Jonathan Cameron
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Shevchenko @ 2025-08-30  7:58 UTC (permalink / raw)
  To: nuno.sa
  Cc: linux-iio, Michael Hennerich, Jonathan Cameron, David Lechner,
	Andy Shevchenko

On Fri, Aug 29, 2025 at 2:25 PM Nuno Sá via B4 Relay
<devnull+nuno.sa.analog.com@kernel.org> wrote:
>
> From: Michael Hennerich <michael.hennerich@analog.com>
>
> The ADF4350/1 features a programmable dual-modulus prescaler of 4/5 or 8/9.
> When set to 4/5, the maximum RF frequency allowed is 3 GHz.
> Therefore, when operating the ADF4351 above 3 GHz, this must be set to 8/9.
> In this context not the RF output frequency is meant
> - it's the VCO frequency.
>
> Therefore move the prescaler selection after we derived the VCO frequency
> from the desired RF output frequency.
>
> This BUG may have caused PLL lock instabilities when operating the VCO at
> the very high range close to 4.4 GHz.
>
> Fixes: e31166f0fd48 ("iio: frequency: New driver for Analog Devices ADF4350/ADF4351 Wideband Synthesizers")
> Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Nuno Sá <nuno.sa@analog.com>
>
> ---
> v2:
>  * Added fixes tag;
>  * Added TODO (suggested by Andy).

Thanks, this is a compromise I can agree with.
Reviewed-by: Andy Shevchenko <andy@kernel,org>

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage.
  2025-08-30  7:58   ` Andy Shevchenko
@ 2025-08-31 15:47     ` Jonathan Cameron
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-08-31 15:47 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: nuno.sa, linux-iio, Michael Hennerich, David Lechner,
	Andy Shevchenko

On Sat, 30 Aug 2025 10:58:49 +0300
Andy Shevchenko <andy.shevchenko@gmail.com> wrote:

> On Fri, Aug 29, 2025 at 2:25 PM Nuno Sá via B4 Relay
> <devnull+nuno.sa.analog.com@kernel.org> wrote:
> >
> > From: Michael Hennerich <michael.hennerich@analog.com>
> >
> > The ADF4350/1 features a programmable dual-modulus prescaler of 4/5 or 8/9.
> > When set to 4/5, the maximum RF frequency allowed is 3 GHz.
> > Therefore, when operating the ADF4351 above 3 GHz, this must be set to 8/9.
> > In this context not the RF output frequency is meant
> > - it's the VCO frequency.
> >
> > Therefore move the prescaler selection after we derived the VCO frequency
> > from the desired RF output frequency.
> >
> > This BUG may have caused PLL lock instabilities when operating the VCO at
> > the very high range close to 4.4 GHz.
> >
> > Fixes: e31166f0fd48 ("iio: frequency: New driver for Analog Devices ADF4350/ADF4351 Wideband Synthesizers")
> > Signed-off-by: Michael Hennerich <michael.hennerich@analog.com>
> > Signed-off-by: Nuno Sá <nuno.sa@analog.com>
> >
> > ---
> > v2:
> >  * Added fixes tag;
> >  * Added TODO (suggested by Andy).  
> 
> Thanks, this is a compromise I can agree with.
> Reviewed-by: Andy Shevchenko <andy@kernel,org>
> 
Fixed up email address and series applied to the fixes-togreg branch of iio.git.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-31 15:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-29 11:25 [PATCH v2 0/2] iio_ frequency: adf4350: prescaler and register map fixes Nuno Sá via B4 Relay
2025-08-29 11:25 ` [PATCH v2 1/2] iio: frequency: adf4350: Fix prescaler usage Nuno Sá via B4 Relay
2025-08-30  7:58   ` Andy Shevchenko
2025-08-31 15:47     ` Jonathan Cameron
2025-08-29 11:25 ` [PATCH v2 2/2] iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE Nuno Sá via B4 Relay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).