Skip to content

Commit 7910f4a

Browse files
committed
[nrf fromlist] drivers: clock_control: nrf54h-common: add utility to obtain LFOSC acc
Add a utility function to obtain LFOSC accuracy in PPM from BICR. Upstream PR #: 81122 Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit af7dba707626e5a09046dcac1d626ef61086bd77)
1 parent 62371a6 commit 7910f4a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

drivers/clock_control/clock_control_nrf2_common.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include "clock_control_nrf2_common.h"
7+
#include <hal/nrf_bicr.h>
78

89
#include <zephyr/logging/log.h>
910
LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
@@ -24,6 +25,8 @@ LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
2425
*/
2526
STRUCT_CLOCK_CONFIG(generic, ONOFF_CNT_MAX);
2627

28+
#define BICR (NRF_BICR_Type *)DT_REG_ADDR(DT_NODELABEL(bicr))
29+
2730
static void update_config(struct clock_config_generic *cfg)
2831
{
2932
atomic_val_t prev_flags = atomic_or(&cfg->flags, FLAG_UPDATE_NEEDED);
@@ -75,6 +78,40 @@ static inline uint8_t get_index_of_highest_bit(uint32_t value)
7578
return value ? (uint8_t)(31 - __builtin_clz(value)) : 0;
7679
}
7780

81+
int lfosc_get_accuracy(uint16_t *accuracy)
82+
{
83+
switch (nrf_bicr_lfosc_accuracy_get(BICR)) {
84+
case NRF_BICR_LFOSC_ACCURACY_500PPM:
85+
*accuracy = 500U;
86+
break;
87+
case NRF_BICR_LFOSC_ACCURACY_250PPM:
88+
*accuracy = 250U;
89+
break;
90+
case NRF_BICR_LFOSC_ACCURACY_150PPM:
91+
*accuracy = 150U;
92+
break;
93+
case NRF_BICR_LFOSC_ACCURACY_100PPM:
94+
*accuracy = 100U;
95+
break;
96+
case NRF_BICR_LFOSC_ACCURACY_75PPM:
97+
*accuracy = 75U;
98+
break;
99+
case NRF_BICR_LFOSC_ACCURACY_50PPM:
100+
*accuracy = 50U;
101+
break;
102+
case NRF_BICR_LFOSC_ACCURACY_30PPM:
103+
*accuracy = 30U;
104+
break;
105+
case NRF_BICR_LFOSC_ACCURACY_20PPM:
106+
*accuracy = 20U;
107+
break;
108+
default:
109+
return -EINVAL;
110+
}
111+
112+
return 0;
113+
}
114+
78115
int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_work_handler)
79116
{
80117
struct clock_config_generic *cfg = clk_cfg;

drivers/clock_control/clock_control_nrf2_common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ struct clock_onoff {
3636
struct clock_onoff onoff[_onoff_cnt]; \
3737
}
3838

39+
/**
40+
* @brief Obtain LFOSC accuracy in ppm.
41+
*
42+
* @param[out] accuracy Accuracy in ppm.
43+
*
44+
* @retval 0 On success
45+
* @retval -EINVAL If accuracy is not configured.
46+
*/
47+
int lfosc_get_accuracy(uint16_t *accuracy);
48+
3949
/**
4050
* @brief Initializes a clock configuration structure.
4151
*

0 commit comments

Comments
 (0)