1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016, NVIDIA CORPORATION.
8 #include <dm/device-internal.h>
13 #include <asm/reset.h>
14 #include <test/test.h>
17 /* This must match the specifier for mbox-names="test" in the DT node */
18 #define TEST_RESET_ID 2
20 /* This is the other reset phandle specifier handled by bulk */
21 #define OTHER_RESET_ID 2
23 /* Base test of the reset uclass */
24 static int dm_test_reset_base(struct unit_test_state *uts)
27 struct reset_ctl reset_method1;
28 struct reset_ctl reset_method2;
30 /* Get the device using the reset device */
31 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
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,
38 ut_asserteq(reset_method1.id, reset_method2.id);
43 DM_TEST(dm_test_reset_base, UT_TESTF_SCAN_FDT);
45 static int dm_test_reset(struct unit_test_state *uts)
47 struct udevice *dev_reset;
48 struct udevice *dev_test;
50 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
52 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
54 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
56 ut_assertok(sandbox_reset_test_get(dev_test));
58 ut_assertok(sandbox_reset_test_assert(dev_test));
59 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
61 ut_assertok(sandbox_reset_test_deassert(dev_test));
62 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
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));
70 DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
72 static int dm_test_reset_devm(struct unit_test_state *uts)
74 struct udevice *dev_reset;
75 struct udevice *dev_test;
77 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
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",
82 ut_assertok(sandbox_reset_test_get_devm(dev_test));
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));
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));
95 DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
97 static int dm_test_reset_bulk(struct unit_test_state *uts)
99 struct udevice *dev_reset;
100 struct udevice *dev_test;
102 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
104 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
105 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
107 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
109 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
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));
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));
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));
125 DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
127 static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
129 struct udevice *dev_reset;
130 struct udevice *dev_test;
132 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
134 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
135 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
137 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
139 ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test));
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));
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));
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));
157 DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);