2 * Copyright (C) 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0+
11 #include <linux/err.h>
14 static int dm_test_clk(struct unit_test_state *uts)
16 struct udevice *dev_fixed, *dev_clk, *dev_test;
19 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-fixed",
22 ut_assertok(uclass_get_device_by_name(UCLASS_CLK, "clk-sbox",
24 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
25 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
26 ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI));
27 ut_asserteq(0, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C));
29 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "clk-test",
31 ut_assertok(sandbox_clk_test_get(dev_test));
34 sandbox_clk_test_get_rate(dev_test,
35 SANDBOX_CLK_TEST_ID_FIXED));
36 ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
37 SANDBOX_CLK_TEST_ID_SPI));
38 ut_asserteq(0, sandbox_clk_test_get_rate(dev_test,
39 SANDBOX_CLK_TEST_ID_I2C));
41 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED,
43 ut_assert(IS_ERR_VALUE(rate));
44 rate = sandbox_clk_test_get_rate(dev_test, SANDBOX_CLK_TEST_ID_FIXED);
45 ut_asserteq(1234, rate);
47 ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
48 SANDBOX_CLK_TEST_ID_SPI,
50 ut_asserteq(0, sandbox_clk_test_set_rate(dev_test,
51 SANDBOX_CLK_TEST_ID_I2C,
54 ut_asserteq(1000, sandbox_clk_test_get_rate(dev_test,
55 SANDBOX_CLK_TEST_ID_SPI));
56 ut_asserteq(2000, sandbox_clk_test_get_rate(dev_test,
57 SANDBOX_CLK_TEST_ID_I2C));
59 ut_asserteq(1000, sandbox_clk_test_set_rate(dev_test,
60 SANDBOX_CLK_TEST_ID_SPI,
62 ut_asserteq(2000, sandbox_clk_test_set_rate(dev_test,
63 SANDBOX_CLK_TEST_ID_I2C,
66 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_SPI, 0);
67 ut_assert(IS_ERR_VALUE(rate));
68 rate = sandbox_clk_test_set_rate(dev_test, SANDBOX_CLK_TEST_ID_I2C, 0);
69 ut_assert(IS_ERR_VALUE(rate));
71 ut_asserteq(10000, sandbox_clk_test_get_rate(dev_test,
72 SANDBOX_CLK_TEST_ID_SPI));
73 ut_asserteq(20000, sandbox_clk_test_get_rate(dev_test,
74 SANDBOX_CLK_TEST_ID_I2C));
76 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
77 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
78 ut_asserteq(10000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_SPI));
79 ut_asserteq(20000, sandbox_clk_query_rate(dev_clk, SANDBOX_CLK_ID_I2C));
81 ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_SPI));
82 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
83 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
85 ut_assertok(sandbox_clk_test_enable(dev_test, SANDBOX_CLK_TEST_ID_I2C));
86 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
87 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
89 ut_assertok(sandbox_clk_test_disable(dev_test,
90 SANDBOX_CLK_TEST_ID_SPI));
91 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
92 ut_asserteq(1, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
94 ut_assertok(sandbox_clk_test_disable(dev_test,
95 SANDBOX_CLK_TEST_ID_I2C));
96 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_SPI));
97 ut_asserteq(0, sandbox_clk_query_enable(dev_clk, SANDBOX_CLK_ID_I2C));
99 ut_assertok(sandbox_clk_test_free(dev_test));
103 DM_TEST(dm_test_clk, DM_TESTF_SCAN_FDT);