blob: 691683c567400a119c541160cb2d942c67023dcd [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephen Warren11636252016-05-12 12:03:35 -06002/*
3 * Copyright (C) 2015 Google, Inc
Stephen Warren11636252016-05-12 12:03:35 -06004 */
5
6#include <common.h>
7#include <dm.h>
8#include <sysreset.h>
9#include <asm/state.h>
10#include <asm/test.h>
11#include <dm/test.h>
Simon Glass0e1fad42020-07-19 10:15:37 -060012#include <test/test.h>
Stephen Warren11636252016-05-12 12:03:35 -060013#include <test/ut.h>
14
15/* Test that we can use particular sysreset devices */
16static int dm_test_sysreset_base(struct unit_test_state *uts)
17{
18 struct sandbox_state *state = state_get_current();
19 struct udevice *dev;
20
21 /* Device 0 is the platform data device - it should never respond */
22 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
23 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
24 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
25 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
26
27 /* Device 1 is the warm sysreset device */
28 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
29 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
30 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
31 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
32
33 state->sysreset_allowed[SYSRESET_WARM] = true;
34 ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
35 state->sysreset_allowed[SYSRESET_WARM] = false;
36
37 /* Device 2 is the cold sysreset device */
38 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
39 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010040 state->sysreset_allowed[SYSRESET_COLD] = false;
Stephen Warren11636252016-05-12 12:03:35 -060041 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010042 state->sysreset_allowed[SYSRESET_COLD] = true;
Stephen Warren11636252016-05-12 12:03:35 -060043 state->sysreset_allowed[SYSRESET_POWER] = false;
44 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
45 state->sysreset_allowed[SYSRESET_POWER] = true;
46
47 return 0;
48}
Simon Glasse180c2b2020-07-28 19:41:12 -060049DM_TEST(dm_test_sysreset_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Stephen Warren11636252016-05-12 12:03:35 -060050
Mario Sixcda46882018-08-06 10:23:33 +020051static int dm_test_sysreset_get_status(struct unit_test_state *uts)
52{
53 struct udevice *dev;
54 char msg[64];
55
56 /* Device 1 is the warm sysreset device */
57 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
58 ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
59 ut_asserteq_str("Reset Status: WARM", msg);
60
61 /* Device 2 is the cold sysreset device */
62 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
63 ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
64 ut_asserteq_str("Reset Status: COLD", msg);
65
66 return 0;
67}
Simon Glasse180c2b2020-07-28 19:41:12 -060068DM_TEST(dm_test_sysreset_get_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Mario Sixcda46882018-08-06 10:23:33 +020069
Stephen Warren11636252016-05-12 12:03:35 -060070/* Test that we can walk through the sysreset devices */
71static int dm_test_sysreset_walk(struct unit_test_state *uts)
72{
73 struct sandbox_state *state = state_get_current();
74
75 /* If we generate a power sysreset, we will exit sandbox! */
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010076 state->sysreset_allowed[SYSRESET_WARM] = false;
77 state->sysreset_allowed[SYSRESET_COLD] = false;
Stephen Warren11636252016-05-12 12:03:35 -060078 state->sysreset_allowed[SYSRESET_POWER] = false;
Simon Glass751fed42018-10-01 12:22:46 -060079 state->sysreset_allowed[SYSRESET_POWER_OFF] = false;
Stephen Warren11636252016-05-12 12:03:35 -060080 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
81 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
82 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010083 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER_OFF));
Stephen Warren11636252016-05-12 12:03:35 -060084
85 /*
86 * Enable cold system reset - this should make cold system reset work,
87 * plus a warm system reset should be promoted to cold, since this is
88 * the next step along.
89 */
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010090 state->sysreset_allowed[SYSRESET_WARM] = true;
Stephen Warren11636252016-05-12 12:03:35 -060091 ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010092 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
Stephen Warren11636252016-05-12 12:03:35 -060093 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
Heinrich Schuchardtbf896a22020-10-27 20:29:26 +010094 state->sysreset_allowed[SYSRESET_COLD] = true;
Stephen Warren11636252016-05-12 12:03:35 -060095 state->sysreset_allowed[SYSRESET_POWER] = true;
96
97 return 0;
98}
Simon Glasse180c2b2020-07-28 19:41:12 -060099DM_TEST(dm_test_sysreset_walk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Simon Glass751fed42018-10-01 12:22:46 -0600100
101static int dm_test_sysreset_get_last(struct unit_test_state *uts)
102{
103 struct udevice *dev;
104
105 /* Device 1 is the warm sysreset device */
106 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
107 ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
108
109 /* Device 2 is the cold sysreset device */
110 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
Simon Glass2a072692018-11-23 21:29:28 -0700111 ut_asserteq(SYSRESET_POWER, sysreset_get_last(dev));
Simon Glass751fed42018-10-01 12:22:46 -0600112
113 /* This is device 0, the non-DT one */
Simon Glass2a072692018-11-23 21:29:28 -0700114 ut_asserteq(SYSRESET_POWER, sysreset_get_last_walk());
Simon Glass751fed42018-10-01 12:22:46 -0600115
116 return 0;
117}
Simon Glasse180c2b2020-07-28 19:41:12 -0600118DM_TEST(dm_test_sysreset_get_last, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);