1212LOG_MODULE_DECLARE (clock_control_nrf2 , CONFIG_CLOCK_CONTROL_LOG_LEVEL );
1313
1414#include <soc_lrcconf.h>
15+ #include <hal/nrf_bicr.h>
1516
1617BUILD_ASSERT (DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) == 1 ,
1718 "multiple instances not supported" );
@@ -24,14 +25,16 @@ struct dev_data_hfxo {
2425#if defined(CONFIG_ZERO_LATENCY_IRQS )
2526 uint16_t request_count ;
2627#endif /* CONFIG_ZERO_LATENCY_IRQS */
28+ k_timeout_t start_up_time ;
2729};
2830
2931struct dev_config_hfxo {
3032 uint32_t fixed_frequency ;
3133 uint16_t fixed_accuracy ;
32- k_timeout_t start_up_time ;
3334};
3435
36+ #define BICR (NRF_BICR_Type *)DT_REG_ADDR(DT_NODELABEL(bicr))
37+
3538#if defined(CONFIG_ZERO_LATENCY_IRQS )
3639static uint32_t full_irq_lock (void )
3740{
@@ -106,8 +109,6 @@ static void onoff_start_hfxo(struct onoff_manager *mgr, onoff_notify_fn notify)
106109{
107110 struct dev_data_hfxo * dev_data =
108111 CONTAINER_OF (mgr , struct dev_data_hfxo , mgr );
109- const struct device * dev = DEVICE_DT_INST_GET (0 );
110- const struct dev_config_hfxo * dev_config = dev -> config ;
111112
112113 dev_data -> notify = notify ;
113114 request_hfxo (dev_data );
@@ -116,7 +117,7 @@ static void onoff_start_hfxo(struct onoff_manager *mgr, onoff_notify_fn notify)
116117 * unreliable. Hence the timer is used to simply wait the expected
117118 * start-up time. To be removed once the hardware is fixed.
118119 */
119- k_timer_start (& dev_data -> timer , dev_config -> start_up_time , K_NO_WAIT );
120+ k_timer_start (& dev_data -> timer , dev_data -> start_up_time , K_NO_WAIT );
120121}
121122
122123static void stop_hfxo (struct dev_data_hfxo * dev_data )
@@ -250,13 +251,21 @@ static int init_hfxo(const struct device *dev)
250251 .start = onoff_start_hfxo ,
251252 .stop = onoff_stop_hfxo
252253 };
254+ uint32_t start_up_time ;
253255 int rc ;
254256
255257 rc = onoff_manager_init (& dev_data -> mgr , & transitions );
256258 if (rc < 0 ) {
257259 return rc ;
258260 }
259261
262+ start_up_time = nrf_bicr_hfxo_startup_time_us_get (BICR );
263+ if (start_up_time == NRF_BICR_HFXO_STARTUP_TIME_UNCONFIGURED ) {
264+ return - EINVAL ;
265+ }
266+
267+ dev_data -> start_up_time = K_USEC (start_up_time );
268+
260269 k_timer_init (& dev_data -> timer , hfxo_start_up_timer_handler , NULL );
261270
262271 return 0 ;
@@ -278,7 +287,6 @@ static struct dev_data_hfxo data_hfxo;
278287static const struct dev_config_hfxo config_hfxo = {
279288 .fixed_frequency = DT_INST_PROP (0 , clock_frequency ),
280289 .fixed_accuracy = DT_INST_PROP (0 , accuracy_ppm ),
281- .start_up_time = K_USEC (DT_INST_PROP (0 , startup_time_us )),
282290};
283291
284292DEVICE_DT_INST_DEFINE (0 , init_hfxo , NULL ,
0 commit comments