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 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 39 | static int sandbox_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 40 | { |
| 41 | struct sandbox_state *state = state_get_current(); |
| 42 | |
| 43 | /* |
| 44 | * If we have a device tree, the device we created from platform data |
| 45 | * (see the U_BOOT_DEVICE() declaration below) should not do anything. |
| 46 | * If we are that device, return an error. |
| 47 | */ |
Simon Glass | 177520f | 2017-05-18 20:09:59 -0600 | [diff] [blame] | 48 | if (state->fdt_fname && !dev_of_valid(dev)) |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 49 | return -ENODEV; |
| 50 | |
| 51 | switch (type) { |
| 52 | case SYSRESET_COLD: |
| 53 | state->last_sysreset = type; |
| 54 | break; |
| 55 | case SYSRESET_POWER: |
| 56 | state->last_sysreset = type; |
| 57 | if (!state->sysreset_allowed[type]) |
| 58 | return -EACCES; |
| 59 | sandbox_exit(); |
| 60 | break; |
| 61 | default: |
| 62 | return -ENOSYS; |
| 63 | } |
| 64 | if (!state->sysreset_allowed[type]) |
| 65 | return -EACCES; |
| 66 | |
| 67 | return -EINPROGRESS; |
| 68 | } |
| 69 | |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame^] | 70 | int sandbox_sysreset_get_status(struct udevice *dev, char *buf, int size) |
| 71 | { |
| 72 | strlcpy(buf, "Reset Status: COLD", size); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 77 | static struct sysreset_ops sandbox_sysreset_ops = { |
| 78 | .request = sandbox_sysreset_request, |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame^] | 79 | .get_status = sandbox_sysreset_get_status, |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | static const struct udevice_id sandbox_sysreset_ids[] = { |
| 83 | { .compatible = "sandbox,reset" }, |
| 84 | { } |
| 85 | }; |
| 86 | |
| 87 | U_BOOT_DRIVER(sysreset_sandbox) = { |
| 88 | .name = "sysreset_sandbox", |
| 89 | .id = UCLASS_SYSRESET, |
| 90 | .of_match = sandbox_sysreset_ids, |
| 91 | .ops = &sandbox_sysreset_ops, |
| 92 | }; |
| 93 | |
| 94 | static struct sysreset_ops sandbox_warm_sysreset_ops = { |
| 95 | .request = sandbox_warm_sysreset_request, |
Mario Six | b6da1fb | 2018-08-06 10:23:33 +0200 | [diff] [blame^] | 96 | .get_status = sandbox_warm_sysreset_get_status, |
Stephen Warren | 859f256 | 2016-05-12 12:03:35 -0600 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | static const struct udevice_id sandbox_warm_sysreset_ids[] = { |
| 100 | { .compatible = "sandbox,warm-reset" }, |
| 101 | { } |
| 102 | }; |
| 103 | |
| 104 | U_BOOT_DRIVER(warm_sysreset_sandbox) = { |
| 105 | .name = "warm_sysreset_sandbox", |
| 106 | .id = UCLASS_SYSRESET, |
| 107 | .of_match = sandbox_warm_sysreset_ids, |
| 108 | .ops = &sandbox_warm_sysreset_ops, |
| 109 | }; |
| 110 | |
| 111 | /* This is here in case we don't have a device tree */ |
| 112 | U_BOOT_DEVICE(sysreset_sandbox_non_fdt) = { |
| 113 | .name = "sysreset_sandbox", |
| 114 | }; |