Skip to content

Commit 21c48ca

Browse files
[nrf fromlist] 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 hard coupling to the CLOCK_CONTROL drivers. To preserve backwards compatibility, if CLOCK_CONTROL_NRF_K32SRC_RC is selected, GRTC will default to LFLPRC. Upstream PR #: 99147 Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
1 parent ce93ada commit 21c48ca

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

drivers/timer/Kconfig.nrf_grtc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,29 @@ 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 LFLPRC if CLOCK_CONTROL_NRF_K32SRC_RC for backwards compatibility
64+
default NRF_GRTC_TIMER_SOURCE_LFLPRC if CLOCK_CONTROL_NRF_K32SRC_RC
65+
# Default to LFXO if present as this allows GRTC to run in SYSTEM OFF
66+
default NRF_GRTC_TIMER_SOURCE_LFXO
67+
# Default to SYSTEM_LFCLK if LFXO is not present
68+
default NRF_GRTC_TIMER_SOURCE_SYSTEM_LFCLK
69+
70+
config NRF_GRTC_TIMER_SOURCE_LFXO
71+
bool "Use Low Frequency XO as clock source"
72+
depends on $(dt_nodelabel_enabled,lfxo)
73+
74+
config NRF_GRTC_TIMER_SOURCE_SYSTEM_LFCLK
75+
bool "Use System Low Frequency clock as clock source"
76+
77+
config NRF_GRTC_TIMER_SOURCE_LFLPRC
78+
bool "Use Low Frequency Low Power RC as clock source"
79+
80+
endchoice # NRF_GRTC_TIMER_SOURCE
81+
82+
endif # NRF_GRTC_START_SYSCOUNTER
83+
5984
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)