]> Git Repo - linux.git/blob - drivers/gpu/drm/omapdrm/dss/base.c
Merge tag 'char-misc-4.21-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
[linux.git] / drivers / gpu / drm / omapdrm / dss / base.c
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/list.h>
18 #include <linux/module.h>
19 #include <linux/mutex.h>
20 #include <linux/of.h>
21 #include <linux/of_graph.h>
22
23 #include "dss.h"
24 #include "omapdss.h"
25
26 static struct dss_device *dss_device;
27
28 struct dss_device *omapdss_get_dss(void)
29 {
30         return dss_device;
31 }
32 EXPORT_SYMBOL(omapdss_get_dss);
33
34 void omapdss_set_dss(struct dss_device *dss)
35 {
36         dss_device = dss;
37 }
38 EXPORT_SYMBOL(omapdss_set_dss);
39
40 struct dispc_device *dispc_get_dispc(struct dss_device *dss)
41 {
42         return dss->dispc;
43 }
44 EXPORT_SYMBOL(dispc_get_dispc);
45
46 const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
47 {
48         return dss->dispc_ops;
49 }
50 EXPORT_SYMBOL(dispc_get_ops);
51
52
53 /* -----------------------------------------------------------------------------
54  * OMAP DSS Devices Handling
55  */
56
57 static LIST_HEAD(omapdss_devices_list);
58 static DEFINE_MUTEX(omapdss_devices_lock);
59
60 void omapdss_device_register(struct omap_dss_device *dssdev)
61 {
62         mutex_lock(&omapdss_devices_lock);
63         list_add_tail(&dssdev->list, &omapdss_devices_list);
64         mutex_unlock(&omapdss_devices_lock);
65 }
66 EXPORT_SYMBOL_GPL(omapdss_device_register);
67
68 void omapdss_device_unregister(struct omap_dss_device *dssdev)
69 {
70         mutex_lock(&omapdss_devices_lock);
71         list_del(&dssdev->list);
72         mutex_unlock(&omapdss_devices_lock);
73 }
74 EXPORT_SYMBOL_GPL(omapdss_device_unregister);
75
76 static bool omapdss_device_is_registered(struct device_node *node)
77 {
78         struct omap_dss_device *dssdev;
79         bool found = false;
80
81         mutex_lock(&omapdss_devices_lock);
82
83         list_for_each_entry(dssdev, &omapdss_devices_list, list) {
84                 if (dssdev->dev->of_node == node) {
85                         found = true;
86                         break;
87                 }
88         }
89
90         mutex_unlock(&omapdss_devices_lock);
91         return found;
92 }
93
94 struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev)
95 {
96         if (!try_module_get(dssdev->owner))
97                 return NULL;
98
99         if (get_device(dssdev->dev) == NULL) {
100                 module_put(dssdev->owner);
101                 return NULL;
102         }
103
104         return dssdev;
105 }
106 EXPORT_SYMBOL(omapdss_device_get);
107
108 void omapdss_device_put(struct omap_dss_device *dssdev)
109 {
110         put_device(dssdev->dev);
111         module_put(dssdev->owner);
112 }
113 EXPORT_SYMBOL(omapdss_device_put);
114
115 struct omap_dss_device *omapdss_find_device_by_port(struct device_node *src,
116                                                     unsigned int port)
117 {
118         struct omap_dss_device *dssdev;
119
120         list_for_each_entry(dssdev, &omapdss_devices_list, list) {
121                 if (dssdev->dev->of_node == src && dssdev->of_ports & BIT(port))
122                         return omapdss_device_get(dssdev);
123         }
124
125         return NULL;
126 }
127
128 /*
129  * Search for the next device starting at @from. The type argument specfies
130  * which device types to consider when searching. Searching for multiple types
131  * is supported by and'ing their type flags. Release the reference to the @from
132  * device, and acquire a reference to the returned device if found.
133  */
134 struct omap_dss_device *omapdss_device_get_next(struct omap_dss_device *from,
135                                                 enum omap_dss_device_type type)
136 {
137         struct omap_dss_device *dssdev;
138         struct list_head *list;
139
140         mutex_lock(&omapdss_devices_lock);
141
142         if (list_empty(&omapdss_devices_list)) {
143                 dssdev = NULL;
144                 goto done;
145         }
146
147         /*
148          * Start from the from entry if given or from omapdss_devices_list
149          * otherwise.
150          */
151         list = from ? &from->list : &omapdss_devices_list;
152
153         list_for_each_entry(dssdev, list, list) {
154                 /*
155                  * Stop if we reach the omapdss_devices_list, that's the end of
156                  * the list.
157                  */
158                 if (&dssdev->list == &omapdss_devices_list) {
159                         dssdev = NULL;
160                         goto done;
161                 }
162
163                 /*
164                  * Accept display entities if the display type is requested,
165                  * and output entities if the output type is requested.
166                  */
167                 if ((type & OMAP_DSS_DEVICE_TYPE_DISPLAY) &&
168                     !dssdev->output_type)
169                         goto done;
170                 if ((type & OMAP_DSS_DEVICE_TYPE_OUTPUT) && dssdev->id &&
171                     dssdev->next)
172                         goto done;
173         }
174
175         dssdev = NULL;
176
177 done:
178         if (from)
179                 omapdss_device_put(from);
180         if (dssdev)
181                 omapdss_device_get(dssdev);
182
183         mutex_unlock(&omapdss_devices_lock);
184         return dssdev;
185 }
186 EXPORT_SYMBOL(omapdss_device_get_next);
187
188 int omapdss_device_connect(struct dss_device *dss,
189                            struct omap_dss_device *src,
190                            struct omap_dss_device *dst)
191 {
192         int ret;
193
194         dev_dbg(dst->dev, "connect\n");
195
196         if (omapdss_device_is_connected(dst))
197                 return -EBUSY;
198
199         dst->dss = dss;
200
201         ret = dst->ops->connect(src, dst);
202         if (ret < 0) {
203                 dst->dss = NULL;
204                 return ret;
205         }
206
207         if (src) {
208                 WARN_ON(src->dst);
209                 dst->src = src;
210                 src->dst = dst;
211         }
212
213         return 0;
214 }
215 EXPORT_SYMBOL_GPL(omapdss_device_connect);
216
217 void omapdss_device_disconnect(struct omap_dss_device *src,
218                                struct omap_dss_device *dst)
219 {
220         dev_dbg(dst->dev, "disconnect\n");
221
222         if (!dst->id && !omapdss_device_is_connected(dst)) {
223                 WARN_ON(dst->output_type);
224                 return;
225         }
226
227         if (src) {
228                 if (WARN_ON(dst != src->dst))
229                         return;
230
231                 dst->src = NULL;
232                 src->dst = NULL;
233         }
234
235         WARN_ON(dst->state != OMAP_DSS_DISPLAY_DISABLED);
236
237         dst->ops->disconnect(src, dst);
238         dst->dss = NULL;
239 }
240 EXPORT_SYMBOL_GPL(omapdss_device_disconnect);
241
242 /* -----------------------------------------------------------------------------
243  * Components Handling
244  */
245
246 static struct list_head omapdss_comp_list;
247
248 struct omapdss_comp_node {
249         struct list_head list;
250         struct device_node *node;
251         bool dss_core_component;
252 };
253
254 static bool omapdss_list_contains(const struct device_node *node)
255 {
256         struct omapdss_comp_node *comp;
257
258         list_for_each_entry(comp, &omapdss_comp_list, list) {
259                 if (comp->node == node)
260                         return true;
261         }
262
263         return false;
264 }
265
266 static void omapdss_walk_device(struct device *dev, struct device_node *node,
267                                 bool dss_core)
268 {
269         struct device_node *n;
270         struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
271                                                       GFP_KERNEL);
272
273         if (comp) {
274                 comp->node = node;
275                 comp->dss_core_component = dss_core;
276                 list_add(&comp->list, &omapdss_comp_list);
277         }
278
279         /*
280          * of_graph_get_remote_port_parent() prints an error if there is no
281          * port/ports node. To avoid that, check first that there's the node.
282          */
283         n = of_get_child_by_name(node, "ports");
284         if (!n)
285                 n = of_get_child_by_name(node, "port");
286         if (!n)
287                 return;
288
289         of_node_put(n);
290
291         n = NULL;
292         while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
293                 struct device_node *pn = of_graph_get_remote_port_parent(n);
294
295                 if (!pn)
296                         continue;
297
298                 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
299                         of_node_put(pn);
300                         continue;
301                 }
302
303                 omapdss_walk_device(dev, pn, false);
304         }
305 }
306
307 void omapdss_gather_components(struct device *dev)
308 {
309         struct device_node *child;
310
311         INIT_LIST_HEAD(&omapdss_comp_list);
312
313         omapdss_walk_device(dev, dev->of_node, true);
314
315         for_each_available_child_of_node(dev->of_node, child) {
316                 if (!of_find_property(child, "compatible", NULL))
317                         continue;
318
319                 omapdss_walk_device(dev, child, true);
320         }
321 }
322 EXPORT_SYMBOL(omapdss_gather_components);
323
324 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
325 {
326         if (comp->dss_core_component)
327                 return true;
328         if (omapdss_device_is_registered(comp->node))
329                 return true;
330
331         return false;
332 }
333
334 bool omapdss_stack_is_ready(void)
335 {
336         struct omapdss_comp_node *comp;
337
338         list_for_each_entry(comp, &omapdss_comp_list, list) {
339                 if (!omapdss_component_is_loaded(comp))
340                         return false;
341         }
342
343         return true;
344 }
345 EXPORT_SYMBOL(omapdss_stack_is_ready);
346
347 MODULE_AUTHOR("Tomi Valkeinen <[email protected]>");
348 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
349 MODULE_LICENSE("GPL v2");
This page took 0.071867 seconds and 4 git commands to generate.