2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-05-12 18:03:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sysreset.h>
|
|
|
|
#include <asm/state.h>
|
|
|
|
#include <asm/test.h>
|
|
|
|
|
|
|
|
static int sandbox_warm_sysreset_request(struct udevice *dev,
|
|
|
|
enum sysreset_t type)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYSRESET_WARM:
|
|
|
|
state->last_sysreset = type;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
if (!state->sysreset_allowed[type])
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
2018-08-06 08:23:33 +00:00
|
|
|
int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size)
|
|
|
|
{
|
|
|
|
strlcpy(buf, "Reset Status: WARM", size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-01 18:22:46 +00:00
|
|
|
int sandbox_warm_sysreset_get_last(struct udevice *dev)
|
|
|
|
{
|
|
|
|
return SYSRESET_WARM;
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
|
|
|
|
{
|
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a device tree, the device we created from platform data
|
|
|
|
* (see the U_BOOT_DEVICE() declaration below) should not do anything.
|
|
|
|
* If we are that device, return an error.
|
|
|
|
*/
|
2017-05-19 02:09:59 +00:00
|
|
|
if (state->fdt_fname && !dev_of_valid(dev))
|
2016-05-12 18:03:35 +00:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYSRESET_COLD:
|
|
|
|
state->last_sysreset = type;
|
|
|
|
break;
|
2019-05-16 21:48:41 +00:00
|
|
|
case SYSRESET_POWER_OFF:
|
2016-05-12 18:03:35 +00:00
|
|
|
state->last_sysreset = type;
|
|
|
|
if (!state->sysreset_allowed[type])
|
|
|
|
return -EACCES;
|
|
|
|
sandbox_exit();
|
|
|
|
break;
|
2019-05-16 21:48:41 +00:00
|
|
|
case SYSRESET_POWER:
|
2018-10-01 18:22:46 +00:00
|
|
|
if (!state->sysreset_allowed[type])
|
|
|
|
return -EACCES;
|
2019-05-18 17:59:43 +00:00
|
|
|
sandbox_exit();
|
2016-05-12 18:03:35 +00:00
|
|
|
default:
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
if (!state->sysreset_allowed[type])
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
return -EINPROGRESS;
|
|
|
|
}
|
|
|
|
|
2018-08-06 08:23:33 +00:00
|
|
|
int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
|
|
|
|
{
|
|
|
|
strlcpy(buf, "Reset Status: COLD", size);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-01 18:22:46 +00:00
|
|
|
int sandbox_sysreset_get_last(struct udevice *dev)
|
|
|
|
{
|
2018-11-24 04:29:28 +00:00
|
|
|
struct sandbox_state *state = state_get_current();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The first phase is a power reset, after that we assume we don't
|
|
|
|
* know.
|
|
|
|
*/
|
|
|
|
return state->jumped_fname ? SYSRESET_WARM : SYSRESET_POWER;
|
2018-10-01 18:22:46 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
static struct sysreset_ops sandbox_sysreset_ops = {
|
|
|
|
.request = sandbox_sysreset_request,
|
2018-08-06 08:23:33 +00:00
|
|
|
.get_status = sandbox_sysreset_get_status,
|
2018-10-01 18:22:46 +00:00
|
|
|
.get_last = sandbox_sysreset_get_last,
|
2016-05-12 18:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id sandbox_sysreset_ids[] = {
|
|
|
|
{ .compatible = "sandbox,reset" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sysreset_sandbox) = {
|
|
|
|
.name = "sysreset_sandbox",
|
|
|
|
.id = UCLASS_SYSRESET,
|
|
|
|
.of_match = sandbox_sysreset_ids,
|
|
|
|
.ops = &sandbox_sysreset_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct sysreset_ops sandbox_warm_sysreset_ops = {
|
|
|
|
.request = sandbox_warm_sysreset_request,
|
2018-08-06 08:23:33 +00:00
|
|
|
.get_status = sandbox_warm_sysreset_get_status,
|
2018-10-01 18:22:46 +00:00
|
|
|
.get_last = sandbox_warm_sysreset_get_last,
|
2016-05-12 18:03:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id sandbox_warm_sysreset_ids[] = {
|
|
|
|
{ .compatible = "sandbox,warm-reset" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(warm_sysreset_sandbox) = {
|
|
|
|
.name = "warm_sysreset_sandbox",
|
|
|
|
.id = UCLASS_SYSRESET,
|
|
|
|
.of_match = sandbox_warm_sysreset_ids,
|
|
|
|
.ops = &sandbox_warm_sysreset_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is here in case we don't have a device tree */
|
|
|
|
U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
|
|
|
|
.name = "sysreset_sandbox",
|
|
|
|
};
|