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 struct dispc_device *dispc_get_dispc(struct dss_device *dss)
24 /* -----------------------------------------------------------------------------
25 * OMAP DSS Devices Handling
28 static LIST_HEAD(omapdss_devices_list);
29 static DEFINE_MUTEX(omapdss_devices_lock);
31 void omapdss_device_register(struct omap_dss_device *dssdev)
33 mutex_lock(&omapdss_devices_lock);
34 list_add_tail(&dssdev->list, &omapdss_devices_list);
35 mutex_unlock(&omapdss_devices_lock);
38 void omapdss_device_unregister(struct omap_dss_device *dssdev)
40 mutex_lock(&omapdss_devices_lock);
41 list_del(&dssdev->list);
42 mutex_unlock(&omapdss_devices_lock);
45 static bool omapdss_device_is_registered(struct device_node *node)
47 struct omap_dss_device *dssdev;
50 mutex_lock(&omapdss_devices_lock);
52 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
53 if (dssdev->dev->of_node == node) {
59 mutex_unlock(&omapdss_devices_lock);
63 struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev)
65 if (get_device(dssdev->dev) == NULL)
71 void omapdss_device_put(struct omap_dss_device *dssdev)
73 put_device(dssdev->dev);
76 struct omap_dss_device *omapdss_find_device_by_node(struct device_node *node)
78 struct omap_dss_device *dssdev;
80 list_for_each_entry(dssdev, &omapdss_devices_list, list) {
81 if (dssdev->dev->of_node == node)
82 return omapdss_device_get(dssdev);
89 * Search for the next output device starting at @from. Release the reference to
90 * the @from device, and acquire a reference to the returned device if found.
92 struct omap_dss_device *omapdss_device_next_output(struct omap_dss_device *from)
94 struct omap_dss_device *dssdev;
95 struct list_head *list;
97 mutex_lock(&omapdss_devices_lock);
99 if (list_empty(&omapdss_devices_list)) {
105 * Start from the from entry if given or from omapdss_devices_list
108 list = from ? &from->list : &omapdss_devices_list;
110 list_for_each_entry(dssdev, list, list) {
112 * Stop if we reach the omapdss_devices_list, that's the end of
115 if (&dssdev->list == &omapdss_devices_list) {
120 if (dssdev->id && dssdev->bridge)
128 omapdss_device_put(from);
130 omapdss_device_get(dssdev);
132 mutex_unlock(&omapdss_devices_lock);
136 static bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
141 int omapdss_device_connect(struct dss_device *dss,
142 struct omap_dss_device *src,
143 struct omap_dss_device *dst)
145 dev_dbg(&dss->pdev->dev, "connect(%s, %s)\n",
146 src ? dev_name(src->dev) : "NULL",
147 dst ? dev_name(dst->dev) : "NULL");
151 * The destination is NULL when the source is connected to a
152 * bridge instead of a DSS device. Stop here, we will attach
153 * the bridge later when we will have a DRM encoder.
155 return src && src->bridge ? 0 : -EINVAL;
158 if (omapdss_device_is_connected(dst))
166 void omapdss_device_disconnect(struct omap_dss_device *src,
167 struct omap_dss_device *dst)
169 struct dss_device *dss = src ? src->dss : dst->dss;
171 dev_dbg(&dss->pdev->dev, "disconnect(%s, %s)\n",
172 src ? dev_name(src->dev) : "NULL",
173 dst ? dev_name(dst->dev) : "NULL");
176 WARN_ON(!src->bridge);
180 if (!dst->id && !omapdss_device_is_connected(dst)) {
188 /* -----------------------------------------------------------------------------
189 * Components Handling
192 static struct list_head omapdss_comp_list;
194 struct omapdss_comp_node {
195 struct list_head list;
196 struct device_node *node;
197 bool dss_core_component;
201 static bool omapdss_list_contains(const struct device_node *node)
203 struct omapdss_comp_node *comp;
205 list_for_each_entry(comp, &omapdss_comp_list, list) {
206 if (comp->node == node)
213 static void omapdss_walk_device(struct device *dev, struct device_node *node,
216 struct omapdss_comp_node *comp;
217 struct device_node *n;
221 ret = of_property_read_string(node, "compatible", &compat);
225 comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
228 comp->dss_core_component = dss_core;
229 comp->compat = compat;
230 list_add(&comp->list, &omapdss_comp_list);
234 * of_graph_get_remote_port_parent() prints an error if there is no
235 * port/ports node. To avoid that, check first that there's the node.
237 n = of_get_child_by_name(node, "ports");
239 n = of_get_child_by_name(node, "port");
246 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
247 struct device_node *pn = of_graph_get_remote_port_parent(n);
252 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
257 omapdss_walk_device(dev, pn, false);
261 void omapdss_gather_components(struct device *dev)
263 struct device_node *child;
265 INIT_LIST_HEAD(&omapdss_comp_list);
267 omapdss_walk_device(dev, dev->of_node, true);
269 for_each_available_child_of_node(dev->of_node, child)
270 omapdss_walk_device(dev, child, true);
273 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
275 if (comp->dss_core_component)
277 if (!strstarts(comp->compat, "omapdss,"))
279 if (omapdss_device_is_registered(comp->node))
285 bool omapdss_stack_is_ready(void)
287 struct omapdss_comp_node *comp;
289 list_for_each_entry(comp, &omapdss_comp_list, list) {
290 if (!omapdss_component_is_loaded(comp))