of_graph.h 3.6 KB

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