diff options
author | Simon Glass | 2018-11-18 08:14:31 -0700 |
---|---|---|
committer | Simon Glass | 2018-11-29 09:30:05 -0700 |
commit | 3abe1115355900172a8681f5e6fa01ca71a9b916 (patch) | |
tree | 9c2aeebe14de6b7c227845d8b2df0372bc81cd8f /test | |
parent | d0b4f68d199c075f5d734cf184f7eaf1a642083d (diff) |
dm: core: Add a few more specific child-finding functions
Add two functions which can find a child device by uclass or by name.
The first is useful with Multi-Function-Devices (MFDs) to find one of a
particular type. The second is useful when only the name is known.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/test-fdt.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index b70e3fa18ac..0fbd9be765a 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -631,3 +631,30 @@ static int dm_test_fdt_phandle(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_fdt_phandle, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test device_find_first_child_by_uclass() */ +static int dm_test_first_child(struct unit_test_state *uts) +{ + struct udevice *i2c, *dev, *dev2; + + ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c)); + ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_RTC, &dev)); + ut_asserteq_str("rtc@43", dev->name); + ut_assertok(device_find_child_by_name(i2c, "rtc@43", &dev2)); + ut_asserteq_ptr(dev, dev2); + ut_assertok(device_find_child_by_name(i2c, "rtc@61", &dev2)); + ut_asserteq_str("rtc@61", dev2->name); + + ut_assertok(device_find_first_child_by_uclass(i2c, UCLASS_I2C_EEPROM, + &dev)); + ut_asserteq_str("eeprom@2c", dev->name); + ut_assertok(device_find_child_by_name(i2c, "eeprom@2c", &dev2)); + ut_asserteq_ptr(dev, dev2); + + ut_asserteq(-ENODEV, device_find_first_child_by_uclass(i2c, + UCLASS_VIDEO, &dev)); + ut_asserteq(-ENODEV, device_find_child_by_name(i2c, "missing", &dev)); + + return 0; +} +DM_TEST(dm_test_first_child, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |