UPSTREAM: 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. Change-Id: Id221809d6f9f818b52a5bf88f4e12d409a070f05 Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Kever Yang <kever.yang@rock-chips.com> (cherry picked from commit 6e43d1b19982b1756b7c607569d1778e556d6577)
This commit is contained in:
parent
18aa8da9a4
commit
440e24d771
|
|
@ -161,6 +161,20 @@ const char *uclass_get_name(enum uclass_id id)
|
||||||
return uc->uc_drv->name;
|
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)
|
int uclass_find_device(enum uclass_id id, int index, struct udevice **devp)
|
||||||
{
|
{
|
||||||
struct uclass *uc;
|
struct uclass *uc;
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,14 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
|
||||||
*/
|
*/
|
||||||
const char *uclass_get_name(enum uclass_id id);
|
const char *uclass_get_name(enum uclass_id id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* uclass_get_by_name() - Look up a uclass by its driver name
|
||||||
|
*
|
||||||
|
* @name: Name to look up
|
||||||
|
* @returns the associated uclass ID, or UCLASS_INVALID if not found
|
||||||
|
*/
|
||||||
|
enum uclass_id uclass_get_by_name(const char *name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uclass_get_device() - Get a uclass device based on an ID and index
|
* uclass_get_device() - Get a uclass device based on an ID and index
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -862,3 +862,12 @@ static int dm_test_device_get_uclass_id(struct unit_test_state *uts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_device_get_uclass_id, DM_TESTF_SCAN_PDATA);
|
DM_TEST(dm_test_device_get_uclass_id, DM_TESTF_SCAN_PDATA);
|
||||||
|
|
||||||
|
static int dm_test_uclass_names(struct unit_test_state *uts)
|
||||||
|
{
|
||||||
|
ut_asserteq_str("test", uclass_get_name(UCLASS_TEST));
|
||||||
|
ut_asserteq(UCLASS_TEST, uclass_get_by_name("test"));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
DM_TEST(dm_test_uclass_names, DM_TESTF_SCAN_PDATA);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue