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