xref: /openbmc/u-boot/test/dm/reset.c (revision 894c3ad2)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016, NVIDIA CORPORATION.
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <dm/test.h>
9 #include <asm/reset.h>
10 #include <test/ut.h>
11 
12 /* This must match the specifier for mbox-names="test" in the DT node */
13 #define TEST_RESET_ID 2
14 
15 /* This is the other reset phandle specifier handled by bulk */
16 #define OTHER_RESET_ID 2
17 
18 static int dm_test_reset(struct unit_test_state *uts)
19 {
20 	struct udevice *dev_reset;
21 	struct udevice *dev_test;
22 
23 	ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
24 					      &dev_reset));
25 	ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
26 
27 	ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
28 					      &dev_test));
29 	ut_assertok(sandbox_reset_test_get(dev_test));
30 
31 	ut_assertok(sandbox_reset_test_assert(dev_test));
32 	ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
33 
34 	ut_assertok(sandbox_reset_test_deassert(dev_test));
35 	ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
36 
37 	ut_assertok(sandbox_reset_test_free(dev_test));
38 
39 	return 0;
40 }
41 DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);
42 
43 static int dm_test_reset_bulk(struct unit_test_state *uts)
44 {
45 	struct udevice *dev_reset;
46 	struct udevice *dev_test;
47 
48 	ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
49 					      &dev_reset));
50 	ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
51 	ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
52 
53 	ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
54 					      &dev_test));
55 	ut_assertok(sandbox_reset_test_get_bulk(dev_test));
56 
57 	ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
58 	ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
59 	ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
60 
61 	ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
62 	ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
63 	ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
64 
65 	ut_assertok(sandbox_reset_test_release_bulk(dev_test));
66 	ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
67 	ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
68 
69 	return 0;
70 }
71 DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT);
72