blob: 05a32e19fc4e17bd186f4f6ce17c4cfae87da6d5 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2019 MediaTek Inc.
4 */
5
6#include <linux/clk.h>
7#include <linux/delay.h>
8#include <linux/mfd/syscon.h>
9#include <linux/of.h>
10#include <linux/of_address.h>
11#include <linux/of_device.h>
12#include <linux/platform_device.h>
13#include <linux/slab.h>
14
15#include "clk-mtk.h"
16#include "clk-mux.h"
17#include "clk-gate.h"
18
19#include <dt-bindings/clock/mt8168-clk.h>
20
21#define CLK_CFG_UPDATE 0x004
22#define CLK_CFG_UPDATE1 0x008
23static DEFINE_SPINLOCK(mt8168_clk_lock);
24
25static const struct mtk_fixed_clk top_fixed_clks[] = {
26 FIXED_CLK(CLK_TOP_CLK_NULL, "clk_null", NULL, 0),
27 FIXED_CLK(CLK_TOP_I2S0_BCK, "i2s0_bck", "clk_null", 26000000),
28 FIXED_CLK(CLK_TOP_DSI0_LNTC_DSICK, "dsi0_lntc_dsick", "clk26m",
29 75000000),
30 FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", "clk26m", 75000000),
31 FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx_dig_cts", "clk26m",
32 52500000),
33};
34
35static const struct mtk_fixed_factor top_divs[] = {
36 FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
37 FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "mainpll", 1, 4),
38 FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "mainpll", 1, 8),
39 FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "mainpll", 1, 16),
40 FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "mainpll", 1, 32),
41 FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
42 FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "mainpll", 1, 6),
43 FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "mainpll", 1, 12),
44 FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "mainpll", 1, 24),
45 FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
46 FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "mainpll", 1, 10),
47 FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "mainpll", 1, 20),
48 FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
49 FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "mainpll", 1, 14),
50 FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "mainpll", 1, 28),
51 FACTOR(CLK_TOP_UNIVPLL, "univpll", "univpll2", 1, 2),
52 FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
53 FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll", 1, 4),
54 FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll", 1, 8),
55 FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
56 FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 6),
57 FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 12),
58 FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 24),
59 FACTOR(CLK_TOP_UNIVPLL2_D32, "univpll2_d32", "univpll", 1, 96),
60 FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
61 FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll", 1, 10),
62 FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll", 1, 20),
63 FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1, 1),
64 FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll", 1, 2),
65 FACTOR(CLK_TOP_MFGPLL, "mfgpll_ck", "mfgpll", 1, 1),
66 FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll", 1, 2),
67 FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll", 1, 4),
68 FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll", 1, 8),
69 FACTOR(CLK_TOP_LVDSPLL_D16, "lvdspll_d16", "lvdspll", 1, 16),
70 FACTOR(CLK_TOP_USB20_192M, "usb20_192m_ck", "univpll", 1, 1),
71 FACTOR(CLK_TOP_USB20_192M_D4, "usb20_192m_d4", "usb20_192m_ck", 1, 4),
72 FACTOR(CLK_TOP_USB20_192M_D8, "usb20_192m_d8", "usb20_192m_ck", 1, 8),
73 FACTOR(CLK_TOP_USB20_192M_D16, "usb20_192m_d16", "usb20_192m_ck",
74 1, 16),
75 FACTOR(CLK_TOP_USB20_192M_D32, "usb20_192m_d32", "usb20_192m_ck",
76 1, 32),
77 FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
78 FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2),
79 FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1, 4),
80 FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1, 8),
81 FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1, 1),
82 FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1, 2),
83 FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2_ck", 1, 4),
84 FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2_ck", 1, 8),
85 FACTOR(CLK_TOP_CLK26M, "clk26m_ck", "clk26m", 1, 1),
86 FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1),
87 FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1, 2),
88 FACTOR(CLK_TOP_DSPPLL, "dsppll_ck", "dsppll", 1, 1),
89 FACTOR(CLK_TOP_DSPPLL_D2, "dsppll_d2", "dsppll", 1, 2),
90 FACTOR(CLK_TOP_DSPPLL_D4, "dsppll_d4", "dsppll", 1, 4),
91 FACTOR(CLK_TOP_DSPPLL_D8, "dsppll_d8", "dsppll", 1, 8),
92 FACTOR(CLK_TOP_APUPLL, "apupll_ck", "apupll", 1, 1),
93 FACTOR(CLK_TOP_CLK26M_D52, "clk26m_d52", "clk26m", 1, 52),
94};
95
96static const char * const axi_parents[] = {
97 "clk26m_ck",
98 "syspll_d7",
99 "syspll1_d4",
100 "syspll3_d2"
101};
102
103static const char * const mem_parents[] = {
104 "clk26m_ck",
105 "mmpll_ck",
106 "syspll_d3",
107 "syspll1_d2"
108};
109
110static const char * const mm_parents[] = {
111 "clk26m_ck",
112 "mmpll_ck",
113 "syspll1_d2",
114 "syspll_d5",
115 "syspll1_d4",
116 "univpll_d5",
117 "univpll1_d2",
118 "mmpll_d2"
119};
120
121static const char * const scp_parents[] = {
122 "clk26m_ck",
123 "syspll4_d2",
124 "univpll2_d2",
125 "syspll1_d2",
126 "univpll1_d2",
127 "syspll_d3",
128 "univpll_d3"
129};
130
131static const char * const mfg_parents[] = {
132 "clk26m_ck",
133 "mfgpll_ck",
134 "syspll_d3",
135 "univpll_d3"
136};
137
138static const char * const atb_parents[] = {
139 "clk26m_ck",
140 "syspll1_d4",
141 "syspll1_d2"
142};
143
144static const char * const camtg_parents[] = {
145 "clk26m_ck",
146 "usb20_192m_d8",
147 "univpll2_d8",
148 "usb20_192m_d4",
149 "univpll2_d32",
150 "usb20_192m_d16",
151 "usb20_192m_d32"
152};
153
154static const char * const uart_parents[] = {
155 "clk26m_ck",
156 "univpll2_d8"
157};
158
159static const char * const spi_parents[] = {
160 "clk26m_ck",
161 "univpll2_d2",
162 "univpll2_d4",
163 "univpll2_d8"
164};
165
166static const char * const msdc50_0_hc_parents[] = {
167 "clk26m_ck",
168 "syspll1_d2",
169 "univpll1_d4",
170 "syspll2_d2"
171};
172
173static const char * const msdc50_0_parents[] = {
174 "clk26m_ck",
175 "msdcpll_ck",
176 "univpll1_d2",
177 "syspll1_d2",
178 "univpll_d5",
179 "syspll2_d2",
180 "univpll1_d4",
181 "syspll4_d2"
182};
183
184static const char * const msdc50_2_parents[] = {
185 "clk26m_ck",
186 "msdcpll_ck",
187 "univpll_d3",
188 "univpll1_d2",
189 "syspll1_d2",
190 "univpll2_d2",
191 "syspll2_d2",
192 "univpll1_d4"
193};
194
195static const char * const msdc30_1_parents[] = {
196 "clk26m_ck",
197 "msdcpll_d2",
198 "univpll2_d2",
199 "syspll2_d2",
200 "univpll1_d4",
201 "syspll1_d4",
202 "syspll2_d4",
203 "univpll2_d8"
204};
205
206static const char * const audio_parents[] = {
207 "clk26m_ck",
208 "syspll3_d4",
209 "syspll4_d4",
210 "syspll1_d16"
211};
212
213static const char * const aud_intbus_parents[] = {
214 "clk26m_ck",
215 "syspll1_d4",
216 "syspll4_d2"
217};
218
219static const char * const aud_1_parents[] = {
220 "clk26m_ck",
221 "apll1_ck"
222};
223
224static const char * const aud_2_parents[] = {
225 "clk26m_ck",
226 "apll2_ck"
227};
228
229static const char * const aud_engen1_parents[] = {
230 "clk26m_ck",
231 "apll1_d2",
232 "apll1_d4",
233 "apll1_d8"
234};
235
236static const char * const aud_engen2_parents[] = {
237 "clk26m_ck",
238 "apll2_d2",
239 "apll2_d4",
240 "apll2_d8"
241};
242
243static const char * const aud_spdif_parents[] = {
244 "clk26m_ck",
245 "univpll_d2"
246};
247
248static const char * const disp_pwm_parents[] = {
249 "clk26m_ck",
250 "univpll2_d4"
251};
252
253static const char * const dxcc_parents[] = {
254 "clk26m_ck",
255 "syspll1_d2",
256 "syspll1_d4",
257 "syspll1_d8"
258};
259
260static const char * const ssusb_sys_parents[] = {
261 "clk26m_ck",
262 "univpll3_d4",
263 "univpll2_d4",
264 "univpll3_d2"
265};
266
267static const char * const spm_parents[] = {
268 "clk26m_ck",
269 "syspll1_d8"
270};
271
272static const char * const i2c_parents[] = {
273 "clk26m_ck",
274 "univpll3_d4",
275 "univpll3_d2",
276 "syspll1_d8",
277 "syspll2_d8"
278};
279
280static const char * const pwm_parents[] = {
281 "clk26m_ck",
282 "univpll3_d4",
283 "syspll1_d8"
284};
285
286static const char * const senif_parents[] = {
287 "clk26m_ck",
288 "univpll1_d4",
289 "univpll1_d2",
290 "univpll2_d2"
291};
292
293static const char * const aes_fde_parents[] = {
294 "clk26m_ck",
295 "msdcpll_ck",
296 "univpll_d3",
297 "univpll2_d2",
298 "univpll1_d2",
299 "syspll1_d2"
300};
301
302static const char * const dpi0_parents[] = {
303 "clk26m_ck",
304 "lvdspll_d2",
305 "lvdspll_d4",
306 "lvdspll_d8",
307 "lvdspll_d16"
308};
309
310static const char * const dsp_parents[] = {
311 "clk26m_ck",
312 "sys_26m_d2",
313 "dsppll_ck",
314 "dsppll_d2",
315 "dsppll_d4",
316 "dsppll_d8"
317};
318
319static const char * const nfi2x_parents[] = {
320 "clk26m_ck",
321 "syspll2_d2",
322 "syspll_d7",
323 "syspll_d3",
324 "syspll2_d4",
325 "msdcpll_d2",
326 "univpll1_d2",
327 "univpll_d5"
328};
329
330static const char * const nfiecc_parents[] = {
331 "clk26m_ck",
332 "syspll4_d2",
333 "univpll2_d4",
334 "syspll_d7",
335 "univpll1_d2",
336 "syspll1_d2",
337 "univpll2_d2",
338 "syspll_d5"
339};
340
341static const char * const ecc_parents[] = {
342 "clk26m_ck",
343 "univpll2_d2",
344 "univpll1_d2",
345 "univpll_d3",
346 "syspll_d2"
347};
348
349static const char * const eth_parents[] = {
350 "clk26m_ck",
351 "univpll2_d8",
352 "syspll4_d4",
353 "syspll1_d8",
354 "syspll4_d2"
355};
356
357static const char * const gcpu_parents[] = {
358 "clk26m_ck",
359 "univpll_d3",
360 "univpll2_d2",
361 "syspll_d3",
362 "syspll2_d2"
363};
364
365static const char * const gcpu_cpm_parents[] = {
366 "clk26m_ck",
367 "univpll2_d2",
368 "syspll2_d2"
369};
370
371static const char * const apu_parents[] = {
372 "clk26m_ck",
373 "univpll_d2",
374 "apupll_ck",
375 "mmpll_ck",
376 "syspll_d3",
377 "univpll1_d2",
378 "syspll1_d2",
379 "syspll1_d4"
380};
381
382static const char * const mbist_diag_parents[] = {
383 "clk26m_ck",
384 "syspll4_d4",
385 "univpll2_d8"
386};
387
388static const char * const apll_i2s0_parents[] = {
389 "aud_1_sel",
390 "aud_2_sel"
391};
392
393static struct mtk_composite top_misc_muxes[] = {
394 /* CLK_CFG_11 */
395 MUX_GATE(CLK_TOP_MBIST_DIAG_SEL, "mbist_diag_sel", mbist_diag_parents,
396 0x0ec, 0, 2, 7),
397 /* CLK_AUDDIV_0 */
398 MUX(CLK_TOP_APLL_I2S0_SEL, "apll_i2s0_sel", apll_i2s0_parents,
399 0x320, 11, 1),
400 MUX(CLK_TOP_APLL_I2S1_SEL, "apll_i2s1_sel", apll_i2s0_parents,
401 0x320, 12, 1),
402 MUX(CLK_TOP_APLL_I2S2_SEL, "apll_i2s2_sel", apll_i2s0_parents,
403 0x320, 13, 1),
404 MUX(CLK_TOP_APLL_I2S3_SEL, "apll_i2s3_sel", apll_i2s0_parents,
405 0x320, 14, 1),
406 MUX(CLK_TOP_APLL_TDMOUT_SEL, "apll_tdmout_sel", apll_i2s0_parents,
407 0x320, 15, 1),
408 MUX(CLK_TOP_APLL_TDMIN_SEL, "apll_tdmin_sel", apll_i2s0_parents,
409 0x320, 16, 1),
410 MUX(CLK_TOP_APLL_SPDIF_SEL, "apll_spdif_sel", apll_i2s0_parents,
411 0x320, 17, 1),
412};
413
414static const struct mtk_mux top_muxes[] = {
415 /* CLK_CFG_0 */
416 MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
417 0x040, 0x044, 0x048, 0, 2, 7,
418 CLK_CFG_UPDATE, 0, CLK_IS_CRITICAL),
419 MUX_GATE_CLR_SET_UPD(CLK_TOP_MEM_SEL, "mem_sel", mem_parents,
420 0x040, 0x044, 0x048, 8, 2, 15, CLK_CFG_UPDATE, 1),
421 MUX_GATE_CLR_SET_UPD(CLK_TOP_MM_SEL, "mm_sel", mm_parents,
422 0x040, 0x044, 0x048, 16, 3, 23, CLK_CFG_UPDATE, 2),
423 MUX_GATE_CLR_SET_UPD(CLK_TOP_SCP_SEL, "scp_sel", scp_parents,
424 0x040, 0x044, 0x048, 24, 3, 31, CLK_CFG_UPDATE, 3),
425 /* CLK_CFG_1 */
426 MUX_GATE_CLR_SET_UPD(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents,
427 0x050, 0x054, 0x058, 0, 2, 7, CLK_CFG_UPDATE, 4),
428 MUX_GATE_CLR_SET_UPD(CLK_TOP_ATB_SEL, "atb_sel", atb_parents,
429 0x050, 0x054, 0x058, 8, 2, 15, CLK_CFG_UPDATE, 5),
430 MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG_SEL, "camtg_sel", camtg_parents,
431 0x050, 0x054, 0x058, 16, 3, 23, CLK_CFG_UPDATE, 6),
432 MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG1_SEL, "camtg1_sel", camtg_parents,
433 0x050, 0x054, 0x058, 24, 3, 31, CLK_CFG_UPDATE, 7),
434 /* CLK_CFG_2 */
435 MUX_GATE_CLR_SET_UPD(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
436 0x060, 0x064, 0x068, 0, 1, 7, CLK_CFG_UPDATE, 8),
437 MUX_GATE_CLR_SET_UPD(CLK_TOP_SPI_SEL, "spi_sel", spi_parents,
438 0x060, 0x064, 0x068, 8, 2, 15, CLK_CFG_UPDATE, 9),
439 MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_HC_SEL, "msdc50_0_hc_sel",
440 msdc50_0_hc_parents, 0x060, 0x064, 0x068, 16, 2, 23,
441 CLK_CFG_UPDATE, 10),
442 MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC2_2_HC_SEL, "msdc2_2_hc_sel",
443 msdc50_0_hc_parents, 0x060, 0x064, 0x068, 24, 2, 31,
444 CLK_CFG_UPDATE, 11),
445 /* CLK_CFG_3 */
446 MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
447 msdc50_0_parents, 0x070, 0x074, 0x078, 0, 3, 7,
448 CLK_CFG_UPDATE, 12),
449 MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_2_SEL, "msdc50_2_sel",
450 msdc50_2_parents, 0x070, 0x074, 0x078, 8, 3, 15,
451 CLK_CFG_UPDATE, 13),
452 MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
453 msdc30_1_parents, 0x070, 0x074, 0x078, 16, 3, 23,
454 CLK_CFG_UPDATE, 14),
455 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents,
456 0x070, 0x074, 0x078, 24, 2, 31, CLK_CFG_UPDATE, 15),
457 /* CLK_CFG_4 */
458 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
459 aud_intbus_parents, 0x080, 0x084, 0x088, 0, 2, 7,
460 CLK_CFG_UPDATE, 16),
461 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_1_SEL, "aud_1_sel", aud_1_parents,
462 0x080, 0x084, 0x088, 8, 1, 15, CLK_CFG_UPDATE, 17),
463 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_2_SEL, "aud_2_sel", aud_2_parents,
464 0x080, 0x084, 0x088, 16, 1, 23, CLK_CFG_UPDATE, 18),
465 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel",
466 aud_engen1_parents, 0x080, 0x084, 0x088, 24, 2, 31,
467 CLK_CFG_UPDATE, 19),
468 /* CLK_CFG_5 */
469 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_ENGEN2_SEL, "aud_engen2_sel",
470 aud_engen2_parents, 0x090, 0x094, 0x098, 0, 2, 7,
471 CLK_CFG_UPDATE, 20),
472 MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_SPDIF_SEL, "aud_spdif_sel",
473 aud_spdif_parents, 0x090, 0x094, 0x098, 8, 1, 15,
474 CLK_CFG_UPDATE, 21),
475 MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_PWM_SEL, "disp_pwm_sel", disp_pwm_parents,
476 0x090, 0x094, 0x098, 16, 2, 23, CLK_CFG_UPDATE, 22),
477 /* CLK_CFG_6 */
478 MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_DXCC_SEL, "dxcc_sel", dxcc_parents,
479 0x0a0, 0x0a4, 0x0a8, 0, 2, 7,
480 CLK_CFG_UPDATE, 24, CLK_IS_CRITICAL),
481 MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_SYS_SEL, "ssusb_sys_sel",
482 ssusb_sys_parents, 0x0a0, 0x0a4, 0x0a8, 8, 2, 15,
483 CLK_CFG_UPDATE, 25),
484 MUX_GATE_CLR_SET_UPD(CLK_TOP_SSUSB_XHCI_SEL, "ssusb_xhci_sel",
485 ssusb_sys_parents, 0x0a0, 0x0a4, 0x0a8, 16, 2, 23,
486 CLK_CFG_UPDATE, 26),
487 MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_SPM_SEL, "spm_sel", spm_parents,
488 0x0a0, 0x0a4, 0x0a8, 24, 1, 31,
489 CLK_CFG_UPDATE, 27, CLK_IS_CRITICAL),
490 /* CLK_CFG_7 */
491 MUX_GATE_CLR_SET_UPD(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents,
492 0x0b0, 0x0b4, 0x0b8, 0, 3, 7, CLK_CFG_UPDATE, 28),
493 MUX_GATE_CLR_SET_UPD(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
494 0x0b0, 0x0b4, 0x0b8, 8, 2, 15, CLK_CFG_UPDATE, 29),
495 MUX_GATE_CLR_SET_UPD(CLK_TOP_SENIF_SEL, "senif_sel", senif_parents,
496 0x0b0, 0x0b4, 0x0b8, 16, 2, 23, CLK_CFG_UPDATE, 30),
497 MUX_GATE_CLR_SET_UPD(CLK_TOP_AES_FDE_SEL, "aes_fde_sel", aes_fde_parents,
498 0x0b0, 0x0b4, 0x0b8, 24, 3, 31, CLK_CFG_UPDATE, 31),
499 /* CLK_CFG_8 */
500 MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTM_SEL, "camtm_sel", senif_parents,
501 0x0c0, 0x0c4, 0x0c8, 0, 2, 7, CLK_CFG_UPDATE1, 0),
502 MUX_GATE_CLR_SET_UPD(CLK_TOP_DPI0_SEL, "dpi0_sel", dpi0_parents,
503 0x0c0, 0x0c4, 0x0c8, 8, 3, 15, CLK_CFG_UPDATE1, 1),
504 MUX_GATE_CLR_SET_UPD(CLK_TOP_DPI1_SEL, "dpi1_sel", dpi0_parents,
505 0x0c0, 0x0c4, 0x0c8, 16, 3, 23, CLK_CFG_UPDATE1, 2),
506 MUX_GATE_CLR_SET_UPD(CLK_TOP_DSP_SEL, "dsp_sel", dsp_parents,
507 0x0c0, 0x0c4, 0x0c8, 24, 3, 31, CLK_CFG_UPDATE1, 3),
508 /* CLK_CFG_9 */
509 MUX_GATE_CLR_SET_UPD(CLK_TOP_NFI2X_SEL, "nfi2x_sel", nfi2x_parents,
510 0x0d0, 0x0d4, 0x0d8, 0, 3, 7, CLK_CFG_UPDATE1, 4),
511 MUX_GATE_CLR_SET_UPD(CLK_TOP_NFIECC_SEL, "nfiecc_sel", nfiecc_parents,
512 0x0d0, 0x0d4, 0x0d8, 8, 3, 15, CLK_CFG_UPDATE1, 5),
513 MUX_GATE_CLR_SET_UPD(CLK_TOP_ECC_SEL, "ecc_sel", ecc_parents,
514 0x0d0, 0x0d4, 0x0d8, 16, 3, 23, CLK_CFG_UPDATE1, 6),
515 MUX_GATE_CLR_SET_UPD(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
516 0x0d0, 0x0d4, 0x0d8, 24, 3, 31, CLK_CFG_UPDATE1, 7),
517 /* CLK_CFG_10 */
518 MUX_GATE_CLR_SET_UPD(CLK_TOP_GCPU_SEL, "gcpu_sel", gcpu_parents,
519 0x0e0, 0x0e4, 0x0e8, 0, 3, 7, CLK_CFG_UPDATE1, 8),
520 MUX_GATE_CLR_SET_UPD(CLK_TOP_GCPU_CPM_SEL, "gcpu_cpm_sel", gcpu_cpm_parents,
521 0x0e0, 0x0e4, 0x0e8, 8, 2, 15, CLK_CFG_UPDATE1, 9),
522 MUX_GATE_CLR_SET_UPD(CLK_TOP_APU_SEL, "apu_sel", apu_parents,
523 0x0e0, 0x0e4, 0x0e8, 16, 3, 23, CLK_CFG_UPDATE1, 10),
524 MUX_GATE_CLR_SET_UPD(CLK_TOP_APU_IF_SEL, "apu_if_sel", apu_parents,
525 0x0e0, 0x0e4, 0x0e8, 24, 3, 31, CLK_CFG_UPDATE1, 11),
526};
527
528static const char * const mcu_bus_parents[] = {
529 "clk26m_ck",
530 "armpll",
531 "mainpll",
532 "univpll_d2"
533};
534
535static struct mtk_composite mcu_muxes[] = {
536 /* bus_pll_divider_cfg */
537 MUX_GATE_FLAGS(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0,
538 9, 2, -1, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL),
539};
540
541#define DIV_ADJ_F(_id, _name, _parent, _reg, _shift, _width, _flags) { \
542 .id = _id, \
543 .name = _name, \
544 .parent_name = _parent, \
545 .div_reg = _reg, \
546 .div_shift = _shift, \
547 .div_width = _width, \
548 .clk_divider_flags = _flags, \
549}
550
551static const struct mtk_clk_divider top_adj_divs[] = {
552 DIV_ADJ_F(CLK_TOP_APLL12_CK_DIV0, "apll12_ck_div0", "apll_i2s0_sel",
553 0x324, 0, 8, CLK_DIVIDER_ROUND_CLOSEST),
554 DIV_ADJ_F(CLK_TOP_APLL12_CK_DIV1, "apll12_ck_div1", "apll_i2s1_sel",
555 0x324, 8, 8, CLK_DIVIDER_ROUND_CLOSEST),
556 DIV_ADJ_F(CLK_TOP_APLL12_CK_DIV2, "apll12_ck_div2", "apll_i2s2_sel",
557 0x324, 16, 8, CLK_DIVIDER_ROUND_CLOSEST),
558 DIV_ADJ_F(CLK_TOP_APLL12_CK_DIV3, "apll12_ck_div3", "apll_i2s3_sel",
559 0x324, 24, 8, CLK_DIVIDER_ROUND_CLOSEST),
560 DIV_ADJ_F(CLK_TOP_APLL12_CK_DIV6, "apll12_ck_div6", "apll_spdif_sel",
561 0x32c, 0, 8, CLK_DIVIDER_ROUND_CLOSEST),
562};
563
564#define DIV_FIXUP(_id, _name, _parent, _reg, _reg_fixup, _shift, _width,\
565 _flags) { \
566 .id = _id, \
567 .name = _name, \
568 .parent_name = _parent, \
569 .div_reg = _reg, \
570 .div_reg_fixup = _reg_fixup, \
571 .div_shift = _shift, \
572 .div_width = _width, \
573 .clk_divider_flags = _flags, \
574}
575
576static const struct mtk_clk_divider top_fixup_divs[] = {
577 DIV_FIXUP(CLK_TOP_APLL12_CK_DIV4, "apll12_ck_div4", "apll_tdmout_sel",
578 0x328, 0x500, 0, 8, CLK_DIVIDER_ROUND_CLOSEST),
579 DIV_FIXUP(CLK_TOP_APLL12_CK_DIV4B, "apll12_ck_div4b", "apll12_ck_div4",
580 0x328, 0x500, 8, 8, CLK_DIVIDER_ROUND_CLOSEST),
581 DIV_FIXUP(CLK_TOP_APLL12_CK_DIV5, "apll12_ck_div5", "apll_tdmin_sel",
582 0x328, 0x500, 16, 8, CLK_DIVIDER_ROUND_CLOSEST),
583 DIV_FIXUP(CLK_TOP_APLL12_CK_DIV5B, "apll12_ck_div5b", "apll12_ck_div5",
584 0x328, 0x500, 24, 8, CLK_DIVIDER_ROUND_CLOSEST),
585};
586
587static const struct mtk_gate_regs top0_cg_regs = {
588 .set_ofs = 0x0,
589 .clr_ofs = 0x0,
590 .sta_ofs = 0x0,
591};
592
593static const struct mtk_gate_regs top1_cg_regs = {
594 .set_ofs = 0x104,
595 .clr_ofs = 0x104,
596 .sta_ofs = 0x104,
597};
598
599static const struct mtk_gate_regs top2_cg_regs = {
600 .set_ofs = 0x320,
601 .clr_ofs = 0x320,
602 .sta_ofs = 0x320,
603};
604
605#define GATE_TOP0(_id, _name, _parent, _shift) { \
606 .id = _id, \
607 .name = _name, \
608 .parent_name = _parent, \
609 .regs = &top0_cg_regs, \
610 .shift = _shift, \
611 .ops = &mtk_clk_gate_ops_no_setclr, \
612 }
613
614#define GATE_TOP0_I(_id, _name, _parent, _shift) { \
615 .id = _id, \
616 .name = _name, \
617 .parent_name = _parent, \
618 .regs = &top0_cg_regs, \
619 .shift = _shift, \
620 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
621 }
622
623#define GATE_TOP1(_id, _name, _parent, _shift) { \
624 .id = _id, \
625 .name = _name, \
626 .parent_name = _parent, \
627 .regs = &top1_cg_regs, \
628 .shift = _shift, \
629 .ops = &mtk_clk_gate_ops_no_setclr, \
630 }
631
632#define GATE_TOP1_I(_id, _name, _parent, _shift) { \
633 .id = _id, \
634 .name = _name, \
635 .parent_name = _parent, \
636 .regs = &top1_cg_regs, \
637 .shift = _shift, \
638 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
639 }
640
641#define GATE_TOP2(_id, _name, _parent, _shift) { \
642 .id = _id, \
643 .name = _name, \
644 .parent_name = _parent, \
645 .regs = &top2_cg_regs, \
646 .shift = _shift, \
647 .ops = &mtk_clk_gate_ops_no_setclr, \
648 }
649
650static const struct mtk_gate top_clks[] = {
651 /* TOP0 */
652 GATE_TOP0(CLK_TOP_CONN_32K, "conn_32k", "clk32k", 10),
653 GATE_TOP0(CLK_TOP_CONN_26M, "conn_26m", "clk26m_ck", 11),
654 GATE_TOP0(CLK_TOP_DSP_32K, "dsp_32k", "clk32k", 16),
655 GATE_TOP0(CLK_TOP_DSP_26M, "dsp_26m", "clk26m_ck", 17),
656 /* TOP1 */
657 GATE_TOP1_I(CLK_TOP_USB20_48M_EN, "usb20_48m_en", "usb20_192m_d4", 8),
658 GATE_TOP1_I(CLK_TOP_UNIVPLL_48M_EN, "univpll_48m_en", "usb20_192m_d4",
659 9),
660 GATE_TOP1_I(CLK_TOP_LVDSTX_CLKDIG_EN, "lvdstx_dig_en", "lvdstx_dig_cts",
661 20),
662 GATE_TOP1_I(CLK_TOP_VPLL_DPIX_EN, "vpll_dpix_en", "vpll_dpix", 21),
663 GATE_TOP1_I(CLK_TOP_SSUSB_TOP_CK_EN, "ssusb_top_ck_en", "clk_null", 22),
664 GATE_TOP1_I(CLK_TOP_SSUSB_PHY_CK_EN, "ssusb_phy_ck_en", "clk_null", 23),
665 /* TOP2 */
666 GATE_TOP2(CLK_TOP_AUD_I2S0_M, "aud_i2s0_m_ck", "apll12_ck_div0", 0),
667 GATE_TOP2(CLK_TOP_AUD_I2S1_M, "aud_i2s1_m_ck", "apll12_ck_div1", 1),
668 GATE_TOP2(CLK_TOP_AUD_I2S2_M, "aud_i2s2_m_ck", "apll12_ck_div2", 2),
669 GATE_TOP2(CLK_TOP_AUD_I2S3_M, "aud_i2s3_m_ck", "apll12_ck_div3", 3),
670 GATE_TOP2(CLK_TOP_AUD_TDMOUT_M, "aud_tdmout_m_ck", "apll12_ck_div4", 4),
671 GATE_TOP2(CLK_TOP_AUD_TDMOUT_B, "aud_tdmout_b_ck", "apll12_ck_div4b",
672 5),
673 GATE_TOP2(CLK_TOP_AUD_TDMIN_M, "aud_tdmin_m_ck", "apll12_ck_div5", 6),
674 GATE_TOP2(CLK_TOP_AUD_TDMIN_B, "aud_tdmin_b_ck", "apll12_ck_div5b", 7),
675 GATE_TOP2(CLK_TOP_AUD_SPDIF_M, "aud_spdif_m_ck", "apll12_ck_div6", 8),
676
677};
678
679static const struct mtk_gate_regs ifr0_cg_regs = {
680 .set_ofs = 0x200,
681 .clr_ofs = 0x200,
682 .sta_ofs = 0x200,
683};
684
685static const struct mtk_gate_regs ifr1_cg_regs = {
686 .set_ofs = 0x74,
687 .clr_ofs = 0x74,
688 .sta_ofs = 0x74,
689};
690
691static const struct mtk_gate_regs ifr2_cg_regs = {
692 .set_ofs = 0x80,
693 .clr_ofs = 0x84,
694 .sta_ofs = 0x90,
695};
696
697static const struct mtk_gate_regs ifr3_cg_regs = {
698 .set_ofs = 0x88,
699 .clr_ofs = 0x8c,
700 .sta_ofs = 0x94,
701};
702
703static const struct mtk_gate_regs ifr4_cg_regs = {
704 .set_ofs = 0xa4,
705 .clr_ofs = 0xa8,
706 .sta_ofs = 0xac,
707};
708
709static const struct mtk_gate_regs ifr5_cg_regs = {
710 .set_ofs = 0xc0,
711 .clr_ofs = 0xc4,
712 .sta_ofs = 0xc8,
713};
714
715static const struct mtk_gate_regs ifr6_cg_regs = {
716 .set_ofs = 0xd0,
717 .clr_ofs = 0xd4,
718 .sta_ofs = 0xd8,
719};
720
721#define GATE_IFR0(_id, _name, _parent, _shift) { \
722 .id = _id, \
723 .name = _name, \
724 .parent_name = _parent, \
725 .regs = &ifr0_cg_regs, \
726 .shift = _shift, \
727 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
728 }
729
730#define GATE_IFR1(_id, _name, _parent, _shift) { \
731 .id = _id, \
732 .name = _name, \
733 .parent_name = _parent, \
734 .regs = &ifr1_cg_regs, \
735 .shift = _shift, \
736 .ops = &mtk_clk_gate_ops_no_setclr, \
737 }
738
739#define GATE_IFR2(_id, _name, _parent, _shift) { \
740 .id = _id, \
741 .name = _name, \
742 .parent_name = _parent, \
743 .regs = &ifr2_cg_regs, \
744 .shift = _shift, \
745 .ops = &mtk_clk_gate_ops_setclr, \
746 }
747
748#define GATE_IFR3(_id, _name, _parent, _shift) { \
749 .id = _id, \
750 .name = _name, \
751 .parent_name = _parent, \
752 .regs = &ifr3_cg_regs, \
753 .shift = _shift, \
754 .ops = &mtk_clk_gate_ops_setclr, \
755 }
756
757#define GATE_IFR4(_id, _name, _parent, _shift) { \
758 .id = _id, \
759 .name = _name, \
760 .parent_name = _parent, \
761 .regs = &ifr4_cg_regs, \
762 .shift = _shift, \
763 .ops = &mtk_clk_gate_ops_setclr, \
764 }
765
766#define GATE_IFR5(_id, _name, _parent, _shift) { \
767 .id = _id, \
768 .name = _name, \
769 .parent_name = _parent, \
770 .regs = &ifr5_cg_regs, \
771 .shift = _shift, \
772 .ops = &mtk_clk_gate_ops_setclr, \
773 }
774
775#define GATE_IFR6(_id, _name, _parent, _shift) { \
776 .id = _id, \
777 .name = _name, \
778 .parent_name = _parent, \
779 .regs = &ifr6_cg_regs, \
780 .shift = _shift, \
781 .ops = &mtk_clk_gate_ops_setclr, \
782 }
783
784static const struct mtk_gate ifr_clks[] = {
785 /* IFR2 */
786 GATE_IFR2(CLK_IFR_PMIC_TMR, "ifr_pmic_tmr", "clk26m_ck", 0),
787 GATE_IFR2(CLK_IFR_PMIC_AP, "ifr_pmic_ap", "clk26m_ck", 1),
788 GATE_IFR2(CLK_IFR_PMIC_MD, "ifr_pmic_md", "clk26m_ck", 2),
789 GATE_IFR2(CLK_IFR_PMIC_CONN, "ifr_pmic_conn", "clk26m_ck", 3),
790 GATE_IFR2(CLK_IFR_ICUSB, "ifr_icusb", "axi_sel", 8),
791 GATE_IFR2(CLK_IFR_GCE, "ifr_gce", "axi_sel", 9),
792 GATE_IFR2(CLK_IFR_THERM, "ifr_therm", "axi_sel", 10),
793 GATE_IFR2(CLK_IFR_PWM_HCLK, "ifr_pwm_hclk", "axi_sel", 15),
794 GATE_IFR2(CLK_IFR_PWM1, "ifr_pwm1", "pwm_sel", 16),
795 GATE_IFR2(CLK_IFR_PWM2, "ifr_pwm2", "pwm_sel", 17),
796 GATE_IFR2(CLK_IFR_PWM3, "ifr_pwm3", "pwm_sel", 18),
797 GATE_IFR2(CLK_IFR_PWM4, "ifr_pwm4", "pwm_sel", 19),
798 GATE_IFR2(CLK_IFR_PWM5, "ifr_pwm5", "pwm_sel", 20),
799 GATE_IFR2(CLK_IFR_PWM, "ifr_pwm", "pwm_sel", 21),
800 GATE_IFR2(CLK_IFR_UART0, "ifr_uart0", "uart_sel", 22),
801 GATE_IFR2(CLK_IFR_UART1, "ifr_uart1", "uart_sel", 23),
802 GATE_IFR2(CLK_IFR_UART2, "ifr_uart2", "uart_sel", 24),
803 GATE_IFR2(CLK_IFR_DSP_UART, "ifr_dsp_uart", "uart_sel", 26),
804 GATE_IFR2(CLK_IFR_GCE_26M, "ifr_gce_26m", "clk26m_ck", 27),
805 GATE_IFR2(CLK_IFR_CQ_DMA_FPC, "ifr_cq_dma_fpc", "axi_sel", 28),
806 GATE_IFR2(CLK_IFR_BTIF, "ifr_btif", "axi_sel", 31),
807 /* IFR3 */
808 GATE_IFR3(CLK_IFR_SPI0, "ifr_spi0", "spi_sel", 1),
809 GATE_IFR3(CLK_IFR_MSDC0_HCLK, "ifr_msdc0", "msdc50_0_hc_sel", 2),
810 GATE_IFR3(CLK_IFR_MSDC2_HCLK, "ifr_msdc2", "msdc2_2_hc_sel", 3),
811 GATE_IFR3(CLK_IFR_MSDC1_HCLK, "ifr_msdc1", "axi_sel", 4),
812 GATE_IFR3(CLK_IFR_DVFSRC, "ifr_dvfsrc", "clk26m_ck", 7),
813 GATE_IFR3(CLK_IFR_GCPU, "ifr_gcpu", "axi_sel", 8),
814 GATE_IFR3(CLK_IFR_TRNG, "ifr_trng", "axi_sel", 9),
815 GATE_IFR3(CLK_IFR_AUXADC, "ifr_auxadc", "clk26m_ck", 10),
816 GATE_IFR3(CLK_IFR_AUXADC_MD, "ifr_auxadc_md", "clk26m_ck", 14),
817 GATE_IFR3(CLK_IFR_AP_DMA, "ifr_ap_dma", "axi_sel", 18),
818 GATE_IFR3(CLK_IFR_DEBUGSYS, "ifr_debugsys", "axi_sel", 24),
819 GATE_IFR3(CLK_IFR_AUDIO, "ifr_audio", "axi_sel", 25),
820 /* IFR4 */
821 GATE_IFR4(CLK_IFR_PWM_FBCLK6, "ifr_pwm_fbclk6", "pwm_sel", 0),
822 GATE_IFR4(CLK_IFR_DISP_PWM, "ifr_disp_pwm", "disp_pwm_sel", 2),
823 GATE_IFR4(CLK_IFR_AUD_26M_BK, "ifr_aud_26m_bk", "clk26m_ck", 4),
824 GATE_IFR4(CLK_IFR_CQ_DMA, "ifr_cq_dma", "axi_sel", 27),
825 /* IFR5 */
826 GATE_IFR5(CLK_IFR_MSDC0_SF, "ifr_msdc0_sf", "msdc50_0_sel", 0),
827 GATE_IFR5(CLK_IFR_MSDC1_SF, "ifr_msdc1_sf", "msdc50_0_sel", 1),
828 GATE_IFR5(CLK_IFR_MSDC2_SF, "ifr_msdc2_sf", "msdc50_0_sel", 2),
829 GATE_IFR5(CLK_IFR_AP_MSDC0, "ifr_ap_msdc0", "msdc50_0_sel", 7),
830 GATE_IFR5(CLK_IFR_MD_MSDC0, "ifr_md_msdc0", "msdc50_0_sel", 8),
831 GATE_IFR5(CLK_IFR_MSDC0_SRC, "ifr_msdc0_src", "msdc50_0_sel", 9),
832 GATE_IFR5(CLK_IFR_MSDC1_SRC, "ifr_msdc1_src", "msdc30_1_sel", 10),
833 GATE_IFR5(CLK_IFR_MSDC2_SRC, "ifr_msdc2_src", "msdc50_2_sel", 11),
834 GATE_IFR5(CLK_IFR_PWRAP_TMR, "ifr_pwrap_tmr", "clk26m_ck", 12),
835 GATE_IFR5(CLK_IFR_PWRAP_SPI, "ifr_pwrap_spi", "clk26m_ck", 13),
836 GATE_IFR5(CLK_IFR_PWRAP_SYS, "ifr_pwrap_sys", "clk26m_ck", 14),
837 GATE_IFR5(CLK_IFR_IRRX_26M, "ifr_irrx_26m", "clk26m_ck", 22),
838 GATE_IFR5(CLK_IFR_IRRX_32K, "ifr_irrx_32k", "clk32k", 23),
839 GATE_IFR5(CLK_IFR_I2C0_AXI, "ifr_i2c0_axi", "i2c_sel", 24),
840 GATE_IFR5(CLK_IFR_I2C1_AXI, "ifr_i2c1_axi", "i2c_sel", 25),
841 GATE_IFR5(CLK_IFR_I2C2_AXI, "ifr_i2c2_axi", "i2c_sel", 26),
842 GATE_IFR5(CLK_IFR_I2C3_AXI, "ifr_i2c3_axi", "i2c_sel", 27),
843 GATE_IFR5(CLK_IFR_NIC_AXI, "ifr_nic_axi", "axi_sel", 28),
844 GATE_IFR5(CLK_IFR_NIC_SLV_AXI, "ifr_nic_slv_axi", "axi_sel", 29),
845 GATE_IFR5(CLK_IFR_APU_AXI, "ifr_apu_axi", "axi_sel", 30),
846 /* IFR6 */
847 GATE_IFR6(CLK_IFR_NFIECC, "ifr_nfiecc", "nfiecc_sel", 0),
848 GATE_IFR6(CLK_IFR_NFI1X_BK, "ifr_nfi1x_bk", "nfi2x_sel", 1),
849 GATE_IFR6(CLK_IFR_NFIECC_BK, "ifr_nfiecc_bk", "nfi2x_sel", 2),
850 GATE_IFR6(CLK_IFR_NFI_BK, "ifr_nfi_bk", "axi_sel", 3),
851 GATE_IFR6(CLK_IFR_MSDC2_AP_BK, "ifr_msdc2_ap_bk", "axi_sel", 4),
852 GATE_IFR6(CLK_IFR_MSDC2_MD_BK, "ifr_msdc2_md_bk", "axi_sel", 5),
853 GATE_IFR6(CLK_IFR_MSDC2_BK, "ifr_msdc2_bk", "axi_sel", 6),
854 GATE_IFR6(CLK_IFR_SUSB_133_BK, "ifr_susb_133_bk", "axi_sel", 7),
855 GATE_IFR6(CLK_IFR_SUSB_66_BK, "ifr_susb_66_bk", "axi_sel", 8),
856 GATE_IFR6(CLK_IFR_SSUSB_SYS, "ifr_ssusb_sys", "ssusb_sys_sel", 9),
857 GATE_IFR6(CLK_IFR_SSUSB_REF, "ifr_ssusb_ref", "ssusb_sys_sel", 10),
858 GATE_IFR6(CLK_IFR_SSUSB_XHCI, "ifr_ssusb_xhci", "ssusb_xhci_sel", 11),
859
860};
861
862static const struct mtk_gate_regs peri_cg_regs = {
863 .set_ofs = 0x20c,
864 .clr_ofs = 0x20c,
865 .sta_ofs = 0x20c,
866};
867
868#define GATE_PERI(_id, _name, _parent, _shift) { \
869 .id = _id, \
870 .name = _name, \
871 .parent_name = _parent, \
872 .regs = &peri_cg_regs, \
873 .shift = _shift, \
874 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
875 }
876
877static const struct mtk_gate peri_clks[] = {
878 GATE_PERI(CLK_PERIAXI, "periaxi", "axi_sel", 31),
879};
880
881#define MT8168_PLL_FMAX (3800UL * MHZ)
882#define MT8168_PLL_FMIN (1500UL * MHZ)
883#define CON0_MT8168_RST_BAR BIT(23)
884
885#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
886 _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
887 _tuner_en_bit, _pcw_reg, _pcw_shift, _div_table, \
888 _rst_bar_mask, _pcw_chg_reg) { \
889 .id = _id, \
890 .name = _name, \
891 .reg = _reg, \
892 .pwr_reg = _pwr_reg, \
893 .en_mask = _en_mask, \
894 .flags = _flags, \
895 .rst_bar_mask = _rst_bar_mask, \
896 .fmax = MT8168_PLL_FMAX, \
897 .fmin = MT8168_PLL_FMIN, \
898 .pcwbits = _pcwbits, \
899 .pcwibits = 8, \
900 .pd_reg = _pd_reg, \
901 .pd_shift = _pd_shift, \
902 .tuner_reg = _tuner_reg, \
903 .tuner_en_reg = _tuner_en_reg, \
904 .tuner_en_bit = _tuner_en_bit, \
905 .pcw_reg = _pcw_reg, \
906 .pcw_shift = _pcw_shift, \
907 .pcw_chg_reg = _pcw_chg_reg, \
908 .div_table = _div_table, \
909 }
910
911#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
912 _pd_reg, _pd_shift, _tuner_reg, \
913 _tuner_en_reg, _tuner_en_bit, _pcw_reg, \
914 _pcw_shift, _rst_bar_mask, _pcw_chg_reg) \
915 PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
916 _pcwbits, _pd_reg, _pd_shift, \
917 _tuner_reg, _tuner_en_reg, _tuner_en_bit, \
918 _pcw_reg, _pcw_shift, NULL, _rst_bar_mask, \
919 _pcw_chg_reg) \
920
921static const struct mtk_pll_div_table armpll_div_table[] = {
922 { .div = 0, .freq = MT8168_PLL_FMAX },
923 { .div = 1, .freq = 1500000000 },
924 { .div = 2, .freq = 750000000 },
925 { .div = 3, .freq = 375000000 },
926 { .div = 4, .freq = 182500000 },
927 { } /* sentinel */
928};
929static const struct mtk_pll_div_table mfgpll_div_table[] = {
930 { .div = 0, .freq = MT8168_PLL_FMAX },
931 { .div = 1, .freq = 1600000000 },
932 { .div = 2, .freq = 800000000 },
933 { .div = 3, .freq = 400000000 },
934 { .div = 4, .freq = 200000000 },
935 { } /* sentinel */
936};
937static const struct mtk_pll_div_table dsppll_div_table[] = {
938 { .div = 0, .freq = MT8168_PLL_FMAX },
939 { .div = 1, .freq = 1600000000 },
940 { .div = 2, .freq = 600000000 },
941 { .div = 3, .freq = 400000000 },
942 { .div = 4, .freq = 200000000 },
943 { } /* sentinel */
944};
945
946static const struct mtk_pll_data plls[] = {
947 PLL_B(CLK_APMIXED_ARMPLL, "armpll", 0x030C, 0x0318, 0x00000001, 0, 22,
948 0x0310, 24, 0, 0, 0, 0x0310, 0, armpll_div_table, 0, 0),
949 PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0228, 0x0234, 0xFF000001,
950 HAVE_RST_BAR, 22, 0x022C, 24, 0, 0, 0, 0x022C, 0,
951 CON0_MT8168_RST_BAR, 0),
952 PLL(CLK_APMIXED_UNIVPLL, "univpll2", 0x0208, 0x0214, 0xFF000001,
953 HAVE_RST_BAR, 22, 0x020C, 24, 0, 0, 0, 0x020C, 0,
954 CON0_MT8168_RST_BAR, 0),
955 PLL_B(CLK_APMIXED_MFGPLL, "mfgpll", 0x0218, 0x0224, 0x00000001, 0, 22,
956 0x021C, 24, 0, 0, 0, 0x021C, 0, mfgpll_div_table, 0, 0),
957 PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0350, 0x035C, 0x00000001, 0, 22,
958 0x0354, 24, 0, 0, 0, 0x0354, 0, 0, 0),
959 PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0330, 0x033C, 0x00000001, 0, 22,
960 0x0334, 24, 0, 0, 0, 0x0334, 0, 0, 0),
961 PLL(CLK_APMIXED_APLL1, "apll1", 0x031C, 0x032C, 0x00000001, 0, 32,
962 0x0320, 24, 0x0040, 0x000C, 0, 0x0324, 0, 0, 0x0320),
963 PLL(CLK_APMIXED_APLL2, "apll2", 0x0360, 0x0370, 0x00000001, 0, 32,
964 0x0364, 24, 0x004C, 0x000C, 5, 0x0368, 0, 0, 0x0364),
965 PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0374, 0x0380, 0x00000001, 0, 22,
966 0x0378, 24, 0, 0, 0, 0x0378, 0, 0, 0),
967 PLL_B(CLK_APMIXED_DSPPLL, "dsppll", 0x0390, 0x039C, 0x00000001, 0, 22,
968 0x0394, 24, 0, 0, 0, 0x0394, 0, dsppll_div_table, 0, 0),
969 PLL(CLK_APMIXED_APUPLL, "apupll", 0x03A0, 0x03AC, 0x00000001, 0, 22,
970 0x03A4, 24, 0, 0, 0, 0x03A4, 0, 0, 0),
971};
972
973static const struct mtk_fixed_factor top_early_divs[] = {
974 FACTOR(CLK_TOP_SYS_26M_D2, "sys_26m_d2", "clk26m", 1, 2),
975};
976
977static struct clk_onecell_data *top_clk_data;
978
979static void clk_mt8168_top_init_early(struct device_node *node)
980{
981 int r, i;
982
983 if (!top_clk_data) {
984 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
985
986 for (i = 0; i < CLK_TOP_NR_CLK; i++)
987 top_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
988 }
989
990 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
991 top_clk_data);
992
993 r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
994 if (r)
995 pr_err("%s(): could not register clock provider: %d\n",
996 __func__, r);
997}
998
999CLK_OF_DECLARE_DRIVER(mt8168_topckgen, "mediatek,mt8168-topckgen",
1000 clk_mt8168_top_init_early);
1001
1002static int clk_mt8168_top_probe(struct platform_device *pdev)
1003{
1004 int r;
1005 struct device_node *node = pdev->dev.of_node;
1006 void __iomem *base;
1007 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1008
1009 base = devm_ioremap_resource(&pdev->dev, res);
1010 if (IS_ERR(base)) {
1011 pr_err("%s(): ioremap failed\n", __func__);
1012 return PTR_ERR(base);
1013 }
1014
1015 if (!top_clk_data)
1016 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1017
1018 mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
1019 top_clk_data);
1020 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
1021 top_clk_data);
1022 mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
1023 mtk_clk_register_muxes(top_muxes, ARRAY_SIZE(top_muxes),
1024 node, &mt8168_clk_lock, top_clk_data);
1025 mtk_clk_register_composites(top_misc_muxes, ARRAY_SIZE(top_misc_muxes),
1026 base, &mt8168_clk_lock, top_clk_data);
1027 mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs), base,
1028 &mt8168_clk_lock, top_clk_data);
1029 mtk_clk_register_fixup_dividers(top_fixup_divs,
1030 ARRAY_SIZE(top_fixup_divs), base,
1031 &mt8168_clk_lock, top_clk_data);
1032 mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
1033 top_clk_data);
1034
1035 r = of_clk_add_provider(node, of_clk_src_onecell_get, top_clk_data);
1036
1037 if (r)
1038 pr_err("%s(): could not register clock provider: %d\n",
1039 __func__, r);
1040
1041 return r;
1042}
1043
1044static int clk_mt8168_infra_probe(struct platform_device *pdev)
1045{
1046 struct clk_onecell_data *clk_data;
1047 struct device_node *node = pdev->dev.of_node;
1048 int r;
1049
1050 clk_data = mtk_alloc_clk_data(CLK_IFR_NR_CLK);
1051
1052 mtk_clk_register_gates(node, ifr_clks, ARRAY_SIZE(ifr_clks),
1053 clk_data);
1054
1055 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1056
1057 if (r)
1058 pr_err("%s(): could not register clock provider: %d\n",
1059 __func__, r);
1060
1061 return r;
1062}
1063
1064static int clk_mt8168_peri_probe(struct platform_device *pdev)
1065{
1066 struct clk_onecell_data *clk_data;
1067 int r;
1068 struct device_node *node = pdev->dev.of_node;
1069
1070 clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
1071
1072 mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
1073 clk_data);
1074
1075 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1076
1077 if (r)
1078 pr_err("%s(): could not register clock provider: %d\n",
1079 __func__, r);
1080
1081 return r;
1082}
1083
1084static int clk_mt8168_apmixed_probe(struct platform_device *pdev)
1085{
1086 struct clk_onecell_data *clk_data;
1087 int r;
1088 struct device_node *node = pdev->dev.of_node;
1089 void __iomem *base;
1090 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1091
1092 base = devm_ioremap_resource(&pdev->dev, res);
1093 if (IS_ERR(base)) {
1094 pr_err("%s(): ioremap failed\n", __func__);
1095 return PTR_ERR(base);
1096 }
1097
1098 clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
1099
1100 mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
1101
1102 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1103
1104 if (r)
1105 pr_err("%s(): could not register clock provider: %d\n",
1106 __func__, r);
1107
1108 return r;
1109}
1110
1111static int clk_mt8168_mcu_probe(struct platform_device *pdev)
1112{
1113 struct clk_onecell_data *clk_data;
1114 int r;
1115 struct device_node *node = pdev->dev.of_node;
1116 void __iomem *base;
1117 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1118
1119 base = devm_ioremap_resource(&pdev->dev, res);
1120 if (IS_ERR(base)) {
1121 pr_err("%s(): ioremap failed\n", __func__);
1122 return PTR_ERR(base);
1123 }
1124
1125 clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
1126
1127 mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes),
1128 base, &mt8168_clk_lock, clk_data);
1129
1130 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1131
1132 if (r)
1133 pr_err("%s(): could not register clock provider: %d\n",
1134 __func__, r);
1135
1136 return r;
1137}
1138
1139static const struct of_device_id of_match_clk_mt8168[] = {
1140 {
1141 .compatible = "mediatek,mt8168-apmixedsys",
1142 .data = clk_mt8168_apmixed_probe,
1143 }, {
1144 .compatible = "mediatek,mt8168-topckgen",
1145 .data = clk_mt8168_top_probe,
1146 }, {
1147 .compatible = "mediatek,mt8168-infracfg",
1148 .data = clk_mt8168_infra_probe,
1149 }, {
1150 .compatible = "mediatek,mt8168-pericfg",
1151 .data = clk_mt8168_peri_probe,
1152 }, {
1153 .compatible = "mediatek,mt8168-mcucfg",
1154 .data = clk_mt8168_mcu_probe,
1155 }, {
1156 /* sentinel */
1157 }
1158};
1159
1160static int clk_mt8168_probe(struct platform_device *pdev)
1161{
1162 int (*clk_probe)(struct platform_device *p);
1163 int r;
1164
1165 clk_probe = of_device_get_match_data(&pdev->dev);
1166 if (!clk_probe)
1167 return -EINVAL;
1168
1169 r = clk_probe(pdev);
1170 if (r)
1171 dev_err(&pdev->dev,
1172 "could not register clock provider: %s: %d\n",
1173 pdev->name, r);
1174
1175 return r;
1176}
1177
1178static struct platform_driver clk_mt8168_drv = {
1179 .probe = clk_mt8168_probe,
1180 .driver = {
1181 .name = "clk-mt8168",
1182 .owner = THIS_MODULE,
1183 .of_match_table = of_match_clk_mt8168,
1184 },
1185};
1186
1187static int __init clk_mt8168_init(void)
1188{
1189 return platform_driver_register(&clk_mt8168_drv);
1190}
1191
1192arch_initcall(clk_mt8168_init);