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 25 static struct dss_device *dss_device; 26 27 static struct list_head omapdss_comp_list; 28 29 struct omapdss_comp_node { 30 struct list_head list; 31 struct device_node *node; 32 bool dss_core_component; 33 }; 34 35 struct dss_device *omapdss_get_dss(void) 36 { 37 return dss_device; 38 } 39 EXPORT_SYMBOL(omapdss_get_dss); 40 41 void omapdss_set_dss(struct dss_device *dss) 42 { 43 dss_device = dss; 44 } 45 EXPORT_SYMBOL(omapdss_set_dss); 46 47 const struct dispc_ops *dispc_get_ops(struct dss_device *dss) 48 { 49 return dss->dispc_ops; 50 } 51 EXPORT_SYMBOL(dispc_get_ops); 52 53 static bool omapdss_list_contains(const struct device_node *node) 54 { 55 struct omapdss_comp_node *comp; 56 57 list_for_each_entry(comp, &omapdss_comp_list, list) { 58 if (comp->node == node) 59 return true; 60 } 61 62 return false; 63 } 64 65 static void omapdss_walk_device(struct device *dev, struct device_node *node, 66 bool dss_core) 67 { 68 struct device_node *n; 69 struct omapdss_comp_node *comp = devm_kzalloc(dev, sizeof(*comp), 70 GFP_KERNEL); 71 72 if (comp) { 73 comp->node = node; 74 comp->dss_core_component = dss_core; 75 list_add(&comp->list, &omapdss_comp_list); 76 } 77 78 /* 79 * of_graph_get_remote_port_parent() prints an error if there is no 80 * port/ports node. To avoid that, check first that there's the node. 81 */ 82 n = of_get_child_by_name(node, "ports"); 83 if (!n) 84 n = of_get_child_by_name(node, "port"); 85 if (!n) 86 return; 87 88 of_node_put(n); 89 90 n = NULL; 91 while ((n = of_graph_get_next_endpoint(node, n)) != NULL) { 92 struct device_node *pn = of_graph_get_remote_port_parent(n); 93 94 if (!pn) 95 continue; 96 97 if (!of_device_is_available(pn) || omapdss_list_contains(pn)) { 98 of_node_put(pn); 99 continue; 100 } 101 102 omapdss_walk_device(dev, pn, false); 103 } 104 } 105 106 void omapdss_gather_components(struct device *dev) 107 { 108 struct device_node *child; 109 110 INIT_LIST_HEAD(&omapdss_comp_list); 111 112 omapdss_walk_device(dev, dev->of_node, true); 113 114 for_each_available_child_of_node(dev->of_node, child) { 115 if (!of_find_property(child, "compatible", NULL)) 116 continue; 117 118 omapdss_walk_device(dev, child, true); 119 } 120 } 121 EXPORT_SYMBOL(omapdss_gather_components); 122 123 static bool omapdss_component_is_loaded(struct omapdss_comp_node *comp) 124 { 125 if (comp->dss_core_component) 126 return true; 127 if (omapdss_component_is_display(comp->node)) 128 return true; 129 if (omapdss_component_is_output(comp->node)) 130 return true; 131 132 return false; 133 } 134 135 bool omapdss_stack_is_ready(void) 136 { 137 struct omapdss_comp_node *comp; 138 139 list_for_each_entry(comp, &omapdss_comp_list, list) { 140 if (!omapdss_component_is_loaded(comp)) 141 return false; 142 } 143 144 return true; 145 } 146 EXPORT_SYMBOL(omapdss_stack_is_ready); 147 148 MODULE_AUTHOR("Tomi Valkeinen <tomi.valkeinen@ti.com>"); 149 MODULE_DESCRIPTION("OMAP Display Subsystem Base"); 150 MODULE_LICENSE("GPL v2"); 151