diff options
author | Simon Glass <sjg@chromium.org> | 2017-05-27 11:37:17 -0600 |
---|---|---|
committer | Jaehoon Chung <jh80.chung@samsung.com> | 2017-06-09 20:25:16 +0900 |
commit | 9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba (patch) | |
tree | a4f8dd89d5ec45049c7bc0c389ce59835e1bcb23 /drivers/block | |
parent | fc69d472621b5c7513bcb8b4e1fe58ca8f5e035a (diff) | |
download | u-boot-9f103b9cb5f8de4f196b5ef8f6ddb4749cd732ba.tar.gz |
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 'drivers/block')
-rw-r--r-- | drivers/block/blk-uclass.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index 6145675271..23f131b7ad 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -453,6 +453,32 @@ int blk_prepare_device(struct udevice *dev) return 0; } +int blk_get_from_parent(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + enum uclass_id id; + int ret; + + device_find_first_child(parent, &dev); + if (!dev) { + debug("%s: No block device found for parent '%s'\n", __func__, + parent->name); + return -ENODEV; + } + id = device_get_uclass_id(dev); + if (id != UCLASS_BLK) { + debug("%s: Incorrect uclass %s for block device '%s'\n", + __func__, uclass_get_name(id), dev->name); + return -ENOTBLK; + } + ret = device_probe(dev); + if (ret) + return ret; + *devp = dev; + + return 0; +} + int blk_find_max_devnum(enum if_type if_type) { struct udevice *dev; |