Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <sysreset.h> |
| 8 | #include <asm/state.h> |
| 9 | #include <asm/test.h> |
| 10 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 11 | #include <test/test.h> |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 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)); |
Paul Barker | bdb3a3f | 2023-11-08 08:51:10 +0000 | [diff] [blame] | 29 | ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_COLD)); |
| 30 | ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_POWER)); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 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)); |
Paul Barker | bdb3a3f | 2023-11-08 08:51:10 +0000 | [diff] [blame] | 38 | ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_WARM)); |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 39 | state->sysreset_allowed[SYSRESET_COLD] = false; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 40 | ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD)); |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 41 | state->sysreset_allowed[SYSRESET_COLD] = true; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 42 | state->sysreset_allowed[SYSRESET_POWER] = false; |
| 43 | ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER)); |
| 44 | state->sysreset_allowed[SYSRESET_POWER] = true; |
| 45 | |
| 46 | return 0; |
| 47 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 48 | DM_TEST(dm_test_sysreset_base, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 49 | |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 50 | static int dm_test_sysreset_get_status(struct unit_test_state *uts) |
| 51 | { |
| 52 | struct udevice *dev; |
| 53 | char msg[64]; |
| 54 | |
| 55 | /* Device 1 is the warm sysreset device */ |
| 56 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); |
| 57 | ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); |
| 58 | ut_asserteq_str("Reset Status: WARM", msg); |
| 59 | |
| 60 | /* Device 2 is the cold sysreset device */ |
| 61 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); |
| 62 | ut_assertok(sysreset_get_status(dev, msg, sizeof(msg))); |
| 63 | ut_asserteq_str("Reset Status: COLD", msg); |
| 64 | |
| 65 | return 0; |
| 66 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 67 | DM_TEST(dm_test_sysreset_get_status, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 68 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 69 | /* Test that we can walk through the sysreset devices */ |
| 70 | static int dm_test_sysreset_walk(struct unit_test_state *uts) |
| 71 | { |
| 72 | struct sandbox_state *state = state_get_current(); |
| 73 | |
| 74 | /* If we generate a power sysreset, we will exit sandbox! */ |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 75 | state->sysreset_allowed[SYSRESET_WARM] = false; |
| 76 | state->sysreset_allowed[SYSRESET_COLD] = false; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 77 | state->sysreset_allowed[SYSRESET_POWER] = false; |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 78 | state->sysreset_allowed[SYSRESET_POWER_OFF] = false; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 79 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM)); |
| 80 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); |
| 81 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 82 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER_OFF)); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 83 | |
| 84 | /* |
| 85 | * Enable cold system reset - this should make cold system reset work, |
| 86 | * plus a warm system reset should be promoted to cold, since this is |
| 87 | * the next step along. |
| 88 | */ |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 89 | state->sysreset_allowed[SYSRESET_WARM] = true; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 90 | ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM)); |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 91 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD)); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 92 | ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER)); |
Heinrich Schuchardt | e7e4f2d | 2020-10-27 20:29:26 +0100 | [diff] [blame] | 93 | state->sysreset_allowed[SYSRESET_COLD] = true; |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 94 | state->sysreset_allowed[SYSRESET_POWER] = true; |
| 95 | |
| 96 | return 0; |
| 97 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 98 | DM_TEST(dm_test_sysreset_walk, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 99 | |
| 100 | static int dm_test_sysreset_get_last(struct unit_test_state *uts) |
| 101 | { |
| 102 | struct udevice *dev; |
| 103 | |
| 104 | /* Device 1 is the warm sysreset device */ |
| 105 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev)); |
| 106 | ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev)); |
| 107 | |
| 108 | /* Device 2 is the cold sysreset device */ |
| 109 | ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev)); |
Simon Glass | 7e4d49c | 2018-11-23 21:29:28 -0700 | [diff] [blame] | 110 | ut_asserteq(SYSRESET_POWER, sysreset_get_last(dev)); |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 111 | |
| 112 | /* This is device 0, the non-DT one */ |
Simon Glass | 7e4d49c | 2018-11-23 21:29:28 -0700 | [diff] [blame] | 113 | ut_asserteq(SYSRESET_POWER, sysreset_get_last_walk()); |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 114 | |
| 115 | return 0; |
| 116 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 117 | DM_TEST(dm_test_sysreset_get_last, UTF_SCAN_PDATA | UTF_SCAN_FDT); |