summaryrefslogtreecommitdiffstats
path: root/drivers/of
diff options
context:
space:
mode:
authorHyungwon Hwang <human.hwang@samsung.com>2015-06-12 21:59:01 +0900
committerInki Dae <inki.dae@samsung.com>2015-06-22 19:56:51 +0900
commit8ccd0d0ca04147e91890c373677f1e741dda2631 (patch)
tree7260e81214d10d2d083b537555627f5b6ac3dd29 /drivers/of
parentc8466a9166b00ecb0c6f768baf70636fe15f63ef (diff)
downloadlinux-8ccd0d0ca04147e91890c373677f1e741dda2631.tar.bz2
of: add helper for getting endpoint node of specific identifiers
When there are multiple ports or multiple endpoints in a port, they have to be distinguished by the value of reg property. It is common. The drivers can get the specific endpoint in the specific port via this function. Now the drivers have to implement this code in themselves or have to force the order of dt nodes to get the right node. Signed-off-by: Hyungwon Hwang <human.hwang@samsung.com> Acked-by: Rob Herring <robh+dt@kernel.org> Signed-off-by: Inki Dae <inki.dae@samsung.com>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 99764db0875a..f3b583b81105 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2233,6 +2233,39 @@ struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
EXPORT_SYMBOL(of_graph_get_next_endpoint);
/**
+ * of_graph_get_endpoint_by_regs() - get endpoint node of specific identifiers
+ * @parent: pointer to the parent device node
+ * @port_reg: identifier (value of reg property) of the parent port node
+ * @reg: identifier (value of reg property) of the endpoint node
+ *
+ * Return: An 'endpoint' node pointer which is identified by reg and at the same
+ * is the child of a port node identified by port_reg. reg and port_reg are
+ * ignored when they are -1.
+ */
+struct device_node *of_graph_get_endpoint_by_regs(
+ const struct device_node *parent, int port_reg, int reg)
+{
+ struct of_endpoint endpoint;
+ struct device_node *node, *prev_node = NULL;
+
+ while (1) {
+ node = of_graph_get_next_endpoint(parent, prev_node);
+ of_node_put(prev_node);
+ if (!node)
+ break;
+
+ of_graph_parse_endpoint(node, &endpoint);
+ if (((port_reg == -1) || (endpoint.port == port_reg)) &&
+ ((reg == -1) || (endpoint.id == reg)))
+ return node;
+
+ prev_node = node;
+ }
+
+ return NULL;
+}
+
+/**
* of_graph_get_remote_port_parent() - get remote port's parent node
* @node: pointer to a local endpoint device_node
*