Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-2024 NXP |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <s32cc-clk-ids.h> |
| 7 | #include <s32cc-clk-modules.h> |
| 8 | #include <s32cc-clk-utils.h> |
| 9 | |
Ghennadi Procopciuc | 2be71a3 | 2024-06-12 12:06:36 +0300 | [diff] [blame] | 10 | #define S32CC_A53_MIN_FREQ (48UL * MHZ) |
| 11 | #define S32CC_A53_MAX_FREQ (1000UL * MHZ) |
| 12 | |
Ghennadi Procopciuc | d3cd783 | 2024-09-17 09:02:24 +0300 | [diff] [blame] | 13 | /* Partitions */ |
| 14 | static struct s32cc_part part0 = S32CC_PART(0); |
| 15 | |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 16 | /* Oscillators */ |
| 17 | static struct s32cc_osc fxosc = |
| 18 | S32CC_OSC_INIT(S32CC_FXOSC); |
| 19 | static struct s32cc_clk fxosc_clk = |
| 20 | S32CC_MODULE_CLK(fxosc); |
| 21 | |
| 22 | static struct s32cc_osc firc = |
| 23 | S32CC_OSC_INIT(S32CC_FIRC); |
| 24 | static struct s32cc_clk firc_clk = |
| 25 | S32CC_MODULE_CLK(firc); |
| 26 | |
| 27 | static struct s32cc_osc sirc = |
| 28 | S32CC_OSC_INIT(S32CC_SIRC); |
| 29 | static struct s32cc_clk sirc_clk = |
| 30 | S32CC_MODULE_CLK(sirc); |
| 31 | |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 32 | /* ARM PLL */ |
| 33 | static struct s32cc_clkmux arm_pll_mux = |
| 34 | S32CC_CLKMUX_INIT(S32CC_ARM_PLL, 0, 2, |
| 35 | S32CC_CLK_FIRC, |
| 36 | S32CC_CLK_FXOSC, 0, 0, 0); |
| 37 | static struct s32cc_clk arm_pll_mux_clk = |
| 38 | S32CC_MODULE_CLK(arm_pll_mux); |
| 39 | static struct s32cc_pll armpll = |
| 40 | S32CC_PLL_INIT(arm_pll_mux_clk, S32CC_ARM_PLL, 2); |
| 41 | static struct s32cc_clk arm_pll_vco_clk = |
| 42 | S32CC_FREQ_MODULE_CLK(armpll, 1400 * MHZ, 2000 * MHZ); |
| 43 | |
| 44 | static struct s32cc_pll_out_div arm_pll_phi0_div = |
| 45 | S32CC_PLL_OUT_DIV_INIT(armpll, 0); |
| 46 | static struct s32cc_clk arm_pll_phi0_clk = |
| 47 | S32CC_FREQ_MODULE_CLK(arm_pll_phi0_div, 0, GHZ); |
| 48 | |
Ghennadi Procopciuc | 6494966 | 2024-08-05 16:49:51 +0300 | [diff] [blame] | 49 | /* ARM DFS */ |
| 50 | static struct s32cc_dfs armdfs = |
| 51 | S32CC_DFS_INIT(armpll, S32CC_ARM_DFS); |
| 52 | static struct s32cc_dfs_div arm_dfs1_div = |
| 53 | S32CC_DFS_DIV_INIT(armdfs, 0); |
| 54 | static struct s32cc_clk arm_dfs1_clk = |
| 55 | S32CC_FREQ_MODULE_CLK(arm_dfs1_div, 0, 800 * MHZ); |
| 56 | |
| 57 | /* MC_CGM0 */ |
| 58 | static struct s32cc_clkmux cgm0_mux0 = |
| 59 | S32CC_SHARED_CLKMUX_INIT(S32CC_CGM0, 0, 2, |
| 60 | S32CC_CLK_FIRC, |
| 61 | S32CC_CLK_ARM_PLL_DFS1, 0, 0, 0); |
| 62 | static struct s32cc_clk cgm0_mux0_clk = S32CC_MODULE_CLK(cgm0_mux0); |
| 63 | |
Ghennadi Procopciuc | 0609bcd | 2024-08-06 13:25:51 +0300 | [diff] [blame] | 64 | static struct s32cc_clkmux cgm0_mux8 = |
| 65 | S32CC_SHARED_CLKMUX_INIT(S32CC_CGM0, 8, 3, |
| 66 | S32CC_CLK_FIRC, |
| 67 | S32CC_CLK_PERIPH_PLL_PHI3, |
| 68 | S32CC_CLK_FXOSC, 0, 0); |
| 69 | static struct s32cc_clk cgm0_mux8_clk = S32CC_MODULE_CLK(cgm0_mux8); |
| 70 | |
Ghennadi Procopciuc | 6494966 | 2024-08-05 16:49:51 +0300 | [diff] [blame] | 71 | /* XBAR */ |
| 72 | static struct s32cc_clk xbar_2x_clk = |
| 73 | S32CC_CHILD_CLK(cgm0_mux0_clk, 48 * MHZ, 800 * MHZ); |
| 74 | static struct s32cc_fixed_div xbar_div2 = |
| 75 | S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 2); |
| 76 | static struct s32cc_clk xbar_clk = |
| 77 | S32CC_FREQ_MODULE_CLK(xbar_div2, 24 * MHZ, 400 * MHZ); |
| 78 | static struct s32cc_fixed_div xbar_div4 = |
| 79 | S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 4); |
| 80 | static struct s32cc_clk xbar_div2_clk = |
| 81 | S32CC_FREQ_MODULE_CLK(xbar_div4, 12 * MHZ, 200 * MHZ); |
| 82 | static struct s32cc_fixed_div xbar_div6 = |
| 83 | S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 6); |
| 84 | static struct s32cc_clk xbar_div3_clk = |
| 85 | S32CC_FREQ_MODULE_CLK(xbar_div6, 8 * MHZ, 133333333); |
| 86 | static struct s32cc_fixed_div xbar_div8 = |
| 87 | S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 8); |
| 88 | static struct s32cc_clk xbar_div4_clk = |
| 89 | S32CC_FREQ_MODULE_CLK(xbar_div8, 6 * MHZ, 100 * MHZ); |
| 90 | static struct s32cc_fixed_div xbar_div12 = |
| 91 | S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 12); |
| 92 | static struct s32cc_clk xbar_div6_clk = |
| 93 | S32CC_FREQ_MODULE_CLK(xbar_div12, 4 * MHZ, 66666666); |
| 94 | |
Ghennadi Procopciuc | 0609bcd | 2024-08-06 13:25:51 +0300 | [diff] [blame] | 95 | /* Linflex */ |
| 96 | static struct s32cc_clk linflex_baud_clk = |
| 97 | S32CC_CHILD_CLK(cgm0_mux8_clk, 19200, 133333333); |
| 98 | static struct s32cc_fixed_div linflex_div = |
| 99 | S32CC_FIXED_DIV_INIT(linflex_baud_clk, 2); |
| 100 | static struct s32cc_clk linflex_clk = |
| 101 | S32CC_FREQ_MODULE_CLK(linflex_div, 9600, 66666666); |
| 102 | |
Ghennadi Procopciuc | 8384d18 | 2024-06-12 10:53:06 +0300 | [diff] [blame] | 103 | /* MC_CGM1 */ |
| 104 | static struct s32cc_clkmux cgm1_mux0 = |
| 105 | S32CC_SHARED_CLKMUX_INIT(S32CC_CGM1, 0, 3, |
| 106 | S32CC_CLK_FIRC, |
| 107 | S32CC_CLK_ARM_PLL_PHI0, |
| 108 | S32CC_CLK_ARM_PLL_DFS2, 0, 0); |
| 109 | static struct s32cc_clk cgm1_mux0_clk = S32CC_MODULE_CLK(cgm1_mux0); |
| 110 | |
Ghennadi Procopciuc | 2be71a3 | 2024-06-12 12:06:36 +0300 | [diff] [blame] | 111 | /* A53_CORE */ |
| 112 | static struct s32cc_clk a53_core_clk = |
| 113 | S32CC_FREQ_MODULE_CLK(cgm1_mux0_clk, S32CC_A53_MIN_FREQ, |
| 114 | S32CC_A53_MAX_FREQ); |
| 115 | /* A53_CORE_DIV2 */ |
| 116 | static struct s32cc_fixed_div a53_core_div2 = |
| 117 | S32CC_FIXED_DIV_INIT(cgm1_mux0_clk, 2); |
| 118 | static struct s32cc_clk a53_core_div2_clk = |
| 119 | S32CC_FREQ_MODULE_CLK(a53_core_div2, S32CC_A53_MIN_FREQ / 2, |
| 120 | S32CC_A53_MAX_FREQ / 2); |
| 121 | /* A53_CORE_DIV10 */ |
| 122 | static struct s32cc_fixed_div a53_core_div10 = |
| 123 | S32CC_FIXED_DIV_INIT(cgm1_mux0_clk, 10); |
| 124 | static struct s32cc_clk a53_core_div10_clk = |
| 125 | S32CC_FREQ_MODULE_CLK(a53_core_div10, S32CC_A53_MIN_FREQ / 10, |
| 126 | S32CC_A53_MAX_FREQ / 10); |
| 127 | |
Ghennadi Procopciuc | 22f9474 | 2024-08-06 11:48:11 +0300 | [diff] [blame] | 128 | /* PERIPH PLL */ |
| 129 | static struct s32cc_clkmux periph_pll_mux = |
| 130 | S32CC_CLKMUX_INIT(S32CC_PERIPH_PLL, 0, 2, |
| 131 | S32CC_CLK_FIRC, |
| 132 | S32CC_CLK_FXOSC, 0, 0, 0); |
| 133 | static struct s32cc_clk periph_pll_mux_clk = |
| 134 | S32CC_MODULE_CLK(periph_pll_mux); |
| 135 | static struct s32cc_pll periphpll = |
| 136 | S32CC_PLL_INIT(periph_pll_mux_clk, S32CC_PERIPH_PLL, 2); |
| 137 | static struct s32cc_clk periph_pll_vco_clk = |
| 138 | S32CC_FREQ_MODULE_CLK(periphpll, 1300 * MHZ, 2 * GHZ); |
| 139 | |
| 140 | static struct s32cc_pll_out_div periph_pll_phi3_div = |
| 141 | S32CC_PLL_OUT_DIV_INIT(periphpll, 3); |
| 142 | static struct s32cc_clk periph_pll_phi3_clk = |
| 143 | S32CC_FREQ_MODULE_CLK(periph_pll_phi3_div, 0, 133333333); |
| 144 | |
Ghennadi Procopciuc | d3cd783 | 2024-09-17 09:02:24 +0300 | [diff] [blame] | 145 | /* DDR PLL */ |
| 146 | static struct s32cc_clkmux ddr_pll_mux = |
| 147 | S32CC_CLKMUX_INIT(S32CC_DDR_PLL, 0, 2, |
| 148 | S32CC_CLK_FIRC, |
| 149 | S32CC_CLK_FXOSC, 0, 0, 0); |
| 150 | static struct s32cc_clk ddr_pll_mux_clk = |
| 151 | S32CC_MODULE_CLK(ddr_pll_mux); |
| 152 | static struct s32cc_pll ddrpll = |
| 153 | S32CC_PLL_INIT(ddr_pll_mux_clk, S32CC_DDR_PLL, 1); |
| 154 | static struct s32cc_clk ddr_pll_vco_clk = |
| 155 | S32CC_FREQ_MODULE_CLK(ddrpll, 1300 * MHZ, 1600 * MHZ); |
| 156 | |
| 157 | static struct s32cc_pll_out_div ddr_pll_phi0_div = |
| 158 | S32CC_PLL_OUT_DIV_INIT(ddrpll, 0); |
| 159 | static struct s32cc_clk ddr_pll_phi0_clk = |
| 160 | S32CC_FREQ_MODULE_CLK(ddr_pll_phi0_div, 0, 800 * MHZ); |
| 161 | |
| 162 | /* MC_CGM5 */ |
| 163 | static struct s32cc_clkmux cgm5_mux0 = |
| 164 | S32CC_SHARED_CLKMUX_INIT(S32CC_CGM5, 0, 2, |
| 165 | S32CC_CLK_FIRC, |
| 166 | S32CC_CLK_DDR_PLL_PHI0, |
| 167 | 0, 0, 0); |
| 168 | static struct s32cc_clk cgm5_mux0_clk = S32CC_MODULE_CLK(cgm5_mux0); |
| 169 | |
| 170 | /* DDR clock */ |
| 171 | static struct s32cc_part_block part0_block1 = |
| 172 | S32CC_PART_BLOCK(&part0, s32cc_part_block1); |
| 173 | static struct s32cc_part_block_link ddr_block_link = |
| 174 | S32CC_PART_BLOCK_LINK(cgm5_mux0_clk, &part0_block1); |
| 175 | static struct s32cc_clk ddr_clk = |
| 176 | S32CC_FREQ_MODULE_CLK(ddr_block_link, 0, 800 * MHZ); |
| 177 | |
| 178 | static struct s32cc_clk *s32cc_hw_clk_list[37] = { |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 179 | /* Oscillators */ |
| 180 | [S32CC_CLK_ID(S32CC_CLK_FIRC)] = &firc_clk, |
| 181 | [S32CC_CLK_ID(S32CC_CLK_SIRC)] = &sirc_clk, |
| 182 | [S32CC_CLK_ID(S32CC_CLK_FXOSC)] = &fxosc_clk, |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 183 | /* ARM PLL */ |
| 184 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_PHI0)] = &arm_pll_phi0_clk, |
Ghennadi Procopciuc | 6494966 | 2024-08-05 16:49:51 +0300 | [diff] [blame] | 185 | /* ARM DFS */ |
| 186 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_DFS1)] = &arm_dfs1_clk, |
Ghennadi Procopciuc | 22f9474 | 2024-08-06 11:48:11 +0300 | [diff] [blame] | 187 | /* PERIPH PLL */ |
| 188 | [S32CC_CLK_ID(S32CC_CLK_PERIPH_PLL_PHI3)] = &periph_pll_phi3_clk, |
Ghennadi Procopciuc | d3cd783 | 2024-09-17 09:02:24 +0300 | [diff] [blame] | 189 | /* DDR PLL */ |
| 190 | [S32CC_CLK_ID(S32CC_CLK_DDR_PLL_PHI0)] = &ddr_pll_phi0_clk, |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | static struct s32cc_clk_array s32cc_hw_clocks = { |
| 194 | .type_mask = S32CC_CLK_TYPE(S32CC_CLK_FIRC), |
| 195 | .clks = &s32cc_hw_clk_list[0], |
| 196 | .n_clks = ARRAY_SIZE(s32cc_hw_clk_list), |
| 197 | }; |
| 198 | |
Ghennadi Procopciuc | d3cd783 | 2024-09-17 09:02:24 +0300 | [diff] [blame] | 199 | static struct s32cc_clk *s32cc_arch_clk_list[22] = { |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 200 | /* ARM PLL */ |
| 201 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_MUX)] = &arm_pll_mux_clk, |
| 202 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_VCO)] = &arm_pll_vco_clk, |
Ghennadi Procopciuc | 22f9474 | 2024-08-06 11:48:11 +0300 | [diff] [blame] | 203 | /* PERIPH PLL */ |
| 204 | [S32CC_CLK_ID(S32CC_CLK_PERIPH_PLL_MUX)] = &periph_pll_mux_clk, |
| 205 | [S32CC_CLK_ID(S32CC_CLK_PERIPH_PLL_VCO)] = &periph_pll_vco_clk, |
Ghennadi Procopciuc | 6494966 | 2024-08-05 16:49:51 +0300 | [diff] [blame] | 206 | /* MC_CGM0 */ |
| 207 | [S32CC_CLK_ID(S32CC_CLK_MC_CGM0_MUX0)] = &cgm0_mux0_clk, |
Ghennadi Procopciuc | 0609bcd | 2024-08-06 13:25:51 +0300 | [diff] [blame] | 208 | [S32CC_CLK_ID(S32CC_CLK_MC_CGM0_MUX8)] = &cgm0_mux8_clk, |
Ghennadi Procopciuc | 6494966 | 2024-08-05 16:49:51 +0300 | [diff] [blame] | 209 | /* XBAR */ |
| 210 | [S32CC_CLK_ID(S32CC_CLK_XBAR_2X)] = &xbar_2x_clk, |
| 211 | [S32CC_CLK_ID(S32CC_CLK_XBAR)] = &xbar_clk, |
| 212 | [S32CC_CLK_ID(S32CC_CLK_XBAR_DIV2)] = &xbar_div2_clk, |
| 213 | [S32CC_CLK_ID(S32CC_CLK_XBAR_DIV3)] = &xbar_div3_clk, |
| 214 | [S32CC_CLK_ID(S32CC_CLK_XBAR_DIV4)] = &xbar_div4_clk, |
| 215 | [S32CC_CLK_ID(S32CC_CLK_XBAR_DIV6)] = &xbar_div6_clk, |
Ghennadi Procopciuc | 8384d18 | 2024-06-12 10:53:06 +0300 | [diff] [blame] | 216 | /* MC_CGM1 */ |
| 217 | [S32CC_CLK_ID(S32CC_CLK_MC_CGM1_MUX0)] = &cgm1_mux0_clk, |
Ghennadi Procopciuc | 2be71a3 | 2024-06-12 12:06:36 +0300 | [diff] [blame] | 218 | /* A53 */ |
| 219 | [S32CC_CLK_ID(S32CC_CLK_A53_CORE)] = &a53_core_clk, |
| 220 | [S32CC_CLK_ID(S32CC_CLK_A53_CORE_DIV2)] = &a53_core_div2_clk, |
| 221 | [S32CC_CLK_ID(S32CC_CLK_A53_CORE_DIV10)] = &a53_core_div10_clk, |
Ghennadi Procopciuc | 0609bcd | 2024-08-06 13:25:51 +0300 | [diff] [blame] | 222 | /* Linflex */ |
| 223 | [S32CC_CLK_ID(S32CC_CLK_LINFLEX)] = &linflex_clk, |
| 224 | [S32CC_CLK_ID(S32CC_CLK_LINFLEX_BAUD)] = &linflex_baud_clk, |
Ghennadi Procopciuc | d3cd783 | 2024-09-17 09:02:24 +0300 | [diff] [blame] | 225 | /* DDR PLL */ |
| 226 | [S32CC_CLK_ID(S32CC_CLK_DDR_PLL_MUX)] = &ddr_pll_mux_clk, |
| 227 | [S32CC_CLK_ID(S32CC_CLK_DDR_PLL_VCO)] = &ddr_pll_vco_clk, |
| 228 | /* MC_CGM5 */ |
| 229 | [S32CC_CLK_ID(S32CC_CLK_MC_CGM5_MUX0)] = &cgm5_mux0_clk, |
| 230 | /* DDR */ |
| 231 | [S32CC_CLK_ID(S32CC_CLK_DDR)] = &ddr_clk, |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | static struct s32cc_clk_array s32cc_arch_clocks = { |
| 235 | .type_mask = S32CC_CLK_TYPE(S32CC_CLK_ARM_PLL_MUX), |
| 236 | .clks = &s32cc_arch_clk_list[0], |
| 237 | .n_clks = ARRAY_SIZE(s32cc_arch_clk_list), |
| 238 | }; |
| 239 | |
Ghennadi Procopciuc | 302831c | 2024-09-11 09:29:50 +0300 | [diff] [blame] | 240 | static const struct s32cc_clk_array *s32cc_clk_table[2] = { |
| 241 | &s32cc_hw_clocks, |
| 242 | &s32cc_arch_clocks, |
| 243 | }; |
| 244 | |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 245 | struct s32cc_clk *s32cc_get_arch_clk(unsigned long id) |
| 246 | { |
Ghennadi Procopciuc | 302831c | 2024-09-11 09:29:50 +0300 | [diff] [blame] | 247 | return s32cc_get_clk_from_table(s32cc_clk_table, |
| 248 | ARRAY_SIZE(s32cc_clk_table), |
| 249 | id); |
| 250 | } |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 251 | |
Ghennadi Procopciuc | 302831c | 2024-09-11 09:29:50 +0300 | [diff] [blame] | 252 | int s32cc_get_clk_id(const struct s32cc_clk *clk, unsigned long *id) |
| 253 | { |
| 254 | return s32cc_get_id_from_table(s32cc_clk_table, |
| 255 | ARRAY_SIZE(s32cc_clk_table), |
| 256 | clk, id); |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 257 | } |