drm_modes.h 9.2 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. * Copyright © 2014 Intel Corporation
  7. * Daniel Vetter <daniel.vetter@ffwll.ch>
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. */
  27. #ifndef __DRM_MODES_H__
  28. #define __DRM_MODES_H__
  29. /*
  30. * Note on terminology: here, for brevity and convenience, we refer to connector
  31. * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS,
  32. * DVI, etc. And 'screen' refers to the whole of the visible display, which
  33. * may span multiple monitors (and therefore multiple CRTC and connector
  34. * structures).
  35. */
  36. enum drm_mode_status {
  37. MODE_OK = 0, /* Mode OK */
  38. MODE_HSYNC, /* hsync out of range */
  39. MODE_VSYNC, /* vsync out of range */
  40. MODE_H_ILLEGAL, /* mode has illegal horizontal timings */
  41. MODE_V_ILLEGAL, /* mode has illegal horizontal timings */
  42. MODE_BAD_WIDTH, /* requires an unsupported linepitch */
  43. MODE_NOMODE, /* no mode with a matching name */
  44. MODE_NO_INTERLACE, /* interlaced mode not supported */
  45. MODE_NO_DBLESCAN, /* doublescan mode not supported */
  46. MODE_NO_VSCAN, /* multiscan mode not supported */
  47. MODE_MEM, /* insufficient video memory */
  48. MODE_VIRTUAL_X, /* mode width too large for specified virtual size */
  49. MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */
  50. MODE_MEM_VIRT, /* insufficient video memory given virtual size */
  51. MODE_NOCLOCK, /* no fixed clock available */
  52. MODE_CLOCK_HIGH, /* clock required is too high */
  53. MODE_CLOCK_LOW, /* clock required is too low */
  54. MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */
  55. MODE_BAD_HVALUE, /* horizontal timing was out of range */
  56. MODE_BAD_VVALUE, /* vertical timing was out of range */
  57. MODE_BAD_VSCAN, /* VScan value out of range */
  58. MODE_HSYNC_NARROW, /* horizontal sync too narrow */
  59. MODE_HSYNC_WIDE, /* horizontal sync too wide */
  60. MODE_HBLANK_NARROW, /* horizontal blanking too narrow */
  61. MODE_HBLANK_WIDE, /* horizontal blanking too wide */
  62. MODE_VSYNC_NARROW, /* vertical sync too narrow */
  63. MODE_VSYNC_WIDE, /* vertical sync too wide */
  64. MODE_VBLANK_NARROW, /* vertical blanking too narrow */
  65. MODE_VBLANK_WIDE, /* vertical blanking too wide */
  66. MODE_PANEL, /* exceeds panel dimensions */
  67. MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */
  68. MODE_ONE_WIDTH, /* only one width is supported */
  69. MODE_ONE_HEIGHT, /* only one height is supported */
  70. MODE_ONE_SIZE, /* only one resolution is supported */
  71. MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */
  72. MODE_NO_STEREO, /* stereo modes not supported */
  73. MODE_UNVERIFIED = -3, /* mode needs to reverified */
  74. MODE_BAD = -2, /* unspecified reason */
  75. MODE_ERROR = -1 /* error condition */
  76. };
  77. #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
  78. DRM_MODE_TYPE_CRTC_C)
  79. #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
  80. .name = nm, .status = 0, .type = (t), .clock = (c), \
  81. .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
  82. .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
  83. .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
  84. .vscan = (vs), .flags = (f), \
  85. .base.type = DRM_MODE_OBJECT_MODE
  86. #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
  87. #define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */
  88. #define CRTC_NO_DBLSCAN (1 << 2) /* don't adjust doublescan */
  89. #define CRTC_NO_VSCAN (1 << 3) /* don't adjust doublescan */
  90. #define CRTC_STEREO_DOUBLE_ONLY (CRTC_STEREO_DOUBLE | CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
  91. #define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
  92. struct drm_display_mode {
  93. /* Header */
  94. struct list_head head;
  95. struct drm_mode_object base;
  96. char name[DRM_DISPLAY_MODE_LEN];
  97. enum drm_mode_status status;
  98. unsigned int type;
  99. /* Proposed mode values */
  100. int clock; /* in kHz */
  101. int hdisplay;
  102. int hsync_start;
  103. int hsync_end;
  104. int htotal;
  105. int hskew;
  106. int vdisplay;
  107. int vsync_start;
  108. int vsync_end;
  109. int vtotal;
  110. int vscan;
  111. unsigned int flags;
  112. /* Addressable image size (may be 0 for projectors, etc.) */
  113. int width_mm;
  114. int height_mm;
  115. /* Actual mode we give to hw */
  116. int crtc_clock; /* in KHz */
  117. int crtc_hdisplay;
  118. int crtc_hblank_start;
  119. int crtc_hblank_end;
  120. int crtc_hsync_start;
  121. int crtc_hsync_end;
  122. int crtc_htotal;
  123. int crtc_hskew;
  124. int crtc_vdisplay;
  125. int crtc_vblank_start;
  126. int crtc_vblank_end;
  127. int crtc_vsync_start;
  128. int crtc_vsync_end;
  129. int crtc_vtotal;
  130. /* Driver private mode info */
  131. int *private;
  132. int private_flags;
  133. int vrefresh; /* in Hz */
  134. int hsync; /* in kHz */
  135. enum hdmi_picture_aspect picture_aspect_ratio;
  136. };
  137. /* mode specified on the command line */
  138. struct drm_cmdline_mode {
  139. bool specified;
  140. bool refresh_specified;
  141. bool bpp_specified;
  142. int xres, yres;
  143. int bpp;
  144. int refresh;
  145. bool rb;
  146. bool interlace;
  147. bool cvt;
  148. bool margins;
  149. enum drm_connector_force force;
  150. };
  151. /**
  152. * drm_mode_is_stereo - check for stereo mode flags
  153. * @mode: drm_display_mode to check
  154. *
  155. * Returns:
  156. * True if the mode is one of the stereo modes (like side-by-side), false if
  157. * not.
  158. */
  159. static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode)
  160. {
  161. return mode->flags & DRM_MODE_FLAG_3D_MASK;
  162. }
  163. struct drm_connector;
  164. struct drm_cmdline_mode;
  165. struct drm_display_mode *drm_mode_create(struct drm_device *dev);
  166. void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
  167. void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
  168. const struct drm_display_mode *in);
  169. int drm_mode_convert_umode(struct drm_display_mode *out,
  170. const struct drm_mode_modeinfo *in);
  171. void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
  172. void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
  173. struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
  174. int hdisplay, int vdisplay, int vrefresh,
  175. bool reduced, bool interlaced,
  176. bool margins);
  177. struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
  178. int hdisplay, int vdisplay, int vrefresh,
  179. bool interlaced, int margins);
  180. struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
  181. int hdisplay, int vdisplay,
  182. int vrefresh, bool interlaced,
  183. int margins,
  184. int GTF_M, int GTF_2C,
  185. int GTF_K, int GTF_2J);
  186. void drm_display_mode_from_videomode(const struct videomode *vm,
  187. struct drm_display_mode *dmode);
  188. void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
  189. struct videomode *vm);
  190. int of_get_drm_display_mode(struct device_node *np,
  191. struct drm_display_mode *dmode,
  192. int index);
  193. void drm_mode_set_name(struct drm_display_mode *mode);
  194. int drm_mode_hsync(const struct drm_display_mode *mode);
  195. int drm_mode_vrefresh(const struct drm_display_mode *mode);
  196. void drm_mode_set_crtcinfo(struct drm_display_mode *p,
  197. int adjust_flags);
  198. void drm_mode_copy(struct drm_display_mode *dst,
  199. const struct drm_display_mode *src);
  200. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  201. const struct drm_display_mode *mode);
  202. bool drm_mode_equal(const struct drm_display_mode *mode1,
  203. const struct drm_display_mode *mode2);
  204. bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
  205. const struct drm_display_mode *mode2);
  206. /* for use by the crtc helper probe functions */
  207. enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode);
  208. enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
  209. int maxX, int maxY);
  210. void drm_mode_prune_invalid(struct drm_device *dev,
  211. struct list_head *mode_list, bool verbose);
  212. void drm_mode_sort(struct list_head *mode_list);
  213. void drm_mode_connector_list_update(struct drm_connector *connector, bool merge_type_bits);
  214. /* parsing cmdline modes */
  215. bool
  216. drm_mode_parse_command_line_for_connector(const char *mode_option,
  217. struct drm_connector *connector,
  218. struct drm_cmdline_mode *mode);
  219. struct drm_display_mode *
  220. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  221. struct drm_cmdline_mode *cmd);
  222. #endif /* __DRM_MODES_H__ */