blob: ba19504573f4faf79f43c19f24a0dc536924f778 [file] [log] [blame]
Sean Anderson0c1f6bf2020-06-24 06:41:14 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020 Sean Anderson <seanga2@gmail.com>
4 */
5
Sean Anderson0c1f6bf2020-06-24 06:41:14 -04006#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
25static 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}
Simon Glass974dccd2020-07-28 19:41:12 -060058DM_TEST(dm_test_syscon_reset, UT_TESTF_SCAN_FDT);