From 6b3e9136772c131795418fc855a1234d93699e09 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Wed, 27 Nov 2024 22:00:47 +0100 Subject: [PATCH] soc: nordic: nrf54h20: restrict global hsfll freq Introduce feature which restricts the minimum global hsfll frequency. This feature is selected by default to preserve the behavior of the global hsfll before the clock control driver for it was introduced, which configured it as a fixed clock at 320MHz. Signed-off-by: Bjarki Arge Andreasen --- soc/nordic/nrf54h/CMakeLists.txt | 1 + soc/nordic/nrf54h/Kconfig | 20 ++++++++++++++++ soc/nordic/nrf54h/global_hsfll.c | 41 ++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/soc/nordic/nrf54h/CMakeLists.txt b/soc/nordic/nrf54h/CMakeLists.txt index 7edc4d43ea12895..0b25692ea3531dd 100644 --- a/soc/nordic/nrf54h/CMakeLists.txt +++ b/soc/nordic/nrf54h/CMakeLists.txt @@ -9,6 +9,7 @@ if(CONFIG_ARM) endif() zephyr_library_sources_ifdef(CONFIG_PM_S2RAM pm_s2ram.c) +zephyr_library_sources_ifdef(CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_RESTRICT_MIN_FREQ global_hsfll.c) zephyr_include_directories(.) diff --git a/soc/nordic/nrf54h/Kconfig b/soc/nordic/nrf54h/Kconfig index cbbe2bbd2d9c148..be05c9d808d4d17 100644 --- a/soc/nordic/nrf54h/Kconfig +++ b/soc/nordic/nrf54h/Kconfig @@ -67,3 +67,23 @@ config SOC_NRF54H20_CPUFLPR depends on RISCV_CORE_NORDIC_VPR rsource "gpd/Kconfig" + +config SOC_NRF54H20_GLOBAL_HSFLL_RESTRICT_MIN_FREQ + bool "Restrict minimum global HSFLL clock frequency" + select NRFS + select NRFS_GDFS_SERVICE_ENABLED + select CLOCK_CONTROL + default y if SOC_NRF54H20_CPUAPP + +if SOC_NRF54H20_GLOBAL_HSFLL_RESTRICT_MIN_FREQ + +config SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_HZ + int "Minimum global HSFLL clock frequency in Hertz" + range 64000000 320000000 + default 320000000 + +config SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS + int "Global HSFLL timeout in milliseconds" + default 1000 + +endif # SOC_NRF54H20_RESTRICT_GLOBAL_HSFLL_FREQ diff --git a/soc/nordic/nrf54h/global_hsfll.c b/soc/nordic/nrf54h/global_hsfll.c index 025fc761dc84f17..414450697602c8b 100644 --- a/soc/nordic/nrf54h/global_hsfll.c +++ b/soc/nordic/nrf54h/global_hsfll.c @@ -4,37 +4,54 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include +#include +#include +#include + +LOG_MODULE_DECLARE(soc, CONFIG_SOC_LOG_LEVEL); + +#define GLOBAL_HSFLL_MIN_FREQ_HZ \ + CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_MIN_FREQ_HZ + +#define NRFS_BACKEND_TIMEOUT \ + K_MSEC(CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS) + +#define GLOBAL_HSFLL_REQUEST_TIMEOUT_MS \ + CONFIG_SOC_NRF54H20_GLOBAL_HSFLL_TIMEOUT_MS static struct onoff_client cli; static const struct device *global_hsfll = DEVICE_DT_GET(DT_NODELABEL(hsfll120)); static const struct nrf_clock_spec spec = { - .frequency = CONFIG_SOC_NRF54H20_GDFS_MIN_FREQ, + .frequency = GLOBAL_HSFLL_MIN_FREQ_HZ, }; -static int nordicsemi_nrf54h_gdfs_init(void) +static int nordicsemi_nrf54h_global_hsfll_init(void) { int ret; int res; + bool completed; + + nrfs_backend_wait_for_connection(NRFS_BACKEND_TIMEOUT); sys_notify_init_spinwait(&cli.notify); - ret = nrf_clock_control_request(clk_dev, clk_spec, &cli); + ret = nrf_clock_control_request(global_hsfll, &spec, &cli); if (ret) { return ret; } - ret = WAIT_FOR(sys_notify_fetch_result(&cli.notify, &res) == 0, - 2000, - k_msleep(1); - ); + res = -EIO; + completed = WAIT_FOR(sys_notify_fetch_result(&cli.notify, &res) == 0, + GLOBAL_HSFLL_REQUEST_TIMEOUT_MS, + k_msleep(1)); - if (ret) { - return ret; + if (!completed || res) { + LOG_ERR("Failed to restrict global HSFLL frequency"); + return -EIO; } - return res; + return 0; } -SYS_INIT(nordicsemi_nrf54h_gdfs_init, POST_KERNEL, 99); +SYS_INIT(nordicsemi_nrf54h_global_hsfll_init, POST_KERNEL, 99);