Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 5 | */ |
| 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 Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 14 | static 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 | |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 32 | int sandbox_warm_sysreset_get_status(struct udevice *dev, char *buf, int size) |
| 33 | { |
| 34 | strlcpy(buf, "Reset Status: WARM", size); |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 39 | int sandbox_warm_sysreset_get_last(struct udevice *dev) |
| 40 | { |
| 41 | return SYSRESET_WARM; |
| 42 | } |
| 43 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 44 | static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 45 | { |
| 46 | struct sandbox_state *state = state_get_current(); |
| 47 | |
| 48 | /* |
| 49 | * If we have a device tree, the device we created from platform data |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 50 | * (see the U_BOOT_DRVINFO() declaration below) should not do anything. |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 51 | * If we are that device, return an error. |
| 52 | */ |
Simon Glass | f1d50f7 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 53 | if (state->fdt_fname && !dev_has_ofnode(dev)) |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 54 | return -ENODEV; |
| 55 | |
| 56 | switch (type) { |
| 57 | case SYSRESET_COLD: |
| 58 | state->last_sysreset = type; |
Heinrich Schuchardt | 1c67844 | 2020-10-27 20:29:25 +0100 | [diff] [blame] | 59 | if (!state->sysreset_allowed[type]) |
| 60 | return -EACCES; |
| 61 | sandbox_reset(); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 62 | break; |
Urja Rannikko | 25394e7 | 2019-05-16 21:48:41 +0000 | [diff] [blame] | 63 | case SYSRESET_POWER_OFF: |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 64 | state->last_sysreset = type; |
| 65 | if (!state->sysreset_allowed[type]) |
| 66 | return -EACCES; |
| 67 | sandbox_exit(); |
Urja Rannikko | 25394e7 | 2019-05-16 21:48:41 +0000 | [diff] [blame] | 68 | case SYSRESET_POWER: |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 69 | if (!state->sysreset_allowed[type]) |
| 70 | return -EACCES; |
Simon Glass | 2fe5b91 | 2019-05-18 11:59:43 -0600 | [diff] [blame] | 71 | sandbox_exit(); |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 72 | default: |
| 73 | return -ENOSYS; |
| 74 | } |
| 75 | if (!state->sysreset_allowed[type]) |
| 76 | return -EACCES; |
| 77 | |
| 78 | return -EINPROGRESS; |
| 79 | } |
| 80 | |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 81 | int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size) |
| 82 | { |
| 83 | strlcpy(buf, "Reset Status: COLD", size); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 88 | int sandbox_sysreset_get_last(struct udevice *dev) |
| 89 | { |
Simon Glass | 7e4d49c | 2018-11-23 21:29:28 -0700 | [diff] [blame] | 90 | struct sandbox_state *state = state_get_current(); |
| 91 | |
| 92 | /* |
| 93 | * The first phase is a power reset, after that we assume we don't |
| 94 | * know. |
| 95 | */ |
| 96 | return state->jumped_fname ? SYSRESET_WARM : SYSRESET_POWER; |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 97 | } |
| 98 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 99 | static struct sysreset_ops sandbox_sysreset_ops = { |
| 100 | .request = sandbox_sysreset_request, |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 101 | .get_status = sandbox_sysreset_get_status, |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 102 | .get_last = sandbox_sysreset_get_last, |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | static const struct udevice_id sandbox_sysreset_ids[] = { |
| 106 | { .compatible = "sandbox,reset" }, |
| 107 | { } |
| 108 | }; |
| 109 | |
| 110 | U_BOOT_DRIVER(sysreset_sandbox) = { |
| 111 | .name = "sysreset_sandbox", |
| 112 | .id = UCLASS_SYSRESET, |
| 113 | .of_match = sandbox_sysreset_ids, |
| 114 | .ops = &sandbox_sysreset_ops, |
| 115 | }; |
| 116 | |
| 117 | static struct sysreset_ops sandbox_warm_sysreset_ops = { |
| 118 | .request = sandbox_warm_sysreset_request, |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame] | 119 | .get_status = sandbox_warm_sysreset_get_status, |
Simon Glass | 07fbba5 | 2018-10-01 12:22:46 -0600 | [diff] [blame] | 120 | .get_last = sandbox_warm_sysreset_get_last, |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static const struct udevice_id sandbox_warm_sysreset_ids[] = { |
| 124 | { .compatible = "sandbox,warm-reset" }, |
| 125 | { } |
| 126 | }; |
| 127 | |
| 128 | U_BOOT_DRIVER(warm_sysreset_sandbox) = { |
| 129 | .name = "warm_sysreset_sandbox", |
| 130 | .id = UCLASS_SYSRESET, |
| 131 | .of_match = sandbox_warm_sysreset_ids, |
| 132 | .ops = &sandbox_warm_sysreset_ops, |
| 133 | }; |
| 134 | |
Simon Glass | 9288265 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 135 | #if CONFIG_IS_ENABLED(OF_REAL) |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 136 | /* This is here in case we don't have a device tree */ |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 137 | U_BOOT_DRVINFO(sysreset_sandbox_non_fdt) = { |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 138 | .name = "sysreset_sandbox", |
| 139 | }; |
Simon Glass | cb90bd3 | 2020-10-03 11:31:23 -0600 | [diff] [blame] | 140 | #endif |