1 /*
2  * Copyright (c) 2021 Linaro Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief System/hardware module for STM32U5 processor
10  */
11 
12 #include <zephyr/device.h>
13 #include <zephyr/init.h>
14 #include <stm32_ll_bus.h>
15 #include <stm32_ll_pwr.h>
16 #include <stm32_ll_icache.h>
17 #include <zephyr/logging/log.h>
18 
19 #include <cmsis_core.h>
20 
21 #define LOG_LEVEL CONFIG_SOC_LOG_LEVEL
22 LOG_MODULE_REGISTER(soc);
23 
24 extern void stm32_power_init(void);
25 /**
26  * @brief Perform basic hardware initialization at boot.
27  *
28  * This needs to be run from the very beginning.
29  */
soc_early_init_hook(void)30 void soc_early_init_hook(void)
31 {
32 	/* Enable instruction cache in 1-way (direct mapped cache) */
33 	LL_ICACHE_SetMode(LL_ICACHE_1WAY);
34 	LL_ICACHE_Enable();
35 
36 	/* Update CMSIS SystemCoreClock variable (HCLK) */
37 	/* At reset, system core clock is set to 4 MHz from MSIS */
38 	SystemCoreClock = 4000000;
39 
40 	/* Enable PWR */
41 	LL_AHB3_GRP1_EnableClock(LL_AHB3_GRP1_PERIPH_PWR);
42 
43 	/* For devices with USB C PD, we can disable the dead battery
44 	 * pull-down behaviour.
45 	 */
46 #if defined(UCPD1)
47 	if (IS_ENABLED(CONFIG_DT_HAS_ST_STM32_UCPD_ENABLED) ||
48 		!IS_ENABLED(CONFIG_USB_DEVICE_DRIVER)) {
49 		/* Disable USB Type-C dead battery pull-down behavior */
50 		LL_PWR_DisableUCPDDeadBattery();
51 	}
52 #endif
53 
54 	/* Power Configuration */
55 #if defined(CONFIG_POWER_SUPPLY_DIRECT_SMPS)
56 	LL_PWR_SetRegulatorSupply(LL_PWR_SMPS_SUPPLY);
57 #elif defined(CONFIG_POWER_SUPPLY_LDO)
58 	LL_PWR_SetRegulatorSupply(LL_PWR_LDO_SUPPLY);
59 #else
60 #error "Unsupported power configuration"
61 #endif
62 
63 #if CONFIG_PM
64 	stm32_power_init();
65 #endif
66 }
67