dm: core: Add a way to count the devices in a uclass

Add a function that returns the number of devices in a uclass. This can be
helpful in sizing an array that needs to hold a list of them.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2021-10-23 17:26:09 -06:00
parent 4b030177b6
commit 29fe555dec
2 changed files with 20 additions and 0 deletions

View file

@ -794,6 +794,18 @@ int uclass_probe_all(enum uclass_id id)
return 0;
}
int uclass_id_count(enum uclass_id id)
{
struct udevice *dev;
struct uclass *uc;
int count = 0;
uclass_id_foreach_dev(id, dev, uc)
count++;
return count;
}
UCLASS_DRIVER(nop) = {
.id = UCLASS_NOP,
.name = "nop",

View file

@ -425,6 +425,14 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
*/
int uclass_probe_all(enum uclass_id id);
/**
* uclass_id_count() - Count the number of devices in a uclass
*
* @id: uclass ID to look up
* @return number of devices in that uclass (0 if none)
*/
int uclass_id_count(enum uclass_id id);
/**
* uclass_id_foreach_dev() - Helper function to iteration through devices
*