sysreset: Add a way to find the last reset

We have a method to return the last reset as a string for humans, but not
a method that allows it to be used programmatically. Add a new method that
returns the last reset as an enum.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2018-10-01 12:22:46 -06:00
parent eb517315a6
commit 751fed426f
4 changed files with 95 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
/* If we generate a power sysreset, we will exit sandbox! */
state->sysreset_allowed[SYSRESET_POWER] = false;
state->sysreset_allowed[SYSRESET_POWER_OFF] = false;
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
@@ -90,3 +91,22 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
static int dm_test_sysreset_get_last(struct unit_test_state *uts)
{
struct udevice *dev;
/* Device 1 is the warm sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
/* Device 2 is the cold sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
ut_asserteq(SYSRESET_COLD, sysreset_get_last(dev));
/* This is device 0, the non-DT one */
ut_asserteq(SYSRESET_COLD, sysreset_get_last_walk());
return 0;
}
DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);