Skip to content

Commit 1e21cb2

Browse files
tests: drivers: clock_management: add clock_management_minimal test
Add clock_management_minimal test. This test is intended to verify that clock management functions correctly when runtime notifications and rate setting are disabled. It also verifies that support for multiple clock outputs on a device works as expected. The test has the following phases: - apply default clock state for both clock outputs of the emulated consumer. Verify that the resulting clock frequencies match what is expected. - apply sleep clock state for both clock outputs of the emulated consumer. Verify that the resulting clock frequencies match what is expected. - Request a clock frequency from each clock output, which should match the frequency of one of the defined states exactly. Verify that the expected state is applied. The test is supported on the `native_sim` target using emulated clock drivers for testing purposes in CI, and on the `lpcxpresso55s69/lpc55s69/cpu0` target to verify the clock management API on real hardware. Signed-off-by: Daniel DeGrasse <ddegrasse@tenstorrent.com>
1 parent 0207218 commit 1e21cb2

File tree

11 files changed

+542
-0
lines changed

11 files changed

+542
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(clock_management_minimal)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
FILE(GLOB clock_sources ../common/emul_clock_drivers/*.c)
10+
target_sources(app PRIVATE ${app_sources} ${clock_sources})
11+
12+
# Add custom clock drivers to clock management header list
13+
add_clock_management_header("../common/emul_clock_drivers/emul_clock_drivers.h")
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Clock Management Minimal Test
2+
#############################
3+
4+
This test is designed to verify that the clock management API can function
5+
correctly without runtime callbacks or rate setting enabled. It defines one
6+
dummy clock consumer. In addition, it defines several dummy clock nodes to
7+
verify API functionality. Boards should configure these dummy devices with
8+
clock states as described within the tests below.
9+
10+
Boards may also use the dummy clock nodes as needed if they do not have a
11+
hardware clock output they can safely reconfigure as part of this testcase.
12+
13+
The following tests will run, using the output clock with name "default":
14+
15+
* Verify that the consumer can apply the clock state named "default" for
16+
both the "slow" and "fast" clock output, and that the queried rates of
17+
the "slow" and "fast" clocks match the properties "slow-default-freq"
18+
and "fast-default-freq", respectively.
19+
20+
* Verify that the consumer can apply the clock state named "sleep" for
21+
both the "slow" and "fast" clock output, and that the queried rates of
22+
the "slow" and "fast" clocks match the properties "slow-sleep-freq"
23+
and "fast-sleep-freq", respectively.
24+
25+
* Verify that requesting the frequency given by "slow-request-freq" from
26+
the "slow" clock output reconfigures that clock output to *exactly* the
27+
frequency given by the "slow-request-freq" property.
28+
29+
* Verify that requesting the frequency given by "fast-request-freq" from
30+
the "fast" clock output reconfigures that clock output to *exactly* the
31+
frequency given by the "fast-request-freq" property.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <freq.h>
8+
9+
/* Clock CPU from FROHF, since we will use the PLLs within our testcases */
10+
&system_clock {
11+
sys_clk_96mhz: sys-clk-96mhz {
12+
compatible = "clock-state";
13+
clocks = <&ahbclkdiv 1 &fro_hf 1 &mainclksela 3 &mainclkselb 0>;
14+
clock-frequency = <DT_FREQ_M(96)>;
15+
locking-state;
16+
};
17+
};
18+
19+
&cpu0 {
20+
clock-state-0 = <&sys_clk_96mhz>;
21+
};
22+
23+
/* Disable the SD controller- we are using its clock for this test */
24+
&sdif {
25+
status = "disabled";
26+
};
27+
28+
/* Define clock states for clockout clock */
29+
&clkout_clock {
30+
clkout_16mhz: clkout-16mhz {
31+
compatible = "clock-state";
32+
/* Expect a clock frequency of 16 MHz */
33+
clocks = <&xtal32m 1 &clk_in_en 1 &pll0clksel 1
34+
&pll0_pdec 4 &pll0_directo 0
35+
&pll0 512000000 8 256 0 31 31 0 0 0
36+
&pll1_bypass 0 &clkoutsel 1
37+
&clkoutdiv 8>;
38+
clock-frequency = <DT_FREQ_M(16)>;
39+
};
40+
41+
clkout_1mhz: clkout-1mhz {
42+
compatible = "clock-state";
43+
/* Expect a clock frequency of 1MHz */
44+
clocks = <&fro_1m 1 &clkoutsel 4 &clkoutdiv 1>;
45+
clock-frequency = <DT_FREQ_M(1)>;
46+
};
47+
48+
clkout_500mhz: clkout-500mhz {
49+
compatible = "clock-state";
50+
/* Expect a clock frequency of 500 KHz */
51+
clocks = <&xtal32m 1 &clk_in_en 1 &pll0clksel 1
52+
&pll0_pdec 4 &pll0_directo 0
53+
&pll0 512000000 8 256 0 31 31 0 0 0
54+
&pll1_bypass 0 &clkoutsel 1
55+
&clkoutdiv 256>;
56+
clock-frequency = <DT_FREQ_K(500)>;
57+
};
58+
};
59+
60+
/* Define clock states for SDIO clock */
61+
&sdio_clock {
62+
sdioclk_48mhz: sdioclk-48mhz {
63+
compatible = "clock-state";
64+
/* Expect a clock frequency of 48 MHz */
65+
clocks = <&fro_12m 1 &pll1clksel 0
66+
&pll1_pdec 4 &pll1_directo 0
67+
&pll1 384000000 4 128 0 62 31
68+
&pll1_bypass 0 &sdioclksel 5
69+
&sdioclkdiv 2>;
70+
clock-frequency = <DT_FREQ_M(48)>;
71+
};
72+
73+
sdioclk_24mhz: sdioclk-24mhz {
74+
compatible = "clock-state";
75+
/* Expect a clock frequency of 24 MHz */
76+
clocks = <&fro_12m 1 &pll1clksel 0
77+
&pll1_pdec 4 &pll1_directo 0
78+
&pll1 384000000 4 128 0 62 31
79+
&pll1_bypass 0 &sdioclksel 5
80+
&sdioclkdiv 4>;
81+
clock-frequency = <DT_FREQ_M(24)>;
82+
};
83+
84+
sdioclk_12mhz: sdioclk-12mhz {
85+
compatible = "clock-state";
86+
/* Expect a clock frequency of 12 MHz */
87+
clocks = <&fro_hf 1 &sdioclksel 3
88+
&sdioclkdiv 8>;
89+
clock-frequency = <DT_FREQ_M(12)>;
90+
};
91+
};
92+
93+
/ {
94+
/* Emulated device clock consumer */
95+
emul_device {
96+
emul_dev1: emul-dev1 {
97+
compatible = "vnd,emul-clock-consumer";
98+
clock-outputs = <&clkout_clock &sdio_clock>;
99+
clock-output-names = "slow", "fast";
100+
clock-state-0 = <&clkout_16mhz &sdioclk_48mhz>;
101+
slow-default-freq = <DT_FREQ_M(16)>;
102+
fast-default-freq = <DT_FREQ_M(48)>;
103+
slow-sleep-freq = <DT_FREQ_M(1)>;
104+
fast-sleep-freq = <DT_FREQ_M(12)>;
105+
clock-state-1 = <&clkout_1mhz &sdioclk_12mhz>;
106+
slow-request-freq = <DT_FREQ_K(500)>;
107+
fast-request-freq = <DT_FREQ_M(24)>;
108+
clock-state-names = "default", "sleep";
109+
};
110+
};
111+
};
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Define clock tree with emulated clock nodes.
9+
* These node labels are chosen so that they won't conflict with SOC clock
10+
* tree nodelabels. The clock driver implementations used by this tree are
11+
* stored within the test itself
12+
*/
13+
14+
#include <freq.h>
15+
16+
/ {
17+
emul_clock_root {
18+
emul_source1: emul-source1 {
19+
compatible = "fixed-clock";
20+
clock-frequency = <DT_FREQ_M(10)>;
21+
#clock-cells = <0>;
22+
23+
emul_div1: emul-div1 {
24+
compatible = "vnd,emul-clock-div";
25+
max-div = <64>;
26+
#clock-cells = <1>;
27+
};
28+
};
29+
30+
emul_source2: emul-source2 {
31+
compatible = "fixed-clock";
32+
clock-frequency = <DT_FREQ_M(50)>;
33+
#clock-cells = <0>;
34+
35+
emul_div2: emul-div2 {
36+
compatible = "vnd,emul-clock-div";
37+
max-div = <256>;
38+
#clock-cells = <1>;
39+
};
40+
};
41+
42+
emul_source3: emul-source3 {
43+
compatible = "fixed-clock";
44+
clock-frequency = <DT_FREQ_M(100)>;
45+
#clock-cells = <0>;
46+
};
47+
48+
emul_mux1: emul-mux1 {
49+
compatible = "vnd,emul-clock-mux";
50+
inputs = <&emul_div1 &emul_div2>;
51+
#clock-cells = <1>;
52+
53+
dev1_out_slow: dev1-out-slow {
54+
compatible = "clock-output";
55+
#clock-cells = <0>;
56+
57+
/* Expect a clock frequency of 10 MHz */
58+
dev1_10mhz: dev1-10mhz {
59+
compatible = "clock-state";
60+
clocks = <&emul_div1 1 &emul_mux1 0>;
61+
clock-frequency = <DT_FREQ_M(10)>;
62+
};
63+
64+
/* Expect a clock frequency of 5 MHz */
65+
dev1_5mhz: dev1-5mhz {
66+
compatible = "clock-state";
67+
clocks = <&emul_div1 2 &emul_mux1 0>;
68+
clock-frequency = <DT_FREQ_M(5)>;
69+
};
70+
71+
/* Expect a clock frequency of 3.333333 MHz */
72+
dev1_3mhz: dev1-3mhz {
73+
compatible = "clock-state";
74+
clocks = <&emul_div1 3 &emul_mux1 0>;
75+
clock-frequency = <3333333>;
76+
};
77+
};
78+
};
79+
80+
emul_mux2: emul-mux2 {
81+
compatible = "vnd,emul-clock-mux";
82+
inputs = <&emul_mux1 &emul_source3>;
83+
#clock-cells = <1>;
84+
85+
dev1_out_fast: dev1-out-fast {
86+
compatible = "clock-output";
87+
#clock-cells = <0>;
88+
89+
/* Expect a clock frequency of 100 MHz */
90+
dev1_100mhz: dev1-100mhz {
91+
compatible = "clock-state";
92+
clocks = <&emul_mux2 1>;
93+
clock-frequency = <DT_FREQ_M(100)>;
94+
};
95+
96+
/* Expect a clock frequency of 50 MHz */
97+
dev1_50mhz: dev1-50mhz {
98+
compatible = "clock-state";
99+
clocks = <&emul_mux2 0
100+
&emul_mux1 1
101+
&emul_div2 1>;
102+
clock-frequency = <DT_FREQ_M(50)>;
103+
};
104+
105+
/* Expect a clock frequency of 25 MHz */
106+
dev1_25mhz: dev1-25mhz {
107+
compatible = "clock-state";
108+
clocks = <&emul_mux2 0
109+
&emul_mux1 1
110+
&emul_div2 2>;
111+
clock-frequency = <DT_FREQ_M(25)>;
112+
};
113+
};
114+
};
115+
};
116+
117+
/* Emulated device clock consumer */
118+
emul_device {
119+
emul_dev1: emul-dev1 {
120+
compatible = "vnd,emul-clock-consumer";
121+
clock-outputs = <&dev1_out_slow &dev1_out_fast>;
122+
clock-output-names = "slow", "fast";
123+
clock-state-0 = <&dev1_10mhz &dev1_100mhz>;
124+
slow-default-freq = <DT_FREQ_M(10)>;
125+
fast-default-freq = <DT_FREQ_M(100)>;
126+
slow-sleep-freq = <3333333>;
127+
fast-sleep-freq = <DT_FREQ_M(25)>;
128+
clock-state-1 = <&dev1_3mhz &dev1_25mhz>;
129+
slow-request-freq = <DT_FREQ_M(5)>;
130+
fast-request-freq = <DT_FREQ_M(50)>;
131+
clock-state-names = "default", "sleep";
132+
};
133+
};
134+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/*
2+
* Copyright (c) 2024 Tenstorrent AI ULC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "native_sim.overlay"
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2024 Tenstorrent AI UL
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: |
6+
Binding for emulated clock consumer device. This device is used in testing
7+
to verify that clock states are applied as expected.
8+
9+
compatible: "vnd,emul-clock-consumer"
10+
11+
include: [clock-device.yaml]
12+
13+
properties:
14+
fast-default-freq:
15+
type: int
16+
required: true
17+
description: |
18+
Frequency this consumer expects to read when applying default
19+
clock state for fast output
20+
21+
fast-sleep-freq:
22+
type: int
23+
required: true
24+
description: |
25+
Frequency this consumer expects to read when applying sleep
26+
clock state for fast output
27+
28+
fast-request-freq:
29+
type: int
30+
required: true
31+
description: |
32+
Frequency this consumer will request from the fast output. Consumer
33+
expects the resulting frequency from this request to match the
34+
requested frequency exactly.
35+
36+
slow-default-freq:
37+
type: int
38+
required: true
39+
description: |
40+
Frequency this consumer expects to read when applying default
41+
clock state for slow output
42+
43+
slow-sleep-freq:
44+
type: int
45+
required: true
46+
description: |
47+
Frequency this consumer expects to read when applying sleep
48+
clock state for slow output
49+
50+
slow-request-freq:
51+
type: int
52+
required: true
53+
description: |
54+
Frequency this consumer will request from the slow output. Consumer
55+
expects the resulting frequency from this request to match the
56+
requested frequency exactly.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright 2024 NXP
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: |
6+
Binding for emulated clock divider node. This divider will divide
7+
the input clock by an integer value, up to the max divider value set
8+
for the node. The node accepts one specifier, the integer value to divide
9+
the clock by.
10+
11+
compatible: "vnd,emul-clock-div"
12+
13+
include: [clock-node.yaml]
14+
15+
properties:
16+
max-div:
17+
type: int
18+
required: true
19+
description: |
20+
Maximum divider value this node can support.
21+
22+
"#clock-cells":
23+
const: 1
24+
25+
clock-cells:
26+
- divider

0 commit comments

Comments
 (0)