summaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorTien Fong Chee <tien.fong.chee@intel.com>2018-07-06 16:26:36 +0800
committerTom Rini <trini@konsulko.com>2018-09-28 20:22:33 -0400
commitbc53d2637e5477ca3cd63ab942ef6038615a8e01 (patch)
tree5aea0b1ec694e13cb95477adaa59d83cb463f468 /drivers/block
parent14dfc6482a9057472ea202d2df4133a45bc3c1bc (diff)
downloadu-boot-bc53d2637e5477ca3cd63ab942ef6038615a8e01.tar.gz
u-boot-bc53d2637e5477ca3cd63ab942ef6038615a8e01.tar.xz
u-boot-bc53d2637e5477ca3cd63ab942ef6038615a8e01.zip
block: Add a function to find block device descriptor
Add a function to find the block device descriptor of the parent device. Signed-off-by: Tien Fong Chee <tien.fong.chee@intel.com> [trini: Move function declaration to avoid warning] Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/blk-uclass.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 9e0c823969..facf52711c 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -132,6 +132,29 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
}
/**
+ * blk_get_by_device() - Get the block device descriptor for the given device
+ * @dev: Instance of a storage device
+ *
+ * Return: With block device descriptor on success , NULL if there is no such
+ * block device.
+ */
+struct blk_desc *blk_get_by_device(struct udevice *dev)
+{
+ struct udevice *child_dev, *next;
+
+ device_foreach_child_safe(child_dev, next, dev) {
+ if (device_get_uclass_id(child_dev) != UCLASS_BLK)
+ continue;
+
+ return dev_get_uclass_platdata(child_dev);
+ }
+
+ debug("%s: No block device found\n", __func__);
+
+ return NULL;
+}
+
+/**
* get_desc() - Get the block device descriptor for the given device number
*
* @if_type: Interface type