blob: 9c0045233642cc567c3228205a10be31098fd6bb [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren4581b712016-06-17 09:43:59 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren4581b712016-06-17 09:43:59 -06004 */
5
6#include <common.h>
7#include <dm.h>
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +05308#include <dm/device-internal.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070010#include <malloc.h>
Jagan Teki41cdb282019-02-28 00:26:56 +053011#include <reset.h>
Stephen Warren4581b712016-06-17 09:43:59 -060012#include <dm/test.h>
13#include <asm/reset.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060014#include <test/test.h>
Stephen Warren4581b712016-06-17 09:43:59 -060015#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
Neil Armstrong91f5f8b2018-04-03 11:40:51 +020020/* This is the other reset phandle specifier handled by bulk */
21#define OTHER_RESET_ID 2
22
Jagan Teki41cdb282019-02-28 00:26:56 +053023/* Base test of the reset uclass */
24static int dm_test_reset_base(struct unit_test_state *uts)
25{
26 struct udevice *dev;
Neil Armstrongbdfe6902021-04-20 10:42:25 +020027 struct reset_ctl reset_method1, reset_method1_1;
28 struct reset_ctl reset_method2, reset_method2_1;
29 struct reset_ctl reset_method3, reset_method3_1;
30 struct reset_ctl reset_method4, reset_method4_1;
Jagan Teki41cdb282019-02-28 00:26:56 +053031
32 /* Get the device using the reset device */
33 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
34 &dev));
35
36 /* Get the same reset port in 2 different ways and compare */
Neil Armstrongbdfe6902021-04-20 10:42:25 +020037 ut_assertok(reset_get_by_index(dev, 0, &reset_method1));
38 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 0,
39 &reset_method1_1));
40 ut_assertok(reset_get_by_index(dev, 1, &reset_method2));
Jagan Teki41cdb282019-02-28 00:26:56 +053041 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
Neil Armstrongbdfe6902021-04-20 10:42:25 +020042 &reset_method2_1));
43 ut_assertok(reset_get_by_index(dev, 2, &reset_method3));
44 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 2,
45 &reset_method3_1));
46 ut_assertok(reset_get_by_index(dev, 3, &reset_method4));
47 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 3,
48 &reset_method4_1));
49
50 ut_asserteq(reset_method1.id, reset_method1_1.id);
51 ut_asserteq(reset_method2.id, reset_method2_1.id);
52 ut_asserteq(reset_method3.id, reset_method3_1.id);
53 ut_asserteq(reset_method4.id, reset_method4_1.id);
54
55 ut_asserteq(true, reset_method1.id != reset_method2.id);
56 ut_asserteq(true, reset_method1.id != reset_method3.id);
57 ut_asserteq(true, reset_method1.id != reset_method4.id);
58 ut_asserteq(true, reset_method2.id != reset_method3.id);
59 ut_asserteq(true, reset_method2.id != reset_method4.id);
60 ut_asserteq(true, reset_method3.id != reset_method4.id);
61
62 ut_asserteq(true, reset_method1_1.id != reset_method2_1.id);
63 ut_asserteq(true, reset_method1_1.id != reset_method3_1.id);
64 ut_asserteq(true, reset_method1_1.id != reset_method4_1.id);
65 ut_asserteq(true, reset_method2_1.id != reset_method3_1.id);
66 ut_asserteq(true, reset_method2_1.id != reset_method4_1.id);
67 ut_asserteq(true, reset_method3_1.id != reset_method4_1.id);
Jagan Teki41cdb282019-02-28 00:26:56 +053068
69 return 0;
70}
71
Simon Glasse180c2b2020-07-28 19:41:12 -060072DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT);
Jagan Teki41cdb282019-02-28 00:26:56 +053073
Stephen Warren4581b712016-06-17 09:43:59 -060074static int dm_test_reset(struct unit_test_state *uts)
75{
76 struct udevice *dev_reset;
77 struct udevice *dev_test;
78
79 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
80 &dev_reset));
81 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
82
83 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
84 &dev_test));
85 ut_assertok(sandbox_reset_test_get(dev_test));
86
87 ut_assertok(sandbox_reset_test_assert(dev_test));
88 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
89
90 ut_assertok(sandbox_reset_test_deassert(dev_test));
91 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
92
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053093 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
Stephen Warren4581b712016-06-17 09:43:59 -060094 ut_assertok(sandbox_reset_test_free(dev_test));
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +053095 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
Stephen Warren4581b712016-06-17 09:43:59 -060096
97 return 0;
98}
Simon Glasse180c2b2020-07-28 19:41:12 -060099DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
Neil Armstrong91f5f8b2018-04-03 11:40:51 +0200100
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +0530101static int dm_test_reset_devm(struct unit_test_state *uts)
102{
103 struct udevice *dev_reset;
104 struct udevice *dev_test;
105
106 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
107 &dev_reset));
108 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
109 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
110 &dev_test));
111 ut_assertok(sandbox_reset_test_get_devm(dev_test));
112
113 ut_assertok(sandbox_reset_test_assert(dev_test));
114 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
115 ut_assertok(sandbox_reset_test_deassert(dev_test));
116 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
117
118 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
119 ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
120 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
121
122 return 0;
123}
124DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
125
Neil Armstrong91f5f8b2018-04-03 11:40:51 +0200126static int dm_test_reset_bulk(struct unit_test_state *uts)
127{
128 struct udevice *dev_reset;
129 struct udevice *dev_test;
130
131 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
132 &dev_reset));
133 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
134 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
135
136 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
137 &dev_test));
138 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
139
140 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
141 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
142 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
143
144 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
145 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
146 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
147
148 ut_assertok(sandbox_reset_test_release_bulk(dev_test));
149 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
150 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
151
152 return 0;
153}
Simon Glasse180c2b2020-07-28 19:41:12 -0600154DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
Jean-Jacques Hiblotbad24332020-09-09 15:37:04 +0530155
156static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
157{
158 struct udevice *dev_reset;
159 struct udevice *dev_test;
160
161 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
162 &dev_reset));
163 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
164 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
165
166 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
167 &dev_test));
168 ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test));
169
170 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
171 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
172 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
173
174 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
175 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
176 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
177
178 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
179 ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
180 ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
181 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
182 ut_asserteq(0, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
183
184 return 0;
185}
186DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);