Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of_graph: add of_graph_is_present()

In some cases it's very useful to silently check whether port node exists
at all in a device-tree before proceeding with parsing the graph. The DRM
bridges code is one example of such case where absence of a graph in a
device-tree is a legit condition.

This patch adds of_graph_is_present() which returns true if given
device-tree node contains OF graph port.

Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20200701074232.13632-2-digetx@gmail.com

authored by

Dmitry Osipenko and committed by
Sam Ravnborg
4ec0a44b 1185c406

+29
+23
drivers/of/property.c
··· 30 30 #include "of_private.h" 31 31 32 32 /** 33 + * of_graph_is_present() - check graph's presence 34 + * @node: pointer to device_node containing graph port 35 + * 36 + * Return: True if @node has a port or ports (with a port) sub-node, 37 + * false otherwise. 38 + */ 39 + bool of_graph_is_present(const struct device_node *node) 40 + { 41 + struct device_node *ports, *port; 42 + 43 + ports = of_get_child_by_name(node, "ports"); 44 + if (ports) 45 + node = ports; 46 + 47 + port = of_get_child_by_name(node, "port"); 48 + of_node_put(ports); 49 + of_node_put(port); 50 + 51 + return !!port; 52 + } 53 + EXPORT_SYMBOL(of_graph_is_present); 54 + 55 + /** 33 56 * of_property_count_elems_of_size - Count the number of elements in a property 34 57 * 35 58 * @np: device node from which the property value is to be read.
+6
include/linux/of_graph.h
··· 38 38 child = of_graph_get_next_endpoint(parent, child)) 39 39 40 40 #ifdef CONFIG_OF 41 + bool of_graph_is_present(const struct device_node *node); 41 42 int of_graph_parse_endpoint(const struct device_node *node, 42 43 struct of_endpoint *endpoint); 43 44 int of_graph_get_endpoint_count(const struct device_node *np); ··· 56 55 struct device_node *of_graph_get_remote_node(const struct device_node *node, 57 56 u32 port, u32 endpoint); 58 57 #else 58 + 59 + static inline bool of_graph_is_present(const struct device_node *node) 60 + { 61 + return false; 62 + } 59 63 60 64 static inline int of_graph_parse_endpoint(const struct device_node *node, 61 65 struct of_endpoint *endpoint)