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 | |
| 10 | /* Oscillators */ |
| 11 | static struct s32cc_osc fxosc = |
| 12 | S32CC_OSC_INIT(S32CC_FXOSC); |
| 13 | static struct s32cc_clk fxosc_clk = |
| 14 | S32CC_MODULE_CLK(fxosc); |
| 15 | |
| 16 | static struct s32cc_osc firc = |
| 17 | S32CC_OSC_INIT(S32CC_FIRC); |
| 18 | static struct s32cc_clk firc_clk = |
| 19 | S32CC_MODULE_CLK(firc); |
| 20 | |
| 21 | static struct s32cc_osc sirc = |
| 22 | S32CC_OSC_INIT(S32CC_SIRC); |
| 23 | static struct s32cc_clk sirc_clk = |
| 24 | S32CC_MODULE_CLK(sirc); |
| 25 | |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 26 | /* ARM PLL */ |
| 27 | static struct s32cc_clkmux arm_pll_mux = |
| 28 | S32CC_CLKMUX_INIT(S32CC_ARM_PLL, 0, 2, |
| 29 | S32CC_CLK_FIRC, |
| 30 | S32CC_CLK_FXOSC, 0, 0, 0); |
| 31 | static struct s32cc_clk arm_pll_mux_clk = |
| 32 | S32CC_MODULE_CLK(arm_pll_mux); |
| 33 | static struct s32cc_pll armpll = |
| 34 | S32CC_PLL_INIT(arm_pll_mux_clk, S32CC_ARM_PLL, 2); |
| 35 | static struct s32cc_clk arm_pll_vco_clk = |
| 36 | S32CC_FREQ_MODULE_CLK(armpll, 1400 * MHZ, 2000 * MHZ); |
| 37 | |
| 38 | static struct s32cc_pll_out_div arm_pll_phi0_div = |
| 39 | S32CC_PLL_OUT_DIV_INIT(armpll, 0); |
| 40 | static struct s32cc_clk arm_pll_phi0_clk = |
| 41 | S32CC_FREQ_MODULE_CLK(arm_pll_phi0_div, 0, GHZ); |
| 42 | |
Ghennadi Procopciuc | 8384d18 | 2024-06-12 10:53:06 +0300 | [diff] [blame^] | 43 | /* MC_CGM1 */ |
| 44 | static struct s32cc_clkmux cgm1_mux0 = |
| 45 | S32CC_SHARED_CLKMUX_INIT(S32CC_CGM1, 0, 3, |
| 46 | S32CC_CLK_FIRC, |
| 47 | S32CC_CLK_ARM_PLL_PHI0, |
| 48 | S32CC_CLK_ARM_PLL_DFS2, 0, 0); |
| 49 | static struct s32cc_clk cgm1_mux0_clk = S32CC_MODULE_CLK(cgm1_mux0); |
| 50 | |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 51 | static struct s32cc_clk *s32cc_hw_clk_list[5] = { |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 52 | /* Oscillators */ |
| 53 | [S32CC_CLK_ID(S32CC_CLK_FIRC)] = &firc_clk, |
| 54 | [S32CC_CLK_ID(S32CC_CLK_SIRC)] = &sirc_clk, |
| 55 | [S32CC_CLK_ID(S32CC_CLK_FXOSC)] = &fxosc_clk, |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 56 | /* ARM PLL */ |
| 57 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_PHI0)] = &arm_pll_phi0_clk, |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static struct s32cc_clk_array s32cc_hw_clocks = { |
| 61 | .type_mask = S32CC_CLK_TYPE(S32CC_CLK_FIRC), |
| 62 | .clks = &s32cc_hw_clk_list[0], |
| 63 | .n_clks = ARRAY_SIZE(s32cc_hw_clk_list), |
| 64 | }; |
| 65 | |
Ghennadi Procopciuc | 8384d18 | 2024-06-12 10:53:06 +0300 | [diff] [blame^] | 66 | static struct s32cc_clk *s32cc_arch_clk_list[3] = { |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 67 | /* ARM PLL */ |
| 68 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_MUX)] = &arm_pll_mux_clk, |
| 69 | [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_VCO)] = &arm_pll_vco_clk, |
Ghennadi Procopciuc | 8384d18 | 2024-06-12 10:53:06 +0300 | [diff] [blame^] | 70 | /* MC_CGM1 */ |
| 71 | [S32CC_CLK_ID(S32CC_CLK_MC_CGM1_MUX0)] = &cgm1_mux0_clk, |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | static struct s32cc_clk_array s32cc_arch_clocks = { |
| 75 | .type_mask = S32CC_CLK_TYPE(S32CC_CLK_ARM_PLL_MUX), |
| 76 | .clks = &s32cc_arch_clk_list[0], |
| 77 | .n_clks = ARRAY_SIZE(s32cc_arch_clk_list), |
| 78 | }; |
| 79 | |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 80 | struct s32cc_clk *s32cc_get_arch_clk(unsigned long id) |
| 81 | { |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 82 | static const struct s32cc_clk_array *clk_table[2] = { |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 83 | &s32cc_hw_clocks, |
Ghennadi Procopciuc | 7277b97 | 2024-06-12 09:53:18 +0300 | [diff] [blame] | 84 | &s32cc_arch_clocks, |
Ghennadi Procopciuc | ecc98d2 | 2024-06-12 07:38:52 +0300 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | return s32cc_get_clk_from_table(clk_table, ARRAY_SIZE(clk_table), id); |
| 88 | } |