xref: /OK3568_Linux_fs/u-boot/include/reset.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright (c) 2016, NVIDIA CORPORATION.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier: GPL-2.0
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #ifndef _RESET_H
8*4882a593Smuzhiyun #define _RESET_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/errno.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /**
13*4882a593Smuzhiyun  * A reset is a hardware signal indicating that a HW module (or IP block, or
14*4882a593Smuzhiyun  * sometimes an entire off-CPU chip) reset all of its internal state to some
15*4882a593Smuzhiyun  * known-good initial state. Drivers will often reset HW modules when they
16*4882a593Smuzhiyun  * begin execution to ensure that hardware correctly responds to all requests,
17*4882a593Smuzhiyun  * or in response to some error condition. Reset signals are often controlled
18*4882a593Smuzhiyun  * externally to the HW module being reset, by an entity this API calls a reset
19*4882a593Smuzhiyun  * controller. This API provides a standard means for drivers to request that
20*4882a593Smuzhiyun  * reset controllers set or clear reset signals.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * A driver that implements UCLASS_RESET is a reset controller or provider. A
23*4882a593Smuzhiyun  * controller will often implement multiple separate reset signals, since the
24*4882a593Smuzhiyun  * hardware it manages often has this capability. reset-uclass.h describes the
25*4882a593Smuzhiyun  * interface which reset controllers must implement.
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  * Reset consumers/clients are the HW modules affected by reset signals. This
28*4882a593Smuzhiyun  * header file describes the API used by drivers for those HW modules.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun struct udevice;
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /**
34*4882a593Smuzhiyun  * struct reset_ctl - A handle to (allowing control of) a single reset signal.
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  * Clients provide storage for reset control handles. The content of the
37*4882a593Smuzhiyun  * structure is managed solely by the reset API and reset drivers. A reset
38*4882a593Smuzhiyun  * control struct is initialized by "get"ing the reset control struct. The
39*4882a593Smuzhiyun  * reset control struct is passed to all other reset APIs to identify which
40*4882a593Smuzhiyun  * reset signal to operate upon.
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * @dev: The device which implements the reset signal.
43*4882a593Smuzhiyun  * @id: The reset signal ID within the provider.
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  * Currently, the reset API assumes that a single integer ID is enough to
46*4882a593Smuzhiyun  * identify and configure any reset signal for any reset provider. If this
47*4882a593Smuzhiyun  * assumption becomes invalid in the future, the struct could be expanded to
48*4882a593Smuzhiyun  * either (a) add more fields to allow reset providers to store additional
49*4882a593Smuzhiyun  * information, or (b) replace the id field with an opaque pointer, which the
50*4882a593Smuzhiyun  * provider would dynamically allocated during its .of_xlate op, and process
51*4882a593Smuzhiyun  * during is .request op. This may require the addition of an extra op to clean
52*4882a593Smuzhiyun  * up the allocation.
53*4882a593Smuzhiyun  */
54*4882a593Smuzhiyun struct reset_ctl {
55*4882a593Smuzhiyun 	struct udevice *dev;
56*4882a593Smuzhiyun 	/*
57*4882a593Smuzhiyun 	 * Written by of_xlate. We assume a single id is enough for now. In the
58*4882a593Smuzhiyun 	 * future, we might add more fields here.
59*4882a593Smuzhiyun 	 */
60*4882a593Smuzhiyun 	unsigned long id;
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /**
64*4882a593Smuzhiyun  * struct reset_ctl_bulk - A handle to (allowing control of) a bulk of reset
65*4882a593Smuzhiyun  * signals.
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * Clients provide storage for the reset control bulk. The content of the
68*4882a593Smuzhiyun  * structure is managed solely by the reset API. A reset control bulk struct is
69*4882a593Smuzhiyun  * initialized by "get"ing the reset control bulk struct.
70*4882a593Smuzhiyun  * The reset control bulk struct is passed to all other bulk reset APIs to apply
71*4882a593Smuzhiyun  * the API to all the reset signals in the bulk struct.
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * @resets: An array of reset signal handles handles.
74*4882a593Smuzhiyun  * @count: The number of reset signal handles in the reset array.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun struct reset_ctl_bulk {
77*4882a593Smuzhiyun 	struct reset_ctl *resets;
78*4882a593Smuzhiyun 	unsigned int count;
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun #ifdef CONFIG_DM_RESET
82*4882a593Smuzhiyun /**
83*4882a593Smuzhiyun  * reset_get_by_index - Get/request a reset signal by integer index.
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * This looks up and requests a reset signal. The index is relative to the
86*4882a593Smuzhiyun  * client device; each device is assumed to have n reset signals associated
87*4882a593Smuzhiyun  * with it somehow, and this function finds and requests one of them. The
88*4882a593Smuzhiyun  * mapping of client device reset signal indices to provider reset signals may
89*4882a593Smuzhiyun  * be via device-tree properties, board-provided mapping tables, or some other
90*4882a593Smuzhiyun  * mechanism.
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * @dev:	The client device.
93*4882a593Smuzhiyun  * @index:	The index of the reset signal to request, within the client's
94*4882a593Smuzhiyun  *		list of reset signals.
95*4882a593Smuzhiyun  * @reset_ctl	A pointer to a reset control struct to initialize.
96*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
97*4882a593Smuzhiyun  */
98*4882a593Smuzhiyun int reset_get_by_index(struct udevice *dev, int index,
99*4882a593Smuzhiyun 		       struct reset_ctl *reset_ctl);
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /**
102*4882a593Smuzhiyun  * reset_get_bulk - Get/request all reset signals of a device.
103*4882a593Smuzhiyun  *
104*4882a593Smuzhiyun  * This looks up and requests all reset signals of the client device; each
105*4882a593Smuzhiyun  * device is assumed to have n reset signals associated with it somehow,
106*4882a593Smuzhiyun  * and this function finds and requests all of them in a separate structure.
107*4882a593Smuzhiyun  * The mapping of client device reset signals indices to provider reset signals
108*4882a593Smuzhiyun  * may be via device-tree properties, board-provided mapping tables, or some
109*4882a593Smuzhiyun  * other mechanism.
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * @dev:	The client device.
112*4882a593Smuzhiyun  * @bulk	A pointer to a reset control bulk struct to initialize.
113*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
114*4882a593Smuzhiyun  */
115*4882a593Smuzhiyun int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun /**
118*4882a593Smuzhiyun  * reset_get_by_name - Get/request a reset signal by name.
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * This looks up and requests a reset signal. The name is relative to the
121*4882a593Smuzhiyun  * client device; each device is assumed to have n reset signals associated
122*4882a593Smuzhiyun  * with it somehow, and this function finds and requests one of them. The
123*4882a593Smuzhiyun  * mapping of client device reset signal names to provider reset signal may be
124*4882a593Smuzhiyun  * via device-tree properties, board-provided mapping tables, or some other
125*4882a593Smuzhiyun  * mechanism.
126*4882a593Smuzhiyun  *
127*4882a593Smuzhiyun  * @dev:	The client device.
128*4882a593Smuzhiyun  * @name:	The name of the reset signal to request, within the client's
129*4882a593Smuzhiyun  *		list of reset signals.
130*4882a593Smuzhiyun  * @reset_ctl:	A pointer to a reset control struct to initialize.
131*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
132*4882a593Smuzhiyun  */
133*4882a593Smuzhiyun int reset_get_by_name(struct udevice *dev, const char *name,
134*4882a593Smuzhiyun 		      struct reset_ctl *reset_ctl);
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun /**
137*4882a593Smuzhiyun  * reset_request - Request a reset signal.
138*4882a593Smuzhiyun  *
139*4882a593Smuzhiyun  * @reset_ctl:	A reset control struct.
140*4882a593Smuzhiyun  *
141*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun int reset_request(struct reset_ctl *reset_ctl);
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun /**
146*4882a593Smuzhiyun  * reset_free - Free a previously requested reset signal.
147*4882a593Smuzhiyun  *
148*4882a593Smuzhiyun  * @reset_ctl:	A reset control struct that was previously successfully
149*4882a593Smuzhiyun  *		requested by reset_get_by_*().
150*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
151*4882a593Smuzhiyun  */
152*4882a593Smuzhiyun int reset_free(struct reset_ctl *reset_ctl);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun /**
155*4882a593Smuzhiyun  * reset_assert - Assert a reset signal.
156*4882a593Smuzhiyun  *
157*4882a593Smuzhiyun  * This function will assert the specified reset signal, thus resetting the
158*4882a593Smuzhiyun  * affected HW module(s). Depending on the reset controller hardware, the reset
159*4882a593Smuzhiyun  * signal will either stay asserted until reset_deassert() is called, or the
160*4882a593Smuzhiyun  * hardware may autonomously clear the reset signal itself.
161*4882a593Smuzhiyun  *
162*4882a593Smuzhiyun  * @reset_ctl:	A reset control struct that was previously successfully
163*4882a593Smuzhiyun  *		requested by reset_get_by_*().
164*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
165*4882a593Smuzhiyun  */
166*4882a593Smuzhiyun int reset_assert(struct reset_ctl *reset_ctl);
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun /**
169*4882a593Smuzhiyun  * reset_assert_bulk - Assert all reset signals in a reset control bulk struct.
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  * This function will assert the specified reset signals in a reset control
172*4882a593Smuzhiyun  * bulk struct, thus resetting the affected HW module(s). Depending on the
173*4882a593Smuzhiyun  * reset controller hardware, the reset signals will either stay asserted
174*4882a593Smuzhiyun  * until reset_deassert_bulk() is called, or the hardware may autonomously
175*4882a593Smuzhiyun  * clear the reset signals itself.
176*4882a593Smuzhiyun  *
177*4882a593Smuzhiyun  * @bulk:	A reset control bulk struct that was previously successfully
178*4882a593Smuzhiyun  *		requested by reset_get_bulk().
179*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
180*4882a593Smuzhiyun  */
181*4882a593Smuzhiyun int reset_assert_bulk(struct reset_ctl_bulk *bulk);
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun /**
184*4882a593Smuzhiyun  * reset_deassert - Deassert a reset signal.
185*4882a593Smuzhiyun  *
186*4882a593Smuzhiyun  * This function will deassert the specified reset signal, thus releasing the
187*4882a593Smuzhiyun  * affected HW modules() from reset, and allowing them to continue normal
188*4882a593Smuzhiyun  * operation.
189*4882a593Smuzhiyun  *
190*4882a593Smuzhiyun  * @reset_ctl:	A reset control struct that was previously successfully
191*4882a593Smuzhiyun  *		requested by reset_get_by_*().
192*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
193*4882a593Smuzhiyun  */
194*4882a593Smuzhiyun int reset_deassert(struct reset_ctl *reset_ctl);
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun /**
197*4882a593Smuzhiyun  * reset_deassert_bulk - Deassert all reset signals in a reset control bulk
198*4882a593Smuzhiyun  * struct.
199*4882a593Smuzhiyun  *
200*4882a593Smuzhiyun  * This function will deassert the specified reset signals in a reset control
201*4882a593Smuzhiyun  * bulk struct, thus releasing the affected HW modules() from reset, and
202*4882a593Smuzhiyun  * allowing them to continue normal operation.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * @bulk:	A reset control bulk struct that was previously successfully
205*4882a593Smuzhiyun  *		requested by reset_get_bulk().
206*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
207*4882a593Smuzhiyun  */
208*4882a593Smuzhiyun int reset_deassert_bulk(struct reset_ctl_bulk *bulk);
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun /**
211*4882a593Smuzhiyun  * reset_release_all - Assert/Free an array of previously requested resets.
212*4882a593Smuzhiyun  *
213*4882a593Smuzhiyun  * For each reset contained in the reset array, this function will check if
214*4882a593Smuzhiyun  * reset has been previously requested and then will assert and free it.
215*4882a593Smuzhiyun  *
216*4882a593Smuzhiyun  * @reset_ctl:	A reset struct array that was previously successfully
217*4882a593Smuzhiyun  *		requested by reset_get_by_*().
218*4882a593Smuzhiyun  * @count	Number of reset contained in the array
219*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
220*4882a593Smuzhiyun  */
221*4882a593Smuzhiyun int reset_release_all(struct reset_ctl *reset_ctl, int count);
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun /**
224*4882a593Smuzhiyun  * reset_release_bulk - Assert/Free an array of previously requested reset
225*4882a593Smuzhiyun  * signals in a reset control bulk struct.
226*4882a593Smuzhiyun  *
227*4882a593Smuzhiyun  * For each reset contained in the reset control bulk struct, this function
228*4882a593Smuzhiyun  * will check if reset has been previously requested and then will assert
229*4882a593Smuzhiyun  * and free it.
230*4882a593Smuzhiyun  *
231*4882a593Smuzhiyun  * @bulk:	A reset control bulk struct that was previously successfully
232*4882a593Smuzhiyun  *		requested by reset_get_bulk().
233*4882a593Smuzhiyun  * @return 0 if OK, or a negative error code.
234*4882a593Smuzhiyun  */
reset_release_bulk(struct reset_ctl_bulk * bulk)235*4882a593Smuzhiyun static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun 	return reset_release_all(bulk->resets, bulk->count);
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun #else
reset_get_by_index(struct udevice * dev,int index,struct reset_ctl * reset_ctl)240*4882a593Smuzhiyun static inline int reset_get_by_index(struct udevice *dev, int index,
241*4882a593Smuzhiyun 				     struct reset_ctl *reset_ctl)
242*4882a593Smuzhiyun {
243*4882a593Smuzhiyun 	return -ENOTSUPP;
244*4882a593Smuzhiyun }
245*4882a593Smuzhiyun 
reset_get_bulk(struct udevice * dev,struct reset_ctl_bulk * bulk)246*4882a593Smuzhiyun static inline int reset_get_bulk(struct udevice *dev,
247*4882a593Smuzhiyun 				 struct reset_ctl_bulk *bulk)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun 	return -ENOTSUPP;
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun 
reset_get_by_name(struct udevice * dev,const char * name,struct reset_ctl * reset_ctl)252*4882a593Smuzhiyun static inline int reset_get_by_name(struct udevice *dev, const char *name,
253*4882a593Smuzhiyun 				    struct reset_ctl *reset_ctl)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun 	return -ENOTSUPP;
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun 
reset_free(struct reset_ctl * reset_ctl)258*4882a593Smuzhiyun static inline int reset_free(struct reset_ctl *reset_ctl)
259*4882a593Smuzhiyun {
260*4882a593Smuzhiyun 	return 0;
261*4882a593Smuzhiyun }
262*4882a593Smuzhiyun 
reset_assert(struct reset_ctl * reset_ctl)263*4882a593Smuzhiyun static inline int reset_assert(struct reset_ctl *reset_ctl)
264*4882a593Smuzhiyun {
265*4882a593Smuzhiyun 	return 0;
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
reset_assert_bulk(struct reset_ctl_bulk * bulk)268*4882a593Smuzhiyun static inline int reset_assert_bulk(struct reset_ctl_bulk *bulk)
269*4882a593Smuzhiyun {
270*4882a593Smuzhiyun 	return 0;
271*4882a593Smuzhiyun }
272*4882a593Smuzhiyun 
reset_deassert(struct reset_ctl * reset_ctl)273*4882a593Smuzhiyun static inline int reset_deassert(struct reset_ctl *reset_ctl)
274*4882a593Smuzhiyun {
275*4882a593Smuzhiyun 	return 0;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun 
reset_deassert_bulk(struct reset_ctl_bulk * bulk)278*4882a593Smuzhiyun static inline int reset_deassert_bulk(struct reset_ctl_bulk *bulk)
279*4882a593Smuzhiyun {
280*4882a593Smuzhiyun 	return 0;
281*4882a593Smuzhiyun }
282*4882a593Smuzhiyun 
reset_release_all(struct reset_ctl * reset_ctl,int count)283*4882a593Smuzhiyun static inline int reset_release_all(struct reset_ctl *reset_ctl, int count)
284*4882a593Smuzhiyun {
285*4882a593Smuzhiyun 	return 0;
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun 
reset_release_bulk(struct reset_ctl_bulk * bulk)288*4882a593Smuzhiyun static inline int reset_release_bulk(struct reset_ctl_bulk *bulk)
289*4882a593Smuzhiyun {
290*4882a593Smuzhiyun 	return 0;
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun #endif
293*4882a593Smuzhiyun 
294*4882a593Smuzhiyun #endif
295