1 // SPDX-License-Identifier: GPL-2.0-only
3 * OMAP Display Subsystem Base
5 * Copyright (C) 2015-2017 Texas Instruments Incorporated - https://www.ti.com/
8 #include <linux/kernel.h>
9 #include <linux/list.h>
10 #include <linux/module.h>
11 #include <linux/mutex.h>
13 #include <linux/of_graph.h>
14 #include <linux/platform_device.h>
19 static struct dss_device
*dss_device
;
21 struct dss_device
*omapdss_get_dss(void)
25 EXPORT_SYMBOL(omapdss_get_dss
);
27 void omapdss_set_dss(struct dss_device
*dss
)
31 EXPORT_SYMBOL(omapdss_set_dss
);
33 struct dispc_device
*dispc_get_dispc(struct dss_device
*dss
)
37 EXPORT_SYMBOL(dispc_get_dispc
);
39 const struct dispc_ops
*dispc_get_ops(struct dss_device
*dss
)
41 return dss
->dispc_ops
;
43 EXPORT_SYMBOL(dispc_get_ops
);
46 /* -----------------------------------------------------------------------------
47 * OMAP DSS Devices Handling
50 static LIST_HEAD(omapdss_devices_list
);
51 static DEFINE_MUTEX(omapdss_devices_lock
);
53 void omapdss_device_register(struct omap_dss_device
*dssdev
)
55 mutex_lock(&omapdss_devices_lock
);
56 list_add_tail(&dssdev
->list
, &omapdss_devices_list
);
57 mutex_unlock(&omapdss_devices_lock
);
59 EXPORT_SYMBOL_GPL(omapdss_device_register
);
61 void omapdss_device_unregister(struct omap_dss_device
*dssdev
)
63 mutex_lock(&omapdss_devices_lock
);
64 list_del(&dssdev
->list
);
65 mutex_unlock(&omapdss_devices_lock
);
67 EXPORT_SYMBOL_GPL(omapdss_device_unregister
);
69 static bool omapdss_device_is_registered(struct device_node
*node
)
71 struct omap_dss_device
*dssdev
;
74 mutex_lock(&omapdss_devices_lock
);
76 list_for_each_entry(dssdev
, &omapdss_devices_list
, list
) {
77 if (dssdev
->dev
->of_node
== node
) {
83 mutex_unlock(&omapdss_devices_lock
);
87 struct omap_dss_device
*omapdss_device_get(struct omap_dss_device
*dssdev
)
89 if (!try_module_get(dssdev
->owner
))
92 if (get_device(dssdev
->dev
) == NULL
) {
93 module_put(dssdev
->owner
);
99 EXPORT_SYMBOL(omapdss_device_get
);
101 void omapdss_device_put(struct omap_dss_device
*dssdev
)
103 put_device(dssdev
->dev
);
104 module_put(dssdev
->owner
);
106 EXPORT_SYMBOL(omapdss_device_put
);
108 struct omap_dss_device
*omapdss_find_device_by_node(struct device_node
*node
)
110 struct omap_dss_device
*dssdev
;
112 list_for_each_entry(dssdev
, &omapdss_devices_list
, list
) {
113 if (dssdev
->dev
->of_node
== node
)
114 return omapdss_device_get(dssdev
);
121 * Search for the next output device starting at @from. Release the reference to
122 * the @from device, and acquire a reference to the returned device if found.
124 struct omap_dss_device
*omapdss_device_next_output(struct omap_dss_device
*from
)
126 struct omap_dss_device
*dssdev
;
127 struct list_head
*list
;
129 mutex_lock(&omapdss_devices_lock
);
131 if (list_empty(&omapdss_devices_list
)) {
137 * Start from the from entry if given or from omapdss_devices_list
140 list
= from
? &from
->list
: &omapdss_devices_list
;
142 list_for_each_entry(dssdev
, list
, list
) {
144 * Stop if we reach the omapdss_devices_list, that's the end of
147 if (&dssdev
->list
== &omapdss_devices_list
) {
152 if (dssdev
->id
&& (dssdev
->next
|| dssdev
->bridge
))
160 omapdss_device_put(from
);
162 omapdss_device_get(dssdev
);
164 mutex_unlock(&omapdss_devices_lock
);
167 EXPORT_SYMBOL(omapdss_device_next_output
);
169 static bool omapdss_device_is_connected(struct omap_dss_device
*dssdev
)
174 int omapdss_device_connect(struct dss_device
*dss
,
175 struct omap_dss_device
*src
,
176 struct omap_dss_device
*dst
)
180 dev_dbg(&dss
->pdev
->dev
, "connect(%s, %s)\n",
181 src
? dev_name(src
->dev
) : "NULL",
182 dst
? dev_name(dst
->dev
) : "NULL");
186 * The destination is NULL when the source is connected to a
187 * bridge instead of a DSS device. Stop here, we will attach
188 * the bridge later when we will have a DRM encoder.
190 return src
&& src
->bridge
? 0 : -EINVAL
;
193 if (omapdss_device_is_connected(dst
))
198 if (dst
->ops
&& dst
->ops
->connect
) {
199 ret
= dst
->ops
->connect(src
, dst
);
208 EXPORT_SYMBOL_GPL(omapdss_device_connect
);
210 void omapdss_device_disconnect(struct omap_dss_device
*src
,
211 struct omap_dss_device
*dst
)
213 struct dss_device
*dss
= src
? src
->dss
: dst
->dss
;
215 dev_dbg(&dss
->pdev
->dev
, "disconnect(%s, %s)\n",
216 src
? dev_name(src
->dev
) : "NULL",
217 dst
? dev_name(dst
->dev
) : "NULL");
220 WARN_ON(!src
->bridge
);
224 if (!dst
->id
&& !omapdss_device_is_connected(dst
)) {
225 WARN_ON(!dst
->display
);
229 WARN_ON(dst
->state
!= OMAP_DSS_DISPLAY_DISABLED
);
231 if (dst
->ops
&& dst
->ops
->disconnect
)
232 dst
->ops
->disconnect(src
, dst
);
235 EXPORT_SYMBOL_GPL(omapdss_device_disconnect
);
237 void omapdss_device_enable(struct omap_dss_device
*dssdev
)
242 if (dssdev
->ops
&& dssdev
->ops
->enable
)
243 dssdev
->ops
->enable(dssdev
);
245 omapdss_device_enable(dssdev
->next
);
247 dssdev
->state
= OMAP_DSS_DISPLAY_ACTIVE
;
249 EXPORT_SYMBOL_GPL(omapdss_device_enable
);
251 void omapdss_device_disable(struct omap_dss_device
*dssdev
)
256 omapdss_device_disable(dssdev
->next
);
258 if (dssdev
->ops
&& dssdev
->ops
->disable
)
259 dssdev
->ops
->disable(dssdev
);
261 EXPORT_SYMBOL_GPL(omapdss_device_disable
);
263 /* -----------------------------------------------------------------------------
264 * Components Handling
267 static struct list_head omapdss_comp_list
;
269 struct omapdss_comp_node
{
270 struct list_head list
;
271 struct device_node
*node
;
272 bool dss_core_component
;
276 static bool omapdss_list_contains(const struct device_node
*node
)
278 struct omapdss_comp_node
*comp
;
280 list_for_each_entry(comp
, &omapdss_comp_list
, list
) {
281 if (comp
->node
== node
)
288 static void omapdss_walk_device(struct device
*dev
, struct device_node
*node
,
291 struct omapdss_comp_node
*comp
;
292 struct device_node
*n
;
296 ret
= of_property_read_string(node
, "compatible", &compat
);
300 comp
= devm_kzalloc(dev
, sizeof(*comp
), GFP_KERNEL
);
303 comp
->dss_core_component
= dss_core
;
304 comp
->compat
= compat
;
305 list_add(&comp
->list
, &omapdss_comp_list
);
309 * of_graph_get_remote_port_parent() prints an error if there is no
310 * port/ports node. To avoid that, check first that there's the node.
312 n
= of_get_child_by_name(node
, "ports");
314 n
= of_get_child_by_name(node
, "port");
321 while ((n
= of_graph_get_next_endpoint(node
, n
)) != NULL
) {
322 struct device_node
*pn
= of_graph_get_remote_port_parent(n
);
327 if (!of_device_is_available(pn
) || omapdss_list_contains(pn
)) {
332 omapdss_walk_device(dev
, pn
, false);
336 void omapdss_gather_components(struct device
*dev
)
338 struct device_node
*child
;
340 INIT_LIST_HEAD(&omapdss_comp_list
);
342 omapdss_walk_device(dev
, dev
->of_node
, true);
344 for_each_available_child_of_node(dev
->of_node
, child
)
345 omapdss_walk_device(dev
, child
, true);
347 EXPORT_SYMBOL(omapdss_gather_components
);
349 static bool omapdss_component_is_loaded(struct omapdss_comp_node
*comp
)
351 if (comp
->dss_core_component
)
353 if (!strstarts(comp
->compat
, "omapdss,"))
355 if (omapdss_device_is_registered(comp
->node
))
361 bool omapdss_stack_is_ready(void)
363 struct omapdss_comp_node
*comp
;
365 list_for_each_entry(comp
, &omapdss_comp_list
, list
) {
366 if (!omapdss_component_is_loaded(comp
))
372 EXPORT_SYMBOL(omapdss_stack_is_ready
);
374 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
375 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
376 MODULE_LICENSE("GPL v2");