Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 4 | */ |
| 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> |
| 12 | #include <test/ut.h> |
| 13 | |
| 14 | /* Test that we can use particular sysreset devices */ |
| 15 | static int dm_test_sysreset_base(struct unit_test_state *uts) |
| 16 | { |
| 17 | struct sandbox_state *state = state_get_current(); |
| 18 | struct udevice *dev; |
| 19 | |
| 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)); |
| 25 | |
| 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)); |
| 31 | |
| 32 | state->sysreset_allowed[SYSRESET_WARM] = true; |
| 33 | ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM)); |
| 34 | state->sysreset_allowed[SYSRESET_WARM] = false; |
| 35 | |
| 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; |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 47 | |
Mario Six | cda4688 | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 48 | static int dm_test_sysreset_get_status(struct unit_test_state *uts) |
| 49 | { |
| 50 | struct udevice *dev; |
| 51 | char msg[64]; |
| 52 | |
| 53 | /* Device 1 is the warm sysreset device */ |
| 54 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); |
| 55 | ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); |
| 56 | ut_asserteq_str("Reset Status: WARM", msg); |
| 57 | |
| 58 | /* Device 2 is the cold sysreset device */ |
| 59 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); |
| 60 | ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); |
| 61 | ut_asserteq_str("Reset Status: COLD", msg); |
| 62 | |
| 63 | return 0; |
| 64 | } |
Mario Six | cda4688 | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 65 | DM_TEST(dm_test_sysreset_get_status, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
| 66 | |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 67 | /* Test that we can walk through the sysreset devices */ |
| 68 | static int dm_test_sysreset_walk(struct unit_test_state *uts) |
| 69 | { |
| 70 | struct sandbox_state *state = state_get_current(); |
| 71 | |
| 72 | /* If we generate a power sysreset, we will exit sandbox! */ |
| 73 | state->sysreset_allowed[SYSRESET_POWER] = false; |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 74 | state->sysreset_allowed[SYSRESET_POWER_OFF] = false; |
Stephen Warren | 1163625 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 75 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM)); |
| 76 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); |
| 77 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
| 78 | |
| 79 | /* |
| 80 | * Enable cold system reset - this should make cold system reset work, |
| 81 | * plus a warm system reset should be promoted to cold, since this is |
| 82 | * the next step along. |
| 83 | */ |
| 84 | state->sysreset_allowed[SYSRESET_COLD] = true; |
| 85 | ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM)); |
| 86 | ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_COLD)); |
| 87 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
| 88 | state->sysreset_allowed[SYSRESET_COLD] = false; |
| 89 | state->sysreset_allowed[SYSRESET_POWER] = true; |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 94 | |
| 95 | static int dm_test_sysreset_get_last(struct unit_test_state *uts) |
| 96 | { |
| 97 | struct udevice *dev; |
| 98 | |
| 99 | /* Device 1 is the warm sysreset device */ |
| 100 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); |
| 101 | ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev)); |
| 102 | |
| 103 | /* Device 2 is the cold sysreset device */ |
| 104 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); |
Simon Glass | 2a07269 | 2018-11-23 21:29:28 -0700 | [diff] [blame] | 105 | ut_asserteq(SYSRESET_POWER, sysreset_get_last(dev)); |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 106 | |
| 107 | /* This is device 0, the non-DT one */ |
Simon Glass | 2a07269 | 2018-11-23 21:29:28 -0700 | [diff] [blame] | 108 | ut_asserteq(SYSRESET_POWER, sysreset_get_last_walk()); |
Simon Glass | 751fed4 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |