[PATCH 1/4] driver: implement device_detect_by_name function

Sascha Hauer s.hauer at pengutronix.de
Wed Jun 26 03:33:13 EDT 2013


It becomes a common pattern for boards to find a device and
call device_detect on it. Add a convenience wrapper for it.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/base/driver.c | 10 ++++++++++
 include/driver.h      |  1 +
 2 files changed, 11 insertions(+)

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 810d001..16b7f06 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -100,6 +100,16 @@ int device_detect(struct device_d *dev)
 	return dev->detect(dev);
 }
 
+int device_detect_by_name(const char *devname)
+{
+	struct device_d *dev = get_device_by_name(devname);
+
+	if (!dev)
+		return -ENODEV;
+
+	return device_detect(dev);
+}
+
 static int match(struct driver_d *drv, struct device_d *dev)
 {
 	int ret;
diff --git a/include/driver.h b/include/driver.h
index 8b3af4d..b18318f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -159,6 +159,7 @@ int device_probe(struct device_d *dev);
 
 /* detect devices attached to this device (cards, disks,...) */
 int device_detect(struct device_d *dev);
+int device_detect_by_name(const char *devname);
 
 /* Unregister a device. This function can fail, e.g. when the device
  * has children.
-- 
1.8.3.1




More information about the barebox mailing list