From c0505a4ced230cec7fef7ba80d9293b28555754b Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 19 Sep 2025 16:57:35 +0200 Subject: [PATCH 1/4] [nrf fromtree] pm: bind the PM_S2RAM kconfig option to devicetree Currently it is possible to have an enabled (status="okay") "suspend-to-ram" "zephyr,power-state" in the devicetree, CONFIG_PM=y, but CONFIG_PM_S2RAM=n This means the presence and state of the "suspend-to-ram" power state in the devicetree does not match the PM_S2RAM option, despite PM_S2RAM being dependent on the devicetree state. This commit makes the devicetree the "source of truth" for whether one or more s2ram power states shall be included and supported, by enabling PM_S2RAM if any s2ram power state with status "okay" is present in the devicetree. To disable the s2ram power state, like with any other state, disable it by setting its state to "disabled". The help of the now promptless PM_S2RAM config has been updated to reflect the new meaning. It previously held cortex-m specific implementation details, these have been removed as these details are already present in the file pointed to as well (arch/arm/core/cortex_m/pm_s2ram.c line 22) Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 4626f6b776f662702934ac85929edc35dce832b1) --- samples/boards/nordic/spis_wakeup/prj.conf | 1 - .../nordic/spis_wakeup/wakeup_trigger/prj.conf | 1 - .../boards/st/power_mgmt/suspend_to_ram/prj.conf | 1 - subsys/pm/Kconfig | 13 ++++++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/boards/nordic/spis_wakeup/prj.conf b/samples/boards/nordic/spis_wakeup/prj.conf index ca92fc6de6ae..c1cc933296f0 100644 --- a/samples/boards/nordic/spis_wakeup/prj.conf +++ b/samples/boards/nordic/spis_wakeup/prj.conf @@ -3,7 +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..9c30d5a98fd7 100644 --- a/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf +++ b/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf @@ -3,7 +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/subsys/pm/Kconfig b/subsys/pm/Kconfig index d1d99ac02e3a..abd424a88009 100644 --- a/subsys/pm/Kconfig +++ b/subsys/pm/Kconfig @@ -33,14 +33,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. + 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_S2RAM_CUSTOM_MARKING bool "Use custom marking functions" From 00bdf5ff82acab819075b52bdf354266b4f76651 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Mon, 22 Sep 2025 07:28:21 +0200 Subject: [PATCH 2/4] [nrf fromtree] pm: refactor PM_S2RAM_CUSTOM_MARKING option to be promptless The config PM_S2RAM_CUSTOM_MARKING is not an optional config for a user to select, it is required by some soc implementations of S2RAM, in which case it must be selected by the soc. Refactor the configuration to be HAS_PM_S2RAM_CUSTOM_MARKING, and make the currently only soc which needs it select it. Then update samples which previously had to select this option for this soc. Signed-off-by: Bjarki Arge Andreasen (cherry picked from commit 1767f131aac706f978eb93bd548b7e7419a0457d) --- arch/arm/core/cortex_m/pm_s2ram.c | 4 ++-- include/zephyr/arch/common/pm_s2ram.h | 8 ++++---- samples/boards/nordic/spis_wakeup/prj.conf | 1 - .../nordic/spis_wakeup/wakeup_trigger/prj.conf | 1 - soc/nordic/nrf54h/Kconfig | 2 ++ subsys/pm/Kconfig | 15 ++++++++------- 6 files changed, 16 insertions(+), 15 deletions(-) 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 c1cc933296f0..e313ffeed82b 100644 --- a/samples/boards/nordic/spis_wakeup/prj.conf +++ b/samples/boards/nordic/spis_wakeup/prj.conf @@ -3,7 +3,6 @@ CONFIG_SPI_SLAVE=y CONFIG_GPIO=y CONFIG_PM=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 9c30d5a98fd7..ad4577807f89 100644 --- a/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf +++ b/samples/boards/nordic/spis_wakeup/wakeup_trigger/prj.conf @@ -3,7 +3,6 @@ CONFIG_SPI_NRFX_WAKE_TIMEOUT_US=500 CONFIG_GPIO=y CONFIG_PM=y -CONFIG_PM_S2RAM_CUSTOM_MARKING=y CONFIG_PM_DEVICE=y CONFIG_PM_DEVICE_RUNTIME=y diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index d4c86932a2c4..9aae7f379bb8 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 @@ -64,6 +65,7 @@ config SOC_NRF54H20_CPURAD_COMMON select HAS_NORDIC_DMM select HAS_NORDIC_RAM_CTRL select HAS_PM + select HAS_PM_S2RAM_CUSTOM_MARKING select HAS_POWEROFF config SOC_NRF54H20_CPURAD_ENABLE diff --git a/subsys/pm/Kconfig b/subsys/pm/Kconfig index abd424a88009..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 @@ -45,13 +53,6 @@ config PM_S2RAM sleep states if PM is enabled and one or more suspend-to-ram sleep states are enabled in the devicetree. -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. - config PM_NEED_ALL_DEVICES_IDLE bool "System Low Power Mode Needs All Devices Idle" depends on PM_DEVICE && !SMP From 69780d2b2297b1b98c91d1f6df48d449513a456c Mon Sep 17 00:00:00 2001 From: Rubin Gerritsen Date: Sun, 28 Sep 2025 19:43:33 +0200 Subject: [PATCH 3/4] [nrf fromtree] soc: nordic: nrf54h: s2ram: Support disabled MPU This commit adds support using pm_s2ram for 54H when the MPU is disabled. This is the case for the out of tree sample `sdk-nrf/samples/nrf54h/empty_app_core`. Without this commit the linker will fail to link `z_arm_mpu_init` and `z_arm_configure_static_mpu_regions`. Signed-off-by: Rubin Gerritsen (cherry picked from commit 05b77ece23e9104aee17e6c11dff544ad0ca8783) --- soc/nordic/nrf54h/pm_s2ram.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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); From 5c4bf0fa368246aa553d402090e37e0dda7c2417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C5=82=C4=85b?= Date: Fri, 24 Oct 2025 13:09:10 +0200 Subject: [PATCH 4/4] [nrf fromtree] soc: nordic: nrf54h: Disable S2RAM on cpurad MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On nrf54h20 only cpuapp supports s2ram low power cpu state. Signed-off-by: Sebastian Głąb (cherry picked from commit 6ec763474f6593ceafe70f79731247ede3721984) --- soc/nordic/nrf54h/Kconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index 9aae7f379bb8..f07a620ccdb3 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -65,7 +65,6 @@ config SOC_NRF54H20_CPURAD_COMMON select HAS_NORDIC_DMM select HAS_NORDIC_RAM_CTRL select HAS_PM - select HAS_PM_S2RAM_CUSTOM_MARKING select HAS_POWEROFF config SOC_NRF54H20_CPURAD_ENABLE