blob: 7476024f5843562d5c335ee5740d0c05c9807de1 [file] [log] [blame]
developer37161fe2022-09-09 20:00:09 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7986 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/mt7986-clk.h>
14#include <linux/bitops.h>
15
16#include "clk-mtk.h"
17
18#define MT7986_CLK_PDN 0x250
19#define MT7986_CLK_PDN_EN_WRITE BIT(31)
20
Christian Marangi0fc50e72024-08-03 10:40:43 +020021#define APMIXED_PARENT(_id) PARENT(_id, CLK_PARENT_APMIXED)
22#define INFRA_PARENT(_id) PARENT(_id, CLK_PARENT_INFRASYS)
23#define TOP_PARENT(_id) PARENT(_id, CLK_PARENT_TOPCKGEN)
24#define VOID_PARENT PARENT(-1, 0)
25
developer37161fe2022-09-09 20:00:09 +080026#define PLL_FACTOR(_id, _name, _parent, _mult, _div) \
27 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
28
29#define TOP_FACTOR(_id, _name, _parent, _mult, _div) \
30 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
31
32#define INFRA_FACTOR(_id, _name, _parent, _mult, _div) \
33 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_INFRASYS)
34
35/* FIXED PLLS */
36static const struct mtk_fixed_clk fixed_pll_clks[] = {
37 FIXED_CLK(CK_APMIXED_ARMPLL, CLK_XTAL, 2000000000),
38 FIXED_CLK(CK_APMIXED_NET2PLL, CLK_XTAL, 800000000),
39 FIXED_CLK(CK_APMIXED_MMPLL, CLK_XTAL, 1440000000),
40 FIXED_CLK(CK_APMIXED_SGMPLL, CLK_XTAL, 325000000),
41 FIXED_CLK(CK_APMIXED_WEDMCUPLL, CLK_XTAL, 760000000),
42 FIXED_CLK(CK_APMIXED_NET1PLL, CLK_XTAL, 2500000000),
43 FIXED_CLK(CK_APMIXED_MPLL, CLK_XTAL, 416000000),
44 FIXED_CLK(CK_APMIXED_APLL2, CLK_XTAL, 196608000),
45};
46
47/* TOPCKGEN FIXED CLK */
48static const struct mtk_fixed_clk top_fixed_clks[] = {
Christian Marangi0178c612024-08-03 10:40:35 +020049 FIXED_CLK(CK_TOP_XTAL, CLK_XTAL, 40000000),
developer37161fe2022-09-09 20:00:09 +080050};
51
52/* TOPCKGEN FIXED DIV */
53static const struct mtk_fixed_factor top_fixed_divs[] = {
Christian Marangi83b17ec2024-08-03 10:40:42 +020054 /* TOP Factors */
55 TOP_FACTOR(CK_TOP_XTAL_D2, "xtal_d2", CK_TOP_XTAL,
56 1, 2),
57 TOP_FACTOR(CK_TOP_RTC_32K, "rtc_32k", CK_TOP_XTAL, 1,
58 1250),
59 TOP_FACTOR(CK_TOP_RTC_32P7K, "rtc_32p7k", CK_TOP_XTAL, 1,
60 1220),
Christian Marangiefc33e42024-08-03 10:40:44 +020061 /* Not defined upstream and not used */
62 /* TOP_FACTOR(CK_TOP_A_TUNER, "a_tuner", CK_TOP_A_TUNER_SEL, 2, 1), */
Christian Marangi9276f072024-08-03 10:40:41 +020063 /* MPLL */
Christian Marangi9276f072024-08-03 10:40:41 +020064 PLL_FACTOR(CK_TOP_MPLL_D2, "mpll_d2", CK_APMIXED_MPLL, 1, 2),
65 PLL_FACTOR(CK_TOP_MPLL_D4, "mpll_d4", CK_APMIXED_MPLL, 1, 4),
66 PLL_FACTOR(CK_TOP_MPLL_D8, "mpll_d8", CK_APMIXED_MPLL, 1, 8),
67 PLL_FACTOR(CK_TOP_MPLL_D8_D2, "mpll_d8_d2", CK_APMIXED_MPLL, 1, 16),
68 PLL_FACTOR(CK_TOP_MPLL_D3_D2, "mpll_d3_d2", CK_APMIXED_MPLL, 1, 2),
69 /* MMPLL */
70 PLL_FACTOR(CK_TOP_MMPLL_D2, "mmpll_d2", CK_APMIXED_MMPLL, 1, 2),
71 PLL_FACTOR(CK_TOP_MMPLL_D4, "mmpll_d4", CK_APMIXED_MMPLL, 1, 4),
72 PLL_FACTOR(CK_TOP_MMPLL_D8, "mmpll_d8", CK_APMIXED_MMPLL, 1, 8),
73 PLL_FACTOR(CK_TOP_MMPLL_D8_D2, "mmpll_d8_d2", CK_APMIXED_MMPLL, 1, 16),
74 PLL_FACTOR(CK_TOP_MMPLL_D3_D8, "mmpll_d3_d8", CK_APMIXED_MMPLL, 1, 8),
75 PLL_FACTOR(CK_TOP_MMPLL_U2PHYD, "mmpll_u2phy", CK_APMIXED_MMPLL, 1, 30),
76 /* APLL2 */
developer37161fe2022-09-09 20:00:09 +080077 PLL_FACTOR(CK_TOP_APLL2_D4, "apll2_d4", CK_APMIXED_APLL2, 1, 4),
Christian Marangi9276f072024-08-03 10:40:41 +020078 /* NET1PLL */
79 PLL_FACTOR(CK_TOP_NET1PLL_D4, "net1pll_d4", CK_APMIXED_NET1PLL, 1, 4),
80 PLL_FACTOR(CK_TOP_NET1PLL_D5, "net1pll_d5", CK_APMIXED_NET1PLL, 1, 5),
81 PLL_FACTOR(CK_TOP_NET1PLL_D5_D2, "net1pll_d5_d2", CK_APMIXED_NET1PLL, 1, 10),
82 PLL_FACTOR(CK_TOP_NET1PLL_D5_D4, "net1pll_d5_d4", CK_APMIXED_NET1PLL, 1, 20),
83 PLL_FACTOR(CK_TOP_NET1PLL_D8_D2, "net1pll_d8_d2", CK_APMIXED_NET1PLL, 1, 16),
84 PLL_FACTOR(CK_TOP_NET1PLL_D8_D4, "net1pll_d8_d4", CK_APMIXED_NET1PLL, 1, 32),
85 /* NET2PLL */
Christian Marangi9276f072024-08-03 10:40:41 +020086 PLL_FACTOR(CK_TOP_NET2PLL_D4, "net2pll_d4", CK_APMIXED_NET2PLL, 1, 4),
87 PLL_FACTOR(CK_TOP_NET2PLL_D4_D2, "net2pll_d4_d2", CK_APMIXED_NET2PLL, 1, 8),
88 PLL_FACTOR(CK_TOP_NET2PLL_D3_D2, "net2pll_d3_d2", CK_APMIXED_NET2PLL, 1, 2),
89 /* WEDMCUPLL */
Christian Marangi9276f072024-08-03 10:40:41 +020090 PLL_FACTOR(CK_TOP_WEDMCUPLL_D5_D2, "wedmcupll_d5_d2", CK_APMIXED_WEDMCUPLL, 1,
developer37161fe2022-09-09 20:00:09 +080091 10),
developer37161fe2022-09-09 20:00:09 +080092};
93
94/* TOPCKGEN MUX PARENTS */
Christian Marangi0fc50e72024-08-03 10:40:43 +020095static const struct mtk_parent nfi1x_parents[] = {
96 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MMPLL_D8),
97 TOP_PARENT(CK_TOP_NET1PLL_D8_D2), TOP_PARENT(CK_TOP_NET2PLL_D3_D2),
98 TOP_PARENT(CK_TOP_MPLL_D4), TOP_PARENT(CK_TOP_MMPLL_D8_D2),
99 TOP_PARENT(CK_TOP_WEDMCUPLL_D5_D2), TOP_PARENT(CK_TOP_MPLL_D8),
100};
developer37161fe2022-09-09 20:00:09 +0800101
Christian Marangi0fc50e72024-08-03 10:40:43 +0200102static const struct mtk_parent spinfi_parents[] = {
103 TOP_PARENT(CK_TOP_XTAL_D2), TOP_PARENT(CK_TOP_XTAL),
104 TOP_PARENT(CK_TOP_NET1PLL_D5_D4), TOP_PARENT(CK_TOP_MPLL_D4),
105 TOP_PARENT(CK_TOP_MMPLL_D8_D2), TOP_PARENT(CK_TOP_WEDMCUPLL_D5_D2),
106 TOP_PARENT(CK_TOP_MMPLL_D3_D8), TOP_PARENT(CK_TOP_MPLL_D8),
developer37161fe2022-09-09 20:00:09 +0800107};
108
Christian Marangi0fc50e72024-08-03 10:40:43 +0200109static const struct mtk_parent spi_parents[] = {
110 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MPLL_D2),
111 TOP_PARENT(CK_TOP_MMPLL_D8), TOP_PARENT(CK_TOP_NET1PLL_D8_D2),
112 TOP_PARENT(CK_TOP_NET2PLL_D3_D2), TOP_PARENT(CK_TOP_NET1PLL_D5_D4),
113 TOP_PARENT(CK_TOP_MPLL_D4), TOP_PARENT(CK_TOP_WEDMCUPLL_D5_D2),
114};
developer37161fe2022-09-09 20:00:09 +0800115
Christian Marangi0fc50e72024-08-03 10:40:43 +0200116static const struct mtk_parent uart_parents[] = {
117 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MPLL_D8),
118 TOP_PARENT(CK_TOP_MPLL_D8_D2),
119};
developer37161fe2022-09-09 20:00:09 +0800120
Christian Marangi0fc50e72024-08-03 10:40:43 +0200121static const struct mtk_parent pwm_parents[] = {
122 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D8_D2),
123 TOP_PARENT(CK_TOP_NET1PLL_D5_D4), TOP_PARENT(CK_TOP_MPLL_D4),
124};
developer37161fe2022-09-09 20:00:09 +0800125
Christian Marangi0fc50e72024-08-03 10:40:43 +0200126static const struct mtk_parent i2c_parents[] = {
127 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D5_D4),
128 TOP_PARENT(CK_TOP_MPLL_D4), TOP_PARENT(CK_TOP_NET1PLL_D8_D4),
129};
developer37161fe2022-09-09 20:00:09 +0800130
Christian Marangi0fc50e72024-08-03 10:40:43 +0200131static const struct mtk_parent pextp_tl_ck_parents[] = {
132 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D5_D4),
133 TOP_PARENT(CK_TOP_NET2PLL_D4_D2), TOP_PARENT(CK_TOP_RTC_32K),
134};
developer37161fe2022-09-09 20:00:09 +0800135
Christian Marangi0fc50e72024-08-03 10:40:43 +0200136static const struct mtk_parent emmc_250m_parents[] = {
137 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D5_D2),
138};
developer37161fe2022-09-09 20:00:09 +0800139
Christian Marangi0fc50e72024-08-03 10:40:43 +0200140static const struct mtk_parent emmc_416m_parents[] = {
141 TOP_PARENT(CK_TOP_XTAL), APMIXED_PARENT(CK_APMIXED_MPLL),
142};
developer37161fe2022-09-09 20:00:09 +0800143
Christian Marangi0fc50e72024-08-03 10:40:43 +0200144static const struct mtk_parent f_26m_adc_parents[] = {
145 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MPLL_D8_D2),
146};
developer37161fe2022-09-09 20:00:09 +0800147
Christian Marangi0fc50e72024-08-03 10:40:43 +0200148static const struct mtk_parent dramc_md32_parents[] = {
149 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MPLL_D2),
150};
developer37161fe2022-09-09 20:00:09 +0800151
Christian Marangi0fc50e72024-08-03 10:40:43 +0200152static const struct mtk_parent sysaxi_parents[] = {
153 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D8_D2),
154 TOP_PARENT(CK_TOP_NET2PLL_D4),
155};
developer37161fe2022-09-09 20:00:09 +0800156
Christian Marangi0fc50e72024-08-03 10:40:43 +0200157static const struct mtk_parent sysapb_parents[] = {
158 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MPLL_D3_D2),
159 TOP_PARENT(CK_TOP_NET2PLL_D4_D2),
160};
developer37161fe2022-09-09 20:00:09 +0800161
Christian Marangi0fc50e72024-08-03 10:40:43 +0200162static const struct mtk_parent arm_db_main_parents[] = {
163 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET2PLL_D3_D2),
164};
developer37161fe2022-09-09 20:00:09 +0800165
Christian Marangi0fc50e72024-08-03 10:40:43 +0200166static const struct mtk_parent arm_db_jtsel_parents[] = {
167 VOID_PARENT, TOP_PARENT(CK_TOP_XTAL),
168};
developer37161fe2022-09-09 20:00:09 +0800169
Christian Marangi0fc50e72024-08-03 10:40:43 +0200170static const struct mtk_parent netsys_parents[] = {
171 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MMPLL_D4),
172};
developer37161fe2022-09-09 20:00:09 +0800173
Christian Marangi0fc50e72024-08-03 10:40:43 +0200174static const struct mtk_parent netsys_500m_parents[] = {
175 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D5),
176};
developer37161fe2022-09-09 20:00:09 +0800177
Christian Marangi0fc50e72024-08-03 10:40:43 +0200178static const struct mtk_parent netsys_mcu_parents[] = {
179 TOP_PARENT(CK_TOP_XTAL), APMIXED_PARENT(CK_APMIXED_WEDMCUPLL),
180 TOP_PARENT(CK_TOP_MMPLL_D2), TOP_PARENT(CK_TOP_NET1PLL_D4),
181 TOP_PARENT(CK_TOP_NET1PLL_D5),
182};
developer37161fe2022-09-09 20:00:09 +0800183
Christian Marangi0fc50e72024-08-03 10:40:43 +0200184static const struct mtk_parent netsys_2x_parents[] = {
185 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_APMIXED_NET2PLL),
186 APMIXED_PARENT(CK_APMIXED_WEDMCUPLL), TOP_PARENT(CK_TOP_MMPLL_D2),
187};
developer37161fe2022-09-09 20:00:09 +0800188
Christian Marangi0fc50e72024-08-03 10:40:43 +0200189static const struct mtk_parent sgm_325m_parents[] = {
190 TOP_PARENT(CK_TOP_XTAL), APMIXED_PARENT(CK_APMIXED_SGMPLL),
191};
developer37161fe2022-09-09 20:00:09 +0800192
Christian Marangi0fc50e72024-08-03 10:40:43 +0200193static const struct mtk_parent sgm_reg_parents[] = {
194 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D8_D4),
195};
developer37161fe2022-09-09 20:00:09 +0800196
Christian Marangi0fc50e72024-08-03 10:40:43 +0200197static const struct mtk_parent a1sys_parents[] = {
198 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_APLL2_D4),
199};
developer37161fe2022-09-09 20:00:09 +0800200
Christian Marangi0fc50e72024-08-03 10:40:43 +0200201static const struct mtk_parent conn_mcusys_parents[] = {
202 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MMPLL_D2),
203};
developer37161fe2022-09-09 20:00:09 +0800204
Christian Marangi0fc50e72024-08-03 10:40:43 +0200205static const struct mtk_parent eip_b_parents[] = {
206 TOP_PARENT(CK_TOP_XTAL), APMIXED_PARENT(CK_APMIXED_NET2PLL),
207};
developer37161fe2022-09-09 20:00:09 +0800208
Christian Marangi0fc50e72024-08-03 10:40:43 +0200209static const struct mtk_parent aud_l_parents[] = {
210 TOP_PARENT(CK_TOP_XTAL), APMIXED_PARENT(CK_APMIXED_APLL2),
211 TOP_PARENT(CK_TOP_MPLL_D8_D2),
212};
developer37161fe2022-09-09 20:00:09 +0800213
Christian Marangi0fc50e72024-08-03 10:40:43 +0200214static const struct mtk_parent a_tuner_parents[] = {
215 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_APLL2_D4),
216 TOP_PARENT(CK_TOP_MPLL_D8_D2),
217};
developer37161fe2022-09-09 20:00:09 +0800218
Christian Marangi0fc50e72024-08-03 10:40:43 +0200219static const struct mtk_parent u2u3_sys_parents[] = {
220 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_NET1PLL_D5_D4),
221};
developer37161fe2022-09-09 20:00:09 +0800222
Christian Marangi0fc50e72024-08-03 10:40:43 +0200223static const struct mtk_parent da_u2_refsel_parents[] = {
224 TOP_PARENT(CK_TOP_XTAL), TOP_PARENT(CK_TOP_MMPLL_U2PHYD),
225};
developer37161fe2022-09-09 20:00:09 +0800226
227#define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
228 _shift, _width, _gate, _upd_ofs, _upd) \
229 { \
230 .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \
231 .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \
232 .upd_shift = _upd, .mux_shift = _shift, \
233 .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \
Christian Marangi0fc50e72024-08-03 10:40:43 +0200234 .gate_shift = _gate, .parent_flags = _parents, \
developer37161fe2022-09-09 20:00:09 +0800235 .num_parents = ARRAY_SIZE(_parents), \
Christian Marangi0fc50e72024-08-03 10:40:43 +0200236 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \
developer37161fe2022-09-09 20:00:09 +0800237 }
238
239/* TOPCKGEN MUX_GATE */
240static const struct mtk_composite top_muxes[] = {
241 /* CLK_CFG_0 */
242 TOP_MUX(CK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x000, 0x004,
243 0x008, 0, 3, 7, 0x1C0, 0),
244 TOP_MUX(CK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x000, 0x004,
245 0x008, 8, 3, 15, 0x1C0, 1),
246 TOP_MUX(CK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x000, 0x004, 0x008, 16,
247 3, 23, 0x1C0, 2),
248 TOP_MUX(CK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x000, 0x004,
249 0x008, 24, 3, 31, 0x1C0, 3),
250 /* CLK_CFG_1 */
251 TOP_MUX(CK_TOP_UART_SEL, "uart_sel", uart_parents, 0x010, 0x014, 0x018,
252 0, 2, 7, 0x1C0, 4),
253 TOP_MUX(CK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x010, 0x014, 0x018, 8,
254 2, 15, 0x1C0, 5),
255 TOP_MUX(CK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x010, 0x014, 0x018, 16,
256 2, 23, 0x1C0, 6),
257 TOP_MUX(CK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents,
258 0x010, 0x014, 0x018, 24, 2, 31, 0x1C0, 7),
259 /* CLK_CFG_2 */
260 TOP_MUX(CK_TOP_EMMC_250M_SEL, "emmc_250m_sel", emmc_250m_parents, 0x020,
261 0x024, 0x028, 0, 1, 7, 0x1C0, 8),
262 TOP_MUX(CK_TOP_EMMC_416M_SEL, "emmc_416m_sel", emmc_416m_parents, 0x020,
263 0x024, 0x028, 8, 1, 15, 0x1C0, 9),
264 TOP_MUX(CK_TOP_F_26M_ADC_SEL, "f_26m_adc_sel", f_26m_adc_parents, 0x020,
265 0x024, 0x028, 16, 1, 23, 0x1C0, 10),
266 TOP_MUX(CK_TOP_DRAMC_SEL, "dramc_sel", f_26m_adc_parents, 0x020, 0x024,
267 0x028, 24, 1, 31, 0x1C0, 11),
268 /* CLK_CFG_3 */
269 TOP_MUX(CK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents,
270 0x030, 0x034, 0x038, 0, 1, 7, 0x1C0, 12),
271 TOP_MUX(CK_TOP_SYSAXI_SEL, "sysaxi_sel", sysaxi_parents, 0x030, 0x034,
272 0x038, 8, 2, 15, 0x1C0, 13),
273 TOP_MUX(CK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0x030, 0x034,
274 0x038, 16, 2, 23, 0x1C0, 14),
275 TOP_MUX(CK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel", arm_db_main_parents,
276 0x030, 0x034, 0x038, 24, 1, 31, 0x1C0, 15),
277 /* CLK_CFG_4 */
278 TOP_MUX(CK_TOP_ARM_DB_JTSEL, "arm_db_jtsel", arm_db_jtsel_parents,
279 0x040, 0x044, 0x048, 0, 1, 7, 0x1C0, 16),
280 TOP_MUX(CK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x040, 0x044,
281 0x048, 8, 1, 15, 0x1C0, 17),
282 TOP_MUX(CK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents,
283 0x040, 0x044, 0x048, 16, 1, 23, 0x1C0, 18),
284 TOP_MUX(CK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents,
285 0x040, 0x044, 0x048, 24, 3, 31, 0x1C0, 19),
286 /* CLK_CFG_5 */
287 TOP_MUX(CK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x050,
288 0x054, 0x058, 0, 2, 7, 0x1C0, 20),
289 TOP_MUX(CK_TOP_SGM_325M_SEL, "sgm_325m_sel", sgm_325m_parents, 0x050,
290 0x054, 0x058, 8, 1, 15, 0x1C0, 21),
291 TOP_MUX(CK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents, 0x050,
292 0x054, 0x058, 16, 1, 23, 0x1C0, 22),
293 TOP_MUX(CK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x050, 0x054,
294 0x058, 24, 1, 31, 0x1C0, 23),
295 /* CLK_CFG_6 */
296 TOP_MUX(CK_TOP_CONN_MCUSYS_SEL, "conn_mcusys_sel", conn_mcusys_parents,
297 0x060, 0x064, 0x068, 0, 1, 7, 0x1C0, 24),
298 TOP_MUX(CK_TOP_EIP_B_SEL, "eip_b_sel", eip_b_parents, 0x060, 0x064,
299 0x068, 8, 1, 15, 0x1C0, 25),
300 TOP_MUX(CK_TOP_PCIE_PHY_SEL, "pcie_phy_sel", f_26m_adc_parents, 0x060,
301 0x064, 0x068, 16, 1, 23, 0x1C0, 26),
302 TOP_MUX(CK_TOP_USB3_PHY_SEL, "usb3_phy_sel", f_26m_adc_parents, 0x060,
303 0x064, 0x068, 24, 1, 31, 0x1C0, 27),
304 /* CLK_CFG_7 */
305 TOP_MUX(CK_TOP_F26M_SEL, "csw_f26m_sel", f_26m_adc_parents, 0x070,
306 0x074, 0x078, 0, 1, 7, 0x1C0, 28),
307 TOP_MUX(CK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x070, 0x074,
308 0x078, 8, 2, 15, 0x1C0, 29),
309 TOP_MUX(CK_TOP_A_TUNER_SEL, "a_tuner_sel", a_tuner_parents, 0x070,
310 0x074, 0x078, 16, 2, 23, 0x1C0, 30),
311 TOP_MUX(CK_TOP_U2U3_SEL, "u2u3_sel", f_26m_adc_parents, 0x070, 0x074,
312 0x078, 24, 1, 31, 0x1C4, 0),
313 /* CLK_CFG_8 */
314 TOP_MUX(CK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel", u2u3_sys_parents, 0x080,
315 0x084, 0x088, 0, 1, 7, 0x1C4, 1),
316 TOP_MUX(CK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel", u2u3_sys_parents, 0x080,
317 0x084, 0x088, 8, 1, 15, 0x1C4, 2),
318 TOP_MUX(CK_TOP_DA_U2_REFSEL, "da_u2_refsel", da_u2_refsel_parents,
319 0x080, 0x084, 0x088, 16, 1, 23, 0x1C4, 3),
320 TOP_MUX(CK_TOP_DA_U2_CK_1P_SEL, "da_u2_ck_1p_sel", da_u2_refsel_parents,
321 0x080, 0x084, 0x088, 24, 1, 31, 0x1C4, 4),
322 /* CLK_CFG_9 */
323 TOP_MUX(CK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel", sgm_reg_parents,
324 0x090, 0x094, 0x098, 0, 1, 7, 0x1C4, 5),
325};
326
327/* INFRA FIXED DIV */
328static const struct mtk_fixed_factor infra_fixed_divs[] = {
Christian Marangi7739a5f2024-08-03 10:40:36 +0200329 TOP_FACTOR(CK_INFRA_SYSAXI_D2, "infra_sysaxi_d2", CK_TOP_SYSAXI_SEL, 1, 2),
developer37161fe2022-09-09 20:00:09 +0800330};
331
332/* INFRASYS MUX PARENTS */
Christian Marangi0fc50e72024-08-03 10:40:43 +0200333
developer37161fe2022-09-09 20:00:09 +0800334
Christian Marangiab4de132024-08-03 10:40:38 +0200335static const struct mtk_parent infra_uart0_parents[] = {
336 TOP_PARENT(CK_TOP_F26M_SEL),
337 TOP_PARENT(CK_TOP_UART_SEL)
338};
339
340static const struct mtk_parent infra_spi0_parents[] = {
341 TOP_PARENT(CK_TOP_I2C_SEL),
342 TOP_PARENT(CK_TOP_SPI_SEL)
343};
developer37161fe2022-09-09 20:00:09 +0800344
Christian Marangiab4de132024-08-03 10:40:38 +0200345static const struct mtk_parent infra_spi1_parents[] = {
346 TOP_PARENT(CK_TOP_I2C_SEL),
347 TOP_PARENT(CK_TOP_SPINFI_SEL)
348};
developer37161fe2022-09-09 20:00:09 +0800349
Christian Marangiab4de132024-08-03 10:40:38 +0200350static const struct mtk_parent infra_pwm_bsel_parents[] = {
Christian Marangi9276f072024-08-03 10:40:41 +0200351 TOP_PARENT(CK_TOP_RTC_32P7K),
Christian Marangiab4de132024-08-03 10:40:38 +0200352 TOP_PARENT(CK_TOP_F26M_SEL),
353 INFRA_PARENT(CK_INFRA_SYSAXI_D2),
354 TOP_PARENT(CK_TOP_PWM_SEL)
355};
developer37161fe2022-09-09 20:00:09 +0800356
Christian Marangiab4de132024-08-03 10:40:38 +0200357static const struct mtk_parent infra_pcie_parents[] = {
Christian Marangi9276f072024-08-03 10:40:41 +0200358 TOP_PARENT(CK_TOP_RTC_32P7K),
Christian Marangiab4de132024-08-03 10:40:38 +0200359 TOP_PARENT(CK_TOP_F26M_SEL),
Christian Marangi6a89a382024-08-03 10:40:39 +0200360 TOP_PARENT(CK_TOP_XTAL),
Christian Marangiab4de132024-08-03 10:40:38 +0200361 TOP_PARENT(CK_TOP_PEXTP_TL_SEL)
362};
developer37161fe2022-09-09 20:00:09 +0800363
364#define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \
365 { \
366 .id = _id, .mux_reg = (_reg) + 0x8, \
367 .mux_set_reg = (_reg) + 0x0, .mux_clr_reg = (_reg) + 0x4, \
368 .mux_shift = _shift, .mux_mask = BIT(_width) - 1, \
Christian Marangiab4de132024-08-03 10:40:38 +0200369 .parent_flags = _parents, .num_parents = ARRAY_SIZE(_parents), \
370 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \
developer37161fe2022-09-09 20:00:09 +0800371 }
372
373/* INFRA MUX */
374
375static const struct mtk_composite infra_muxes[] = {
376 /* MODULE_CLK_SEL_0 */
377 INFRA_MUX(CK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart0_parents,
378 0x10, 0, 1),
379 INFRA_MUX(CK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart0_parents,
380 0x10, 1, 1),
381 INFRA_MUX(CK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart0_parents,
382 0x10, 2, 1),
383 INFRA_MUX(CK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x10,
384 4, 1),
385 INFRA_MUX(CK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x10,
386 5, 1),
387 INFRA_MUX(CK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm_bsel_parents,
388 0x10, 9, 2),
389 INFRA_MUX(CK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm_bsel_parents,
390 0x10, 11, 2),
391 INFRA_MUX(CK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents,
392 0x10, 13, 2),
393 /* MODULE_CLK_SEL_1 */
394 INFRA_MUX(CK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x20,
395 0, 2),
396};
397
398static const struct mtk_gate_regs infra_0_cg_regs = {
399 .set_ofs = 0x40,
400 .clr_ofs = 0x44,
401 .sta_ofs = 0x48,
402};
403
404static const struct mtk_gate_regs infra_1_cg_regs = {
405 .set_ofs = 0x50,
406 .clr_ofs = 0x54,
407 .sta_ofs = 0x58,
408};
409
410static const struct mtk_gate_regs infra_2_cg_regs = {
411 .set_ofs = 0x60,
412 .clr_ofs = 0x64,
413 .sta_ofs = 0x68,
414};
415
Christian Marangiab4de132024-08-03 10:40:38 +0200416#define GATE_INFRA0(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800417 { \
418 .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \
419 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200420 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800421 }
Christian Marangiab4de132024-08-03 10:40:38 +0200422#define GATE_INFRA0_INFRA(_id, _name, _parent, _shift) \
423 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
424#define GATE_INFRA0_TOP(_id, _name, _parent, _shift) \
425 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800426
Christian Marangiab4de132024-08-03 10:40:38 +0200427#define GATE_INFRA1(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800428 { \
429 .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \
430 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200431 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800432 }
Christian Marangiab4de132024-08-03 10:40:38 +0200433#define GATE_INFRA1_INFRA(_id, _name, _parent, _shift) \
434 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
435#define GATE_INFRA1_TOP(_id, _name, _parent, _shift) \
436 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800437
Christian Marangiab4de132024-08-03 10:40:38 +0200438#define GATE_INFRA2(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800439 { \
440 .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \
441 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200442 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800443 }
Christian Marangiab4de132024-08-03 10:40:38 +0200444#define GATE_INFRA2_INFRA(_id, _name, _parent, _shift) \
445 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
446#define GATE_INFRA2_TOP(_id, _name, _parent, _shift) \
447 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800448
449/* INFRA GATE */
450
451static const struct mtk_gate infracfg_ao_gates[] = {
452 /* INFRA0 */
Christian Marangiab4de132024-08-03 10:40:38 +0200453 GATE_INFRA0_INFRA(CK_INFRA_GPT_STA, "infra_gpt_sta", CK_INFRA_SYSAXI_D2, 0),
454 GATE_INFRA0_INFRA(CK_INFRA_PWM_HCK, "infra_pwm_hck", CK_INFRA_SYSAXI_D2, 1),
455 GATE_INFRA0_INFRA(CK_INFRA_PWM_STA, "infra_pwm_sta", CK_INFRA_PWM_BSEL, 2),
456 GATE_INFRA0_INFRA(CK_INFRA_PWM1_CK, "infra_pwm1", CK_INFRA_PWM1_SEL, 3),
457 GATE_INFRA0_INFRA(CK_INFRA_PWM2_CK, "infra_pwm2", CK_INFRA_PWM2_SEL, 4),
458 GATE_INFRA0_TOP(CK_INFRA_CQ_DMA_CK, "infra_cq_dma", CK_TOP_SYSAXI_SEL, 6),
459 GATE_INFRA0_TOP(CK_INFRA_EIP97_CK, "infra_eip97", CK_TOP_EIP_B_SEL, 7),
460 GATE_INFRA0_TOP(CK_INFRA_AUD_BUS_CK, "infra_aud_bus", CK_TOP_SYSAXI_SEL, 8),
461 GATE_INFRA0_TOP(CK_INFRA_AUD_26M_CK, "infra_aud_26m", CK_TOP_F26M_SEL, 9),
462 GATE_INFRA0_TOP(CK_INFRA_AUD_L_CK, "infra_aud_l", CK_TOP_AUD_L_SEL, 10),
463 GATE_INFRA0_TOP(CK_INFRA_AUD_AUD_CK, "infra_aud_aud", CK_TOP_A1SYS_SEL,
464 11),
465 GATE_INFRA0_TOP(CK_INFRA_AUD_EG2_CK, "infra_aud_eg2", CK_TOP_A_TUNER_SEL,
466 13),
467 GATE_INFRA0_TOP(CK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", CK_TOP_F26M_SEL,
468 14),
469 GATE_INFRA0_INFRA(CK_INFRA_DBG_CK, "infra_dbg", CK_INFRA_SYSAXI_D2, 15),
470 GATE_INFRA0_INFRA(CK_INFRA_AP_DMA_CK, "infra_ap_dma", CK_INFRA_SYSAXI_D2, 16),
471 GATE_INFRA0_INFRA(CK_INFRA_SEJ_CK, "infra_sej", CK_INFRA_SYSAXI_D2, 24),
472 GATE_INFRA0_TOP(CK_INFRA_SEJ_13M_CK, "infra_sej_13m", CK_TOP_F26M_SEL, 25),
developer37161fe2022-09-09 20:00:09 +0800473 /* INFRA1 */
Christian Marangiab4de132024-08-03 10:40:38 +0200474 GATE_INFRA1_TOP(CK_INFRA_THERM_CK, "infra_therm", CK_TOP_F26M_SEL, 0),
Christian Marangi30c4b862024-08-03 10:40:40 +0200475 GATE_INFRA1_TOP(CK_INFRA_I2C0_CK, "infra_i2co", CK_TOP_I2C_SEL, 1),
Christian Marangiab4de132024-08-03 10:40:38 +0200476 GATE_INFRA1_INFRA(CK_INFRA_UART0_CK, "infra_uart0", CK_INFRA_UART0_SEL, 2),
477 GATE_INFRA1_INFRA(CK_INFRA_UART1_CK, "infra_uart1", CK_INFRA_UART1_SEL, 3),
478 GATE_INFRA1_INFRA(CK_INFRA_UART2_CK, "infra_uart2", CK_INFRA_UART2_SEL, 4),
479 GATE_INFRA1_TOP(CK_INFRA_NFI1_CK, "infra_nfi1", CK_TOP_NFI1X_SEL, 8),
480 GATE_INFRA1_TOP(CK_INFRA_SPINFI1_CK, "infra_spinfi1", CK_TOP_SPINFI_SEL,
481 9),
482 GATE_INFRA1_INFRA(CK_INFRA_NFI_HCK_CK, "infra_nfi_hck", CK_INFRA_SYSAXI_D2, 10),
483 GATE_INFRA1_INFRA(CK_INFRA_SPI0_CK, "infra_spi0", CK_INFRA_SPI0_SEL, 11),
484 GATE_INFRA1_INFRA(CK_INFRA_SPI1_CK, "infra_spi1", CK_INFRA_SPI1_SEL, 12),
485 GATE_INFRA1_INFRA(CK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", CK_INFRA_SYSAXI_D2,
486 13),
487 GATE_INFRA1_INFRA(CK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", CK_INFRA_SYSAXI_D2,
488 14),
Christian Marangi9276f072024-08-03 10:40:41 +0200489 GATE_INFRA1_TOP(CK_INFRA_FRTC_CK, "infra_frtc", CK_TOP_RTC_32K, 15),
Christian Marangiab4de132024-08-03 10:40:38 +0200490 GATE_INFRA1_TOP(CK_INFRA_MSDC_CK, "infra_msdc", CK_TOP_EMMC_416M_SEL, 16),
491 GATE_INFRA1_TOP(CK_INFRA_MSDC_HCK_CK, "infra_msdc_hck",
492 CK_TOP_EMMC_250M_SEL, 17),
493 GATE_INFRA1_TOP(CK_INFRA_MSDC_133M_CK, "infra_msdc_133m",
494 CK_TOP_SYSAXI_SEL, 18),
495 GATE_INFRA1_INFRA(CK_INFRA_MSDC_66M_CK, "infra_msdc_66m", CK_INFRA_SYSAXI_D2,
496 19),
497 GATE_INFRA1_INFRA(CK_INFRA_ADC_26M_CK, "infra_adc_26m", CK_INFRA_ADC_FRC_CK, 20),
498 GATE_INFRA1_TOP(CK_INFRA_ADC_FRC_CK, "infra_adc_frc", CK_TOP_F26M_SEL, 21),
499 GATE_INFRA1_TOP(CK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", CK_TOP_NFI1X_SEL,
500 23),
developer37161fe2022-09-09 20:00:09 +0800501 /* INFRA2 */
Christian Marangiab4de132024-08-03 10:40:38 +0200502 GATE_INFRA2_TOP(CK_INFRA_IUSB_133_CK, "infra_iusb_133", CK_TOP_SYSAXI_SEL,
503 0),
504 GATE_INFRA2_INFRA(CK_INFRA_IUSB_66M_CK, "infra_iusb_66m", CK_INFRA_SYSAXI_D2,
505 1),
506 GATE_INFRA2_TOP(CK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", CK_TOP_U2U3_SYS_SEL,
507 2),
508 GATE_INFRA2_TOP(CK_INFRA_IUSB_CK, "infra_iusb", CK_TOP_U2U3_SEL, 3),
509 GATE_INFRA2_TOP(CK_INFRA_IPCIE_CK, "infra_ipcie", CK_TOP_PEXTP_TL_SEL, 12),
Christian Marangi6a89a382024-08-03 10:40:39 +0200510 GATE_INFRA2_TOP(CK_INFRA_IPCIE_PIPE_CK, "infra_ipcie_pipe", CK_TOP_XTAL, 13),
Christian Marangiab4de132024-08-03 10:40:38 +0200511 GATE_INFRA2_TOP(CK_INFRA_IPCIER_CK, "infra_ipcier", CK_TOP_F26M_SEL, 14),
512 GATE_INFRA2_TOP(CK_INFRA_IPCIEB_CK, "infra_ipcieb", CK_TOP_SYSAXI_SEL, 15),
Christian Marangi6698b4d2024-08-03 10:40:45 +0200513 /* upstream linux unordered */
514 GATE_INFRA0_TOP(CK_INFRA_TRNG_CK, "infra_trng", CK_TOP_SYSAXI_SEL, 26),
developer37161fe2022-09-09 20:00:09 +0800515};
516
517static const struct mtk_clk_tree mt7986_fixed_pll_clk_tree = {
518 .fdivs_offs = CLK_APMIXED_NR_CLK,
519 .xtal_rate = 40 * MHZ,
520 .fclks = fixed_pll_clks,
Christian Marangi0fc50e72024-08-03 10:40:43 +0200521 .flags = CLK_APMIXED,
developer37161fe2022-09-09 20:00:09 +0800522};
523
524static const struct mtk_clk_tree mt7986_topckgen_clk_tree = {
Christian Marangi0fc50e72024-08-03 10:40:43 +0200525 .fdivs_offs = CK_TOP_XTAL_D2,
developer37161fe2022-09-09 20:00:09 +0800526 .muxes_offs = CK_TOP_NFI1X_SEL,
527 .fclks = top_fixed_clks,
528 .fdivs = top_fixed_divs,
529 .muxes = top_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200530 .flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
developer37161fe2022-09-09 20:00:09 +0800531};
532
533static const struct mtk_clk_tree mt7986_infracfg_clk_tree = {
Christian Marangiab4de132024-08-03 10:40:38 +0200534 .fdivs_offs = CK_INFRA_SYSAXI_D2,
developer37161fe2022-09-09 20:00:09 +0800535 .muxes_offs = CK_INFRA_UART0_SEL,
536 .fdivs = infra_fixed_divs,
537 .muxes = infra_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200538 .flags = CLK_INFRASYS,
developer37161fe2022-09-09 20:00:09 +0800539};
540
541static const struct udevice_id mt7986_fixed_pll_compat[] = {
542 { .compatible = "mediatek,mt7986-fixed-plls" },
Christian Marangi4dd4a282024-06-24 23:03:40 +0200543 { .compatible = "mediatek,mt7986-apmixedsys" },
developer37161fe2022-09-09 20:00:09 +0800544 {}
545};
546
547static const struct udevice_id mt7986_topckgen_compat[] = {
548 { .compatible = "mediatek,mt7986-topckgen" },
549 {}
550};
551
552static int mt7986_fixed_pll_probe(struct udevice *dev)
553{
554 return mtk_common_clk_init(dev, &mt7986_fixed_pll_clk_tree);
555}
556
557static int mt7986_topckgen_probe(struct udevice *dev)
558{
559 struct mtk_clk_priv *priv = dev_get_priv(dev);
560
561 priv->base = dev_read_addr_ptr(dev);
562 writel(MT7986_CLK_PDN_EN_WRITE, priv->base + MT7986_CLK_PDN);
563
564 return mtk_common_clk_init(dev, &mt7986_topckgen_clk_tree);
565}
566
567U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
568 .name = "mt7986-clock-fixed-pll",
569 .id = UCLASS_CLK,
570 .of_match = mt7986_fixed_pll_compat,
571 .probe = mt7986_fixed_pll_probe,
572 .priv_auto = sizeof(struct mtk_clk_priv),
573 .ops = &mtk_clk_topckgen_ops,
574 .flags = DM_FLAG_PRE_RELOC,
575};
576
577U_BOOT_DRIVER(mtk_clk_topckgen) = {
578 .name = "mt7986-clock-topckgen",
579 .id = UCLASS_CLK,
580 .of_match = mt7986_topckgen_compat,
581 .probe = mt7986_topckgen_probe,
582 .priv_auto = sizeof(struct mtk_clk_priv),
583 .ops = &mtk_clk_topckgen_ops,
584 .flags = DM_FLAG_PRE_RELOC,
585};
586
587static const struct udevice_id mt7986_infracfg_compat[] = {
588 { .compatible = "mediatek,mt7986-infracfg" },
589 {}
590};
591
592static const struct udevice_id mt7986_infracfg_ao_compat[] = {
593 { .compatible = "mediatek,mt7986-infracfg_ao" },
594 {}
595};
596
597static int mt7986_infracfg_probe(struct udevice *dev)
598{
599 return mtk_common_clk_init(dev, &mt7986_infracfg_clk_tree);
600}
601
602static int mt7986_infracfg_ao_probe(struct udevice *dev)
603{
604 return mtk_common_clk_gate_init(dev, &mt7986_infracfg_clk_tree,
605 infracfg_ao_gates);
606}
607
608U_BOOT_DRIVER(mtk_clk_infracfg) = {
609 .name = "mt7986-clock-infracfg",
610 .id = UCLASS_CLK,
611 .of_match = mt7986_infracfg_compat,
612 .probe = mt7986_infracfg_probe,
613 .priv_auto = sizeof(struct mtk_clk_priv),
614 .ops = &mtk_clk_infrasys_ops,
615 .flags = DM_FLAG_PRE_RELOC,
616};
617
618U_BOOT_DRIVER(mtk_clk_infracfg_ao) = {
619 .name = "mt7986-clock-infracfg-ao",
620 .id = UCLASS_CLK,
621 .of_match = mt7986_infracfg_ao_compat,
622 .probe = mt7986_infracfg_ao_probe,
623 .priv_auto = sizeof(struct mtk_cg_priv),
624 .ops = &mtk_clk_gate_ops,
625 .flags = DM_FLAG_PRE_RELOC,
626};
627
628/* ethsys */
629static const struct mtk_gate_regs eth_cg_regs = {
630 .sta_ofs = 0x30,
631};
632
633#define GATE_ETH(_id, _name, _parent, _shift) \
634 { \
635 .id = _id, .parent = _parent, .regs = &eth_cg_regs, \
636 .shift = _shift, \
637 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
638 }
639
640static const struct mtk_gate eth_cgs[] = {
Christian Marangi0fc50e72024-08-03 10:40:43 +0200641 GATE_ETH(CK_ETH_FE_EN, "eth_fe_en", CK_TOP_NETSYS_2X_SEL, 7),
642 GATE_ETH(CK_ETH_GP2_EN, "eth_gp2_en", CK_TOP_SGM_325M_SEL, 8),
643 GATE_ETH(CK_ETH_GP1_EN, "eth_gp1_en", CK_TOP_SGM_325M_SEL, 8),
644 GATE_ETH(CK_ETH_WOCPU1_EN, "eth_wocpu1_en", CK_TOP_NETSYS_MCU_SEL, 14),
645 GATE_ETH(CK_ETH_WOCPU0_EN, "eth_wocpu0_en", CK_TOP_NETSYS_MCU_SEL, 15),
developer37161fe2022-09-09 20:00:09 +0800646};
647
648static int mt7986_ethsys_probe(struct udevice *dev)
649{
650 return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree,
651 eth_cgs);
652}
653
654static int mt7986_ethsys_bind(struct udevice *dev)
655{
656 int ret = 0;
657
658 if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
659 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
660 if (ret)
661 debug("Warning: failed to bind reset controller\n");
662 }
663
664 return ret;
665}
666
667static const struct udevice_id mt7986_ethsys_compat[] = {
668 { .compatible = "mediatek,mt7986-ethsys" },
669 { }
670};
671
672U_BOOT_DRIVER(mtk_clk_ethsys) = {
673 .name = "mt7986-clock-ethsys",
674 .id = UCLASS_CLK,
675 .of_match = mt7986_ethsys_compat,
676 .probe = mt7986_ethsys_probe,
677 .bind = mt7986_ethsys_bind,
678 .priv_auto = sizeof(struct mtk_cg_priv),
679 .ops = &mtk_clk_gate_ops,
680};