1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
11 #include <asm/state.h>
14 static int sandbox_warm_sysreset_request(struct udevice *dev,
17 struct sandbox_state *state = state_get_current();
21 state->last_sysreset = type;
26 if (!state->sysreset_allowed[type])
32 int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size)
34 strlcpy(buf, "Reset Status: WARM", size);
39 int sandbox_warm_sysreset_get_last(struct udevice *dev)
44 static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
46 struct sandbox_state *state = state_get_current();
49 * If we have a device tree, the device we created from platform data
50 * (see the U_BOOT_DRVINFO() declaration below) should not do anything.
51 * If we are that device, return an error.
53 if (state->fdt_fname && !dev_has_ofnode(dev))
58 state->last_sysreset = type;
59 if (!state->sysreset_allowed[type])
63 case SYSRESET_POWER_OFF:
64 state->last_sysreset = type;
65 if (!state->sysreset_allowed[type])
70 if (!state->sysreset_allowed[type])
76 if (!state->sysreset_allowed[type])
82 int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size)
84 strlcpy(buf, "Reset Status: COLD", size);
89 int sandbox_sysreset_get_last(struct udevice *dev)
91 struct sandbox_state *state = state_get_current();
94 * The first phase is a power reset, after that we assume we don't
97 return state->jumped_fname ? SYSRESET_WARM : SYSRESET_POWER;
100 static struct sysreset_ops sandbox_sysreset_ops = {
101 .request = sandbox_sysreset_request,
102 .get_status = sandbox_sysreset_get_status,
103 .get_last = sandbox_sysreset_get_last,
106 static const struct udevice_id sandbox_sysreset_ids[] = {
107 { .compatible = "sandbox,reset" },
111 U_BOOT_DRIVER(sysreset_sandbox) = {
112 .name = "sysreset_sandbox",
113 .id = UCLASS_SYSRESET,
114 .of_match = sandbox_sysreset_ids,
115 .ops = &sandbox_sysreset_ops,
118 static struct sysreset_ops sandbox_warm_sysreset_ops = {
119 .request = sandbox_warm_sysreset_request,
120 .get_status = sandbox_warm_sysreset_get_status,
121 .get_last = sandbox_warm_sysreset_get_last,
124 static const struct udevice_id sandbox_warm_sysreset_ids[] = {
125 { .compatible = "sandbox,warm-reset" },
129 U_BOOT_DRIVER(warm_sysreset_sandbox) = {
130 .name = "warm_sysreset_sandbox",
131 .id = UCLASS_SYSRESET,
132 .of_match = sandbox_warm_sysreset_ids,
133 .ops = &sandbox_warm_sysreset_ops,
136 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
137 /* This is here in case we don't have a device tree */
138 U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = {
139 .name = "sysreset_sandbox",