1 /*
2 * Copyright (c) 2022 Intel Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6 #include <zephyr/ztest.h>
7 #include <zephyr/drivers/clock_control/clock_control_adsp.h>
8 #include <zephyr/drivers/clock_control.h>
9
check_clocks(struct adsp_cpu_clock_info * clocks,uint32_t freq_idx)10 static void check_clocks(struct adsp_cpu_clock_info *clocks, uint32_t freq_idx)
11 {
12 int i;
13 unsigned int num_cpus = arch_num_cpus();
14
15 for (i = 0; i < num_cpus; i++) {
16 zassert_equal(clocks[i].current_freq, freq_idx, "");
17 }
18 }
19
ZTEST(adsp_clock_control,test_adsp_clock_driver)20 ZTEST(adsp_clock_control, test_adsp_clock_driver)
21 {
22 struct adsp_cpu_clock_info *clocks = adsp_cpu_clocks_get();
23
24 zassert_not_null(clocks, "");
25
26 adsp_clock_set_cpu_freq(ADSP_CPU_CLOCK_FREQ_LPRO);
27 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_LPRO);
28
29 adsp_clock_set_cpu_freq(ADSP_CPU_CLOCK_FREQ_HPRO);
30 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_HPRO);
31
32 #ifdef ADSP_CLOCK_HAS_WOVCRO
33 adsp_clock_set_cpu_freq(ADSP_CPU_CLOCK_FREQ_WOVCRO);
34 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_WOVCRO);
35 #endif
36 }
37
ZTEST(adsp_clock_control,test_adsp_clock_control)38 ZTEST(adsp_clock_control, test_adsp_clock_control)
39 {
40 struct adsp_cpu_clock_info *clocks = adsp_cpu_clocks_get();
41 const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(clkctl));
42
43 zassert_not_null(clocks, "");
44
45 clock_control_set_rate(dev, NULL, (clock_control_subsys_rate_t)
46 ADSP_CPU_CLOCK_FREQ_LPRO);
47 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_LPRO);
48
49 clock_control_set_rate(dev, NULL, (clock_control_subsys_rate_t)
50 ADSP_CPU_CLOCK_FREQ_HPRO);
51 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_HPRO);
52
53 #ifdef ADSP_CLOCK_HAS_WOVCRO
54 clock_control_set_rate(dev, NULL, (clock_control_subsys_rate_t)
55 ADSP_CPU_CLOCK_FREQ_WOVCRO);
56 check_clocks(clocks, ADSP_CPU_CLOCK_FREQ_WOVCRO);
57 #endif
58 }
59 ZTEST_SUITE(adsp_clock_control, NULL, NULL, NULL, NULL, NULL);
60