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_port(struct device_node *src,
118 struct omap_dss_device *dssdev;
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);
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.
134 struct omap_dss_device *omapdss_device_get_next(struct omap_dss_device *from,
135 enum omap_dss_device_type type)
137 struct omap_dss_device *dssdev;
138 struct list_head *list;
140 mutex_lock(&omapdss_devices_lock);
142 if (list_empty(&omapdss_devices_list)) {
148 * Start from the from entry if given or from omapdss_devices_list
151 list = from ? &from->list : &omapdss_devices_list;
153 list_for_each_entry(dssdev, list, list) {
155 * Stop if we reach the omapdss_devices_list, that's the end of
158 if (&dssdev->list == &omapdss_devices_list) {
164 * Accept display entities if the display type is requested,
165 * and output entities if the output type is requested.
167 if ((type & OMAP_DSS_DEVICE_TYPE_DISPLAY) &&
168 !dssdev->output_type)
170 if ((type & OMAP_DSS_DEVICE_TYPE_OUTPUT) && dssdev->id &&
179 omapdss_device_put(from);
181 omapdss_device_get(dssdev);
183 mutex_unlock(&omapdss_devices_lock);
186 EXPORT_SYMBOL(omapdss_device_get_next);
188 int omapdss_device_connect(struct dss_device *dss,
189 struct omap_dss_device *src,
190 struct omap_dss_device *dst)
194 dev_dbg(dst->dev, "connect\n");
196 if (omapdss_device_is_connected(dst))
201 ret = dst->ops->connect(src, dst);
215 EXPORT_SYMBOL_GPL(omapdss_device_connect);
217 void omapdss_device_disconnect(struct omap_dss_device *src,
218 struct omap_dss_device *dst)
220 dev_dbg(dst->dev, "disconnect\n");
222 if (!dst->id && !omapdss_device_is_connected(dst)) {
223 WARN_ON(dst->output_type);
228 if (WARN_ON(dst != src->dst))
235 WARN_ON(dst->state != OMAP_DSS_DISPLAY_DISABLED);
237 dst->ops->disconnect(src, dst);
240 EXPORT_SYMBOL_GPL(omapdss_device_disconnect);
242 /* -----------------------------------------------------------------------------
243 * Components Handling
246 static struct list_head omapdss_comp_list;
248 struct omapdss_comp_node {
249 struct list_head list;
250 struct device_node *node;
251 bool dss_core_component;
254 static bool omapdss_list_contains(const struct device_node *node)
256 struct omapdss_comp_node *comp;
258 list_for_each_entry(comp, &omapdss_comp_list, list) {
259 if (comp->node == node)
266 static void omapdss_walk_device(struct device *dev, struct device_node *node,
269 struct device_node *n;
270 struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
275 comp->dss_core_component = dss_core;
276 list_add(&comp->list, &omapdss_comp_list);
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.
283 n = of_get_child_by_name(node, "ports");
285 n = of_get_child_by_name(node, "port");
292 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
293 struct device_node *pn = of_graph_get_remote_port_parent(n);
298 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
303 omapdss_walk_device(dev, pn, false);
307 void omapdss_gather_components(struct device *dev)
309 struct device_node *child;
311 INIT_LIST_HEAD(&omapdss_comp_list);
313 omapdss_walk_device(dev, dev->of_node, true);
315 for_each_available_child_of_node(dev->of_node, child) {
316 if (!of_find_property(child, "compatible", NULL))
319 omapdss_walk_device(dev, child, true);
322 EXPORT_SYMBOL(omapdss_gather_components);
324 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
326 if (comp->dss_core_component)
328 if (omapdss_device_is_registered(comp->node))
334 bool omapdss_stack_is_ready(void)
336 struct omapdss_comp_node *comp;
338 list_for_each_entry(comp, &omapdss_comp_list, list) {
339 if (!omapdss_component_is_loaded(comp))
345 EXPORT_SYMBOL(omapdss_stack_is_ready);
348 MODULE_DESCRIPTION("OMAP Display Subsystem Base");
349 MODULE_LICENSE("GPL v2");