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> 17*6a7c5a22SLaurent Pinchart #include <linux/list.h> 18a99ac0d9STomi Valkeinen #include <linux/module.h> 19*6a7c5a22SLaurent Pinchart #include <linux/mutex.h> 201e08c822SPeter Ujfalusi #include <linux/of.h> 211e08c822SPeter Ujfalusi #include <linux/of_graph.h> 22d3541ca8SLaurent Pinchart 23d3541ca8SLaurent Pinchart #include "dss.h" 241e08c822SPeter Ujfalusi #include "omapdss.h" 25a99ac0d9STomi Valkeinen 2672877cf3SLaurent Pinchart static struct dss_device *dss_device; 277c299716STomi Valkeinen 2872877cf3SLaurent Pinchart struct dss_device *omapdss_get_dss(void) 297c299716STomi Valkeinen { 3072877cf3SLaurent Pinchart return dss_device; 317c299716STomi Valkeinen } 3272877cf3SLaurent Pinchart EXPORT_SYMBOL(omapdss_get_dss); 337c299716STomi Valkeinen 3472877cf3SLaurent Pinchart void omapdss_set_dss(struct dss_device *dss) 357c299716STomi Valkeinen { 3672877cf3SLaurent Pinchart dss_device = dss; 377c299716STomi Valkeinen } 3872877cf3SLaurent Pinchart EXPORT_SYMBOL(omapdss_set_dss); 397c299716STomi Valkeinen 4050638ae5SLaurent Pinchart struct dispc_device *dispc_get_dispc(struct dss_device *dss) 4150638ae5SLaurent Pinchart { 4250638ae5SLaurent Pinchart return dss->dispc; 4350638ae5SLaurent Pinchart } 4450638ae5SLaurent Pinchart EXPORT_SYMBOL(dispc_get_dispc); 4550638ae5SLaurent Pinchart 46d3541ca8SLaurent Pinchart const struct dispc_ops *dispc_get_ops(struct dss_device *dss) 478a13398cSTomi Valkeinen { 48d3541ca8SLaurent Pinchart return dss->dispc_ops; 498a13398cSTomi Valkeinen } 508a13398cSTomi Valkeinen EXPORT_SYMBOL(dispc_get_ops); 518a13398cSTomi Valkeinen 52*6a7c5a22SLaurent Pinchart 53*6a7c5a22SLaurent Pinchart /* ----------------------------------------------------------------------------- 54*6a7c5a22SLaurent Pinchart * OMAP DSS Devices Handling 55*6a7c5a22SLaurent Pinchart */ 56*6a7c5a22SLaurent Pinchart 57*6a7c5a22SLaurent Pinchart static LIST_HEAD(omapdss_devices_list); 58*6a7c5a22SLaurent Pinchart static DEFINE_MUTEX(omapdss_devices_lock); 59*6a7c5a22SLaurent Pinchart 60*6a7c5a22SLaurent Pinchart void omapdss_device_register(struct omap_dss_device *dssdev) 61*6a7c5a22SLaurent Pinchart { 62*6a7c5a22SLaurent Pinchart mutex_lock(&omapdss_devices_lock); 63*6a7c5a22SLaurent Pinchart list_add_tail(&dssdev->list, &omapdss_devices_list); 64*6a7c5a22SLaurent Pinchart mutex_unlock(&omapdss_devices_lock); 65*6a7c5a22SLaurent Pinchart } 66*6a7c5a22SLaurent Pinchart 67*6a7c5a22SLaurent Pinchart void omapdss_device_unregister(struct omap_dss_device *dssdev) 68*6a7c5a22SLaurent Pinchart { 69*6a7c5a22SLaurent Pinchart mutex_lock(&omapdss_devices_lock); 70*6a7c5a22SLaurent Pinchart list_del(&dssdev->list); 71*6a7c5a22SLaurent Pinchart mutex_unlock(&omapdss_devices_lock); 72*6a7c5a22SLaurent Pinchart } 73*6a7c5a22SLaurent Pinchart 74*6a7c5a22SLaurent Pinchart /* ----------------------------------------------------------------------------- 75*6a7c5a22SLaurent Pinchart * Components Handling 76*6a7c5a22SLaurent Pinchart */ 77*6a7c5a22SLaurent Pinchart 78*6a7c5a22SLaurent Pinchart static struct list_head omapdss_comp_list; 79*6a7c5a22SLaurent Pinchart 80*6a7c5a22SLaurent Pinchart struct omapdss_comp_node { 81*6a7c5a22SLaurent Pinchart struct list_head list; 82*6a7c5a22SLaurent Pinchart struct device_node *node; 83*6a7c5a22SLaurent Pinchart bool dss_core_component; 84*6a7c5a22SLaurent Pinchart }; 85*6a7c5a22SLaurent Pinchart 861e08c822SPeter Ujfalusi static bool omapdss_list_contains(const struct device_node *node) 871e08c822SPeter Ujfalusi { 881e08c822SPeter Ujfalusi struct omapdss_comp_node *comp; 891e08c822SPeter Ujfalusi 901e08c822SPeter Ujfalusi list_for_each_entry(comp, &omapdss_comp_list, list) { 911e08c822SPeter Ujfalusi if (comp->node == node) 921e08c822SPeter Ujfalusi return true; 931e08c822SPeter Ujfalusi } 941e08c822SPeter Ujfalusi 951e08c822SPeter Ujfalusi return false; 961e08c822SPeter Ujfalusi } 971e08c822SPeter Ujfalusi 981e08c822SPeter Ujfalusi static void omapdss_walk_device(struct device *dev, struct device_node *node, 991e08c822SPeter Ujfalusi bool dss_core) 1001e08c822SPeter Ujfalusi { 1011e08c822SPeter Ujfalusi struct device_node *n; 1021e08c822SPeter Ujfalusi struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp), 1031e08c822SPeter Ujfalusi GFP_KERNEL); 1041e08c822SPeter Ujfalusi 1051e08c822SPeter Ujfalusi if (comp) { 1061e08c822SPeter Ujfalusi comp->node = node; 1071e08c822SPeter Ujfalusi comp->dss_core_component = dss_core; 1081e08c822SPeter Ujfalusi list_add(&comp->list, &omapdss_comp_list); 1091e08c822SPeter Ujfalusi } 1101e08c822SPeter Ujfalusi 1111e08c822SPeter Ujfalusi /* 1121e08c822SPeter Ujfalusi * of_graph_get_remote_port_parent() prints an error if there is no 1131e08c822SPeter Ujfalusi * port/ports node. To avoid that, check first that there's the node. 1141e08c822SPeter Ujfalusi */ 1151e08c822SPeter Ujfalusi n = of_get_child_by_name(node, "ports"); 1161e08c822SPeter Ujfalusi if (!n) 1171e08c822SPeter Ujfalusi n = of_get_child_by_name(node, "port"); 1181e08c822SPeter Ujfalusi if (!n) 1191e08c822SPeter Ujfalusi return; 1201e08c822SPeter Ujfalusi 1211e08c822SPeter Ujfalusi of_node_put(n); 1221e08c822SPeter Ujfalusi 1231e08c822SPeter Ujfalusi n = NULL; 1241e08c822SPeter Ujfalusi while ((n = of_graph_get_next_endpoint(node, n)) != NULL) { 1251e08c822SPeter Ujfalusi struct device_node *pn = of_graph_get_remote_port_parent(n); 1261e08c822SPeter Ujfalusi 1271e08c822SPeter Ujfalusi if (!pn) 1281e08c822SPeter Ujfalusi continue; 1291e08c822SPeter Ujfalusi 1301e08c822SPeter Ujfalusi if (!of_device_is_available(pn) || omapdss_list_contains(pn)) { 1311e08c822SPeter Ujfalusi of_node_put(pn); 1321e08c822SPeter Ujfalusi continue; 1331e08c822SPeter Ujfalusi } 1341e08c822SPeter Ujfalusi 1351e08c822SPeter Ujfalusi omapdss_walk_device(dev, pn, false); 1361e08c822SPeter Ujfalusi } 1371e08c822SPeter Ujfalusi } 1381e08c822SPeter Ujfalusi 1391e08c822SPeter Ujfalusi void omapdss_gather_components(struct device *dev) 1401e08c822SPeter Ujfalusi { 1411e08c822SPeter Ujfalusi struct device_node *child; 1421e08c822SPeter Ujfalusi 1431e08c822SPeter Ujfalusi INIT_LIST_HEAD(&omapdss_comp_list); 1441e08c822SPeter Ujfalusi 1451e08c822SPeter Ujfalusi omapdss_walk_device(dev, dev->of_node, true); 1461e08c822SPeter Ujfalusi 1471e08c822SPeter Ujfalusi for_each_available_child_of_node(dev->of_node, child) { 1481e08c822SPeter Ujfalusi if (!of_find_property(child, "compatible", NULL)) 1491e08c822SPeter Ujfalusi continue; 1501e08c822SPeter Ujfalusi 1511e08c822SPeter Ujfalusi omapdss_walk_device(dev, child, true); 1521e08c822SPeter Ujfalusi } 1531e08c822SPeter Ujfalusi } 1541e08c822SPeter Ujfalusi EXPORT_SYMBOL(omapdss_gather_components); 1551e08c822SPeter Ujfalusi 1561e08c822SPeter Ujfalusi static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp) 1571e08c822SPeter Ujfalusi { 1581e08c822SPeter Ujfalusi if (comp->dss_core_component) 1591e08c822SPeter Ujfalusi return true; 1601e08c822SPeter Ujfalusi if (omapdss_component_is_display(comp->node)) 1611e08c822SPeter Ujfalusi return true; 1621e08c822SPeter Ujfalusi if (omapdss_component_is_output(comp->node)) 1631e08c822SPeter Ujfalusi return true; 1641e08c822SPeter Ujfalusi 1651e08c822SPeter Ujfalusi return false; 1661e08c822SPeter Ujfalusi } 1671e08c822SPeter Ujfalusi 1681e08c822SPeter Ujfalusi bool omapdss_stack_is_ready(void) 1691e08c822SPeter Ujfalusi { 1701e08c822SPeter Ujfalusi struct omapdss_comp_node *comp; 1711e08c822SPeter Ujfalusi 1721e08c822SPeter Ujfalusi list_for_each_entry(comp, &omapdss_comp_list, list) { 1731e08c822SPeter Ujfalusi if (!omapdss_component_is_loaded(comp)) 1741e08c822SPeter Ujfalusi return false; 1751e08c822SPeter Ujfalusi } 1761e08c822SPeter Ujfalusi 1771e08c822SPeter Ujfalusi return true; 1781e08c822SPeter Ujfalusi } 1791e08c822SPeter Ujfalusi EXPORT_SYMBOL(omapdss_stack_is_ready); 1801e08c822SPeter Ujfalusi 181a99ac0d9STomi Valkeinen MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); 182a99ac0d9STomi Valkeinen MODULE_DESCRIPTION("OMAP Display Subsystem Base"); 183a99ac0d9STomi Valkeinen MODULE_LICENSE("GPL v2"); 184