[U-Boot] [PATCH 01/39] dm: blk: Add a function to find an interface-type name
Simon Glass
sjg at chromium.org
Tue Jul 4 19:48:53 UTC 2017
Add a function to find the name of an interface type (e.g. "sata", "scsi")
from the interface type enum.
This is useful for generic code (not specific to SATA or SCSI, for
example) that wants to display the type of interface it is dealing with.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
drivers/block/blk-uclass.c | 5 +++++
drivers/block/blk_legacy.c | 7 +++++++
include/blk.h | 8 ++++++++
3 files changed, 20 insertions(+)
diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c
index 23f131b7ad..fbe5f30fc0 100644
--- a/drivers/block/blk-uclass.c
+++ b/drivers/block/blk-uclass.c
@@ -55,6 +55,11 @@ static enum uclass_id if_type_to_uclass_id(enum if_type if_type)
return if_type_uclass_id[if_type];
}
+const char *blk_get_if_type_name(enum if_type if_type)
+{
+ return if_typename_str[if_type];
+}
+
struct blk_desc *blk_get_devnum_by_type(enum if_type if_type, int devnum)
{
struct blk_desc *desc;
diff --git a/drivers/block/blk_legacy.c b/drivers/block/blk_legacy.c
index 7b90a8a6e1..981872ecb3 100644
--- a/drivers/block/blk_legacy.c
+++ b/drivers/block/blk_legacy.c
@@ -38,6 +38,13 @@ static struct blk_driver *blk_driver_lookup_typename(const char *if_typename)
return NULL;
}
+const char *blk_get_if_type_name(enum if_type if_type)
+{
+ struct blk_driver *drv = blk_driver_lookup_type(if_type);
+
+ return drv ? drv->if_typename : NULL;
+}
+
/**
* get_desc() - Get the block device descriptor for the given device number
*
diff --git a/include/blk.h b/include/blk.h
index 1e6239ac9e..69076d3683 100644
--- a/include/blk.h
+++ b/include/blk.h
@@ -623,4 +623,12 @@ ulong blk_write_devnum(enum if_type if_type, int devnum, lbaint_t start,
*/
int blk_select_hwpart_devnum(enum if_type if_type, int devnum, int hwpart);
+/**
+ * blk_get_if_type_name() - Get the name of an interface type
+ *
+ * @if_type: Interface type to check
+ * @return name of interface, or NULL if none
+ */
+const char *blk_get_if_type_name(enum if_type if_type);
+
#endif
--
2.13.2.725.g09c95d1e9-goog
More information about the U-Boot
mailing list