From a8e21ce8ffaeab9555c8fe137cbe461b19b36aae Mon Sep 17 00:00:00 2001 From: Adam Kondraciuk Date: Thu, 31 Oct 2024 12:48:35 +0100 Subject: [PATCH] [nrf fromlist] drivers: timer: grtc: Add LFPRC as the source of GRTC This commit allows to switch the GRTC clock source to an RC oscillator. Upstream PR #: 80622 Signed-off-by: Adam Kondraciuk (cherry picked from commit 822bd4f6d37746bc9b060e1d5d24327d4cf73ae1) --- drivers/timer/nrf_grtc_timer.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/timer/nrf_grtc_timer.c b/drivers/timer/nrf_grtc_timer.c index fb9c859caeb..ee3f35e09d0 100644 --- a/drivers/timer/nrf_grtc_timer.c +++ b/drivers/timer/nrf_grtc_timer.c @@ -426,8 +426,12 @@ 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 DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) && NRF_GRTC_HAS_CLKSEL +#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; @@ -501,11 +505,15 @@ static int sys_clock_driver_init(void) z_nrf_clock_control_lf_on(mode); #endif -#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && \ - DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo)) && NRF_GRTC_HAS_CLKSEL +#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);