developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * MediaTek clock driver for MT7981 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/mt7981-clk.h> |
| 14 | #include <linux/bitops.h> |
| 15 | |
| 16 | #include "clk-mtk.h" |
| 17 | |
| 18 | #define MT7981_CLK_PDN 0x250 |
| 19 | #define MT7981_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 */ |
| 31 | static const struct mtk_fixed_clk fixed_pll_clks[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 32 | FIXED_CLK(CLK_APMIXED_ARMPLL, CLK_XTAL, 1300000000), |
| 33 | FIXED_CLK(CLK_APMIXED_NET2PLL, CLK_XTAL, 800000000), |
| 34 | FIXED_CLK(CLK_APMIXED_MMPLL, CLK_XTAL, 720000000), |
| 35 | FIXED_CLK(CLK_APMIXED_SGMPLL, CLK_XTAL, 325000000), |
| 36 | FIXED_CLK(CLK_APMIXED_WEDMCUPLL, CLK_XTAL, 208000000), |
| 37 | FIXED_CLK(CLK_APMIXED_NET1PLL, CLK_XTAL, 2500000000), |
| 38 | FIXED_CLK(CLK_APMIXED_MPLL, CLK_XTAL, 416000000), |
| 39 | FIXED_CLK(CLK_APMIXED_APLL2, CLK_XTAL, 196608000), |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | /* TOPCKGEN FIXED CLK */ |
| 43 | static const struct mtk_fixed_clk top_fixed_clks[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 44 | FIXED_CLK(CLK_TOP_CB_CKSQ_40M, CLK_XTAL, 40000000), |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | /* TOPCKGEN FIXED DIV */ |
| 48 | static const struct mtk_fixed_factor top_fixed_divs[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 49 | PLL_FACTOR(CLK_TOP_CB_M_416M, "cb_m_416m", CLK_APMIXED_MPLL, 1, 1), |
| 50 | PLL_FACTOR(CLK_TOP_CB_M_D2, "cb_m_d2", CLK_APMIXED_MPLL, 1, 2), |
| 51 | PLL_FACTOR(CLK_TOP_CB_M_D3, "cb_m_d3", CLK_APMIXED_MPLL, 1, 3), |
| 52 | PLL_FACTOR(CLK_TOP_M_D3_D2, "m_d3_d2", CLK_APMIXED_MPLL, 1, 2), |
| 53 | PLL_FACTOR(CLK_TOP_CB_M_D4, "cb_m_d4", CLK_APMIXED_MPLL, 1, 4), |
| 54 | PLL_FACTOR(CLK_TOP_CB_M_D8, "cb_m_d8", CLK_APMIXED_MPLL, 1, 8), |
| 55 | PLL_FACTOR(CLK_TOP_M_D8_D2, "m_d8_d2", CLK_APMIXED_MPLL, 1, 16), |
| 56 | PLL_FACTOR(CLK_TOP_CB_MM_720M, "cb_mm_720m", CLK_APMIXED_MMPLL, 1, 1), |
| 57 | PLL_FACTOR(CLK_TOP_CB_MM_D2, "cb_mm_d2", CLK_APMIXED_MMPLL, 1, 2), |
| 58 | PLL_FACTOR(CLK_TOP_CB_MM_D3, "cb_mm_d3", CLK_APMIXED_MMPLL, 1, 3), |
| 59 | PLL_FACTOR(CLK_TOP_CB_MM_D3_D5, "cb_mm_d3_d5", CLK_APMIXED_MMPLL, 1, 15), |
| 60 | PLL_FACTOR(CLK_TOP_CB_MM_D4, "cb_mm_d4", CLK_APMIXED_MMPLL, 1, 4), |
| 61 | PLL_FACTOR(CLK_TOP_CB_MM_D6, "cb_mm_d6", CLK_APMIXED_MMPLL, 1, 6), |
| 62 | PLL_FACTOR(CLK_TOP_MM_D6_D2, "mm_d6_d2", CLK_APMIXED_MMPLL, 1, 12), |
| 63 | PLL_FACTOR(CLK_TOP_CB_MM_D8, "cb_mm_d8", CLK_APMIXED_MMPLL, 1, 8), |
| 64 | PLL_FACTOR(CLK_TOP_CB_APLL2_196M, "cb_apll2_196m", CLK_APMIXED_APLL2, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 65 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 66 | PLL_FACTOR(CLK_TOP_APLL2_D2, "apll2_d2", CLK_APMIXED_APLL2, 1, 2), |
| 67 | PLL_FACTOR(CLK_TOP_APLL2_D4, "apll2_d4", CLK_APMIXED_APLL2, 1, 4), |
| 68 | PLL_FACTOR(CLK_TOP_NET1_2500M, "net1_2500m", CLK_APMIXED_NET1PLL, 1, 1), |
| 69 | PLL_FACTOR(CLK_TOP_CB_NET1_D4, "cb_net1_d4", CLK_APMIXED_NET1PLL, 1, 4), |
| 70 | PLL_FACTOR(CLK_TOP_CB_NET1_D5, "cb_net1_d5", CLK_APMIXED_NET1PLL, 1, 5), |
| 71 | PLL_FACTOR(CLK_TOP_NET1_D5_D2, "net1_d5_d2", CLK_APMIXED_NET1PLL, 1, 10), |
| 72 | PLL_FACTOR(CLK_TOP_NET1_D5_D4, "net1_d5_d4", CLK_APMIXED_NET1PLL, 1, 20), |
| 73 | PLL_FACTOR(CLK_TOP_CB_NET1_D8, "cb_net1_d8", CLK_APMIXED_NET1PLL, 1, 8), |
| 74 | PLL_FACTOR(CLK_TOP_NET1_D8_D2, "net1_d8_d2", CLK_APMIXED_NET1PLL, 1, 16), |
| 75 | PLL_FACTOR(CLK_TOP_NET1_D8_D4, "net1_d8_d4", CLK_APMIXED_NET1PLL, 1, 32), |
| 76 | PLL_FACTOR(CLK_TOP_CB_NET2_800M, "cb_net2_800m", CLK_APMIXED_NET2PLL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 77 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 78 | PLL_FACTOR(CLK_TOP_CB_NET2_D2, "cb_net2_d2", CLK_APMIXED_NET2PLL, 1, 2), |
| 79 | PLL_FACTOR(CLK_TOP_CB_NET2_D4, "cb_net2_d4", CLK_APMIXED_NET2PLL, 1, 4), |
| 80 | PLL_FACTOR(CLK_TOP_NET2_D4_D2, "net2_d4_d2", CLK_APMIXED_NET2PLL, 1, 8), |
| 81 | PLL_FACTOR(CLK_TOP_NET2_D4_D4, "net2_d4_d4", CLK_APMIXED_NET2PLL, 1, 16), |
| 82 | PLL_FACTOR(CLK_TOP_CB_NET2_D6, "cb_net2_d6", CLK_APMIXED_NET2PLL, 1, 6), |
| 83 | PLL_FACTOR(CLK_TOP_CB_WEDMCU_208M, "cb_wedmcu_208m", |
| 84 | CLK_APMIXED_WEDMCUPLL, 1, 1), |
| 85 | PLL_FACTOR(CLK_TOP_CB_SGM_325M, "cb_sgm_325m", CLK_APMIXED_SGMPLL, 1, 1), |
| 86 | TOP_FACTOR(CLK_TOP_CKSQ_40M_D2, "cksq_40m_d2", CLK_TOP_CB_CKSQ_40M, 1, 2), |
| 87 | TOP_FACTOR(CLK_TOP_CB_RTC_32K, "cb_rtc_32k", CLK_TOP_CB_CKSQ_40M, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 88 | 1250), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 89 | TOP_FACTOR(CLK_TOP_CB_RTC_32P7K, "cb_rtc_32p7k", CLK_TOP_CB_CKSQ_40M, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 90 | 1220), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 91 | TOP_FACTOR(CLK_TOP_USB_TX250M, "usb_tx250m", CLK_TOP_CB_CKSQ_40M, 1, 1), |
| 92 | TOP_FACTOR(CLK_TOP_FAUD, "faud", CLK_TOP_AUD_SEL, 1, 1), |
| 93 | TOP_FACTOR(CLK_TOP_NFI1X, "nfi1x", CLK_TOP_NFI1X_SEL, 1, 1), |
| 94 | TOP_FACTOR(CLK_TOP_USB_EQ_RX250M, "usb_eq_rx250m", CLK_TOP_CB_CKSQ_40M, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 95 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 96 | TOP_FACTOR(CLK_TOP_USB_CDR_CK, "usb_cdr", CLK_TOP_CB_CKSQ_40M, 1, 1), |
| 97 | TOP_FACTOR(CLK_TOP_USB_LN0_CK, "usb_ln0", CLK_TOP_CB_CKSQ_40M, 1, 1), |
| 98 | TOP_FACTOR(CLK_TOP_SPINFI_BCK, "spinfi_bck", CLK_TOP_SPINFI_SEL, 1, 1), |
| 99 | TOP_FACTOR(CLK_TOP_SPI, "spi", CLK_TOP_SPI_SEL, 1, 1), |
| 100 | TOP_FACTOR(CLK_TOP_SPIM_MST, "spim_mst", CLK_TOP_SPIM_MST_SEL, 1, 1), |
| 101 | TOP_FACTOR(CLK_TOP_UART_BCK, "uart_bck", CLK_TOP_UART_SEL, 1, 1), |
| 102 | TOP_FACTOR(CLK_TOP_PWM_BCK, "pwm_bck", CLK_TOP_PWM_SEL, 1, 1), |
| 103 | TOP_FACTOR(CLK_TOP_I2C_BCK, "i2c_bck", CLK_TOP_I2C_SEL, 1, 1), |
| 104 | TOP_FACTOR(CLK_TOP_PEXTP_TL, "pextp_tl", CLK_TOP_PEXTP_TL_SEL, 1, 1), |
| 105 | TOP_FACTOR(CLK_TOP_EMMC_208M, "emmc_208m", CLK_TOP_EMMC_208M_SEL, 1, 1), |
| 106 | TOP_FACTOR(CLK_TOP_EMMC_400M, "emmc_400m", CLK_TOP_EMMC_400M_SEL, 1, 1), |
| 107 | TOP_FACTOR(CLK_TOP_DRAMC_REF, "dramc_ref", CLK_TOP_DRAMC_SEL, 1, 1), |
| 108 | TOP_FACTOR(CLK_TOP_DRAMC_MD32, "dramc_md32", CLK_TOP_DRAMC_MD32_SEL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 109 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 110 | TOP_FACTOR(CLK_TOP_SYSAXI, "sysaxi", CLK_TOP_SYSAXI_SEL, 1, 1), |
| 111 | TOP_FACTOR(CLK_TOP_SYSAPB, "sysapb", CLK_TOP_SYSAPB_SEL, 1, 1), |
| 112 | TOP_FACTOR(CLK_TOP_ARM_DB_MAIN, "arm_db_main", CLK_TOP_ARM_DB_MAIN_SEL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 113 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 114 | TOP_FACTOR(CLK_TOP_AP2CNN_HOST, "ap2cnn_host", CLK_TOP_AP2CNN_HOST_SEL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 115 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 116 | TOP_FACTOR(CLK_TOP_NETSYS, "netsys", CLK_TOP_NETSYS_SEL, 1, 1), |
| 117 | TOP_FACTOR(CLK_TOP_NETSYS_500M, "netsys_500m", CLK_TOP_NETSYS_500M_SEL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 118 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 119 | TOP_FACTOR(CLK_TOP_NETSYS_WED_MCU, "netsys_wed_mcu", |
| 120 | CLK_TOP_NETSYS_MCU_SEL, 1, 1), |
| 121 | TOP_FACTOR(CLK_TOP_NETSYS_2X, "netsys_2x", CLK_TOP_NETSYS_2X_SEL, 1, 1), |
| 122 | TOP_FACTOR(CLK_TOP_SGM_325M, "sgm_325m", CLK_TOP_SGM_325M_SEL, 1, 1), |
| 123 | TOP_FACTOR(CLK_TOP_SGM_REG, "sgm_reg", CLK_TOP_SGM_REG_SEL, 1, 1), |
| 124 | TOP_FACTOR(CLK_TOP_F26M, "csw_f26m", CLK_TOP_F26M_SEL, 1, 1), |
| 125 | TOP_FACTOR(CLK_TOP_EIP97B, "eip97b", CLK_TOP_EIP97B_SEL, 1, 1), |
| 126 | TOP_FACTOR(CLK_TOP_USB3_PHY, "usb3_phy", CLK_TOP_USB3_PHY_SEL, 1, 1), |
| 127 | TOP_FACTOR(CLK_TOP_AUD, "aud", CLK_TOP_FAUD, 1, 1), |
| 128 | TOP_FACTOR(CLK_TOP_A1SYS, "a1sys", CLK_TOP_A1SYS_SEL, 1, 1), |
| 129 | TOP_FACTOR(CLK_TOP_AUD_L, "aud_l", CLK_TOP_AUD_L_SEL, 1, 1), |
| 130 | TOP_FACTOR(CLK_TOP_A_TUNER, "a_tuner", CLK_TOP_A_TUNER_SEL, 1, 1), |
| 131 | TOP_FACTOR(CLK_TOP_U2U3_REF, "u2u3_ref", CLK_TOP_U2U3_SEL, 1, 1), |
| 132 | TOP_FACTOR(CLK_TOP_U2U3_SYS, "u2u3_sys", CLK_TOP_U2U3_SYS_SEL, 1, 1), |
| 133 | TOP_FACTOR(CLK_TOP_U2U3_XHCI, "u2u3_xhci", CLK_TOP_U2U3_XHCI_SEL, 1, 1), |
| 134 | TOP_FACTOR(CLK_TOP_USB_FRMCNT, "usb_frmcnt", CLK_TOP_USB_FRMCNT_SEL, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 135 | 1), |
| 136 | }; |
| 137 | |
| 138 | /* TOPCKGEN MUX PARENTS */ |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 139 | static const int nfi1x_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_MM_D4, |
| 140 | CLK_TOP_NET1_D8_D2, CLK_TOP_CB_NET2_D6, |
| 141 | CLK_TOP_CB_M_D4, CLK_TOP_CB_MM_D8, |
| 142 | CLK_TOP_NET1_D8_D4, CLK_TOP_CB_M_D8 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 143 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 144 | static const int spinfi_parents[] = { CLK_TOP_CKSQ_40M_D2, CLK_TOP_CB_CKSQ_40M, |
| 145 | CLK_TOP_NET1_D5_D4, CLK_TOP_CB_M_D4, |
| 146 | CLK_TOP_CB_MM_D8, CLK_TOP_NET1_D8_D4, |
| 147 | CLK_TOP_MM_D6_D2, CLK_TOP_CB_M_D8 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 148 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 149 | static const int spi_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_M_D2, |
| 150 | CLK_TOP_CB_MM_D4, CLK_TOP_NET1_D8_D2, |
| 151 | CLK_TOP_CB_NET2_D6, CLK_TOP_NET1_D5_D4, |
| 152 | CLK_TOP_CB_M_D4, CLK_TOP_NET1_D8_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 153 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 154 | static const int uart_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_M_D8, |
| 155 | CLK_TOP_M_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 156 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 157 | static const int pwm_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_NET1_D8_D2, |
| 158 | CLK_TOP_NET1_D5_D4, CLK_TOP_CB_M_D4, |
| 159 | CLK_TOP_M_D8_D2, CLK_TOP_CB_RTC_32K }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 160 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 161 | static const int i2c_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_NET1_D5_D4, |
| 162 | CLK_TOP_CB_M_D4, CLK_TOP_NET1_D8_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 163 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 164 | static const int pextp_tl_ck_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 165 | CLK_TOP_NET1_D5_D4, CLK_TOP_CB_M_D4, |
| 166 | CLK_TOP_CB_RTC_32K }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 167 | |
| 168 | static const int emmc_208m_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 169 | CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_M_D2, CLK_TOP_CB_NET2_D4, |
| 170 | CLK_TOP_CB_APLL2_196M, CLK_TOP_CB_MM_D4, CLK_TOP_NET1_D8_D2, |
| 171 | CLK_TOP_CB_MM_D6 |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 172 | }; |
| 173 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 174 | static const int emmc_400m_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_NET2_D2, |
| 175 | CLK_TOP_CB_MM_D2, CLK_TOP_CB_NET2_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 176 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 177 | static const int csw_f26m_parents[] = { CLK_TOP_CKSQ_40M_D2, CLK_TOP_M_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 178 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 179 | static const int dramc_md32_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_M_D2, |
| 180 | CLK_TOP_CB_WEDMCU_208M }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 181 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 182 | static const int sysaxi_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_NET1_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 183 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 184 | static const int sysapb_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_M_D3_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 185 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 186 | static const int arm_db_main_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 187 | CLK_TOP_CB_NET2_D6 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 188 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 189 | static const int ap2cnn_host_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 190 | CLK_TOP_NET1_D8_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 191 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 192 | static const int netsys_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_MM_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 193 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 194 | static const int netsys_500m_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 195 | CLK_TOP_CB_NET1_D5 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 196 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 197 | static const int netsys_mcu_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_MM_720M, |
| 198 | CLK_TOP_CB_NET1_D4, CLK_TOP_CB_NET1_D5, |
| 199 | CLK_TOP_CB_M_416M }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 200 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 201 | static const int netsys_2x_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 202 | CLK_TOP_CB_NET2_800M, |
| 203 | CLK_TOP_CB_MM_720M }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 204 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 205 | static const int sgm_325m_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 206 | CLK_TOP_CB_SGM_325M }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 207 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 208 | static const int sgm_reg_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_NET2_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 209 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 210 | static const int eip97b_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_NET1_D5, |
| 211 | CLK_TOP_CB_M_416M, CLK_TOP_CB_MM_D2, |
| 212 | CLK_TOP_NET1_D5_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 213 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 214 | static const int aud_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_APLL2_196M }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 215 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 216 | static const int a1sys_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_APLL2_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 217 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 218 | static const int aud_l_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_CB_APLL2_196M, |
| 219 | CLK_TOP_M_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 220 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 221 | static const int a_tuner_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_APLL2_D4, |
| 222 | CLK_TOP_M_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 223 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 224 | static const int u2u3_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_M_D8_D2 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 225 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 226 | static const int u2u3_sys_parents[] = { CLK_TOP_CB_CKSQ_40M, CLK_TOP_NET1_D5_D4 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 227 | |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 228 | static const int usb_frmcnt_parents[] = { CLK_TOP_CB_CKSQ_40M, |
| 229 | CLK_TOP_CB_MM_D3_D5 }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 230 | |
| 231 | #define TOP_MUX(_id, _name, _parents, _mux_ofs, _mux_set_ofs, _mux_clr_ofs, \ |
| 232 | _shift, _width, _gate, _upd_ofs, _upd) \ |
| 233 | { \ |
| 234 | .id = _id, .mux_reg = _mux_ofs, .mux_set_reg = _mux_set_ofs, \ |
| 235 | .mux_clr_reg = _mux_clr_ofs, .upd_reg = _upd_ofs, \ |
| 236 | .upd_shift = _upd, .mux_shift = _shift, \ |
| 237 | .mux_mask = BIT(_width) - 1, .gate_reg = _mux_ofs, \ |
| 238 | .gate_shift = _gate, .parent = _parents, \ |
| 239 | .num_parents = ARRAY_SIZE(_parents), \ |
| 240 | .flags = CLK_MUX_SETCLR_UPD, \ |
| 241 | } |
| 242 | |
| 243 | /* TOPCKGEN MUX_GATE */ |
| 244 | static const struct mtk_composite top_muxes[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 245 | TOP_MUX(CLK_TOP_NFI1X_SEL, "nfi1x_sel", nfi1x_parents, 0x0, 0x4, 0x8, 0, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 246 | 3, 7, 0x1c0, 0), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 247 | TOP_MUX(CLK_TOP_SPINFI_SEL, "spinfi_sel", spinfi_parents, 0x0, 0x4, 0x8, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 248 | 8, 3, 15, 0x1c0, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 249 | TOP_MUX(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, 0x0, 0x4, 0x8, 16, 3, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 250 | 23, 0x1c0, 2), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 251 | TOP_MUX(CLK_TOP_SPIM_MST_SEL, "spim_mst_sel", spi_parents, 0x0, 0x4, 0x8, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 252 | 24, 3, 31, 0x1c0, 3), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 253 | TOP_MUX(CLK_TOP_UART_SEL, "uart_sel", uart_parents, 0x10, 0x14, 0x18, 0, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 254 | 2, 7, 0x1c0, 4), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 255 | TOP_MUX(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, 0x10, 0x14, 0x18, 8, 3, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 256 | 15, 0x1c0, 5), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 257 | TOP_MUX(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents, 0x10, 0x14, 0x18, 16, 2, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 258 | 23, 0x1c0, 6), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 259 | TOP_MUX(CLK_TOP_PEXTP_TL_SEL, "pextp_tl_ck_sel", pextp_tl_ck_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 260 | 0x10, 0x14, 0x18, 24, 2, 31, 0x1c0, 7), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 261 | TOP_MUX(CLK_TOP_EMMC_208M_SEL, "emmc_208m_sel", emmc_208m_parents, 0x20, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 262 | 0x24, 0x28, 0, 3, 7, 0x1c0, 8), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 263 | TOP_MUX(CLK_TOP_EMMC_400M_SEL, "emmc_400m_sel", emmc_400m_parents, 0x20, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 264 | 0x24, 0x28, 8, 2, 15, 0x1c0, 9), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 265 | TOP_MUX(CLK_TOP_F26M_SEL, "csw_f26m_sel", csw_f26m_parents, 0x20, 0x24, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 266 | 0x28, 16, 1, 23, 0x1c0, 10), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 267 | TOP_MUX(CLK_TOP_DRAMC_SEL, "dramc_sel", csw_f26m_parents, 0x20, 0x24, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 268 | 0x28, 24, 1, 31, 0x1c0, 11), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 269 | TOP_MUX(CLK_TOP_DRAMC_MD32_SEL, "dramc_md32_sel", dramc_md32_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 270 | 0x30, 0x34, 0x38, 0, 2, 7, 0x1c0, 12), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 271 | TOP_MUX(CLK_TOP_SYSAXI_SEL, "sysaxi_sel", sysaxi_parents, 0x30, 0x34, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 272 | 0x38, 8, 1, 15, 0x1c0, 13), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 273 | TOP_MUX(CLK_TOP_SYSAPB_SEL, "sysapb_sel", sysapb_parents, 0x30, 0x34, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 274 | 0x38, 16, 1, 23, 0x1c0, 14), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 275 | TOP_MUX(CLK_TOP_ARM_DB_MAIN_SEL, "arm_db_main_sel", arm_db_main_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 276 | 0x30, 0x34, 0x38, 24, 1, 31, 0x1c0, 15), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 277 | TOP_MUX(CLK_TOP_AP2CNN_HOST_SEL, "ap2cnn_host_sel", ap2cnn_host_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 278 | 0x40, 0x44, 0x48, 0, 1, 7, 0x1c0, 16), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 279 | TOP_MUX(CLK_TOP_NETSYS_SEL, "netsys_sel", netsys_parents, 0x40, 0x44, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 280 | 0x48, 8, 1, 15, 0x1c0, 17), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 281 | TOP_MUX(CLK_TOP_NETSYS_500M_SEL, "netsys_500m_sel", netsys_500m_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 282 | 0x40, 0x44, 0x48, 16, 1, 23, 0x1c0, 18), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 283 | TOP_MUX(CLK_TOP_NETSYS_MCU_SEL, "netsys_mcu_sel", netsys_mcu_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 284 | 0x40, 0x44, 0x48, 24, 3, 31, 0x1c0, 19), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 285 | TOP_MUX(CLK_TOP_NETSYS_2X_SEL, "netsys_2x_sel", netsys_2x_parents, 0x50, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 286 | 0x54, 0x58, 0, 2, 7, 0x1c0, 20), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 287 | TOP_MUX(CLK_TOP_SGM_325M_SEL, "sgm_325m_sel", sgm_325m_parents, 0x50, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 288 | 0x54, 0x58, 8, 1, 15, 0x1c0, 21), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 289 | TOP_MUX(CLK_TOP_SGM_REG_SEL, "sgm_reg_sel", sgm_reg_parents, 0x50, 0x54, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 290 | 0x58, 16, 1, 23, 0x1c0, 22), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 291 | TOP_MUX(CLK_TOP_EIP97B_SEL, "eip97b_sel", eip97b_parents, 0x50, 0x54, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 292 | 0x58, 24, 3, 31, 0x1c0, 23), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 293 | TOP_MUX(CLK_TOP_USB3_PHY_SEL, "usb3_phy_sel", csw_f26m_parents, 0x60, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 294 | 0x64, 0x68, 0, 1, 7, 0x1c0, 24), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 295 | TOP_MUX(CLK_TOP_AUD_SEL, "aud_sel", aud_parents, 0x60, 0x64, 0x68, 8, 1, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 296 | 15, 0x1c0, 25), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 297 | TOP_MUX(CLK_TOP_A1SYS_SEL, "a1sys_sel", a1sys_parents, 0x60, 0x64, 0x68, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 298 | 16, 1, 23, 0x1c0, 26), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 299 | TOP_MUX(CLK_TOP_AUD_L_SEL, "aud_l_sel", aud_l_parents, 0x60, 0x64, 0x68, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 300 | 24, 2, 31, 0x1c0, 27), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 301 | TOP_MUX(CLK_TOP_A_TUNER_SEL, "a_tuner_sel", a_tuner_parents, 0x70, 0x74, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 302 | 0x78, 0, 2, 7, 0x1c0, 28), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 303 | TOP_MUX(CLK_TOP_U2U3_SEL, "u2u3_sel", u2u3_parents, 0x70, 0x74, 0x78, 8, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 304 | 1, 15, 0x1c0, 29), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 305 | TOP_MUX(CLK_TOP_U2U3_SYS_SEL, "u2u3_sys_sel", u2u3_sys_parents, 0x70, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 306 | 0x74, 0x78, 16, 1, 23, 0x1c0, 30), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 307 | TOP_MUX(CLK_TOP_U2U3_XHCI_SEL, "u2u3_xhci_sel", u2u3_sys_parents, 0x70, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 308 | 0x74, 0x78, 24, 1, 31, 0x1c4, 0), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 309 | TOP_MUX(CLK_TOP_USB_FRMCNT_SEL, "usb_frmcnt_sel", usb_frmcnt_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 310 | 0x80, 0x84, 0x88, 0, 1, 7, 0x1c4, 1), |
| 311 | }; |
| 312 | |
| 313 | /* INFRA FIXED DIV */ |
| 314 | static const struct mtk_fixed_factor infra_fixed_divs[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 315 | TOP_FACTOR(CLK_INFRA_66M_MCK, "infra_66m_mck", CLK_TOP_SYSAXI_SEL, 1, 2), |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 316 | }; |
| 317 | |
| 318 | /* INFRASYS MUX PARENTS */ |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 319 | #define INFRA_PARENT(_id) PARENT(_id, CLK_PARENT_INFRASYS) |
| 320 | #define TOP_PARENT(_id) PARENT(_id, CLK_PARENT_TOPCKGEN) |
| 321 | #define VOID_PARENT PARENT(-1, 0) |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 322 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 323 | static const struct mtk_parent infra_uart0_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 324 | TOP_PARENT(CLK_TOP_F26M_SEL), |
| 325 | TOP_PARENT(CLK_TOP_UART_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 326 | }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 327 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 328 | static const struct mtk_parent infra_spi0_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 329 | TOP_PARENT(CLK_TOP_I2C_SEL), |
| 330 | TOP_PARENT(CLK_TOP_SPI_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 331 | }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 332 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 333 | static const struct mtk_parent infra_spi1_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 334 | TOP_PARENT(CLK_TOP_I2C_SEL), |
| 335 | TOP_PARENT(CLK_TOP_SPIM_MST_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 336 | }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 337 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 338 | static const struct mtk_parent infra_pwm1_parents[] = { |
| 339 | VOID_PARENT, |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 340 | TOP_PARENT(CLK_TOP_PWM_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 341 | }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 342 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 343 | static const struct mtk_parent infra_pwm_bsel_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 344 | TOP_PARENT(CLK_TOP_CB_RTC_32P7K), |
| 345 | TOP_PARENT(CLK_TOP_F26M_SEL), |
| 346 | INFRA_PARENT(CLK_INFRA_66M_MCK), |
| 347 | TOP_PARENT(CLK_TOP_PWM_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | static const struct mtk_parent infra_pcie_parents[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 351 | TOP_PARENT(CLK_TOP_CB_RTC_32P7K), |
| 352 | TOP_PARENT(CLK_TOP_F26M_SEL), |
| 353 | TOP_PARENT(CLK_TOP_CB_CKSQ_40M), |
| 354 | TOP_PARENT(CLK_TOP_PEXTP_TL_SEL) |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 355 | }; |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 356 | |
| 357 | #define INFRA_MUX(_id, _name, _parents, _reg, _shift, _width) \ |
| 358 | { \ |
| 359 | .id = _id, .mux_reg = (_reg) + 0x8, \ |
| 360 | .mux_set_reg = (_reg) + 0x0, .mux_clr_reg = (_reg) + 0x4, \ |
| 361 | .mux_shift = _shift, .mux_mask = BIT(_width) - 1, \ |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 362 | .parent_flags = _parents, .num_parents = ARRAY_SIZE(_parents), \ |
| 363 | .flags = CLK_MUX_SETCLR_UPD | CLK_PARENT_MIXED, \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* INFRA MUX */ |
| 367 | static const struct mtk_composite infra_muxes[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 368 | INFRA_MUX(CLK_INFRA_UART0_SEL, "infra_uart0_sel", infra_uart0_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 369 | 0x10, 0, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 370 | INFRA_MUX(CLK_INFRA_UART1_SEL, "infra_uart1_sel", infra_uart0_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 371 | 0x10, 1, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 372 | INFRA_MUX(CLK_INFRA_UART2_SEL, "infra_uart2_sel", infra_uart0_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 373 | 0x10, 2, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 374 | INFRA_MUX(CLK_INFRA_SPI0_SEL, "infra_spi0_sel", infra_spi0_parents, 0x10, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 375 | 4, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 376 | INFRA_MUX(CLK_INFRA_SPI1_SEL, "infra_spi1_sel", infra_spi1_parents, 0x10, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 377 | 5, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 378 | INFRA_MUX(CLK_INFRA_SPI2_SEL, "infra_spi2_sel", infra_spi0_parents, 0x10, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 379 | 6, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 380 | INFRA_MUX(CLK_INFRA_PWM1_SEL, "infra_pwm1_sel", infra_pwm1_parents, 0x10, |
Christian Marangi | 046faee | 2024-08-02 15:53:04 +0200 | [diff] [blame] | 381 | 9, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 382 | INFRA_MUX(CLK_INFRA_PWM2_SEL, "infra_pwm2_sel", infra_pwm1_parents, 0x10, |
Christian Marangi | 046faee | 2024-08-02 15:53:04 +0200 | [diff] [blame] | 383 | 11, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 384 | INFRA_MUX(CLK_INFRA_PWM3_SEL, "infra_pwm3_sel", infra_pwm1_parents, 0x10, |
Christian Marangi | 8199eeb | 2024-08-02 15:53:13 +0200 | [diff] [blame] | 385 | 15, 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 386 | INFRA_MUX(CLK_INFRA_PWM_BSEL, "infra_pwm_bsel", infra_pwm_bsel_parents, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 387 | 0x10, 13, 2), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 388 | INFRA_MUX(CLK_INFRA_PCIE_SEL, "infra_pcie_sel", infra_pcie_parents, 0x20, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 389 | 0, 2), |
| 390 | }; |
| 391 | |
| 392 | static const struct mtk_gate_regs infra_0_cg_regs = { |
| 393 | .set_ofs = 0x40, |
| 394 | .clr_ofs = 0x44, |
| 395 | .sta_ofs = 0x48, |
| 396 | }; |
| 397 | |
| 398 | static const struct mtk_gate_regs infra_1_cg_regs = { |
| 399 | .set_ofs = 0x50, |
| 400 | .clr_ofs = 0x54, |
| 401 | .sta_ofs = 0x58, |
| 402 | }; |
| 403 | |
| 404 | static const struct mtk_gate_regs infra_2_cg_regs = { |
| 405 | .set_ofs = 0x60, |
| 406 | .clr_ofs = 0x64, |
| 407 | .sta_ofs = 0x68, |
| 408 | }; |
| 409 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 410 | #define GATE_INFRA0(_id, _name, _parent, _shift, _flags) \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 411 | { \ |
| 412 | .id = _id, .parent = _parent, .regs = &infra_0_cg_regs, \ |
| 413 | .shift = _shift, \ |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 414 | .flags = _flags, \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 415 | } |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 416 | #define GATE_INFRA0_INFRA(_id, _name, _parent, _shift) \ |
| 417 | GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS) |
| 418 | #define GATE_INFRA0_TOP(_id, _name, _parent, _shift) \ |
| 419 | GATE_INFRA0(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN) |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 420 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 421 | #define GATE_INFRA1(_id, _name, _parent, _shift, _flags) \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 422 | { \ |
| 423 | .id = _id, .parent = _parent, .regs = &infra_1_cg_regs, \ |
| 424 | .shift = _shift, \ |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 425 | .flags = _flags, \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 426 | } |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 427 | #define GATE_INFRA1_INFRA(_id, _name, _parent, _shift) \ |
| 428 | GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS) |
| 429 | #define GATE_INFRA1_TOP(_id, _name, _parent, _shift) \ |
| 430 | GATE_INFRA1(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN) |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 431 | |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 432 | #define GATE_INFRA2(_id, _name, _parent, _shift, _flags) \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 433 | { \ |
| 434 | .id = _id, .parent = _parent, .regs = &infra_2_cg_regs, \ |
| 435 | .shift = _shift, \ |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 436 | .flags = _flags, \ |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 437 | } |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 438 | #define GATE_INFRA2_INFRA(_id, _name, _parent, _shift) \ |
| 439 | GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_INFRASYS) |
| 440 | #define GATE_INFRA2_TOP(_id, _name, _parent, _shift) \ |
| 441 | GATE_INFRA2(_id, _name, _parent, _shift, CLK_GATE_SETCLR | CLK_PARENT_TOPCKGEN) |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 442 | |
| 443 | /* INFRA GATE */ |
Christian Marangi | 9435d81 | 2024-08-02 15:53:14 +0200 | [diff] [blame] | 444 | static const struct mtk_gate infracfg_gates[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 445 | GATE_INFRA0_INFRA(CLK_INFRA_GPT_STA, "infra_gpt_sta", CLK_INFRA_66M_MCK, 0), |
| 446 | GATE_INFRA0_INFRA(CLK_INFRA_PWM_HCK, "infra_pwm_hck", CLK_INFRA_66M_MCK, 1), |
| 447 | GATE_INFRA0_INFRA(CLK_INFRA_PWM_STA, "infra_pwm_sta", CLK_INFRA_PWM_BSEL, 2), |
| 448 | GATE_INFRA0_INFRA(CLK_INFRA_PWM1_CK, "infra_pwm1", CLK_INFRA_PWM1_SEL, 3), |
| 449 | GATE_INFRA0_INFRA(CLK_INFRA_PWM2_CK, "infra_pwm2", CLK_INFRA_PWM2_SEL, 4), |
| 450 | GATE_INFRA0_INFRA(CLK_INFRA_PWM3_CK, "infra_pwm3", CLK_INFRA_PWM3_SEL, 27), |
| 451 | GATE_INFRA0_TOP(CLK_INFRA_CQ_DMA_CK, "infra_cq_dma", CLK_TOP_SYSAXI, 6), |
| 452 | GATE_INFRA0_TOP(CLK_INFRA_AUD_BUS_CK, "infra_aud_bus", CLK_TOP_SYSAXI, 8), |
| 453 | GATE_INFRA0_TOP(CLK_INFRA_AUD_26M_CK, "infra_aud_26m", CLK_TOP_F26M_SEL, 9), |
| 454 | GATE_INFRA0_TOP(CLK_INFRA_AUD_L_CK, "infra_aud_l", CLK_TOP_AUD_L, 10), |
| 455 | GATE_INFRA0_TOP(CLK_INFRA_AUD_AUD_CK, "infra_aud_aud", CLK_TOP_A1SYS, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 456 | 11), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 457 | GATE_INFRA0_TOP(CLK_INFRA_AUD_EG2_CK, "infra_aud_eg2", CLK_TOP_A_TUNER, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 458 | 13), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 459 | GATE_INFRA0_TOP(CLK_INFRA_DRAMC_26M_CK, "infra_dramc_26m", CLK_TOP_F26M_SEL, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 460 | 14), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 461 | GATE_INFRA0_INFRA(CLK_INFRA_DBG_CK, "infra_dbg", CLK_INFRA_66M_MCK, 15), |
| 462 | GATE_INFRA0_INFRA(CLK_INFRA_AP_DMA_CK, "infra_ap_dma", CLK_INFRA_66M_MCK, 16), |
| 463 | GATE_INFRA0_INFRA(CLK_INFRA_SEJ_CK, "infra_sej", CLK_INFRA_66M_MCK, 24), |
| 464 | GATE_INFRA0_TOP(CLK_INFRA_SEJ_13M_CK, "infra_sej_13m", CLK_TOP_F26M_SEL, 25), |
| 465 | GATE_INFRA1_TOP(CLK_INFRA_THERM_CK, "infra_therm", CLK_TOP_F26M_SEL, 0), |
| 466 | GATE_INFRA1_TOP(CLK_INFRA_I2C0_CK, "infra_i2c0", CLK_TOP_I2C_BCK, 1), |
| 467 | GATE_INFRA1_INFRA(CLK_INFRA_UART0_CK, "infra_uart0", CLK_INFRA_UART0_SEL, 2), |
| 468 | GATE_INFRA1_INFRA(CLK_INFRA_UART1_CK, "infra_uart1", CLK_INFRA_UART1_SEL, 3), |
| 469 | GATE_INFRA1_INFRA(CLK_INFRA_UART2_CK, "infra_uart2", CLK_INFRA_UART2_SEL, 4), |
| 470 | GATE_INFRA1_INFRA(CLK_INFRA_SPI2_CK, "infra_spi2", CLK_INFRA_SPI2_SEL, 6), |
| 471 | GATE_INFRA1_INFRA(CLK_INFRA_SPI2_HCK_CK, "infra_spi2_hck", CLK_INFRA_66M_MCK, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 472 | 7), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 473 | GATE_INFRA1_TOP(CLK_INFRA_NFI1_CK, "infra_nfi1", CLK_TOP_NFI1X, 8), |
| 474 | GATE_INFRA1_TOP(CLK_INFRA_SPINFI1_CK, "infra_spinfi1", CLK_TOP_SPINFI_BCK, |
| 475 | 9), |
| 476 | GATE_INFRA1_INFRA(CLK_INFRA_NFI_HCK_CK, "infra_nfi_hck", CLK_INFRA_66M_MCK, 10), |
| 477 | GATE_INFRA1_INFRA(CLK_INFRA_SPI0_CK, "infra_spi0", CLK_INFRA_SPI0_SEL, 11), |
| 478 | GATE_INFRA1_INFRA(CLK_INFRA_SPI1_CK, "infra_spi1", CLK_INFRA_SPI1_SEL, 12), |
| 479 | GATE_INFRA1_INFRA(CLK_INFRA_SPI0_HCK_CK, "infra_spi0_hck", CLK_INFRA_66M_MCK, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 480 | 13), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 481 | GATE_INFRA1_INFRA(CLK_INFRA_SPI1_HCK_CK, "infra_spi1_hck", CLK_INFRA_66M_MCK, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 482 | 14), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 483 | GATE_INFRA1_TOP(CLK_INFRA_FRTC_CK, "infra_frtc", CLK_TOP_CB_RTC_32K, 15), |
| 484 | GATE_INFRA1_TOP(CLK_INFRA_MSDC_CK, "infra_msdc", CLK_TOP_EMMC_400M, 16), |
| 485 | GATE_INFRA1_TOP(CLK_INFRA_MSDC_HCK_CK, "infra_msdc_hck", |
| 486 | CLK_TOP_EMMC_208M, 17), |
| 487 | GATE_INFRA1_TOP(CLK_INFRA_MSDC_133M_CK, "infra_msdc_133m", |
| 488 | CLK_TOP_SYSAXI, 18), |
| 489 | GATE_INFRA1_TOP(CLK_INFRA_MSDC_66M_CK, "infra_msdc_66m", CLK_TOP_SYSAXI, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 490 | 19), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 491 | GATE_INFRA1_INFRA(CLK_INFRA_ADC_26M_CK, "infra_adc_26m", CLK_INFRA_ADC_FRC_CK, 20), |
| 492 | GATE_INFRA1_TOP(CLK_INFRA_ADC_FRC_CK, "infra_adc_frc", CLK_TOP_F26M, 21), |
| 493 | GATE_INFRA1_TOP(CLK_INFRA_FBIST2FPC_CK, "infra_fbist2fpc", CLK_TOP_NFI1X, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 494 | 23), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 495 | GATE_INFRA1_TOP(CLK_INFRA_I2C_MCK_CK, "infra_i2c_mck", CLK_TOP_SYSAXI, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 496 | 25), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 497 | GATE_INFRA1_INFRA(CLK_INFRA_I2C_PCK_CK, "infra_i2c_pck", CLK_INFRA_66M_MCK, 26), |
| 498 | GATE_INFRA2_TOP(CLK_INFRA_IUSB_133_CK, "infra_iusb_133", CLK_TOP_SYSAXI, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 499 | 0), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 500 | GATE_INFRA2_TOP(CLK_INFRA_IUSB_66M_CK, "infra_iusb_66m", CLK_TOP_SYSAXI, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 501 | 1), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 502 | GATE_INFRA2_TOP(CLK_INFRA_IUSB_SYS_CK, "infra_iusb_sys", CLK_TOP_U2U3_SYS, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 503 | 2), |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 504 | GATE_INFRA2_TOP(CLK_INFRA_IUSB_CK, "infra_iusb", CLK_TOP_U2U3_REF, 3), |
| 505 | GATE_INFRA2_TOP(CLK_INFRA_IPCIE_CK, "infra_ipcie", CLK_TOP_PEXTP_TL, 12), |
| 506 | GATE_INFRA2_TOP(CLK_INFRA_IPCIE_PIPE_CK, "infra_ipcie_pipe", CLK_TOP_CB_CKSQ_40M, 13), |
| 507 | GATE_INFRA2_TOP(CLK_INFRA_IPCIER_CK, "infra_ipcier", CLK_TOP_F26M, 14), |
| 508 | GATE_INFRA2_TOP(CLK_INFRA_IPCIEB_CK, "infra_ipcieb", CLK_TOP_SYSAXI, 15), |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | static const struct mtk_clk_tree mt7981_fixed_pll_clk_tree = { |
| 512 | .fdivs_offs = CLK_APMIXED_NR_CLK, |
| 513 | .xtal_rate = 40 * MHZ, |
| 514 | .fclks = fixed_pll_clks, |
| 515 | }; |
| 516 | |
| 517 | static const struct mtk_clk_tree mt7981_topckgen_clk_tree = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 518 | .fdivs_offs = CLK_TOP_CB_M_416M, |
| 519 | .muxes_offs = CLK_TOP_NFI1X_SEL, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 520 | .fclks = top_fixed_clks, |
| 521 | .fdivs = top_fixed_divs, |
| 522 | .muxes = top_muxes, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 523 | .flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | static const struct mtk_clk_tree mt7981_infracfg_clk_tree = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 527 | .fdivs_offs = CLK_INFRA_66M_MCK, |
| 528 | .muxes_offs = CLK_INFRA_UART0_SEL, |
| 529 | .gates_offs = CLK_INFRA_GPT_STA, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 530 | .fdivs = infra_fixed_divs, |
| 531 | .muxes = infra_muxes, |
Christian Marangi | 9435d81 | 2024-08-02 15:53:14 +0200 | [diff] [blame] | 532 | .gates = infracfg_gates, |
Christian Marangi | bc63482 | 2024-08-02 15:53:11 +0200 | [diff] [blame] | 533 | .flags = CLK_INFRASYS, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 534 | }; |
| 535 | |
| 536 | static const struct udevice_id mt7981_fixed_pll_compat[] = { |
| 537 | { .compatible = "mediatek,mt7981-fixed-plls" }, |
Christian Marangi | 8cba8f0 | 2024-06-24 23:03:35 +0200 | [diff] [blame] | 538 | { .compatible = "mediatek,mt7981-apmixedsys" }, |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 539 | {} |
| 540 | }; |
| 541 | |
| 542 | static const struct udevice_id mt7981_topckgen_compat[] = { |
| 543 | { .compatible = "mediatek,mt7981-topckgen" }, |
| 544 | {} |
| 545 | }; |
| 546 | |
| 547 | static int mt7981_fixed_pll_probe(struct udevice *dev) |
| 548 | { |
| 549 | return mtk_common_clk_init(dev, &mt7981_fixed_pll_clk_tree); |
| 550 | } |
| 551 | |
| 552 | static int mt7981_topckgen_probe(struct udevice *dev) |
| 553 | { |
| 554 | struct mtk_clk_priv *priv = dev_get_priv(dev); |
| 555 | |
| 556 | priv->base = dev_read_addr_ptr(dev); |
| 557 | writel(MT7981_CLK_PDN_EN_WRITE, priv->base + MT7981_CLK_PDN); |
| 558 | |
| 559 | return mtk_common_clk_init(dev, &mt7981_topckgen_clk_tree); |
| 560 | } |
| 561 | |
| 562 | U_BOOT_DRIVER(mtk_clk_apmixedsys) = { |
| 563 | .name = "mt7981-clock-fixed-pll", |
| 564 | .id = UCLASS_CLK, |
| 565 | .of_match = mt7981_fixed_pll_compat, |
| 566 | .probe = mt7981_fixed_pll_probe, |
| 567 | .priv_auto = sizeof(struct mtk_clk_priv), |
| 568 | .ops = &mtk_clk_topckgen_ops, |
| 569 | .flags = DM_FLAG_PRE_RELOC, |
| 570 | }; |
| 571 | |
| 572 | U_BOOT_DRIVER(mtk_clk_topckgen) = { |
| 573 | .name = "mt7981-clock-topckgen", |
| 574 | .id = UCLASS_CLK, |
| 575 | .of_match = mt7981_topckgen_compat, |
| 576 | .probe = mt7981_topckgen_probe, |
| 577 | .priv_auto = sizeof(struct mtk_clk_priv), |
| 578 | .ops = &mtk_clk_topckgen_ops, |
| 579 | .flags = DM_FLAG_PRE_RELOC, |
| 580 | }; |
| 581 | |
| 582 | static const struct udevice_id mt7981_infracfg_compat[] = { |
| 583 | { .compatible = "mediatek,mt7981-infracfg" }, |
| 584 | {} |
| 585 | }; |
| 586 | |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 587 | static int mt7981_infracfg_probe(struct udevice *dev) |
| 588 | { |
Christian Marangi | 9435d81 | 2024-08-02 15:53:14 +0200 | [diff] [blame] | 589 | return mtk_common_clk_infrasys_init(dev, &mt7981_infracfg_clk_tree); |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | U_BOOT_DRIVER(mtk_clk_infracfg) = { |
| 593 | .name = "mt7981-clock-infracfg", |
| 594 | .id = UCLASS_CLK, |
| 595 | .of_match = mt7981_infracfg_compat, |
| 596 | .probe = mt7981_infracfg_probe, |
| 597 | .priv_auto = sizeof(struct mtk_clk_priv), |
| 598 | .ops = &mtk_clk_infrasys_ops, |
| 599 | .flags = DM_FLAG_PRE_RELOC, |
| 600 | }; |
| 601 | |
Christian Marangi | be9dbee | 2024-08-02 15:53:10 +0200 | [diff] [blame] | 602 | /* sgmiisys */ |
| 603 | static const struct mtk_gate_regs sgmii_cg_regs = { |
| 604 | .set_ofs = 0xe4, |
| 605 | .clr_ofs = 0xe4, |
| 606 | .sta_ofs = 0xe4, |
| 607 | }; |
| 608 | |
| 609 | #define GATE_SGMII(_id, _name, _parent, _shift) \ |
| 610 | { \ |
| 611 | .id = _id, .parent = _parent, .regs = &sgmii_cg_regs, \ |
| 612 | .shift = _shift, \ |
| 613 | .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \ |
| 614 | } |
| 615 | |
| 616 | static const struct mtk_gate sgmii0_cgs[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 617 | GATE_SGMII(CLK_SGM0_TX_EN, "sgm0_tx_en", CLK_TOP_USB_TX250M, 2), |
| 618 | GATE_SGMII(CLK_SGM0_RX_EN, "sgm0_rx_en", CLK_TOP_USB_EQ_RX250M, 3), |
| 619 | GATE_SGMII(CLK_SGM0_CK0_EN, "sgm0_ck0_en", CLK_TOP_USB_LN0_CK, 4), |
| 620 | GATE_SGMII(CLK_SGM0_CDR_CK0_EN, "sgm0_cdr_ck0_en", CLK_TOP_USB_CDR_CK, 5), |
Christian Marangi | be9dbee | 2024-08-02 15:53:10 +0200 | [diff] [blame] | 621 | }; |
| 622 | |
| 623 | static int mt7981_sgmii0sys_probe(struct udevice *dev) |
| 624 | { |
| 625 | return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree, |
| 626 | sgmii0_cgs); |
| 627 | } |
| 628 | |
| 629 | static const struct udevice_id mt7981_sgmii0sys_compat[] = { |
| 630 | { .compatible = "mediatek,mt7981-sgmiisys_0", }, |
| 631 | {} |
| 632 | }; |
| 633 | |
| 634 | U_BOOT_DRIVER(mtk_clk_sgmii0sys) = { |
| 635 | .name = "mt7981-clock-sgmii0sys", |
| 636 | .id = UCLASS_CLK, |
| 637 | .of_match = mt7981_sgmii0sys_compat, |
| 638 | .probe = mt7981_sgmii0sys_probe, |
| 639 | .priv_auto = sizeof(struct mtk_cg_priv), |
| 640 | .ops = &mtk_clk_gate_ops, |
| 641 | }; |
| 642 | |
| 643 | static const struct mtk_gate sgmii1_cgs[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 644 | GATE_SGMII(CLK_SGM1_TX_EN, "sgm1_tx_en", CLK_TOP_USB_TX250M, 2), |
| 645 | GATE_SGMII(CLK_SGM1_RX_EN, "sgm1_rx_en", CLK_TOP_USB_EQ_RX250M, 3), |
| 646 | GATE_SGMII(CLK_SGM1_CK1_EN, "sgm1_ck1_en", CLK_TOP_USB_LN0_CK, 4), |
| 647 | GATE_SGMII(CLK_SGM1_CDR_CK1_EN, "sgm1_cdr_ck1_en", CLK_TOP_USB_CDR_CK, 5), |
Christian Marangi | be9dbee | 2024-08-02 15:53:10 +0200 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | static int mt7981_sgmii1sys_probe(struct udevice *dev) |
| 651 | { |
| 652 | return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree, |
| 653 | sgmii1_cgs); |
| 654 | } |
| 655 | |
| 656 | static const struct udevice_id mt7981_sgmii1sys_compat[] = { |
| 657 | { .compatible = "mediatek,mt7981-sgmiisys_1", }, |
| 658 | {} |
| 659 | }; |
| 660 | |
| 661 | U_BOOT_DRIVER(mtk_clk_sgmii1sys) = { |
| 662 | .name = "mt7981-clock-sgmii1sys", |
| 663 | .id = UCLASS_CLK, |
| 664 | .of_match = mt7981_sgmii1sys_compat, |
| 665 | .probe = mt7981_sgmii1sys_probe, |
| 666 | .priv_auto = sizeof(struct mtk_cg_priv), |
| 667 | .ops = &mtk_clk_gate_ops, |
| 668 | }; |
| 669 | |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 670 | /* ethsys */ |
| 671 | static const struct mtk_gate_regs eth_cg_regs = { |
| 672 | .set_ofs = 0x30, |
| 673 | .clr_ofs = 0x30, |
| 674 | .sta_ofs = 0x30, |
| 675 | }; |
| 676 | |
| 677 | #define GATE_ETH(_id, _name, _parent, _shift) \ |
| 678 | { \ |
| 679 | .id = _id, .parent = _parent, .regs = ð_cg_regs, \ |
| 680 | .shift = _shift, \ |
| 681 | .flags = CLK_GATE_NO_SETCLR_INV | CLK_PARENT_TOPCKGEN, \ |
| 682 | } |
| 683 | |
| 684 | static const struct mtk_gate eth_cgs[] = { |
Christian Marangi | f245164 | 2024-08-02 15:53:15 +0200 | [diff] [blame] | 685 | GATE_ETH(CLK_ETH_FE_EN, "eth_fe_en", CLK_TOP_NETSYS_2X, 6), |
| 686 | GATE_ETH(CLK_ETH_GP2_EN, "eth_gp2_en", CLK_TOP_SGM_325M, 7), |
| 687 | GATE_ETH(CLK_ETH_GP1_EN, "eth_gp1_en", CLK_TOP_SGM_325M, 8), |
| 688 | GATE_ETH(CLK_ETH_WOCPU0_EN, "eth_wocpu0_en", CLK_TOP_NETSYS_WED_MCU, 15), |
developer | 79128da | 2022-09-09 20:00:12 +0800 | [diff] [blame] | 689 | }; |
| 690 | |
| 691 | static int mt7981_ethsys_probe(struct udevice *dev) |
| 692 | { |
| 693 | return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree, |
| 694 | eth_cgs); |
| 695 | } |
| 696 | |
| 697 | static int mt7981_ethsys_bind(struct udevice *dev) |
| 698 | { |
| 699 | int ret = 0; |
| 700 | |
| 701 | if (CONFIG_IS_ENABLED(RESET_MEDIATEK)) { |
| 702 | ret = mediatek_reset_bind(dev, ETHSYS_HIFSYS_RST_CTRL_OFS, 1); |
| 703 | if (ret) |
| 704 | debug("Warning: failed to bind reset controller\n"); |
| 705 | } |
| 706 | |
| 707 | return ret; |
| 708 | } |
| 709 | |
| 710 | static const struct udevice_id mt7981_ethsys_compat[] = { |
| 711 | { .compatible = "mediatek,mt7981-ethsys", }, |
| 712 | {} |
| 713 | }; |
| 714 | |
| 715 | U_BOOT_DRIVER(mtk_clk_ethsys) = { |
| 716 | .name = "mt7981-clock-ethsys", |
| 717 | .id = UCLASS_CLK, |
| 718 | .of_match = mt7981_ethsys_compat, |
| 719 | .probe = mt7981_ethsys_probe, |
| 720 | .bind = mt7981_ethsys_bind, |
| 721 | .priv_auto = sizeof(struct mtk_cg_priv), |
| 722 | .ops = &mtk_clk_gate_ops, |
| 723 | }; |