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/device-internal.h>
9 #include <log.h>
10 #include <malloc.h>
11 #include <reset.h>
12 #include <dm/test.h>
13 #include <asm/reset.h>
14 #include <test/test.h>
15 #include <test/ut.h>
16
17 /* This must match the specifier for mbox-names="test" in the DT node */
18 #define TEST_RESET_ID 2
19
20 /* This is the other reset phandle specifier handled by bulk */
21 #define OTHER_RESET_ID 2
22
23 /* Base test of the reset uclass */
dm_test_reset_base(struct unit_test_state * uts)24 static int dm_test_reset_base(struct unit_test_state *uts)
25 {
26 struct udevice *dev;
27 struct reset_ctl reset_method1;
28 struct reset_ctl reset_method2;
29
30 /* Get the device using the reset device */
31 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
32 &dev));
33
34 /* Get the same reset port in 2 different ways and compare */
35 ut_assertok(reset_get_by_index(dev, 1, &reset_method1));
36 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
37 &reset_method2));
38 ut_asserteq(reset_method1.id, reset_method2.id);
39
40 return 0;
41 }
42
43 DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT);
44
dm_test_reset(struct unit_test_state * uts)45 static int dm_test_reset(struct unit_test_state *uts)
46 {
47 struct udevice *dev_reset;
48 struct udevice *dev_test;
49
50 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
51 &dev_reset));
52 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
53
54 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
55 &dev_test));
56 ut_assertok(sandbox_reset_test_get(dev_test));
57
58 ut_assertok(sandbox_reset_test_assert(dev_test));
59 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
60
61 ut_assertok(sandbox_reset_test_deassert(dev_test));
62 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
63
64 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
65 ut_assertok(sandbox_reset_test_free(dev_test));
66 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
67
68 return 0;
69 }
70 DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
71
dm_test_reset_devm(struct unit_test_state * uts)72 static int dm_test_reset_devm(struct unit_test_state *uts)
73 {
74 struct udevice *dev_reset;
75 struct udevice *dev_test;
76
77 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
78 &dev_reset));
79 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
80 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
81 &dev_test));
82 ut_assertok(sandbox_reset_test_get_devm(dev_test));
83
84 ut_assertok(sandbox_reset_test_assert(dev_test));
85 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
86 ut_assertok(sandbox_reset_test_deassert(dev_test));
87 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
88
89 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
90 ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
91 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
92
93 return 0;
94 }
95 DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
96
dm_test_reset_bulk(struct unit_test_state * uts)97 static int dm_test_reset_bulk(struct unit_test_state *uts)
98 {
99 struct udevice *dev_reset;
100 struct udevice *dev_test;
101
102 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
103 &dev_reset));
104 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
105 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
106
107 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
108 &dev_test));
109 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
110
111 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
112 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
113 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
114
115 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
116 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
117 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
118
119 ut_assertok(sandbox_reset_test_release_bulk(dev_test));
120 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
121 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
122
123 return 0;
124 }
125 DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
126
dm_test_reset_bulk_devm(struct unit_test_state * uts)127 static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
128 {
129 struct udevice *dev_reset;
130 struct udevice *dev_test;
131
132 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
133 &dev_reset));
134 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
135 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
136
137 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
138 &dev_test));
139 ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test));
140
141 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
142 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
143 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
144
145 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
146 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
147 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
148
149 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
150 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
151 ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
152 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
153 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
154
155 return 0;
156 }
157 DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);
158