0001
0002
0003
0004
0005
0006
0007 #include <linux/clk.h>
0008 #include <linux/delay.h>
0009 #include <linux/mfd/syscon.h>
0010 #include <linux/of.h>
0011 #include <linux/of_address.h>
0012 #include <linux/of_device.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/slab.h>
0015
0016 #include "clk-gate.h"
0017 #include "clk-pll.h"
0018 #include "clk-mtk.h"
0019
0020 #include <dt-bindings/clock/mt2712-clk.h>
0021
0022 static DEFINE_SPINLOCK(mt2712_clk_lock);
0023
0024 static const struct mtk_fixed_clk top_fixed_clks[] = {
0025 FIXED_CLK(CLK_TOP_VPLL3_DPIX, "vpll3_dpix", NULL, 200000000),
0026 FIXED_CLK(CLK_TOP_VPLL_DPIX, "vpll_dpix", NULL, 200000000),
0027 FIXED_CLK(CLK_TOP_LTEPLL_FS26M, "ltepll_fs26m", NULL, 26000000),
0028 FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", NULL, 350000000),
0029 FIXED_CLK(CLK_TOP_DSI0_LNTC, "dsi0_lntc", NULL, 143000000),
0030 FIXED_CLK(CLK_TOP_DSI1_LNTC, "dsi1_lntc", NULL, 143000000),
0031 FIXED_CLK(CLK_TOP_LVDSTX3_CLKDIG_CTS, "lvdstx3", NULL, 140000000),
0032 FIXED_CLK(CLK_TOP_LVDSTX_CLKDIG_CTS, "lvdstx", NULL, 140000000),
0033 FIXED_CLK(CLK_TOP_CLKRTC_EXT, "clkrtc_ext", NULL, 32768),
0034 FIXED_CLK(CLK_TOP_CLKRTC_INT, "clkrtc_int", NULL, 32747),
0035 FIXED_CLK(CLK_TOP_CSI0, "csi0", NULL, 26000000),
0036 FIXED_CLK(CLK_TOP_CVBSPLL, "cvbspll", NULL, 108000000),
0037 };
0038
0039 static const struct mtk_fixed_factor top_early_divs[] = {
0040 FACTOR(CLK_TOP_SYS_26M, "sys_26m", "clk26m", 1,
0041 1),
0042 FACTOR(CLK_TOP_CLK26M_D2, "clk26m_d2", "sys_26m", 1,
0043 2),
0044 };
0045
0046 static const struct mtk_fixed_factor top_divs[] = {
0047 FACTOR(CLK_TOP_ARMCA35PLL, "armca35pll_ck", "armca35pll", 1,
0048 1),
0049 FACTOR(CLK_TOP_ARMCA35PLL_600M, "armca35pll_600m", "armca35pll_ck", 1,
0050 2),
0051 FACTOR(CLK_TOP_ARMCA35PLL_400M, "armca35pll_400m", "armca35pll_ck", 1,
0052 3),
0053 FACTOR(CLK_TOP_ARMCA72PLL, "armca72pll_ck", "armca72pll", 1,
0054 1),
0055 FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1,
0056 1),
0057 FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "syspll_ck", 1,
0058 2),
0059 FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1,
0060 2),
0061 FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1,
0062 4),
0063 FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1,
0064 8),
0065 FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1,
0066 16),
0067 FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "syspll_ck", 1,
0068 3),
0069 FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1,
0070 2),
0071 FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1,
0072 4),
0073 FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "syspll_ck", 1,
0074 5),
0075 FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1,
0076 2),
0077 FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1,
0078 4),
0079 FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "syspll_ck", 1,
0080 7),
0081 FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1,
0082 2),
0083 FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1,
0084 4),
0085 FACTOR(CLK_TOP_UNIVPLL, "univpll_ck", "univpll", 1,
0086 1),
0087 FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll_ck", 1,
0088 7),
0089 FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll_ck", 1,
0090 26),
0091 FACTOR(CLK_TOP_UNIVPLL_D52, "univpll_d52", "univpll_ck", 1,
0092 52),
0093 FACTOR(CLK_TOP_UNIVPLL_D104, "univpll_d104", "univpll_ck", 1,
0094 104),
0095 FACTOR(CLK_TOP_UNIVPLL_D208, "univpll_d208", "univpll_ck", 1,
0096 208),
0097 FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll_ck", 1,
0098 2),
0099 FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1,
0100 2),
0101 FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1,
0102 4),
0103 FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1,
0104 8),
0105 FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll_ck", 1,
0106 3),
0107 FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1,
0108 2),
0109 FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1,
0110 4),
0111 FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1,
0112 8),
0113 FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll_ck", 1,
0114 5),
0115 FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1,
0116 2),
0117 FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1,
0118 4),
0119 FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1,
0120 8),
0121 FACTOR(CLK_TOP_F_MP0_PLL1, "f_mp0_pll1_ck", "univpll_d2", 1,
0122 1),
0123 FACTOR(CLK_TOP_F_MP0_PLL2, "f_mp0_pll2_ck", "univpll1_d2", 1,
0124 1),
0125 FACTOR(CLK_TOP_F_BIG_PLL1, "f_big_pll1_ck", "univpll_d2", 1,
0126 1),
0127 FACTOR(CLK_TOP_F_BIG_PLL2, "f_big_pll2_ck", "univpll1_d2", 1,
0128 1),
0129 FACTOR(CLK_TOP_F_BUS_PLL1, "f_bus_pll1_ck", "univpll_d2", 1,
0130 1),
0131 FACTOR(CLK_TOP_F_BUS_PLL2, "f_bus_pll2_ck", "univpll1_d2", 1,
0132 1),
0133 FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1,
0134 1),
0135 FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1,
0136 2),
0137 FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1,
0138 4),
0139 FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1,
0140 8),
0141 FACTOR(CLK_TOP_APLL1_D16, "apll1_d16", "apll1_ck", 1,
0142 16),
0143 FACTOR(CLK_TOP_APLL2, "apll2_ck", "apll2", 1,
0144 1),
0145 FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", "apll2_ck", 1,
0146 2),
0147 FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", "apll2_ck", 1,
0148 4),
0149 FACTOR(CLK_TOP_APLL2_D8, "apll2_d8", "apll2_ck", 1,
0150 8),
0151 FACTOR(CLK_TOP_APLL2_D16, "apll2_d16", "apll2_ck", 1,
0152 16),
0153 FACTOR(CLK_TOP_LVDSPLL, "lvdspll_ck", "lvdspll", 1,
0154 1),
0155 FACTOR(CLK_TOP_LVDSPLL_D2, "lvdspll_d2", "lvdspll_ck", 1,
0156 2),
0157 FACTOR(CLK_TOP_LVDSPLL_D4, "lvdspll_d4", "lvdspll_ck", 1,
0158 4),
0159 FACTOR(CLK_TOP_LVDSPLL_D8, "lvdspll_d8", "lvdspll_ck", 1,
0160 8),
0161 FACTOR(CLK_TOP_LVDSPLL2, "lvdspll2_ck", "lvdspll2", 1,
0162 1),
0163 FACTOR(CLK_TOP_LVDSPLL2_D2, "lvdspll2_d2", "lvdspll2_ck", 1,
0164 2),
0165 FACTOR(CLK_TOP_LVDSPLL2_D4, "lvdspll2_d4", "lvdspll2_ck", 1,
0166 4),
0167 FACTOR(CLK_TOP_LVDSPLL2_D8, "lvdspll2_d8", "lvdspll2_ck", 1,
0168 8),
0169 FACTOR(CLK_TOP_ETHERPLL_125M, "etherpll_125m", "etherpll", 1,
0170 1),
0171 FACTOR(CLK_TOP_ETHERPLL_50M, "etherpll_50m", "etherpll", 1,
0172 1),
0173 FACTOR(CLK_TOP_CVBS, "cvbs", "cvbspll", 1,
0174 1),
0175 FACTOR(CLK_TOP_CVBS_D2, "cvbs_d2", "cvbs", 1,
0176 2),
0177 FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1,
0178 1),
0179 FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll_ck", 1,
0180 2),
0181 FACTOR(CLK_TOP_VENCPLL, "vencpll_ck", "vencpll", 1,
0182 1),
0183 FACTOR(CLK_TOP_VENCPLL_D2, "vencpll_d2", "vencpll_ck", 1,
0184 2),
0185 FACTOR(CLK_TOP_VCODECPLL, "vcodecpll_ck", "vcodecpll", 1,
0186 1),
0187 FACTOR(CLK_TOP_VCODECPLL_D2, "vcodecpll_d2", "vcodecpll_ck", 1,
0188 2),
0189 FACTOR(CLK_TOP_TVDPLL, "tvdpll_ck", "tvdpll", 1,
0190 1),
0191 FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1,
0192 2),
0193 FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1,
0194 4),
0195 FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1,
0196 8),
0197 FACTOR(CLK_TOP_TVDPLL_429M, "tvdpll_429m", "tvdpll", 1,
0198 1),
0199 FACTOR(CLK_TOP_TVDPLL_429M_D2, "tvdpll_429m_d2", "tvdpll_429m", 1,
0200 2),
0201 FACTOR(CLK_TOP_TVDPLL_429M_D4, "tvdpll_429m_d4", "tvdpll_429m", 1,
0202 4),
0203 FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1,
0204 1),
0205 FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1,
0206 2),
0207 FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1,
0208 4),
0209 FACTOR(CLK_TOP_MSDCPLL2, "msdcpll2_ck", "msdcpll2", 1,
0210 1),
0211 FACTOR(CLK_TOP_MSDCPLL2_D2, "msdcpll2_d2", "msdcpll2_ck", 1,
0212 2),
0213 FACTOR(CLK_TOP_MSDCPLL2_D4, "msdcpll2_d4", "msdcpll2_ck", 1,
0214 4),
0215 FACTOR(CLK_TOP_D2A_ULCLK_6P5M, "d2a_ulclk_6p5m", "clk26m", 1,
0216 4),
0217 FACTOR(CLK_TOP_APLL1_D3, "apll1_d3", "apll1_ck", 1,
0218 3),
0219 FACTOR(CLK_TOP_APLL2_D3, "apll2_d3", "apll2_ck", 1,
0220 3),
0221 };
0222
0223 static const char * const axi_parents[] = {
0224 "clk26m",
0225 "syspll1_d2",
0226 "syspll_d5",
0227 "syspll1_d4",
0228 "univpll_d5",
0229 "univpll2_d2",
0230 "msdcpll2_ck"
0231 };
0232
0233 static const char * const mem_parents[] = {
0234 "clk26m",
0235 "dmpll_ck"
0236 };
0237
0238 static const char * const mm_parents[] = {
0239 "clk26m",
0240 "vencpll_ck",
0241 "syspll_d3",
0242 "syspll1_d2",
0243 "syspll_d5",
0244 "syspll1_d4",
0245 "univpll1_d2",
0246 "univpll2_d2"
0247 };
0248
0249 static const char * const pwm_parents[] = {
0250 "clk26m",
0251 "univpll2_d4",
0252 "univpll3_d2",
0253 "univpll1_d4"
0254 };
0255
0256 static const char * const vdec_parents[] = {
0257 "clk26m",
0258 "vcodecpll_ck",
0259 "tvdpll_429m",
0260 "univpll_d3",
0261 "vencpll_ck",
0262 "syspll_d3",
0263 "univpll1_d2",
0264 "mmpll_d2",
0265 "syspll3_d2",
0266 "tvdpll_ck"
0267 };
0268
0269 static const char * const venc_parents[] = {
0270 "clk26m",
0271 "univpll1_d2",
0272 "mmpll_d2",
0273 "tvdpll_d2",
0274 "syspll1_d2",
0275 "univpll_d5",
0276 "vcodecpll_d2",
0277 "univpll2_d2",
0278 "syspll3_d2"
0279 };
0280
0281 static const char * const mfg_parents[] = {
0282 "clk26m",
0283 "mmpll_ck",
0284 "univpll_d3",
0285 "clk26m",
0286 "clk26m",
0287 "clk26m",
0288 "clk26m",
0289 "clk26m",
0290 "clk26m",
0291 "syspll_d3",
0292 "syspll1_d2",
0293 "syspll_d5",
0294 "univpll_d3",
0295 "univpll1_d2",
0296 "univpll_d5",
0297 "univpll2_d2"
0298 };
0299
0300 static const char * const camtg_parents[] = {
0301 "clk26m",
0302 "univpll_d52",
0303 "univpll_d208",
0304 "univpll_d104",
0305 "clk26m_d2",
0306 "univpll_d26",
0307 "univpll2_d8",
0308 "syspll3_d4",
0309 "syspll3_d2",
0310 "univpll1_d4",
0311 "univpll2_d2"
0312 };
0313
0314 static const char * const uart_parents[] = {
0315 "clk26m",
0316 "univpll2_d8"
0317 };
0318
0319 static const char * const spi_parents[] = {
0320 "clk26m",
0321 "univpll2_d4",
0322 "univpll1_d4",
0323 "univpll2_d2",
0324 "univpll3_d2",
0325 "univpll1_d8"
0326 };
0327
0328 static const char * const usb20_parents[] = {
0329 "clk26m",
0330 "univpll1_d8",
0331 "univpll3_d4"
0332 };
0333
0334 static const char * const usb30_parents[] = {
0335 "clk26m",
0336 "univpll3_d2",
0337 "univpll3_d4",
0338 "univpll2_d4"
0339 };
0340
0341 static const char * const msdc50_0_h_parents[] = {
0342 "clk26m",
0343 "syspll1_d2",
0344 "syspll2_d2",
0345 "syspll4_d2",
0346 "univpll_d5",
0347 "univpll1_d4"
0348 };
0349
0350 static const char * const msdc50_0_parents[] = {
0351 "clk26m",
0352 "msdcpll_ck",
0353 "msdcpll_d2",
0354 "univpll1_d4",
0355 "syspll2_d2",
0356 "msdcpll_d4",
0357 "vencpll_d2",
0358 "univpll1_d2",
0359 "msdcpll2_ck",
0360 "msdcpll2_d2",
0361 "msdcpll2_d4"
0362 };
0363
0364 static const char * const msdc30_1_parents[] = {
0365 "clk26m",
0366 "univpll2_d2",
0367 "msdcpll_d2",
0368 "univpll1_d4",
0369 "syspll2_d2",
0370 "univpll_d7",
0371 "vencpll_d2"
0372 };
0373
0374 static const char * const msdc30_3_parents[] = {
0375 "clk26m",
0376 "msdcpll2_ck",
0377 "msdcpll2_d2",
0378 "univpll2_d2",
0379 "msdcpll2_d4",
0380 "univpll1_d4",
0381 "syspll2_d2",
0382 "syspll_d7",
0383 "univpll_d7",
0384 "vencpll_d2",
0385 "msdcpll_ck",
0386 "msdcpll_d2",
0387 "msdcpll_d4"
0388 };
0389
0390 static const char * const audio_parents[] = {
0391 "clk26m",
0392 "syspll3_d4",
0393 "syspll4_d4",
0394 "syspll1_d16"
0395 };
0396
0397 static const char * const aud_intbus_parents[] = {
0398 "clk26m",
0399 "syspll1_d4",
0400 "syspll4_d2",
0401 "univpll3_d2",
0402 "univpll2_d8",
0403 "syspll3_d2",
0404 "syspll3_d4"
0405 };
0406
0407 static const char * const pmicspi_parents[] = {
0408 "clk26m",
0409 "syspll1_d8",
0410 "syspll3_d4",
0411 "syspll1_d16",
0412 "univpll3_d4",
0413 "univpll_d26",
0414 "syspll3_d4"
0415 };
0416
0417 static const char * const dpilvds1_parents[] = {
0418 "clk26m",
0419 "lvdspll2_ck",
0420 "lvdspll2_d2",
0421 "lvdspll2_d4",
0422 "lvdspll2_d8",
0423 "clkfpc"
0424 };
0425
0426 static const char * const atb_parents[] = {
0427 "clk26m",
0428 "syspll1_d2",
0429 "univpll_d5",
0430 "syspll_d5"
0431 };
0432
0433 static const char * const nr_parents[] = {
0434 "clk26m",
0435 "univpll1_d4",
0436 "syspll2_d2",
0437 "syspll1_d4",
0438 "univpll1_d8",
0439 "univpll3_d2",
0440 "univpll2_d2",
0441 "syspll_d5"
0442 };
0443
0444 static const char * const nfi2x_parents[] = {
0445 "clk26m",
0446 "syspll4_d4",
0447 "univpll3_d4",
0448 "univpll1_d8",
0449 "syspll2_d4",
0450 "univpll3_d2",
0451 "syspll_d7",
0452 "syspll2_d2",
0453 "univpll2_d2",
0454 "syspll_d5",
0455 "syspll1_d2"
0456 };
0457
0458 static const char * const irda_parents[] = {
0459 "clk26m",
0460 "univpll2_d4",
0461 "syspll2_d4",
0462 "univpll2_d8"
0463 };
0464
0465 static const char * const cci400_parents[] = {
0466 "clk26m",
0467 "vencpll_ck",
0468 "armca35pll_600m",
0469 "armca35pll_400m",
0470 "univpll_d2",
0471 "syspll_d2",
0472 "msdcpll_ck",
0473 "univpll_d3"
0474 };
0475
0476 static const char * const aud_1_parents[] = {
0477 "clk26m",
0478 "apll1_ck",
0479 "univpll2_d4",
0480 "univpll2_d8"
0481 };
0482
0483 static const char * const aud_2_parents[] = {
0484 "clk26m",
0485 "apll2_ck",
0486 "univpll2_d4",
0487 "univpll2_d8"
0488 };
0489
0490 static const char * const mem_mfg_parents[] = {
0491 "clk26m",
0492 "mmpll_ck",
0493 "univpll_d3"
0494 };
0495
0496 static const char * const axi_mfg_parents[] = {
0497 "clk26m",
0498 "axi_sel",
0499 "univpll_d5"
0500 };
0501
0502 static const char * const scam_parents[] = {
0503 "clk26m",
0504 "syspll3_d2",
0505 "univpll2_d4",
0506 "syspll2_d4"
0507 };
0508
0509 static const char * const nfiecc_parents[] = {
0510 "clk26m",
0511 "nfi2x_sel",
0512 "syspll_d7",
0513 "syspll2_d2",
0514 "univpll2_d2",
0515 "univpll_d5",
0516 "syspll1_d2"
0517 };
0518
0519 static const char * const pe2_mac_p0_parents[] = {
0520 "clk26m",
0521 "syspll1_d8",
0522 "syspll4_d2",
0523 "syspll2_d4",
0524 "univpll2_d4",
0525 "syspll3_d2"
0526 };
0527
0528 static const char * const dpilvds_parents[] = {
0529 "clk26m",
0530 "lvdspll_ck",
0531 "lvdspll_d2",
0532 "lvdspll_d4",
0533 "lvdspll_d8",
0534 "clkfpc"
0535 };
0536
0537 static const char * const hdcp_parents[] = {
0538 "clk26m",
0539 "syspll4_d2",
0540 "syspll3_d4",
0541 "univpll2_d4"
0542 };
0543
0544 static const char * const hdcp_24m_parents[] = {
0545 "clk26m",
0546 "univpll_d26",
0547 "univpll_d52",
0548 "univpll2_d8"
0549 };
0550
0551 static const char * const rtc_parents[] = {
0552 "clkrtc_int",
0553 "clkrtc_ext",
0554 "clk26m",
0555 "univpll3_d8"
0556 };
0557
0558 static const char * const spinor_parents[] = {
0559 "clk26m",
0560 "clk26m_d2",
0561 "syspll4_d4",
0562 "univpll2_d8",
0563 "univpll3_d4",
0564 "syspll4_d2",
0565 "syspll2_d4",
0566 "univpll2_d4",
0567 "etherpll_125m",
0568 "syspll1_d4"
0569 };
0570
0571 static const char * const apll_parents[] = {
0572 "clk26m",
0573 "apll1_ck",
0574 "apll1_d2",
0575 "apll1_d4",
0576 "apll1_d8",
0577 "apll1_d16",
0578 "apll2_ck",
0579 "apll2_d2",
0580 "apll2_d4",
0581 "apll2_d8",
0582 "apll2_d16",
0583 "clk26m",
0584 "clk26m"
0585 };
0586
0587 static const char * const a1sys_hp_parents[] = {
0588 "clk26m",
0589 "apll1_ck",
0590 "apll1_d2",
0591 "apll1_d4",
0592 "apll1_d8",
0593 "apll1_d3"
0594 };
0595
0596 static const char * const a2sys_hp_parents[] = {
0597 "clk26m",
0598 "apll2_ck",
0599 "apll2_d2",
0600 "apll2_d4",
0601 "apll2_d8",
0602 "apll2_d3"
0603 };
0604
0605 static const char * const asm_l_parents[] = {
0606 "clk26m",
0607 "univpll2_d4",
0608 "univpll2_d2",
0609 "syspll_d5"
0610 };
0611
0612 static const char * const i2so1_parents[] = {
0613 "clk26m",
0614 "apll1_ck",
0615 "apll2_ck"
0616 };
0617
0618 static const char * const ether_125m_parents[] = {
0619 "clk26m",
0620 "etherpll_125m",
0621 "univpll3_d2"
0622 };
0623
0624 static const char * const ether_50m_parents[] = {
0625 "clk26m",
0626 "etherpll_50m",
0627 "apll1_d3",
0628 "univpll3_d4"
0629 };
0630
0631 static const char * const jpgdec_parents[] = {
0632 "clk26m",
0633 "univpll_d3",
0634 "tvdpll_429m",
0635 "vencpll_ck",
0636 "syspll_d3",
0637 "vcodecpll_ck",
0638 "univpll1_d2",
0639 "armca35pll_400m",
0640 "tvdpll_429m_d2",
0641 "tvdpll_429m_d4"
0642 };
0643
0644 static const char * const spislv_parents[] = {
0645 "clk26m",
0646 "univpll2_d4",
0647 "univpll1_d4",
0648 "univpll2_d2",
0649 "univpll3_d2",
0650 "univpll1_d8",
0651 "univpll1_d2",
0652 "univpll_d5"
0653 };
0654
0655 static const char * const ether_parents[] = {
0656 "clk26m",
0657 "etherpll_50m",
0658 "univpll_d26"
0659 };
0660
0661 static const char * const di_parents[] = {
0662 "clk26m",
0663 "tvdpll_d2",
0664 "tvdpll_d4",
0665 "tvdpll_d8",
0666 "vencpll_ck",
0667 "vencpll_d2",
0668 "cvbs",
0669 "cvbs_d2"
0670 };
0671
0672 static const char * const tvd_parents[] = {
0673 "clk26m",
0674 "cvbs_d2",
0675 "univpll2_d8"
0676 };
0677
0678 static const char * const i2c_parents[] = {
0679 "clk26m",
0680 "univpll_d26",
0681 "univpll2_d4",
0682 "univpll3_d2",
0683 "univpll1_d4"
0684 };
0685
0686 static const char * const msdc0p_aes_parents[] = {
0687 "clk26m",
0688 "syspll_d2",
0689 "univpll_d3",
0690 "vcodecpll_ck"
0691 };
0692
0693 static const char * const cmsys_parents[] = {
0694 "clk26m",
0695 "univpll_d3",
0696 "syspll_d3",
0697 "syspll1_d2",
0698 "syspll2_d2"
0699 };
0700
0701 static const char * const gcpu_parents[] = {
0702 "clk26m",
0703 "syspll_d3",
0704 "syspll1_d2",
0705 "univpll1_d2",
0706 "univpll_d5",
0707 "univpll3_d2",
0708 "univpll_d3"
0709 };
0710
0711 static const char * const aud_apll1_parents[] = {
0712 "apll1",
0713 "clkaud_ext_i_1"
0714 };
0715
0716 static const char * const aud_apll2_parents[] = {
0717 "apll2",
0718 "clkaud_ext_i_2"
0719 };
0720
0721 static const char * const apll1_ref_parents[] = {
0722 "clkaud_ext_i_2",
0723 "clkaud_ext_i_1",
0724 "clki2si0_mck_i",
0725 "clki2si1_mck_i",
0726 "clki2si2_mck_i",
0727 "clktdmin_mclk_i",
0728 "clki2si2_mck_i",
0729 "clktdmin_mclk_i"
0730 };
0731
0732 static const char * const audull_vtx_parents[] = {
0733 "d2a_ulclk_6p5m",
0734 "clkaud_ext_i_0"
0735 };
0736
0737 static struct mtk_composite top_muxes[] = {
0738
0739 MUX_GATE_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents, 0x040, 0, 3,
0740 7, CLK_IS_CRITICAL),
0741 MUX_GATE_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents, 0x040, 8, 1,
0742 15, CLK_IS_CRITICAL),
0743 MUX_GATE(CLK_TOP_MM_SEL, "mm_sel",
0744 mm_parents, 0x040, 24, 3, 31),
0745
0746 MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel",
0747 pwm_parents, 0x050, 0, 2, 7),
0748 MUX_GATE(CLK_TOP_VDEC_SEL, "vdec_sel",
0749 vdec_parents, 0x050, 8, 4, 15),
0750 MUX_GATE(CLK_TOP_VENC_SEL, "venc_sel",
0751 venc_parents, 0x050, 16, 4, 23),
0752 MUX_GATE(CLK_TOP_MFG_SEL, "mfg_sel",
0753 mfg_parents, 0x050, 24, 4, 31),
0754
0755 MUX_GATE(CLK_TOP_CAMTG_SEL, "camtg_sel",
0756 camtg_parents, 0x060, 0, 4, 7),
0757 MUX_GATE(CLK_TOP_UART_SEL, "uart_sel",
0758 uart_parents, 0x060, 8, 1, 15),
0759 MUX_GATE(CLK_TOP_SPI_SEL, "spi_sel",
0760 spi_parents, 0x060, 16, 3, 23),
0761 MUX_GATE(CLK_TOP_USB20_SEL, "usb20_sel",
0762 usb20_parents, 0x060, 24, 2, 31),
0763
0764 MUX_GATE(CLK_TOP_USB30_SEL, "usb30_sel",
0765 usb30_parents, 0x070, 0, 2, 7),
0766 MUX_GATE(CLK_TOP_MSDC50_0_HCLK_SEL, "msdc50_0_h_sel",
0767 msdc50_0_h_parents, 0x070, 8, 3, 15),
0768 MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
0769 msdc50_0_parents, 0x070, 16, 4, 23),
0770 MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
0771 msdc30_1_parents, 0x070, 24, 3, 31),
0772
0773 MUX_GATE(CLK_TOP_MSDC30_2_SEL, "msdc30_2_sel",
0774 msdc30_1_parents, 0x080, 0, 3, 7),
0775 MUX_GATE(CLK_TOP_MSDC30_3_SEL, "msdc30_3_sel",
0776 msdc30_3_parents, 0x080, 8, 4, 15),
0777 MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel",
0778 audio_parents, 0x080, 16, 2, 23),
0779 MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
0780 aud_intbus_parents, 0x080, 24, 3, 31),
0781
0782 MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel",
0783 pmicspi_parents, 0x090, 0, 3, 7),
0784 MUX_GATE(CLK_TOP_DPILVDS1_SEL, "dpilvds1_sel",
0785 dpilvds1_parents, 0x090, 8, 3, 15),
0786 MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel",
0787 atb_parents, 0x090, 16, 2, 23),
0788 MUX_GATE(CLK_TOP_NR_SEL, "nr_sel",
0789 nr_parents, 0x090, 24, 3, 31),
0790
0791 MUX_GATE(CLK_TOP_NFI2X_SEL, "nfi2x_sel",
0792 nfi2x_parents, 0x0a0, 0, 4, 7),
0793 MUX_GATE(CLK_TOP_IRDA_SEL, "irda_sel",
0794 irda_parents, 0x0a0, 8, 2, 15),
0795 MUX_GATE(CLK_TOP_CCI400_SEL, "cci400_sel",
0796 cci400_parents, 0x0a0, 16, 3, 23),
0797 MUX_GATE(CLK_TOP_AUD_1_SEL, "aud_1_sel",
0798 aud_1_parents, 0x0a0, 24, 2, 31),
0799
0800 MUX_GATE(CLK_TOP_AUD_2_SEL, "aud_2_sel",
0801 aud_2_parents, 0x0b0, 0, 2, 7),
0802 MUX_GATE(CLK_TOP_MEM_MFG_IN_AS_SEL, "mem_mfg_sel",
0803 mem_mfg_parents, 0x0b0, 8, 2, 15),
0804 MUX_GATE(CLK_TOP_AXI_MFG_IN_AS_SEL, "axi_mfg_sel",
0805 axi_mfg_parents, 0x0b0, 16, 2, 23),
0806 MUX_GATE(CLK_TOP_SCAM_SEL, "scam_sel",
0807 scam_parents, 0x0b0, 24, 2, 31),
0808
0809 MUX_GATE(CLK_TOP_NFIECC_SEL, "nfiecc_sel",
0810 nfiecc_parents, 0x0c0, 0, 3, 7),
0811 MUX_GATE(CLK_TOP_PE2_MAC_P0_SEL, "pe2_mac_p0_sel",
0812 pe2_mac_p0_parents, 0x0c0, 8, 3, 15),
0813 MUX_GATE(CLK_TOP_PE2_MAC_P1_SEL, "pe2_mac_p1_sel",
0814 pe2_mac_p0_parents, 0x0c0, 16, 3, 23),
0815 MUX_GATE(CLK_TOP_DPILVDS_SEL, "dpilvds_sel",
0816 dpilvds_parents, 0x0c0, 24, 3, 31),
0817
0818 MUX_GATE(CLK_TOP_MSDC50_3_HCLK_SEL, "msdc50_3_h_sel",
0819 msdc50_0_h_parents, 0x0d0, 0, 3, 7),
0820 MUX_GATE(CLK_TOP_HDCP_SEL, "hdcp_sel",
0821 hdcp_parents, 0x0d0, 8, 2, 15),
0822 MUX_GATE(CLK_TOP_HDCP_24M_SEL, "hdcp_24m_sel",
0823 hdcp_24m_parents, 0x0d0, 16, 2, 23),
0824 MUX_GATE_FLAGS(CLK_TOP_RTC_SEL, "rtc_sel", rtc_parents, 0x0d0, 24, 2,
0825 31, CLK_IS_CRITICAL),
0826
0827 MUX_GATE(CLK_TOP_SPINOR_SEL, "spinor_sel",
0828 spinor_parents, 0x500, 0, 4, 7),
0829 MUX_GATE(CLK_TOP_APLL_SEL, "apll_sel",
0830 apll_parents, 0x500, 8, 4, 15),
0831 MUX_GATE(CLK_TOP_APLL2_SEL, "apll2_sel",
0832 apll_parents, 0x500, 16, 4, 23),
0833 MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel",
0834 a1sys_hp_parents, 0x500, 24, 3, 31),
0835
0836 MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel",
0837 a2sys_hp_parents, 0x510, 0, 3, 7),
0838 MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel",
0839 asm_l_parents, 0x510, 8, 2, 15),
0840 MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel",
0841 asm_l_parents, 0x510, 16, 2, 23),
0842 MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel",
0843 asm_l_parents, 0x510, 24, 2, 31),
0844
0845 MUX_GATE(CLK_TOP_I2SO1_SEL, "i2so1_sel",
0846 i2so1_parents, 0x520, 0, 2, 7),
0847 MUX_GATE(CLK_TOP_I2SO2_SEL, "i2so2_sel",
0848 i2so1_parents, 0x520, 8, 2, 15),
0849 MUX_GATE(CLK_TOP_I2SO3_SEL, "i2so3_sel",
0850 i2so1_parents, 0x520, 16, 2, 23),
0851 MUX_GATE(CLK_TOP_TDMO0_SEL, "tdmo0_sel",
0852 i2so1_parents, 0x520, 24, 2, 31),
0853
0854 MUX_GATE(CLK_TOP_TDMO1_SEL, "tdmo1_sel",
0855 i2so1_parents, 0x530, 0, 2, 7),
0856 MUX_GATE(CLK_TOP_I2SI1_SEL, "i2si1_sel",
0857 i2so1_parents, 0x530, 8, 2, 15),
0858 MUX_GATE(CLK_TOP_I2SI2_SEL, "i2si2_sel",
0859 i2so1_parents, 0x530, 16, 2, 23),
0860 MUX_GATE(CLK_TOP_I2SI3_SEL, "i2si3_sel",
0861 i2so1_parents, 0x530, 24, 2, 31),
0862
0863 MUX_GATE(CLK_TOP_ETHER_125M_SEL, "ether_125m_sel",
0864 ether_125m_parents, 0x540, 0, 2, 7),
0865 MUX_GATE(CLK_TOP_ETHER_50M_SEL, "ether_50m_sel",
0866 ether_50m_parents, 0x540, 8, 2, 15),
0867 MUX_GATE(CLK_TOP_JPGDEC_SEL, "jpgdec_sel",
0868 jpgdec_parents, 0x540, 16, 4, 23),
0869 MUX_GATE(CLK_TOP_SPISLV_SEL, "spislv_sel",
0870 spislv_parents, 0x540, 24, 3, 31),
0871
0872 MUX_GATE(CLK_TOP_ETHER_50M_RMII_SEL, "ether_sel",
0873 ether_parents, 0x550, 0, 2, 7),
0874 MUX_GATE(CLK_TOP_CAM2TG_SEL, "cam2tg_sel",
0875 camtg_parents, 0x550, 8, 4, 15),
0876 MUX_GATE(CLK_TOP_DI_SEL, "di_sel",
0877 di_parents, 0x550, 16, 3, 23),
0878 MUX_GATE(CLK_TOP_TVD_SEL, "tvd_sel",
0879 tvd_parents, 0x550, 24, 2, 31),
0880
0881 MUX_GATE(CLK_TOP_I2C_SEL, "i2c_sel",
0882 i2c_parents, 0x560, 0, 3, 7),
0883 MUX_GATE(CLK_TOP_PWM_INFRA_SEL, "pwm_infra_sel",
0884 pwm_parents, 0x560, 8, 2, 15),
0885 MUX_GATE(CLK_TOP_MSDC0P_AES_SEL, "msdc0p_aes_sel",
0886 msdc0p_aes_parents, 0x560, 16, 2, 23),
0887 MUX_GATE(CLK_TOP_CMSYS_SEL, "cmsys_sel",
0888 cmsys_parents, 0x560, 24, 3, 31),
0889
0890 MUX_GATE(CLK_TOP_GCPU_SEL, "gcpu_sel",
0891 gcpu_parents, 0x570, 0, 3, 7),
0892
0893 MUX(CLK_TOP_AUD_APLL1_SEL, "aud_apll1_sel",
0894 aud_apll1_parents, 0x134, 0, 1),
0895 MUX(CLK_TOP_AUD_APLL2_SEL, "aud_apll2_sel",
0896 aud_apll2_parents, 0x134, 1, 1),
0897 MUX(CLK_TOP_DA_AUDULL_VTX_6P5M_SEL, "audull_vtx_sel",
0898 audull_vtx_parents, 0x134, 31, 1),
0899 MUX(CLK_TOP_APLL1_REF_SEL, "apll1_ref_sel",
0900 apll1_ref_parents, 0x134, 4, 3),
0901 MUX(CLK_TOP_APLL2_REF_SEL, "apll2_ref_sel",
0902 apll1_ref_parents, 0x134, 7, 3),
0903 };
0904
0905 static const char * const mcu_mp0_parents[] = {
0906 "clk26m",
0907 "armca35pll_ck",
0908 "f_mp0_pll1_ck",
0909 "f_mp0_pll2_ck"
0910 };
0911
0912 static const char * const mcu_mp2_parents[] = {
0913 "clk26m",
0914 "armca72pll_ck",
0915 "f_big_pll1_ck",
0916 "f_big_pll2_ck"
0917 };
0918
0919 static const char * const mcu_bus_parents[] = {
0920 "clk26m",
0921 "cci400_sel",
0922 "f_bus_pll1_ck",
0923 "f_bus_pll2_ck"
0924 };
0925
0926 static struct mtk_composite mcu_muxes[] = {
0927
0928 MUX_GATE_FLAGS(CLK_MCU_MP0_SEL, "mcu_mp0_sel", mcu_mp0_parents, 0x7A0,
0929 9, 2, -1, CLK_IS_CRITICAL),
0930
0931 MUX_GATE_FLAGS(CLK_MCU_MP2_SEL, "mcu_mp2_sel", mcu_mp2_parents, 0x7A8,
0932 9, 2, -1, CLK_IS_CRITICAL),
0933
0934 MUX_GATE_FLAGS(CLK_MCU_BUS_SEL, "mcu_bus_sel", mcu_bus_parents, 0x7C0,
0935 9, 2, -1, CLK_IS_CRITICAL),
0936 };
0937
0938 static const struct mtk_clk_divider top_adj_divs[] = {
0939 DIV_ADJ(CLK_TOP_APLL_DIV0, "apll_div0", "i2so1_sel", 0x124, 0, 8),
0940 DIV_ADJ(CLK_TOP_APLL_DIV1, "apll_div1", "i2so2_sel", 0x124, 8, 8),
0941 DIV_ADJ(CLK_TOP_APLL_DIV2, "apll_div2", "i2so3_sel", 0x124, 16, 8),
0942 DIV_ADJ(CLK_TOP_APLL_DIV3, "apll_div3", "tdmo0_sel", 0x124, 24, 8),
0943 DIV_ADJ(CLK_TOP_APLL_DIV4, "apll_div4", "tdmo1_sel", 0x128, 0, 8),
0944 DIV_ADJ(CLK_TOP_APLL_DIV5, "apll_div5", "i2si1_sel", 0x128, 8, 8),
0945 DIV_ADJ(CLK_TOP_APLL_DIV6, "apll_div6", "i2si2_sel", 0x128, 16, 8),
0946 DIV_ADJ(CLK_TOP_APLL_DIV7, "apll_div7", "i2si3_sel", 0x128, 24, 8),
0947 };
0948
0949 static const struct mtk_gate_regs top0_cg_regs = {
0950 .set_ofs = 0x120,
0951 .clr_ofs = 0x120,
0952 .sta_ofs = 0x120,
0953 };
0954
0955 static const struct mtk_gate_regs top1_cg_regs = {
0956 .set_ofs = 0x424,
0957 .clr_ofs = 0x424,
0958 .sta_ofs = 0x424,
0959 };
0960
0961 #define GATE_TOP0(_id, _name, _parent, _shift) { \
0962 .id = _id, \
0963 .name = _name, \
0964 .parent_name = _parent, \
0965 .regs = &top0_cg_regs, \
0966 .shift = _shift, \
0967 .ops = &mtk_clk_gate_ops_no_setclr, \
0968 }
0969
0970 #define GATE_TOP1(_id, _name, _parent, _shift) { \
0971 .id = _id, \
0972 .name = _name, \
0973 .parent_name = _parent, \
0974 .regs = &top1_cg_regs, \
0975 .shift = _shift, \
0976 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
0977 }
0978
0979 static const struct mtk_gate top_clks[] = {
0980
0981 GATE_TOP0(CLK_TOP_APLL_DIV_PDN0, "apll_div_pdn0", "i2so1_sel", 0),
0982 GATE_TOP0(CLK_TOP_APLL_DIV_PDN1, "apll_div_pdn1", "i2so2_sel", 1),
0983 GATE_TOP0(CLK_TOP_APLL_DIV_PDN2, "apll_div_pdn2", "i2so3_sel", 2),
0984 GATE_TOP0(CLK_TOP_APLL_DIV_PDN3, "apll_div_pdn3", "tdmo0_sel", 3),
0985 GATE_TOP0(CLK_TOP_APLL_DIV_PDN4, "apll_div_pdn4", "tdmo1_sel", 4),
0986 GATE_TOP0(CLK_TOP_APLL_DIV_PDN5, "apll_div_pdn5", "i2si1_sel", 5),
0987 GATE_TOP0(CLK_TOP_APLL_DIV_PDN6, "apll_div_pdn6", "i2si2_sel", 6),
0988 GATE_TOP0(CLK_TOP_APLL_DIV_PDN7, "apll_div_pdn7", "i2si3_sel", 7),
0989
0990 GATE_TOP1(CLK_TOP_NFI2X_EN, "nfi2x_en", "nfi2x_sel", 0),
0991 GATE_TOP1(CLK_TOP_NFIECC_EN, "nfiecc_en", "nfiecc_sel", 1),
0992 GATE_TOP1(CLK_TOP_NFI1X_CK_EN, "nfi1x_ck_en", "nfi2x_sel", 2),
0993 };
0994
0995 static const struct mtk_gate_regs infra_cg_regs = {
0996 .set_ofs = 0x40,
0997 .clr_ofs = 0x44,
0998 .sta_ofs = 0x48,
0999 };
1000
1001 #define GATE_INFRA(_id, _name, _parent, _shift) { \
1002 .id = _id, \
1003 .name = _name, \
1004 .parent_name = _parent, \
1005 .regs = &infra_cg_regs, \
1006 .shift = _shift, \
1007 .ops = &mtk_clk_gate_ops_setclr, \
1008 }
1009
1010 static const struct mtk_gate infra_clks[] = {
1011 GATE_INFRA(CLK_INFRA_DBGCLK, "infra_dbgclk", "axi_sel", 0),
1012 GATE_INFRA(CLK_INFRA_GCE, "infra_gce", "axi_sel", 6),
1013 GATE_INFRA(CLK_INFRA_M4U, "infra_m4u", "mem_sel", 8),
1014 GATE_INFRA(CLK_INFRA_KP, "infra_kp", "axi_sel", 16),
1015 GATE_INFRA(CLK_INFRA_AO_SPI0, "infra_ao_spi0", "spi_sel", 24),
1016 GATE_INFRA(CLK_INFRA_AO_SPI1, "infra_ao_spi1", "spislv_sel", 25),
1017 GATE_INFRA(CLK_INFRA_AO_UART5, "infra_ao_uart5", "axi_sel", 26),
1018 };
1019
1020 static const struct mtk_gate_regs peri0_cg_regs = {
1021 .set_ofs = 0x8,
1022 .clr_ofs = 0x10,
1023 .sta_ofs = 0x18,
1024 };
1025
1026 static const struct mtk_gate_regs peri1_cg_regs = {
1027 .set_ofs = 0xc,
1028 .clr_ofs = 0x14,
1029 .sta_ofs = 0x1c,
1030 };
1031
1032 static const struct mtk_gate_regs peri2_cg_regs = {
1033 .set_ofs = 0x42c,
1034 .clr_ofs = 0x42c,
1035 .sta_ofs = 0x42c,
1036 };
1037
1038 #define GATE_PERI0(_id, _name, _parent, _shift) { \
1039 .id = _id, \
1040 .name = _name, \
1041 .parent_name = _parent, \
1042 .regs = &peri0_cg_regs, \
1043 .shift = _shift, \
1044 .ops = &mtk_clk_gate_ops_setclr, \
1045 }
1046
1047 #define GATE_PERI1(_id, _name, _parent, _shift) { \
1048 .id = _id, \
1049 .name = _name, \
1050 .parent_name = _parent, \
1051 .regs = &peri1_cg_regs, \
1052 .shift = _shift, \
1053 .ops = &mtk_clk_gate_ops_setclr, \
1054 }
1055
1056 #define GATE_PERI2(_id, _name, _parent, _shift) { \
1057 .id = _id, \
1058 .name = _name, \
1059 .parent_name = _parent, \
1060 .regs = &peri2_cg_regs, \
1061 .shift = _shift, \
1062 .ops = &mtk_clk_gate_ops_no_setclr_inv, \
1063 }
1064
1065 static const struct mtk_gate peri_clks[] = {
1066
1067 GATE_PERI0(CLK_PERI_NFI, "per_nfi",
1068 "axi_sel", 0),
1069 GATE_PERI0(CLK_PERI_THERM, "per_therm",
1070 "axi_sel", 1),
1071 GATE_PERI0(CLK_PERI_PWM0, "per_pwm0",
1072 "pwm_sel", 2),
1073 GATE_PERI0(CLK_PERI_PWM1, "per_pwm1",
1074 "pwm_sel", 3),
1075 GATE_PERI0(CLK_PERI_PWM2, "per_pwm2",
1076 "pwm_sel", 4),
1077 GATE_PERI0(CLK_PERI_PWM3, "per_pwm3",
1078 "pwm_sel", 5),
1079 GATE_PERI0(CLK_PERI_PWM4, "per_pwm4",
1080 "pwm_sel", 6),
1081 GATE_PERI0(CLK_PERI_PWM5, "per_pwm5",
1082 "pwm_sel", 7),
1083 GATE_PERI0(CLK_PERI_PWM6, "per_pwm6",
1084 "pwm_sel", 8),
1085 GATE_PERI0(CLK_PERI_PWM7, "per_pwm7",
1086 "pwm_sel", 9),
1087 GATE_PERI0(CLK_PERI_PWM, "per_pwm",
1088 "pwm_sel", 10),
1089 GATE_PERI0(CLK_PERI_AP_DMA, "per_ap_dma",
1090 "axi_sel", 13),
1091 GATE_PERI0(CLK_PERI_MSDC30_0, "per_msdc30_0",
1092 "msdc50_0_sel", 14),
1093 GATE_PERI0(CLK_PERI_MSDC30_1, "per_msdc30_1",
1094 "msdc30_1_sel", 15),
1095 GATE_PERI0(CLK_PERI_MSDC30_2, "per_msdc30_2",
1096 "msdc30_2_sel", 16),
1097 GATE_PERI0(CLK_PERI_MSDC30_3, "per_msdc30_3",
1098 "msdc30_3_sel", 17),
1099 GATE_PERI0(CLK_PERI_UART0, "per_uart0",
1100 "uart_sel", 20),
1101 GATE_PERI0(CLK_PERI_UART1, "per_uart1",
1102 "uart_sel", 21),
1103 GATE_PERI0(CLK_PERI_UART2, "per_uart2",
1104 "uart_sel", 22),
1105 GATE_PERI0(CLK_PERI_UART3, "per_uart3",
1106 "uart_sel", 23),
1107 GATE_PERI0(CLK_PERI_I2C0, "per_i2c0",
1108 "axi_sel", 24),
1109 GATE_PERI0(CLK_PERI_I2C1, "per_i2c1",
1110 "axi_sel", 25),
1111 GATE_PERI0(CLK_PERI_I2C2, "per_i2c2",
1112 "axi_sel", 26),
1113 GATE_PERI0(CLK_PERI_I2C3, "per_i2c3",
1114 "axi_sel", 27),
1115 GATE_PERI0(CLK_PERI_I2C4, "per_i2c4",
1116 "axi_sel", 28),
1117 GATE_PERI0(CLK_PERI_AUXADC, "per_auxadc",
1118 "ltepll_fs26m", 29),
1119 GATE_PERI0(CLK_PERI_SPI0, "per_spi0",
1120 "spi_sel", 30),
1121
1122 GATE_PERI1(CLK_PERI_SPI, "per_spi",
1123 "spinor_sel", 1),
1124 GATE_PERI1(CLK_PERI_I2C5, "per_i2c5",
1125 "axi_sel", 3),
1126 GATE_PERI1(CLK_PERI_SPI2, "per_spi2",
1127 "spi_sel", 5),
1128 GATE_PERI1(CLK_PERI_SPI3, "per_spi3",
1129 "spi_sel", 6),
1130 GATE_PERI1(CLK_PERI_SPI5, "per_spi5",
1131 "spi_sel", 8),
1132 GATE_PERI1(CLK_PERI_UART4, "per_uart4",
1133 "uart_sel", 9),
1134 GATE_PERI1(CLK_PERI_SFLASH, "per_sflash",
1135 "uart_sel", 11),
1136 GATE_PERI1(CLK_PERI_GMAC, "per_gmac",
1137 "uart_sel", 12),
1138 GATE_PERI1(CLK_PERI_PCIE0, "per_pcie0",
1139 "uart_sel", 14),
1140 GATE_PERI1(CLK_PERI_PCIE1, "per_pcie1",
1141 "uart_sel", 15),
1142 GATE_PERI1(CLK_PERI_GMAC_PCLK, "per_gmac_pclk",
1143 "uart_sel", 16),
1144
1145 GATE_PERI2(CLK_PERI_MSDC50_0_EN, "per_msdc50_0_en",
1146 "msdc50_0_sel", 0),
1147 GATE_PERI2(CLK_PERI_MSDC30_1_EN, "per_msdc30_1_en",
1148 "msdc30_1_sel", 1),
1149 GATE_PERI2(CLK_PERI_MSDC30_2_EN, "per_msdc30_2_en",
1150 "msdc30_2_sel", 2),
1151 GATE_PERI2(CLK_PERI_MSDC30_3_EN, "per_msdc30_3_en",
1152 "msdc30_3_sel", 3),
1153 GATE_PERI2(CLK_PERI_MSDC50_0_HCLK_EN, "per_msdc50_0_h",
1154 "msdc50_0_h_sel", 4),
1155 GATE_PERI2(CLK_PERI_MSDC50_3_HCLK_EN, "per_msdc50_3_h",
1156 "msdc50_3_h_sel", 5),
1157 GATE_PERI2(CLK_PERI_MSDC30_0_QTR_EN, "per_msdc30_0_q",
1158 "axi_sel", 6),
1159 GATE_PERI2(CLK_PERI_MSDC30_3_QTR_EN, "per_msdc30_3_q",
1160 "mem_sel", 7),
1161 };
1162
1163 #define MT2712_PLL_FMAX (3000UL * MHZ)
1164
1165 #define CON0_MT2712_RST_BAR BIT(24)
1166
1167 #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
1168 _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
1169 _tuner_en_bit, _pcw_reg, _pcw_shift, \
1170 _div_table) { \
1171 .id = _id, \
1172 .name = _name, \
1173 .reg = _reg, \
1174 .pwr_reg = _pwr_reg, \
1175 .en_mask = _en_mask, \
1176 .flags = _flags, \
1177 .rst_bar_mask = CON0_MT2712_RST_BAR, \
1178 .fmax = MT2712_PLL_FMAX, \
1179 .pcwbits = _pcwbits, \
1180 .pd_reg = _pd_reg, \
1181 .pd_shift = _pd_shift, \
1182 .tuner_reg = _tuner_reg, \
1183 .tuner_en_reg = _tuner_en_reg, \
1184 .tuner_en_bit = _tuner_en_bit, \
1185 .pcw_reg = _pcw_reg, \
1186 .pcw_shift = _pcw_shift, \
1187 .div_table = _div_table, \
1188 }
1189
1190 #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
1191 _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg, \
1192 _tuner_en_bit, _pcw_reg, _pcw_shift) \
1193 PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, \
1194 _pcwbits, _pd_reg, _pd_shift, _tuner_reg, \
1195 _tuner_en_reg, _tuner_en_bit, _pcw_reg, \
1196 _pcw_shift, NULL)
1197
1198 static const struct mtk_pll_div_table armca35pll_div_table[] = {
1199 { .div = 0, .freq = MT2712_PLL_FMAX },
1200 { .div = 1, .freq = 1202500000 },
1201 { .div = 2, .freq = 500500000 },
1202 { .div = 3, .freq = 315250000 },
1203 { .div = 4, .freq = 157625000 },
1204 { }
1205 };
1206
1207 static const struct mtk_pll_div_table armca72pll_div_table[] = {
1208 { .div = 0, .freq = MT2712_PLL_FMAX },
1209 { .div = 1, .freq = 994500000 },
1210 { .div = 2, .freq = 520000000 },
1211 { .div = 3, .freq = 315250000 },
1212 { .div = 4, .freq = 157625000 },
1213 { }
1214 };
1215
1216 static const struct mtk_pll_div_table mmpll_div_table[] = {
1217 { .div = 0, .freq = MT2712_PLL_FMAX },
1218 { .div = 1, .freq = 1001000000 },
1219 { .div = 2, .freq = 601250000 },
1220 { .div = 3, .freq = 250250000 },
1221 { .div = 4, .freq = 125125000 },
1222 { }
1223 };
1224
1225 static const struct mtk_pll_data plls[] = {
1226 PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0230, 0x023C, 0xf0000100,
1227 HAVE_RST_BAR, 31, 0x0230, 4, 0, 0, 0, 0x0234, 0),
1228 PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0240, 0x024C, 0xfe000100,
1229 HAVE_RST_BAR, 31, 0x0240, 4, 0, 0, 0, 0x0244, 0),
1230 PLL(CLK_APMIXED_VCODECPLL, "vcodecpll", 0x0320, 0x032C, 0xc0000100,
1231 0, 31, 0x0320, 4, 0, 0, 0, 0x0324, 0),
1232 PLL(CLK_APMIXED_VENCPLL, "vencpll", 0x0280, 0x028C, 0x00000100,
1233 0, 31, 0x0280, 4, 0, 0, 0, 0x0284, 0),
1234 PLL(CLK_APMIXED_APLL1, "apll1", 0x0330, 0x0340, 0x00000100,
1235 0, 31, 0x0330, 4, 0x0338, 0x0014, 0, 0x0334, 0),
1236 PLL(CLK_APMIXED_APLL2, "apll2", 0x0350, 0x0360, 0x00000100,
1237 0, 31, 0x0350, 4, 0x0358, 0x0014, 1, 0x0354, 0),
1238 PLL(CLK_APMIXED_LVDSPLL, "lvdspll", 0x0370, 0x037c, 0x00000100,
1239 0, 31, 0x0370, 4, 0, 0, 0, 0x0374, 0),
1240 PLL(CLK_APMIXED_LVDSPLL2, "lvdspll2", 0x0390, 0x039C, 0x00000100,
1241 0, 31, 0x0390, 4, 0, 0, 0, 0x0394, 0),
1242 PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0270, 0x027C, 0x00000100,
1243 0, 31, 0x0270, 4, 0, 0, 0, 0x0274, 0),
1244 PLL(CLK_APMIXED_MSDCPLL2, "msdcpll2", 0x0410, 0x041C, 0x00000100,
1245 0, 31, 0x0410, 4, 0, 0, 0, 0x0414, 0),
1246 PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0290, 0x029C, 0xc0000100,
1247 0, 31, 0x0290, 4, 0, 0, 0, 0x0294, 0),
1248 PLL_B(CLK_APMIXED_MMPLL, "mmpll", 0x0250, 0x0260, 0x00000100,
1249 0, 31, 0x0250, 4, 0, 0, 0, 0x0254, 0,
1250 mmpll_div_table),
1251 PLL_B(CLK_APMIXED_ARMCA35PLL, "armca35pll", 0x0100, 0x0110, 0xf0000100,
1252 HAVE_RST_BAR, 31, 0x0100, 4, 0, 0, 0, 0x0104, 0,
1253 armca35pll_div_table),
1254 PLL_B(CLK_APMIXED_ARMCA72PLL, "armca72pll", 0x0210, 0x0220, 0x00000100,
1255 0, 31, 0x0210, 4, 0, 0, 0, 0x0214, 0,
1256 armca72pll_div_table),
1257 PLL(CLK_APMIXED_ETHERPLL, "etherpll", 0x0300, 0x030C, 0xc0000100,
1258 0, 31, 0x0300, 4, 0, 0, 0, 0x0304, 0),
1259 };
1260
1261 static u16 infrasys_rst_ofs[] = { 0x30, 0x34, };
1262 static u16 pericfg_rst_ofs[] = { 0x0, 0x4, };
1263
1264 static const struct mtk_clk_rst_desc clk_rst_desc[] = {
1265
1266 {
1267 .version = MTK_RST_SIMPLE,
1268 .rst_bank_ofs = infrasys_rst_ofs,
1269 .rst_bank_nr = ARRAY_SIZE(infrasys_rst_ofs),
1270 },
1271
1272 {
1273 .version = MTK_RST_SIMPLE,
1274 .rst_bank_ofs = pericfg_rst_ofs,
1275 .rst_bank_nr = ARRAY_SIZE(pericfg_rst_ofs),
1276 },
1277 };
1278
1279 static int clk_mt2712_apmixed_probe(struct platform_device *pdev)
1280 {
1281 struct clk_hw_onecell_data *clk_data;
1282 int r;
1283 struct device_node *node = pdev->dev.of_node;
1284
1285 clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
1286
1287 mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
1288
1289 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
1290
1291 if (r != 0)
1292 pr_err("%s(): could not register clock provider: %d\n",
1293 __func__, r);
1294
1295 return r;
1296 }
1297
1298 static struct clk_hw_onecell_data *top_clk_data;
1299
1300 static void clk_mt2712_top_init_early(struct device_node *node)
1301 {
1302 int r, i;
1303
1304 if (!top_clk_data) {
1305 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1306
1307 for (i = 0; i < CLK_TOP_NR_CLK; i++)
1308 top_clk_data->hws[i] = ERR_PTR(-EPROBE_DEFER);
1309 }
1310
1311 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
1312 top_clk_data);
1313
1314 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data);
1315 if (r)
1316 pr_err("%s(): could not register clock provider: %d\n",
1317 __func__, r);
1318 }
1319
1320 CLK_OF_DECLARE_DRIVER(mt2712_topckgen, "mediatek,mt2712-topckgen",
1321 clk_mt2712_top_init_early);
1322
1323 static int clk_mt2712_top_probe(struct platform_device *pdev)
1324 {
1325 int r, i;
1326 struct device_node *node = pdev->dev.of_node;
1327 void __iomem *base;
1328
1329 base = devm_platform_ioremap_resource(pdev, 0);
1330 if (IS_ERR(base)) {
1331 pr_err("%s(): ioremap failed\n", __func__);
1332 return PTR_ERR(base);
1333 }
1334
1335 if (!top_clk_data) {
1336 top_clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
1337 } else {
1338 for (i = 0; i < CLK_TOP_NR_CLK; i++) {
1339 if (top_clk_data->hws[i] == ERR_PTR(-EPROBE_DEFER))
1340 top_clk_data->hws[i] = ERR_PTR(-ENOENT);
1341 }
1342 }
1343
1344 mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
1345 top_clk_data);
1346 mtk_clk_register_factors(top_early_divs, ARRAY_SIZE(top_early_divs),
1347 top_clk_data);
1348 mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs), top_clk_data);
1349 mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
1350 &mt2712_clk_lock, top_clk_data);
1351 mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs), base,
1352 &mt2712_clk_lock, top_clk_data);
1353 mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
1354 top_clk_data);
1355
1356 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, top_clk_data);
1357
1358 if (r != 0)
1359 pr_err("%s(): could not register clock provider: %d\n",
1360 __func__, r);
1361
1362 return r;
1363 }
1364
1365 static int clk_mt2712_infra_probe(struct platform_device *pdev)
1366 {
1367 struct clk_hw_onecell_data *clk_data;
1368 int r;
1369 struct device_node *node = pdev->dev.of_node;
1370
1371 clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
1372
1373 mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
1374 clk_data);
1375
1376 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
1377
1378 if (r != 0)
1379 pr_err("%s(): could not register clock provider: %d\n",
1380 __func__, r);
1381
1382 mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[0]);
1383
1384 return r;
1385 }
1386
1387 static int clk_mt2712_peri_probe(struct platform_device *pdev)
1388 {
1389 struct clk_hw_onecell_data *clk_data;
1390 int r;
1391 struct device_node *node = pdev->dev.of_node;
1392
1393 clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
1394
1395 mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
1396 clk_data);
1397
1398 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
1399
1400 if (r != 0)
1401 pr_err("%s(): could not register clock provider: %d\n",
1402 __func__, r);
1403
1404 mtk_register_reset_controller_with_dev(&pdev->dev, &clk_rst_desc[1]);
1405
1406 return r;
1407 }
1408
1409 static int clk_mt2712_mcu_probe(struct platform_device *pdev)
1410 {
1411 struct clk_hw_onecell_data *clk_data;
1412 int r;
1413 struct device_node *node = pdev->dev.of_node;
1414 void __iomem *base;
1415
1416 base = devm_platform_ioremap_resource(pdev, 0);
1417 if (IS_ERR(base)) {
1418 pr_err("%s(): ioremap failed\n", __func__);
1419 return PTR_ERR(base);
1420 }
1421
1422 clk_data = mtk_alloc_clk_data(CLK_MCU_NR_CLK);
1423
1424 mtk_clk_register_composites(mcu_muxes, ARRAY_SIZE(mcu_muxes), base,
1425 &mt2712_clk_lock, clk_data);
1426
1427 r = of_clk_add_hw_provider(node, of_clk_hw_onecell_get, clk_data);
1428
1429 if (r != 0)
1430 pr_err("%s(): could not register clock provider: %d\n",
1431 __func__, r);
1432
1433 return r;
1434 }
1435
1436 static const struct of_device_id of_match_clk_mt2712[] = {
1437 {
1438 .compatible = "mediatek,mt2712-apmixedsys",
1439 .data = clk_mt2712_apmixed_probe,
1440 }, {
1441 .compatible = "mediatek,mt2712-topckgen",
1442 .data = clk_mt2712_top_probe,
1443 }, {
1444 .compatible = "mediatek,mt2712-infracfg",
1445 .data = clk_mt2712_infra_probe,
1446 }, {
1447 .compatible = "mediatek,mt2712-pericfg",
1448 .data = clk_mt2712_peri_probe,
1449 }, {
1450 .compatible = "mediatek,mt2712-mcucfg",
1451 .data = clk_mt2712_mcu_probe,
1452 }, {
1453
1454 }
1455 };
1456
1457 static int clk_mt2712_probe(struct platform_device *pdev)
1458 {
1459 int (*clk_probe)(struct platform_device *);
1460 int r;
1461
1462 clk_probe = of_device_get_match_data(&pdev->dev);
1463 if (!clk_probe)
1464 return -EINVAL;
1465
1466 r = clk_probe(pdev);
1467 if (r != 0)
1468 dev_err(&pdev->dev,
1469 "could not register clock provider: %s: %d\n",
1470 pdev->name, r);
1471
1472 return r;
1473 }
1474
1475 static struct platform_driver clk_mt2712_drv = {
1476 .probe = clk_mt2712_probe,
1477 .driver = {
1478 .name = "clk-mt2712",
1479 .of_match_table = of_match_clk_mt2712,
1480 },
1481 };
1482
1483 static int __init clk_mt2712_init(void)
1484 {
1485 return platform_driver_register(&clk_mt2712_drv);
1486 }
1487
1488 arch_initcall(clk_mt2712_init);