]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0 |
4581b717 SW |
2 | /* |
3 | * Copyright (c) 2016, NVIDIA CORPORATION. | |
4581b717 SW |
4 | */ |
5 | ||
d678a59d | 6 | #include <common.h> |
4581b717 | 7 | #include <dm.h> |
f7ae49fc | 8 | #include <log.h> |
336d4615 | 9 | #include <malloc.h> |
4581b717 SW |
10 | #include <reset-uclass.h> |
11 | #include <asm/io.h> | |
12 | #include <asm/reset.h> | |
13 | ||
91f5f8b7 | 14 | #define SANDBOX_RESET_SIGNALS 101 |
4581b717 SW |
15 | |
16 | struct sandbox_reset_signal { | |
17 | bool asserted; | |
bad24331 | 18 | bool requested; |
4581b717 SW |
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 | { | |
bad24331 JJH |
27 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
28 | ||
4581b717 SW |
29 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
30 | ||
31 | if (reset_ctl->id >= SANDBOX_RESET_SIGNALS) | |
32 | return -EINVAL; | |
33 | ||
bad24331 | 34 | sbr->signals[reset_ctl->id].requested = true; |
4581b717 SW |
35 | return 0; |
36 | } | |
37 | ||
38 | static int sandbox_reset_free(struct reset_ctl *reset_ctl) | |
39 | { | |
bad24331 JJH |
40 | struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev); |
41 | ||
4581b717 SW |
42 | debug("%s(reset_ctl=%p)\n", __func__, reset_ctl); |
43 | ||
bad24331 | 44 | sbr->signals[reset_ctl->id].requested = false; |
4581b717 SW |
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, | |
94474b25 | 91 | .rfree = sandbox_reset_free, |
4581b717 SW |
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, | |
41575d8e | 102 | .priv_auto = sizeof(struct sandbox_reset), |
4581b717 SW |
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 | } | |
bad24331 JJH |
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 | } |