16494d708SSimon Glass /* 26494d708SSimon Glass * Copyright (c) 2013 Google, Inc 36494d708SSimon Glass * 46494d708SSimon Glass * (C) Copyright 2012 56494d708SSimon Glass * Pavel Herrmann <morpheus.ibis@gmail.com> 66494d708SSimon Glass * 76494d708SSimon Glass * SPDX-License-Identifier: GPL-2.0+ 86494d708SSimon Glass */ 96494d708SSimon Glass 106494d708SSimon Glass #ifndef _DM_UCLASS_H 116494d708SSimon Glass #define _DM_UCLASS_H 126494d708SSimon Glass 1340bb637dSSimon Glass #include <dm/ofnode.h> 146494d708SSimon Glass #include <dm/uclass-id.h> 1542c23dd2SMasahiro Yamada #include <linker_lists.h> 166494d708SSimon Glass #include <linux/list.h> 176494d708SSimon Glass 186494d708SSimon Glass /** 196494d708SSimon Glass * struct uclass - a U-Boot drive class, collecting together similar drivers 206494d708SSimon Glass * 216494d708SSimon Glass * A uclass provides an interface to a particular function, which is 226494d708SSimon Glass * implemented by one or more drivers. Every driver belongs to a uclass even 236494d708SSimon Glass * if it is the only driver in that uclass. An example uclass is GPIO, which 246494d708SSimon Glass * provides the ability to change read inputs, set and clear outputs, etc. 256494d708SSimon Glass * There may be drivers for on-chip SoC GPIO banks, I2C GPIO expanders and 266494d708SSimon Glass * PMIC IO lines, all made available in a unified way through the uclass. 276494d708SSimon Glass * 286494d708SSimon Glass * @priv: Private data for this uclass 296494d708SSimon Glass * @uc_drv: The driver for the uclass itself, not to be confused with a 306494d708SSimon Glass * 'struct driver' 31f2bc6fc3SSimon Glass * @dev_head: List of devices in this uclass (devices are attached to their 326494d708SSimon Glass * uclass when their bind method is called) 336494d708SSimon Glass * @sibling_node: Next uclass in the linked list of uclasses 346494d708SSimon Glass */ 356494d708SSimon Glass struct uclass { 366494d708SSimon Glass void *priv; 376494d708SSimon Glass struct uclass_driver *uc_drv; 386494d708SSimon Glass struct list_head dev_head; 396494d708SSimon Glass struct list_head sibling_node; 40d9da4b44SJoseph Chen #ifdef CONFIG_USING_KERNEL_DTB_V2 41d9da4b44SJoseph Chen struct list_head *u_boot_dev_head; 42d9da4b44SJoseph Chen #endif 436494d708SSimon Glass }; 446494d708SSimon Glass 45c57f806bSSimon Glass struct driver; 4654c5d08aSHeiko Schocher struct udevice; 476494d708SSimon Glass 489cc36a2bSSimon Glass /* Members of this uclass sequence themselves with aliases */ 499cc36a2bSSimon Glass #define DM_UC_FLAG_SEQ_ALIAS (1 << 0) 509cc36a2bSSimon Glass 516494d708SSimon Glass /** 526494d708SSimon Glass * struct uclass_driver - Driver for the uclass 536494d708SSimon Glass * 546494d708SSimon Glass * A uclass_driver provides a consistent interface to a set of related 556494d708SSimon Glass * drivers. 566494d708SSimon Glass * 576494d708SSimon Glass * @name: Name of uclass driver 586494d708SSimon Glass * @id: ID number of this uclass 596494d708SSimon Glass * @post_bind: Called after a new device is bound to this uclass 606494d708SSimon Glass * @pre_unbind: Called before a device is unbound from this uclass 6102c07b37SSimon Glass * @pre_probe: Called before a new device is probed 626494d708SSimon Glass * @post_probe: Called after a new device is probed 636494d708SSimon Glass * @pre_remove: Called before a device is removed 64081f2fcbSSimon Glass * @child_post_bind: Called after a child is bound to a device in this uclass 656494d708SSimon Glass * @init: Called to set up the uclass 666494d708SSimon Glass * @destroy: Called to destroy the uclass 676494d708SSimon Glass * @priv_auto_alloc_size: If non-zero this is the size of the private data 686494d708SSimon Glass * to be allocated in the uclass's ->priv pointer. If zero, then the uclass 696494d708SSimon Glass * driver is responsible for allocating any data required. 706494d708SSimon Glass * @per_device_auto_alloc_size: Each device can hold private data owned 716494d708SSimon Glass * by the uclass. If required this will be automatically allocated if this 726494d708SSimon Glass * value is non-zero. 735eaed880SPrzemyslaw Marczak * @per_device_platdata_auto_alloc_size: Each device can hold platform data 745eaed880SPrzemyslaw Marczak * owned by the uclass as 'dev->uclass_platdata'. If the value is non-zero, 755eaed880SPrzemyslaw Marczak * then this will be automatically allocated. 76dac8db2cSSimon Glass * @per_child_auto_alloc_size: Each child device (of a parent in this 77dac8db2cSSimon Glass * uclass) can hold parent data for the device/uclass. This value is only 78dac8db2cSSimon Glass * used as a falback if this member is 0 in the driver. 79ba8da9dcSSimon Glass * @per_child_platdata_auto_alloc_size: A bus likes to store information about 80ba8da9dcSSimon Glass * its children. If non-zero this is the size of this data, to be allocated 81ba8da9dcSSimon Glass * in the child device's parent_platdata pointer. This value is only used as 82ba8da9dcSSimon Glass * a falback if this member is 0 in the driver. 836494d708SSimon Glass * @ops: Uclass operations, providing the consistent interface to devices 846494d708SSimon Glass * within the uclass. 859cc36a2bSSimon Glass * @flags: Flags for this uclass (DM_UC_...) 866494d708SSimon Glass */ 876494d708SSimon Glass struct uclass_driver { 886494d708SSimon Glass const char *name; 896494d708SSimon Glass enum uclass_id id; 9054c5d08aSHeiko Schocher int (*post_bind)(struct udevice *dev); 9154c5d08aSHeiko Schocher int (*pre_unbind)(struct udevice *dev); 9202c07b37SSimon Glass int (*pre_probe)(struct udevice *dev); 9354c5d08aSHeiko Schocher int (*post_probe)(struct udevice *dev); 9454c5d08aSHeiko Schocher int (*pre_remove)(struct udevice *dev); 95081f2fcbSSimon Glass int (*child_post_bind)(struct udevice *dev); 9683c7e434SSimon Glass int (*child_pre_probe)(struct udevice *dev); 976494d708SSimon Glass int (*init)(struct uclass *class); 986494d708SSimon Glass int (*destroy)(struct uclass *class); 996494d708SSimon Glass int priv_auto_alloc_size; 1006494d708SSimon Glass int per_device_auto_alloc_size; 1015eaed880SPrzemyslaw Marczak int per_device_platdata_auto_alloc_size; 102dac8db2cSSimon Glass int per_child_auto_alloc_size; 103ba8da9dcSSimon Glass int per_child_platdata_auto_alloc_size; 1046494d708SSimon Glass const void *ops; 1059cc36a2bSSimon Glass uint32_t flags; 1066494d708SSimon Glass }; 1076494d708SSimon Glass 1086494d708SSimon Glass /* Declare a new uclass_driver */ 1096494d708SSimon Glass #define UCLASS_DRIVER(__name) \ 1106494d708SSimon Glass ll_entry_declare(struct uclass_driver, __name, uclass) 1116494d708SSimon Glass 1126494d708SSimon Glass /** 1136494d708SSimon Glass * uclass_get() - Get a uclass based on an ID, creating it if needed 1146494d708SSimon Glass * 1156494d708SSimon Glass * Every uclass is identified by an ID, a number from 0 to n-1 where n is 1166494d708SSimon Glass * the number of uclasses. This function allows looking up a uclass by its 1176494d708SSimon Glass * ID. 1186494d708SSimon Glass * 1196494d708SSimon Glass * @key: ID to look up 1206494d708SSimon Glass * @ucp: Returns pointer to uclass (there is only one per ID) 1216494d708SSimon Glass * @return 0 if OK, -ve on error 1226494d708SSimon Glass */ 1236494d708SSimon Glass int uclass_get(enum uclass_id key, struct uclass **ucp); 1246494d708SSimon Glass 1256494d708SSimon Glass /** 1260a5f6f86SSimon Glass * uclass_get_name() - Get the name of a uclass driver 1270a5f6f86SSimon Glass * 1280a5f6f86SSimon Glass * @id: ID to look up 1290a5f6f86SSimon Glass * @returns the name of the uclass driver for that ID, or NULL if none 1300a5f6f86SSimon Glass */ 1310a5f6f86SSimon Glass const char *uclass_get_name(enum uclass_id id); 1320a5f6f86SSimon Glass 1330a5f6f86SSimon Glass /** 134440e24d7SSimon Glass * uclass_get_by_name() - Look up a uclass by its driver name 135440e24d7SSimon Glass * 136440e24d7SSimon Glass * @name: Name to look up 137440e24d7SSimon Glass * @returns the associated uclass ID, or UCLASS_INVALID if not found 138440e24d7SSimon Glass */ 139440e24d7SSimon Glass enum uclass_id uclass_get_by_name(const char *name); 140440e24d7SSimon Glass 141440e24d7SSimon Glass /** 1426494d708SSimon Glass * uclass_get_device() - Get a uclass device based on an ID and index 1436494d708SSimon Glass * 144f2bc6fc3SSimon Glass * The device is probed to activate it ready for use. 145f2bc6fc3SSimon Glass * 1460040b944SSimon Glass * @id: ID to look up 1476494d708SSimon Glass * @index: Device number within that uclass (0=first) 148f2bc6fc3SSimon Glass * @devp: Returns pointer to device (there is only one per for each ID) 1496494d708SSimon Glass * @return 0 if OK, -ve on error 1506494d708SSimon Glass */ 151f2bc6fc3SSimon Glass int uclass_get_device(enum uclass_id id, int index, struct udevice **devp); 1526494d708SSimon Glass 1536494d708SSimon Glass /** 15474356d7fSSimon Glass * uclass_get_device_by_name() - Get a uclass device by its name 155b7af1a2dSPrzemyslaw Marczak * 156a7b82502SPrzemyslaw Marczak * This searches the devices in the uclass for one with the exactly given name. 157b7af1a2dSPrzemyslaw Marczak * 158b7af1a2dSPrzemyslaw Marczak * The device is probed to activate it ready for use. 159b7af1a2dSPrzemyslaw Marczak * 160b7af1a2dSPrzemyslaw Marczak * @id: ID to look up 161b7af1a2dSPrzemyslaw Marczak * @name: name of a device to get 162b7af1a2dSPrzemyslaw Marczak * @devp: Returns pointer to device (the first one with the name) 163b7af1a2dSPrzemyslaw Marczak * @return 0 if OK, -ve on error 164b7af1a2dSPrzemyslaw Marczak */ 165b7af1a2dSPrzemyslaw Marczak int uclass_get_device_by_name(enum uclass_id id, const char *name, 166b7af1a2dSPrzemyslaw Marczak struct udevice **devp); 167b7af1a2dSPrzemyslaw Marczak 168b7af1a2dSPrzemyslaw Marczak /** 1695a66a8ffSSimon Glass * uclass_get_device_by_seq() - Get a uclass device based on an ID and sequence 1705a66a8ffSSimon Glass * 1715a66a8ffSSimon Glass * If an active device has this sequence it will be returned. If there is no 1725a66a8ffSSimon Glass * such device then this will check for a device that is requesting this 1735a66a8ffSSimon Glass * sequence. 1745a66a8ffSSimon Glass * 1755a66a8ffSSimon Glass * The device is probed to activate it ready for use. 1765a66a8ffSSimon Glass * 1775a66a8ffSSimon Glass * @id: ID to look up 1785a66a8ffSSimon Glass * @seq: Sequence number to find (0=first) 1795a66a8ffSSimon Glass * @devp: Returns pointer to device (there is only one for each seq) 1805a66a8ffSSimon Glass * @return 0 if OK, -ve on error 1815a66a8ffSSimon Glass */ 1825a66a8ffSSimon Glass int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp); 1835a66a8ffSSimon Glass 1845a66a8ffSSimon Glass /** 185f4cdead2SSimon Glass * uclass_get_device_by_of_offset() - Get a uclass device by device tree node 186f4cdead2SSimon Glass * 187f4cdead2SSimon Glass * This searches the devices in the uclass for one attached to the given 188f4cdead2SSimon Glass * device tree node. 189f4cdead2SSimon Glass * 190f4cdead2SSimon Glass * The device is probed to activate it ready for use. 191f4cdead2SSimon Glass * 192f4cdead2SSimon Glass * @id: ID to look up 193f4cdead2SSimon Glass * @node: Device tree offset to search for (if -ve then -ENODEV is returned) 194f4cdead2SSimon Glass * @devp: Returns pointer to device (there is only one for each node) 195f4cdead2SSimon Glass * @return 0 if OK, -ve on error 196f4cdead2SSimon Glass */ 197f4cdead2SSimon Glass int uclass_get_device_by_of_offset(enum uclass_id id, int node, 198f4cdead2SSimon Glass struct udevice **devp); 199f4cdead2SSimon Glass 200f4cdead2SSimon Glass /** 20140bb637dSSimon Glass * uclass_get_device_by_ofnode() - Get a uclass device by device tree node 20240bb637dSSimon Glass * 20340bb637dSSimon Glass * This searches the devices in the uclass for one attached to the given 20440bb637dSSimon Glass * device tree node. 20540bb637dSSimon Glass * 20640bb637dSSimon Glass * The device is probed to activate it ready for use. 20740bb637dSSimon Glass * 20840bb637dSSimon Glass * @id: ID to look up 20940bb637dSSimon Glass * @np: Device tree node to search for (if NULL then -ENODEV is returned) 21040bb637dSSimon Glass * @devp: Returns pointer to device (there is only one for each node) 21140bb637dSSimon Glass * @return 0 if OK, -ve on error 21240bb637dSSimon Glass */ 21340bb637dSSimon Glass int uclass_get_device_by_ofnode(enum uclass_id id, ofnode node, 21440bb637dSSimon Glass struct udevice **devp); 21540bb637dSSimon Glass 21640bb637dSSimon Glass /** 2171d5894f2SKever Yang * uclass_get_device_by_phandle_id() - Get a uclass device by phandle id 2181d5894f2SKever Yang * 2191d5894f2SKever Yang * This searches the devices in the uclass for one with the given phandle id. 2201d5894f2SKever Yang * 2211d5894f2SKever Yang * The device is probed to activate it ready for use. 2221d5894f2SKever Yang * 2231d5894f2SKever Yang * @id: uclass ID to look up 2241d5894f2SKever Yang * @phandle_id: the phandle id to look up 2251d5894f2SKever Yang * @devp: Returns pointer to device (there is only one for each node) 2261d5894f2SKever Yang * @return 0 if OK, -ENODEV if there is no device match the phandle, other 2271d5894f2SKever Yang * -ve on error 2281d5894f2SKever Yang */ 2297862d7bfSJianqun Xu int uclass_get_device_by_phandle_id(enum uclass_id id, uint phandle_id, 2301d5894f2SKever Yang struct udevice **devp); 2311d5894f2SKever Yang 2321d5894f2SKever Yang /** 233d82ba4c0SSimon Glass * uclass_get_device_by_phandle() - Get a uclass device by phandle 234d82ba4c0SSimon Glass * 235d82ba4c0SSimon Glass * This searches the devices in the uclass for one with the given phandle. 236d82ba4c0SSimon Glass * 237d82ba4c0SSimon Glass * The device is probed to activate it ready for use. 238d82ba4c0SSimon Glass * 239d82ba4c0SSimon Glass * @id: uclass ID to look up 240d82ba4c0SSimon Glass * @parent: Parent device containing the phandle pointer 241d82ba4c0SSimon Glass * @name: Name of property in the parent device node 242d82ba4c0SSimon Glass * @devp: Returns pointer to device (there is only one for each node) 243d82ba4c0SSimon Glass * @return 0 if OK, -ENOENT if there is no @name present in the node, other 244d82ba4c0SSimon Glass * -ve on error 245d82ba4c0SSimon Glass */ 246d82ba4c0SSimon Glass int uclass_get_device_by_phandle(enum uclass_id id, struct udevice *parent, 247d82ba4c0SSimon Glass const char *name, struct udevice **devp); 248d82ba4c0SSimon Glass 249d82ba4c0SSimon Glass /** 250c57f806bSSimon Glass * uclass_get_device_by_driver() - Get a uclass device for a driver 251c57f806bSSimon Glass * 252c57f806bSSimon Glass * This searches the devices in the uclass for one that uses the given 253c57f806bSSimon Glass * driver. Use DM_GET_DRIVER(name) for the @drv argument, where 'name' is 254c57f806bSSimon Glass * the driver name - as used in U_BOOT_DRIVER(name). 255c57f806bSSimon Glass * 256c57f806bSSimon Glass * The device is probed to activate it ready for use. 257c57f806bSSimon Glass * 258c57f806bSSimon Glass * @id: ID to look up 259c57f806bSSimon Glass * @drv: Driver to look for 260c57f806bSSimon Glass * @devp: Returns pointer to the first device with that driver 261c57f806bSSimon Glass * @return 0 if OK, -ve on error 262c57f806bSSimon Glass */ 263c57f806bSSimon Glass int uclass_get_device_by_driver(enum uclass_id id, const struct driver *drv, 264c57f806bSSimon Glass struct udevice **devp); 265c57f806bSSimon Glass 266c57f806bSSimon Glass /** 2676494d708SSimon Glass * uclass_first_device() - Get the first device in a uclass 2686494d708SSimon Glass * 269040b69afSSimon Glass * The device returned is probed if necessary, and ready for use 270*1f383ee4SMichal Suchanek * Devices that fail to probe are skipped 271040b69afSSimon Glass * 27230a570a9SSimon Glass * This function is useful to start iterating through a list of devices which 27330a570a9SSimon Glass * are functioning correctly and can be probed. 27430a570a9SSimon Glass * 2756494d708SSimon Glass * @id: Uclass ID to look up 27630a570a9SSimon Glass * @devp: Returns pointer to the first device in that uclass if no error 277*1f383ee4SMichal Suchanek * occurred, or NULL if there is no usable device 2786494d708SSimon Glass */ 279*1f383ee4SMichal Suchanek void uclass_first_device(enum uclass_id id, struct udevice **devp); 2806494d708SSimon Glass 2816494d708SSimon Glass /** 2826494d708SSimon Glass * uclass_next_device() - Get the next device in a uclass 2836494d708SSimon Glass * 284040b69afSSimon Glass * The device returned is probed if necessary, and ready for use 285*1f383ee4SMichal Suchanek * Devices that fail to probe are skipped 286040b69afSSimon Glass * 28730a570a9SSimon Glass * This function is useful to start iterating through a list of devices which 28830a570a9SSimon Glass * are functioning correctly and can be probed. 28930a570a9SSimon Glass * 2906494d708SSimon Glass * @devp: On entry, pointer to device to lookup. On exit, returns pointer 29130a570a9SSimon Glass * to the next device in the uclass if no error occurred, or NULL if there is 292*1f383ee4SMichal Suchanek * no next device 2936494d708SSimon Glass */ 294*1f383ee4SMichal Suchanek void uclass_next_device(struct udevice **devp); 2956494d708SSimon Glass 2966494d708SSimon Glass /** 297d1cab63eSMichal Suchanek * uclass_first_device_err() - Get the first device in a uclass 298d1cab63eSMichal Suchanek * 299d1cab63eSMichal Suchanek * The device returned is probed if necessary, and ready for use 300d1cab63eSMichal Suchanek * 301d1cab63eSMichal Suchanek * @id: Uclass ID to look up 302d1cab63eSMichal Suchanek * @devp: Returns pointer to the first device in that uclass, or NULL if none 303d1cab63eSMichal Suchanek * Return: 0 if found, -ENODEV if not found, other -ve on error 304d1cab63eSMichal Suchanek */ 305d1cab63eSMichal Suchanek int uclass_first_device_err(enum uclass_id id, struct udevice **devp); 306d1cab63eSMichal Suchanek 307d1cab63eSMichal Suchanek /** 308d07fa43eSPatrice Chotard * uclass_next_device_err() - Get the next device in a uclass 309d07fa43eSPatrice Chotard * 310d07fa43eSPatrice Chotard * The device returned is probed if necessary, and ready for use 311d07fa43eSPatrice Chotard * 312d07fa43eSPatrice Chotard * @devp: On entry, pointer to device to lookup. On exit, returns pointer 313d07fa43eSPatrice Chotard * to the next device in the uclass if no error occurred, or -ENODEV if 314d07fa43eSPatrice Chotard * there is no next device. 315d07fa43eSPatrice Chotard * @return 0 if found, -ENODEV if not found, other -ve on error 316d07fa43eSPatrice Chotard */ 317d07fa43eSPatrice Chotard int uclass_next_device_err(struct udevice **devp); 318d07fa43eSPatrice Chotard 319d07fa43eSPatrice Chotard /** 320739ce16aSBin Meng * uclass_first_device_check() - Get the first device in a uclass 32195ce385aSSimon Glass * 32295ce385aSSimon Glass * The device returned is probed if necessary, and ready for use 32395ce385aSSimon Glass * 32495ce385aSSimon Glass * This function is useful to start iterating through a list of devices which 32595ce385aSSimon Glass * are functioning correctly and can be probed. 32695ce385aSSimon Glass * 32795ce385aSSimon Glass * @id: Uclass ID to look up 32895ce385aSSimon Glass * @devp: Returns pointer to the first device in that uclass, or NULL if there 32995ce385aSSimon Glass * is no first device 33095ce385aSSimon Glass * @return 0 if OK (found or not found), other -ve on error. If an error occurs 33195ce385aSSimon Glass * it is still possible to move to the next device. 33295ce385aSSimon Glass */ 33395ce385aSSimon Glass int uclass_first_device_check(enum uclass_id id, struct udevice **devp); 33495ce385aSSimon Glass 33595ce385aSSimon Glass /** 336739ce16aSBin Meng * uclass_next_device_check() - Get the next device in a uclass 33795ce385aSSimon Glass * 33895ce385aSSimon Glass * The device returned is probed if necessary, and ready for use 33995ce385aSSimon Glass * 34095ce385aSSimon Glass * This function is useful to start iterating through a list of devices which 34195ce385aSSimon Glass * are functioning correctly and can be probed. 34295ce385aSSimon Glass * 34395ce385aSSimon Glass * @devp: On entry, pointer to device to lookup. On exit, returns pointer 34495ce385aSSimon Glass * to the next device in the uclass if any 34595ce385aSSimon Glass * @return 0 if OK (found or not found), other -ve on error. If an error occurs 34695ce385aSSimon Glass * it is still possible to move to the next device. 34795ce385aSSimon Glass */ 34895ce385aSSimon Glass int uclass_next_device_check(struct udevice **devp); 34995ce385aSSimon Glass 35095ce385aSSimon Glass /** 351771aadbaSSimon Glass * uclass_first_device_drvdata() - Find the first device with given driver data 352771aadbaSSimon Glass * 353771aadbaSSimon Glass * This searches through the devices for a particular uclass looking for one 354771aadbaSSimon Glass * that has the given driver data. 355771aadbaSSimon Glass * 356771aadbaSSimon Glass * @id: Uclass ID to check 357771aadbaSSimon Glass * @driver_data: Driver data to search for 358771aadbaSSimon Glass * @devp: Returns pointer to the first matching device in that uclass, if found 359771aadbaSSimon Glass * @return 0 if found, -ENODEV if not found, other -ve on error 360771aadbaSSimon Glass */ 361771aadbaSSimon Glass int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data, 362771aadbaSSimon Glass struct udevice **devp); 363771aadbaSSimon Glass 364771aadbaSSimon Glass /** 3655a66a8ffSSimon Glass * uclass_resolve_seq() - Resolve a device's sequence number 3665a66a8ffSSimon Glass * 3675a66a8ffSSimon Glass * On entry dev->seq is -1, and dev->req_seq may be -1 (to allocate a 3685a66a8ffSSimon Glass * sequence number automatically, or >= 0 to select a particular number. 3695a66a8ffSSimon Glass * If the requested sequence number is in use, then this device will 3705a66a8ffSSimon Glass * be allocated another one. 3715a66a8ffSSimon Glass * 3725a66a8ffSSimon Glass * Note that the device's seq value is not changed by this function. 3735a66a8ffSSimon Glass * 3745a66a8ffSSimon Glass * @dev: Device for which to allocate sequence number 3755a66a8ffSSimon Glass * @return sequence number allocated, or -ve on error 3765a66a8ffSSimon Glass */ 3775a66a8ffSSimon Glass int uclass_resolve_seq(struct udevice *dev); 3785a66a8ffSSimon Glass 3795a66a8ffSSimon Glass /** 3802c3c84fcSSimon Glass * uclass_id_foreach_dev() - Helper function to iteration through devices 3812c3c84fcSSimon Glass * 3822c3c84fcSSimon Glass * This creates a for() loop which works through the available devices in 3832c3c84fcSSimon Glass * a uclass ID in order from start to end. 3842c3c84fcSSimon Glass * 3852c3c84fcSSimon Glass * If for some reason the uclass cannot be found, this does nothing. 3862c3c84fcSSimon Glass * 3872c3c84fcSSimon Glass * @id: enum uclass_id ID to use 3882c3c84fcSSimon Glass * @pos: struct udevice * to hold the current device. Set to NULL when there 3892c3c84fcSSimon Glass * are no more devices. 3902c3c84fcSSimon Glass * @uc: temporary uclass variable (struct udevice *) 3912c3c84fcSSimon Glass */ 3922c3c84fcSSimon Glass #define uclass_id_foreach_dev(id, pos, uc) \ 3932c3c84fcSSimon Glass if (!uclass_get(id, &uc)) \ 3942c3c84fcSSimon Glass list_for_each_entry(pos, &uc->dev_head, uclass_node) 3952c3c84fcSSimon Glass 3962c3c84fcSSimon Glass /** 3976494d708SSimon Glass * uclass_foreach_dev() - Helper function to iteration through devices 3986494d708SSimon Glass * 3996494d708SSimon Glass * This creates a for() loop which works through the available devices in 4006494d708SSimon Glass * a uclass in order from start to end. 4016494d708SSimon Glass * 40254c5d08aSHeiko Schocher * @pos: struct udevice * to hold the current device. Set to NULL when there 4036494d708SSimon Glass * are no more devices. 404f2bc6fc3SSimon Glass * @uc: uclass to scan 4056494d708SSimon Glass */ 4066494d708SSimon Glass #define uclass_foreach_dev(pos, uc) \ 40771f1e3f1SMasahiro Yamada list_for_each_entry(pos, &uc->dev_head, uclass_node) 4086494d708SSimon Glass 4097aeac5bcSSimon Glass /** 4107aeac5bcSSimon Glass * uclass_foreach_dev_safe() - Helper function to safely iteration through devs 4117aeac5bcSSimon Glass * 4127aeac5bcSSimon Glass * This creates a for() loop which works through the available devices in 4137aeac5bcSSimon Glass * a uclass in order from start to end. Inside the loop, it is safe to remove 4147aeac5bcSSimon Glass * @pos if required. 4157aeac5bcSSimon Glass * 4167aeac5bcSSimon Glass * @pos: struct udevice * to hold the current device. Set to NULL when there 4177aeac5bcSSimon Glass * are no more devices. 4187aeac5bcSSimon Glass * @next: struct udevice * to hold the next next 4197aeac5bcSSimon Glass * @uc: uclass to scan 4207aeac5bcSSimon Glass */ 4217aeac5bcSSimon Glass #define uclass_foreach_dev_safe(pos, next, uc) \ 4227aeac5bcSSimon Glass list_for_each_entry_safe(pos, next, &uc->dev_head, uclass_node) 4237aeac5bcSSimon Glass 424563bfcf9SPatrice Chotard /** 425563bfcf9SPatrice Chotard * uclass_foreach_dev_probe() - Helper function to iteration through devices 426563bfcf9SPatrice Chotard * of given uclass 427563bfcf9SPatrice Chotard * 428563bfcf9SPatrice Chotard * This creates a for() loop which works through the available devices in 429563bfcf9SPatrice Chotard * a uclass in order from start to end. Devices are probed if necessary, 430563bfcf9SPatrice Chotard * and ready for use. 431563bfcf9SPatrice Chotard * 432563bfcf9SPatrice Chotard * @id: Uclass ID 433563bfcf9SPatrice Chotard * @dev: struct udevice * to hold the current device. Set to NULL when there 434563bfcf9SPatrice Chotard * are no more devices. 435563bfcf9SPatrice Chotard */ 436563bfcf9SPatrice Chotard #define uclass_foreach_dev_probe(id, dev) \ 437563bfcf9SPatrice Chotard for (int _ret = uclass_first_device_err(id, &dev); !_ret && dev; \ 438563bfcf9SPatrice Chotard _ret = uclass_next_device_err(&dev)) 439563bfcf9SPatrice Chotard 4406494d708SSimon Glass #endif 441