From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jNttD-0005Tg-Mc for barebox@lists.infradead.org; Mon, 13 Apr 2020 07:52:21 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jNttC-0003RE-IY for barebox@lists.infradead.org; Mon, 13 Apr 2020 09:52:18 +0200 Received: from afa by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1jNttC-0005E1-9n for barebox@lists.infradead.org; Mon, 13 Apr 2020 09:52:18 +0200 From: Ahmad Fatoum Date: Mon, 13 Apr 2020 09:51:50 +0200 Message-Id: <20200413075204.17544-8-a.fatoum@pengutronix.de> In-Reply-To: <20200413075204.17544-1-a.fatoum@pengutronix.de> References: <20200413075204.17544-1-a.fatoum@pengutronix.de> MIME-Version: 1.0 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "barebox" Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: [PATCH 07/21] of: port Linux of_get_compatible_child helper To: barebox@lists.infradead.org Incoming Linux code port makes use of the helper. Add it now instead of having to open-code it later. Signed-off-by: Ahmad Fatoum --- drivers/of/base.c | 25 +++++++++++++++++++++++++ include/of.h | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 346d72e1e09e..5a0374a82c5c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1712,6 +1712,31 @@ int of_get_available_child_count(const struct device_node *parent) } EXPORT_SYMBOL(of_get_available_child_count); +/** + * of_get_compatible_child - Find compatible child node + * @parent: parent node + * @compatible: compatible string + * + * Lookup child node whose compatible property contains the given compatible + * string. + * + * Returns a node pointer with refcount incremented, use of_node_put() on it + * when done; or NULL if not found. + */ +struct device_node *of_get_compatible_child(const struct device_node *parent, + const char *compatible) +{ + struct device_node *child; + + for_each_child_of_node(parent, child) { + if (of_device_is_compatible(child, compatible)) + break; + } + + return child; +} +EXPORT_SYMBOL(of_get_compatible_child); + /** * of_get_child_by_name - Find the child node by name for a given parent * @node: parent node diff --git a/include/of.h b/include/of.h index eea5abae459b..85d55f9b57dc 100644 --- a/include/of.h +++ b/include/of.h @@ -177,6 +177,8 @@ struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev); extern int of_get_child_count(const struct device_node *parent); extern int of_get_available_child_count(const struct device_node *parent); +extern struct device_node *of_get_compatible_child(const struct device_node *parent, + const char *compatible); extern struct device_node *of_get_child_by_name(const struct device_node *node, const char *name); extern char *of_get_reproducible_name(struct device_node *node); @@ -380,6 +382,12 @@ static inline int of_get_available_child_count(const struct device_node *parent) return -ENOSYS; } +static inline struct device_node *of_get_compatible_child(const struct device_node *parent, + const char *compatible) +{ + return NULL; +} + static inline struct device_node *of_get_child_by_name( const struct device_node *node, const char *name) { -- 2.26.0.rc2 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox