1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
14 /* Test that we can use particular sysreset devices */
15 static int dm_test_sysreset_base(struct unit_test_state *uts)
17 struct sandbox_state *state = state_get_current();
20 /* Device 0 is the platform data device - it should never respond */
21 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
22 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
23 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
24 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
26 /* Device 1 is the warm sysreset device */
27 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
28 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
29 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
30 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
32 state->sysreset_allowed[SYSRESET_WARM] = true;
33 ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
34 state->sysreset_allowed[SYSRESET_WARM] = false;
36 /* Device 2 is the cold sysreset device */
37 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
38 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
39 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
40 state->sysreset_allowed[SYSRESET_POWER] = false;
41 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
42 state->sysreset_allowed[SYSRESET_POWER] = true;
46 DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
48 /* Test that we can walk through the sysreset devices */
49 static int dm_test_sysreset_walk(struct unit_test_state *uts)
51 struct sandbox_state *state = state_get_current();
53 /* If we generate a power sysreset, we will exit sandbox! */
54 state->sysreset_allowed[SYSRESET_POWER] = false;
55 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
56 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
57 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
60 * Enable cold system reset - this should make cold system reset work,
61 * plus a warm system reset should be promoted to cold, since this is
62 * the next step along.
64 state->sysreset_allowed[SYSRESET_COLD] = true;
65 ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
66 ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD));
67 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
68 state->sysreset_allowed[SYSRESET_COLD] = false;
69 state->sysreset_allowed[SYSRESET_POWER] = true;
73 DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);