7#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
8#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
18#if defined(CONFIG_CLOCK_CONTROL_NRF)
20#include <hal/nrf_clock.h>
26enum clock_control_nrf_type {
27 CLOCK_CONTROL_NRF_TYPE_HFCLK,
28 CLOCK_CONTROL_NRF_TYPE_LFCLK,
29#if NRF_CLOCK_HAS_HFCLK24M
30 CLOCK_CONTROL_NRF_TYPE_HFCLK24M,
32#if NRF_CLOCK_HAS_HFCLK192M
33 CLOCK_CONTROL_NRF_TYPE_HFCLK192M,
35#if NRF_CLOCK_HAS_HFCLKAUDIO
36 CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO,
38 CLOCK_CONTROL_NRF_TYPE_COUNT
44#define CLOCK_CONTROL_NRF_SUBSYS_HF \
45 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK)
46#define CLOCK_CONTROL_NRF_SUBSYS_LF \
47 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_LFCLK)
48#define CLOCK_CONTROL_NRF_SUBSYS_HF24M \
49 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK24M)
50#define CLOCK_CONTROL_NRF_SUBSYS_HF192M \
51 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK192M)
52#define CLOCK_CONTROL_NRF_SUBSYS_HFAUDIO \
53 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO)
56enum nrf_lfclk_start_mode {
57 CLOCK_CONTROL_NRF_LF_START_NOWAIT,
58 CLOCK_CONTROL_NRF_LF_START_AVAILABLE,
59 CLOCK_CONTROL_NRF_LF_START_STABLE,
63#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC
64#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_RC
66#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL
67#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL
69#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH
70#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_SYNTH
72#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_LOW_SWING
73#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_LOW_SWING
75#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_FULL_SWING
76#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_FULL_SWING
80#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM
81#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 0
83#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM
84#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 1
86#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM
87#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 2
89#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM
90#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 3
92#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM
93#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 4
95#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM
96#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 5
98#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM
99#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 6
101#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM
102#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7
106void z_nrf_clock_calibration_force_start(
void);
114int z_nrf_clock_calibration_count(
void);
122int z_nrf_clock_calibration_skips_count(
void);
129bool z_nrf_clock_calibration_is_in_progress(
void);
147void z_nrf_clock_control_lf_on(
enum nrf_lfclk_start_mode start_mode);
161void z_nrf_clock_bt_ctlr_hf_request(
void);
167void z_nrf_clock_bt_ctlr_hf_release(
void);
174uint32_t z_nrf_clock_bt_ctlr_hf_get_startup_time_us(
void);
179#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
182#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
184#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
187#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
189#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
192#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ 80000000
193#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ 11289591
194#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ 24000000
195#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ 12287963
198#define _CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(freq_val) \
199 ((freq_val) == NRF_AUXPLL_FREQ_DIV_MIN ? \
200 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ : \
201 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_44K1 ? \
202 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ : \
203 (freq_val) == NRF_AUXPLL_FREQ_DIV_USB24M ? \
204 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ : \
205 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_48K ? \
206 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ : 0)
209#define CLOCK_CONTROL_NRF_AUXPLL_GET_FREQ(node) \
210 COND_CODE_1(DT_NODE_HAS_PROP(node, nordic_frequency), \
211 (_CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(DT_PROP(node, nordic_frequency))), \
218struct nrf_clock_spec {
224__subsystem
struct nrf_clock_control_driver_api {
225 struct clock_control_driver_api std_api;
227 int (*request)(
const struct device *dev,
228 const struct nrf_clock_spec *spec,
229 struct onoff_client *cli);
230 int (*release)(
const struct device *dev,
231 const struct nrf_clock_spec *spec);
232 int (*cancel_or_release)(
const struct device *dev,
233 const struct nrf_clock_spec *spec,
234 struct onoff_client *cli);
235 int (*resolve)(
const struct device *dev,
236 const struct nrf_clock_spec *req_spec,
237 struct nrf_clock_spec *res_spec);
238 int (*get_startup_time)(
const struct device *dev,
239 const struct nrf_clock_spec *spec,
283 const struct nrf_clock_spec *spec,
286 return DEVICE_API_GET(nrf_clock_control, dev)->request(dev, spec, cli);
304 const struct nrf_clock_spec *spec,
323 const struct nrf_clock_spec *spec)
325 return DEVICE_API_GET(nrf_clock_control, dev)->release(dev, spec);
352 const struct nrf_clock_spec *spec,
355 return DEVICE_API_GET(nrf_clock_control, dev)->cancel_or_release(dev, spec, cli);
369 const struct nrf_clock_spec *req_spec,
370 struct nrf_clock_spec *res_spec)
372 const struct nrf_clock_control_driver_api *api =
DEVICE_API_GET(nrf_clock_control, dev);
374 if (api->resolve ==
NULL) {
378 return api->resolve(dev, req_spec, res_spec);
392 const struct nrf_clock_spec *spec,
395 const struct nrf_clock_control_driver_api *api =
DEVICE_API_GET(nrf_clock_control, dev);
397 if (api->get_startup_time ==
NULL) {
401 return api->get_startup_time(dev, spec, startup_time_us);
Main header file for clock control driver API.
#define DEVICE_API_EXTENDS(_child, _parent, _member)
Declare that API class _child is an extension of device API class _parent.
Definition device.h:1390
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Callback API to enable or disable a clock.
Definition clock_control.h:90
void * clock_control_subsys_t
clock_control_subsys_t is a type to identify a clock controller sub-system.
Definition clock_control.h:59
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
static int nrf_clock_control_get_startup_time(const struct device *dev, const struct nrf_clock_spec *spec, uint32_t *startup_time_us)
Get the startup time of a clock.
Definition nrf_clock_control.h:391
void nrf_clock_control_hfxo_request(void)
Request the HFXO from Zero Latency Interrupt context.
static int nrf_clock_control_request(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Request a reservation to use a given clock with specified attributes.
Definition nrf_clock_control.h:282
static int nrf_clock_control_cancel_or_release(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Safely cancel a reservation request.
Definition nrf_clock_control.h:351
void nrf_clock_control_hfxo_release(void)
Release the HFXO from Zero Latency Interrupt context.
static int nrf_clock_control_release(const struct device *dev, const struct nrf_clock_spec *spec)
Release a reserved use of a clock.
Definition nrf_clock_control.h:322
static int nrf_clock_control_resolve(const struct device *dev, const struct nrf_clock_spec *req_spec, struct nrf_clock_spec *res_spec)
Resolve a requested clock spec to resulting spec.
Definition nrf_clock_control.h:368
int nrf_clock_control_request_sync(const struct device *dev, const struct nrf_clock_spec *spec, k_timeout_t timeout)
Synchronously request a reservation to use a given clock with specified attributes.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Kernel timeout type.
Definition clock.h:65
State associated with a client of an on-off service.
Definition onoff.h:274
State associated with an on-off manager.
Definition onoff.h:154