block: Add a function to find block device descriptor
authorTien Fong Chee <tien.fong.chee@intel.com>
Fri, 6 Jul 2018 08:26:36 +0000 (16:26 +0800)
committerTom Rini <trini@konsulko.com>
Sat, 29 Sep 2018 00:22:33 +0000 (20:22 -0400)
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>
drivers/block/blk-uclass.c
include/blk.h

index 9e0c8239690d295406872a695629a248f33952f3..facf52711ccfd735171ba7c0235aa275ad089af1 100644 (file)
@@ -131,6 +131,29 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
        return NULL;
 }
 
+/**
+ * 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
  *
index 86f6d5057f23e7155a6ead3248d426baef94d171..6af219681cd1b52caee57fbb5dc07511933ed165 100644 (file)
@@ -406,6 +406,15 @@ int blk_select_hwpart(struct udevice *dev, int hwpart);
  */
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
 
+/**
+ * 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);
+
 #else
 #include <errno.h>
 /*