blob: 0a1495a464e7cfa93ed8190e6a32db5a99582037 [file] [log] [blame]
Sam Shih72ab6032020-01-10 16:30:29 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7622 SoC
4 *
5 * Copyright (C) 2019 MediaTek Inc.
6 * Author: Ryder Lee <ryder.lee@mediatek.com>
7 */
8
9#include <common.h>
10#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Sam Shih72ab6032020-01-10 16:30:29 +080012#include <asm/arch-mediatek/reset.h>
13#include <asm/io.h>
14#include <dt-bindings/clock/mt7622-clk.h>
15
16#include "clk-mtk.h"
17
18#define MT7622_CLKSQ_STB_CON0 0x20
19#define MT7622_PLL_ISO_CON0 0x2c
20#define MT7622_PLL_FMAX (2500UL * MHZ)
21#define MT7622_CON0_RST_BAR BIT(24)
22
23#define MCU_AXI_DIV 0x640
24#define AXI_DIV_MSK GENMASK(4, 0)
25#define AXI_DIV_SEL(x) (x)
26
27#define MCU_BUS_MUX 0x7c0
28#define MCU_BUS_MSK GENMASK(10, 9)
29#define MCU_BUS_SEL(x) ((x) << 9)
30
31/* apmixedsys */
32#define PLL(_id, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
33 _pd_shift, _pcw_reg, _pcw_shift) { \
34 .id = _id, \
35 .reg = _reg, \
36 .pwr_reg = _pwr_reg, \
37 .en_mask = _en_mask, \
38 .rst_bar_mask = MT7622_CON0_RST_BAR, \
39 .fmax = MT7622_PLL_FMAX, \
40 .flags = _flags, \
41 .pcwbits = _pcwbits, \
42 .pd_reg = _pd_reg, \
43 .pd_shift = _pd_shift, \
44 .pcw_reg = _pcw_reg, \
45 .pcw_shift = _pcw_shift, \
46 }
47
48static const struct mtk_pll_data apmixed_plls[] = {
49 PLL(CLK_APMIXED_ARMPLL, 0x200, 0x20c, 0x1, 0,
50 21, 0x204, 24, 0x204, 0),
51 PLL(CLK_APMIXED_MAINPLL, 0x210, 0x21c, 0x1, HAVE_RST_BAR,
52 21, 0x214, 24, 0x214, 0),
53 PLL(CLK_APMIXED_UNIV2PLL, 0x220, 0x22c, 0x1, HAVE_RST_BAR,
54 7, 0x224, 24, 0x224, 14),
55 PLL(CLK_APMIXED_ETH1PLL, 0x300, 0x310, 0x1, 0,
56 21, 0x300, 1, 0x304, 0),
57 PLL(CLK_APMIXED_ETH2PLL, 0x314, 0x320, 0x1, 0,
58 21, 0x314, 1, 0x318, 0),
59 PLL(CLK_APMIXED_AUD1PLL, 0x324, 0x330, 0x1, 0,
60 31, 0x324, 1, 0x328, 0),
61 PLL(CLK_APMIXED_AUD2PLL, 0x334, 0x340, 0x1, 0,
62 31, 0x334, 1, 0x338, 0),
63 PLL(CLK_APMIXED_TRGPLL, 0x344, 0x354, 0x1, 0,
64 21, 0x344, 1, 0x348, 0),
65 PLL(CLK_APMIXED_SGMIPLL, 0x358, 0x368, 0x1, 0,
66 21, 0x358, 1, 0x35c, 0),
67};
68
69/* topckgen */
70#define FACTOR0(_id, _parent, _mult, _div) \
71 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
72
73#define FACTOR1(_id, _parent, _mult, _div) \
74 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
75
76#define FACTOR2(_id, _parent, _mult, _div) \
77 FACTOR(_id, _parent, _mult, _div, 0)
78
79static const struct mtk_fixed_clk top_fixed_clks[] = {
80 FIXED_CLK(CLK_TOP_TO_U2_PHY, CLK_XTAL, 31250000),
81 FIXED_CLK(CLK_TOP_TO_U2_PHY_1P, CLK_XTAL, 31250000),
82 FIXED_CLK(CLK_TOP_PCIE0_PIPE_EN, CLK_XTAL, 125000000),
83 FIXED_CLK(CLK_TOP_PCIE1_PIPE_EN, CLK_XTAL, 125000000),
84 FIXED_CLK(CLK_TOP_SSUSB_TX250M, CLK_XTAL, 250000000),
85 FIXED_CLK(CLK_TOP_SSUSB_EQ_RX250M, CLK_XTAL, 250000000),
86 FIXED_CLK(CLK_TOP_SSUSB_CDR_REF, CLK_XTAL, 33333333),
87 FIXED_CLK(CLK_TOP_SSUSB_CDR_FB, CLK_XTAL, 50000000),
88 FIXED_CLK(CLK_TOP_SATA_ASIC, CLK_XTAL, 50000000),
89 FIXED_CLK(CLK_TOP_SATA_RBC, CLK_XTAL, 50000000),
90};
91
92static const struct mtk_fixed_factor top_fixed_divs[] = {
93 FACTOR0(CLK_TOP_TO_USB3_SYS, CLK_APMIXED_ETH1PLL, 1, 4),
94 FACTOR0(CLK_TOP_P1_1MHZ, CLK_APMIXED_ETH1PLL, 1, 500),
95 FACTOR0(CLK_TOP_4MHZ, CLK_APMIXED_ETH1PLL, 1, 125),
96 FACTOR0(CLK_TOP_P0_1MHZ, CLK_APMIXED_ETH1PLL, 1, 500),
97 FACTOR1(CLK_TOP_TXCLK_SRC_PRE, CLK_TOP_SGMIIPLL_D2, 1, 1),
98 FACTOR2(CLK_TOP_RTC, CLK_XTAL, 1, 1024),
99 FACTOR2(CLK_TOP_MEMPLL, CLK_XTAL, 32, 1),
100 FACTOR1(CLK_TOP_DMPLL, CLK_TOP_MEMPLL, 1, 1),
101 FACTOR0(CLK_TOP_SYSPLL_D2, CLK_APMIXED_MAINPLL, 1, 2),
102 FACTOR0(CLK_TOP_SYSPLL1_D2, CLK_APMIXED_MAINPLL, 1, 4),
103 FACTOR0(CLK_TOP_SYSPLL1_D4, CLK_APMIXED_MAINPLL, 1, 8),
104 FACTOR0(CLK_TOP_SYSPLL1_D8, CLK_APMIXED_MAINPLL, 1, 16),
105 FACTOR0(CLK_TOP_SYSPLL2_D4, CLK_APMIXED_MAINPLL, 1, 12),
106 FACTOR0(CLK_TOP_SYSPLL2_D8, CLK_APMIXED_MAINPLL, 1, 24),
107 FACTOR0(CLK_TOP_SYSPLL_D5, CLK_APMIXED_MAINPLL, 1, 5),
108 FACTOR0(CLK_TOP_SYSPLL3_D2, CLK_APMIXED_MAINPLL, 1, 10),
109 FACTOR0(CLK_TOP_SYSPLL3_D4, CLK_APMIXED_MAINPLL, 1, 20),
110 FACTOR0(CLK_TOP_SYSPLL4_D2, CLK_APMIXED_MAINPLL, 1, 14),
111 FACTOR0(CLK_TOP_SYSPLL4_D4, CLK_APMIXED_MAINPLL, 1, 28),
112 FACTOR0(CLK_TOP_SYSPLL4_D16, CLK_APMIXED_MAINPLL, 1, 112),
113 FACTOR0(CLK_TOP_UNIVPLL, CLK_APMIXED_UNIV2PLL, 1, 2),
114 FACTOR0(CLK_TOP_UNIVPLL_D2, CLK_TOP_UNIVPLL, 1, 2),
115 FACTOR1(CLK_TOP_UNIVPLL1_D2, CLK_TOP_UNIVPLL, 1, 4),
116 FACTOR1(CLK_TOP_UNIVPLL1_D4, CLK_TOP_UNIVPLL, 1, 8),
117 FACTOR1(CLK_TOP_UNIVPLL1_D8, CLK_TOP_UNIVPLL, 1, 16),
118 FACTOR1(CLK_TOP_UNIVPLL1_D16, CLK_TOP_UNIVPLL, 1, 32),
119 FACTOR1(CLK_TOP_UNIVPLL2_D2, CLK_TOP_UNIVPLL, 1, 6),
120 FACTOR1(CLK_TOP_UNIVPLL2_D4, CLK_TOP_UNIVPLL, 1, 12),
121 FACTOR1(CLK_TOP_UNIVPLL2_D8, CLK_TOP_UNIVPLL, 1, 24),
122 FACTOR1(CLK_TOP_UNIVPLL2_D16, CLK_TOP_UNIVPLL, 1, 48),
123 FACTOR1(CLK_TOP_UNIVPLL_D5, CLK_TOP_UNIVPLL, 1, 5),
124 FACTOR1(CLK_TOP_UNIVPLL3_D2, CLK_TOP_UNIVPLL, 1, 10),
125 FACTOR1(CLK_TOP_UNIVPLL3_D4, CLK_TOP_UNIVPLL, 1, 20),
126 FACTOR1(CLK_TOP_UNIVPLL3_D16, CLK_TOP_UNIVPLL, 1, 80),
127 FACTOR1(CLK_TOP_UNIVPLL_D7, CLK_TOP_UNIVPLL, 1, 7),
128 FACTOR1(CLK_TOP_UNIVPLL_D80_D4, CLK_TOP_UNIVPLL, 1, 320),
129 FACTOR1(CLK_TOP_UNIV48M, CLK_TOP_UNIVPLL, 1, 25),
130 FACTOR0(CLK_TOP_SGMIIPLL, CLK_APMIXED_SGMIPLL, 1, 1),
131 FACTOR0(CLK_TOP_SGMIIPLL_D2, CLK_APMIXED_SGMIPLL, 1, 2),
132 FACTOR0(CLK_TOP_AUD1PLL, CLK_APMIXED_AUD1PLL, 1, 1),
133 FACTOR0(CLK_TOP_AUD2PLL, CLK_APMIXED_AUD2PLL, 1, 1),
134 FACTOR1(CLK_TOP_AUD_I2S2_MCK, CLK_TOP_I2S2_MCK_SEL, 1, 2),
135 FACTOR1(CLK_TOP_TO_USB3_REF, CLK_TOP_UNIVPLL2_D4, 1, 4),
136 FACTOR1(CLK_TOP_PCIE1_MAC_EN, CLK_TOP_UNIVPLL1_D4, 1, 1),
137 FACTOR1(CLK_TOP_PCIE0_MAC_EN, CLK_TOP_UNIVPLL1_D4, 1, 1),
138 FACTOR0(CLK_TOP_ETH_500M, CLK_APMIXED_ETH1PLL, 1, 1),
139};
140
141static const int axi_parents[] = {
142 CLK_XTAL,
143 CLK_TOP_SYSPLL1_D2,
144 CLK_TOP_SYSPLL_D5,
145 CLK_TOP_SYSPLL1_D4,
146 CLK_TOP_UNIVPLL_D5,
147 CLK_TOP_UNIVPLL2_D2,
148 CLK_TOP_UNIVPLL_D7
149};
150
151static const int mem_parents[] = {
152 CLK_XTAL,
153 CLK_TOP_DMPLL
154};
155
156static const int ddrphycfg_parents[] = {
157 CLK_XTAL,
158 CLK_TOP_SYSPLL1_D8
159};
160
161static const int eth_parents[] = {
162 CLK_XTAL,
163 CLK_TOP_SYSPLL1_D2,
164 CLK_TOP_UNIVPLL1_D2,
165 CLK_TOP_SYSPLL1_D4,
166 CLK_TOP_UNIVPLL_D5,
167 -1,
168 CLK_TOP_UNIVPLL_D7
169};
170
171static const int pwm_parents[] = {
172 CLK_XTAL,
173 CLK_TOP_UNIVPLL2_D4
174};
175
176static const int f10m_ref_parents[] = {
177 CLK_XTAL,
178 CLK_TOP_SYSPLL4_D16
179};
180
181static const int nfi_infra_parents[] = {
182 CLK_XTAL,
183 CLK_XTAL,
184 CLK_XTAL,
185 CLK_XTAL,
186 CLK_XTAL,
187 CLK_XTAL,
188 CLK_XTAL,
189 CLK_XTAL,
190 CLK_TOP_UNIVPLL2_D8,
191 CLK_TOP_SYSPLL1_D8,
192 CLK_TOP_UNIVPLL1_D8,
193 CLK_TOP_SYSPLL4_D2,
194 CLK_TOP_UNIVPLL2_D4,
195 CLK_TOP_UNIVPLL3_D2,
196 CLK_TOP_SYSPLL1_D4
197};
198
199static const int flash_parents[] = {
200 CLK_XTAL,
201 CLK_TOP_UNIVPLL_D80_D4,
202 CLK_TOP_SYSPLL2_D8,
203 CLK_TOP_SYSPLL3_D4,
204 CLK_TOP_UNIVPLL3_D4,
205 CLK_TOP_UNIVPLL1_D8,
206 CLK_TOP_SYSPLL2_D4,
207 CLK_TOP_UNIVPLL2_D4
208};
209
210static const int uart_parents[] = {
211 CLK_XTAL,
212 CLK_TOP_UNIVPLL2_D8
213};
214
215static const int spi0_parents[] = {
216 CLK_XTAL,
217 CLK_TOP_SYSPLL3_D2,
218 CLK_XTAL,
219 CLK_TOP_SYSPLL2_D4,
220 CLK_TOP_SYSPLL4_D2,
221 CLK_TOP_UNIVPLL2_D4,
222 CLK_TOP_UNIVPLL1_D8,
223 CLK_XTAL
224};
225
226static const int spi1_parents[] = {
227 CLK_XTAL,
228 CLK_TOP_SYSPLL3_D2,
229 CLK_XTAL,
230 CLK_TOP_SYSPLL4_D4,
231 CLK_TOP_SYSPLL4_D2,
232 CLK_TOP_UNIVPLL2_D4,
233 CLK_TOP_UNIVPLL1_D8,
234 CLK_XTAL
235};
236
237static const int msdc30_0_parents[] = {
238 CLK_XTAL,
239 CLK_TOP_UNIVPLL2_D16,
240 CLK_TOP_UNIV48M
241};
242
243static const int a1sys_hp_parents[] = {
244 CLK_XTAL,
245 CLK_TOP_AUD1PLL,
246 CLK_TOP_AUD2PLL,
247 CLK_XTAL
248};
249
250static const int intdir_parents[] = {
251 CLK_XTAL,
252 CLK_TOP_SYSPLL1_D2,
253 CLK_TOP_UNIVPLL_D2,
254 CLK_TOP_SGMIIPLL
255};
256
257static const int aud_intbus_parents[] = {
258 CLK_XTAL,
259 CLK_TOP_SYSPLL1_D4,
260 CLK_TOP_SYSPLL4_D2,
261 CLK_TOP_SYSPLL3_D2
262};
263
264static const int pmicspi_parents[] = {
265 CLK_XTAL,
266 -1,
267 -1,
268 -1,
269 -1,
270 CLK_TOP_UNIVPLL2_D16
271};
272
273static const int atb_parents[] = {
274 CLK_XTAL,
275 CLK_TOP_SYSPLL1_D2,
276 CLK_TOP_SYSPLL_D5
277};
278
279static const int audio_parents[] = {
280 CLK_XTAL,
281 CLK_TOP_SYSPLL3_D4,
282 CLK_TOP_SYSPLL4_D4,
283 CLK_TOP_UNIVPLL1_D16
284};
285
286static const int usb20_parents[] = {
287 CLK_XTAL,
288 CLK_TOP_UNIVPLL3_D4,
289 CLK_TOP_SYSPLL1_D8,
290 CLK_XTAL
291};
292
293static const int aud1_parents[] = {
294 CLK_XTAL,
295 CLK_TOP_AUD1PLL
296};
297
298static const int asm_l_parents[] = {
299 CLK_XTAL,
300 CLK_TOP_SYSPLL_D5,
301 CLK_TOP_UNIVPLL2_D2,
302 CLK_TOP_UNIVPLL2_D4
303};
304
305static const int apll1_ck_parents[] = {
306 CLK_TOP_AUD1_SEL,
307 CLK_TOP_AUD2_SEL
308};
309
310static const struct mtk_composite top_muxes[] = {
311 /* CLK_CFG_0 */
312 MUX_GATE(CLK_TOP_AXI_SEL, axi_parents, 0x40, 0, 3, 7),
313 MUX_GATE(CLK_TOP_MEM_SEL, mem_parents, 0x40, 8, 1, 15),
314 MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, ddrphycfg_parents, 0x40, 16, 1, 23),
315 MUX_GATE(CLK_TOP_ETH_SEL, eth_parents, 0x40, 24, 3, 31),
316
317 /* CLK_CFG_1 */
318 MUX_GATE(CLK_TOP_PWM_SEL, pwm_parents, 0x50, 0, 2, 7),
319 MUX_GATE(CLK_TOP_F10M_REF_SEL, f10m_ref_parents, 0x50, 8, 1, 15),
320 MUX_GATE(CLK_TOP_NFI_INFRA_SEL, nfi_infra_parents, 0x50, 16, 4, 23),
321 MUX_GATE(CLK_TOP_FLASH_SEL, flash_parents, 0x50, 24, 3, 31),
322
323 /* CLK_CFG_2 */
324 MUX_GATE(CLK_TOP_UART_SEL, uart_parents, 0x60, 0, 1, 7),
325 MUX_GATE(CLK_TOP_SPI0_SEL, spi0_parents, 0x60, 8, 3, 15),
326 MUX_GATE(CLK_TOP_SPI1_SEL, spi1_parents, 0x60, 16, 3, 23),
327 MUX_GATE(CLK_TOP_MSDC50_0_SEL, uart_parents, 0x60, 24, 3, 31),
328
329 /* CLK_CFG_3 */
330 MUX_GATE(CLK_TOP_MSDC30_0_SEL, msdc30_0_parents, 0x70, 0, 3, 7),
331 MUX_GATE(CLK_TOP_MSDC30_1_SEL, msdc30_0_parents, 0x70, 8, 3, 15),
332 MUX_GATE(CLK_TOP_A1SYS_HP_SEL, a1sys_hp_parents, 0x70, 16, 3, 23),
333 MUX_GATE(CLK_TOP_A2SYS_HP_SEL, a1sys_hp_parents, 0x70, 24, 3, 31),
334
335 /* CLK_CFG_4 */
336 MUX_GATE(CLK_TOP_INTDIR_SEL, intdir_parents, 0x80, 0, 2, 7),
337 MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, aud_intbus_parents, 0x80, 8, 2, 15),
338 MUX_GATE(CLK_TOP_PMICSPI_SEL, pmicspi_parents, 0x80, 16, 3, 23),
339 MUX_GATE(CLK_TOP_SCP_SEL, ddrphycfg_parents, 0x80, 24, 2, 31),
340
341 /* CLK_CFG_5 */
342 MUX_GATE(CLK_TOP_ATB_SEL, atb_parents, 0x90, 0, 2, 7),
343 MUX_GATE_FLAGS(CLK_TOP_HIF_SEL, eth_parents, 0x90, 8, 3, 15,
344 CLK_DOMAIN_SCPSYS),
345 MUX_GATE(CLK_TOP_AUDIO_SEL, audio_parents, 0x90, 16, 2, 23),
346 MUX_GATE(CLK_TOP_U2_SEL, usb20_parents, 0x90, 24, 2, 31),
347
348 /* CLK_CFG_6 */
349 MUX_GATE(CLK_TOP_AUD1_SEL, aud1_parents, 0xA0, 0, 1, 7),
350 MUX_GATE(CLK_TOP_AUD2_SEL, aud1_parents, 0xA0, 8, 1, 15),
351 MUX_GATE(CLK_TOP_IRRX_SEL, f10m_ref_parents, 0xA0, 16, 1, 23),
352 MUX_GATE(CLK_TOP_IRTX_SEL, f10m_ref_parents, 0xA0, 24, 1, 31),
353
354 /* CLK_CFG_7 */
355 MUX_GATE(CLK_TOP_ASM_L_SEL, asm_l_parents, 0xB0, 0, 2, 7),
356 MUX_GATE(CLK_TOP_ASM_M_SEL, asm_l_parents, 0xB0, 8, 2, 15),
357 MUX_GATE(CLK_TOP_ASM_H_SEL, asm_l_parents, 0xB0, 16, 2, 23),
358
359 /* CLK_AUDDIV_0 */
360 MUX(CLK_TOP_APLL1_SEL, apll1_ck_parents, 0x120, 6, 1),
361 MUX(CLK_TOP_APLL2_SEL, apll1_ck_parents, 0x120, 7, 1),
362 MUX(CLK_TOP_I2S0_MCK_SEL, apll1_ck_parents, 0x120, 8, 1),
363 MUX(CLK_TOP_I2S1_MCK_SEL, apll1_ck_parents, 0x120, 9, 1),
364 MUX(CLK_TOP_I2S2_MCK_SEL, apll1_ck_parents, 0x120, 10, 1),
365 MUX(CLK_TOP_I2S3_MCK_SEL, apll1_ck_parents, 0x120, 161, 1),
366};
367
368/* infracfg */
369static const struct mtk_gate_regs infra_cg_regs = {
370 .set_ofs = 0x40,
371 .clr_ofs = 0x44,
372 .sta_ofs = 0x48,
373};
374
375#define GATE_INFRA(_id, _parent, _shift) { \
376 .id = _id, \
377 .parent = _parent, \
378 .regs = &infra_cg_regs, \
379 .shift = _shift, \
380 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
381 }
382
383static const struct mtk_gate infra_cgs[] = {
384 GATE_INFRA(CLK_INFRA_DBGCLK_PD, CLK_TOP_AXI_SEL, 0),
385 GATE_INFRA(CLK_INFRA_TRNG, CLK_TOP_AXI_SEL, 2),
386 GATE_INFRA(CLK_INFRA_AUDIO_PD, CLK_TOP_AUD_INTBUS_SEL, 5),
387 GATE_INFRA(CLK_INFRA_IRRX_PD, CLK_TOP_IRRX_SEL, 16),
388 GATE_INFRA(CLK_INFRA_APXGPT_PD, CLK_TOP_F10M_REF_SEL, 18),
389 GATE_INFRA(CLK_INFRA_PMIC_PD, CLK_TOP_PMICSPI_SEL, 22),
390};
391
392/* pericfg */
393static const struct mtk_gate_regs peri0_cg_regs = {
394 .set_ofs = 0x8,
395 .clr_ofs = 0x10,
396 .sta_ofs = 0x18,
397};
398
399static const struct mtk_gate_regs peri1_cg_regs = {
400 .set_ofs = 0xC,
401 .clr_ofs = 0x14,
402 .sta_ofs = 0x1C,
403};
404
405#define GATE_PERI0(_id, _parent, _shift) { \
406 .id = _id, \
407 .parent = _parent, \
408 .regs = &peri0_cg_regs, \
409 .shift = _shift, \
410 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
411 }
412
413#define GATE_PERI1(_id, _parent, _shift) { \
414 .id = _id, \
415 .parent = _parent, \
416 .regs = &peri1_cg_regs, \
417 .shift = _shift, \
418 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
419 }
420
421static const struct mtk_gate peri_cgs[] = {
422 /* PERI0 */
423 GATE_PERI0(CLK_PERI_THERM_PD, CLK_TOP_AXI_SEL, 1),
424 GATE_PERI0(CLK_PERI_PWM1_PD, CLK_XTAL, 2),
425 GATE_PERI0(CLK_PERI_PWM2_PD, CLK_XTAL, 3),
426 GATE_PERI0(CLK_PERI_PWM3_PD, CLK_XTAL, 4),
427 GATE_PERI0(CLK_PERI_PWM4_PD, CLK_XTAL, 5),
428 GATE_PERI0(CLK_PERI_PWM5_PD, CLK_XTAL, 6),
429 GATE_PERI0(CLK_PERI_PWM6_PD, CLK_XTAL, 7),
430 GATE_PERI0(CLK_PERI_PWM7_PD, CLK_XTAL, 8),
431 GATE_PERI0(CLK_PERI_PWM_PD, CLK_XTAL, 9),
432 GATE_PERI0(CLK_PERI_AP_DMA_PD, CLK_TOP_AXI_SEL, 12),
433 GATE_PERI0(CLK_PERI_MSDC30_0_PD, CLK_TOP_MSDC30_0_SEL, 13),
434 GATE_PERI0(CLK_PERI_MSDC30_1_PD, CLK_TOP_MSDC30_1_SEL, 14),
435 GATE_PERI0(CLK_PERI_UART0_PD, CLK_TOP_AXI_SEL, 17),
436 GATE_PERI0(CLK_PERI_UART1_PD, CLK_TOP_AXI_SEL, 18),
437 GATE_PERI0(CLK_PERI_UART2_PD, CLK_TOP_AXI_SEL, 19),
438 GATE_PERI0(CLK_PERI_UART3_PD, CLK_TOP_AXI_SEL, 20),
439 GATE_PERI0(CLK_PERI_BTIF_PD, CLK_TOP_AXI_SEL, 22),
440 GATE_PERI0(CLK_PERI_I2C0_PD, CLK_TOP_AXI_SEL, 23),
441 GATE_PERI0(CLK_PERI_I2C1_PD, CLK_TOP_AXI_SEL, 24),
442 GATE_PERI0(CLK_PERI_I2C2_PD, CLK_TOP_AXI_SEL, 25),
443 GATE_PERI0(CLK_PERI_SPI1_PD, CLK_TOP_SPI1_SEL, 26),
444 GATE_PERI0(CLK_PERI_AUXADC_PD, CLK_XTAL, 27),
445 GATE_PERI0(CLK_PERI_SPI0_PD, CLK_TOP_SPI0_SEL, 28),
446 GATE_PERI0(CLK_PERI_SNFI_PD, CLK_TOP_NFI_INFRA_SEL, 29),
447 GATE_PERI0(CLK_PERI_NFI_PD, CLK_TOP_AXI_SEL, 30),
448 GATE_PERI1(CLK_PERI_NFIECC_PD, CLK_TOP_AXI_SEL, 31),
449
450 /* PERI1 */
451 GATE_PERI1(CLK_PERI_FLASH_PD, CLK_TOP_FLASH_SEL, 1),
452 GATE_PERI1(CLK_PERI_IRTX_PD, CLK_TOP_IRTX_SEL, 2),
453};
454
455/* ethsys */
456static const struct mtk_gate_regs eth_cg_regs = {
457 .sta_ofs = 0x30,
458};
459
460#define GATE_ETH(_id, _parent, _shift) { \
461 .id = _id, \
462 .parent = _parent, \
463 .regs = &eth_cg_regs, \
464 .shift = _shift, \
465 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
466 }
467
468static const struct mtk_gate eth_cgs[] = {
469 GATE_ETH(CLK_ETH_HSDMA_EN, CLK_TOP_ETH_SEL, 5),
470 GATE_ETH(CLK_ETH_ESW_EN, CLK_TOP_ETH_500M, 6),
471 GATE_ETH(CLK_ETH_GP2_EN, CLK_TOP_TXCLK_SRC_PRE, 7),
472 GATE_ETH(CLK_ETH_GP1_EN, CLK_TOP_TXCLK_SRC_PRE, 8),
473 GATE_ETH(CLK_ETH_GP0_EN, CLK_TOP_TXCLK_SRC_PRE, 9),
474};
475
476static const struct mtk_gate_regs sgmii_cg_regs = {
477 .sta_ofs = 0xE4,
478};
479
480#define GATE_SGMII(_id, _parent, _shift) { \
481 .id = _id, \
482 .parent = _parent, \
483 .regs = &sgmii_cg_regs, \
484 .shift = _shift, \
485 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
486}
487
488static const struct mtk_gate sgmii_cgs[] = {
489 GATE_SGMII(CLK_SGMII_TX250M_EN, CLK_TOP_SSUSB_TX250M, 2),
490 GATE_SGMII(CLK_SGMII_RX250M_EN, CLK_TOP_SSUSB_EQ_RX250M, 3),
491 GATE_SGMII(CLK_SGMII_CDR_REF, CLK_TOP_SSUSB_CDR_REF, 4),
492 GATE_SGMII(CLK_SGMII_CDR_FB, CLK_TOP_SSUSB_CDR_FB, 5),
493};
494
495static const struct mtk_clk_tree mt7622_clk_tree = {
496 .xtal_rate = 25 * MHZ,
497 .xtal2_rate = 25 * MHZ,
498 .fdivs_offs = CLK_TOP_TO_USB3_SYS,
499 .muxes_offs = CLK_TOP_AXI_SEL,
500 .plls = apmixed_plls,
501 .fclks = top_fixed_clks,
502 .fdivs = top_fixed_divs,
503 .muxes = top_muxes,
504};
505
506static int mt7622_mcucfg_probe(struct udevice *dev)
507{
508 void __iomem *base;
509
510 base = dev_read_addr_ptr(dev);
511 if (!base)
512 return -ENOENT;
513
514 clrsetbits_le32(base + MCU_AXI_DIV, AXI_DIV_MSK,
515 AXI_DIV_SEL(0x12));
516 clrsetbits_le32(base + MCU_BUS_MUX, MCU_BUS_MSK,
517 MCU_BUS_SEL(0x1));
518
519 return 0;
520}
521
522static int mt7622_apmixedsys_probe(struct udevice *dev)
523{
524 struct mtk_clk_priv *priv = dev_get_priv(dev);
525 int ret;
526
527 ret = mtk_common_clk_init(dev, &mt7622_clk_tree);
528 if (ret)
529 return ret;
530
531 /* reduce clock square disable time */
532 // writel(0x501, priv->base + MT7622_CLKSQ_STB_CON0);
533 writel(0x98940501, priv->base + MT7622_CLKSQ_STB_CON0);
534
535 /* extend pwr/iso control timing to 1us */
536 writel(0x80008, priv->base + MT7622_PLL_ISO_CON0);
537
538 return 0;
539}
540
541static int mt7622_topckgen_probe(struct udevice *dev)
542{
543 return mtk_common_clk_init(dev, &mt7622_clk_tree);
544}
545
546static int mt7622_infracfg_probe(struct udevice *dev)
547{
548 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, infra_cgs);
549}
550
551static int mt7622_pericfg_probe(struct udevice *dev)
552{
553 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, peri_cgs);
554}
555
556static int mt7622_ethsys_probe(struct udevice *dev)
557{
558 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, eth_cgs);
559}
560
561static int mt7622_ethsys_bind(struct udevice *dev)
562{
563 int ret = 0;
564
565#if CONFIG_IS_ENABLED(RESET_MEDIATEK)
566 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
567 if (ret)
568 debug("Warning: failed to bind reset controller\n");
569#endif
570
571 return ret;
572}
573
574static int mt7622_sgmiisys_probe(struct udevice *dev)
575{
576 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, sgmii_cgs);
577}
578
579static const struct udevice_id mt7622_apmixed_compat[] = {
580 { .compatible = "mediatek,mt7622-apmixedsys" },
581 { }
582};
583
584static const struct udevice_id mt7622_topckgen_compat[] = {
585 { .compatible = "mediatek,mt7622-topckgen" },
586 { }
587};
588
589static const struct udevice_id mt7622_infracfg_compat[] = {
590 { .compatible = "mediatek,mt7622-infracfg", },
591 { }
592};
593
594static const struct udevice_id mt7622_pericfg_compat[] = {
595 { .compatible = "mediatek,mt7622-pericfg", },
596 { }
597};
598
599static const struct udevice_id mt7622_ethsys_compat[] = {
600 { .compatible = "mediatek,mt7622-ethsys", },
601 { }
602};
603
604static const struct udevice_id mt7622_sgmiisys_compat[] = {
605 { .compatible = "mediatek,mt7622-sgmiisys", },
606 { }
607};
608
609static const struct udevice_id mt7622_mcucfg_compat[] = {
610 { .compatible = "mediatek,mt7622-mcucfg" },
611 { }
612};
613
614U_BOOT_DRIVER(mtk_mcucfg) = {
615 .name = "mt7622-mcucfg",
616 .id = UCLASS_SYSCON,
617 .of_match = mt7622_mcucfg_compat,
618 .probe = mt7622_mcucfg_probe,
619 .flags = DM_FLAG_PRE_RELOC,
620};
621
622U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
623 .name = "mt7622-clock-apmixedsys",
624 .id = UCLASS_CLK,
625 .of_match = mt7622_apmixed_compat,
626 .probe = mt7622_apmixedsys_probe,
627 .priv_auto_alloc_size = sizeof(struct mtk_clk_priv),
628 .ops = &mtk_clk_apmixedsys_ops,
629 .flags = DM_FLAG_PRE_RELOC,
630};
631
632U_BOOT_DRIVER(mtk_clk_topckgen) = {
633 .name = "mt7622-clock-topckgen",
634 .id = UCLASS_CLK,
635 .of_match = mt7622_topckgen_compat,
636 .probe = mt7622_topckgen_probe,
637 .priv_auto_alloc_size = sizeof(struct mtk_clk_priv),
638 .ops = &mtk_clk_topckgen_ops,
639 .flags = DM_FLAG_PRE_RELOC,
640};
641
642U_BOOT_DRIVER(mtk_clk_infracfg) = {
643 .name = "mt7622-clock-infracfg",
644 .id = UCLASS_CLK,
645 .of_match = mt7622_infracfg_compat,
646 .probe = mt7622_infracfg_probe,
647 .priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
648 .ops = &mtk_clk_gate_ops,
649 .flags = DM_FLAG_PRE_RELOC,
650};
651
652U_BOOT_DRIVER(mtk_clk_pericfg) = {
653 .name = "mt7622-clock-pericfg",
654 .id = UCLASS_CLK,
655 .of_match = mt7622_pericfg_compat,
656 .probe = mt7622_pericfg_probe,
657 .priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
658 .ops = &mtk_clk_gate_ops,
659 .flags = DM_FLAG_PRE_RELOC,
660};
661
662U_BOOT_DRIVER(mtk_clk_ethsys) = {
663 .name = "mt7622-clock-ethsys",
664 .id = UCLASS_CLK,
665 .of_match = mt7622_ethsys_compat,
666 .probe = mt7622_ethsys_probe,
667 .bind = mt7622_ethsys_bind,
668 .priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
669 .ops = &mtk_clk_gate_ops,
670};
671
672U_BOOT_DRIVER(mtk_clk_sgmiisys) = {
673 .name = "mt7622-clock-sgmiisys",
674 .id = UCLASS_CLK,
675 .of_match = mt7622_sgmiisys_compat,
676 .probe = mt7622_sgmiisys_probe,
677 .priv_auto_alloc_size = sizeof(struct mtk_cg_priv),
678 .ops = &mtk_clk_gate_ops,
679};