diff options
author | Simon Glass <sjg@chromium.org> | 2017-12-28 13:14:15 -0700 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-02-03 10:08:40 -0700 |
commit | 6e43d1b19982b1756b7c607569d1778e556d6577 (patch) | |
tree | deeea583f64dead224bba4cbad75da72efe4b5cf /drivers | |
parent | b2153075f42c2d46d310778e226bcb11f0af47f5 (diff) | |
download | u-boot-6e43d1b19982b1756b7c607569d1778e556d6577.zip u-boot-6e43d1b19982b1756b7c607569d1778e556d6577.tar.gz u-boot-6e43d1b19982b1756b7c607569d1778e556d6577.tar.bz2 |
dm: core: Add a function to look up a uclass by name
Each uclass has a driver name which we can use to look up the uclass. This
is useful for logging, where the uclass ID is used as the category.
Add a function to handle this, as well as a test.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/core/uclass.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index f5e4067..1aedaa0 100644 --- a/drivers/core/uclass.c +++ b/drivers/core/uclass.c @@ -158,6 +158,20 @@ const char *uclass_get_name(enum uclass_id id) return uc->uc_drv->name; } +enum uclass_id uclass_get_by_name(const char *name) +{ + int i; + + for (i = 0; i < UCLASS_COUNT; i++) { + struct uclass_driver *uc_drv = lists_uclass_lookup(i); + + if (uc_drv && !strcmp(uc_drv->name, name)) + return i; + } + + return UCLASS_INVALID; +} + int uclass_find_device(enum uclass_id id, int index, struct udevice **devp) { struct uclass *uc; |