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