blob: 8f173b794533b13299b095ebcc08fab2dddbe590 [file] [log] [blame]
developerdea56512020-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
developerdea56512020-01-10 16:30:29 +08009#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
developerdea56512020-01-10 16:30:29 +080011#include <asm/arch-mediatek/reset.h>
12#include <asm/io.h>
13#include <dt-bindings/clock/mt7622-clk.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
developerdea56512020-01-10 16:30:29 +080015
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),
developerdea56512020-01-10 16:30:29 +0800385 GATE_INFRA(CLK_INFRA_AUDIO_PD, CLK_TOP_AUD_INTBUS_SEL, 5),
386 GATE_INFRA(CLK_INFRA_IRRX_PD, CLK_TOP_IRRX_SEL, 16),
387 GATE_INFRA(CLK_INFRA_APXGPT_PD, CLK_TOP_F10M_REF_SEL, 18),
388 GATE_INFRA(CLK_INFRA_PMIC_PD, CLK_TOP_PMICSPI_SEL, 22),
Christian Marangi614ae872024-08-03 10:43:21 +0200389 GATE_INFRA(CLK_INFRA_TRNG, CLK_TOP_AXI_SEL, 2),
developerdea56512020-01-10 16:30:29 +0800390};
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
Christian Marangi20cefbc2024-08-03 10:43:19 +0200405#define GATE_PERI0_FLAGS(_id, _parent, _shift, _flags) { \
developerdea56512020-01-10 16:30:29 +0800406 .id = _id, \
407 .parent = _parent, \
408 .regs = &peri0_cg_regs, \
409 .shift = _shift, \
Christian Marangi20cefbc2024-08-03 10:43:19 +0200410 .flags = _flags, \
developerdea56512020-01-10 16:30:29 +0800411 }
Christian Marangi20cefbc2024-08-03 10:43:19 +0200412#define GATE_PERI0(_id, _parent, _shift) \
413 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
414#define GATE_PERI0_XTAL(_id, _parent, _shift) \
415 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
developerdea56512020-01-10 16:30:29 +0800416
417#define GATE_PERI1(_id, _parent, _shift) { \
418 .id = _id, \
419 .parent = _parent, \
420 .regs = &peri1_cg_regs, \
421 .shift = _shift, \
422 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
423 }
424
425static const struct mtk_gate peri_cgs[] = {
426 /* PERI0 */
427 GATE_PERI0(CLK_PERI_THERM_PD, CLK_TOP_AXI_SEL, 1),
Christian Marangi20cefbc2024-08-03 10:43:19 +0200428 GATE_PERI0_XTAL(CLK_PERI_PWM1_PD, CLK_XTAL, 2),
429 GATE_PERI0_XTAL(CLK_PERI_PWM2_PD, CLK_XTAL, 3),
430 GATE_PERI0_XTAL(CLK_PERI_PWM3_PD, CLK_XTAL, 4),
431 GATE_PERI0_XTAL(CLK_PERI_PWM4_PD, CLK_XTAL, 5),
432 GATE_PERI0_XTAL(CLK_PERI_PWM5_PD, CLK_XTAL, 6),
433 GATE_PERI0_XTAL(CLK_PERI_PWM6_PD, CLK_XTAL, 7),
434 GATE_PERI0_XTAL(CLK_PERI_PWM7_PD, CLK_XTAL, 8),
435 GATE_PERI0_XTAL(CLK_PERI_PWM_PD, CLK_XTAL, 9),
developerdea56512020-01-10 16:30:29 +0800436 GATE_PERI0(CLK_PERI_AP_DMA_PD, CLK_TOP_AXI_SEL, 12),
437 GATE_PERI0(CLK_PERI_MSDC30_0_PD, CLK_TOP_MSDC30_0_SEL, 13),
438 GATE_PERI0(CLK_PERI_MSDC30_1_PD, CLK_TOP_MSDC30_1_SEL, 14),
439 GATE_PERI0(CLK_PERI_UART0_PD, CLK_TOP_AXI_SEL, 17),
440 GATE_PERI0(CLK_PERI_UART1_PD, CLK_TOP_AXI_SEL, 18),
441 GATE_PERI0(CLK_PERI_UART2_PD, CLK_TOP_AXI_SEL, 19),
442 GATE_PERI0(CLK_PERI_UART3_PD, CLK_TOP_AXI_SEL, 20),
443 GATE_PERI0(CLK_PERI_BTIF_PD, CLK_TOP_AXI_SEL, 22),
444 GATE_PERI0(CLK_PERI_I2C0_PD, CLK_TOP_AXI_SEL, 23),
445 GATE_PERI0(CLK_PERI_I2C1_PD, CLK_TOP_AXI_SEL, 24),
446 GATE_PERI0(CLK_PERI_I2C2_PD, CLK_TOP_AXI_SEL, 25),
447 GATE_PERI0(CLK_PERI_SPI1_PD, CLK_TOP_SPI1_SEL, 26),
Christian Marangi20cefbc2024-08-03 10:43:19 +0200448 GATE_PERI0_XTAL(CLK_PERI_AUXADC_PD, CLK_XTAL, 27),
developerdea56512020-01-10 16:30:29 +0800449 GATE_PERI0(CLK_PERI_SPI0_PD, CLK_TOP_SPI0_SEL, 28),
450 GATE_PERI0(CLK_PERI_SNFI_PD, CLK_TOP_NFI_INFRA_SEL, 29),
451 GATE_PERI0(CLK_PERI_NFI_PD, CLK_TOP_AXI_SEL, 30),
452 GATE_PERI1(CLK_PERI_NFIECC_PD, CLK_TOP_AXI_SEL, 31),
453
454 /* PERI1 */
455 GATE_PERI1(CLK_PERI_FLASH_PD, CLK_TOP_FLASH_SEL, 1),
456 GATE_PERI1(CLK_PERI_IRTX_PD, CLK_TOP_IRTX_SEL, 2),
457};
458
developer420e8bf2020-08-10 16:17:08 +0800459/* pciesys */
460static const struct mtk_gate_regs pcie_cg_regs = {
461 .set_ofs = 0x30,
462 .clr_ofs = 0x30,
463 .sta_ofs = 0x30,
464};
465
466#define GATE_PCIE(_id, _parent, _shift) { \
467 .id = _id, \
468 .parent = _parent, \
469 .regs = &pcie_cg_regs, \
470 .shift = _shift, \
471 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
472 }
473
474static const struct mtk_gate pcie_cgs[] = {
475 GATE_PCIE(CLK_PCIE_P1_AUX_EN, CLK_TOP_P1_1MHZ, 12),
476 GATE_PCIE(CLK_PCIE_P1_OBFF_EN, CLK_TOP_4MHZ, 13),
477 GATE_PCIE(CLK_PCIE_P1_AHB_EN, CLK_TOP_AXI_SEL, 14),
478 GATE_PCIE(CLK_PCIE_P1_AXI_EN, CLK_TOP_HIF_SEL, 15),
479 GATE_PCIE(CLK_PCIE_P1_MAC_EN, CLK_TOP_PCIE1_MAC_EN, 16),
480 GATE_PCIE(CLK_PCIE_P1_PIPE_EN, CLK_TOP_PCIE1_PIPE_EN, 17),
481 GATE_PCIE(CLK_PCIE_P0_AUX_EN, CLK_TOP_P0_1MHZ, 18),
482 GATE_PCIE(CLK_PCIE_P0_OBFF_EN, CLK_TOP_4MHZ, 19),
483 GATE_PCIE(CLK_PCIE_P0_AHB_EN, CLK_TOP_AXI_SEL, 20),
484 GATE_PCIE(CLK_PCIE_P0_AXI_EN, CLK_TOP_HIF_SEL, 21),
485 GATE_PCIE(CLK_PCIE_P0_MAC_EN, CLK_TOP_PCIE0_MAC_EN, 22),
486 GATE_PCIE(CLK_PCIE_P0_PIPE_EN, CLK_TOP_PCIE0_PIPE_EN, 23),
487 GATE_PCIE(CLK_SATA_AHB_EN, CLK_TOP_AXI_SEL, 26),
488 GATE_PCIE(CLK_SATA_AXI_EN, CLK_TOP_HIF_SEL, 27),
489 GATE_PCIE(CLK_SATA_ASIC_EN, CLK_TOP_SATA_ASIC, 28),
490 GATE_PCIE(CLK_SATA_RBC_EN, CLK_TOP_SATA_RBC, 29),
491 GATE_PCIE(CLK_SATA_PM_EN, CLK_TOP_UNIVPLL2_D4, 30),
492};
493
developerdea56512020-01-10 16:30:29 +0800494/* ethsys */
495static const struct mtk_gate_regs eth_cg_regs = {
496 .sta_ofs = 0x30,
497};
498
499#define GATE_ETH(_id, _parent, _shift) { \
500 .id = _id, \
501 .parent = _parent, \
502 .regs = &eth_cg_regs, \
503 .shift = _shift, \
504 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
505 }
506
507static const struct mtk_gate eth_cgs[] = {
508 GATE_ETH(CLK_ETH_HSDMA_EN, CLK_TOP_ETH_SEL, 5),
509 GATE_ETH(CLK_ETH_ESW_EN, CLK_TOP_ETH_500M, 6),
510 GATE_ETH(CLK_ETH_GP2_EN, CLK_TOP_TXCLK_SRC_PRE, 7),
511 GATE_ETH(CLK_ETH_GP1_EN, CLK_TOP_TXCLK_SRC_PRE, 8),
512 GATE_ETH(CLK_ETH_GP0_EN, CLK_TOP_TXCLK_SRC_PRE, 9),
513};
514
515static const struct mtk_gate_regs sgmii_cg_regs = {
516 .sta_ofs = 0xE4,
517};
518
519#define GATE_SGMII(_id, _parent, _shift) { \
520 .id = _id, \
521 .parent = _parent, \
522 .regs = &sgmii_cg_regs, \
523 .shift = _shift, \
524 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
525}
526
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200527static const struct mtk_gate_regs ssusb_cg_regs = {
528 .set_ofs = 0x30,
529 .clr_ofs = 0x30,
530 .sta_ofs = 0x30,
531};
532
533#define GATE_SSUSB(_id, _parent, _shift) { \
534 .id = _id, \
535 .parent = _parent, \
536 .regs = &ssusb_cg_regs, \
537 .shift = _shift, \
538 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
539}
540
developerdea56512020-01-10 16:30:29 +0800541static const struct mtk_gate sgmii_cgs[] = {
542 GATE_SGMII(CLK_SGMII_TX250M_EN, CLK_TOP_SSUSB_TX250M, 2),
543 GATE_SGMII(CLK_SGMII_RX250M_EN, CLK_TOP_SSUSB_EQ_RX250M, 3),
544 GATE_SGMII(CLK_SGMII_CDR_REF, CLK_TOP_SSUSB_CDR_REF, 4),
545 GATE_SGMII(CLK_SGMII_CDR_FB, CLK_TOP_SSUSB_CDR_FB, 5),
546};
547
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200548static const struct mtk_gate ssusb_cgs[] = {
549 GATE_SSUSB(CLK_SSUSB_U2_PHY_1P_EN, CLK_TOP_TO_U2_PHY_1P, 0),
550 GATE_SSUSB(CLK_SSUSB_U2_PHY_EN, CLK_TOP_TO_U2_PHY, 1),
551 GATE_SSUSB(CLK_SSUSB_REF_EN, CLK_TOP_TO_USB3_REF, 5),
552 GATE_SSUSB(CLK_SSUSB_SYS_EN, CLK_TOP_TO_USB3_SYS, 6),
553 GATE_SSUSB(CLK_SSUSB_MCU_EN, CLK_TOP_AXI_SEL, 7),
554 GATE_SSUSB(CLK_SSUSB_DMA_EN, CLK_TOP_HIF_SEL, 8),
555};
556
developerdea56512020-01-10 16:30:29 +0800557static const struct mtk_clk_tree mt7622_clk_tree = {
558 .xtal_rate = 25 * MHZ,
559 .xtal2_rate = 25 * MHZ,
560 .fdivs_offs = CLK_TOP_TO_USB3_SYS,
561 .muxes_offs = CLK_TOP_AXI_SEL,
562 .plls = apmixed_plls,
563 .fclks = top_fixed_clks,
564 .fdivs = top_fixed_divs,
565 .muxes = top_muxes,
566};
567
568static int mt7622_mcucfg_probe(struct udevice *dev)
569{
570 void __iomem *base;
571
572 base = dev_read_addr_ptr(dev);
573 if (!base)
574 return -ENOENT;
575
576 clrsetbits_le32(base + MCU_AXI_DIV, AXI_DIV_MSK,
577 AXI_DIV_SEL(0x12));
578 clrsetbits_le32(base + MCU_BUS_MUX, MCU_BUS_MSK,
579 MCU_BUS_SEL(0x1));
580
581 return 0;
582}
583
584static int mt7622_apmixedsys_probe(struct udevice *dev)
585{
586 struct mtk_clk_priv *priv = dev_get_priv(dev);
587 int ret;
588
589 ret = mtk_common_clk_init(dev, &mt7622_clk_tree);
590 if (ret)
591 return ret;
592
593 /* reduce clock square disable time */
594 // writel(0x501, priv->base + MT7622_CLKSQ_STB_CON0);
595 writel(0x98940501, priv->base + MT7622_CLKSQ_STB_CON0);
596
597 /* extend pwr/iso control timing to 1us */
598 writel(0x80008, priv->base + MT7622_PLL_ISO_CON0);
599
600 return 0;
601}
602
603static int mt7622_topckgen_probe(struct udevice *dev)
604{
605 return mtk_common_clk_init(dev, &mt7622_clk_tree);
606}
607
608static int mt7622_infracfg_probe(struct udevice *dev)
609{
610 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, infra_cgs);
611}
612
613static int mt7622_pericfg_probe(struct udevice *dev)
614{
615 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, peri_cgs);
616}
617
developer420e8bf2020-08-10 16:17:08 +0800618static int mt7622_pciesys_probe(struct udevice *dev)
619{
620 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, pcie_cgs);
621}
622
Frank Wunderlich8bdcb392020-08-13 10:20:46 +0200623static int mt7622_pciesys_bind(struct udevice *dev)
624{
625 int ret = 0;
626
627 if (IS_ENABLED(CONFIG_RESET_MEDIATEK)) {
Frank Wunderlich8bdcb392020-08-13 10:20:46 +0200628 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
629 if (ret)
630 debug("Warning: failed to bind reset controller\n");
631 }
632
633 return ret;
634}
635
developerdea56512020-01-10 16:30:29 +0800636static int mt7622_ethsys_probe(struct udevice *dev)
637{
638 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, eth_cgs);
639}
640
641static int mt7622_ethsys_bind(struct udevice *dev)
642{
643 int ret = 0;
644
645#if CONFIG_IS_ENABLED(RESET_MEDIATEK)
646 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
647 if (ret)
648 debug("Warning: failed to bind reset controller\n");
649#endif
650
651 return ret;
652}
653
654static int mt7622_sgmiisys_probe(struct udevice *dev)
655{
656 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, sgmii_cgs);
657}
658
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200659static int mt7622_ssusbsys_probe(struct udevice *dev)
660{
661 return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, ssusb_cgs);
662}
663
developerdea56512020-01-10 16:30:29 +0800664static const struct udevice_id mt7622_apmixed_compat[] = {
665 { .compatible = "mediatek,mt7622-apmixedsys" },
666 { }
667};
668
669static const struct udevice_id mt7622_topckgen_compat[] = {
670 { .compatible = "mediatek,mt7622-topckgen" },
671 { }
672};
673
674static const struct udevice_id mt7622_infracfg_compat[] = {
675 { .compatible = "mediatek,mt7622-infracfg", },
676 { }
677};
678
679static const struct udevice_id mt7622_pericfg_compat[] = {
680 { .compatible = "mediatek,mt7622-pericfg", },
681 { }
682};
683
developer420e8bf2020-08-10 16:17:08 +0800684static const struct udevice_id mt7622_pciesys_compat[] = {
685 { .compatible = "mediatek,mt7622-pciesys", },
686 { }
687};
688
developerdea56512020-01-10 16:30:29 +0800689static const struct udevice_id mt7622_ethsys_compat[] = {
690 { .compatible = "mediatek,mt7622-ethsys", },
691 { }
692};
693
694static const struct udevice_id mt7622_sgmiisys_compat[] = {
695 { .compatible = "mediatek,mt7622-sgmiisys", },
696 { }
697};
698
699static const struct udevice_id mt7622_mcucfg_compat[] = {
700 { .compatible = "mediatek,mt7622-mcucfg" },
701 { }
702};
703
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200704static const struct udevice_id mt7622_ssusbsys_compat[] = {
705 { .compatible = "mediatek,mt7622-ssusbsys" },
706 { }
707};
708
developerdea56512020-01-10 16:30:29 +0800709U_BOOT_DRIVER(mtk_mcucfg) = {
710 .name = "mt7622-mcucfg",
711 .id = UCLASS_SYSCON,
712 .of_match = mt7622_mcucfg_compat,
713 .probe = mt7622_mcucfg_probe,
714 .flags = DM_FLAG_PRE_RELOC,
715};
716
717U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
718 .name = "mt7622-clock-apmixedsys",
719 .id = UCLASS_CLK,
720 .of_match = mt7622_apmixed_compat,
721 .probe = mt7622_apmixedsys_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700722 .priv_auto = sizeof(struct mtk_clk_priv),
developerdea56512020-01-10 16:30:29 +0800723 .ops = &mtk_clk_apmixedsys_ops,
724 .flags = DM_FLAG_PRE_RELOC,
725};
726
727U_BOOT_DRIVER(mtk_clk_topckgen) = {
728 .name = "mt7622-clock-topckgen",
729 .id = UCLASS_CLK,
730 .of_match = mt7622_topckgen_compat,
731 .probe = mt7622_topckgen_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700732 .priv_auto = sizeof(struct mtk_clk_priv),
developerdea56512020-01-10 16:30:29 +0800733 .ops = &mtk_clk_topckgen_ops,
734 .flags = DM_FLAG_PRE_RELOC,
735};
736
737U_BOOT_DRIVER(mtk_clk_infracfg) = {
738 .name = "mt7622-clock-infracfg",
739 .id = UCLASS_CLK,
740 .of_match = mt7622_infracfg_compat,
741 .probe = mt7622_infracfg_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700742 .priv_auto = sizeof(struct mtk_cg_priv),
developerdea56512020-01-10 16:30:29 +0800743 .ops = &mtk_clk_gate_ops,
744 .flags = DM_FLAG_PRE_RELOC,
745};
746
747U_BOOT_DRIVER(mtk_clk_pericfg) = {
748 .name = "mt7622-clock-pericfg",
749 .id = UCLASS_CLK,
750 .of_match = mt7622_pericfg_compat,
751 .probe = mt7622_pericfg_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700752 .priv_auto = sizeof(struct mtk_cg_priv),
developerdea56512020-01-10 16:30:29 +0800753 .ops = &mtk_clk_gate_ops,
754 .flags = DM_FLAG_PRE_RELOC,
755};
756
developer420e8bf2020-08-10 16:17:08 +0800757U_BOOT_DRIVER(mtk_clk_pciesys) = {
758 .name = "mt7622-clock-pciesys",
759 .id = UCLASS_CLK,
760 .of_match = mt7622_pciesys_compat,
761 .probe = mt7622_pciesys_probe,
Frank Wunderlich8bdcb392020-08-13 10:20:46 +0200762 .bind = mt7622_pciesys_bind,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700763 .priv_auto = sizeof(struct mtk_cg_priv),
developer420e8bf2020-08-10 16:17:08 +0800764 .ops = &mtk_clk_gate_ops,
765};
766
developerdea56512020-01-10 16:30:29 +0800767U_BOOT_DRIVER(mtk_clk_ethsys) = {
768 .name = "mt7622-clock-ethsys",
769 .id = UCLASS_CLK,
770 .of_match = mt7622_ethsys_compat,
771 .probe = mt7622_ethsys_probe,
772 .bind = mt7622_ethsys_bind,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700773 .priv_auto = sizeof(struct mtk_cg_priv),
developerdea56512020-01-10 16:30:29 +0800774 .ops = &mtk_clk_gate_ops,
775};
776
777U_BOOT_DRIVER(mtk_clk_sgmiisys) = {
778 .name = "mt7622-clock-sgmiisys",
779 .id = UCLASS_CLK,
780 .of_match = mt7622_sgmiisys_compat,
781 .probe = mt7622_sgmiisys_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700782 .priv_auto = sizeof(struct mtk_cg_priv),
developerdea56512020-01-10 16:30:29 +0800783 .ops = &mtk_clk_gate_ops,
784};
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200785
786U_BOOT_DRIVER(mtk_clk_ssusbsys) = {
787 .name = "mt7622-clock-ssusbsys",
788 .id = UCLASS_CLK,
789 .of_match = mt7622_ssusbsys_compat,
790 .probe = mt7622_ssusbsys_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700791 .priv_auto = sizeof(struct mtk_cg_priv),
Frank Wunderliche51b57a2020-08-20 16:37:55 +0200792 .ops = &mtk_clk_gate_ops,
793};