blob: 71055abc0466798ca68214cc644c28f117e7b89b [file] [log] [blame]
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +03001/*
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 Procopciuc2be71a32024-06-12 12:06:36 +030010#define S32CC_A53_MIN_FREQ (48UL * MHZ)
11#define S32CC_A53_MAX_FREQ (1000UL * MHZ)
12
Ghennadi Procopciucd3cd7832024-09-17 09:02:24 +030013/* Partitions */
14static struct s32cc_part part0 = S32CC_PART(0);
15
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +030016/* Oscillators */
17static struct s32cc_osc fxosc =
18 S32CC_OSC_INIT(S32CC_FXOSC);
19static struct s32cc_clk fxosc_clk =
20 S32CC_MODULE_CLK(fxosc);
21
22static struct s32cc_osc firc =
23 S32CC_OSC_INIT(S32CC_FIRC);
24static struct s32cc_clk firc_clk =
25 S32CC_MODULE_CLK(firc);
26
27static struct s32cc_osc sirc =
28 S32CC_OSC_INIT(S32CC_SIRC);
29static struct s32cc_clk sirc_clk =
30 S32CC_MODULE_CLK(sirc);
31
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030032/* ARM PLL */
33static 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);
37static struct s32cc_clk arm_pll_mux_clk =
38 S32CC_MODULE_CLK(arm_pll_mux);
39static struct s32cc_pll armpll =
40 S32CC_PLL_INIT(arm_pll_mux_clk, S32CC_ARM_PLL, 2);
41static struct s32cc_clk arm_pll_vco_clk =
42 S32CC_FREQ_MODULE_CLK(armpll, 1400 * MHZ, 2000 * MHZ);
43
44static struct s32cc_pll_out_div arm_pll_phi0_div =
45 S32CC_PLL_OUT_DIV_INIT(armpll, 0);
46static struct s32cc_clk arm_pll_phi0_clk =
47 S32CC_FREQ_MODULE_CLK(arm_pll_phi0_div, 0, GHZ);
48
Ghennadi Procopciuc64949662024-08-05 16:49:51 +030049/* ARM DFS */
50static struct s32cc_dfs armdfs =
51 S32CC_DFS_INIT(armpll, S32CC_ARM_DFS);
52static struct s32cc_dfs_div arm_dfs1_div =
53 S32CC_DFS_DIV_INIT(armdfs, 0);
54static struct s32cc_clk arm_dfs1_clk =
55 S32CC_FREQ_MODULE_CLK(arm_dfs1_div, 0, 800 * MHZ);
56
57/* MC_CGM0 */
58static 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);
62static struct s32cc_clk cgm0_mux0_clk = S32CC_MODULE_CLK(cgm0_mux0);
63
Ghennadi Procopciuc0609bcd2024-08-06 13:25:51 +030064static 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);
69static struct s32cc_clk cgm0_mux8_clk = S32CC_MODULE_CLK(cgm0_mux8);
70
Ghennadi Procopciuc64949662024-08-05 16:49:51 +030071/* XBAR */
72static struct s32cc_clk xbar_2x_clk =
73 S32CC_CHILD_CLK(cgm0_mux0_clk, 48 * MHZ, 800 * MHZ);
74static struct s32cc_fixed_div xbar_div2 =
75 S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 2);
76static struct s32cc_clk xbar_clk =
77 S32CC_FREQ_MODULE_CLK(xbar_div2, 24 * MHZ, 400 * MHZ);
78static struct s32cc_fixed_div xbar_div4 =
79 S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 4);
80static struct s32cc_clk xbar_div2_clk =
81 S32CC_FREQ_MODULE_CLK(xbar_div4, 12 * MHZ, 200 * MHZ);
82static struct s32cc_fixed_div xbar_div6 =
83 S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 6);
84static struct s32cc_clk xbar_div3_clk =
85 S32CC_FREQ_MODULE_CLK(xbar_div6, 8 * MHZ, 133333333);
86static struct s32cc_fixed_div xbar_div8 =
87 S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 8);
88static struct s32cc_clk xbar_div4_clk =
89 S32CC_FREQ_MODULE_CLK(xbar_div8, 6 * MHZ, 100 * MHZ);
90static struct s32cc_fixed_div xbar_div12 =
91 S32CC_FIXED_DIV_INIT(cgm0_mux0_clk, 12);
92static struct s32cc_clk xbar_div6_clk =
93 S32CC_FREQ_MODULE_CLK(xbar_div12, 4 * MHZ, 66666666);
94
Ghennadi Procopciuc0609bcd2024-08-06 13:25:51 +030095/* Linflex */
96static struct s32cc_clk linflex_baud_clk =
97 S32CC_CHILD_CLK(cgm0_mux8_clk, 19200, 133333333);
98static struct s32cc_fixed_div linflex_div =
99 S32CC_FIXED_DIV_INIT(linflex_baud_clk, 2);
100static struct s32cc_clk linflex_clk =
101 S32CC_FREQ_MODULE_CLK(linflex_div, 9600, 66666666);
102
Ghennadi Procopciuc8384d182024-06-12 10:53:06 +0300103/* MC_CGM1 */
104static 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);
109static struct s32cc_clk cgm1_mux0_clk = S32CC_MODULE_CLK(cgm1_mux0);
110
Ghennadi Procopciuc2be71a32024-06-12 12:06:36 +0300111/* A53_CORE */
112static 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 */
116static struct s32cc_fixed_div a53_core_div2 =
117 S32CC_FIXED_DIV_INIT(cgm1_mux0_clk, 2);
118static 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 */
122static struct s32cc_fixed_div a53_core_div10 =
123 S32CC_FIXED_DIV_INIT(cgm1_mux0_clk, 10);
124static 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 Procopciuc22f94742024-08-06 11:48:11 +0300128/* PERIPH PLL */
129static 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);
133static struct s32cc_clk periph_pll_mux_clk =
134 S32CC_MODULE_CLK(periph_pll_mux);
135static struct s32cc_pll periphpll =
136 S32CC_PLL_INIT(periph_pll_mux_clk, S32CC_PERIPH_PLL, 2);
137static struct s32cc_clk periph_pll_vco_clk =
138 S32CC_FREQ_MODULE_CLK(periphpll, 1300 * MHZ, 2 * GHZ);
139
140static struct s32cc_pll_out_div periph_pll_phi3_div =
141 S32CC_PLL_OUT_DIV_INIT(periphpll, 3);
142static struct s32cc_clk periph_pll_phi3_clk =
143 S32CC_FREQ_MODULE_CLK(periph_pll_phi3_div, 0, 133333333);
144
Ghennadi Procopciucd3cd7832024-09-17 09:02:24 +0300145/* DDR PLL */
146static 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);
150static struct s32cc_clk ddr_pll_mux_clk =
151 S32CC_MODULE_CLK(ddr_pll_mux);
152static struct s32cc_pll ddrpll =
153 S32CC_PLL_INIT(ddr_pll_mux_clk, S32CC_DDR_PLL, 1);
154static struct s32cc_clk ddr_pll_vco_clk =
155 S32CC_FREQ_MODULE_CLK(ddrpll, 1300 * MHZ, 1600 * MHZ);
156
157static struct s32cc_pll_out_div ddr_pll_phi0_div =
158 S32CC_PLL_OUT_DIV_INIT(ddrpll, 0);
159static struct s32cc_clk ddr_pll_phi0_clk =
160 S32CC_FREQ_MODULE_CLK(ddr_pll_phi0_div, 0, 800 * MHZ);
161
162/* MC_CGM5 */
163static 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);
168static struct s32cc_clk cgm5_mux0_clk = S32CC_MODULE_CLK(cgm5_mux0);
169
170/* DDR clock */
171static struct s32cc_part_block part0_block1 =
172 S32CC_PART_BLOCK(&part0, s32cc_part_block1);
173static struct s32cc_part_block_link ddr_block_link =
174 S32CC_PART_BLOCK_LINK(cgm5_mux0_clk, &part0_block1);
175static struct s32cc_clk ddr_clk =
176 S32CC_FREQ_MODULE_CLK(ddr_block_link, 0, 800 * MHZ);
177
178static struct s32cc_clk *s32cc_hw_clk_list[37] = {
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +0300179 /* 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 Procopciuc7277b972024-06-12 09:53:18 +0300183 /* ARM PLL */
184 [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_PHI0)] = &arm_pll_phi0_clk,
Ghennadi Procopciuc64949662024-08-05 16:49:51 +0300185 /* ARM DFS */
186 [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_DFS1)] = &arm_dfs1_clk,
Ghennadi Procopciuc22f94742024-08-06 11:48:11 +0300187 /* PERIPH PLL */
188 [S32CC_CLK_ID(S32CC_CLK_PERIPH_PLL_PHI3)] = &periph_pll_phi3_clk,
Ghennadi Procopciucd3cd7832024-09-17 09:02:24 +0300189 /* DDR PLL */
190 [S32CC_CLK_ID(S32CC_CLK_DDR_PLL_PHI0)] = &ddr_pll_phi0_clk,
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +0300191};
192
193static 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 Procopciucd3cd7832024-09-17 09:02:24 +0300199static struct s32cc_clk *s32cc_arch_clk_list[22] = {
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +0300200 /* 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 Procopciuc22f94742024-08-06 11:48:11 +0300203 /* 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 Procopciuc64949662024-08-05 16:49:51 +0300206 /* MC_CGM0 */
207 [S32CC_CLK_ID(S32CC_CLK_MC_CGM0_MUX0)] = &cgm0_mux0_clk,
Ghennadi Procopciuc0609bcd2024-08-06 13:25:51 +0300208 [S32CC_CLK_ID(S32CC_CLK_MC_CGM0_MUX8)] = &cgm0_mux8_clk,
Ghennadi Procopciuc64949662024-08-05 16:49:51 +0300209 /* 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 Procopciuc8384d182024-06-12 10:53:06 +0300216 /* MC_CGM1 */
217 [S32CC_CLK_ID(S32CC_CLK_MC_CGM1_MUX0)] = &cgm1_mux0_clk,
Ghennadi Procopciuc2be71a32024-06-12 12:06:36 +0300218 /* 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 Procopciuc0609bcd2024-08-06 13:25:51 +0300222 /* Linflex */
223 [S32CC_CLK_ID(S32CC_CLK_LINFLEX)] = &linflex_clk,
224 [S32CC_CLK_ID(S32CC_CLK_LINFLEX_BAUD)] = &linflex_baud_clk,
Ghennadi Procopciucd3cd7832024-09-17 09:02:24 +0300225 /* 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 Procopciuc7277b972024-06-12 09:53:18 +0300232};
233
234static 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 Procopciuc302831c2024-09-11 09:29:50 +0300240static const struct s32cc_clk_array *s32cc_clk_table[2] = {
241 &s32cc_hw_clocks,
242 &s32cc_arch_clocks,
243};
244
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +0300245struct s32cc_clk *s32cc_get_arch_clk(unsigned long id)
246{
Ghennadi Procopciuc302831c2024-09-11 09:29:50 +0300247 return s32cc_get_clk_from_table(s32cc_clk_table,
248 ARRAY_SIZE(s32cc_clk_table),
249 id);
250}
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +0300251
Ghennadi Procopciuc302831c2024-09-11 09:29:50 +0300252int 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 Procopciucecc98d22024-06-12 07:38:52 +0300257}