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