base.c 3.4 KB

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