blob: 82328072644b81bab7267ca3a916a9c0afd445be [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>
Simon Glass75c4d412020-07-19 10:15:37 -060013#include <test/test.h>
Stephen Warren6488e642016-06-17 09:43:59 -060014#include <test/ut.h>
15
16/* This must match the specifier for mbox-names="test" in the DT node */
17#define TEST_RESET_ID 2
18
Neil Armstrong20c633d2018-04-03 11:40:51 +020019/* This is the other reset phandle specifier handled by bulk */
20#define OTHER_RESET_ID 2
21
Jagan Tekidcd48c32019-02-28 00:26:56 +053022/* Base test of the reset uclass */
23static int dm_test_reset_base(struct unit_test_state *uts)
24{
25 struct udevice *dev;
26 struct reset_ctl reset_method1;
27 struct reset_ctl reset_method2;
28
29 /* Get the device using the reset device */
30 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
31 &dev));
32
33 /* Get the same reset port in 2 different ways and compare */
34 ut_assertok(reset_get_by_index(dev, 1, &reset_method1));
35 ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
36 &reset_method2));
37 ut_asserteq(reset_method1.id, reset_method2.id);
38
39 return 0;
40}
41
42DM_TEST(dm_test_reset_base, DM_TESTF_SCAN_FDT);
43
Stephen Warren6488e642016-06-17 09:43:59 -060044static int dm_test_reset(struct unit_test_state *uts)
45{
46 struct udevice *dev_reset;
47 struct udevice *dev_test;
48
49 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
50 &dev_reset));
51 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
52
53 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
54 &dev_test));
55 ut_assertok(sandbox_reset_test_get(dev_test));
56
57 ut_assertok(sandbox_reset_test_assert(dev_test));
58 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
59
60 ut_assertok(sandbox_reset_test_deassert(dev_test));
61 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
62
63 ut_assertok(sandbox_reset_test_free(dev_test));
64
65 return 0;
66}
67DM_TEST(dm_test_reset, DM_TESTF_SCAN_FDT);
Neil Armstrong20c633d2018-04-03 11:40:51 +020068
69static int dm_test_reset_bulk(struct unit_test_state *uts)
70{
71 struct udevice *dev_reset;
72 struct udevice *dev_test;
73
74 ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
75 &dev_reset));
76 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
77 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
78
79 ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
80 &dev_test));
81 ut_assertok(sandbox_reset_test_get_bulk(dev_test));
82
83 ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
84 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
85 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
86
87 ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
88 ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
89 ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
90
91 ut_assertok(sandbox_reset_test_release_bulk(dev_test));
92 ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
93 ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
94
95 return 0;
96}
97DM_TEST(dm_test_reset_bulk, DM_TESTF_SCAN_FDT);