of_graph.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * OF graph binding parsing helpers
  3. *
  4. * Copyright (C) 2012 - 2013 Samsung Electronics Co., Ltd.
  5. * Author: Sylwester Nawrocki <s.nawrocki@samsung.com>
  6. *
  7. * Copyright (C) 2012 Renesas Electronics Corp.
  8. * Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. */
  14. #ifndef __LINUX_OF_GRAPH_H
  15. #define __LINUX_OF_GRAPH_H
  16. #include <linux/types.h>
  17. #include <linux/errno.h>
  18. /**
  19. * struct of_endpoint - the OF graph endpoint data structure
  20. * @port: identifier (value of reg property) of a port this endpoint belongs to
  21. * @id: identifier (value of reg property) of this endpoint
  22. * @local_node: pointer to device_node of this endpoint
  23. */
  24. struct of_endpoint {
  25. unsigned int port;
  26. unsigned int id;
  27. const struct device_node *local_node;
  28. };
  29. /**
  30. * for_each_endpoint_of_node - iterate over every endpoint in a device node
  31. * @parent: parent device node containing ports and endpoints
  32. * @child: loop variable pointing to the current endpoint node
  33. *
  34. * When breaking out of the loop, of_node_put(child) has to be called manually.
  35. */
  36. #define for_each_endpoint_of_node(parent, child) \
  37. for (child = of_graph_get_next_endpoint(parent, NULL); child != NULL; \
  38. child = of_graph_get_next_endpoint(parent, child))
  39. #ifdef CONFIG_OF
  40. int of_graph_parse_endpoint(const struct device_node *node,
  41. struct of_endpoint *endpoint);
  42. int of_graph_get_endpoint_count(const struct device_node *np);
  43. struct device_node *of_graph_get_port_by_id(struct device_node *node, u32 id);
  44. struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
  45. struct device_node *previous);
  46. struct device_node *of_graph_get_endpoint_by_regs(
  47. const struct device_node *parent, int port_reg, int reg);
  48. struct device_node *of_graph_get_remote_endpoint(
  49. const struct device_node *node);
  50. struct device_node *of_graph_get_port_parent(struct device_node *node);
  51. struct device_node *of_graph_get_remote_port_parent(
  52. const struct device_node *node);
  53. struct device_node *of_graph_get_remote_port(const struct device_node *node);
  54. struct device_node *of_graph_get_remote_node(const struct device_node *node,
  55. u32 port, u32 endpoint);
  56. #else
  57. static inline int of_graph_parse_endpoint(const struct device_node *node,
  58. struct of_endpoint *endpoint)
  59. {
  60. return -ENOSYS;
  61. }
  62. static inline int of_graph_get_endpoint_count(const struct device_node *np)
  63. {
  64. return 0;
  65. }
  66. static inline struct device_node *of_graph_get_port_by_id(
  67. struct device_node *node, u32 id)
  68. {
  69. return NULL;
  70. }
  71. static inline struct device_node *of_graph_get_next_endpoint(
  72. const struct device_node *parent,
  73. struct device_node *previous)
  74. {
  75. return NULL;
  76. }
  77. static inline struct device_node *of_graph_get_endpoint_by_regs(
  78. const struct device_node *parent, int port_reg, int reg)
  79. {
  80. return NULL;
  81. }
  82. static inline struct device_node *of_graph_get_remote_endpoint(
  83. const struct device_node *node)
  84. {
  85. return NULL;
  86. }
  87. static inline struct device_node *of_graph_get_port_parent(
  88. struct device_node *node)
  89. {
  90. return NULL;
  91. }
  92. static inline struct device_node *of_graph_get_remote_port_parent(
  93. const struct device_node *node)
  94. {
  95. return NULL;
  96. }
  97. static inline struct device_node *of_graph_get_remote_port(
  98. const struct device_node *node)
  99. {
  100. return NULL;
  101. }
  102. static inline struct device_node *of_graph_get_remote_node(
  103. const struct device_node *node,
  104. u32 port, u32 endpoint)
  105. {
  106. return NULL;
  107. }
  108. #endif /* CONFIG_OF */
  109. #endif /* __LINUX_OF_GRAPH_H */