xref: /OK3568_Linux_fs/kernel/drivers/clk/mediatek/clk-mt6797.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2016 MediaTek Inc.
4*4882a593Smuzhiyun  * Author: Kevin Chen <kevin-cw.chen@mediatek.com>
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/of.h>
8*4882a593Smuzhiyun #include <linux/of_address.h>
9*4882a593Smuzhiyun #include <linux/of_device.h>
10*4882a593Smuzhiyun #include <linux/platform_device.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include "clk-mtk.h"
13*4882a593Smuzhiyun #include "clk-gate.h"
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <dt-bindings/clock/mt6797-clk.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * For some clocks, we don't care what their actual rates are. And these
19*4882a593Smuzhiyun  * clocks may change their rate on different products or different scenarios.
20*4882a593Smuzhiyun  * So we model these clocks' rate as 0, to denote it's not an actual rate.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun static DEFINE_SPINLOCK(mt6797_clk_lock);
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun static const struct mtk_fixed_factor top_fixed_divs[] = {
26*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1, 1),
27*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
28*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2),
29*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4),
30*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8),
31*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16),
32*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
33*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_D3_D3, "syspll_d3_d3", "syspll_d3", 1, 3),
34*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2),
35*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4),
36*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8),
37*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
38*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2),
39*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4),
40*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
41*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2),
42*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4),
43*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1, 1),
44*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
45*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll", 1, 26),
46*4882a593Smuzhiyun 	FACTOR(CLK_TOP_SSUSB_PHY_48M_CK, "ssusb_phy_48m_ck", "univpll", 1, 1),
47*4882a593Smuzhiyun 	FACTOR(CLK_TOP_USB_PHY48M_CK, "usb_phy48m_ck", "univpll", 1, 1),
48*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
49*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2),
50*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4),
51*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8),
52*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
53*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 2),
54*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 4),
55*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 8),
56*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
57*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2),
58*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4),
59*4882a593Smuzhiyun 	FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8),
60*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_CK_ORG, "ulposc_ck_org", "ulposc", 1, 1),
61*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_CK, "ulposc_ck", "ulposc_ck_org", 1, 3),
62*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_D2, "ulposc_d2", "ulposc_ck", 1, 2),
63*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_D3, "ulposc_d3", "ulposc_ck", 1, 4),
64*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_D4, "ulposc_d4", "ulposc_ck", 1, 8),
65*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_D8, "ulposc_d8", "ulposc_ck", 1, 10),
66*4882a593Smuzhiyun 	FACTOR(CLK_TOP_ULPOSC_D10, "ulposc_d10", "ulposc_ck_org", 1, 1),
67*4882a593Smuzhiyun 	FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1, 1),
68*4882a593Smuzhiyun 	FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1, 1),
69*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1, 1),
70*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MFGPLL_D2, "mfgpll_d2", "mfgpll_ck", 1, 2),
71*4882a593Smuzhiyun 	FACTOR(CLK_TOP_IMGPLL_CK, "imgpll_ck", "imgpll", 1, 1),
72*4882a593Smuzhiyun 	FACTOR(CLK_TOP_IMGPLL_D2, "imgpll_d2", "imgpll_ck", 1, 2),
73*4882a593Smuzhiyun 	FACTOR(CLK_TOP_IMGPLL_D4, "imgpll_d4", "imgpll_ck", 1, 4),
74*4882a593Smuzhiyun 	FACTOR(CLK_TOP_CODECPLL_CK, "codecpll_ck", "codecpll", 1, 1),
75*4882a593Smuzhiyun 	FACTOR(CLK_TOP_CODECPLL_D2, "codecpll_d2", "codecpll_ck", 1, 2),
76*4882a593Smuzhiyun 	FACTOR(CLK_TOP_VDECPLL_CK, "vdecpll_ck", "vdecpll", 1, 1),
77*4882a593Smuzhiyun 	FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1, 1),
78*4882a593Smuzhiyun 	FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2),
79*4882a593Smuzhiyun 	FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4),
80*4882a593Smuzhiyun 	FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8),
81*4882a593Smuzhiyun 	FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_ck", 1, 16),
82*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1, 1),
83*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2),
84*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1, 4),
85*4882a593Smuzhiyun 	FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll_ck", 1, 8),
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun static const char * const axi_parents[] = {
89*4882a593Smuzhiyun 	"clk26m",
90*4882a593Smuzhiyun 	"syspll_d7",
91*4882a593Smuzhiyun 	"ulposc_axi_ck_mux",
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun static const char * const ulposc_axi_ck_mux_parents[] = {
95*4882a593Smuzhiyun 	"syspll1_d4",
96*4882a593Smuzhiyun 	"ulposc_axi_ck_mux_pre",
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun static const char * const ulposc_axi_ck_mux_pre_parents[] = {
100*4882a593Smuzhiyun 	"ulposc_d2",
101*4882a593Smuzhiyun 	"ulposc_d3",
102*4882a593Smuzhiyun };
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun static const char * const ddrphycfg_parents[] = {
105*4882a593Smuzhiyun 	"clk26m",
106*4882a593Smuzhiyun 	"syspll3_d2",
107*4882a593Smuzhiyun 	"syspll2_d4",
108*4882a593Smuzhiyun 	"syspll1_d8",
109*4882a593Smuzhiyun };
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun static const char * const mm_parents[] = {
112*4882a593Smuzhiyun 	"clk26m",
113*4882a593Smuzhiyun 	"imgpll_ck",
114*4882a593Smuzhiyun 	"univpll1_d2",
115*4882a593Smuzhiyun 	"syspll1_d2",
116*4882a593Smuzhiyun };
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun static const char * const pwm_parents[] = {
119*4882a593Smuzhiyun 	"clk26m",
120*4882a593Smuzhiyun 	"univpll2_d4",
121*4882a593Smuzhiyun 	"ulposc_d2",
122*4882a593Smuzhiyun 	"ulposc_d3",
123*4882a593Smuzhiyun 	"ulposc_d8",
124*4882a593Smuzhiyun 	"ulposc_d10",
125*4882a593Smuzhiyun 	"ulposc_d4",
126*4882a593Smuzhiyun };
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun static const char * const vdec_parents[] = {
129*4882a593Smuzhiyun 	"clk26m",
130*4882a593Smuzhiyun 	"vdecpll_ck",
131*4882a593Smuzhiyun 	"imgpll_ck",
132*4882a593Smuzhiyun 	"syspll_d3",
133*4882a593Smuzhiyun 	"univpll_d5",
134*4882a593Smuzhiyun 	"clk26m",
135*4882a593Smuzhiyun 	"clk26m",
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun static const char * const venc_parents[] = {
139*4882a593Smuzhiyun 	"clk26m",
140*4882a593Smuzhiyun 	"codecpll_ck",
141*4882a593Smuzhiyun 	"syspll_d3",
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun static const char * const mfg_parents[] = {
145*4882a593Smuzhiyun 	"clk26m",
146*4882a593Smuzhiyun 	"mfgpll_ck",
147*4882a593Smuzhiyun 	"syspll_d3",
148*4882a593Smuzhiyun 	"univpll_d3",
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun static const char * const camtg[] = {
152*4882a593Smuzhiyun 	"clk26m",
153*4882a593Smuzhiyun 	"univpll_d26",
154*4882a593Smuzhiyun 	"univpll2_d2",
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun static const char * const uart_parents[] = {
158*4882a593Smuzhiyun 	"clk26m",
159*4882a593Smuzhiyun 	"univpll2_d8",
160*4882a593Smuzhiyun };
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun static const char * const spi_parents[] = {
163*4882a593Smuzhiyun 	"clk26m",
164*4882a593Smuzhiyun 	"syspll3_d2",
165*4882a593Smuzhiyun 	"syspll2_d4",
166*4882a593Smuzhiyun 	"ulposc_spi_ck_mux",
167*4882a593Smuzhiyun };
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun static const char * const ulposc_spi_ck_mux_parents[] = {
170*4882a593Smuzhiyun 	"ulposc_d2",
171*4882a593Smuzhiyun 	"ulposc_d3",
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun static const char * const usb20_parents[] = {
175*4882a593Smuzhiyun 	"clk26m",
176*4882a593Smuzhiyun 	"univpll1_d8",
177*4882a593Smuzhiyun 	"syspll4_d2",
178*4882a593Smuzhiyun };
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun static const char * const msdc50_0_hclk_parents[] = {
181*4882a593Smuzhiyun 	"clk26m",
182*4882a593Smuzhiyun 	"syspll1_d2",
183*4882a593Smuzhiyun 	"syspll2_d2",
184*4882a593Smuzhiyun 	"syspll4_d2",
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun 
187*4882a593Smuzhiyun static const char * const msdc50_0_parents[] = {
188*4882a593Smuzhiyun 	"clk26m",
189*4882a593Smuzhiyun 	"msdcpll",
190*4882a593Smuzhiyun 	"syspll_d3",
191*4882a593Smuzhiyun 	"univpll1_d4",
192*4882a593Smuzhiyun 	"syspll2_d2",
193*4882a593Smuzhiyun 	"syspll_d7",
194*4882a593Smuzhiyun 	"msdcpll_d2",
195*4882a593Smuzhiyun 	"univpll1_d2",
196*4882a593Smuzhiyun 	"univpll_d3",
197*4882a593Smuzhiyun };
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun static const char * const msdc30_1_parents[] = {
200*4882a593Smuzhiyun 	"clk26m",
201*4882a593Smuzhiyun 	"univpll2_d2",
202*4882a593Smuzhiyun 	"msdcpll_d2",
203*4882a593Smuzhiyun 	"univpll1_d4",
204*4882a593Smuzhiyun 	"syspll2_d2",
205*4882a593Smuzhiyun 	"syspll_d7",
206*4882a593Smuzhiyun 	"univpll_d7",
207*4882a593Smuzhiyun };
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun static const char * const msdc30_2_parents[] = {
210*4882a593Smuzhiyun 	"clk26m",
211*4882a593Smuzhiyun 	"univpll2_d8",
212*4882a593Smuzhiyun 	"syspll2_d8",
213*4882a593Smuzhiyun 	"syspll1_d8",
214*4882a593Smuzhiyun 	"msdcpll_d8",
215*4882a593Smuzhiyun 	"syspll3_d4",
216*4882a593Smuzhiyun 	"univpll_d26",
217*4882a593Smuzhiyun };
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun static const char * const audio_parents[] = {
220*4882a593Smuzhiyun 	"clk26m",
221*4882a593Smuzhiyun 	"syspll3_d4",
222*4882a593Smuzhiyun 	"syspll4_d4",
223*4882a593Smuzhiyun 	"syspll1_d16",
224*4882a593Smuzhiyun };
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun static const char * const aud_intbus_parents[] = {
227*4882a593Smuzhiyun 	"clk26m",
228*4882a593Smuzhiyun 	"syspll1_d4",
229*4882a593Smuzhiyun 	"syspll4_d2",
230*4882a593Smuzhiyun };
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun static const char * const pmicspi_parents[] = {
233*4882a593Smuzhiyun 	"clk26m",
234*4882a593Smuzhiyun 	"univpll_d26",
235*4882a593Smuzhiyun 	"syspll3_d4",
236*4882a593Smuzhiyun 	"syspll1_d8",
237*4882a593Smuzhiyun 	"ulposc_d4",
238*4882a593Smuzhiyun 	"ulposc_d8",
239*4882a593Smuzhiyun 	"syspll2_d8",
240*4882a593Smuzhiyun };
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun static const char * const scp_parents[] = {
243*4882a593Smuzhiyun 	"clk26m",
244*4882a593Smuzhiyun 	"syspll_d3",
245*4882a593Smuzhiyun 	"ulposc_ck",
246*4882a593Smuzhiyun 	"univpll_d5",
247*4882a593Smuzhiyun };
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun static const char * const atb_parents[] = {
250*4882a593Smuzhiyun 	"clk26m",
251*4882a593Smuzhiyun 	"syspll1_d2",
252*4882a593Smuzhiyun 	"syspll_d5",
253*4882a593Smuzhiyun };
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun static const char * const mjc_parents[] = {
256*4882a593Smuzhiyun 	"clk26m",
257*4882a593Smuzhiyun 	"imgpll_ck",
258*4882a593Smuzhiyun 	"univpll_d5",
259*4882a593Smuzhiyun 	"syspll1_d2",
260*4882a593Smuzhiyun };
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun static const char * const dpi0_parents[] = {
263*4882a593Smuzhiyun 	"clk26m",
264*4882a593Smuzhiyun 	"tvdpll_d2",
265*4882a593Smuzhiyun 	"tvdpll_d4",
266*4882a593Smuzhiyun 	"tvdpll_d8",
267*4882a593Smuzhiyun 	"tvdpll_d16",
268*4882a593Smuzhiyun 	"clk26m",
269*4882a593Smuzhiyun 	"clk26m",
270*4882a593Smuzhiyun };
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun static const char * const aud_1_parents[] = {
273*4882a593Smuzhiyun 	"clk26m",
274*4882a593Smuzhiyun 	"apll1_ck",
275*4882a593Smuzhiyun };
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun static const char * const aud_2_parents[] = {
278*4882a593Smuzhiyun 	"clk26m",
279*4882a593Smuzhiyun 	"apll2_ck",
280*4882a593Smuzhiyun };
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun static const char * const ssusb_top_sys_parents[] = {
283*4882a593Smuzhiyun 	"clk26m",
284*4882a593Smuzhiyun 	"univpll3_d2",
285*4882a593Smuzhiyun };
286*4882a593Smuzhiyun 
287*4882a593Smuzhiyun static const char * const spm_parents[] = {
288*4882a593Smuzhiyun 	"clk26m",
289*4882a593Smuzhiyun 	"syspll1_d8",
290*4882a593Smuzhiyun };
291*4882a593Smuzhiyun 
292*4882a593Smuzhiyun static const char * const bsi_spi_parents[] = {
293*4882a593Smuzhiyun 	"clk26m",
294*4882a593Smuzhiyun 	"syspll_d3_d3",
295*4882a593Smuzhiyun 	"syspll1_d4",
296*4882a593Smuzhiyun 	"syspll_d7",
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun static const char * const audio_h_parents[] = {
300*4882a593Smuzhiyun 	"clk26m",
301*4882a593Smuzhiyun 	"apll2_ck",
302*4882a593Smuzhiyun 	"apll1_ck",
303*4882a593Smuzhiyun 	"univpll_d7",
304*4882a593Smuzhiyun };
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun static const char * const mfg_52m_parents[] = {
307*4882a593Smuzhiyun 	"clk26m",
308*4882a593Smuzhiyun 	"univpll2_d8",
309*4882a593Smuzhiyun 	"univpll2_d4",
310*4882a593Smuzhiyun 	"univpll2_d4",
311*4882a593Smuzhiyun };
312*4882a593Smuzhiyun 
313*4882a593Smuzhiyun static const char * const anc_md32_parents[] = {
314*4882a593Smuzhiyun 	"clk26m",
315*4882a593Smuzhiyun 	"syspll1_d2",
316*4882a593Smuzhiyun 	"univpll_d5",
317*4882a593Smuzhiyun };
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun /*
320*4882a593Smuzhiyun  * Clock mux ddrphycfg is needed by the DRAM controller. We mark it as
321*4882a593Smuzhiyun  * critical as otherwise the system will hang after boot.
322*4882a593Smuzhiyun  */
323*4882a593Smuzhiyun static const struct mtk_composite top_muxes[] = {
324*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE, "ulposc_axi_ck_mux_pre",
325*4882a593Smuzhiyun 	    ulposc_axi_ck_mux_pre_parents, 0x0040, 3, 1),
326*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX, "ulposc_axi_ck_mux",
327*4882a593Smuzhiyun 	    ulposc_axi_ck_mux_parents, 0x0040, 2, 1),
328*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_AXI, "axi_sel", axi_parents,
329*4882a593Smuzhiyun 	    0x0040, 0, 2),
330*4882a593Smuzhiyun 	MUX_FLAGS(CLK_TOP_MUX_DDRPHYCFG, "ddrphycfg_sel", ddrphycfg_parents,
331*4882a593Smuzhiyun 		  0x0040, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
332*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_MM, "mm_sel", mm_parents,
333*4882a593Smuzhiyun 	    0x0040, 24, 2),
334*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_PWM, "pwm_sel", pwm_parents, 0x0050, 0, 3, 7),
335*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_VDEC, "vdec_sel", vdec_parents, 0x0050, 8, 3, 15),
336*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_VENC, "venc_sel", venc_parents, 0x0050, 16, 2, 23),
337*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_MFG, "mfg_sel", mfg_parents, 0x0050, 24, 2, 31),
338*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_CAMTG, "camtg_sel", camtg, 0x0060, 0, 2, 7),
339*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_UART, "uart_sel", uart_parents, 0x0060, 8, 1, 15),
340*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_SPI, "spi_sel", spi_parents, 0x0060, 16, 2, 23),
341*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_ULPOSC_SPI_CK_MUX, "ulposc_spi_ck_mux",
342*4882a593Smuzhiyun 	    ulposc_spi_ck_mux_parents, 0x0060, 18, 1),
343*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_USB20, "usb20_sel", usb20_parents,
344*4882a593Smuzhiyun 		 0x0060, 24, 2, 31),
345*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_0_hclk_sel",
346*4882a593Smuzhiyun 	    msdc50_0_hclk_parents, 0x0070, 8, 2),
347*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel", msdc50_0_parents,
348*4882a593Smuzhiyun 		 0x0070, 16, 4, 23),
349*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel", msdc30_1_parents,
350*4882a593Smuzhiyun 		 0x0070, 24, 3, 31),
351*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel", msdc30_2_parents,
352*4882a593Smuzhiyun 		 0x0080, 0, 3, 7),
353*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_AUDIO, "audio_sel", audio_parents,
354*4882a593Smuzhiyun 		 0x0080, 16, 2, 23),
355*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel", aud_intbus_parents,
356*4882a593Smuzhiyun 	    0x0080, 24, 2),
357*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_PMICSPI, "pmicspi_sel", pmicspi_parents,
358*4882a593Smuzhiyun 	    0x0090, 0, 3),
359*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_SCP, "scp_sel", scp_parents,
360*4882a593Smuzhiyun 	    0x0090, 8, 2),
361*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_ATB, "atb_sel", atb_parents,
362*4882a593Smuzhiyun 	    0x0090, 16, 2),
363*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_MJC, "mjc_sel", mjc_parents, 0x0090, 24, 2, 31),
364*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_DPI0, "dpi0_sel", dpi0_parents, 0x00A0, 0, 3, 7),
365*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_AUD_1, "aud_1_sel", aud_1_parents,
366*4882a593Smuzhiyun 		 0x00A0, 16, 1, 23),
367*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_AUD_2, "aud_2_sel", aud_2_parents,
368*4882a593Smuzhiyun 		 0x00A0, 24, 1, 31),
369*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_SSUSB_TOP_SYS, "ssusb_top_sys_sel",
370*4882a593Smuzhiyun 	    ssusb_top_sys_parents, 0x00B0, 8, 1),
371*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_SPM, "spm_sel", spm_parents,
372*4882a593Smuzhiyun 	    0x00C0, 0, 1),
373*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_BSI_SPI, "bsi_spi_sel", bsi_spi_parents,
374*4882a593Smuzhiyun 	    0x00C0, 8, 2),
375*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_AUDIO_H, "audio_h_sel", audio_h_parents,
376*4882a593Smuzhiyun 		 0x00C0, 16, 2, 23),
377*4882a593Smuzhiyun 	MUX_GATE(CLK_TOP_MUX_ANC_MD32, "anc_md32_sel", anc_md32_parents,
378*4882a593Smuzhiyun 		 0x00C0, 24, 2, 31),
379*4882a593Smuzhiyun 	MUX(CLK_TOP_MUX_MFG_52M, "mfg_52m_sel", mfg_52m_parents,
380*4882a593Smuzhiyun 	    0x0104, 1, 2),
381*4882a593Smuzhiyun };
382*4882a593Smuzhiyun 
mtk_topckgen_init(struct platform_device * pdev)383*4882a593Smuzhiyun static int mtk_topckgen_init(struct platform_device *pdev)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun 	struct clk_onecell_data *clk_data;
386*4882a593Smuzhiyun 	void __iomem *base;
387*4882a593Smuzhiyun 	struct device_node *node = pdev->dev.of_node;
388*4882a593Smuzhiyun 
389*4882a593Smuzhiyun 	base = devm_platform_ioremap_resource(pdev, 0);
390*4882a593Smuzhiyun 	if (IS_ERR(base))
391*4882a593Smuzhiyun 		return PTR_ERR(base);
392*4882a593Smuzhiyun 
393*4882a593Smuzhiyun 	clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
394*4882a593Smuzhiyun 
395*4882a593Smuzhiyun 	mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
396*4882a593Smuzhiyun 				 clk_data);
397*4882a593Smuzhiyun 
398*4882a593Smuzhiyun 	mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
399*4882a593Smuzhiyun 				    &mt6797_clk_lock, clk_data);
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun 	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun 
404*4882a593Smuzhiyun static const struct mtk_gate_regs infra0_cg_regs = {
405*4882a593Smuzhiyun 	.set_ofs = 0x0080,
406*4882a593Smuzhiyun 	.clr_ofs = 0x0084,
407*4882a593Smuzhiyun 	.sta_ofs = 0x0090,
408*4882a593Smuzhiyun };
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun static const struct mtk_gate_regs infra1_cg_regs = {
411*4882a593Smuzhiyun 	.set_ofs = 0x0088,
412*4882a593Smuzhiyun 	.clr_ofs = 0x008c,
413*4882a593Smuzhiyun 	.sta_ofs = 0x0094,
414*4882a593Smuzhiyun };
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun static const struct mtk_gate_regs infra2_cg_regs = {
417*4882a593Smuzhiyun 	.set_ofs = 0x00a8,
418*4882a593Smuzhiyun 	.clr_ofs = 0x00ac,
419*4882a593Smuzhiyun 	.sta_ofs = 0x00b0,
420*4882a593Smuzhiyun };
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun #define GATE_ICG0(_id, _name, _parent, _shift) {		\
423*4882a593Smuzhiyun 	.id = _id,						\
424*4882a593Smuzhiyun 	.name = _name,						\
425*4882a593Smuzhiyun 	.parent_name = _parent,					\
426*4882a593Smuzhiyun 	.regs = &infra0_cg_regs,				\
427*4882a593Smuzhiyun 	.shift = _shift,					\
428*4882a593Smuzhiyun 	.ops = &mtk_clk_gate_ops_setclr,			\
429*4882a593Smuzhiyun }
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun #define GATE_ICG1(_id, _name, _parent, _shift)			\
432*4882a593Smuzhiyun 	GATE_ICG1_FLAGS(_id, _name, _parent, _shift, 0)
433*4882a593Smuzhiyun 
434*4882a593Smuzhiyun #define GATE_ICG1_FLAGS(_id, _name, _parent, _shift, _flags) {	\
435*4882a593Smuzhiyun 	.id = _id,						\
436*4882a593Smuzhiyun 	.name = _name,						\
437*4882a593Smuzhiyun 	.parent_name = _parent,					\
438*4882a593Smuzhiyun 	.regs = &infra1_cg_regs,				\
439*4882a593Smuzhiyun 	.shift = _shift,					\
440*4882a593Smuzhiyun 	.ops = &mtk_clk_gate_ops_setclr,			\
441*4882a593Smuzhiyun 	.flags = _flags,					\
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun #define GATE_ICG2(_id, _name, _parent, _shift)			\
445*4882a593Smuzhiyun 	GATE_ICG2_FLAGS(_id, _name, _parent, _shift, 0)
446*4882a593Smuzhiyun 
447*4882a593Smuzhiyun #define GATE_ICG2_FLAGS(_id, _name, _parent, _shift, _flags) {	\
448*4882a593Smuzhiyun 	.id = _id,						\
449*4882a593Smuzhiyun 	.name = _name,						\
450*4882a593Smuzhiyun 	.parent_name = _parent,					\
451*4882a593Smuzhiyun 	.regs = &infra2_cg_regs,				\
452*4882a593Smuzhiyun 	.shift = _shift,					\
453*4882a593Smuzhiyun 	.ops = &mtk_clk_gate_ops_setclr,			\
454*4882a593Smuzhiyun 	.flags = _flags,					\
455*4882a593Smuzhiyun }
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun /*
458*4882a593Smuzhiyun  * Clock gates dramc and dramc_b are needed by the DRAM controller.
459*4882a593Smuzhiyun  * We mark them as critical as otherwise the system will hang after boot.
460*4882a593Smuzhiyun  */
461*4882a593Smuzhiyun static const struct mtk_gate infra_clks[] = {
462*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "ulposc", 0),
463*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "pmicspi_sel", 1),
464*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "pmicspi_sel", 2),
465*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "pmicspi_sel", 3),
466*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_SCP, "infra_scp", "scp_sel", 4),
467*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_SEJ, "infra_sej", "axi_sel", 5),
468*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6),
469*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_SEJ_13M, "infra_sej_13m", "clk26m", 7),
470*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_ICUSB, "infra_icusb", "usb20_sel", 8),
471*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 9),
472*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10),
473*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_I2C0, "infra_i2c0", "axi_sel", 11),
474*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_I2C1, "infra_i2c1", "axi_sel", 12),
475*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_I2C2, "infra_i2c2", "axi_sel", 13),
476*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_I2C3, "infra_i2c3", "axi_sel", 14),
477*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk", "axi_sel", 15),
478*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM1, "infra_pwm1", "axi_sel", 16),
479*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM2, "infra_pwm2", "axi_sel", 17),
480*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM3, "infra_pwm3", "axi_sel", 18),
481*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM4, "infra_pwm4", "axi_sel", 19),
482*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_PWM, "infra_pwm", "axi_sel", 21),
483*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22),
484*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23),
485*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24),
486*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25),
487*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_0, "infra_md2md_ccif_0", "axi_sel", 27),
488*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_1, "infra_md2md_ccif_1", "axi_sel", 28),
489*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_2, "infra_md2md_ccif_2", "axi_sel", 29),
490*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_FHCTL, "infra_fhctl", "clk26m", 30),
491*4882a593Smuzhiyun 	GATE_ICG0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31),
492*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_3, "infra_md2md_ccif_3", "axi_sel", 0),
493*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_SPI, "infra_spi", "spi_sel", 1),
494*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_0_sel", 2),
495*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_4, "infra_md2md_ccif_4", "axi_sel", 3),
496*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MSDC1, "infra_msdc1", "msdc30_1_sel", 4),
497*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MSDC2, "infra_msdc2", "msdc30_2_sel", 5),
498*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_5, "infra_md2md_ccif_5", "axi_sel", 7),
499*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8),
500*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9),
501*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_AUXADC, "infra_auxadc", "clk26m", 10),
502*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11),
503*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_0, "infra_ap_c2k_ccif_0",
504*4882a593Smuzhiyun 		  "axi_sel", 12),
505*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_1, "infra_ap_c2k_ccif_1",
506*4882a593Smuzhiyun 		  "axi_sel", 13),
507*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_CLDMA, "infra_cldma", "axi_sel", 16),
508*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_DISP_PWM, "infra_disp_pwm", "pwm_sel", 17),
509*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_AP_DMA, "infra_ap_dma", "axi_sel", 18),
510*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20),
511*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "mm_sel", 22),
512*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23),
513*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25),
514*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26),
515*4882a593Smuzhiyun 	GATE_ICG1_FLAGS(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m",
516*4882a593Smuzhiyun 			"clk26m", 31, CLK_IS_CRITICAL),
517*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C4, "infra_i2c4", "axi_sel", 0),
518*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C_APPM, "infra_i2c_appm", "axi_sel", 1),
519*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C_GPUPM, "infra_i2c_gpupm", "axi_sel", 2),
520*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "axi_sel", 3),
521*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C2_ARB, "infra_i2c2_arb", "axi_sel", 4),
522*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C3_IMM, "infra_i2c3_imm", "axi_sel", 5),
523*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C3_ARB, "infra_i2c3_arb", "axi_sel", 6),
524*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_I2C5, "infra_i2c5", "axi_sel", 7),
525*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SYS_CIRQ, "infra_sys_cirq", "axi_sel", 8),
526*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 10),
527*4882a593Smuzhiyun 	GATE_ICG2_FLAGS(CLK_INFRA_DRAMC_B_F26M, "infra_dramc_b_f26m",
528*4882a593Smuzhiyun 			"clk26m", 11, CLK_IS_CRITICAL),
529*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_ANC_MD32, "infra_anc_md32", "anc_md32_sel", 12),
530*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_ANC_MD32_32K, "infra_anc_md32_32k", "clk26m", 13),
531*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_DVFS_SPM1, "infra_dvfs_spm1", "axi_sel", 15),
532*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_AES_TOP0, "infra_aes_top0", "axi_sel", 16),
533*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_AES_TOP1, "infra_aes_top1", "axi_sel", 17),
534*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SSUSB_BUS, "infra_ssusb_bus", "axi_sel", 18),
535*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 19),
536*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 20),
537*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 21),
538*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 22),
539*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_IRTX, "infra_irtx", "spi_sel", 23),
540*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SSUSB_SYS, "infra_ssusb_sys",
541*4882a593Smuzhiyun 		  "ssusb_top_sys_sel", 24),
542*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_SSUSB_REF, "infra_ssusb_ref", "clk26m", 9),
543*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_AUDIO_26M, "infra_audio_26m", "clk26m", 26),
544*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_AUDIO_26M_PAD_TOP, "infra_audio_26m_pad_top",
545*4882a593Smuzhiyun 		  "clk26m", 27),
546*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_modem_temp_share",
547*4882a593Smuzhiyun 		  "axi_sel", 28),
548*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_VAD_WRAP_SOC, "infra_vad_wrap_soc", "axi_sel", 29),
549*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_DRAMC_CONF, "infra_dramc_conf", "axi_sel", 30),
550*4882a593Smuzhiyun 	GATE_ICG2(CLK_INFRA_DRAMC_B_CONF, "infra_dramc_b_conf", "axi_sel", 31),
551*4882a593Smuzhiyun 	GATE_ICG1(CLK_INFRA_MFG_VCG, "infra_mfg_vcg", "mfg_52m_sel", 14),
552*4882a593Smuzhiyun };
553*4882a593Smuzhiyun 
554*4882a593Smuzhiyun static const struct mtk_fixed_factor infra_fixed_divs[] = {
555*4882a593Smuzhiyun 	FACTOR(CLK_INFRA_13M, "clk13m", "clk26m", 1, 2),
556*4882a593Smuzhiyun };
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun static struct clk_onecell_data *infra_clk_data;
559*4882a593Smuzhiyun 
mtk_infrasys_init_early(struct device_node * node)560*4882a593Smuzhiyun static void mtk_infrasys_init_early(struct device_node *node)
561*4882a593Smuzhiyun {
562*4882a593Smuzhiyun 	int r, i;
563*4882a593Smuzhiyun 
564*4882a593Smuzhiyun 	if (!infra_clk_data) {
565*4882a593Smuzhiyun 		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
566*4882a593Smuzhiyun 
567*4882a593Smuzhiyun 		for (i = 0; i < CLK_INFRA_NR; i++)
568*4882a593Smuzhiyun 			infra_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
569*4882a593Smuzhiyun 	}
570*4882a593Smuzhiyun 
571*4882a593Smuzhiyun 	mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
572*4882a593Smuzhiyun 				 infra_clk_data);
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun 	r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
575*4882a593Smuzhiyun 	if (r)
576*4882a593Smuzhiyun 		pr_err("%s(): could not register clock provider: %d\n",
577*4882a593Smuzhiyun 		       __func__, r);
578*4882a593Smuzhiyun }
579*4882a593Smuzhiyun 
580*4882a593Smuzhiyun CLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt6797-infracfg",
581*4882a593Smuzhiyun 		      mtk_infrasys_init_early);
582*4882a593Smuzhiyun 
mtk_infrasys_init(struct platform_device * pdev)583*4882a593Smuzhiyun static int mtk_infrasys_init(struct platform_device *pdev)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun 	int i;
586*4882a593Smuzhiyun 	struct device_node *node = pdev->dev.of_node;
587*4882a593Smuzhiyun 
588*4882a593Smuzhiyun 	if (!infra_clk_data) {
589*4882a593Smuzhiyun 		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
590*4882a593Smuzhiyun 	} else {
591*4882a593Smuzhiyun 		for (i = 0; i < CLK_INFRA_NR; i++) {
592*4882a593Smuzhiyun 			if (infra_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
593*4882a593Smuzhiyun 				infra_clk_data->clks[i] = ERR_PTR(-ENOENT);
594*4882a593Smuzhiyun 		}
595*4882a593Smuzhiyun 	}
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun 	mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
598*4882a593Smuzhiyun 			       infra_clk_data);
599*4882a593Smuzhiyun 	mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
600*4882a593Smuzhiyun 				 infra_clk_data);
601*4882a593Smuzhiyun 
602*4882a593Smuzhiyun 	return of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
603*4882a593Smuzhiyun }
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun #define MT6797_PLL_FMAX		(3000UL * MHZ)
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun #define CON0_MT6797_RST_BAR	BIT(24)
608*4882a593Smuzhiyun 
609*4882a593Smuzhiyun #define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
610*4882a593Smuzhiyun 			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg,	\
611*4882a593Smuzhiyun 			_pcw_shift, _div_table) {			\
612*4882a593Smuzhiyun 	.id = _id,						\
613*4882a593Smuzhiyun 	.name = _name,						\
614*4882a593Smuzhiyun 	.reg = _reg,						\
615*4882a593Smuzhiyun 	.pwr_reg = _pwr_reg,					\
616*4882a593Smuzhiyun 	.en_mask = _en_mask,					\
617*4882a593Smuzhiyun 	.flags = _flags,					\
618*4882a593Smuzhiyun 	.rst_bar_mask = CON0_MT6797_RST_BAR,			\
619*4882a593Smuzhiyun 	.fmax = MT6797_PLL_FMAX,				\
620*4882a593Smuzhiyun 	.pcwbits = _pcwbits,					\
621*4882a593Smuzhiyun 	.pd_reg = _pd_reg,					\
622*4882a593Smuzhiyun 	.pd_shift = _pd_shift,					\
623*4882a593Smuzhiyun 	.tuner_reg = _tuner_reg,				\
624*4882a593Smuzhiyun 	.pcw_reg = _pcw_reg,					\
625*4882a593Smuzhiyun 	.pcw_shift = _pcw_shift,				\
626*4882a593Smuzhiyun 	.div_table = _div_table,				\
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun 
629*4882a593Smuzhiyun #define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
630*4882a593Smuzhiyun 			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg,	\
631*4882a593Smuzhiyun 			_pcw_shift)					\
632*4882a593Smuzhiyun 		PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
633*4882a593Smuzhiyun 			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
634*4882a593Smuzhiyun 			NULL)
635*4882a593Smuzhiyun 
636*4882a593Smuzhiyun static const struct mtk_pll_data plls[] = {
637*4882a593Smuzhiyun 	PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0xF0000101, PLL_AO,
638*4882a593Smuzhiyun 	    21, 0x220, 4, 0x0, 0x224, 0),
639*4882a593Smuzhiyun 	PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0230, 0x023C, 0xFE000011, 0, 7,
640*4882a593Smuzhiyun 	    0x230, 4, 0x0, 0x234, 14),
641*4882a593Smuzhiyun 	PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0x00000101, 0, 21,
642*4882a593Smuzhiyun 	    0x244, 24, 0x0, 0x244, 0),
643*4882a593Smuzhiyun 	PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0x00000121, 0, 21,
644*4882a593Smuzhiyun 	    0x250, 4, 0x0, 0x254, 0),
645*4882a593Smuzhiyun 	PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0260, 0x026C, 0x00000121, 0, 21,
646*4882a593Smuzhiyun 	    0x260, 4, 0x0, 0x264, 0),
647*4882a593Smuzhiyun 	PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0270, 0x027C, 0xC0000121, 0, 21,
648*4882a593Smuzhiyun 	    0x270, 4, 0x0, 0x274, 0),
649*4882a593Smuzhiyun 	PLL(CLK_APMIXED_CODECPLL, "codecpll", 0x0290, 0x029C, 0x00000121, 0, 21,
650*4882a593Smuzhiyun 	    0x290, 4, 0x0, 0x294, 0),
651*4882a593Smuzhiyun 	PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x02E4, 0x02F0, 0x00000121, 0, 21,
652*4882a593Smuzhiyun 	    0x2E4, 4, 0x0, 0x2E8, 0),
653*4882a593Smuzhiyun 	PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0x00000131, 0, 31,
654*4882a593Smuzhiyun 	    0x2A0, 4, 0x2A8, 0x2A4, 0),
655*4882a593Smuzhiyun 	PLL(CLK_APMIXED_APLL2, "apll2", 0x02B4, 0x02C4, 0x00000131, 0, 31,
656*4882a593Smuzhiyun 	    0x2B4, 4, 0x2BC, 0x2B8, 0),
657*4882a593Smuzhiyun };
658*4882a593Smuzhiyun 
mtk_apmixedsys_init(struct platform_device * pdev)659*4882a593Smuzhiyun static int mtk_apmixedsys_init(struct platform_device *pdev)
660*4882a593Smuzhiyun {
661*4882a593Smuzhiyun 	struct clk_onecell_data *clk_data;
662*4882a593Smuzhiyun 	struct device_node *node = pdev->dev.of_node;
663*4882a593Smuzhiyun 
664*4882a593Smuzhiyun 	clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
665*4882a593Smuzhiyun 	if (!clk_data)
666*4882a593Smuzhiyun 		return -ENOMEM;
667*4882a593Smuzhiyun 
668*4882a593Smuzhiyun 	mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun 	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun 
673*4882a593Smuzhiyun static const struct of_device_id of_match_clk_mt6797[] = {
674*4882a593Smuzhiyun 	{
675*4882a593Smuzhiyun 		.compatible = "mediatek,mt6797-topckgen",
676*4882a593Smuzhiyun 		.data = mtk_topckgen_init,
677*4882a593Smuzhiyun 	}, {
678*4882a593Smuzhiyun 		.compatible = "mediatek,mt6797-infracfg",
679*4882a593Smuzhiyun 		.data = mtk_infrasys_init,
680*4882a593Smuzhiyun 	}, {
681*4882a593Smuzhiyun 		.compatible = "mediatek,mt6797-apmixedsys",
682*4882a593Smuzhiyun 		.data = mtk_apmixedsys_init,
683*4882a593Smuzhiyun 	}, {
684*4882a593Smuzhiyun 		/* sentinel */
685*4882a593Smuzhiyun 	}
686*4882a593Smuzhiyun };
687*4882a593Smuzhiyun 
clk_mt6797_probe(struct platform_device * pdev)688*4882a593Smuzhiyun static int clk_mt6797_probe(struct platform_device *pdev)
689*4882a593Smuzhiyun {
690*4882a593Smuzhiyun 	int (*clk_init)(struct platform_device *);
691*4882a593Smuzhiyun 	int r;
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun 	clk_init = of_device_get_match_data(&pdev->dev);
694*4882a593Smuzhiyun 	if (!clk_init)
695*4882a593Smuzhiyun 		return -EINVAL;
696*4882a593Smuzhiyun 
697*4882a593Smuzhiyun 	r = clk_init(pdev);
698*4882a593Smuzhiyun 	if (r)
699*4882a593Smuzhiyun 		dev_err(&pdev->dev,
700*4882a593Smuzhiyun 			"could not register clock provider: %s: %d\n",
701*4882a593Smuzhiyun 			pdev->name, r);
702*4882a593Smuzhiyun 
703*4882a593Smuzhiyun 	return r;
704*4882a593Smuzhiyun }
705*4882a593Smuzhiyun 
706*4882a593Smuzhiyun static struct platform_driver clk_mt6797_drv = {
707*4882a593Smuzhiyun 	.probe = clk_mt6797_probe,
708*4882a593Smuzhiyun 	.driver = {
709*4882a593Smuzhiyun 		.name = "clk-mt6797",
710*4882a593Smuzhiyun 		.of_match_table = of_match_clk_mt6797,
711*4882a593Smuzhiyun 	},
712*4882a593Smuzhiyun };
713*4882a593Smuzhiyun 
clk_mt6797_init(void)714*4882a593Smuzhiyun static int __init clk_mt6797_init(void)
715*4882a593Smuzhiyun {
716*4882a593Smuzhiyun 	return platform_driver_register(&clk_mt6797_drv);
717*4882a593Smuzhiyun }
718*4882a593Smuzhiyun 
719*4882a593Smuzhiyun arch_initcall(clk_mt6797_init);
720