dss-of.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (C) 2013 Texas Instruments
  3. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #include <linux/device.h>
  15. #include <linux/err.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/seq_file.h>
  19. #include <video/omapdss.h>
  20. struct device_node *
  21. omapdss_of_get_next_port(const struct device_node *parent,
  22. struct device_node *prev)
  23. {
  24. struct device_node *port = NULL;
  25. if (!parent)
  26. return NULL;
  27. if (!prev) {
  28. struct device_node *ports;
  29. /*
  30. * It's the first call, we have to find a port subnode
  31. * within this node or within an optional 'ports' node.
  32. */
  33. ports = of_get_child_by_name(parent, "ports");
  34. if (ports)
  35. parent = ports;
  36. port = of_get_child_by_name(parent, "port");
  37. /* release the 'ports' node */
  38. of_node_put(ports);
  39. } else {
  40. struct device_node *ports;
  41. ports = of_get_parent(prev);
  42. if (!ports)
  43. return NULL;
  44. do {
  45. port = of_get_next_child(ports, prev);
  46. if (!port) {
  47. of_node_put(ports);
  48. return NULL;
  49. }
  50. prev = port;
  51. } while (of_node_cmp(port->name, "port") != 0);
  52. }
  53. return port;
  54. }
  55. EXPORT_SYMBOL_GPL(omapdss_of_get_next_port);
  56. struct device_node *
  57. omapdss_of_get_next_endpoint(const struct device_node *parent,
  58. struct device_node *prev)
  59. {
  60. struct device_node *ep = NULL;
  61. if (!parent)
  62. return NULL;
  63. do {
  64. ep = of_get_next_child(parent, prev);
  65. if (!ep)
  66. return NULL;
  67. prev = ep;
  68. } while (of_node_cmp(ep->name, "endpoint") != 0);
  69. return ep;
  70. }
  71. EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint);
  72. static struct device_node *
  73. omapdss_of_get_remote_device_node(const struct device_node *node)
  74. {
  75. struct device_node *np;
  76. int i;
  77. np = of_parse_phandle(node, "remote-endpoint", 0);
  78. if (!np)
  79. return NULL;
  80. np = of_get_next_parent(np);
  81. for (i = 0; i < 3 && np; ++i) {
  82. struct property *prop;
  83. prop = of_find_property(np, "compatible", NULL);
  84. if (prop)
  85. return np;
  86. np = of_get_next_parent(np);
  87. }
  88. return NULL;
  89. }
  90. struct device_node *
  91. omapdss_of_get_first_endpoint(const struct device_node *parent)
  92. {
  93. struct device_node *port, *ep;
  94. port = omapdss_of_get_next_port(parent, NULL);
  95. if (!port)
  96. return NULL;
  97. ep = omapdss_of_get_next_endpoint(port, NULL);
  98. of_node_put(port);
  99. return ep;
  100. }
  101. EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint);
  102. struct omap_dss_device *
  103. omapdss_of_find_source_for_first_ep(struct device_node *node)
  104. {
  105. struct device_node *ep;
  106. struct device_node *src_node;
  107. struct omap_dss_device *src;
  108. ep = omapdss_of_get_first_endpoint(node);
  109. if (!ep)
  110. return ERR_PTR(-EINVAL);
  111. src_node = omapdss_of_get_remote_device_node(ep);
  112. of_node_put(ep);
  113. if (!src_node)
  114. return ERR_PTR(-EINVAL);
  115. src = omap_dss_find_output_by_node(src_node);
  116. of_node_put(src_node);
  117. if (!src)
  118. return ERR_PTR(-EPROBE_DEFER);
  119. return src;
  120. }
  121. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);