]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Add a way to count the devices in a uclass
authorSimon Glass <sjg@chromium.org>
Sat, 23 Oct 2021 23:26:09 +0000 (17:26 -0600)
committerSimon Glass <sjg@chromium.org>
Sun, 28 Nov 2021 23:51:51 +0000 (16:51 -0700)
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>
drivers/core/uclass.c
include/dm/uclass.h

index 3de5f27fe4ae819249b6900e39e2caeb74c07a78..2aa214307754aa5f3c051076d2a5bfd0e77b6f68 100644 (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",
index aea2f34fce14b7022f9073825e60cdc7e0909368..f1fd2ba246315b35dedebe4c919d0d4abd8f4228 100644 (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
  *