drm_crtc_helper.h 5.2 KB

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