Thread (3 messages) 3 messages, 2 authors, 16d ago

[PATCH] clk: sunxi-ng: ccu_common: Replace ktime-dependent lock wait loop with udelay

flat view
COLD16d

From: Alastair D'Silva <hidden>
Date: 2026-09-16 04:11:42
Also in: linux-clk, linux-sunxi, lkml
Subsystem: arm/allwinner sunxi soc support, common clk framework, the rest · Maintainers: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland, Stephen Boyd, Brian Masney, Jerome Brunet, Linus Torvalds

The Allwinner sunxi-ng CCU driver uses readl_relaxed_poll_timeout() in
ccu_helper_wait_for_lock() to wait for PLLs to lock.

This poll macro relies on ktime_get() and the kernel timekeeping
infrastructure. During early boot or sensitive clock transitions
(such as CPUfreq DVFS scaling) where timer interrupts or timekeeping may
be suspended or unstable, ktime_get() fails to increment. This turns the
timeout calculation into an infinite busy-wait loop, causing RCU stalls
and system freezes if the PLL lock bit does not assert immediately.

Decouple the PLL lock wait loop from the timekeeping framework by replacing
readl_relaxed_poll_timeout() with an iteration loop using udelay(1) up to
100ms.

Assisted-by: LLM
Signed-off-by: Alastair D'Silva <redacted>
---

Notes:
    Tested on Allwinner H618 (Mellow Fly-C5) and H616 boards in Armbian, resolving intermittent boot freezes and CPUfreq DVFS scaling lockups when timekeeping interrupts were suspended.

 drivers/clk/sunxi-ng/ccu_common.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 43d8eca6abee..00daedadb5c8 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -7,6 +7,7 @@
 
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <linux/delay.h>
 #include <linux/device.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
@@ -25,7 +26,7 @@ struct sunxi_ccu {
 void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock)
 {
 	void __iomem *addr;
-	u32 reg;
+	int i;
 
 	if (!lock)
 		return;
@@ -35,7 +36,14 @@ void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock)
 	else
 		addr = common->base + common->reg;
 
-	WARN_ON(readl_relaxed_poll_timeout(addr, reg, reg & lock, 100, 70000));
+	for (i = 0; i < 100000; i++) {
+		if (readl_relaxed(addr) & lock)
+			return;
+		udelay(1);
+	}
+
+	if (!(readl_relaxed(addr) & lock))
+		pr_warn("%s: clock lock timeout\n", clk_hw_get_name(&common->hw));
 }
 EXPORT_SYMBOL_NS_GPL(ccu_helper_wait_for_lock, "SUNXI_CCU");
 
-- 
2.53.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help