1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Copyright (c) 2017 MediaTek Inc.
4*4882a593Smuzhiyun * Author: Chen Zhong <chen.zhong@mediatek.com>
5*4882a593Smuzhiyun * Sean Wang <sean.wang@mediatek.com>
6*4882a593Smuzhiyun */
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <linux/clk-provider.h>
9*4882a593Smuzhiyun #include <linux/of.h>
10*4882a593Smuzhiyun #include <linux/of_address.h>
11*4882a593Smuzhiyun #include <linux/of_device.h>
12*4882a593Smuzhiyun #include <linux/platform_device.h>
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun #include "clk-mtk.h"
15*4882a593Smuzhiyun #include "clk-gate.h"
16*4882a593Smuzhiyun #include "clk-cpumux.h"
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <dt-bindings/clock/mt7622-clk.h>
19*4882a593Smuzhiyun #include <linux/clk.h> /* for consumer */
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun #define MT7622_PLL_FMAX (2500UL * MHZ)
22*4882a593Smuzhiyun #define CON0_MT7622_RST_BAR BIT(27)
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun #define PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
25*4882a593Smuzhiyun _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
26*4882a593Smuzhiyun _pcw_shift, _div_table, _parent_name) { \
27*4882a593Smuzhiyun .id = _id, \
28*4882a593Smuzhiyun .name = _name, \
29*4882a593Smuzhiyun .reg = _reg, \
30*4882a593Smuzhiyun .pwr_reg = _pwr_reg, \
31*4882a593Smuzhiyun .en_mask = _en_mask, \
32*4882a593Smuzhiyun .flags = _flags, \
33*4882a593Smuzhiyun .rst_bar_mask = CON0_MT7622_RST_BAR, \
34*4882a593Smuzhiyun .fmax = MT7622_PLL_FMAX, \
35*4882a593Smuzhiyun .pcwbits = _pcwbits, \
36*4882a593Smuzhiyun .pd_reg = _pd_reg, \
37*4882a593Smuzhiyun .pd_shift = _pd_shift, \
38*4882a593Smuzhiyun .tuner_reg = _tuner_reg, \
39*4882a593Smuzhiyun .pcw_reg = _pcw_reg, \
40*4882a593Smuzhiyun .pcw_shift = _pcw_shift, \
41*4882a593Smuzhiyun .div_table = _div_table, \
42*4882a593Smuzhiyun .parent_name = _parent_name, \
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
46*4882a593Smuzhiyun _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, \
47*4882a593Smuzhiyun _pcw_shift) \
48*4882a593Smuzhiyun PLL_xtal(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,\
49*4882a593Smuzhiyun _pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
50*4882a593Smuzhiyun NULL, "clkxtal")
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #define GATE_APMIXED(_id, _name, _parent, _shift) { \
53*4882a593Smuzhiyun .id = _id, \
54*4882a593Smuzhiyun .name = _name, \
55*4882a593Smuzhiyun .parent_name = _parent, \
56*4882a593Smuzhiyun .regs = &apmixed_cg_regs, \
57*4882a593Smuzhiyun .shift = _shift, \
58*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_no_setclr_inv, \
59*4882a593Smuzhiyun }
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun #define GATE_INFRA(_id, _name, _parent, _shift) { \
62*4882a593Smuzhiyun .id = _id, \
63*4882a593Smuzhiyun .name = _name, \
64*4882a593Smuzhiyun .parent_name = _parent, \
65*4882a593Smuzhiyun .regs = &infra_cg_regs, \
66*4882a593Smuzhiyun .shift = _shift, \
67*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_setclr, \
68*4882a593Smuzhiyun }
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun #define GATE_TOP0(_id, _name, _parent, _shift) { \
71*4882a593Smuzhiyun .id = _id, \
72*4882a593Smuzhiyun .name = _name, \
73*4882a593Smuzhiyun .parent_name = _parent, \
74*4882a593Smuzhiyun .regs = &top0_cg_regs, \
75*4882a593Smuzhiyun .shift = _shift, \
76*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_no_setclr, \
77*4882a593Smuzhiyun }
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun #define GATE_TOP1(_id, _name, _parent, _shift) { \
80*4882a593Smuzhiyun .id = _id, \
81*4882a593Smuzhiyun .name = _name, \
82*4882a593Smuzhiyun .parent_name = _parent, \
83*4882a593Smuzhiyun .regs = &top1_cg_regs, \
84*4882a593Smuzhiyun .shift = _shift, \
85*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_no_setclr, \
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun #define GATE_PERI0(_id, _name, _parent, _shift) { \
89*4882a593Smuzhiyun .id = _id, \
90*4882a593Smuzhiyun .name = _name, \
91*4882a593Smuzhiyun .parent_name = _parent, \
92*4882a593Smuzhiyun .regs = &peri0_cg_regs, \
93*4882a593Smuzhiyun .shift = _shift, \
94*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_setclr, \
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun #define GATE_PERI1(_id, _name, _parent, _shift) { \
98*4882a593Smuzhiyun .id = _id, \
99*4882a593Smuzhiyun .name = _name, \
100*4882a593Smuzhiyun .parent_name = _parent, \
101*4882a593Smuzhiyun .regs = &peri1_cg_regs, \
102*4882a593Smuzhiyun .shift = _shift, \
103*4882a593Smuzhiyun .ops = &mtk_clk_gate_ops_setclr, \
104*4882a593Smuzhiyun }
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun static DEFINE_SPINLOCK(mt7622_clk_lock);
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun static const char * const infra_mux1_parents[] = {
109*4882a593Smuzhiyun "clkxtal",
110*4882a593Smuzhiyun "armpll",
111*4882a593Smuzhiyun "main_core_en",
112*4882a593Smuzhiyun "armpll"
113*4882a593Smuzhiyun };
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun static const char * const axi_parents[] = {
116*4882a593Smuzhiyun "clkxtal",
117*4882a593Smuzhiyun "syspll1_d2",
118*4882a593Smuzhiyun "syspll_d5",
119*4882a593Smuzhiyun "syspll1_d4",
120*4882a593Smuzhiyun "univpll_d5",
121*4882a593Smuzhiyun "univpll2_d2",
122*4882a593Smuzhiyun "univpll_d7"
123*4882a593Smuzhiyun };
124*4882a593Smuzhiyun
125*4882a593Smuzhiyun static const char * const mem_parents[] = {
126*4882a593Smuzhiyun "clkxtal",
127*4882a593Smuzhiyun "dmpll_ck"
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun static const char * const ddrphycfg_parents[] = {
131*4882a593Smuzhiyun "clkxtal",
132*4882a593Smuzhiyun "syspll1_d8"
133*4882a593Smuzhiyun };
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun static const char * const eth_parents[] = {
136*4882a593Smuzhiyun "clkxtal",
137*4882a593Smuzhiyun "syspll1_d2",
138*4882a593Smuzhiyun "univpll1_d2",
139*4882a593Smuzhiyun "syspll1_d4",
140*4882a593Smuzhiyun "univpll_d5",
141*4882a593Smuzhiyun "clk_null",
142*4882a593Smuzhiyun "univpll_d7"
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun static const char * const pwm_parents[] = {
146*4882a593Smuzhiyun "clkxtal",
147*4882a593Smuzhiyun "univpll2_d4"
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun static const char * const f10m_ref_parents[] = {
151*4882a593Smuzhiyun "clkxtal",
152*4882a593Smuzhiyun "syspll4_d16"
153*4882a593Smuzhiyun };
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun static const char * const nfi_infra_parents[] = {
156*4882a593Smuzhiyun "clkxtal",
157*4882a593Smuzhiyun "clkxtal",
158*4882a593Smuzhiyun "clkxtal",
159*4882a593Smuzhiyun "clkxtal",
160*4882a593Smuzhiyun "clkxtal",
161*4882a593Smuzhiyun "clkxtal",
162*4882a593Smuzhiyun "clkxtal",
163*4882a593Smuzhiyun "clkxtal",
164*4882a593Smuzhiyun "univpll2_d8",
165*4882a593Smuzhiyun "syspll1_d8",
166*4882a593Smuzhiyun "univpll1_d8",
167*4882a593Smuzhiyun "syspll4_d2",
168*4882a593Smuzhiyun "univpll2_d4",
169*4882a593Smuzhiyun "univpll3_d2",
170*4882a593Smuzhiyun "syspll1_d4"
171*4882a593Smuzhiyun };
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun static const char * const flash_parents[] = {
174*4882a593Smuzhiyun "clkxtal",
175*4882a593Smuzhiyun "univpll_d80_d4",
176*4882a593Smuzhiyun "syspll2_d8",
177*4882a593Smuzhiyun "syspll3_d4",
178*4882a593Smuzhiyun "univpll3_d4",
179*4882a593Smuzhiyun "univpll1_d8",
180*4882a593Smuzhiyun "syspll2_d4",
181*4882a593Smuzhiyun "univpll2_d4"
182*4882a593Smuzhiyun };
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun static const char * const uart_parents[] = {
185*4882a593Smuzhiyun "clkxtal",
186*4882a593Smuzhiyun "univpll2_d8"
187*4882a593Smuzhiyun };
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun static const char * const spi0_parents[] = {
190*4882a593Smuzhiyun "clkxtal",
191*4882a593Smuzhiyun "syspll3_d2",
192*4882a593Smuzhiyun "clkxtal",
193*4882a593Smuzhiyun "syspll2_d4",
194*4882a593Smuzhiyun "syspll4_d2",
195*4882a593Smuzhiyun "univpll2_d4",
196*4882a593Smuzhiyun "univpll1_d8",
197*4882a593Smuzhiyun "clkxtal"
198*4882a593Smuzhiyun };
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun static const char * const spi1_parents[] = {
201*4882a593Smuzhiyun "clkxtal",
202*4882a593Smuzhiyun "syspll3_d2",
203*4882a593Smuzhiyun "clkxtal",
204*4882a593Smuzhiyun "syspll4_d4",
205*4882a593Smuzhiyun "syspll4_d2",
206*4882a593Smuzhiyun "univpll2_d4",
207*4882a593Smuzhiyun "univpll1_d8",
208*4882a593Smuzhiyun "clkxtal"
209*4882a593Smuzhiyun };
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun static const char * const msdc30_0_parents[] = {
212*4882a593Smuzhiyun "clkxtal",
213*4882a593Smuzhiyun "univpll2_d16",
214*4882a593Smuzhiyun "univ48m"
215*4882a593Smuzhiyun };
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun static const char * const a1sys_hp_parents[] = {
218*4882a593Smuzhiyun "clkxtal",
219*4882a593Smuzhiyun "aud1pll_ck",
220*4882a593Smuzhiyun "aud2pll_ck",
221*4882a593Smuzhiyun "clkxtal"
222*4882a593Smuzhiyun };
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun static const char * const intdir_parents[] = {
225*4882a593Smuzhiyun "clkxtal",
226*4882a593Smuzhiyun "syspll_d2",
227*4882a593Smuzhiyun "univpll_d2",
228*4882a593Smuzhiyun "sgmiipll_ck"
229*4882a593Smuzhiyun };
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun static const char * const aud_intbus_parents[] = {
232*4882a593Smuzhiyun "clkxtal",
233*4882a593Smuzhiyun "syspll1_d4",
234*4882a593Smuzhiyun "syspll4_d2",
235*4882a593Smuzhiyun "syspll3_d2"
236*4882a593Smuzhiyun };
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun static const char * const pmicspi_parents[] = {
239*4882a593Smuzhiyun "clkxtal",
240*4882a593Smuzhiyun "clk_null",
241*4882a593Smuzhiyun "clk_null",
242*4882a593Smuzhiyun "clk_null",
243*4882a593Smuzhiyun "clk_null",
244*4882a593Smuzhiyun "univpll2_d16"
245*4882a593Smuzhiyun };
246*4882a593Smuzhiyun
247*4882a593Smuzhiyun static const char * const atb_parents[] = {
248*4882a593Smuzhiyun "clkxtal",
249*4882a593Smuzhiyun "syspll1_d2",
250*4882a593Smuzhiyun "syspll_d5"
251*4882a593Smuzhiyun };
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun static const char * const audio_parents[] = {
254*4882a593Smuzhiyun "clkxtal",
255*4882a593Smuzhiyun "syspll3_d4",
256*4882a593Smuzhiyun "syspll4_d4",
257*4882a593Smuzhiyun "univpll1_d16"
258*4882a593Smuzhiyun };
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun static const char * const usb20_parents[] = {
261*4882a593Smuzhiyun "clkxtal",
262*4882a593Smuzhiyun "univpll3_d4",
263*4882a593Smuzhiyun "syspll1_d8",
264*4882a593Smuzhiyun "clkxtal"
265*4882a593Smuzhiyun };
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun static const char * const aud1_parents[] = {
268*4882a593Smuzhiyun "clkxtal",
269*4882a593Smuzhiyun "aud1pll_ck"
270*4882a593Smuzhiyun };
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun static const char * const aud2_parents[] = {
273*4882a593Smuzhiyun "clkxtal",
274*4882a593Smuzhiyun "aud2pll_ck"
275*4882a593Smuzhiyun };
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun static const char * const asm_l_parents[] = {
278*4882a593Smuzhiyun "clkxtal",
279*4882a593Smuzhiyun "syspll_d5",
280*4882a593Smuzhiyun "univpll2_d2",
281*4882a593Smuzhiyun "univpll2_d4"
282*4882a593Smuzhiyun };
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun static const char * const apll1_ck_parents[] = {
285*4882a593Smuzhiyun "aud1_sel",
286*4882a593Smuzhiyun "aud2_sel"
287*4882a593Smuzhiyun };
288*4882a593Smuzhiyun
289*4882a593Smuzhiyun static const char * const peribus_ck_parents[] = {
290*4882a593Smuzhiyun "syspll1_d8",
291*4882a593Smuzhiyun "syspll1_d4"
292*4882a593Smuzhiyun };
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun static const struct mtk_gate_regs apmixed_cg_regs = {
295*4882a593Smuzhiyun .set_ofs = 0x8,
296*4882a593Smuzhiyun .clr_ofs = 0x8,
297*4882a593Smuzhiyun .sta_ofs = 0x8,
298*4882a593Smuzhiyun };
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun static const struct mtk_gate_regs infra_cg_regs = {
301*4882a593Smuzhiyun .set_ofs = 0x40,
302*4882a593Smuzhiyun .clr_ofs = 0x44,
303*4882a593Smuzhiyun .sta_ofs = 0x48,
304*4882a593Smuzhiyun };
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun static const struct mtk_gate_regs top0_cg_regs = {
307*4882a593Smuzhiyun .set_ofs = 0x120,
308*4882a593Smuzhiyun .clr_ofs = 0x120,
309*4882a593Smuzhiyun .sta_ofs = 0x120,
310*4882a593Smuzhiyun };
311*4882a593Smuzhiyun
312*4882a593Smuzhiyun static const struct mtk_gate_regs top1_cg_regs = {
313*4882a593Smuzhiyun .set_ofs = 0x128,
314*4882a593Smuzhiyun .clr_ofs = 0x128,
315*4882a593Smuzhiyun .sta_ofs = 0x128,
316*4882a593Smuzhiyun };
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun static const struct mtk_gate_regs peri0_cg_regs = {
319*4882a593Smuzhiyun .set_ofs = 0x8,
320*4882a593Smuzhiyun .clr_ofs = 0x10,
321*4882a593Smuzhiyun .sta_ofs = 0x18,
322*4882a593Smuzhiyun };
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun static const struct mtk_gate_regs peri1_cg_regs = {
325*4882a593Smuzhiyun .set_ofs = 0xC,
326*4882a593Smuzhiyun .clr_ofs = 0x14,
327*4882a593Smuzhiyun .sta_ofs = 0x1C,
328*4882a593Smuzhiyun };
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun static const struct mtk_pll_data plls[] = {
331*4882a593Smuzhiyun PLL(CLK_APMIXED_ARMPLL, "armpll", 0x0200, 0x020C, 0x00000001,
332*4882a593Smuzhiyun PLL_AO, 21, 0x0204, 24, 0, 0x0204, 0),
333*4882a593Smuzhiyun PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0210, 0x021C, 0x00000001,
334*4882a593Smuzhiyun HAVE_RST_BAR, 21, 0x0214, 24, 0, 0x0214, 0),
335*4882a593Smuzhiyun PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x0220, 0x022C, 0x00000001,
336*4882a593Smuzhiyun HAVE_RST_BAR, 7, 0x0224, 24, 0, 0x0224, 14),
337*4882a593Smuzhiyun PLL(CLK_APMIXED_ETH1PLL, "eth1pll", 0x0300, 0x0310, 0x00000001,
338*4882a593Smuzhiyun 0, 21, 0x0300, 1, 0, 0x0304, 0),
339*4882a593Smuzhiyun PLL(CLK_APMIXED_ETH2PLL, "eth2pll", 0x0314, 0x0320, 0x00000001,
340*4882a593Smuzhiyun 0, 21, 0x0314, 1, 0, 0x0318, 0),
341*4882a593Smuzhiyun PLL(CLK_APMIXED_AUD1PLL, "aud1pll", 0x0324, 0x0330, 0x00000001,
342*4882a593Smuzhiyun 0, 31, 0x0324, 1, 0, 0x0328, 0),
343*4882a593Smuzhiyun PLL(CLK_APMIXED_AUD2PLL, "aud2pll", 0x0334, 0x0340, 0x00000001,
344*4882a593Smuzhiyun 0, 31, 0x0334, 1, 0, 0x0338, 0),
345*4882a593Smuzhiyun PLL(CLK_APMIXED_TRGPLL, "trgpll", 0x0344, 0x0354, 0x00000001,
346*4882a593Smuzhiyun 0, 21, 0x0344, 1, 0, 0x0348, 0),
347*4882a593Smuzhiyun PLL(CLK_APMIXED_SGMIPLL, "sgmipll", 0x0358, 0x0368, 0x00000001,
348*4882a593Smuzhiyun 0, 21, 0x0358, 1, 0, 0x035C, 0),
349*4882a593Smuzhiyun };
350*4882a593Smuzhiyun
351*4882a593Smuzhiyun static const struct mtk_gate apmixed_clks[] = {
352*4882a593Smuzhiyun GATE_APMIXED(CLK_APMIXED_MAIN_CORE_EN, "main_core_en", "mainpll", 5),
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun static const struct mtk_gate infra_clks[] = {
356*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_DBGCLK_PD, "infra_dbgclk_pd", "axi_sel", 0),
357*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_TRNG, "trng_ck", "axi_sel", 2),
358*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_AUDIO_PD, "infra_audio_pd", "aud_intbus_sel", 5),
359*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_IRRX_PD, "infra_irrx_pd", "irrx_sel", 16),
360*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_APXGPT_PD, "infra_apxgpt_pd", "f10m_ref_sel", 18),
361*4882a593Smuzhiyun GATE_INFRA(CLK_INFRA_PMIC_PD, "infra_pmic_pd", "pmicspi_sel", 22),
362*4882a593Smuzhiyun };
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun static const struct mtk_fixed_clk top_fixed_clks[] = {
365*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_TO_U2_PHY, "to_u2_phy", "clkxtal",
366*4882a593Smuzhiyun 31250000),
367*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_TO_U2_PHY_1P, "to_u2_phy_1p", "clkxtal",
368*4882a593Smuzhiyun 31250000),
369*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_PCIE0_PIPE_EN, "pcie0_pipe_en", "clkxtal",
370*4882a593Smuzhiyun 125000000),
371*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_PCIE1_PIPE_EN, "pcie1_pipe_en", "clkxtal",
372*4882a593Smuzhiyun 125000000),
373*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SSUSB_TX250M, "ssusb_tx250m", "clkxtal",
374*4882a593Smuzhiyun 250000000),
375*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SSUSB_EQ_RX250M, "ssusb_eq_rx250m", "clkxtal",
376*4882a593Smuzhiyun 250000000),
377*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SSUSB_CDR_REF, "ssusb_cdr_ref", "clkxtal",
378*4882a593Smuzhiyun 33333333),
379*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SSUSB_CDR_FB, "ssusb_cdr_fb", "clkxtal",
380*4882a593Smuzhiyun 50000000),
381*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SATA_ASIC, "sata_asic", "clkxtal",
382*4882a593Smuzhiyun 50000000),
383*4882a593Smuzhiyun FIXED_CLK(CLK_TOP_SATA_RBC, "sata_rbc", "clkxtal",
384*4882a593Smuzhiyun 50000000),
385*4882a593Smuzhiyun };
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun static const struct mtk_fixed_factor top_divs[] = {
388*4882a593Smuzhiyun FACTOR(CLK_TOP_TO_USB3_SYS, "to_usb3_sys", "eth1pll", 1, 4),
389*4882a593Smuzhiyun FACTOR(CLK_TOP_P1_1MHZ, "p1_1mhz", "eth1pll", 1, 500),
390*4882a593Smuzhiyun FACTOR(CLK_TOP_4MHZ, "free_run_4mhz", "eth1pll", 1, 125),
391*4882a593Smuzhiyun FACTOR(CLK_TOP_P0_1MHZ, "p0_1mhz", "eth1pll", 1, 500),
392*4882a593Smuzhiyun FACTOR(CLK_TOP_TXCLK_SRC_PRE, "txclk_src_pre", "sgmiipll_d2", 1, 1),
393*4882a593Smuzhiyun FACTOR(CLK_TOP_RTC, "rtc", "clkxtal", 1, 1024),
394*4882a593Smuzhiyun FACTOR(CLK_TOP_MEMPLL, "mempll", "clkxtal", 32, 1),
395*4882a593Smuzhiyun FACTOR(CLK_TOP_DMPLL, "dmpll_ck", "mempll", 1, 1),
396*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
397*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "mainpll", 1, 4),
398*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "mainpll", 1, 8),
399*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "mainpll", 1, 16),
400*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "mainpll", 1, 12),
401*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "mainpll", 1, 24),
402*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
403*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "mainpll", 1, 10),
404*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "mainpll", 1, 20),
405*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "mainpll", 1, 14),
406*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "mainpll", 1, 28),
407*4882a593Smuzhiyun FACTOR(CLK_TOP_SYSPLL4_D16, "syspll4_d16", "mainpll", 1, 112),
408*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1, 2),
409*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
410*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll", 1, 4),
411*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll", 1, 8),
412*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll", 1, 16),
413*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL1_D16, "univpll1_d16", "univpll", 1, 32),
414*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 6),
415*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 12),
416*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 24),
417*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL2_D16, "univpll2_d16", "univpll", 1, 48),
418*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
419*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll", 1, 10),
420*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll", 1, 20),
421*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL3_D16, "univpll3_d16", "univpll", 1, 80),
422*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
423*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIVPLL_D80_D4, "univpll_d80_d4", "univpll", 1, 320),
424*4882a593Smuzhiyun FACTOR(CLK_TOP_UNIV48M, "univ48m", "univpll", 1, 25),
425*4882a593Smuzhiyun FACTOR(CLK_TOP_SGMIIPLL, "sgmiipll_ck", "sgmipll", 1, 1),
426*4882a593Smuzhiyun FACTOR(CLK_TOP_SGMIIPLL_D2, "sgmiipll_d2", "sgmipll", 1, 2),
427*4882a593Smuzhiyun FACTOR(CLK_TOP_AUD1PLL, "aud1pll_ck", "aud1pll", 1, 1),
428*4882a593Smuzhiyun FACTOR(CLK_TOP_AUD2PLL, "aud2pll_ck", "aud2pll", 1, 1),
429*4882a593Smuzhiyun FACTOR(CLK_TOP_AUD_I2S2_MCK, "aud_i2s2_mck", "i2s2_mck_sel", 1, 2),
430*4882a593Smuzhiyun FACTOR(CLK_TOP_TO_USB3_REF, "to_usb3_ref", "univpll2_d4", 1, 4),
431*4882a593Smuzhiyun FACTOR(CLK_TOP_PCIE1_MAC_EN, "pcie1_mac_en", "univpll1_d4", 1, 1),
432*4882a593Smuzhiyun FACTOR(CLK_TOP_PCIE0_MAC_EN, "pcie0_mac_en", "univpll1_d4", 1, 1),
433*4882a593Smuzhiyun FACTOR(CLK_TOP_ETH_500M, "eth_500m", "eth1pll", 1, 1),
434*4882a593Smuzhiyun };
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun static const struct mtk_gate top_clks[] = {
437*4882a593Smuzhiyun /* TOP0 */
438*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_APLL1_DIV_PD, "apll1_ck_div_pd", "apll1_ck_div", 0),
439*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_APLL2_DIV_PD, "apll2_ck_div_pd", "apll2_ck_div", 1),
440*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_I2S0_MCK_DIV_PD, "i2s0_mck_div_pd", "i2s0_mck_div",
441*4882a593Smuzhiyun 2),
442*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_I2S1_MCK_DIV_PD, "i2s1_mck_div_pd", "i2s1_mck_div",
443*4882a593Smuzhiyun 3),
444*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_I2S2_MCK_DIV_PD, "i2s2_mck_div_pd", "i2s2_mck_div",
445*4882a593Smuzhiyun 4),
446*4882a593Smuzhiyun GATE_TOP0(CLK_TOP_I2S3_MCK_DIV_PD, "i2s3_mck_div_pd", "i2s3_mck_div",
447*4882a593Smuzhiyun 5),
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun /* TOP1 */
450*4882a593Smuzhiyun GATE_TOP1(CLK_TOP_A1SYS_HP_DIV_PD, "a1sys_div_pd", "a1sys_div", 0),
451*4882a593Smuzhiyun GATE_TOP1(CLK_TOP_A2SYS_HP_DIV_PD, "a2sys_div_pd", "a2sys_div", 16),
452*4882a593Smuzhiyun };
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun static const struct mtk_clk_divider top_adj_divs[] = {
455*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_APLL1_DIV, "apll1_ck_div", "apll1_ck_sel",
456*4882a593Smuzhiyun 0x120, 24, 3),
457*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_APLL2_DIV, "apll2_ck_div", "apll2_ck_sel",
458*4882a593Smuzhiyun 0x120, 28, 3),
459*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_I2S0_MCK_DIV, "i2s0_mck_div", "i2s0_mck_sel",
460*4882a593Smuzhiyun 0x124, 0, 7),
461*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_I2S1_MCK_DIV, "i2s1_mck_div", "i2s1_mck_sel",
462*4882a593Smuzhiyun 0x124, 8, 7),
463*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_I2S2_MCK_DIV, "i2s2_mck_div", "aud_i2s2_mck",
464*4882a593Smuzhiyun 0x124, 16, 7),
465*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_I2S3_MCK_DIV, "i2s3_mck_div", "i2s3_mck_sel",
466*4882a593Smuzhiyun 0x124, 24, 7),
467*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_A1SYS_HP_DIV, "a1sys_div", "a1sys_hp_sel",
468*4882a593Smuzhiyun 0x128, 8, 7),
469*4882a593Smuzhiyun DIV_ADJ(CLK_TOP_A2SYS_HP_DIV, "a2sys_div", "a2sys_hp_sel",
470*4882a593Smuzhiyun 0x128, 24, 7),
471*4882a593Smuzhiyun };
472*4882a593Smuzhiyun
473*4882a593Smuzhiyun static const struct mtk_gate peri_clks[] = {
474*4882a593Smuzhiyun /* PERI0 */
475*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_THERM_PD, "peri_therm_pd", "axi_sel", 1),
476*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM1_PD, "peri_pwm1_pd", "clkxtal", 2),
477*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM2_PD, "peri_pwm2_pd", "clkxtal", 3),
478*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM3_PD, "peri_pwm3_pd", "clkxtal", 4),
479*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM4_PD, "peri_pwm4_pd", "clkxtal", 5),
480*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM5_PD, "peri_pwm5_pd", "clkxtal", 6),
481*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM6_PD, "peri_pwm6_pd", "clkxtal", 7),
482*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM7_PD, "peri_pwm7_pd", "clkxtal", 8),
483*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_PWM_PD, "peri_pwm_pd", "clkxtal", 9),
484*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_AP_DMA_PD, "peri_ap_dma_pd", "axi_sel", 12),
485*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_MSDC30_0_PD, "peri_msdc30_0", "msdc30_0_sel", 13),
486*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_MSDC30_1_PD, "peri_msdc30_1", "msdc30_1_sel", 14),
487*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_UART0_PD, "peri_uart0_pd", "axi_sel", 17),
488*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_UART1_PD, "peri_uart1_pd", "axi_sel", 18),
489*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_UART2_PD, "peri_uart2_pd", "axi_sel", 19),
490*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_UART3_PD, "peri_uart3_pd", "axi_sel", 20),
491*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_UART4_PD, "peri_uart4_pd", "axi_sel", 21),
492*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_BTIF_PD, "peri_btif_pd", "axi_sel", 22),
493*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_I2C0_PD, "peri_i2c0_pd", "axi_sel", 23),
494*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_I2C1_PD, "peri_i2c1_pd", "axi_sel", 24),
495*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_I2C2_PD, "peri_i2c2_pd", "axi_sel", 25),
496*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_SPI1_PD, "peri_spi1_pd", "spi1_sel", 26),
497*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_AUXADC_PD, "peri_auxadc_pd", "clkxtal", 27),
498*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_SPI0_PD, "peri_spi0_pd", "spi0_sel", 28),
499*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_SNFI_PD, "peri_snfi_pd", "nfi_infra_sel", 29),
500*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_NFI_PD, "peri_nfi_pd", "axi_sel", 30),
501*4882a593Smuzhiyun GATE_PERI0(CLK_PERI_NFIECC_PD, "peri_nfiecc_pd", "axi_sel", 31),
502*4882a593Smuzhiyun
503*4882a593Smuzhiyun /* PERI1 */
504*4882a593Smuzhiyun GATE_PERI1(CLK_PERI_FLASH_PD, "peri_flash_pd", "flash_sel", 1),
505*4882a593Smuzhiyun GATE_PERI1(CLK_PERI_IRTX_PD, "peri_irtx_pd", "irtx_sel", 2),
506*4882a593Smuzhiyun };
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun static struct mtk_composite infra_muxes[] = {
509*4882a593Smuzhiyun MUX(CLK_INFRA_MUX1_SEL, "infra_mux1_sel", infra_mux1_parents,
510*4882a593Smuzhiyun 0x000, 2, 2),
511*4882a593Smuzhiyun };
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun static struct mtk_composite top_muxes[] = {
514*4882a593Smuzhiyun /* CLK_CFG_0 */
515*4882a593Smuzhiyun MUX_GATE(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
516*4882a593Smuzhiyun 0x040, 0, 3, 7),
517*4882a593Smuzhiyun MUX_GATE(CLK_TOP_MEM_SEL, "mem_sel", mem_parents,
518*4882a593Smuzhiyun 0x040, 8, 1, 15),
519*4882a593Smuzhiyun MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, "ddrphycfg_sel", ddrphycfg_parents,
520*4882a593Smuzhiyun 0x040, 16, 1, 23),
521*4882a593Smuzhiyun MUX_GATE(CLK_TOP_ETH_SEL, "eth_sel", eth_parents,
522*4882a593Smuzhiyun 0x040, 24, 3, 31),
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun /* CLK_CFG_1 */
525*4882a593Smuzhiyun MUX_GATE(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents,
526*4882a593Smuzhiyun 0x050, 0, 2, 7),
527*4882a593Smuzhiyun MUX_GATE(CLK_TOP_F10M_REF_SEL, "f10m_ref_sel", f10m_ref_parents,
528*4882a593Smuzhiyun 0x050, 8, 1, 15),
529*4882a593Smuzhiyun MUX_GATE(CLK_TOP_NFI_INFRA_SEL, "nfi_infra_sel", nfi_infra_parents,
530*4882a593Smuzhiyun 0x050, 16, 4, 23),
531*4882a593Smuzhiyun MUX_GATE(CLK_TOP_FLASH_SEL, "flash_sel", flash_parents,
532*4882a593Smuzhiyun 0x050, 24, 3, 31),
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun /* CLK_CFG_2 */
535*4882a593Smuzhiyun MUX_GATE(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
536*4882a593Smuzhiyun 0x060, 0, 1, 7),
537*4882a593Smuzhiyun MUX_GATE(CLK_TOP_SPI0_SEL, "spi0_sel", spi0_parents,
538*4882a593Smuzhiyun 0x060, 8, 3, 15),
539*4882a593Smuzhiyun MUX_GATE(CLK_TOP_SPI1_SEL, "spi1_sel", spi1_parents,
540*4882a593Smuzhiyun 0x060, 16, 3, 23),
541*4882a593Smuzhiyun MUX_GATE(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel", uart_parents,
542*4882a593Smuzhiyun 0x060, 24, 3, 31),
543*4882a593Smuzhiyun
544*4882a593Smuzhiyun /* CLK_CFG_3 */
545*4882a593Smuzhiyun MUX_GATE(CLK_TOP_MSDC30_0_SEL, "msdc30_0_sel", msdc30_0_parents,
546*4882a593Smuzhiyun 0x070, 0, 3, 7),
547*4882a593Smuzhiyun MUX_GATE(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel", msdc30_0_parents,
548*4882a593Smuzhiyun 0x070, 8, 3, 15),
549*4882a593Smuzhiyun MUX_GATE(CLK_TOP_A1SYS_HP_SEL, "a1sys_hp_sel", a1sys_hp_parents,
550*4882a593Smuzhiyun 0x070, 16, 2, 23),
551*4882a593Smuzhiyun MUX_GATE(CLK_TOP_A2SYS_HP_SEL, "a2sys_hp_sel", a1sys_hp_parents,
552*4882a593Smuzhiyun 0x070, 24, 2, 31),
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun /* CLK_CFG_4 */
555*4882a593Smuzhiyun MUX_GATE(CLK_TOP_INTDIR_SEL, "intdir_sel", intdir_parents,
556*4882a593Smuzhiyun 0x080, 0, 2, 7),
557*4882a593Smuzhiyun MUX_GATE(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel", aud_intbus_parents,
558*4882a593Smuzhiyun 0x080, 8, 2, 15),
559*4882a593Smuzhiyun MUX_GATE(CLK_TOP_PMICSPI_SEL, "pmicspi_sel", pmicspi_parents,
560*4882a593Smuzhiyun 0x080, 16, 3, 23),
561*4882a593Smuzhiyun MUX_GATE(CLK_TOP_SCP_SEL, "scp_sel", ddrphycfg_parents,
562*4882a593Smuzhiyun 0x080, 24, 2, 31),
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun /* CLK_CFG_5 */
565*4882a593Smuzhiyun MUX_GATE(CLK_TOP_ATB_SEL, "atb_sel", atb_parents,
566*4882a593Smuzhiyun 0x090, 0, 2, 7),
567*4882a593Smuzhiyun MUX_GATE(CLK_TOP_HIF_SEL, "hif_sel", eth_parents,
568*4882a593Smuzhiyun 0x090, 8, 3, 15),
569*4882a593Smuzhiyun MUX_GATE(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents,
570*4882a593Smuzhiyun 0x090, 16, 2, 23),
571*4882a593Smuzhiyun MUX_GATE(CLK_TOP_U2_SEL, "usb20_sel", usb20_parents,
572*4882a593Smuzhiyun 0x090, 24, 2, 31),
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun /* CLK_CFG_6 */
575*4882a593Smuzhiyun MUX_GATE(CLK_TOP_AUD1_SEL, "aud1_sel", aud1_parents,
576*4882a593Smuzhiyun 0x0A0, 0, 1, 7),
577*4882a593Smuzhiyun MUX_GATE(CLK_TOP_AUD2_SEL, "aud2_sel", aud2_parents,
578*4882a593Smuzhiyun 0x0A0, 8, 1, 15),
579*4882a593Smuzhiyun MUX_GATE(CLK_TOP_IRRX_SEL, "irrx_sel", f10m_ref_parents,
580*4882a593Smuzhiyun 0x0A0, 16, 1, 23),
581*4882a593Smuzhiyun MUX_GATE(CLK_TOP_IRTX_SEL, "irtx_sel", f10m_ref_parents,
582*4882a593Smuzhiyun 0x0A0, 24, 1, 31),
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun /* CLK_CFG_7 */
585*4882a593Smuzhiyun MUX_GATE(CLK_TOP_ASM_L_SEL, "asm_l_sel", asm_l_parents,
586*4882a593Smuzhiyun 0x0B0, 0, 2, 7),
587*4882a593Smuzhiyun MUX_GATE(CLK_TOP_ASM_M_SEL, "asm_m_sel", asm_l_parents,
588*4882a593Smuzhiyun 0x0B0, 8, 2, 15),
589*4882a593Smuzhiyun MUX_GATE(CLK_TOP_ASM_H_SEL, "asm_h_sel", asm_l_parents,
590*4882a593Smuzhiyun 0x0B0, 16, 2, 23),
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun /* CLK_AUDDIV_0 */
593*4882a593Smuzhiyun MUX(CLK_TOP_APLL1_SEL, "apll1_ck_sel", apll1_ck_parents,
594*4882a593Smuzhiyun 0x120, 6, 1),
595*4882a593Smuzhiyun MUX(CLK_TOP_APLL2_SEL, "apll2_ck_sel", apll1_ck_parents,
596*4882a593Smuzhiyun 0x120, 7, 1),
597*4882a593Smuzhiyun MUX(CLK_TOP_I2S0_MCK_SEL, "i2s0_mck_sel", apll1_ck_parents,
598*4882a593Smuzhiyun 0x120, 8, 1),
599*4882a593Smuzhiyun MUX(CLK_TOP_I2S1_MCK_SEL, "i2s1_mck_sel", apll1_ck_parents,
600*4882a593Smuzhiyun 0x120, 9, 1),
601*4882a593Smuzhiyun MUX(CLK_TOP_I2S2_MCK_SEL, "i2s2_mck_sel", apll1_ck_parents,
602*4882a593Smuzhiyun 0x120, 10, 1),
603*4882a593Smuzhiyun MUX(CLK_TOP_I2S3_MCK_SEL, "i2s3_mck_sel", apll1_ck_parents,
604*4882a593Smuzhiyun 0x120, 11, 1),
605*4882a593Smuzhiyun };
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun static struct mtk_composite peri_muxes[] = {
608*4882a593Smuzhiyun /* PERI_GLOBALCON_CKSEL */
609*4882a593Smuzhiyun MUX(CLK_PERIBUS_SEL, "peribus_ck_sel", peribus_ck_parents, 0x05C, 0, 1),
610*4882a593Smuzhiyun };
611*4882a593Smuzhiyun
mtk_topckgen_init(struct platform_device * pdev)612*4882a593Smuzhiyun static int mtk_topckgen_init(struct platform_device *pdev)
613*4882a593Smuzhiyun {
614*4882a593Smuzhiyun struct clk_onecell_data *clk_data;
615*4882a593Smuzhiyun void __iomem *base;
616*4882a593Smuzhiyun struct device_node *node = pdev->dev.of_node;
617*4882a593Smuzhiyun
618*4882a593Smuzhiyun base = devm_platform_ioremap_resource(pdev, 0);
619*4882a593Smuzhiyun if (IS_ERR(base))
620*4882a593Smuzhiyun return PTR_ERR(base);
621*4882a593Smuzhiyun
622*4882a593Smuzhiyun clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
623*4882a593Smuzhiyun
624*4882a593Smuzhiyun mtk_clk_register_fixed_clks(top_fixed_clks, ARRAY_SIZE(top_fixed_clks),
625*4882a593Smuzhiyun clk_data);
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs),
628*4882a593Smuzhiyun clk_data);
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes),
631*4882a593Smuzhiyun base, &mt7622_clk_lock, clk_data);
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun mtk_clk_register_dividers(top_adj_divs, ARRAY_SIZE(top_adj_divs),
634*4882a593Smuzhiyun base, &mt7622_clk_lock, clk_data);
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
637*4882a593Smuzhiyun clk_data);
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_TOP_AXI_SEL]);
640*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_TOP_MEM_SEL]);
641*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_TOP_DDRPHYCFG_SEL]);
642*4882a593Smuzhiyun
643*4882a593Smuzhiyun return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
644*4882a593Smuzhiyun }
645*4882a593Smuzhiyun
mtk_infrasys_init(struct platform_device * pdev)646*4882a593Smuzhiyun static int mtk_infrasys_init(struct platform_device *pdev)
647*4882a593Smuzhiyun {
648*4882a593Smuzhiyun struct device_node *node = pdev->dev.of_node;
649*4882a593Smuzhiyun struct clk_onecell_data *clk_data;
650*4882a593Smuzhiyun int r;
651*4882a593Smuzhiyun
652*4882a593Smuzhiyun clk_data = mtk_alloc_clk_data(CLK_INFRA_NR_CLK);
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
655*4882a593Smuzhiyun clk_data);
656*4882a593Smuzhiyun
657*4882a593Smuzhiyun mtk_clk_register_cpumuxes(node, infra_muxes, ARRAY_SIZE(infra_muxes),
658*4882a593Smuzhiyun clk_data);
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun r = of_clk_add_provider(node, of_clk_src_onecell_get,
661*4882a593Smuzhiyun clk_data);
662*4882a593Smuzhiyun if (r)
663*4882a593Smuzhiyun return r;
664*4882a593Smuzhiyun
665*4882a593Smuzhiyun mtk_register_reset_controller(node, 1, 0x30);
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun return 0;
668*4882a593Smuzhiyun }
669*4882a593Smuzhiyun
mtk_apmixedsys_init(struct platform_device * pdev)670*4882a593Smuzhiyun static int mtk_apmixedsys_init(struct platform_device *pdev)
671*4882a593Smuzhiyun {
672*4882a593Smuzhiyun struct clk_onecell_data *clk_data;
673*4882a593Smuzhiyun struct device_node *node = pdev->dev.of_node;
674*4882a593Smuzhiyun
675*4882a593Smuzhiyun clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
676*4882a593Smuzhiyun if (!clk_data)
677*4882a593Smuzhiyun return -ENOMEM;
678*4882a593Smuzhiyun
679*4882a593Smuzhiyun mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls),
680*4882a593Smuzhiyun clk_data);
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun mtk_clk_register_gates(node, apmixed_clks,
683*4882a593Smuzhiyun ARRAY_SIZE(apmixed_clks), clk_data);
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_APMIXED_ARMPLL]);
686*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_APMIXED_MAIN_CORE_EN]);
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
689*4882a593Smuzhiyun }
690*4882a593Smuzhiyun
mtk_pericfg_init(struct platform_device * pdev)691*4882a593Smuzhiyun static int mtk_pericfg_init(struct platform_device *pdev)
692*4882a593Smuzhiyun {
693*4882a593Smuzhiyun struct clk_onecell_data *clk_data;
694*4882a593Smuzhiyun void __iomem *base;
695*4882a593Smuzhiyun int r;
696*4882a593Smuzhiyun struct device_node *node = pdev->dev.of_node;
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun base = devm_platform_ioremap_resource(pdev, 0);
699*4882a593Smuzhiyun if (IS_ERR(base))
700*4882a593Smuzhiyun return PTR_ERR(base);
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun clk_data = mtk_alloc_clk_data(CLK_PERI_NR_CLK);
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun mtk_clk_register_gates(node, peri_clks, ARRAY_SIZE(peri_clks),
705*4882a593Smuzhiyun clk_data);
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun mtk_clk_register_composites(peri_muxes, ARRAY_SIZE(peri_muxes), base,
708*4882a593Smuzhiyun &mt7622_clk_lock, clk_data);
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
711*4882a593Smuzhiyun if (r)
712*4882a593Smuzhiyun return r;
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun clk_prepare_enable(clk_data->clks[CLK_PERI_UART0_PD]);
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun mtk_register_reset_controller(node, 2, 0x0);
717*4882a593Smuzhiyun
718*4882a593Smuzhiyun return 0;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun static const struct of_device_id of_match_clk_mt7622[] = {
722*4882a593Smuzhiyun {
723*4882a593Smuzhiyun .compatible = "mediatek,mt7622-apmixedsys",
724*4882a593Smuzhiyun .data = mtk_apmixedsys_init,
725*4882a593Smuzhiyun }, {
726*4882a593Smuzhiyun .compatible = "mediatek,mt7622-infracfg",
727*4882a593Smuzhiyun .data = mtk_infrasys_init,
728*4882a593Smuzhiyun }, {
729*4882a593Smuzhiyun .compatible = "mediatek,mt7622-topckgen",
730*4882a593Smuzhiyun .data = mtk_topckgen_init,
731*4882a593Smuzhiyun }, {
732*4882a593Smuzhiyun .compatible = "mediatek,mt7622-pericfg",
733*4882a593Smuzhiyun .data = mtk_pericfg_init,
734*4882a593Smuzhiyun }, {
735*4882a593Smuzhiyun /* sentinel */
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun };
738*4882a593Smuzhiyun
clk_mt7622_probe(struct platform_device * pdev)739*4882a593Smuzhiyun static int clk_mt7622_probe(struct platform_device *pdev)
740*4882a593Smuzhiyun {
741*4882a593Smuzhiyun int (*clk_init)(struct platform_device *);
742*4882a593Smuzhiyun int r;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun clk_init = of_device_get_match_data(&pdev->dev);
745*4882a593Smuzhiyun if (!clk_init)
746*4882a593Smuzhiyun return -EINVAL;
747*4882a593Smuzhiyun
748*4882a593Smuzhiyun r = clk_init(pdev);
749*4882a593Smuzhiyun if (r)
750*4882a593Smuzhiyun dev_err(&pdev->dev,
751*4882a593Smuzhiyun "could not register clock provider: %s: %d\n",
752*4882a593Smuzhiyun pdev->name, r);
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun return r;
755*4882a593Smuzhiyun }
756*4882a593Smuzhiyun
757*4882a593Smuzhiyun static struct platform_driver clk_mt7622_drv = {
758*4882a593Smuzhiyun .probe = clk_mt7622_probe,
759*4882a593Smuzhiyun .driver = {
760*4882a593Smuzhiyun .name = "clk-mt7622",
761*4882a593Smuzhiyun .of_match_table = of_match_clk_mt7622,
762*4882a593Smuzhiyun },
763*4882a593Smuzhiyun };
764*4882a593Smuzhiyun
clk_mt7622_init(void)765*4882a593Smuzhiyun static int clk_mt7622_init(void)
766*4882a593Smuzhiyun {
767*4882a593Smuzhiyun return platform_driver_register(&clk_mt7622_drv);
768*4882a593Smuzhiyun }
769*4882a593Smuzhiyun
770*4882a593Smuzhiyun arch_initcall(clk_mt7622_init);
771