blob: 8f4e8f4e8c9c3f76331fb524214ec71947749313 [file] [log] [blame]
Weijie Gao42143692023-07-19 17:16:28 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7988 SoC
4 *
5 * Copyright (C) 2022 MediaTek Inc.
6 * Author: Sam Shih <sam.shih@mediatek.com>
7 */
8
9#include <dm.h>
10#include <log.h>
11#include <asm/arch-mediatek/reset.h>
12#include <asm/io.h>
13#include <dt-bindings/clock/mt7988-clk.h>
14#include <linux/bitops.h>
15
16#include "clk-mtk.h"
17
18#define MT7988_CLK_PDN 0x250
19#define MT7988_CLK_PDN_EN_WRITE BIT(31)
20
21#define MT7988_ETHDMA_RST_CTRL_OFS 0x34
22#define MT7988_ETHWARP_RST_CTRL_OFS 0x8
23
24#define XTAL_FACTOR(_id, _name, _parent, _mult, _div) \
25 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_XTAL)
26
27#define PLL_FACTOR(_id, _name, _parent, _mult, _div) \
28 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
29
30#define TOP_FACTOR(_id, _name, _parent, _mult, _div) \
31 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
32
33#define INFRA_FACTOR(_id, _name, _parent, _mult, _div) \
34 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_INFRASYS)
35
36/* FIXED PLLS */
37static const struct mtk_fixed_clk apmixedsys_mtk_plls[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +020038 FIXED_CLK(CLK_APMIXED_NETSYSPLL, CLK_XTAL, 850000000),
39 FIXED_CLK(CLK_APMIXED_MPLL, CLK_XTAL, 416000000),
40 FIXED_CLK(CLK_APMIXED_MMPLL, CLK_XTAL, 720000000),
41 FIXED_CLK(CLK_APMIXED_APLL2, CLK_XTAL, 196608000),
42 FIXED_CLK(CLK_APMIXED_NET1PLL, CLK_XTAL, 2500000000),
43 FIXED_CLK(CLK_APMIXED_NET2PLL, CLK_XTAL, 800000000),
44 FIXED_CLK(CLK_APMIXED_WEDMCUPLL, CLK_XTAL, 208000000),
45 FIXED_CLK(CLK_APMIXED_SGMPLL, CLK_XTAL, 325000000),
46 FIXED_CLK(CLK_APMIXED_ARM_B, CLK_XTAL, 1500000000),
47 FIXED_CLK(CLK_APMIXED_CCIPLL2_B, CLK_XTAL, 960000000),
48 FIXED_CLK(CLK_APMIXED_USXGMIIPLL, CLK_XTAL, 644533000),
49 FIXED_CLK(CLK_APMIXED_MSDCPLL, CLK_XTAL, 400000000),
Weijie Gao42143692023-07-19 17:16:28 +080050};
51
Christian Marangid061f732024-08-03 10:32:58 +020052/* TOPCKGEN FIXED CLK */
53static const struct mtk_fixed_clk topckgen_mtk_fixed_clks[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +020054 FIXED_CLK(CLK_TOP_XTAL, CLK_XTAL, 40000000),
Christian Marangid061f732024-08-03 10:32:58 +020055};
56
Weijie Gao42143692023-07-19 17:16:28 +080057/* TOPCKGEN FIXED DIV */
58static const struct mtk_fixed_factor topckgen_mtk_fixed_factors[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +020059 TOP_FACTOR(CLK_TOP_XTAL_D2, "xtal_d2", CLK_TOP_XTAL, 1, 2),
60 TOP_FACTOR(CLK_TOP_RTC_32K, "rtc_32k", CLK_TOP_XTAL, 1,
Weijie Gao42143692023-07-19 17:16:28 +080061 1250),
Christian Marangi99c5fa12024-08-03 10:33:02 +020062 TOP_FACTOR(CLK_TOP_RTC_32P7K, "rtc_32p7k", CLK_TOP_XTAL, 1,
Weijie Gao42143692023-07-19 17:16:28 +080063 1220),
Christian Marangi99c5fa12024-08-03 10:33:02 +020064 PLL_FACTOR(CLK_TOP_MPLL_D2, "mpll_d2", CLK_APMIXED_MPLL, 1, 2),
65 PLL_FACTOR(CLK_TOP_MPLL_D3_D2, "mpll_d3_d2", CLK_APMIXED_MPLL, 1, 2),
66 PLL_FACTOR(CLK_TOP_MPLL_D4, "mpll_d4", CLK_APMIXED_MPLL, 1, 4),
67 PLL_FACTOR(CLK_TOP_MPLL_D8, "mpll_d8", CLK_APMIXED_MPLL, 1, 8),
68 PLL_FACTOR(CLK_TOP_MPLL_D8_D2, "mpll_d8_d2", CLK_APMIXED_MPLL, 1, 16),
69 PLL_FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", CLK_APMIXED_MMPLL, 1, 2),
70 PLL_FACTOR(CLK_TOP_MMPLL_D3_D5, "mmpll_d3_d5", CLK_APMIXED_MMPLL, 1, 15),
71 PLL_FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", CLK_APMIXED_MMPLL, 1, 4),
72 PLL_FACTOR(CLK_TOP_MMPLL_D6_D2, "mmpll_d6_d2", CLK_APMIXED_MMPLL, 1, 12),
73 PLL_FACTOR(CLK_TOP_MMPLL_D8, "mmpll_d8", CLK_APMIXED_MMPLL, 1, 8),
74 PLL_FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", CLK_APMIXED_APLL2, 1, 4),
75 PLL_FACTOR(CLK_TOP_NET1PLL_D4, "net1pll_d4", CLK_APMIXED_NET1PLL, 1, 4),
76 PLL_FACTOR(CLK_TOP_NET1PLL_D5, "net1pll_d5", CLK_APMIXED_NET1PLL, 1, 5),
77 PLL_FACTOR(CLK_TOP_NET1PLL_D5_D2, "net1pll_d5_d2", CLK_APMIXED_NET1PLL, 1, 10),
78 PLL_FACTOR(CLK_TOP_NET1PLL_D5_D4, "net1pll_d5_d4", CLK_APMIXED_NET1PLL, 1, 20),
79 PLL_FACTOR(CLK_TOP_NET1PLL_D8, "net1pll_d8", CLK_APMIXED_NET1PLL, 1, 8),
80 PLL_FACTOR(CLK_TOP_NET1PLL_D8_D2, "net1pll_d8_d2", CLK_APMIXED_NET1PLL, 1, 16),
81 PLL_FACTOR(CLK_TOP_NET1PLL_D8_D4, "net1pll_d8_d4", CLK_APMIXED_NET1PLL, 1, 32),
82 PLL_FACTOR(CLK_TOP_NET1PLL_D8_D8, "net1pll_d8_d8", CLK_APMIXED_NET1PLL, 1, 64),
83 PLL_FACTOR(CLK_TOP_NET1PLL_D8_D16, "net1pll_d8_d16", CLK_APMIXED_NET1PLL, 1,
Christian Marangi1bafda92024-08-03 10:32:57 +020084 128),
Christian Marangi99c5fa12024-08-03 10:33:02 +020085 PLL_FACTOR(CLK_TOP_NET2PLL_D2, "net2pll_d2", CLK_APMIXED_NET2PLL, 1, 2),
86 PLL_FACTOR(CLK_TOP_NET2PLL_D4, "net2pll_d4", CLK_APMIXED_NET2PLL, 1, 4),
87 PLL_FACTOR(CLK_TOP_NET2PLL_D4_D4, "net2pll_d4_d4", CLK_APMIXED_NET2PLL, 1, 16),
88 PLL_FACTOR(CLK_TOP_NET2PLL_D4_D8, "net2pll_d4_d8", CLK_APMIXED_NET2PLL, 1, 32),
89 PLL_FACTOR(CLK_TOP_NET2PLL_D6, "net2pll_d6", CLK_APMIXED_NET2PLL, 1, 6),
90 PLL_FACTOR(CLK_TOP_NET2PLL_D8, "net2pll_d8", CLK_APMIXED_NET2PLL, 1, 8),
Weijie Gao42143692023-07-19 17:16:28 +080091};
92
93/* TOPCKGEN MUX PARENTS */
Christian Marangid061f732024-08-03 10:32:58 +020094#define APMIXED_PARENT(_id) PARENT(_id, CLK_PARENT_APMIXED)
95#define TOP_PARENT(_id) PARENT(_id, CLK_PARENT_TOPCKGEN)
Weijie Gao42143692023-07-19 17:16:28 +080096
Christian Marangid061f732024-08-03 10:32:58 +020097static const struct mtk_parent netsys_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +020098 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D2),
99 TOP_PARENT(CLK_TOP_MMPLL_D2),
Weijie Gao42143692023-07-19 17:16:28 +0800100};
101
Christian Marangid061f732024-08-03 10:32:58 +0200102static const struct mtk_parent netsys_500m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200103 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5),
104 TOP_PARENT(CLK_TOP_NET1PLL_D5_D2),
Weijie Gao42143692023-07-19 17:16:28 +0800105};
106
Christian Marangid061f732024-08-03 10:32:58 +0200107static const struct mtk_parent netsys_2x_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200108 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_NET2PLL),
109 APMIXED_PARENT(CLK_APMIXED_MMPLL),
Weijie Gao42143692023-07-19 17:16:28 +0800110};
111
Christian Marangid061f732024-08-03 10:32:58 +0200112static const struct mtk_parent netsys_gsw_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200113 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D4),
114 TOP_PARENT(CLK_TOP_NET1PLL_D5),
Christian Marangid061f732024-08-03 10:32:58 +0200115};
Weijie Gao42143692023-07-19 17:16:28 +0800116
Christian Marangid061f732024-08-03 10:32:58 +0200117static const struct mtk_parent eth_gmii_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200118 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200119};
Weijie Gao42143692023-07-19 17:16:28 +0800120
Christian Marangid061f732024-08-03 10:32:58 +0200121static const struct mtk_parent netsys_mcu_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200122 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_NET2PLL),
123 APMIXED_PARENT(CLK_APMIXED_MMPLL), TOP_PARENT(CLK_TOP_NET1PLL_D4),
124 TOP_PARENT(CLK_TOP_NET1PLL_D5), APMIXED_PARENT(CLK_APMIXED_MPLL),
Christian Marangid061f732024-08-03 10:32:58 +0200125};
Weijie Gao42143692023-07-19 17:16:28 +0800126
Christian Marangid061f732024-08-03 10:32:58 +0200127static const struct mtk_parent eip197_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200128 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_NETSYSPLL),
129 APMIXED_PARENT(CLK_APMIXED_NET2PLL), APMIXED_PARENT(CLK_APMIXED_MMPLL),
130 TOP_PARENT(CLK_TOP_NET1PLL_D4), TOP_PARENT(CLK_TOP_NET1PLL_D5),
Christian Marangid061f732024-08-03 10:32:58 +0200131};
Weijie Gao42143692023-07-19 17:16:28 +0800132
Christian Marangid061f732024-08-03 10:32:58 +0200133static const struct mtk_parent axi_infra_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200134 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D8_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200135};
Weijie Gao42143692023-07-19 17:16:28 +0800136
Christian Marangid061f732024-08-03 10:32:58 +0200137static const struct mtk_parent uart_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200138 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MPLL_D8),
139 TOP_PARENT(CLK_TOP_MPLL_D8_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200140};
Weijie Gao42143692023-07-19 17:16:28 +0800141
Christian Marangid061f732024-08-03 10:32:58 +0200142static const struct mtk_parent emmc_250m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200143 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5_D2),
144 TOP_PARENT(CLK_TOP_MMPLL_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200145};
Weijie Gao42143692023-07-19 17:16:28 +0800146
Christian Marangid061f732024-08-03 10:32:58 +0200147static const struct mtk_parent emmc_400m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200148 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_MSDCPLL),
149 TOP_PARENT(CLK_TOP_MMPLL_D2), TOP_PARENT(CLK_TOP_MPLL_D2),
150 TOP_PARENT(CLK_TOP_MMPLL_D4), TOP_PARENT(CLK_TOP_NET1PLL_D8_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200151};
Weijie Gao42143692023-07-19 17:16:28 +0800152
Christian Marangid061f732024-08-03 10:32:58 +0200153static const struct mtk_parent spi_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200154 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MPLL_D2),
155 TOP_PARENT(CLK_TOP_MMPLL_D4), TOP_PARENT(CLK_TOP_NET1PLL_D8_D2),
156 TOP_PARENT(CLK_TOP_NET2PLL_D6), TOP_PARENT(CLK_TOP_NET1PLL_D5_D4),
157 TOP_PARENT(CLK_TOP_MPLL_D4), TOP_PARENT(CLK_TOP_NET1PLL_D8_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200158};
Weijie Gao42143692023-07-19 17:16:28 +0800159
Christian Marangid061f732024-08-03 10:32:58 +0200160static const struct mtk_parent nfi1x_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200161 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MMPLL_D4),
162 TOP_PARENT(CLK_TOP_NET1PLL_D8_D2), TOP_PARENT(CLK_TOP_NET2PLL_D6),
163 TOP_PARENT(CLK_TOP_MPLL_D4), TOP_PARENT(CLK_TOP_MMPLL_D8),
164 TOP_PARENT(CLK_TOP_NET1PLL_D8_D4), TOP_PARENT(CLK_TOP_MPLL_D8),
Christian Marangid061f732024-08-03 10:32:58 +0200165};
Weijie Gao42143692023-07-19 17:16:28 +0800166
Christian Marangid061f732024-08-03 10:32:58 +0200167static const struct mtk_parent spinfi_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200168 TOP_PARENT(CLK_TOP_XTAL_D2), TOP_PARENT(CLK_TOP_XTAL),
169 TOP_PARENT(CLK_TOP_NET1PLL_D5_D4), TOP_PARENT(CLK_TOP_MPLL_D4),
170 TOP_PARENT(CLK_TOP_MMPLL_D8), TOP_PARENT(CLK_TOP_NET1PLL_D8_D4),
171 TOP_PARENT(CLK_TOP_MMPLL_D6_D2), TOP_PARENT(CLK_TOP_MPLL_D8),
Christian Marangid061f732024-08-03 10:32:58 +0200172};
Weijie Gao42143692023-07-19 17:16:28 +0800173
Christian Marangid061f732024-08-03 10:32:58 +0200174static const struct mtk_parent pwm_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200175 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D8_D2),
176 TOP_PARENT(CLK_TOP_NET1PLL_D5_D4), TOP_PARENT(CLK_TOP_MPLL_D4),
177 TOP_PARENT(CLK_TOP_MPLL_D8_D2), TOP_PARENT(CLK_TOP_RTC_32K),
Christian Marangid061f732024-08-03 10:32:58 +0200178};
Weijie Gao42143692023-07-19 17:16:28 +0800179
Christian Marangid061f732024-08-03 10:32:58 +0200180static const struct mtk_parent i2c_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200181 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5_D4),
182 TOP_PARENT(CLK_TOP_MPLL_D4), TOP_PARENT(CLK_TOP_NET1PLL_D8_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200183};
Weijie Gao42143692023-07-19 17:16:28 +0800184
Christian Marangid061f732024-08-03 10:32:58 +0200185static const struct mtk_parent pcie_mbist_250m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200186 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200187};
Weijie Gao42143692023-07-19 17:16:28 +0800188
Christian Marangid061f732024-08-03 10:32:58 +0200189static const struct mtk_parent pextp_tl_ck_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200190 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D6),
191 TOP_PARENT(CLK_TOP_MMPLL_D8), TOP_PARENT(CLK_TOP_MPLL_D8_D2),
192 TOP_PARENT(CLK_TOP_RTC_32K),
Christian Marangid061f732024-08-03 10:32:58 +0200193};
Weijie Gao42143692023-07-19 17:16:28 +0800194
Christian Marangid061f732024-08-03 10:32:58 +0200195static const struct mtk_parent usb_frmcnt_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200196 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MMPLL_D3_D5),
Christian Marangid061f732024-08-03 10:32:58 +0200197};
Weijie Gao42143692023-07-19 17:16:28 +0800198
Christian Marangid061f732024-08-03 10:32:58 +0200199static const struct mtk_parent aud_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200200 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_APLL2),
Christian Marangid061f732024-08-03 10:32:58 +0200201};
Weijie Gao42143692023-07-19 17:16:28 +0800202
Christian Marangid061f732024-08-03 10:32:58 +0200203static const struct mtk_parent a1sys_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200204 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_APLL2_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200205};
Weijie Gao42143692023-07-19 17:16:28 +0800206
Christian Marangid061f732024-08-03 10:32:58 +0200207static const struct mtk_parent aud_l_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200208 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_APLL2),
209 TOP_PARENT(CLK_TOP_MPLL_D8_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200210};
Weijie Gao42143692023-07-19 17:16:28 +0800211
Christian Marangid061f732024-08-03 10:32:58 +0200212static const struct mtk_parent sspxtp_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200213 TOP_PARENT(CLK_TOP_XTAL_D2), TOP_PARENT(CLK_TOP_MPLL_D8_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200214};
Weijie Gao42143692023-07-19 17:16:28 +0800215
Christian Marangid061f732024-08-03 10:32:58 +0200216static const struct mtk_parent usxgmii_sbus_0_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200217 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D8_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200218};
Weijie Gao42143692023-07-19 17:16:28 +0800219
Christian Marangid061f732024-08-03 10:32:58 +0200220static const struct mtk_parent sgm_0_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200221 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_SGMPLL),
Christian Marangid061f732024-08-03 10:32:58 +0200222};
Weijie Gao42143692023-07-19 17:16:28 +0800223
Christian Marangid061f732024-08-03 10:32:58 +0200224static const struct mtk_parent sysapb_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200225 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MPLL_D3_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200226};
Weijie Gao42143692023-07-19 17:16:28 +0800227
Christian Marangid061f732024-08-03 10:32:58 +0200228static const struct mtk_parent eth_refck_50m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200229 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D4_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200230};
Weijie Gao42143692023-07-19 17:16:28 +0800231
Christian Marangid061f732024-08-03 10:32:58 +0200232static const struct mtk_parent eth_sys_200m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200233 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200234};
Weijie Gao42143692023-07-19 17:16:28 +0800235
Christian Marangid061f732024-08-03 10:32:58 +0200236static const struct mtk_parent eth_xgmii_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200237 TOP_PARENT(CLK_TOP_XTAL_D2), TOP_PARENT(CLK_TOP_NET1PLL_D8_D8),
238 TOP_PARENT(CLK_TOP_NET1PLL_D8_D16),
Christian Marangid061f732024-08-03 10:32:58 +0200239};
240
241static const struct mtk_parent bus_tops_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200242 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D5),
243 TOP_PARENT(CLK_TOP_NET2PLL_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200244};
245
246static const struct mtk_parent npu_tops_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200247 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_NET2PLL),
Christian Marangid061f732024-08-03 10:32:58 +0200248};
249
250static const struct mtk_parent dramc_md32_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200251 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_MPLL_D2),
252 APMIXED_PARENT(CLK_APMIXED_WEDMCUPLL),
Christian Marangid061f732024-08-03 10:32:58 +0200253};
254
255static const struct mtk_parent da_xtp_glb_p0_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200256 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D8),
Christian Marangid061f732024-08-03 10:32:58 +0200257};
258
259static const struct mtk_parent mcusys_backup_625m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200260 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET1PLL_D4),
Christian Marangid061f732024-08-03 10:32:58 +0200261};
262
263static const struct mtk_parent macsec_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200264 TOP_PARENT(CLK_TOP_XTAL), APMIXED_PARENT(CLK_APMIXED_SGMPLL),
265 TOP_PARENT(CLK_TOP_NET1PLL_D8),
Christian Marangid061f732024-08-03 10:32:58 +0200266};
267
268static const struct mtk_parent netsys_tops_400m_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200269 TOP_PARENT(CLK_TOP_XTAL), TOP_PARENT(CLK_TOP_NET2PLL_D2),
Christian Marangid061f732024-08-03 10:32:58 +0200270};
271
272static const struct mtk_parent eth_mii_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200273 TOP_PARENT(CLK_TOP_XTAL_D2), TOP_PARENT(CLK_TOP_NET2PLL_D4_D8),
Christian Marangid061f732024-08-03 10:32:58 +0200274};
Weijie Gao42143692023-07-19 17:16:28 +0800275
276#define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
277 _shift, _width, _gate, _upd_ofs, _upd) \
278 { \
279 .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \
280 .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \
281 .upd_shift = _upd, .mux_shift = _shift, \
282 .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \
Christian Marangid061f732024-08-03 10:32:58 +0200283 .gate_shift = _gate, .parent_flags = _parents, \
Weijie Gao42143692023-07-19 17:16:28 +0800284 .num_parents = ARRAY_SIZE(_parents), \
Christian Marangid061f732024-08-03 10:32:58 +0200285 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \
Weijie Gao42143692023-07-19 17:16:28 +0800286 }
287
288/* TOPCKGEN MUX_GATE */
289static const struct mtk_composite topckgen_mtk_muxes[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200290 TOP_MUX(CLK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x0, 0x4, 0x8,
Weijie Gao42143692023-07-19 17:16:28 +0800291 0, 2, 7, 0x1c0, 0),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200292 TOP_MUX(CLK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800293 0x0, 0x4, 0x8, 8, 2, 15, 0x1c0, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200294 TOP_MUX(CLK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x0,
Weijie Gao42143692023-07-19 17:16:28 +0800295 0x4, 0x8, 16, 2, 23, 0x1c0, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200296 TOP_MUX(CLK_TOP_NETSYS_GSW_SEL, "netsys_gsw_sel", netsys_gsw_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800297 0x0, 0x4, 0x8, 24, 2, 31, 0x1c0, 3),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200298 TOP_MUX(CLK_TOP_ETH_GMII_SEL, "eth_gmii_sel", eth_gmii_parents, 0x10,
Weijie Gao42143692023-07-19 17:16:28 +0800299 0x14, 0x18, 0, 1, 7, 0x1c0, 4),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200300 TOP_MUX(CLK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800301 0x10, 0x14, 0x18, 8, 3, 15, 0x1c0, 5),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200302 TOP_MUX(CLK_TOP_NETSYS_PAO_2X_SEL, "netsys_pao_2x_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800303 netsys_mcu_parents, 0x10, 0x14, 0x18, 16, 3, 23, 0x1c0, 6),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200304 TOP_MUX(CLK_TOP_EIP197_SEL, "eip197_sel", eip197_parents, 0x10, 0x14,
Weijie Gao42143692023-07-19 17:16:28 +0800305 0x18, 24, 3, 31, 0x1c0, 7),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200306 TOP_MUX(CLK_TOP_AXI_INFRA_SEL, "axi_infra_sel", axi_infra_parents, 0x20,
Weijie Gao42143692023-07-19 17:16:28 +0800307 0x24, 0x28, 0, 1, 7, 0x1c0, 8),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200308 TOP_MUX(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x20, 0x24, 0x28, 8,
Weijie Gao42143692023-07-19 17:16:28 +0800309 2, 15, 0x1c0, 9),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200310 TOP_MUX(CLK_TOP_EMMC_250M_SEL, "emmc_250m_sel", emmc_250m_parents, 0x20,
Weijie Gao42143692023-07-19 17:16:28 +0800311 0x24, 0x28, 16, 2, 23, 0x1c0, 10),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200312 TOP_MUX(CLK_TOP_EMMC_400M_SEL, "emmc_400m_sel", emmc_400m_parents, 0x20,
Weijie Gao42143692023-07-19 17:16:28 +0800313 0x24, 0x28, 24, 3, 31, 0x1c0, 11),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200314 TOP_MUX(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x30, 0x34, 0x38, 0, 3,
Weijie Gao42143692023-07-19 17:16:28 +0800315 7, 0x1c0, 12),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200316 TOP_MUX(CLK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x30, 0x34,
Weijie Gao42143692023-07-19 17:16:28 +0800317 0x38, 8, 3, 15, 0x1c0, 13),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200318 TOP_MUX(CLK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x30, 0x34, 0x38,
Weijie Gao42143692023-07-19 17:16:28 +0800319 16, 3, 23, 0x1c0, 14),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200320 TOP_MUX(CLK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x30, 0x34,
Weijie Gao42143692023-07-19 17:16:28 +0800321 0x38, 24, 3, 31, 0x1c0, 15),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200322 TOP_MUX(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x40, 0x44, 0x48, 0, 3,
Weijie Gao42143692023-07-19 17:16:28 +0800323 7, 0x1c0, 16),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200324 TOP_MUX(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x40, 0x44, 0x48, 8, 2,
Weijie Gao42143692023-07-19 17:16:28 +0800325 15, 0x1c0, 17),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200326 TOP_MUX(CLK_TOP_PCIE_MBIST_250M_SEL, "pcie_mbist_250m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800327 pcie_mbist_250m_parents, 0x40, 0x44, 0x48, 16, 1, 23, 0x1c0,
328 18),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200329 TOP_MUX(CLK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800330 0x40, 0x44, 0x48, 24, 3, 31, 0x1c0, 19),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200331 TOP_MUX(CLK_TOP_PEXTP_TL_P1_SEL, "pextp_tl_ck_p1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800332 pextp_tl_ck_parents, 0x50, 0x54, 0x58, 0, 3, 7, 0x1c0, 20),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200333 TOP_MUX(CLK_TOP_PEXTP_TL_P2_SEL, "pextp_tl_ck_p2_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800334 pextp_tl_ck_parents, 0x50, 0x54, 0x58, 8, 3, 15, 0x1c0, 21),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200335 TOP_MUX(CLK_TOP_PEXTP_TL_P3_SEL, "pextp_tl_ck_p3_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800336 pextp_tl_ck_parents, 0x50, 0x54, 0x58, 16, 3, 23, 0x1c0, 22),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200337 TOP_MUX(CLK_TOP_USB_SYS_SEL, "usb_sys_sel", eth_gmii_parents, 0x50, 0x54,
Weijie Gao42143692023-07-19 17:16:28 +0800338 0x58, 24, 1, 31, 0x1c0, 23),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200339 TOP_MUX(CLK_TOP_USB_SYS_P1_SEL, "usb_sys_p1_sel", eth_gmii_parents, 0x60,
Weijie Gao42143692023-07-19 17:16:28 +0800340 0x64, 0x68, 0, 1, 7, 0x1c0, 24),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200341 TOP_MUX(CLK_TOP_USB_XHCI_SEL, "usb_xhci_sel", eth_gmii_parents, 0x60,
Weijie Gao42143692023-07-19 17:16:28 +0800342 0x64, 0x68, 8, 1, 15, 0x1c0, 25),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200343 TOP_MUX(CLK_TOP_USB_XHCI_P1_SEL, "usb_xhci_p1_sel", eth_gmii_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800344 0x60, 0x64, 0x68, 16, 1, 23, 0x1c0, 26),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200345 TOP_MUX(CLK_TOP_USB_FRMCNT_SEL, "usb_frmcnt_sel", usb_frmcnt_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800346 0x60, 0x64, 0x68, 24, 1, 31, 0x1c0, 27),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200347 TOP_MUX(CLK_TOP_USB_FRMCNT_P1_SEL, "usb_frmcnt_p1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800348 usb_frmcnt_parents, 0x70, 0x74, 0x78, 0, 1, 7, 0x1c0, 28),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200349 TOP_MUX(CLK_TOP_AUD_SEL, "aud_sel", aud_parents, 0x70, 0x74, 0x78, 8, 1,
Weijie Gao42143692023-07-19 17:16:28 +0800350 15, 0x1c0, 29),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200351 TOP_MUX(CLK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x70, 0x74, 0x78,
Weijie Gao42143692023-07-19 17:16:28 +0800352 16, 1, 23, 0x1c0, 30),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200353 TOP_MUX(CLK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x70, 0x74, 0x78,
Weijie Gao42143692023-07-19 17:16:28 +0800354 24, 2, 31, 0x1c4, 0),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200355 TOP_MUX(CLK_TOP_A_TUNER_SEL, "a_tuner_sel", a1sys_parents, 0x80, 0x84,
Weijie Gao42143692023-07-19 17:16:28 +0800356 0x88, 0, 1, 7, 0x1c4, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200357 TOP_MUX(CLK_TOP_SSPXTP_SEL, "sspxtp_sel", sspxtp_parents, 0x80, 0x84,
Weijie Gao42143692023-07-19 17:16:28 +0800358 0x88, 8, 1, 15, 0x1c4, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200359 TOP_MUX(CLK_TOP_USB_PHY_SEL, "usb_phy_sel", sspxtp_parents, 0x80, 0x84,
Weijie Gao42143692023-07-19 17:16:28 +0800360 0x88, 16, 1, 23, 0x1c4, 3),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200361 TOP_MUX(CLK_TOP_USXGMII_SBUS_0_SEL, "usxgmii_sbus_0_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800362 usxgmii_sbus_0_parents, 0x80, 0x84, 0x88, 24, 1, 31, 0x1c4, 4),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200363 TOP_MUX(CLK_TOP_USXGMII_SBUS_1_SEL, "usxgmii_sbus_1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800364 usxgmii_sbus_0_parents, 0x90, 0x94, 0x98, 0, 1, 7, 0x1c4, 5),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200365 TOP_MUX(CLK_TOP_SGM_0_SEL, "sgm_0_sel", sgm_0_parents, 0x90, 0x94, 0x98,
Weijie Gao42143692023-07-19 17:16:28 +0800366 8, 1, 15, 0x1c4, 6),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200367 TOP_MUX(CLK_TOP_SGM_SBUS_0_SEL, "sgm_sbus_0_sel", usxgmii_sbus_0_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800368 0x90, 0x94, 0x98, 16, 1, 23, 0x1c4, 7),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200369 TOP_MUX(CLK_TOP_SGM_1_SEL, "sgm_1_sel", sgm_0_parents, 0x90, 0x94, 0x98,
Weijie Gao42143692023-07-19 17:16:28 +0800370 24, 1, 31, 0x1c4, 8),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200371 TOP_MUX(CLK_TOP_SGM_SBUS_1_SEL, "sgm_sbus_1_sel", usxgmii_sbus_0_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800372 0xa0, 0xa4, 0xa8, 0, 1, 7, 0x1c4, 9),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200373 TOP_MUX(CLK_TOP_XFI_PHY_0_XTAL_SEL, "xfi_phy_0_xtal_sel", sspxtp_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800374 0xa0, 0xa4, 0xa8, 8, 1, 15, 0x1c4, 10),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200375 TOP_MUX(CLK_TOP_XFI_PHY_1_XTAL_SEL, "xfi_phy_1_xtal_sel", sspxtp_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800376 0xa0, 0xa4, 0xa8, 16, 1, 23, 0x1c4, 11),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200377 TOP_MUX(CLK_TOP_SYSAXI_SEL, "sysaxi_sel", axi_infra_parents, 0xa0, 0xa4,
Weijie Gao42143692023-07-19 17:16:28 +0800378 0xa8, 24, 1, 31, 0x1c4, 12),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200379 TOP_MUX(CLK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0xb0, 0xb4,
Weijie Gao42143692023-07-19 17:16:28 +0800380 0xb8, 0, 1, 7, 0x1c4, 13),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200381 TOP_MUX(CLK_TOP_ETH_REFCK_50M_SEL, "eth_refck_50m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800382 eth_refck_50m_parents, 0xb0, 0xb4, 0xb8, 8, 1, 15, 0x1c4, 14),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200383 TOP_MUX(CLK_TOP_ETH_SYS_200M_SEL, "eth_sys_200m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800384 eth_sys_200m_parents, 0xb0, 0xb4, 0xb8, 16, 1, 23, 0x1c4, 15),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200385 TOP_MUX(CLK_TOP_ETH_SYS_SEL, "eth_sys_sel", pcie_mbist_250m_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800386 0xb0, 0xb4, 0xb8, 24, 1, 31, 0x1c4, 16),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200387 TOP_MUX(CLK_TOP_ETH_XGMII_SEL, "eth_xgmii_sel", eth_xgmii_parents, 0xc0,
Weijie Gao42143692023-07-19 17:16:28 +0800388 0xc4, 0xc8, 0, 2, 7, 0x1c4, 17),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200389 TOP_MUX(CLK_TOP_BUS_TOPS_SEL, "bus_tops_sel", bus_tops_parents, 0xc0,
Weijie Gao42143692023-07-19 17:16:28 +0800390 0xc4, 0xc8, 8, 2, 15, 0x1c4, 18),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200391 TOP_MUX(CLK_TOP_NPU_TOPS_SEL, "npu_tops_sel", npu_tops_parents, 0xc0,
Weijie Gao42143692023-07-19 17:16:28 +0800392 0xc4, 0xc8, 16, 1, 23, 0x1c4, 19),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200393 TOP_MUX(CLK_TOP_DRAMC_SEL, "dramc_sel", sspxtp_parents, 0xc0, 0xc4, 0xc8,
Weijie Gao42143692023-07-19 17:16:28 +0800394 24, 1, 31, 0x1c4, 20),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200395 TOP_MUX(CLK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800396 0xd0, 0xd4, 0xd8, 0, 2, 7, 0x1c4, 21),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200397 TOP_MUX(CLK_TOP_INFRA_F26M_SEL, "csw_infra_f26m_sel", sspxtp_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800398 0xd0, 0xd4, 0xd8, 8, 1, 15, 0x1c4, 22),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200399 TOP_MUX(CLK_TOP_PEXTP_P0_SEL, "pextp_p0_sel", sspxtp_parents, 0xd0, 0xd4,
Weijie Gao42143692023-07-19 17:16:28 +0800400 0xd8, 16, 1, 23, 0x1c4, 23),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200401 TOP_MUX(CLK_TOP_PEXTP_P1_SEL, "pextp_p1_sel", sspxtp_parents, 0xd0, 0xd4,
Weijie Gao42143692023-07-19 17:16:28 +0800402 0xd8, 24, 1, 31, 0x1c4, 24),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200403 TOP_MUX(CLK_TOP_PEXTP_P2_SEL, "pextp_p2_sel", sspxtp_parents, 0xe0, 0xe4,
Weijie Gao42143692023-07-19 17:16:28 +0800404 0xe8, 0, 1, 7, 0x1c4, 25),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200405 TOP_MUX(CLK_TOP_PEXTP_P3_SEL, "pextp_p3_sel", sspxtp_parents, 0xe0, 0xe4,
Weijie Gao42143692023-07-19 17:16:28 +0800406 0xe8, 8, 1, 15, 0x1c4, 26),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200407 TOP_MUX(CLK_TOP_DA_XTP_GLB_P0_SEL, "da_xtp_glb_p0_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800408 da_xtp_glb_p0_parents, 0xe0, 0xe4, 0xe8, 16, 1, 23, 0x1c4, 27),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200409 TOP_MUX(CLK_TOP_DA_XTP_GLB_P1_SEL, "da_xtp_glb_p1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800410 da_xtp_glb_p0_parents, 0xe0, 0xe4, 0xe8, 24, 1, 31, 0x1c4, 28),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200411 TOP_MUX(CLK_TOP_DA_XTP_GLB_P2_SEL, "da_xtp_glb_p2_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800412 da_xtp_glb_p0_parents, 0xf0, 0xf4, 0xf8, 0, 1, 7, 0x1c4, 29),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200413 TOP_MUX(CLK_TOP_DA_XTP_GLB_P3_SEL, "da_xtp_glb_p3_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800414 da_xtp_glb_p0_parents, 0xf0, 0xf4, 0xf8, 8, 1, 15, 0x1c4, 30),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200415 TOP_MUX(CLK_TOP_CKM_SEL, "ckm_sel", sspxtp_parents, 0xf0, 0xf4, 0xf8, 16,
Weijie Gao42143692023-07-19 17:16:28 +0800416 1, 23, 0x1c8, 0),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200417 TOP_MUX(CLK_TOP_DA_SEL, "da_sel", sspxtp_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800418 0xf0, 0xf4, 0xf8, 24, 1, 31, 0x1c8, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200419 TOP_MUX(CLK_TOP_PEXTP_SEL, "pextp_sel", sspxtp_parents, 0x100, 0x104,
Weijie Gao42143692023-07-19 17:16:28 +0800420 0x108, 0, 1, 7, 0x1c8, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200421 TOP_MUX(CLK_TOP_TOPS_P2_26M_SEL, "tops_p2_26m_sel", sspxtp_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800422 0x100, 0x104, 0x108, 8, 1, 15, 0x1c8, 3),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200423 TOP_MUX(CLK_TOP_MCUSYS_BACKUP_625M_SEL, "mcusys_backup_625m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800424 mcusys_backup_625m_parents, 0x100, 0x104, 0x108, 16, 1, 23,
425 0x1c8, 4),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200426 TOP_MUX(CLK_TOP_NETSYS_SYNC_250M_SEL, "netsys_sync_250m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800427 pcie_mbist_250m_parents, 0x100, 0x104, 0x108, 24, 1, 31, 0x1c8,
428 5),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200429 TOP_MUX(CLK_TOP_MACSEC_SEL, "macsec_sel", macsec_parents, 0x110, 0x114,
Weijie Gao42143692023-07-19 17:16:28 +0800430 0x118, 0, 2, 7, 0x1c8, 6),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200431 TOP_MUX(CLK_TOP_NETSYS_TOPS_400M_SEL, "netsys_tops_400m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800432 netsys_tops_400m_parents, 0x110, 0x114, 0x118, 8, 1, 15, 0x1c8,
433 7),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200434 TOP_MUX(CLK_TOP_NETSYS_PPEFB_250M_SEL, "netsys_ppefb_250m_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800435 pcie_mbist_250m_parents, 0x110, 0x114, 0x118, 16, 1, 23, 0x1c8,
436 8),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200437 TOP_MUX(CLK_TOP_NETSYS_WARP_SEL, "netsys_warp_sel", netsys_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800438 0x110, 0x114, 0x118, 24, 2, 31, 0x1c8, 9),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200439 TOP_MUX(CLK_TOP_ETH_MII_SEL, "eth_mii_sel", eth_mii_parents, 0x120,
Weijie Gao42143692023-07-19 17:16:28 +0800440 0x124, 0x128, 0, 1, 7, 0x1c8, 10),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200441 TOP_MUX(CLK_TOP_NPU_SEL, "ck_npu_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800442 netsys_2x_parents, 0x120, 0x124, 0x128, 8, 2, 15, 0x1c8, 11),
443};
444
Weijie Gao42143692023-07-19 17:16:28 +0800445/* INFRASYS MUX PARENTS */
Christian Marangi99c5fa12024-08-03 10:33:02 +0200446static const int infra_mux_uart0_parents[] = { CLK_TOP_INFRA_F26M_SEL,
447 CLK_TOP_UART_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800448
Christian Marangi99c5fa12024-08-03 10:33:02 +0200449static const int infra_mux_uart1_parents[] = { CLK_TOP_INFRA_F26M_SEL,
450 CLK_TOP_UART_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800451
Christian Marangi99c5fa12024-08-03 10:33:02 +0200452static const int infra_mux_uart2_parents[] = { CLK_TOP_INFRA_F26M_SEL,
453 CLK_TOP_UART_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800454
Christian Marangi99c5fa12024-08-03 10:33:02 +0200455static const int infra_mux_spi0_parents[] = { CLK_TOP_I2C_SEL, CLK_TOP_SPI_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800456
Christian Marangi99c5fa12024-08-03 10:33:02 +0200457static const int infra_mux_spi1_parents[] = { CLK_TOP_I2C_SEL, CLK_TOP_SPIM_MST_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800458
Christian Marangi99c5fa12024-08-03 10:33:02 +0200459static const int infra_pwm_bck_parents[] = { CLK_TOP_RTC_32P7K,
460 CLK_TOP_INFRA_F26M_SEL, CLK_TOP_SYSAXI_SEL,
461 CLK_TOP_PWM_SEL };
Weijie Gao42143692023-07-19 17:16:28 +0800462
463static const int infra_pcie_gfmux_tl_ck_o_p0_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200464 CLK_TOP_RTC_32P7K, CLK_TOP_INFRA_F26M_SEL, CLK_TOP_INFRA_F26M_SEL,
465 CLK_TOP_PEXTP_TL_SEL
Weijie Gao42143692023-07-19 17:16:28 +0800466};
467
468static const int infra_pcie_gfmux_tl_ck_o_p1_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200469 CLK_TOP_RTC_32P7K, CLK_TOP_INFRA_F26M_SEL, CLK_TOP_INFRA_F26M_SEL,
470 CLK_TOP_PEXTP_TL_P1_SEL
Weijie Gao42143692023-07-19 17:16:28 +0800471};
472
473static const int infra_pcie_gfmux_tl_ck_o_p2_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200474 CLK_TOP_RTC_32P7K, CLK_TOP_INFRA_F26M_SEL, CLK_TOP_INFRA_F26M_SEL,
475 CLK_TOP_PEXTP_TL_P2_SEL
Weijie Gao42143692023-07-19 17:16:28 +0800476};
477
478static const int infra_pcie_gfmux_tl_ck_o_p3_parents[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200479 CLK_TOP_RTC_32P7K, CLK_TOP_INFRA_F26M_SEL, CLK_TOP_INFRA_F26M_SEL,
480 CLK_TOP_PEXTP_TL_P3_SEL
Weijie Gao42143692023-07-19 17:16:28 +0800481};
482
483#define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \
484 { \
485 .id = _id, .mux_reg = _reg + 0x8, .mux_set_reg = _reg + 0x0, \
486 .mux_clr_reg = _reg + 0x4, .mux_shift = _shift, \
487 .mux_mask = BIT(_width) - 1, .parent = _parents, \
488 .num_parents = ARRAY_SIZE(_parents), \
Christian Marangi78507c32024-08-03 10:32:55 +0200489 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_TOPCKGEN, \
Weijie Gao42143692023-07-19 17:16:28 +0800490 }
491
492/* INFRA MUX */
493static const struct mtk_composite infracfg_mtk_mux[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200494 INFRA_MUX(CLK_INFRA_MUX_UART0_SEL, "infra_mux_uart0_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800495 infra_mux_uart0_parents, 0x10, 0, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200496 INFRA_MUX(CLK_INFRA_MUX_UART1_SEL, "infra_mux_uart1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800497 infra_mux_uart1_parents, 0x10, 1, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200498 INFRA_MUX(CLK_INFRA_MUX_UART2_SEL, "infra_mux_uart2_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800499 infra_mux_uart2_parents, 0x10, 2, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200500 INFRA_MUX(CLK_INFRA_MUX_SPI0_SEL, "infra_mux_spi0_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800501 infra_mux_spi0_parents, 0x10, 4, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200502 INFRA_MUX(CLK_INFRA_MUX_SPI1_SEL, "infra_mux_spi1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800503 infra_mux_spi1_parents, 0x10, 5, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200504 INFRA_MUX(CLK_INFRA_MUX_SPI2_SEL, "infra_mux_spi2_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800505 infra_mux_spi0_parents, 0x10, 6, 1),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200506 INFRA_MUX(CLK_INFRA_PWM_SEL, "infra_pwm_sel", infra_pwm_bck_parents,
Weijie Gao42143692023-07-19 17:16:28 +0800507 0x10, 14, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200508 INFRA_MUX(CLK_INFRA_PWM_CK1_SEL, "infra_pwm_ck1_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800509 infra_pwm_bck_parents, 0x10, 16, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200510 INFRA_MUX(CLK_INFRA_PWM_CK2_SEL, "infra_pwm_ck2_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800511 infra_pwm_bck_parents, 0x10, 18, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200512 INFRA_MUX(CLK_INFRA_PWM_CK3_SEL, "infra_pwm_ck3_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800513 infra_pwm_bck_parents, 0x10, 20, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200514 INFRA_MUX(CLK_INFRA_PWM_CK4_SEL, "infra_pwm_ck4_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800515 infra_pwm_bck_parents, 0x10, 22, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200516 INFRA_MUX(CLK_INFRA_PWM_CK5_SEL, "infra_pwm_ck5_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800517 infra_pwm_bck_parents, 0x10, 24, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200518 INFRA_MUX(CLK_INFRA_PWM_CK6_SEL, "infra_pwm_ck6_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800519 infra_pwm_bck_parents, 0x10, 26, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200520 INFRA_MUX(CLK_INFRA_PWM_CK7_SEL, "infra_pwm_ck7_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800521 infra_pwm_bck_parents, 0x10, 28, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200522 INFRA_MUX(CLK_INFRA_PWM_CK8_SEL, "infra_pwm_ck8_sel",
Weijie Gao42143692023-07-19 17:16:28 +0800523 infra_pwm_bck_parents, 0x10, 30, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200524 INFRA_MUX(CLK_INFRA_PCIE_GFMUX_TL_O_P0_SEL,
Weijie Gao42143692023-07-19 17:16:28 +0800525 "infra_pcie_gfmux_tl_o_p0_sel",
526 infra_pcie_gfmux_tl_ck_o_p0_parents, 0x20, 0, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200527 INFRA_MUX(CLK_INFRA_PCIE_GFMUX_TL_O_P1_SEL,
Weijie Gao42143692023-07-19 17:16:28 +0800528 "infra_pcie_gfmux_tl_o_p1_sel",
529 infra_pcie_gfmux_tl_ck_o_p1_parents, 0x20, 2, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200530 INFRA_MUX(CLK_INFRA_PCIE_GFMUX_TL_O_P2_SEL,
Weijie Gao42143692023-07-19 17:16:28 +0800531 "infra_pcie_gfmux_tl_o_p2_sel",
532 infra_pcie_gfmux_tl_ck_o_p2_parents, 0x20, 4, 2),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200533 INFRA_MUX(CLK_INFRA_PCIE_GFMUX_TL_O_P3_SEL,
Weijie Gao42143692023-07-19 17:16:28 +0800534 "infra_pcie_gfmux_tl_o_p3_sel",
535 infra_pcie_gfmux_tl_ck_o_p3_parents, 0x20, 6, 2),
536};
537
538static const struct mtk_gate_regs infra_0_cg_regs = {
539 .set_ofs = 0x10,
540 .clr_ofs = 0x14,
541 .sta_ofs = 0x18,
542};
543
544static const struct mtk_gate_regs infra_1_cg_regs = {
545 .set_ofs = 0x40,
546 .clr_ofs = 0x44,
547 .sta_ofs = 0x48,
548};
549
550static const struct mtk_gate_regs infra_2_cg_regs = {
551 .set_ofs = 0x50,
552 .clr_ofs = 0x54,
553 .sta_ofs = 0x58,
554};
555
556static const struct mtk_gate_regs infra_3_cg_regs = {
557 .set_ofs = 0x60,
558 .clr_ofs = 0x64,
559 .sta_ofs = 0x68,
560};
561
Christian Marangi78507c32024-08-03 10:32:55 +0200562#define GATE_INFRA0(_id, _name, _parent, _shift, _flags) \
Weijie Gao42143692023-07-19 17:16:28 +0800563 { \
564 .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \
565 .shift = _shift, \
Christian Marangi78507c32024-08-03 10:32:55 +0200566 .flags = _flags, \
Weijie Gao42143692023-07-19 17:16:28 +0800567 }
Christian Marangi78507c32024-08-03 10:32:55 +0200568#define GATE_INFRA0_INFRA(_id, _name, _parent, _shift) \
569 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
570#define GATE_INFRA0_TOP(_id, _name, _parent, _shift) \
571 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
Weijie Gao42143692023-07-19 17:16:28 +0800572
Christian Marangi78507c32024-08-03 10:32:55 +0200573#define GATE_INFRA1(_id, _name, _parent, _shift, _flags) \
Weijie Gao42143692023-07-19 17:16:28 +0800574 { \
575 .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \
576 .shift = _shift, \
Christian Marangi78507c32024-08-03 10:32:55 +0200577 .flags = _flags, \
Weijie Gao42143692023-07-19 17:16:28 +0800578 }
Christian Marangi78507c32024-08-03 10:32:55 +0200579#define GATE_INFRA1_INFRA(_id, _name, _parent, _shift) \
580 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
581#define GATE_INFRA1_TOP(_id, _name, _parent, _shift) \
582 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
Weijie Gao42143692023-07-19 17:16:28 +0800583
Christian Marangi78507c32024-08-03 10:32:55 +0200584#define GATE_INFRA2(_id, _name, _parent, _shift, _flags) \
Weijie Gao42143692023-07-19 17:16:28 +0800585 { \
586 .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \
587 .shift = _shift, \
Christian Marangi78507c32024-08-03 10:32:55 +0200588 .flags = _flags, \
Weijie Gao42143692023-07-19 17:16:28 +0800589 }
Christian Marangi78507c32024-08-03 10:32:55 +0200590#define GATE_INFRA2_INFRA(_id, _name, _parent, _shift) \
591 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
592#define GATE_INFRA2_TOP(_id, _name, _parent, _shift) \
593 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
Weijie Gao42143692023-07-19 17:16:28 +0800594
Christian Marangi78507c32024-08-03 10:32:55 +0200595#define GATE_INFRA3(_id, _name, _parent, _shift, _flags) \
Weijie Gao42143692023-07-19 17:16:28 +0800596 { \
597 .id = _id, .parent = _parent, .regs = &infra_3_cg_regs, \
598 .shift = _shift, \
Christian Marangi78507c32024-08-03 10:32:55 +0200599 .flags = _flags, \
Weijie Gao42143692023-07-19 17:16:28 +0800600 }
Christian Marangi78507c32024-08-03 10:32:55 +0200601#define GATE_INFRA3_INFRA(_id, _name, _parent, _shift) \
602 GATE_INFRA3(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
603#define GATE_INFRA3_TOP(_id, _name, _parent, _shift) \
604 GATE_INFRA3(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
605#define GATE_INFRA3_XTAL(_id, _name, _parent, _shift) \
606 GATE_INFRA3(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
Weijie Gao42143692023-07-19 17:16:28 +0800607
608/* INFRA GATE */
609static const struct mtk_gate infracfg_mtk_gates[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200610 GATE_INFRA0_TOP(CLK_INFRA_PCIE_PERI_26M_CK_P0,
611 "infra_pcie_peri_ck_26m_ck_p0", CLK_TOP_INFRA_F26M_SEL, 7),
612 GATE_INFRA0_TOP(CLK_INFRA_PCIE_PERI_26M_CK_P1,
613 "infra_pcie_peri_ck_26m_ck_p1", CLK_TOP_INFRA_F26M_SEL, 8),
614 GATE_INFRA0_INFRA(CLK_INFRA_PCIE_PERI_26M_CK_P2,
615 "infra_pcie_peri_ck_26m_ck_p2", CLK_INFRA_PCIE_PERI_26M_CK_P3, 9),
616 GATE_INFRA0_TOP(CLK_INFRA_PCIE_PERI_26M_CK_P3,
617 "infra_pcie_peri_ck_26m_ck_p3", CLK_TOP_INFRA_F26M_SEL, 10),
618 GATE_INFRA1_TOP(CLK_INFRA_66M_GPT_BCK, "infra_hf_66m_gpt_bck",
619 CLK_TOP_SYSAXI_SEL, 0),
620 GATE_INFRA1_TOP(CLK_INFRA_66M_PWM_HCK, "infra_hf_66m_pwm_hck",
621 CLK_TOP_SYSAXI_SEL, 1),
622 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_BCK, "infra_hf_66m_pwm_bck",
623 CLK_INFRA_PWM_SEL, 2),
624 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK1, "infra_hf_66m_pwm_ck1",
625 CLK_INFRA_PWM_CK1_SEL, 3),
626 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK2, "infra_hf_66m_pwm_ck2",
627 CLK_INFRA_PWM_CK2_SEL, 4),
628 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK3, "infra_hf_66m_pwm_ck3",
629 CLK_INFRA_PWM_CK3_SEL, 5),
630 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK4, "infra_hf_66m_pwm_ck4",
631 CLK_INFRA_PWM_CK4_SEL, 6),
632 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK5, "infra_hf_66m_pwm_ck5",
633 CLK_INFRA_PWM_CK5_SEL, 7),
634 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK6, "infra_hf_66m_pwm_ck6",
635 CLK_INFRA_PWM_CK6_SEL, 8),
636 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK7, "infra_hf_66m_pwm_ck7",
637 CLK_INFRA_PWM_CK7_SEL, 9),
638 GATE_INFRA1_INFRA(CLK_INFRA_66M_PWM_CK8, "infra_hf_66m_pwm_ck8",
639 CLK_INFRA_PWM_CK8_SEL, 10),
640 GATE_INFRA1_TOP(CLK_INFRA_133M_CQDMA_BCK, "infra_hf_133m_cqdma_bck",
641 CLK_TOP_SYSAXI_SEL, 12),
642 GATE_INFRA1_TOP(CLK_INFRA_66M_AUD_SLV_BCK, "infra_66m_aud_slv_bck",
643 CLK_TOP_SYSAXI_SEL, 13),
644 GATE_INFRA1_TOP(CLK_INFRA_AUD_26M, "infra_f_faud_26m", CLK_TOP_INFRA_F26M_SEL, 14),
645 GATE_INFRA1_TOP(CLK_INFRA_AUD_L, "infra_f_faud_l", CLK_TOP_AUD_L_SEL, 15),
646 GATE_INFRA1_TOP(CLK_INFRA_AUD_AUD, "infra_f_aud_aud", CLK_TOP_A1SYS_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200647 16),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200648 GATE_INFRA1_TOP(CLK_INFRA_AUD_EG2, "infra_f_faud_eg2", CLK_TOP_A_TUNER_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200649 18),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200650 GATE_INFRA1_TOP(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m", CLK_TOP_INFRA_F26M_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200651 19),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200652 GATE_INFRA1_TOP(CLK_INFRA_133M_DBG_ACKM, "infra_hf_133m_dbg_ackm",
653 CLK_TOP_SYSAXI_SEL, 20),
654 GATE_INFRA1_TOP(CLK_INFRA_66M_AP_DMA_BCK, "infra_66m_ap_dma_bck",
655 CLK_TOP_SYSAXI_SEL, 21),
656 GATE_INFRA1_TOP(CLK_INFRA_66M_SEJ_BCK, "infra_hf_66m_sej_bck",
657 CLK_TOP_SYSAXI_SEL, 29),
658 GATE_INFRA1_TOP(CLK_INFRA_PRE_CK_SEJ_F13M, "infra_pre_ck_sej_f13m",
659 CLK_TOP_INFRA_F26M_SEL, 30),
660 /* GATE_INFRA1_TOP(CLK_INFRA_66M_TRNG, "infra_hf_66m_trng", CLK_TOP_SYSAXI_SEL,
Christian Marangi6e54f032024-08-03 10:32:59 +0200661 31), */
Christian Marangi99c5fa12024-08-03 10:33:02 +0200662 GATE_INFRA2_TOP(CLK_INFRA_26M_THERM_SYSTEM, "infra_hf_26m_therm_system",
663 CLK_TOP_INFRA_F26M_SEL, 0),
664 GATE_INFRA2_TOP(CLK_INFRA_I2C_BCK, "infra_i2c_bck", CLK_TOP_I2C_SEL, 1),
665 /* GATE_INFRA2_TOP(CLK_INFRA_66M_UART0_PCK, "infra_hf_66m_uart0_pck",
666 CLK_TOP_SYSAXI_SEL, 3), */
667 /* GATE_INFRA2_TOP(CLK_INFRA_66M_UART1_PCK, "infra_hf_66m_uart1_pck",
668 CLK_TOP_SYSAXI_SEL, 4), */
669 /* GATE_INFRA2_TOP(CLK_INFRA_66M_UART2_PCK, "infra_hf_66m_uart2_pck",
670 CLK_TOP_SYSAXI_SEL, 5), */
671 GATE_INFRA2_INFRA(CLK_INFRA_52M_UART0_CK, "infra_f_52m_uart0",
672 CLK_INFRA_MUX_UART0_SEL, 3),
673 GATE_INFRA2_INFRA(CLK_INFRA_52M_UART1_CK, "infra_f_52m_uart1",
674 CLK_INFRA_MUX_UART1_SEL, 4),
675 GATE_INFRA2_INFRA(CLK_INFRA_52M_UART2_CK, "infra_f_52m_uart2",
676 CLK_INFRA_MUX_UART2_SEL, 5),
677 GATE_INFRA2_TOP(CLK_INFRA_NFI, "infra_f_fnfi", CLK_TOP_NFI1X_SEL, 9),
678 GATE_INFRA2_TOP(CLK_INFRA_SPINFI, "infra_f_fspinfi", CLK_TOP_SPINFI_SEL, 10),
679 GATE_INFRA2_TOP(CLK_INFRA_66M_NFI_HCK, "infra_hf_66m_nfi_hck",
680 CLK_TOP_SYSAXI_SEL, 11),
681 GATE_INFRA2_INFRA(CLK_INFRA_104M_SPI0, "infra_hf_104m_spi0",
682 CLK_INFRA_MUX_SPI0_SEL, 12),
683 GATE_INFRA2_INFRA(CLK_INFRA_104M_SPI1, "infra_hf_104m_spi1",
684 CLK_INFRA_MUX_SPI1_SEL, 13),
685 GATE_INFRA2_INFRA(CLK_INFRA_104M_SPI2_BCK, "infra_hf_104m_spi2_bck",
686 CLK_INFRA_MUX_SPI2_SEL, 14),
687 GATE_INFRA2_TOP(CLK_INFRA_66M_SPI0_HCK, "infra_hf_66m_spi0_hck",
688 CLK_TOP_SYSAXI_SEL, 15),
689 GATE_INFRA2_TOP(CLK_INFRA_66M_SPI1_HCK, "infra_hf_66m_spi1_hck",
690 CLK_TOP_SYSAXI_SEL, 16),
691 GATE_INFRA2_TOP(CLK_INFRA_66M_SPI2_HCK, "infra_hf_66m_spi2_hck",
692 CLK_TOP_SYSAXI_SEL, 17),
693 GATE_INFRA2_TOP(CLK_INFRA_66M_FLASHIF_AXI, "infra_hf_66m_flashif_axi",
694 CLK_TOP_SYSAXI_SEL, 18),
695 GATE_INFRA2_TOP(CLK_INFRA_RTC, "infra_f_frtc", CLK_TOP_RTC_32K, 19),
696 GATE_INFRA2_TOP(CLK_INFRA_26M_ADC_BCK, "infra_f_26m_adc_bck",
697 CLK_TOP_INFRA_F26M_SEL, 20),
698 GATE_INFRA2_INFRA(CLK_INFRA_RC_ADC, "infra_f_frc_adc", CLK_INFRA_26M_ADC_BCK,
Christian Marangi78507c32024-08-03 10:32:55 +0200699 21),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200700 GATE_INFRA2_TOP(CLK_INFRA_MSDC400, "infra_f_fmsdc400", CLK_TOP_EMMC_400M_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200701 22),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200702 GATE_INFRA2_TOP(CLK_INFRA_MSDC2_HCK, "infra_f_fmsdc2_hck",
703 CLK_TOP_EMMC_250M_SEL, 23),
704 GATE_INFRA2_TOP(CLK_INFRA_133M_MSDC_0_HCK, "infra_hf_133m_msdc_0_hck",
705 CLK_TOP_SYSAXI_SEL, 24),
706 GATE_INFRA2_TOP(CLK_INFRA_66M_MSDC_0_HCK, "infra_66m_msdc_0_hck",
707 CLK_TOP_SYSAXI_SEL, 25),
708 GATE_INFRA2_TOP(CLK_INFRA_133M_CPUM_BCK, "infra_hf_133m_cpum_bck",
709 CLK_TOP_SYSAXI_SEL, 26),
710 GATE_INFRA2_TOP(CLK_INFRA_BIST2FPC, "infra_hf_fbist2fpc", CLK_TOP_NFI1X_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200711 27),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200712 GATE_INFRA2_TOP(CLK_INFRA_I2C_X16W_MCK_CK_P1, "infra_hf_i2c_x16w_mck_ck_p1",
713 CLK_TOP_SYSAXI_SEL, 29),
714 GATE_INFRA2_TOP(CLK_INFRA_I2C_X16W_PCK_CK_P1, "infra_hf_i2c_x16w_pck_ck_p1",
715 CLK_TOP_SYSAXI_SEL, 31),
716 GATE_INFRA3_TOP(CLK_INFRA_133M_USB_HCK, "infra_133m_usb_hck",
717 CLK_TOP_SYSAXI_SEL, 0),
718 GATE_INFRA3_TOP(CLK_INFRA_133M_USB_HCK_CK_P1, "infra_133m_usb_hck_ck_p1",
719 CLK_TOP_SYSAXI_SEL, 1),
720 GATE_INFRA3_TOP(CLK_INFRA_66M_USB_HCK, "infra_66m_usb_hck",
721 CLK_TOP_SYSAXI_SEL, 2),
722 GATE_INFRA3_TOP(CLK_INFRA_66M_USB_HCK_CK_P1, "infra_66m_usb_hck_ck_p1",
723 CLK_TOP_SYSAXI_SEL, 3),
724 GATE_INFRA3_TOP(CLK_INFRA_USB_SYS, "infra_usb_sys", CLK_TOP_USB_SYS_SEL, 4),
725 GATE_INFRA3_TOP(CLK_INFRA_USB_SYS_CK_P1, "infra_usb_sys_ck_p1",
726 CLK_TOP_USB_SYS_P1_SEL, 5),
727 GATE_INFRA3_XTAL(CLK_INFRA_USB_REF, "infra_usb_ref", CLK_XTAL, 6),
728 GATE_INFRA3_XTAL(CLK_INFRA_USB_CK_P1, "infra_usb_ck_p1", CLK_XTAL,
Christian Marangid061f732024-08-03 10:32:58 +0200729 7),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200730 GATE_INFRA3_TOP(CLK_INFRA_USB_FRMCNT, "infra_usb_frmcnt",
731 CLK_TOP_USB_FRMCNT_SEL, 8),
732 GATE_INFRA3_TOP(CLK_INFRA_USB_FRMCNT_CK_P1, "infra_usb_frmcnt_ck_p1",
733 CLK_TOP_USB_FRMCNT_P1_SEL, 9),
734 GATE_INFRA3_XTAL(CLK_INFRA_USB_PIPE, "infra_usb_pipe", CLK_XTAL,
Christian Marangi78507c32024-08-03 10:32:55 +0200735 10),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200736 GATE_INFRA3_XTAL(CLK_INFRA_USB_PIPE_CK_P1, "infra_usb_pipe_ck_p1",
Christian Marangi78507c32024-08-03 10:32:55 +0200737 CLK_XTAL, 11),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200738 GATE_INFRA3_XTAL(CLK_INFRA_USB_UTMI, "infra_usb_utmi", CLK_XTAL,
Christian Marangi78507c32024-08-03 10:32:55 +0200739 12),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200740 GATE_INFRA3_XTAL(CLK_INFRA_USB_UTMI_CK_P1, "infra_usb_utmi_ck_p1",
Christian Marangi78507c32024-08-03 10:32:55 +0200741 CLK_XTAL, 13),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200742 GATE_INFRA3_TOP(CLK_INFRA_USB_XHCI, "infra_usb_xhci", CLK_TOP_USB_XHCI_SEL,
Christian Marangi78507c32024-08-03 10:32:55 +0200743 14),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200744 GATE_INFRA3_TOP(CLK_INFRA_USB_XHCI_CK_P1, "infra_usb_xhci_ck_p1",
745 CLK_TOP_USB_XHCI_P1_SEL, 15),
746 GATE_INFRA3_INFRA(CLK_INFRA_PCIE_GFMUX_TL_P0, "infra_pcie_gfmux_tl_ck_p0",
747 CLK_INFRA_PCIE_GFMUX_TL_O_P0_SEL, 20),
748 GATE_INFRA3_INFRA(CLK_INFRA_PCIE_GFMUX_TL_P1, "infra_pcie_gfmux_tl_ck_p1",
749 CLK_INFRA_PCIE_GFMUX_TL_O_P1_SEL, 21),
750 GATE_INFRA3_INFRA(CLK_INFRA_PCIE_GFMUX_TL_P2, "infra_pcie_gfmux_tl_ck_p2",
751 CLK_INFRA_PCIE_GFMUX_TL_O_P2_SEL, 22),
752 GATE_INFRA3_INFRA(CLK_INFRA_PCIE_GFMUX_TL_P3, "infra_pcie_gfmux_tl_ck_p3",
753 CLK_INFRA_PCIE_GFMUX_TL_O_P3_SEL, 23),
754 GATE_INFRA3_XTAL(CLK_INFRA_PCIE_PIPE_P0, "infra_pcie_pipe_ck_p0",
Christian Marangi78507c32024-08-03 10:32:55 +0200755 CLK_XTAL, 24),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200756 GATE_INFRA3_XTAL(CLK_INFRA_PCIE_PIPE_P1, "infra_pcie_pipe_ck_p1",
Christian Marangi78507c32024-08-03 10:32:55 +0200757 CLK_XTAL, 25),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200758 GATE_INFRA3_XTAL(CLK_INFRA_PCIE_PIPE_P2, "infra_pcie_pipe_ck_p2",
Christian Marangi78507c32024-08-03 10:32:55 +0200759 CLK_XTAL, 26),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200760 GATE_INFRA3_XTAL(CLK_INFRA_PCIE_PIPE_P3, "infra_pcie_pipe_ck_p3",
Christian Marangi78507c32024-08-03 10:32:55 +0200761 CLK_XTAL, 27),
Christian Marangi99c5fa12024-08-03 10:33:02 +0200762 GATE_INFRA3_TOP(CLK_INFRA_133M_PCIE_CK_P0, "infra_133m_pcie_ck_p0",
763 CLK_TOP_SYSAXI_SEL, 28),
764 GATE_INFRA3_TOP(CLK_INFRA_133M_PCIE_CK_P1, "infra_133m_pcie_ck_p1",
765 CLK_TOP_SYSAXI_SEL, 29),
766 GATE_INFRA3_TOP(CLK_INFRA_133M_PCIE_CK_P2, "infra_133m_pcie_ck_p2",
767 CLK_TOP_SYSAXI_SEL, 30),
768 GATE_INFRA3_TOP(CLK_INFRA_133M_PCIE_CK_P3, "infra_133m_pcie_ck_p3",
769 CLK_TOP_SYSAXI_SEL, 31),
Weijie Gao42143692023-07-19 17:16:28 +0800770};
771
772static const struct mtk_clk_tree mt7988_fixed_pll_clk_tree = {
773 .fdivs_offs = ARRAY_SIZE(apmixedsys_mtk_plls),
774 .fclks = apmixedsys_mtk_plls,
Christian Marangid061f732024-08-03 10:32:58 +0200775 .flags = CLK_APMIXED,
Weijie Gao42143692023-07-19 17:16:28 +0800776 .xtal_rate = 40 * MHZ,
777};
778
779static const struct mtk_clk_tree mt7988_topckgen_clk_tree = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200780 .fdivs_offs = CLK_TOP_XTAL_D2,
781 .muxes_offs = CLK_TOP_NETSYS_SEL,
Christian Marangid061f732024-08-03 10:32:58 +0200782 .fclks = topckgen_mtk_fixed_clks,
Weijie Gao42143692023-07-19 17:16:28 +0800783 .fdivs = topckgen_mtk_fixed_factors,
784 .muxes = topckgen_mtk_muxes,
Christian Marangid061f732024-08-03 10:32:58 +0200785 .flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
Weijie Gao42143692023-07-19 17:16:28 +0800786 .xtal_rate = 40 * MHZ,
787};
788
789static const struct mtk_clk_tree mt7988_infracfg_clk_tree = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200790 .muxes_offs = CLK_INFRA_MUX_UART0_SEL,
791 .gates_offs = CLK_INFRA_PCIE_PERI_26M_CK_P0,
Weijie Gao42143692023-07-19 17:16:28 +0800792 .muxes = infracfg_mtk_mux,
Christian Marangief4a6482024-08-03 10:33:01 +0200793 .gates = infracfg_mtk_gates,
Weijie Gao42143692023-07-19 17:16:28 +0800794 .flags = CLK_BYPASS_XTAL,
795 .xtal_rate = 40 * MHZ,
796};
797
798static const struct udevice_id mt7988_fixed_pll_compat[] = {
799 { .compatible = "mediatek,mt7988-fixed-plls" },
Christian Marangi2fa520c2024-06-24 23:03:39 +0200800 { .compatible = "mediatek,mt7988-apmixedsys" },
Weijie Gao42143692023-07-19 17:16:28 +0800801 {}
802};
803
804static const struct udevice_id mt7988_topckgen_compat[] = {
805 { .compatible = "mediatek,mt7988-topckgen" },
806 {}
807};
808
809static int mt7988_fixed_pll_probe(struct udevice *dev)
810{
811 return mtk_common_clk_init(dev, &mt7988_fixed_pll_clk_tree);
812}
813
814static int mt7988_topckgen_probe(struct udevice *dev)
815{
816 struct mtk_clk_priv *priv = dev_get_priv(dev);
817
818 priv->base = dev_read_addr_ptr(dev);
819 if (!priv->base)
820 return -ENOENT;
821
822 writel(MT7988_CLK_PDN_EN_WRITE, priv->base + MT7988_CLK_PDN);
823 return mtk_common_clk_init(dev, &mt7988_topckgen_clk_tree);
824}
825
826U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
827 .name = "mt7988-clock-fixed-pll",
828 .id = UCLASS_CLK,
829 .of_match = mt7988_fixed_pll_compat,
830 .probe = mt7988_fixed_pll_probe,
831 .priv_auto = sizeof(struct mtk_clk_priv),
832 .ops = &mtk_clk_topckgen_ops,
833 .flags = DM_FLAG_PRE_RELOC,
834};
835
836U_BOOT_DRIVER(mtk_clk_topckgen) = {
837 .name = "mt7988-clock-topckgen",
838 .id = UCLASS_CLK,
839 .of_match = mt7988_topckgen_compat,
840 .probe = mt7988_topckgen_probe,
841 .priv_auto = sizeof(struct mtk_clk_priv),
842 .ops = &mtk_clk_topckgen_ops,
843 .flags = DM_FLAG_PRE_RELOC,
844};
845
846static const struct udevice_id mt7988_infracfg_compat[] = {
847 { .compatible = "mediatek,mt7988-infracfg" },
848 {}
849};
850
Weijie Gao42143692023-07-19 17:16:28 +0800851static int mt7988_infracfg_probe(struct udevice *dev)
852{
Christian Marangief4a6482024-08-03 10:33:01 +0200853 return mtk_common_clk_infrasys_init(dev, &mt7988_infracfg_clk_tree);
Weijie Gao42143692023-07-19 17:16:28 +0800854}
855
856U_BOOT_DRIVER(mtk_clk_infracfg) = {
857 .name = "mt7988-clock-infracfg",
858 .id = UCLASS_CLK,
859 .of_match = mt7988_infracfg_compat,
860 .probe = mt7988_infracfg_probe,
861 .priv_auto = sizeof(struct mtk_clk_priv),
862 .ops = &mtk_clk_infrasys_ops,
863 .flags = DM_FLAG_PRE_RELOC,
864};
865
Weijie Gao42143692023-07-19 17:16:28 +0800866/* ETHDMA */
867
868static const struct mtk_gate_regs ethdma_cg_regs = {
869 .set_ofs = 0x30,
870 .clr_ofs = 0x30,
871 .sta_ofs = 0x30,
872};
873
874#define GATE_ETHDMA(_id, _name, _parent, _shift) \
875 { \
876 .id = _id, .parent = _parent, .regs = &ethdma_cg_regs, \
877 .shift = _shift, \
878 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
879 }
880
881static const struct mtk_gate ethdma_mtk_gate[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200882 GATE_ETHDMA(CLK_ETHDMA_FE_EN, "ethdma_fe_en", CLK_TOP_NETSYS_2X_SEL, 6),
Weijie Gao42143692023-07-19 17:16:28 +0800883};
884
885static int mt7988_ethdma_probe(struct udevice *dev)
886{
887 return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
888 ethdma_mtk_gate);
889}
890
891static int mt7988_ethdma_bind(struct udevice *dev)
892{
893 int ret = 0;
894
895 if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
896 ret = mediatek_reset_bind(dev, MT7988_ETHDMA_RST_CTRL_OFS, 1);
897 if (ret)
898 debug("Warning: failed to bind reset controller\n");
899 }
900
901 return ret;
902}
903
904static const struct udevice_id mt7988_ethdma_compat[] = {
905 {
906 .compatible = "mediatek,mt7988-ethdma",
907 },
908 {}
909};
910
911U_BOOT_DRIVER(mtk_clk_ethdma) = {
912 .name = "mt7988-clock-ethdma",
913 .id = UCLASS_CLK,
914 .of_match = mt7988_ethdma_compat,
915 .probe = mt7988_ethdma_probe,
916 .bind = mt7988_ethdma_bind,
917 .priv_auto = sizeof(struct mtk_cg_priv),
918 .ops = &mtk_clk_gate_ops,
919};
920
921/* SGMIISYS_0 */
922
923static const struct mtk_gate_regs sgmii0_cg_regs = {
924 .set_ofs = 0xE4,
925 .clr_ofs = 0xE4,
926 .sta_ofs = 0xE4,
927};
928
929#define GATE_SGMII0(_id, _name, _parent, _shift) \
930 { \
931 .id = _id, .parent = _parent, .regs = &sgmii0_cg_regs, \
932 .shift = _shift, \
933 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
934 }
935
936static const struct mtk_gate sgmiisys_0_mtk_gate[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200937 /* connect to fake clock, so use CLK_TOP_XTAL as the clock parent */
938 GATE_SGMII0(CLK_SGM0_TX_EN, "sgm0_tx_en", CLK_TOP_XTAL, 2),
939 /* connect to fake clock, so use CLK_TOP_XTAL as the clock parent */
940 GATE_SGMII0(CLK_SGM0_RX_EN, "sgm0_rx_en", CLK_TOP_XTAL, 3),
Weijie Gao42143692023-07-19 17:16:28 +0800941};
942
943static int mt7988_sgmiisys_0_probe(struct udevice *dev)
944{
945 return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
946 sgmiisys_0_mtk_gate);
947}
948
949static const struct udevice_id mt7988_sgmiisys_0_compat[] = {
950 {
951 .compatible = "mediatek,mt7988-sgmiisys_0",
952 },
953 {}
954};
955
956U_BOOT_DRIVER(mtk_clk_sgmiisys_0) = {
957 .name = "mt7988-clock-sgmiisys_0",
958 .id = UCLASS_CLK,
959 .of_match = mt7988_sgmiisys_0_compat,
960 .probe = mt7988_sgmiisys_0_probe,
961 .priv_auto = sizeof(struct mtk_cg_priv),
962 .ops = &mtk_clk_gate_ops,
963};
964
965/* SGMIISYS_1 */
966
967static const struct mtk_gate_regs sgmii1_cg_regs = {
968 .set_ofs = 0xE4,
969 .clr_ofs = 0xE4,
970 .sta_ofs = 0xE4,
971};
972
973#define GATE_SGMII1(_id, _name, _parent, _shift) \
974 { \
975 .id = _id, .parent = _parent, .regs = &sgmii1_cg_regs, \
976 .shift = _shift, \
977 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
978 }
979
980static const struct mtk_gate sgmiisys_1_mtk_gate[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +0200981 /* connect to fake clock, so use CLK_TOP_XTAL as the clock parent */
982 GATE_SGMII1(CLK_SGM1_TX_EN, "sgm1_tx_en", CLK_TOP_XTAL, 2),
983 /* connect to fake clock, so use CLK_TOP_XTAL as the clock parent */
984 GATE_SGMII1(CLK_SGM1_RX_EN, "sgm1_rx_en", CLK_TOP_XTAL, 3),
Weijie Gao42143692023-07-19 17:16:28 +0800985};
986
987static int mt7988_sgmiisys_1_probe(struct udevice *dev)
988{
989 return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
990 sgmiisys_1_mtk_gate);
991}
992
993static const struct udevice_id mt7988_sgmiisys_1_compat[] = {
994 {
995 .compatible = "mediatek,mt7988-sgmiisys_1",
996 },
997 {}
998};
999
1000U_BOOT_DRIVER(mtk_clk_sgmiisys_1) = {
1001 .name = "mt7988-clock-sgmiisys_1",
1002 .id = UCLASS_CLK,
1003 .of_match = mt7988_sgmiisys_1_compat,
1004 .probe = mt7988_sgmiisys_1_probe,
1005 .priv_auto = sizeof(struct mtk_cg_priv),
1006 .ops = &mtk_clk_gate_ops,
1007};
1008
1009/* ETHWARP */
1010
1011static const struct mtk_gate_regs ethwarp_cg_regs = {
1012 .set_ofs = 0x14,
1013 .clr_ofs = 0x14,
1014 .sta_ofs = 0x14,
1015};
1016
1017#define GATE_ETHWARP(_id, _name, _parent, _shift) \
1018 { \
1019 .id = _id, .parent = _parent, .regs = &ethwarp_cg_regs, \
1020 .shift = _shift, \
1021 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
1022 }
1023
1024static const struct mtk_gate ethwarp_mtk_gate[] = {
Christian Marangi99c5fa12024-08-03 10:33:02 +02001025 GATE_ETHWARP(CLK_ETHWARP_WOCPU2_EN, "ethwarp_wocpu2_en",
1026 CLK_TOP_NETSYS_MCU_SEL, 13),
1027 GATE_ETHWARP(CLK_ETHWARP_WOCPU1_EN, "ethwarp_wocpu1_en",
1028 CLK_TOP_NETSYS_MCU_SEL, 14),
1029 GATE_ETHWARP(CLK_ETHWARP_WOCPU0_EN, "ethwarp_wocpu0_en",
1030 CLK_TOP_NETSYS_MCU_SEL, 15),
Weijie Gao42143692023-07-19 17:16:28 +08001031};
1032
1033static int mt7988_ethwarp_probe(struct udevice *dev)
1034{
1035 return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
1036 ethwarp_mtk_gate);
1037}
1038
1039static int mt7988_ethwarp_bind(struct udevice *dev)
1040{
1041 int ret = 0;
1042
1043 if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
1044 ret = mediatek_reset_bind(dev, MT7988_ETHWARP_RST_CTRL_OFS, 2);
1045 if (ret)
1046 debug("Warning: failed to bind reset controller\n");
1047 }
1048
1049 return ret;
1050}
1051
1052static const struct udevice_id mt7988_ethwarp_compat[] = {
1053 {
1054 .compatible = "mediatek,mt7988-ethwarp",
1055 },
1056 {}
1057};
1058
1059U_BOOT_DRIVER(mtk_clk_ethwarp) = {
1060 .name = "mt7988-clock-ethwarp",
1061 .id = UCLASS_CLK,
1062 .of_match = mt7988_ethwarp_compat,
1063 .probe = mt7988_ethwarp_probe,
1064 .bind = mt7988_ethwarp_bind,
1065 .priv_auto = sizeof(struct mtk_cg_priv),
1066 .ops = &mtk_clk_gate_ops,
1067};