diff options
author | Simon Glass <sjg@chromium.org> | 2022-10-29 19:47:14 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2022-11-07 16:24:30 -0700 |
commit | 41e751091d7cb1a71ac13ab037e0fcf4fcee67e3 (patch) | |
tree | 45cc31cf54eea520dce5bc5a681ba367bde074d7 /drivers | |
parent | d1b46595700b063faaec3e33f5754642e68b3d8f (diff) | |
download | u-boot-41e751091d7cb1a71ac13ab037e0fcf4fcee67e3.zip u-boot-41e751091d7cb1a71ac13ab037e0fcf4fcee67e3.tar.gz u-boot-41e751091d7cb1a71ac13ab037e0fcf4fcee67e3.tar.bz2 |
dm: blk: Tidy up obtaining a block device from its parent
This function now finds its block-device child by looking for a child
device of the correct uclass (UCLASS_BLK). It cannot produce a device of
any other type, so drop the superfluous check.
Provide a version which does not probe the device, since that is often
needed when setting up the device's platdata.
Also fix up the function's comment.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/blk-uclass.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index e82789f..38800a3 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -508,24 +508,28 @@ ulong blk_derase(struct blk_desc *desc, lbaint_t start, lbaint_t blkcnt) return blk_erase(desc->bdev, start, blkcnt); } -int blk_get_from_parent(struct udevice *parent, struct udevice **devp) +int blk_find_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) { + if (device_find_first_child_by_uclass(parent, UCLASS_BLK, &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; - } + *devp = dev; + + return 0; +} + +int blk_get_from_parent(struct udevice *parent, struct udevice **devp) +{ + struct udevice *dev; + int ret; + + ret = blk_find_from_parent(parent, &dev); + if (ret) + return ret; ret = device_probe(dev); if (ret) return ret; |