From ee8905963ed0bc9dfc0952dc35e16e233c10e212 Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Mon, 14 Apr 2014 17:53:25 +0200
Subject: of: Add for_each_endpoint_of_node helper macro
Note that while of_graph_get_next_endpoint decrements the reference count
of the child node passed to it, of_node_put(child) still has to be called
manually when breaking out of the loop.
Signed-off-by: Philipp Zabel
Acked-by: Laurent Pinchart
---
include/linux/of_graph.h | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'include')
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index befef42e015b..e43442efcbe5 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -26,6 +26,17 @@ struct of_endpoint {
const struct device_node *local_node;
};
+/**
+ * for_each_endpoint_of_node - iterate over every endpoint in a device node
+ * @parent: parent device node containing ports and endpoints
+ * @child: loop variable pointing to the current endpoint node
+ *
+ * When breaking out of the loop, of_node_put(child) has to be called manually.
+ */
+#define for_each_endpoint_of_node(parent, child) \
+ for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
+ child = of_graph_get_next_endpoint(parent, child))
+
#ifdef CONFIG_OF
int of_graph_parse_endpoint(const struct device_node *node,
struct of_endpoint *endpoint);
--
cgit v1.2.3-55-g7522
From bfe446e37c4efd8ade454911e8f80414bcbfc10d Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Tue, 11 Mar 2014 11:21:11 +0100
Subject: of: Add of_graph_get_port_by_id function
This patch adds a function to get a port device tree node by port id,
or reg property value.
Signed-off-by: Philipp Zabel
Acked-by: Laurent Pinchart
---
drivers/of/base.c | 32 ++++++++++++++++++++++++++++++++
include/linux/of_graph.h | 7 +++++++
2 files changed, 39 insertions(+)
(limited to 'include')
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 05b20f1cca7b..6398b9ca9157 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2080,6 +2080,38 @@ int of_graph_parse_endpoint(const struct device_node *node,
}
EXPORT_SYMBOL(of_graph_parse_endpoint);
+/**
+ * of_graph_get_port_by_id() - get the port matching a given id
+ * @parent: pointer to the parent device node
+ * @id: id of the port
+ *
+ * Return: A 'port' node pointer with refcount incremented. The caller
+ * has to use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_port_by_id(struct device_node *parent, u32 id)
+{
+ struct device_node *node, *port;
+
+ node = of_get_child_by_name(parent, "ports");
+ if (node)
+ parent = node;
+
+ for_each_child_of_node(parent, port) {
+ u32 port_id = 0;
+
+ if (of_node_cmp(port->name, "port") != 0)
+ continue;
+ of_property_read_u32(port, "reg", &port_id);
+ if (id == port_id)
+ break;
+ }
+
+ of_node_put(node);
+
+ return port;
+}
+EXPORT_SYMBOL(of_graph_get_port_by_id);
+
/**
* of_graph_get_next_endpoint() - get next endpoint node
* @parent: pointer to the parent device node
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index e43442efcbe5..3c1c95a39e0c 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -40,6 +40,7 @@ struct of_endpoint {
#ifdef CONFIG_OF
int of_graph_parse_endpoint(const struct device_node *node,
struct of_endpoint *endpoint);
+struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
struct device_node *previous);
struct device_node *of_graph_get_remote_port_parent(
@@ -53,6 +54,12 @@ static inline int of_graph_parse_endpoint(const struct device_node *node,
return -ENOSYS;
}
+static inline struct device_node *of_graph_get_port_by_id(
+ struct device_node *node, u32 id)
+{
+ return NULL;
+}
+
static inline struct device_node *of_graph_get_next_endpoint(
const struct device_node *parent,
struct device_node *previous)
--
cgit v1.2.3-55-g7522
From 01218bf14ee60d4a2d6c667ebdbba3ae9a7a1d66 Mon Sep 17 00:00:00 2001
From: Mark Brown
Date: Thu, 26 Mar 2015 09:47:55 -0700
Subject: of: Explicitly include linux/types.h in of_graph.h
In current -next of_graph.h fails to build due to it relying on
linux/types.h without explicitly including it:
../include/linux/of_graph.h:43:71: error: unknown type name 'u32'
caused by bfe446e37c4e (of: Add of_graph_get_port_by_id function). Add
an explicit inclusion to fix this.
Signed-off-by: Mark Brown
Acked-by: Laurent Pinchart
Acked-by: Philipp Zabel
Signed-off-by: Rob Herring
---
include/linux/of_graph.h | 2 ++
1 file changed, 2 insertions(+)
(limited to 'include')
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
index 3c1c95a39e0c..7bc92e050608 100644
--- a/include/linux/of_graph.h
+++ b/include/linux/of_graph.h
@@ -14,6 +14,8 @@
#ifndef __LINUX_OF_GRAPH_H
#define __LINUX_OF_GRAPH_H
+#include
+
/**
* struct of_endpoint - the OF graph endpoint data structure
* @port: identifier (value of reg property) of a port this endpoint belongs to
--
cgit v1.2.3-55-g7522