xref: /rk3399_ARM-atf/drivers/nxp/clk/s32cc/s32cc_early_clks.c (revision 7ad4e2312f58606ee74ac7c655a655bd85148582)
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)
12*7ad4e231SGhennadi Procopciuc #define S32CC_ARM_PLL_VCO_FREQ	(2U * GHZ)
1366af5425SGhennadi Procopciuc 
1466af5425SGhennadi Procopciuc int s32cc_init_early_clks(void)
1566af5425SGhennadi Procopciuc {
1666af5425SGhennadi Procopciuc 	int ret;
1766af5425SGhennadi Procopciuc 
1866af5425SGhennadi Procopciuc 	s32cc_clk_register_drv();
1966af5425SGhennadi Procopciuc 
2083af4504SGhennadi Procopciuc 	ret = clk_set_parent(S32CC_CLK_ARM_PLL_MUX, S32CC_CLK_FXOSC);
2183af4504SGhennadi Procopciuc 	if (ret != 0) {
2283af4504SGhennadi Procopciuc 		return ret;
2383af4504SGhennadi Procopciuc 	}
2483af4504SGhennadi Procopciuc 
2583af4504SGhennadi Procopciuc 	ret = clk_set_parent(S32CC_CLK_MC_CGM1_MUX0, S32CC_CLK_ARM_PLL_PHI0);
2683af4504SGhennadi Procopciuc 	if (ret != 0) {
2783af4504SGhennadi Procopciuc 		return ret;
2883af4504SGhennadi Procopciuc 	}
2983af4504SGhennadi Procopciuc 
3066af5425SGhennadi Procopciuc 	ret = clk_set_rate(S32CC_CLK_FXOSC, S32CC_FXOSC_FREQ, NULL);
3166af5425SGhennadi Procopciuc 	if (ret != 0) {
3266af5425SGhennadi Procopciuc 		return ret;
3366af5425SGhennadi Procopciuc 	}
3466af5425SGhennadi Procopciuc 
35*7ad4e231SGhennadi Procopciuc 	ret = clk_set_rate(S32CC_CLK_ARM_PLL_VCO, S32CC_ARM_PLL_VCO_FREQ, NULL);
36*7ad4e231SGhennadi Procopciuc 	if (ret != 0) {
37*7ad4e231SGhennadi Procopciuc 		return ret;
38*7ad4e231SGhennadi Procopciuc 	}
39*7ad4e231SGhennadi Procopciuc 
408ab34357SGhennadi Procopciuc 	ret = clk_enable(S32CC_CLK_FXOSC);
418ab34357SGhennadi Procopciuc 	if (ret != 0) {
428ab34357SGhennadi Procopciuc 		return ret;
438ab34357SGhennadi Procopciuc 	}
448ab34357SGhennadi Procopciuc 
4566af5425SGhennadi Procopciuc 	return ret;
4666af5425SGhennadi Procopciuc }
47