blob: a1a9ad5603dba2e6d6fb027471c0ffc552ad67f1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Stephen Warren185ad872016-06-17 09:43:58 -06002/*
3 * Copyright (c) 2016, NVIDIA CORPORATION.
Stephen Warren185ad872016-06-17 09:43:58 -06004 */
5
6#ifndef _RESET_H
7#define _RESET_H
8
Masahiro Yamadaaf727132016-09-21 11:29:01 +09009#include <linux/errno.h>
10
Stephen Warren185ad872016-06-17 09:43:58 -060011/**
12 * A reset is a hardware signal indicating that a HW module (or IP block, or
13 * sometimes an entire off-CPU chip) reset all of its internal state to some
14 * known-good initial state. Drivers will often reset HW modules when they
15 * begin execution to ensure that hardware correctly responds to all requests,
16 * or in response to some error condition. Reset signals are often controlled
17 * externally to the HW module being reset, by an entity this API calls a reset
18 * controller. This API provides a standard means for drivers to request that
19 * reset controllers set or clear reset signals.
20 *
21 * A driver that implements UCLASS_RESET is a reset controller or provider. A
22 * controller will often implement multiple separate reset signals, since the
23 * hardware it manages often has this capability. reset-uclass.h describes the
24 * interface which reset controllers must implement.
25 *
26 * Reset consumers/clients are the HW modules affected by reset signals. This
27 * header file describes the API used by drivers for those HW modules.
28 */
29
30struct udevice;
31
32/**
33 * struct reset_ctl - A handle to (allowing control of) a single reset signal.
34 *
35 * Clients provide storage for reset control handles. The content of the
36 * structure is managed solely by the reset API and reset drivers. A reset
37 * control struct is initialized by "get"ing the reset control struct. The
38 * reset control struct is passed to all other reset APIs to identify which
39 * reset signal to operate upon.
40 *
41 * @dev: The device which implements the reset signal.
42 * @id: The reset signal ID within the provider.
Andreas Dannenbergc82550f2018-08-27 15:57:40 +053043 * @data: An optional data field for scenarios where a single integer ID is not
44 * sufficient. If used, it can be populated through an .of_xlate op and
45 * processed during the various reset ops.
Shawn Guo9aec3cd2019-03-20 15:32:38 +080046 * @polarity: An optional polarity field for drivers that support
47 * different reset polarities.
Stephen Warren185ad872016-06-17 09:43:58 -060048 *
Andreas Dannenbergc82550f2018-08-27 15:57:40 +053049 * Should additional information to identify and configure any reset signal
50 * for any provider be required in the future, the struct could be expanded to
Stephen Warren185ad872016-06-17 09:43:58 -060051 * either (a) add more fields to allow reset providers to store additional
52 * information, or (b) replace the id field with an opaque pointer, which the
53 * provider would dynamically allocated during its .of_xlate op, and process
54 * during is .request op. This may require the addition of an extra op to clean
55 * up the allocation.
56 */
57struct reset_ctl {
58 struct udevice *dev;
59 /*
Andreas Dannenbergc82550f2018-08-27 15:57:40 +053060 * Written by of_xlate. In the future, we might add more fields here.
Stephen Warren185ad872016-06-17 09:43:58 -060061 */
62 unsigned long id;
Andreas Dannenbergc82550f2018-08-27 15:57:40 +053063 unsigned long data;
Shawn Guo9aec3cd2019-03-20 15:32:38 +080064 unsigned long polarity;
Stephen Warren185ad872016-06-17 09:43:58 -060065};
66
Neil Armstrongdbb26d32018-04-03 11:40:50 +020067/**
68 * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset
69 * signals.
70 *
71 * Clients provide storage for the reset control bulk. The content of the
72 * structure is managed solely by the reset API. A reset control bulk struct is
73 * initialized by "get"ing the reset control bulk struct.
74 * The reset control bulk struct is passed to all other bulk reset APIs to apply
75 * the API to all the reset signals in the bulk struct.
76 *
77 * @resets: An array of reset signal handles handles.
78 * @count: The number of reset signal handles in the reset array.
79 */
80struct reset_ctl_bulk {
81 struct reset_ctl *resets;
82 unsigned int count;
83};
84
Ley Foon Tan8d7072b2018-06-14 18:45:20 +080085#if CONFIG_IS_ENABLED(DM_RESET)
Stephen Warren185ad872016-06-17 09:43:58 -060086/**
87 * reset_get_by_index - Get/request a reset signal by integer index.
88 *
89 * This looks up and requests a reset signal. The index is relative to the
90 * client device; each device is assumed to have n reset signals associated
91 * with it somehow, and this function finds and requests one of them. The
92 * mapping of client device reset signal indices to provider reset signals may
93 * be via device-tree properties, board-provided mapping tables, or some other
94 * mechanism.
95 *
96 * @dev: The client device.
97 * @index: The index of the reset signal to request, within the client's
98 * list of reset signals.
99 * @reset_ctl A pointer to a reset control struct to initialize.
100 * @return 0 if OK, or a negative error code.
101 */
102int reset_get_by_index(struct udevice *dev, int index,
103 struct reset_ctl *reset_ctl);
104
105/**
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200106 * reset_get_bulk - Get/request all reset signals of a device.
107 *
108 * This looks up and requests all reset signals of the client device; each
109 * device is assumed to have n reset signals associated with it somehow,
110 * and this function finds and requests all of them in a separate structure.
111 * The mapping of client device reset signals indices to provider reset signals
112 * may be via device-tree properties, board-provided mapping tables, or some
113 * other mechanism.
114 *
115 * @dev: The client device.
116 * @bulk A pointer to a reset control bulk struct to initialize.
117 * @return 0 if OK, or a negative error code.
118 */
119int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
120
121/**
Stephen Warren185ad872016-06-17 09:43:58 -0600122 * reset_get_by_name - Get/request a reset signal by name.
123 *
124 * This looks up and requests a reset signal. The name is relative to the
125 * client device; each device is assumed to have n reset signals associated
126 * with it somehow, and this function finds and requests one of them. The
127 * mapping of client device reset signal names to provider reset signal may be
128 * via device-tree properties, board-provided mapping tables, or some other
129 * mechanism.
130 *
131 * @dev: The client device.
132 * @name: The name of the reset signal to request, within the client's
133 * list of reset signals.
134 * @reset_ctl: A pointer to a reset control struct to initialize.
135 * @return 0 if OK, or a negative error code.
136 */
137int reset_get_by_name(struct udevice *dev, const char *name,
138 struct reset_ctl *reset_ctl);
139
140/**
Patrice Chotard76290e32017-07-18 11:57:05 +0200141 * reset_request - Request a reset signal.
142 *
143 * @reset_ctl: A reset control struct.
144 *
145 * @return 0 if OK, or a negative error code.
146 */
147int reset_request(struct reset_ctl *reset_ctl);
148
149/**
Stephen Warren185ad872016-06-17 09:43:58 -0600150 * reset_free - Free a previously requested reset signal.
151 *
152 * @reset_ctl: A reset control struct that was previously successfully
153 * requested by reset_get_by_*().
154 * @return 0 if OK, or a negative error code.
155 */
156int reset_free(struct reset_ctl *reset_ctl);
157
158/**
159 * reset_assert - Assert a reset signal.
160 *
161 * This function will assert the specified reset signal, thus resetting the
162 * affected HW module(s). Depending on the reset controller hardware, the reset
163 * signal will either stay asserted until reset_deassert() is called, or the
164 * hardware may autonomously clear the reset signal itself.
165 *
166 * @reset_ctl: A reset control struct that was previously successfully
167 * requested by reset_get_by_*().
168 * @return 0 if OK, or a negative error code.
169 */
170int reset_assert(struct reset_ctl *reset_ctl);
171
172/**
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200173 * reset_assert_bulk - Assert all reset signals in a reset control bulk struct.
174 *
175 * This function will assert the specified reset signals in a reset control
176 * bulk struct, thus resetting the affected HW module(s). Depending on the
177 * reset controller hardware, the reset signals will either stay asserted
178 * until reset_deassert_bulk() is called, or the hardware may autonomously
179 * clear the reset signals itself.
180 *
181 * @bulk: A reset control bulk struct that was previously successfully
182 * requested by reset_get_bulk().
183 * @return 0 if OK, or a negative error code.
184 */
185int reset_assert_bulk(struct reset_ctl_bulk *bulk);
186
187/**
Stephen Warren185ad872016-06-17 09:43:58 -0600188 * reset_deassert - Deassert a reset signal.
189 *
190 * This function will deassert the specified reset signal, thus releasing the
191 * affected HW modules() from reset, and allowing them to continue normal
192 * operation.
193 *
194 * @reset_ctl: A reset control struct that was previously successfully
195 * requested by reset_get_by_*().
196 * @return 0 if OK, or a negative error code.
197 */
198int reset_deassert(struct reset_ctl *reset_ctl);
199
Patrice Chotarde4d368e2017-07-18 11:57:06 +0200200/**
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200201 * reset_deassert_bulk - Deassert all reset signals in a reset control bulk
202 * struct.
203 *
204 * This function will deassert the specified reset signals in a reset control
205 * bulk struct, thus releasing the affected HW modules() from reset, and
206 * allowing them to continue normal operation.
207 *
208 * @bulk: A reset control bulk struct that was previously successfully
209 * requested by reset_get_bulk().
210 * @return 0 if OK, or a negative error code.
211 */
212int reset_deassert_bulk(struct reset_ctl_bulk *bulk);
213
214/**
Andreas Dannenberge2bc7402018-08-27 15:57:39 +0530215 * rst_status - Check reset signal status.
216 *
217 * @reset_ctl: The reset signal to check.
218 * @return 0 if deasserted, positive if asserted, or a negative
219 * error code.
220 */
221int reset_status(struct reset_ctl *reset_ctl);
222
223/**
Patrice Chotarde4d368e2017-07-18 11:57:06 +0200224 * reset_release_all - Assert/Free an array of previously requested resets.
225 *
226 * For each reset contained in the reset array, this function will check if
227 * reset has been previously requested and then will assert and free it.
228 *
229 * @reset_ctl: A reset struct array that was previously successfully
230 * requested by reset_get_by_*().
231 * @count Number of reset contained in the array
232 * @return 0 if OK, or a negative error code.
233 */
234int reset_release_all(struct reset_ctl *reset_ctl, int count);
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200235
236/**
237 * reset_release_bulk - Assert/Free an array of previously requested reset
238 * signals in a reset control bulk struct.
239 *
240 * For each reset contained in the reset control bulk struct, this function
241 * will check if reset has been previously requested and then will assert
242 * and free it.
243 *
244 * @bulk: A reset control bulk struct that was previously successfully
245 * requested by reset_get_bulk().
246 * @return 0 if OK, or a negative error code.
247 */
248static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
249{
250 return reset_release_all(bulk->resets, bulk->count);
251}
Masahiro Yamadaaf727132016-09-21 11:29:01 +0900252#else
253static inline int reset_get_by_index(struct udevice *dev, int index,
254 struct reset_ctl *reset_ctl)
255{
256 return -ENOTSUPP;
257}
258
Neil Armstrong1b75ce42018-04-12 10:03:19 +0200259static inline int reset_get_bulk(struct udevice *dev,
260 struct reset_ctl_bulk *bulk)
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200261{
262 return -ENOTSUPP;
263}
264
Masahiro Yamadaaf727132016-09-21 11:29:01 +0900265static inline int reset_get_by_name(struct udevice *dev, const char *name,
266 struct reset_ctl *reset_ctl)
267{
268 return -ENOTSUPP;
269}
270
271static inline int reset_free(struct reset_ctl *reset_ctl)
272{
273 return 0;
274}
275
276static inline int reset_assert(struct reset_ctl *reset_ctl)
277{
278 return 0;
279}
280
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200281static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk)
282{
283 return 0;
284}
285
Masahiro Yamadaaf727132016-09-21 11:29:01 +0900286static inline int reset_deassert(struct reset_ctl *reset_ctl)
287{
288 return 0;
289}
Patrice Chotarde4d368e2017-07-18 11:57:06 +0200290
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200291static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
292{
293 return 0;
294}
295
Andreas Dannenberge2bc7402018-08-27 15:57:39 +0530296static inline int reset_status(struct reset_ctl *reset_ctl)
297{
298 return -ENOTSUPP;
299}
300
Patrice Chotarde4d368e2017-07-18 11:57:06 +0200301static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
302{
303 return 0;
304}
305
Neil Armstrong1b75ce42018-04-12 10:03:19 +0200306static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
Neil Armstrongdbb26d32018-04-03 11:40:50 +0200307{
308 return 0;
309}
Masahiro Yamadaaf727132016-09-21 11:29:01 +0900310#endif
311
Jagan Tekia1a6da82018-08-06 18:55:06 +0530312/**
313 * reset_valid() - check if reset is valid
314 *
315 * @reset_ctl: the reset to check
316 * @return TRUE if valid, or FALSE
317 */
318static inline bool reset_valid(struct reset_ctl *reset_ctl)
319{
320 return !!reset_ctl->dev;
321}
322
Stephen Warren185ad872016-06-17 09:43:58 -0600323#endif