blob: 6af6f9f11bd0f33673e5993b999e6be8f80db793 [file] [log] [blame]
developerd1b1ffa2018-11-15 10:07:55 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7623 SoC
4 *
5 * Copyright (C) 2018 MediaTek Inc.
6 * Author: Ryder Lee <ryder.lee@mediatek.com>
7 */
8
developerd1b1ffa2018-11-15 10:07:55 +08009#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
developer02259452018-12-20 16:12:52 +080011#include <asm/arch-mediatek/reset.h>
developerd1b1ffa2018-11-15 10:07:55 +080012#include <asm/io.h>
13#include <dt-bindings/clock/mt7623-clk.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
developerd1b1ffa2018-11-15 10:07:55 +080015
16#include "clk-mtk.h"
17
18#define MT7623_CLKSQ_STB_CON0 0x18
19#define MT7623_PLL_ISO_CON0 0x24
20#define MT7623_PLL_FMAX (2000UL * MHZ)
21#define MT7623_CON0_RST_BAR BIT(27)
22
23#define MCU_AXI_DIV 0x60
24#define AXI_DIV_MSK GENMASK(4, 0)
25#define AXI_DIV_SEL(x) (x)
26
27/* apmixedsys */
28#define PLL(_id, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, _pd_reg, \
29 _pd_shift, _pcw_reg, _pcw_shift) { \
30 .id = _id, \
31 .reg = _reg, \
32 .pwr_reg = _pwr_reg, \
33 .en_mask = _en_mask, \
34 .rst_bar_mask = MT7623_CON0_RST_BAR, \
35 .fmax = MT7623_PLL_FMAX, \
36 .flags = _flags, \
37 .pcwbits = _pcwbits, \
38 .pd_reg = _pd_reg, \
39 .pd_shift = _pd_shift, \
40 .pcw_reg = _pcw_reg, \
41 .pcw_shift = _pcw_shift, \
42 }
43
44static const struct mtk_pll_data apmixed_plls[] = {
45 PLL(CLK_APMIXED_ARMPLL, 0x200, 0x20c, 0x80000001, 0,
46 21, 0x204, 24, 0x204, 0),
47 PLL(CLK_APMIXED_MAINPLL, 0x210, 0x21c, 0xf0000001, HAVE_RST_BAR,
48 21, 0x210, 4, 0x214, 0),
49 PLL(CLK_APMIXED_UNIVPLL, 0x220, 0x22c, 0xf3000001, HAVE_RST_BAR,
50 7, 0x220, 4, 0x224, 14),
51 PLL(CLK_APMIXED_MMPLL, 0x230, 0x23c, 0x00000001, 0,
52 21, 0x230, 4, 0x234, 0),
53 PLL(CLK_APMIXED_MSDCPLL, 0x240, 0x24c, 0x00000001, 0,
54 21, 0x240, 4, 0x244, 0),
55 PLL(CLK_APMIXED_TVDPLL, 0x250, 0x25c, 0x00000001, 0,
56 21, 0x250, 4, 0x254, 0),
57 PLL(CLK_APMIXED_AUD1PLL, 0x270, 0x27c, 0x00000001, 0,
58 31, 0x270, 4, 0x274, 0),
59 PLL(CLK_APMIXED_TRGPLL, 0x280, 0x28c, 0x00000001, 0,
60 31, 0x280, 4, 0x284, 0),
61 PLL(CLK_APMIXED_ETHPLL, 0x290, 0x29c, 0x00000001, 0,
62 31, 0x290, 4, 0x294, 0),
63 PLL(CLK_APMIXED_VDECPLL, 0x2a0, 0x2ac, 0x00000001, 0,
64 31, 0x2a0, 4, 0x2a4, 0),
65 PLL(CLK_APMIXED_HADDS2PLL, 0x2b0, 0x2bc, 0x00000001, 0,
66 31, 0x2b0, 4, 0x2b4, 0),
67 PLL(CLK_APMIXED_AUD2PLL, 0x2c0, 0x2cc, 0x00000001, 0,
68 31, 0x2c0, 4, 0x2c4, 0),
69 PLL(CLK_APMIXED_TVD2PLL, 0x2d0, 0x2dc, 0x00000001, 0,
70 21, 0x2d0, 4, 0x2d4, 0),
71};
72
73/* topckgen */
Christian Marangie80ebc82024-08-02 15:45:03 +020074
75/* Fixed CLK exposed upstream by the hdmi PHY driver */
76#define CLK_TOP_HDMITX_CLKDIG_CTS CLK_TOP_NR
77
78static const int top_id_offs_map[CLK_TOP_NR + 1] = {
79 /* Fixed CLK */
80 [CLK_TOP_DPI] = 0,
81 [CLK_TOP_DMPLL] = 1,
82 [CLK_TOP_VENCPLL] = 2,
83 [CLK_TOP_HDMI_0_PIX340M] = 3,
84 [CLK_TOP_HDMI_0_DEEP340M] = 4,
85 [CLK_TOP_HDMI_0_PLL340M] = 5,
86 [CLK_TOP_HADDS2_FB] = 6,
87 [CLK_TOP_WBG_DIG_416M] = 7,
88 [CLK_TOP_DSI0_LNTC_DSI] = 8,
89 [CLK_TOP_HDMI_SCL_RX] = 9,
90 [CLK_TOP_32K_EXTERNAL] = 10,
91 [CLK_TOP_HDMITX_CLKDIG_CTS] = 11,
92 [CLK_TOP_AUD_EXT1] = 12,
93 [CLK_TOP_AUD_EXT2] = 13,
94 [CLK_TOP_NFI1X_PAD] = 14,
95 /* Factor CLK */
96 [CLK_TOP_SYSPLL] = 15,
97 [CLK_TOP_SYSPLL_D2] = 16,
98 [CLK_TOP_SYSPLL_D3] = 17,
99 [CLK_TOP_SYSPLL_D5] = 18,
100 [CLK_TOP_SYSPLL_D7] = 19,
101 [CLK_TOP_SYSPLL1_D2] = 20,
102 [CLK_TOP_SYSPLL1_D4] = 21,
103 [CLK_TOP_SYSPLL1_D8] = 22,
104 [CLK_TOP_SYSPLL1_D16] = 23,
105 [CLK_TOP_SYSPLL2_D2] = 24,
106 [CLK_TOP_SYSPLL2_D4] = 25,
107 [CLK_TOP_SYSPLL2_D8] = 26,
108 [CLK_TOP_SYSPLL3_D2] = 27,
109 [CLK_TOP_SYSPLL3_D4] = 28,
110 [CLK_TOP_SYSPLL4_D2] = 29,
111 [CLK_TOP_SYSPLL4_D4] = 30,
112 [CLK_TOP_UNIVPLL] = 31,
113 [CLK_TOP_UNIVPLL_D2] = 32,
114 [CLK_TOP_UNIVPLL_D3] = 33,
115 [CLK_TOP_UNIVPLL_D5] = 34,
116 [CLK_TOP_UNIVPLL_D7] = 35,
117 [CLK_TOP_UNIVPLL_D26] = 36,
118 [CLK_TOP_UNIVPLL_D52] = 37,
119 [CLK_TOP_UNIVPLL_D108] = 38,
120 [CLK_TOP_USB_PHY48M] = 39,
121 [CLK_TOP_UNIVPLL1_D2] = 40,
122 [CLK_TOP_UNIVPLL1_D4] = 41,
123 [CLK_TOP_UNIVPLL1_D8] = 42,
124 [CLK_TOP_UNIVPLL2_D2] = 43,
125 [CLK_TOP_UNIVPLL2_D4] = 44,
126 [CLK_TOP_UNIVPLL2_D8] = 45,
127 [CLK_TOP_UNIVPLL2_D16] = 46,
128 [CLK_TOP_UNIVPLL2_D32] = 47,
129 [CLK_TOP_UNIVPLL3_D2] = 48,
130 [CLK_TOP_UNIVPLL3_D4] = 49,
131 [CLK_TOP_UNIVPLL3_D8] = 50,
132 [CLK_TOP_MSDCPLL] = 51,
133 [CLK_TOP_MSDCPLL_D2] = 52,
134 [CLK_TOP_MSDCPLL_D4] = 53,
135 [CLK_TOP_MSDCPLL_D8] = 54,
136 [CLK_TOP_MMPLL] = 55,
137 [CLK_TOP_MMPLL_D2] = 56,
138 [CLK_TOP_DMPLL_D2] = 57,
139 [CLK_TOP_DMPLL_D4] = 58,
140 [CLK_TOP_DMPLL_X2] = 59,
141 [CLK_TOP_TVDPLL] = 60,
142 [CLK_TOP_TVDPLL_D2] = 61,
143 [CLK_TOP_TVDPLL_D4] = 62,
144 [CLK_TOP_VDECPLL] = 63,
145 [CLK_TOP_TVD2PLL] = 64,
146 [CLK_TOP_TVD2PLL_D2] = 65,
147 [CLK_TOP_MIPIPLL] = 66,
148 [CLK_TOP_MIPIPLL_D2] = 67,
149 [CLK_TOP_MIPIPLL_D4] = 68,
150 [CLK_TOP_HDMIPLL] = 69,
151 [CLK_TOP_HDMIPLL_D2] = 70,
152 [CLK_TOP_HDMIPLL_D3] = 71,
153 [CLK_TOP_ARMPLL_1P3G] = 72,
154 [CLK_TOP_AUDPLL] = 73,
155 [CLK_TOP_AUDPLL_D4] = 74,
156 [CLK_TOP_AUDPLL_D8] = 75,
157 [CLK_TOP_AUDPLL_D16] = 76,
158 [CLK_TOP_AUDPLL_D24] = 77,
159 [CLK_TOP_AUD1PLL_98M] = 78,
160 [CLK_TOP_AUD2PLL_90M] = 79,
161 [CLK_TOP_HADDS2PLL_98M] = 80,
162 [CLK_TOP_HADDS2PLL_294M] = 81,
163 [CLK_TOP_ETHPLL_500M] = 82,
164 [CLK_TOP_CLK26M_D8] = 83,
165 [CLK_TOP_32K_INTERNAL] = 84,
166 [CLK_TOP_AXISEL_D4] = 85,
167 [CLK_TOP_8BDAC] = 86,
168 /* MUX CLK */
169 [CLK_TOP_AXI_SEL] = 87,
170 [CLK_TOP_MEM_SEL] = 88,
171 [CLK_TOP_DDRPHYCFG_SEL] = 89,
172 [CLK_TOP_MM_SEL] = 90,
173 [CLK_TOP_PWM_SEL] = 91,
174 [CLK_TOP_VDEC_SEL] = 92,
175 [CLK_TOP_MFG_SEL] = 93,
176 [CLK_TOP_CAMTG_SEL] = 94,
177 [CLK_TOP_UART_SEL] = 95,
178 [CLK_TOP_SPI0_SEL] = 96,
179 [CLK_TOP_USB20_SEL] = 97,
180 [CLK_TOP_MSDC30_0_SEL] = 98,
181 [CLK_TOP_MSDC30_1_SEL] = 99,
182 [CLK_TOP_MSDC30_2_SEL] = 100,
183 [CLK_TOP_AUDIO_SEL] = 101,
184 [CLK_TOP_AUDINTBUS_SEL] = 102,
185 [CLK_TOP_PMICSPI_SEL] = 103,
186 [CLK_TOP_SCP_SEL] = 104,
187 [CLK_TOP_DPI0_SEL] = 105,
188 [CLK_TOP_DPI1_SEL] = 106,
189 [CLK_TOP_TVE_SEL] = 107,
190 [CLK_TOP_HDMI_SEL] = 108,
191 [CLK_TOP_APLL_SEL] = 109,
192 [CLK_TOP_RTC_SEL] = 110,
193 [CLK_TOP_NFI2X_SEL] = 111,
194 [CLK_TOP_EMMC_HCLK_SEL] = 112,
195 [CLK_TOP_FLASH_SEL] = 113,
196 [CLK_TOP_DI_SEL] = 114,
197 [CLK_TOP_NR_SEL] = 115,
198 [CLK_TOP_OSD_SEL] = 116,
199 [CLK_TOP_HDMIRX_BIST_SEL] = 117,
200 [CLK_TOP_INTDIR_SEL] = 118,
201 [CLK_TOP_ASM_I_SEL] = 119,
202 [CLK_TOP_ASM_M_SEL] = 120,
203 [CLK_TOP_ASM_H_SEL] = 121,
204 [CLK_TOP_MS_CARD_SEL] = 122,
205 [CLK_TOP_ETHIF_SEL] = 123,
206 [CLK_TOP_HDMIRX26_24_SEL] = 124,
207 [CLK_TOP_MSDC30_3_SEL] = 125,
208 [CLK_TOP_CMSYS_SEL] = 126,
209 [CLK_TOP_SPI1_SEL] = 127,
210 [CLK_TOP_SPI2_SEL] = 128,
211 [CLK_TOP_8BDAC_SEL] = 129,
212 [CLK_TOP_AUD2DVD_SEL] = 130,
213 [CLK_TOP_PADMCLK_SEL] = 131,
214 [CLK_TOP_AUD_MUX1_SEL] = 132,
215 [CLK_TOP_AUD_MUX2_SEL] = 133,
216 [CLK_TOP_AUDPLL_MUX_SEL] = 134,
217 [CLK_TOP_AUD_K1_SRC_SEL] = 135,
218 [CLK_TOP_AUD_K2_SRC_SEL] = 136,
219 [CLK_TOP_AUD_K3_SRC_SEL] = 137,
220 [CLK_TOP_AUD_K4_SRC_SEL] = 138,
221 [CLK_TOP_AUD_K5_SRC_SEL] = 139,
222 [CLK_TOP_AUD_K6_SRC_SEL] = 140,
223 /* Misc CLK only used as parents */
224 [CLK_TOP_AUD_EXTCK1_DIV] = 141,
225 [CLK_TOP_AUD_EXTCK2_DIV] = 142,
226 [CLK_TOP_AUD_MUX1_DIV] = 143,
227 [CLK_TOP_AUD_MUX2_DIV] = 144,
228 [CLK_TOP_AUD_K1_SRC_DIV] = 145,
229 [CLK_TOP_AUD_K2_SRC_DIV] = 146,
230 [CLK_TOP_AUD_K3_SRC_DIV] = 147,
231 [CLK_TOP_AUD_K4_SRC_DIV] = 148,
232 [CLK_TOP_AUD_K5_SRC_DIV] = 149,
233 [CLK_TOP_AUD_K6_SRC_DIV] = 150,
234 [CLK_TOP_AUD_48K_TIMING] = 151,
235 [CLK_TOP_AUD_44K_TIMING] = 152,
236 [CLK_TOP_AUD_I2S1_MCLK] = 153,
237 [CLK_TOP_AUD_I2S2_MCLK] = 154,
238 [CLK_TOP_AUD_I2S3_MCLK] = 155,
239 [CLK_TOP_AUD_I2S4_MCLK] = 156,
240 [CLK_TOP_AUD_I2S5_MCLK] = 157,
241 [CLK_TOP_AUD_I2S6_MCLK] = 158,
242};
243
developerd1b1ffa2018-11-15 10:07:55 +0800244#define FACTOR0(_id, _parent, _mult, _div) \
245 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
246
247#define FACTOR1(_id, _parent, _mult, _div) \
248 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
249
250#define FACTOR2(_id, _parent, _mult, _div) \
251 FACTOR(_id, _parent, _mult, _div, 0)
252
253static const struct mtk_fixed_clk top_fixed_clks[] = {
254 FIXED_CLK(CLK_TOP_DPI, CLK_XTAL, 108 * MHZ),
255 FIXED_CLK(CLK_TOP_DMPLL, CLK_XTAL, 400 * MHZ),
256 FIXED_CLK(CLK_TOP_VENCPLL, CLK_XTAL, 295.75 * MHZ),
257 FIXED_CLK(CLK_TOP_HDMI_0_PIX340M, CLK_XTAL, 340 * MHZ),
258 FIXED_CLK(CLK_TOP_HDMI_0_DEEP340M, CLK_XTAL, 340 * MHZ),
259 FIXED_CLK(CLK_TOP_HDMI_0_PLL340M, CLK_XTAL, 340 * MHZ),
260 FIXED_CLK(CLK_TOP_HADDS2_FB, CLK_XTAL, 27 * MHZ),
261 FIXED_CLK(CLK_TOP_WBG_DIG_416M, CLK_XTAL, 416 * MHZ),
262 FIXED_CLK(CLK_TOP_DSI0_LNTC_DSI, CLK_XTAL, 143 * MHZ),
263 FIXED_CLK(CLK_TOP_HDMI_SCL_RX, CLK_XTAL, 27 * MHZ),
264 FIXED_CLK(CLK_TOP_32K_EXTERNAL, CLK_XTAL, 32000),
265 FIXED_CLK(CLK_TOP_HDMITX_CLKDIG_CTS, CLK_XTAL, 300 * MHZ),
266 FIXED_CLK(CLK_TOP_AUD_EXT1, CLK_XTAL, 0),
267 FIXED_CLK(CLK_TOP_AUD_EXT2, CLK_XTAL, 0),
268 FIXED_CLK(CLK_TOP_NFI1X_PAD, CLK_XTAL, 0),
269};
270
271static const struct mtk_fixed_factor top_fixed_divs[] = {
272 FACTOR0(CLK_TOP_SYSPLL, CLK_APMIXED_MAINPLL, 1, 1),
273 FACTOR0(CLK_TOP_SYSPLL_D2, CLK_APMIXED_MAINPLL, 1, 2),
274 FACTOR0(CLK_TOP_SYSPLL_D3, CLK_APMIXED_MAINPLL, 1, 3),
275 FACTOR0(CLK_TOP_SYSPLL_D5, CLK_APMIXED_MAINPLL, 1, 5),
276 FACTOR0(CLK_TOP_SYSPLL_D7, CLK_APMIXED_MAINPLL, 1, 7),
277 FACTOR1(CLK_TOP_SYSPLL1_D2, CLK_TOP_SYSPLL_D2, 1, 2),
278 FACTOR1(CLK_TOP_SYSPLL1_D4, CLK_TOP_SYSPLL_D2, 1, 4),
279 FACTOR1(CLK_TOP_SYSPLL1_D8, CLK_TOP_SYSPLL_D2, 1, 8),
280 FACTOR1(CLK_TOP_SYSPLL1_D16, CLK_TOP_SYSPLL_D2, 1, 16),
281 FACTOR1(CLK_TOP_SYSPLL2_D2, CLK_TOP_SYSPLL_D3, 1, 2),
282 FACTOR1(CLK_TOP_SYSPLL2_D4, CLK_TOP_SYSPLL_D3, 1, 4),
283 FACTOR1(CLK_TOP_SYSPLL2_D8, CLK_TOP_SYSPLL_D3, 1, 8),
284 FACTOR1(CLK_TOP_SYSPLL3_D2, CLK_TOP_SYSPLL_D5, 1, 2),
285 FACTOR1(CLK_TOP_SYSPLL3_D4, CLK_TOP_SYSPLL_D5, 1, 4),
286 FACTOR1(CLK_TOP_SYSPLL4_D2, CLK_TOP_SYSPLL_D7, 1, 2),
287 FACTOR1(CLK_TOP_SYSPLL4_D4, CLK_TOP_SYSPLL_D7, 1, 4),
288
289 FACTOR0(CLK_TOP_UNIVPLL, CLK_APMIXED_UNIVPLL, 1, 1),
290 FACTOR0(CLK_TOP_UNIVPLL_D2, CLK_APMIXED_UNIVPLL, 1, 2),
291 FACTOR0(CLK_TOP_UNIVPLL_D3, CLK_APMIXED_UNIVPLL, 1, 3),
292 FACTOR0(CLK_TOP_UNIVPLL_D5, CLK_APMIXED_UNIVPLL, 1, 5),
293 FACTOR0(CLK_TOP_UNIVPLL_D7, CLK_APMIXED_UNIVPLL, 1, 7),
294 FACTOR0(CLK_TOP_UNIVPLL_D26, CLK_APMIXED_UNIVPLL, 1, 26),
295 FACTOR0(CLK_TOP_UNIVPLL_D52, CLK_APMIXED_UNIVPLL, 1, 52),
296 FACTOR0(CLK_TOP_UNIVPLL_D108, CLK_APMIXED_UNIVPLL, 1, 108),
297 FACTOR0(CLK_TOP_USB_PHY48M, CLK_APMIXED_UNIVPLL, 1, 26),
298 FACTOR1(CLK_TOP_UNIVPLL1_D2, CLK_TOP_UNIVPLL_D2, 1, 2),
299 FACTOR1(CLK_TOP_UNIVPLL1_D4, CLK_TOP_UNIVPLL_D2, 1, 4),
300 FACTOR1(CLK_TOP_UNIVPLL1_D8, CLK_TOP_UNIVPLL_D2, 1, 8),
301 FACTOR1(CLK_TOP_UNIVPLL2_D2, CLK_TOP_UNIVPLL_D3, 1, 2),
302 FACTOR1(CLK_TOP_UNIVPLL2_D4, CLK_TOP_UNIVPLL_D3, 1, 4),
303 FACTOR1(CLK_TOP_UNIVPLL2_D8, CLK_TOP_UNIVPLL_D3, 1, 8),
304 FACTOR1(CLK_TOP_UNIVPLL2_D16, CLK_TOP_UNIVPLL_D3, 1, 16),
305 FACTOR1(CLK_TOP_UNIVPLL2_D32, CLK_TOP_UNIVPLL_D3, 1, 32),
306 FACTOR1(CLK_TOP_UNIVPLL3_D2, CLK_TOP_UNIVPLL_D5, 1, 2),
307 FACTOR1(CLK_TOP_UNIVPLL3_D4, CLK_TOP_UNIVPLL_D5, 1, 4),
308 FACTOR1(CLK_TOP_UNIVPLL3_D8, CLK_TOP_UNIVPLL_D5, 1, 8),
309
310 FACTOR0(CLK_TOP_MSDCPLL, CLK_APMIXED_MSDCPLL, 1, 1),
311 FACTOR0(CLK_TOP_MSDCPLL_D2, CLK_APMIXED_MSDCPLL, 1, 2),
312 FACTOR0(CLK_TOP_MSDCPLL_D4, CLK_APMIXED_MSDCPLL, 1, 4),
313 FACTOR0(CLK_TOP_MSDCPLL_D8, CLK_APMIXED_MSDCPLL, 1, 8),
314
315 FACTOR0(CLK_TOP_MMPLL, CLK_APMIXED_MMPLL, 1, 1),
316 FACTOR0(CLK_TOP_MMPLL_D2, CLK_APMIXED_MMPLL, 1, 2),
317
318 FACTOR1(CLK_TOP_DMPLL_D2, CLK_TOP_DMPLL, 1, 2),
319 FACTOR1(CLK_TOP_DMPLL_D4, CLK_TOP_DMPLL, 1, 4),
320 FACTOR1(CLK_TOP_DMPLL_X2, CLK_TOP_DMPLL, 1, 1),
321
322 FACTOR0(CLK_TOP_TVDPLL, CLK_APMIXED_TVDPLL, 1, 1),
323 FACTOR0(CLK_TOP_TVDPLL_D2, CLK_APMIXED_TVDPLL, 1, 2),
324 FACTOR0(CLK_TOP_TVDPLL_D4, CLK_APMIXED_TVDPLL, 1, 4),
325
326 FACTOR0(CLK_TOP_VDECPLL, CLK_APMIXED_VDECPLL, 1, 1),
327 FACTOR0(CLK_TOP_TVD2PLL, CLK_APMIXED_TVD2PLL, 1, 1),
328 FACTOR0(CLK_TOP_TVD2PLL_D2, CLK_APMIXED_TVD2PLL, 1, 2),
329
330 FACTOR1(CLK_TOP_MIPIPLL, CLK_TOP_DPI, 1, 1),
331 FACTOR1(CLK_TOP_MIPIPLL_D2, CLK_TOP_DPI, 1, 2),
332 FACTOR1(CLK_TOP_MIPIPLL_D4, CLK_TOP_DPI, 1, 4),
333
334 FACTOR1(CLK_TOP_HDMIPLL, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 1),
335 FACTOR1(CLK_TOP_HDMIPLL_D2, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 2),
336 FACTOR1(CLK_TOP_HDMIPLL_D3, CLK_TOP_HDMITX_CLKDIG_CTS, 1, 3),
337
338 FACTOR0(CLK_TOP_ARMPLL_1P3G, CLK_APMIXED_ARMPLL, 1, 1),
339
340 FACTOR1(CLK_TOP_AUDPLL, CLK_TOP_AUDPLL_MUX_SEL, 1, 1),
341 FACTOR1(CLK_TOP_AUDPLL_D4, CLK_TOP_AUDPLL_MUX_SEL, 1, 4),
342 FACTOR1(CLK_TOP_AUDPLL_D8, CLK_TOP_AUDPLL_MUX_SEL, 1, 8),
343 FACTOR1(CLK_TOP_AUDPLL_D16, CLK_TOP_AUDPLL_MUX_SEL, 1, 16),
344 FACTOR1(CLK_TOP_AUDPLL_D24, CLK_TOP_AUDPLL_MUX_SEL, 1, 24),
345
346 FACTOR0(CLK_TOP_AUD1PLL_98M, CLK_APMIXED_AUD1PLL, 1, 3),
347 FACTOR0(CLK_TOP_AUD2PLL_90M, CLK_APMIXED_AUD2PLL, 1, 3),
348 FACTOR0(CLK_TOP_HADDS2PLL_98M, CLK_APMIXED_HADDS2PLL, 1, 3),
349 FACTOR0(CLK_TOP_HADDS2PLL_294M, CLK_APMIXED_HADDS2PLL, 1, 1),
350 FACTOR0(CLK_TOP_ETHPLL_500M, CLK_APMIXED_ETHPLL, 1, 1),
351 FACTOR2(CLK_TOP_CLK26M_D8, CLK_XTAL, 1, 8),
352 FACTOR2(CLK_TOP_32K_INTERNAL, CLK_XTAL, 1, 793),
353 FACTOR1(CLK_TOP_AXISEL_D4, CLK_TOP_AXI_SEL, 1, 4),
354 FACTOR1(CLK_TOP_8BDAC, CLK_TOP_UNIVPLL_D2, 1, 1),
355};
356
357static const int axi_parents[] = {
358 CLK_XTAL,
359 CLK_TOP_SYSPLL1_D2,
360 CLK_TOP_SYSPLL_D5,
361 CLK_TOP_SYSPLL1_D4,
362 CLK_TOP_UNIVPLL_D5,
363 CLK_TOP_UNIVPLL2_D2,
364 CLK_TOP_MMPLL_D2,
365 CLK_TOP_DMPLL_D2
366};
367
368static const int mem_parents[] = {
369 CLK_XTAL,
370 CLK_TOP_DMPLL
371};
372
373static const int ddrphycfg_parents[] = {
374 CLK_XTAL,
375 CLK_TOP_SYSPLL1_D8
376};
377
378static const int mm_parents[] = {
379 CLK_XTAL,
380 CLK_TOP_VENCPLL,
381 CLK_TOP_SYSPLL1_D2,
382 CLK_TOP_SYSPLL1_D4,
383 CLK_TOP_UNIVPLL_D5,
384 CLK_TOP_UNIVPLL1_D2,
385 CLK_TOP_UNIVPLL2_D2,
386 CLK_TOP_DMPLL
387};
388
389static const int pwm_parents[] = {
390 CLK_XTAL,
391 CLK_TOP_UNIVPLL2_D4,
392 CLK_TOP_UNIVPLL3_D2,
393 CLK_TOP_UNIVPLL1_D4
394};
395
396static const int vdec_parents[] = {
397 CLK_XTAL,
398 CLK_TOP_VDECPLL,
399 CLK_TOP_SYSPLL_D5,
400 CLK_TOP_SYSPLL1_D4,
401 CLK_TOP_UNIVPLL_D5,
402 CLK_TOP_UNIVPLL2_D2,
403 CLK_TOP_VENCPLL,
404 CLK_TOP_MSDCPLL_D2,
405 CLK_TOP_MMPLL_D2
406};
407
408static const int mfg_parents[] = {
409 CLK_XTAL,
410 CLK_TOP_MMPLL,
411 CLK_TOP_DMPLL_X2,
412 CLK_TOP_MSDCPLL,
413 CLK_XTAL,
414 CLK_TOP_SYSPLL_D3,
415 CLK_TOP_UNIVPLL_D3,
416 CLK_TOP_UNIVPLL1_D2
417};
418
419static const int camtg_parents[] = {
420 CLK_XTAL,
421 CLK_TOP_UNIVPLL_D26,
422 CLK_TOP_UNIVPLL2_D2,
423 CLK_TOP_SYSPLL3_D2,
424 CLK_TOP_SYSPLL3_D4,
425 CLK_TOP_MSDCPLL_D2,
426 CLK_TOP_MMPLL_D2
427};
428
429static const int uart_parents[] = {
430 CLK_XTAL,
431 CLK_TOP_UNIVPLL2_D8
432};
433
434static const int spi_parents[] = {
435 CLK_XTAL,
436 CLK_TOP_SYSPLL3_D2,
437 CLK_TOP_SYSPLL4_D2,
438 CLK_TOP_UNIVPLL2_D4,
439 CLK_TOP_UNIVPLL1_D8
440};
441
442static const int usb20_parents[] = {
443 CLK_XTAL,
444 CLK_TOP_UNIVPLL1_D8,
445 CLK_TOP_UNIVPLL3_D4
446};
447
448static const int msdc30_parents[] = {
449 CLK_XTAL,
450 CLK_TOP_MSDCPLL_D2,
451 CLK_TOP_SYSPLL2_D2,
452 CLK_TOP_SYSPLL1_D4,
453 CLK_TOP_UNIVPLL1_D4,
454 CLK_TOP_UNIVPLL2_D4,
455};
456
457static const int aud_intbus_parents[] = {
458 CLK_XTAL,
459 CLK_TOP_SYSPLL1_D4,
460 CLK_TOP_SYSPLL3_D2,
461 CLK_TOP_SYSPLL4_D2,
462 CLK_TOP_UNIVPLL3_D2,
463 CLK_TOP_UNIVPLL2_D4
464};
465
466static const int pmicspi_parents[] = {
467 CLK_XTAL,
468 CLK_TOP_SYSPLL1_D8,
469 CLK_TOP_SYSPLL2_D4,
470 CLK_TOP_SYSPLL4_D2,
471 CLK_TOP_SYSPLL3_D4,
472 CLK_TOP_SYSPLL2_D8,
473 CLK_TOP_SYSPLL1_D16,
474 CLK_TOP_UNIVPLL3_D4,
475 CLK_TOP_UNIVPLL_D26,
476 CLK_TOP_DMPLL_D2,
477 CLK_TOP_DMPLL_D4
478};
479
480static const int scp_parents[] = {
481 CLK_XTAL,
482 CLK_TOP_SYSPLL1_D8,
483 CLK_TOP_DMPLL_D2,
484 CLK_TOP_DMPLL_D4
485};
486
487static const int dpi0_tve_parents[] = {
488 CLK_XTAL,
489 CLK_TOP_MIPIPLL,
490 CLK_TOP_MIPIPLL_D2,
491 CLK_TOP_MIPIPLL_D4,
492 CLK_XTAL,
493 CLK_TOP_TVDPLL,
494 CLK_TOP_TVDPLL_D2,
495 CLK_TOP_TVDPLL_D4
496};
497
498static const int dpi1_parents[] = {
499 CLK_XTAL,
500 CLK_TOP_TVDPLL,
501 CLK_TOP_TVDPLL_D2,
502 CLK_TOP_TVDPLL_D4
503};
504
505static const int hdmi_parents[] = {
506 CLK_XTAL,
507 CLK_TOP_HDMIPLL,
508 CLK_TOP_HDMIPLL_D2,
509 CLK_TOP_HDMIPLL_D3
510};
511
512static const int apll_parents[] = {
513 CLK_XTAL,
514 CLK_TOP_AUDPLL,
515 CLK_TOP_AUDPLL_D4,
516 CLK_TOP_AUDPLL_D8,
517 CLK_TOP_AUDPLL_D16,
518 CLK_TOP_AUDPLL_D24,
519 CLK_XTAL,
520 CLK_XTAL
521};
522
523static const int rtc_parents[] = {
524 CLK_TOP_32K_INTERNAL,
525 CLK_TOP_32K_EXTERNAL,
526 CLK_XTAL,
527 CLK_TOP_UNIVPLL3_D8
528};
529
530static const int nfi2x_parents[] = {
531 CLK_XTAL,
532 CLK_TOP_SYSPLL2_D2,
533 CLK_TOP_SYSPLL_D7,
534 CLK_TOP_UNIVPLL3_D2,
535 CLK_TOP_SYSPLL2_D4,
536 CLK_TOP_UNIVPLL3_D4,
537 CLK_TOP_SYSPLL4_D4,
538 CLK_XTAL
539};
540
541static const int emmc_hclk_parents[] = {
542 CLK_XTAL,
543 CLK_TOP_SYSPLL1_D2,
544 CLK_TOP_SYSPLL1_D4,
545 CLK_TOP_SYSPLL2_D2
546};
547
548static const int flash_parents[] = {
549 CLK_TOP_CLK26M_D8,
550 CLK_XTAL,
551 CLK_TOP_SYSPLL2_D8,
552 CLK_TOP_SYSPLL3_D4,
553 CLK_TOP_UNIVPLL3_D4,
554 CLK_TOP_SYSPLL4_D2,
555 CLK_TOP_SYSPLL2_D4,
556 CLK_TOP_UNIVPLL2_D4
557};
558
559static const int di_parents[] = {
560 CLK_XTAL,
561 CLK_TOP_TVD2PLL,
562 CLK_TOP_TVD2PLL_D2,
563 CLK_XTAL
564};
565
566static const int nr_osd_parents[] = {
567 CLK_XTAL,
568 CLK_TOP_VENCPLL,
569 CLK_TOP_SYSPLL1_D2,
570 CLK_TOP_SYSPLL1_D4,
571 CLK_TOP_UNIVPLL_D5,
572 CLK_TOP_UNIVPLL1_D2,
573 CLK_TOP_UNIVPLL2_D2,
574 CLK_TOP_DMPLL
575};
576
577static const int hdmirx_bist_parents[] = {
578 CLK_XTAL,
579 CLK_TOP_SYSPLL_D3,
580 CLK_XTAL,
581 CLK_TOP_SYSPLL1_D16,
582 CLK_TOP_SYSPLL4_D2,
583 CLK_TOP_SYSPLL1_D4,
584 CLK_TOP_VENCPLL,
585 CLK_XTAL
586};
587
588static const int intdir_parents[] = {
589 CLK_XTAL,
590 CLK_TOP_MMPLL,
591 CLK_TOP_SYSPLL_D2,
592 CLK_TOP_UNIVPLL_D2
593};
594
595static const int asm_parents[] = {
596 CLK_XTAL,
597 CLK_TOP_UNIVPLL2_D4,
598 CLK_TOP_UNIVPLL2_D2,
599 CLK_TOP_SYSPLL_D5
600};
601
602static const int ms_card_parents[] = {
603 CLK_XTAL,
604 CLK_TOP_UNIVPLL3_D8,
605 CLK_TOP_SYSPLL4_D4
606};
607
608static const int ethif_parents[] = {
609 CLK_XTAL,
610 CLK_TOP_SYSPLL1_D2,
611 CLK_TOP_SYSPLL_D5,
612 CLK_TOP_SYSPLL1_D4,
613 CLK_TOP_UNIVPLL_D5,
614 CLK_TOP_UNIVPLL1_D2,
615 CLK_TOP_DMPLL,
616 CLK_TOP_DMPLL_D2
617};
618
619static const int hdmirx_parents[] = {
620 CLK_XTAL,
621 CLK_TOP_UNIVPLL_D52
622};
623
624static const int cmsys_parents[] = {
625 CLK_XTAL,
626 CLK_TOP_SYSPLL1_D2,
627 CLK_TOP_UNIVPLL1_D2,
628 CLK_TOP_UNIVPLL_D5,
629 CLK_TOP_SYSPLL_D5,
630 CLK_TOP_SYSPLL2_D2,
631 CLK_TOP_SYSPLL1_D4,
632 CLK_TOP_SYSPLL3_D2,
633 CLK_TOP_SYSPLL2_D4,
634 CLK_TOP_SYSPLL1_D8,
635 CLK_XTAL,
636 CLK_XTAL,
637 CLK_XTAL,
638 CLK_XTAL,
639 CLK_XTAL
640};
641
642static const int clk_8bdac_parents[] = {
643 CLK_TOP_32K_INTERNAL,
644 CLK_TOP_8BDAC,
645 CLK_XTAL,
646 CLK_XTAL
647};
648
649static const int aud2dvd_parents[] = {
650 CLK_TOP_AUD_48K_TIMING,
651 CLK_TOP_AUD_44K_TIMING
652};
653
654static const int padmclk_parents[] = {
655 CLK_XTAL,
656 CLK_TOP_UNIVPLL_D26,
657 CLK_TOP_UNIVPLL_D52,
658 CLK_TOP_UNIVPLL_D108,
659 CLK_TOP_UNIVPLL2_D8,
660 CLK_TOP_UNIVPLL2_D16,
661 CLK_TOP_UNIVPLL2_D32
662};
663
664static const int aud_mux_parents[] = {
665 CLK_XTAL,
666 CLK_TOP_AUD1PLL_98M,
667 CLK_TOP_AUD2PLL_90M,
668 CLK_TOP_HADDS2PLL_98M,
669 CLK_TOP_AUD_EXTCK1_DIV,
670 CLK_TOP_AUD_EXTCK2_DIV
671};
672
673static const int aud_src_parents[] = {
674 CLK_TOP_AUD_MUX1_SEL,
675 CLK_TOP_AUD_MUX2_SEL
676};
677
678static const struct mtk_composite top_muxes[] = {
679 MUX_GATE(CLK_TOP_AXI_SEL, axi_parents, 0x40, 0, 3, 7),
680 MUX_GATE(CLK_TOP_MEM_SEL, mem_parents, 0x40, 8, 1, 15),
681 MUX_GATE(CLK_TOP_DDRPHYCFG_SEL, ddrphycfg_parents, 0x40, 16, 1, 23),
682 MUX_GATE_FLAGS(CLK_TOP_MM_SEL, mm_parents, 0x40, 24, 3, 31,
683 CLK_DOMAIN_SCPSYS),
684
685 MUX_GATE(CLK_TOP_PWM_SEL, pwm_parents, 0x50, 0, 2, 7),
686 MUX_GATE(CLK_TOP_VDEC_SEL, vdec_parents, 0x50, 8, 4, 15),
687 MUX_GATE_FLAGS(CLK_TOP_MFG_SEL, mfg_parents, 0x50, 16, 3, 23,
688 CLK_DOMAIN_SCPSYS),
689 MUX_GATE(CLK_TOP_CAMTG_SEL, camtg_parents, 0x50, 24, 3, 31),
690
691 MUX_GATE(CLK_TOP_UART_SEL, uart_parents, 0x60, 0, 1, 7),
692 MUX_GATE(CLK_TOP_SPI0_SEL, spi_parents, 0x60, 8, 3, 15),
693 MUX_GATE(CLK_TOP_USB20_SEL, usb20_parents, 0x60, 16, 2, 23),
694 MUX_GATE(CLK_TOP_MSDC30_0_SEL, msdc30_parents, 0x60, 24, 3, 31),
695
696 MUX_GATE(CLK_TOP_MSDC30_1_SEL, msdc30_parents, 0x70, 0, 3, 7),
697 MUX_GATE(CLK_TOP_MSDC30_2_SEL, msdc30_parents, 0x70, 8, 3, 15),
698 MUX_GATE(CLK_TOP_AUDIO_SEL, msdc30_parents, 0x70, 16, 1, 23),
699 MUX_GATE(CLK_TOP_AUDINTBUS_SEL, aud_intbus_parents, 0x70, 24, 3, 31),
700
701 MUX_GATE(CLK_TOP_PMICSPI_SEL, pmicspi_parents, 0x80, 0, 4, 7),
702 MUX_GATE(CLK_TOP_SCP_SEL, scp_parents, 0x80, 8, 2, 15),
703 MUX_GATE(CLK_TOP_DPI0_SEL, dpi0_tve_parents, 0x80, 16, 3, 23),
704 MUX_GATE(CLK_TOP_DPI1_SEL, dpi1_parents, 0x80, 24, 2, 31),
705
706 MUX_GATE(CLK_TOP_TVE_SEL, dpi0_tve_parents, 0x90, 0, 3, 7),
707 MUX_GATE(CLK_TOP_HDMI_SEL, hdmi_parents, 0x90, 8, 2, 15),
708 MUX_GATE(CLK_TOP_APLL_SEL, apll_parents, 0x90, 16, 3, 23),
709
710 MUX_GATE(CLK_TOP_RTC_SEL, rtc_parents, 0xA0, 0, 2, 7),
711 MUX_GATE(CLK_TOP_NFI2X_SEL, nfi2x_parents, 0xA0, 8, 3, 15),
712 MUX_GATE(CLK_TOP_EMMC_HCLK_SEL, emmc_hclk_parents, 0xA0, 24, 2, 31),
713
714 MUX_GATE(CLK_TOP_FLASH_SEL, flash_parents, 0xB0, 0, 3, 7),
715 MUX_GATE(CLK_TOP_DI_SEL, di_parents, 0xB0, 8, 2, 15),
716 MUX_GATE(CLK_TOP_NR_SEL, nr_osd_parents, 0xB0, 16, 3, 23),
717 MUX_GATE(CLK_TOP_OSD_SEL, nr_osd_parents, 0xB0, 24, 3, 31),
718
719 MUX_GATE(CLK_TOP_HDMIRX_BIST_SEL, hdmirx_bist_parents, 0xC0, 0, 3, 7),
720 MUX_GATE(CLK_TOP_INTDIR_SEL, intdir_parents, 0xC0, 8, 2, 15),
721 MUX_GATE(CLK_TOP_ASM_I_SEL, asm_parents, 0xC0, 16, 2, 23),
722 MUX_GATE(CLK_TOP_ASM_M_SEL, asm_parents, 0xC0, 24, 3, 31),
723
724 MUX_GATE(CLK_TOP_ASM_H_SEL, asm_parents, 0xD0, 0, 2, 7),
725 MUX_GATE(CLK_TOP_MS_CARD_SEL, ms_card_parents, 0xD0, 16, 2, 23),
726 MUX_GATE_FLAGS(CLK_TOP_ETHIF_SEL, ethif_parents, 0xD0, 24, 3, 31,
727 CLK_DOMAIN_SCPSYS),
728
729 MUX_GATE(CLK_TOP_HDMIRX26_24_SEL, hdmirx_parents, 0xE0, 0, 1, 7),
730 MUX_GATE(CLK_TOP_MSDC30_3_SEL, msdc30_parents, 0xE0, 8, 3, 15),
731 MUX_GATE(CLK_TOP_CMSYS_SEL, cmsys_parents, 0xE0, 16, 4, 23),
732
733 MUX_GATE(CLK_TOP_SPI1_SEL, spi_parents, 0xE0, 24, 3, 31),
734 MUX_GATE(CLK_TOP_SPI2_SEL, spi_parents, 0xF0, 0, 3, 7),
735 MUX_GATE(CLK_TOP_8BDAC_SEL, clk_8bdac_parents, 0xF0, 8, 2, 15),
736 MUX_GATE(CLK_TOP_AUD2DVD_SEL, aud2dvd_parents, 0xF0, 16, 1, 23),
737
738 MUX(CLK_TOP_PADMCLK_SEL, padmclk_parents, 0x100, 0, 3),
739
740 MUX(CLK_TOP_AUD_MUX1_SEL, aud_mux_parents, 0x12c, 0, 3),
741 MUX(CLK_TOP_AUD_MUX2_SEL, aud_mux_parents, 0x12c, 3, 3),
742 MUX(CLK_TOP_AUDPLL_MUX_SEL, aud_mux_parents, 0x12c, 6, 3),
743
744 MUX_GATE(CLK_TOP_AUD_K1_SRC_SEL, aud_src_parents, 0x12c, 15, 1, 23),
745 MUX_GATE(CLK_TOP_AUD_K2_SRC_SEL, aud_src_parents, 0x12c, 16, 1, 24),
746 MUX_GATE(CLK_TOP_AUD_K3_SRC_SEL, aud_src_parents, 0x12c, 17, 1, 25),
747 MUX_GATE(CLK_TOP_AUD_K4_SRC_SEL, aud_src_parents, 0x12c, 18, 1, 26),
748 MUX_GATE(CLK_TOP_AUD_K5_SRC_SEL, aud_src_parents, 0x12c, 19, 1, 27),
749 MUX_GATE(CLK_TOP_AUD_K6_SRC_SEL, aud_src_parents, 0x12c, 20, 1, 28),
750};
751
752/* infracfg */
753static const struct mtk_gate_regs infra_cg_regs = {
754 .set_ofs = 0x40,
755 .clr_ofs = 0x44,
756 .sta_ofs = 0x48,
757};
758
Christian Marangi87b96c32024-08-02 15:45:01 +0200759#define GATE_INFRA_FLAGS(_id, _parent, _shift, _flags) { \
developerd1b1ffa2018-11-15 10:07:55 +0800760 .id = _id, \
761 .parent = _parent, \
762 .regs = &infra_cg_regs, \
763 .shift = _shift, \
Christian Marangi87b96c32024-08-02 15:45:01 +0200764 .flags = _flags, \
developerd1b1ffa2018-11-15 10:07:55 +0800765 }
Christian Marangi87b96c32024-08-02 15:45:01 +0200766#define GATE_INFRA(_id, _parent, _shift) \
767 GATE_INFRA_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
768#define GATE_INFRA_XTAL(_id, _parent, _shift) \
769 GATE_INFRA_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
770
developerd1b1ffa2018-11-15 10:07:55 +0800771
772static const struct mtk_gate infra_cgs[] = {
773 GATE_INFRA(CLK_INFRA_DBG, CLK_TOP_AXI_SEL, 0),
774 GATE_INFRA(CLK_INFRA_SMI, CLK_TOP_MM_SEL, 1),
775 GATE_INFRA(CLK_INFRA_QAXI_CM4, CLK_TOP_AXI_SEL, 2),
776 GATE_INFRA(CLK_INFRA_AUD_SPLIN_B, CLK_TOP_HADDS2PLL_294M, 4),
Christian Marangi87b96c32024-08-02 15:45:01 +0200777 GATE_INFRA_XTAL(CLK_INFRA_AUDIO, CLK_XTAL, 5),
778 GATE_INFRA_XTAL(CLK_INFRA_EFUSE, CLK_XTAL, 6),
developerd1b1ffa2018-11-15 10:07:55 +0800779 GATE_INFRA(CLK_INFRA_L2C_SRAM, CLK_TOP_MM_SEL, 7),
780 GATE_INFRA(CLK_INFRA_M4U, CLK_TOP_MEM_SEL, 8),
781 GATE_INFRA(CLK_INFRA_CONNMCU, CLK_TOP_WBG_DIG_416M, 12),
782 GATE_INFRA(CLK_INFRA_TRNG, CLK_TOP_AXI_SEL, 13),
783 GATE_INFRA(CLK_INFRA_RAMBUFIF, CLK_TOP_MEM_SEL, 14),
784 GATE_INFRA(CLK_INFRA_CPUM, CLK_TOP_MEM_SEL, 15),
785 GATE_INFRA(CLK_INFRA_KP, CLK_TOP_AXI_SEL, 16),
786 GATE_INFRA(CLK_INFRA_CEC, CLK_TOP_RTC_SEL, 18),
787 GATE_INFRA(CLK_INFRA_IRRX, CLK_TOP_AXI_SEL, 19),
788 GATE_INFRA(CLK_INFRA_PMICSPI, CLK_TOP_PMICSPI_SEL, 22),
789 GATE_INFRA(CLK_INFRA_PMICWRAP, CLK_TOP_AXI_SEL, 23),
790 GATE_INFRA(CLK_INFRA_DDCCI, CLK_TOP_AXI_SEL, 24),
791};
792
793/* pericfg */
794static const struct mtk_gate_regs peri0_cg_regs = {
795 .set_ofs = 0x8,
796 .clr_ofs = 0x10,
797 .sta_ofs = 0x18,
798};
799
800static const struct mtk_gate_regs peri1_cg_regs = {
801 .set_ofs = 0xC,
802 .clr_ofs = 0x14,
803 .sta_ofs = 0x1C,
804};
805
Christian Marangi87b96c32024-08-02 15:45:01 +0200806#define GATE_PERI0_FLAGS(_id, _parent, _shift, _flags) { \
developerd1b1ffa2018-11-15 10:07:55 +0800807 .id = _id, \
808 .parent = _parent, \
809 .regs = &peri0_cg_regs, \
810 .shift = _shift, \
Christian Marangi87b96c32024-08-02 15:45:01 +0200811 .flags = _flags, \
developerd1b1ffa2018-11-15 10:07:55 +0800812 }
Christian Marangi87b96c32024-08-02 15:45:01 +0200813#define GATE_PERI0(_id, _parent, _shift) \
814 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
815#define GATE_PERI0_XTAL(_id, _parent, _shift) \
816 GATE_PERI0_FLAGS(_id, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_XTAL)
developerd1b1ffa2018-11-15 10:07:55 +0800817
818#define GATE_PERI1(_id, _parent, _shift) { \
819 .id = _id, \
820 .parent = _parent, \
821 .regs = &peri1_cg_regs, \
822 .shift = _shift, \
823 .flags = CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN, \
824 }
825
826static const struct mtk_gate peri_cgs[] = {
827 GATE_PERI0(CLK_PERI_NFI, CLK_TOP_NFI2X_SEL, 0),
828 GATE_PERI0(CLK_PERI_THERM, CLK_TOP_AXI_SEL, 1),
829 GATE_PERI0(CLK_PERI_PWM1, CLK_TOP_AXISEL_D4, 2),
830 GATE_PERI0(CLK_PERI_PWM2, CLK_TOP_AXISEL_D4, 3),
831 GATE_PERI0(CLK_PERI_PWM3, CLK_TOP_AXISEL_D4, 4),
832 GATE_PERI0(CLK_PERI_PWM4, CLK_TOP_AXISEL_D4, 5),
833 GATE_PERI0(CLK_PERI_PWM5, CLK_TOP_AXISEL_D4, 6),
834 GATE_PERI0(CLK_PERI_PWM6, CLK_TOP_AXISEL_D4, 7),
835 GATE_PERI0(CLK_PERI_PWM7, CLK_TOP_AXISEL_D4, 8),
836 GATE_PERI0(CLK_PERI_PWM, CLK_TOP_AXI_SEL, 9),
837 GATE_PERI0(CLK_PERI_USB0, CLK_TOP_USB20_SEL, 10),
838 GATE_PERI0(CLK_PERI_USB1, CLK_TOP_USB20_SEL, 11),
839 GATE_PERI0(CLK_PERI_AP_DMA, CLK_TOP_AXI_SEL, 12),
840 GATE_PERI0(CLK_PERI_MSDC30_0, CLK_TOP_MSDC30_0_SEL, 13),
841 GATE_PERI0(CLK_PERI_MSDC30_1, CLK_TOP_MSDC30_1_SEL, 14),
842 GATE_PERI0(CLK_PERI_MSDC30_2, CLK_TOP_MSDC30_2_SEL, 15),
843 GATE_PERI0(CLK_PERI_MSDC30_3, CLK_TOP_MSDC30_3_SEL, 16),
844 GATE_PERI0(CLK_PERI_MSDC50_3, CLK_TOP_EMMC_HCLK_SEL, 17),
845 GATE_PERI0(CLK_PERI_NLI, CLK_TOP_AXI_SEL, 18),
846 GATE_PERI0(CLK_PERI_UART0, CLK_TOP_AXI_SEL, 19),
847 GATE_PERI0(CLK_PERI_UART1, CLK_TOP_AXI_SEL, 20),
848 GATE_PERI0(CLK_PERI_UART2, CLK_TOP_AXI_SEL, 21),
849 GATE_PERI0(CLK_PERI_UART3, CLK_TOP_AXI_SEL, 22),
850 GATE_PERI0(CLK_PERI_BTIF, CLK_TOP_AXI_SEL, 23),
851 GATE_PERI0(CLK_PERI_I2C0, CLK_TOP_AXI_SEL, 24),
852 GATE_PERI0(CLK_PERI_I2C1, CLK_TOP_AXI_SEL, 25),
853 GATE_PERI0(CLK_PERI_I2C2, CLK_TOP_AXI_SEL, 26),
Christian Marangi87b96c32024-08-02 15:45:01 +0200854 GATE_PERI0_XTAL(CLK_PERI_I2C3, CLK_XTAL, 27),
855 GATE_PERI0_XTAL(CLK_PERI_AUXADC, CLK_XTAL, 28),
developerd1b1ffa2018-11-15 10:07:55 +0800856 GATE_PERI0(CLK_PERI_SPI0, CLK_TOP_SPI0_SEL, 29),
Christian Marangi87b96c32024-08-02 15:45:01 +0200857 GATE_PERI0_XTAL(CLK_PERI_ETH, CLK_XTAL, 30),
developerd1b1ffa2018-11-15 10:07:55 +0800858 GATE_PERI0(CLK_PERI_USB0_MCU, CLK_TOP_AXI_SEL, 31),
859
860 GATE_PERI1(CLK_PERI_USB1_MCU, CLK_TOP_AXI_SEL, 0),
861 GATE_PERI1(CLK_PERI_USB_SLV, CLK_TOP_AXI_SEL, 1),
862 GATE_PERI1(CLK_PERI_GCPU, CLK_TOP_AXI_SEL, 2),
863 GATE_PERI1(CLK_PERI_NFI_ECC, CLK_TOP_NFI1X_PAD, 3),
864 GATE_PERI1(CLK_PERI_NFI_PAD, CLK_TOP_NFI1X_PAD, 4),
865 GATE_PERI1(CLK_PERI_FLASH, CLK_TOP_NFI2X_SEL, 5),
866 GATE_PERI1(CLK_PERI_HOST89_INT, CLK_TOP_AXI_SEL, 6),
867 GATE_PERI1(CLK_PERI_HOST89_SPI, CLK_TOP_SPI0_SEL, 7),
868 GATE_PERI1(CLK_PERI_HOST89_DVD, CLK_TOP_AUD2DVD_SEL, 8),
869 GATE_PERI1(CLK_PERI_SPI1, CLK_TOP_SPI1_SEL, 9),
870 GATE_PERI1(CLK_PERI_SPI2, CLK_TOP_SPI2_SEL, 10),
871 GATE_PERI1(CLK_PERI_FCI, CLK_TOP_MS_CARD_SEL, 11),
872};
873
developera588d152019-07-29 22:17:48 +0800874/* ethsys and hifsys */
875static const struct mtk_gate_regs eth_hif_cg_regs = {
developerd1b1ffa2018-11-15 10:07:55 +0800876 .sta_ofs = 0x30,
877};
878
developera588d152019-07-29 22:17:48 +0800879#define GATE_ETH_HIF(_id, _parent, _shift, _flag) { \
developerd1b1ffa2018-11-15 10:07:55 +0800880 .id = _id, \
881 .parent = _parent, \
developera588d152019-07-29 22:17:48 +0800882 .regs = &eth_hif_cg_regs, \
developerd1b1ffa2018-11-15 10:07:55 +0800883 .shift = _shift, \
884 .flags = CLK_GATE_NO_SETCLR_INV | (_flag), \
885 }
886
developera588d152019-07-29 22:17:48 +0800887#define GATE_ETH_HIF0(_id, _parent, _shift) \
888 GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_APMIXED)
developerd1b1ffa2018-11-15 10:07:55 +0800889
developera588d152019-07-29 22:17:48 +0800890#define GATE_ETH_HIF1(_id, _parent, _shift) \
891 GATE_ETH_HIF(_id, _parent, _shift, CLK_PARENT_TOPCKGEN)
developerd1b1ffa2018-11-15 10:07:55 +0800892
893static const struct mtk_gate eth_cgs[] = {
developera588d152019-07-29 22:17:48 +0800894 GATE_ETH_HIF1(CLK_ETHSYS_HSDMA, CLK_TOP_ETHIF_SEL, 5),
895 GATE_ETH_HIF1(CLK_ETHSYS_ESW, CLK_TOP_ETHPLL_500M, 6),
896 GATE_ETH_HIF0(CLK_ETHSYS_GP2, CLK_APMIXED_TRGPLL, 7),
897 GATE_ETH_HIF1(CLK_ETHSYS_GP1, CLK_TOP_ETHPLL_500M, 8),
898 GATE_ETH_HIF1(CLK_ETHSYS_PCM, CLK_TOP_ETHIF_SEL, 11),
899 GATE_ETH_HIF1(CLK_ETHSYS_GDMA, CLK_TOP_ETHIF_SEL, 14),
900 GATE_ETH_HIF1(CLK_ETHSYS_I2S, CLK_TOP_ETHIF_SEL, 17),
901 GATE_ETH_HIF1(CLK_ETHSYS_CRYPTO, CLK_TOP_ETHIF_SEL, 29),
developerd1b1ffa2018-11-15 10:07:55 +0800902};
903
developera588d152019-07-29 22:17:48 +0800904static const struct mtk_gate hif_cgs[] = {
905 GATE_ETH_HIF1(CLK_HIFSYS_USB0PHY, CLK_TOP_ETHPLL_500M, 21),
906 GATE_ETH_HIF1(CLK_HIFSYS_USB1PHY, CLK_TOP_ETHPLL_500M, 22),
907 GATE_ETH_HIF1(CLK_HIFSYS_PCIE0, CLK_TOP_ETHPLL_500M, 24),
908 GATE_ETH_HIF1(CLK_HIFSYS_PCIE1, CLK_TOP_ETHPLL_500M, 25),
909 GATE_ETH_HIF1(CLK_HIFSYS_PCIE2, CLK_TOP_ETHPLL_500M, 26),
910};
911
Christian Marangi326ab202024-08-02 15:45:02 +0200912static const struct mtk_clk_tree mt7623_apmixedsys_clk_tree = {
developerd1b1ffa2018-11-15 10:07:55 +0800913 .xtal2_rate = 26 * MHZ,
Christian Marangi326ab202024-08-02 15:45:02 +0200914 .plls = apmixed_plls,
915};
916
917static const struct mtk_clk_tree mt7623_topckgen_clk_tree = {
918 .xtal_rate = 26 * MHZ,
Christian Marangie80ebc82024-08-02 15:45:03 +0200919 .id_offs_map = top_id_offs_map,
920 .fdivs_offs = top_id_offs_map[CLK_TOP_SYSPLL],
921 .muxes_offs = top_id_offs_map[CLK_TOP_AXI_SEL],
developerd1b1ffa2018-11-15 10:07:55 +0800922 .fclks = top_fixed_clks,
923 .fdivs = top_fixed_divs,
924 .muxes = top_muxes,
925};
926
927static int mt7623_mcucfg_probe(struct udevice *dev)
928{
929 void __iomem *base;
930
931 base = dev_read_addr_ptr(dev);
932 if (!base)
933 return -ENOENT;
934
935 clrsetbits_le32(base + MCU_AXI_DIV, AXI_DIV_MSK,
936 AXI_DIV_SEL(0x12));
937
938 return 0;
939}
940
941static int mt7623_apmixedsys_probe(struct udevice *dev)
942{
943 struct mtk_clk_priv *priv = dev_get_priv(dev);
944 int ret;
945
Christian Marangi326ab202024-08-02 15:45:02 +0200946 ret = mtk_common_clk_init(dev, &mt7623_apmixedsys_clk_tree);
developerd1b1ffa2018-11-15 10:07:55 +0800947 if (ret)
948 return ret;
949
950 /* reduce clock square disable time */
951 writel(0x50001, priv->base + MT7623_CLKSQ_STB_CON0);
952 /* extend control timing to 1us */
953 writel(0x888, priv->base + MT7623_PLL_ISO_CON0);
954
955 return 0;
956}
957
958static int mt7623_topckgen_probe(struct udevice *dev)
959{
Christian Marangi326ab202024-08-02 15:45:02 +0200960 return mtk_common_clk_init(dev, &mt7623_topckgen_clk_tree);
developerd1b1ffa2018-11-15 10:07:55 +0800961}
962
Christian Marangie80ebc82024-08-02 15:45:03 +0200963static const struct mtk_clk_tree mt7623_clk_gate_tree = {
964 /* Each CLK ID for gates clock starts at index 1 */
965 .gates_offs = 1,
966};
967
developerd1b1ffa2018-11-15 10:07:55 +0800968static int mt7623_infracfg_probe(struct udevice *dev)
969{
Christian Marangie80ebc82024-08-02 15:45:03 +0200970 return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
Christian Marangi326ab202024-08-02 15:45:02 +0200971 infra_cgs);
developerd1b1ffa2018-11-15 10:07:55 +0800972}
973
974static int mt7623_pericfg_probe(struct udevice *dev)
975{
Christian Marangie80ebc82024-08-02 15:45:03 +0200976 return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
Christian Marangi326ab202024-08-02 15:45:02 +0200977 peri_cgs);
developerd1b1ffa2018-11-15 10:07:55 +0800978}
979
developera588d152019-07-29 22:17:48 +0800980static int mt7623_hifsys_probe(struct udevice *dev)
981{
Christian Marangie80ebc82024-08-02 15:45:03 +0200982 return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
Christian Marangi326ab202024-08-02 15:45:02 +0200983 hif_cgs);
developera588d152019-07-29 22:17:48 +0800984}
985
developerd1b1ffa2018-11-15 10:07:55 +0800986static int mt7623_ethsys_probe(struct udevice *dev)
987{
Christian Marangie80ebc82024-08-02 15:45:03 +0200988 return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
Christian Marangi326ab202024-08-02 15:45:02 +0200989 eth_cgs);
developerd1b1ffa2018-11-15 10:07:55 +0800990}
991
developera588d152019-07-29 22:17:48 +0800992static int mt7623_ethsys_hifsys_bind(struct udevice *dev)
developer02259452018-12-20 16:12:52 +0800993{
994 int ret = 0;
995
996#if CONFIG_IS_ENABLED(RESET_MEDIATEK)
developera588d152019-07-29 22:17:48 +0800997 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
developer02259452018-12-20 16:12:52 +0800998 if (ret)
developera588d152019-07-29 22:17:48 +0800999 debug("Warning: failed to bind reset controller\n");
developer02259452018-12-20 16:12:52 +08001000#endif
1001
1002 return ret;
1003}
1004
developerd1b1ffa2018-11-15 10:07:55 +08001005static const struct udevice_id mt7623_apmixed_compat[] = {
1006 { .compatible = "mediatek,mt7623-apmixedsys" },
1007 { }
1008};
1009
1010static const struct udevice_id mt7623_topckgen_compat[] = {
1011 { .compatible = "mediatek,mt7623-topckgen" },
1012 { }
1013};
1014
1015static const struct udevice_id mt7623_infracfg_compat[] = {
1016 { .compatible = "mediatek,mt7623-infracfg", },
1017 { }
1018};
1019
1020static const struct udevice_id mt7623_pericfg_compat[] = {
1021 { .compatible = "mediatek,mt7623-pericfg", },
1022 { }
1023};
1024
1025static const struct udevice_id mt7623_ethsys_compat[] = {
1026 { .compatible = "mediatek,mt7623-ethsys" },
1027 { }
1028};
1029
developera588d152019-07-29 22:17:48 +08001030static const struct udevice_id mt7623_hifsys_compat[] = {
1031 { .compatible = "mediatek,mt7623-hifsys" },
1032 { }
1033};
1034
developerd1b1ffa2018-11-15 10:07:55 +08001035static const struct udevice_id mt7623_mcucfg_compat[] = {
1036 { .compatible = "mediatek,mt7623-mcucfg" },
1037 { }
1038};
1039
1040U_BOOT_DRIVER(mtk_mcucfg) = {
1041 .name = "mt7623-mcucfg",
1042 .id = UCLASS_SYSCON,
1043 .of_match = mt7623_mcucfg_compat,
1044 .probe = mt7623_mcucfg_probe,
1045 .flags = DM_FLAG_PRE_RELOC,
1046};
1047
1048U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
1049 .name = "mt7623-clock-apmixedsys",
1050 .id = UCLASS_CLK,
1051 .of_match = mt7623_apmixed_compat,
1052 .probe = mt7623_apmixedsys_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001053 .priv_auto = sizeof(struct mtk_clk_priv),
developerd1b1ffa2018-11-15 10:07:55 +08001054 .ops = &mtk_clk_apmixedsys_ops,
1055 .flags = DM_FLAG_PRE_RELOC,
1056};
1057
1058U_BOOT_DRIVER(mtk_clk_topckgen) = {
1059 .name = "mt7623-clock-topckgen",
1060 .id = UCLASS_CLK,
1061 .of_match = mt7623_topckgen_compat,
1062 .probe = mt7623_topckgen_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001063 .priv_auto = sizeof(struct mtk_clk_priv),
developerd1b1ffa2018-11-15 10:07:55 +08001064 .ops = &mtk_clk_topckgen_ops,
1065 .flags = DM_FLAG_PRE_RELOC,
1066};
1067
1068U_BOOT_DRIVER(mtk_clk_infracfg) = {
1069 .name = "mt7623-infracfg",
1070 .id = UCLASS_CLK,
1071 .of_match = mt7623_infracfg_compat,
1072 .probe = mt7623_infracfg_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001073 .priv_auto = sizeof(struct mtk_cg_priv),
developerd1b1ffa2018-11-15 10:07:55 +08001074 .ops = &mtk_clk_gate_ops,
1075 .flags = DM_FLAG_PRE_RELOC,
1076};
1077
1078U_BOOT_DRIVER(mtk_clk_pericfg) = {
1079 .name = "mt7623-pericfg",
1080 .id = UCLASS_CLK,
1081 .of_match = mt7623_pericfg_compat,
1082 .probe = mt7623_pericfg_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001083 .priv_auto = sizeof(struct mtk_cg_priv),
developerd1b1ffa2018-11-15 10:07:55 +08001084 .ops = &mtk_clk_gate_ops,
1085 .flags = DM_FLAG_PRE_RELOC,
1086};
1087
developera588d152019-07-29 22:17:48 +08001088U_BOOT_DRIVER(mtk_clk_hifsys) = {
1089 .name = "mt7623-clock-hifsys",
1090 .id = UCLASS_CLK,
1091 .of_match = mt7623_hifsys_compat,
1092 .probe = mt7623_hifsys_probe,
1093 .bind = mt7623_ethsys_hifsys_bind,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001094 .priv_auto = sizeof(struct mtk_cg_priv),
developera588d152019-07-29 22:17:48 +08001095 .ops = &mtk_clk_gate_ops,
1096};
1097
developerd1b1ffa2018-11-15 10:07:55 +08001098U_BOOT_DRIVER(mtk_clk_ethsys) = {
1099 .name = "mt7623-clock-ethsys",
1100 .id = UCLASS_CLK,
1101 .of_match = mt7623_ethsys_compat,
1102 .probe = mt7623_ethsys_probe,
developera588d152019-07-29 22:17:48 +08001103 .bind = mt7623_ethsys_hifsys_bind,
Simon Glass8a2b47f2020-12-03 16:55:17 -07001104 .priv_auto = sizeof(struct mtk_cg_priv),
developerd1b1ffa2018-11-15 10:07:55 +08001105 .ops = &mtk_clk_gate_ops,
1106};