blob: 3cc61ede2a09503c6bc0859b24eb761e21f9ec6d [file] [log] [blame]
Simon Glassb9d33fa2015-07-06 12:54:28 -06001/*
2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <errno.h>
11#include <reset.h>
12#include <asm/state.h>
13#include <asm/test.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17static int sandbox_warm_reset_request(struct udevice *dev, enum reset_t type)
18{
19 struct sandbox_state *state = state_get_current();
20
21 switch (type) {
22 case RESET_WARM:
23 state->last_reset = type;
24 break;
25 default:
26 return -ENOSYS;
27 }
28 if (!state->reset_allowed[type])
29 return -EACCES;
30
31 return -EINPROGRESS;
32}
33
34static int sandbox_reset_request(struct udevice *dev, enum reset_t type)
35{
36 struct sandbox_state *state = state_get_current();
37
38 /*
39 * If we have a device tree, the device we created from platform data
40 * (see the U_BOOT_DEVICE() declaration below) should not do anything.
41 * If we are that device, return an error.
42 */
43 if (gd->fdt_blob && dev->of_offset == -1)
44 return -ENODEV;
45
46 switch (type) {
47 case RESET_COLD:
48 state->last_reset = type;
49 break;
50 case RESET_POWER:
51 state->last_reset = type;
52 if (!state->reset_allowed[type])
53 return -EACCES;
54 /* TODO: sandbox_exit(); */
55 break;
56 default:
57 return -ENOSYS;
58 }
59 if (!state->reset_allowed[type])
60 return -EACCES;
61
62 return -EINPROGRESS;
63}
64
65static struct reset_ops sandbox_reset_ops = {
66 .request = sandbox_reset_request,
67};
68
69static const struct udevice_id sandbox_reset_ids[] = {
70 { .compatible = "sandbox,reset" },
71 { }
72};
73
74U_BOOT_DRIVER(reset_sandbox) = {
75 .name = "reset_sandbox",
76 .id = UCLASS_RESET,
77 .of_match = sandbox_reset_ids,
78 .ops = &sandbox_reset_ops,
79};
80
81static struct reset_ops sandbox_warm_reset_ops = {
82 .request = sandbox_warm_reset_request,
83};
84
85static const struct udevice_id sandbox_warm_reset_ids[] = {
86 { .compatible = "sandbox,warm-reset" },
87 { }
88};
89
90U_BOOT_DRIVER(warm_reset_sandbox) = {
91 .name = "warm_reset_sandbox",
92 .id = UCLASS_RESET,
93 .of_match = sandbox_warm_reset_ids,
94 .ops = &sandbox_warm_reset_ops,
95};
96
97/* This is here in case we don't have a device tree */
98U_BOOT_DEVICE(reset_sandbox_non_fdt) = {
99 .name = "reset_sandbox",
100};