drm_encoder.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #ifndef __DRM_ENCODER_H__
  23. #define __DRM_ENCODER_H__
  24. #include <linux/list.h>
  25. #include <linux/ctype.h>
  26. #include <drm/drm_modeset.h>
  27. /**
  28. * struct drm_encoder_funcs - encoder controls
  29. *
  30. * Encoders sit between CRTCs and connectors.
  31. */
  32. struct drm_encoder_funcs {
  33. /**
  34. * @reset:
  35. *
  36. * Reset encoder hardware and software state to off. This function isn't
  37. * called by the core directly, only through drm_mode_config_reset().
  38. * It's not a helper hook only for historical reasons.
  39. */
  40. void (*reset)(struct drm_encoder *encoder);
  41. /**
  42. * @destroy:
  43. *
  44. * Clean up encoder resources. This is only called at driver unload time
  45. * through drm_mode_config_cleanup() since an encoder cannot be
  46. * hotplugged in DRM.
  47. */
  48. void (*destroy)(struct drm_encoder *encoder);
  49. /**
  50. * @late_register:
  51. *
  52. * This optional hook can be used to register additional userspace
  53. * interfaces attached to the encoder like debugfs interfaces.
  54. * It is called late in the driver load sequence from drm_dev_register().
  55. * Everything added from this callback should be unregistered in
  56. * the early_unregister callback.
  57. *
  58. * Returns:
  59. *
  60. * 0 on success, or a negative error code on failure.
  61. */
  62. int (*late_register)(struct drm_encoder *encoder);
  63. /**
  64. * @early_unregister:
  65. *
  66. * This optional hook should be used to unregister the additional
  67. * userspace interfaces attached to the encoder from
  68. * late_unregister(). It is called from drm_dev_unregister(),
  69. * early in the driver unload sequence to disable userspace access
  70. * before data structures are torndown.
  71. */
  72. void (*early_unregister)(struct drm_encoder *encoder);
  73. };
  74. /**
  75. * struct drm_encoder - central DRM encoder structure
  76. * @dev: parent DRM device
  77. * @head: list management
  78. * @base: base KMS object
  79. * @name: human readable name, can be overwritten by the driver
  80. * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
  81. * @possible_crtcs: bitmask of potential CRTC bindings
  82. * @possible_clones: bitmask of potential sibling encoders for cloning
  83. * @crtc: currently bound CRTC
  84. * @bridge: bridge associated to the encoder
  85. * @funcs: control functions
  86. * @helper_private: mid-layer private data
  87. *
  88. * CRTCs drive pixels to encoders, which convert them into signals
  89. * appropriate for a given connector or set of connectors.
  90. */
  91. struct drm_encoder {
  92. struct drm_device *dev;
  93. struct list_head head;
  94. struct drm_mode_object base;
  95. char *name;
  96. int encoder_type;
  97. /**
  98. * @index: Position inside the mode_config.list, can be used as an array
  99. * index. It is invariant over the lifetime of the encoder.
  100. */
  101. unsigned index;
  102. uint32_t possible_crtcs;
  103. uint32_t possible_clones;
  104. struct drm_crtc *crtc;
  105. struct drm_bridge *bridge;
  106. const struct drm_encoder_funcs *funcs;
  107. const struct drm_encoder_helper_funcs *helper_private;
  108. };
  109. #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
  110. __printf(5, 6)
  111. int drm_encoder_init(struct drm_device *dev,
  112. struct drm_encoder *encoder,
  113. const struct drm_encoder_funcs *funcs,
  114. int encoder_type, const char *name, ...);
  115. /**
  116. * drm_encoder_index - find the index of a registered encoder
  117. * @encoder: encoder to find index for
  118. *
  119. * Given a registered encoder, return the index of that encoder within a DRM
  120. * device's list of encoders.
  121. */
  122. static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
  123. {
  124. return encoder->index;
  125. }
  126. /* FIXME: We have an include file mess still, drm_crtc.h needs untangling. */
  127. static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc);
  128. /**
  129. * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
  130. * @encoder: encoder to test
  131. * @crtc: crtc to test
  132. *
  133. * Return false if @encoder can't be driven by @crtc, true otherwise.
  134. */
  135. static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
  136. struct drm_crtc *crtc)
  137. {
  138. return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
  139. }
  140. static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
  141. uint32_t id)
  142. {
  143. struct drm_mode_object *mo;
  144. mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
  145. return mo ? obj_to_encoder(mo) : NULL;
  146. }
  147. void drm_encoder_cleanup(struct drm_encoder *encoder);
  148. #endif