From 3027f6872ddfdaf4cdf5b47e9724567d0db88ecf Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Tue, 18 Feb 2025 10:10:00 +0100 Subject: [PATCH 1/2] [nrf fromlist] drivers: timer: nrf_grtc_timer: Move up GRTC clock selection Selection of the LF clock source for the GRTC should be performed as early as possible, before starting GRTC. Upstream PR #: 87199 Signed-off-by: Adam Kondraciuk --- drivers/timer/nrf_grtc_timer.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index 05779038142d..609a32b406a2 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -429,13 +429,6 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us) nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 + MAX_CC_LATCH_WAIT_TIME_US; k_busy_wait(wait_time); -#if NRF_GRTC_HAS_CLKSEL -#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) - nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC); -#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) - nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO); -#endif -#endif k_spin_unlock(&lock, key); return 0; } @@ -475,6 +468,18 @@ static int sys_clock_driver_init(void) IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr, nrfx_grtc_irq_handler, 0); +#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL +#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) + /* Switch to LFPRC as the low-frequency clock source. */ + nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC); +#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) + /* Switch to LFXO as the low-frequency clock source. */ + nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO); +#else + nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFCLK); +#endif +#endif + err_code = nrfx_grtc_init(0); if (err_code != NRFX_SUCCESS) { return -EPERM; @@ -508,16 +513,6 @@ static int sys_clock_driver_init(void) z_nrf_clock_control_lf_on(mode); #endif -#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL -#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC) - /* Switch to LFPRC as the low-frequency clock source. */ - nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC); -#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) - /* Switch to LFXO as the low-frequency clock source. */ - nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO); -#endif -#endif - #if defined(CONFIG_NRF_GRTC_ALWAYS_ON) nrfx_grtc_active_request_set(true); #endif From fa8f97ce56e405c8467804c823773a3eb2fdb3b7 Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Mon, 17 Mar 2025 12:38:43 +0100 Subject: [PATCH 2/2] [nrf fromlist] modules: hal_nordic: nrfx: switch off auto clksel for GRTC Disable automatic LFCLK selection for GRTC during driver initialization. For Zephyr applications it is selected by `sys_clock_driver_init()` depending on configuration and DTS. Upstream PR #: 87199 Signed-off-by: Adam Kondraciuk --- modules/hal_nordic/nrfx/nrfx_kconfig.h | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/hal_nordic/nrfx/nrfx_kconfig.h b/modules/hal_nordic/nrfx/nrfx_kconfig.h index 1eb51f997247..c970140c36c8 100644 --- a/modules/hal_nordic/nrfx/nrfx_kconfig.h +++ b/modules/hal_nordic/nrfx/nrfx_kconfig.h @@ -170,6 +170,7 @@ #ifdef CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT #define NRF_GRTC_HAS_EXTENDED 1 +#define NRFX_GRTC_CONFIG_LFCLK_SELECT_AT_INIT 0 #endif #ifdef CONFIG_NRF_GRTC_TIMER_AUTO_KEEP_ALIVE #define NRFX_GRTC_CONFIG_AUTOEN 1