Skip to content

Commit 45f1f73

Browse files
committed
[nrf fromlist] treewide: Replace clock_control_nrf api with clock speciffic api
Replaced clock_control_nrf api with clock speciffic api and removed clock_control_nrf api. Upstream PR #: 99257 Signed-off-by: Michal Frankiewicz <[email protected]>
1 parent f07840c commit 45f1f73

File tree

8 files changed

+47
-823
lines changed

8 files changed

+47
-823
lines changed

drivers/clock_control/clock_control_nrf.c

Lines changed: 0 additions & 782 deletions
This file was deleted.

samples/boards/nordic/clock_skew/src/main.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#define UPDATE_INTERVAL_S 10
1616

17-
static const struct device *const clock0 = DEVICE_DT_GET_ONE(nordic_nrf_clock);
1817
static const struct device *const timer0 = DEVICE_DT_GET(DT_NODELABEL(timer0));
1918
static struct timeutil_sync_config sync_config;
2019
static uint64_t counter_ref;
@@ -100,14 +99,18 @@ static void show_clocks(const char *tag)
10099
enum clock_control_status clkstat;
101100
bool running;
102101

103-
clkstat = clock_control_get_status(clock0, CLOCK_CONTROL_NRF_SUBSYS_LF);
104-
running = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK,
105-
&src.lf);
102+
clkstat = clock_control_get_status(DEVICE_DT_GET_ONE(nordic_nrf_clock_lfclk), NULL);
103+
running = nrfx_clock_lfclk_running_check(&src.lf);
106104
printk("%s: LFCLK[%s]: %s %s ; ", tag, clkstat_s[clkstat],
107105
running ? "Running" : "Off", lfsrc_s[src.lf]);
108-
clkstat = clock_control_get_status(clock0, CLOCK_CONTROL_NRF_SUBSYS_HF);
109-
running = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK,
110-
&src.hf);
106+
clkstat = clock_control_get_status(DEVICE_DT_GET_ONE(COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
107+
(nordic_nrf_clock_hfclk),
108+
(nordic_nrf_clock_xo))),
109+
NULL);
110+
111+
running = COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
112+
(nrfx_clock_hfclk_running_check),
113+
(nrfx_clock_xo_running_check))(&src.hf);
111114
printk("HFCLK[%s]: %s %s\n", clkstat_s[clkstat],
112115
running ? "Running" : "Off", hfsrc_s[src.hf]);
113116
}
@@ -196,19 +199,22 @@ static void sync_work_handler(struct k_work *work)
196199

197200
int main(void)
198201
{
202+
struct device *clock = DEVICE_DT_GET_ONE(COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
203+
(nordic_nrf_clock_hfclk),
204+
(nordic_nrf_clock_xo)));
199205
uint32_t top;
200206
int rc;
201207

202208
/* Grab the clock driver */
203-
if (!device_is_ready(clock0)) {
204-
printk("%s: device not ready.\n", clock0->name);
209+
if (!device_is_ready(clock)) {
210+
printk("%s: device not ready.\n", clock->name);
205211
return 0;
206212
}
207213

208214
show_clocks("Power-up clocks");
209215

210216
if (IS_ENABLED(CONFIG_APP_ENABLE_HFXO)) {
211-
rc = clock_control_on(clock0, CLOCK_CONTROL_NRF_SUBSYS_HF);
217+
rc = clock_control_on(clock, NULL);
212218
printk("Enable HFXO got %d\n", rc);
213219
}
214220

samples/net/zperf/src/nrf5340_cpu_boost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int nrf53_cpu_boost(void)
2121
int err;
2222

2323
/* For optimal performance, the CPU frequency should be set to 128 MHz */
24-
err = nrfx_clock_divider_set(NRF_CLOCK_DOMAIN_HFCLK, NRF_CLOCK_HFCLK_DIV_1);
24+
err = nrfx_clock_hfclk_divider_set(NRF_CLOCK_HFCLK_DIV_1);
2525
err -= NRFX_ERROR_BASE_NUM;
2626
if (err != 0) {
2727
LOG_WRN("Failed to set 128 MHz: %d", err);

subsys/bluetooth/audio/shell/bap_usb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ int bap_usb_init(void)
736736
* This may not be required, but reduces the risk of not decoding fast enough
737737
* to keep up with USB
738738
*/
739-
err = nrfx_clock_divider_set(NRF_CLOCK_DOMAIN_HFCLK, NRF_CLOCK_HFCLK_DIV_1);
739+
err = nrfx_clock_hfclk_divider_set(NRF_CLOCK_HFCLK_DIV_1);
740740

741741
err -= NRFX_ERROR_BASE_NUM;
742742
if (err != 0) {

tests/drivers/clock_control/clock_control_api/src/nrf_device_subsys.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@
1010
#if NRF_CLOCK_HAS_HFCLK
1111
static const struct device_subsys_data subsys_data_hfclk[] = {
1212
{
13-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF,
13+
.subsys = NULL,
1414
.startup_us = CONFIG_TEST_NRF_HF_STARTUP_TIME_US
1515
}
1616
};
1717
#endif /* NRF_CLOCK_HAS_HFCLK */
1818
#if NRF_CLOCK_HAS_XO
1919
static const struct device_subsys_data subsys_data_xo[] = {
2020
{
21-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF,
21+
.subsys = NULL,
2222
.startup_us = CONFIG_TEST_NRF_HF_STARTUP_TIME_US
2323
}
2424
};
2525
#endif /* NRF_CLOCK_HAS_XO */
2626
#if !defined(CONFIG_SOC_NRF52832)
2727
static const struct device_subsys_data subsys_data_lfclk[] = {
2828
{
29-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_LF,
29+
.subsys = NULL,
3030
.startup_us = (CLOCK_CONTROL_NRF_K32SRC ==
3131
NRF_CLOCK_LFCLK_RC) ? 1000 : 500000
3232
}
@@ -35,23 +35,23 @@ static const struct device_subsys_data subsys_data_lfclk[] = {
3535
#if NRF_CLOCK_HAS_HFCLK192M
3636
static const struct device_subsys_data subsys_data_hfclk192m[] = {
3737
{
38-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF192M,
38+
.subsys = NULL,
3939
.startup_us = 5
4040
}
4141
};
4242
#endif /* NRF_CLOCK_HAS_HFCLK192M */
4343
#if NRF_CLOCK_HAS_HFCLKAUDIO
4444
static const struct device_subsys_data subsys_data_hfclkaudio[] = {
4545
{
46-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HFAUDIO,
46+
.subsys = NULL,
4747
.startup_us = 30
4848
}
4949
};
5050
#endif /* NRF_CLOCK_HAS_HFCLKAUDIO */
5151
#if NRF_CLOCK_HAS_XO24M
5252
static const struct device_subsys_data subsys_data_xo24m[] = {
5353
{
54-
.subsys = CLOCK_CONTROL_NRF_SUBSYS_HF24M,
54+
.subsys = NULL,
5555
.startup_us = 5
5656
}
5757
};

tests/drivers/clock_control/nrf_lf_clock_start/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ ZTEST(nrf_lf_clock_start, test_wait_in_thread)
7474
}
7575

7676
z_nrf_clock_control_lf_on(CLOCK_CONTROL_NRF_LF_START_AVAILABLE);
77-
o = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, &t);
77+
o = nrfx_clock_lfclk_running_check(&t);
7878
zassert_false((t == NRF_CLOCK_LFCLK_XTAL) && o);
7979
k_busy_wait(35);
8080
zassert_true(k_cycle_get_32() > 0);
8181

8282
z_nrf_clock_control_lf_on(CLOCK_CONTROL_NRF_LF_START_STABLE);
83-
o = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, &t);
83+
o = nrfx_clock_lfclk_running_check(&t);
8484
zassert_true((t == NRF_CLOCK_LFCLK_XTAL) && o);
8585
}
8686

@@ -118,7 +118,7 @@ static int get_lfclk_state(void)
118118
* not valid, in that case read system clock to check if it has
119119
* progressed.
120120
*/
121-
clk_on = nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_LFCLK, &clk_type);
121+
clk_on = nrfx_clock_lfclk_running_check(&clk_type);
122122
k_busy_wait(100);
123123
rtc_cnt = k_cycle_get_32();
124124

tests/drivers/clock_control/nrf_onoff_and_bt/src/main.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ LOG_MODULE_REGISTER(test);
1919
static bool test_end;
2020

2121
static const struct device *const entropy = DEVICE_DT_GET(DT_CHOSEN(zephyr_entropy));
22-
static const struct device *const clock_dev = DEVICE_DT_GET_ONE(nordic_nrf_clock);
23-
static struct device *hf_dev;
22+
static const struct device *const clock_dev = DEVICE_DT_GET_ONE(
23+
COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
24+
(nordic_nrf_clock_hfclk),
25+
(nordic_nrf_clock_xo)));
2426
static struct onoff_client cli;
2527
static uint32_t iteration;
2628

@@ -29,11 +31,6 @@ static void *setup(void)
2931
zassert_true(device_is_ready(entropy));
3032
zassert_true(device_is_ready(clock_dev));
3133

32-
hf_dev = DEVICE_DT_GET_ONE(COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
33-
(nordic_nrf_clock_hfclk),
34-
(nordic_nrf_clock_xo)));
35-
zassert_true(hf_dev);
36-
3734
return NULL;
3835
}
3936

@@ -65,20 +62,21 @@ static void bt_timeout_handler(struct k_timer *timer)
6562

6663
K_TIMER_DEFINE(timer1, bt_timeout_handler, NULL);
6764

68-
static void check_hf_status(const struct device *dev, bool exp_on,
69-
bool sw_check)
65+
static void check_hf_status(bool exp_on, bool sw_check)
7066
{
7167
nrf_clock_hfclk_t type;
7268

73-
nrf_clock_is_running(NRF_CLOCK, NRF_CLOCK_DOMAIN_HFCLK, &type);
69+
COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
70+
(nrfx_clock_hfclk_running_check),
71+
(nrfx_clock_xo_running_check))(&type);
72+
7473
zassert_equal(type, exp_on ? NRF_CLOCK_HFCLK_HIGH_ACCURACY :
7574
NRF_CLOCK_HFCLK_LOW_ACCURACY,
7675
"%d: Clock expected to be %s",
7776
iteration, exp_on ? "on" : "off");
7877

7978
if (sw_check) {
80-
enum clock_control_status status =
81-
clock_control_get_status(dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
79+
enum clock_control_status status = clock_control_get_status(clock_dev, NULL);
8280

8381
zassert_equal(status, exp_on ? CLOCK_CONTROL_STATUS_ON :
8482
CLOCK_CONTROL_STATUS_OFF,
@@ -117,16 +115,16 @@ ZTEST(nrf_onoff_and_bt, test_onoff_interrupted)
117115
backoff = 3 * rand;
118116

119117
sys_notify_init_spinwait(&cli.notify);
120-
err = nrf_clock_control_request(hf_dev, NULL, &cli);
118+
err = nrf_clock_control_request(clock_dev, NULL, &cli);
121119
zassert_true(err >= 0);
122120

123121
k_busy_wait(backoff);
124122

125123
if (backoff > HF_STARTUP_TIME_US) {
126-
check_hf_status(clock_dev, true, true);
124+
check_hf_status(true, true);
127125
}
128126

129-
err = nrf_clock_control_cancel_or_release(hf_dev, NULL, &cli);
127+
err = nrf_clock_control_cancel_or_release(clock_dev, NULL, &cli);
130128
zassert_true(err >= 0);
131129

132130
elapsed = k_uptime_get() - start_time;
@@ -138,7 +136,7 @@ ZTEST(nrf_onoff_and_bt, test_onoff_interrupted)
138136

139137
test_end = true;
140138
k_msleep(100);
141-
check_hf_status(clock_dev, false, true);
139+
check_hf_status(false, true);
142140
}
143141

144142
static void onoff_timeout_handler(struct k_timer *timer)
@@ -209,7 +207,7 @@ ZTEST(nrf_onoff_and_bt, test_bt_interrupted)
209207
k_busy_wait(backoff);
210208

211209
if (backoff > HF_STARTUP_TIME_US) {
212-
check_hf_status(clock_dev, true, false);
210+
check_hf_status(true, false);
213211
}
214212

215213
z_nrf_clock_bt_ctlr_hf_release();
@@ -223,6 +221,6 @@ ZTEST(nrf_onoff_and_bt, test_bt_interrupted)
223221

224222
test_end = true;
225223
k_msleep(100);
226-
check_hf_status(clock_dev, false, true);
224+
check_hf_status(false, true);
227225
}
228226
ZTEST_SUITE(nrf_onoff_and_bt, NULL, setup, NULL, NULL, NULL);

tests/drivers/clock_control/onoff/src/test_clock_control_onoff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ LOG_MODULE_REGISTER(test);
1616

1717
static bool clock_is_off(void)
1818
{
19-
const struct device *const clk = DEVICE_DT_GET_ONE(nordic_nrf_clock);
19+
const struct device *const clk = DEVICE_DT_GET_ONE(COND_CODE_1((NRF_CLOCK_HAS_HFCLK),
20+
(nordic_nrf_clock_hfclk),
21+
(nordic_nrf_clock_xo)));
2022

2123
zassert_true(device_is_ready(clk), "Device is not ready");
2224

23-
return clock_control_get_status(clk, CLOCK_CONTROL_NRF_SUBSYS_HF) ==
25+
return clock_control_get_status(clk, NULL) ==
2426
CLOCK_CONTROL_STATUS_OFF;
2527
}
2628

0 commit comments

Comments
 (0)