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_set_priv() - Set the private data for a uclass
17 * This is normally handled by driver model, which automatically allocates
18 * private data when an 'auto' size if provided by the uclass driver.
20 * Use this function to override normal operation for special situations, such
21 * as needing to allocate a variable amount of data.
23 * @uc Uclass to update
24 * @priv New private-data pointer
26 void uclass_set_priv(struct uclass *uc, void *priv);
29 * uclass_find_next_free_seq() - Get the next free sequence number
31 * This returns the next free sequence number. This is useful only if
32 * OF_CONTROL is not used. The next free sequence number is simply the
33 * maximum sequence number used by all devices in the uclass + 1. The value
34 * returned is always greater than the largest alias, if DM_SEQ_ALIAS is enabled
35 * and the uclass has the DM_UC_FLAG_SEQ_ALIAS flag.
37 * This allows assigning the sequence number in the binding order.
39 * @uc: uclass to check
40 * @return The next free sequence number
42 int uclass_find_next_free_seq(struct uclass *uc);
45 * uclass_get_device_tail() - handle the end of a get_device call
47 * This handles returning an error or probing a device as needed.
49 * @dev: Device that needs to be probed
50 * @ret: Error to return. If non-zero then the device is not probed
51 * @devp: Returns the value of 'dev' if there is no error
52 * @return ret, if non-zero, else the result of the device_probe() call
54 int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
57 * dev_get_uclass_index() - Get uclass and index of device
58 * @dev: - in - Device that we want the uclass/index of
59 * @ucp: - out - A pointer to the uclass the device belongs to
61 * The device is not prepared for use - this is an internal function.
63 * @return the index of the device in the uclass list or -ENODEV if not found.
65 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
68 * uclass_find_device() - Return n-th child of uclass
69 * @id: Id number of the uclass
70 * @index: Position of the child in uclass's list
71 * #devp: Returns pointer to device, or NULL on error
73 * The device is not prepared for use - this is an internal function.
74 * The function uclass_get_device_tail() can be used to probe the device.
76 * @return the uclass pointer of a child at the given index or
77 * return NULL on error.
79 int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
82 * uclass_find_first_device() - Return the first device in a uclass
83 * @id: Id number of the uclass
84 * #devp: Returns pointer to device, or NULL on error
86 * The device is not prepared for use - this is an internal function.
87 * The function uclass_get_device_tail() can be used to probe the device.
89 * @return 0 if OK (found or not found), -ve on error
91 int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
94 * uclass_find_next_device() - Return the next device in a uclass
95 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
96 * to the next device in the same uclass, or NULL if none
98 * The device is not prepared for use - this is an internal function.
99 * The function uclass_get_device_tail() can be used to probe the device.
101 * @return 0 if OK (found or not found), -ve on error
103 int uclass_find_next_device(struct udevice **devp);
106 * uclass_find_device_by_name() - Find uclass device based on ID and name
108 * This searches for a device with the exactly given name.
110 * The device is NOT probed, it is merely returned.
113 * @name: name of a device to find
114 * @devp: Returns pointer to device (the first one with the name)
115 * @return 0 if OK, -ve on error
117 int uclass_find_device_by_name(enum uclass_id id, const char *name,
118 struct udevice **devp);
121 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
123 * This searches for a device with the given seq.
125 * The device is NOT probed, it is merely returned.
128 * @seq: Sequence number to find (0=first)
129 * @devp: Returns pointer to device (there is only one per for each seq)
130 * @return 0 if OK, -ENODEV if not found
132 int uclass_find_device_by_seq(enum uclass_id id, int seq,
133 struct udevice **devp);
136 * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
138 * This searches the devices in the uclass for one attached to the given
141 * The device is NOT probed, it is merely returned.
144 * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
145 * @devp: Returns pointer to device (there is only one for each node)
146 * @return 0 if OK, -ve on error
148 int uclass_find_device_by_of_offset(enum uclass_id id, int node,
149 struct udevice **devp);
152 * uclass_find_device_by_of_node() - Find a uclass device by device tree node
154 * This searches the devices in the uclass for one attached to the given
157 * The device is NOT probed, it is merely returned.
160 * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
161 * @devp: Returns pointer to device (there is only one for each node)
162 * @return 0 if OK, -ve on error
164 int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
165 struct udevice **devp);
168 * uclass_find_device_by_phandle() - Find a uclass device by phandle
170 * This searches the devices in the uclass for one with the given phandle.
172 * The device is NOT probed, it is merely returned.
175 * @parent: Parent device containing the phandle pointer
176 * @name: Name of property in the parent device node
177 * @devp: Returns pointer to device (there is only one for each node)
178 * @return 0 if OK, -ENOENT if there is no @name present in the node, other
181 int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
182 const char *name, struct udevice **devp);
185 * uclass_bind_device() - Associate device with a uclass
187 * Connect the device into uclass's list of devices.
189 * @dev: Pointer to the device
190 * #return 0 on success, -ve on error
192 int uclass_bind_device(struct udevice *dev);
195 * uclass_unbind_device() - Deassociate device with a uclass
197 * Disconnect the device from uclass's list of devices.
199 * @dev: Pointer to the device
200 * #return 0 on success, -ve on error
202 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
203 int uclass_unbind_device(struct udevice *dev);
205 static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
209 * uclass_pre_probe_device() - Deal with a device that is about to be probed
211 * Perform any pre-processing that is needed by the uclass before it can be
212 * probed. This includes the uclass' pre-probe() method and the parent
213 * uclass' child_pre_probe() method.
215 * @dev: Pointer to the device
216 * #return 0 on success, -ve on error
218 int uclass_pre_probe_device(struct udevice *dev);
221 * uclass_post_probe_device() - Deal with a device that has just been probed
223 * Perform any post-processing of a probed device that is needed by the
226 * @dev: Pointer to the device
227 * #return 0 on success, -ve on error
229 int uclass_post_probe_device(struct udevice *dev);
232 * uclass_pre_remove_device() - Handle a device which is about to be removed
234 * Perform any pre-processing of a device that is about to be removed.
236 * @dev: Pointer to the device
237 * #return 0 on success, -ve on error
239 #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
240 int uclass_pre_remove_device(struct udevice *dev);
242 static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
246 * uclass_find() - Find uclass by its id
248 * @id: Id to serach for
249 * @return pointer to uclass, or NULL if not found
251 struct uclass *uclass_find(enum uclass_id key);
254 * uclass_destroy() - Destroy a uclass
256 * Destroy a uclass and all its devices
258 * @uc: uclass to destroy
259 * @return 0 on success, -ve on error
261 int uclass_destroy(struct uclass *uc);