drm_crtc_helper.h 4.8 KB

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