blob: f1870ce3d60f1b52a0e48cf900370e9186c0db1a [file] [log] [blame]
developer37161fe2022-09-09 20:00:09 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * MediaTek clock driver for MT7986 SoC
4 *
5 * Copyright (C) 2022 MediaTek Inc.
6 * Author: Sam Shih <sam.shih@mediatek.com>
7 */
8
9#include <dm.h>
10#include <log.h>
11#include <asm/arch-mediatek/reset.h>
12#include <asm/io.h>
13#include <dt-bindings/clock/mt7986-clk.h>
14#include <linux/bitops.h>
15
16#include "clk-mtk.h"
17
18#define MT7986_CLK_PDN 0x250
19#define MT7986_CLK_PDN_EN_WRITE BIT(31)
20
21#define PLL_FACTOR(_id, _name, _parent, _mult, _div) \
22 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_APMIXED)
23
24#define TOP_FACTOR(_id, _name, _parent, _mult, _div) \
25 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_TOPCKGEN)
26
27#define INFRA_FACTOR(_id, _name, _parent, _mult, _div) \
28 FACTOR(_id, _parent, _mult, _div, CLK_PARENT_INFRASYS)
29
30/* FIXED PLLS */
31static const struct mtk_fixed_clk fixed_pll_clks[] = {
32 FIXED_CLK(CK_APMIXED_ARMPLL, CLK_XTAL, 2000000000),
33 FIXED_CLK(CK_APMIXED_NET2PLL, CLK_XTAL, 800000000),
34 FIXED_CLK(CK_APMIXED_MMPLL, CLK_XTAL, 1440000000),
35 FIXED_CLK(CK_APMIXED_SGMPLL, CLK_XTAL, 325000000),
36 FIXED_CLK(CK_APMIXED_WEDMCUPLL, CLK_XTAL, 760000000),
37 FIXED_CLK(CK_APMIXED_NET1PLL, CLK_XTAL, 2500000000),
38 FIXED_CLK(CK_APMIXED_MPLL, CLK_XTAL, 416000000),
39 FIXED_CLK(CK_APMIXED_APLL2, CLK_XTAL, 196608000),
40};
41
42/* TOPCKGEN FIXED CLK */
43static const struct mtk_fixed_clk top_fixed_clks[] = {
Christian Marangi0178c612024-08-03 10:40:35 +020044 FIXED_CLK(CK_TOP_XTAL, CLK_XTAL, 40000000),
developer37161fe2022-09-09 20:00:09 +080045};
46
47/* TOPCKGEN FIXED DIV */
48static const struct mtk_fixed_factor top_fixed_divs[] = {
49 PLL_FACTOR(CK_TOP_CB_M_416M, "cb_m_416m", CK_APMIXED_MPLL, 1, 1),
50 PLL_FACTOR(CK_TOP_CB_M_D2, "cb_m_d2", CK_APMIXED_MPLL, 1, 2),
51 PLL_FACTOR(CK_TOP_CB_M_D4, "cb_m_d4", CK_APMIXED_MPLL, 1, 4),
52 PLL_FACTOR(CK_TOP_CB_M_D8, "cb_m_d8", CK_APMIXED_MPLL, 1, 8),
53 PLL_FACTOR(CK_TOP_M_D8_D2, "m_d8_d2", CK_APMIXED_MPLL, 1, 16),
54 PLL_FACTOR(CK_TOP_M_D3_D2, "m_d3_d2", CK_APMIXED_MPLL, 1, 2),
55 PLL_FACTOR(CK_TOP_CB_MM_D2, "cb_mm_d2", CK_APMIXED_MMPLL, 1, 2),
56 PLL_FACTOR(CK_TOP_CB_MM_D4, "cb_mm_d4", CK_APMIXED_MMPLL, 1, 4),
57 PLL_FACTOR(CK_TOP_CB_MM_D8, "cb_mm_d8", CK_APMIXED_MMPLL, 1, 8),
58 PLL_FACTOR(CK_TOP_MM_D8_D2, "mm_d8_d2", CK_APMIXED_MMPLL, 1, 16),
59 PLL_FACTOR(CK_TOP_MM_D3_D8, "mm_d3_d8", CK_APMIXED_MMPLL, 1, 8),
60 PLL_FACTOR(CK_TOP_CB_U2_PHYD_CK, "cb_u2_phyd", CK_APMIXED_MMPLL, 1, 30),
61 PLL_FACTOR(CK_TOP_CB_APLL2_196M, "cb_apll2_196m", CK_APMIXED_APLL2, 1,
62 1),
63 PLL_FACTOR(CK_TOP_APLL2_D4, "apll2_d4", CK_APMIXED_APLL2, 1, 4),
64 PLL_FACTOR(CK_TOP_CB_NET1_D4, "cb_net1_d4", CK_APMIXED_NET1PLL, 1, 4),
65 PLL_FACTOR(CK_TOP_CB_NET1_D5, "cb_net1_d5", CK_APMIXED_NET1PLL, 1, 5),
66 PLL_FACTOR(CK_TOP_NET1_D5_D2, "net1_d5_d2", CK_APMIXED_NET1PLL, 1, 10),
67 PLL_FACTOR(CK_TOP_NET1_D5_D4, "net1_d5_d4", CK_APMIXED_NET1PLL, 1, 20),
68 PLL_FACTOR(CK_TOP_NET1_D8_D2, "net1_d8_d2", CK_APMIXED_NET1PLL, 1, 16),
69 PLL_FACTOR(CK_TOP_NET1_D8_D4, "net1_d8_d4", CK_APMIXED_NET1PLL, 1, 32),
70 PLL_FACTOR(CK_TOP_CB_NET2_800M, "cb_net2_800m", CK_APMIXED_NET2PLL, 1,
71 1),
72 PLL_FACTOR(CK_TOP_CB_NET2_D4, "cb_net2_d4", CK_APMIXED_NET2PLL, 1, 4),
73 PLL_FACTOR(CK_TOP_NET2_D4_D2, "net2_d4_d2", CK_APMIXED_NET2PLL, 1, 8),
74 PLL_FACTOR(CK_TOP_NET2_D3_D2, "net2_d3_d2", CK_APMIXED_NET2PLL, 1, 2),
75 PLL_FACTOR(CK_TOP_CB_WEDMCU_760M, "cb_wedmcu_760m",
76 CK_APMIXED_WEDMCUPLL, 1, 1),
77 PLL_FACTOR(CK_TOP_WEDMCU_D5_D2, "wedmcu_d5_d2", CK_APMIXED_WEDMCUPLL, 1,
78 10),
79 PLL_FACTOR(CK_TOP_CB_SGM_325M, "cb_sgm_325m", CK_APMIXED_SGMPLL, 1, 1),
Christian Marangi0178c612024-08-03 10:40:35 +020080 TOP_FACTOR(CK_TOP_XTAL_D2, "xtal_d2", CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +080081 1, 2),
Christian Marangi0178c612024-08-03 10:40:35 +020082 TOP_FACTOR(CK_TOP_CB_RTC_32K, "cb_rtc_32k", CK_TOP_XTAL, 1,
developer37161fe2022-09-09 20:00:09 +080083 1250),
Christian Marangi0178c612024-08-03 10:40:35 +020084 TOP_FACTOR(CK_TOP_CB_RTC_32P7K, "cb_rtc_32p7k", CK_TOP_XTAL, 1,
developer37161fe2022-09-09 20:00:09 +080085 1220),
86 TOP_FACTOR(CK_TOP_NFI1X, "nfi1x", CK_TOP_NFI1X_SEL, 1, 1),
Christian Marangi0178c612024-08-03 10:40:35 +020087 TOP_FACTOR(CK_TOP_USB_EQ_RX250M, "usb_eq_rx250m", CK_TOP_XTAL, 1,
developer37161fe2022-09-09 20:00:09 +080088 1),
Christian Marangi0178c612024-08-03 10:40:35 +020089 TOP_FACTOR(CK_TOP_USB_TX250M, "usb_tx250m", CK_TOP_XTAL, 1, 1),
90 TOP_FACTOR(CK_TOP_USB_LN0_CK, "usb_ln0", CK_TOP_XTAL, 1, 1),
91 TOP_FACTOR(CK_TOP_USB_CDR_CK, "usb_cdr", CK_TOP_XTAL, 1, 1),
developer37161fe2022-09-09 20:00:09 +080092 TOP_FACTOR(CK_TOP_SPINFI_BCK, "spinfi_bck", CK_TOP_SPINFI_SEL, 1, 1),
93 TOP_FACTOR(CK_TOP_I2C_BCK, "i2c_bck", CK_TOP_I2C_SEL, 1, 1),
94 TOP_FACTOR(CK_TOP_PEXTP_TL, "pextp_tl", CK_TOP_PEXTP_TL_SEL, 1, 1),
95 TOP_FACTOR(CK_TOP_EMMC_250M, "emmc_250m", CK_TOP_EMMC_250M_SEL, 1, 1),
96 TOP_FACTOR(CK_TOP_EMMC_416M, "emmc_416m", CK_TOP_EMMC_416M_SEL, 1, 1),
97 TOP_FACTOR(CK_TOP_F_26M_ADC_CK, "f_26m_adc", CK_TOP_F_26M_ADC_SEL, 1,
98 1),
99 TOP_FACTOR(CK_TOP_SYSAXI, "sysaxi", CK_TOP_SYSAXI_SEL, 1, 1),
100 TOP_FACTOR(CK_TOP_NETSYS_WED_MCU, "netsys_wed_mcu",
101 CK_TOP_NETSYS_MCU_SEL, 1, 1),
102 TOP_FACTOR(CK_TOP_NETSYS_2X, "netsys_2x", CK_TOP_NETSYS_2X_SEL, 1, 1),
103 TOP_FACTOR(CK_TOP_SGM_325M, "sgm_325m", CK_TOP_SGM_325M_SEL, 1, 1),
104 TOP_FACTOR(CK_TOP_A1SYS, "a1sys", CK_TOP_A1SYS_SEL, 1, 1),
105 TOP_FACTOR(CK_TOP_EIP_B, "eip_b", CK_TOP_EIP_B_SEL, 1, 1),
106 TOP_FACTOR(CK_TOP_F26M, "csw_f26m", CK_TOP_F26M_SEL, 1, 1),
107 TOP_FACTOR(CK_TOP_AUD_L, "aud_l", CK_TOP_AUD_L_SEL, 1, 1),
108 TOP_FACTOR(CK_TOP_A_TUNER, "a_tuner", CK_TOP_A_TUNER_SEL, 2, 1),
109 TOP_FACTOR(CK_TOP_U2U3_REF, "u2u3_ref", CK_TOP_U2U3_SEL, 1, 1),
110 TOP_FACTOR(CK_TOP_U2U3_SYS, "u2u3_sys", CK_TOP_U2U3_SYS_SEL, 1, 1),
111 TOP_FACTOR(CK_TOP_U2U3_XHCI, "u2u3_xhci", CK_TOP_U2U3_XHCI_SEL, 1, 1),
112 TOP_FACTOR(CK_TOP_AP2CNN_HOST, "ap2cnn_host", CK_TOP_AP2CNN_HOST_SEL, 1,
113 1),
114};
115
116/* TOPCKGEN MUX PARENTS */
Christian Marangi0178c612024-08-03 10:40:35 +0200117static const int nfi1x_parents[] = { CK_TOP_XTAL, CK_TOP_CB_MM_D8,
developer37161fe2022-09-09 20:00:09 +0800118 CK_TOP_NET1_D8_D2, CK_TOP_NET2_D3_D2,
119 CK_TOP_CB_M_D4, CK_TOP_MM_D8_D2,
120 CK_TOP_WEDMCU_D5_D2, CK_TOP_CB_M_D8 };
121
122static const int spinfi_parents[] = {
Christian Marangi0178c612024-08-03 10:40:35 +0200123 CK_TOP_XTAL_D2, CK_TOP_XTAL, CK_TOP_NET1_D5_D4,
developer37161fe2022-09-09 20:00:09 +0800124 CK_TOP_CB_M_D4, CK_TOP_MM_D8_D2, CK_TOP_WEDMCU_D5_D2,
125 CK_TOP_MM_D3_D8, CK_TOP_CB_M_D8
126};
127
Christian Marangi0178c612024-08-03 10:40:35 +0200128static const int spi_parents[] = { CK_TOP_XTAL, CK_TOP_CB_M_D2,
developer37161fe2022-09-09 20:00:09 +0800129 CK_TOP_CB_MM_D8, CK_TOP_NET1_D8_D2,
130 CK_TOP_NET2_D3_D2, CK_TOP_NET1_D5_D4,
131 CK_TOP_CB_M_D4, CK_TOP_WEDMCU_D5_D2 };
132
Christian Marangi0178c612024-08-03 10:40:35 +0200133static const int uart_parents[] = { CK_TOP_XTAL, CK_TOP_CB_M_D8,
developer37161fe2022-09-09 20:00:09 +0800134 CK_TOP_M_D8_D2 };
135
Christian Marangi0178c612024-08-03 10:40:35 +0200136static const int pwm_parents[] = { CK_TOP_XTAL, CK_TOP_NET1_D8_D2,
developer37161fe2022-09-09 20:00:09 +0800137 CK_TOP_NET1_D5_D4, CK_TOP_CB_M_D4 };
138
Christian Marangi0178c612024-08-03 10:40:35 +0200139static const int i2c_parents[] = { CK_TOP_XTAL, CK_TOP_NET1_D5_D4,
developer37161fe2022-09-09 20:00:09 +0800140 CK_TOP_CB_M_D4, CK_TOP_NET1_D8_D4 };
141
Christian Marangi0178c612024-08-03 10:40:35 +0200142static const int pextp_tl_ck_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800143 CK_TOP_NET1_D5_D4, CK_TOP_NET2_D4_D2,
144 CK_TOP_CB_RTC_32K };
145
Christian Marangi0178c612024-08-03 10:40:35 +0200146static const int emmc_250m_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800147 CK_TOP_NET1_D5_D2 };
148
Christian Marangi0178c612024-08-03 10:40:35 +0200149static const int emmc_416m_parents[] = { CK_TOP_XTAL, CK_TOP_CB_M_416M };
developer37161fe2022-09-09 20:00:09 +0800150
Christian Marangi0178c612024-08-03 10:40:35 +0200151static const int f_26m_adc_parents[] = { CK_TOP_XTAL, CK_TOP_M_D8_D2 };
developer37161fe2022-09-09 20:00:09 +0800152
Christian Marangi0178c612024-08-03 10:40:35 +0200153static const int dramc_md32_parents[] = { CK_TOP_XTAL, CK_TOP_CB_M_D2 };
developer37161fe2022-09-09 20:00:09 +0800154
Christian Marangi0178c612024-08-03 10:40:35 +0200155static const int sysaxi_parents[] = { CK_TOP_XTAL, CK_TOP_NET1_D8_D2,
developer37161fe2022-09-09 20:00:09 +0800156 CK_TOP_CB_NET2_D4 };
157
Christian Marangi0178c612024-08-03 10:40:35 +0200158static const int sysapb_parents[] = { CK_TOP_XTAL, CK_TOP_M_D3_D2,
developer37161fe2022-09-09 20:00:09 +0800159 CK_TOP_NET2_D4_D2 };
160
Christian Marangi0178c612024-08-03 10:40:35 +0200161static const int arm_db_main_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800162 CK_TOP_NET2_D3_D2 };
163
Christian Marangi0178c612024-08-03 10:40:35 +0200164static const int arm_db_jtsel_parents[] = { -1, CK_TOP_XTAL };
developer37161fe2022-09-09 20:00:09 +0800165
Christian Marangi0178c612024-08-03 10:40:35 +0200166static const int netsys_parents[] = { CK_TOP_XTAL, CK_TOP_CB_MM_D4 };
developer37161fe2022-09-09 20:00:09 +0800167
Christian Marangi0178c612024-08-03 10:40:35 +0200168static const int netsys_500m_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800169 CK_TOP_CB_NET1_D5 };
170
Christian Marangi0178c612024-08-03 10:40:35 +0200171static const int netsys_mcu_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800172 CK_TOP_CB_WEDMCU_760M,
173 CK_TOP_CB_MM_D2, CK_TOP_CB_NET1_D4,
174 CK_TOP_CB_NET1_D5 };
175
Christian Marangi0178c612024-08-03 10:40:35 +0200176static const int netsys_2x_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800177 CK_TOP_CB_NET2_800M,
178 CK_TOP_CB_WEDMCU_760M,
179 CK_TOP_CB_MM_D2 };
180
Christian Marangi0178c612024-08-03 10:40:35 +0200181static const int sgm_325m_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800182 CK_TOP_CB_SGM_325M };
183
Christian Marangi0178c612024-08-03 10:40:35 +0200184static const int sgm_reg_parents[] = { CK_TOP_XTAL, CK_TOP_NET1_D8_D4 };
developer37161fe2022-09-09 20:00:09 +0800185
Christian Marangi0178c612024-08-03 10:40:35 +0200186static const int a1sys_parents[] = { CK_TOP_XTAL, CK_TOP_APLL2_D4 };
developer37161fe2022-09-09 20:00:09 +0800187
Christian Marangi0178c612024-08-03 10:40:35 +0200188static const int conn_mcusys_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800189 CK_TOP_CB_MM_D2 };
190
Christian Marangi0178c612024-08-03 10:40:35 +0200191static const int eip_b_parents[] = { CK_TOP_XTAL, CK_TOP_CB_NET2_800M };
developer37161fe2022-09-09 20:00:09 +0800192
Christian Marangi0178c612024-08-03 10:40:35 +0200193static const int aud_l_parents[] = { CK_TOP_XTAL, CK_TOP_CB_APLL2_196M,
developer37161fe2022-09-09 20:00:09 +0800194 CK_TOP_M_D8_D2 };
195
Christian Marangi0178c612024-08-03 10:40:35 +0200196static const int a_tuner_parents[] = { CK_TOP_XTAL, CK_TOP_APLL2_D4,
developer37161fe2022-09-09 20:00:09 +0800197 CK_TOP_M_D8_D2 };
198
Christian Marangi0178c612024-08-03 10:40:35 +0200199static const int u2u3_sys_parents[] = { CK_TOP_XTAL, CK_TOP_NET1_D5_D4 };
developer37161fe2022-09-09 20:00:09 +0800200
Christian Marangi0178c612024-08-03 10:40:35 +0200201static const int da_u2_refsel_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800202 CK_TOP_CB_U2_PHYD_CK };
203
204#define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
205 _shift, _width, _gate, _upd_ofs, _upd) \
206 { \
207 .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \
208 .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \
209 .upd_shift = _upd, .mux_shift = _shift, \
210 .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \
211 .gate_shift = _gate, .parent = _parents, \
212 .num_parents = ARRAY_SIZE(_parents), \
213 .flags = CLK_MUX_SETCLR_UPD, \
214 }
215
216/* TOPCKGEN MUX_GATE */
217static const struct mtk_composite top_muxes[] = {
218 /* CLK_CFG_0 */
219 TOP_MUX(CK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x000, 0x004,
220 0x008, 0, 3, 7, 0x1C0, 0),
221 TOP_MUX(CK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x000, 0x004,
222 0x008, 8, 3, 15, 0x1C0, 1),
223 TOP_MUX(CK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x000, 0x004, 0x008, 16,
224 3, 23, 0x1C0, 2),
225 TOP_MUX(CK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x000, 0x004,
226 0x008, 24, 3, 31, 0x1C0, 3),
227 /* CLK_CFG_1 */
228 TOP_MUX(CK_TOP_UART_SEL, "uart_sel", uart_parents, 0x010, 0x014, 0x018,
229 0, 2, 7, 0x1C0, 4),
230 TOP_MUX(CK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x010, 0x014, 0x018, 8,
231 2, 15, 0x1C0, 5),
232 TOP_MUX(CK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x010, 0x014, 0x018, 16,
233 2, 23, 0x1C0, 6),
234 TOP_MUX(CK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents,
235 0x010, 0x014, 0x018, 24, 2, 31, 0x1C0, 7),
236 /* CLK_CFG_2 */
237 TOP_MUX(CK_TOP_EMMC_250M_SEL, "emmc_250m_sel", emmc_250m_parents, 0x020,
238 0x024, 0x028, 0, 1, 7, 0x1C0, 8),
239 TOP_MUX(CK_TOP_EMMC_416M_SEL, "emmc_416m_sel", emmc_416m_parents, 0x020,
240 0x024, 0x028, 8, 1, 15, 0x1C0, 9),
241 TOP_MUX(CK_TOP_F_26M_ADC_SEL, "f_26m_adc_sel", f_26m_adc_parents, 0x020,
242 0x024, 0x028, 16, 1, 23, 0x1C0, 10),
243 TOP_MUX(CK_TOP_DRAMC_SEL, "dramc_sel", f_26m_adc_parents, 0x020, 0x024,
244 0x028, 24, 1, 31, 0x1C0, 11),
245 /* CLK_CFG_3 */
246 TOP_MUX(CK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents,
247 0x030, 0x034, 0x038, 0, 1, 7, 0x1C0, 12),
248 TOP_MUX(CK_TOP_SYSAXI_SEL, "sysaxi_sel", sysaxi_parents, 0x030, 0x034,
249 0x038, 8, 2, 15, 0x1C0, 13),
250 TOP_MUX(CK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0x030, 0x034,
251 0x038, 16, 2, 23, 0x1C0, 14),
252 TOP_MUX(CK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel", arm_db_main_parents,
253 0x030, 0x034, 0x038, 24, 1, 31, 0x1C0, 15),
254 /* CLK_CFG_4 */
255 TOP_MUX(CK_TOP_ARM_DB_JTSEL, "arm_db_jtsel", arm_db_jtsel_parents,
256 0x040, 0x044, 0x048, 0, 1, 7, 0x1C0, 16),
257 TOP_MUX(CK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x040, 0x044,
258 0x048, 8, 1, 15, 0x1C0, 17),
259 TOP_MUX(CK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents,
260 0x040, 0x044, 0x048, 16, 1, 23, 0x1C0, 18),
261 TOP_MUX(CK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents,
262 0x040, 0x044, 0x048, 24, 3, 31, 0x1C0, 19),
263 /* CLK_CFG_5 */
264 TOP_MUX(CK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x050,
265 0x054, 0x058, 0, 2, 7, 0x1C0, 20),
266 TOP_MUX(CK_TOP_SGM_325M_SEL, "sgm_325m_sel", sgm_325m_parents, 0x050,
267 0x054, 0x058, 8, 1, 15, 0x1C0, 21),
268 TOP_MUX(CK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents, 0x050,
269 0x054, 0x058, 16, 1, 23, 0x1C0, 22),
270 TOP_MUX(CK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x050, 0x054,
271 0x058, 24, 1, 31, 0x1C0, 23),
272 /* CLK_CFG_6 */
273 TOP_MUX(CK_TOP_CONN_MCUSYS_SEL, "conn_mcusys_sel", conn_mcusys_parents,
274 0x060, 0x064, 0x068, 0, 1, 7, 0x1C0, 24),
275 TOP_MUX(CK_TOP_EIP_B_SEL, "eip_b_sel", eip_b_parents, 0x060, 0x064,
276 0x068, 8, 1, 15, 0x1C0, 25),
277 TOP_MUX(CK_TOP_PCIE_PHY_SEL, "pcie_phy_sel", f_26m_adc_parents, 0x060,
278 0x064, 0x068, 16, 1, 23, 0x1C0, 26),
279 TOP_MUX(CK_TOP_USB3_PHY_SEL, "usb3_phy_sel", f_26m_adc_parents, 0x060,
280 0x064, 0x068, 24, 1, 31, 0x1C0, 27),
281 /* CLK_CFG_7 */
282 TOP_MUX(CK_TOP_F26M_SEL, "csw_f26m_sel", f_26m_adc_parents, 0x070,
283 0x074, 0x078, 0, 1, 7, 0x1C0, 28),
284 TOP_MUX(CK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x070, 0x074,
285 0x078, 8, 2, 15, 0x1C0, 29),
286 TOP_MUX(CK_TOP_A_TUNER_SEL, "a_tuner_sel", a_tuner_parents, 0x070,
287 0x074, 0x078, 16, 2, 23, 0x1C0, 30),
288 TOP_MUX(CK_TOP_U2U3_SEL, "u2u3_sel", f_26m_adc_parents, 0x070, 0x074,
289 0x078, 24, 1, 31, 0x1C4, 0),
290 /* CLK_CFG_8 */
291 TOP_MUX(CK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel", u2u3_sys_parents, 0x080,
292 0x084, 0x088, 0, 1, 7, 0x1C4, 1),
293 TOP_MUX(CK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel", u2u3_sys_parents, 0x080,
294 0x084, 0x088, 8, 1, 15, 0x1C4, 2),
295 TOP_MUX(CK_TOP_DA_U2_REFSEL, "da_u2_refsel", da_u2_refsel_parents,
296 0x080, 0x084, 0x088, 16, 1, 23, 0x1C4, 3),
297 TOP_MUX(CK_TOP_DA_U2_CK_1P_SEL, "da_u2_ck_1p_sel", da_u2_refsel_parents,
298 0x080, 0x084, 0x088, 24, 1, 31, 0x1C4, 4),
299 /* CLK_CFG_9 */
300 TOP_MUX(CK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel", sgm_reg_parents,
301 0x090, 0x094, 0x098, 0, 1, 7, 0x1C4, 5),
302};
303
304/* INFRA FIXED DIV */
305static const struct mtk_fixed_factor infra_fixed_divs[] = {
Christian Marangi7739a5f2024-08-03 10:40:36 +0200306 TOP_FACTOR(CK_INFRA_SYSAXI_D2, "infra_sysaxi_d2", CK_TOP_SYSAXI_SEL, 1, 2),
developer37161fe2022-09-09 20:00:09 +0800307};
308
309/* INFRASYS MUX PARENTS */
Christian Marangiab4de132024-08-03 10:40:38 +0200310#define INFRA_PARENT(_id) PARENT(_id, CLK_PARENT_INFRASYS)
311#define TOP_PARENT(_id) PARENT(_id, CLK_PARENT_TOPCKGEN)
312#define VOID_PARENT PARENT(-1, 0)
developer37161fe2022-09-09 20:00:09 +0800313
Christian Marangiab4de132024-08-03 10:40:38 +0200314static const struct mtk_parent infra_uart0_parents[] = {
315 TOP_PARENT(CK_TOP_F26M_SEL),
316 TOP_PARENT(CK_TOP_UART_SEL)
317};
318
319static const struct mtk_parent infra_spi0_parents[] = {
320 TOP_PARENT(CK_TOP_I2C_SEL),
321 TOP_PARENT(CK_TOP_SPI_SEL)
322};
developer37161fe2022-09-09 20:00:09 +0800323
Christian Marangiab4de132024-08-03 10:40:38 +0200324static const struct mtk_parent infra_spi1_parents[] = {
325 TOP_PARENT(CK_TOP_I2C_SEL),
326 TOP_PARENT(CK_TOP_SPINFI_SEL)
327};
developer37161fe2022-09-09 20:00:09 +0800328
Christian Marangiab4de132024-08-03 10:40:38 +0200329static const struct mtk_parent infra_pwm_bsel_parents[] = {
330 TOP_PARENT(CK_TOP_CB_RTC_32P7K),
331 TOP_PARENT(CK_TOP_F26M_SEL),
332 INFRA_PARENT(CK_INFRA_SYSAXI_D2),
333 TOP_PARENT(CK_TOP_PWM_SEL)
334};
developer37161fe2022-09-09 20:00:09 +0800335
Christian Marangiab4de132024-08-03 10:40:38 +0200336static const struct mtk_parent infra_pcie_parents[] = {
337 TOP_PARENT(CK_TOP_CB_RTC_32P7K),
338 TOP_PARENT(CK_TOP_F26M_SEL),
339 VOID_PARENT,
340 TOP_PARENT(CK_TOP_PEXTP_TL_SEL)
341};
developer37161fe2022-09-09 20:00:09 +0800342
343#define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \
344 { \
345 .id = _id, .mux_reg = (_reg) + 0x8, \
346 .mux_set_reg = (_reg) + 0x0, .mux_clr_reg = (_reg) + 0x4, \
347 .mux_shift = _shift, .mux_mask = BIT(_width) - 1, \
Christian Marangiab4de132024-08-03 10:40:38 +0200348 .parent_flags = _parents, .num_parents = ARRAY_SIZE(_parents), \
349 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \
developer37161fe2022-09-09 20:00:09 +0800350 }
351
352/* INFRA MUX */
353
354static const struct mtk_composite infra_muxes[] = {
355 /* MODULE_CLK_SEL_0 */
356 INFRA_MUX(CK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart0_parents,
357 0x10, 0, 1),
358 INFRA_MUX(CK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart0_parents,
359 0x10, 1, 1),
360 INFRA_MUX(CK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart0_parents,
361 0x10, 2, 1),
362 INFRA_MUX(CK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x10,
363 4, 1),
364 INFRA_MUX(CK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x10,
365 5, 1),
366 INFRA_MUX(CK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm_bsel_parents,
367 0x10, 9, 2),
368 INFRA_MUX(CK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm_bsel_parents,
369 0x10, 11, 2),
370 INFRA_MUX(CK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents,
371 0x10, 13, 2),
372 /* MODULE_CLK_SEL_1 */
373 INFRA_MUX(CK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x20,
374 0, 2),
375};
376
377static const struct mtk_gate_regs infra_0_cg_regs = {
378 .set_ofs = 0x40,
379 .clr_ofs = 0x44,
380 .sta_ofs = 0x48,
381};
382
383static const struct mtk_gate_regs infra_1_cg_regs = {
384 .set_ofs = 0x50,
385 .clr_ofs = 0x54,
386 .sta_ofs = 0x58,
387};
388
389static const struct mtk_gate_regs infra_2_cg_regs = {
390 .set_ofs = 0x60,
391 .clr_ofs = 0x64,
392 .sta_ofs = 0x68,
393};
394
Christian Marangiab4de132024-08-03 10:40:38 +0200395#define GATE_INFRA0(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800396 { \
397 .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \
398 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200399 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800400 }
Christian Marangiab4de132024-08-03 10:40:38 +0200401#define GATE_INFRA0_INFRA(_id, _name, _parent, _shift) \
402 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
403#define GATE_INFRA0_TOP(_id, _name, _parent, _shift) \
404 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800405
Christian Marangiab4de132024-08-03 10:40:38 +0200406#define GATE_INFRA1(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800407 { \
408 .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \
409 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200410 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800411 }
Christian Marangiab4de132024-08-03 10:40:38 +0200412#define GATE_INFRA1_INFRA(_id, _name, _parent, _shift) \
413 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
414#define GATE_INFRA1_TOP(_id, _name, _parent, _shift) \
415 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800416
Christian Marangiab4de132024-08-03 10:40:38 +0200417#define GATE_INFRA2(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800418 { \
419 .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \
420 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200421 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800422 }
Christian Marangiab4de132024-08-03 10:40:38 +0200423#define GATE_INFRA2_INFRA(_id, _name, _parent, _shift) \
424 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
425#define GATE_INFRA2_TOP(_id, _name, _parent, _shift) \
426 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800427
428/* INFRA GATE */
429
430static const struct mtk_gate infracfg_ao_gates[] = {
431 /* INFRA0 */
Christian Marangiab4de132024-08-03 10:40:38 +0200432 GATE_INFRA0_INFRA(CK_INFRA_GPT_STA, "infra_gpt_sta", CK_INFRA_SYSAXI_D2, 0),
433 GATE_INFRA0_INFRA(CK_INFRA_PWM_HCK, "infra_pwm_hck", CK_INFRA_SYSAXI_D2, 1),
434 GATE_INFRA0_INFRA(CK_INFRA_PWM_STA, "infra_pwm_sta", CK_INFRA_PWM_BSEL, 2),
435 GATE_INFRA0_INFRA(CK_INFRA_PWM1_CK, "infra_pwm1", CK_INFRA_PWM1_SEL, 3),
436 GATE_INFRA0_INFRA(CK_INFRA_PWM2_CK, "infra_pwm2", CK_INFRA_PWM2_SEL, 4),
437 GATE_INFRA0_TOP(CK_INFRA_CQ_DMA_CK, "infra_cq_dma", CK_TOP_SYSAXI_SEL, 6),
438 GATE_INFRA0_TOP(CK_INFRA_EIP97_CK, "infra_eip97", CK_TOP_EIP_B_SEL, 7),
439 GATE_INFRA0_TOP(CK_INFRA_AUD_BUS_CK, "infra_aud_bus", CK_TOP_SYSAXI_SEL, 8),
440 GATE_INFRA0_TOP(CK_INFRA_AUD_26M_CK, "infra_aud_26m", CK_TOP_F26M_SEL, 9),
441 GATE_INFRA0_TOP(CK_INFRA_AUD_L_CK, "infra_aud_l", CK_TOP_AUD_L_SEL, 10),
442 GATE_INFRA0_TOP(CK_INFRA_AUD_AUD_CK, "infra_aud_aud", CK_TOP_A1SYS_SEL,
443 11),
444 GATE_INFRA0_TOP(CK_INFRA_AUD_EG2_CK, "infra_aud_eg2", CK_TOP_A_TUNER_SEL,
445 13),
446 GATE_INFRA0_TOP(CK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", CK_TOP_F26M_SEL,
447 14),
448 GATE_INFRA0_INFRA(CK_INFRA_DBG_CK, "infra_dbg", CK_INFRA_SYSAXI_D2, 15),
449 GATE_INFRA0_INFRA(CK_INFRA_AP_DMA_CK, "infra_ap_dma", CK_INFRA_SYSAXI_D2, 16),
450 GATE_INFRA0_INFRA(CK_INFRA_SEJ_CK, "infra_sej", CK_INFRA_SYSAXI_D2, 24),
451 GATE_INFRA0_TOP(CK_INFRA_SEJ_13M_CK, "infra_sej_13m", CK_TOP_F26M_SEL, 25),
452 GATE_INFRA0_TOP(CK_INFRA_TRNG_CK, "infra_trng", CK_TOP_SYSAXI_SEL, 26),
developer37161fe2022-09-09 20:00:09 +0800453 /* INFRA1 */
Christian Marangiab4de132024-08-03 10:40:38 +0200454 GATE_INFRA1_TOP(CK_INFRA_THERM_CK, "infra_therm", CK_TOP_F26M_SEL, 0),
455 GATE_INFRA1_TOP(CK_INFRA_I2CO_CK, "infra_i2co", CK_TOP_I2C_SEL, 1),
456 GATE_INFRA1_INFRA(CK_INFRA_UART0_CK, "infra_uart0", CK_INFRA_UART0_SEL, 2),
457 GATE_INFRA1_INFRA(CK_INFRA_UART1_CK, "infra_uart1", CK_INFRA_UART1_SEL, 3),
458 GATE_INFRA1_INFRA(CK_INFRA_UART2_CK, "infra_uart2", CK_INFRA_UART2_SEL, 4),
459 GATE_INFRA1_TOP(CK_INFRA_NFI1_CK, "infra_nfi1", CK_TOP_NFI1X_SEL, 8),
460 GATE_INFRA1_TOP(CK_INFRA_SPINFI1_CK, "infra_spinfi1", CK_TOP_SPINFI_SEL,
461 9),
462 GATE_INFRA1_INFRA(CK_INFRA_NFI_HCK_CK, "infra_nfi_hck", CK_INFRA_SYSAXI_D2, 10),
463 GATE_INFRA1_INFRA(CK_INFRA_SPI0_CK, "infra_spi0", CK_INFRA_SPI0_SEL, 11),
464 GATE_INFRA1_INFRA(CK_INFRA_SPI1_CK, "infra_spi1", CK_INFRA_SPI1_SEL, 12),
465 GATE_INFRA1_INFRA(CK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", CK_INFRA_SYSAXI_D2,
466 13),
467 GATE_INFRA1_INFRA(CK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", CK_INFRA_SYSAXI_D2,
468 14),
469 GATE_INFRA1_TOP(CK_INFRA_FRTC_CK, "infra_frtc", CK_TOP_CB_RTC_32K, 15),
470 GATE_INFRA1_TOP(CK_INFRA_MSDC_CK, "infra_msdc", CK_TOP_EMMC_416M_SEL, 16),
471 GATE_INFRA1_TOP(CK_INFRA_MSDC_HCK_CK, "infra_msdc_hck",
472 CK_TOP_EMMC_250M_SEL, 17),
473 GATE_INFRA1_TOP(CK_INFRA_MSDC_133M_CK, "infra_msdc_133m",
474 CK_TOP_SYSAXI_SEL, 18),
475 GATE_INFRA1_INFRA(CK_INFRA_MSDC_66M_CK, "infra_msdc_66m", CK_INFRA_SYSAXI_D2,
476 19),
477 GATE_INFRA1_INFRA(CK_INFRA_ADC_26M_CK, "infra_adc_26m", CK_INFRA_ADC_FRC_CK, 20),
478 GATE_INFRA1_TOP(CK_INFRA_ADC_FRC_CK, "infra_adc_frc", CK_TOP_F26M_SEL, 21),
479 GATE_INFRA1_TOP(CK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", CK_TOP_NFI1X_SEL,
480 23),
developer37161fe2022-09-09 20:00:09 +0800481 /* INFRA2 */
Christian Marangiab4de132024-08-03 10:40:38 +0200482 GATE_INFRA2_TOP(CK_INFRA_IUSB_133_CK, "infra_iusb_133", CK_TOP_SYSAXI_SEL,
483 0),
484 GATE_INFRA2_INFRA(CK_INFRA_IUSB_66M_CK, "infra_iusb_66m", CK_INFRA_SYSAXI_D2,
485 1),
486 GATE_INFRA2_TOP(CK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", CK_TOP_U2U3_SYS_SEL,
487 2),
488 GATE_INFRA2_TOP(CK_INFRA_IUSB_CK, "infra_iusb", CK_TOP_U2U3_SEL, 3),
489 GATE_INFRA2_TOP(CK_INFRA_IPCIE_CK, "infra_ipcie", CK_TOP_PEXTP_TL_SEL, 12),
490 GATE_INFRA2_TOP(CK_INFRA_IPCIER_CK, "infra_ipcier", CK_TOP_F26M_SEL, 14),
491 GATE_INFRA2_TOP(CK_INFRA_IPCIEB_CK, "infra_ipcieb", CK_TOP_SYSAXI_SEL, 15),
developer37161fe2022-09-09 20:00:09 +0800492};
493
494static const struct mtk_clk_tree mt7986_fixed_pll_clk_tree = {
495 .fdivs_offs = CLK_APMIXED_NR_CLK,
496 .xtal_rate = 40 * MHZ,
497 .fclks = fixed_pll_clks,
498};
499
500static const struct mtk_clk_tree mt7986_topckgen_clk_tree = {
501 .fdivs_offs = CK_TOP_CB_M_416M,
502 .muxes_offs = CK_TOP_NFI1X_SEL,
503 .fclks = top_fixed_clks,
504 .fdivs = top_fixed_divs,
505 .muxes = top_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200506 .flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
developer37161fe2022-09-09 20:00:09 +0800507};
508
509static const struct mtk_clk_tree mt7986_infracfg_clk_tree = {
Christian Marangiab4de132024-08-03 10:40:38 +0200510 .fdivs_offs = CK_INFRA_SYSAXI_D2,
developer37161fe2022-09-09 20:00:09 +0800511 .muxes_offs = CK_INFRA_UART0_SEL,
512 .fdivs = infra_fixed_divs,
513 .muxes = infra_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200514 .flags = CLK_INFRASYS,
developer37161fe2022-09-09 20:00:09 +0800515};
516
517static const struct udevice_id mt7986_fixed_pll_compat[] = {
518 { .compatible = "mediatek,mt7986-fixed-plls" },
Christian Marangi4dd4a282024-06-24 23:03:40 +0200519 { .compatible = "mediatek,mt7986-apmixedsys" },
developer37161fe2022-09-09 20:00:09 +0800520 {}
521};
522
523static const struct udevice_id mt7986_topckgen_compat[] = {
524 { .compatible = "mediatek,mt7986-topckgen" },
525 {}
526};
527
528static int mt7986_fixed_pll_probe(struct udevice *dev)
529{
530 return mtk_common_clk_init(dev, &mt7986_fixed_pll_clk_tree);
531}
532
533static int mt7986_topckgen_probe(struct udevice *dev)
534{
535 struct mtk_clk_priv *priv = dev_get_priv(dev);
536
537 priv->base = dev_read_addr_ptr(dev);
538 writel(MT7986_CLK_PDN_EN_WRITE, priv->base + MT7986_CLK_PDN);
539
540 return mtk_common_clk_init(dev, &mt7986_topckgen_clk_tree);
541}
542
543U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
544 .name = "mt7986-clock-fixed-pll",
545 .id = UCLASS_CLK,
546 .of_match = mt7986_fixed_pll_compat,
547 .probe = mt7986_fixed_pll_probe,
548 .priv_auto = sizeof(struct mtk_clk_priv),
549 .ops = &mtk_clk_topckgen_ops,
550 .flags = DM_FLAG_PRE_RELOC,
551};
552
553U_BOOT_DRIVER(mtk_clk_topckgen) = {
554 .name = "mt7986-clock-topckgen",
555 .id = UCLASS_CLK,
556 .of_match = mt7986_topckgen_compat,
557 .probe = mt7986_topckgen_probe,
558 .priv_auto = sizeof(struct mtk_clk_priv),
559 .ops = &mtk_clk_topckgen_ops,
560 .flags = DM_FLAG_PRE_RELOC,
561};
562
563static const struct udevice_id mt7986_infracfg_compat[] = {
564 { .compatible = "mediatek,mt7986-infracfg" },
565 {}
566};
567
568static const struct udevice_id mt7986_infracfg_ao_compat[] = {
569 { .compatible = "mediatek,mt7986-infracfg_ao" },
570 {}
571};
572
573static int mt7986_infracfg_probe(struct udevice *dev)
574{
575 return mtk_common_clk_init(dev, &mt7986_infracfg_clk_tree);
576}
577
578static int mt7986_infracfg_ao_probe(struct udevice *dev)
579{
580 return mtk_common_clk_gate_init(dev, &mt7986_infracfg_clk_tree,
581 infracfg_ao_gates);
582}
583
584U_BOOT_DRIVER(mtk_clk_infracfg) = {
585 .name = "mt7986-clock-infracfg",
586 .id = UCLASS_CLK,
587 .of_match = mt7986_infracfg_compat,
588 .probe = mt7986_infracfg_probe,
589 .priv_auto = sizeof(struct mtk_clk_priv),
590 .ops = &mtk_clk_infrasys_ops,
591 .flags = DM_FLAG_PRE_RELOC,
592};
593
594U_BOOT_DRIVER(mtk_clk_infracfg_ao) = {
595 .name = "mt7986-clock-infracfg-ao",
596 .id = UCLASS_CLK,
597 .of_match = mt7986_infracfg_ao_compat,
598 .probe = mt7986_infracfg_ao_probe,
599 .priv_auto = sizeof(struct mtk_cg_priv),
600 .ops = &mtk_clk_gate_ops,
601 .flags = DM_FLAG_PRE_RELOC,
602};
603
604/* ethsys */
605static const struct mtk_gate_regs eth_cg_regs = {
606 .sta_ofs = 0x30,
607};
608
609#define GATE_ETH(_id, _name, _parent, _shift) \
610 { \
611 .id = _id, .parent = _parent, .regs = &eth_cg_regs, \
612 .shift = _shift, \
613 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
614 }
615
616static const struct mtk_gate eth_cgs[] = {
617 GATE_ETH(CK_ETH_FE_EN, "eth_fe_en", CK_TOP_NETSYS_2X, 7),
618 GATE_ETH(CK_ETH_GP2_EN, "eth_gp2_en", CK_TOP_SGM_325M, 8),
619 GATE_ETH(CK_ETH_GP1_EN, "eth_gp1_en", CK_TOP_SGM_325M, 8),
620 GATE_ETH(CK_ETH_WOCPU1_EN, "eth_wocpu1_en", CK_TOP_NETSYS_WED_MCU, 14),
621 GATE_ETH(CK_ETH_WOCPU0_EN, "eth_wocpu0_en", CK_TOP_NETSYS_WED_MCU, 15),
622};
623
624static int mt7986_ethsys_probe(struct udevice *dev)
625{
626 return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree,
627 eth_cgs);
628}
629
630static int mt7986_ethsys_bind(struct udevice *dev)
631{
632 int ret = 0;
633
634 if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
635 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
636 if (ret)
637 debug("Warning: failed to bind reset controller\n");
638 }
639
640 return ret;
641}
642
643static const struct udevice_id mt7986_ethsys_compat[] = {
644 { .compatible = "mediatek,mt7986-ethsys" },
645 { }
646};
647
648U_BOOT_DRIVER(mtk_clk_ethsys) = {
649 .name = "mt7986-clock-ethsys",
650 .id = UCLASS_CLK,
651 .of_match = mt7986_ethsys_compat,
652 .probe = mt7986_ethsys_probe,
653 .bind = mt7986_ethsys_bind,
654 .priv_auto = sizeof(struct mtk_cg_priv),
655 .ops = &mtk_clk_gate_ops,
656};