git: cd20e8dcebd5 - main - clk/mediatek: Add MT7986 APMIXEDSYS PLL controller
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 20 Nov 2026 01:13:45 UTC
The branch main has been updated by hayzam:
URL: https://cgit.FreeBSD.org/src/commit/?id=cd20e8dcebd5ad49c03c6fb711eefab070a875b8
commit cd20e8dcebd5ad49c03c6fb711eefab070a875b8
Author: Hayzam Sherif <hayzam@FreeBSD.org>
AuthorDate: 2026-11-04 10:26:50 +0000
Commit: Hayzam Sherif <hayzam@FreeBSD.org>
CommitDate: 2026-11-20 01:10:53 +0000
clk/mediatek: Add MT7986 APMIXEDSYS PLL controller
Add the eight MT7986 PLLs, all fed by the 40 MHz crystal. MPLL,
NET1PLL and NET2PLL never stop: they feed the DRAM, bus and 26 MHz
clocks. ARMPLL clocks the CPUs; to change its rate, a cpufreq driver
moves them to another clock first. APMIXEDSYS attaches after the fixed
clocks.
The rates are the ones set by TF-A BL2, which also starts every PLL.
The register layout and the reset bar bit (CON0 bit 24 on NET2PLL,
MMPLL, WEDMCUPLL, NET1PLL and MPLL) follow MediaTek's TF-A [1][2].
[1] https://github.com/mtk-openwrt/arm-trusted-firmware/blob/a229810586d8/plat/mediatek/mt7986/drivers/pll/pll.c
[2] https://github.com/mtk-openwrt/arm-trusted-firmware/blob/a229810586d8/plat/mediatek/mt7986/drivers/pll/pll.h
Reviewed by: mmel
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61188
---
sys/conf/files.arm64 | 1 +
sys/dev/clk/mediatek/mt7986_apmixedsys.c | 98 ++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64
index 80e58541b4c8..631be0833ab0 100644
--- a/sys/conf/files.arm64
+++ b/sys/conf/files.arm64
@@ -849,6 +849,7 @@ dev/clk/mediatek/mtk_clk.c optional fdt soc_mediatek
dev/clk/mediatek/mtk_clk_gate.c optional fdt soc_mediatek
dev/clk/mediatek/mtk_clk_mux.c optional fdt soc_mediatek
dev/clk/mediatek/mtk_clk_pll.c optional fdt soc_mediatek
+dev/clk/mediatek/mt7986_apmixedsys.c optional fdt soc_mediatek_mt7986
# RockChip Clock support
dev/clk/rockchip/rk_cru.c optional fdt soc_rockchip
diff --git a/sys/dev/clk/mediatek/mt7986_apmixedsys.c b/sys/dev/clk/mediatek/mt7986_apmixedsys.c
new file mode 100644
index 000000000000..ecf1fabd30e8
--- /dev/null
+++ b/sys/dev/clk/mediatek/mt7986_apmixedsys.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2026 Hayzam Sherif <hayzam@FreeBSD.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+/*
+ * MediaTek MT7986 APMIXEDSYS: the PLLs, all fed by the 40 MHz crystal.
+ * NET2PLL, MMPLL, WEDMCUPLL, NET1PLL and MPLL also have a reset bar bit
+ * (CON0 bit 24) that is released once the PLL has locked.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+
+#include <dev/clk/mediatek/mtk_clk.h>
+
+#include <dt-bindings/clock/mt7986-clk.h>
+
+#define MT7986_RST_BAR (1u << 24)
+
+#define MT7986_PLL(_id, _name, _con0, _rst_bar, _flags) \
+ { .type = MTK_CLK_PLL, .pll = { \
+ .clkdef = { .name = (_name), .id = (_id), \
+ .parent_names = (const char *[]){ "clkxtal" }, \
+ .parent_cnt = 1, .flags = (_flags) }, \
+ .con0 = (_con0), .rst_bar = (_rst_bar) } }
+
+static struct mtk_clk_def mt7986_apmixedsys_clks[] = {
+ /* 40 MHz crystal, provided by a fixed-clock node */
+ MTK_LINK("clkxtal"),
+
+ /*
+ * MPLL, NET1PLL and NET2PLL feed the DRAM, bus and 26 MHz clocks: none
+ * of them may ever stop. ARMPLL clocks the CPUs through a mux in
+ * MCUSYS, where a cpufreq driver moves them to another clock while it
+ * changes the rate.
+ */
+ MT7986_PLL(CLK_APMIXED_ARMPLL, "armpll", 0x200, 0, 0),
+ MT7986_PLL(CLK_APMIXED_NET2PLL, "net2pll", 0x210, MT7986_RST_BAR,
+ CLK_NODE_CANNOT_STOP),
+ MT7986_PLL(CLK_APMIXED_MMPLL, "mmpll", 0x220, MT7986_RST_BAR,
+ 0),
+ MT7986_PLL(CLK_APMIXED_SGMPLL, "sgmpll", 0x230, 0, 0),
+ MT7986_PLL(CLK_APMIXED_WEDMCUPLL, "wedmcupll", 0x240, MT7986_RST_BAR,
+ 0),
+ MT7986_PLL(CLK_APMIXED_NET1PLL, "net1pll", 0x250, MT7986_RST_BAR,
+ CLK_NODE_CANNOT_STOP),
+ MT7986_PLL(CLK_APMIXED_MPLL, "mpll", 0x260, MT7986_RST_BAR,
+ CLK_NODE_CANNOT_STOP),
+ MT7986_PLL(CLK_APMIXED_APLL2, "apll2", 0x278, 0, 0),
+};
+
+static const struct mtk_clk_desc mt7986_apmixedsys_desc = {
+ .clks = mt7986_apmixedsys_clks,
+ .nclks = nitems(mt7986_apmixedsys_clks),
+};
+
+static struct ofw_compat_data compat_data[] = {
+ { "mediatek,mt7986-apmixedsys", 1 },
+ { NULL, 0 }
+};
+
+static int
+mt7986_apmixedsys_probe(device_t dev)
+{
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+ if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
+ return (ENXIO);
+ device_set_desc(dev, "MediaTek MT7986 PLL controller");
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+mt7986_apmixedsys_attach(device_t dev)
+{
+ return (mtk_clk_attach(dev, &mt7986_apmixedsys_desc));
+}
+
+static device_method_t mt7986_apmixedsys_methods[] = {
+ DEVMETHOD(device_probe, mt7986_apmixedsys_probe),
+ DEVMETHOD(device_attach, mt7986_apmixedsys_attach),
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(mt7986_apmixedsys, mt7986_apmixedsys_driver,
+ mt7986_apmixedsys_methods, sizeof(struct mtk_clk_softc), mtk_clk_driver);
+
+/* After the fixed clocks, so the ARMPLL reference reaches the crystal. */
+EARLY_DRIVER_MODULE(mt7986_apmixedsys, simplebus, mt7986_apmixedsys_driver,
+ NULL, NULL, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE + 1);