[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220715085012.2630214-6-mw@semihalf.com>
Date: Fri, 15 Jul 2022 10:50:09 +0200
From: Marcin Wojtas <mw@...ihalf.com>
To: linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
netdev@...r.kernel.org
Cc: rafael@...nel.org, andriy.shevchenko@...ux.intel.com,
sean.wang@...iatek.com, Landen.Chao@...iatek.com,
linus.walleij@...aro.org, andrew@...n.ch, vivien.didelot@...il.com,
f.fainelli@...il.com, olteanv@...il.com, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
linux@...linux.org.uk, hkallweit1@...il.com, gjb@...ihalf.com,
mw@...ihalf.com, jaz@...ihalf.com, tn@...ihalf.com,
Samer.El-Haj-Mahmoud@....com, upstream@...ihalf.com
Subject: [net-next: PATCH v2 5/8] device property: introduce fwnode_dev_node_match
This patch adds a new generic routine fwnode_dev_node_match
that can be used e.g. as a callback for class_find_device().
It searches for the struct device corresponding to a
struct fwnode_handle by iterating over device and
its parents.
Signed-off-by: Marcin Wojtas <mw@...ihalf.com>
---
include/linux/property.h | 2 ++
drivers/base/property.c | 22 ++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/linux/property.h b/include/linux/property.h
index 23330ae2b1fa..21b59ad08a39 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -456,6 +456,8 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
devcon_match_fn_t match,
void **matches, unsigned int matches_len);
+int fwnode_dev_node_match(struct device *dev, const void *data);
+
/* -------------------------------------------------------------------------- */
/* Software fwnode support - when HW description is incomplete or missing */
diff --git a/drivers/base/property.c b/drivers/base/property.c
index ed6f449f8e5c..839e7d586129 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1344,3 +1344,25 @@ int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
return count_graph + count_ref;
}
EXPORT_SYMBOL_GPL(fwnode_connection_find_matches);
+
+/*
+ * fwnode_dev_node_match - look for a device matching the struct fwnode_handle
+ * @dev: the struct device to initiate the search
+ * @data: pointer to the fwnode_handle
+ *
+ * Looks up the device structure corresponding with the fwnode by iterating
+ * over @dev and its parents.
+ * The routine can be used e.g. as a callback for class_find_device().
+ *
+ * Return: 1 - if match is found, 0 - otherwise.
+ */
+int fwnode_dev_node_match(struct device *dev, const void *data)
+{
+ for (; dev; dev = dev->parent) {
+ if (device_match_fwnode(dev, data))
+ return 1;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(fwnode_dev_node_match);
--
2.29.0
Powered by blists - more mailing lists