dtb_fwnode.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef __DTB_FWNODE_H__
  2. #define __DTB_FWNODE_H__
  3. #include "libfdt_env.h"
  4. #include <rtthread.h>
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. struct fwnode_operations;
  8. struct rt_device;
  9. #define FWNODE_FLAG_LINKS_ADDED 0x01
  10. #define FWNODE_FLAG_NOT_DEVICE 0x02
  11. #define FWNODE_FLAG_INITIALIZED 0x04
  12. #define NR_FWNODE_REFERENCE_ARGS 8
  13. struct fwnode_handle
  14. {
  15. struct fwnode_handle *secondary;
  16. const struct fwnode_operations *ops;
  17. struct rt_device *dev;
  18. struct rt_list_node suppliers;
  19. struct rt_list_node consumers;
  20. uint8_t flags;
  21. };
  22. struct fwnode_link
  23. {
  24. struct fwnode_handle *supplier;
  25. struct rt_list_node s_hook;
  26. struct fwnode_handle *consumer;
  27. struct rt_list_node c_hook;
  28. };
  29. struct fwnode_endpoint
  30. {
  31. unsigned int port;
  32. unsigned int id;
  33. const struct fwnode_handle *local_fwnode;
  34. };
  35. struct fwnode_reference_args
  36. {
  37. struct fwnode_handle *fwnode;
  38. unsigned int nargs;
  39. uint64_t args[NR_FWNODE_REFERENCE_ARGS];
  40. };
  41. struct fwnode_operations
  42. {
  43. struct fwnode_handle *(*get)(struct fwnode_handle *fwnode);
  44. void (*put)(struct fwnode_handle *fwnode);
  45. bool (*device_is_available)(const struct fwnode_handle *fwnode);
  46. const void *(*device_get_match_data)(const struct fwnode_handle *fwnode,
  47. const struct rt_device *dev);
  48. bool (*property_present)(const struct fwnode_handle *fwnode,
  49. const char *propname);
  50. int (*property_read_int_array)(const struct fwnode_handle *fwnode,
  51. const char *propname,
  52. unsigned int elem_size, void *val,
  53. size_t nval);
  54. int (*property_read_string_array)(const struct fwnode_handle *fwnode_handle,
  55. const char *propname, const char **val,
  56. size_t nval);
  57. const char *(*get_name)(const struct fwnode_handle *fwnode);
  58. const char *(*get_name_prefix)(const struct fwnode_handle *fwnode);
  59. struct fwnode_handle *(*get_parent)(const struct fwnode_handle *fwnode);
  60. struct fwnode_handle *(*get_next_child_node)(const struct fwnode_handle *fwnode,
  61. struct fwnode_handle *child);
  62. struct fwnode_handle *(*get_named_child_node)(const struct fwnode_handle *fwnode,
  63. const char *name);
  64. int (*get_reference_args)(const struct fwnode_handle *fwnode,
  65. const char *prop, const char *nargs_prop,
  66. unsigned int nargs, unsigned int index,
  67. struct fwnode_reference_args *args);
  68. struct fwnode_handle *(*graph_get_next_endpoint)(const struct fwnode_handle *fwnode,
  69. struct fwnode_handle *prev);
  70. struct fwnode_handle *(*graph_get_remote_endpoint)(const struct fwnode_handle *fwnode);
  71. struct fwnode_handle *(*graph_get_port_parent)(struct fwnode_handle *fwnode);
  72. int (*graph_parse_endpoint)(const struct fwnode_handle *fwnode,
  73. struct fwnode_endpoint *endpoint);
  74. int (*add_links)(struct fwnode_handle *fwnode);
  75. };
  76. #define fwnode_has_op(fwnode, op) \
  77. ((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
  78. #define fwnode_call_int_op(fwnode, op, ...) \
  79. (fwnode ? (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : -ENXIO) : -EINVAL)
  80. #define fwnode_call_bool_op(fwnode, op, ...) \
  81. (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : false)
  82. #define fwnode_call_ptr_op(fwnode, op, ...) \
  83. (fwnode_has_op(fwnode, op) ? (fwnode)->ops->op(fwnode, ##__VA_ARGS__) : NULL)
  84. #define fwnode_call_void_op(fwnode, op, ...) \
  85. do \
  86. { \
  87. if (fwnode_has_op(fwnode, op)) \
  88. (fwnode)->ops->op(fwnode, ##__VA_ARGS__); \
  89. } while (false)
  90. #define get_dev_from_fwnode(fwnode) ((fwnode)->dev)
  91. static inline void fwnode_init(struct fwnode_handle *fwnode,
  92. const struct fwnode_operations *ops)
  93. {
  94. fwnode->ops = ops;
  95. rt_list_init(&fwnode->consumers);
  96. rt_list_init(&fwnode->suppliers);
  97. }
  98. static inline void fwnode_dev_initialized(struct fwnode_handle *fwnode,
  99. bool initialized)
  100. {
  101. if (!fwnode)
  102. return;
  103. if (initialized)
  104. fwnode->flags |= FWNODE_FLAG_INITIALIZED;
  105. else
  106. fwnode->flags &= ~FWNODE_FLAG_INITIALIZED;
  107. }
  108. #endif //__DTB_FWNODE_H__