blob: 871d6400a07346ca5d441408da95d29aed410291 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren6488e642016-06-17 09:43:59 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren6488e642016-06-17 09:43:59 -06004 */
5
6#include <common.h>
7#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Jagan Tekidcd48c32019-02-28 00:26:56 +053010#include <reset.h>
Stephen Warren6488e642016-06-17 09:43:59 -060011#include <dm/test.h>
12#include <asm/reset.h>
13#include <test/ut.h>
14
15/* This must match the specifier for mbox-names="test" in the DT node */
16#define TEST_RESET_ID 2
17
Neil Armstrong20c633d2018-04-03 11:40:51 +020018/* This is the other reset phandle specifier handled by bulk */
19#define OTHER_RESET_ID 2
20
Jagan Tekidcd48c32019-02-28 00:26:56 +053021/* Base test of the reset uclass */
22static int dm_test_reset_base(struct unit_test_state *uts)
23{
24 struct udevice *dev;
25 struct reset_ctl reset_method1;
26 struct reset_ctl reset_method2;
27
28 /* Get the device using the reset device */
29 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
30 &dev));
31
32 /* Get the same reset port in 2 different ways and compare */
33 ut_assertok(reset_get_by_index(dev, 1, &reset_method1));
34 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
35 &reset_method2));
36 ut_asserteq(reset_method1.id, reset_method2.id);
37
38 return 0;
39}
40
41DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_FDT);
42
Stephen Warren6488e642016-06-17 09:43:59 -060043static int dm_test_reset(struct unit_test_state *uts)
44{
45 struct udevice *dev_reset;
46 struct udevice *dev_test;
47
48 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
49 &dev_reset));
50 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
51
52 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
53 &dev_test));
54 ut_assertok(sandbox_reset_test_get(dev_test));
55
56 ut_assertok(sandbox_reset_test_assert(dev_test));
57 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
58
59 ut_assertok(sandbox_reset_test_deassert(dev_test));
60 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
61
62 ut_assertok(sandbox_reset_test_free(dev_test));
63
64 return 0;
65}
66DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);
Neil Armstrong20c633d2018-04-03 11:40:51 +020067
68static int dm_test_reset_bulk(struct unit_test_state *uts)
69{
70 struct udevice *dev_reset;
71 struct udevice *dev_test;
72
73 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
74 &dev_reset));
75 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
76 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
77
78 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
79 &dev_test));
80 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
81
82 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
83 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
84 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
85
86 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
87 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
88 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
89
90 ut_assertok(sandbox_reset_test_release_bulk(dev_test));
91 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
92 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
93
94 return 0;
95}
96DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT);