drm_crtc_helper.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. /* Move the crtc on the current fb to the given position *optional* */
  65. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  66. struct drm_framebuffer *old_fb);
  67. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  68. struct drm_framebuffer *fb, int x, int y,
  69. enum mode_set_atomic);
  70. /* reload the current crtc LUT */
  71. void (*load_lut)(struct drm_crtc *crtc);
  72. /* disable crtc when not in use - more explicit than dpms off */
  73. void (*disable)(struct drm_crtc *crtc);
  74. };
  75. /**
  76. * drm_encoder_helper_funcs - helper operations for encoders
  77. * @mode_fixup: try to fixup proposed mode for this connector
  78. * @mode_set: set this mode
  79. *
  80. * The helper operations are called by the mid-layer CRTC helper.
  81. */
  82. struct drm_encoder_helper_funcs {
  83. void (*dpms)(struct drm_encoder *encoder, int mode);
  84. void (*save)(struct drm_encoder *encoder);
  85. void (*restore)(struct drm_encoder *encoder);
  86. bool (*mode_fixup)(struct drm_encoder *encoder,
  87. const struct drm_display_mode *mode,
  88. struct drm_display_mode *adjusted_mode);
  89. void (*prepare)(struct drm_encoder *encoder);
  90. void (*commit)(struct drm_encoder *encoder);
  91. void (*mode_set)(struct drm_encoder *encoder,
  92. struct drm_display_mode *mode,
  93. struct drm_display_mode *adjusted_mode);
  94. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  95. /* detect for DAC style encoders */
  96. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  97. struct drm_connector *connector);
  98. /* disable encoder when not in use - more explicit than dpms off */
  99. void (*disable)(struct drm_encoder *encoder);
  100. };
  101. /**
  102. * drm_connector_helper_funcs - helper operations for connectors
  103. * @get_modes: get mode list for this connector
  104. * @mode_valid: is this mode valid on the given connector?
  105. *
  106. * The helper operations are called by the mid-layer CRTC helper.
  107. */
  108. struct drm_connector_helper_funcs {
  109. int (*get_modes)(struct drm_connector *connector);
  110. int (*mode_valid)(struct drm_connector *connector,
  111. struct drm_display_mode *mode);
  112. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  113. };
  114. extern int drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY);
  115. extern void drm_helper_disable_unused_functions(struct drm_device *dev);
  116. extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
  117. extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
  118. struct drm_display_mode *mode,
  119. int x, int y,
  120. struct drm_framebuffer *old_fb);
  121. extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
  122. extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
  123. extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
  124. extern int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
  125. struct drm_mode_fb_cmd2 *mode_cmd);
  126. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  127. const struct drm_crtc_helper_funcs *funcs)
  128. {
  129. crtc->helper_private = (void *)funcs;
  130. }
  131. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  132. const struct drm_encoder_helper_funcs *funcs)
  133. {
  134. encoder->helper_private = (void *)funcs;
  135. }
  136. static inline void drm_connector_helper_add(struct drm_connector *connector,
  137. const struct drm_connector_helper_funcs *funcs)
  138. {
  139. connector->helper_private = (void *)funcs;
  140. }
  141. extern int drm_helper_resume_force_mode(struct drm_device *dev);
  142. extern void drm_kms_helper_poll_init(struct drm_device *dev);
  143. extern void drm_kms_helper_poll_fini(struct drm_device *dev);
  144. extern void drm_helper_hpd_irq_event(struct drm_device *dev);
  145. extern void drm_kms_helper_poll_disable(struct drm_device *dev);
  146. extern void drm_kms_helper_poll_enable(struct drm_device *dev);
  147. #endif