drm_crtc_helper.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. struct drm_crtc_helper_funcs {
  42. /*
  43. * Control power levels on the CRTC. If the mode passed in is
  44. * unsupported, the provider must use the next lowest power level.
  45. */
  46. void (*dpms)(struct drm_crtc *crtc, int mode);
  47. void (*prepare)(struct drm_crtc *crtc);
  48. void (*commit)(struct drm_crtc *crtc);
  49. /* Provider can fixup or change mode timings before modeset occurs */
  50. bool (*mode_fixup)(struct drm_crtc *crtc,
  51. struct drm_display_mode *mode,
  52. struct drm_display_mode *adjusted_mode);
  53. /* Actually set the mode */
  54. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  55. struct drm_display_mode *adjusted_mode, int x, int y,
  56. struct drm_framebuffer *old_fb);
  57. /* Move the crtc on the current fb to the given position *optional* */
  58. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  59. struct drm_framebuffer *old_fb);
  60. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  61. struct drm_framebuffer *fb, int x, int y,
  62. enum mode_set_atomic);
  63. /* reload the current crtc LUT */
  64. void (*load_lut)(struct drm_crtc *crtc);
  65. /* disable crtc when not in use - more explicit than dpms off */
  66. void (*disable)(struct drm_crtc *crtc);
  67. };
  68. struct drm_encoder_helper_funcs {
  69. void (*dpms)(struct drm_encoder *encoder, int mode);
  70. void (*save)(struct drm_encoder *encoder);
  71. void (*restore)(struct drm_encoder *encoder);
  72. bool (*mode_fixup)(struct drm_encoder *encoder,
  73. struct drm_display_mode *mode,
  74. struct drm_display_mode *adjusted_mode);
  75. void (*prepare)(struct drm_encoder *encoder);
  76. void (*commit)(struct drm_encoder *encoder);
  77. void (*mode_set)(struct drm_encoder *encoder,
  78. struct drm_display_mode *mode,
  79. struct drm_display_mode *adjusted_mode);
  80. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  81. /* detect for DAC style encoders */
  82. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  83. struct drm_connector *connector);
  84. /* disable encoder when not in use - more explicit than dpms off */
  85. void (*disable)(struct drm_encoder *encoder);
  86. };
  87. struct drm_connector_helper_funcs {
  88. int (*get_modes)(struct drm_connector *connector);
  89. int (*mode_valid)(struct drm_connector *connector,
  90. struct drm_display_mode *mode);
  91. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  92. };
  93. extern int drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY);
  94. extern void drm_helper_disable_unused_functions(struct drm_device *dev);
  95. extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
  96. extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
  97. struct drm_display_mode *mode,
  98. int x, int y,
  99. struct drm_framebuffer *old_fb);
  100. extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
  101. extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
  102. extern void drm_helper_connector_dpms(struct drm_connector *connector, int mode);
  103. extern int drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
  104. struct drm_mode_fb_cmd *mode_cmd);
  105. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  106. const struct drm_crtc_helper_funcs *funcs)
  107. {
  108. crtc->helper_private = (void *)funcs;
  109. }
  110. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  111. const struct drm_encoder_helper_funcs *funcs)
  112. {
  113. encoder->helper_private = (void *)funcs;
  114. }
  115. static inline void drm_connector_helper_add(struct drm_connector *connector,
  116. const struct drm_connector_helper_funcs *funcs)
  117. {
  118. connector->helper_private = (void *)funcs;
  119. }
  120. extern int drm_helper_resume_force_mode(struct drm_device *dev);
  121. extern void drm_kms_helper_poll_init(struct drm_device *dev);
  122. extern void drm_kms_helper_poll_fini(struct drm_device *dev);
  123. extern void drm_helper_hpd_irq_event(struct drm_device *dev);
  124. extern void drm_kms_helper_poll_disable(struct drm_device *dev);
  125. extern void drm_kms_helper_poll_enable(struct drm_device *dev);
  126. #endif