1 /*
2  * SPDX-License-Identifier: Apache-2.0
3  *
4  * Copyright (c) 2020 Linumiz
5  * Author: Parthiban Nallathambi <parthiban@linumiz.com>
6  *
7  */
8 
9 #include <xmc_scu.h>
10 #include <zephyr/kernel.h>
11 #include <zephyr/init.h>
12 #include <soc.h>
13 
14 #ifdef CONFIG_SOC_XMC4500
15 #define PMU_FLASH_WS		(0x3U)
16 #elif CONFIG_SOC_XMC4700
17 #define PMU_FLASH_WS		(0x4U)
18 #endif
19 
soc_reset_hook(void)20 void soc_reset_hook(void)
21 {
22 	uint32_t temp;
23 
24 	/* unaligned trap bit is enabled on reset. disable it here and set later via */
25 	/* CONFIG_TRAP_UNALIGNED_ACCESS if needed. */
26 	SCB->CCR &= ~SCB_CCR_UNALIGN_TRP_Msk;
27 
28 	/* setup flash wait state */
29 	temp = FLASH0->FCON;
30 	temp &= ~FLASH_FCON_WSPFLASH_Msk;
31 	temp |= PMU_FLASH_WS;
32 	FLASH0->FCON = temp;
33 
34 	XMC_SCU_CLOCK_SetSleepConfig(XMC_SCU_CLOCK_SLEEP_MODE_CONFIG_SYSCLK_FPLL
35 #ifdef CONFIG_PWM_XMC4XXX_CCU4
36 				     | XMC_SCU_CLOCK_SLEEP_MODE_CONFIG_ENABLE_CCU
37 #endif
38 #ifdef CONFIG_PWM_XMC4XXX_CCU8
39 				     | XMC_SCU_CLOCK_SLEEP_MODE_CONFIG_ENABLE_CCU
40 #endif
41 #ifdef CONFIG_ETH_XMC4XXX
42 				     | XMC_SCU_CLOCK_SLEEP_MODE_CONFIG_ENABLE_ETH
43 #endif
44 	);
45 
46 	/* configure PLL & system clock */
47 	SystemCoreClockSetup();
48 }
49