diff --git a/arch/arm/core/cortex_m/pm_s2ram.c b/arch/arm/core/cortex_m/pm_s2ram.c index 81a4ae20a4f6..ce80c78a078a 100644 --- a/arch/arm/core/cortex_m/pm_s2ram.c +++ b/arch/arm/core/cortex_m/pm_s2ram.c @@ -28,7 +28,7 @@ __noinit #endif _cpu_context_t _cpu_context; -#ifndef CONFIG_PM_S2RAM_CUSTOM_MARKING +#ifndef CONFIG_HAS_PM_S2RAM_CUSTOM_MARKING /** * S2RAM Marker */ @@ -50,4 +50,4 @@ bool pm_s2ram_mark_check_and_clear(void) return false; } -#endif /* CONFIG_PM_S2RAM_CUSTOM_MARKING */ +#endif /* CONFIG_HAS_PM_S2RAM_CUSTOM_MARKING */ diff --git a/include/zephyr/arch/common/pm_s2ram.h b/include/zephyr/arch/common/pm_s2ram.h index 34c544c769b9..322cefe6ebb2 100644 --- a/include/zephyr/arch/common/pm_s2ram.h +++ b/include/zephyr/arch/common/pm_s2ram.h @@ -63,8 +63,8 @@ int arch_pm_s2ram_suspend(pm_s2ram_system_off_fn_t system_off); * Function is called when system state is stored to RAM, just before going to system * off. * - * Default implementation is setting a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING - * allows custom implementation. + * Default implementation is setting a magic word in RAM used if + * CONFIG_HAS_PM_S2RAM_CUSTOM_MARKING is not set. */ void pm_s2ram_mark_set(void); @@ -74,8 +74,8 @@ void pm_s2ram_mark_set(void); * Function is used to determine if resuming after suspend-to-RAM shall be performed * or standard boot code shall be executed. * - * Default implementation is checking a magic word in RAM. CONFIG_PM_S2RAM_CUSTOM_MARKING - * allows custom implementation. + * Default implementation is checking a magic word in RAM used if + * CONFIG_HAS_PM_S2RAM_CUSTOM_MARKING is not set. * * @retval true if marking is found which indicates resuming after suspend-to-RAM. * @retval false if marking is not found which indicates standard boot. diff --git a/samples/boards/nordic/spis_wakeup/prj.conf b/samples/boards/nordic/spis_wakeup/prj.conf index ca92fc6de6ae..e313ffeed82b 100644 --- a/samples/boards/nordic/spis_wakeup/prj.conf +++ b/samples/boards/nordic/spis_wakeup/prj.conf @@ -3,8 +3,6 @@ CONFIG_SPI_SLAVE=y CONFIG_GPIO=y CONFIG_PM=y -CONFIG_PM_S2RAM=y -CONFIG_PM_S2RAM_CUSTOM_MARKING=y CONFIG_PM_DEVICE=y CONFIG_PM_DEVICE_RUNTIME=y diff --git a/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf b/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf index 1de6459a6083..ad4577807f89 100644 --- a/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf +++ b/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf @@ -3,8 +3,6 @@ CONFIG_SPI_NRFX_WAKE_TIMEOUT_US=500 CONFIG_GPIO=y CONFIG_PM=y -CONFIG_PM_S2RAM=y -CONFIG_PM_S2RAM_CUSTOM_MARKING=y CONFIG_PM_DEVICE=y CONFIG_PM_DEVICE_RUNTIME=y diff --git a/samples/boards/st/power_mgmt/suspend_to_ram/prj.conf b/samples/boards/st/power_mgmt/suspend_to_ram/prj.conf index b9a1cf9305e4..1f23c5a27e2c 100644 --- a/samples/boards/st/power_mgmt/suspend_to_ram/prj.conf +++ b/samples/boards/st/power_mgmt/suspend_to_ram/prj.conf @@ -2,7 +2,6 @@ CONFIG_PM=y CONFIG_PM_DEVICE=y CONFIG_PM_DEVICE_RUNTIME=y CONFIG_PM_DEVICE_SYSTEM_MANAGED=y -CONFIG_PM_S2RAM=y CONFIG_ADC=y CONFIG_ENTROPY_GENERATOR=y CONFIG_SPI=y diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index d4c86932a2c4..f07a620ccdb3 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -35,6 +35,7 @@ config SOC_NRF54H20_CPUAPP_COMMON select NRFS_HAS_TEMP_SERVICE select NRFS_HAS_VBUS_DETECTOR_SERVICE select HAS_PM + select HAS_PM_S2RAM_CUSTOM_MARKING select HAS_POWEROFF config SOC_NRF54H20_CPUAPP diff --git a/soc/nordic/nrf54h/pm_s2ram.c b/soc/nordic/nrf54h/pm_s2ram.c index 6916e4884727..768233b2ac8b 100644 --- a/soc/nordic/nrf54h/pm_s2ram.c +++ b/soc/nordic/nrf54h/pm_s2ram.c @@ -76,7 +76,9 @@ typedef struct { struct backup { _nvic_context_t nvic_context; +#if defined(CONFIG_MPU) _mpu_context_t mpu_context; +#endif _scb_context_t scb_context; #if defined(CONFIG_FPU) && !defined(CONFIG_FPU_SHARING) _fpu_context_t fpu_context; @@ -88,6 +90,7 @@ static __noinit struct backup backup_data; extern void z_arm_configure_static_mpu_regions(void); extern int z_arm_mpu_init(void); +#if defined(CONFIG_MPU) /* MPU registers cannot be simply copied because content of RBARx RLARx registers * depends on region which is selected by RNR register. */ @@ -130,6 +133,7 @@ static void mpu_restore(_mpu_context_t *backup) MPU->RNR = rnr; MPU->CTRL = backup->CTRL; } +#endif /* defined(CONFIG_MPU) */ static void nvic_save(_nvic_context_t *backup) { @@ -245,7 +249,9 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off) fpu_power_down(); #endif nvic_save(&backup_data.nvic_context); +#if defined(CONFIG_MPU) mpu_save(&backup_data.mpu_context); +#endif ret = arch_pm_s2ram_suspend(system_off); /* Cache and FPU are powered down so power up is needed even if s2ram failed. */ nrf_power_up_cache(); @@ -260,7 +266,9 @@ int soc_s2ram_suspend(pm_s2ram_system_off_fn_t system_off) return ret; } +#if defined(CONFIG_MPU) mpu_restore(&backup_data.mpu_context); +#endif nvic_restore(&backup_data.nvic_context); scb_restore(&backup_data.scb_context); diff --git a/subsys/pm/Kconfig b/subsys/pm/Kconfig index d1d99ac02e3a..676f4ef229f5 100644 --- a/subsys/pm/Kconfig +++ b/subsys/pm/Kconfig @@ -10,6 +10,14 @@ config HAS_PM This option must be selected by SoCs that provide PM hooks, that is, calls to configure low-power states. +config HAS_PM_S2RAM_CUSTOM_MARKING + bool + depends on HAS_PM + help + By default a magic word in RAM is used to mark entering suspend-to-RAM. If this + option is selected, a custom implementation of functions which handle the marking + must be provided. + config PM bool "System Power Management" depends on SYS_CLOCK_EXISTS && HAS_PM @@ -33,21 +41,17 @@ config PM_STATS help Enable System Power Management Stats. +DT_POWER_STATE_COMPAT := zephyr,power-state + config PM_S2RAM - bool "Suspend-to-RAM (S2RAM)" + bool + default y depends on ARCH_HAS_SUSPEND_TO_RAM + depends on $(dt_compat_any_has_prop,$(DT_POWER_STATE_COMPAT),power-state-name,suspend-to-ram) help - This option enables suspend-to-RAM (S2RAM). - When enabled on Cortex-M, and a 'zephyr,memory-region' compatible node with nodelabel - 'pm_s2ram' is defined in DT, _cpu_context symbol (located in arch/arm/core/cortex_m/pm_s2ram.c) - is placed in linker section given by 'zephyr,memory-region' property of aforementioned node. - -config PM_S2RAM_CUSTOM_MARKING - bool "Use custom marking functions" - depends on PM_S2RAM - help - By default a magic word in RAM is used to mark entering suspend-to-RAM. Enabling - this option allows custom implementation of functions which handle the marking. + This option enables the SoC specific implementations of suspend-to-ram (S2RAM) + sleep states if PM is enabled and one or more suspend-to-ram sleep states are + enabled in the devicetree. config PM_NEED_ALL_DEVICES_IDLE bool "System Low Power Mode Needs All Devices Idle"