fwnode.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * fwnode.h - Firmware device node object handle type definition.
  4. *
  5. * Copyright (C) 2015, Intel Corporation
  6. * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  7. */
  8. #ifndef _LINUX_FWNODE_H_
  9. #define _LINUX_FWNODE_H_
  10. #include <linux/types.h>
  11. #include <linux/list.h>
  12. #include <linux/bits.h>
  13. #include <linux/err.h>
  14. #include <linux/android_kabi.h>
  15. struct fwnode_operations;
  16. struct device;
  17. /*
  18. * fwnode link flags
  19. *
  20. * LINKS_ADDED: The fwnode has already be parsed to add fwnode links.
  21. * NOT_DEVICE: The fwnode will never be populated as a struct device.
  22. * INITIALIZED: The hardware corresponding to fwnode has been initialized.
  23. */
  24. #define FWNODE_FLAG_LINKS_ADDED BIT(0)
  25. #define FWNODE_FLAG_NOT_DEVICE BIT(1)
  26. #define FWNODE_FLAG_INITIALIZED BIT(2)
  27. struct fwnode_handle {
  28. struct fwnode_handle *secondary;
  29. const struct fwnode_operations *ops;
  30. struct device *dev;
  31. struct list_head suppliers;
  32. struct list_head consumers;
  33. u8 flags;
  34. ANDROID_KABI_RESERVE(1);
  35. };
  36. struct fwnode_link {
  37. struct fwnode_handle *supplier;
  38. struct list_head s_hook;
  39. struct fwnode_handle *consumer;
  40. struct list_head c_hook;
  41. ANDROID_KABI_RESERVE(1);
  42. ANDROID_KABI_RESERVE(2);
  43. ANDROID_KABI_RESERVE(3);
  44. };
  45. /**
  46. * struct fwnode_endpoint - Fwnode graph endpoint
  47. * @port: Port number
  48. * @id: Endpoint id
  49. * @local_fwnode: reference to the related fwnode
  50. */
  51. struct fwnode_endpoint {
  52. unsigned int port;
  53. unsigned int id;
  54. const struct fwnode_handle *local_fwnode;
  55. };
  56. #define NR_FWNODE_REFERENCE_ARGS 8
  57. /**
  58. * struct fwnode_reference_args - Fwnode reference with additional arguments
  59. * @fwnode:- A reference to the base fwnode
  60. * @nargs: Number of elements in @args array
  61. * @args: Integer arguments on the fwnode
  62. */
  63. struct fwnode_reference_args {
  64. struct fwnode_handle *fwnode;
  65. unsigned int nargs;
  66. u64 args[NR_FWNODE_REFERENCE_ARGS];
  67. };
  68. /**
  69. * struct fwnode_operations - Operations for fwnode interface
  70. * @get: Get a reference to an fwnode.
  71. * @put: Put a reference to an fwnode.
  72. * @device_is_available: Return true if the device is available.
  73. * @device_get_match_data: Return the device driver match data.
  74. * @property_present: Return true if a property is present.
  75. * @property_read_int_array: Read an array of integer properties. Return zero on
  76. * success, a negative error code otherwise.
  77. * @property_read_string_array: Read an array of string properties. Return zero
  78. * on success, a negative error code otherwise.
  79. * @get_name: Return the name of an fwnode.
  80. * @get_name_prefix: Get a prefix for a node (for printing purposes).
  81. * @get_parent: Return the parent of an fwnode.
  82. * @get_next_child_node: Return the next child node in an iteration.
  83. * @get_named_child_node: Return a child node with a given name.
  84. * @get_reference_args: Return a reference pointed to by a property, with args
  85. * @graph_get_next_endpoint: Return an endpoint node in an iteration.
  86. * @graph_get_remote_endpoint: Return the remote endpoint node of a local
  87. * endpoint node.
  88. * @graph_get_port_parent: Return the parent node of a port node.
  89. * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
  90. * @add_links: Create fwnode links to all the suppliers of the fwnode. Return
  91. * zero on success, a negative error code otherwise.
  92. */
  93. struct fwnode_operations {
  94. struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
  95. void (*put)(struct fwnode_handle *fwnode);
  96. bool (*device_is_available)(const struct fwnode_handle *fwnode);
  97. const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
  98. const struct device *dev);
  99. bool (*property_present)(const struct fwnode_handle *fwnode,
  100. const char *propname);
  101. int (*property_read_int_array)(const struct fwnode_handle *fwnode,
  102. const char *propname,
  103. unsigned int elem_size, void *val,
  104. size_t nval);
  105. int
  106. (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
  107. const char *propname, const char **val,
  108. size_t nval);
  109. const char *(*get_name)(const struct fwnode_handle *fwnode);
  110. const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
  111. struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
  112. struct fwnode_handle *
  113. (*get_next_child_node)(const struct fwnode_handle *fwnode,
  114. struct fwnode_handle *child);
  115. struct fwnode_handle *
  116. (*get_named_child_node)(const struct fwnode_handle *fwnode,
  117. const char *name);
  118. int (*get_reference_args)(const struct fwnode_handle *fwnode,
  119. const char *prop, const char *nargs_prop,
  120. unsigned int nargs, unsigned int index,
  121. struct fwnode_reference_args *args);
  122. struct fwnode_handle *
  123. (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
  124. struct fwnode_handle *prev);
  125. struct fwnode_handle *
  126. (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
  127. struct fwnode_handle *
  128. (*graph_get_port_parent)(struct fwnode_handle *fwnode);
  129. int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
  130. struct fwnode_endpoint *endpoint);
  131. int (*add_links)(struct fwnode_handle *fwnode);
  132. };
  133. #define fwnode_has_op(fwnode, op) \
  134. ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
  135. #define fwnode_call_int_op(fwnode, op, ...) \
  136. (fwnode ? (fwnode_has_op(fwnode, op) ? \
  137. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
  138. -EINVAL)
  139. #define fwnode_call_bool_op(fwnode, op, ...) \
  140. (fwnode_has_op(fwnode, op) ? \
  141. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false)
  142. #define fwnode_call_ptr_op(fwnode, op, ...) \
  143. (fwnode_has_op(fwnode, op) ? \
  144. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
  145. #define fwnode_call_void_op(fwnode, op, ...) \
  146. do { \
  147. if (fwnode_has_op(fwnode, op)) \
  148. (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
  149. } while (false)
  150. #define get_dev_from_fwnode(fwnode) get_device((fwnode)->dev)
  151. static inline void fwnode_init(struct fwnode_handle *fwnode,
  152. const struct fwnode_operations *ops)
  153. {
  154. fwnode->ops = ops;
  155. INIT_LIST_HEAD(&fwnode->consumers);
  156. INIT_LIST_HEAD(&fwnode->suppliers);
  157. }
  158. static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
  159. bool initialized)
  160. {
  161. if (IS_ERR_OR_NULL(fwnode))
  162. return;
  163. if (initialized)
  164. fwnode->flags |= FWNODE_FLAG_INITIALIZED;
  165. else
  166. fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
  167. }
  168. extern u32 fw_devlink_get_flags(void);
  169. extern bool fw_devlink_is_strict(void);
  170. int fwnode_link_add(struct fwnode_handle *con, struct fwnode_handle *sup);
  171. void fwnode_links_purge(struct fwnode_handle *fwnode);
  172. #endif