1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 Texas Instruments
4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
7 #include <linux/device.h>
9 #include <linux/module.h>
11 #include <linux/of_graph.h>
12 #include <linux/seq_file.h>
14 #include <video/omapfb_dss.h>
19 omapdss_of_get_next_port(const struct device_node
*parent
,
20 struct device_node
*prev
)
22 struct device_node
*port
= NULL
;
28 struct device_node
*ports
;
30 * It's the first call, we have to find a port subnode
31 * within this node or within an optional 'ports' node.
33 ports
= of_get_child_by_name(parent
, "ports");
37 port
= of_get_child_by_name(parent
, "port");
39 /* release the 'ports' node */
42 struct device_node
*ports
;
44 ports
= of_get_parent(prev
);
49 port
= of_get_next_child(ports
, prev
);
55 } while (!of_node_name_eq(port
, "port"));
62 EXPORT_SYMBOL_GPL(omapdss_of_get_next_port
);
65 omapdss_of_get_next_endpoint(const struct device_node
*parent
,
66 struct device_node
*prev
)
68 struct device_node
*ep
= NULL
;
74 ep
= of_get_next_child(parent
, prev
);
78 } while (!of_node_name_eq(ep
, "endpoint"));
82 EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint
);
84 struct device_node
*dss_of_port_get_parent_device(struct device_node
*port
)
86 struct device_node
*np
;
92 np
= of_get_parent(port
);
94 for (i
= 0; i
< 2 && np
; ++i
) {
95 struct property
*prop
;
97 prop
= of_find_property(np
, "compatible", NULL
);
102 np
= of_get_next_parent(np
);
108 u32
dss_of_port_get_port_number(struct device_node
*port
)
113 r
= of_property_read_u32(port
, "reg", ®
);
120 static struct device_node
*omapdss_of_get_remote_port(const struct device_node
*node
)
122 struct device_node
*np
;
124 np
= of_graph_get_remote_endpoint(node
);
128 np
= of_get_next_parent(np
);
134 omapdss_of_get_first_endpoint(const struct device_node
*parent
)
136 struct device_node
*port
, *ep
;
138 port
= omapdss_of_get_next_port(parent
, NULL
);
143 ep
= omapdss_of_get_next_endpoint(port
, NULL
);
149 EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint
);
151 struct omap_dss_device
*
152 omapdss_of_find_source_for_first_ep(struct device_node
*node
)
154 struct device_node
*ep
;
155 struct device_node
*src_port
;
156 struct omap_dss_device
*src
;
158 ep
= omapdss_of_get_first_endpoint(node
);
160 return ERR_PTR(-EINVAL
);
162 src_port
= omapdss_of_get_remote_port(ep
);
165 return ERR_PTR(-EINVAL
);
170 src
= omap_dss_find_output_by_port_node(src_port
);
172 of_node_put(src_port
);
174 return src
? src
: ERR_PTR(-EPROBE_DEFER
);
176 EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep
);