blob: f12c4e841989f6f84461a434170be1539c8fa012 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephen Warren859f2562016-05-12 12:03:35 -06002/*
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Stephen Warren859f2562016-05-12 12:03:35 -06005 */
6
7#include <common.h>
8#include <dm.h>
9#include <errno.h>
10#include <sysreset.h>
11#include <asm/state.h>
12#include <asm/test.h>
13
Stephen Warren859f2562016-05-12 12:03:35 -060014static int sandbox_warm_sysreset_request(struct udevice *dev,
15 enum sysreset_t type)
16{
17 struct sandbox_state *state = state_get_current();
18
19 switch (type) {
20 case SYSRESET_WARM:
21 state->last_sysreset = type;
22 break;
23 default:
24 return -ENOSYS;
25 }
26 if (!state->sysreset_allowed[type])
27 return -EACCES;
28
29 return -EINPROGRESS;
30}
31
32static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type)
33{
34 struct sandbox_state *state = state_get_current();
35
36 /*
37 * If we have a device tree, the device we created from platform data
38 * (see the U_BOOT_DEVICE() declaration below) should not do anything.
39 * If we are that device, return an error.
40 */
Simon Glass177520f2017-05-18 20:09:59 -060041 if (state->fdt_fname && !dev_of_valid(dev))
Stephen Warren859f2562016-05-12 12:03:35 -060042 return -ENODEV;
43
44 switch (type) {
45 case SYSRESET_COLD:
46 state->last_sysreset = type;
47 break;
48 case SYSRESET_POWER:
49 state->last_sysreset = type;
50 if (!state->sysreset_allowed[type])
51 return -EACCES;
52 sandbox_exit();
53 break;
54 default:
55 return -ENOSYS;
56 }
57 if (!state->sysreset_allowed[type])
58 return -EACCES;
59
60 return -EINPROGRESS;
61}
62
63static struct sysreset_ops sandbox_sysreset_ops = {
64 .request = sandbox_sysreset_request,
65};
66
67static const struct udevice_id sandbox_sysreset_ids[] = {
68 { .compatible = "sandbox,reset" },
69 { }
70};
71
72U_BOOT_DRIVER(sysreset_sandbox) = {
73 .name = "sysreset_sandbox",
74 .id = UCLASS_SYSRESET,
75 .of_match = sandbox_sysreset_ids,
76 .ops = &sandbox_sysreset_ops,
77};
78
79static struct sysreset_ops sandbox_warm_sysreset_ops = {
80 .request = sandbox_warm_sysreset_request,
81};
82
83static const struct udevice_id sandbox_warm_sysreset_ids[] = {
84 { .compatible = "sandbox,warm-reset" },
85 { }
86};
87
88U_BOOT_DRIVER(warm_sysreset_sandbox) = {
89 .name = "warm_sysreset_sandbox",
90 .id = UCLASS_SYSRESET,
91 .of_match = sandbox_warm_sysreset_ids,
92 .ops = &sandbox_warm_sysreset_ops,
93};
94
95/* This is here in case we don't have a device tree */
96U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = {
97 .name = "sysreset_sandbox",
98};