From 32b3ab2354204e470141a9245dd3748ed3d70e5e Mon Sep 17 00:00:00 2001 From: Marcin Szymczyk Date: Tue, 26 Nov 2019 11:58:36 +0100 Subject: [PATCH] soc: nrf53: add power management Only System OFF mode is supported. Signed-off-by: Marcin Szymczyk --- soc/arm/nordic_nrf/nrf53/CMakeLists.txt | 4 ++ soc/arm/nordic_nrf/nrf53/Kconfig.series | 1 - soc/arm/nordic_nrf/nrf53/Kconfig.soc | 1 + soc/arm/nordic_nrf/nrf53/power.c | 55 +++++++++++++++++++++++++ subsys/power/device.c | 2 +- 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 soc/arm/nordic_nrf/nrf53/power.c diff --git a/soc/arm/nordic_nrf/nrf53/CMakeLists.txt b/soc/arm/nordic_nrf/nrf53/CMakeLists.txt index 332416ba43b..e2cdaf798b7 100644 --- a/soc/arm/nordic_nrf/nrf53/CMakeLists.txt +++ b/soc/arm/nordic_nrf/nrf53/CMakeLists.txt @@ -3,3 +3,7 @@ zephyr_sources( soc.c ) + +zephyr_library_sources_ifdef(CONFIG_SYS_POWER_MANAGEMENT + power.c + ) diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.series b/soc/arm/nordic_nrf/nrf53/Kconfig.series index 57fcce41c70..3ee66be232d 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.series +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.series @@ -8,7 +8,6 @@ config SOC_SERIES_NRF53X select CPU_CORTEX_M33 select CPU_HAS_ARM_MPU select SOC_FAMILY_NRF - select HAS_SYS_POWER_STATE_DEEP_SLEEP_1 select XIP select HAS_NRFX select HAS_SEGGER_RTT diff --git a/soc/arm/nordic_nrf/nrf53/Kconfig.soc b/soc/arm/nordic_nrf/nrf53/Kconfig.soc index 7156e753198..446be7331e7 100644 --- a/soc/arm/nordic_nrf/nrf53/Kconfig.soc +++ b/soc/arm/nordic_nrf/nrf53/Kconfig.soc @@ -9,6 +9,7 @@ config SOC_NRF5340_CPUAPP select CPU_HAS_NRF_IDAU select CPU_HAS_FPU select ARMV8_M_DSP + select HAS_SYS_POWER_STATE_DEEP_SLEEP_1 select HAS_HW_NRF_CC312 select HAS_HW_NRF_CLOCK select HAS_HW_NRF_DPPIC diff --git a/soc/arm/nordic_nrf/nrf53/power.c b/soc/arm/nordic_nrf/nrf53/power.c new file mode 100644 index 00000000000..c02dcd144b0 --- /dev/null +++ b/soc/arm/nordic_nrf/nrf53/power.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2017 Intel Corporation. + * Copytight (c) 2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include + +#ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1 +#include +#endif + +#include +LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); + +/* Invoke Low Power/System Off specific Tasks */ +void sys_set_power_state(enum power_states state) +{ + switch (state) { +#ifdef CONFIG_SYS_POWER_DEEP_SLEEP_STATES + #ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1 + case SYS_POWER_STATE_DEEP_SLEEP_1: + nrf_regulators_system_off(NRF_REGULATORS); + break; + #endif +#endif + default: + LOG_DBG("Unsupported power state %u", state); + break; + } +} + +/* Handle SOC specific activity after Low Power Mode Exit */ +void _sys_pm_power_state_exit_post_ops(enum power_states state) +{ + switch (state) { +#ifdef CONFIG_SYS_POWER_DEEP_SLEEP_STATES + #ifdef CONFIG_HAS_SYS_POWER_STATE_DEEP_SLEEP_1 + case SYS_POWER_STATE_DEEP_SLEEP_1: + /* Nothing to do. */ + break; + #endif +#endif + default: + LOG_DBG("Unsupported power state %u", state); + break; + } + + /* + * System is now in active mode. Reenable interrupts which were disabled + * when OS started idling code. + */ + irq_unlock(0); +} diff --git a/subsys/power/device.c b/subsys/power/device.c index dd3b3ad4ba7..6520683c0ae 100644 --- a/subsys/power/device.c +++ b/subsys/power/device.c @@ -22,7 +22,7 @@ LOG_MODULE_DECLARE(power); * to build the device list based on devices power * and clock domain dependencies. */ -#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF51X) +#if defined(CONFIG_SOC_SERIES_NRF52X) || defined(CONFIG_SOC_SERIES_NRF51X) || defined(CONFIG_SOC_SERIES_NRF53X) #define MAX_PM_DEVICES 15 #define NUM_CORE_DEVICES 4 #define MAX_DEV_NAME_LEN 16