Skip to content

Commit 44ed967

Browse files
drivers: timer: nrf_grtc_timer: Move clksel management to an early stage of init
Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent ffd1c70 commit 44ed967

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -429,13 +429,7 @@ int z_nrf_grtc_wakeup_prepare(uint64_t wake_time_us)
429429
nrfy_grtc_timeout_get(NRF_GRTC) * CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC / 32768 +
430430
MAX_CC_LATCH_WAIT_TIME_US;
431431
k_busy_wait(wait_time);
432-
#if NRF_GRTC_HAS_CLKSEL
433-
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
434-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
435-
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
436-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
437-
#endif
438-
#endif
432+
439433
k_spin_unlock(&lock, key);
440434
return 0;
441435
}
@@ -475,6 +469,20 @@ static int sys_clock_driver_init(void)
475469
IRQ_CONNECT(DT_IRQN(GRTC_NODE), DT_IRQ(GRTC_NODE, priority), nrfx_isr,
476470
nrfx_grtc_irq_handler, 0);
477471

472+
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
473+
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
474+
475+
/* Switch to LFPRC as the low-frequency clock source. */
476+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
477+
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
478+
/* Switch to LFXO as the low-frequency clock source. */
479+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
480+
#else
481+
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFCLK);
482+
#endif
483+
#endif
484+
485+
478486
err_code = nrfx_grtc_init(0);
479487
if (err_code != NRFX_SUCCESS) {
480488
return -EPERM;
@@ -508,16 +516,6 @@ static int sys_clock_driver_init(void)
508516
z_nrf_clock_control_lf_on(mode);
509517
#endif
510518

511-
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
512-
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
513-
/* Switch to LFPRC as the low-frequency clock source. */
514-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
515-
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
516-
/* Switch to LFXO as the low-frequency clock source. */
517-
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
518-
#endif
519-
#endif
520-
521519
#if defined(CONFIG_NRF_GRTC_ALWAYS_ON)
522520
nrfx_grtc_active_request_set(true);
523521
#endif

0 commit comments

Comments
 (0)