1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016, NVIDIA CORPORATION.
10 #include <asm/reset.h>
13 /* This must match the specifier for mbox-names="test" in the DT node */
14 #define TEST_RESET_ID 2
16 /* This is the other reset phandle specifier handled by bulk */
17 #define OTHER_RESET_ID 2
19 /* Base test of the reset uclass */
20 static int dm_test_reset_base(struct unit_test_state *uts)
23 struct reset_ctl reset_method1;
24 struct reset_ctl reset_method2;
26 /* Get the device using the reset device */
27 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
30 /* Get the same reset port in 2 different ways and compare */
31 ut_assertok(reset_get_by_index(dev, 1, &reset_method1));
32 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
34 ut_asserteq(reset_method1.id, reset_method2.id);
39 DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_FDT);
41 static int dm_test_reset(struct unit_test_state *uts)
43 struct udevice *dev_reset;
44 struct udevice *dev_test;
46 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
48 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
50 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
52 ut_assertok(sandbox_reset_test_get(dev_test));
54 ut_assertok(sandbox_reset_test_assert(dev_test));
55 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
57 ut_assertok(sandbox_reset_test_deassert(dev_test));
58 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
60 ut_assertok(sandbox_reset_test_free(dev_test));
64 DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);
66 static int dm_test_reset_bulk(struct unit_test_state *uts)
68 struct udevice *dev_reset;
69 struct udevice *dev_test;
71 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
73 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
74 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
76 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
78 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
80 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
81 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
82 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
84 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
85 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
86 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
88 ut_assertok(sandbox_reset_test_release_bulk(dev_test));
89 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
90 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
94 DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT);