[PATCH v3 09/31] dm: blk: Add a function to return the device type

Simon Glass sjg at chromium.org
Wed Jan 19 02:42:53 CET 2022


Use the uclass name to get the device type for a block device.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 drivers/block/blk-uclass.c | 8 ++++++++
 include/blk.h              | 8 ++++++++
 2 files changed, 16 insertions(+)

diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index a055387570a..cfc34417a27 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -509,6 +509,14 @@ int blk_get_from_parent(struct udevice *parent, struct udevice **devp)
 	return 0;
 }
 
+const char *blk_get_devtype(struct udevice *dev)
+{
+	struct udevice *parent = dev_get_parent(dev);
+
+	return uclass_get_name(device_get_uclass_id(parent));
+};
+
+
 int blk_find_max_devnum(enum if_type if_type)
 {
 	struct udevice *dev;
diff --git a/include/blk.h b/include/blk.h
index 133204a82e1..e88948e4c32 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -433,6 +433,14 @@ int blk_select_hwpart(struct udevice *dev, int hwpart);
  */
 int blk_get_from_parent(struct udevice *parent, struct udevice **devp);
 
+/**
+ * blk_get_devtype() - Get the device type of a block device
+ *
+ * @dev:	Block device to check
+ * @return device tree, i.e. the uclass name of its parent, e.g. "mmc"
+ */
+const char *blk_get_devtype(struct udevice *dev);
+
 /**
  * blk_get_by_device() - Get the block device descriptor for the given device
  * @dev:	Instance of a storage device
-- 
2.34.1.703.g22d0c6ccf7-goog



More information about the U-Boot mailing list