Skip to content

Commit 487959d

Browse files
gmarulljukkar
authored andcommitted
[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 bb2e6d4f2e83ad80e299418a9883670e0de627ae)
1 parent 625a31e commit 487959d

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
@@ -5,6 +5,7 @@
55

66
#include "clock_control_nrf2_common.h"
77
#include <zephyr/drivers/clock_control/nrf_clock_control.h>
8+
#include <hal/nrf_bicr.h>
89

910
#include <zephyr/logging/log.h>
1011
LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
@@ -19,6 +20,8 @@ LOG_MODULE_REGISTER(clock_control_nrf2, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
1920
(idx * sizeof(array[0])) - \
2021
offsetof(type, array[0]))
2122

23+
#define BICR (NRF_BICR_Type *)DT_REG_ADDR(DT_NODELABEL(bicr))
24+
2225
/*
2326
* Definition of `struct clock_config_generic`.
2427
* Used to access `clock_config_*` structures in a common way.
@@ -83,6 +86,40 @@ static inline uint8_t get_index_of_highest_bit(uint32_t value)
8386
return value ? (uint8_t)(31 - __builtin_clz(value)) : 0;
8487
}
8588

89+
int lfosc_get_accuracy(uint16_t *accuracy)
90+
{
91+
switch (nrf_bicr_lfosc_accuracy_get(BICR)) {
92+
case NRF_BICR_LFOSC_ACCURACY_500PPM:
93+
*accuracy = 500U;
94+
break;
95+
case NRF_BICR_LFOSC_ACCURACY_250PPM:
96+
*accuracy = 250U;
97+
break;
98+
case NRF_BICR_LFOSC_ACCURACY_150PPM:
99+
*accuracy = 150U;
100+
break;
101+
case NRF_BICR_LFOSC_ACCURACY_100PPM:
102+
*accuracy = 100U;
103+
break;
104+
case NRF_BICR_LFOSC_ACCURACY_75PPM:
105+
*accuracy = 75U;
106+
break;
107+
case NRF_BICR_LFOSC_ACCURACY_50PPM:
108+
*accuracy = 50U;
109+
break;
110+
case NRF_BICR_LFOSC_ACCURACY_30PPM:
111+
*accuracy = 30U;
112+
break;
113+
case NRF_BICR_LFOSC_ACCURACY_20PPM:
114+
*accuracy = 20U;
115+
break;
116+
default:
117+
return -EINVAL;
118+
}
119+
120+
return 0;
121+
}
122+
86123
int clock_config_init(void *clk_cfg, uint8_t onoff_cnt, k_work_handler_t update_work_handler)
87124
{
88125
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)