From: Philipp Zabel <p.zabel@pengutronix.de>
To: Russell King - ARM Linux <linux@arm.linux.org.uk>
Cc: devel@driverdev.osuosl.org, devicetree@vger.kernel.org,
Philipp Zabel <philipp.zabel@gmail.com>,
David Airlie <airlied@linux.ie>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
dri-devel@lists.freedesktop.org, kernel@pengutronix.de,
Grant Likely <grant.likely@linaro.org>,
Shawn Guo <shawn.guo@linaro.org>,
linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH v3 2/9] staging: imx-drm: Add temporary copies of v4l2-of parsing functions
Date: Tue, 18 Feb 2014 12:36:03 +0100 [thread overview]
Message-ID: <1392723370-4772-3-git-send-email-p.zabel@pengutronix.de> (raw)
In-Reply-To: <1392723370-4772-1-git-send-email-p.zabel@pengutronix.de>
From: Philipp Zabel <philipp.zabel@gmail.com>
The existing v4l2-of parser functions for the video interface bindings
described in Documentation/device-tree/bindings/media/video-interfaces.txt
are useful for DRM drivers, too. They will be moved to drivers/media
so they can be used by drm drivers, too. Until then, duplicate the
v4l2-of parser functions temporarily.
Signed-off-by: Philipp Zabel <philipp.zabel@gmail.com>
---
drivers/staging/imx-drm/Makefile | 2 +-
drivers/staging/imx-drm/imx-drm-of.c | 132 +++++++++++++++++++++++++++++++++++
drivers/staging/imx-drm/imx-drm.h | 6 ++
3 files changed, 139 insertions(+), 1 deletion(-)
create mode 100644 drivers/staging/imx-drm/imx-drm-of.c
diff --git a/drivers/staging/imx-drm/Makefile b/drivers/staging/imx-drm/Makefile
index 129e3a3..743b875 100644
--- a/drivers/staging/imx-drm/Makefile
+++ b/drivers/staging/imx-drm/Makefile
@@ -1,5 +1,5 @@
-imxdrm-objs := imx-drm-core.o
+imxdrm-objs := imx-drm-core.o imx-drm-of.o
obj-$(CONFIG_DRM_IMX) += imxdrm.o
diff --git a/drivers/staging/imx-drm/imx-drm-of.c b/drivers/staging/imx-drm/imx-drm-of.c
new file mode 100644
index 0000000..e14b4f3
--- /dev/null
+++ b/drivers/staging/imx-drm/imx-drm-of.c
@@ -0,0 +1,132 @@
+/*
+ * Video Interface OF 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>
+
+/**
+ * imx_drm_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 decremented.
+ */
+struct device_node *imx_drm_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 ?... */
+ of_node_put(prev);
+ return NULL;
+ }
+
+ 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_GPL(imx_drm_of_get_next_endpoint);
+
+/**
+ * imx_drm_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 *imx_drm_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(imx_drm_of_get_remote_port_parent);
+
+/**
+ * imx_drm_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 *imx_drm_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_GPL(imx_drm_of_get_remote_port);
diff --git a/drivers/staging/imx-drm/imx-drm.h b/drivers/staging/imx-drm/imx-drm.h
index aa21028..793a80b 100644
--- a/drivers/staging/imx-drm/imx-drm.h
+++ b/drivers/staging/imx-drm/imx-drm.h
@@ -58,4 +58,10 @@ int imx_drm_connector_mode_valid(struct drm_connector *connector,
void imx_drm_connector_destroy(struct drm_connector *connector);
void imx_drm_encoder_destroy(struct drm_encoder *encoder);
+struct device_node *imx_drm_of_get_next_endpoint(
+ const struct device_node *parent, struct device_node *prev);
+struct device_node *imx_drm_of_get_remote_port_parent(
+ const struct device_node *node);
+struct device_node *imx_drm_of_get_remote_port(const struct device_node *node);
+
#endif /* _IMX_DRM_H_ */
--
1.8.5.3
next prev parent reply other threads:[~2014-02-18 11:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-18 11:36 [RFC PATCH v3 0/9] imx-drm dt bindings Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 1/9] staging: imx-drm-core: don't request probe deferral in imx_drm_encoder_parse_of Philipp Zabel
2014-02-24 15:49 ` Russell King - ARM Linux
2014-02-24 16:56 ` Philipp Zabel
2014-02-24 17:03 ` Philipp Zabel
2014-02-24 17:06 ` Russell King - ARM Linux
2014-02-24 17:41 ` Philipp Zabel
2014-02-18 11:36 ` Philipp Zabel [this message]
2014-02-24 15:52 ` [RFC PATCH v3 2/9] staging: imx-drm: Add temporary copies of v4l2-of parsing functions Russell King - ARM Linux
2014-02-24 17:31 ` Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 3/9] staging: imx-drm-core: Use OF graph to find components and connections between encoder and crtcs Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 4/9] staging: imx-drm: Document updated imx-drm device tree bindings Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 5/9] staging: imx-drm: Document imx-hdmi " Philipp Zabel
[not found] ` <1392723370-4772-1-git-send-email-p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2014-02-18 11:36 ` [RFC PATCH v3 6/9] ARM: dts: imx51: Add IPU ports and endpoints, move imx-drm node to dtsi Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 9/9] staging: imx-drm: Update TODO Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 7/9] ARM: dts: imx53: Add IPU DI ports and endpoints, move imx-drm node to dtsi Philipp Zabel
2014-02-18 11:36 ` [RFC PATCH v3 8/9] ARM: dts: imx6qdl: " Philipp Zabel
2014-02-24 15:36 ` [RFC PATCH v3 0/9] imx-drm dt bindings Philipp Zabel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1392723370-4772-3-git-send-email-p.zabel@pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=airlied@linux.ie \
--cc=devel@driverdev.osuosl.org \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=grant.likely@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux@arm.linux.org.uk \
--cc=philipp.zabel@gmail.com \
--cc=shawn.guo@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).