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 <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. of_node_put(ports);
  54. }
  55. return port;
  56. }
  57. EXPORT_SYMBOL_GPL(omapdss_of_get_next_port);
  58. struct device_node *
  59. omapdss_of_get_next_endpoint(const struct device_node *parent,
  60. struct device_node *prev)
  61. {
  62. struct device_node *ep = NULL;
  63. if (!parent)
  64. return NULL;
  65. do {
  66. ep = of_get_next_child(parent, prev);
  67. if (!ep)
  68. return NULL;
  69. prev = ep;
  70. } while (of_node_cmp(ep->name, "endpoint") != 0);
  71. return ep;
  72. }
  73. EXPORT_SYMBOL_GPL(omapdss_of_get_next_endpoint);
  74. struct device_node *dss_of_port_get_parent_device(struct device_node *port)
  75. {
  76. struct device_node *np;
  77. int i;
  78. if (!port)
  79. return NULL;
  80. np = of_get_parent(port);
  81. for (i = 0; i < 2 && 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. 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. static struct device_node *omapdss_of_get_remote_port(const struct device_node *node)
  100. {
  101. struct device_node *np;
  102. np = of_parse_phandle(node, "remote-endpoint", 0);
  103. if (!np)
  104. return NULL;
  105. np = of_get_next_parent(np);
  106. return np;
  107. }
  108. struct device_node *
  109. omapdss_of_get_first_endpoint(const struct device_node *parent)
  110. {
  111. struct device_node *port, *ep;
  112. port = omapdss_of_get_next_port(parent, NULL);
  113. if (!port)
  114. return NULL;
  115. ep = omapdss_of_get_next_endpoint(port, NULL);
  116. of_node_put(port);
  117. return ep;
  118. }
  119. EXPORT_SYMBOL_GPL(omapdss_of_get_first_endpoint);
  120. struct omap_dss_device *
  121. omapdss_of_find_source_for_first_ep(struct device_node *node)
  122. {
  123. struct device_node *ep;
  124. struct device_node *src_port;
  125. struct omap_dss_device *src;
  126. ep = omapdss_of_get_first_endpoint(node);
  127. if (!ep)
  128. return ERR_PTR(-EINVAL);
  129. src_port = omapdss_of_get_remote_port(ep);
  130. if (!src_port) {
  131. of_node_put(ep);
  132. return ERR_PTR(-EINVAL);
  133. }
  134. of_node_put(ep);
  135. src = omap_dss_find_output_by_port_node(src_port);
  136. of_node_put(src_port);
  137. return src ? src : ERR_PTR(-EPROBE_DEFER);
  138. }
  139. EXPORT_SYMBOL_GPL(omapdss_of_find_source_for_first_ep);