1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2013 Google, Inc
9 #ifndef _DM_UCLASS_INTERNAL_H
10 #define _DM_UCLASS_INTERNAL_H
12 #include <dm/ofnode.h>
15 * uclass_find_next_free_req_seq() - Get the next free req_seq number
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.
22 * @id: Id number of the uclass
23 * @return The next free req_seq number
25 int uclass_find_next_free_req_seq(enum uclass_id id);
28 * uclass_get_device_tail() - handle the end of a get_device call
30 * This handles returning an error or probing a device as needed.
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
37 int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
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
44 * The device is not prepared for use - this is an internal function.
46 * @return the index of the device in the uclass list or -ENODEV if not found.
48 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
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
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.
59 * @return the uclass pointer of a child at the given index or
60 * return NULL on error.
62 int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
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
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.
72 * @return 0 if OK (found or not found), -ve on error
74 int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
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
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.
84 * @return 0 if OK (found or not found), -ve on error
86 int uclass_find_next_device(struct udevice **devp);
89 * uclass_find_device_by_name() - Find uclass device based on ID and name
91 * This searches for a device with the exactly given name.
93 * The device is NOT probed, it is merely returned.
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
100 int uclass_find_device_by_name(enum uclass_id id, const char *name,
101 struct udevice **devp);
104 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
106 * This searches for a device with the given seq or req_seq.
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.
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.
115 * The device is NOT probed, it is merely returned.
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
123 int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
124 bool find_req_seq, struct udevice **devp);
127 * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
129 * This searches the devices in the uclass for one attached to the given
132 * The device is NOT probed, it is merely returned.
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
139 int uclass_find_device_by_of_offset(enum uclass_id id, int node,
140 struct udevice **devp);
143 * uclass_find_device_by_of_node() - Find a uclass device by device tree node
145 * This searches the devices in the uclass for one attached to the given
148 * The device is NOT probed, it is merely returned.
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
155 int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
156 struct udevice **devp);
159 * uclass_find_device_by_phandle() - Find a uclass device by phandle
161 * This searches the devices in the uclass for one with the given phandle.
163 * The device is NOT probed, it is merely returned.
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
172 int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
173 const char *name, struct udevice **devp);
176 * uclass_bind_device() - Associate device with a uclass
178 * Connect the device into uclass's list of devices.
180 * @dev: Pointer to the device
181 * #return 0 on success, -ve on error
183 int uclass_bind_device(struct udevice *dev);
186 * uclass_unbind_device() - Deassociate device with a uclass
188 * Disconnect the device from uclass's list of devices.
190 * @dev: Pointer to the device
191 * #return 0 on success, -ve on error
193 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
194 int uclass_unbind_device(struct udevice *dev);
196 static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
200 * uclass_pre_probe_device() - Deal with a device that is about to be probed
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.
206 * @dev: Pointer to the device
207 * #return 0 on success, -ve on error
209 int uclass_pre_probe_device(struct udevice *dev);
212 * uclass_post_probe_device() - Deal with a device that has just been probed
214 * Perform any post-processing of a probed device that is needed by the
217 * @dev: Pointer to the device
218 * #return 0 on success, -ve on error
220 int uclass_post_probe_device(struct udevice *dev);
223 * uclass_pre_remove_device() - Handle a device which is about to be removed
225 * Perform any pre-processing of a device that is about to be removed.
227 * @dev: Pointer to the device
228 * #return 0 on success, -ve on error
230 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
231 int uclass_pre_remove_device(struct udevice *dev);
233 static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
237 * uclass_find() - Find uclass by its id
239 * @id: Id to serach for
240 * @return pointer to uclass, or NULL if not found
242 struct uclass *uclass_find(enum uclass_id key);
245 * uclass_destroy() - Destroy a uclass
247 * Destroy a uclass and all its devices
249 * @uc: uclass to destroy
250 * @return 0 on success, -ve on error
252 int uclass_destroy(struct uclass *uc);