[<prev] [next>] [day] [month] [year] [list]
Message-Id: <1559577023-558-14-git-send-email-suzuki.poulose@arm.com>
Date: Mon, 3 Jun 2019 16:49:39 +0100
From: Suzuki K Poulose <suzuki.poulose@....com>
To: linux-kernel@...r.kernel.org
Cc: gregkh@...uxfoundation.org, rafael@...nel.org,
suzuki.poulose@....com, Ulf Hansson <ulf.hansson@...aro.org>
Subject: [RFC PATCH 13/57] drivers: Add generic helper for matching device by fwnode
Instead of spilling the match function to check the device fwnode
everywhere, let us add a generic helper which can be reused by all.
Also adds a wrapper for bus_find_device to find a device by fwnode.
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@...nel.org>
Cc: Ulf Hansson <ulf.hansson@...aro.org>
Signed-off-by: Suzuki K Poulose <suzuki.poulose@....com>
---
drivers/base/core.c | 6 ++++++
include/linux/device.h | 15 +++++++++++++++
2 files changed, 21 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index d20699c..141c4f8 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -3334,3 +3334,9 @@ int device_match_of_node(struct device *dev, void *np)
return dev->of_node == np;
}
EXPORT_SYMBOL_GPL(device_match_of_node);
+
+int device_match_fwnode(struct device *dev, void *fwnode)
+{
+ return dev_fwnode(dev) == fwnode;
+}
+EXPORT_SYMBOL_GPL(device_match_fwnode);
diff --git a/include/linux/device.h b/include/linux/device.h
index fe16be4..54be931 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -164,6 +164,7 @@ struct device *subsys_dev_iter_next(struct subsys_dev_iter *iter);
void subsys_dev_iter_exit(struct subsys_dev_iter *iter);
int device_match_of_node(struct device *dev, void *np);
+int device_match_fwnode(struct device *dev, void *fwnode);
int bus_for_each_dev(struct bus_type *bus, struct device *start, void *data,
int (*fn)(struct device *dev, void *data));
@@ -188,6 +189,20 @@ static inline struct device *bus_find_device_by_of_node(struct bus_type *bus,
return bus_find_device(bus, start, np, device_match_of_node);
}
+/**
+ * bus_find_device_by_fwnode : device iterator for locating a particular device
+ * matching the fwnode.
+ * @bus: bus type
+ * @start: Device to begin with
+ * @fwnode: fwnode of the device to match.
+ */
+static inline struct device *bus_find_device_by_fwnode(struct bus_type *bus,
+ struct device *start,
+ struct fwnode_handle *fwnode)
+{
+ return bus_find_device(bus, start, fwnode, device_match_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,
--
2.7.4
Powered by blists - more mailing lists