1 // SPDX-License-Identifier: GPL-2.0+
12 #include <dm/uclass.h>
13 #include <linux/err.h>
15 #include <sandbox-clk.h>
17 /* Tests for Common Clock Framework driver */
18 static int dm_test_clk_ccf(struct unit_test_state *uts)
20 struct clk *clk, *pclk;
25 /* Get the device using the clk device */
26 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-ccf", &dev));
28 /* Test for clk_get_by_id() */
29 ret = clk_get_by_id(SANDBOX_CLK_ECSPI_ROOT, &clk);
31 ut_asserteq_str("ecspi_root", clk->dev->name);
33 /* Test for clk_get_parent_rate() */
34 ret = clk_get_by_id(SANDBOX_CLK_ECSPI1, &clk);
36 ut_asserteq_str("ecspi1", clk->dev->name);
38 rate = clk_get_parent_rate(clk);
39 ut_asserteq(rate, 20000000);
41 /* Test the mux of CCF */
42 ret = clk_get_by_id(SANDBOX_CLK_USDHC1_SEL, &clk);
44 ut_asserteq_str("usdhc1_sel", clk->dev->name);
46 rate = clk_get_parent_rate(clk);
47 ut_asserteq(rate, 60000000);
49 ret = clk_get_by_id(SANDBOX_CLK_USDHC2_SEL, &clk);
51 ut_asserteq_str("usdhc2_sel", clk->dev->name);
53 rate = clk_get_parent_rate(clk);
54 ut_asserteq(rate, 80000000);
56 pclk = clk_get_parent(clk);
57 ut_asserteq_str("pll3_80m", pclk->dev->name);
59 /* Test the composite of CCF */
60 ret = clk_get_by_id(SANDBOX_CLK_I2C, &clk);
62 ut_asserteq_str("i2c", clk->dev->name);
64 rate = clk_get_rate(clk);
65 ut_asserteq(rate, 60000000);
67 #if CONFIG_IS_ENABLED(CLK_CCF)
68 /* Test clk tree enable/disable */
69 ret = clk_get_by_id(SANDBOX_CLK_I2C_ROOT, &clk);
71 ut_asserteq_str("i2c_root", clk->dev->name);
73 ret = clk_enable(clk);
76 ret = sandbox_clk_enable_count(clk);
79 ret = clk_get_by_id(SANDBOX_CLK_I2C, &pclk);
82 ret = sandbox_clk_enable_count(pclk);
85 ret = clk_disable(clk);
88 ret = sandbox_clk_enable_count(clk);
91 ret = sandbox_clk_enable_count(pclk);
98 DM_TEST(dm_test_clk_ccf, DM_TESTF_SCAN_FDT);