1 /*
2 * Copyright (c) 2021 metraTec GmbH
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/device.h>
9 #include <zephyr/init.h>
10 #include <soc.h>
11 #include <fsl_power.h>
12 #include <fsl_clock.h>
13
soc_early_init_hook(void)14 void soc_early_init_hook(void)
15 {
16 POWER_DisablePD(kPDRUNCFG_PD_FRO_EN);
17 CLOCK_SetupFROClocking(12000000U);
18 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
19
20 CLOCK_SetFLASHAccessCyclesForFreq(12000000U);
21
22 CLOCK_SetClkDiv(kCLOCK_DivAhbClk, 1U, false);
23 CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 0U, true);
24 CLOCK_SetClkDiv(kCLOCK_DivSystickClk, 1U, false);
25
26 CLOCK_AttachClk(kFRO12M_to_MAIN_CLK);
27
28 /* Attach 12 MHz clock to flexcomm0 */
29 CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
30
31 #if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_i2c, okay)
32 /* attach 12 MHz clock for flexcomm4 */
33 CLOCK_AttachClk(kFRO12M_to_FLEXCOMM4);
34 #endif
35
36 #if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm5), nxp_lpc_spi, okay)
37 /* attach 12MHz clock to flexcomm5 */
38 CLOCK_AttachClk(kFRO12M_to_FLEXCOMM5);
39 #endif
40
41 POWER_DisablePD(kPDRUNCFG_PD_ADC0);
42 POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA);
43 POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW);
44 POWER_DisablePD(kPDRUNCFG_PD_TEMPS);
45 }
46
47 #ifdef CONFIG_SOC_RESET_HOOK
soc_reset_hook(void)48 void soc_reset_hook(void)
49 {
50 SystemInit();
51 }
52 #endif /* CONFIG_SOC_RESET_HOOK */
53