component.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef COMPONENT_H
  3. #define COMPONENT_H
  4. #include <linux/stddef.h>
  5. struct device;
  6. /**
  7. * struct component_ops - callbacks for component drivers
  8. *
  9. * Components are registered with component_add() and unregistered with
  10. * component_del().
  11. */
  12. struct component_ops {
  13. /**
  14. * @bind:
  15. *
  16. * Called through component_bind_all() when the aggregate driver is
  17. * ready to bind the overall driver.
  18. */
  19. int (*bind)(struct device *comp, struct device *master,
  20. void *master_data);
  21. /**
  22. * @unbind:
  23. *
  24. * Called through component_unbind_all() when the aggregate driver is
  25. * ready to bind the overall driver, or when component_bind_all() fails
  26. * part-ways through and needs to unbind some already bound components.
  27. */
  28. void (*unbind)(struct device *comp, struct device *master,
  29. void *master_data);
  30. };
  31. int component_add(struct device *, const struct component_ops *);
  32. int component_add_typed(struct device *dev, const struct component_ops *ops,
  33. int subcomponent);
  34. void component_del(struct device *, const struct component_ops *);
  35. int component_bind_all(struct device *parent, void *data);
  36. void component_unbind_all(struct device *parent, void *data);
  37. struct aggregate_device;
  38. /**
  39. * struct component_master_ops - callback for the aggregate driver
  40. *
  41. * Aggregate drivers are registered with component_master_add_with_match() and
  42. * unregistered with component_master_del().
  43. */
  44. struct component_master_ops {
  45. /**
  46. * @bind:
  47. *
  48. * Called when all components or the aggregate driver, as specified in
  49. * the match list passed to component_master_add_with_match(), are
  50. * ready. Usually there are 3 steps to bind an aggregate driver:
  51. *
  52. * 1. Allocate a structure for the aggregate driver.
  53. *
  54. * 2. Bind all components to the aggregate driver by calling
  55. * component_bind_all() with the aggregate driver structure as opaque
  56. * pointer data.
  57. *
  58. * 3. Register the aggregate driver with the subsystem to publish its
  59. * interfaces.
  60. *
  61. * Note that the lifetime of the aggregate driver does not align with
  62. * any of the underlying &struct device instances. Therefore devm cannot
  63. * be used and all resources acquired or allocated in this callback must
  64. * be explicitly released in the @unbind callback.
  65. */
  66. int (*bind)(struct device *master);
  67. /**
  68. * @unbind:
  69. *
  70. * Called when either the aggregate driver, using
  71. * component_master_del(), or one of its components, using
  72. * component_del(), is unregistered.
  73. */
  74. void (*unbind)(struct device *master);
  75. };
  76. /* A set helper functions for component compare/release */
  77. int component_compare_of(struct device *dev, void *data);
  78. void component_release_of(struct device *dev, void *data);
  79. int component_compare_dev(struct device *dev, void *data);
  80. int component_compare_dev_name(struct device *dev, void *data);
  81. void component_master_del(struct device *,
  82. const struct component_master_ops *);
  83. struct component_match;
  84. int component_master_add_with_match(struct device *,
  85. const struct component_master_ops *, struct component_match *);
  86. void component_match_add_release(struct device *parent,
  87. struct component_match **matchptr,
  88. void (*release)(struct device *, void *),
  89. int (*compare)(struct device *, void *), void *compare_data);
  90. void component_match_add_typed(struct device *parent,
  91. struct component_match **matchptr,
  92. int (*compare_typed)(struct device *, int, void *), void *compare_data);
  93. /**
  94. * component_match_add - add a component match entry
  95. * @parent: device with the aggregate driver
  96. * @matchptr: pointer to the list of component matches
  97. * @compare: compare function to match against all components
  98. * @compare_data: opaque pointer passed to the @compare function
  99. *
  100. * Adds a new component match to the list stored in @matchptr, which the @parent
  101. * aggregate driver needs to function. The list of component matches pointed to
  102. * by @matchptr must be initialized to NULL before adding the first match. This
  103. * only matches against components added with component_add().
  104. *
  105. * The allocated match list in @matchptr is automatically released using devm
  106. * actions.
  107. *
  108. * See also component_match_add_release() and component_match_add_typed().
  109. */
  110. static inline void component_match_add(struct device *parent,
  111. struct component_match **matchptr,
  112. int (*compare)(struct device *, void *), void *compare_data)
  113. {
  114. component_match_add_release(parent, matchptr, NULL, compare,
  115. compare_data);
  116. }
  117. #endif