xref: /rk3399_ARM-atf/drivers/nxp/clk/s32cc/s32cc_early_clks.c (revision de950ef04f2bf71924d7ac65e86cfc0cfd97aae3)
166af5425SGhennadi Procopciuc /*
266af5425SGhennadi Procopciuc  * Copyright 2024 NXP
366af5425SGhennadi Procopciuc  *
466af5425SGhennadi Procopciuc  * SPDX-License-Identifier: BSD-3-Clause
566af5425SGhennadi Procopciuc  */
666af5425SGhennadi Procopciuc #include <drivers/clk.h>
766af5425SGhennadi Procopciuc #include <s32cc-clk-drv.h>
866af5425SGhennadi Procopciuc #include <s32cc-clk-ids.h>
966af5425SGhennadi Procopciuc #include <s32cc-clk-utils.h>
1066af5425SGhennadi Procopciuc 
1166af5425SGhennadi Procopciuc #define S32CC_FXOSC_FREQ	(40U * MHZ)
127ad4e231SGhennadi Procopciuc #define S32CC_ARM_PLL_VCO_FREQ	(2U * GHZ)
13*de950ef0SGhennadi Procopciuc #define S32CC_ARM_PLL_PHI0_FREQ	(1U * GHZ)
1466af5425SGhennadi Procopciuc 
1566af5425SGhennadi Procopciuc int s32cc_init_early_clks(void)
1666af5425SGhennadi Procopciuc {
1766af5425SGhennadi Procopciuc 	int ret;
1866af5425SGhennadi Procopciuc 
1966af5425SGhennadi Procopciuc 	s32cc_clk_register_drv();
2066af5425SGhennadi Procopciuc 
2183af4504SGhennadi Procopciuc 	ret = clk_set_parent(S32CC_CLK_ARM_PLL_MUX, S32CC_CLK_FXOSC);
2283af4504SGhennadi Procopciuc 	if (ret != 0) {
2383af4504SGhennadi Procopciuc 		return ret;
2483af4504SGhennadi Procopciuc 	}
2583af4504SGhennadi Procopciuc 
2683af4504SGhennadi Procopciuc 	ret = clk_set_parent(S32CC_CLK_MC_CGM1_MUX0, S32CC_CLK_ARM_PLL_PHI0);
2783af4504SGhennadi Procopciuc 	if (ret != 0) {
2883af4504SGhennadi Procopciuc 		return ret;
2983af4504SGhennadi Procopciuc 	}
3083af4504SGhennadi Procopciuc 
3166af5425SGhennadi Procopciuc 	ret = clk_set_rate(S32CC_CLK_FXOSC, S32CC_FXOSC_FREQ, NULL);
3266af5425SGhennadi Procopciuc 	if (ret != 0) {
3366af5425SGhennadi Procopciuc 		return ret;
3466af5425SGhennadi Procopciuc 	}
3566af5425SGhennadi Procopciuc 
367ad4e231SGhennadi Procopciuc 	ret = clk_set_rate(S32CC_CLK_ARM_PLL_VCO, S32CC_ARM_PLL_VCO_FREQ, NULL);
377ad4e231SGhennadi Procopciuc 	if (ret != 0) {
387ad4e231SGhennadi Procopciuc 		return ret;
397ad4e231SGhennadi Procopciuc 	}
407ad4e231SGhennadi Procopciuc 
41*de950ef0SGhennadi Procopciuc 	ret = clk_set_rate(S32CC_CLK_ARM_PLL_PHI0, S32CC_ARM_PLL_PHI0_FREQ, NULL);
42*de950ef0SGhennadi Procopciuc 	if (ret != 0) {
43*de950ef0SGhennadi Procopciuc 		return ret;
44*de950ef0SGhennadi Procopciuc 	}
45*de950ef0SGhennadi Procopciuc 
468ab34357SGhennadi Procopciuc 	ret = clk_enable(S32CC_CLK_FXOSC);
478ab34357SGhennadi Procopciuc 	if (ret != 0) {
488ab34357SGhennadi Procopciuc 		return ret;
498ab34357SGhennadi Procopciuc 	}
508ab34357SGhennadi Procopciuc 
5166af5425SGhennadi Procopciuc 	return ret;
5266af5425SGhennadi Procopciuc }
53