fwnode.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * fwnode.h - Firmware device node object handle type definition.
  3. *
  4. * Copyright (C) 2015, Intel Corporation
  5. * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #ifndef _LINUX_FWNODE_H_
  12. #define _LINUX_FWNODE_H_
  13. #include <linux/types.h>
  14. struct fwnode_operations;
  15. struct device;
  16. struct fwnode_handle {
  17. struct fwnode_handle *secondary;
  18. const struct fwnode_operations *ops;
  19. };
  20. /**
  21. * struct fwnode_endpoint - Fwnode graph endpoint
  22. * @port: Port number
  23. * @id: Endpoint id
  24. * @local_fwnode: reference to the related fwnode
  25. */
  26. struct fwnode_endpoint {
  27. unsigned int port;
  28. unsigned int id;
  29. const struct fwnode_handle *local_fwnode;
  30. };
  31. #define NR_FWNODE_REFERENCE_ARGS 8
  32. /**
  33. * struct fwnode_reference_args - Fwnode reference with additional arguments
  34. * @fwnode:- A reference to the base fwnode
  35. * @nargs: Number of elements in @args array
  36. * @args: Integer arguments on the fwnode
  37. */
  38. struct fwnode_reference_args {
  39. struct fwnode_handle *fwnode;
  40. unsigned int nargs;
  41. u64 args[NR_FWNODE_REFERENCE_ARGS];
  42. };
  43. /**
  44. * struct fwnode_operations - Operations for fwnode interface
  45. * @get: Get a reference to an fwnode.
  46. * @put: Put a reference to an fwnode.
  47. * @device_get_match_data: Return the device driver match data.
  48. * @property_present: Return true if a property is present.
  49. * @property_read_integer_array: Read an array of integer properties. Return
  50. * zero on success, a negative error code
  51. * otherwise.
  52. * @property_read_string_array: Read an array of string properties. Return zero
  53. * on success, a negative error code otherwise.
  54. * @get_parent: Return the parent of an fwnode.
  55. * @get_next_child_node: Return the next child node in an iteration.
  56. * @get_named_child_node: Return a child node with a given name.
  57. * @get_reference_args: Return a reference pointed to by a property, with args
  58. * @graph_get_next_endpoint: Return an endpoint node in an iteration.
  59. * @graph_get_remote_endpoint: Return the remote endpoint node of a local
  60. * endpoint node.
  61. * @graph_get_port_parent: Return the parent node of a port node.
  62. * @graph_parse_endpoint: Parse endpoint for port and endpoint id.
  63. */
  64. struct fwnode_operations {
  65. struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
  66. void (*put)(struct fwnode_handle *fwnode);
  67. bool (*device_is_available)(const struct fwnode_handle *fwnode);
  68. const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
  69. const struct device *dev);
  70. bool (*property_present)(const struct fwnode_handle *fwnode,
  71. const char *propname);
  72. int (*property_read_int_array)(const struct fwnode_handle *fwnode,
  73. const char *propname,
  74. unsigned int elem_size, void *val,
  75. size_t nval);
  76. int
  77. (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
  78. const char *propname, const char **val,
  79. size_t nval);
  80. struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
  81. struct fwnode_handle *
  82. (*get_next_child_node)(const struct fwnode_handle *fwnode,
  83. struct fwnode_handle *child);
  84. struct fwnode_handle *
  85. (*get_named_child_node)(const struct fwnode_handle *fwnode,
  86. const char *name);
  87. int (*get_reference_args)(const struct fwnode_handle *fwnode,
  88. const char *prop, const char *nargs_prop,
  89. unsigned int nargs, unsigned int index,
  90. struct fwnode_reference_args *args);
  91. struct fwnode_handle *
  92. (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
  93. struct fwnode_handle *prev);
  94. struct fwnode_handle *
  95. (*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
  96. struct fwnode_handle *
  97. (*graph_get_port_parent)(struct fwnode_handle *fwnode);
  98. int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
  99. struct fwnode_endpoint *endpoint);
  100. };
  101. #define fwnode_has_op(fwnode, op) \
  102. ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
  103. #define fwnode_call_int_op(fwnode, op, ...) \
  104. (fwnode ? (fwnode_has_op(fwnode, op) ? \
  105. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
  106. -EINVAL)
  107. #define fwnode_call_bool_op(fwnode, op, ...) \
  108. (fwnode ? (fwnode_has_op(fwnode, op) ? \
  109. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : false) : \
  110. false)
  111. #define fwnode_call_ptr_op(fwnode, op, ...) \
  112. (fwnode_has_op(fwnode, op) ? \
  113. (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
  114. #define fwnode_call_void_op(fwnode, op, ...) \
  115. do { \
  116. if (fwnode_has_op(fwnode, op)) \
  117. (fwnode)->ops->op(fwnode, ## __VA_ARGS__); \
  118. } while (false)
  119. #endif