diff options
author | Simon Glass <sjg@chromium.org> | 2014-07-23 06:55:14 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-07-23 14:07:25 +0100 |
commit | f4cdead24a1a0c39c29c04e107c2f98ba61c5da8 (patch) | |
tree | cbabf26d3f1df2d80529543f5a4bcfeeef4a34f3 /test/dm/test-fdt.c | |
parent | b7d665705ebb29f06616b7f365ab8732e9779bf6 (diff) | |
download | u-boot-f4cdead24a1a0c39c29c04e107c2f98ba61c5da8.zip u-boot-f4cdead24a1a0c39c29c04e107c2f98ba61c5da8.tar.gz u-boot-f4cdead24a1a0c39c29c04e107c2f98ba61c5da8.tar.bz2 |
dm: Allow a device to be found by its FDT offset
Each device that was bound from a device tree has an node that caused it to
be bound. Add functions that find and return a device based on a device tree
offset.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/dm/test-fdt.c')
-rw-r--r-- | test/dm/test-fdt.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index d8e94d8..7980a68 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -215,3 +215,33 @@ static int dm_test_fdt_uclass_seq(struct dm_test_state *dms) return 0; } DM_TEST(dm_test_fdt_uclass_seq, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that we can find a device by device tree offset */ +static int dm_test_fdt_offset(struct dm_test_state *dms) +{ + const void *blob = gd->fdt_blob; + struct udevice *dev; + int node; + + node = fdt_path_offset(blob, "/e-test"); + ut_assert(node > 0); + ut_assertok(uclass_get_device_by_of_offset(UCLASS_TEST_FDT, node, + &dev)); + ut_asserteq_str("e-test", dev->name); + + /* This node should not be bound */ + node = fdt_path_offset(blob, "/junk"); + ut_assert(node > 0); + ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, + node, &dev)); + + /* This is not a top level node so should not be probed */ + node = fdt_path_offset(blob, "/some-bus/c-test"); + ut_assert(node > 0); + ut_asserteq(-ENODEV, uclass_get_device_by_of_offset(UCLASS_TEST_FDT, + node, &dev)); + + return 0; +} + +DM_TEST(dm_test_fdt_offset, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |