* [PATCH v1 1/3] clk: clocking-wizard: fix clock difference detection
2026-05-06 20:05 [PATCH v1 0/3] clock-wizard fixups Colin Foster
@ 2026-05-06 20:05 ` Colin Foster
2026-05-06 20:05 ` [PATCH v1 2/3] clk: clocking-wizard: optimize clock search Colin Foster
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Colin Foster @ 2026-05-06 20:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-clk
Cc: Brian Masney, Shubhrajyoti Datta, Michal Simek, Stephen Boyd,
Michael Turquette
The diff calculation didn't take into account rollover. As such, a
target clock frequency below the requested rate would not be considered.
Before this change, bogus diffs would be used to determine the closest
possible clock:
8<--------
clk-wizard-test: requesting 133312500 Hz on output 0 (clock NOT enabled)
*** Clock wizard - Matching for rate 133312500 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 18446744073708237796
m = 34, d = 1, o = 26, freq = 130767923, diff = 18446744073707007039
m = 35, d = 1, o = 26, freq = 134614038, diff = 1301538
m = 36, d = 1, o = 27, freq = 133332000, diff = 19500
8<--------
After this change:
8<--------
clk-wizard-test: requesting 133312500 Hz on output 0 (clock NOT enabled)
*** Clock wizard - Matching for rate 133312500 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1313820
m = 35, d = 1, o = 26, freq = 134614038, diff = 1301538
m = 36, d = 1, o = 27, freq = 133332000, diff = 19500
8<--------
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
index 032a688840d8..88b47b8cc387 100644
--- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
@@ -408,7 +408,7 @@ static int clk_wzrd_get_divisors(struct clk_hw *hw, unsigned long rate,
if (o < omin || o > omax)
continue;
freq = DIV_ROUND_CLOSEST_ULL(vco_freq, o);
- diff = freq - rate;
+ diff = abs(freq - rate);
if (diff < best_diff) {
printk("m = %d, d = %d, o = %d, freq = %llu, diff = %llu", m, d, o, freq, diff);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 2/3] clk: clocking-wizard: optimize clock search
2026-05-06 20:05 [PATCH v1 0/3] clock-wizard fixups Colin Foster
2026-05-06 20:05 ` [PATCH v1 1/3] clk: clocking-wizard: fix clock difference detection Colin Foster
@ 2026-05-06 20:05 ` Colin Foster
2026-05-06 20:05 ` [PATCH v1 3/3] clk: clocking-wizard: remove 20kHz restriction Colin Foster
2026-05-07 11:59 ` [PATCH v1 0/3] clock-wizard fixups Datta, Shubhrajyoti
3 siblings, 0 replies; 5+ messages in thread
From: Colin Foster @ 2026-05-06 20:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-clk
Cc: Brian Masney, Shubhrajyoti Datta, Michal Simek, Stephen Boyd,
Michael Turquette
When an exact clock match is found, there is no need to continue
searching. This process was optimized for versal as part of
'commit e0a94c6bb5b4 ("clk: xilinx: Optimize divisor search in
clk_wzrd_get_divisors_ver()")' but that logic wasn't applied to
the non-versal driver.
Apply this fast-exit logic to the non-versal driver.
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
index 88b47b8cc387..d43f20e9ac59 100644
--- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
@@ -419,6 +419,9 @@ static int clk_wzrd_get_divisors(struct clk_hw *hw, unsigned long rate,
divider->d = d;
divider->o = o >> 3;
divider->o_frac = (o - (divider->o << 3)) * 125;
+
+ if (!diff)
+ return 0;
}
}
}
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH v1 3/3] clk: clocking-wizard: remove 20kHz restriction
2026-05-06 20:05 [PATCH v1 0/3] clock-wizard fixups Colin Foster
2026-05-06 20:05 ` [PATCH v1 1/3] clk: clocking-wizard: fix clock difference detection Colin Foster
2026-05-06 20:05 ` [PATCH v1 2/3] clk: clocking-wizard: optimize clock search Colin Foster
@ 2026-05-06 20:05 ` Colin Foster
2026-05-07 11:59 ` [PATCH v1 0/3] clock-wizard fixups Datta, Shubhrajyoti
3 siblings, 0 replies; 5+ messages in thread
From: Colin Foster @ 2026-05-06 20:05 UTC (permalink / raw)
To: linux-kernel, linux-arm-kernel, linux-clk
Cc: Brian Masney, Shubhrajyoti Datta, Michal Simek, Stephen Boyd,
Michael Turquette
There is a 20KHz minimum target for clock difference that was baked into
the driver. This is unnecessary, and causes target clock frequencies to
be rejected that should otherwise succeed.
The discrepancy existed in versal drivers as well, but was removed as
part of 'commit e0a94c6bb5b4 ("clk: xilinx: Optimize divisor search in
clk_wzrd_get_divisors_ver()")'
Apply the change to allow differences >= 20kHz.
Before the change:
8<--------
clk-wizard-test: requesting 133312000 Hz on output 0 (clock NOT enabled)
*** Clock wizard - Matching for rate 133312000 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1313320
m = 35, d = 1, o = 26, freq = 134614038, diff = 1302038
m = 36, d = 1, o = 27, freq = 133332000, diff = 20000
*** Clock wizard - Matching for rate 133312000 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1313320
m = 35, d = 1, o = 26, freq = 134614038, diff = 1302038
m = 36, d = 1, o = 27, freq = 133332000, diff = 20000
clk-wizard-test: clk_set_rate(133312000) failed: -22
8<--------
After the change:
8<--------
clk-wizard-test: requesting 133312000 Hz on output 0 (clock NOT enabled)
*** Clock wizard - Matching for rate 133312000 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1313320
m = 35, d = 1, o = 26, freq = 134614038, diff = 1302038
m = 36, d = 1, o = 27, freq = 133332000, diff = 20000
*** Clock wizard - Matching for rate 133312000 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1313320
m = 35, d = 1, o = 26, freq = 134614038, diff = 1302038
m = 36, d = 1, o = 27, freq = 133332000, diff = 20000
*** Clock wizard - Matching for rate 133332000 parent rate 99999000
m = 33, d = 1, o = 25, freq = 131998680, diff = 1333320
m = 35, d = 1, o = 26, freq = 134614038, diff = 1282038
m = 36, d = 1, o = 27, freq = 133332000, diff = 0
clk-wizard-test: success -- actual rate: 133332000 Hz (requested 133312000 Hz, error 20000 Hz)
8<--------
Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
---
drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
index d43f20e9ac59..bc71d6155b06 100644
--- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
@@ -105,7 +105,6 @@
#define VER_WZRD_VCO_MAX 4320000000ULL
#define VER_WZRD_O_MIN 2
#define VER_WZRD_O_MAX 511
-#define WZRD_MIN_ERR 20000
#define WZRD_FRAC_POINTS 1000
/* Get the mask from width */
@@ -425,7 +424,7 @@ static int clk_wzrd_get_divisors(struct clk_hw *hw, unsigned long rate,
}
}
}
- return best_diff < WZRD_MIN_ERR ? 0 : -EBUSY;
+ return best_diff != -1ULL ? 0 : -EBUSY;
}
static int clk_wzrd_reconfig(struct clk_wzrd_divider *divider, void __iomem *div_addr)
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH v1 0/3] clock-wizard fixups
2026-05-06 20:05 [PATCH v1 0/3] clock-wizard fixups Colin Foster
` (2 preceding siblings ...)
2026-05-06 20:05 ` [PATCH v1 3/3] clk: clocking-wizard: remove 20kHz restriction Colin Foster
@ 2026-05-07 11:59 ` Datta, Shubhrajyoti
3 siblings, 0 replies; 5+ messages in thread
From: Datta, Shubhrajyoti @ 2026-05-07 11:59 UTC (permalink / raw)
To: Colin Foster, linux-kernel, linux-arm-kernel, linux-clk
Cc: Brian Masney, Shubhrajyoti Datta, Michal Simek, Stephen Boyd,
Michael Turquette
On 5/7/2026 1:35 AM, Colin Foster wrote:
> The clock-wizard driver had a hard-coded 20KHz minimum accuracy. This
> led to out-of-tree drivers silently failing to set clock rates instead
> of dealing with the best-effort.
>
> Remove this 20KHz restriction to match the Versal clock wizard driver.
> There also was a bug in the difference calculation that is addressed in
> the first patch.
>
> The second patch optimizes the search if an exact match is found.
>
> The third removes the restriction.
LGTM
Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@amd.com>
>
> Colin Foster (3):
> clk: clocking-wizard: fix clock difference detection
> clk: clocking-wizard: optimize clock search
> clk: clocking-wizard: remove 20kHz restriction
>
> drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread