Skip to content

Commit 59509c5

Browse files
tests: drivers: clock_management: add clock management hardware test
Add clock management hardware test. This test applies a series of clock states for a given consumer, and verifies that each state produces the expected rate. This test is intended to verify that each clock node driver within an SOC implementation works as expected. Boards should define their test overlays for this test to exercise as much of the clock tree as possible, and ensure some clock states do not define an explicit clocks property, to test their `clock_set_rate` and `clock_round_rate` implementations. Initial support is added for the `lpcxpresso55s69/lpc55s69/cpu0` target, as this is the only hardware supporting clock management. Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
1 parent b3a9a1c commit 59509c5

File tree

7 files changed

+233
-0
lines changed

7 files changed

+233
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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_hw)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Clock Management Hardware Test
2+
##############################
3+
4+
This test is designed to verify the functionality of hardware clock trees
5+
implementing the clock management API. It defines one dummy devices, which
6+
will be a clock consumer.
7+
8+
The test will apply five clock states for the dummy device, and verify the
9+
frequency matches an expected value for each state. The states are as
10+
follows:
11+
12+
* clock-state-0: CLOCK_MANAGEMENT_STATE_DEFAULT, frequency set by "default-freq"
13+
property of consumer node
14+
15+
* clock-state-1: CLOCK_MANAGEMENT_STATE_SLEEP, frequency set by "sleep-freq"
16+
property of consumer node
17+
18+
* clock-state-2: CLOCK_MANAGEMENT_STATE_TEST1, frequency set by "test1-freq"
19+
property of consumer node
20+
21+
* clock-state-3: CLOCK_MANAGEMENT_STATE_TEST2, frequency set by "test2-freq"
22+
property of consumer node
23+
24+
* clock-state-4: CLOCK_MANAGEMENT_STATE_TEST3, frequency set by "test3-freq"
25+
property of consumer node
26+
27+
Devices should define these states to exercise as many clock node drivers as
28+
possible. One example might be clocking from a PLL in the default state, a
29+
high speed internal oscillator in the sleep state, and a low speed external
30+
oscillator in the test state. Some states should avoid defining explicit
31+
configuration settings, to verify that runtime clock set_rate APIs work as
32+
expected.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* Clock CPU from FROHF, since we will use the PLLs within our testcases */
7+
&system_clock {
8+
sys_clk_96mhz: sys-clk-96mhz {
9+
compatible = "clock-state";
10+
clocks = <&ahbclkdiv 1 &fro_hf 1 &mainclksela 3 &mainclkselb 0>;
11+
clock-frequency = <DT_FREQ_M(96)>;
12+
locking-state;
13+
};
14+
};
15+
16+
&cpu0 {
17+
clock-state-0 = <&sys_clk_96mhz>;
18+
};
19+
20+
/* Define clock states for clockout clock */
21+
&clkout_clock {
22+
clkout_default: clkout-default {
23+
compatible = "clock-state";
24+
/* Enable PLL1 and switch clkout to use it */
25+
clocks = <&xtal32m 1 &clk_in_en 1 &pll1clksel 1 &pll1_pdec 2
26+
&pll1_directo 0 &pll1 300000000 4 75 0 39 19
27+
&pll1_bypass 0 &clkoutsel 5 &clkoutdiv 2>;
28+
clock-frequency = <75000000>;
29+
};
30+
clkout_sleep: clkout-sleep {
31+
compatible = "clock-state";
32+
clocks = <&fro_hf 1 &clkoutsel 3 &clkoutdiv 1>;
33+
clock-frequency = <96000000>;
34+
};
35+
clkout_test1: clkout-test1 {
36+
/* Should use runtime frequency requests */
37+
compatible = "clock-state";
38+
clock-frequency = <73000000>;
39+
};
40+
clkout_test2: clkout-test2 {
41+
/* Should use runtime frequency requests */
42+
compatible = "clock-state";
43+
clock-frequency = <147640000>;
44+
};
45+
clkout_test3: clkout-test3 {
46+
/* Should use runtime frequency requests */
47+
compatible = "clock-state";
48+
clock-frequency = <1000000>;
49+
};
50+
};
51+
52+
/ {
53+
emul_dev: emul-dev {
54+
compatible = "vnd,emul-clock-consumer";
55+
clock-outputs = <&clkout_clock>;
56+
clock-output-names = "default";
57+
clock-state-0 = <&clkout_default>;
58+
default-freq = <75000000>;
59+
clock-state-1 = <&clkout_sleep>;
60+
sleep-freq = <96000000>;
61+
clock-state-2 = <&clkout_test1>;
62+
test1-freq = <73000000>;
63+
clock-state-3 = <&clkout_test2>;
64+
test2-freq = <147640000>;
65+
clock-state-4 = <&clkout_test3>;
66+
test3-freq = <1000000>;
67+
clock-state-names= "default", "sleep", "test1",
68+
"test2", "test3";
69+
};
70+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2024 NXP
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+
default-freq:
15+
type: int
16+
required: true
17+
description: |
18+
Frequency this consumer expects to read when applying default clock
19+
management state
20+
21+
sleep-freq:
22+
type: int
23+
required: true
24+
description: |
25+
Frequency this consumer expects to read when applying sleep clock
26+
management state
27+
28+
test1-freq:
29+
type: int
30+
required: true
31+
description: |
32+
Frequency this consumer expects to read when applying test1 clock
33+
management state
34+
35+
test2-freq:
36+
type: int
37+
required: true
38+
description: |
39+
Frequency this consumer expects to read when applying test2 clock
40+
management state
41+
42+
test3-freq:
43+
type: int
44+
required: true
45+
description: |
46+
Frequency this consumer expects to read when applying test3 clock
47+
management state
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CONFIG_ZTEST=y
2+
CONFIG_CLOCK_MANAGEMENT=y
3+
CONFIG_CLOCK_MANAGEMENT_RUNTIME=y
4+
CONFIG_CLOCK_MANAGEMENT_SET_RATE=y
5+
CONFIG_ZTEST_STACK_SIZE=2048
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include <zephyr/ztest.h>
7+
#include <zephyr/drivers/clock_management.h>
8+
#include <zephyr/logging/log.h>
9+
LOG_MODULE_REGISTER(test);
10+
11+
#define CONSUMER_NODE DT_NODELABEL(emul_dev)
12+
13+
CLOCK_MANAGEMENT_DT_DEFINE_OUTPUT_BY_NAME(CONSUMER_NODE, default);
14+
15+
/* Get references to each clock management state and output */
16+
static const struct clock_output *dev_out =
17+
CLOCK_MANAGEMENT_DT_GET_OUTPUT_BY_NAME(CONSUMER_NODE, default);
18+
static clock_management_state_t dev_default =
19+
CLOCK_MANAGEMENT_DT_GET_STATE(CONSUMER_NODE, default, default);
20+
static clock_management_state_t dev_sleep =
21+
CLOCK_MANAGEMENT_DT_GET_STATE(CONSUMER_NODE, default, sleep);
22+
static clock_management_state_t dev_test1 =
23+
CLOCK_MANAGEMENT_DT_GET_STATE(CONSUMER_NODE, default, test1);
24+
static clock_management_state_t dev_test2 =
25+
CLOCK_MANAGEMENT_DT_GET_STATE(CONSUMER_NODE, default, test2);
26+
static clock_management_state_t dev_test3 =
27+
CLOCK_MANAGEMENT_DT_GET_STATE(CONSUMER_NODE, default, test3);
28+
29+
void apply_clock_state(clock_management_state_t state, const char *state_name,
30+
int expected_rate)
31+
{
32+
int ret;
33+
34+
/* Apply clock state, verify frequencies */
35+
TC_PRINT("Try to apply %s clock state\n", state_name);
36+
37+
ret = clock_management_apply_state(dev_out, state);
38+
zassert_equal(ret, expected_rate,
39+
"Failed to apply %s clock management state", state_name);
40+
41+
/* Check rate */
42+
ret = clock_management_get_rate(dev_out);
43+
TC_PRINT("Consumer %s clock rate: %d\n", state_name, ret);
44+
zassert_equal(ret, expected_rate,
45+
"Consumer has invalid %s clock rate", state_name);
46+
}
47+
48+
ZTEST(clock_management_hw, test_apply_states)
49+
{
50+
apply_clock_state(dev_default, "default",
51+
DT_PROP(CONSUMER_NODE, default_freq));
52+
apply_clock_state(dev_sleep, "sleep",
53+
DT_PROP(CONSUMER_NODE, sleep_freq));
54+
apply_clock_state(dev_test1, "test1",
55+
DT_PROP(CONSUMER_NODE, test1_freq));
56+
apply_clock_state(dev_test2, "test2",
57+
DT_PROP(CONSUMER_NODE, test2_freq));
58+
apply_clock_state(dev_test3, "test3",
59+
DT_PROP(CONSUMER_NODE, test3_freq));
60+
}
61+
62+
ZTEST_SUITE(clock_management_hw, NULL, NULL, NULL, NULL, NULL);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
tests:
2+
drivers.clock_management.hw:
3+
tags:
4+
- drivers
5+
- clock_management
6+
integration_platforms:
7+
- lpcxpresso55s69/lpc55s69/cpu0
8+
filter: dt_compat_enabled("vnd,emul-clock-consumer")

0 commit comments

Comments
 (0)