xref: /linux/drivers/gpu/drm/omapdrm/dss/base.c (revision 72877cf38b4b78fbb3a852f2288d7f2a7af0db22)
1bb5cdf8dSAndrew F. Davis /*
2bb5cdf8dSAndrew F. Davis  * OMAP Display Subsystem Base
3bb5cdf8dSAndrew F. Davis  *
4bb5cdf8dSAndrew F. Davis  * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
5bb5cdf8dSAndrew F. Davis  *
6bb5cdf8dSAndrew F. Davis  * This program is free software; you can redistribute it and/or modify
7bb5cdf8dSAndrew F. Davis  * it under the terms of the GNU General Public License version 2 as
8bb5cdf8dSAndrew F. Davis  * published by the Free Software Foundation.
9bb5cdf8dSAndrew F. Davis  *
10bb5cdf8dSAndrew F. Davis  * This program is distributed in the hope that it will be useful, but
11bb5cdf8dSAndrew F. Davis  * WITHOUT ANY WARRANTY; without even the implied warranty of
12bb5cdf8dSAndrew F. Davis  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13bb5cdf8dSAndrew F. Davis  * General Public License for more details.
14bb5cdf8dSAndrew F. Davis  */
15bb5cdf8dSAndrew F. Davis 
16a99ac0d9STomi Valkeinen #include <linux/kernel.h>
17a99ac0d9STomi Valkeinen #include <linux/module.h>
181e08c822SPeter Ujfalusi #include <linux/of.h>
191e08c822SPeter Ujfalusi #include <linux/of_graph.h>
201e08c822SPeter Ujfalusi #include <linux/list.h>
211e08c822SPeter Ujfalusi #include "omapdss.h"
22a99ac0d9STomi Valkeinen 
23*72877cf3SLaurent Pinchart static struct dss_device *dss_device;
248a13398cSTomi Valkeinen static const struct dispc_ops *ops;
257c299716STomi Valkeinen 
261e08c822SPeter Ujfalusi static struct list_head omapdss_comp_list;
271e08c822SPeter Ujfalusi 
281e08c822SPeter Ujfalusi struct omapdss_comp_node {
291e08c822SPeter Ujfalusi 	struct list_head list;
301e08c822SPeter Ujfalusi 	struct device_node *node;
311e08c822SPeter Ujfalusi 	bool dss_core_component;
321e08c822SPeter Ujfalusi };
331e08c822SPeter Ujfalusi 
34*72877cf3SLaurent Pinchart struct dss_device *omapdss_get_dss(void)
357c299716STomi Valkeinen {
36*72877cf3SLaurent Pinchart 	return dss_device;
377c299716STomi Valkeinen }
38*72877cf3SLaurent Pinchart EXPORT_SYMBOL(omapdss_get_dss);
397c299716STomi Valkeinen 
40*72877cf3SLaurent Pinchart void omapdss_set_dss(struct dss_device *dss)
417c299716STomi Valkeinen {
42*72877cf3SLaurent Pinchart 	dss_device = dss;
437c299716STomi Valkeinen }
44*72877cf3SLaurent Pinchart EXPORT_SYMBOL(omapdss_set_dss);
457c299716STomi Valkeinen 
468a13398cSTomi Valkeinen void dispc_set_ops(const struct dispc_ops *o)
478a13398cSTomi Valkeinen {
488a13398cSTomi Valkeinen 	ops = o;
498a13398cSTomi Valkeinen }
508a13398cSTomi Valkeinen EXPORT_SYMBOL(dispc_set_ops);
518a13398cSTomi Valkeinen 
528a13398cSTomi Valkeinen const struct dispc_ops *dispc_get_ops(void)
538a13398cSTomi Valkeinen {
548a13398cSTomi Valkeinen 	return ops;
558a13398cSTomi Valkeinen }
568a13398cSTomi Valkeinen EXPORT_SYMBOL(dispc_get_ops);
578a13398cSTomi Valkeinen 
581e08c822SPeter Ujfalusi static bool omapdss_list_contains(const struct device_node *node)
591e08c822SPeter Ujfalusi {
601e08c822SPeter Ujfalusi 	struct omapdss_comp_node *comp;
611e08c822SPeter Ujfalusi 
621e08c822SPeter Ujfalusi 	list_for_each_entry(comp, &omapdss_comp_list, list) {
631e08c822SPeter Ujfalusi 		if (comp->node == node)
641e08c822SPeter Ujfalusi 			return true;
651e08c822SPeter Ujfalusi 	}
661e08c822SPeter Ujfalusi 
671e08c822SPeter Ujfalusi 	return false;
681e08c822SPeter Ujfalusi }
691e08c822SPeter Ujfalusi 
701e08c822SPeter Ujfalusi static void omapdss_walk_device(struct device *dev, struct device_node *node,
711e08c822SPeter Ujfalusi 				bool dss_core)
721e08c822SPeter Ujfalusi {
731e08c822SPeter Ujfalusi 	struct device_node *n;
741e08c822SPeter Ujfalusi 	struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp),
751e08c822SPeter Ujfalusi 						      GFP_KERNEL);
761e08c822SPeter Ujfalusi 
771e08c822SPeter Ujfalusi 	if (comp) {
781e08c822SPeter Ujfalusi 		comp->node = node;
791e08c822SPeter Ujfalusi 		comp->dss_core_component = dss_core;
801e08c822SPeter Ujfalusi 		list_add(&comp->list, &omapdss_comp_list);
811e08c822SPeter Ujfalusi 	}
821e08c822SPeter Ujfalusi 
831e08c822SPeter Ujfalusi 	/*
841e08c822SPeter Ujfalusi 	 * of_graph_get_remote_port_parent() prints an error if there is no
851e08c822SPeter Ujfalusi 	 * port/ports node. To avoid that, check first that there's the node.
861e08c822SPeter Ujfalusi 	 */
871e08c822SPeter Ujfalusi 	n = of_get_child_by_name(node, "ports");
881e08c822SPeter Ujfalusi 	if (!n)
891e08c822SPeter Ujfalusi 		n = of_get_child_by_name(node, "port");
901e08c822SPeter Ujfalusi 	if (!n)
911e08c822SPeter Ujfalusi 		return;
921e08c822SPeter Ujfalusi 
931e08c822SPeter Ujfalusi 	of_node_put(n);
941e08c822SPeter Ujfalusi 
951e08c822SPeter Ujfalusi 	n = NULL;
961e08c822SPeter Ujfalusi 	while ((n = of_graph_get_next_endpoint(node, n)) != NULL) {
971e08c822SPeter Ujfalusi 		struct device_node *pn = of_graph_get_remote_port_parent(n);
981e08c822SPeter Ujfalusi 
991e08c822SPeter Ujfalusi 		if (!pn)
1001e08c822SPeter Ujfalusi 			continue;
1011e08c822SPeter Ujfalusi 
1021e08c822SPeter Ujfalusi 		if (!of_device_is_available(pn) || omapdss_list_contains(pn)) {
1031e08c822SPeter Ujfalusi 			of_node_put(pn);
1041e08c822SPeter Ujfalusi 			continue;
1051e08c822SPeter Ujfalusi 		}
1061e08c822SPeter Ujfalusi 
1071e08c822SPeter Ujfalusi 		omapdss_walk_device(dev, pn, false);
1081e08c822SPeter Ujfalusi 	}
1091e08c822SPeter Ujfalusi }
1101e08c822SPeter Ujfalusi 
1111e08c822SPeter Ujfalusi void omapdss_gather_components(struct device *dev)
1121e08c822SPeter Ujfalusi {
1131e08c822SPeter Ujfalusi 	struct device_node *child;
1141e08c822SPeter Ujfalusi 
1151e08c822SPeter Ujfalusi 	INIT_LIST_HEAD(&omapdss_comp_list);
1161e08c822SPeter Ujfalusi 
1171e08c822SPeter Ujfalusi 	omapdss_walk_device(dev, dev->of_node, true);
1181e08c822SPeter Ujfalusi 
1191e08c822SPeter Ujfalusi 	for_each_available_child_of_node(dev->of_node, child) {
1201e08c822SPeter Ujfalusi 		if (!of_find_property(child, "compatible", NULL))
1211e08c822SPeter Ujfalusi 			continue;
1221e08c822SPeter Ujfalusi 
1231e08c822SPeter Ujfalusi 		omapdss_walk_device(dev, child, true);
1241e08c822SPeter Ujfalusi 	}
1251e08c822SPeter Ujfalusi }
1261e08c822SPeter Ujfalusi EXPORT_SYMBOL(omapdss_gather_components);
1271e08c822SPeter Ujfalusi 
1281e08c822SPeter Ujfalusi static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp)
1291e08c822SPeter Ujfalusi {
1301e08c822SPeter Ujfalusi 	if (comp->dss_core_component)
1311e08c822SPeter Ujfalusi 		return true;
1321e08c822SPeter Ujfalusi 	if (omapdss_component_is_display(comp->node))
1331e08c822SPeter Ujfalusi 		return true;
1341e08c822SPeter Ujfalusi 	if (omapdss_component_is_output(comp->node))
1351e08c822SPeter Ujfalusi 		return true;
1361e08c822SPeter Ujfalusi 
1371e08c822SPeter Ujfalusi 	return false;
1381e08c822SPeter Ujfalusi }
1391e08c822SPeter Ujfalusi 
1401e08c822SPeter Ujfalusi bool omapdss_stack_is_ready(void)
1411e08c822SPeter Ujfalusi {
1421e08c822SPeter Ujfalusi 	struct omapdss_comp_node *comp;
1431e08c822SPeter Ujfalusi 
1441e08c822SPeter Ujfalusi 	list_for_each_entry(comp, &omapdss_comp_list, list) {
1451e08c822SPeter Ujfalusi 		if (!omapdss_component_is_loaded(comp))
1461e08c822SPeter Ujfalusi 			return false;
1471e08c822SPeter Ujfalusi 	}
1481e08c822SPeter Ujfalusi 
1491e08c822SPeter Ujfalusi 	return true;
1501e08c822SPeter Ujfalusi }
1511e08c822SPeter Ujfalusi EXPORT_SYMBOL(omapdss_stack_is_ready);
1521e08c822SPeter Ujfalusi 
153a99ac0d9STomi Valkeinen MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>");
154a99ac0d9STomi Valkeinen MODULE_DESCRIPTION("OMAP Display Subsystem Base");
155a99ac0d9STomi Valkeinen MODULE_LICENSE("GPL v2");
156