soc: sam: Add poweroff implementation

This commit adds an implementation of poweroff, which first
uses SUPC to enable all defined wakeup sources (except for
sam4l), followed by entering backup mode.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit is contained in:
Bjarki Arge Andreasen 2023-10-20 00:26:08 +02:00 committed by Carles Cufí
commit 9b21d4d366
9 changed files with 74 additions and 0 deletions

View file

@ -4,6 +4,8 @@ zephyr_include_directories(.)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_pmc.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_gpio.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_supc.c)
zephyr_library_sources_ifndef(CONFIG_SOC_SERIES_SAM4L soc_poweroff.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_pm.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_gpio.c)
zephyr_library_sources_ifdef(CONFIG_SOC_SERIES_SAM4L soc_sam4l_poweroff.c)

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Bjarki Arge Andreasen
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/poweroff.h>
#include <soc.h>
/*
* Poweroff will make the chip enter the backup low-power mode, which
* achieves the lowest possible power consumption. Wakeup from this mode
* requires enabling a wakeup source or input, or power cycling the device.
*/
static void soc_core_sleepdeep_enable(void)
{
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
}
static void soc_core_sleepdeep_wait(void)
{
__WFE();
__WFI();
}
void z_sys_poweroff(void)
{
soc_core_sleepdeep_enable();
soc_supc_core_voltage_regulator_off();
soc_core_sleepdeep_wait();
CODE_UNREACHABLE;
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2023 Bjarki Arge Andreasen
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/sys/poweroff.h>
#include <soc.h>
/*
* Poweroff will make the chip enter the backup low-power mode, which
* achieves the lowest possible power consumption. Wakeup from this mode
* requires enabling a wakeup source or input, or power cycling the device.
*/
static void soc_core_sleepdeep_enable(void)
{
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
}
static void soc_core_sleepdeep_wait(void)
{
__WFE();
__WFI();
}
void z_sys_poweroff(void)
{
soc_core_sleepdeep_enable();
BPM->PMCON |= BPM_PMCON_BKUP;
soc_core_sleepdeep_wait();
CODE_UNREACHABLE;
}

View file

@ -15,6 +15,7 @@ config SOC_SERIES_SAM3X
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM3X Cortex-M3 microcontrollers.
Part No.: SAM3X8E

View file

@ -15,6 +15,7 @@ config SOC_SERIES_SAM4E
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4E Cortex-M4 microcontrollers.
Part No.: SAM4E16E, SAM4E16C, SAM4E8E, SAM4E8C

View file

@ -10,6 +10,7 @@ config SOC_SERIES_SAM4L
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4L Cortex-M4 microcontrollers.
Part No.: SAM4LS8C, SAM4LS8B, SAM4LS8A, SAM4LS4C, SAM4LS4B,

View file

@ -14,6 +14,7 @@ config SOC_SERIES_SAM4S
select SOC_FAMILY_SAM
select PLATFORM_SPECIFIC_INIT
select ASF
select HAS_POWEROFF
help
Enable support for Atmel SAM4S Cortex-M4 microcontrollers.
Part No.: SAM4S16C, SAM4S16B, SAM4S8C, SAM4S8B,

View file

@ -16,6 +16,7 @@ config SOC_SERIES_SAME70
select ASF
select HAS_SWO
select XIP
select HAS_POWEROFF
help
Enable support for Atmel SAM E70 ARM Cortex-M7 Microcontrollers.
Part No.: SAME70J19, SAME70J20, SAME70J21, SAME70N19, SAME70N20,

View file

@ -16,6 +16,7 @@ config SOC_SERIES_SAMV71
select ASF
select HAS_SWO
select XIP
select HAS_POWEROFF
help
Enable support for Atmel SAM V71 ARM Cortex-M7 Microcontrollers.
Part No.: SAMV71J19, SAMV71J20, SAMV71J21, SAMV71N19, SAMV71N20,