dss-of.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 "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. of_node_put(ports);
  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_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. EXPORT_SYMBOL_GPL(dss_of_port_get_parent_device);
  90. u32 dss_of_port_get_port_number(struct device_node *port)
  91. {
  92. int r;
  93. u32 reg;
  94. r = of_property_read_u32(port, "reg", &reg);
  95. if (r)
  96. reg = 0;
  97. return reg;
  98. }
  99. EXPORT_SYMBOL_GPL(dss_of_port_get_port_number);
  100. static struct device_node *omapdss_of_get_remote_port(const struct device_node *node)
  101. {
  102. struct device_node *np;
  103. np = of_parse_phandle(node, "remote-endpoint", 0);
  104. if (!np)
  105. return NULL;
  106. np = of_get_next_parent(np);
  107. return np;
  108. }
  109. struct device_node *
  110. omapdss_of_get_first_endpoint(const struct device_node *parent)
  111. {
  112. struct device_node *port, *ep;
  113. port = omapdss_of_get_next_port(parent, NULL);
  114. if (!port)
  115. return NULL;
  116. ep = omapdss_of_get_next_endpoint(port, NULL);
  117. of_node_put(port);
  118. return ep;
  119. }
  120. EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint);
  121. struct omap_dss_device *
  122. omapdss_of_find_source_for_first_ep(struct device_node *node)
  123. {
  124. struct device_node *ep;
  125. struct device_node *src_port;
  126. struct omap_dss_device *src;
  127. ep = omapdss_of_get_first_endpoint(node);
  128. if (!ep)
  129. return ERR_PTR(-EINVAL);
  130. src_port = omapdss_of_get_remote_port(ep);
  131. if (!src_port) {
  132. of_node_put(ep);
  133. return ERR_PTR(-EINVAL);
  134. }
  135. of_node_put(ep);
  136. src = omap_dss_find_output_by_port_node(src_port);
  137. of_node_put(src_port);
  138. return src ? src : ERR_PTR(-EPROBE_DEFER);
  139. }
  140. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);