Merge tag 'efi-2020-07-rc6' of https://gitlab.denx.de/u-boot/custodians/u-boot-efi
[oweals/u-boot.git] / include / dm / uclass-internal.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2013 Google, Inc
4  *
5  * (C) Copyright 2012
6  * Pavel Herrmann <morpheus.ibis@gmail.com>
7  */
8
9 #ifndef _DM_UCLASS_INTERNAL_H
10 #define _DM_UCLASS_INTERNAL_H
11
12 #include <dm/ofnode.h>
13
14 /**
15  * uclass_find_next_free_req_seq() - Get the next free req_seq number
16  *
17  * This returns the next free req_seq number. This is useful only if
18  * OF_CONTROL is not used. The next free req_seq number is simply the
19  * maximum req_seq of the uclass + 1.
20  * This allows assiging req_seq number in the binding order.
21  *
22  * @id:         Id number of the uclass
23  * @return      The next free req_seq number
24  */
25 int uclass_find_next_free_req_seq(enum uclass_id id);
26
27 /**
28  * uclass_get_device_tail() - handle the end of a get_device call
29  *
30  * This handles returning an error or probing a device as needed.
31  *
32  * @dev: Device that needs to be probed
33  * @ret: Error to return. If non-zero then the device is not probed
34  * @devp: Returns the value of 'dev' if there is no error
35  * @return ret, if non-zero, else the result of the device_probe() call
36  */
37 int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
38
39 /**
40  * dev_get_uclass_index() - Get uclass and index of device
41  * @dev:        - in - Device that we want the uclass/index of
42  * @ucp:        - out - A pointer to the uclass the device belongs to
43  *
44  * The device is not prepared for use - this is an internal function.
45  *
46  * @return the index of the device in the uclass list or -ENODEV if not found.
47  */
48 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
49
50 /**
51  * uclass_find_device() - Return n-th child of uclass
52  * @id:         Id number of the uclass
53  * @index:      Position of the child in uclass's list
54  * #devp:       Returns pointer to device, or NULL on error
55  *
56  * The device is not prepared for use - this is an internal function.
57  * The function uclass_get_device_tail() can be used to probe the device.
58  *
59  * @return the uclass pointer of a child at the given index or
60  * return NULL on error.
61  */
62 int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
63
64 /**
65  * uclass_find_first_device() - Return the first device in a uclass
66  * @id:         Id number of the uclass
67  * #devp:       Returns pointer to device, or NULL on error
68  *
69  * The device is not prepared for use - this is an internal function.
70  * The function uclass_get_device_tail() can be used to probe the device.
71  *
72  * @return 0 if OK (found or not found), -ve on error
73  */
74 int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
75
76 /**
77  * uclass_find_next_device() - Return the next device in a uclass
78  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
79  * to the next device in the same uclass, or NULL if none
80  *
81  * The device is not prepared for use - this is an internal function.
82  * The function uclass_get_device_tail() can be used to probe the device.
83  *
84  * @return 0 if OK (found or not found), -ve on error
85  */
86 int uclass_find_next_device(struct udevice **devp);
87
88 /**
89  * uclass_find_device_by_name() - Find uclass device based on ID and name
90  *
91  * This searches for a device with the exactly given name.
92  *
93  * The device is NOT probed, it is merely returned.
94  *
95  * @id: ID to look up
96  * @name: name of a device to find
97  * @devp: Returns pointer to device (the first one with the name)
98  * @return 0 if OK, -ve on error
99  */
100 int uclass_find_device_by_name(enum uclass_id id, const char *name,
101                                struct udevice **devp);
102
103 /**
104  * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
105  *
106  * This searches for a device with the given seq or req_seq.
107  *
108  * For seq, if an active device has this sequence it will be returned.
109  * If there is no such device then this will return -ENODEV.
110  *
111  * For req_seq, if a device (whether activated or not) has this req_seq
112  * value, that device will be returned. This is a strong indication that
113  * the device will receive that sequence when activated.
114  *
115  * The device is NOT probed, it is merely returned.
116  *
117  * @id: ID to look up
118  * @seq_or_req_seq: Sequence number to find (0=first)
119  * @find_req_seq: true to find req_seq, false to find seq
120  * @devp: Returns pointer to device (there is only one per for each seq)
121  * @return 0 if OK, -ve on error
122  */
123 int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
124                               bool find_req_seq, struct udevice **devp);
125
126 /**
127  * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
128  *
129  * This searches the devices in the uclass for one attached to the given
130  * device tree node.
131  *
132  * The device is NOT probed, it is merely returned.
133  *
134  * @id: ID to look up
135  * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
136  * @devp: Returns pointer to device (there is only one for each node)
137  * @return 0 if OK, -ve on error
138  */
139 int uclass_find_device_by_of_offset(enum uclass_id id, int node,
140                                     struct udevice **devp);
141
142 /**
143  * uclass_find_device_by_of_node() - Find a uclass device by device tree node
144  *
145  * This searches the devices in the uclass for one attached to the given
146  * device tree node.
147  *
148  * The device is NOT probed, it is merely returned.
149  *
150  * @id: ID to look up
151  * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
152  * @devp: Returns pointer to device (there is only one for each node)
153  * @return 0 if OK, -ve on error
154  */
155 int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
156                                  struct udevice **devp);
157
158 /**
159  * uclass_find_device_by_phandle() - Find a uclass device by phandle
160  *
161  * This searches the devices in the uclass for one with the given phandle.
162  *
163  * The device is NOT probed, it is merely returned.
164  *
165  * @id: ID to look up
166  * @parent: Parent device containing the phandle pointer
167  * @name: Name of property in the parent device node
168  * @devp: Returns pointer to device (there is only one for each node)
169  * @return 0 if OK, -ENOENT if there is no @name present in the node, other
170  *      -ve on error
171  */
172 int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
173                                   const char *name, struct udevice **devp);
174
175 /**
176  * uclass_bind_device() - Associate device with a uclass
177  *
178  * Connect the device into uclass's list of devices.
179  *
180  * @dev:        Pointer to the device
181  * #return 0 on success, -ve on error
182  */
183 int uclass_bind_device(struct udevice *dev);
184
185 /**
186  * uclass_unbind_device() - Deassociate device with a uclass
187  *
188  * Disconnect the device from uclass's list of devices.
189  *
190  * @dev:        Pointer to the device
191  * #return 0 on success, -ve on error
192  */
193 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
194 int uclass_unbind_device(struct udevice *dev);
195 #else
196 static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
197 #endif
198
199 /**
200  * uclass_pre_probe_device() - Deal with a device that is about to be probed
201  *
202  * Perform any pre-processing that is needed by the uclass before it can be
203  * probed. This includes the uclass' pre-probe() method and the parent
204  * uclass' child_pre_probe() method.
205  *
206  * @dev:        Pointer to the device
207  * #return 0 on success, -ve on error
208  */
209 int uclass_pre_probe_device(struct udevice *dev);
210
211 /**
212  * uclass_post_probe_device() - Deal with a device that has just been probed
213  *
214  * Perform any post-processing of a probed device that is needed by the
215  * uclass.
216  *
217  * @dev:        Pointer to the device
218  * #return 0 on success, -ve on error
219  */
220 int uclass_post_probe_device(struct udevice *dev);
221
222 /**
223  * uclass_pre_remove_device() - Handle a device which is about to be removed
224  *
225  * Perform any pre-processing of a device that is about to be removed.
226  *
227  * @dev:        Pointer to the device
228  * #return 0 on success, -ve on error
229  */
230 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
231 int uclass_pre_remove_device(struct udevice *dev);
232 #else
233 static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
234 #endif
235
236 /**
237  * uclass_find() - Find uclass by its id
238  *
239  * @id:         Id to serach for
240  * @return pointer to uclass, or NULL if not found
241  */
242 struct uclass *uclass_find(enum uclass_id key);
243
244 /**
245  * uclass_destroy() - Destroy a uclass
246  *
247  * Destroy a uclass and all its devices
248  *
249  * @uc: uclass to destroy
250  * @return 0 on success, -ve on error
251  */
252 int uclass_destroy(struct uclass *uc);
253
254 #endif