Skip to content

Commit 042c5c6

Browse files
adamkondraciukkartben
authored andcommitted
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. Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent 25fcfff commit 042c5c6

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -417,13 +417,6 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
417417
nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 +
418418
MAX_CC_LATCH_WAIT_TIME_US;
419419
k_busy_wait(wait_time);
420-
#if NRF_GRTC_HAS_CLKSEL
421-
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
422-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
423-
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
424-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
425-
#endif
426-
#endif
427420
k_spin_unlock(&lock, key);
428421
return 0;
429422
}
@@ -463,6 +456,18 @@ static int sys_clock_driver_init(void)
463456
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
464457
nrfx_grtc_irq_handler, 0);
465458

459+
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
460+
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
461+
/* Switch to LFPRC as the low-frequency clock source. */
462+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
463+
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
464+
/* Switch to LFXO as the low-frequency clock source. */
465+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
466+
#else
467+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFCLK);
468+
#endif
469+
#endif
470+
466471
err_code = nrfx_grtc_init(0);
467472
if (err_code != NRFX_SUCCESS) {
468473
return -EPERM;
@@ -496,16 +501,6 @@ static int sys_clock_driver_init(void)
496501
z_nrf_clock_control_lf_on(mode);
497502
#endif
498503

499-
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
500-
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
501-
/* Switch to LFPRC as the low-frequency clock source. */
502-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
503-
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
504-
/* Switch to LFXO as the low-frequency clock source. */
505-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
506-
#endif
507-
#endif
508-
509504
#if defined(CONFIG_NRF_GRTC_ALWAYS_ON)
510505
nrfx_grtc_active_request_set(true);
511506
#endif

0 commit comments

Comments
 (0)