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