blob: 1f381b601d46ed21aca5c0d2e02a0862ae9b9e4b [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
10/* Oscillators */
11static struct s32cc_osc fxosc =
12 S32CC_OSC_INIT(S32CC_FXOSC);
13static struct s32cc_clk fxosc_clk =
14 S32CC_MODULE_CLK(fxosc);
15
16static struct s32cc_osc firc =
17 S32CC_OSC_INIT(S32CC_FIRC);
18static struct s32cc_clk firc_clk =
19 S32CC_MODULE_CLK(firc);
20
21static struct s32cc_osc sirc =
22 S32CC_OSC_INIT(S32CC_SIRC);
23static struct s32cc_clk sirc_clk =
24 S32CC_MODULE_CLK(sirc);
25
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030026/* ARM PLL */
27static 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);
31static struct s32cc_clk arm_pll_mux_clk =
32 S32CC_MODULE_CLK(arm_pll_mux);
33static struct s32cc_pll armpll =
34 S32CC_PLL_INIT(arm_pll_mux_clk, S32CC_ARM_PLL, 2);
35static struct s32cc_clk arm_pll_vco_clk =
36 S32CC_FREQ_MODULE_CLK(armpll, 1400 * MHZ, 2000 * MHZ);
37
38static struct s32cc_pll_out_div arm_pll_phi0_div =
39 S32CC_PLL_OUT_DIV_INIT(armpll, 0);
40static struct s32cc_clk arm_pll_phi0_clk =
41 S32CC_FREQ_MODULE_CLK(arm_pll_phi0_div, 0, GHZ);
42
Ghennadi Procopciuc8384d182024-06-12 10:53:06 +030043/* MC_CGM1 */
44static 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);
49static struct s32cc_clk cgm1_mux0_clk = S32CC_MODULE_CLK(cgm1_mux0);
50
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030051static struct s32cc_clk *s32cc_hw_clk_list[5] = {
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +030052 /* 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 Procopciuc7277b972024-06-12 09:53:18 +030056 /* ARM PLL */
57 [S32CC_CLK_ID(S32CC_CLK_ARM_PLL_PHI0)] = &arm_pll_phi0_clk,
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +030058};
59
60static 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 Procopciuc8384d182024-06-12 10:53:06 +030066static struct s32cc_clk *s32cc_arch_clk_list[3] = {
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030067 /* 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 Procopciuc8384d182024-06-12 10:53:06 +030070 /* MC_CGM1 */
71 [S32CC_CLK_ID(S32CC_CLK_MC_CGM1_MUX0)] = &cgm1_mux0_clk,
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030072};
73
74static 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 Procopciucecc98d22024-06-12 07:38:52 +030080struct s32cc_clk *s32cc_get_arch_clk(unsigned long id)
81{
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030082 static const struct s32cc_clk_array *clk_table[2] = {
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +030083 &s32cc_hw_clocks,
Ghennadi Procopciuc7277b972024-06-12 09:53:18 +030084 &s32cc_arch_clocks,
Ghennadi Procopciucecc98d22024-06-12 07:38:52 +030085 };
86
87 return s32cc_get_clk_from_table(clk_table, ARRAY_SIZE(clk_table), id);
88}