Skip to content

Commit e00fbfb

Browse files
drivers: timer: nrf_grtc: Decouple clock source from CLOCK_CONTROL
The GRTC timer, typically used as sys clock on newer nordic chips, is currently tightly coupled to the CLOCK_CONTROL_NRF drivers though not being dependent on it. The GRTC and its device driver is independent from CLOCK_CONTROL, its clock requirements are managed by hardware, based on its clock source selection. This commit moves the clock source selection to the GRTC driver, and removes the direct coupling to the CLOCK_CONTROL drivers. To preserve backwards compatibility in cases where the CLOCK_CONTROL LFCLK configuration was used to determine the clock source of the GRTC, the new clock source selection defaults to clock used for LFCLK if CLOCK_CONTROL_NRF is enabled, otherwise, it defaults to LFXO first as this clock is most accurate and can run in SYSTEM OFF, then LFLPRC as this is the most power efficient. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
1 parent 91b1b84 commit e00fbfb

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

drivers/timer/Kconfig.nrf_grtc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,31 @@ config NRF_GRTC_TIMER_AUTO_KEEP_ALIVE
5656
This feature prevents the SYSCOUNTER from sleeping when any core is in
5757
active state.
5858

59+
if NRF_GRTC_START_SYSCOUNTER
60+
61+
choice NRF_GRTC_TIMER_SOURCE
62+
prompt "nRF GRTC clock source"
63+
# Default to clock selected by CLOCK_CONTROL_NRF if enabled
64+
default NRF_GRTC_TIMER_SOURCE_LFLPRC if CLOCK_CONTROL_NRF_K32SRC_RC
65+
default NRF_GRTC_TIMER_SOURCE_LFXO if CLOCK_CONTROL_NRF_K32SRC_XTAL
66+
default NRF_GRTC_TIMER_SOURCE_SYSTEM_LFCLK if CLOCK_CONTROL_NRF_K32SRC_SYNTH
67+
# Default to LFXO if present as this allows GRTC to run in SYSTEM OFF
68+
default NRF_GRTC_TIMER_SOURCE_LFXO
69+
# Default to LFLPRC if LFXO is not present
70+
default NRF_GRTC_TIMER_SOURCE_LFLPRC
71+
72+
config NRF_GRTC_TIMER_SOURCE_LFXO
73+
bool "Use Low Frequency Crystal as clock source"
74+
depends on $(dt_nodelabel_enabled,lfxo)
75+
76+
config NRF_GRTC_TIMER_SOURCE_SYSTEM_LFCLK
77+
bool "Use System Low Frequency clock as clock source"
78+
79+
config NRF_GRTC_TIMER_SOURCE_LFLPRC
80+
bool "Use Low Frequency Low Power RC as clock source"
81+
82+
endchoice # NRF_GRTC_TIMER_SOURCE
83+
84+
endif # NRF_GRTC_START_SYSCOUNTER
85+
5986
endif # NRF_GRTC_TIMER

drivers/timer/nrf_grtc_timer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,13 +477,14 @@ static int sys_clock_driver_init(void)
477477
#endif
478478

479479
#if defined(CONFIG_NRF_GRTC_TIMER_CLOCK_MANAGEMENT) && NRF_GRTC_HAS_CLKSEL
480-
#if defined(CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC)
480+
#if defined(CONFIG_NRF_GRTC_TIMER_SOURCE_LFLPRC)
481481
/* Switch to LFPRC as the low-frequency clock source. */
482482
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFLPRC);
483-
#elif DT_NODE_HAS_STATUS_OKAY(DT_NODELABEL(lfxo))
483+
#elif defined(CONFIG_NRF_GRTC_TIMER_SOURCE_LFXO)
484484
/* Switch to LFXO as the low-frequency clock source. */
485485
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFXO);
486486
#else
487+
/* Use LFCLK as the low-frequency clock source. */
487488
nrfx_grtc_clock_source_set(NRF_GRTC_CLKSEL_LFCLK);
488489
#endif
489490
#endif

0 commit comments

Comments
 (0)