summaryrefslogtreecommitdiff
path: root/drivers/sysreset
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2018-10-01 12:22:46 -0600
committerSimon Glass <sjg@chromium.org>2018-10-09 04:40:27 -0600
commit751fed426f87204517df14de76762461cd2a4203 (patch)
tree97843e594f8276674c09d73665fe376bba040ae3 /drivers/sysreset
parenteb517315a67320e770cf4a100a922e8ae18fa54e (diff)
downloadu-boot-751fed426f87204517df14de76762461cd2a4203.tar.gz
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>
Diffstat (limited to 'drivers/sysreset')
-rw-r--r--drivers/sysreset/sysreset-uclass.c30
-rw-r--r--drivers/sysreset/sysreset_sandbox.c15
2 files changed, 45 insertions, 0 deletions
diff --git a/drivers/sysreset/sysreset-uclass.c b/drivers/sysreset/sysreset-uclass.c
index e38814b3ed..ad831c703a 100644
--- a/drivers/sysreset/sysreset-uclass.c
+++ b/drivers/sysreset/sysreset-uclass.c
@@ -36,6 +36,16 @@ int sysreset_get_status(struct udevice *dev, char *buf, int size)
return ops->get_status(dev, buf, size);
}
+int sysreset_get_last(struct udevice *dev)
+{
+ struct sysreset_ops *ops = sysreset_get_ops(dev);
+
+ if (!ops->get_last)
+ return -ENOSYS;
+
+ return ops->get_last(dev);
+}
+
int sysreset_walk(enum sysreset_t type)
{
struct udevice *dev;
@@ -55,6 +65,26 @@ int sysreset_walk(enum sysreset_t type)
return ret;
}
+int sysreset_get_last_walk(void)
+{
+ struct udevice *dev;
+ int value = -ENOENT;
+
+ for (uclass_first_device(UCLASS_SYSRESET, &dev);
+ dev;
+ uclass_next_device(&dev)) {
+ int ret;
+
+ ret = sysreset_get_last(dev);
+ if (ret >= 0) {
+ value = ret;
+ break;
+ }
+ }
+
+ return value;
+}
+
void sysreset_walk_halt(enum sysreset_t type)
{
int ret;
diff --git a/drivers/sysreset/sysreset_sandbox.c b/drivers/sysreset/sysreset_sandbox.c
index 75004d9f77..7f6d4186e1 100644
--- a/drivers/sysreset/sysreset_sandbox.c
+++ b/drivers/sysreset/sysreset_sandbox.c
@@ -36,6 +36,11 @@ int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size)
return 0;
}
+int sandbox_warm_sysreset_get_last(struct udevice *dev)
+{
+ return SYSRESET_WARM;
+}
+
static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
{
struct sandbox_state *state = state_get_current();
@@ -58,6 +63,9 @@ static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
return -EACCES;
sandbox_exit();
break;
+ case SYSRESET_POWER_OFF:
+ if (!state->sysreset_allowed[type])
+ return -EACCES;
default:
return -ENOSYS;
}
@@ -74,9 +82,15 @@ int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
return 0;
}
+int sandbox_sysreset_get_last(struct udevice *dev)
+{
+ return SYSRESET_COLD;
+}
+
static struct sysreset_ops sandbox_sysreset_ops = {
.request = sandbox_sysreset_request,
.get_status = sandbox_sysreset_get_status,
+ .get_last = sandbox_sysreset_get_last,
};
static const struct udevice_id sandbox_sysreset_ids[] = {
@@ -94,6 +108,7 @@ U_BOOT_DRIVER(sysreset_sandbox) = {
static struct sysreset_ops sandbox_warm_sysreset_ops = {
.request = sandbox_warm_sysreset_request,
.get_status = sandbox_warm_sysreset_get_status,
+ .get_last = sandbox_warm_sysreset_get_last,
};
static const struct udevice_id sandbox_warm_sysreset_ids[] = {