Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <sysreset.h> |
| 10 | #include <asm/state.h> |
| 11 | #include <asm/test.h> |
| 12 | #include <dm/test.h> |
| 13 | #include <test/ut.h> |
| 14 | |
| 15 | /* Test that we can use particular sysreset devices */ |
| 16 | static 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)); |
| 40 | ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD)); |
| 41 | state->sysreset_allowed[SYSRESET_POWER] = false; |
| 42 | ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER)); |
| 43 | state->sysreset_allowed[SYSRESET_POWER] = true; |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 48 | |
| 49 | /* Test that we can walk through the sysreset devices */ |
| 50 | static int dm_test_sysreset_walk(struct unit_test_state *uts) |
| 51 | { |
| 52 | struct sandbox_state *state = state_get_current(); |
| 53 | |
| 54 | /* If we generate a power sysreset, we will exit sandbox! */ |
| 55 | state->sysreset_allowed[SYSRESET_POWER] = false; |
| 56 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM)); |
| 57 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); |
| 58 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
| 59 | |
| 60 | /* |
| 61 | * Enable cold system reset - this should make cold system reset work, |
| 62 | * plus a warm system reset should be promoted to cold, since this is |
| 63 | * the next step along. |
| 64 | */ |
| 65 | state->sysreset_allowed[SYSRESET_COLD] = true; |
| 66 | ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM)); |
| 67 | ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD)); |
| 68 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
| 69 | state->sysreset_allowed[SYSRESET_COLD] = false; |
| 70 | state->sysreset_allowed[SYSRESET_POWER] = true; |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |