1 /*
2  * Copyright (c) 2023 Ambiq Micro Inc. <www.ambiq.com>
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/init.h>
8 
9 #include <am_mcu_apollo.h>
10 
11 extern void ambiq_power_init(void);
12 
soc_early_init_hook(void)13 void soc_early_init_hook(void)
14 {
15 	/* Set the clock frequency. */
16 	am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_SYSCLK_MAX, 0);
17 
18 	/* Enable Flash cache.*/
19 	am_hal_cachectrl_config(&am_hal_cachectrl_defaults);
20 	am_hal_cachectrl_enable();
21 
22 	/* Initialize for low power in the power control block */
23 	am_hal_pwrctrl_low_power_init();
24 
25 	/* Disable the RTC. */
26 	am_hal_rtc_osc_disable();
27 
28 #ifdef CONFIG_PM
29 	ambiq_power_init();
30 #endif
31 
32 #ifdef CONFIG_LOG_BACKEND_SWO
33 	/* Select HFRC/8 (6MHz) for the TPIU clock source */
34 	MCUCTRL->TPIUCTRL_b.CLKSEL = MCUCTRL_TPIUCTRL_CLKSEL_HFRCDIV8;
35 	MCUCTRL->TPIUCTRL_b.ENABLE = MCUCTRL_TPIUCTRL_ENABLE_EN;
36 #endif
37 }
38