aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2017-05-27 11:37:17 -0600
committerJaehoon Chung <jh80.chung@samsung.com>2017-06-09 20:25:16 +0900
commit9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba (patch)
treea4f8dd89d5ec45049c7bc0c389ce59835e1bcb23 /test
parentfc69d472621b5c7513bcb8b4e1fe58ca8f5e035a (diff)
downloadu-boot-9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba.zip
u-boot-9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba.tar.gz
u-boot-9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba.tar.bz2
dm: blk: Add a way to obtain a block device from its parent
Many devices support a child block device (e.g. MMC, USB). Add a convenient way to get this device given the parent device. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'test')
-rw-r--r--test/dm/blk.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/dm/blk.c b/test/dm/blk.c
index 5c5eb82..923e8d9 100644
--- a/test/dm/blk.c
+++ b/test/dm/blk.c
@@ -150,3 +150,21 @@ static int dm_test_blk_devnum(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_blk_devnum, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we can get a block from its parent */
+static int dm_test_blk_get_from_parent(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+
+ ut_assertok(uclass_get_device(UCLASS_MMC, 0, &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+
+ ut_assertok(uclass_get_device(UCLASS_I2C, 0, &dev));
+ ut_asserteq(-ENOTBLK, blk_get_from_parent(dev, &blk));
+
+ ut_assertok(uclass_get_device(UCLASS_GPIO, 0, &dev));
+ ut_asserteq(-ENODEV, blk_get_from_parent(dev, &blk));
+
+ return 0;
+}
+DM_TEST(dm_test_blk_get_from_parent, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);