1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (c) 2016, NVIDIA CORPORATION.
9 #include <linux/errno.h>
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.
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.
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.
33 * struct reset_ctl - A handle to (allowing control of) a single reset signal.
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.
41 * @dev: The device which implements the reset signal.
42 * @id: The reset signal ID within the provider.
43 * @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.
46 * @polarity: An optional polarity field for drivers that support
47 * different reset polarities.
49 * 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
51 * 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
60 * Written by of_xlate. In the future, we might add more fields here.
64 unsigned long polarity;
68 * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset
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.
77 * @resets: An array of reset signal handles handles.
78 * @count: The number of reset signal handles in the reset array.
80 struct reset_ctl_bulk {
81 struct reset_ctl *resets;
85 #if CONFIG_IS_ENABLED(DM_RESET)
87 * reset_get_by_index - Get/request a reset signal by integer index.
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
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.
102 int reset_get_by_index(struct udevice *dev, int index,
103 struct reset_ctl *reset_ctl);
106 * reset_get_bulk - Get/request all reset signals of a device.
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
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.
119 int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
122 * reset_get_by_name - Get/request a reset signal by name.
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
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.
137 int reset_get_by_name(struct udevice *dev, const char *name,
138 struct reset_ctl *reset_ctl);
141 * reset_request - Request a reset signal.
143 * @reset_ctl: A reset control struct.
145 * @return 0 if OK, or a negative error code.
147 int reset_request(struct reset_ctl *reset_ctl);
150 * reset_free - Free a previously requested reset signal.
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.
156 int reset_free(struct reset_ctl *reset_ctl);
159 * reset_assert - Assert a reset signal.
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.
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.
170 int reset_assert(struct reset_ctl *reset_ctl);
173 * reset_assert_bulk - Assert all reset signals in a reset control bulk struct.
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.
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.
185 int reset_assert_bulk(struct reset_ctl_bulk *bulk);
188 * reset_deassert - Deassert a reset signal.
190 * This function will deassert the specified reset signal, thus releasing the
191 * affected HW modules() from reset, and allowing them to continue normal
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.
198 int reset_deassert(struct reset_ctl *reset_ctl);
201 * reset_deassert_bulk - Deassert all reset signals in a reset control bulk
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.
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.
212 int reset_deassert_bulk(struct reset_ctl_bulk *bulk);
215 * rst_status - Check reset signal status.
217 * @reset_ctl: The reset signal to check.
218 * @return 0 if deasserted, positive if asserted, or a negative
221 int reset_status(struct reset_ctl *reset_ctl);
224 * reset_release_all - Assert/Free an array of previously requested resets.
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.
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.
234 int reset_release_all(struct reset_ctl *reset_ctl, int count);
237 * reset_release_bulk - Assert/Free an array of previously requested reset
238 * signals in a reset control bulk struct.
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
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.
248 static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
250 return reset_release_all(bulk->resets, bulk->count);
253 static inline int reset_get_by_index(struct udevice *dev, int index,
254 struct reset_ctl *reset_ctl)
259 static inline int reset_get_bulk(struct udevice *dev,
260 struct reset_ctl_bulk *bulk)
265 static inline int reset_get_by_name(struct udevice *dev, const char *name,
266 struct reset_ctl *reset_ctl)
271 static inline int reset_free(struct reset_ctl *reset_ctl)
276 static inline int reset_assert(struct reset_ctl *reset_ctl)
281 static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk)
286 static inline int reset_deassert(struct reset_ctl *reset_ctl)
291 static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
296 static inline int reset_status(struct reset_ctl *reset_ctl)
301 static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
306 static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
313 * reset_valid() - check if reset is valid
315 * @reset_ctl: the reset to check
316 * @return TRUE if valid, or FALSE
318 static inline bool reset_valid(struct reset_ctl *reset_ctl)
320 return !!reset_ctl->dev;