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