1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2013 Google, Inc
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
9 #ifndef _DM_UCLASS_INTERNAL_H
10 #define _DM_UCLASS_INTERNAL_H
12 #include <dm/ofnode.h>
15 * uclass_get_device_tail() - handle the end of a get_device call
17 * This handles returning an error or probing a device as needed.
19 * @dev: Device that needs to be probed
20 * @ret: Error to return. If non-zero then the device is not probed
21 * @devp: Returns the value of 'dev' if there is no error
22 * @return ret, if non-zero, else the result of the device_probe() call
24 int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
27 * dev_get_uclass_index() - Get uclass and index of device
28 * @dev: - in - Device that we want the uclass/index of
29 * @ucp: - out - A pointer to the uclass the device belongs to
31 * The device is not prepared for use - this is an internal function.
33 * @return the index of the device in the uclass list or -ENODEV if not found.
35 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
38 * uclass_find_device() - Return n-th child of uclass
39 * @id: Id number of the uclass
40 * @index: Position of the child in uclass's list
41 * #devp: Returns pointer to device, or NULL on error
43 * The device is not prepared for use - this is an internal function.
44 * The function uclass_get_device_tail() can be used to probe the device.
46 * @return the uclass pointer of a child at the given index or
47 * return NULL on error.
49 int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
52 * uclass_find_first_device() - Return the first device in a uclass
53 * @id: Id number of the uclass
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 0 if OK (found or not found), -1 on error
61 int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
64 * uclass_find_next_device() - Return the next device in a uclass
65 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
66 * to the next device in the same uclass, or NULL if none
68 * The device is not prepared for use - this is an internal function.
69 * The function uclass_get_device_tail() can be used to probe the device.
71 * @return 0 if OK (found or not found), -1 on error
73 int uclass_find_next_device(struct udevice **devp);
76 * uclass_find_device_by_name() - Find uclass device based on ID and name
78 * This searches for a device with the exactly given name.
80 * The device is NOT probed, it is merely returned.
83 * @name: name of a device to find
84 * @devp: Returns pointer to device (the first one with the name)
85 * @return 0 if OK, -ve on error
87 int uclass_find_device_by_name(enum uclass_id id, const char *name,
88 struct udevice **devp);
91 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
93 * This searches for a device with the given seq or req_seq.
95 * For seq, if an active device has this sequence it will be returned.
96 * If there is no such device then this will return -ENODEV.
98 * For req_seq, if a device (whether activated or not) has this req_seq
99 * value, that device will be returned. This is a strong indication that
100 * the device will receive that sequence when activated.
102 * The device is NOT probed, it is merely returned.
105 * @seq_or_req_seq: Sequence number to find (0=first)
106 * @find_req_seq: true to find req_seq, false to find seq
107 * @devp: Returns pointer to device (there is only one per for each seq)
108 * @return 0 if OK, -ve on error
110 int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
111 bool find_req_seq, struct udevice **devp);
114 * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
116 * This searches the devices in the uclass for one attached to the given
119 * The device is NOT probed, it is merely returned.
122 * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
123 * @devp: Returns pointer to device (there is only one for each node)
124 * @return 0 if OK, -ve on error
126 int uclass_find_device_by_of_offset(enum uclass_id id, int node,
127 struct udevice **devp);
130 * uclass_find_device_by_of_node() - Find a uclass device by device tree node
132 * This searches the devices in the uclass for one attached to the given
135 * The device is NOT probed, it is merely returned.
138 * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
139 * @devp: Returns pointer to device (there is only one for each node)
140 * @return 0 if OK, -ve on error
142 int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
143 struct udevice **devp);
146 * uclass_find_device_by_phandle() - Find a uclass device by phandle
148 * This searches the devices in the uclass for one with the given phandle.
150 * The device is NOT probed, it is merely returned.
153 * @parent: Parent device containing the phandle pointer
154 * @name: Name of property in the parent device node
155 * @devp: Returns pointer to device (there is only one for each node)
156 * @return 0 if OK, -ENOENT if there is no @name present in the node, other
159 int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
160 const char *name, struct udevice **devp);
163 * uclass_bind_device() - Associate device with a uclass
165 * Connect the device into uclass's list of devices.
167 * @dev: Pointer to the device
168 * #return 0 on success, -ve on error
170 int uclass_bind_device(struct udevice *dev);
173 * uclass_unbind_device() - Deassociate device with a uclass
175 * Disconnect the device from uclass's list of devices.
177 * @dev: Pointer to the device
178 * #return 0 on success, -ve on error
180 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
181 int uclass_unbind_device(struct udevice *dev);
183 static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
187 * uclass_pre_probe_device() - Deal with a device that is about to be probed
189 * Perform any pre-processing that is needed by the uclass before it can be
190 * probed. This includes the uclass' pre-probe() method and the parent
191 * uclass' child_pre_probe() method.
193 * @dev: Pointer to the device
194 * #return 0 on success, -ve on error
196 int uclass_pre_probe_device(struct udevice *dev);
199 * uclass_post_probe_device() - Deal with a device that has just been probed
201 * Perform any post-processing of a probed device that is needed by the
204 * @dev: Pointer to the device
205 * #return 0 on success, -ve on error
207 int uclass_post_probe_device(struct udevice *dev);
210 * uclass_pre_remove_device() - Handle a device which is about to be removed
212 * Perform any pre-processing of a device that is about to be removed.
214 * @dev: Pointer to the device
215 * #return 0 on success, -ve on error
217 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
218 int uclass_pre_remove_device(struct udevice *dev);
220 static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
224 * uclass_find() - Find uclass by its id
226 * @id: Id to serach for
227 * @return pointer to uclass, or NULL if not found
229 struct uclass *uclass_find(enum uclass_id key);
232 * uclass_destroy() - Destroy a uclass
234 * Destroy a uclass and all its devices
236 * @uc: uclass to destroy
237 * @return 0 on success, -ve on error
239 int uclass_destroy(struct uclass *uc);