git: da4aca33d26e - main - aw_ccu: d1: Set the lock enable bit of the PLLs

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Fri, 13 Nov 2026 07:29:49 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=da4aca33d26eef787786f4ced9fab1337520de5d

commit da4aca33d26eef787786f4ced9fab1337520de5d
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-13 06:41:53 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-13 07:29:30 +0000

    aw_ccu: d1: Set the lock enable bit of the PLLs
    
    The lock status bit of a PLL is only updated when its lock enable bit,
    bit 29, is set, and the firmware only sets it for the PLLs it uses.
    Enabling another PLL, or changing the rate of an enabled one, then
    waited for a lock that never came and ended after a second with an
    error.  Set the bit on all the PLLs when attaching, like Linux does.
    
    Reported by:    llm-postcr
    Fixes:          92b59f3d010d ("aw_clk: Wait for the PLL to lock when enabling it")
---
 sys/dev/clk/allwinner/ccu_d1.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/sys/dev/clk/allwinner/ccu_d1.c b/sys/dev/clk/allwinner/ccu_d1.c
index cb9137976e69..45655b651812 100644
--- a/sys/dev/clk/allwinner/ccu_d1.c
+++ b/sys/dev/clk/allwinner/ccu_d1.c
@@ -1018,6 +1018,23 @@ static struct aw_ccung_clk ccu_d1_clks[] = {
 	{ .type = AW_CLK_DIV,	.clk.div	= &riscv_axi_clk},
 };
 
+/*
+ * Registers of the PLLs, the lock status bit of a PLL is only updated when
+ * its lock enable bit is set.
+ */
+#define	PLL_LOCK_ENABLE		(1 << 29)
+
+static const bus_size_t d1_pll_regs[] = {
+	0x00,	/* PLL_CPUX */
+	0x10,	/* PLL_DDR0 */
+	0x20,	/* PLL_PERIPH0 */
+	0x40,	/* PLL_VIDEO0 */
+	0x48,	/* PLL_VIDEO1 */
+	0x58,	/* PLL_VE */
+	0x78,	/* PLL_AUDIO0 */
+	0x80,	/* PLL_AUDIO1 */
+};
+
 static int
 ccu_d1_probe(device_t dev)
 {
@@ -1035,6 +1052,8 @@ static int
 ccu_d1_attach(device_t dev)
 {
 	struct aw_ccung_softc *sc;
+	uint32_t val;
+	int error, i;
 
 	sc = device_get_softc(dev);
 
@@ -1045,7 +1064,20 @@ ccu_d1_attach(device_t dev)
 	sc->clks = ccu_d1_clks;
 	sc->nclks = nitems(ccu_d1_clks);
 
-	return (aw_ccung_attach(dev));
+	error = aw_ccung_attach(dev);
+	if (error != 0)
+		return (error);
+
+	/*
+	 * Only the PLLs used by the firmware have the lock enable bit set,
+	 * set it for all of them so that we can wait for them to lock.
+	 */
+	for (i = 0; i < nitems(d1_pll_regs); i++) {
+		val = bus_read_4(sc->res, d1_pll_regs[i]);
+		bus_write_4(sc->res, d1_pll_regs[i], val | PLL_LOCK_ENABLE);
+	}
+
+	return (0);
 }
 
 static device_method_t ccu_d1_methods[] = {