xref: /openbmc/linux/drivers/gpu/drm/omapdrm/dss/base.c (revision 5a244f48)
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/of.h>
4 #include <linux/of_graph.h>
5 #include <linux/list.h>
6 #include "omapdss.h"
7 
8 static bool dss_initialized;
9 static const struct dispc_ops *ops;
10 
11 static struct list_head omapdss_comp_list;
12 
13 struct omapdss_comp_node {
14 	struct list_head list;
15 	struct device_node *node;
16 	bool dss_core_component;
17 };
18 
19 void omapdss_set_is_initialized(bool set)
20 {
21 	dss_initialized = set;
22 }
23 EXPORT_SYMBOL(omapdss_set_is_initialized);
24 
25 bool omapdss_is_initialized(void)
26 {
27 	return dss_initialized;
28 }
29 EXPORT_SYMBOL(omapdss_is_initialized);
30 
31 void dispc_set_ops(const struct dispc_ops *o)
32 {
33 	ops = o;
34 }
35 EXPORT_SYMBOL(dispc_set_ops);
36 
37 const struct dispc_ops *dispc_get_ops(void)
38 {
39 	return ops;
40 }
41 EXPORT_SYMBOL(dispc_get_ops);
42 
43 static bool omapdss_list_contains(const struct device_node *node)
44 {
45 	struct omapdss_comp_node *comp;
46 
47 	list_for_each_entry(comp, &omapdss_comp_list, list) {
48 		if (comp->node == node)
49 			return true;
50 	}
51 
52 	return false;
53 }
54 
55 static void omapdss_walk_device(struct device *dev, struct device_node *node,
56 				bool dss_core)
57 {
58 	struct device_node *n;
59 	struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
60 						      GFP_KERNEL);
61 
62 	if (comp) {
63 		comp->node = node;
64 		comp->dss_core_component = dss_core;
65 		list_add(&comp->list, &omapdss_comp_list);
66 	}
67 
68 	/*
69 	 * of_graph_get_remote_port_parent() prints an error if there is no
70 	 * port/ports node. To avoid that, check first that there's the node.
71 	 */
72 	n = of_get_child_by_name(node, "ports");
73 	if (!n)
74 		n = of_get_child_by_name(node, "port");
75 	if (!n)
76 		return;
77 
78 	of_node_put(n);
79 
80 	n = NULL;
81 	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
82 		struct device_node *pn = of_graph_get_remote_port_parent(n);
83 
84 		if (!pn)
85 			continue;
86 
87 		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
88 			of_node_put(pn);
89 			continue;
90 		}
91 
92 		omapdss_walk_device(dev, pn, false);
93 	}
94 }
95 
96 void omapdss_gather_components(struct device *dev)
97 {
98 	struct device_node *child;
99 
100 	INIT_LIST_HEAD(&omapdss_comp_list);
101 
102 	omapdss_walk_device(dev, dev->of_node, true);
103 
104 	for_each_available_child_of_node(dev->of_node, child) {
105 		if (!of_find_property(child, "compatible", NULL))
106 			continue;
107 
108 		omapdss_walk_device(dev, child, true);
109 	}
110 }
111 EXPORT_SYMBOL(omapdss_gather_components);
112 
113 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
114 {
115 	if (comp->dss_core_component)
116 		return true;
117 	if (omapdss_component_is_display(comp->node))
118 		return true;
119 	if (omapdss_component_is_output(comp->node))
120 		return true;
121 
122 	return false;
123 }
124 
125 bool omapdss_stack_is_ready(void)
126 {
127 	struct omapdss_comp_node *comp;
128 
129 	list_for_each_entry(comp, &omapdss_comp_list, list) {
130 		if (!omapdss_component_is_loaded(comp))
131 			return false;
132 	}
133 
134 	return true;
135 }
136 EXPORT_SYMBOL(omapdss_stack_is_ready);
137 
138 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
139 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
140 MODULE_LICENSE("GPL v2");
141