All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode
@ 2018-09-25  5:28 Silesh C V
  2018-09-25  5:28 ` [PATCH v2 2/2] treewide: use bus_find_device_by_fwnode Silesh C V
  2018-10-08  8:13 ` [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode Rafael J. Wysocki
  0 siblings, 2 replies; 10+ messages in thread
From: Silesh C V @ 2018-09-25  5:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki
  Cc: linux-kernel, Rob Herring, Frank Rowand, Silesh C V

Some drivers need to find the device on a bus having a specific firmware
node. Currently, such drivers have their own implementations to do this.
Provide a helper similar to bus_find_device_by_name so that each driver
does not have to reinvent this.

Signed-off-by: Silesh C V <svellattu@mvista.com>
---
 drivers/base/bus.c     | 26 ++++++++++++++++++++++++++
 include/linux/device.h |  3 +++
 2 files changed, 29 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8bfd27e..148b198 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -17,6 +17,7 @@
 #include <linux/string.h>
 #include <linux/mutex.h>
 #include <linux/sysfs.h>
+#include <linux/of.h>
 #include "base.h"
 #include "power/power.h"
 
@@ -373,6 +374,31 @@ struct device *bus_find_device_by_name(struct bus_type *bus,
 }
 EXPORT_SYMBOL_GPL(bus_find_device_by_name);
 
+static int match_fwnode(struct device *dev, void *data)
+{
+	struct fwnode_handle *fwnode = data;
+	struct device_node *of_node = to_of_node(fwnode);
+
+	if (of_node)
+		return dev->of_node == of_node;
+	else
+		return dev->fwnode == fwnode;
+}
+
+/**
+ * bus_find_device_by_fwnode - device iterator for locating a particular device
+ * having a specific firmware node
+ * @bus: bus type
+ * @start: Device to begin with
+ * @fwnode: firmware node of the device to match
+ */
+struct device *bus_find_device_by_fwnode(struct bus_type *bus, struct device *start,
+					struct fwnode_handle *fwnode)
+{
+	return bus_find_device(bus, start, (void *)fwnode, match_fwnode);
+}
+EXPORT_SYMBOL_GPL(bus_find_device_by_fwnode);
+
 /**
  * subsys_find_device_by_id - find a device with a specific enumeration number
  * @subsys: subsystem
diff --git a/include/linux/device.h b/include/linux/device.h
index 8f88254..09384f6 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -171,6 +171,9 @@ struct device *bus_find_device(struct bus_type *bus, struct device *start,
 struct device *bus_find_device_by_name(struct bus_type *bus,
 				       struct device *start,
 				       const char *name);
+struct device *bus_find_device_by_fwnode(struct bus_type *bus,
+				       struct device *start,
+				       struct fwnode_handle *fwnode);
 struct device *subsys_find_device_by_id(struct bus_type *bus, unsigned int id,
 					struct device *hint);
 int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-10-09  3:13 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25  5:28 [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode Silesh C V
2018-09-25  5:28 ` [PATCH v2 2/2] treewide: use bus_find_device_by_fwnode Silesh C V
2018-09-25  7:04   ` Greg Kroah-Hartman
2018-09-25  7:31     ` Silesh C V
2018-09-25  7:41       ` Silesh C V
2018-10-08  8:08         ` Rafael J. Wysocki
2018-10-08 15:45         ` Rob Herring
2018-10-09  3:13           ` Silesh C V
2018-10-08  8:13 ` [PATCH v2 1/2] Driver core: add bus_find_device_by_fwnode Rafael J. Wysocki
2018-10-09  3:11   ` Silesh C V

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.