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; |
| 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 | { |
| 26 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 27 | |
| 28 | if (reset_ctl->id >= SANDBOX_RESET_SIGNALS) |
| 29 | return -EINVAL; |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static int sandbox_reset_free(struct reset_ctl *reset_ctl) |
| 35 | { |
| 36 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | static int sandbox_reset_assert(struct reset_ctl *reset_ctl) |
| 42 | { |
| 43 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 44 | |
| 45 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 46 | |
| 47 | sbr->signals[reset_ctl->id].asserted = true; |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
| 52 | static int sandbox_reset_deassert(struct reset_ctl *reset_ctl) |
| 53 | { |
| 54 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
| 55 | |
| 56 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
| 57 | |
| 58 | sbr->signals[reset_ctl->id].asserted = false; |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int sandbox_reset_bind(struct udevice *dev) |
| 64 | { |
| 65 | debug("%s(dev=%p)\n", __func__, dev); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | static int sandbox_reset_probe(struct udevice *dev) |
| 71 | { |
| 72 | debug("%s(dev=%p)\n", __func__, dev); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static const struct udevice_id sandbox_reset_ids[] = { |
| 78 | { .compatible = "sandbox,reset-ctl" }, |
| 79 | { } |
| 80 | }; |
| 81 | |
| 82 | struct reset_ops sandbox_reset_reset_ops = { |
| 83 | .request = sandbox_reset_request, |
Simon Glass | 1928cd4 | 2020-02-03 07:35:52 -0700 | [diff] [blame] | 84 | .rfree = sandbox_reset_free, |
Stephen Warren | 6488e64 | 2016-06-17 09:43:59 -0600 | [diff] [blame] | 85 | .rst_assert = sandbox_reset_assert, |
| 86 | .rst_deassert = sandbox_reset_deassert, |
| 87 | }; |
| 88 | |
| 89 | U_BOOT_DRIVER(sandbox_reset) = { |
| 90 | .name = "sandbox_reset", |
| 91 | .id = UCLASS_RESET, |
| 92 | .of_match = sandbox_reset_ids, |
| 93 | .bind = sandbox_reset_bind, |
| 94 | .probe = sandbox_reset_probe, |
| 95 | .priv_auto_alloc_size = sizeof(struct sandbox_reset), |
| 96 | .ops = &sandbox_reset_reset_ops, |
| 97 | }; |
| 98 | |
| 99 | int sandbox_reset_query(struct udevice *dev, unsigned long id) |
| 100 | { |
| 101 | struct sandbox_reset *sbr = dev_get_priv(dev); |
| 102 | |
| 103 | debug("%s(dev=%p, id=%ld)\n", __func__, dev, id); |
| 104 | |
| 105 | if (id >= SANDBOX_RESET_SIGNALS) |
| 106 | return -EINVAL; |
| 107 | |
| 108 | return sbr->signals[id].asserted; |
| 109 | } |