blob: 61ccd4a210fec2aecaa7bf9fb68bc37337bd1485 [file] [log] [blame]
Julien Massone9e0fee2023-12-04 11:48:52 +01001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT8365 SoC
4 *
5 * Copyright (C) 2023 BayLibre, SAS
6 * Copyright (c) 2023 MediaTek Inc.
7 * Author: Julien Masson <jmasson@baylibre.com>
8 * Author: Fabien Parent <fparent@baylibre.com>
9 * Author: Weiyi Lu <weiyi.lu@mediatek.com>
10 */
11
12#include <dm.h>
13#include <dt-bindings/clock/mediatek,mt8365-clk.h>
14#include "clk-mtk.h"
15
16/* apmixedsys */
17#define MT8365_PLL_FMAX (3800UL * MHZ)
18#define MT8365_PLL_FMIN (1500UL * MHZ)
19#define CON0_MT8365_RST_BAR BIT(23)
20#define PLL_AO BIT(1)
21
22#define PLL(_id, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
23 _pd_shift, _pcw_reg, _pcw_shift, _rst_bar_mask, _pcw_chg_reg) { \
24 .id = _id, \
25 .reg = _reg, \
26 .pwr_reg = _pwr_reg, \
27 .en_mask = _en_mask, \
28 .pd_reg = _pd_reg, \
29 .pd_shift = _pd_shift, \
30 .flags = _flags, \
31 .rst_bar_mask = _rst_bar_mask, \
32 .fmax = MT8365_PLL_FMAX, \
33 .fmin = MT8365_PLL_FMIN, \
34 .pcwbits = _pcwbits, \
35 .pcwibits = 8, \
36 .pcw_reg = _pcw_reg, \
37 .pcw_shift = _pcw_shift, \
38 .pcw_chg_reg = _pcw_chg_reg, \
39 }
40
41static const struct mtk_pll_data apmixed_plls[] = {
42 PLL(CLK_APMIXED_ARMPLL, 0x030C, 0x0318, 0x00000001, PLL_AO, 22, 0x0310,
43 24, 0x0310, 0, 0, 0),
44 PLL(CLK_APMIXED_MAINPLL, 0x0228, 0x0234, 0xFF000001, HAVE_RST_BAR, 22,
45 0x022C, 24, 0x022C, 0, CON0_MT8365_RST_BAR, 0),
46 PLL(CLK_APMIXED_UNIVPLL, 0x0208, 0x0214, 0xFF000001, HAVE_RST_BAR, 22,
47 0x020C, 24, 0x020C, 0, CON0_MT8365_RST_BAR, 0),
48 PLL(CLK_APMIXED_MFGPLL, 0x0218, 0x0224, 0x00000001, 0, 22, 0x021C, 24,
49 0x021C, 0, 0, 0),
50 PLL(CLK_APMIXED_MSDCPLL, 0x0350, 0x035C, 0x00000001, 0, 22, 0x0354, 24,
51 0x0354, 0, 0, 0),
52 PLL(CLK_APMIXED_MMPLL, 0x0330, 0x033C, 0x00000001, 0, 22, 0x0334, 24,
53 0x0334, 0, 0, 0),
54 PLL(CLK_APMIXED_APLL1, 0x031C, 0x032C, 0x00000001, 0, 32, 0x0320, 24,
55 0x0324, 0, 0, 0x0320),
56 PLL(CLK_APMIXED_APLL2, 0x0360, 0x0370, 0x00000001, 0, 32, 0x0364, 24,
57 0x0368, 0, 0, 0x0364),
58 PLL(CLK_APMIXED_LVDSPLL, 0x0374, 0x0380, 0x00000001, 0, 22, 0x0378, 24,
59 0x0378, 0, 0, 0),
60 PLL(CLK_APMIXED_DSPPLL, 0x0390, 0x039C, 0x00000001, 0, 22, 0x0394, 24,
61 0x0394, 0, 0, 0),
62 PLL(CLK_APMIXED_APUPLL, 0x03A0, 0x03AC, 0x00000001, 0, 22, 0x03A4, 24,
63 0x03A4, 0, 0, 0),
64};
65
66/* topckgen */
67static const struct mtk_fixed_clk top_fixed_clks[] = {
68 FIXED_CLK(CLK_TOP_CLK_NULL, CLK_XTAL, 0),
69 FIXED_CLK(CLK_TOP_I2S0_BCK, CLK_XTAL, 26000000),
70 FIXED_CLK(CLK_TOP_DSI0_LNTC_DSICK, CLK_TOP_CLK26M, 75000000),
71 FIXED_CLK(CLK_TOP_VPLL_DPIX, CLK_TOP_CLK26M, 75000000),
72 FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, CLK_TOP_CLK26M, 52500000),
73};
74
75#define PLL_FACTOR(_id, _name, _parent, _mult, _div) \
76 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
77
78static const struct mtk_fixed_factor top_divs[] = {
79 PLL_FACTOR(CLK_TOP_SYS_26M_D2, "sys_26m_d2", CLK_XTAL, 1, 2),
80 PLL_FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", CLK_APMIXED_MAINPLL, 1, 2),
81 PLL_FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", CLK_APMIXED_MAINPLL, 1, 4),
82 PLL_FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", CLK_APMIXED_MAINPLL, 1, 8),
83 PLL_FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", CLK_APMIXED_MAINPLL, 1, 16),
84 PLL_FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", CLK_APMIXED_MAINPLL, 1, 32),
85 PLL_FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", CLK_APMIXED_MAINPLL, 1, 3),
86 PLL_FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", CLK_APMIXED_MAINPLL, 1, 6),
87 PLL_FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", CLK_APMIXED_MAINPLL, 1, 12),
88 PLL_FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", CLK_APMIXED_MAINPLL, 1, 24),
89 PLL_FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", CLK_APMIXED_MAINPLL, 1, 5),
90 PLL_FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", CLK_APMIXED_MAINPLL, 1, 10),
91 PLL_FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", CLK_APMIXED_MAINPLL, 1, 20),
92 PLL_FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", CLK_APMIXED_MAINPLL, 1, 7),
93 PLL_FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", CLK_APMIXED_MAINPLL, 1, 14),
94 PLL_FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", CLK_APMIXED_MAINPLL, 1, 28),
95 PLL_FACTOR(CLK_TOP_UNIVPLL, "univpll", CLK_APMIXED_UNIV_EN, 1, 2),
96 PLL_FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", CLK_APMIXED_UNIVPLL, 1, 2),
97 PLL_FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", CLK_APMIXED_UNIVPLL, 1, 4),
98 PLL_FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", CLK_APMIXED_UNIVPLL, 1, 8),
99 PLL_FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", CLK_APMIXED_UNIVPLL, 1, 3),
100 PLL_FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", CLK_APMIXED_UNIVPLL, 1, 6),
101 PLL_FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", CLK_APMIXED_UNIVPLL, 1, 12),
102 PLL_FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", CLK_APMIXED_UNIVPLL, 1, 24),
103 PLL_FACTOR(CLK_TOP_UNIVPLL2_D32, "univpll2_d32", CLK_APMIXED_UNIVPLL, 1, 96),
104 PLL_FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", CLK_APMIXED_UNIVPLL, 1, 5),
105 PLL_FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", CLK_APMIXED_UNIVPLL, 1, 10),
106 PLL_FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", CLK_APMIXED_UNIVPLL, 1, 20),
107 PLL_FACTOR(CLK_TOP_MMPLL, "mmpll_ck", CLK_APMIXED_MMPLL, 1, 1),
108 PLL_FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", CLK_APMIXED_MMPLL, 1, 2),
109 PLL_FACTOR(CLK_TOP_MFGPLL, "mfgpll_ck", CLK_APMIXED_MFGPLL, 1, 1),
110 PLL_FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", CLK_APMIXED_LVDSPLL, 1, 2),
111 PLL_FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", CLK_APMIXED_LVDSPLL, 1, 4),
112 PLL_FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", CLK_APMIXED_LVDSPLL, 1, 8),
113 PLL_FACTOR(CLK_TOP_LVDSPLL_D16, "lvdspll_d16", CLK_APMIXED_LVDSPLL, 1, 16),
114 PLL_FACTOR(CLK_TOP_USB20_192M, "usb20_192m_ck", CLK_APMIXED_USB20_EN, 1, 13),
115 PLL_FACTOR(CLK_TOP_USB20_192M_D4, "usb20_192m_d4", CLK_TOP_USB20_192M, 1, 4),
116 PLL_FACTOR(CLK_TOP_USB20_192M_D8, "usb20_192m_d8", CLK_TOP_USB20_192M, 1, 8),
117 PLL_FACTOR(CLK_TOP_USB20_192M_D16, "usb20_192m_d16", CLK_TOP_USB20_192M, 1, 16),
118 PLL_FACTOR(CLK_TOP_USB20_192M_D32, "usb20_192m_d32", CLK_TOP_USB20_192M, 1, 32),
119 PLL_FACTOR(CLK_TOP_APLL1, "apll1_ck", CLK_APMIXED_APLL1, 1, 1),
120 PLL_FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", CLK_APMIXED_APLL1, 1, 2),
121 PLL_FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", CLK_APMIXED_APLL1, 1, 4),
122 PLL_FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", CLK_APMIXED_APLL1, 1, 8),
123 PLL_FACTOR(CLK_TOP_APLL2, "apll2_ck", CLK_APMIXED_APLL2, 1, 1),
124 PLL_FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", CLK_APMIXED_APLL2, 1, 2),
125 PLL_FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", CLK_APMIXED_APLL2, 1, 4),
126 PLL_FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", CLK_APMIXED_APLL2, 1, 8),
127 PLL_FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", CLK_APMIXED_MSDCPLL, 1, 1),
128 PLL_FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", CLK_APMIXED_MSDCPLL, 1, 2),
129 PLL_FACTOR(CLK_TOP_DSPPLL, "dsppll_ck", CLK_APMIXED_DSPPLL, 1, 1),
130 PLL_FACTOR(CLK_TOP_DSPPLL_D2, "dsppll_d2", CLK_APMIXED_DSPPLL, 1, 2),
131 PLL_FACTOR(CLK_TOP_DSPPLL_D4, "dsppll_d4", CLK_APMIXED_DSPPLL, 1, 4),
132 PLL_FACTOR(CLK_TOP_DSPPLL_D8, "dsppll_d8", CLK_APMIXED_DSPPLL, 1, 8),
133 PLL_FACTOR(CLK_TOP_APUPLL, "apupll_ck", CLK_APMIXED_APUPLL, 1, 1),
134 PLL_FACTOR(CLK_TOP_CLK26M_D52, "clk26m_d52", CLK_XTAL, 1, 52),
135};
136
137static const int axi_parents[] = {
138 CLK_TOP_CLK26M,
139 CLK_TOP_SYSPLL_D7,
140 CLK_TOP_SYSPLL1_D4,
141 CLK_TOP_SYSPLL3_D2
142};
143
144static const int mem_parents[] = {
145 CLK_TOP_CLK26M,
146 CLK_TOP_MMPLL,
147 CLK_TOP_SYSPLL_D3,
148 CLK_TOP_SYSPLL1_D2
149};
150
151static const int mm_parents[] = {
152 CLK_TOP_CLK26M,
153 CLK_TOP_MMPLL,
154 CLK_TOP_SYSPLL1_D2,
155 CLK_TOP_SYSPLL_D5,
156 CLK_TOP_SYSPLL1_D4,
157 CLK_TOP_UNIVPLL_D5,
158 CLK_TOP_UNIVPLL1_D2,
159 CLK_TOP_MMPLL_D2,
160};
161
162static const int scp_parents[] = {
163 CLK_TOP_CLK26M,
164 CLK_TOP_SYSPLL4_D2,
165 CLK_TOP_UNIVPLL2_D2,
166 CLK_TOP_SYSPLL1_D2,
167 CLK_TOP_UNIVPLL1_D2,
168 CLK_TOP_SYSPLL_D3,
169 CLK_TOP_UNIVPLL_D3
170};
171
172static const int mfg_parents[] = {
173 CLK_TOP_CLK26M,
174 CLK_TOP_MFGPLL,
175 CLK_TOP_SYSPLL_D3,
176 CLK_TOP_UNIVPLL_D3
177};
178
179static const int atb_parents[] = {
180 CLK_TOP_CLK26M,
181 CLK_TOP_SYSPLL1_D4,
182 CLK_TOP_SYSPLL1_D2
183};
184
185static const int camtg_parents[] = {
186 CLK_TOP_CLK26M,
187 CLK_TOP_USB20_192M_D8,
188 CLK_TOP_UNIVPLL2_D8,
189 CLK_TOP_USB20_192M_D4,
190 CLK_TOP_UNIVPLL2_D32,
191 CLK_TOP_USB20_192M_D16,
192 CLK_TOP_USB20_192M_D32,
193};
194
195static const int uart_parents[] = {
196 CLK_TOP_CLK26M,
197 CLK_TOP_UNIVPLL2_D8
198};
199
200static const int spi_parents[] = {
201 CLK_TOP_CLK26M,
202 CLK_TOP_UNIVPLL2_D2,
203 CLK_TOP_UNIVPLL2_D4,
204 CLK_TOP_UNIVPLL2_D8
205};
206
207static const int msdc50_0_hc_parents[] = {
208 CLK_TOP_CLK26M,
209 CLK_TOP_SYSPLL1_D2,
210 CLK_TOP_UNIVPLL1_D4,
211 CLK_TOP_SYSPLL2_D2
212};
213
214static const int msdc50_0_parents[] = {
215 CLK_TOP_CLK26M,
216 CLK_TOP_MSDCPLL,
217 CLK_TOP_UNIVPLL1_D2,
218 CLK_TOP_SYSPLL1_D2,
219 CLK_TOP_UNIVPLL_D5,
220 CLK_TOP_SYSPLL2_D2,
221 CLK_TOP_UNIVPLL1_D4,
222 CLK_TOP_SYSPLL4_D2
223};
224
225static const int msdc50_2_parents[] = {
226 CLK_TOP_CLK26M,
227 CLK_TOP_MSDCPLL,
228 CLK_TOP_UNIVPLL_D3,
229 CLK_TOP_UNIVPLL1_D2,
230 CLK_TOP_SYSPLL1_D2,
231 CLK_TOP_UNIVPLL2_D2,
232 CLK_TOP_SYSPLL2_D2,
233 CLK_TOP_UNIVPLL1_D4
234};
235
236static const int msdc30_1_parents[] = {
237 CLK_TOP_CLK26M,
238 CLK_TOP_MSDCPLL_D2,
239 CLK_TOP_UNIVPLL2_D2,
240 CLK_TOP_SYSPLL2_D2,
241 CLK_TOP_UNIVPLL1_D4,
242 CLK_TOP_SYSPLL1_D4,
243 CLK_TOP_SYSPLL2_D4,
244 CLK_TOP_UNIVPLL2_D8
245};
246
247static const int audio_parents[] = {
248 CLK_TOP_CLK26M,
249 CLK_TOP_SYSPLL3_D4,
250 CLK_TOP_SYSPLL4_D4,
251 CLK_TOP_SYSPLL1_D16
252};
253
254static const int aud_intbus_parents[] = {
255 CLK_TOP_CLK26M,
256 CLK_TOP_SYSPLL1_D4,
257 CLK_TOP_SYSPLL4_D2
258};
259
260static const int aud_1_parents[] = {
261 CLK_TOP_CLK26M,
262 CLK_TOP_APLL1
263};
264
265static const int aud_2_parents[] = {
266 CLK_TOP_CLK26M,
267 CLK_TOP_APLL2
268};
269
270static const int aud_engen1_parents[] = {
271 CLK_TOP_CLK26M,
272 CLK_TOP_APLL1_D2,
273 CLK_TOP_APLL1_D4,
274 CLK_TOP_APLL1_D8
275};
276
277static const int aud_engen2_parents[] = {
278 CLK_TOP_CLK26M,
279 CLK_TOP_APLL2_D2,
280 CLK_TOP_APLL2_D4,
281 CLK_TOP_APLL2_D8,
282};
283
284static const int aud_spdif_parents[] = {
285 CLK_TOP_CLK26M,
286 CLK_TOP_UNIVPLL_D2
287};
288
289static const int disp_pwm_parents[] = {
290 CLK_TOP_CLK26M,
291 CLK_TOP_UNIVPLL2_D4
292};
293
294static const int dxcc_parents[] = {
295 CLK_TOP_CLK26M,
296 CLK_TOP_SYSPLL1_D2,
297 CLK_TOP_SYSPLL1_D4,
298 CLK_TOP_SYSPLL1_D8
299};
300
301static const int ssusb_sys_parents[] = {
302 CLK_TOP_CLK26M,
303 CLK_TOP_UNIVPLL3_D4,
304 CLK_TOP_UNIVPLL2_D4,
305 CLK_TOP_UNIVPLL3_D2
306};
307
308static const int spm_parents[] = {
309 CLK_TOP_CLK26M,
310 CLK_TOP_SYSPLL1_D8
311};
312
313static const int i2c_parents[] = {
314 CLK_TOP_CLK26M,
315 CLK_TOP_UNIVPLL3_D4,
316 CLK_TOP_UNIVPLL3_D2,
317 CLK_TOP_SYSPLL1_D8,
318 CLK_TOP_SYSPLL2_D8
319};
320
321static const int pwm_parents[] = {
322 CLK_TOP_CLK26M,
323 CLK_TOP_UNIVPLL3_D4,
324 CLK_TOP_SYSPLL1_D8
325};
326
327static const int senif_parents[] = {
328 CLK_TOP_CLK26M,
329 CLK_TOP_UNIVPLL1_D4,
330 CLK_TOP_UNIVPLL1_D2,
331 CLK_TOP_UNIVPLL2_D2
332};
333
334static const int aes_fde_parents[] = {
335 CLK_TOP_CLK26M,
336 CLK_TOP_MSDCPLL,
337 CLK_TOP_UNIVPLL_D3,
338 CLK_TOP_UNIVPLL2_D2,
339 CLK_TOP_UNIVPLL1_D2,
340 CLK_TOP_SYSPLL1_D2
341};
342
343static const int dpi0_parents[] = {
344 CLK_TOP_CLK26M,
345 CLK_TOP_LVDSPLL_D2,
346 CLK_TOP_LVDSPLL_D4,
347 CLK_TOP_LVDSPLL_D8,
348 CLK_TOP_LVDSPLL_D16
349};
350
351static const int dsp_parents[] = {
352 CLK_TOP_CLK26M,
353 CLK_TOP_SYS_26M_D2,
354 CLK_TOP_DSPPLL,
355 CLK_TOP_DSPPLL_D2,
356 CLK_TOP_DSPPLL_D4,
357 CLK_TOP_DSPPLL_D8
358};
359
360static const int nfi2x_parents[] = {
361 CLK_TOP_CLK26M,
362 CLK_TOP_SYSPLL2_D2,
363 CLK_TOP_SYSPLL_D7,
364 CLK_TOP_SYSPLL_D3,
365 CLK_TOP_SYSPLL2_D4,
366 CLK_TOP_MSDCPLL_D2,
367 CLK_TOP_UNIVPLL1_D2,
368 CLK_TOP_UNIVPLL_D5
369};
370
371static const int nfiecc_parents[] = {
372 CLK_TOP_CLK26M,
373 CLK_TOP_SYSPLL4_D2,
374 CLK_TOP_UNIVPLL2_D4,
375 CLK_TOP_SYSPLL_D7,
376 CLK_TOP_UNIVPLL1_D2,
377 CLK_TOP_SYSPLL1_D2,
378 CLK_TOP_UNIVPLL2_D2,
379 CLK_TOP_SYSPLL_D5
380};
381
382static const int ecc_parents[] = {
383 CLK_TOP_CLK26M,
384 CLK_TOP_UNIVPLL2_D2,
385 CLK_TOP_UNIVPLL1_D2,
386 CLK_TOP_UNIVPLL_D3,
387 CLK_TOP_SYSPLL_D2
388};
389
390static const int eth_parents[] = {
391 CLK_TOP_CLK26M,
392 CLK_TOP_UNIVPLL2_D8,
393 CLK_TOP_SYSPLL4_D4,
394 CLK_TOP_SYSPLL1_D8,
395 CLK_TOP_SYSPLL4_D2
396};
397
398static const int gcpu_parents[] = {
399 CLK_TOP_CLK26M,
400 CLK_TOP_UNIVPLL_D3,
401 CLK_TOP_UNIVPLL2_D2,
402 CLK_TOP_SYSPLL_D3,
403 CLK_TOP_SYSPLL2_D2
404};
405
406static const int gcpu_cpm_parents[] = {
407 CLK_TOP_CLK26M,
408 CLK_TOP_UNIVPLL2_D2,
409 CLK_TOP_SYSPLL2_D2
410};
411
412static const int apu_parents[] = {
413 CLK_TOP_CLK26M,
414 CLK_TOP_UNIVPLL_D2,
415 CLK_APMIXED_APUPLL,
416 CLK_TOP_MMPLL,
417 CLK_TOP_SYSPLL_D3,
418 CLK_TOP_UNIVPLL1_D2,
419 CLK_TOP_SYSPLL1_D2,
420 CLK_TOP_SYSPLL1_D4
421};
422
423static const struct mtk_composite top_muxes[] = {
424 /* CLK_CFG_0 */
425 MUX_GATE(CLK_TOP_AXI_SEL, axi_parents, 0x040, 0, 2, 7),
426 MUX_GATE(CLK_TOP_MEM_SEL, mem_parents, 0x040, 8, 2, 15),
427 MUX_GATE(CLK_TOP_MM_SEL, mm_parents, 0x040, 16, 3, 23),
428 MUX_GATE(CLK_TOP_SCP_SEL, scp_parents, 0x040, 24, 3, 31),
429 /* CLK_CFG_1 */
430 MUX_GATE(CLK_TOP_MFG_SEL, mfg_parents, 0x050, 0, 2, 7),
431 MUX_GATE(CLK_TOP_ATB_SEL, atb_parents, 0x050, 8, 2, 15),
432 MUX_GATE(CLK_TOP_CAMTG_SEL, camtg_parents, 0x050, 16, 3, 23),
433 MUX_GATE(CLK_TOP_CAMTG1_SEL, camtg_parents, 0x050, 24, 3, 31),
434 /* CLK_CFG_2 */
435 MUX_GATE(CLK_TOP_UART_SEL, uart_parents, 0x060, 0, 1, 7),
436 MUX_GATE(CLK_TOP_SPI_SEL, spi_parents, 0x060, 8, 2, 15),
437 MUX_GATE(CLK_TOP_MSDC50_0_HC_SEL, msdc50_0_hc_parents, 0x060, 16, 2, 23),
438 MUX_GATE(CLK_TOP_MSDC2_2_HC_SEL, msdc50_0_hc_parents, 0x060, 24, 2, 31),
439 /* CLK_CFG_3 */
440 MUX_GATE(CLK_TOP_MSDC50_0_SEL, msdc50_0_parents, 0x070, 0, 3, 7),
441 MUX_GATE(CLK_TOP_MSDC50_2_SEL, msdc50_2_parents, 0x070, 8, 3, 15),
442 MUX_GATE(CLK_TOP_MSDC30_1_SEL, msdc30_1_parents, 0x070, 16, 3, 23),
443 MUX_GATE(CLK_TOP_AUDIO_SEL, audio_parents, 0x070, 24, 2, 31),
444 /* CLK_CFG_4 */
445 MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, aud_intbus_parents, 0x080, 0, 2, 7),
446 MUX_GATE(CLK_TOP_AUD_1_SEL, aud_1_parents, 0x080, 8, 1, 15),
447 MUX_GATE(CLK_TOP_AUD_2_SEL, aud_2_parents, 0x080, 16, 1, 23),
448 MUX_GATE(CLK_TOP_AUD_ENGEN1_SEL, aud_engen1_parents, 0x080, 24, 2, 31),
449 /* CLK_CFG_5 */
450 MUX_GATE(CLK_TOP_AUD_ENGEN2_SEL, aud_engen2_parents, 0x090, 0, 2, 7),
451 MUX_GATE(CLK_TOP_AUD_SPDIF_SEL, aud_spdif_parents, 0x090, 8, 1, 15),
452 MUX_GATE(CLK_TOP_DISP_PWM_SEL, disp_pwm_parents, 0x090, 16, 2, 23),
453 /* CLK_CFG_6 */
454 MUX_GATE(CLK_TOP_DXCC_SEL, dxcc_parents, 0x0a0, 0, 2, 7),
455 MUX_GATE(CLK_TOP_SSUSB_SYS_SEL, ssusb_sys_parents, 0x0a0, 8, 2, 15),
456 MUX_GATE(CLK_TOP_SSUSB_XHCI_SEL, ssusb_sys_parents, 0x0a0, 16, 2, 23),
457 MUX_GATE(CLK_TOP_SPM_SEL, spm_parents, 0x0a0, 24, 1, 31),
458 /* CLK_CFG_7 */
459 MUX_GATE(CLK_TOP_I2C_SEL, i2c_parents, 0x0b0, 0, 3, 7),
460 MUX_GATE(CLK_TOP_PWM_SEL, pwm_parents, 0x0b0, 8, 2, 15),
461 MUX_GATE(CLK_TOP_SENIF_SEL, senif_parents, 0x0b0, 16, 2, 23),
462 MUX_GATE(CLK_TOP_AES_FDE_SEL, aes_fde_parents, 0x0b0, 24, 3, 31),
463 /* CLK_CFG_8 */
464 MUX_GATE(CLK_TOP_CAMTM_SEL, senif_parents, 0x0c0, 0, 2, 7),
465 MUX_GATE(CLK_TOP_DPI0_SEL, dpi0_parents, 0x0c0, 8, 3, 15),
466 MUX_GATE(CLK_TOP_DPI1_SEL, dpi0_parents, 0x0c0, 16, 3, 23),
467 MUX_GATE(CLK_TOP_DSP_SEL, dsp_parents, 0x0c0, 24, 3, 31),
468 /* CLK_CFG_9 */
469 MUX_GATE(CLK_TOP_NFI2X_SEL, nfi2x_parents, 0x0d0, 0, 3, 7),
470 MUX_GATE(CLK_TOP_NFIECC_SEL, nfiecc_parents, 0x0d0, 8, 3, 15),
471 MUX_GATE(CLK_TOP_ECC_SEL, ecc_parents, 0x0d0, 16, 3, 23),
472 MUX_GATE(CLK_TOP_ETH_SEL, eth_parents, 0x0d0, 24, 3, 31),
473 /* CLK_CFG_10 */
474 MUX_GATE(CLK_TOP_GCPU_SEL, gcpu_parents, 0x0e0, 0, 3, 7),
475 MUX_GATE(CLK_TOP_GCPU_CPM_SEL, gcpu_cpm_parents, 0x0e0, 8, 2, 15),
476 MUX_GATE(CLK_TOP_APU_SEL, apu_parents, 0x0e0, 16, 3, 23),
477 MUX_GATE(CLK_TOP_APU_IF_SEL, apu_parents, 0x0e0, 24, 3, 31),
478};
479
480static const struct mtk_clk_tree mt8365_clk_tree = {
481 .xtal_rate = 26 * MHZ,
482 .xtal2_rate = 26 * MHZ,
483 .fdivs_offs = CLK_TOP_SYSPLL_D2,
484 .muxes_offs = CLK_TOP_AXI_SEL,
485 .plls = apmixed_plls,
486 .fclks = top_fixed_clks,
487 .fdivs = top_divs,
488 .muxes = top_muxes,
489};
490
491/* topckgen cg */
492static const struct mtk_gate_regs top0_cg_regs = {
493 .set_ofs = 0,
494 .clr_ofs = 0,
495 .sta_ofs = 0,
496};
497
498static const struct mtk_gate_regs top1_cg_regs = {
499 .set_ofs = 0x104,
500 .clr_ofs = 0x104,
501 .sta_ofs = 0x104,
502};
503
504static const struct mtk_gate_regs top2_cg_regs = {
505 .set_ofs = 0x320,
506 .clr_ofs = 0x320,
507 .sta_ofs = 0x320,
508};
509
510#define GATE_TOP0(_id, _parent, _shift) { \
511 .id = _id, \
512 .parent = _parent, \
513 .regs = &top0_cg_regs, \
514 .shift = _shift, \
515 .flags = CLK_GATE_NO_SETCLR | CLK_PARENT_TOPCKGEN, \
516 }
517
518#define GATE_TOP1(_id, _parent, _shift) { \
519 .id = _id, \
520 .parent = _parent, \
521 .regs = &top1_cg_regs, \
522 .shift = _shift, \
523 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
524 }
525
526#define GATE_TOP2(_id, _parent, _shift) { \
527 .id = _id, \
528 .parent = _parent, \
529 .regs = &top2_cg_regs, \
530 .shift = _shift, \
531 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
532 }
533
534static const struct mtk_gate top_clk_gates[] = {
535 GATE_TOP0(CLK_TOP_CONN_32K, CLK_TOP_CLK32K, 10),
536 GATE_TOP0(CLK_TOP_CONN_26M, CLK_TOP_CLK26M, 11),
537 GATE_TOP0(CLK_TOP_DSP_32K, CLK_TOP_CLK32K, 16),
538 GATE_TOP0(CLK_TOP_DSP_26M, CLK_TOP_CLK26M, 17),
539 GATE_TOP1(CLK_TOP_USB20_48M_EN, CLK_TOP_USB20_192M_D4, 8),
540 GATE_TOP1(CLK_TOP_UNIVPLL_48M_EN, CLK_TOP_USB20_192M_D4, 9),
541 GATE_TOP1(CLK_TOP_LVDSTX_CLKDIG_EN, CLK_TOP_LVDSTX_CLKDIG_CTS, 20),
542 GATE_TOP1(CLK_TOP_VPLL_DPIX_EN, CLK_TOP_VPLL_DPIX, 21),
543 GATE_TOP1(CLK_TOP_SSUSB_TOP_CK_EN, CLK_TOP_CLK_NULL, 22),
544 GATE_TOP1(CLK_TOP_SSUSB_PHY_CK_EN, CLK_TOP_CLK_NULL, 23),
545 GATE_TOP2(CLK_TOP_AUD_I2S0_M, CLK_TOP_APLL12_CK_DIV0, 0),
546 GATE_TOP2(CLK_TOP_AUD_I2S1_M, CLK_TOP_APLL12_CK_DIV1, 1),
547 GATE_TOP2(CLK_TOP_AUD_I2S2_M, CLK_TOP_APLL12_CK_DIV2, 2),
548 GATE_TOP2(CLK_TOP_AUD_I2S3_M, CLK_TOP_APLL12_CK_DIV3, 3),
549 GATE_TOP2(CLK_TOP_AUD_TDMOUT_M, CLK_TOP_APLL12_CK_DIV4, 4),
550 GATE_TOP2(CLK_TOP_AUD_TDMOUT_B, CLK_TOP_APLL12_CK_DIV4B, 5),
551 GATE_TOP2(CLK_TOP_AUD_TDMIN_M, CLK_TOP_APLL12_CK_DIV5, 6),
552 GATE_TOP2(CLK_TOP_AUD_TDMIN_B, CLK_TOP_APLL12_CK_DIV5B, 7),
553 GATE_TOP2(CLK_TOP_AUD_SPDIF_M, CLK_TOP_APLL12_CK_DIV6, 8),
554};
555
556/* infracfg */
557static const struct mtk_gate_regs ifr2_cg_regs = {
558 .set_ofs = 0x80,
559 .clr_ofs = 0x84,
560 .sta_ofs = 0x90,
561};
562
563static const struct mtk_gate_regs ifr3_cg_regs = {
564 .set_ofs = 0x88,
565 .clr_ofs = 0x8c,
566 .sta_ofs = 0x94,
567};
568
569static const struct mtk_gate_regs ifr4_cg_regs = {
570 .set_ofs = 0xa4,
571 .clr_ofs = 0xa8,
572 .sta_ofs = 0xac,
573};
574
575static const struct mtk_gate_regs ifr5_cg_regs = {
576 .set_ofs = 0xc0,
577 .clr_ofs = 0xc4,
578 .sta_ofs = 0xc8,
579};
580
581static const struct mtk_gate_regs ifr6_cg_regs = {
582 .set_ofs = 0xd0,
583 .clr_ofs = 0xd4,
584 .sta_ofs = 0xd8,
585};
586
587#define GATE_IFRX(_id, _parent, _shift, _regs) \
588 { \
589 .id = _id, \
590 .parent = _parent, \
591 .regs = _regs, \
592 .shift = _shift, \
593 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
594 }
595
596#define GATE_IFR2(_id, _parent, _shift) \
597 GATE_IFRX(_id, _parent, _shift, &ifr2_cg_regs)
598
599#define GATE_IFR3(_id, _parent, _shift) \
600 GATE_IFRX(_id, _parent, _shift, &ifr3_cg_regs)
601
602#define GATE_IFR4(_id, _parent, _shift) \
603 GATE_IFRX(_id, _parent, _shift, &ifr4_cg_regs)
604
605#define GATE_IFR5(_id, _parent, _shift) \
606 GATE_IFRX(_id, _parent, _shift, &ifr5_cg_regs)
607
608#define GATE_IFR6(_id, _parent, _shift) \
609 GATE_IFRX(_id, _parent, _shift, &ifr6_cg_regs)
610
611static const struct mtk_gate ifr_clks[] = {
612 /* IFR2 */
613 GATE_IFR2(CLK_IFR_PMIC_TMR, CLK_TOP_CLK26M, 0),
614 GATE_IFR2(CLK_IFR_PMIC_AP, CLK_TOP_CLK26M, 1),
615 GATE_IFR2(CLK_IFR_PMIC_MD, CLK_TOP_CLK26M, 2),
616 GATE_IFR2(CLK_IFR_PMIC_CONN, CLK_TOP_CLK26M, 3),
617 GATE_IFR2(CLK_IFR_ICUSB, CLK_TOP_AXI_SEL, 8),
618 GATE_IFR2(CLK_IFR_GCE, CLK_TOP_AXI_SEL, 9),
619 GATE_IFR2(CLK_IFR_THERM, CLK_TOP_AXI_SEL, 10),
620 GATE_IFR2(CLK_IFR_PWM_HCLK, CLK_TOP_AXI_SEL, 15),
621 GATE_IFR2(CLK_IFR_PWM1, CLK_TOP_PWM_SEL, 16),
622 GATE_IFR2(CLK_IFR_PWM2, CLK_TOP_PWM_SEL, 17),
623 GATE_IFR2(CLK_IFR_PWM3, CLK_TOP_PWM_SEL, 18),
624 GATE_IFR2(CLK_IFR_PWM4, CLK_TOP_PWM_SEL, 19),
625 GATE_IFR2(CLK_IFR_PWM5, CLK_TOP_PWM_SEL, 20),
626 GATE_IFR2(CLK_IFR_PWM, CLK_TOP_PWM_SEL, 21),
627 GATE_IFR2(CLK_IFR_UART0, CLK_TOP_UART_SEL, 22),
628 GATE_IFR2(CLK_IFR_UART1, CLK_TOP_UART_SEL, 23),
629 GATE_IFR2(CLK_IFR_UART2, CLK_TOP_UART_SEL, 24),
630 GATE_IFR2(CLK_IFR_DSP_UART, CLK_TOP_UART_SEL, 26),
631 GATE_IFR2(CLK_IFR_GCE_26M, CLK_TOP_CLK26M, 27),
632 GATE_IFR2(CLK_IFR_CQ_DMA_FPC, CLK_TOP_AXI_SEL, 28),
633 GATE_IFR2(CLK_IFR_BTIF, CLK_TOP_AXI_SEL, 31),
634 /* IFR3 */
635 GATE_IFR3(CLK_IFR_SPI0, CLK_TOP_SPI_SEL, 1),
636 GATE_IFR3(CLK_IFR_MSDC0_HCLK, CLK_TOP_MSDC50_0_HC_SEL, 2),
637 GATE_IFR3(CLK_IFR_MSDC2_HCLK, CLK_TOP_MSDC2_2_HC_SEL, 3),
638 GATE_IFR3(CLK_IFR_MSDC1_HCLK, CLK_TOP_AXI_SEL, 4),
639 GATE_IFR3(CLK_IFR_DVFSRC, CLK_TOP_CLK26M, 7),
640 GATE_IFR3(CLK_IFR_GCPU, CLK_TOP_AXI_SEL, 8),
641 GATE_IFR3(CLK_IFR_TRNG, CLK_TOP_AXI_SEL, 9),
642 GATE_IFR3(CLK_IFR_AUXADC, CLK_TOP_CLK26M, 10),
643 GATE_IFR3(CLK_IFR_AUXADC_MD, CLK_TOP_CLK26M, 14),
644 GATE_IFR3(CLK_IFR_AP_DMA, CLK_TOP_AXI_SEL, 18),
645 GATE_IFR3(CLK_IFR_DEBUGSYS, CLK_TOP_AXI_SEL, 24),
646 GATE_IFR3(CLK_IFR_AUDIO, CLK_TOP_AXI_SEL, 25),
647 /* IFR4 */
648 GATE_IFR4(CLK_IFR_PWM_FBCLK6, CLK_TOP_PWM_SEL, 0),
649 GATE_IFR4(CLK_IFR_DISP_PWM, CLK_TOP_DISP_PWM_SEL, 2),
650 GATE_IFR4(CLK_IFR_AUD_26M_BK, CLK_TOP_CLK26M, 4),
651 GATE_IFR4(CLK_IFR_CQ_DMA, CLK_TOP_AXI_SEL, 27),
652 /* IFR5 */
653 GATE_IFR5(CLK_IFR_MSDC0_SF, CLK_TOP_MSDC50_0_SEL, 0),
654 GATE_IFR5(CLK_IFR_MSDC1_SF, CLK_TOP_MSDC50_0_SEL, 1),
655 GATE_IFR5(CLK_IFR_MSDC2_SF, CLK_TOP_MSDC50_0_SEL, 2),
656 GATE_IFR5(CLK_IFR_AP_MSDC0, CLK_TOP_MSDC50_0_SEL, 7),
657 GATE_IFR5(CLK_IFR_MD_MSDC0, CLK_TOP_MSDC50_0_SEL, 8),
658 GATE_IFR5(CLK_IFR_MSDC0_SRC, CLK_TOP_MSDC50_0_SEL, 9),
659 GATE_IFR5(CLK_IFR_MSDC1_SRC, CLK_TOP_MSDC30_1_SEL, 10),
660 GATE_IFR5(CLK_IFR_MSDC2_SRC, CLK_TOP_MSDC50_2_SEL, 11),
661 GATE_IFR5(CLK_IFR_PWRAP_TMR, CLK_TOP_CLK26M, 12),
662 GATE_IFR5(CLK_IFR_PWRAP_SPI, CLK_TOP_CLK26M, 13),
663 GATE_IFR5(CLK_IFR_PWRAP_SYS, CLK_TOP_CLK26M, 14),
664 GATE_IFR5(CLK_IFR_IRRX_26M, CLK_TOP_CLK26M, 22),
665 GATE_IFR5(CLK_IFR_IRRX_32K, CLK_TOP_CLK32K, 23),
666 GATE_IFR5(CLK_IFR_I2C0_AXI, CLK_TOP_I2C_SEL, 24),
667 GATE_IFR5(CLK_IFR_I2C1_AXI, CLK_TOP_I2C_SEL, 25),
668 GATE_IFR5(CLK_IFR_I2C2_AXI, CLK_TOP_I2C_SEL, 26),
669 GATE_IFR5(CLK_IFR_I2C3_AXI, CLK_TOP_I2C_SEL, 27),
670 GATE_IFR5(CLK_IFR_NIC_AXI, CLK_TOP_AXI_SEL, 28),
671 GATE_IFR5(CLK_IFR_NIC_SLV_AXI, CLK_TOP_AXI_SEL, 29),
672 GATE_IFR5(CLK_IFR_APU_AXI, CLK_TOP_AXI_SEL, 30),
673 /* IFR6 */
674 GATE_IFR6(CLK_IFR_NFIECC, CLK_TOP_NFIECC_SEL, 0),
675 GATE_IFR6(CLK_IFR_NFI1X_BK, CLK_TOP_NFI2X_SEL, 1),
676 GATE_IFR6(CLK_IFR_NFIECC_BK, CLK_TOP_NFI2X_SEL, 2),
677 GATE_IFR6(CLK_IFR_NFI_BK, CLK_TOP_AXI_SEL, 3),
678 GATE_IFR6(CLK_IFR_MSDC2_AP_BK, CLK_TOP_AXI_SEL, 4),
679 GATE_IFR6(CLK_IFR_MSDC2_MD_BK, CLK_TOP_AXI_SEL, 5),
680 GATE_IFR6(CLK_IFR_MSDC2_BK, CLK_TOP_AXI_SEL, 6),
681 GATE_IFR6(CLK_IFR_SUSB_133_BK, CLK_TOP_AXI_SEL, 7),
682 GATE_IFR6(CLK_IFR_SUSB_66_BK, CLK_TOP_AXI_SEL, 8),
683 GATE_IFR6(CLK_IFR_SSUSB_SYS, CLK_TOP_SSUSB_SYS_SEL, 9),
684 GATE_IFR6(CLK_IFR_SSUSB_REF, CLK_TOP_SSUSB_SYS_SEL, 10),
685 GATE_IFR6(CLK_IFR_SSUSB_XHCI, CLK_TOP_SSUSB_XHCI_SEL, 11),
686};
687
688static int mt8365_apmixedsys_probe(struct udevice *dev)
689{
690 return mtk_common_clk_init(dev, &mt8365_clk_tree);
691}
692
693static int mt8365_topckgen_probe(struct udevice *dev)
694{
695 return mtk_common_clk_init(dev, &mt8365_clk_tree);
696}
697
698static int mt8365_topckgen_cg_probe(struct udevice *dev)
699{
700 return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, top_clk_gates);
701}
702
703static int mt8365_infracfg_probe(struct udevice *dev)
704{
705 return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, ifr_clks);
706}
707
708static const struct udevice_id mt8365_apmixed_compat[] = {
709 { .compatible = "mediatek,mt8365-apmixedsys", },
710 { }
711};
712
713static const struct udevice_id mt8365_topckgen_compat[] = {
714 { .compatible = "mediatek,mt8365-topckgen", },
715 { }
716};
717
718static const struct udevice_id mt8365_topckgen_cg_compat[] = {
719 { .compatible = "mediatek,mt8365-topckgen-cg", },
720 { }
721};
722
723static const struct udevice_id mt8365_infracfg_compat[] = {
724 { .compatible = "mediatek,mt8365-infracfg", },
725 { }
726};
727
728U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
729 .name = "mt8365-apmixedsys",
730 .id = UCLASS_CLK,
731 .of_match = mt8365_apmixed_compat,
732 .probe = mt8365_apmixedsys_probe,
733 .priv_auto = sizeof(struct mtk_clk_priv),
734 .ops = &mtk_clk_apmixedsys_ops,
735 .flags = DM_FLAG_PRE_RELOC,
736};
737
738U_BOOT_DRIVER(mtk_clk_topckgen) = {
739 .name = "mt8365-topckgen",
740 .id = UCLASS_CLK,
741 .of_match = mt8365_topckgen_compat,
742 .probe = mt8365_topckgen_probe,
743 .priv_auto = sizeof(struct mtk_clk_priv),
744 .ops = &mtk_clk_topckgen_ops,
745 .flags = DM_FLAG_PRE_RELOC,
746};
747
748U_BOOT_DRIVER(mtk_clk_topckgen_cg) = {
749 .name = "mt8365-topckgen-cg",
750 .id = UCLASS_CLK,
751 .of_match = mt8365_topckgen_cg_compat,
752 .probe = mt8365_topckgen_cg_probe,
753 .priv_auto = sizeof(struct mtk_cg_priv),
754 .ops = &mtk_clk_gate_ops,
755 .flags = DM_FLAG_PRE_RELOC,
756};
757
758U_BOOT_DRIVER(mtk_clk_infracfg) = {
759 .name = "mt8365-infracfg",
760 .id = UCLASS_CLK,
761 .of_match = mt8365_infracfg_compat,
762 .probe = mt8365_infracfg_probe,
763 .priv_auto = sizeof(struct mtk_cg_priv),
764 .ops = &mtk_clk_gate_ops,
765 .flags = DM_FLAG_PRE_RELOC,
766};