Merge tag 'trace-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux/fpc-iii.git] / drivers / video / fbdev / omap2 / omapfb / dss / dss-of.c
blob0282d4eef139d4971a86b2c2e5b0b289ac9c5a19
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2013 Texas Instruments
4 * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
5 */
7 #include <linux/device.h>
8 #include <linux/err.h>
9 #include <linux/module.h>
10 #include <linux/of.h>
11 #include <linux/of_graph.h>
12 #include <linux/seq_file.h>
14 #include <video/omapfb_dss.h>
16 #include "dss.h"
18 struct device_node *
19 omapdss_of_get_next_port(const struct device_node *parent,
20 struct device_node *prev)
22 struct device_node *port = NULL;
24 if (!parent)
25 return NULL;
27 if (!prev) {
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");
34 if (ports)
35 parent = ports;
37 port = of_get_child_by_name(parent, "port");
39 /* release the 'ports' node */
40 of_node_put(ports);
41 } else {
42 struct device_node *ports;
44 ports = of_get_parent(prev);
45 if (!ports)
46 return NULL;
48 do {
49 port = of_get_next_child(ports, prev);
50 if (!port) {
51 of_node_put(ports);
52 return NULL;
54 prev = port;
55 } while (!of_node_name_eq(port, "port"));
57 of_node_put(ports);
60 return port;
62 EXPORT_SYMBOL_GPL(omapdss_of_get_next_port);
64 struct device_node *
65 omapdss_of_get_next_endpoint(const struct device_node *parent,
66 struct device_node *prev)
68 struct device_node *ep = NULL;
70 if (!parent)
71 return NULL;
73 do {
74 ep = of_get_next_child(parent, prev);
75 if (!ep)
76 return NULL;
77 prev = ep;
78 } while (!of_node_name_eq(ep, "endpoint"));
80 return ep;
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;
87 int i;
89 if (!port)
90 return NULL;
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);
99 if (prop)
100 return np;
102 np = of_get_next_parent(np);
105 return NULL;
108 u32 dss_of_port_get_port_number(struct device_node *port)
110 int r;
111 u32 reg;
113 r = of_property_read_u32(port, "reg", &reg);
114 if (r)
115 reg = 0;
117 return 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);
125 if (!np)
126 return NULL;
128 np = of_get_next_parent(np);
130 return np;
133 struct device_node *
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);
140 if (!port)
141 return NULL;
143 ep = omapdss_of_get_next_endpoint(port, NULL);
145 of_node_put(port);
147 return ep;
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);
159 if (!ep)
160 return ERR_PTR(-EINVAL);
162 src_port = omapdss_of_get_remote_port(ep);
163 if (!src_port) {
164 of_node_put(ep);
165 return ERR_PTR(-EINVAL);
168 of_node_put(ep);
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);