2 * Copyright (C) 2013 Texas Instruments
3 * Author: Tomi Valkeinen <tomi.valkeinen@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/seq_file.h>
21 #include <video/omapdss.h>
26 omapdss_of_get_next_port(const struct device_node
*parent
,
27 struct device_node
*prev
)
29 struct device_node
*port
= NULL
;
35 struct device_node
*ports
;
37 * It's the first call, we have to find a port subnode
38 * within this node or within an optional 'ports' node.
40 ports
= of_get_child_by_name(parent
, "ports");
44 port
= of_get_child_by_name(parent
, "port");
46 /* release the 'ports' node */
49 struct device_node
*ports
;
51 ports
= of_get_parent(prev
);
56 port
= of_get_next_child(ports
, prev
);
62 } while (of_node_cmp(port
->name
, "port") != 0);
69 EXPORT_SYMBOL_GPL(omapdss_of_get_next_port
);
72 omapdss_of_get_next_endpoint(const struct device_node
*parent
,
73 struct device_node
*prev
)
75 struct device_node
*ep
= NULL
;
81 ep
= of_get_next_child(parent
, prev
);
85 } while (of_node_cmp(ep
->name
, "endpoint") != 0);
89 EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint
);
91 struct device_node
*dss_of_port_get_parent_device(struct device_node
*port
)
93 struct device_node
*np
;
99 np
= of_get_parent(port
);
101 for (i
= 0; i
< 2 && np
; ++i
) {
102 struct property
*prop
;
104 prop
= of_find_property(np
, "compatible", NULL
);
109 np
= of_get_next_parent(np
);
115 u32
dss_of_port_get_port_number(struct device_node
*port
)
120 r
= of_property_read_u32(port
, "reg", ®
);
127 static struct device_node
*omapdss_of_get_remote_port(const struct device_node
*node
)
129 struct device_node
*np
;
131 np
= of_parse_phandle(node
, "remote-endpoint", 0);
135 np
= of_get_next_parent(np
);
141 omapdss_of_get_first_endpoint(const struct device_node
*parent
)
143 struct device_node
*port
, *ep
;
145 port
= omapdss_of_get_next_port(parent
, NULL
);
150 ep
= omapdss_of_get_next_endpoint(port
, NULL
);
156 EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint
);
158 struct omap_dss_device
*
159 omapdss_of_find_source_for_first_ep(struct device_node
*node
)
161 struct device_node
*ep
;
162 struct device_node
*src_port
;
163 struct omap_dss_device
*src
;
165 ep
= omapdss_of_get_first_endpoint(node
);
167 return ERR_PTR(-EINVAL
);
169 src_port
= omapdss_of_get_remote_port(ep
);
172 return ERR_PTR(-EINVAL
);
177 src
= omap_dss_find_output_by_port_node(src_port
);
179 of_node_put(src_port
);
181 return src
? src
: ERR_PTR(-EPROBE_DEFER
);
183 EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep
);