Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v4.17
 
  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/module.h>
 
 18#include <linux/of.h>
 19#include <linux/of_graph.h>
 20#include <linux/list.h>
 21
 22#include "dss.h"
 23#include "omapdss.h"
 24
 25static struct dss_device *dss_device;
 26
 27static struct list_head omapdss_comp_list;
 28
 29struct omapdss_comp_node {
 30	struct list_head list;
 31	struct device_node *node;
 32	bool dss_core_component;
 33};
 34
 35struct dss_device *omapdss_get_dss(void)
 36{
 37	return dss_device;
 38}
 39EXPORT_SYMBOL(omapdss_get_dss);
 40
 41void omapdss_set_dss(struct dss_device *dss)
 42{
 43	dss_device = dss;
 44}
 45EXPORT_SYMBOL(omapdss_set_dss);
 46
 47struct dispc_device *dispc_get_dispc(struct dss_device *dss)
 48{
 49	return dss->dispc;
 50}
 51EXPORT_SYMBOL(dispc_get_dispc);
 52
 53const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
 54{
 55	return dss->dispc_ops;
 56}
 57EXPORT_SYMBOL(dispc_get_ops);
 58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 59static bool omapdss_list_contains(const struct device_node *node)
 60{
 61	struct omapdss_comp_node *comp;
 62
 63	list_for_each_entry(comp, &omapdss_comp_list, list) {
 64		if (comp->node == node)
 65			return true;
 66	}
 67
 68	return false;
 69}
 70
 71static void omapdss_walk_device(struct device *dev, struct device_node *node,
 72				bool dss_core)
 73{
 
 74	struct device_node *n;
 75	struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
 76						      GFP_KERNEL);
 
 
 
 
 77
 
 78	if (comp) {
 79		comp->node = node;
 80		comp->dss_core_component = dss_core;
 
 81		list_add(&comp->list, &omapdss_comp_list);
 82	}
 83
 84	/*
 85	 * of_graph_get_remote_port_parent() prints an error if there is no
 86	 * port/ports node. To avoid that, check first that there's the node.
 87	 */
 88	n = of_get_child_by_name(node, "ports");
 89	if (!n)
 90		n = of_get_child_by_name(node, "port");
 91	if (!n)
 92		return;
 93
 94	of_node_put(n);
 95
 96	n = NULL;
 97	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
 98		struct device_node *pn = of_graph_get_remote_port_parent(n);
 99
100		if (!pn)
101			continue;
102
103		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
104			of_node_put(pn);
105			continue;
106		}
107
108		omapdss_walk_device(dev, pn, false);
109	}
110}
111
112void omapdss_gather_components(struct device *dev)
113{
114	struct device_node *child;
115
116	INIT_LIST_HEAD(&omapdss_comp_list);
117
118	omapdss_walk_device(dev, dev->of_node, true);
119
120	for_each_available_child_of_node(dev->of_node, child) {
121		if (!of_find_property(child, "compatible", NULL))
122			continue;
123
124		omapdss_walk_device(dev, child, true);
125	}
126}
127EXPORT_SYMBOL(omapdss_gather_components);
128
129static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
130{
131	if (comp->dss_core_component)
132		return true;
133	if (omapdss_component_is_display(comp->node))
134		return true;
135	if (omapdss_component_is_output(comp->node))
136		return true;
137
138	return false;
139}
140
141bool omapdss_stack_is_ready(void)
142{
143	struct omapdss_comp_node *comp;
144
145	list_for_each_entry(comp, &omapdss_comp_list, list) {
146		if (!omapdss_component_is_loaded(comp))
147			return false;
148	}
149
150	return true;
151}
152EXPORT_SYMBOL(omapdss_stack_is_ready);
153
154MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
155MODULE_DESCRIPTION("OMAP Display Subsystem Base");
156MODULE_LICENSE("GPL v2");
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * OMAP Display Subsystem Base
  4 *
  5 * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#include <linux/kernel.h>
  9#include <linux/list.h>
 10#include <linux/module.h>
 11#include <linux/mutex.h>
 12#include <linux/of.h>
 13#include <linux/of_graph.h>
 14#include <linux/platform_device.h>
 15
 16#include "dss.h"
 17#include "omapdss.h"
 18
 19static struct dss_device *dss_device;
 20
 
 
 
 
 
 
 
 
 21struct dss_device *omapdss_get_dss(void)
 22{
 23	return dss_device;
 24}
 25EXPORT_SYMBOL(omapdss_get_dss);
 26
 27void omapdss_set_dss(struct dss_device *dss)
 28{
 29	dss_device = dss;
 30}
 31EXPORT_SYMBOL(omapdss_set_dss);
 32
 33struct dispc_device *dispc_get_dispc(struct dss_device *dss)
 34{
 35	return dss->dispc;
 36}
 37EXPORT_SYMBOL(dispc_get_dispc);
 38
 39const struct dispc_ops *dispc_get_ops(struct dss_device *dss)
 40{
 41	return dss->dispc_ops;
 42}
 43EXPORT_SYMBOL(dispc_get_ops);
 44
 45
 46/* -----------------------------------------------------------------------------
 47 * OMAP DSS Devices Handling
 48 */
 49
 50static LIST_HEAD(omapdss_devices_list);
 51static DEFINE_MUTEX(omapdss_devices_lock);
 52
 53void omapdss_device_register(struct omap_dss_device *dssdev)
 54{
 55	mutex_lock(&omapdss_devices_lock);
 56	list_add_tail(&dssdev->list, &omapdss_devices_list);
 57	mutex_unlock(&omapdss_devices_lock);
 58}
 59EXPORT_SYMBOL_GPL(omapdss_device_register);
 60
 61void omapdss_device_unregister(struct omap_dss_device *dssdev)
 62{
 63	mutex_lock(&omapdss_devices_lock);
 64	list_del(&dssdev->list);
 65	mutex_unlock(&omapdss_devices_lock);
 66}
 67EXPORT_SYMBOL_GPL(omapdss_device_unregister);
 68
 69static bool omapdss_device_is_registered(struct device_node *node)
 70{
 71	struct omap_dss_device *dssdev;
 72	bool found = false;
 73
 74	mutex_lock(&omapdss_devices_lock);
 75
 76	list_for_each_entry(dssdev, &omapdss_devices_list, list) {
 77		if (dssdev->dev->of_node == node) {
 78			found = true;
 79			break;
 80		}
 81	}
 82
 83	mutex_unlock(&omapdss_devices_lock);
 84	return found;
 85}
 86
 87struct omap_dss_device *omapdss_device_get(struct omap_dss_device *dssdev)
 88{
 89	if (!try_module_get(dssdev->owner))
 90		return NULL;
 91
 92	if (get_device(dssdev->dev) == NULL) {
 93		module_put(dssdev->owner);
 94		return NULL;
 95	}
 96
 97	return dssdev;
 98}
 99EXPORT_SYMBOL(omapdss_device_get);
100
101void omapdss_device_put(struct omap_dss_device *dssdev)
102{
103	put_device(dssdev->dev);
104	module_put(dssdev->owner);
105}
106EXPORT_SYMBOL(omapdss_device_put);
107
108struct omap_dss_device *omapdss_find_device_by_node(struct device_node *node)
109{
110	struct omap_dss_device *dssdev;
111
112	list_for_each_entry(dssdev, &omapdss_devices_list, list) {
113		if (dssdev->dev->of_node == node)
114			return omapdss_device_get(dssdev);
115	}
116
117	return NULL;
118}
119
120/*
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.
123 */
124struct omap_dss_device *omapdss_device_next_output(struct omap_dss_device *from)
125{
126	struct omap_dss_device *dssdev;
127	struct list_head *list;
128
129	mutex_lock(&omapdss_devices_lock);
130
131	if (list_empty(&omapdss_devices_list)) {
132		dssdev = NULL;
133		goto done;
134	}
135
136	/*
137	 * Start from the from entry if given or from omapdss_devices_list
138	 * otherwise.
139	 */
140	list = from ? &from->list : &omapdss_devices_list;
141
142	list_for_each_entry(dssdev, list, list) {
143		/*
144		 * Stop if we reach the omapdss_devices_list, that's the end of
145		 * the list.
146		 */
147		if (&dssdev->list == &omapdss_devices_list) {
148			dssdev = NULL;
149			goto done;
150		}
151
152		if (dssdev->id && (dssdev->next || dssdev->bridge))
153			goto done;
154	}
155
156	dssdev = NULL;
157
158done:
159	if (from)
160		omapdss_device_put(from);
161	if (dssdev)
162		omapdss_device_get(dssdev);
163
164	mutex_unlock(&omapdss_devices_lock);
165	return dssdev;
166}
167EXPORT_SYMBOL(omapdss_device_next_output);
168
169static bool omapdss_device_is_connected(struct omap_dss_device *dssdev)
170{
171	return dssdev->dss;
172}
173
174int omapdss_device_connect(struct dss_device *dss,
175			   struct omap_dss_device *src,
176			   struct omap_dss_device *dst)
177{
178	int ret;
179
180	dev_dbg(&dss->pdev->dev, "connect(%s, %s)\n",
181		src ? dev_name(src->dev) : "NULL",
182		dst ? dev_name(dst->dev) : "NULL");
183
184	if (!dst) {
185		/*
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.
189		 */
190		return src && src->bridge ? 0 : -EINVAL;
191	}
192
193	if (omapdss_device_is_connected(dst))
194		return -EBUSY;
195
196	dst->dss = dss;
197
198	if (dst->ops && dst->ops->connect) {
199		ret = dst->ops->connect(src, dst);
200		if (ret < 0) {
201			dst->dss = NULL;
202			return ret;
203		}
204	}
205
206	return 0;
207}
208EXPORT_SYMBOL_GPL(omapdss_device_connect);
209
210void omapdss_device_disconnect(struct omap_dss_device *src,
211			       struct omap_dss_device *dst)
212{
213	struct dss_device *dss = src ? src->dss : dst->dss;
214
215	dev_dbg(&dss->pdev->dev, "disconnect(%s, %s)\n",
216		src ? dev_name(src->dev) : "NULL",
217		dst ? dev_name(dst->dev) : "NULL");
218
219	if (!dst) {
220		WARN_ON(!src->bridge);
221		return;
222	}
223
224	if (!dst->id && !omapdss_device_is_connected(dst)) {
225		WARN_ON(!dst->display);
226		return;
227	}
228
229	WARN_ON(dst->state != OMAP_DSS_DISPLAY_DISABLED);
230
231	if (dst->ops && dst->ops->disconnect)
232		dst->ops->disconnect(src, dst);
233	dst->dss = NULL;
234}
235EXPORT_SYMBOL_GPL(omapdss_device_disconnect);
236
237void omapdss_device_enable(struct omap_dss_device *dssdev)
238{
239	if (!dssdev)
240		return;
241
242	if (dssdev->ops && dssdev->ops->enable)
243		dssdev->ops->enable(dssdev);
244
245	omapdss_device_enable(dssdev->next);
246
247	dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
248}
249EXPORT_SYMBOL_GPL(omapdss_device_enable);
250
251void omapdss_device_disable(struct omap_dss_device *dssdev)
252{
253	if (!dssdev)
254		return;
255
256	omapdss_device_disable(dssdev->next);
257
258	if (dssdev->ops && dssdev->ops->disable)
259		dssdev->ops->disable(dssdev);
260}
261EXPORT_SYMBOL_GPL(omapdss_device_disable);
262
263/* -----------------------------------------------------------------------------
264 * Components Handling
265 */
266
267static struct list_head omapdss_comp_list;
268
269struct omapdss_comp_node {
270	struct list_head list;
271	struct device_node *node;
272	bool dss_core_component;
273	const char *compat;
274};
275
276static bool omapdss_list_contains(const struct device_node *node)
277{
278	struct omapdss_comp_node *comp;
279
280	list_for_each_entry(comp, &omapdss_comp_list, list) {
281		if (comp->node == node)
282			return true;
283	}
284
285	return false;
286}
287
288static void omapdss_walk_device(struct device *dev, struct device_node *node,
289				bool dss_core)
290{
291	struct omapdss_comp_node *comp;
292	struct device_node *n;
293	const char *compat;
294	int ret;
295
296	ret = of_property_read_string(node, "compatible", &compat);
297	if (ret < 0)
298		return;
299
300	comp = devm_kzalloc(dev, sizeof(*comp), GFP_KERNEL);
301	if (comp) {
302		comp->node = node;
303		comp->dss_core_component = dss_core;
304		comp->compat = compat;
305		list_add(&comp->list, &omapdss_comp_list);
306	}
307
308	/*
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.
311	 */
312	n = of_get_child_by_name(node, "ports");
313	if (!n)
314		n = of_get_child_by_name(node, "port");
315	if (!n)
316		return;
317
318	of_node_put(n);
319
320	n = NULL;
321	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
322		struct device_node *pn = of_graph_get_remote_port_parent(n);
323
324		if (!pn)
325			continue;
326
327		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
328			of_node_put(pn);
329			continue;
330		}
331
332		omapdss_walk_device(dev, pn, false);
333	}
334}
335
336void omapdss_gather_components(struct device *dev)
337{
338	struct device_node *child;
339
340	INIT_LIST_HEAD(&omapdss_comp_list);
341
342	omapdss_walk_device(dev, dev->of_node, true);
343
344	for_each_available_child_of_node(dev->of_node, child)
 
 
 
345		omapdss_walk_device(dev, child, true);
 
346}
347EXPORT_SYMBOL(omapdss_gather_components);
348
349static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
350{
351	if (comp->dss_core_component)
352		return true;
353	if (!strstarts(comp->compat, "omapdss,"))
354		return true;
355	if (omapdss_device_is_registered(comp->node))
356		return true;
357
358	return false;
359}
360
361bool omapdss_stack_is_ready(void)
362{
363	struct omapdss_comp_node *comp;
364
365	list_for_each_entry(comp, &omapdss_comp_list, list) {
366		if (!omapdss_component_is_loaded(comp))
367			return false;
368	}
369
370	return true;
371}
372EXPORT_SYMBOL(omapdss_stack_is_ready);
373
374MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
375MODULE_DESCRIPTION("OMAP Display Subsystem Base");
376MODULE_LICENSE("GPL v2");