2 * OMAP Display Subsystem Base
4 * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
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.
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.
16 #include <linux/kernel.h>
17 #include <linux/list.h>
18 #include <linux/module.h>
19 #include <linux/mutex.h>
21 #include <linux/of_graph.h>
26 static struct dss_device *dss_device;
28 struct dss_device *omapdss_get_dss(void)
32 EXPORT_SYMBOL(omapdss_get_dss);
34 void omapdss_set_dss(struct dss_device *dss)
38 EXPORT_SYMBOL(omapdss_set_dss);
40 struct dispc_device *dispc_get_dispc(struct dss_device *dss)
44 EXPORT_SYMBOL(dispc_get_dispc);
46 const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
48 return dss->dispc_ops;
50 EXPORT_SYMBOL(dispc_get_ops);
53 /* -----------------------------------------------------------------------------
54 * OMAP DSS Devices Handling
57 static LIST_HEAD(omapdss_devices_list);
58 static DEFINE_MUTEX(omapdss_devices_lock);
60 void omapdss_device_register(struct omap_dss_device *dssdev)
62 mutex_lock(&omapdss_devices_lock);
63 list_add_tail(&dssdev->list, &omapdss_devices_list);
64 mutex_unlock(&omapdss_devices_lock);
66 EXPORT_SYMBOL_GPL(omapdss_device_register);
68 void omapdss_device_unregister(struct omap_dss_device *dssdev)
70 mutex_lock(&omapdss_devices_lock);
71 list_del(&dssdev->list);
72 mutex_unlock(&omapdss_devices_lock);
74 EXPORT_SYMBOL_GPL(omapdss_device_unregister);
76 static bool omapdss_device_is_registered(struct device_node *node)
78 struct omap_dss_device *dssdev;
81 mutex_lock(&omapdss_devices_lock);
83 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
84 if (dssdev->dev->of_node == node) {
90 mutex_unlock(&omapdss_devices_lock);
94 struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev)
96 if (!try_module_get(dssdev->owner))
99 if (get_device(dssdev->dev) == NULL) {
100 module_put(dssdev->owner);
106 EXPORT_SYMBOL(omapdss_device_get);
108 void omapdss_device_put(struct omap_dss_device *dssdev)
110 put_device(dssdev->dev);
111 module_put(dssdev->owner);
113 EXPORT_SYMBOL(omapdss_device_put);
115 struct omap_dss_device *omapdss_find_device_by_node(struct device_node *node)
117 struct omap_dss_device *dssdev;
119 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
120 if (dssdev->dev->of_node == node)
121 return omapdss_device_get(dssdev);
128 * Search for the next output device starting at @from. Release the reference to
129 * the @from device, and acquire a reference to the returned device if found.
131 struct omap_dss_device *omapdss_device_next_output(struct omap_dss_device *from)
133 struct omap_dss_device *dssdev;
134 struct list_head *list;
136 mutex_lock(&omapdss_devices_lock);
138 if (list_empty(&omapdss_devices_list)) {
144 * Start from the from entry if given or from omapdss_devices_list
147 list = from ? &from->list : &omapdss_devices_list;
149 list_for_each_entry(dssdev, list, list) {
151 * Stop if we reach the omapdss_devices_list, that's the end of
154 if (&dssdev->list == &omapdss_devices_list) {
159 if (dssdev->id && dssdev->next)
167 omapdss_device_put(from);
169 omapdss_device_get(dssdev);
171 mutex_unlock(&omapdss_devices_lock);
174 EXPORT_SYMBOL(omapdss_device_next_output);
176 static bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
181 int omapdss_device_connect(struct dss_device *dss,
182 struct omap_dss_device *src,
183 struct omap_dss_device *dst)
187 dev_dbg(dst->dev, "connect\n");
189 if (omapdss_device_is_connected(dst))
194 ret = dst->ops->connect(src, dst);
202 EXPORT_SYMBOL_GPL(omapdss_device_connect);
204 void omapdss_device_disconnect(struct omap_dss_device *src,
205 struct omap_dss_device *dst)
207 dev_dbg(dst->dev, "disconnect\n");
209 if (!dst->id && !omapdss_device_is_connected(dst)) {
210 WARN_ON(!dst->display);
214 WARN_ON(dst->state != OMAP_DSS_DISPLAY_DISABLED);
216 dst->ops->disconnect(src, dst);
219 EXPORT_SYMBOL_GPL(omapdss_device_disconnect);
221 void omapdss_device_pre_enable(struct omap_dss_device *dssdev)
226 omapdss_device_pre_enable(dssdev->next);
228 if (dssdev->ops->pre_enable)
229 dssdev->ops->pre_enable(dssdev);
231 EXPORT_SYMBOL_GPL(omapdss_device_pre_enable);
233 void omapdss_device_enable(struct omap_dss_device *dssdev)
238 if (dssdev->ops->enable)
239 dssdev->ops->enable(dssdev);
241 omapdss_device_enable(dssdev->next);
243 dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
245 EXPORT_SYMBOL_GPL(omapdss_device_enable);
247 void omapdss_device_disable(struct omap_dss_device *dssdev)
252 omapdss_device_disable(dssdev->next);
254 if (dssdev->ops->disable)
255 dssdev->ops->disable(dssdev);
257 EXPORT_SYMBOL_GPL(omapdss_device_disable);
259 void omapdss_device_post_disable(struct omap_dss_device *dssdev)
264 if (dssdev->ops->post_disable)
265 dssdev->ops->post_disable(dssdev);
267 omapdss_device_post_disable(dssdev->next);
269 dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
271 EXPORT_SYMBOL_GPL(omapdss_device_post_disable);
273 /* -----------------------------------------------------------------------------
274 * Components Handling
277 static struct list_head omapdss_comp_list;
279 struct omapdss_comp_node {
280 struct list_head list;
281 struct device_node *node;
282 bool dss_core_component;
285 static bool omapdss_list_contains(const struct device_node *node)
287 struct omapdss_comp_node *comp;
289 list_for_each_entry(comp, &omapdss_comp_list, list) {
290 if (comp->node == node)
297 static void omapdss_walk_device(struct device *dev, struct device_node *node,
300 struct device_node *n;
301 struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
306 comp->dss_core_component = dss_core;
307 list_add(&comp->list, &omapdss_comp_list);
311 * of_graph_get_remote_port_parent() prints an error if there is no
312 * port/ports node. To avoid that, check first that there's the node.
314 n = of_get_child_by_name(node, "ports");
316 n = of_get_child_by_name(node, "port");
323 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
324 struct device_node *pn = of_graph_get_remote_port_parent(n);
329 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
334 omapdss_walk_device(dev, pn, false);
338 void omapdss_gather_components(struct device *dev)
340 struct device_node *child;
342 INIT_LIST_HEAD(&omapdss_comp_list);
344 omapdss_walk_device(dev, dev->of_node, true);
346 for_each_available_child_of_node(dev->of_node, child) {
347 if (!of_find_property(child, "compatible", NULL))
350 omapdss_walk_device(dev, child, true);
353 EXPORT_SYMBOL(omapdss_gather_components);
355 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
357 if (comp->dss_core_component)
359 if (omapdss_device_is_registered(comp->node))
365 bool omapdss_stack_is_ready(void)
367 struct omapdss_comp_node *comp;
369 list_for_each_entry(comp, &omapdss_comp_list, list) {
370 if (!omapdss_component_is_loaded(comp))
376 EXPORT_SYMBOL(omapdss_stack_is_ready);
378 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
379 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
380 MODULE_LICENSE("GPL v2");