blob: 34b8eba53985450b12d41329502209c8b2d41802 [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[] = {
Christian Marangi83b17ec2024-08-03 10:40:42 +020049 /* TOP Factors */
50 TOP_FACTOR(CK_TOP_XTAL_D2, "xtal_d2", CK_TOP_XTAL,
51 1, 2),
52 TOP_FACTOR(CK_TOP_RTC_32K, "rtc_32k", CK_TOP_XTAL, 1,
53 1250),
54 TOP_FACTOR(CK_TOP_RTC_32P7K, "rtc_32p7k", CK_TOP_XTAL, 1,
55 1220),
56 TOP_FACTOR(CK_TOP_NFI1X, "nfi1x", CK_TOP_NFI1X_SEL, 1, 1),
57 TOP_FACTOR(CK_TOP_USB_EQ_RX250M, "usb_eq_rx250m", CK_TOP_XTAL, 1,
58 1),
59 TOP_FACTOR(CK_TOP_USB_TX250M, "usb_tx250m", CK_TOP_XTAL, 1, 1),
60 TOP_FACTOR(CK_TOP_USB_LN0_CK, "usb_ln0", CK_TOP_XTAL, 1, 1),
61 TOP_FACTOR(CK_TOP_USB_CDR_CK, "usb_cdr", CK_TOP_XTAL, 1, 1),
62 TOP_FACTOR(CK_TOP_SPINFI_BCK, "spinfi_bck", CK_TOP_SPINFI_SEL, 1, 1),
63 TOP_FACTOR(CK_TOP_I2C_BCK, "i2c_bck", CK_TOP_I2C_SEL, 1, 1),
64 TOP_FACTOR(CK_TOP_PEXTP_TL, "pextp_tl", CK_TOP_PEXTP_TL_SEL, 1, 1),
65 TOP_FACTOR(CK_TOP_EMMC_250M, "emmc_250m", CK_TOP_EMMC_250M_SEL, 1, 1),
66 TOP_FACTOR(CK_TOP_EMMC_416M, "emmc_416m", CK_TOP_EMMC_416M_SEL, 1, 1),
67 TOP_FACTOR(CK_TOP_F_26M_ADC_CK, "f_26m_adc", CK_TOP_F_26M_ADC_SEL, 1,
68 1),
69 TOP_FACTOR(CK_TOP_SYSAXI, "sysaxi", CK_TOP_SYSAXI_SEL, 1, 1),
70 TOP_FACTOR(CK_TOP_NETSYS_WED_MCU, "netsys_wed_mcu",
71 CK_TOP_NETSYS_MCU_SEL, 1, 1),
72 TOP_FACTOR(CK_TOP_NETSYS_2X, "netsys_2x", CK_TOP_NETSYS_2X_SEL, 1, 1),
73 TOP_FACTOR(CK_TOP_SGM_325M, "sgm_325m", CK_TOP_SGM_325M_SEL, 1, 1),
74 TOP_FACTOR(CK_TOP_A1SYS, "a1sys", CK_TOP_A1SYS_SEL, 1, 1),
75 TOP_FACTOR(CK_TOP_EIP_B, "eip_b", CK_TOP_EIP_B_SEL, 1, 1),
76 TOP_FACTOR(CK_TOP_F26M, "csw_f26m", CK_TOP_F26M_SEL, 1, 1),
77 TOP_FACTOR(CK_TOP_AUD_L, "aud_l", CK_TOP_AUD_L_SEL, 1, 1),
78 TOP_FACTOR(CK_TOP_A_TUNER, "a_tuner", CK_TOP_A_TUNER_SEL, 2, 1),
79 TOP_FACTOR(CK_TOP_U2U3_REF, "u2u3_ref", CK_TOP_U2U3_SEL, 1, 1),
80 TOP_FACTOR(CK_TOP_U2U3_SYS, "u2u3_sys", CK_TOP_U2U3_SYS_SEL, 1, 1),
81 TOP_FACTOR(CK_TOP_U2U3_XHCI, "u2u3_xhci", CK_TOP_U2U3_XHCI_SEL, 1, 1),
82 TOP_FACTOR(CK_TOP_AP2CNN_HOST, "ap2cnn_host", CK_TOP_AP2CNN_HOST_SEL, 1,
83 1),
Christian Marangi9276f072024-08-03 10:40:41 +020084 /* MPLL */
85 PLL_FACTOR(CK_TOP_CB_MPLL_416M, "cb_mpll_416m", CK_APMIXED_MPLL, 1, 1),
86 PLL_FACTOR(CK_TOP_MPLL_D2, "mpll_d2", CK_APMIXED_MPLL, 1, 2),
87 PLL_FACTOR(CK_TOP_MPLL_D4, "mpll_d4", CK_APMIXED_MPLL, 1, 4),
88 PLL_FACTOR(CK_TOP_MPLL_D8, "mpll_d8", CK_APMIXED_MPLL, 1, 8),
89 PLL_FACTOR(CK_TOP_MPLL_D8_D2, "mpll_d8_d2", CK_APMIXED_MPLL, 1, 16),
90 PLL_FACTOR(CK_TOP_MPLL_D3_D2, "mpll_d3_d2", CK_APMIXED_MPLL, 1, 2),
91 /* MMPLL */
92 PLL_FACTOR(CK_TOP_MMPLL_D2, "mmpll_d2", CK_APMIXED_MMPLL, 1, 2),
93 PLL_FACTOR(CK_TOP_MMPLL_D4, "mmpll_d4", CK_APMIXED_MMPLL, 1, 4),
94 PLL_FACTOR(CK_TOP_MMPLL_D8, "mmpll_d8", CK_APMIXED_MMPLL, 1, 8),
95 PLL_FACTOR(CK_TOP_MMPLL_D8_D2, "mmpll_d8_d2", CK_APMIXED_MMPLL, 1, 16),
96 PLL_FACTOR(CK_TOP_MMPLL_D3_D8, "mmpll_d3_d8", CK_APMIXED_MMPLL, 1, 8),
97 PLL_FACTOR(CK_TOP_MMPLL_U2PHYD, "mmpll_u2phy", CK_APMIXED_MMPLL, 1, 30),
98 /* APLL2 */
developer37161fe2022-09-09 20:00:09 +080099 PLL_FACTOR(CK_TOP_CB_APLL2_196M, "cb_apll2_196m", CK_APMIXED_APLL2, 1,
100 1),
101 PLL_FACTOR(CK_TOP_APLL2_D4, "apll2_d4", CK_APMIXED_APLL2, 1, 4),
Christian Marangi9276f072024-08-03 10:40:41 +0200102 /* NET1PLL */
103 PLL_FACTOR(CK_TOP_NET1PLL_D4, "net1pll_d4", CK_APMIXED_NET1PLL, 1, 4),
104 PLL_FACTOR(CK_TOP_NET1PLL_D5, "net1pll_d5", CK_APMIXED_NET1PLL, 1, 5),
105 PLL_FACTOR(CK_TOP_NET1PLL_D5_D2, "net1pll_d5_d2", CK_APMIXED_NET1PLL, 1, 10),
106 PLL_FACTOR(CK_TOP_NET1PLL_D5_D4, "net1pll_d5_d4", CK_APMIXED_NET1PLL, 1, 20),
107 PLL_FACTOR(CK_TOP_NET1PLL_D8_D2, "net1pll_d8_d2", CK_APMIXED_NET1PLL, 1, 16),
108 PLL_FACTOR(CK_TOP_NET1PLL_D8_D4, "net1pll_d8_d4", CK_APMIXED_NET1PLL, 1, 32),
109 /* NET2PLL */
110 PLL_FACTOR(CK_TOP_CB_NET2PLL_800M, "cb_net2pll_800m", CK_APMIXED_NET2PLL, 1,
developer37161fe2022-09-09 20:00:09 +0800111 1),
Christian Marangi9276f072024-08-03 10:40:41 +0200112 PLL_FACTOR(CK_TOP_NET2PLL_D4, "net2pll_d4", CK_APMIXED_NET2PLL, 1, 4),
113 PLL_FACTOR(CK_TOP_NET2PLL_D4_D2, "net2pll_d4_d2", CK_APMIXED_NET2PLL, 1, 8),
114 PLL_FACTOR(CK_TOP_NET2PLL_D3_D2, "net2pll_d3_d2", CK_APMIXED_NET2PLL, 1, 2),
115 /* WEDMCUPLL */
116 PLL_FACTOR(CK_TOP_CB_WEDMCUPLL_760M, "cb_wedmcupll_760m",
developer37161fe2022-09-09 20:00:09 +0800117 CK_APMIXED_WEDMCUPLL, 1, 1),
Christian Marangi9276f072024-08-03 10:40:41 +0200118 PLL_FACTOR(CK_TOP_WEDMCUPLL_D5_D2, "wedmcupll_d5_d2", CK_APMIXED_WEDMCUPLL, 1,
developer37161fe2022-09-09 20:00:09 +0800119 10),
Christian Marangi9276f072024-08-03 10:40:41 +0200120 /* SGMPLL */
121 PLL_FACTOR(CK_TOP_CB_SGMPLL_325M, "cb_sgmpll_325m", CK_APMIXED_SGMPLL, 1, 1),
developer37161fe2022-09-09 20:00:09 +0800122};
123
124/* TOPCKGEN MUX PARENTS */
Christian Marangi9276f072024-08-03 10:40:41 +0200125static const int nfi1x_parents[] = { CK_TOP_XTAL, CK_TOP_MMPLL_D8,
126 CK_TOP_NET1PLL_D8_D2, CK_TOP_NET2PLL_D3_D2,
127 CK_TOP_MPLL_D4, CK_TOP_MMPLL_D8_D2,
128 CK_TOP_WEDMCUPLL_D5_D2, CK_TOP_MPLL_D8 };
developer37161fe2022-09-09 20:00:09 +0800129
130static const int spinfi_parents[] = {
Christian Marangi9276f072024-08-03 10:40:41 +0200131 CK_TOP_XTAL_D2, CK_TOP_XTAL, CK_TOP_NET1PLL_D5_D4,
132 CK_TOP_MPLL_D4, CK_TOP_MMPLL_D8_D2, CK_TOP_WEDMCUPLL_D5_D2,
133 CK_TOP_MMPLL_D3_D8, CK_TOP_MPLL_D8
developer37161fe2022-09-09 20:00:09 +0800134};
135
Christian Marangi9276f072024-08-03 10:40:41 +0200136static const int spi_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_D2,
137 CK_TOP_MMPLL_D8, CK_TOP_NET1PLL_D8_D2,
138 CK_TOP_NET2PLL_D3_D2, CK_TOP_NET1PLL_D5_D4,
139 CK_TOP_MPLL_D4, CK_TOP_WEDMCUPLL_D5_D2 };
developer37161fe2022-09-09 20:00:09 +0800140
Christian Marangi9276f072024-08-03 10:40:41 +0200141static const int uart_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_D8,
142 CK_TOP_MPLL_D8_D2 };
developer37161fe2022-09-09 20:00:09 +0800143
Christian Marangi9276f072024-08-03 10:40:41 +0200144static const int pwm_parents[] = { CK_TOP_XTAL, CK_TOP_NET1PLL_D8_D2,
145 CK_TOP_NET1PLL_D5_D4, CK_TOP_MPLL_D4 };
developer37161fe2022-09-09 20:00:09 +0800146
Christian Marangi9276f072024-08-03 10:40:41 +0200147static const int i2c_parents[] = { CK_TOP_XTAL, CK_TOP_NET1PLL_D5_D4,
148 CK_TOP_MPLL_D4, CK_TOP_NET1PLL_D8_D4 };
developer37161fe2022-09-09 20:00:09 +0800149
Christian Marangi0178c612024-08-03 10:40:35 +0200150static const int pextp_tl_ck_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200151 CK_TOP_NET1PLL_D5_D4, CK_TOP_NET2PLL_D4_D2,
152 CK_TOP_RTC_32K };
developer37161fe2022-09-09 20:00:09 +0800153
Christian Marangi0178c612024-08-03 10:40:35 +0200154static const int emmc_250m_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200155 CK_TOP_NET1PLL_D5_D2 };
developer37161fe2022-09-09 20:00:09 +0800156
Christian Marangi9276f072024-08-03 10:40:41 +0200157static const int emmc_416m_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_416M };
developer37161fe2022-09-09 20:00:09 +0800158
Christian Marangi9276f072024-08-03 10:40:41 +0200159static const int f_26m_adc_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_D8_D2 };
developer37161fe2022-09-09 20:00:09 +0800160
Christian Marangi9276f072024-08-03 10:40:41 +0200161static const int dramc_md32_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_D2 };
developer37161fe2022-09-09 20:00:09 +0800162
Christian Marangi9276f072024-08-03 10:40:41 +0200163static const int sysaxi_parents[] = { CK_TOP_XTAL, CK_TOP_NET1PLL_D8_D2,
164 CK_TOP_NET2PLL_D4 };
developer37161fe2022-09-09 20:00:09 +0800165
Christian Marangi9276f072024-08-03 10:40:41 +0200166static const int sysapb_parents[] = { CK_TOP_XTAL, CK_TOP_MPLL_D3_D2,
167 CK_TOP_NET2PLL_D4_D2 };
developer37161fe2022-09-09 20:00:09 +0800168
Christian Marangi0178c612024-08-03 10:40:35 +0200169static const int arm_db_main_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200170 CK_TOP_NET2PLL_D3_D2 };
developer37161fe2022-09-09 20:00:09 +0800171
Christian Marangi0178c612024-08-03 10:40:35 +0200172static const int arm_db_jtsel_parents[] = { -1, CK_TOP_XTAL };
developer37161fe2022-09-09 20:00:09 +0800173
Christian Marangi9276f072024-08-03 10:40:41 +0200174static const int netsys_parents[] = { CK_TOP_XTAL, CK_TOP_MMPLL_D4 };
developer37161fe2022-09-09 20:00:09 +0800175
Christian Marangi0178c612024-08-03 10:40:35 +0200176static const int netsys_500m_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200177 CK_TOP_NET1PLL_D5 };
developer37161fe2022-09-09 20:00:09 +0800178
Christian Marangi0178c612024-08-03 10:40:35 +0200179static const int netsys_mcu_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800180 CK_TOP_CB_WEDMCU_760M,
Christian Marangi9276f072024-08-03 10:40:41 +0200181 CK_TOP_MMPLL_D2, CK_TOP_NET1PLL_D4,
182 CK_TOP_NET1PLL_D5 };
developer37161fe2022-09-09 20:00:09 +0800183
Christian Marangi0178c612024-08-03 10:40:35 +0200184static const int netsys_2x_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200185 CK_TOP_CB_NET2PLL_800M,
developer37161fe2022-09-09 20:00:09 +0800186 CK_TOP_CB_WEDMCU_760M,
Christian Marangi9276f072024-08-03 10:40:41 +0200187 CK_TOP_MMPLL_D2 };
developer37161fe2022-09-09 20:00:09 +0800188
Christian Marangi0178c612024-08-03 10:40:35 +0200189static const int sgm_325m_parents[] = { CK_TOP_XTAL,
developer37161fe2022-09-09 20:00:09 +0800190 CK_TOP_CB_SGM_325M };
191
Christian Marangi9276f072024-08-03 10:40:41 +0200192static const int sgm_reg_parents[] = { CK_TOP_XTAL, CK_TOP_NET1PLL_D8_D4 };
developer37161fe2022-09-09 20:00:09 +0800193
Christian Marangi0178c612024-08-03 10:40:35 +0200194static const int a1sys_parents[] = { CK_TOP_XTAL, CK_TOP_APLL2_D4 };
developer37161fe2022-09-09 20:00:09 +0800195
Christian Marangi0178c612024-08-03 10:40:35 +0200196static const int conn_mcusys_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200197 CK_TOP_MMPLL_D2 };
developer37161fe2022-09-09 20:00:09 +0800198
Christian Marangi9276f072024-08-03 10:40:41 +0200199static const int eip_b_parents[] = { CK_TOP_XTAL, CK_TOP_CB_NET2PLL_800M };
developer37161fe2022-09-09 20:00:09 +0800200
Christian Marangi0178c612024-08-03 10:40:35 +0200201static const int aud_l_parents[] = { CK_TOP_XTAL, CK_TOP_CB_APLL2_196M,
Christian Marangi9276f072024-08-03 10:40:41 +0200202 CK_TOP_MPLL_D8_D2 };
developer37161fe2022-09-09 20:00:09 +0800203
Christian Marangi0178c612024-08-03 10:40:35 +0200204static const int a_tuner_parents[] = { CK_TOP_XTAL, CK_TOP_APLL2_D4,
Christian Marangi9276f072024-08-03 10:40:41 +0200205 CK_TOP_MPLL_D8_D2 };
developer37161fe2022-09-09 20:00:09 +0800206
Christian Marangi9276f072024-08-03 10:40:41 +0200207static const int u2u3_sys_parents[] = { CK_TOP_XTAL, CK_TOP_NET1PLL_D5_D4 };
developer37161fe2022-09-09 20:00:09 +0800208
Christian Marangi0178c612024-08-03 10:40:35 +0200209static const int da_u2_refsel_parents[] = { CK_TOP_XTAL,
Christian Marangi9276f072024-08-03 10:40:41 +0200210 CK_TOP_MMPLL_U2PHYD };
developer37161fe2022-09-09 20:00:09 +0800211
212#define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \
213 _shift, _width, _gate, _upd_ofs, _upd) \
214 { \
215 .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \
216 .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \
217 .upd_shift = _upd, .mux_shift = _shift, \
218 .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \
219 .gate_shift = _gate, .parent = _parents, \
220 .num_parents = ARRAY_SIZE(_parents), \
221 .flags = CLK_MUX_SETCLR_UPD, \
222 }
223
224/* TOPCKGEN MUX_GATE */
225static const struct mtk_composite top_muxes[] = {
226 /* CLK_CFG_0 */
227 TOP_MUX(CK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x000, 0x004,
228 0x008, 0, 3, 7, 0x1C0, 0),
229 TOP_MUX(CK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x000, 0x004,
230 0x008, 8, 3, 15, 0x1C0, 1),
231 TOP_MUX(CK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x000, 0x004, 0x008, 16,
232 3, 23, 0x1C0, 2),
233 TOP_MUX(CK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x000, 0x004,
234 0x008, 24, 3, 31, 0x1C0, 3),
235 /* CLK_CFG_1 */
236 TOP_MUX(CK_TOP_UART_SEL, "uart_sel", uart_parents, 0x010, 0x014, 0x018,
237 0, 2, 7, 0x1C0, 4),
238 TOP_MUX(CK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x010, 0x014, 0x018, 8,
239 2, 15, 0x1C0, 5),
240 TOP_MUX(CK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x010, 0x014, 0x018, 16,
241 2, 23, 0x1C0, 6),
242 TOP_MUX(CK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents,
243 0x010, 0x014, 0x018, 24, 2, 31, 0x1C0, 7),
244 /* CLK_CFG_2 */
245 TOP_MUX(CK_TOP_EMMC_250M_SEL, "emmc_250m_sel", emmc_250m_parents, 0x020,
246 0x024, 0x028, 0, 1, 7, 0x1C0, 8),
247 TOP_MUX(CK_TOP_EMMC_416M_SEL, "emmc_416m_sel", emmc_416m_parents, 0x020,
248 0x024, 0x028, 8, 1, 15, 0x1C0, 9),
249 TOP_MUX(CK_TOP_F_26M_ADC_SEL, "f_26m_adc_sel", f_26m_adc_parents, 0x020,
250 0x024, 0x028, 16, 1, 23, 0x1C0, 10),
251 TOP_MUX(CK_TOP_DRAMC_SEL, "dramc_sel", f_26m_adc_parents, 0x020, 0x024,
252 0x028, 24, 1, 31, 0x1C0, 11),
253 /* CLK_CFG_3 */
254 TOP_MUX(CK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents,
255 0x030, 0x034, 0x038, 0, 1, 7, 0x1C0, 12),
256 TOP_MUX(CK_TOP_SYSAXI_SEL, "sysaxi_sel", sysaxi_parents, 0x030, 0x034,
257 0x038, 8, 2, 15, 0x1C0, 13),
258 TOP_MUX(CK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0x030, 0x034,
259 0x038, 16, 2, 23, 0x1C0, 14),
260 TOP_MUX(CK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel", arm_db_main_parents,
261 0x030, 0x034, 0x038, 24, 1, 31, 0x1C0, 15),
262 /* CLK_CFG_4 */
263 TOP_MUX(CK_TOP_ARM_DB_JTSEL, "arm_db_jtsel", arm_db_jtsel_parents,
264 0x040, 0x044, 0x048, 0, 1, 7, 0x1C0, 16),
265 TOP_MUX(CK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x040, 0x044,
266 0x048, 8, 1, 15, 0x1C0, 17),
267 TOP_MUX(CK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents,
268 0x040, 0x044, 0x048, 16, 1, 23, 0x1C0, 18),
269 TOP_MUX(CK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents,
270 0x040, 0x044, 0x048, 24, 3, 31, 0x1C0, 19),
271 /* CLK_CFG_5 */
272 TOP_MUX(CK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x050,
273 0x054, 0x058, 0, 2, 7, 0x1C0, 20),
274 TOP_MUX(CK_TOP_SGM_325M_SEL, "sgm_325m_sel", sgm_325m_parents, 0x050,
275 0x054, 0x058, 8, 1, 15, 0x1C0, 21),
276 TOP_MUX(CK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents, 0x050,
277 0x054, 0x058, 16, 1, 23, 0x1C0, 22),
278 TOP_MUX(CK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x050, 0x054,
279 0x058, 24, 1, 31, 0x1C0, 23),
280 /* CLK_CFG_6 */
281 TOP_MUX(CK_TOP_CONN_MCUSYS_SEL, "conn_mcusys_sel", conn_mcusys_parents,
282 0x060, 0x064, 0x068, 0, 1, 7, 0x1C0, 24),
283 TOP_MUX(CK_TOP_EIP_B_SEL, "eip_b_sel", eip_b_parents, 0x060, 0x064,
284 0x068, 8, 1, 15, 0x1C0, 25),
285 TOP_MUX(CK_TOP_PCIE_PHY_SEL, "pcie_phy_sel", f_26m_adc_parents, 0x060,
286 0x064, 0x068, 16, 1, 23, 0x1C0, 26),
287 TOP_MUX(CK_TOP_USB3_PHY_SEL, "usb3_phy_sel", f_26m_adc_parents, 0x060,
288 0x064, 0x068, 24, 1, 31, 0x1C0, 27),
289 /* CLK_CFG_7 */
290 TOP_MUX(CK_TOP_F26M_SEL, "csw_f26m_sel", f_26m_adc_parents, 0x070,
291 0x074, 0x078, 0, 1, 7, 0x1C0, 28),
292 TOP_MUX(CK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x070, 0x074,
293 0x078, 8, 2, 15, 0x1C0, 29),
294 TOP_MUX(CK_TOP_A_TUNER_SEL, "a_tuner_sel", a_tuner_parents, 0x070,
295 0x074, 0x078, 16, 2, 23, 0x1C0, 30),
296 TOP_MUX(CK_TOP_U2U3_SEL, "u2u3_sel", f_26m_adc_parents, 0x070, 0x074,
297 0x078, 24, 1, 31, 0x1C4, 0),
298 /* CLK_CFG_8 */
299 TOP_MUX(CK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel", u2u3_sys_parents, 0x080,
300 0x084, 0x088, 0, 1, 7, 0x1C4, 1),
301 TOP_MUX(CK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel", u2u3_sys_parents, 0x080,
302 0x084, 0x088, 8, 1, 15, 0x1C4, 2),
303 TOP_MUX(CK_TOP_DA_U2_REFSEL, "da_u2_refsel", da_u2_refsel_parents,
304 0x080, 0x084, 0x088, 16, 1, 23, 0x1C4, 3),
305 TOP_MUX(CK_TOP_DA_U2_CK_1P_SEL, "da_u2_ck_1p_sel", da_u2_refsel_parents,
306 0x080, 0x084, 0x088, 24, 1, 31, 0x1C4, 4),
307 /* CLK_CFG_9 */
308 TOP_MUX(CK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel", sgm_reg_parents,
309 0x090, 0x094, 0x098, 0, 1, 7, 0x1C4, 5),
310};
311
312/* INFRA FIXED DIV */
313static const struct mtk_fixed_factor infra_fixed_divs[] = {
Christian Marangi7739a5f2024-08-03 10:40:36 +0200314 TOP_FACTOR(CK_INFRA_SYSAXI_D2, "infra_sysaxi_d2", CK_TOP_SYSAXI_SEL, 1, 2),
developer37161fe2022-09-09 20:00:09 +0800315};
316
317/* INFRASYS MUX PARENTS */
Christian Marangiab4de132024-08-03 10:40:38 +0200318#define INFRA_PARENT(_id) PARENT(_id, CLK_PARENT_INFRASYS)
319#define TOP_PARENT(_id) PARENT(_id, CLK_PARENT_TOPCKGEN)
320#define VOID_PARENT PARENT(-1, 0)
developer37161fe2022-09-09 20:00:09 +0800321
Christian Marangiab4de132024-08-03 10:40:38 +0200322static const struct mtk_parent infra_uart0_parents[] = {
323 TOP_PARENT(CK_TOP_F26M_SEL),
324 TOP_PARENT(CK_TOP_UART_SEL)
325};
326
327static const struct mtk_parent infra_spi0_parents[] = {
328 TOP_PARENT(CK_TOP_I2C_SEL),
329 TOP_PARENT(CK_TOP_SPI_SEL)
330};
developer37161fe2022-09-09 20:00:09 +0800331
Christian Marangiab4de132024-08-03 10:40:38 +0200332static const struct mtk_parent infra_spi1_parents[] = {
333 TOP_PARENT(CK_TOP_I2C_SEL),
334 TOP_PARENT(CK_TOP_SPINFI_SEL)
335};
developer37161fe2022-09-09 20:00:09 +0800336
Christian Marangiab4de132024-08-03 10:40:38 +0200337static const struct mtk_parent infra_pwm_bsel_parents[] = {
Christian Marangi9276f072024-08-03 10:40:41 +0200338 TOP_PARENT(CK_TOP_RTC_32P7K),
Christian Marangiab4de132024-08-03 10:40:38 +0200339 TOP_PARENT(CK_TOP_F26M_SEL),
340 INFRA_PARENT(CK_INFRA_SYSAXI_D2),
341 TOP_PARENT(CK_TOP_PWM_SEL)
342};
developer37161fe2022-09-09 20:00:09 +0800343
Christian Marangiab4de132024-08-03 10:40:38 +0200344static const struct mtk_parent infra_pcie_parents[] = {
Christian Marangi9276f072024-08-03 10:40:41 +0200345 TOP_PARENT(CK_TOP_RTC_32P7K),
Christian Marangiab4de132024-08-03 10:40:38 +0200346 TOP_PARENT(CK_TOP_F26M_SEL),
Christian Marangi6a89a382024-08-03 10:40:39 +0200347 TOP_PARENT(CK_TOP_XTAL),
Christian Marangiab4de132024-08-03 10:40:38 +0200348 TOP_PARENT(CK_TOP_PEXTP_TL_SEL)
349};
developer37161fe2022-09-09 20:00:09 +0800350
351#define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \
352 { \
353 .id = _id, .mux_reg = (_reg) + 0x8, \
354 .mux_set_reg = (_reg) + 0x0, .mux_clr_reg = (_reg) + 0x4, \
355 .mux_shift = _shift, .mux_mask = BIT(_width) - 1, \
Christian Marangiab4de132024-08-03 10:40:38 +0200356 .parent_flags = _parents, .num_parents = ARRAY_SIZE(_parents), \
357 .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \
developer37161fe2022-09-09 20:00:09 +0800358 }
359
360/* INFRA MUX */
361
362static const struct mtk_composite infra_muxes[] = {
363 /* MODULE_CLK_SEL_0 */
364 INFRA_MUX(CK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart0_parents,
365 0x10, 0, 1),
366 INFRA_MUX(CK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart0_parents,
367 0x10, 1, 1),
368 INFRA_MUX(CK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart0_parents,
369 0x10, 2, 1),
370 INFRA_MUX(CK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x10,
371 4, 1),
372 INFRA_MUX(CK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x10,
373 5, 1),
374 INFRA_MUX(CK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm_bsel_parents,
375 0x10, 9, 2),
376 INFRA_MUX(CK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm_bsel_parents,
377 0x10, 11, 2),
378 INFRA_MUX(CK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents,
379 0x10, 13, 2),
380 /* MODULE_CLK_SEL_1 */
381 INFRA_MUX(CK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x20,
382 0, 2),
383};
384
385static const struct mtk_gate_regs infra_0_cg_regs = {
386 .set_ofs = 0x40,
387 .clr_ofs = 0x44,
388 .sta_ofs = 0x48,
389};
390
391static const struct mtk_gate_regs infra_1_cg_regs = {
392 .set_ofs = 0x50,
393 .clr_ofs = 0x54,
394 .sta_ofs = 0x58,
395};
396
397static const struct mtk_gate_regs infra_2_cg_regs = {
398 .set_ofs = 0x60,
399 .clr_ofs = 0x64,
400 .sta_ofs = 0x68,
401};
402
Christian Marangiab4de132024-08-03 10:40:38 +0200403#define GATE_INFRA0(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800404 { \
405 .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \
406 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200407 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800408 }
Christian Marangiab4de132024-08-03 10:40:38 +0200409#define GATE_INFRA0_INFRA(_id, _name, _parent, _shift) \
410 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
411#define GATE_INFRA0_TOP(_id, _name, _parent, _shift) \
412 GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800413
Christian Marangiab4de132024-08-03 10:40:38 +0200414#define GATE_INFRA1(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800415 { \
416 .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \
417 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200418 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800419 }
Christian Marangiab4de132024-08-03 10:40:38 +0200420#define GATE_INFRA1_INFRA(_id, _name, _parent, _shift) \
421 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
422#define GATE_INFRA1_TOP(_id, _name, _parent, _shift) \
423 GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800424
Christian Marangiab4de132024-08-03 10:40:38 +0200425#define GATE_INFRA2(_id, _name, _parent, _shift, _flags) \
developer37161fe2022-09-09 20:00:09 +0800426 { \
427 .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \
428 .shift = _shift, \
Christian Marangiab4de132024-08-03 10:40:38 +0200429 .flags = _flags, \
developer37161fe2022-09-09 20:00:09 +0800430 }
Christian Marangiab4de132024-08-03 10:40:38 +0200431#define GATE_INFRA2_INFRA(_id, _name, _parent, _shift) \
432 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS)
433#define GATE_INFRA2_TOP(_id, _name, _parent, _shift) \
434 GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN)
developer37161fe2022-09-09 20:00:09 +0800435
436/* INFRA GATE */
437
438static const struct mtk_gate infracfg_ao_gates[] = {
439 /* INFRA0 */
Christian Marangiab4de132024-08-03 10:40:38 +0200440 GATE_INFRA0_INFRA(CK_INFRA_GPT_STA, "infra_gpt_sta", CK_INFRA_SYSAXI_D2, 0),
441 GATE_INFRA0_INFRA(CK_INFRA_PWM_HCK, "infra_pwm_hck", CK_INFRA_SYSAXI_D2, 1),
442 GATE_INFRA0_INFRA(CK_INFRA_PWM_STA, "infra_pwm_sta", CK_INFRA_PWM_BSEL, 2),
443 GATE_INFRA0_INFRA(CK_INFRA_PWM1_CK, "infra_pwm1", CK_INFRA_PWM1_SEL, 3),
444 GATE_INFRA0_INFRA(CK_INFRA_PWM2_CK, "infra_pwm2", CK_INFRA_PWM2_SEL, 4),
445 GATE_INFRA0_TOP(CK_INFRA_CQ_DMA_CK, "infra_cq_dma", CK_TOP_SYSAXI_SEL, 6),
446 GATE_INFRA0_TOP(CK_INFRA_EIP97_CK, "infra_eip97", CK_TOP_EIP_B_SEL, 7),
447 GATE_INFRA0_TOP(CK_INFRA_AUD_BUS_CK, "infra_aud_bus", CK_TOP_SYSAXI_SEL, 8),
448 GATE_INFRA0_TOP(CK_INFRA_AUD_26M_CK, "infra_aud_26m", CK_TOP_F26M_SEL, 9),
449 GATE_INFRA0_TOP(CK_INFRA_AUD_L_CK, "infra_aud_l", CK_TOP_AUD_L_SEL, 10),
450 GATE_INFRA0_TOP(CK_INFRA_AUD_AUD_CK, "infra_aud_aud", CK_TOP_A1SYS_SEL,
451 11),
452 GATE_INFRA0_TOP(CK_INFRA_AUD_EG2_CK, "infra_aud_eg2", CK_TOP_A_TUNER_SEL,
453 13),
454 GATE_INFRA0_TOP(CK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", CK_TOP_F26M_SEL,
455 14),
456 GATE_INFRA0_INFRA(CK_INFRA_DBG_CK, "infra_dbg", CK_INFRA_SYSAXI_D2, 15),
457 GATE_INFRA0_INFRA(CK_INFRA_AP_DMA_CK, "infra_ap_dma", CK_INFRA_SYSAXI_D2, 16),
458 GATE_INFRA0_INFRA(CK_INFRA_SEJ_CK, "infra_sej", CK_INFRA_SYSAXI_D2, 24),
459 GATE_INFRA0_TOP(CK_INFRA_SEJ_13M_CK, "infra_sej_13m", CK_TOP_F26M_SEL, 25),
460 GATE_INFRA0_TOP(CK_INFRA_TRNG_CK, "infra_trng", CK_TOP_SYSAXI_SEL, 26),
developer37161fe2022-09-09 20:00:09 +0800461 /* INFRA1 */
Christian Marangiab4de132024-08-03 10:40:38 +0200462 GATE_INFRA1_TOP(CK_INFRA_THERM_CK, "infra_therm", CK_TOP_F26M_SEL, 0),
Christian Marangi30c4b862024-08-03 10:40:40 +0200463 GATE_INFRA1_TOP(CK_INFRA_I2C0_CK, "infra_i2co", CK_TOP_I2C_SEL, 1),
Christian Marangiab4de132024-08-03 10:40:38 +0200464 GATE_INFRA1_INFRA(CK_INFRA_UART0_CK, "infra_uart0", CK_INFRA_UART0_SEL, 2),
465 GATE_INFRA1_INFRA(CK_INFRA_UART1_CK, "infra_uart1", CK_INFRA_UART1_SEL, 3),
466 GATE_INFRA1_INFRA(CK_INFRA_UART2_CK, "infra_uart2", CK_INFRA_UART2_SEL, 4),
467 GATE_INFRA1_TOP(CK_INFRA_NFI1_CK, "infra_nfi1", CK_TOP_NFI1X_SEL, 8),
468 GATE_INFRA1_TOP(CK_INFRA_SPINFI1_CK, "infra_spinfi1", CK_TOP_SPINFI_SEL,
469 9),
470 GATE_INFRA1_INFRA(CK_INFRA_NFI_HCK_CK, "infra_nfi_hck", CK_INFRA_SYSAXI_D2, 10),
471 GATE_INFRA1_INFRA(CK_INFRA_SPI0_CK, "infra_spi0", CK_INFRA_SPI0_SEL, 11),
472 GATE_INFRA1_INFRA(CK_INFRA_SPI1_CK, "infra_spi1", CK_INFRA_SPI1_SEL, 12),
473 GATE_INFRA1_INFRA(CK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", CK_INFRA_SYSAXI_D2,
474 13),
475 GATE_INFRA1_INFRA(CK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", CK_INFRA_SYSAXI_D2,
476 14),
Christian Marangi9276f072024-08-03 10:40:41 +0200477 GATE_INFRA1_TOP(CK_INFRA_FRTC_CK, "infra_frtc", CK_TOP_RTC_32K, 15),
Christian Marangiab4de132024-08-03 10:40:38 +0200478 GATE_INFRA1_TOP(CK_INFRA_MSDC_CK, "infra_msdc", CK_TOP_EMMC_416M_SEL, 16),
479 GATE_INFRA1_TOP(CK_INFRA_MSDC_HCK_CK, "infra_msdc_hck",
480 CK_TOP_EMMC_250M_SEL, 17),
481 GATE_INFRA1_TOP(CK_INFRA_MSDC_133M_CK, "infra_msdc_133m",
482 CK_TOP_SYSAXI_SEL, 18),
483 GATE_INFRA1_INFRA(CK_INFRA_MSDC_66M_CK, "infra_msdc_66m", CK_INFRA_SYSAXI_D2,
484 19),
485 GATE_INFRA1_INFRA(CK_INFRA_ADC_26M_CK, "infra_adc_26m", CK_INFRA_ADC_FRC_CK, 20),
486 GATE_INFRA1_TOP(CK_INFRA_ADC_FRC_CK, "infra_adc_frc", CK_TOP_F26M_SEL, 21),
487 GATE_INFRA1_TOP(CK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", CK_TOP_NFI1X_SEL,
488 23),
developer37161fe2022-09-09 20:00:09 +0800489 /* INFRA2 */
Christian Marangiab4de132024-08-03 10:40:38 +0200490 GATE_INFRA2_TOP(CK_INFRA_IUSB_133_CK, "infra_iusb_133", CK_TOP_SYSAXI_SEL,
491 0),
492 GATE_INFRA2_INFRA(CK_INFRA_IUSB_66M_CK, "infra_iusb_66m", CK_INFRA_SYSAXI_D2,
493 1),
494 GATE_INFRA2_TOP(CK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", CK_TOP_U2U3_SYS_SEL,
495 2),
496 GATE_INFRA2_TOP(CK_INFRA_IUSB_CK, "infra_iusb", CK_TOP_U2U3_SEL, 3),
497 GATE_INFRA2_TOP(CK_INFRA_IPCIE_CK, "infra_ipcie", CK_TOP_PEXTP_TL_SEL, 12),
Christian Marangi6a89a382024-08-03 10:40:39 +0200498 GATE_INFRA2_TOP(CK_INFRA_IPCIE_PIPE_CK, "infra_ipcie_pipe", CK_TOP_XTAL, 13),
Christian Marangiab4de132024-08-03 10:40:38 +0200499 GATE_INFRA2_TOP(CK_INFRA_IPCIER_CK, "infra_ipcier", CK_TOP_F26M_SEL, 14),
500 GATE_INFRA2_TOP(CK_INFRA_IPCIEB_CK, "infra_ipcieb", CK_TOP_SYSAXI_SEL, 15),
developer37161fe2022-09-09 20:00:09 +0800501};
502
503static const struct mtk_clk_tree mt7986_fixed_pll_clk_tree = {
504 .fdivs_offs = CLK_APMIXED_NR_CLK,
505 .xtal_rate = 40 * MHZ,
506 .fclks = fixed_pll_clks,
507};
508
509static const struct mtk_clk_tree mt7986_topckgen_clk_tree = {
Christian Marangi9276f072024-08-03 10:40:41 +0200510 .fdivs_offs = CK_TOP_MPLL_416M,
developer37161fe2022-09-09 20:00:09 +0800511 .muxes_offs = CK_TOP_NFI1X_SEL,
512 .fclks = top_fixed_clks,
513 .fdivs = top_fixed_divs,
514 .muxes = top_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200515 .flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
developer37161fe2022-09-09 20:00:09 +0800516};
517
518static const struct mtk_clk_tree mt7986_infracfg_clk_tree = {
Christian Marangiab4de132024-08-03 10:40:38 +0200519 .fdivs_offs = CK_INFRA_SYSAXI_D2,
developer37161fe2022-09-09 20:00:09 +0800520 .muxes_offs = CK_INFRA_UART0_SEL,
521 .fdivs = infra_fixed_divs,
522 .muxes = infra_muxes,
Christian Marangiab4de132024-08-03 10:40:38 +0200523 .flags = CLK_INFRASYS,
developer37161fe2022-09-09 20:00:09 +0800524};
525
526static const struct udevice_id mt7986_fixed_pll_compat[] = {
527 { .compatible = "mediatek,mt7986-fixed-plls" },
Christian Marangi4dd4a282024-06-24 23:03:40 +0200528 { .compatible = "mediatek,mt7986-apmixedsys" },
developer37161fe2022-09-09 20:00:09 +0800529 {}
530};
531
532static const struct udevice_id mt7986_topckgen_compat[] = {
533 { .compatible = "mediatek,mt7986-topckgen" },
534 {}
535};
536
537static int mt7986_fixed_pll_probe(struct udevice *dev)
538{
539 return mtk_common_clk_init(dev, &mt7986_fixed_pll_clk_tree);
540}
541
542static int mt7986_topckgen_probe(struct udevice *dev)
543{
544 struct mtk_clk_priv *priv = dev_get_priv(dev);
545
546 priv->base = dev_read_addr_ptr(dev);
547 writel(MT7986_CLK_PDN_EN_WRITE, priv->base + MT7986_CLK_PDN);
548
549 return mtk_common_clk_init(dev, &mt7986_topckgen_clk_tree);
550}
551
552U_BOOT_DRIVER(mtk_clk_apmixedsys) = {
553 .name = "mt7986-clock-fixed-pll",
554 .id = UCLASS_CLK,
555 .of_match = mt7986_fixed_pll_compat,
556 .probe = mt7986_fixed_pll_probe,
557 .priv_auto = sizeof(struct mtk_clk_priv),
558 .ops = &mtk_clk_topckgen_ops,
559 .flags = DM_FLAG_PRE_RELOC,
560};
561
562U_BOOT_DRIVER(mtk_clk_topckgen) = {
563 .name = "mt7986-clock-topckgen",
564 .id = UCLASS_CLK,
565 .of_match = mt7986_topckgen_compat,
566 .probe = mt7986_topckgen_probe,
567 .priv_auto = sizeof(struct mtk_clk_priv),
568 .ops = &mtk_clk_topckgen_ops,
569 .flags = DM_FLAG_PRE_RELOC,
570};
571
572static const struct udevice_id mt7986_infracfg_compat[] = {
573 { .compatible = "mediatek,mt7986-infracfg" },
574 {}
575};
576
577static const struct udevice_id mt7986_infracfg_ao_compat[] = {
578 { .compatible = "mediatek,mt7986-infracfg_ao" },
579 {}
580};
581
582static int mt7986_infracfg_probe(struct udevice *dev)
583{
584 return mtk_common_clk_init(dev, &mt7986_infracfg_clk_tree);
585}
586
587static int mt7986_infracfg_ao_probe(struct udevice *dev)
588{
589 return mtk_common_clk_gate_init(dev, &mt7986_infracfg_clk_tree,
590 infracfg_ao_gates);
591}
592
593U_BOOT_DRIVER(mtk_clk_infracfg) = {
594 .name = "mt7986-clock-infracfg",
595 .id = UCLASS_CLK,
596 .of_match = mt7986_infracfg_compat,
597 .probe = mt7986_infracfg_probe,
598 .priv_auto = sizeof(struct mtk_clk_priv),
599 .ops = &mtk_clk_infrasys_ops,
600 .flags = DM_FLAG_PRE_RELOC,
601};
602
603U_BOOT_DRIVER(mtk_clk_infracfg_ao) = {
604 .name = "mt7986-clock-infracfg-ao",
605 .id = UCLASS_CLK,
606 .of_match = mt7986_infracfg_ao_compat,
607 .probe = mt7986_infracfg_ao_probe,
608 .priv_auto = sizeof(struct mtk_cg_priv),
609 .ops = &mtk_clk_gate_ops,
610 .flags = DM_FLAG_PRE_RELOC,
611};
612
613/* ethsys */
614static const struct mtk_gate_regs eth_cg_regs = {
615 .sta_ofs = 0x30,
616};
617
618#define GATE_ETH(_id, _name, _parent, _shift) \
619 { \
620 .id = _id, .parent = _parent, .regs = &eth_cg_regs, \
621 .shift = _shift, \
622 .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \
623 }
624
625static const struct mtk_gate eth_cgs[] = {
626 GATE_ETH(CK_ETH_FE_EN, "eth_fe_en", CK_TOP_NETSYS_2X, 7),
627 GATE_ETH(CK_ETH_GP2_EN, "eth_gp2_en", CK_TOP_SGM_325M, 8),
628 GATE_ETH(CK_ETH_GP1_EN, "eth_gp1_en", CK_TOP_SGM_325M, 8),
629 GATE_ETH(CK_ETH_WOCPU1_EN, "eth_wocpu1_en", CK_TOP_NETSYS_WED_MCU, 14),
630 GATE_ETH(CK_ETH_WOCPU0_EN, "eth_wocpu0_en", CK_TOP_NETSYS_WED_MCU, 15),
631};
632
633static int mt7986_ethsys_probe(struct udevice *dev)
634{
635 return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree,
636 eth_cgs);
637}
638
639static int mt7986_ethsys_bind(struct udevice *dev)
640{
641 int ret = 0;
642
643 if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) {
644 ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1);
645 if (ret)
646 debug("Warning: failed to bind reset controller\n");
647 }
648
649 return ret;
650}
651
652static const struct udevice_id mt7986_ethsys_compat[] = {
653 { .compatible = "mediatek,mt7986-ethsys" },
654 { }
655};
656
657U_BOOT_DRIVER(mtk_clk_ethsys) = {
658 .name = "mt7986-clock-ethsys",
659 .id = UCLASS_CLK,
660 .of_match = mt7986_ethsys_compat,
661 .probe = mt7986_ethsys_probe,
662 .bind = mt7986_ethsys_bind,
663 .priv_auto = sizeof(struct mtk_cg_priv),
664 .ops = &mtk_clk_gate_ops,
665};