drm_crtc_helper.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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/drm_crtc.h>
  38. enum mode_set_atomic {
  39. LEAVE_ATOMIC_MODE_SET,
  40. ENTER_ATOMIC_MODE_SET,
  41. };
  42. /**
  43. * struct drm_crtc_helper_funcs - helper operations for CRTCs
  44. * @dpms: set power state
  45. * @prepare: prepare the CRTC, called before @mode_set
  46. * @commit: commit changes to CRTC, called after @mode_set
  47. * @mode_fixup: try to fixup proposed mode for this CRTC
  48. * @mode_set: set this mode
  49. * @mode_set_nofb: set mode only (no scanout buffer attached)
  50. * @mode_set_base: update the scanout buffer
  51. * @mode_set_base_atomic: non-blocking mode set (used for kgdb support)
  52. * @load_lut: load color palette
  53. * @disable: disable CRTC when no longer in use
  54. * @enable: enable CRTC
  55. * @atomic_check: check for validity of an atomic state
  56. * @atomic_begin: begin atomic update
  57. * @atomic_flush: flush atomic update
  58. *
  59. * The helper operations are called by the mid-layer CRTC helper.
  60. *
  61. * Note that with atomic helpers @dpms, @prepare and @commit hooks are
  62. * deprecated. Used @enable and @disable instead exclusively.
  63. *
  64. * With legacy crtc helpers there's a big semantic difference between @disable
  65. * and the other hooks: @disable also needs to release any resources acquired in
  66. * @mode_set (like shared PLLs).
  67. */
  68. struct drm_crtc_helper_funcs {
  69. /*
  70. * Control power levels on the CRTC. If the mode passed in is
  71. * unsupported, the provider must use the next lowest power level.
  72. */
  73. void (*dpms)(struct drm_crtc *crtc, int mode);
  74. void (*prepare)(struct drm_crtc *crtc);
  75. void (*commit)(struct drm_crtc *crtc);
  76. /* Provider can fixup or change mode timings before modeset occurs */
  77. bool (*mode_fixup)(struct drm_crtc *crtc,
  78. const struct drm_display_mode *mode,
  79. struct drm_display_mode *adjusted_mode);
  80. /* Actually set the mode */
  81. int (*mode_set)(struct drm_crtc *crtc, struct drm_display_mode *mode,
  82. struct drm_display_mode *adjusted_mode, int x, int y,
  83. struct drm_framebuffer *old_fb);
  84. /* Actually set the mode for atomic helpers, optional */
  85. void (*mode_set_nofb)(struct drm_crtc *crtc);
  86. /* Move the crtc on the current fb to the given position *optional* */
  87. int (*mode_set_base)(struct drm_crtc *crtc, int x, int y,
  88. struct drm_framebuffer *old_fb);
  89. int (*mode_set_base_atomic)(struct drm_crtc *crtc,
  90. struct drm_framebuffer *fb, int x, int y,
  91. enum mode_set_atomic);
  92. /* reload the current crtc LUT */
  93. void (*load_lut)(struct drm_crtc *crtc);
  94. void (*disable)(struct drm_crtc *crtc);
  95. void (*enable)(struct drm_crtc *crtc);
  96. /* atomic helpers */
  97. int (*atomic_check)(struct drm_crtc *crtc,
  98. struct drm_crtc_state *state);
  99. void (*atomic_begin)(struct drm_crtc *crtc,
  100. struct drm_crtc_state *old_crtc_state);
  101. void (*atomic_flush)(struct drm_crtc *crtc,
  102. struct drm_crtc_state *old_crtc_state);
  103. };
  104. /**
  105. * struct drm_encoder_helper_funcs - helper operations for encoders
  106. * @dpms: set power state
  107. * @save: save connector state
  108. * @restore: restore connector state
  109. * @mode_fixup: try to fixup proposed mode for this connector
  110. * @prepare: part of the disable sequence, called before the CRTC modeset
  111. * @commit: called after the CRTC modeset
  112. * @mode_set: set this mode, optional for atomic helpers
  113. * @get_crtc: return CRTC that the encoder is currently attached to
  114. * @detect: connection status detection
  115. * @disable: disable encoder when not in use (overrides DPMS off)
  116. * @enable: enable encoder
  117. * @atomic_check: check for validity of an atomic update
  118. *
  119. * The helper operations are called by the mid-layer CRTC helper.
  120. *
  121. * Note that with atomic helpers @dpms, @prepare and @commit hooks are
  122. * deprecated. Used @enable and @disable instead exclusively.
  123. *
  124. * With legacy crtc helpers there's a big semantic difference between @disable
  125. * and the other hooks: @disable also needs to release any resources acquired in
  126. * @mode_set (like shared PLLs).
  127. */
  128. struct drm_encoder_helper_funcs {
  129. void (*dpms)(struct drm_encoder *encoder, int mode);
  130. void (*save)(struct drm_encoder *encoder);
  131. void (*restore)(struct drm_encoder *encoder);
  132. bool (*mode_fixup)(struct drm_encoder *encoder,
  133. const struct drm_display_mode *mode,
  134. struct drm_display_mode *adjusted_mode);
  135. void (*prepare)(struct drm_encoder *encoder);
  136. void (*commit)(struct drm_encoder *encoder);
  137. void (*mode_set)(struct drm_encoder *encoder,
  138. struct drm_display_mode *mode,
  139. struct drm_display_mode *adjusted_mode);
  140. struct drm_crtc *(*get_crtc)(struct drm_encoder *encoder);
  141. /* detect for DAC style encoders */
  142. enum drm_connector_status (*detect)(struct drm_encoder *encoder,
  143. struct drm_connector *connector);
  144. void (*disable)(struct drm_encoder *encoder);
  145. void (*enable)(struct drm_encoder *encoder);
  146. /* atomic helpers */
  147. int (*atomic_check)(struct drm_encoder *encoder,
  148. struct drm_crtc_state *crtc_state,
  149. struct drm_connector_state *conn_state);
  150. };
  151. /**
  152. * struct drm_connector_helper_funcs - helper operations for connectors
  153. * @get_modes: get mode list for this connector
  154. * @mode_valid: is this mode valid on the given connector? (optional)
  155. * @best_encoder: return the preferred encoder for this connector
  156. * @atomic_best_encoder: atomic version of @best_encoder
  157. *
  158. * The helper operations are called by the mid-layer CRTC helper.
  159. */
  160. struct drm_connector_helper_funcs {
  161. int (*get_modes)(struct drm_connector *connector);
  162. enum drm_mode_status (*mode_valid)(struct drm_connector *connector,
  163. struct drm_display_mode *mode);
  164. struct drm_encoder *(*best_encoder)(struct drm_connector *connector);
  165. struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
  166. struct drm_connector_state *connector_state);
  167. };
  168. extern void drm_helper_disable_unused_functions(struct drm_device *dev);
  169. extern int drm_crtc_helper_set_config(struct drm_mode_set *set);
  170. extern bool drm_crtc_helper_set_mode(struct drm_crtc *crtc,
  171. struct drm_display_mode *mode,
  172. int x, int y,
  173. struct drm_framebuffer *old_fb);
  174. extern bool drm_helper_crtc_in_use(struct drm_crtc *crtc);
  175. extern bool drm_helper_encoder_in_use(struct drm_encoder *encoder);
  176. extern int drm_helper_connector_dpms(struct drm_connector *connector, int mode);
  177. extern void drm_helper_move_panel_connectors_to_head(struct drm_device *);
  178. extern void drm_helper_mode_fill_fb_struct(struct drm_framebuffer *fb,
  179. struct drm_mode_fb_cmd2 *mode_cmd);
  180. static inline void drm_crtc_helper_add(struct drm_crtc *crtc,
  181. const struct drm_crtc_helper_funcs *funcs)
  182. {
  183. crtc->helper_private = funcs;
  184. }
  185. static inline void drm_encoder_helper_add(struct drm_encoder *encoder,
  186. const struct drm_encoder_helper_funcs *funcs)
  187. {
  188. encoder->helper_private = funcs;
  189. }
  190. static inline void drm_connector_helper_add(struct drm_connector *connector,
  191. const struct drm_connector_helper_funcs *funcs)
  192. {
  193. connector->helper_private = funcs;
  194. }
  195. extern void drm_helper_resume_force_mode(struct drm_device *dev);
  196. int drm_helper_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *mode,
  197. struct drm_display_mode *adjusted_mode, int x, int y,
  198. struct drm_framebuffer *old_fb);
  199. int drm_helper_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
  200. struct drm_framebuffer *old_fb);
  201. /* drm_probe_helper.c */
  202. extern int drm_helper_probe_single_connector_modes(struct drm_connector
  203. *connector, uint32_t maxX,
  204. uint32_t maxY);
  205. extern int drm_helper_probe_single_connector_modes_nomerge(struct drm_connector
  206. *connector,
  207. uint32_t maxX,
  208. uint32_t maxY);
  209. extern void drm_kms_helper_poll_init(struct drm_device *dev);
  210. extern void drm_kms_helper_poll_fini(struct drm_device *dev);
  211. extern bool drm_helper_hpd_irq_event(struct drm_device *dev);
  212. extern void drm_kms_helper_hotplug_event(struct drm_device *dev);
  213. extern void drm_kms_helper_poll_disable(struct drm_device *dev);
  214. extern void drm_kms_helper_poll_enable(struct drm_device *dev);
  215. extern void drm_kms_helper_poll_enable_locked(struct drm_device *dev);
  216. extern bool drm_kms_helper_is_poll_worker(void);
  217. #endif