Skip to content

Commit 5bb7f21

Browse files
committed
[nrf noup] Bluetooth: Controller: nrf54hx: Initial HF clock control
Added initial implementation for nrf54hx HF clock control. Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
1 parent 69d44fe commit 5bb7f21

File tree

1 file changed

+45
-4
lines changed
  • subsys/bluetooth/controller/ll_sw/nordic/lll

1 file changed

+45
-4
lines changed

subsys/bluetooth/controller/ll_sw/nordic/lll/lll_clock.c

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define HFCLOCK_TIMEOUT_MS 2
2020

2121
static uint16_t const sca_ppm_lut[] = {500, 250, 150, 100, 75, 50, 30, 20};
22+
static atomic_val_t hf_refcnt;
2223

2324
#if defined(CONFIG_SOC_SERIES_NRF54HX)
2425
#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7U /* FIXME: */
@@ -63,9 +64,34 @@ int lll_clock_wait(void)
6364
return 0;
6465
}
6566

67+
#if !defined(CONFIG_BT_CTLR_ZLI)
68+
const static struct device *clock_dev_hfxo = DEVICE_DT_GET(DT_NODELABEL(hfxo));
69+
const static struct nrf_clock_spec clock_req_spec_hfxo = {
70+
.frequency = 0, /* Ignore or use default */
71+
.accuracy = 1, /* Use maximum accuracy */
72+
.precision = 1, /* 0 for low precision, 1 for high precision */
73+
};
74+
static struct onoff_client clock_cli_hfxo;
75+
#endif
76+
6677
int lll_hfclock_on(void)
6778
{
68-
/* TODO: */
79+
if (atomic_inc(&hf_refcnt) > 0) {
80+
return 0;
81+
}
82+
83+
#if defined(CONFIG_BT_CTLR_ZLI)
84+
nrf_clock_control_hfxo_request();
85+
#else
86+
int err;
87+
88+
sys_notify_init_spinwait(&clock_cli_hfxo.notify);
89+
90+
err = nrf_clock_control_request(clock_dev_hfxo, &clock_req_spec_hfxo, &clock_cli_hfxo);
91+
if (err) {
92+
return err;
93+
}
94+
#endif
6995

7096
return 0;
7197
}
@@ -79,7 +105,24 @@ int lll_hfclock_on_wait(void)
79105

80106
int lll_hfclock_off(void)
81107
{
82-
/* TODO: */
108+
if (atomic_get(&hf_refcnt) < 1) {
109+
return -EALREADY;
110+
}
111+
112+
if (atomic_dec(&hf_refcnt) > 1) {
113+
return 0;
114+
}
115+
116+
#if defined(CONFIG_BT_CTLR_ZLI)
117+
nrf_clock_control_hfxo_release();
118+
#else
119+
int err;
120+
121+
err = nrf_clock_control_release(clock_dev_hfxo, &clock_req_spec_hfxo);
122+
if (err) {
123+
return err;
124+
}
125+
#endif
83126

84127
return 0;
85128
}
@@ -89,9 +132,7 @@ struct lll_clock_state {
89132
struct onoff_client cli;
90133
struct k_sem sem;
91134
};
92-
93135
static struct onoff_client lf_cli;
94-
static atomic_val_t hf_refcnt;
95136

96137
static void clock_ready(struct onoff_manager *mgr, struct onoff_client *cli,
97138
uint32_t state, int res)

0 commit comments

Comments
 (0)