blob: 79936f1803d3c92ce8f05916b89fb8d14bc0af4f [file] [log] [blame]
Ryder Leec7466512018-11-15 10:07:55 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7623 SoC
4 *
5 * Copyright (C) 2018 MediaTek Inc.
6 * Author: Ryder Lee <ryder.lee@mediatek.com>
7 */
8
Ryder Leec7466512018-11-15 10:07:55 +08009#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Weijie Gao2dca3cc2018-12-20 16:12:52 +080011#include <asm/arch-mediatek/reset.h>
Ryder Leec7466512018-11-15 10:07:55 +080012#include <asm/io.h>
13#include <dt-bindings/clock/mt7623-clk.h>
Simon Glasscd93d622020-05-10 11:40:13 -060014#include <linux/bitops.h>
Ryder Leec7466512018-11-15 10:07:55 +080015
16#include "clk-mtk.h"
17
18#define MT7623_CLKSQ_STB_CON0 0x18
19#define MT7623_PLL_ISO_CON0 0x24
20#define MT7623_PLL_FMAX (2000UL * MHZ)
21#define MT7623_CON0_RST_BAR BIT(27)
22
23#define MCU_AXI_DIV 0x60
24#define AXI_DIV_MSK GENMASK(4, 0)
25#define AXI_DIV_SEL(x) (x)
26
27/* apmixedsys */
28#define PLL(_id, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
29 _pd_shift, _pcw_reg, _pcw_shift) { \
30 .id = _id, \
31 .reg = _reg, \
32 .pwr_reg = _pwr_reg, \
33 .en_mask = _en_mask, \
34 .rst_bar_mask = MT7623_CON0_RST_BAR, \
35 .fmax = MT7623_PLL_FMAX, \
36 .flags = _flags, \
37 .pcwbits = _pcwbits, \
38 .pd_reg = _pd_reg, \
39 .pd_shift = _pd_shift, \
40 .pcw_reg = _pcw_reg, \
41 .pcw_shift = _pcw_shift, \
42 }
43
44static const struct mtk_pll_data apmixed_plls[] = {
45 PLL(CLK_APMIXED_ARMPLL, 0x200, 0x20c, 0x80000001, 0,
46 21, 0x204, 24, 0x204, 0),
47 PLL(CLK_APMIXED_MAINPLL, 0x210, 0x21c, 0xf0000001, HAVE_RST_BAR,
48 21, 0x210, 4, 0x214, 0),
49 PLL(CLK_APMIXED_UNIVPLL, 0x220, 0x22c, 0xf3000001, HAVE_RST_BAR,
50 7, 0x220, 4, 0x224, 14),
51 PLL(CLK_APMIXED_MMPLL, 0x230, 0x23c, 0x00000001, 0,
52 21, 0x230, 4, 0x234, 0),
53 PLL(CLK_APMIXED_MSDCPLL, 0x240, 0x24c, 0x00000001, 0,
54 21, 0x240, 4, 0x244, 0),
55 PLL(CLK_APMIXED_TVDPLL, 0x250, 0x25c, 0x00000001, 0,
56 21, 0x250, 4, 0x254, 0),
57 PLL(CLK_APMIXED_AUD1PLL, 0x270, 0x27c, 0x00000001, 0,
58 31, 0x270, 4, 0x274, 0),
59 PLL(CLK_APMIXED_TRGPLL, 0x280, 0x28c, 0x00000001, 0,
60 31, 0x280, 4, 0x284, 0),
61 PLL(CLK_APMIXED_ETHPLL, 0x290, 0x29c, 0x00000001, 0,
62 31, 0x290, 4, 0x294, 0),
63 PLL(CLK_APMIXED_VDECPLL, 0x2a0, 0x2ac, 0x00000001, 0,
64 31, 0x2a0, 4, 0x2a4, 0),
65 PLL(CLK_APMIXED_HADDS2PLL, 0x2b0, 0x2bc, 0x00000001, 0,
66 31, 0x2b0, 4, 0x2b4, 0),
67 PLL(CLK_APMIXED_AUD2PLL, 0x2c0, 0x2cc, 0x00000001, 0,
68 31, 0x2c0, 4, 0x2c4, 0),
69 PLL(CLK_APMIXED_TVD2PLL, 0x2d0, 0x2dc, 0x00000001, 0,
70 21, 0x2d0, 4, 0x2d4, 0),
71};
72
73/* topckgen */
74#define FACTOR0(_id, _parent, _mult, _div) \
75 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
76
77#define FACTOR1(_id, _parent, _mult, _div) \
78 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
79
80#define FACTOR2(_id, _parent, _mult, _div) \
81 FACTOR(_id, _parent, _mult, _div, 0)
82
83static const struct mtk_fixed_clk top_fixed_clks[] = {
84 FIXED_CLK(CLK_TOP_DPI, CLK_XTAL, 108 * MHZ),
85 FIXED_CLK(CLK_TOP_DMPLL, CLK_XTAL, 400 * MHZ),
86 FIXED_CLK(CLK_TOP_VENCPLL, CLK_XTAL, 295.75 * MHZ),
87 FIXED_CLK(CLK_TOP_HDMI_0_PIX340M, CLK_XTAL, 340 * MHZ),
88 FIXED_CLK(CLK_TOP_HDMI_0_DEEP340M, CLK_XTAL, 340 * MHZ),
89 FIXED_CLK(CLK_TOP_HDMI_0_PLL340M, CLK_XTAL, 340 * MHZ),
90 FIXED_CLK(CLK_TOP_HADDS2_FB, CLK_XTAL, 27 * MHZ),
91 FIXED_CLK(CLK_TOP_WBG_DIG_416M, CLK_XTAL, 416 * MHZ),
92 FIXED_CLK(CLK_TOP_DSI0_LNTC_DSI, CLK_XTAL, 143 * MHZ),
93 FIXED_CLK(CLK_TOP_HDMI_SCL_RX, CLK_XTAL, 27 * MHZ),
94 FIXED_CLK(CLK_TOP_32K_EXTERNAL, CLK_XTAL, 32000),
95 FIXED_CLK(CLK_TOP_HDMITX_CLKDIG_CTS, CLK_XTAL, 300 * MHZ),
96 FIXED_CLK(CLK_TOP_AUD_EXT1, CLK_XTAL, 0),
97 FIXED_CLK(CLK_TOP_AUD_EXT2, CLK_XTAL, 0),
98 FIXED_CLK(CLK_TOP_NFI1X_PAD, CLK_XTAL, 0),
99};
100
101static const struct mtk_fixed_factor top_fixed_divs[] = {
102 FACTOR0(CLK_TOP_SYSPLL, CLK_APMIXED_MAINPLL, 1, 1),
103 FACTOR0(CLK_TOP_SYSPLL_D2, CLK_APMIXED_MAINPLL, 1, 2),
104 FACTOR0(CLK_TOP_SYSPLL_D3, CLK_APMIXED_MAINPLL, 1, 3),
105 FACTOR0(CLK_TOP_SYSPLL_D5, CLK_APMIXED_MAINPLL, 1, 5),
106 FACTOR0(CLK_TOP_SYSPLL_D7, CLK_APMIXED_MAINPLL, 1, 7),
107 FACTOR1(CLK_TOP_SYSPLL1_D2, CLK_TOP_SYSPLL_D2, 1, 2),
108 FACTOR1(CLK_TOP_SYSPLL1_D4, CLK_TOP_SYSPLL_D2, 1, 4),
109 FACTOR1(CLK_TOP_SYSPLL1_D8, CLK_TOP_SYSPLL_D2, 1, 8),
110 FACTOR1(CLK_TOP_SYSPLL1_D16, CLK_TOP_SYSPLL_D2, 1, 16),
111 FACTOR1(CLK_TOP_SYSPLL2_D2, CLK_TOP_SYSPLL_D3, 1, 2),
112 FACTOR1(CLK_TOP_SYSPLL2_D4, CLK_TOP_SYSPLL_D3, 1, 4),
113 FACTOR1(CLK_TOP_SYSPLL2_D8, CLK_TOP_SYSPLL_D3, 1, 8),
114 FACTOR1(CLK_TOP_SYSPLL3_D2, CLK_TOP_SYSPLL_D5, 1, 2),
115 FACTOR1(CLK_TOP_SYSPLL3_D4, CLK_TOP_SYSPLL_D5, 1, 4),
116 FACTOR1(CLK_TOP_SYSPLL4_D2, CLK_TOP_SYSPLL_D7, 1, 2),
117 FACTOR1(CLK_TOP_SYSPLL4_D4, CLK_TOP_SYSPLL_D7, 1, 4),
118
119 FACTOR0(CLK_TOP_UNIVPLL, CLK_APMIXED_UNIVPLL, 1, 1),
120 FACTOR0(CLK_TOP_UNIVPLL_D2, CLK_APMIXED_UNIVPLL, 1, 2),
121 FACTOR0(CLK_TOP_UNIVPLL_D3, CLK_APMIXED_UNIVPLL, 1, 3),
122 FACTOR0(CLK_TOP_UNIVPLL_D5, CLK_APMIXED_UNIVPLL, 1, 5),
123 FACTOR0(CLK_TOP_UNIVPLL_D7, CLK_APMIXED_UNIVPLL, 1, 7),
124 FACTOR0(CLK_TOP_UNIVPLL_D26, CLK_APMIXED_UNIVPLL, 1, 26),
125 FACTOR0(CLK_TOP_UNIVPLL_D52, CLK_APMIXED_UNIVPLL, 1, 52),
126 FACTOR0(CLK_TOP_UNIVPLL_D108, CLK_APMIXED_UNIVPLL, 1, 108),
127 FACTOR0(CLK_TOP_USB_PHY48M, CLK_APMIXED_UNIVPLL, 1, 26),
128 FACTOR1(CLK_TOP_UNIVPLL1_D2, CLK_TOP_UNIVPLL_D2, 1, 2),
129 FACTOR1(CLK_TOP_UNIVPLL1_D4, CLK_TOP_UNIVPLL_D2, 1, 4),
130 FACTOR1(CLK_TOP_UNIVPLL1_D8, CLK_TOP_UNIVPLL_D2, 1, 8),
131 FACTOR1(CLK_TOP_UNIVPLL2_D2, CLK_TOP_UNIVPLL_D3, 1, 2),
132 FACTOR1(CLK_TOP_UNIVPLL2_D4, CLK_TOP_UNIVPLL_D3, 1, 4),
133 FACTOR1(CLK_TOP_UNIVPLL2_D8, CLK_TOP_UNIVPLL_D3, 1, 8),
134 FACTOR1(CLK_TOP_UNIVPLL2_D16, CLK_TOP_UNIVPLL_D3, 1, 16),
135 FACTOR1(CLK_TOP_UNIVPLL2_D32, CLK_TOP_UNIVPLL_D3, 1, 32),
136 FACTOR1(CLK_TOP_UNIVPLL3_D2, CLK_TOP_UNIVPLL_D5, 1, 2),
137 FACTOR1(CLK_TOP_UNIVPLL3_D4, CLK_TOP_UNIVPLL_D5, 1, 4),
138 FACTOR1(CLK_TOP_UNIVPLL3_D8, CLK_TOP_UNIVPLL_D5, 1, 8),
139
140 FACTOR0(CLK_TOP_MSDCPLL, CLK_APMIXED_MSDCPLL, 1, 1),
141 FACTOR0(CLK_TOP_MSDCPLL_D2, CLK_APMIXED_MSDCPLL, 1, 2),
142 FACTOR0(CLK_TOP_MSDCPLL_D4, CLK_APMIXED_MSDCPLL, 1, 4),
143 FACTOR0(CLK_TOP_MSDCPLL_D8, CLK_APMIXED_MSDCPLL, 1, 8),
144
145 FACTOR0(CLK_TOP_MMPLL, CLK_APMIXED_MMPLL, 1, 1),
146 FACTOR0(CLK_TOP_MMPLL_D2, CLK_APMIXED_MMPLL, 1, 2),
147
148 FACTOR1(CLK_TOP_DMPLL_D2, CLK_TOP_DMPLL, 1, 2),
149 FACTOR1(CLK_TOP_DMPLL_D4, CLK_TOP_DMPLL, 1, 4),
150 FACTOR1(CLK_TOP_DMPLL_X2, CLK_TOP_DMPLL, 1, 1),
151
152 FACTOR0(CLK_TOP_TVDPLL, CLK_APMIXED_TVDPLL, 1, 1),
153 FACTOR0(CLK_TOP_TVDPLL_D2, CLK_APMIXED_TVDPLL, 1, 2),
154 FACTOR0(CLK_TOP_TVDPLL_D4, CLK_APMIXED_TVDPLL, 1, 4),
155
156 FACTOR0(CLK_TOP_VDECPLL, CLK_APMIXED_VDECPLL, 1, 1),
157 FACTOR0(CLK_TOP_TVD2PLL, CLK_APMIXED_TVD2PLL, 1, 1),
158 FACTOR0(CLK_TOP_TVD2PLL_D2, CLK_APMIXED_TVD2PLL, 1, 2),
159
160 FACTOR1(CLK_TOP_MIPIPLL, CLK_TOP_DPI, 1, 1),
161 FACTOR1(CLK_TOP_MIPIPLL_D2, CLK_TOP_DPI, 1, 2),
162 FACTOR1(CLK_TOP_MIPIPLL_D4, CLK_TOP_DPI, 1, 4),
163
164 FACTOR1(CLK_TOP_HDMIPLL, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 1),
165 FACTOR1(CLK_TOP_HDMIPLL_D2, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 2),
166 FACTOR1(CLK_TOP_HDMIPLL_D3, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 3),
167
168 FACTOR0(CLK_TOP_ARMPLL_1P3G, CLK_APMIXED_ARMPLL, 1, 1),
169
170 FACTOR1(CLK_TOP_AUDPLL, CLK_TOP_AUDPLL_MUX_SEL, 1, 1),
171 FACTOR1(CLK_TOP_AUDPLL_D4, CLK_TOP_AUDPLL_MUX_SEL, 1, 4),
172 FACTOR1(CLK_TOP_AUDPLL_D8, CLK_TOP_AUDPLL_MUX_SEL, 1, 8),
173 FACTOR1(CLK_TOP_AUDPLL_D16, CLK_TOP_AUDPLL_MUX_SEL, 1, 16),
174 FACTOR1(CLK_TOP_AUDPLL_D24, CLK_TOP_AUDPLL_MUX_SEL, 1, 24),
175
176 FACTOR0(CLK_TOP_AUD1PLL_98M, CLK_APMIXED_AUD1PLL, 1, 3),
177 FACTOR0(CLK_TOP_AUD2PLL_90M, CLK_APMIXED_AUD2PLL, 1, 3),
178 FACTOR0(CLK_TOP_HADDS2PLL_98M, CLK_APMIXED_HADDS2PLL, 1, 3),
179 FACTOR0(CLK_TOP_HADDS2PLL_294M, CLK_APMIXED_HADDS2PLL, 1, 1),
180 FACTOR0(CLK_TOP_ETHPLL_500M, CLK_APMIXED_ETHPLL, 1, 1),
181 FACTOR2(CLK_TOP_CLK26M_D8, CLK_XTAL, 1, 8),
182 FACTOR2(CLK_TOP_32K_INTERNAL, CLK_XTAL, 1, 793),
183 FACTOR1(CLK_TOP_AXISEL_D4, CLK_TOP_AXI_SEL, 1, 4),
184 FACTOR1(CLK_TOP_8BDAC, CLK_TOP_UNIVPLL_D2, 1, 1),
185};
186
187static const int axi_parents[] = {
188 CLK_XTAL,
189 CLK_TOP_SYSPLL1_D2,
190 CLK_TOP_SYSPLL_D5,
191 CLK_TOP_SYSPLL1_D4,
192 CLK_TOP_UNIVPLL_D5,
193 CLK_TOP_UNIVPLL2_D2,
194 CLK_TOP_MMPLL_D2,
195 CLK_TOP_DMPLL_D2
196};
197
198static const int mem_parents[] = {
199 CLK_XTAL,
200 CLK_TOP_DMPLL
201};
202
203static const int ddrphycfg_parents[] = {
204 CLK_XTAL,
205 CLK_TOP_SYSPLL1_D8
206};
207
208static const int mm_parents[] = {
209 CLK_XTAL,
210 CLK_TOP_VENCPLL,
211 CLK_TOP_SYSPLL1_D2,
212 CLK_TOP_SYSPLL1_D4,
213 CLK_TOP_UNIVPLL_D5,
214 CLK_TOP_UNIVPLL1_D2,
215 CLK_TOP_UNIVPLL2_D2,
216 CLK_TOP_DMPLL
217};
218
219static const int pwm_parents[] = {
220 CLK_XTAL,
221 CLK_TOP_UNIVPLL2_D4,
222 CLK_TOP_UNIVPLL3_D2,
223 CLK_TOP_UNIVPLL1_D4
224};
225
226static const int vdec_parents[] = {
227 CLK_XTAL,
228 CLK_TOP_VDECPLL,
229 CLK_TOP_SYSPLL_D5,
230 CLK_TOP_SYSPLL1_D4,
231 CLK_TOP_UNIVPLL_D5,
232 CLK_TOP_UNIVPLL2_D2,
233 CLK_TOP_VENCPLL,
234 CLK_TOP_MSDCPLL_D2,
235 CLK_TOP_MMPLL_D2
236};
237
238static const int mfg_parents[] = {
239 CLK_XTAL,
240 CLK_TOP_MMPLL,
241 CLK_TOP_DMPLL_X2,
242 CLK_TOP_MSDCPLL,
243 CLK_XTAL,
244 CLK_TOP_SYSPLL_D3,
245 CLK_TOP_UNIVPLL_D3,
246 CLK_TOP_UNIVPLL1_D2
247};
248
249static const int camtg_parents[] = {
250 CLK_XTAL,
251 CLK_TOP_UNIVPLL_D26,
252 CLK_TOP_UNIVPLL2_D2,
253 CLK_TOP_SYSPLL3_D2,
254 CLK_TOP_SYSPLL3_D4,
255 CLK_TOP_MSDCPLL_D2,
256 CLK_TOP_MMPLL_D2
257};
258
259static const int uart_parents[] = {
260 CLK_XTAL,
261 CLK_TOP_UNIVPLL2_D8
262};
263
264static const int spi_parents[] = {
265 CLK_XTAL,
266 CLK_TOP_SYSPLL3_D2,
267 CLK_TOP_SYSPLL4_D2,
268 CLK_TOP_UNIVPLL2_D4,
269 CLK_TOP_UNIVPLL1_D8
270};
271
272static const int usb20_parents[] = {
273 CLK_XTAL,
274 CLK_TOP_UNIVPLL1_D8,
275 CLK_TOP_UNIVPLL3_D4
276};
277
278static const int msdc30_parents[] = {
279 CLK_XTAL,
280 CLK_TOP_MSDCPLL_D2,
281 CLK_TOP_SYSPLL2_D2,
282 CLK_TOP_SYSPLL1_D4,
283 CLK_TOP_UNIVPLL1_D4,
284 CLK_TOP_UNIVPLL2_D4,
285};
286
287static const int aud_intbus_parents[] = {
288 CLK_XTAL,
289 CLK_TOP_SYSPLL1_D4,
290 CLK_TOP_SYSPLL3_D2,
291 CLK_TOP_SYSPLL4_D2,
292 CLK_TOP_UNIVPLL3_D2,
293 CLK_TOP_UNIVPLL2_D4
294};
295
296static const int pmicspi_parents[] = {
297 CLK_XTAL,
298 CLK_TOP_SYSPLL1_D8,
299 CLK_TOP_SYSPLL2_D4,
300 CLK_TOP_SYSPLL4_D2,
301 CLK_TOP_SYSPLL3_D4,
302 CLK_TOP_SYSPLL2_D8,
303 CLK_TOP_SYSPLL1_D16,
304 CLK_TOP_UNIVPLL3_D4,
305 CLK_TOP_UNIVPLL_D26,
306 CLK_TOP_DMPLL_D2,
307 CLK_TOP_DMPLL_D4
308};
309
310static const int scp_parents[] = {
311 CLK_XTAL,
312 CLK_TOP_SYSPLL1_D8,
313 CLK_TOP_DMPLL_D2,
314 CLK_TOP_DMPLL_D4
315};
316
317static const int dpi0_tve_parents[] = {
318 CLK_XTAL,
319 CLK_TOP_MIPIPLL,
320 CLK_TOP_MIPIPLL_D2,
321 CLK_TOP_MIPIPLL_D4,
322 CLK_XTAL,
323 CLK_TOP_TVDPLL,
324 CLK_TOP_TVDPLL_D2,
325 CLK_TOP_TVDPLL_D4
326};
327
328static const int dpi1_parents[] = {
329 CLK_XTAL,
330 CLK_TOP_TVDPLL,
331 CLK_TOP_TVDPLL_D2,
332 CLK_TOP_TVDPLL_D4
333};
334
335static const int hdmi_parents[] = {
336 CLK_XTAL,
337 CLK_TOP_HDMIPLL,
338 CLK_TOP_HDMIPLL_D2,
339 CLK_TOP_HDMIPLL_D3
340};
341
342static const int apll_parents[] = {
343 CLK_XTAL,
344 CLK_TOP_AUDPLL,
345 CLK_TOP_AUDPLL_D4,
346 CLK_TOP_AUDPLL_D8,
347 CLK_TOP_AUDPLL_D16,
348 CLK_TOP_AUDPLL_D24,
349 CLK_XTAL,
350 CLK_XTAL
351};
352
353static const int rtc_parents[] = {
354 CLK_TOP_32K_INTERNAL,
355 CLK_TOP_32K_EXTERNAL,
356 CLK_XTAL,
357 CLK_TOP_UNIVPLL3_D8
358};
359
360static const int nfi2x_parents[] = {
361 CLK_XTAL,
362 CLK_TOP_SYSPLL2_D2,
363 CLK_TOP_SYSPLL_D7,
364 CLK_TOP_UNIVPLL3_D2,
365 CLK_TOP_SYSPLL2_D4,
366 CLK_TOP_UNIVPLL3_D4,
367 CLK_TOP_SYSPLL4_D4,
368 CLK_XTAL
369};
370
371static const int emmc_hclk_parents[] = {
372 CLK_XTAL,
373 CLK_TOP_SYSPLL1_D2,
374 CLK_TOP_SYSPLL1_D4,
375 CLK_TOP_SYSPLL2_D2
376};
377
378static const int flash_parents[] = {
379 CLK_TOP_CLK26M_D8,
380 CLK_XTAL,
381 CLK_TOP_SYSPLL2_D8,
382 CLK_TOP_SYSPLL3_D4,
383 CLK_TOP_UNIVPLL3_D4,
384 CLK_TOP_SYSPLL4_D2,
385 CLK_TOP_SYSPLL2_D4,
386 CLK_TOP_UNIVPLL2_D4
387};
388
389static const int di_parents[] = {
390 CLK_XTAL,
391 CLK_TOP_TVD2PLL,
392 CLK_TOP_TVD2PLL_D2,
393 CLK_XTAL
394};
395
396static const int nr_osd_parents[] = {
397 CLK_XTAL,
398 CLK_TOP_VENCPLL,
399 CLK_TOP_SYSPLL1_D2,
400 CLK_TOP_SYSPLL1_D4,
401 CLK_TOP_UNIVPLL_D5,
402 CLK_TOP_UNIVPLL1_D2,
403 CLK_TOP_UNIVPLL2_D2,
404 CLK_TOP_DMPLL
405};
406
407static const int hdmirx_bist_parents[] = {
408 CLK_XTAL,
409 CLK_TOP_SYSPLL_D3,
410 CLK_XTAL,
411 CLK_TOP_SYSPLL1_D16,
412 CLK_TOP_SYSPLL4_D2,
413 CLK_TOP_SYSPLL1_D4,
414 CLK_TOP_VENCPLL,
415 CLK_XTAL
416};
417
418static const int intdir_parents[] = {
419 CLK_XTAL,
420 CLK_TOP_MMPLL,
421 CLK_TOP_SYSPLL_D2,
422 CLK_TOP_UNIVPLL_D2
423};
424
425static const int asm_parents[] = {
426 CLK_XTAL,
427 CLK_TOP_UNIVPLL2_D4,
428 CLK_TOP_UNIVPLL2_D2,
429 CLK_TOP_SYSPLL_D5
430};
431
432static const int ms_card_parents[] = {
433 CLK_XTAL,
434 CLK_TOP_UNIVPLL3_D8,
435 CLK_TOP_SYSPLL4_D4
436};
437
438static const int ethif_parents[] = {
439 CLK_XTAL,
440 CLK_TOP_SYSPLL1_D2,
441 CLK_TOP_SYSPLL_D5,
442 CLK_TOP_SYSPLL1_D4,
443 CLK_TOP_UNIVPLL_D5,
444 CLK_TOP_UNIVPLL1_D2,
445 CLK_TOP_DMPLL,
446 CLK_TOP_DMPLL_D2
447};
448
449static const int hdmirx_parents[] = {
450 CLK_XTAL,
451 CLK_TOP_UNIVPLL_D52
452};
453
454static const int cmsys_parents[] = {
455 CLK_XTAL,
456 CLK_TOP_SYSPLL1_D2,
457 CLK_TOP_UNIVPLL1_D2,
458 CLK_TOP_UNIVPLL_D5,
459 CLK_TOP_SYSPLL_D5,
460 CLK_TOP_SYSPLL2_D2,
461 CLK_TOP_SYSPLL1_D4,
462 CLK_TOP_SYSPLL3_D2,
463 CLK_TOP_SYSPLL2_D4,
464 CLK_TOP_SYSPLL1_D8,
465 CLK_XTAL,
466 CLK_XTAL,
467 CLK_XTAL,
468 CLK_XTAL,
469 CLK_XTAL
470};
471
472static const int clk_8bdac_parents[] = {
473 CLK_TOP_32K_INTERNAL,
474 CLK_TOP_8BDAC,
475 CLK_XTAL,
476 CLK_XTAL
477};
478
479static const int aud2dvd_parents[] = {
480 CLK_TOP_AUD_48K_TIMING,
481 CLK_TOP_AUD_44K_TIMING
482};
483
484static const int padmclk_parents[] = {
485 CLK_XTAL,
486 CLK_TOP_UNIVPLL_D26,
487 CLK_TOP_UNIVPLL_D52,
488 CLK_TOP_UNIVPLL_D108,
489 CLK_TOP_UNIVPLL2_D8,
490 CLK_TOP_UNIVPLL2_D16,
491 CLK_TOP_UNIVPLL2_D32
492};
493
494static const int aud_mux_parents[] = {
495 CLK_XTAL,
496 CLK_TOP_AUD1PLL_98M,
497 CLK_TOP_AUD2PLL_90M,
498 CLK_TOP_HADDS2PLL_98M,
499 CLK_TOP_AUD_EXTCK1_DIV,
500 CLK_TOP_AUD_EXTCK2_DIV
501};
502
503static const int aud_src_parents[] = {
504 CLK_TOP_AUD_MUX1_SEL,
505 CLK_TOP_AUD_MUX2_SEL
506};
507
508static const struct mtk_composite top_muxes[] = {
509 MUX_GATE(CLK_TOP_AXI_SEL, axi_parents, 0x40, 0, 3, 7),
510 MUX_GATE(CLK_TOP_MEM_SEL, mem_parents, 0x40, 8, 1, 15),
511 MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, ddrphycfg_parents, 0x40, 16, 1, 23),
512 MUX_GATE_FLAGS(CLK_TOP_MM_SEL, mm_parents, 0x40, 24, 3, 31,
513 CLK_DOMAIN_SCPSYS),
514
515 MUX_GATE(CLK_TOP_PWM_SEL, pwm_parents, 0x50, 0, 2, 7),
516 MUX_GATE(CLK_TOP_VDEC_SEL, vdec_parents, 0x50, 8, 4, 15),
517 MUX_GATE_FLAGS(CLK_TOP_MFG_SEL, mfg_parents, 0x50, 16, 3, 23,
518 CLK_DOMAIN_SCPSYS),
519 MUX_GATE(CLK_TOP_CAMTG_SEL, camtg_parents, 0x50, 24, 3, 31),
520
521 MUX_GATE(CLK_TOP_UART_SEL, uart_parents, 0x60, 0, 1, 7),
522 MUX_GATE(CLK_TOP_SPI0_SEL, spi_parents, 0x60, 8, 3, 15),
523 MUX_GATE(CLK_TOP_USB20_SEL, usb20_parents, 0x60, 16, 2, 23),
524 MUX_GATE(CLK_TOP_MSDC30_0_SEL, msdc30_parents, 0x60, 24, 3, 31),
525
526 MUX_GATE(CLK_TOP_MSDC30_1_SEL, msdc30_parents, 0x70, 0, 3, 7),
527 MUX_GATE(CLK_TOP_MSDC30_2_SEL, msdc30_parents, 0x70, 8, 3, 15),
528 MUX_GATE(CLK_TOP_AUDIO_SEL, msdc30_parents, 0x70, 16, 1, 23),
529 MUX_GATE(CLK_TOP_AUDINTBUS_SEL, aud_intbus_parents, 0x70, 24, 3, 31),
530
531 MUX_GATE(CLK_TOP_PMICSPI_SEL, pmicspi_parents, 0x80, 0, 4, 7),
532 MUX_GATE(CLK_TOP_SCP_SEL, scp_parents, 0x80, 8, 2, 15),
533 MUX_GATE(CLK_TOP_DPI0_SEL, dpi0_tve_parents, 0x80, 16, 3, 23),
534 MUX_GATE(CLK_TOP_DPI1_SEL, dpi1_parents, 0x80, 24, 2, 31),
535
536 MUX_GATE(CLK_TOP_TVE_SEL, dpi0_tve_parents, 0x90, 0, 3, 7),
537 MUX_GATE(CLK_TOP_HDMI_SEL, hdmi_parents, 0x90, 8, 2, 15),
538 MUX_GATE(CLK_TOP_APLL_SEL, apll_parents, 0x90, 16, 3, 23),
539
540 MUX_GATE(CLK_TOP_RTC_SEL, rtc_parents, 0xA0, 0, 2, 7),
541 MUX_GATE(CLK_TOP_NFI2X_SEL, nfi2x_parents, 0xA0, 8, 3, 15),
542 MUX_GATE(CLK_TOP_EMMC_HCLK_SEL, emmc_hclk_parents, 0xA0, 24, 2, 31),
543
544 MUX_GATE(CLK_TOP_FLASH_SEL, flash_parents, 0xB0, 0, 3, 7),
545 MUX_GATE(CLK_TOP_DI_SEL, di_parents, 0xB0, 8, 2, 15),
546 MUX_GATE(CLK_TOP_NR_SEL, nr_osd_parents, 0xB0, 16, 3, 23),
547 MUX_GATE(CLK_TOP_OSD_SEL, nr_osd_parents, 0xB0, 24, 3, 31),
548
549 MUX_GATE(CLK_TOP_HDMIRX_BIST_SEL, hdmirx_bist_parents, 0xC0, 0, 3, 7),
550 MUX_GATE(CLK_TOP_INTDIR_SEL, intdir_parents, 0xC0, 8, 2, 15),
551 MUX_GATE(CLK_TOP_ASM_I_SEL, asm_parents, 0xC0, 16, 2, 23),
552 MUX_GATE(CLK_TOP_ASM_M_SEL, asm_parents, 0xC0, 24, 3, 31),
553
554 MUX_GATE(CLK_TOP_ASM_H_SEL, asm_parents, 0xD0, 0, 2, 7),
555 MUX_GATE(CLK_TOP_MS_CARD_SEL, ms_card_parents, 0xD0, 16, 2, 23),
556 MUX_GATE_FLAGS(CLK_TOP_ETHIF_SEL, ethif_parents, 0xD0, 24, 3, 31,
557 CLK_DOMAIN_SCPSYS),
558
559 MUX_GATE(CLK_TOP_HDMIRX26_24_SEL, hdmirx_parents, 0xE0, 0, 1, 7),
560 MUX_GATE(CLK_TOP_MSDC30_3_SEL, msdc30_parents, 0xE0, 8, 3, 15),
561 MUX_GATE(CLK_TOP_CMSYS_SEL, cmsys_parents, 0xE0, 16, 4, 23),
562
563 MUX_GATE(CLK_TOP_SPI1_SEL, spi_parents, 0xE0, 24, 3, 31),
564 MUX_GATE(CLK_TOP_SPI2_SEL, spi_parents, 0xF0, 0, 3, 7),
565 MUX_GATE(CLK_TOP_8BDAC_SEL, clk_8bdac_parents, 0xF0, 8, 2, 15),
566 MUX_GATE(CLK_TOP_AUD2DVD_SEL, aud2dvd_parents, 0xF0, 16, 1, 23),
567
568 MUX(CLK_TOP_PADMCLK_SEL, padmclk_parents, 0x100, 0, 3),
569
570 MUX(CLK_TOP_AUD_MUX1_SEL, aud_mux_parents, 0x12c, 0, 3),
571 MUX(CLK_TOP_AUD_MUX2_SEL, aud_mux_parents, 0x12c, 3, 3),
572 MUX(CLK_TOP_AUDPLL_MUX_SEL, aud_mux_parents, 0x12c, 6, 3),
573
574 MUX_GATE(CLK_TOP_AUD_K1_SRC_SEL, aud_src_parents, 0x12c, 15, 1, 23),
575 MUX_GATE(CLK_TOP_AUD_K2_SRC_SEL, aud_src_parents, 0x12c, 16, 1, 24),
576 MUX_GATE(CLK_TOP_AUD_K3_SRC_SEL, aud_src_parents, 0x12c, 17, 1, 25),
577 MUX_GATE(CLK_TOP_AUD_K4_SRC_SEL, aud_src_parents, 0x12c, 18, 1, 26),
578 MUX_GATE(CLK_TOP_AUD_K5_SRC_SEL, aud_src_parents, 0x12c, 19, 1, 27),
579 MUX_GATE(CLK_TOP_AUD_K6_SRC_SEL, aud_src_parents, 0x12c, 20, 1, 28),
580};
581
582/* infracfg */
583static const struct mtk_gate_regs infra_cg_regs = {
584 .set_ofs = 0x40,
585 .clr_ofs = 0x44,
586 .sta_ofs = 0x48,
587};
588
Christian Marangic721d5a2024-08-02 15:45:01 +0200589#define GATE_INFRA_FLAGS(_id, _parent, _shift, _flags) { \
Ryder Leec7466512018-11-15 10:07:55 +0800590 .id = _id, \
591 .parent = _parent, \
592 .regs = &infra_cg_regs, \
593 .shift = _shift, \
Christian Marangic721d5a2024-08-02 15:45:01 +0200594 .flags = _flags, \
Ryder Leec7466512018-11-15 10:07:55 +0800595 }
Christian Marangic721d5a2024-08-02 15:45:01 +0200596#define GATE_INFRA(_id, _parent, _shift) \
597 GATE_INFRA_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
598#define GATE_INFRA_XTAL(_id, _parent, _shift) \
599 GATE_INFRA_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
600
Ryder Leec7466512018-11-15 10:07:55 +0800601
602static const struct mtk_gate infra_cgs[] = {
603 GATE_INFRA(CLK_INFRA_DBG, CLK_TOP_AXI_SEL, 0),
604 GATE_INFRA(CLK_INFRA_SMI, CLK_TOP_MM_SEL, 1),
605 GATE_INFRA(CLK_INFRA_QAXI_CM4, CLK_TOP_AXI_SEL, 2),
606 GATE_INFRA(CLK_INFRA_AUD_SPLIN_B, CLK_TOP_HADDS2PLL_294M, 4),
Christian Marangic721d5a2024-08-02 15:45:01 +0200607 GATE_INFRA_XTAL(CLK_INFRA_AUDIO, CLK_XTAL, 5),
608 GATE_INFRA_XTAL(CLK_INFRA_EFUSE, CLK_XTAL, 6),
Ryder Leec7466512018-11-15 10:07:55 +0800609 GATE_INFRA(CLK_INFRA_L2C_SRAM, CLK_TOP_MM_SEL, 7),
610 GATE_INFRA(CLK_INFRA_M4U, CLK_TOP_MEM_SEL, 8),
611 GATE_INFRA(CLK_INFRA_CONNMCU, CLK_TOP_WBG_DIG_416M, 12),
612 GATE_INFRA(CLK_INFRA_TRNG, CLK_TOP_AXI_SEL, 13),
613 GATE_INFRA(CLK_INFRA_RAMBUFIF, CLK_TOP_MEM_SEL, 14),
614 GATE_INFRA(CLK_INFRA_CPUM, CLK_TOP_MEM_SEL, 15),
615 GATE_INFRA(CLK_INFRA_KP, CLK_TOP_AXI_SEL, 16),
616 GATE_INFRA(CLK_INFRA_CEC, CLK_TOP_RTC_SEL, 18),
617 GATE_INFRA(CLK_INFRA_IRRX, CLK_TOP_AXI_SEL, 19),
618 GATE_INFRA(CLK_INFRA_PMICSPI, CLK_TOP_PMICSPI_SEL, 22),
619 GATE_INFRA(CLK_INFRA_PMICWRAP, CLK_TOP_AXI_SEL, 23),
620 GATE_INFRA(CLK_INFRA_DDCCI, CLK_TOP_AXI_SEL, 24),
621};
622
623/* pericfg */
624static const struct mtk_gate_regs peri0_cg_regs = {
625 .set_ofs = 0x8,
626 .clr_ofs = 0x10,
627 .sta_ofs = 0x18,
628};
629
630static const struct mtk_gate_regs peri1_cg_regs = {
631 .set_ofs = 0xC,
632 .clr_ofs = 0x14,
633 .sta_ofs = 0x1C,
634};
635
Christian Marangic721d5a2024-08-02 15:45:01 +0200636#define GATE_PERI0_FLAGS(_id, _parent, _shift, _flags) { \
Ryder Leec7466512018-11-15 10:07:55 +0800637 .id = _id, \
638 .parent = _parent, \
639 .regs = &peri0_cg_regs, \
640 .shift = _shift, \
Christian Marangic721d5a2024-08-02 15:45:01 +0200641 .flags = _flags, \
Ryder Leec7466512018-11-15 10:07:55 +0800642 }
Christian Marangic721d5a2024-08-02 15:45:01 +0200643#define GATE_PERI0(_id, _parent, _shift) \
644 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
645#define GATE_PERI0_XTAL(_id, _parent, _shift) \
646 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
Ryder Leec7466512018-11-15 10:07:55 +0800647
648#define GATE_PERI1(_id, _parent, _shift) { \
649 .id = _id, \
650 .parent = _parent, \
651 .regs = &peri1_cg_regs, \
652 .shift = _shift, \
653 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
654 }
655
656static const struct mtk_gate peri_cgs[] = {
657 GATE_PERI0(CLK_PERI_NFI, CLK_TOP_NFI2X_SEL, 0),
658 GATE_PERI0(CLK_PERI_THERM, CLK_TOP_AXI_SEL, 1),
659 GATE_PERI0(CLK_PERI_PWM1, CLK_TOP_AXISEL_D4, 2),
660 GATE_PERI0(CLK_PERI_PWM2, CLK_TOP_AXISEL_D4, 3),
661 GATE_PERI0(CLK_PERI_PWM3, CLK_TOP_AXISEL_D4, 4),
662 GATE_PERI0(CLK_PERI_PWM4, CLK_TOP_AXISEL_D4, 5),
663 GATE_PERI0(CLK_PERI_PWM5, CLK_TOP_AXISEL_D4, 6),
664 GATE_PERI0(CLK_PERI_PWM6, CLK_TOP_AXISEL_D4, 7),
665 GATE_PERI0(CLK_PERI_PWM7, CLK_TOP_AXISEL_D4, 8),
666 GATE_PERI0(CLK_PERI_PWM, CLK_TOP_AXI_SEL, 9),
667 GATE_PERI0(CLK_PERI_USB0, CLK_TOP_USB20_SEL, 10),
668 GATE_PERI0(CLK_PERI_USB1, CLK_TOP_USB20_SEL, 11),
669 GATE_PERI0(CLK_PERI_AP_DMA, CLK_TOP_AXI_SEL, 12),
670 GATE_PERI0(CLK_PERI_MSDC30_0, CLK_TOP_MSDC30_0_SEL, 13),
671 GATE_PERI0(CLK_PERI_MSDC30_1, CLK_TOP_MSDC30_1_SEL, 14),
672 GATE_PERI0(CLK_PERI_MSDC30_2, CLK_TOP_MSDC30_2_SEL, 15),
673 GATE_PERI0(CLK_PERI_MSDC30_3, CLK_TOP_MSDC30_3_SEL, 16),
674 GATE_PERI0(CLK_PERI_MSDC50_3, CLK_TOP_EMMC_HCLK_SEL, 17),
675 GATE_PERI0(CLK_PERI_NLI, CLK_TOP_AXI_SEL, 18),
676 GATE_PERI0(CLK_PERI_UART0, CLK_TOP_AXI_SEL, 19),
677 GATE_PERI0(CLK_PERI_UART1, CLK_TOP_AXI_SEL, 20),
678 GATE_PERI0(CLK_PERI_UART2, CLK_TOP_AXI_SEL, 21),
679 GATE_PERI0(CLK_PERI_UART3, CLK_TOP_AXI_SEL, 22),
680 GATE_PERI0(CLK_PERI_BTIF, CLK_TOP_AXI_SEL, 23),
681 GATE_PERI0(CLK_PERI_I2C0, CLK_TOP_AXI_SEL, 24),
682 GATE_PERI0(CLK_PERI_I2C1, CLK_TOP_AXI_SEL, 25),
683 GATE_PERI0(CLK_PERI_I2C2, CLK_TOP_AXI_SEL, 26),
Christian Marangic721d5a2024-08-02 15:45:01 +0200684 GATE_PERI0_XTAL(CLK_PERI_I2C3, CLK_XTAL, 27),
685 GATE_PERI0_XTAL(CLK_PERI_AUXADC, CLK_XTAL, 28),
Ryder Leec7466512018-11-15 10:07:55 +0800686 GATE_PERI0(CLK_PERI_SPI0, CLK_TOP_SPI0_SEL, 29),
Christian Marangic721d5a2024-08-02 15:45:01 +0200687 GATE_PERI0_XTAL(CLK_PERI_ETH, CLK_XTAL, 30),
Ryder Leec7466512018-11-15 10:07:55 +0800688 GATE_PERI0(CLK_PERI_USB0_MCU, CLK_TOP_AXI_SEL, 31),
689
690 GATE_PERI1(CLK_PERI_USB1_MCU, CLK_TOP_AXI_SEL, 0),
691 GATE_PERI1(CLK_PERI_USB_SLV, CLK_TOP_AXI_SEL, 1),
692 GATE_PERI1(CLK_PERI_GCPU, CLK_TOP_AXI_SEL, 2),
693 GATE_PERI1(CLK_PERI_NFI_ECC, CLK_TOP_NFI1X_PAD, 3),
694 GATE_PERI1(CLK_PERI_NFI_PAD, CLK_TOP_NFI1X_PAD, 4),
695 GATE_PERI1(CLK_PERI_FLASH, CLK_TOP_NFI2X_SEL, 5),
696 GATE_PERI1(CLK_PERI_HOST89_INT, CLK_TOP_AXI_SEL, 6),
697 GATE_PERI1(CLK_PERI_HOST89_SPI, CLK_TOP_SPI0_SEL, 7),
698 GATE_PERI1(CLK_PERI_HOST89_DVD, CLK_TOP_AUD2DVD_SEL, 8),
699 GATE_PERI1(CLK_PERI_SPI1, CLK_TOP_SPI1_SEL, 9),
700 GATE_PERI1(CLK_PERI_SPI2, CLK_TOP_SPI2_SEL, 10),
701 GATE_PERI1(CLK_PERI_FCI, CLK_TOP_MS_CARD_SEL, 11),
702};
703
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800704/* ethsys and hifsys */
705static const struct mtk_gate_regs eth_hif_cg_regs = {
Ryder Leec7466512018-11-15 10:07:55 +0800706 .sta_ofs = 0x30,
707};
708
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800709#define GATE_ETH_HIF(_id, _parent, _shift, _flag) { \
Ryder Leec7466512018-11-15 10:07:55 +0800710 .id = _id, \
711 .parent = _parent, \
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800712 .regs = &eth_hif_cg_regs, \
Ryder Leec7466512018-11-15 10:07:55 +0800713 .shift = _shift, \
714 .flags = CLK_GATE_NO_SETCLR_INV | (_flag), \
715 }
716
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800717#define GATE_ETH_HIF0(_id, _parent, _shift) \
718 GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_APMIXED)
Ryder Leec7466512018-11-15 10:07:55 +0800719
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800720#define GATE_ETH_HIF1(_id, _parent, _shift) \
721 GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_TOPCKGEN)
Ryder Leec7466512018-11-15 10:07:55 +0800722
723static const struct mtk_gate eth_cgs[] = {
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800724 GATE_ETH_HIF1(CLK_ETHSYS_HSDMA, CLK_TOP_ETHIF_SEL, 5),
725 GATE_ETH_HIF1(CLK_ETHSYS_ESW, CLK_TOP_ETHPLL_500M, 6),
726 GATE_ETH_HIF0(CLK_ETHSYS_GP2, CLK_APMIXED_TRGPLL, 7),
727 GATE_ETH_HIF1(CLK_ETHSYS_GP1, CLK_TOP_ETHPLL_500M, 8),
728 GATE_ETH_HIF1(CLK_ETHSYS_PCM, CLK_TOP_ETHIF_SEL, 11),
729 GATE_ETH_HIF1(CLK_ETHSYS_GDMA, CLK_TOP_ETHIF_SEL, 14),
730 GATE_ETH_HIF1(CLK_ETHSYS_I2S, CLK_TOP_ETHIF_SEL, 17),
731 GATE_ETH_HIF1(CLK_ETHSYS_CRYPTO, CLK_TOP_ETHIF_SEL, 29),
732};
733
734static const struct mtk_gate hif_cgs[] = {
735 GATE_ETH_HIF1(CLK_HIFSYS_USB0PHY, CLK_TOP_ETHPLL_500M, 21),
736 GATE_ETH_HIF1(CLK_HIFSYS_USB1PHY, CLK_TOP_ETHPLL_500M, 22),
737 GATE_ETH_HIF1(CLK_HIFSYS_PCIE0, CLK_TOP_ETHPLL_500M, 24),
738 GATE_ETH_HIF1(CLK_HIFSYS_PCIE1, CLK_TOP_ETHPLL_500M, 25),
739 GATE_ETH_HIF1(CLK_HIFSYS_PCIE2, CLK_TOP_ETHPLL_500M, 26),
Ryder Leec7466512018-11-15 10:07:55 +0800740};
741
Christian Marangiefd35fa2024-08-02 15:45:02 +0200742static const struct mtk_clk_tree mt7623_apmixedsys_clk_tree = {
Ryder Leec7466512018-11-15 10:07:55 +0800743 .xtal2_rate = 26 * MHZ,
Christian Marangiefd35fa2024-08-02 15:45:02 +0200744 .plls = apmixed_plls,
745};
746
747static const struct mtk_clk_tree mt7623_topckgen_clk_tree = {
748 .xtal_rate = 26 * MHZ,
Ryder Leec7466512018-11-15 10:07:55 +0800749 .fdivs_offs = CLK_TOP_SYSPLL,
750 .muxes_offs = CLK_TOP_AXI_SEL,
Ryder Leec7466512018-11-15 10:07:55 +0800751 .fclks = top_fixed_clks,
752 .fdivs = top_fixed_divs,
753 .muxes = top_muxes,
754};
755
756static int mt7623_mcucfg_probe(struct udevice *dev)
757{
758 void __iomem *base;
759
760 base = dev_read_addr_ptr(dev);
761 if (!base)
762 return -ENOENT;
763
764 clrsetbits_le32(base + MCU_AXI_DIV, AXI_DIV_MSK,
765 AXI_DIV_SEL(0x12));
766
767 return 0;
768}
769
770static int mt7623_apmixedsys_probe(struct udevice *dev)
771{
772 struct mtk_clk_priv *priv = dev_get_priv(dev);
773 int ret;
774
Christian Marangiefd35fa2024-08-02 15:45:02 +0200775 ret = mtk_common_clk_init(dev, &mt7623_apmixedsys_clk_tree);
Ryder Leec7466512018-11-15 10:07:55 +0800776 if (ret)
777 return ret;
778
779 /* reduce clock square disable time */
780 writel(0x50001, priv->base + MT7623_CLKSQ_STB_CON0);
781 /* extend control timing to 1us */
782 writel(0x888, priv->base + MT7623_PLL_ISO_CON0);
783
784 return 0;
785}
786
787static int mt7623_topckgen_probe(struct udevice *dev)
788{
Christian Marangiefd35fa2024-08-02 15:45:02 +0200789 return mtk_common_clk_init(dev, &mt7623_topckgen_clk_tree);
Ryder Leec7466512018-11-15 10:07:55 +0800790}
791
792static int mt7623_infracfg_probe(struct udevice *dev)
793{
Christian Marangiefd35fa2024-08-02 15:45:02 +0200794 return mtk_common_clk_gate_init(dev, &mt7623_topckgen_clk_tree,
795 infra_cgs);
Ryder Leec7466512018-11-15 10:07:55 +0800796}
797
798static int mt7623_pericfg_probe(struct udevice *dev)
799{
Christian Marangiefd35fa2024-08-02 15:45:02 +0200800 return mtk_common_clk_gate_init(dev, &mt7623_topckgen_clk_tree,
801 peri_cgs);
Ryder Leec7466512018-11-15 10:07:55 +0800802}
803
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800804static int mt7623_hifsys_probe(struct udevice *dev)
805{
Christian Marangiefd35fa2024-08-02 15:45:02 +0200806 return mtk_common_clk_gate_init(dev, &mt7623_topckgen_clk_tree,
807 hif_cgs);
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800808}
809
Ryder Leec7466512018-11-15 10:07:55 +0800810static int mt7623_ethsys_probe(struct udevice *dev)
811{
Christian Marangiefd35fa2024-08-02 15:45:02 +0200812 return mtk_common_clk_gate_init(dev, &mt7623_topckgen_clk_tree,
813 eth_cgs);
Ryder Leec7466512018-11-15 10:07:55 +0800814}
815
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800816static int mt7623_ethsys_hifsys_bind(struct udevice *dev)
Weijie Gao2dca3cc2018-12-20 16:12:52 +0800817{
818 int ret = 0;
819
820#if CONFIG_IS_ENABLED(RESET_MEDIATEK)
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800821 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
Weijie Gao2dca3cc2018-12-20 16:12:52 +0800822 if (ret)
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800823 debug("Warning: failed to bind reset controller\n");
Weijie Gao2dca3cc2018-12-20 16:12:52 +0800824#endif
825
826 return ret;
827}
828
Ryder Leec7466512018-11-15 10:07:55 +0800829static const struct udevice_id mt7623_apmixed_compat[] = {
830 { .compatible = "mediatek,mt7623-apmixedsys" },
831 { }
832};
833
834static const struct udevice_id mt7623_topckgen_compat[] = {
835 { .compatible = "mediatek,mt7623-topckgen" },
836 { }
837};
838
839static const struct udevice_id mt7623_infracfg_compat[] = {
840 { .compatible = "mediatek,mt7623-infracfg", },
841 { }
842};
843
844static const struct udevice_id mt7623_pericfg_compat[] = {
845 { .compatible = "mediatek,mt7623-pericfg", },
846 { }
847};
848
849static const struct udevice_id mt7623_ethsys_compat[] = {
850 { .compatible = "mediatek,mt7623-ethsys" },
851 { }
852};
853
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800854static const struct udevice_id mt7623_hifsys_compat[] = {
855 { .compatible = "mediatek,mt7623-hifsys" },
856 { }
857};
858
Ryder Leec7466512018-11-15 10:07:55 +0800859static const struct udevice_id mt7623_mcucfg_compat[] = {
860 { .compatible = "mediatek,mt7623-mcucfg" },
861 { }
862};
863
864U_BOOT_DRIVER(mtk_mcucfg) = {
865 .name = "mt7623-mcucfg",
866 .id = UCLASS_SYSCON,
867 .of_match = mt7623_mcucfg_compat,
868 .probe = mt7623_mcucfg_probe,
869 .flags = DM_FLAG_PRE_RELOC,
870};
871
872U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
873 .name = "mt7623-clock-apmixedsys",
874 .id = UCLASS_CLK,
875 .of_match = mt7623_apmixed_compat,
876 .probe = mt7623_apmixedsys_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700877 .priv_auto = sizeof(struct mtk_clk_priv),
Ryder Leec7466512018-11-15 10:07:55 +0800878 .ops = &mtk_clk_apmixedsys_ops,
879 .flags = DM_FLAG_PRE_RELOC,
880};
881
882U_BOOT_DRIVER(mtk_clk_topckgen) = {
883 .name = "mt7623-clock-topckgen",
884 .id = UCLASS_CLK,
885 .of_match = mt7623_topckgen_compat,
886 .probe = mt7623_topckgen_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700887 .priv_auto = sizeof(struct mtk_clk_priv),
Ryder Leec7466512018-11-15 10:07:55 +0800888 .ops = &mtk_clk_topckgen_ops,
889 .flags = DM_FLAG_PRE_RELOC,
890};
891
892U_BOOT_DRIVER(mtk_clk_infracfg) = {
893 .name = "mt7623-infracfg",
894 .id = UCLASS_CLK,
895 .of_match = mt7623_infracfg_compat,
896 .probe = mt7623_infracfg_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700897 .priv_auto = sizeof(struct mtk_cg_priv),
Ryder Leec7466512018-11-15 10:07:55 +0800898 .ops = &mtk_clk_gate_ops,
899 .flags = DM_FLAG_PRE_RELOC,
900};
901
902U_BOOT_DRIVER(mtk_clk_pericfg) = {
903 .name = "mt7623-pericfg",
904 .id = UCLASS_CLK,
905 .of_match = mt7623_pericfg_compat,
906 .probe = mt7623_pericfg_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700907 .priv_auto = sizeof(struct mtk_cg_priv),
Ryder Leec7466512018-11-15 10:07:55 +0800908 .ops = &mtk_clk_gate_ops,
909 .flags = DM_FLAG_PRE_RELOC,
910};
911
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800912U_BOOT_DRIVER(mtk_clk_hifsys) = {
913 .name = "mt7623-clock-hifsys",
914 .id = UCLASS_CLK,
915 .of_match = mt7623_hifsys_compat,
916 .probe = mt7623_hifsys_probe,
917 .bind = mt7623_ethsys_hifsys_bind,
Simon Glass41575d82020-12-03 16:55:17 -0700918 .priv_auto = sizeof(struct mtk_cg_priv),
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800919 .ops = &mtk_clk_gate_ops,
920};
921
Ryder Leec7466512018-11-15 10:07:55 +0800922U_BOOT_DRIVER(mtk_clk_ethsys) = {
923 .name = "mt7623-clock-ethsys",
924 .id = UCLASS_CLK,
925 .of_match = mt7623_ethsys_compat,
926 .probe = mt7623_ethsys_probe,
Ryder Lee2d88b5a2019-07-29 22:17:48 +0800927 .bind = mt7623_ethsys_hifsys_bind,
Simon Glass41575d82020-12-03 16:55:17 -0700928 .priv_auto = sizeof(struct mtk_cg_priv),
Ryder Leec7466512018-11-15 10:07:55 +0800929 .ops = &mtk_clk_gate_ops,
930};