Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.h> |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 10 | #include <reset-uclass.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/reset.h> |
| 13 | |
Neil Armstrong | 20c633d | 2018-04-03 11:40:51 +0200 | [diff] [blame] | 14 | #define SANDBOX_RESET_SIGNALS 101 |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 15 | |
| 16 | struct sandbox_reset_signal { |
| 17 | bool asserted; |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 18 | bool requested; |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | struct sandbox_reset { |
| 22 | struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS]; |
| 23 | }; |
| 24 | |
| 25 | static int sandbox_reset_request(struct reset_ctl *reset_ctl) |
| 26 | { |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 27 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 28 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 29 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 30 | |
| 31 | if (reset_ctl->id >= SANDBOX_RESET_SIGNALS) |
| 32 | return -EINVAL; |
| 33 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 34 | sbr->signals[reset_ctl->id].requested = true; |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int sandbox_reset_free(struct reset_ctl *reset_ctl) |
| 39 | { |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 40 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 41 | |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 42 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 43 | |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 44 | sbr->signals[reset_ctl->id].requested = false; |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static int sandbox_reset_assert(struct reset_ctl *reset_ctl) |
| 49 | { |
| 50 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 51 | |
| 52 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 53 | |
| 54 | sbr->signals[reset_ctl->id].asserted = true; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static int sandbox_reset_deassert(struct reset_ctl *reset_ctl) |
| 60 | { |
| 61 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 62 | |
| 63 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 64 | |
| 65 | sbr->signals[reset_ctl->id].asserted = false; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int sandbox_reset_bind(struct udevice *dev) |
| 71 | { |
| 72 | debug("%s(dev=%p)\n", __func__, dev); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static int sandbox_reset_probe(struct udevice *dev) |
| 78 | { |
| 79 | debug("%s(dev=%p)\n", __func__, dev); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | static const struct udevice_id sandbox_reset_ids[] = { |
| 85 | { .compatible = "sandbox,reset-ctl" }, |
| 86 | { } |
| 87 | }; |
| 88 | |
| 89 | struct reset_ops sandbox_reset_reset_ops = { |
| 90 | .request = sandbox_reset_request, |
Simon Glass | 1928cd4 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 91 | .rfree = sandbox_reset_free, |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 92 | .rst_assert = sandbox_reset_assert, |
| 93 | .rst_deassert = sandbox_reset_deassert, |
| 94 | }; |
| 95 | |
| 96 | U_BOOT_DRIVER(sandbox_reset) = { |
| 97 | .name = "sandbox_reset", |
| 98 | .id = UCLASS_RESET, |
| 99 | .of_match = sandbox_reset_ids, |
| 100 | .bind = sandbox_reset_bind, |
| 101 | .probe = sandbox_reset_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 102 | .priv_auto = sizeof(struct sandbox_reset), |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 103 | .ops = &sandbox_reset_reset_ops, |
| 104 | }; |
| 105 | |
| 106 | int sandbox_reset_query(struct udevice *dev, unsigned long id) |
| 107 | { |
| 108 | struct sandbox_reset *sbr = dev_get_priv(dev); |
| 109 | |
| 110 | debug("%s(dev=%p, id=%ld)\n", __func__, dev, id); |
| 111 | |
| 112 | if (id >= SANDBOX_RESET_SIGNALS) |
| 113 | return -EINVAL; |
| 114 | |
| 115 | return sbr->signals[id].asserted; |
| 116 | } |
Jean-Jacques Hiblot | 880c5c7 | 2020-09-09 15:37:04 +0530 | [diff] [blame] | 117 | |
| 118 | int sandbox_reset_is_requested(struct udevice *dev, unsigned long id) |
| 119 | { |
| 120 | struct sandbox_reset *sbr = dev_get_priv(dev); |
| 121 | |
| 122 | debug("%s(dev=%p, id=%ld)\n", __func__, dev, id); |
| 123 | |
| 124 | if (id >= SANDBOX_RESET_SIGNALS) |
| 125 | return -EINVAL; |
| 126 | |
| 127 | return sbr->signals[id].requested; |
| 128 | } |