xref: /rk3399_ARM-atf/drivers/nxp/clk/s32cc/s32cc_clk_modules.c (revision a8be748a2821355734f603342b2d2cf7105f6a30)
17c36209bSGhennadi Procopciuc /*
27c36209bSGhennadi Procopciuc  * Copyright 2020-2024 NXP
37c36209bSGhennadi Procopciuc  *
47c36209bSGhennadi Procopciuc  * SPDX-License-Identifier: BSD-3-Clause
57c36209bSGhennadi Procopciuc  */
67c36209bSGhennadi Procopciuc #include <s32cc-clk-ids.h>
77c36209bSGhennadi Procopciuc #include <s32cc-clk-modules.h>
87c36209bSGhennadi Procopciuc #include <s32cc-clk-utils.h>
97c36209bSGhennadi Procopciuc 
107c36209bSGhennadi Procopciuc /* Oscillators */
117c36209bSGhennadi Procopciuc static struct s32cc_osc fxosc =
127c36209bSGhennadi Procopciuc 	S32CC_OSC_INIT(S32CC_FXOSC);
137c36209bSGhennadi Procopciuc static struct s32cc_clk fxosc_clk =
147c36209bSGhennadi Procopciuc 	S32CC_MODULE_CLK(fxosc);
157c36209bSGhennadi Procopciuc 
167c36209bSGhennadi Procopciuc static struct s32cc_osc firc =
177c36209bSGhennadi Procopciuc 	S32CC_OSC_INIT(S32CC_FIRC);
187c36209bSGhennadi Procopciuc static struct s32cc_clk firc_clk =
197c36209bSGhennadi Procopciuc 	S32CC_MODULE_CLK(firc);
207c36209bSGhennadi Procopciuc 
217c36209bSGhennadi Procopciuc static struct s32cc_osc sirc =
227c36209bSGhennadi Procopciuc 	S32CC_OSC_INIT(S32CC_SIRC);
237c36209bSGhennadi Procopciuc static struct s32cc_clk sirc_clk =
247c36209bSGhennadi Procopciuc 	S32CC_MODULE_CLK(sirc);
257c36209bSGhennadi Procopciuc 
26*a8be748aSGhennadi Procopciuc /* ARM PLL */
27*a8be748aSGhennadi Procopciuc static struct s32cc_clkmux arm_pll_mux =
28*a8be748aSGhennadi Procopciuc 	S32CC_CLKMUX_INIT(S32CC_ARM_PLL, 0, 2,
29*a8be748aSGhennadi Procopciuc 			  S32CC_CLK_FIRC,
30*a8be748aSGhennadi Procopciuc 			  S32CC_CLK_FXOSC, 0, 0, 0);
31*a8be748aSGhennadi Procopciuc static struct s32cc_clk arm_pll_mux_clk =
32*a8be748aSGhennadi Procopciuc 	S32CC_MODULE_CLK(arm_pll_mux);
33*a8be748aSGhennadi Procopciuc static struct s32cc_pll armpll =
34*a8be748aSGhennadi Procopciuc 	S32CC_PLL_INIT(arm_pll_mux_clk, S32CC_ARM_PLL, 2);
35*a8be748aSGhennadi Procopciuc static struct s32cc_clk arm_pll_vco_clk =
36*a8be748aSGhennadi Procopciuc 	S32CC_FREQ_MODULE_CLK(armpll, 1400 * MHZ, 2000 * MHZ);
37*a8be748aSGhennadi Procopciuc 
38*a8be748aSGhennadi Procopciuc static struct s32cc_pll_out_div arm_pll_phi0_div =
39*a8be748aSGhennadi Procopciuc 	S32CC_PLL_OUT_DIV_INIT(armpll, 0);
40*a8be748aSGhennadi Procopciuc static struct s32cc_clk arm_pll_phi0_clk =
41*a8be748aSGhennadi Procopciuc 	S32CC_FREQ_MODULE_CLK(arm_pll_phi0_div, 0, GHZ);
42*a8be748aSGhennadi Procopciuc 
43*a8be748aSGhennadi Procopciuc static struct s32cc_clk *s32cc_hw_clk_list[5] = {
447c36209bSGhennadi Procopciuc 	/* Oscillators */
457c36209bSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_FIRC)] = &firc_clk,
467c36209bSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_SIRC)] = &sirc_clk,
477c36209bSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_FXOSC)] = &fxosc_clk,
48*a8be748aSGhennadi Procopciuc 	/* ARM PLL */
49*a8be748aSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_ARM_PLL_PHI0)] = &arm_pll_phi0_clk,
507c36209bSGhennadi Procopciuc };
517c36209bSGhennadi Procopciuc 
527c36209bSGhennadi Procopciuc static struct s32cc_clk_array s32cc_hw_clocks = {
537c36209bSGhennadi Procopciuc 	.type_mask = S32CC_CLK_TYPE(S32CC_CLK_FIRC),
547c36209bSGhennadi Procopciuc 	.clks = &s32cc_hw_clk_list[0],
557c36209bSGhennadi Procopciuc 	.n_clks = ARRAY_SIZE(s32cc_hw_clk_list),
567c36209bSGhennadi Procopciuc };
577c36209bSGhennadi Procopciuc 
58*a8be748aSGhennadi Procopciuc static struct s32cc_clk *s32cc_arch_clk_list[2] = {
59*a8be748aSGhennadi Procopciuc 	/* ARM PLL */
60*a8be748aSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_ARM_PLL_MUX)] = &arm_pll_mux_clk,
61*a8be748aSGhennadi Procopciuc 	[S32CC_CLK_ID(S32CC_CLK_ARM_PLL_VCO)] = &arm_pll_vco_clk,
62*a8be748aSGhennadi Procopciuc };
63*a8be748aSGhennadi Procopciuc 
64*a8be748aSGhennadi Procopciuc static struct s32cc_clk_array s32cc_arch_clocks = {
65*a8be748aSGhennadi Procopciuc 	.type_mask = S32CC_CLK_TYPE(S32CC_CLK_ARM_PLL_MUX),
66*a8be748aSGhennadi Procopciuc 	.clks = &s32cc_arch_clk_list[0],
67*a8be748aSGhennadi Procopciuc 	.n_clks = ARRAY_SIZE(s32cc_arch_clk_list),
68*a8be748aSGhennadi Procopciuc };
69*a8be748aSGhennadi Procopciuc 
707c36209bSGhennadi Procopciuc struct s32cc_clk *s32cc_get_arch_clk(unsigned long id)
717c36209bSGhennadi Procopciuc {
72*a8be748aSGhennadi Procopciuc 	static const struct s32cc_clk_array *clk_table[2] = {
737c36209bSGhennadi Procopciuc 		&s32cc_hw_clocks,
74*a8be748aSGhennadi Procopciuc 		&s32cc_arch_clocks,
757c36209bSGhennadi Procopciuc 	};
767c36209bSGhennadi Procopciuc 
777c36209bSGhennadi Procopciuc 	return s32cc_get_clk_from_table(clk_table, ARRAY_SIZE(clk_table), id);
787c36209bSGhennadi Procopciuc }
79