2 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/device.h>
16 #include <linux/err.h>
17 #include <linux/module.h>
19 #include <linux/of_graph.h>
20 #include <linux/seq_file.h>
24 static struct device_node *
25 dss_of_port_get_parent_device(struct device_node *port)
27 struct device_node *np;
33 np = of_get_parent(port);
35 for (i = 0; i < 2 && np; ++i) {
36 struct property *prop;
38 prop = of_find_property(np, "compatible", NULL);
43 np = of_get_next_parent(np);
49 struct omap_dss_device *
50 omapdss_of_find_connected_device(struct device_node *node, unsigned int port)
52 struct device_node *src_node;
53 struct device_node *src_port;
54 struct device_node *ep;
55 struct omap_dss_device *src;
58 /* Get the endpoint... */
59 ep = of_graph_get_endpoint_by_regs(node, port, 0);
63 /* ... and its remote port... */
64 src_port = of_graph_get_remote_port(ep);
69 /* ... and the remote port's number and parent... */
70 of_property_read_u32(src_port, "reg", &port_number);
71 src_node = dss_of_port_get_parent_device(src_port);
72 of_node_put(src_port);
74 return ERR_PTR(-EINVAL);
76 /* ... and finally the connected device. */
77 src = omapdss_find_device_by_port(src_node, port_number);
78 of_node_put(src_node);
80 return src ? src : ERR_PTR(-EPROBE_DEFER);
82 EXPORT_SYMBOL_GPL(omapdss_of_find_connected_device);