drm_crtc_helper.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. * Copyright © 2006 Keith Packard
  3. * Copyright © 2007-2008 Dave Airlie
  4. * Copyright © 2007-2008 Intel Corporation
  5. * Jesse Barnes <jesse.barnes@intel.com>
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. /*
  26. * The DRM mode setting helper functions are common code for drivers to use if
  27. * they wish. Drivers are not forced to use this code in their
  28. * implementations but it would be useful if they code they do use at least
  29. * provides a consistent interface and operation to userspace
  30. */
  31. #ifndef __DRM_CRTC_HELPER_H__
  32. #define __DRM_CRTC_HELPER_H__
  33. #include <linux/spinlock.h>
  34. #include <linux/types.h>
  35. #include <linux/idr.h>
  36. #include <linux/fb.h>
  37. enum mode_set_atomic {
  38. LEAVE_ATOMIC_MODE_SET,
  39. ENTER_ATOMIC_MODE_SET,
  40. };
  41. /**
  42. * drm_crtc_helper_funcs - helper operations for CRTCs
  43. * @mode_fixup: try to fixup proposed mode for this connector
  44. * @mode_set: set this mode
  45. *
  46. * The helper operations are called by the mid-layer CRTC helper.
  47. */
  48. struct drm_crtc_helper_funcs {
  49. /*
  50. * Control power levels on the CRTC. If the mode passed in is
  51. * unsupported, the provider must use the next lowest power level.
  52. */
  53. void (*dpms)(struct drm_crtc *crtc, int mode);
  54. void (*prepare)(struct drm_crtc *crtc);
  55. void (*commit)(struct drm_crtc *crtc);
  56. /* Provider can fixup or change mode timings before modeset occurs */
  57. bool (*mode_fixup)(struct drm_crtc *crtc,
  58. const struct drm_display_mode *mode,
  59. struct drm_display_mode *adjusted_mode);
  60. /* Actually set the mode */
  61. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  62. struct drm_display_mode *adjusted_mode, int x, int y,
  63. struct drm_framebuffer *old_fb);
  64. void (*mode_set_nofb)(struct drm_crtc *crtc);
  65. /* Move the crtc on the current fb to the given position *optional* */
  66. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  67. struct drm_framebuffer *old_fb);
  68. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  69. struct drm_framebuffer *fb, int x, int y,
  70. enum mode_set_atomic);
  71. /* reload the current crtc LUT */
  72. void (*load_lut)(struct drm_crtc *crtc);
  73. /* disable crtc when not in use - more explicit than dpms off */
  74. void (*disable)(struct drm_crtc *crtc);
  75. /* atomic helpers */
  76. int (*atomic_check)(struct drm_crtc *crtc,
  77. struct drm_crtc_state *state);
  78. void (*atomic_begin)(struct drm_crtc *crtc);
  79. void (*atomic_flush)(struct drm_crtc *crtc);
  80. };
  81. /**
  82. * drm_encoder_helper_funcs - helper operations for encoders
  83. * @mode_fixup: try to fixup proposed mode for this connector
  84. * @mode_set: set this mode
  85. *
  86. * The helper operations are called by the mid-layer CRTC helper.
  87. */
  88. struct drm_encoder_helper_funcs {
  89. void (*dpms)(struct drm_encoder *encoder, int mode);
  90. void (*save)(struct drm_encoder *encoder);
  91. void (*restore)(struct drm_encoder *encoder);
  92. bool (*mode_fixup)(struct drm_encoder *encoder,
  93. const struct drm_display_mode *mode,
  94. struct drm_display_mode *adjusted_mode);
  95. void (*prepare)(struct drm_encoder *encoder);
  96. void (*commit)(struct drm_encoder *encoder);
  97. void (*mode_set)(struct drm_encoder *encoder,
  98. struct drm_display_mode *mode,
  99. struct drm_display_mode *adjusted_mode);
  100. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  101. /* detect for DAC style encoders */
  102. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  103. struct drm_connector *connector);
  104. /* disable encoder when not in use - more explicit than dpms off */
  105. void (*disable)(struct drm_encoder *encoder);
  106. };
  107. /**
  108. * drm_connector_helper_funcs - helper operations for connectors
  109. * @get_modes: get mode list for this connector
  110. * @mode_valid (optional): is this mode valid on the given connector?
  111. *
  112. * The helper operations are called by the mid-layer CRTC helper.
  113. */
  114. struct drm_connector_helper_funcs {
  115. int (*get_modes)(struct drm_connector *connector);
  116. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  117. struct drm_display_mode *mode);
  118. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  119. };
  120. extern void drm_helper_disable_unused_functions(struct drm_device *dev);
  121. extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
  122. extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
  123. struct drm_display_mode *mode,
  124. int x, int y,
  125. struct drm_framebuffer *old_fb);
  126. extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
  127. extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
  128. extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
  129. extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
  130. extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
  131. struct drm_mode_fb_cmd2 *mode_cmd);
  132. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  133. const struct drm_crtc_helper_funcs *funcs)
  134. {
  135. crtc->helper_private = (void *)funcs;
  136. }
  137. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  138. const struct drm_encoder_helper_funcs *funcs)
  139. {
  140. encoder->helper_private = (void *)funcs;
  141. }
  142. static inline void drm_connector_helper_add(struct drm_connector *connector,
  143. const struct drm_connector_helper_funcs *funcs)
  144. {
  145. connector->helper_private = (void *)funcs;
  146. }
  147. extern void drm_helper_resume_force_mode(struct drm_device *dev);
  148. int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
  149. struct drm_display_mode *adjusted_mode, int x, int y,
  150. struct drm_framebuffer *old_fb);
  151. int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  152. struct drm_framebuffer *old_fb);
  153. /* drm_probe_helper.c */
  154. extern int drm_helper_probe_single_connector_modes(struct drm_connector
  155. *connector, uint32_t maxX,
  156. uint32_t maxY);
  157. extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
  158. *connector,
  159. uint32_t maxX,
  160. uint32_t maxY);
  161. extern void drm_kms_helper_poll_init(struct drm_device *dev);
  162. extern void drm_kms_helper_poll_fini(struct drm_device *dev);
  163. extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
  164. extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
  165. extern void drm_kms_helper_poll_disable(struct drm_device *dev);
  166. extern void drm_kms_helper_poll_enable(struct drm_device *dev);
  167. #endif