drm_modes.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
  89. struct drm_display_mode {
  90. /* Header */
  91. struct list_head head;
  92. struct drm_mode_object base;
  93. char name[DRM_DISPLAY_MODE_LEN];
  94. enum drm_mode_status status;
  95. unsigned int type;
  96. /* Proposed mode values */
  97. int clock; /* in kHz */
  98. int hdisplay;
  99. int hsync_start;
  100. int hsync_end;
  101. int htotal;
  102. int hskew;
  103. int vdisplay;
  104. int vsync_start;
  105. int vsync_end;
  106. int vtotal;
  107. int vscan;
  108. unsigned int flags;
  109. /* Addressable image size (may be 0 for projectors, etc.) */
  110. int width_mm;
  111. int height_mm;
  112. /* Actual mode we give to hw */
  113. int crtc_clock; /* in KHz */
  114. int crtc_hdisplay;
  115. int crtc_hblank_start;
  116. int crtc_hblank_end;
  117. int crtc_hsync_start;
  118. int crtc_hsync_end;
  119. int crtc_htotal;
  120. int crtc_hskew;
  121. int crtc_vdisplay;
  122. int crtc_vblank_start;
  123. int crtc_vblank_end;
  124. int crtc_vsync_start;
  125. int crtc_vsync_end;
  126. int crtc_vtotal;
  127. /* Driver private mode info */
  128. int *private;
  129. int private_flags;
  130. int vrefresh; /* in Hz */
  131. int hsync; /* in kHz */
  132. enum hdmi_picture_aspect picture_aspect_ratio;
  133. };
  134. /* mode specified on the command line */
  135. struct drm_cmdline_mode {
  136. bool specified;
  137. bool refresh_specified;
  138. bool bpp_specified;
  139. int xres, yres;
  140. int bpp;
  141. int refresh;
  142. bool rb;
  143. bool interlace;
  144. bool cvt;
  145. bool margins;
  146. enum drm_connector_force force;
  147. };
  148. /**
  149. * drm_mode_is_stereo - check for stereo mode flags
  150. * @mode: drm_display_mode to check
  151. *
  152. * Returns:
  153. * True if the mode is one of the stereo modes (like side-by-side), false if
  154. * not.
  155. */
  156. static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode)
  157. {
  158. return mode->flags & DRM_MODE_FLAG_3D_MASK;
  159. }
  160. struct drm_connector;
  161. struct drm_cmdline_mode;
  162. struct drm_display_mode *drm_mode_create(struct drm_device *dev);
  163. void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
  164. void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
  165. void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
  166. struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
  167. int hdisplay, int vdisplay, int vrefresh,
  168. bool reduced, bool interlaced,
  169. bool margins);
  170. struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
  171. int hdisplay, int vdisplay, int vrefresh,
  172. bool interlaced, int margins);
  173. struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
  174. int hdisplay, int vdisplay,
  175. int vrefresh, bool interlaced,
  176. int margins,
  177. int GTF_M, int GTF_2C,
  178. int GTF_K, int GTF_2J);
  179. void drm_display_mode_from_videomode(const struct videomode *vm,
  180. struct drm_display_mode *dmode);
  181. int of_get_drm_display_mode(struct device_node *np,
  182. struct drm_display_mode *dmode,
  183. int index);
  184. void drm_mode_set_name(struct drm_display_mode *mode);
  185. int drm_mode_hsync(const struct drm_display_mode *mode);
  186. int drm_mode_vrefresh(const struct drm_display_mode *mode);
  187. void drm_mode_set_crtcinfo(struct drm_display_mode *p,
  188. int adjust_flags);
  189. void drm_mode_copy(struct drm_display_mode *dst,
  190. const struct drm_display_mode *src);
  191. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  192. const struct drm_display_mode *mode);
  193. bool drm_mode_equal(const struct drm_display_mode *mode1,
  194. const struct drm_display_mode *mode2);
  195. bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
  196. const struct drm_display_mode *mode2);
  197. /* for use by the crtc helper probe functions */
  198. void drm_mode_validate_size(struct drm_device *dev,
  199. struct list_head *mode_list,
  200. int maxX, int maxY);
  201. void drm_mode_prune_invalid(struct drm_device *dev,
  202. struct list_head *mode_list, bool verbose);
  203. void drm_mode_sort(struct list_head *mode_list);
  204. void drm_mode_connector_list_update(struct drm_connector *connector, bool merge_type_bits);
  205. /* parsing cmdline modes */
  206. bool
  207. drm_mode_parse_command_line_for_connector(const char *mode_option,
  208. struct drm_connector *connector,
  209. struct drm_cmdline_mode *mode);
  210. struct drm_display_mode *
  211. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  212. struct drm_cmdline_mode *cmd);
  213. #endif /* __DRM_MODES_H__ */