xref: /openbmc/u-boot/include/dm/uclass.h (revision 0c4b382f9041f9f2f00246c8a0ece90dae5451be)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
26494d708SSimon Glass /*
36494d708SSimon Glass  * Copyright (c) 2013 Google, Inc
46494d708SSimon Glass  *
56494d708SSimon Glass  * (C) Copyright 2012
66494d708SSimon Glass  * Pavel Herrmann <morpheus.ibis@gmail.com>
76494d708SSimon Glass  */
86494d708SSimon Glass 
96494d708SSimon Glass #ifndef _DM_UCLASS_H
106494d708SSimon Glass #define _DM_UCLASS_H
116494d708SSimon Glass 
1240bb637dSSimon Glass #include <dm/ofnode.h>
136494d708SSimon Glass #include <dm/uclass-id.h>
1442c23dd2SMasahiro Yamada #include <linker_lists.h>
156494d708SSimon Glass #include <linux/list.h>
166494d708SSimon Glass 
176494d708SSimon Glass /**
186494d708SSimon Glass  * struct uclass - a U-Boot drive class, collecting together similar drivers
196494d708SSimon Glass  *
206494d708SSimon Glass  * A uclass provides an interface to a particular function, which is
216494d708SSimon Glass  * implemented by one or more drivers. Every driver belongs to a uclass even
226494d708SSimon Glass  * if it is the only driver in that uclass. An example uclass is GPIO, which
236494d708SSimon Glass  * provides the ability to change read inputs, set and clear outputs, etc.
246494d708SSimon Glass  * There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and
256494d708SSimon Glass  * PMIC IO lines, all made available in a unified way through the uclass.
266494d708SSimon Glass  *
276494d708SSimon Glass  * @priv: Private data for this uclass
286494d708SSimon Glass  * @uc_drv: The driver for the uclass itself, not to be confused with a
296494d708SSimon Glass  * 'struct driver'
30f2bc6fc3SSimon Glass  * @dev_head: List of devices in this uclass (devices are attached to their
316494d708SSimon Glass  * uclass when their bind method is called)
326494d708SSimon Glass  * @sibling_node: Next uclass in the linked list of uclasses
336494d708SSimon Glass  */
346494d708SSimon Glass struct uclass {
356494d708SSimon Glass 	void *priv;
366494d708SSimon Glass 	struct uclass_driver *uc_drv;
376494d708SSimon Glass 	struct list_head dev_head;
386494d708SSimon Glass 	struct list_head sibling_node;
396494d708SSimon Glass };
406494d708SSimon Glass 
41c57f806bSSimon Glass struct driver;
4254c5d08aSHeiko Schocher struct udevice;
436494d708SSimon Glass 
449cc36a2bSSimon Glass /* Members of this uclass sequence themselves with aliases */
459cc36a2bSSimon Glass #define DM_UC_FLAG_SEQ_ALIAS			(1 << 0)
469cc36a2bSSimon Glass 
47c7a3acccSSimon Glass /* Same as DM_FLAG_ALLOC_PRIV_DMA */
48c7a3acccSSimon Glass #define DM_UC_FLAG_ALLOC_PRIV_DMA		(1 << 5)
49c7a3acccSSimon Glass 
506494d708SSimon Glass /**
516494d708SSimon Glass  * struct uclass_driver - Driver for the uclass
526494d708SSimon Glass  *
536494d708SSimon Glass  * A uclass_driver provides a consistent interface to a set of related
546494d708SSimon Glass  * drivers.
556494d708SSimon Glass  *
566494d708SSimon Glass  * @name: Name of uclass driver
576494d708SSimon Glass  * @id: ID number of this uclass
586494d708SSimon Glass  * @post_bind: Called after a new device is bound to this uclass
596494d708SSimon Glass  * @pre_unbind: Called before a device is unbound from this uclass
6002c07b37SSimon Glass  * @pre_probe: Called before a new device is probed
616494d708SSimon Glass  * @post_probe: Called after a new device is probed
626494d708SSimon Glass  * @pre_remove: Called before a device is removed
63081f2fcbSSimon Glass  * @child_post_bind: Called after a child is bound to a device in this uclass
64651d0c01SBin Meng  * @child_pre_probe: Called before a child in this uclass is probed
65651d0c01SBin Meng  * @child_post_probe: Called after a child in this uclass is probed
666494d708SSimon Glass  * @init: Called to set up the uclass
676494d708SSimon Glass  * @destroy: Called to destroy the uclass
686494d708SSimon Glass  * @priv_auto_alloc_size: If non-zero this is the size of the private data
696494d708SSimon Glass  * to be allocated in the uclass's ->priv pointer. If zero, then the uclass
706494d708SSimon Glass  * driver is responsible for allocating any data required.
716494d708SSimon Glass  * @per_device_auto_alloc_size: Each device can hold private data owned
726494d708SSimon Glass  * by the uclass. If required this will be automatically allocated if this
736494d708SSimon Glass  * value is non-zero.
745eaed880SPrzemyslaw Marczak  * @per_device_platdata_auto_alloc_size: Each device can hold platform data
755eaed880SPrzemyslaw Marczak  * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero,
765eaed880SPrzemyslaw Marczak  * then this will be automatically allocated.
77dac8db2cSSimon Glass  * @per_child_auto_alloc_size: Each child device (of a parent in this
78dac8db2cSSimon Glass  * uclass) can hold parent data for the device/uclass. This value is only
79fa9335a8SHeinrich Schuchardt  * used as a fallback if this member is 0 in the driver.
80ba8da9dcSSimon Glass  * @per_child_platdata_auto_alloc_size: A bus likes to store information about
81ba8da9dcSSimon Glass  * its children. If non-zero this is the size of this data, to be allocated
82ba8da9dcSSimon Glass  * in the child device's parent_platdata pointer. This value is only used as
83fa9335a8SHeinrich Schuchardt  * a fallback if this member is 0 in the driver.
846494d708SSimon Glass  * @ops: Uclass operations, providing the consistent interface to devices
856494d708SSimon Glass  * within the uclass.
869cc36a2bSSimon Glass  * @flags: Flags for this uclass (DM_UC_...)
876494d708SSimon Glass  */
886494d708SSimon Glass struct uclass_driver {
896494d708SSimon Glass 	const char *name;
906494d708SSimon Glass 	enum uclass_id id;
9154c5d08aSHeiko Schocher 	int (*post_bind)(struct udevice *dev);
9254c5d08aSHeiko Schocher 	int (*pre_unbind)(struct udevice *dev);
9302c07b37SSimon Glass 	int (*pre_probe)(struct udevice *dev);
9454c5d08aSHeiko Schocher 	int (*post_probe)(struct udevice *dev);
9554c5d08aSHeiko Schocher 	int (*pre_remove)(struct udevice *dev);
96081f2fcbSSimon Glass 	int (*child_post_bind)(struct udevice *dev);
9783c7e434SSimon Glass 	int (*child_pre_probe)(struct udevice *dev);
98651d0c01SBin Meng 	int (*child_post_probe)(struct udevice *dev);
996494d708SSimon Glass 	int (*init)(struct uclass *class);
1006494d708SSimon Glass 	int (*destroy)(struct uclass *class);
1016494d708SSimon Glass 	int priv_auto_alloc_size;
1026494d708SSimon Glass 	int per_device_auto_alloc_size;
1035eaed880SPrzemyslaw Marczak 	int per_device_platdata_auto_alloc_size;
104dac8db2cSSimon Glass 	int per_child_auto_alloc_size;
105ba8da9dcSSimon Glass 	int per_child_platdata_auto_alloc_size;
1066494d708SSimon Glass 	const void *ops;
1079cc36a2bSSimon Glass 	uint32_t flags;
1086494d708SSimon Glass };
1096494d708SSimon Glass 
1106494d708SSimon Glass /* Declare a new uclass_driver */
1116494d708SSimon Glass #define UCLASS_DRIVER(__name)						\
1126494d708SSimon Glass 	ll_entry_declare(struct uclass_driver, __name, uclass)
1136494d708SSimon Glass 
1146494d708SSimon Glass /**
1156494d708SSimon Glass  * uclass_get() - Get a uclass based on an ID, creating it if needed
1166494d708SSimon Glass  *
1176494d708SSimon Glass  * Every uclass is identified by an ID, a number from 0 to n-1 where n is
1186494d708SSimon Glass  * the number of uclasses. This function allows looking up a uclass by its
1196494d708SSimon Glass  * ID.
1206494d708SSimon Glass  *
1216494d708SSimon Glass  * @key: ID to look up
1226494d708SSimon Glass  * @ucp: Returns pointer to uclass (there is only one per ID)
1236494d708SSimon Glass  * @return 0 if OK, -ve on error
1246494d708SSimon Glass  */
1256494d708SSimon Glass int uclass_get(enum uclass_id key, struct uclass **ucp);
1266494d708SSimon Glass 
1276494d708SSimon Glass /**
1280a5f6f86SSimon Glass  * uclass_get_name() - Get the name of a uclass driver
1290a5f6f86SSimon Glass  *
1300a5f6f86SSimon Glass  * @id: ID to look up
1310a5f6f86SSimon Glass  * @returns the name of the uclass driver for that ID, or NULL if none
1320a5f6f86SSimon Glass  */
1330a5f6f86SSimon Glass const char *uclass_get_name(enum uclass_id id);
1340a5f6f86SSimon Glass 
1350a5f6f86SSimon Glass /**
1366e43d1b1SSimon Glass  * uclass_get_by_name() - Look up a uclass by its driver name
1376e43d1b1SSimon Glass  *
1386e43d1b1SSimon Glass  * @name: Name to look up
1396e43d1b1SSimon Glass  * @returns the associated uclass ID, or UCLASS_INVALID if not found
1406e43d1b1SSimon Glass  */
1416e43d1b1SSimon Glass enum uclass_id uclass_get_by_name(const char *name);
1426e43d1b1SSimon Glass 
1436e43d1b1SSimon Glass /**
1446494d708SSimon Glass  * uclass_get_device() - Get a uclass device based on an ID and index
1456494d708SSimon Glass  *
146f2bc6fc3SSimon Glass  * The device is probed to activate it ready for use.
147f2bc6fc3SSimon Glass  *
1480040b944SSimon Glass  * @id: ID to look up
1496494d708SSimon Glass  * @index: Device number within that uclass (0=first)
150f2bc6fc3SSimon Glass  * @devp: Returns pointer to device (there is only one per for each ID)
1516494d708SSimon Glass  * @return 0 if OK, -ve on error
1526494d708SSimon Glass  */
153f2bc6fc3SSimon Glass int uclass_get_device(enum uclass_id id, int index, struct udevice **devp);
1546494d708SSimon Glass 
1556494d708SSimon Glass /**
15674356d7fSSimon Glass  * uclass_get_device_by_name() - Get a uclass device by its name
157b7af1a2dSPrzemyslaw Marczak  *
158a7b82502SPrzemyslaw Marczak  * This searches the devices in the uclass for one with the exactly given name.
159b7af1a2dSPrzemyslaw Marczak  *
160b7af1a2dSPrzemyslaw Marczak  * The device is probed to activate it ready for use.
161b7af1a2dSPrzemyslaw Marczak  *
162b7af1a2dSPrzemyslaw Marczak  * @id: ID to look up
163b7af1a2dSPrzemyslaw Marczak  * @name: name of a device to get
164b7af1a2dSPrzemyslaw Marczak  * @devp: Returns pointer to device (the first one with the name)
165b7af1a2dSPrzemyslaw Marczak  * @return 0 if OK, -ve on error
166b7af1a2dSPrzemyslaw Marczak  */
167b7af1a2dSPrzemyslaw Marczak int uclass_get_device_by_name(enum uclass_id id, const char *name,
168b7af1a2dSPrzemyslaw Marczak 			      struct udevice **devp);
169b7af1a2dSPrzemyslaw Marczak 
170b7af1a2dSPrzemyslaw Marczak /**
1715a66a8ffSSimon Glass  * uclass_get_device_by_seq() - Get a uclass device based on an ID and sequence
1725a66a8ffSSimon Glass  *
1735a66a8ffSSimon Glass  * If an active device has this sequence it will be returned. If there is no
1745a66a8ffSSimon Glass  * such device then this will check for a device that is requesting this
1755a66a8ffSSimon Glass  * sequence.
1765a66a8ffSSimon Glass  *
1775a66a8ffSSimon Glass  * The device is probed to activate it ready for use.
1785a66a8ffSSimon Glass  *
1795a66a8ffSSimon Glass  * @id: ID to look up
1805a66a8ffSSimon Glass  * @seq: Sequence number to find (0=first)
1815a66a8ffSSimon Glass  * @devp: Returns pointer to device (there is only one for each seq)
1825a66a8ffSSimon Glass  * @return 0 if OK, -ve on error
1835a66a8ffSSimon Glass  */
1845a66a8ffSSimon Glass int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp);
1855a66a8ffSSimon Glass 
1865a66a8ffSSimon Glass /**
187f4cdead2SSimon Glass  * uclass_get_device_by_of_offset() - Get a uclass device by device tree node
188f4cdead2SSimon Glass  *
189f4cdead2SSimon Glass  * This searches the devices in the uclass for one attached to the given
190f4cdead2SSimon Glass  * device tree node.
191f4cdead2SSimon Glass  *
192f4cdead2SSimon Glass  * The device is probed to activate it ready for use.
193f4cdead2SSimon Glass  *
194f4cdead2SSimon Glass  * @id: ID to look up
195f4cdead2SSimon Glass  * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
196f4cdead2SSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
197f4cdead2SSimon Glass  * @return 0 if OK, -ve on error
198f4cdead2SSimon Glass  */
199f4cdead2SSimon Glass int uclass_get_device_by_of_offset(enum uclass_id id, int node,
200f4cdead2SSimon Glass 				   struct udevice **devp);
201f4cdead2SSimon Glass 
202f4cdead2SSimon Glass /**
20340bb637dSSimon Glass  * uclass_get_device_by_ofnode() - Get a uclass device by device tree node
20440bb637dSSimon Glass  *
20540bb637dSSimon Glass  * This searches the devices in the uclass for one attached to the given
20640bb637dSSimon Glass  * device tree node.
20740bb637dSSimon Glass  *
20840bb637dSSimon Glass  * The device is probed to activate it ready for use.
20940bb637dSSimon Glass  *
21040bb637dSSimon Glass  * @id: ID to look up
21140bb637dSSimon Glass  * @np: Device tree node to search for (if NULL then -ENODEV is returned)
21240bb637dSSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
21340bb637dSSimon Glass  * @return 0 if OK, -ve on error
21440bb637dSSimon Glass  */
21540bb637dSSimon Glass int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node,
21640bb637dSSimon Glass 				struct udevice **devp);
21740bb637dSSimon Glass 
21840bb637dSSimon Glass /**
219d255fadeSKever Yang  * uclass_get_device_by_phandle_id() - Get a uclass device by phandle id
220d255fadeSKever Yang  *
221d255fadeSKever Yang  * This searches the devices in the uclass for one with the given phandle id.
222d255fadeSKever Yang  *
223d255fadeSKever Yang  * The device is probed to activate it ready for use.
224d255fadeSKever Yang  *
225d255fadeSKever Yang  * @id: uclass ID to look up
226d255fadeSKever Yang  * @phandle_id: the phandle id to look up
227d255fadeSKever Yang  * @devp: Returns pointer to device (there is only one for each node)
228d255fadeSKever Yang  * @return 0 if OK, -ENODEV if there is no device match the phandle, other
229d255fadeSKever Yang  *	-ve on error
230d255fadeSKever Yang  */
231d255fadeSKever Yang int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id,
232d255fadeSKever Yang 				    struct udevice **devp);
233d255fadeSKever Yang 
234d255fadeSKever Yang /**
235d82ba4c0SSimon Glass  * uclass_get_device_by_phandle() - Get a uclass device by phandle
236d82ba4c0SSimon Glass  *
237d82ba4c0SSimon Glass  * This searches the devices in the uclass for one with the given phandle.
238d82ba4c0SSimon Glass  *
239d82ba4c0SSimon Glass  * The device is probed to activate it ready for use.
240d82ba4c0SSimon Glass  *
241d82ba4c0SSimon Glass  * @id: uclass ID to look up
242d82ba4c0SSimon Glass  * @parent: Parent device containing the phandle pointer
243d82ba4c0SSimon Glass  * @name: Name of property in the parent device node
244d82ba4c0SSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
245d82ba4c0SSimon Glass  * @return 0 if OK, -ENOENT if there is no @name present in the node, other
246d82ba4c0SSimon Glass  *	-ve on error
247d82ba4c0SSimon Glass  */
248d82ba4c0SSimon Glass int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent,
249d82ba4c0SSimon Glass 				 const char *name, struct udevice **devp);
250d82ba4c0SSimon Glass 
251d82ba4c0SSimon Glass /**
252c57f806bSSimon Glass  * uclass_get_device_by_driver() - Get a uclass device for a driver
253c57f806bSSimon Glass  *
254c57f806bSSimon Glass  * This searches the devices in the uclass for one that uses the given
255c57f806bSSimon Glass  * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is
256c57f806bSSimon Glass  * the driver name - as used in U_BOOT_DRIVER(name).
257c57f806bSSimon Glass  *
258c57f806bSSimon Glass  * The device is probed to activate it ready for use.
259c57f806bSSimon Glass  *
260c57f806bSSimon Glass  * @id: ID to look up
261c57f806bSSimon Glass  * @drv: Driver to look for
262c57f806bSSimon Glass  * @devp: Returns pointer to the first device with that driver
263c57f806bSSimon Glass  * @return 0 if OK, -ve on error
264c57f806bSSimon Glass  */
265c57f806bSSimon Glass int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv,
266c57f806bSSimon Glass 				struct udevice **devp);
267c57f806bSSimon Glass 
268c57f806bSSimon Glass /**
2696494d708SSimon Glass  * uclass_first_device() - Get the first device in a uclass
2706494d708SSimon Glass  *
271040b69afSSimon Glass  * The device returned is probed if necessary, and ready for use
272040b69afSSimon Glass  *
27330a570a9SSimon Glass  * This function is useful to start iterating through a list of devices which
27430a570a9SSimon Glass  * are functioning correctly and can be probed.
27530a570a9SSimon Glass  *
2766494d708SSimon Glass  * @id: Uclass ID to look up
27730a570a9SSimon Glass  * @devp: Returns pointer to the first device in that uclass if no error
27830a570a9SSimon Glass  * occurred, or NULL if there is no first device, or an error occurred with
27930a570a9SSimon Glass  * that device.
280b0675050SSimon Glass  * @return 0 if OK (found or not found), other -ve on error
2816494d708SSimon Glass  */
28254c5d08aSHeiko Schocher int uclass_first_device(enum uclass_id id, struct udevice **devp);
2836494d708SSimon Glass 
2846494d708SSimon Glass /**
285b0675050SSimon Glass  * uclass_first_device_err() - Get the first device in a uclass
286b0675050SSimon Glass  *
287b0675050SSimon Glass  * The device returned is probed if necessary, and ready for use
288b0675050SSimon Glass  *
289b0675050SSimon Glass  * @id: Uclass ID to look up
290b0675050SSimon Glass  * @devp: Returns pointer to the first device in that uclass, or NULL if none
291b0675050SSimon Glass  * @return 0 if found, -ENODEV if not found, other -ve on error
292b0675050SSimon Glass  */
293b0675050SSimon Glass int uclass_first_device_err(enum uclass_id id, struct udevice **devp);
294b0675050SSimon Glass 
295b0675050SSimon Glass /**
2966494d708SSimon Glass  * uclass_next_device() - Get the next device in a uclass
2976494d708SSimon Glass  *
298040b69afSSimon Glass  * The device returned is probed if necessary, and ready for use
299040b69afSSimon Glass  *
30030a570a9SSimon Glass  * This function is useful to start iterating through a list of devices which
30130a570a9SSimon Glass  * are functioning correctly and can be probed.
30230a570a9SSimon Glass  *
3036494d708SSimon Glass  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
30430a570a9SSimon Glass  * to the next device in the uclass if no error occurred, or NULL if there is
30530a570a9SSimon Glass  * no next device, or an error occurred with that next device.
306b0675050SSimon Glass  * @return 0 if OK (found or not found), other -ve on error
3076494d708SSimon Glass  */
30854c5d08aSHeiko Schocher int uclass_next_device(struct udevice **devp);
3096494d708SSimon Glass 
3106494d708SSimon Glass /**
311f6abd538SPatrice Chotard  * uclass_next_device_err() - Get the next device in a uclass
312f6abd538SPatrice Chotard  *
313f6abd538SPatrice Chotard  * The device returned is probed if necessary, and ready for use
314f6abd538SPatrice Chotard  *
315f6abd538SPatrice Chotard  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
316f6abd538SPatrice Chotard  * to the next device in the uclass if no error occurred, or -ENODEV if
317f6abd538SPatrice Chotard  * there is no next device.
318f6abd538SPatrice Chotard  * @return 0 if found, -ENODEV if not found, other -ve on error
319f6abd538SPatrice Chotard  */
320f6abd538SPatrice Chotard int uclass_next_device_err(struct udevice **devp);
321f6abd538SPatrice Chotard 
322f6abd538SPatrice Chotard /**
323d494131bSBin Meng  * uclass_first_device_check() - Get the first device in a uclass
32495ce385aSSimon Glass  *
32595ce385aSSimon Glass  * The device returned is probed if necessary, and ready for use
32695ce385aSSimon Glass  *
32795ce385aSSimon Glass  * This function is useful to start iterating through a list of devices which
32895ce385aSSimon Glass  * are functioning correctly and can be probed.
32995ce385aSSimon Glass  *
33095ce385aSSimon Glass  * @id: Uclass ID to look up
33195ce385aSSimon Glass  * @devp: Returns pointer to the first device in that uclass, or NULL if there
33295ce385aSSimon Glass  * is no first device
33395ce385aSSimon Glass  * @return 0 if OK (found or not found), other -ve on error. If an error occurs
33495ce385aSSimon Glass  * it is still possible to move to the next device.
33595ce385aSSimon Glass  */
33695ce385aSSimon Glass int uclass_first_device_check(enum uclass_id id, struct udevice **devp);
33795ce385aSSimon Glass 
33895ce385aSSimon Glass /**
339d494131bSBin Meng  * uclass_next_device_check() - Get the next device in a uclass
34095ce385aSSimon Glass  *
34195ce385aSSimon Glass  * The device returned is probed if necessary, and ready for use
34295ce385aSSimon Glass  *
34395ce385aSSimon Glass  * This function is useful to start iterating through a list of devices which
34495ce385aSSimon Glass  * are functioning correctly and can be probed.
34595ce385aSSimon Glass  *
34695ce385aSSimon Glass  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
34795ce385aSSimon Glass  * to the next device in the uclass if any
34895ce385aSSimon Glass  * @return 0 if OK (found or not found), other -ve on error. If an error occurs
34995ce385aSSimon Glass  * it is still possible to move to the next device.
35095ce385aSSimon Glass  */
35195ce385aSSimon Glass int uclass_next_device_check(struct udevice **devp);
35295ce385aSSimon Glass 
35395ce385aSSimon Glass /**
3545a66a8ffSSimon Glass  * uclass_resolve_seq() - Resolve a device's sequence number
3555a66a8ffSSimon Glass  *
3565a66a8ffSSimon Glass  * On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a
3575a66a8ffSSimon Glass  * sequence number automatically, or >= 0 to select a particular number.
3585a66a8ffSSimon Glass  * If the requested sequence number is in use, then this device will
3595a66a8ffSSimon Glass  * be allocated another one.
3605a66a8ffSSimon Glass  *
3615a66a8ffSSimon Glass  * Note that the device's seq value is not changed by this function.
3625a66a8ffSSimon Glass  *
3635a66a8ffSSimon Glass  * @dev: Device for which to allocate sequence number
3645a66a8ffSSimon Glass  * @return sequence number allocated, or -ve on error
3655a66a8ffSSimon Glass  */
3665a66a8ffSSimon Glass int uclass_resolve_seq(struct udevice *dev);
3675a66a8ffSSimon Glass 
3685a66a8ffSSimon Glass /**
3696494d708SSimon Glass  * uclass_foreach_dev() - Helper function to iteration through devices
3706494d708SSimon Glass  *
3716494d708SSimon Glass  * This creates a for() loop which works through the available devices in
3726494d708SSimon Glass  * a uclass in order from start to end.
3736494d708SSimon Glass  *
37454c5d08aSHeiko Schocher  * @pos: struct udevice * to hold the current device. Set to NULL when there
3756494d708SSimon Glass  * are no more devices.
376f2bc6fc3SSimon Glass  * @uc: uclass to scan
3776494d708SSimon Glass  */
3786494d708SSimon Glass #define uclass_foreach_dev(pos, uc)	\
37971f1e3f1SMasahiro Yamada 	list_for_each_entry(pos, &uc->dev_head, uclass_node)
3806494d708SSimon Glass 
3817aeac5bcSSimon Glass /**
3827aeac5bcSSimon Glass  * uclass_foreach_dev_safe() - Helper function to safely iteration through devs
3837aeac5bcSSimon Glass  *
3847aeac5bcSSimon Glass  * This creates a for() loop which works through the available devices in
3857aeac5bcSSimon Glass  * a uclass in order from start to end. Inside the loop, it is safe to remove
3867aeac5bcSSimon Glass  * @pos if required.
3877aeac5bcSSimon Glass  *
3887aeac5bcSSimon Glass  * @pos: struct udevice * to hold the current device. Set to NULL when there
3897aeac5bcSSimon Glass  * are no more devices.
3907aeac5bcSSimon Glass  * @next: struct udevice * to hold the next next
3917aeac5bcSSimon Glass  * @uc: uclass to scan
3927aeac5bcSSimon Glass  */
3937aeac5bcSSimon Glass #define uclass_foreach_dev_safe(pos, next, uc)	\
3947aeac5bcSSimon Glass 	list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node)
3957aeac5bcSSimon Glass 
396*37b596acSPatrice Chotard /**
397*37b596acSPatrice Chotard  * uclass_foreach_dev_probe() - Helper function to iteration through devices
398*37b596acSPatrice Chotard  * of given uclass
399*37b596acSPatrice Chotard  *
400*37b596acSPatrice Chotard  * This creates a for() loop which works through the available devices in
401*37b596acSPatrice Chotard  * a uclass in order from start to end. Devices are probed if necessary,
402*37b596acSPatrice Chotard  * and ready for use.
403*37b596acSPatrice Chotard  *
404*37b596acSPatrice Chotard  * @id: Uclass ID
405*37b596acSPatrice Chotard  * @dev: struct udevice * to hold the current device. Set to NULL when there
406*37b596acSPatrice Chotard  * are no more devices.
407*37b596acSPatrice Chotard  */
408*37b596acSPatrice Chotard #define uclass_foreach_dev_probe(id, dev)	\
409*37b596acSPatrice Chotard 	for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \
410*37b596acSPatrice Chotard 	     _ret = uclass_next_device_err(&dev))
411*37b596acSPatrice Chotard 
4126494d708SSimon Glass #endif
413