1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2016, NVIDIA CORPORATION.
*/
#include <dm.h>
#include <log.h>
#include <malloc.h>
#include <reset-uclass.h>
#include <asm/io.h>
#include <asm/reset.h>
#include <linux/delay.h>
#define SANDBOX_RESET_SIGNALS 101
struct sandbox_reset_signal {
bool asserted;
bool requested;
int reset_count;
};
struct sandbox_reset {
struct sandbox_reset_signal signals[SANDBOX_RESET_SIGNALS];
};
static int sandbox_reset_request(struct reset_ctl *reset_ctl)
{
struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
return -EINVAL;
sbr->signals[reset_ctl->id].requested = true;
sbr->signals[reset_ctl->id].reset_count = 0;
return 0;
}
static int sandbox_reset_free(struct reset_ctl *reset_ctl)
{
struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
sbr->signals[reset_ctl->id].requested = false;
return 0;
}
static int sandbox_reset_assert(struct reset_ctl *reset_ctl)
{
struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
sbr->signals[reset_ctl->id].asserted = true;
return 0;
}
static int sandbox_reset_deassert(struct reset_ctl *reset_ctl)
{
struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
sbr->signals[reset_ctl->id].asserted = false;
return 0;
}
static int sandbox_reset_reset(struct reset_ctl *reset_ctl, ulong delay_us)
{
struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
debug("%s(reset_ctl=%p, delay_us=%lu)\n", __func__, reset_ctl,
delay_us);
sbr->signals[reset_ctl->id].asserted = true;
udelay(delay_us);
sbr->signals[reset_ctl->id].asserted = false;
sbr->signals[reset_ctl->id].reset_count++;
return 0;
}
static int sandbox_reset_bind(struct udevice *dev)
{
debug("%s(dev=%p)\n", __func__, dev);
return 0;
}
static int sandbox_reset_probe(struct udevice *dev)
{
debug("%s(dev=%p)\n", __func__, dev);
return 0;
}
static const struct udevice_id sandbox_reset_ids[] = {
{ .compatible = "sandbox,reset-ctl" },
{ }
};
static const struct reset_ops sandbox_reset_reset_ops = {
.request = sandbox_reset_request,
.rfree = sandbox_reset_free,
.rst_assert = sandbox_reset_assert,
.rst_deassert = sandbox_reset_deassert,
.rst_reset = sandbox_reset_reset,
};
U_BOOT_DRIVER(sandbox_reset) = {
.name = "sandbox_reset",
.id = UCLASS_RESET,
.of_match = sandbox_reset_ids,
.bind = sandbox_reset_bind,
.probe = sandbox_reset_probe,
.priv_auto = sizeof(struct sandbox_reset),
.ops = &sandbox_reset_reset_ops,
};
/*
* Second sandbox reset controller for tests: same assert/deassert
* behaviour as sandbox_reset, but no rst_reset so reset_reset() uses
* the core assert / udelay / deassert fallback (reset_count never bumps).
*/
static const struct udevice_id sandbox_reset_fallback_ids[] = {
{ .compatible = "sandbox,reset-ctl-fallback-only" },
{ }
};
static const struct reset_ops sandbox_reset_fallback_reset_ops = {
.request = sandbox_reset_request,
.rfree = sandbox_reset_free,
.rst_assert = sandbox_reset_assert,
.rst_deassert = sandbox_reset_deassert,
};
U_BOOT_DRIVER(sandbox_reset_fallback) = {
.name = "sandbox_reset_fallback",
.id = UCLASS_RESET,
.of_match = sandbox_reset_fallback_ids,
.bind = sandbox_reset_bind,
.probe = sandbox_reset_probe,
.priv_auto = sizeof(struct sandbox_reset),
.ops = &sandbox_reset_fallback_reset_ops,
};
int sandbox_reset_query(struct udevice *dev, unsigned long id)
{
struct sandbox_reset *sbr = dev_get_priv(dev);
debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
if (id >= SANDBOX_RESET_SIGNALS)
return -EINVAL;
return sbr->signals[id].asserted;
}
int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
{
struct sandbox_reset *sbr = dev_get_priv(dev);
debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
if (id >= SANDBOX_RESET_SIGNALS)
return -EINVAL;
return sbr->signals[id].requested;
}
int sandbox_reset_get_count(struct udevice *dev, unsigned long id)
{
struct sandbox_reset *sbr = dev_get_priv(dev);
debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
if (id >= SANDBOX_RESET_SIGNALS)
return -EINVAL;
return sbr->signals[id].reset_count;
}
|