dss-of.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #include "dss.h"
  21. struct device_node *
  22. omapdss_of_get_next_port(const struct device_node *parent,
  23. struct device_node *prev)
  24. {
  25. struct device_node *port = NULL;
  26. if (!parent)
  27. return NULL;
  28. if (!prev) {
  29. struct device_node *ports;
  30. /*
  31. * It's the first call, we have to find a port subnode
  32. * within this node or within an optional 'ports' node.
  33. */
  34. ports = of_get_child_by_name(parent, "ports");
  35. if (ports)
  36. parent = ports;
  37. port = of_get_child_by_name(parent, "port");
  38. /* release the 'ports' node */
  39. of_node_put(ports);
  40. } else {
  41. struct device_node *ports;
  42. ports = of_get_parent(prev);
  43. if (!ports)
  44. return NULL;
  45. do {
  46. port = of_get_next_child(ports, prev);
  47. if (!port) {
  48. of_node_put(ports);
  49. return NULL;
  50. }
  51. prev = port;
  52. } while (of_node_cmp(port->name, "port") != 0);
  53. }
  54. return port;
  55. }
  56. EXPORT_SYMBOL_GPL(omapdss_of_get_next_port);
  57. struct device_node *
  58. omapdss_of_get_next_endpoint(const struct device_node *parent,
  59. struct device_node *prev)
  60. {
  61. struct device_node *ep = NULL;
  62. if (!parent)
  63. return NULL;
  64. do {
  65. ep = of_get_next_child(parent, prev);
  66. if (!ep)
  67. return NULL;
  68. prev = ep;
  69. } while (of_node_cmp(ep->name, "endpoint") != 0);
  70. return ep;
  71. }
  72. EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint);
  73. struct device_node *dss_of_port_get_parent_device(struct device_node *port)
  74. {
  75. struct device_node *np;
  76. int i;
  77. if (!port)
  78. return NULL;
  79. np = of_get_next_parent(port);
  80. for (i = 0; i < 2 && np; ++i) {
  81. struct property *prop;
  82. prop = of_find_property(np, "compatible", NULL);
  83. if (prop)
  84. return np;
  85. np = of_get_next_parent(np);
  86. }
  87. return NULL;
  88. }
  89. u32 dss_of_port_get_port_number(struct device_node *port)
  90. {
  91. int r;
  92. u32 reg;
  93. r = of_property_read_u32(port, "reg", &reg);
  94. if (r)
  95. reg = 0;
  96. return reg;
  97. }
  98. static struct device_node *omapdss_of_get_remote_port(const struct device_node *node)
  99. {
  100. struct device_node *np;
  101. np = of_parse_phandle(node, "remote-endpoint", 0);
  102. if (!np)
  103. return NULL;
  104. np = of_get_next_parent(np);
  105. return np;
  106. }
  107. struct device_node *
  108. omapdss_of_get_first_endpoint(const struct device_node *parent)
  109. {
  110. struct device_node *port, *ep;
  111. port = omapdss_of_get_next_port(parent, NULL);
  112. if (!port)
  113. return NULL;
  114. ep = omapdss_of_get_next_endpoint(port, NULL);
  115. of_node_put(port);
  116. return ep;
  117. }
  118. EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint);
  119. struct omap_dss_device *
  120. omapdss_of_find_source_for_first_ep(struct device_node *node)
  121. {
  122. struct device_node *ep;
  123. struct device_node *src_port;
  124. struct omap_dss_device *src;
  125. ep = omapdss_of_get_first_endpoint(node);
  126. if (!ep)
  127. return ERR_PTR(-EINVAL);
  128. src_port = omapdss_of_get_remote_port(ep);
  129. if (!src_port) {
  130. of_node_put(ep);
  131. return ERR_PTR(-EINVAL);
  132. }
  133. of_node_put(ep);
  134. src = omap_dss_find_output_by_port_node(src_port);
  135. of_node_put(src_port);
  136. return src ? src : ERR_PTR(-EPROBE_DEFER);
  137. }
  138. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);