1 /*
2  * Copyright (c) 2023 Bjarki Arge Andreasen
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/device.h>
7 #include <zephyr/sys/util_macro.h>
8 #include <soc.h>
9 
10 #define SOC_SUPC_WAKEUP_SOURCE_IDS (3)
11 
soc_supc_core_voltage_regulator_off(void)12 void soc_supc_core_voltage_regulator_off(void)
13 {
14 	SUPC->SUPC_CR = SUPC_CR_KEY_PASSWD | SUPC_CR_VROFF_STOP_VREG;
15 }
16 
soc_supc_slow_clock_select_crystal_osc(void)17 void soc_supc_slow_clock_select_crystal_osc(void)
18 {
19 	SUPC->SUPC_CR = SUPC_CR_KEY_PASSWD | SUPC_CR_XTALSEL_CRYSTAL_SEL;
20 
21 	/* Wait for oscillator to be stabilized. */
22 	while (!(SUPC->SUPC_SR & SUPC_SR_OSCSEL)) {
23 	}
24 }
25 
soc_supc_enable_wakeup_source(uint32_t wakeup_source_id)26 void soc_supc_enable_wakeup_source(uint32_t wakeup_source_id)
27 {
28 	__ASSERT(wakeup_source_id <= SOC_SUPC_WAKEUP_SOURCE_IDS,
29 		 "Wakeup source channel is invalid");
30 
31 	SUPC->SUPC_WUMR |= 1 << wakeup_source_id;
32 }
33