Skip to content

Commit 05551a9

Browse files
[nrf fromlist] drivers: timer: nrf_grtc: Add support for clock outputs
Add support for GRTC clock output pins. Upstream PR #: 82788 Signed-off-by: Adam Kondraciuk <[email protected]>
1 parent cbc6fea commit 05551a9

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

drivers/timer/nrf_grtc_timer.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#if defined(CONFIG_CLOCK_CONTROL_NRF)
1111
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
1212
#endif
13+
#include <zephyr/drivers/pinctrl.h>
1314
#include <zephyr/drivers/timer/system_timer.h>
1415
#include <zephyr/drivers/timer/nrf_grtc_timer.h>
1516
#include <nrfx_grtc.h>
@@ -518,7 +519,31 @@ static int sys_clock_driver_init(void)
518519
#if defined(CONFIG_NRF_GRTC_ALWAYS_ON)
519520
nrfx_grtc_active_request_set(true);
520521
#endif
522+
523+
#if DT_NODE_HAS_PROP(GRTC_NODE, clkout_32k_frequency)
524+
nrfy_grtc_clkout_set(NRF_GRTC, NRF_GRTC_CLKOUT_32K, true);
525+
#endif
526+
527+
#if DT_NODE_HAS_PROP(GRTC_NODE, clkout_fast_frequency)
528+
#if DT_PROP(GRTC_NODE, clkout_fast_frequency) > (DT_PROP(GRTC_NODE, base_frequency) / 2)
529+
#error "Invalid frequency value for fast clock output."
530+
#endif
531+
uint32_t base_frequency = DT_PROP(GRTC_NODE, base_frequency);
532+
uint32_t requested_frequency = DT_PROP(GRTC_NODE, clkout_fast_frequency);
533+
uint32_t grtc_div = base_frequency / (requested_frequency * 2);
534+
535+
nrfy_grtc_clkout_set(NRF_GRTC, NRF_GRTC_CLKOUT_FAST, true);
536+
nrfy_grtc_clkout_divider_set(NRF_GRTC, (uint8_t)grtc_div);
537+
#endif
538+
539+
#if DT_NODE_HAS_PROP(GRTC_NODE, clkout_32k_frequency) || \
540+
DT_NODE_HAS_PROP(GRTC_NODE, clkout_fast_frequency)
541+
PINCTRL_DT_DEFINE(GRTC_NODE);
542+
const struct pinctrl_dev_config *pcfg = PINCTRL_DT_DEV_CONFIG_GET(GRTC_NODE);
543+
return pinctrl_apply_state(pcfg, PINCTRL_STATE_DEFAULT);
544+
#else
521545
return 0;
546+
#endif
522547
}
523548

524549
void sys_clock_set_timeout(int32_t ticks, bool idle)

0 commit comments

Comments
 (0)