xref: /linux/drivers/gpu/drm/omapdrm/dss/base.c (revision e9f0878c4b2004ac19581274c1ae4c61ae3ca70e)
1 /*
2  * OMAP Display Subsystem Base
3  *
4  * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  */
15 
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/of.h>
19 #include <linux/of_graph.h>
20 #include <linux/list.h>
21 
22 #include "dss.h"
23 #include "omapdss.h"
24 
25 static struct dss_device *dss_device;
26 
27 static struct list_head omapdss_comp_list;
28 
29 struct omapdss_comp_node {
30 	struct list_head list;
31 	struct device_node *node;
32 	bool dss_core_component;
33 };
34 
35 struct dss_device *omapdss_get_dss(void)
36 {
37 	return dss_device;
38 }
39 EXPORT_SYMBOL(omapdss_get_dss);
40 
41 void omapdss_set_dss(struct dss_device *dss)
42 {
43 	dss_device = dss;
44 }
45 EXPORT_SYMBOL(omapdss_set_dss);
46 
47 struct dispc_device *dispc_get_dispc(struct dss_device *dss)
48 {
49 	return dss->dispc;
50 }
51 EXPORT_SYMBOL(dispc_get_dispc);
52 
53 const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
54 {
55 	return dss->dispc_ops;
56 }
57 EXPORT_SYMBOL(dispc_get_ops);
58 
59 static bool omapdss_list_contains(const struct device_node *node)
60 {
61 	struct omapdss_comp_node *comp;
62 
63 	list_for_each_entry(comp, &omapdss_comp_list, list) {
64 		if (comp->node == node)
65 			return true;
66 	}
67 
68 	return false;
69 }
70 
71 static void omapdss_walk_device(struct device *dev, struct device_node *node,
72 				bool dss_core)
73 {
74 	struct device_node *n;
75 	struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
76 						      GFP_KERNEL);
77 
78 	if (comp) {
79 		comp->node = node;
80 		comp->dss_core_component = dss_core;
81 		list_add(&comp->list, &omapdss_comp_list);
82 	}
83 
84 	/*
85 	 * of_graph_get_remote_port_parent() prints an error if there is no
86 	 * port/ports node. To avoid that, check first that there's the node.
87 	 */
88 	n = of_get_child_by_name(node, "ports");
89 	if (!n)
90 		n = of_get_child_by_name(node, "port");
91 	if (!n)
92 		return;
93 
94 	of_node_put(n);
95 
96 	n = NULL;
97 	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
98 		struct device_node *pn = of_graph_get_remote_port_parent(n);
99 
100 		if (!pn)
101 			continue;
102 
103 		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
104 			of_node_put(pn);
105 			continue;
106 		}
107 
108 		omapdss_walk_device(dev, pn, false);
109 	}
110 }
111 
112 void omapdss_gather_components(struct device *dev)
113 {
114 	struct device_node *child;
115 
116 	INIT_LIST_HEAD(&omapdss_comp_list);
117 
118 	omapdss_walk_device(dev, dev->of_node, true);
119 
120 	for_each_available_child_of_node(dev->of_node, child) {
121 		if (!of_find_property(child, "compatible", NULL))
122 			continue;
123 
124 		omapdss_walk_device(dev, child, true);
125 	}
126 }
127 EXPORT_SYMBOL(omapdss_gather_components);
128 
129 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
130 {
131 	if (comp->dss_core_component)
132 		return true;
133 	if (omapdss_component_is_display(comp->node))
134 		return true;
135 	if (omapdss_component_is_output(comp->node))
136 		return true;
137 
138 	return false;
139 }
140 
141 bool omapdss_stack_is_ready(void)
142 {
143 	struct omapdss_comp_node *comp;
144 
145 	list_for_each_entry(comp, &omapdss_comp_list, list) {
146 		if (!omapdss_component_is_loaded(comp))
147 			return false;
148 	}
149 
150 	return true;
151 }
152 EXPORT_SYMBOL(omapdss_stack_is_ready);
153 
154 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
155 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
156 MODULE_LICENSE("GPL v2");
157