blob: 5c9ba2971b9b310d36b52fc029fd70b5abee80d9 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 * Author: Weiyi Lu <weiyi.lu@mediatek.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/delay.h>
16#include <linux/mfd/syscon.h>
17#include <linux/of.h>
18#include <linux/of_address.h>
19#include <linux/of_device.h>
20#include <linux/platform_device.h>
21#include <linux/slab.h>
22
23#include "clk-mtk.h"
24#include "clk-mux.h"
25#include "clk-gate.h"
26
27#include <dt-bindings/clock/mt8183-clk.h>
28
29static DEFINE_SPINLOCK(mt8183_clk_lock);
30
31static const struct mtk_fixed_clk top_fixed_clks[] = {
32 FIXED_CLK(CLK_TOP_CLK26M, "f_f26m_ck", "clk26m", 26000000),
33 FIXED_CLK(CLK_TOP_ULPOSC, "osc", NULL, 250000),
34 FIXED_CLK(CLK_TOP_UNIVP_192M, "univpll_192m", "univpll", 192000000),
35};
36
37static const struct mtk_fixed_factor top_divs[] = {
38 FACTOR(CLK_TOP_CLK13M, "clk13m", "clk26m", 1,
39 2),
40 FACTOR(CLK_TOP_F26M_CK_D2, "csw_f26m_ck_d2", "clk26m", 1,
41 2),
42 FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1,
43 1),
44 FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1,
45 2),
46 FACTOR(CLK_TOP_SYSPLL_D2_D2, "syspll_d2_d2", "syspll_d2", 1,
47 2),
48 FACTOR(CLK_TOP_SYSPLL_D2_D4, "syspll_d2_d4", "syspll_d2", 1,
49 4),
50 FACTOR(CLK_TOP_SYSPLL_D2_D8, "syspll_d2_d8", "syspll_d2", 1,
51 8),
52 FACTOR(CLK_TOP_SYSPLL_D2_D16, "syspll_d2_d16", "syspll_d2", 1,
53 16),
54 FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1,
55 3),
56 FACTOR(CLK_TOP_SYSPLL_D3_D2, "syspll_d3_d2", "syspll_d3", 1,
57 2),
58 FACTOR(CLK_TOP_SYSPLL_D3_D4, "syspll_d3_d4", "syspll_d3", 1,
59 4),
60 FACTOR(CLK_TOP_SYSPLL_D3_D8, "syspll_d3_d8", "syspll_d3", 1,
61 8),
62 FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1,
63 5),
64 FACTOR(CLK_TOP_SYSPLL_D5_D2, "syspll_d5_d2", "syspll_d5", 1,
65 2),
66 FACTOR(CLK_TOP_SYSPLL_D5_D4, "syspll_d5_d4", "syspll_d5", 1,
67 4),
68 FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1,
69 7),
70 FACTOR(CLK_TOP_SYSPLL_D7_D2, "syspll_d7_d2", "syspll_d7", 1,
71 2),
72 FACTOR(CLK_TOP_SYSPLL_D7_D4, "syspll_d7_d4", "syspll_d7", 1,
73 4),
74 FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1,
75 1),
76 FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1,
77 2),
78 FACTOR(CLK_TOP_UNIVPLL_D2_D2, "univpll_d2_d2", "univpll_d2", 1,
79 2),
80 FACTOR(CLK_TOP_UNIVPLL_D2_D4, "univpll_d2_d4", "univpll_d2", 1,
81 4),
82 FACTOR(CLK_TOP_UNIVPLL_D2_D8, "univpll_d2_d8", "univpll_d2", 1,
83 8),
84 FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1,
85 3),
86 FACTOR(CLK_TOP_UNIVPLL_D3_D2, "univpll_d3_d2", "univpll_d3", 1,
87 2),
88 FACTOR(CLK_TOP_UNIVPLL_D3_D4, "univpll_d3_d4", "univpll_d3", 1,
89 4),
90 FACTOR(CLK_TOP_UNIVPLL_D3_D8, "univpll_d3_d8", "univpll_d3", 1,
91 8),
92 FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1,
93 5),
94 FACTOR(CLK_TOP_UNIVPLL_D5_D2, "univpll_d5_d2", "univpll_d5", 1,
95 2),
96 FACTOR(CLK_TOP_UNIVPLL_D5_D4, "univpll_d5_d4", "univpll_d5", 1,
97 4),
98 FACTOR(CLK_TOP_UNIVPLL_D5_D8, "univpll_d5_d8", "univpll_d5", 1,
99 8),
100 FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1,
101 7),
102 FACTOR(CLK_TOP_UNIVP_192M_CK, "univ_192m_ck", "univpll_192m", 1,
103 1),
104 FACTOR(CLK_TOP_UNIVP_192M_D2, "univ_192m_d2", "univ_192m_ck", 1,
105 2),
106 FACTOR(CLK_TOP_UNIVP_192M_D4, "univ_192m_d4", "univ_192m_ck", 1,
107 4),
108 FACTOR(CLK_TOP_UNIVP_192M_D8, "univ_192m_d8", "univ_192m_ck", 1,
109 8),
110 FACTOR(CLK_TOP_UNIVP_192M_D16, "univ_192m_d16", "univ_192m_ck", 1,
111 16),
112 FACTOR(CLK_TOP_UNIVP_192M_D32, "univ_192m_d32", "univ_192m_ck", 1,
113 32),
114 FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1,
115 1),
116 FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1", 1,
117 2),
118 FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1", 1,
119 4),
120 FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1", 1,
121 8),
122 FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1,
123 1),
124 FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2", 1,
125 2),
126 FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2", 1,
127 4),
128 FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2", 1,
129 8),
130 FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1,
131 1),
132 FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1,
133 2),
134 FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll", 1,
135 4),
136 FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll", 1,
137 8),
138 FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll", 1,
139 16),
140 FACTOR(CLK_TOP_MMPLL_CK, "mmpll_ck", "mmpll", 1,
141 1),
142 FACTOR(CLK_TOP_MMPLL_D4, "mmpll_d4", "mmpll", 1,
143 4),
144 FACTOR(CLK_TOP_MMPLL_D4_D2, "mmpll_d4_d2", "mmpll_d4", 1,
145 2),
146 FACTOR(CLK_TOP_MMPLL_D4_D4, "mmpll_d4_d4", "mmpll_d4", 1,
147 4),
148 FACTOR(CLK_TOP_MMPLL_D5, "mmpll_d5", "mmpll", 1,
149 5),
150 FACTOR(CLK_TOP_MMPLL_D5_D2, "mmpll_d5_d2", "mmpll_d5", 1,
151 2),
152 FACTOR(CLK_TOP_MMPLL_D5_D4, "mmpll_d5_d4", "mmpll_d5", 1,
153 4),
154 FACTOR(CLK_TOP_MMPLL_D6, "mmpll_d6", "mmpll", 1,
155 6),
156 FACTOR(CLK_TOP_MMPLL_D7, "mmpll_d7", "mmpll", 1,
157 7),
158 FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1,
159 1),
160 FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1,
161 1),
162 FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll", 1,
163 2),
164 FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll", 1,
165 4),
166 FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll", 1,
167 8),
168 FACTOR(CLK_TOP_MSDCPLL_D16, "msdcpll_d16", "msdcpll", 1,
169 16),
170 FACTOR(CLK_TOP_AD_OSC_CK, "ad_osc_ck", "osc", 1,
171 1),
172 FACTOR(CLK_TOP_OSC_D2, "osc_d2", "osc", 1,
173 2),
174 FACTOR(CLK_TOP_OSC_D4, "osc_d4", "osc", 1,
175 4),
176 FACTOR(CLK_TOP_OSC_D8, "osc_d8", "osc", 1,
177 8),
178 FACTOR(CLK_TOP_OSC_D16, "osc_d16", "osc", 1,
179 16),
180 FACTOR(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1,
181 2),
182};
183
184static const char * const axi_parents[] = {
185 "clk26m",
186 "syspll_d2_d4",
187 "syspll_d7",
188 "osc_d4"
189};
190
191static const char * const mm_parents[] = {
192 "clk26m",
193 "mmpll_d7",
194 "syspll_d3",
195 "univpll_d2_d2",
196 "syspll_d2_d2",
197 "syspll_d3_d2"
198};
199
200static const char * const img_parents[] = {
201 "clk26m",
202 "mmpll_d6",
203 "univpll_d3",
204 "syspll_d3",
205 "univpll_d2_d2",
206 "syspll_d2_d2",
207 "univpll_d3_d2",
208 "syspll_d3_d2"
209};
210
211static const char * const cam_parents[] = {
212 "clk26m",
213 "syspll_d2",
214 "mmpll_d6",
215 "syspll_d3",
216 "mmpll_d7",
217 "univpll_d3",
218 "univpll_d2_d2",
219 "syspll_d2_d2",
220 "syspll_d3_d2",
221 "univpll_d3_d2"
222};
223
224static const char * const dsp_parents[] = {
225 "clk26m",
226 "mmpll_d6",
227 "mmpll_d7",
228 "univpll_d3",
229 "syspll_d3",
230 "univpll_d2_d2",
231 "syspll_d2_d2",
232 "univpll_d3_d2",
233 "syspll_d3_d2"
234};
235
236static const char * const dsp1_parents[] = {
237 "clk26m",
238 "mmpll_d6",
239 "mmpll_d7",
240 "univpll_d3",
241 "syspll_d3",
242 "univpll_d2_d2",
243 "syspll_d2_d2",
244 "univpll_d3_d2",
245 "syspll_d3_d2"
246};
247
248static const char * const dsp2_parents[] = {
249 "clk26m",
250 "mmpll_d6",
251 "mmpll_d7",
252 "univpll_d3",
253 "syspll_d3",
254 "univpll_d2_d2",
255 "syspll_d2_d2",
256 "univpll_d3_d2",
257 "syspll_d3_d2"
258};
259
260static const char * const ipu_if_parents[] = {
261 "clk26m",
262 "mmpll_d6",
263 "mmpll_d7",
264 "univpll_d3",
265 "syspll_d3",
266 "univpll_d2_d2",
267 "syspll_d2_d2",
268 "univpll_d3_d2",
269 "syspll_d3_d2"
270};
271
272static const char * const mfg_parents[] = {
273 "clk26m",
274 "mfgpll_ck",
275 "univpll_d3",
276 "syspll_d3"
277};
278
279static const char * const f52m_mfg_parents[] = {
280 "clk26m",
281 "univpll_d3_d2",
282 "univpll_d3_d4",
283 "univpll_d3_d8"
284};
285
286static const char * const camtg_parents[] = {
287 "clk26m",
288 "univ_192m_d8",
289 "univpll_d3_d8",
290 "univ_192m_d4",
291 "univpll_d3_d16",
292 "csw_f26m_ck_d2",
293 "univ_192m_d16",
294 "univ_192m_d32"
295};
296
297static const char * const camtg2_parents[] = {
298 "clk26m",
299 "univ_192m_d8",
300 "univpll_d3_d8",
301 "univ_192m_d4",
302 "univpll_d3_d16",
303 "csw_f26m_ck_d2",
304 "univ_192m_d16",
305 "univ_192m_d32"
306};
307
308static const char * const camtg3_parents[] = {
309 "clk26m",
310 "univ_192m_d8",
311 "univpll_d3_d8",
312 "univ_192m_d4",
313 "univpll_d3_d16",
314 "csw_f26m_ck_d2",
315 "univ_192m_d16",
316 "univ_192m_d32"
317};
318
319static const char * const camtg4_parents[] = {
320 "clk26m",
321 "univ_192m_d8",
322 "univpll_d3_d8",
323 "univ_192m_d4",
324 "univpll_d3_d16",
325 "csw_f26m_ck_d2",
326 "univ_192m_d16",
327 "univ_192m_d32"
328};
329
330static const char * const uart_parents[] = {
331 "clk26m",
332 "univpll_d3_d8"
333};
334
335static const char * const spi_parents[] = {
336 "clk26m",
337 "syspll_d5_d2",
338 "syspll_d3_d4",
339 "msdcpll_d4"
340};
341
342static const char * const msdc50_hclk_parents[] = {
343 "clk26m",
344 "syspll_d2_d2",
345 "syspll_d3_d2"
346};
347
348static const char * const msdc50_0_parents[] = {
349 "clk26m",
350 "msdcpll_ck",
351 "msdcpll_d2",
352 "univpll_d2_d4",
353 "syspll_d3_d2",
354 "univpll_d2_d2"
355};
356
357static const char * const msdc30_1_parents[] = {
358 "clk26m",
359 "univpll_d3_d2",
360 "syspll_d3_d2",
361 "syspll_d7",
362 "msdcpll_d2"
363};
364
365static const char * const msdc30_2_parents[] = {
366 "clk26m",
367 "univpll_d3_d2",
368 "syspll_d3_d2",
369 "syspll_d7",
370 "msdcpll_d2"
371};
372
373static const char * const audio_parents[] = {
374 "clk26m",
375 "syspll_d5_d4",
376 "syspll_d7_d4",
377 "syspll_d2_d16"
378};
379
380static const char * const aud_intbus_parents[] = {
381 "clk26m",
382 "syspll_d2_d4",
383 "syspll_d7_d2"
384};
385
386static const char * const pmicspi_parents[] = {
387 "clk26m",
388 "syspll_d2_d8",
389 "osc_d8"
390};
391
392static const char * const fpwrap_ulposc_parents[] = {
393 "clk26m",
394 "osc_d16",
395 "osc_d4",
396 "osc_d8"
397};
398
399static const char * const atb_parents[] = {
400 "clk26m",
401 "syspll_d2_d2",
402 "syspll_d5"
403};
404
405static const char * const sspm_parents[] = {
406 "clk26m",
407 "univpll_d2_d4",
408 "syspll_d2_d2",
409 "univpll_d2_d2",
410 "syspll_d3"
411};
412
413static const char * const dpi0_parents[] = {
414 "clk26m",
415 "tvdpll_d2",
416 "tvdpll_d4",
417 "tvdpll_d8",
418 "tvdpll_d16",
419 "univpll_d5_d2",
420 "univpll_d3_d4",
421 "syspll_d3_d4",
422 "univpll_d3_d8"
423};
424
425static const char * const scam_parents[] = {
426 "clk26m",
427 "syspll_d5_d2"
428};
429
430static const char * const disppwm_parents[] = {
431 "clk26m",
432 "univpll_d3_d4",
433 "osc_d2",
434 "osc_d4",
435 "osc_d16"
436};
437
438static const char * const usb_top_parents[] = {
439 "clk26m",
440 "univpll_d5_d4",
441 "univpll_d3_d4",
442 "univpll_d5_d2"
443};
444
445
446static const char * const ssusb_top_xhci_parents[] = {
447 "clk26m",
448 "univpll_d5_d4",
449 "univpll_d3_d4",
450 "univpll_d5_d2"
451};
452
453static const char * const spm_parents[] = {
454 "clk26m",
455 "syspll_d2_d8"
456};
457
458static const char * const i2c_parents[] = {
459 "clk26m",
460 "syspll_d2_d8",
461 "univpll_d5_d2"
462};
463
464static const char * const scp_parents[] = {
465 "clk26m",
466 "univpll_d2_d8",
467 "syspll_d5",
468 "syspll_d2_d2",
469 "univpll_d2_d2",
470 "syspll_d3",
471 "univpll_d3"
472};
473
474static const char * const seninf_parents[] = {
475 "clk26m",
476 "univpll_d2_d2",
477 "univpll_d3_d2",
478 "univpll_d2_d4"
479};
480
481static const char * const dxcc_parents[] = {
482 "clk26m",
483 "syspll_d2_d2",
484 "syspll_d2_d4",
485 "syspll_d2_d8"
486};
487
488static const char * const aud_engen1_parents[] = {
489 "clk26m",
490 "apll1_d2",
491 "apll1_d4",
492 "apll1_d8"
493};
494
495static const char * const aud_engen2_parents[] = {
496 "clk26m",
497 "apll2_d2",
498 "apll2_d4",
499 "apll2_d8"
500};
501
502static const char * const faes_ufsfde_parents[] = {
503 "clk26m",
504 "syspll_d2",
505 "syspll_d2_d2",
506 "syspll_d3",
507 "syspll_d2_d4",
508 "univpll_d3"
509};
510
511static const char * const fufs_parents[] = {
512 "clk26m",
513 "syspll_d2_d4",
514 "syspll_d2_d8",
515 "syspll_d2_d16"
516};
517
518static const char * const aud_1_parents[] = {
519 "clk26m",
520 "apll1_ck"
521};
522
523static const char * const aud_2_parents[] = {
524 "clk26m",
525 "apll2_ck"
526};
527
528static const struct mtk_mux top_muxes[] = {
529 /* CLK_CFG_0 */
530 MUX_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_AXI, "axi_sel",
531 axi_parents, 0x40,
532 0x44, 0x48, 0, 2, 7, 0x004, 0, CLK_IS_CRITICAL),
533 MUX_CLR_SET_UPD(CLK_TOP_MUX_MM, "mm_sel",
534 mm_parents, 0x40,
535 0x44, 0x48, 8, 3, 15, 0x004, 1),
536 MUX_CLR_SET_UPD(CLK_TOP_MUX_IMG, "img_sel",
537 img_parents, 0x40,
538 0x44, 0x48, 16, 3, 23, 0x004, 2),
539 MUX_CLR_SET_UPD(CLK_TOP_MUX_CAM, "cam_sel",
540 cam_parents, 0x40,
541 0x44, 0x48, 24, 4, 31, 0x004, 3),
542 /* CLK_CFG_1 */
543 MUX_CLR_SET_UPD(CLK_TOP_MUX_DSP, "dsp_sel",
544 dsp_parents, 0x50,
545 0x54, 0x58, 0, 4, 7, 0x004, 4),
546 MUX_CLR_SET_UPD(CLK_TOP_MUX_DSP1, "dsp1_sel",
547 dsp1_parents, 0x50,
548 0x54, 0x58, 8, 4, 15, 0x004, 5),
549 MUX_CLR_SET_UPD(CLK_TOP_MUX_DSP2, "dsp2_sel",
550 dsp2_parents, 0x50,
551 0x54, 0x58, 16, 4, 23, 0x004, 6),
552 MUX_CLR_SET_UPD(CLK_TOP_MUX_IPU_IF, "ipu_if_sel",
553 ipu_if_parents, 0x50,
554 0x54, 0x58, 24, 4, 31, 0x004, 7),
555 /* CLK_CFG_2 */
556 MUX_CLR_SET_UPD(CLK_TOP_MUX_MFG, "mfg_sel",
557 mfg_parents, 0x60,
558 0x64, 0x68, 0, 2, 7, 0x004, 8),
559 MUX_CLR_SET_UPD(CLK_TOP_MUX_F52M_MFG, "f52m_mfg_sel",
560 f52m_mfg_parents, 0x60,
561 0x64, 0x68, 8, 2, 15, 0x004, 9),
562 MUX_CLR_SET_UPD(CLK_TOP_MUX_CAMTG, "camtg_sel",
563 camtg_parents, 0x60,
564 0x64, 0x68, 16, 3, 23, 0x004, 10),
565 MUX_CLR_SET_UPD(CLK_TOP_MUX_CAMTG2, "camtg2_sel",
566 camtg2_parents, 0x60,
567 0x64, 0x68, 24, 3, 31, 0x004, 11),
568 /* CLK_CFG_3 */
569 MUX_CLR_SET_UPD(CLK_TOP_MUX_CAMTG3, "camtg3_sel",
570 camtg3_parents, 0x70,
571 0x74, 0x78, 0, 3, 7, 0x004, 12),
572 MUX_CLR_SET_UPD(CLK_TOP_MUX_CAMTG4, "camtg4_sel",
573 camtg4_parents, 0x70,
574 0x74, 0x78, 8, 3, 15, 0x004, 13),
575 MUX_CLR_SET_UPD(CLK_TOP_MUX_UART, "uart_sel",
576 uart_parents, 0x70,
577 0x74, 0x78, 16, 1, 23, 0x004, 14),
578 MUX_CLR_SET_UPD(CLK_TOP_MUX_SPI, "spi_sel",
579 spi_parents, 0x70,
580 0x74, 0x78, 24, 2, 31, 0x004, 15),
581 /* CLK_CFG_4 */
582 MUX_CLR_SET_UPD(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_hclk_sel",
583 msdc50_hclk_parents, 0x80,
584 0x84, 0x88, 0, 2, 7, 0x004, 16),
585 MUX_CLR_SET_UPD(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel",
586 msdc50_0_parents, 0x80,
587 0x84, 0x88, 8, 3, 15, 0x004, 17),
588 MUX_CLR_SET_UPD(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel",
589 msdc30_1_parents, 0x80,
590 0x84, 0x88, 16, 3, 23, 0x004, 18),
591 MUX_CLR_SET_UPD(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel",
592 msdc30_2_parents, 0x80,
593 0x84, 0x88, 24, 3, 31, 0x004, 19),
594 /* CLK_CFG_5 */
595 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUDIO, "audio_sel",
596 audio_parents, 0x90,
597 0x94, 0x98, 0, 2, 7, 0x004, 20),
598 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel",
599 aud_intbus_parents, 0x90,
600 0x94, 0x98, 8, 2, 15, 0x004, 21),
601 MUX_CLR_SET_UPD(CLK_TOP_MUX_PMICSPI, "pmicspi_sel",
602 pmicspi_parents, 0x90,
603 0x94, 0x98, 16, 2, 23, 0x004, 22),
604 MUX_CLR_SET_UPD(CLK_TOP_MUX_FPWRAP_ULPOSC, "fpwrap_ulposc_sel",
605 fpwrap_ulposc_parents, 0x90,
606 0x94, 0x98, 24, 2, 31, 0x004, 23),
607 /* CLK_CFG_6 */
608 MUX_CLR_SET_UPD(CLK_TOP_MUX_ATB, "atb_sel",
609 atb_parents, 0xa0,
610 0xa4, 0xa8, 0, 2, 7, 0x004, 24),
611 MUX_CLR_SET_UPD(CLK_TOP_MUX_SSPM, "sspm_sel",
612 sspm_parents, 0xa0,
613 0xa4, 0xa8, 8, 3, 15, 0x004, 25),
614 MUX_CLR_SET_UPD(CLK_TOP_MUX_DPI0, "dpi0_sel",
615 dpi0_parents, 0xa0,
616 0xa4, 0xa8, 16, 4, 23, 0x004, 26),
617 MUX_CLR_SET_UPD(CLK_TOP_MUX_SCAM, "scam_sel",
618 scam_parents, 0xa0,
619 0xa4, 0xa8, 24, 1, 31, 0x004, 27),
620 /* CLK_CFG_7 */
621 MUX_CLR_SET_UPD(CLK_TOP_MUX_DISP_PWM, "disppwm_sel",
622 disppwm_parents, 0xb0,
623 0xb4, 0xb8, 0, 3, 7, 0x004, 28),
624 MUX_CLR_SET_UPD(CLK_TOP_MUX_USB_TOP, "usb_top_sel",
625 usb_top_parents, 0xb0,
626 0xb4, 0xb8, 8, 2, 15, 0x004, 29),
627 MUX_CLR_SET_UPD(CLK_TOP_MUX_SSUSB_TOP_XHCI, "ssusb_top_xhci_sel",
628 ssusb_top_xhci_parents, 0xb0,
629 0xb4, 0xb8, 16, 2, 23, 0x004, 30),
630 MUX_CLR_SET_UPD_FLAGS(CLK_TOP_MUX_SPM, "spm_sel",
631 spm_parents, 0xb0,
632 0xb4, 0xb8, 24, 1, 31, 0x008, 0, CLK_IS_CRITICAL),
633 /* CLK_CFG_8 */
634 MUX_CLR_SET_UPD(CLK_TOP_MUX_I2C, "i2c_sel",
635 i2c_parents, 0xc0,
636 0xc4, 0xc8, 0, 2, 7, 0x008, 1),
637 MUX_CLR_SET_UPD(CLK_TOP_MUX_SCP, "scp_sel",
638 scp_parents, 0xc0,
639 0xc4, 0xc8, 8, 3, 15, 0x008, 2),
640 MUX_CLR_SET_UPD(CLK_TOP_MUX_SENINF, "seninf_sel",
641 seninf_parents, 0xc0,
642 0xc4, 0xc8, 16, 2, 23, 0x008, 3),
643 MUX_CLR_SET_UPD(CLK_TOP_MUX_DXCC, "dxcc_sel",
644 dxcc_parents, 0xc0,
645 0xc4, 0xc8, 24, 2, 31, 0x008, 4),
646 /* CLK_CFG_9 */
647 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG1, "aud_eng1_sel",
648 aud_engen1_parents, 0xd0,
649 0xd4, 0xd8, 0, 2, 7, 0x008, 5),
650 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUD_ENG2, "aud_eng2_sel",
651 aud_engen2_parents, 0xd0,
652 0xd4, 0xd8, 8, 2, 15, 0x008, 6),
653 MUX_CLR_SET_UPD(CLK_TOP_MUX_FAES_UFSFDE, "faes_ufsfde_sel",
654 faes_ufsfde_parents, 0xd0,
655 0xd4, 0xd8, 16, 3, 23, 0x008, 7),
656 MUX_CLR_SET_UPD(CLK_TOP_MUX_FUFS, "fufs_sel",
657 fufs_parents, 0xd0,
658 0xd4, 0xd8, 24, 2, 31, 0x008, 8),
659 /* CLK_CFG_10 */
660 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUD_1, "aud_1_sel",
661 aud_1_parents, 0xe0,
662 0xe4, 0xe8, 0, 1, 7, 0x008, 9),
663 MUX_CLR_SET_UPD(CLK_TOP_MUX_AUD_2, "aud_2_sel",
664 aud_2_parents, 0xe0,
665 0xe4, 0xe8, 8, 1, 15, 0x008, 10),
666};
667
668static const char * const apll_i2s0_parents[] = {
669 "aud_1_sel",
670 "aud_2_sel"
671};
672
673static const char * const apll_i2s1_parents[] = {
674 "aud_1_sel",
675 "aud_2_sel"
676};
677
678static const char * const apll_i2s2_parents[] = {
679 "aud_1_sel",
680 "aud_2_sel"
681};
682
683static const char * const apll_i2s3_parents[] = {
684 "aud_1_sel",
685 "aud_2_sel"
686};
687
688static const char * const apll_i2s4_parents[] = {
689 "aud_1_sel",
690 "aud_2_sel"
691};
692
693static const char * const apll_i2s5_parents[] = {
694 "aud_1_sel",
695 "aud_2_sel"
696};
697
698static struct mtk_composite top_aud_muxes[] = {
699 MUX(CLK_TOP_MUX_APLL_I2S0, "apll_i2s0_sel", apll_i2s0_parents,
700 0x320, 8, 1),
701 MUX(CLK_TOP_MUX_APLL_I2S1, "apll_i2s1_sel", apll_i2s1_parents,
702 0x320, 9, 1),
703 MUX(CLK_TOP_MUX_APLL_I2S2, "apll_i2s2_sel", apll_i2s2_parents,
704 0x320, 10, 1),
705 MUX(CLK_TOP_MUX_APLL_I2S3, "apll_i2s3_sel", apll_i2s3_parents,
706 0x320, 11, 1),
707 MUX(CLK_TOP_MUX_APLL_I2S4, "apll_i2s4_sel", apll_i2s4_parents,
708 0x320, 12, 1),
709 MUX(CLK_TOP_MUX_APLL_I2S5, "apll_i2s5_sel", apll_i2s5_parents,
710 0x328, 20, 1),
711};
712
713static const char * const mcu_mp0_parents[] = {
714 "clk26m",
715 "armpll_ll",
716 "armpll_div_pll1",
717 "armpll_div_pll2"
718};
719
720static const char * const mcu_mp2_parents[] = {
721 "clk26m",
722 "armpll_l",
723 "armpll_div_pll1",
724 "armpll_div_pll2"
725};
726
727static const char * const mcu_bus_parents[] = {
728 "clk26m",
729 "ccipll",
730 "armpll_div_pll1",
731 "armpll_div_pll2"
732};
733
734static struct mtk_composite mcu_muxes[] = {
735 /* mp0_pll_divider_cfg */
736 MUX(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0, 9, 2),
737 /* mp2_pll_divider_cfg */
738 MUX(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8, 9, 2),
739 /* bus_pll_divider_cfg */
740 MUX(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0, 9, 2),
741};
742
743static struct mtk_composite top_aud_divs[] = {
744 DIV_GATE(CLK_TOP_APLL12_DIV0, "apll12_div0", "apll_i2s0_sel",
745 0x320, 2, 0x324, 8, 0),
746 DIV_GATE(CLK_TOP_APLL12_DIV1, "apll12_div1", "apll_i2s1_sel",
747 0x320, 3, 0x324, 8, 8),
748 DIV_GATE(CLK_TOP_APLL12_DIV2, "apll12_div2", "apll_i2s2_sel",
749 0x320, 4, 0x324, 8, 16),
750 DIV_GATE(CLK_TOP_APLL12_DIV3, "apll12_div3", "apll_i2s3_sel",
751 0x320, 5, 0x324, 8, 24),
752 DIV_GATE(CLK_TOP_APLL12_DIV4, "apll12_div4", "apll_i2s4_sel",
753 0x320, 6, 0x328, 8, 0),
754 DIV_GATE(CLK_TOP_APLL12_DIVB, "apll12_divb", "apll12_div4",
755 0x320, 7, 0x328, 8, 8),
756};
757
758static const struct mtk_gate_regs top_cg_regs = {
759 .set_ofs = 0x104,
760 .clr_ofs = 0x104,
761 .sta_ofs = 0x104,
762};
763
764#define GATE_TOP(_id, _name, _parent, _shift) { \
765 .id = _id, \
766 .name = _name, \
767 .parent_name = _parent, \
768 .regs = &top_cg_regs, \
769 .shift = _shift, \
770 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
771 }
772
773static const struct mtk_gate top_clks[] = {
774 /* TOP */
775 GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL1, "armpll_div_pll1", "mainpll", 4),
776 GATE_TOP(CLK_TOP_ARMPLL_DIV_PLL2, "armpll_div_pll2", "univpll", 5),
777};
778
779static const struct mtk_gate_regs infra0_cg_regs = {
780 .set_ofs = 0x80,
781 .clr_ofs = 0x84,
782 .sta_ofs = 0x90,
783};
784
785static const struct mtk_gate_regs infra1_cg_regs = {
786 .set_ofs = 0x88,
787 .clr_ofs = 0x8c,
788 .sta_ofs = 0x94,
789};
790
791static const struct mtk_gate_regs infra2_cg_regs = {
792 .set_ofs = 0xa4,
793 .clr_ofs = 0xa8,
794 .sta_ofs = 0xac,
795};
796
797static const struct mtk_gate_regs infra3_cg_regs = {
798 .set_ofs = 0xc0,
799 .clr_ofs = 0xc4,
800 .sta_ofs = 0xc8,
801};
802
803#define GATE_INFRA0(_id, _name, _parent, _shift) { \
804 .id = _id, \
805 .name = _name, \
806 .parent_name = _parent, \
807 .regs = &infra0_cg_regs, \
808 .shift = _shift, \
809 .ops = &mtk_clk_gate_ops_setclr, \
810 }
811
812#define GATE_INFRA1(_id, _name, _parent, _shift) { \
813 .id = _id, \
814 .name = _name, \
815 .parent_name = _parent, \
816 .regs = &infra1_cg_regs, \
817 .shift = _shift, \
818 .ops = &mtk_clk_gate_ops_setclr, \
819 }
820
821#define GATE_INFRA2(_id, _name, _parent, _shift) { \
822 .id = _id, \
823 .name = _name, \
824 .parent_name = _parent, \
825 .regs = &infra2_cg_regs, \
826 .shift = _shift, \
827 .ops = &mtk_clk_gate_ops_setclr, \
828 }
829
830#define GATE_INFRA3(_id, _name, _parent, _shift) { \
831 .id = _id, \
832 .name = _name, \
833 .parent_name = _parent, \
834 .regs = &infra3_cg_regs, \
835 .shift = _shift, \
836 .ops = &mtk_clk_gate_ops_setclr, \
837 }
838
839static const struct mtk_gate infra_clks[] = {
840 /* INFRA0 */
841 GATE_INFRA0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr",
842 "axi_sel", 0),
843 GATE_INFRA0(CLK_INFRA_PMIC_AP, "infra_pmic_ap",
844 "axi_sel", 1),
845 GATE_INFRA0(CLK_INFRA_PMIC_MD, "infra_pmic_md",
846 "axi_sel", 2),
847 GATE_INFRA0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn",
848 "axi_sel", 3),
849 GATE_INFRA0(CLK_INFRA_SCPSYS, "infra_scp",
850 "axi_sel", 4),
851 GATE_INFRA0(CLK_INFRA_SEJ, "infra_sej",
852 "f_f26m_ck", 5),
853 GATE_INFRA0(CLK_INFRA_APXGPT, "infra_apxgpt",
854 "axi_sel", 6),
855 GATE_INFRA0(CLK_INFRA_ICUSB, "infra_icusb",
856 "axi_sel", 8),
857 GATE_INFRA0(CLK_INFRA_GCE, "infra_gce",
858 "axi_sel", 9),
859 GATE_INFRA0(CLK_INFRA_THERM, "infra_therm",
860 "axi_sel", 10),
861 GATE_INFRA0(CLK_INFRA_I2C0, "infra_i2c0",
862 "i2c_sel", 11),
863 GATE_INFRA0(CLK_INFRA_I2C1, "infra_i2c1",
864 "i2c_sel", 12),
865 GATE_INFRA0(CLK_INFRA_I2C2, "infra_i2c2",
866 "i2c_sel", 13),
867 GATE_INFRA0(CLK_INFRA_I2C3, "infra_i2c3",
868 "i2c_sel", 14),
869 GATE_INFRA0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk",
870 "axi_sel", 15),
871 GATE_INFRA0(CLK_INFRA_PWM1, "infra_pwm1",
872 "i2c_sel", 16),
873 GATE_INFRA0(CLK_INFRA_PWM2, "infra_pwm2",
874 "i2c_sel", 17),
875 GATE_INFRA0(CLK_INFRA_PWM3, "infra_pwm3",
876 "i2c_sel", 18),
877 GATE_INFRA0(CLK_INFRA_PWM4, "infra_pwm4",
878 "i2c_sel", 19),
879 GATE_INFRA0(CLK_INFRA_PWM, "infra_pwm",
880 "i2c_sel", 21),
881 GATE_INFRA0(CLK_INFRA_UART0, "infra_uart0",
882 "uart_sel", 22),
883 GATE_INFRA0(CLK_INFRA_UART1, "infra_uart1",
884 "uart_sel", 23),
885 GATE_INFRA0(CLK_INFRA_UART2, "infra_uart2",
886 "uart_sel", 24),
887 GATE_INFRA0(CLK_INFRA_UART3, "infra_uart3",
888 "uart_sel", 25),
889 GATE_INFRA0(CLK_INFRA_GCE_26M, "infra_gce_26m",
890 "axi_sel", 27),
891 GATE_INFRA0(CLK_INFRA_CQ_DMA_FPC, "infra_cqdma_fpc",
892 "axi_sel", 28),
893 GATE_INFRA0(CLK_INFRA_BTIF, "infra_btif",
894 "axi_sel", 31),
895 /* INFRA1 */
896 GATE_INFRA1(CLK_INFRA_SPI0, "infra_spi0",
897 "spi_sel", 1),
898 GATE_INFRA1(CLK_INFRA_MSDC0, "infra_msdc0",
899 "msdc50_hclk_sel", 2),
900 GATE_INFRA1(CLK_INFRA_MSDC1, "infra_msdc1",
901 "axi_sel", 4),
902 GATE_INFRA1(CLK_INFRA_MSDC2, "infra_msdc2",
903 "axi_sel", 5),
904 GATE_INFRA1(CLK_INFRA_MSDC0_SCK, "infra_msdc0_sck",
905 "msdc50_0_sel", 6),
906 GATE_INFRA1(CLK_INFRA_DVFSRC, "infra_dvfsrc",
907 "f_f26m_ck", 7),
908 GATE_INFRA1(CLK_INFRA_GCPU, "infra_gcpu",
909 "axi_sel", 8),
910 GATE_INFRA1(CLK_INFRA_TRNG, "infra_trng",
911 "axi_sel", 9),
912 GATE_INFRA1(CLK_INFRA_AUXADC, "infra_auxadc",
913 "f_f26m_ck", 10),
914 GATE_INFRA1(CLK_INFRA_CPUM, "infra_cpum",
915 "axi_sel", 11),
916 GATE_INFRA1(CLK_INFRA_CCIF1_AP, "infra_ccif1_ap",
917 "axi_sel", 12),
918 GATE_INFRA1(CLK_INFRA_CCIF1_MD, "infra_ccif1_md",
919 "axi_sel", 13),
920 GATE_INFRA1(CLK_INFRA_AUXADC_MD, "infra_auxadc_md",
921 "f_f26m_ck", 14),
922 GATE_INFRA1(CLK_INFRA_MSDC1_SCK, "infra_msdc1_sck",
923 "msdc30_1_sel", 16),
924 GATE_INFRA1(CLK_INFRA_MSDC2_SCK, "infra_msdc2_sck",
925 "msdc30_2_sel", 17),
926 GATE_INFRA1(CLK_INFRA_AP_DMA, "infra_apdma",
927 "axi_sel", 18),
928 GATE_INFRA1(CLK_INFRA_XIU, "infra_xiu",
929 "axi_sel", 19),
930 GATE_INFRA1(CLK_INFRA_DEVICE_APC, "infra_device_apc",
931 "axi_sel", 20),
932 GATE_INFRA1(CLK_INFRA_CCIF_AP, "infra_ccif_ap",
933 "axi_sel", 23),
934 GATE_INFRA1(CLK_INFRA_DEBUGSYS, "infra_debugsys",
935 "axi_sel", 24),
936 GATE_INFRA1(CLK_INFRA_AUDIO, "infra_audio",
937 "axi_sel", 25),
938 GATE_INFRA1(CLK_INFRA_CCIF_MD, "infra_ccif_md",
939 "axi_sel", 26),
940 GATE_INFRA1(CLK_INFRA_DXCC_SEC_CORE, "infra_dxcc_sec_core",
941 "dxcc_sel", 27),
942 GATE_INFRA1(CLK_INFRA_DXCC_AO, "infra_dxcc_ao",
943 "dxcc_sel", 28),
944 GATE_INFRA1(CLK_INFRA_DEVMPU_BCLK, "infra_devmpu_bclk",
945 "axi_sel", 30),
946 GATE_INFRA1(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m",
947 "f_f26m_ck", 31),
948 /* INFRA2 */
949 GATE_INFRA2(CLK_INFRA_IRTX, "infra_irtx",
950 "f_f26m_ck", 0),
951 GATE_INFRA2(CLK_INFRA_USB, "infra_usb",
952 "usb_top_sel", 1),
953 GATE_INFRA2(CLK_INFRA_DISP_PWM, "infra_disppwm",
954 "axi_sel", 2),
955 GATE_INFRA2(CLK_INFRA_CLDMA_BCLK, "infra_cldma_bclk",
956 "axi_sel", 3),
957 GATE_INFRA2(CLK_INFRA_AUDIO_26M_BCLK, "infra_audio_26m_bclk",
958 "f_f26m_ck", 4),
959 GATE_INFRA2(CLK_INFRA_SPI1, "infra_spi1",
960 "spi_sel", 6),
961 GATE_INFRA2(CLK_INFRA_I2C4, "infra_i2c4",
962 "i2c_sel", 7),
963 GATE_INFRA2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_md_tmp_share",
964 "f_f26m_ck", 8),
965 GATE_INFRA2(CLK_INFRA_SPI2, "infra_spi2",
966 "spi_sel", 9),
967 GATE_INFRA2(CLK_INFRA_SPI3, "infra_spi3",
968 "spi_sel", 10),
969 GATE_INFRA2(CLK_INFRA_UNIPRO_SCK, "infra_unipro_sck",
970 "ssusb_top_xhci_sel", 11),
971 GATE_INFRA2(CLK_INFRA_UNIPRO_TICK, "infra_unipro_tick",
972 "fufs_sel", 12),
973 GATE_INFRA2(CLK_INFRA_UFS_MP_SAP_BCLK, "infra_ufs_mp_sap_bck",
974 "fufs_sel", 13),
975 GATE_INFRA2(CLK_INFRA_MD32_BCLK, "infra_md32_bclk",
976 "axi_sel", 14),
977 GATE_INFRA2(CLK_INFRA_SSPM, "infra_sspm",
978 "sspm_sel", 15),
979 GATE_INFRA2(CLK_INFRA_UNIPRO_MBIST, "infra_unipro_mbist",
980 "axi_sel", 16),
981 GATE_INFRA2(CLK_INFRA_SSPM_BUS_HCLK, "infra_sspm_bus_hclk",
982 "axi_sel", 17),
983 GATE_INFRA2(CLK_INFRA_I2C5, "infra_i2c5",
984 "i2c_sel", 18),
985 GATE_INFRA2(CLK_INFRA_I2C5_ARBITER, "infra_i2c5_arbiter",
986 "i2c_sel", 19),
987 GATE_INFRA2(CLK_INFRA_I2C5_IMM, "infra_i2c5_imm",
988 "i2c_sel", 20),
989 GATE_INFRA2(CLK_INFRA_I2C1_ARBITER, "infra_i2c1_arbiter",
990 "i2c_sel", 21),
991 GATE_INFRA2(CLK_INFRA_I2C1_IMM, "infra_i2c1_imm",
992 "i2c_sel", 22),
993 GATE_INFRA2(CLK_INFRA_I2C2_ARBITER, "infra_i2c2_arbiter",
994 "i2c_sel", 23),
995 GATE_INFRA2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm",
996 "i2c_sel", 24),
997 GATE_INFRA2(CLK_INFRA_SPI4, "infra_spi4",
998 "spi_sel", 25),
999 GATE_INFRA2(CLK_INFRA_SPI5, "infra_spi5",
1000 "spi_sel", 26),
1001 GATE_INFRA2(CLK_INFRA_CQ_DMA, "infra_cqdma",
1002 "axi_sel", 27),
1003 GATE_INFRA2(CLK_INFRA_UFS, "infra_ufs",
1004 "fufs_sel", 28),
1005 GATE_INFRA2(CLK_INFRA_AES_UFSFDE, "infra_aes_ufsfde",
1006 "faes_ufsfde_sel", 29),
1007 GATE_INFRA2(CLK_INFRA_UFS_TICK, "infra_ufs_tick",
1008 "fufs_sel", 30),
1009 /* INFRA3 */
1010 GATE_INFRA3(CLK_INFRA_MSDC0_SELF, "infra_msdc0_self",
1011 "msdc50_0_sel", 0),
1012 GATE_INFRA3(CLK_INFRA_MSDC1_SELF, "infra_msdc1_self",
1013 "msdc50_0_sel", 1),
1014 GATE_INFRA3(CLK_INFRA_MSDC2_SELF, "infra_msdc2_self",
1015 "msdc50_0_sel", 2),
1016 GATE_INFRA3(CLK_INFRA_SSPM_26M_SELF, "infra_sspm_26m_self",
1017 "f_f26m_ck", 3),
1018 GATE_INFRA3(CLK_INFRA_SSPM_32K_SELF, "infra_sspm_32k_self",
1019 "f_f26m_ck", 4),
1020 GATE_INFRA3(CLK_INFRA_UFS_AXI, "infra_ufs_axi",
1021 "axi_sel", 5),
1022 GATE_INFRA3(CLK_INFRA_I2C6, "infra_i2c6",
1023 "i2c_sel", 6),
1024 GATE_INFRA3(CLK_INFRA_AP_MSDC0, "infra_ap_msdc0",
1025 "msdc50_hclk_sel", 7),
1026 GATE_INFRA3(CLK_INFRA_MD_MSDC0, "infra_md_msdc0",
1027 "msdc50_hclk_sel", 8),
1028 GATE_INFRA3(CLK_INFRA_CCIF2_AP, "infra_ccif2_ap",
1029 "axi_sel", 16),
1030 GATE_INFRA3(CLK_INFRA_CCIF2_MD, "infra_ccif2_md",
1031 "axi_sel", 17),
1032 GATE_INFRA3(CLK_INFRA_CCIF3_AP, "infra_ccif3_ap",
1033 "axi_sel", 18),
1034 GATE_INFRA3(CLK_INFRA_CCIF3_MD, "infra_ccif3_md",
1035 "axi_sel", 19),
1036 GATE_INFRA3(CLK_INFRA_SEJ_F13M, "infra_sej_f13m",
1037 "f_f26m_ck", 20),
1038 GATE_INFRA3(CLK_INFRA_AES_BCLK, "infra_aes_bclk",
1039 "axi_sel", 21),
1040 GATE_INFRA3(CLK_INFRA_I2C7, "infra_i2c7",
1041 "i2c_sel", 22),
1042 GATE_INFRA3(CLK_INFRA_I2C8, "infra_i2c8",
1043 "i2c_sel", 23),
1044 GATE_INFRA3(CLK_INFRA_FBIST2FPC, "infra_fbist2fpc",
1045 "msdc50_0_sel", 24),
1046};
1047
1048static const struct mtk_gate_regs apmixed_cg_regs = {
1049 .set_ofs = 0x20,
1050 .clr_ofs = 0x20,
1051 .sta_ofs = 0x20,
1052};
1053
1054#define GATE_APMIXED_FLAGS(_id, _name, _parent, _shift, _flags) { \
1055 .id = _id, \
1056 .name = _name, \
1057 .parent_name = _parent, \
1058 .regs = &apmixed_cg_regs, \
1059 .shift = _shift, \
1060 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
1061 .flags = _flags, \
1062 }
1063
1064#define GATE_APMIXED(_id, _name, _parent, _shift) \
1065 GATE_APMIXED_FLAGS(_id, _name, _parent, _shift, 0)
1066
1067static const struct mtk_gate apmixed_clks[] = {
1068 /* AUDIO0 */
1069 GATE_APMIXED(CLK_APMIXED_SSUSB_26M, "apmixed_ssusb26m",
1070 "f_f26m_ck", 4),
1071 GATE_APMIXED_FLAGS(CLK_APMIXED_APPLL_26M, "apmixed_appll26m",
1072 "f_f26m_ck", 5, CLK_IS_CRITICAL),
1073 GATE_APMIXED(CLK_APMIXED_MIPIC0_26M, "apmixed_mipic026m",
1074 "f_f26m_ck", 6),
1075 GATE_APMIXED(CLK_APMIXED_MDPLLGP_26M, "apmixed_mdpll26m",
1076 "f_f26m_ck", 7),
1077 GATE_APMIXED(CLK_APMIXED_MMSYS_26M, "apmixed_mmsys26m",
1078 "f_f26m_ck", 8),
1079 GATE_APMIXED(CLK_APMIXED_UFS_26M, "apmixed_ufs26m",
1080 "f_f26m_ck", 9),
1081 GATE_APMIXED(CLK_APMIXED_MIPIC1_26M, "apmixed_mipic126m",
1082 "f_f26m_ck", 11),
1083 GATE_APMIXED(CLK_APMIXED_MEMPLL_26M, "apmixed_mempll26m",
1084 "f_f26m_ck", 13),
1085 GATE_APMIXED(CLK_APMIXED_CLKSQ_LVPLL_26M, "apmixed_lvpll26m",
1086 "f_f26m_ck", 14),
1087 GATE_APMIXED(CLK_APMIXED_MIPID0_26M, "apmixed_mipid026m",
1088 "f_f26m_ck", 16),
1089 GATE_APMIXED(CLK_APMIXED_MIPID1_26M, "apmixed_mipid126m",
1090 "f_f26m_ck", 17),
1091};
1092
1093#define MT8183_PLL_FMAX (3800UL * MHZ)
1094#define MT8183_PLL_FMIN (1500UL * MHZ)
1095
1096#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
1097 _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
1098 _pd_shift, _tuner_reg, _tuner_en_reg, \
1099 _tuner_en_bit, _pcw_reg, _pcw_shift, \
1100 _div_table) { \
1101 .id = _id, \
1102 .name = _name, \
1103 .reg = _reg, \
1104 .pwr_reg = _pwr_reg, \
1105 .en_mask = _en_mask, \
1106 .flags = _flags, \
1107 .rst_bar_mask = _rst_bar_mask, \
1108 .fmax = MT8183_PLL_FMAX, \
1109 .fmin = MT8183_PLL_FMIN, \
1110 .pcwbits = _pcwbits, \
1111 .pcwibits = _pcwibits, \
1112 .pd_reg = _pd_reg, \
1113 .pd_shift = _pd_shift, \
1114 .tuner_reg = _tuner_reg, \
1115 .tuner_en_reg = _tuner_en_reg, \
1116 .tuner_en_bit = _tuner_en_bit, \
1117 .pcw_reg = _pcw_reg, \
1118 .pcw_shift = _pcw_shift, \
1119 .div_table = _div_table, \
1120 }
1121
1122#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
1123 _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
1124 _pd_shift, _tuner_reg, _tuner_en_reg, \
1125 _tuner_en_bit, _pcw_reg, _pcw_shift) \
1126 PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
1127 _rst_bar_mask, _pcwbits, _pcwibits, _pd_reg, \
1128 _pd_shift, _tuner_reg, _tuner_en_reg, \
1129 _tuner_en_bit, _pcw_reg, _pcw_shift, NULL)
1130
1131static const struct mtk_pll_div_table armpll_div_table[] = {
1132 { .div = 0, .freq = MT8183_PLL_FMAX },
1133 { .div = 1, .freq = 1500 * MHZ },
1134 { .div = 2, .freq = 750 * MHZ },
1135 { .div = 3, .freq = 375 * MHZ },
1136 { .div = 4, .freq = 187500000 },
1137 { } /* sentinel */
1138};
1139
1140static const struct mtk_pll_data plls[] = {
1141 PLL_B(CLK_APMIXED_ARMPLL_LL, "armpll_ll", 0x0200, 0x020C, 0x00000001,
1142 HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0204, 24, 0x0, 0x0, 0,
1143 0x0204, 0, armpll_div_table),
1144 PLL_B(CLK_APMIXED_ARMPLL_L, "armpll_l", 0x0210, 0x021C, 0x00000001,
1145 HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0214, 24, 0x0, 0x0, 0,
1146 0x0214, 0, armpll_div_table),
1147 PLL(CLK_APMIXED_CCIPLL, "ccipll", 0x0290, 0x029C, 0x00000001,
1148 HAVE_RST_BAR | PLL_AO, BIT(24), 22, 8, 0x0294, 24, 0x0, 0x0, 0,
1149 0x0294, 0),
1150 PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0x00000001,
1151 HAVE_RST_BAR, BIT(24), 22, 8, 0x0224, 24, 0x0, 0x0, 0,
1152 0x0224, 0),
1153 PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x0230, 0x023C, 0x00000001,
1154 HAVE_RST_BAR, BIT(24), 22, 8, 0x0234, 24, 0x0, 0x0, 0,
1155 0x0234, 0),
1156 PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0x00000001,
1157 0, 0, 22, 8, 0x0244, 24, 0x0, 0x0, 0, 0x0244, 0),
1158 PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0x00000001,
1159 0, 0, 22, 8, 0x0254, 24, 0x0, 0x0, 0, 0x0254, 0),
1160 PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0260, 0x026C, 0x00000001,
1161 0, 0, 22, 8, 0x0264, 24, 0x0, 0x0, 0, 0x0264, 0),
1162 PLL(CLK_APMIXED_MMPLL, "mmpll", 0x0270, 0x027C, 0x00000001,
1163 HAVE_RST_BAR, BIT(23), 22, 8, 0x0274, 24, 0x0, 0x0, 0,
1164 0x0274, 0),
1165 PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0x00000001,
1166 0, 0, 32, 8, 0x02A0, 1, 0x02A8, 0x0014, 0, 0x02A4, 0),
1167 PLL(CLK_APMIXED_APLL2, "apll2", 0x02b4, 0x02c4, 0x00000001,
1168 0, 0, 32, 8, 0x02b4, 1, 0x02BC, 0x0014, 1, 0x02B8, 0),
1169};
1170
1171static int clk_mt8183_apmixed_probe(struct platform_device *pdev)
1172{
1173 struct clk_onecell_data *clk_data;
1174 struct device_node *node = pdev->dev.of_node;
1175 int r;
1176
1177 clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
1178
1179 mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
1180
1181 mtk_clk_register_gates(node, apmixed_clks, ARRAY_SIZE(apmixed_clks),
1182 clk_data);
1183
1184 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1185
1186 if (r)
1187 pr_err("%s(): could not register clock provider: %d\n",
1188 __func__, r);
1189
1190 return r;
1191}
1192
1193static int clk_mt8183_top_probe(struct platform_device *pdev)
1194{
1195 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1196 void __iomem *base;
1197 struct clk_onecell_data *clk_data;
1198 struct device_node *node = pdev->dev.of_node;
1199 int r;
1200
1201 base = devm_ioremap_resource(&pdev->dev, res);
1202 if (IS_ERR(base)) {
1203 pr_err("%s(): ioremap failed\n", __func__);
1204 return PTR_ERR(base);
1205 }
1206
1207 clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1208
1209 mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
1210 clk_data);
1211
1212 mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), clk_data);
1213
1214 mtk_clk_register_muxes(top_muxes, ARRAY_SIZE(top_muxes),
1215 node, &mt8183_clk_lock, clk_data);
1216
1217 mtk_clk_register_composites(top_aud_muxes, ARRAY_SIZE(top_aud_muxes),
1218 base, &mt8183_clk_lock, clk_data);
1219
1220 mtk_clk_register_composites(top_aud_divs, ARRAY_SIZE(top_aud_divs),
1221 base, &mt8183_clk_lock, clk_data);
1222
1223 mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
1224 clk_data);
1225
1226 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1227
1228 if (r)
1229 pr_err("%s(): could not register clock provider: %d\n",
1230 __func__, r);
1231
1232 return r;
1233}
1234
1235static int clk_mt8183_infra_probe(struct platform_device *pdev)
1236{
1237 struct clk_onecell_data *clk_data;
1238 struct device_node *node = pdev->dev.of_node;
1239 int r;
1240
1241 clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
1242
1243 mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
1244 clk_data);
1245
1246 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1247
1248 if (r)
1249 pr_err("%s(): could not register clock provider: %d\n",
1250 __func__, r);
1251
1252 mtk_register_reset_controller_set_clr(node, 4, 0x120);
1253
1254 return r;
1255}
1256
1257static int clk_mt8183_mcu_probe(struct platform_device *pdev)
1258{
1259 struct clk_onecell_data *clk_data;
1260 int r;
1261 struct device_node *node = pdev->dev.of_node;
1262 void __iomem *base;
1263 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1264
1265 base = devm_ioremap_resource(&pdev->dev, res);
1266 if (IS_ERR(base)) {
1267 pr_err("%s(): ioremap failed\n", __func__);
1268 return PTR_ERR(base);
1269 }
1270
1271 clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
1272
1273 mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes), base,
1274 &mt8183_clk_lock, clk_data);
1275
1276 r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
1277
1278 if (r != 0)
1279 pr_err("%s(): could not register clock provider: %d\n",
1280 __func__, r);
1281
1282 return r;
1283}
1284
1285static const struct of_device_id of_match_clk_mt8183[] = {
1286 {
1287 .compatible = "mediatek,mt8183-apmixedsys",
1288 .data = clk_mt8183_apmixed_probe,
1289 }, {
1290 .compatible = "mediatek,mt8183-topckgen",
1291 .data = clk_mt8183_top_probe,
1292 }, {
1293 .compatible = "mediatek,mt8183-infracfg",
1294 .data = clk_mt8183_infra_probe,
1295 }, {
1296 .compatible = "mediatek,mt8183-mcucfg",
1297 .data = clk_mt8183_mcu_probe,
1298 }, {
1299 /* sentinel */
1300 }
1301};
1302
1303static int clk_mt8183_probe(struct platform_device *pdev)
1304{
1305 int (*clk_probe)(struct platform_device *);
1306 int r;
1307
1308 clk_probe = of_device_get_match_data(&pdev->dev);
1309 if (!clk_probe)
1310 return -EINVAL;
1311
1312 r = clk_probe(pdev);
1313 if (r)
1314 dev_err(&pdev->dev,
1315 "could not register clock provider: %s: %d\n",
1316 pdev->name, r);
1317
1318 return r;
1319}
1320
1321static struct platform_driver clk_mt8183_drv = {
1322 .probe = clk_mt8183_probe,
1323 .driver = {
1324 .name = "clk-mt8183",
1325 .owner = THIS_MODULE,
1326 .of_match_table = of_match_clk_mt8183,
1327 },
1328};
1329
1330static int __init clk_mt8183_init(void)
1331{
1332 return platform_driver_register(&clk_mt8183_drv);
1333}
1334
1335arch_initcall(clk_mt8183_init);