]> Git Repo - u-boot.git/blob - test/dm/syscon-reset.c
Merge branch 'master' of https://source.denx.de/u-boot/custodians/u-boot-sh
[u-boot.git] / test / dm / syscon-reset.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2020 Sean Anderson <[email protected]>
4  */
5
6 #include <dm.h>
7 #include <dm/test.h>
8 #include <regmap.h>
9 #include <reset.h>
10 #include <syscon.h>
11 #include <test/ut.h>
12 #include <asm/test.h>
13 #include <linux/bitops.h>
14
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)
20
21 #define TEST_RESET_VALID 15
22 #define TEST_RESET_NOMASK 30
23 #define TEST_RESET_OUTOFRANGE 60
24
25 static int dm_test_syscon_reset(struct unit_test_state *uts)
26 {
27         struct regmap *map;
28         struct reset_ctl rst;
29         struct udevice *reset;
30         struct udevice *syscon;
31         struct udevice *syscon_reset;
32         uint reg;
33
34         ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "syscon-reset-test",
35                                               &reset));
36         ut_assertok(uclass_get_device_by_name(UCLASS_SYSCON, "syscon@0",
37                                               &syscon));
38         ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "syscon-reset",
39                                               &syscon_reset));
40         ut_assertok_ptr((map = syscon_get_regmap(syscon)));
41
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));
45
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, &reg));
50         ut_asserteq(TEST_RESET_DEASSERT ^ BIT(TEST_RESET_VALID), reg);
51
52         ut_assertok(reset_deassert(&rst));
53         ut_assertok(regmap_read(map, TEST_RESET_REG, &reg));
54         ut_asserteq(TEST_RESET_DEASSERT, reg);
55
56         return 0;
57 }
58 DM_TEST(dm_test_syscon_reset, UTF_SCAN_FDT);
This page took 0.030174 seconds and 4 git commands to generate.