[U-Boot] [PATCH V4 07/10] dm: core: uclass: add function: uclass_get_device_by_name()

Przemyslaw Marczak p.marczak at samsung.com
Wed Apr 15 13:07:23 CEST 2015


This commit extends the driver model uclass's API by function:
- uclass_get_device_by_name()

And this function returns the device if:
- uclass with given ID, exists,
- device with exactly given name(dev->name), exists,
- device probe, doesn't return an error.

The returned device is activated and ready to use.

Note:
This function returns the first device, which name is equal
to the given one. This means, that using this function you must
assume, that the device name is unique in the given uclass's ID
device list.

Signed-off-by: Przemyslaw Marczak <p.marczak at samsung.com>
Cc: Simon Glass <sjg at chromium.org>
---
Changes V4:
- new commit
---
 drivers/core/uclass.c | 11 +++++++++++
 include/dm/uclass.h   | 15 +++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 219d765..a139134 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -298,6 +298,17 @@ int uclass_get_device(enum uclass_id id, int index, struct udevice **devp)
 	return uclass_get_device_tail(dev, ret, devp);
 }
 
+int uclass_get_device_by_name(enum uclass_id id, const char *name,
+			      struct udevice **devp)
+{
+	struct udevice *dev;
+	int ret;
+
+	*devp = NULL;
+	ret = uclass_find_device_by_name(id, name, &dev);
+	return uclass_get_device_tail(dev, ret, devp);
+}
+
 int uclass_get_device_by_seq(enum uclass_id id, int seq, struct udevice **devp)
 {
 	struct udevice *dev;
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index b271472..66e0ea5 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -130,6 +130,21 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
 int uclass_get_device(enum uclass_id id, int index, struct udevice **devp);
 
 /**
+ * uclass_get_device_by_name() - Get a uclass device by it's name
+ *
+ * This searches the devices in the uclass for one with the given name.
+ *
+ * The device is probed to activate it ready for use.
+ *
+ * @id: ID to look up
+ * @name: name of a device to get
+ * @devp: Returns pointer to device (the first one with the name)
+ * @return 0 if OK, -ve on error
+ */
+int uclass_get_device_by_name(enum uclass_id id, const char *name,
+			      struct udevice **devp);
+
+/**
  * uclass_get_device_by_seq() - Get a uclass device based on an ID and sequence
  *
  * If an active device has this sequence it will be returned. If there is no
-- 
1.9.1



More information about the U-Boot mailing list