From 3e6d6033bbd21432b41ad5a0463bc47ae6fcf0df Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 16 Oct 2024 15:36:50 +0200 Subject: [PATCH] soc: nordic: add fn for setting constlat mode Nordic SoCs implement an event system, for which the system can optimize for low latency/high power or low power. Add soc level implementation of reference counted API which will optimize for low latency if any part of the system requires it. Signed-off-by: Bjarki Arge Andreasen --- soc/nordic/common/CMakeLists.txt | 2 + soc/nordic/common/Kconfig | 4 ++ soc/nordic/common/nrf_sys_event.c | 95 +++++++++++++++++++++++++++++++ soc/nordic/common/nrf_sys_event.h | 30 ++++++++++ 4 files changed, 131 insertions(+) create mode 100644 soc/nordic/common/nrf_sys_event.c create mode 100644 soc/nordic/common/nrf_sys_event.h diff --git a/soc/nordic/common/CMakeLists.txt b/soc/nordic/common/CMakeLists.txt index 38c55c614e9..1a4e17c20d1 100644 --- a/soc/nordic/common/CMakeLists.txt +++ b/soc/nordic/common/CMakeLists.txt @@ -29,3 +29,5 @@ if(CONFIG_TFM_PARTITION_PLATFORM) $/api_ns/interface/include ) endif() + +zephyr_library_sources_ifdef(CONFIG_NRF_SYS_EVENT nrf_sys_event.c) diff --git a/soc/nordic/common/Kconfig b/soc/nordic/common/Kconfig index 8de20c37dd4..ef32e7403c1 100644 --- a/soc/nordic/common/Kconfig +++ b/soc/nordic/common/Kconfig @@ -4,4 +4,8 @@ config HAS_NORDIC_DMM bool +config NRF_SYS_EVENT + bool "nRF system event support" + select NRFX_POWER if !NRF_PLATFORM_HALTIUM + rsource "vpr/Kconfig" diff --git a/soc/nordic/common/nrf_sys_event.c b/soc/nordic/common/nrf_sys_event.c new file mode 100644 index 00000000000..47c02eadb96 --- /dev/null +++ b/soc/nordic/common/nrf_sys_event.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#if CONFIG_SOC_SERIES_NRF54HX + +/* + * The 54HX is not yet supported by an nrfx driver nor the system controller so + * we implement an ISR and concurrent access safe reference counting implementation + * here using the nrfx hal. + */ + +#include + +static struct k_spinlock global_constlat_lock; +static uint16_t global_constlat_count; + +int nrf_sys_event_request_global_constlat(void) +{ + K_SPINLOCK(&global_constlat_lock) { + if (global_constlat_count == 0) { +#if CONFIG_SOC_NRF54H20_CPUAPP + nrf_lrcconf_task_trigger(NRF_LRCCONF010, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); +#elif CONFIG_SOC_NRF54H20_CPURAD + nrf_lrcconf_task_trigger(NRF_LRCCONF000, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); + nrf_lrcconf_task_trigger(NRF_LRCCONF020, + NRF_LRCCONF_TASK_CONSTLAT_ENABLE); +#else +#error "unsupported" +#endif + } + + global_constlat_count++; + } + + return 0; +} + +int nrf_sys_event_release_global_constlat(void) +{ + K_SPINLOCK(&global_constlat_lock) { + if (global_constlat_count == 1) { +#if CONFIG_SOC_NRF54H20_CPUAPP + nrf_lrcconf_task_trigger(NRF_LRCCONF010, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); +#elif CONFIG_SOC_NRF54H20_CPURAD + nrf_lrcconf_task_trigger(NRF_LRCCONF000, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); + nrf_lrcconf_task_trigger(NRF_LRCCONF020, + NRF_LRCCONF_TASK_CONSTLAT_DISABLE); +#else +#error "unsupported" +#endif + } + + global_constlat_count--; + } + + return 0; +} + +#else + +/* + * The nrfx power driver already contains an ISR and concurrent access safe reference + * counting API so we just use it directly when available. + */ + +#include + +int nrf_sys_event_request_global_constlat(void) +{ + nrfx_err_t err; + + err = nrfx_power_constlat_mode_request(); + + return (err == NRFX_SUCCESS || err == NRFX_ERROR_ALREADY) ? 0 : -EAGAIN; +} + +int nrf_sys_event_release_global_constlat(void) +{ + nrfx_err_t err; + + err = nrfx_power_constlat_mode_free(); + + return (err == NRFX_SUCCESS || err == NRFX_ERROR_BUSY) ? 0 : -EAGAIN; +} + +#endif diff --git a/soc/nordic/common/nrf_sys_event.h b/soc/nordic/common/nrf_sys_event.h new file mode 100644 index 00000000000..a4d6d8050f0 --- /dev/null +++ b/soc/nordic/common/nrf_sys_event.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +/** + * @brief Request lowest latency for system events + * + * @details System will be configured for lowest latency after first + * call to nrf_sys_event_request_global_constlat() and will remain + * configured for lowest latency until matching number of calls to + * nrf_sys_event_release_global_constlat() occur. + * + * @retval 0 if successful + * @retval -errno code otherwise + */ +int nrf_sys_event_request_global_constlat(void); + +/** + * @brief Release low latency request + * + * @see nrf_sys_event_request_global_constlat() + * + * @retval 0 if successful + * @retval -errno code otherwise + */ +int nrf_sys_event_release_global_constlat(void);