1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
14 #include <linux/bitops.h>
16 /* The following values must match the device tree */
17 #define TEST_RESET_REG 1
18 #define TEST_RESET_ASSERT_HIGH 0
19 #define TEST_RESET_ASSERT (TEST_RESET_ASSERT_HIGH ? (u32)-1 : (u32)0)
20 #define TEST_RESET_DEASSERT (~TEST_RESET_ASSERT)
22 #define TEST_RESET_VALID 15
23 #define TEST_RESET_NOMASK 30
24 #define TEST_RESET_OUTOFRANGE 60
26 static int dm_test_syscon_reset(struct unit_test_state *uts)
30 struct udevice *reset;
31 struct udevice *syscon;
32 struct udevice *syscon_reset;
35 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "syscon-reset-test",
37 ut_assertok(uclass_get_device_by_name(UCLASS_SYSCON, "syscon@0",
39 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "syscon-reset",
41 ut_assertok_ptr((map = syscon_get_regmap(syscon)));
43 ut_asserteq(-EINVAL, reset_get_by_name(reset, "no_mask", &rst));
44 ut_asserteq(-EINVAL, reset_get_by_name(reset, "out_of_range", &rst));
45 ut_assertok(reset_get_by_name(reset, "valid", &rst));
47 sandbox_set_enable_memio(true);
48 ut_assertok(regmap_write(map, TEST_RESET_REG, TEST_RESET_DEASSERT));
49 ut_assertok(reset_assert(&rst));
50 ut_assertok(regmap_read(map, TEST_RESET_REG, ®));
51 ut_asserteq(TEST_RESET_DEASSERT ^ BIT(TEST_RESET_VALID), reg);
53 ut_assertok(reset_deassert(&rst));
54 ut_assertok(regmap_read(map, TEST_RESET_REG, ®));
55 ut_asserteq(TEST_RESET_DEASSERT, reg);
59 DM_TEST(dm_test_syscon_reset, DM_TESTF_SCAN_FDT);