devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-acpi@vger.kernel.org
Cc: devicetree@vger.kernel.org, sudeep.holla@arm.com,
	lorenzo.pieralisi@arm.com, mika.westerberg@linux.intel.com,
	rafael@kernel.org, mark.rutland@arm.com, broonie@kernel.org,
	robh@kernel.org, ahs3@redhat.com, frowand.list@gmail.com
Subject: [PATCH v5 1/5] of: Add of_graph_get_port_parent() to obtain a port's parent node
Date: Thu,  4 May 2017 10:14:07 +0300	[thread overview]
Message-ID: <1493882051-28814-2-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <1493882051-28814-1-git-send-email-sakari.ailus@linux.intel.com>

Split off obtaining a port's parent node. This will be soon needed for
implementing the fwnode ops.

Depends-on: ("of: Move OF property and graph API from base.c to property.c")
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/of/property.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index e5d3e1f..cf704f4 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -681,6 +681,30 @@ struct device_node *of_graph_get_endpoint_by_regs(
 EXPORT_SYMBOL(of_graph_get_endpoint_by_regs);
 
 /**
+ * of_graph_get_port_parent() - get port's parent node
+ * @node: pointer to a port node
+ *
+ * Return: Device node which is the parent of the given port node
+ *	   @node. Use of_node_put() on it when done.
+ */
+static struct device_node *
+of_graph_get_port_parent(struct device_node *node)
+{
+	struct device_node *np;
+
+	/* Get the parent of the port */
+	np = of_get_next_parent(node);
+	if (!np)
+		return NULL;
+
+	/* Is there "ports" node? If not, return it. */
+	if (of_node_cmp(np->name, "ports"))
+		return np;
+
+	return of_get_next_parent(np);
+}
+
+/**
  * of_graph_get_remote_port_parent() - get remote port's parent node
  * @node: pointer to a local endpoint device_node
  *
@@ -691,18 +715,13 @@ 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);
+	if (!np)
+		return NULL;
 
-	/* 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;
+	return of_graph_get_port_parent(of_get_next_parent(np));
 }
 EXPORT_SYMBOL(of_graph_get_remote_port_parent);
 
-- 
2.7.4


  reply	other threads:[~2017-05-04  7:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-04  7:14 [PATCH v5 0/5] Move firmware specific code to firmware specific locations Sakari Ailus
2017-05-04  7:14 ` Sakari Ailus [this message]
2017-05-04  7:14 ` [PATCH v5 2/5] device property: Move FW type specific functionality to FW specific files Sakari Ailus
2017-05-04  7:14 ` [PATCH v5 3/5] device property: Move fwnode graph ops to firmware specific locations Sakari Ailus
     [not found]   ` <1493882051-28814-4-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-05-08 18:23     ` Rob Herring
2017-05-09 12:36       ` Sakari Ailus
2017-05-04  7:14 ` [PATCH v5 4/5] device property: Introduce fwnode_device_is_available() Sakari Ailus
2017-05-04  7:14 ` [PATCH v5 5/5] device property: Add FW type agnostic fwnode_graph_get_remote_node Sakari Ailus

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=1493882051-28814-2-git-send-email-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=ahs3@redhat.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=rafael@kernel.org \
    --cc=robh@kernel.org \
    --cc=sudeep.holla@arm.com \
    /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).