1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
10 #include <linux/err.h>
13 static int dm_test_clk(struct unit_test_state *uts)
15 struct udevice *dev_fixed, *dev_clk, *dev_test;
18 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed",
21 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
23 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
24 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
25 ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI));
26 ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C));
28 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
30 ut_assertok(sandbox_clk_test_get(dev_test));
33 sandbox_clk_test_get_rate(dev_test,
34 SANDBOX_CLK_TEST_ID_FIXED));
35 ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
36 SANDBOX_CLK_TEST_ID_SPI));
37 ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
38 SANDBOX_CLK_TEST_ID_I2C));
40 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED,
42 ut_assert(IS_ERR_VALUE(rate));
43 rate = sandbox_clk_test_get_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED);
44 ut_asserteq(1234, rate);
46 ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
47 SANDBOX_CLK_TEST_ID_SPI,
49 ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
50 SANDBOX_CLK_TEST_ID_I2C,
53 ut_asserteq(1000, sandbox_clk_test_get_rate(dev_test,
54 SANDBOX_CLK_TEST_ID_SPI));
55 ut_asserteq(2000, sandbox_clk_test_get_rate(dev_test,
56 SANDBOX_CLK_TEST_ID_I2C));
58 ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test,
59 SANDBOX_CLK_TEST_ID_SPI,
61 ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test,
62 SANDBOX_CLK_TEST_ID_I2C,
65 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0);
66 ut_assert(IS_ERR_VALUE(rate));
67 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0);
68 ut_assert(IS_ERR_VALUE(rate));
70 ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test,
71 SANDBOX_CLK_TEST_ID_SPI));
72 ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test,
73 SANDBOX_CLK_TEST_ID_I2C));
75 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
76 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
77 ut_asserteq(10000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI));
78 ut_asserteq(20000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C));
80 ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_SPI));
81 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
82 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
84 ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_I2C));
85 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
86 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
88 ut_assertok(sandbox_clk_test_disable(dev_test,
89 SANDBOX_CLK_TEST_ID_SPI));
90 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
91 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
93 ut_assertok(sandbox_clk_test_disable(dev_test,
94 SANDBOX_CLK_TEST_ID_I2C));
95 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
96 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
98 ut_assertok(sandbox_clk_test_free(dev_test));
102 DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT);
104 static int dm_test_clk_bulk(struct unit_test_state *uts)
106 struct udevice *dev_clk, *dev_test;
108 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
110 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
112 ut_assertok(sandbox_clk_test_get_bulk(dev_test));
114 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
115 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
117 /* Fixed clock does not support enable, thus should not fail */
118 ut_assertok(sandbox_clk_test_enable_bulk(dev_test));
119 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
120 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
122 /* Fixed clock does not support disable, thus should not fail */
123 ut_assertok(sandbox_clk_test_disable_bulk(dev_test));
124 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
125 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
127 /* Fixed clock does not support enable, thus should not fail */
128 ut_assertok(sandbox_clk_test_enable_bulk(dev_test));
129 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
130 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
132 /* Fixed clock does not support disable, thus should not fail */
133 ut_assertok(sandbox_clk_test_release_bulk(dev_test));
134 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
135 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
139 DM_TEST(dm_test_clk_bulk, DM_TESTF_SCAN_FDT);