1 // SPDX-License-Identifier: GPL-2.0+
13 #include <linux/bitops.h>
15 /* The following values must match the device tree */
16 #define TEST_RESET_REG 1
17 #define TEST_RESET_ASSERT_HIGH 0
18 #define TEST_RESET_ASSERT (TEST_RESET_ASSERT_HIGH ? (u32)-1 : (u32)0)
19 #define TEST_RESET_DEASSERT (~TEST_RESET_ASSERT)
21 #define TEST_RESET_VALID 15
22 #define TEST_RESET_NOMASK 30
23 #define TEST_RESET_OUTOFRANGE 60
25 static int dm_test_syscon_reset(struct unit_test_state *uts)
29 struct udevice *reset;
30 struct udevice *syscon;
31 struct udevice *syscon_reset;
34 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "syscon-reset-test",
36 ut_assertok(uclass_get_device_by_name(UCLASS_SYSCON, "syscon@0",
38 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "syscon-reset",
40 ut_assertok_ptr((map = syscon_get_regmap(syscon)));
42 ut_asserteq(-EINVAL, reset_get_by_name(reset, "no_mask", &rst));
43 ut_asserteq(-EINVAL, reset_get_by_name(reset, "out_of_range", &rst));
44 ut_assertok(reset_get_by_name(reset, "valid", &rst));
46 sandbox_set_enable_memio(true);
47 ut_assertok(regmap_write(map, TEST_RESET_REG, TEST_RESET_DEASSERT));
48 ut_assertok(reset_assert(&rst));
49 ut_assertok(regmap_read(map, TEST_RESET_REG, ®));
50 ut_asserteq(TEST_RESET_DEASSERT ^ BIT(TEST_RESET_VALID), reg);
52 ut_assertok(reset_deassert(&rst));
53 ut_assertok(regmap_read(map, TEST_RESET_REG, ®));
54 ut_asserteq(TEST_RESET_DEASSERT, reg);
58 DM_TEST(dm_test_syscon_reset, UTF_SCAN_FDT);