devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] [media]: of: move graph helpers from drivers/media/v4l2-core to drivers/of
@ 2014-02-11 11:45 Philipp Zabel
       [not found] ` < 20140310145815.17595C405FA@trevor.secretlab.ca>
                   ` (4 more replies)
  0 siblings, 5 replies; 74+ messages in thread
From: Philipp Zabel @ 2014-02-11 11:45 UTC (permalink / raw)
  To: Russell King - ARM Linux, Mauro Carvalho Chehab
  Cc: Grant Likely, Rob Herring, Sylwester Nawrocki, Laurent Pinchart,
	Tomi Valkeinen, Kyungmin Park, linux-kernel, linux-media,
	devicetree, Philipp Zabel, Philipp Zabel

From: Philipp Zabel <philipp.zabel@gmail.com>

This patch moves the parsing helpers used to parse connected graphs
in the device tree, like the video interface bindings documented in
Documentation/devicetree/bindings/media/video-interfaces.txt, from
drivers/media/v4l2-core to drivers/of.

This allows to reuse the same parser code from outside the V4L2 framework,
most importantly from display drivers. There have been patches that duplicate
the code (and I am going to send one of my own), such as
http://lists.freedesktop.org/archives/dri-devel/2013-August/043308.html
and others that parse the same binding in a different way:
https://www.mail-archive.com/linux-omap@vger.kernel.org/msg100761.html

I think that all common video interface parsing helpers should be moved to a
single place, outside of the specific subsystems, so that it can be reused
by all drivers.

I moved v4l2_of_get_next_endpoint, v4l2_of_get_remote_port,
and v4l2_of_get_remote_port_parent. They are renamed to
of_graph_get_next_endpoint, of_graph_get_remote_port, and
of_graph_get_remote_port_parent, respectively.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/Kconfig             |   1 +
 drivers/media/v4l2-core/v4l2-of.c | 117 ---------------------------------
 drivers/of/Kconfig                |   3 +
 drivers/of/Makefile               |   1 +
 drivers/of/of_graph.c             | 133 ++++++++++++++++++++++++++++++++++++++
 include/linux/of_graph.h          |  23 +++++++
 include/media/v4l2-of.h           |  16 ++---
 7 files changed, 167 insertions(+), 127 deletions(-)
 create mode 100644 drivers/of/of_graph.c
 create mode 100644 include/linux/of_graph.h

diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 1d0758a..882faeb 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -96,6 +96,7 @@ config VIDEO_DEV
 	tristate
 	depends on MEDIA_SUPPORT
 	depends on MEDIA_CAMERA_SUPPORT || MEDIA_ANALOG_TV_SUPPORT || MEDIA_RADIO_SUPPORT
+	select OF_GRAPH if OF
 	default y
 
 config VIDEO_V4L2_SUBDEV_API
diff --git a/drivers/media/v4l2-core/v4l2-of.c b/drivers/media/v4l2-core/v4l2-of.c
index 42e3e8a..f919db3 100644
--- a/drivers/media/v4l2-core/v4l2-of.c
+++ b/drivers/media/v4l2-core/v4l2-of.c
@@ -152,120 +152,3 @@ int v4l2_of_parse_endpoint(const struct device_node *node,
 	return 0;
 }
 EXPORT_SYMBOL(v4l2_of_parse_endpoint);
-
-/**
- * v4l2_of_get_next_endpoint() - get next endpoint node
- * @parent: pointer to the parent device node
- * @prev: previous endpoint node, or NULL to get first
- *
- * Return: An 'endpoint' node pointer with refcount incremented. Refcount
- * of the passed @prev node is not decremented, the caller have to use
- * of_node_put() on it when done.
- */
-struct device_node *v4l2_of_get_next_endpoint(const struct device_node *parent,
-					struct device_node *prev)
-{
-	struct device_node *endpoint;
-	struct device_node *port = NULL;
-
-	if (!parent)
-		return NULL;
-
-	if (!prev) {
-		struct device_node *node;
-		/*
-		 * It's the first call, we have to find a port subnode
-		 * within this node or within an optional 'ports' node.
-		 */
-		node = of_get_child_by_name(parent, "ports");
-		if (node)
-			parent = node;
-
-		port = of_get_child_by_name(parent, "port");
-
-		if (port) {
-			/* Found a port, get an endpoint. */
-			endpoint = of_get_next_child(port, NULL);
-			of_node_put(port);
-		} else {
-			endpoint = NULL;
-		}
-
-		if (!endpoint)
-			pr_err("%s(): no endpoint nodes specified for %s\n",
-			       __func__, parent->full_name);
-		of_node_put(node);
-	} else {
-		port = of_get_parent(prev);
-		if (!port)
-			/* Hm, has someone given us the root node ?... */
-			return NULL;
-
-		/* Avoid dropping prev node refcount to 0. */
-		of_node_get(prev);
-		endpoint = of_get_next_child(port, prev);
-		if (endpoint) {
-			of_node_put(port);
-			return endpoint;
-		}
-
-		/* No more endpoints under this port, try the next one. */
-		do {
-			port = of_get_next_child(parent, port);
-			if (!port)
-				return NULL;
-		} while (of_node_cmp(port->name, "port"));
-
-		/* Pick up the first endpoint in this port. */
-		endpoint = of_get_next_child(port, NULL);
-		of_node_put(port);
-	}
-
-	return endpoint;
-}
-EXPORT_SYMBOL(v4l2_of_get_next_endpoint);
-
-/**
- * v4l2_of_get_remote_port_parent() - get remote port's parent node
- * @node: pointer to a local endpoint device_node
- *
- * Return: Remote device node associated with remote endpoint node linked
- *	   to @node. Use of_node_put() on it when done.
- */
-struct device_node *v4l2_of_get_remote_port_parent(
-			       const struct device_node *node)
-{
-	struct device_node *np;
-	unsigned int depth;
-
-	/* Get remote endpoint node. */
-	np = of_parse_phandle(node, "remote-endpoint", 0);
-
-	/* Walk 3 levels up only if there is 'ports' node. */
-	for (depth = 3; depth && np; depth--) {
-		np = of_get_next_parent(np);
-		if (depth == 2 && of_node_cmp(np->name, "ports"))
-			break;
-	}
-	return np;
-}
-EXPORT_SYMBOL(v4l2_of_get_remote_port_parent);
-
-/**
- * v4l2_of_get_remote_port() - get remote port node
- * @node: pointer to a local endpoint device_node
- *
- * Return: Remote port node associated with remote endpoint node linked
- *	   to @node. Use of_node_put() on it when done.
- */
-struct device_node *v4l2_of_get_remote_port(const struct device_node *node)
-{
-	struct device_node *np;
-
-	/* Get remote endpoint node. */
-	np = of_parse_phandle(node, "remote-endpoint", 0);
-	if (!np)
-		return NULL;
-	return of_get_next_parent(np);
-}
-EXPORT_SYMBOL(v4l2_of_get_remote_port);
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index c6973f1..1bfbb0e 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -75,4 +75,7 @@ config OF_MTD
 	depends on MTD
 	def_bool y
 
+config OF_GRAPH
+	bool
+
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index efd0510..7ee8ab3 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -9,3 +9,4 @@ obj-$(CONFIG_OF_MDIO)	+= of_mdio.o
 obj-$(CONFIG_OF_PCI)	+= of_pci.o
 obj-$(CONFIG_OF_PCI_IRQ)  += of_pci_irq.o
 obj-$(CONFIG_OF_MTD)	+= of_mtd.o
+obj-$(CONFIG_OF_GRAPH)	+= of_graph.o
diff --git a/drivers/of/of_graph.c b/drivers/of/of_graph.c
new file mode 100644
index 0000000..aa526d7
--- /dev/null
+++ b/drivers/of/of_graph.c
@@ -0,0 +1,133 @@
+/*
+ * OF graph binding parsing library
+ *
+ * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
+ * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
+ *
+ * Copyright (C) 2012 Renesas Electronics Corp.
+ * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/types.h>
+
+/**
+ * of_graph_get_next_endpoint() - get next endpoint node
+ * @parent: pointer to the parent device node
+ * @prev: previous endpoint node, or NULL to get first
+ *
+ * Return: An 'endpoint' node pointer with refcount incremented. Refcount
+ * of the passed @prev node is not decremented, the caller have to use
+ * of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
+					struct device_node *prev)
+{
+	struct device_node *endpoint;
+	struct device_node *port = NULL;
+
+	if (!parent)
+		return NULL;
+
+	if (!prev) {
+		struct device_node *node;
+		/*
+		 * It's the first call, we have to find a port subnode
+		 * within this node or within an optional 'ports' node.
+		 */
+		node = of_get_child_by_name(parent, "ports");
+		if (node)
+			parent = node;
+
+		port = of_get_child_by_name(parent, "port");
+
+		if (port) {
+			/* Found a port, get an endpoint. */
+			endpoint = of_get_next_child(port, NULL);
+			of_node_put(port);
+		} else {
+			endpoint = NULL;
+		}
+
+		if (!endpoint)
+			pr_err("%s(): no endpoint nodes specified for %s\n",
+			       __func__, parent->full_name);
+		of_node_put(node);
+	} else {
+		port = of_get_parent(prev);
+		if (!port)
+			/* Hm, has someone given us the root node ?... */
+			return NULL;
+
+		/* Avoid dropping prev node refcount to 0. */
+		of_node_get(prev);
+		endpoint = of_get_next_child(port, prev);
+		if (endpoint) {
+			of_node_put(port);
+			return endpoint;
+		}
+
+		/* No more endpoints under this port, try the next one. */
+		do {
+			port = of_get_next_child(parent, port);
+			if (!port)
+				return NULL;
+		} while (of_node_cmp(port->name, "port"));
+
+		/* Pick up the first endpoint in this port. */
+		endpoint = of_get_next_child(port, NULL);
+		of_node_put(port);
+	}
+
+	return endpoint;
+}
+EXPORT_SYMBOL(of_graph_get_next_endpoint);
+
+/**
+ * of_graph_get_remote_port_parent() - get remote port's parent node
+ * @node: pointer to a local endpoint device_node
+ *
+ * Return: Remote device node associated with remote endpoint node linked
+ *	   to @node. Use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_remote_port_parent(
+			       const struct device_node *node)
+{
+	struct device_node *np;
+	unsigned int depth;
+
+	/* Get remote endpoint node. */
+	np = of_parse_phandle(node, "remote-endpoint", 0);
+
+	/* Walk 3 levels up only if there is 'ports' node. */
+	for (depth = 3; depth && np; depth--) {
+		np = of_get_next_parent(np);
+		if (depth == 2 && of_node_cmp(np->name, "ports"))
+			break;
+	}
+	return np;
+}
+EXPORT_SYMBOL(of_graph_get_remote_port_parent);
+
+/**
+ * of_graph_get_remote_port() - get remote port node
+ * @node: pointer to a local endpoint device_node
+ *
+ * Return: Remote port node associated with remote endpoint node linked
+ *	   to @node. Use of_node_put() on it when done.
+ */
+struct device_node *of_graph_get_remote_port(const struct device_node *node)
+{
+	struct device_node *np;
+
+	/* Get remote endpoint node. */
+	np = of_parse_phandle(node, "remote-endpoint", 0);
+	if (!np)
+		return NULL;
+	return of_get_next_parent(np);
+}
+EXPORT_SYMBOL(of_graph_get_remote_port);
diff --git a/include/linux/of_graph.h b/include/linux/of_graph.h
new file mode 100644
index 0000000..352306a
--- /dev/null
+++ b/include/linux/of_graph.h
@@ -0,0 +1,23 @@
+/*
+ * OF graph binding parsing helpers
+ *
+ * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
+ * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
+ *
+ * Copyright (C) 2012 Renesas Electronics Corp.
+ * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ */
+#ifndef __LINUX_OF_GRAPH_H
+#define __LINUX_OF_GRAPH_H
+
+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(
+					const struct device_node *node);
+struct device_node *of_graph_get_remote_port(const struct device_node *node);
+
+#endif /* __LINUX_OF_GRAPH_H */
diff --git a/include/media/v4l2-of.h b/include/media/v4l2-of.h
index 541cea4..404a493 100644
--- a/include/media/v4l2-of.h
+++ b/include/media/v4l2-of.h
@@ -17,6 +17,7 @@
 #include <linux/list.h>
 #include <linux/types.h>
 #include <linux/errno.h>
+#include <linux/of_graph.h>
 
 #include <media/v4l2-mediabus.h>
 
@@ -72,11 +73,6 @@ struct v4l2_of_endpoint {
 #ifdef CONFIG_OF
 int v4l2_of_parse_endpoint(const struct device_node *node,
 			   struct v4l2_of_endpoint *endpoint);
-struct device_node *v4l2_of_get_next_endpoint(const struct device_node *parent,
-					struct device_node *previous);
-struct device_node *v4l2_of_get_remote_port_parent(
-					const struct device_node *node);
-struct device_node *v4l2_of_get_remote_port(const struct device_node *node);
 #else /* CONFIG_OF */
 
 static inline int v4l2_of_parse_endpoint(const struct device_node *node,
@@ -85,25 +81,25 @@ static inline int v4l2_of_parse_endpoint(const struct device_node *node,
 	return -ENOSYS;
 }
 
+#endif /* CONFIG_OF */
+
 static inline struct device_node *v4l2_of_get_next_endpoint(
 					const struct device_node *parent,
 					struct device_node *previous)
 {
-	return NULL;
+	return of_graph_get_next_endpoint(parent, previous);
 }
 
 static inline struct device_node *v4l2_of_get_remote_port_parent(
 					const struct device_node *node)
 {
-	return NULL;
+	return of_graph_get_remote_port_parent(node);
 }
 
 static inline struct device_node *v4l2_of_get_remote_port(
 					const struct device_node *node)
 {
-	return NULL;
+	return of_graph_get_remote_port(node);
 }
 
-#endif /* CONFIG_OF */
-
 #endif /* _V4L2_OF_H */
-- 
1.8.5.3

^ permalink raw reply related	[flat|nested] 74+ messages in thread

end of thread, other threads:[~2014-03-21 14:33 UTC | newest]

Thread overview: 74+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-11 11:45 [RFC PATCH] [media]: of: move graph helpers from drivers/media/v4l2-core to drivers/of Philipp Zabel
     [not found] ` < 20140310145815.17595C405FA@trevor.secretlab.ca>
     [not found] ` < 4339286.FzhQ2m6hoA@avalon>
     [not found] ` < CAL_Jsq+U9zU1i+STLHMBjY5BeEP6djYnJVE5X1ix-D2q_zWztQ@mail.gmail.com>
     [not found]   ` < 20140217181451.7EB7FC4044D@trevor.secretlab.ca>
     [not found] ` < 20140320153804.35d5b835@samsung.com>
2014-02-11 13:56 ` Rob Herring
2014-02-11 14:52   ` Russell King - ARM Linux
2014-02-11 15:23     ` Laurent Pinchart
2014-02-11 16:36       ` Philipp Zabel
     [not found]         ` <1392136617.6943.33.camel-/rZezPiN1rtR6QfukMTsflXZhhPuCNm+@public.gmane.org>
2014-02-11 17:22           ` Sylwester Nawrocki
2014-02-11 17:41             ` Mauro Carvalho Chehab
2014-02-11 21:00               ` Guennadi Liakhovetski
2014-02-11 21:46             ` Philipp Zabel
2014-02-11 17:24           ` Laurent Pinchart
2014-02-11 16:30     ` Rob Herring
2014-02-11 15:27   ` Philipp Zabel
2014-02-17 18:14   ` Grant Likely
2014-02-18  7:06     ` Sascha Hauer
2014-02-18 16:26       ` Grant Likely
     [not found]         ` < 1393263389.3091.82.camel@pizza.hi.pengutronix.de>
     [not found]           ` <20140226110114. CF2C7C40A89@trevor.secretlab.ca>
     [not found]         ` <20140218162627.32BA4C40517-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-02-24 17:36           ` Philipp Zabel
2014-02-26 11:01             ` Grant Likely
2014-02-26 14:48               ` Philipp Zabel
     [not found]                 ` <1393426129.3248.64.camel-+qGW7pzALmz7o/J7KWpOmN53zsg1cpMQ@public.gmane.org>
2014-02-27  8:36                   ` Tomi Valkeinen
2014-03-07 17:06                     ` Grant Likely
2014-03-08 10:57                       ` Tomi Valkeinen
2014-03-07 17:05                 ` Grant Likely
2014-03-08 10:33                   ` Tomi Valkeinen
2014-03-08 11:41                     ` Grant Likely
2014-03-08 23:25                       ` Sylwester Nawrocki
2014-03-10 10:18                       ` Tomi Valkeinen
     [not found]                         ` <531D916C.2010903-l0cyMroinI0@public.gmane.org>
2014-03-10 13:52                           ` Laurent Pinchart
2014-03-10 14:10                             ` Tomi Valkeinen
2014-03-10 14:58                             ` Grant Likely
2014-03-10 15:15                               ` Laurent Pinchart
2014-03-10 15:40                                 ` Philipp Zabel
2014-03-11 11:43                                   ` Laurent Pinchart
2014-03-11 12:59                                     ` Tomi Valkeinen
     [not found]                                       ` <1883687.VdfitvQEN3@samsung.com>
     [not found]                                         ` <avalon@samsung.com>
     [not found]                                       ` <531F08A8.300-l0cyMroinI0@public.gmane.org>
2014-03-11 13:16                                         ` Laurent Pinchart
2014-03-11 13:27                                           ` Tomi Valkeinen
2014-03-11 13:44                                             ` Philipp Zabel
2014-03-20 17:23                                           ` Grant Likely
2014-03-21 10:44                                             ` Andrzej Hajda
2014-03-21 11:47                                               ` Grant Likely
2014-03-21 12:16                                                 ` Tomi Valkeinen
     [not found]                                                   ` <532C2D94.4020705-l0cyMroinI0@public.gmane.org>
2014-03-21 14:33                                                     ` Grant Likely
2014-03-20 17:09                                     ` Grant Likely
2014-03-11 13:04                                 ` Andrzej Hajda
     [not found]                                   ` <531F09E2.3070407-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-03-20 17:33                                     ` Grant Likely
2014-03-20 17:01                                 ` Grant Likely
2014-03-21 12:10                                   ` Tomi Valkeinen
2014-03-11 15:07                               ` Philipp Zabel
     [not found]                                 ` <1394550420.3772.29.camel-+qGW7pzALmz7o/J7KWpOmN53zsg1cpMQ@public.gmane.org>
2014-03-11 15:21                                   ` Laurent Pinchart
2014-03-11 18:52                                     ` Philipp Zabel
2014-03-20 17:53                                     ` Grant Likely
2014-03-20 17:36                                   ` Grant Likely
2014-03-12 10:25                             ` Russell King - ARM Linux
2014-03-12 10:47                               ` Tomi Valkeinen
     [not found]                                 ` <53203B2D.6080201-l0cyMroinI0@public.gmane.org>
2014-03-12 11:21                                   ` Laurent Pinchart
2014-03-20 17:54                               ` Grant Likely
     [not found]                                 ` <20140320175432.0559CC4067A-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-20 18:16                                   ` Laurent Pinchart
2014-03-20 18:18                                     ` Russell King - ARM Linux
     [not found]                                       ` <20140320181820.GY7528-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2014-03-20 18:50                                         ` Laurent Pinchart
2014-03-20 19:27                                       ` Laurent Pinchart
2014-03-20 18:38                                   ` Mauro Carvalho Chehab
2014-03-20 18:43                                     ` Russell King - ARM Linux
2014-03-20 18:49                                       ` Laurent Pinchart
2014-03-21  8:20                                         ` Tomi Valkeinen
     [not found]                                 ` <20140320153804.35d5b835@ samsung.com>
     [not found]                                   ` <20140320153804.35d5b835-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-03-20 18:48                                     ` Grant Likely
     [not found]                                       ` <20140320184816.7AB02C4067A-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-20 18:52                                         ` Laurent Pinchart
2014-03-20 23:12                                           ` Grant Likely
     [not found]                                             ` <20140320231250.8F0E0C412EA-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-20 23:26                                               ` Laurent Pinchart
2014-03-21  8:15                                                 ` Grant Likely
2014-03-21 12:44                                                   ` Laurent Pinchart
2014-03-21 13:26                                                     ` Grant Likely
2014-03-10 14:41                           ` Grant Likely
2014-03-08 11:54                   ` Russell King - ARM Linux
     [not found]     ` <20140217181451.7EB7FC4044D-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-02-18 10:43       ` Sylwester Nawrocki
2014-02-18 13:41     ` Philipp Zabel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).