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" );
@@ -20,15 +21,16 @@ struct dev_data_hfxo {
2021 struct onoff_manager mgr ;
2122 onoff_notify_fn notify ;
2223 struct k_timer timer ;
23- sys_snode_t hfxo_node ;
24+ k_timeout_t start_up_time ;
2425};
2526
2627struct dev_config_hfxo {
2728 uint32_t fixed_frequency ;
2829 uint16_t fixed_accuracy ;
29- k_timeout_t start_up_time ;
3030};
3131
32+ #define BICR (NRF_BICR_Type *)DT_REG_ADDR(DT_NODELABEL(bicr))
33+
3234static void hfxo_start_up_timer_handler (struct k_timer * timer )
3335{
3436 struct dev_data_hfxo * dev_data =
@@ -52,8 +54,6 @@ static void onoff_start_hfxo(struct onoff_manager *mgr, onoff_notify_fn notify)
5254{
5355 struct dev_data_hfxo * dev_data =
5456 CONTAINER_OF (mgr , struct dev_data_hfxo , mgr );
55- const struct device * dev = DEVICE_DT_INST_GET (0 );
56- const struct dev_config_hfxo * dev_config = dev -> config ;
5757
5858 dev_data -> notify = notify ;
5959
@@ -65,7 +65,7 @@ static void onoff_start_hfxo(struct onoff_manager *mgr, onoff_notify_fn notify)
6565 * unreliable. Hence the timer is used to simply wait the expected
6666 * start-up time. To be removed once the hardware is fixed.
6767 */
68- k_timer_start (& dev_data -> timer , dev_config -> start_up_time , K_NO_WAIT );
68+ k_timer_start (& dev_data -> timer , dev_data -> start_up_time , K_NO_WAIT );
6969}
7070
7171static void onoff_stop_hfxo (struct onoff_manager * mgr , onoff_notify_fn notify )
@@ -159,13 +159,21 @@ static int init_hfxo(const struct device *dev)
159159 .start = onoff_start_hfxo ,
160160 .stop = onoff_stop_hfxo
161161 };
162+ uint32_t start_up_time ;
162163 int rc ;
163164
164165 rc = onoff_manager_init (& dev_data -> mgr , & transitions );
165166 if (rc < 0 ) {
166167 return rc ;
167168 }
168169
170+ start_up_time = nrf_bicr_hfxo_startup_time_us_get (BICR );
171+ if (start_up_time == NRF_BICR_HFXO_STARTUP_TIME_UNCONFIGURED ) {
172+ return - EINVAL ;
173+ }
174+
175+ dev_data -> start_up_time = K_USEC (start_up_time );
176+
169177 k_timer_init (& dev_data -> timer , hfxo_start_up_timer_handler , NULL );
170178
171179 return 0 ;
@@ -187,7 +195,6 @@ static struct dev_data_hfxo data_hfxo;
187195static const struct dev_config_hfxo config_hfxo = {
188196 .fixed_frequency = DT_INST_PROP (0 , clock_frequency ),
189197 .fixed_accuracy = DT_INST_PROP (0 , accuracy_ppm ),
190- .start_up_time = K_USEC (DT_INST_PROP (0 , startup_time_us )),
191198};
192199
193200DEVICE_DT_INST_DEFINE (0 , init_hfxo , NULL ,
0 commit comments