diff --git a/soc/arm/atmel_sam/common/CMakeLists.txt b/soc/arm/atmel_sam/common/CMakeLists.txt index 0c8602d1a355677..fe19e6282e9b68e 100644 --- a/soc/arm/atmel_sam/common/CMakeLists.txt +++ b/soc/arm/atmel_sam/common/CMakeLists.txt @@ -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_ifndef(CONFIG_SOC_SERIES_SAM4L soc_poweroff.c) diff --git a/soc/arm/atmel_sam/common/soc_poweroff.c b/soc/arm/atmel_sam/common/soc_poweroff.c new file mode 100644 index 000000000000000..9d4ecd3d9707fa2 --- /dev/null +++ b/soc/arm/atmel_sam/common/soc_poweroff.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Bjarki Arge Andreasen + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* + * 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_supc_configure_wakeup_sources(); + soc_supc_configure_wakeup_inputs(); + soc_core_sleepdeep_enable(); + soc_supc_core_voltage_regulator_off(); + soc_core_sleepdeep_wait(); + + CODE_UNREACHABLE; +} diff --git a/soc/arm/atmel_sam/common/soc_sam4l_poweroff.c b/soc/arm/atmel_sam/common/soc_sam4l_poweroff.c new file mode 100644 index 000000000000000..dae4a97f588073c --- /dev/null +++ b/soc/arm/atmel_sam/common/soc_sam4l_poweroff.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 Bjarki Arge Andreasen + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +/* + * 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) +{ + core_sleepdeep_enable(); + BMP->PMCON |= BPM_PMCON_BKUP; + soc_core_sleepdeep_wait(); + + CODE_UNREACHABLE; +} diff --git a/soc/arm/atmel_sam/sam3x/Kconfig.series b/soc/arm/atmel_sam/sam3x/Kconfig.series index 911eab6b1cc7a6a..08a3781b6d3ea19 100644 --- a/soc/arm/atmel_sam/sam3x/Kconfig.series +++ b/soc/arm/atmel_sam/sam3x/Kconfig.series @@ -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 diff --git a/soc/arm/atmel_sam/sam4e/Kconfig.series b/soc/arm/atmel_sam/sam4e/Kconfig.series index 612e1d20bd62e2b..93cc0e20a483652 100644 --- a/soc/arm/atmel_sam/sam4e/Kconfig.series +++ b/soc/arm/atmel_sam/sam4e/Kconfig.series @@ -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 diff --git a/soc/arm/atmel_sam/sam4l/Kconfig.series b/soc/arm/atmel_sam/sam4l/Kconfig.series index 7a41ba2ff246d75..0a8192f5bd9fddb 100644 --- a/soc/arm/atmel_sam/sam4l/Kconfig.series +++ b/soc/arm/atmel_sam/sam4l/Kconfig.series @@ -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, diff --git a/soc/arm/atmel_sam/sam4s/Kconfig.series b/soc/arm/atmel_sam/sam4s/Kconfig.series index 34fe0ce55f2789c..f591d96ba88e3a6 100644 --- a/soc/arm/atmel_sam/sam4s/Kconfig.series +++ b/soc/arm/atmel_sam/sam4s/Kconfig.series @@ -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, diff --git a/soc/arm/atmel_sam/same70/Kconfig.series b/soc/arm/atmel_sam/same70/Kconfig.series index f8955bd4a769a50..0e19a2197bad346 100644 --- a/soc/arm/atmel_sam/same70/Kconfig.series +++ b/soc/arm/atmel_sam/same70/Kconfig.series @@ -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, diff --git a/soc/arm/atmel_sam/samv71/Kconfig.series b/soc/arm/atmel_sam/samv71/Kconfig.series index 75072eec1eeee2a..49de040aff8dd0f 100644 --- a/soc/arm/atmel_sam/samv71/Kconfig.series +++ b/soc/arm/atmel_sam/samv71/Kconfig.series @@ -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,