Skip to contentSkip to conversation

clk: add a driver for the ath79 PLL controller

PATCH Superseded Rosen Penev 3 participants 12 messages Nov 11 – Nov 12

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover clk: add a driver for the ath79 PLL controller

The clocks of the Atheros/Qualcomm ath79 MIPS SoCs are set up by arch/mips/ath79/clock.c, a CLK_OF_DECLARE driver that registers every clock before the driver core is up. This series replaces it with a new driver in drivers/clk.

Only the reference and CPU clocks are registered early, with CLK_OF_DECLARE_DRIVER(), because the MIPS timer needs the CPU rate from plat_time_init(). A platform driver bound to the same node registers the DDR, AHB, MDIO, UART1 and PCIe clocks. Until it does, the early provider returns -EPROBE_DEFER for them. clk-mt7621 uses the same scheme.

Patches 1 and 2 move the two remaining non-clock duties out of the arch clock code, so that it only uses its own registers and the clk API: the QCA956x timer interrupt workaround, and the reference clock that is read from the bootstrap pins when the device tree has no rate. Patches 3 and 4 drop ATH79_CLK_END, which is not ABI, from the binding header, and patch 5 adds the UART1 and PCIe PLL clock IDs. Patch 6 adds the new driver, and patch 7 removes the old code.

Tested on a TP-Link Archer C7 v2 (QCA9558) with an LLVM build. The CPU, DDR, AHB and reference rates (960, 800, 266.67 and 40 MHz) match those of the old code. The serial console, both GMACs, the PCIe PLL with a QCA9880 behind it, and the WMAC all work, and no devices are left deferred. The debugfs clk_summary, consumers included, is the same as with v2, and stays the same when the clock-frequency of the reference clock node is removed. The other SoCs are not tested on hardware. For each SoC the rate calculation was compiled in userspace together with the old code and fed 2 million random register sets. The results are identical, except where the old code overflowed 32 bits with register values that no real setup uses.

Changes in v3:
- Register the reference clock read from the bootstrap pins as the provider of the reference clock node instead of with clkdev, so that its other consumers, such as the AR933x UART, find it and fw_devlink doesn't hold the platform driver back when the device tree has no rate. Drop the clk_get_sys() fallbacks (review feedback).
- Wait for the PCIe PLL update to finish after each write in unprepare too (review feedback).
- Add the UART1 and PCIe PLL clock IDs in one patch (review feedback).
- Drop ATH79_CLK_END from the binding header instead of growing it, as the number of clocks is not ABI, after moving the old clock code off it (review feedback).

v2: https://lore.kernel.org/linux-clk/[email protected]/

Changes in v2:
- Post the new driver as one patch, instead of moving arch/mips/ath79/clock.c to drivers/clk and cleaning it up over six patches (review feedback).
- Register only the reference and CPU clocks with CLK_OF_DECLARE, and the others from a platform driver (review feedback).
- Describe the SoCs with match data, and read the CPU, DDR and AHB selection of AR934x and later with one function.
- Keep mapping the AR934x SRIF block from its fixed address. It lies inside the wireless MAC registers, which ath9k claims, so it can't be a reg entry of the PLL node.
- Drop the clkdev registrations, which have no users.

Claude Code (Claude Opus 5.5) was used while preparing this series. It wrote most of the new driver from the old one, together with the userspace test of the rate calculation. I reviewed and tested every change and take responsibility for it.

Rosen Penev (7):
MIPS: ath79: apply the QCA956x timer workaround in setup
MIPS: ath79: move the bootstrap reference clock to setup
MIPS: ath79: stop using ATH79_CLK_END
dt-bindings: clock: ath79: drop ATH79_CLK_END
dt-bindings: clock: ath79: add the UART1 and PCIe PLL clocks
clk: add a driver for the Atheros/Qualcomm ath79 PLL controller
MIPS: ath79: remove the old clock code

 MAINTAINERS                           |   8 +
 arch/mips/ath79/Makefile              |   2 +-
 arch/mips/ath79/clock.c               | 673 ----------------------
 arch/mips/ath79/setup.c               | 107 ++++
 drivers/clk/Kconfig                   |  12 +
 drivers/clk/Makefile                  |   1 +
 drivers/clk/clk-ath79.c               | 782 ++++++++++++++++++++++++++
 include/dt-bindings/clock/ath79-clk.h |   4 +-
 8 files changed, 913 insertions(+), 676 deletions(-)
 delete mode 100644 arch/mips/ath79/clock.c
 create mode 100644 drivers/clk/clk-ath79.c

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

Signature · 1 line
2.56.0
#1 lore raw

PATCH v3 1/7 MIPS: ath79: apply the QCA956x timer workaround in setup

qca956x_clocks_init() enables the MIPS timer interrupt in the misc interrupt controller, which QCA956x needs before the clocks are set up, or there are no jiffies. That has nothing to do with the clocks, and it ties the clock code to ath79_reset_base.

Do it in plat_time_init() right before of_clk_init() instead, which runs the clock setup. The order is the same. TP9343 boards use the QCA956x PLL and took this path too, so check for both.

---
 arch/mips/ath79/clock.c | 10 ----------
 arch/mips/ath79/setup.c | 13 +++++++++++++
 2 files changed, 13 insertions(+), 10 deletions(-)
arch/mips/ath79/clock.c +0 -10
index 050f6553f398..8c5eaa4ab6e0 100644
@@ -523,16 +523,6 @@ static void __init qca956x_clocks_init(void __iomem *pll_base)
 	u32 cpu_pll, ddr_pll;
 	u32 bootstrap;
 
-	/*
-	 * QCA956x timer init workaround has to be applied right before setting
-	 * up the clock. Else, there will be no jiffies
-	 */
-	u32 misc;
-
-	misc = ath79_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE);
-	misc |= MISC_INT_MIPS_SI_TIMERINT_MASK;
-	ath79_reset_wr(AR71XX_RESET_REG_MISC_INT_ENABLE, misc);
-
 	bootstrap = ath79_reset_rr(QCA956X_RESET_REG_BOOTSTRAP);
 	if (bootstrap &	QCA956X_BOOTSTRAP_REF_CLK_40)
 		ref_rate = 40 * 1000 * 1000;
arch/mips/ath79/setup.c +13 -0
index 4e18cdcf65a0..d9e1cc77ad04 100644
@@ -241,6 +241,19 @@ void __init plat_time_init(void)
 	struct clk *clk;
 	unsigned long cpu_clk_rate;
 
+	/*
+	 * QCA956x needs the MIPS timer interrupt enabled in the misc
+	 * interrupt controller before the clocks are set up, or there are
+	 * no jiffies.
+	 */
+	if (soc_is_qca956x() || soc_is_tp9343()) {
+		u32 misc;
+
+		misc = ath79_reset_rr(AR71XX_RESET_REG_MISC_INT_ENABLE);
+		misc |= MISC_INT_MIPS_SI_TIMERINT_MASK;
+		ath79_reset_wr(AR71XX_RESET_REG_MISC_INT_ENABLE, misc);
+	}
+
 	of_clk_init(NULL);
 
 	np = of_get_cpu_node(0, NULL);

base-commit: 630059a5a632377b9b7b487baccde92b7ae1dd47

Signature · 1 line
2.56.0
#2 lore raw

PATCH v3 2/7 MIPS: ath79: move the bootstrap reference clock to setup

In reply to Rosen Penev

The qca,ath79-pll binding requires the reference clock as an input, and a rate in the device tree already took precedence over the 25/40 MHz that the clock code read from the bootstrap pins. Many AR933x boards leave the rate out, though, and rely on the pins.

Read the pins in plat_time_init() instead. When the device tree gives no rate, so that the fixed-clock driver can't register the clock, register it from the pins as the provider of the reference clock node. The clock code then takes it from the device tree, like every other consumer of the node, such as the AR933x UART, and no longer needs ath79_reset_base.

When the device tree does give a rate, warn if it disagrees with the
pins: a wrong rate leaves the CPU, DDR and AHB rates off, the UART baud rate included.

---
 arch/mips/ath79/clock.c | 65 +++++-----------------------
 arch/mips/ath79/setup.c | 94 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 105 insertions(+), 54 deletions(-)
arch/mips/ath79/clock.c +11 -54
index 8c5eaa4ab6e0..6a8bef782186 100644
@@ -25,9 +25,6 @@
 #include <asm/mach-ath79/ar71xx_regs.h>
 #include "common.h"
 
-#define AR71XX_BASE_FREQ	40000000
-#define AR724X_BASE_FREQ	40000000
-
 static struct clk *clks[ATH79_CLK_END];
 static struct clk_onecell_data clk_data = {
 	.clks = clks,
@@ -78,16 +75,12 @@ static struct clk * __init ath79_set_ff_clk(int type, const char *parent,
 	return clk;
 }
 
-static unsigned long __init ath79_setup_ref_clk(unsigned long rate)
+static unsigned long __init ath79_get_ref_rate(void)
 {
-	struct clk *clk = clks[ATH79_CLK_REF];
-
-	if (clk)
-		rate = clk_get_rate(clk);
-	else
-		clk = ath79_set_clk(ATH79_CLK_REF, rate);
+	if (!clks[ATH79_CLK_REF])
+		panic("ath79: no reference clock");
 
-	return rate;
+	return clk_get_rate(clks[ATH79_CLK_REF]);
 }
 
 static void __init ar71xx_clocks_init(void __iomem *pll_base)
@@ -100,7 +93,7 @@ static void __init ar71xx_clocks_init(void __iomem *pll_base)
 	u32 freq;
 	u32 div;
 
-	ref_rate = ath79_setup_ref_clk(AR71XX_BASE_FREQ);
+	ref_rate = ath79_get_ref_rate();
 
 	pll = __raw_readl(pll_base + AR71XX_PLL_REG_CPU_CONFIG);
 
@@ -126,7 +119,7 @@ static void __init ar724x_clocks_init(void __iomem *pll_base)
 	u32 mult, div, ddr_div, ahb_div;
 	u32 pll;
 
-	ath79_setup_ref_clk(AR71XX_BASE_FREQ);
+	ath79_get_ref_rate();
 
 	pll = __raw_readl(pll_base + AR724X_PLL_REG_CPU_CONFIG);
 
@@ -143,7 +136,6 @@ static void __init ar724x_clocks_init(void __iomem *pll_base)
 
 static void __init ar933x_clocks_init(void __iomem *pll_base)
 {
-	unsigned long ref_rate;
 	u32 clock_ctrl;
 	u32 ref_div;
 	u32 ninit_mul;
@@ -152,15 +144,8 @@ static void __init ar933x_clocks_init(void __iomem *pll_base)
 	u32 cpu_div;
 	u32 ddr_div;
 	u32 ahb_div;
-	u32 t;
 
-	t = ath79_reset_rr(AR933X_RESET_REG_BOOTSTRAP);
-	if (t & AR933X_BOOTSTRAP_REF_CLK_40)
-		ref_rate = (40 * 1000 * 1000);
-	else
-		ref_rate = (25 * 1000 * 1000);
-
-	ath79_setup_ref_clk(ref_rate);
+	ath79_get_ref_rate();
 
 	clock_ctrl = __raw_readl(pll_base + AR933X_PLL_CLOCK_CTRL_REG);
 	if (clock_ctrl & AR933X_PLL_CLOCK_CTRL_BYPASS) {
@@ -237,18 +222,11 @@ static void __init ar934x_clocks_init(void __iomem *pll_base)
 	unsigned long ahb_rate;
 	u32 pll, out_div, ref_div, nint, nfrac, frac, clk_ctrl, postdiv;
 	u32 cpu_pll, ddr_pll;
-	u32 bootstrap;
 	void __iomem *dpll_base;
 
 	dpll_base = ioremap(AR934X_SRIF_BASE, AR934X_SRIF_SIZE);
 
-	bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
-	if (bootstrap & AR934X_BOOTSTRAP_REF_CLK_40)
-		ref_rate = 40 * 1000 * 1000;
-	else
-		ref_rate = 25 * 1000 * 1000;
-
-	ref_rate = ath79_setup_ref_clk(ref_rate);
+	ref_rate = ath79_get_ref_rate();
 
 	pll = __raw_readl(dpll_base + AR934X_SRIF_CPU_DPLL2_REG);
 	if (pll & AR934X_SRIF_DPLL2_LOCAL_PLL) {
@@ -355,15 +333,8 @@ static void __init qca953x_clocks_init(void __iomem *pll_base)
 	unsigned long ahb_rate;
 	u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv;
 	u32 cpu_pll, ddr_pll;
-	u32 bootstrap;
-
-	bootstrap = ath79_reset_rr(QCA953X_RESET_REG_BOOTSTRAP);
-	if (bootstrap &	QCA953X_BOOTSTRAP_REF_CLK_40)
-		ref_rate = 40 * 1000 * 1000;
-	else
-		ref_rate = 25 * 1000 * 1000;
 
-	ref_rate = ath79_setup_ref_clk(ref_rate);
+	ref_rate = ath79_get_ref_rate();
 
 	pll = __raw_readl(pll_base + QCA953X_PLL_CPU_CONFIG_REG);
 	out_div = (pll >> QCA953X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
@@ -438,15 +409,8 @@ static void __init qca955x_clocks_init(void __iomem *pll_base)
 	unsigned long ahb_rate;
 	u32 pll, out_div, ref_div, nint, frac, clk_ctrl, postdiv;
 	u32 cpu_pll, ddr_pll;
-	u32 bootstrap;
 
-	bootstrap = ath79_reset_rr(QCA955X_RESET_REG_BOOTSTRAP);
-	if (bootstrap &	QCA955X_BOOTSTRAP_REF_CLK_40)
-		ref_rate = 40 * 1000 * 1000;
-	else
-		ref_rate = 25 * 1000 * 1000;
-
-	ref_rate = ath79_setup_ref_clk(ref_rate);
+	ref_rate = ath79_get_ref_rate();
 
 	pll = __raw_readl(pll_base + QCA955X_PLL_CPU_CONFIG_REG);
 	out_div = (pll >> QCA955X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
@@ -521,15 +485,8 @@ static void __init qca956x_clocks_init(void __iomem *pll_base)
 	unsigned long ahb_rate;
 	u32 pll, out_div, ref_div, nint, hfrac, lfrac, clk_ctrl, postdiv;
 	u32 cpu_pll, ddr_pll;
-	u32 bootstrap;
-
-	bootstrap = ath79_reset_rr(QCA956X_RESET_REG_BOOTSTRAP);
-	if (bootstrap &	QCA956X_BOOTSTRAP_REF_CLK_40)
-		ref_rate = 40 * 1000 * 1000;
-	else
-		ref_rate = 25 * 1000 * 1000;
 
-	ref_rate = ath79_setup_ref_clk(ref_rate);
+	ref_rate = ath79_get_ref_rate();
 
 	pll = __raw_readl(pll_base + QCA956X_PLL_CPU_CONFIG_REG);
 	out_div = (pll >> QCA956X_PLL_CPU_CONFIG_OUTDIV_SHIFT) &
arch/mips/ath79/setup.c +94 -0

112 lines not on this page · raw message

Signature · 1 line
2.56.0
#3 lore raw

PATCH v3 3/7 MIPS: ath79: stop using ATH79_CLK_END

In reply to Rosen Penev

ATH79_CLK_END counts the clocks in the dt-bindings header, which means it has to change whenever a clock is added, but it is not part of the ABI. Size the clock table from the IDs that the clock code uses instead, so the define can be dropped from the header.

---
 arch/mips/ath79/clock.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/mips/ath79/clock.c +4 -2
index 6a8bef782186..55d8ef8c1c8c 100644
@@ -25,13 +25,15 @@
 #include <asm/mach-ath79/ar71xx_regs.h>
 #include "common.h"
 
-static struct clk *clks[ATH79_CLK_END];
+#define ATH79_CLK_NUM	(ATH79_CLK_MDIO + 1)
+
+static struct clk *clks[ATH79_CLK_NUM];
 static struct clk_onecell_data clk_data = {
 	.clks = clks,
 	.clk_num = ARRAY_SIZE(clks),
 };
 
-static const char * const clk_names[ATH79_CLK_END] = {
+static const char * const clk_names[ATH79_CLK_NUM] = {
 	[ATH79_CLK_CPU] = "cpu",
 	[ATH79_CLK_DDR] = "ddr",
 	[ATH79_CLK_AHB] = "ahb",
Signature · 1 line
2.56.0
#4 lore raw

PATCH v3 4/7 dt-bindings: clock: ath79: drop ATH79_CLK_END

In reply to Rosen Penev

ATH79_CLK_END only counts the clocks for the driver. No device tree uses it and it is not part of the ABI, and it would have to change whenever a clock is added. Drop it.

---
 include/dt-bindings/clock/ath79-clk.h | 2 --
 1 file changed, 2 deletions(-)
include/dt-bindings/clock/ath79-clk.h +0 -2
index eec8f399b9e6..27e31452544d 100644
@@ -12,6 +12,4 @@
 #define ATH79_CLK_REF		3
 #define ATH79_CLK_MDIO		4
 
-#define ATH79_CLK_END		5
-
 #endif /* __DT_BINDINGS_ATH79_CLK_H */
Signature · 1 line
2.56.0
Acked-by on v3 4/7
#5 lore raw

Re: [PATCH v3 4/7] dt-bindings: clock: ath79: drop ATH79_CLK_END

Quoted 8 lines · Rosen Penev

ATH79_CLK_END only counts the clocks for the driver. No device tree uses it and it is not part of the ABI, and it would have to change whenever a clock is added. Drop it.

---
 include/dt-bindings/clock/ath79-clk.h | 2 --
 1 file changed, 2 deletions(-)

Best regards,
Krzysztof

#6 lore raw

PATCH v3 5/7 dt-bindings: clock: ath79: add the UART1 and PCIe PLL clocks

In reply to Rosen Penev

Add IDs for two more clocks:

The second, high speed UART of AR934x, which is compatible with the qca,ar9330-uart one, can run from a 100 MHz clock instead of the reference clock.

AR724x, AR934x, QCA953x, QCA955x and QCA956x have a PCIe PLL, which the PCIe host controller nodes need to reference.

---
 include/dt-bindings/clock/ath79-clk.h | 2 ++
 1 file changed, 2 insertions(+)
include/dt-bindings/clock/ath79-clk.h +2 -0
index 27e31452544d..57d966ae9722 100644
@@ -11,5 +11,7 @@
 #define ATH79_CLK_AHB		2
 #define ATH79_CLK_REF		3
 #define ATH79_CLK_MDIO		4
+#define ATH79_CLK_UART1		5
+#define ATH79_CLK_PCIE		6
 
 #endif /* __DT_BINDINGS_ATH79_CLK_H */
Signature · 1 line
2.56.0
Acked-by on v3 5/7
#7 lore raw

Re: [PATCH v3 5/7] dt-bindings: clock: ath79: add the UART1 and PCIe PLL clocks

Quoted 6 lines · Rosen Penev

Add IDs for two more clocks:

The second, high speed UART of AR934x, which is compatible with the qca,ar9330-uart one, can run from a 100 MHz clock instead of the reference clock.

Quoted 7 lines

AR724x, AR934x, QCA953x, QCA955x and QCA956x have a PCIe PLL, which the PCIe host controller nodes need to reference.

---
 include/dt-bindings/clock/ath79-clk.h | 2 ++
 1 file changed, 2 insertions(+)

Best regards,
Krzysztof

#8 lore raw

PATCH v3 6/7 clk: add a driver for the Atheros/Qualcomm ath79 PLL controller

In reply to Rosen Penev

The ath79 clocks are set up by arch/mips/ath79/clock.c, a CLK_OF_DECLARE driver that registers every clock before the driver core is up. Add a replacement in drivers/clk.

Only the reference and CPU clocks are registered early, with CLK_OF_DECLARE_DRIVER(), as the MIPS timer needs the CPU rate from plat_time_init(). The other clocks come from a platform driver for the same node, like the MT7621 clocks do. The early provider returns -EPROBE_DEFER for them until the platform driver fills them in.

The bootloader sets up the PLLs, and the CPU, DDR and AHB clocks are read back from the registers as fixed rates, as before. Compared to the arch code:

- Each SoC is described by match data: a function that reads the rates, and for AR934x and later the bits of CPU_DDR_CLOCK_CONTROL that select a PLL for each clock. The bypass bits and post dividers of that register are the same on every SoC, so one function handles them. AR934x, QCA953x and QCA955x share the fractional PLL calculation, done with 64-bit intermediates.
- The AR724x and AR933x clocks were fixed factors of a parent named "ref". They are fixed rates now, like the others, all with the reference clock's clk_hw as the parent.
- Invalid register contents, a reference clock that is missing and registration failures are reported instead of causing a panic or a division by zero.
- The AR934x SRIF block, which holds the CPU and DDR DPLLs, is still mapped from its fixed address. It lies inside the register space of the wireless MAC, which ath9k claims, so it can't be a reg entry of the PLL node. The driver only reads it and doesn't claim it.
- The clocks are no longer registered with clkdev. No driver looks them up by name.
- AR934x gets its UART1 clock: 100 MHz when UART1_CLK_SEL is set in SWITCH_CLOCK_CONTROL, the reference clock otherwise and on the other SoCs. This is based on an OpenWrt patch by Daniel Golle.
- The PCIe PLL is a clock, so that a PCIe host driver can use the clk API instead of poking the PLL block through the arch code. Prepare powers the PLL up and takes it out of bypass, and unprepare does the reverse, waiting for UPDATING to clear after each step. Every write to the register freezes the high speed clocks for about 60 us (AR7242 datasheet, 4.4.4), so a PLL the bootloader already started is left alone. AR724x holds the PLL in reset instead of powering it down, and the register is at 0x10 on AR724x, AR934x and QCA953x, 0x0c on QCA955x and 0x14 on QCA956x. The clock is CLK_IGNORE_UNUSED, so a PLL that no driver claims stays as the bootloader left it.

The rates match the arch code for every SoC, checked in userspace against it with random register values. They differ only where the arch code overflowed 32 bits with register values that no real setup uses.

COMMON_CLK_ATH79 defaults to ATH79, and arch/mips/ath79/clock.c is no longer built when it is enabled.

---
 MAINTAINERS              |   8 +
 arch/mips/ath79/Makefile |   5 +-
 drivers/clk/Kconfig      |  12 +
 drivers/clk/Makefile     |   1 +
 drivers/clk/clk-ath79.c  | 782 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 807 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/clk-ath79.c
MAINTAINERS +8 -0
index c57be10c8729..98f42425b37d 100644
@@ -4341,6 +4341,14 @@ S:	Supported
 F:	Documentation/devicetree/bindings/rtc/andestech,atcrtc100.yaml
 F:	drivers/rtc/rtc-atcrtc100.c
 
+ATHEROS 71XX/9XXX CLOCK DRIVER
+M:	Alban Bedel <[email protected]>
+M:	Antony Pavlov <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/clock/qca,ath79-pll.yaml
+F:	drivers/clk/clk-ath79.c
+F:	include/dt-bindings/clock/ath79-clk.h
+
 ATHEROS 71XX/9XXX GPIO DRIVER
 M:	Alban Bedel <[email protected]>
 S:	Maintained
arch/mips/ath79/Makefile +4 -1
index 0fb3aaf42149..b78ffdc9b389 100644
@@ -6,6 +6,9 @@
 # Copyright (C) 2008 Imre Kaloz <[email protected]>
 #
 
-obj-y	:= prom.o setup.o common.o clock.o
+obj-y	:= prom.o setup.o common.o
+
+# replaced by the clk-ath79 driver
+obj-$(if $(CONFIG_COMMON_CLK_ATH79),,y) += clock.o
 
 obj-$(CONFIG_EARLY_PRINTK)		+= early_printk.o
drivers/clk/Kconfig +12 -0
index 37a8e35d4178..bd5f77cddfe0 100644
@@ -66,6 +66,18 @@ config COMMON_CLK_APPLE_NCO
 	  found on Apple SoCs such as t8103 (M1). The blocks are typically
 	  generators of audio clocks.
 
+config COMMON_CLK_ATH79
+	bool "Clock driver for Atheros/Qualcomm ath79 SoCs" if COMPILE_TEST
+	depends on ATH79 || COMPILE_TEST
+	depends on OF
+	default ATH79
+	help
+	  Support for the PLL controller of the Atheros/Qualcomm ath79
+	  family of MIPS SoCs: AR71xx, AR724x, AR913x, AR933x, AR934x,
+	  QCA953x, QCA955x and QCA956x. It provides the CPU, DDR, AHB,
+	  MDIO, UART1 and PCIe clocks, derived from the board's reference
+	  clock.
+
 config COMMON_CLK_MAX77686
 	tristate "Clock driver for Maxim 77620/77686/77802 MFD"
 	depends on MFD_MAX77686 || MFD_MAX77620 || COMPILE_TEST
drivers/clk/Makefile +1 -0
index 52d138d4ffc8..589d2ef9dc89 100644
@@ -58,6 +58,7 @@ endif
 # please keep this section sorted lexicographically by file path name
 obj-$(CONFIG_COMMON_CLK_APPLE_NCO)  	+= clk-apple-nco.o
 obj-$(CONFIG_MACH_ASM9260)		+= clk-asm9260.o
+obj-$(CONFIG_COMMON_CLK_ATH79)		+= clk-ath79.o
 obj-$(CONFIG_COMMON_CLK_AXI_CLKGEN)	+= clk-axi-clkgen.o
 obj-$(CONFIG_ARCH_AXXIA)		+= clk-axm5516.o
 obj-$(CONFIG_COMMON_CLK_BD718XX)	+= clk-bd718x7.o
drivers/clk/clk-ath79.c new file +782 -0

782 lines not on this page · raw message

Signature · 1 line
2.56.0
#9 lore raw

Re: [PATCH v3 6/7] clk: add a driver for the Atheros/Qualcomm ath79 PLL controller

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] clk: ath79: zeroed hfrac shift in qca956x_pll_rate() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] clk: ath79: zeroed hfrac shift in qca956x_pll_rate() --

commit 423abf763de32c1b127032d8210181c833b02aa9
Author: Rosen Penev <[email protected]>

clk: add a driver for the Atheros/Qualcomm ath79 PLL controller

This commit adds a common clock driver for the Atheros/Qualcomm ath79 PLL controller to replace the arch/mips/ath79/clock.c setup code.

Quoted 6 lines
drivers/clk/clk-ath79.c new file +0 -0
new file mode 100644
index 0000000000000..6eab4cd1a91f7
@@ -0,0 +1,782 @@

[ ... ]

Quoted 3 lines
drivers/clk/clk-ath79.c new file +3 -0
+#define QCA956X_PLL_CONFIG1_NFRAC_L			GENMASK(4, 0)
+#define QCA956X_PLL_CONFIG1_NFRAC_H			GENMASK(17, 5)
+#define QCA956X_PLL_CONFIG1_NINT			GENMASK(26, 18)

[ ... ]

Quoted 9 lines
drivers/clk/clk-ath79.c new file +9 -0
+static unsigned long qca956x_pll_rate(unsigned long ref, u32 config,
+				      u32 config1, u32 refdiv_mask,
+				      u32 outdiv_mask)
+{
+	u32 ref_div, out_div, nint, hfrac, lfrac;
+	u64 rate;
+
+	ref_div = (config & refdiv_mask) >> __ffs(refdiv_mask);
+	out_div = (config & outdiv_mask) >> __ffs(outdiv_mask);

drivers/clk/clk-ath79.c line 365

Quoted 10 lines
drivers/clk/clk-ath79.c new file +10 -0
+	nint = FIELD_GET(QCA956X_PLL_CONFIG1_NINT, config1);
+	hfrac = FIELD_GET(QCA956X_PLL_CONFIG1_NFRAC_H, config1);
+	lfrac = FIELD_GET(QCA956X_PLL_CONFIG1_NFRAC_L, config1);
+
+	if (!ref_div)
+		return 0;
+
+	rate = div_u64((u64)ref * nint, ref_div);
+	rate += div_u64((u64)ref * lfrac, (ref_div * 25) << 13);
+	rate += div_u64((u64)ref * (hfrac >> 13), ref_div);

[Severity: Medium]
Does (hfrac >> 13) always evaluate to 0 here? QCA956X_PLL_CONFIG1_NFRAC_H is a 13-bit mask (GENMASK(17, 5)), so hfrac is at most 0x1fff and shifting it right by 13 drops the upper fractional multiplier completely when computing the QCA956x CPU, DDR, and AHB clock rates. Matching the lfrac term above, it looks like the divisor should be shifted instead:
div_u64((u64)ref * hfrac, ref_div << 13).

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#10 lore raw

Re: [PATCH v3 6/7] clk: add a driver for the Atheros/Qualcomm ath79 PLL controller

Quoted 49 lines · On Wed, Nov 11, 2026 at 2:14 PM <[email protected]> wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] clk: ath79: zeroed hfrac shift in qca956x_pll_rate() --

commit 423abf763de32c1b127032d8210181c833b02aa9
Author: Rosen Penev <[email protected]>

clk: add a driver for the Atheros/Qualcomm ath79 PLL controller

This commit adds a common clock driver for the Atheros/Qualcomm ath79 PLL controller to replace the arch/mips/ath79/clock.c setup code.

Quoted 6 lines
drivers/clk/clk-ath79.c new file +0 -0
new file mode 100644
index 0000000000000..6eab4cd1a91f7
@@ -0,0 +1,782 @@

[ ... ]

Quoted 3 lines
drivers/clk/clk-ath79.c new file +3 -0
+#define QCA956X_PLL_CONFIG1_NFRAC_L                  GENMASK(4, 0)
+#define QCA956X_PLL_CONFIG1_NFRAC_H                  GENMASK(17, 5)
+#define QCA956X_PLL_CONFIG1_NINT                     GENMASK(26, 18)

[ ... ]

Quoted 9 lines
drivers/clk/clk-ath79.c new file +9 -0
+static unsigned long qca956x_pll_rate(unsigned long ref, u32 config,
+                                   u32 config1, u32 refdiv_mask,
+                                   u32 outdiv_mask)
+{
+     u32 ref_div, out_div, nint, hfrac, lfrac;
+     u64 rate;
+
+     ref_div = (config & refdiv_mask) >> __ffs(refdiv_mask);
+     out_div = (config & outdiv_mask) >> __ffs(outdiv_mask);

drivers/clk/clk-ath79.c line 365

Quoted 10 lines
drivers/clk/clk-ath79.c new file +10 -0
+     nint = FIELD_GET(QCA956X_PLL_CONFIG1_NINT, config1);
+     hfrac = FIELD_GET(QCA956X_PLL_CONFIG1_NFRAC_H, config1);
+     lfrac = FIELD_GET(QCA956X_PLL_CONFIG1_NFRAC_L, config1);
+
+     if (!ref_div)
+             return 0;
+
+     rate = div_u64((u64)ref * nint, ref_div);
+     rate += div_u64((u64)ref * lfrac, (ref_div * 25) << 13);
+     rate += div_u64((u64)ref * (hfrac >> 13), ref_div);
Quoted 7 lines

[Severity: Medium]
Does (hfrac >> 13) always evaluate to 0 here? QCA956X_PLL_CONFIG1_NFRAC_H is a 13-bit mask (GENMASK(17, 5)), so hfrac is at most 0x1fff and shifting it right by 13 drops the upper fractional multiplier completely when computing the QCA956x CPU, DDR, and AHB clock rates. Matching the lfrac term above, it looks like the divisor should be shifted instead:
div_u64((u64)ref * hfrac, ref_div << 13).

This was present in the old code. Unfortunately, I don't have the hardware to test this.

Quoted 3 lines

--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6

#11 lore raw

PATCH v3 7/7 MIPS: ath79: remove the old clock code

In reply to Rosen Penev

The clk-ath79 driver in drivers/clk has replaced arch/mips/ath79/clock.c, which is no longer built. Remove it.

---
 arch/mips/ath79/Makefile |   3 -
 arch/mips/ath79/clock.c  | 622 ---------------------------------------
 2 files changed, 625 deletions(-)
 delete mode 100644 arch/mips/ath79/clock.c
arch/mips/ath79/Makefile +0 -3
index b78ffdc9b389..5df55b5e1c15 100644
@@ -8,7 +8,4 @@
 
 obj-y	:= prom.o setup.o common.o
 
-# replaced by the clk-ath79 driver
-obj-$(if $(CONFIG_COMMON_CLK_ATH79),,y) += clock.o
-
 obj-$(CONFIG_EARLY_PRINTK)		+= early_printk.o
arch/mips/ath79/clock.c deleted +0 -622

622 lines not on this page · raw message

Signature · 1 line
2.56.0