of: back-porting generic graph bindings
authorMathieu Poirier <mathieu.poirier@linaro.org>
Wed, 8 Oct 2014 19:09:30 +0000 (13:09 -0600)
committerMathieu Poirier <mathieu.poirier@linaro.org>
Mon, 22 Dec 2014 17:45:55 +0000 (10:45 -0700)
This patch is back-porting the generic _portion_ of
f2a575f67695dcba9062acd666ae5aab2380b95c to 3.10

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
drivers/of/base.c
include/linux/of_graph.h

index 4caad01b6feca685a0c47510bbdd49ea6a20a5f2..c66ecf958b673cbc339b1fa3bdd96af4e81ce2bd 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/ctype.h>
 #include <linux/module.h>
 #include <linux/of.h>
+#include <linux/of_graph.h>
 #include <linux/spinlock.h>
 #include <linux/slab.h>
 #include <linux/proc_fs.h>
@@ -1704,6 +1705,37 @@ const char *of_prop_next_string(struct property *prop, const char *cur)
 }
 EXPORT_SYMBOL_GPL(of_prop_next_string);
 
+/**
+ * of_graph_parse_endpoint() - parse common endpoint node properties
+ * @node: pointer to endpoint device_node
+ * @endpoint: pointer to the OF endpoint data structure
+ *
+ * The caller should hold a reference to @node.
+ */
+int of_graph_parse_endpoint(const struct device_node *node,
+                           struct of_endpoint *endpoint)
+{
+       struct device_node *port_node = of_get_parent(node);
+
+       WARN_ONCE(!port_node, "%s(): endpoint %s has no parent node\n",
+                 __func__, node->full_name);
+
+       memset(endpoint, 0, sizeof(*endpoint));
+
+       endpoint->local_node = node;
+       /*
+        * It doesn't matter whether the two calls below succeed.
+        * If they don't then the default value 0 is used.
+        */
+       of_property_read_u32(port_node, "reg", &endpoint->port);
+       of_property_read_u32(node, "reg", &endpoint->id);
+
+       of_node_put(port_node);
+
+       return 0;
+}
+EXPORT_SYMBOL(of_graph_parse_endpoint);
+
 /**
  * of_graph_get_next_endpoint() - get next endpoint node
  * @parent: pointer to the parent device node
index 3bbeb609a360f992692c1fc67d9255bd9194db7c..56e0507a0d5881c4e55a68b7238ed19482b1331e 100644 (file)
 #ifndef __LINUX_OF_GRAPH_H
 #define __LINUX_OF_GRAPH_H
 
+/**
+ * struct of_endpoint - the OF graph endpoint data structure
+ * @port: identifier (value of reg property) of a port this endpoint belongs to
+ * @id: identifier (value of reg property) of this endpoint
+ * @local_node: pointer to device_node of this endpoint
+ */
+struct of_endpoint {
+       unsigned int port;
+       unsigned int id;
+       const struct device_node *local_node;
+};
+
 #ifdef CONFIG_OF
+int of_graph_parse_endpoint(const struct device_node *node,
+                               struct of_endpoint *endpoint);
 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(
@@ -22,6 +36,11 @@ struct device_node *of_graph_get_remote_port_parent(
 struct device_node *of_graph_get_remote_port(const struct device_node *node);
 #else
 
+static inline int of_graph_parse_endpoint(const struct device_node *node,
+                                       struct of_endpoint *endpoint)
+{
+       return -ENOSYS;
+}
 static inline struct device_node *of_graph_get_next_endpoint(
                                        const struct device_node *parent,
                                        struct device_node *previous)