drm_modes.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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. /**
  37. * enum drm_mode_status - hardware support status of a mode
  38. * @MODE_OK: Mode OK
  39. * @MODE_HSYNC: hsync out of range
  40. * @MODE_VSYNC: vsync out of range
  41. * @MODE_H_ILLEGAL: mode has illegal horizontal timings
  42. * @MODE_V_ILLEGAL: mode has illegal horizontal timings
  43. * @MODE_BAD_WIDTH: requires an unsupported linepitch
  44. * @MODE_NOMODE: no mode with a matching name
  45. * @MODE_NO_INTERLACE: interlaced mode not supported
  46. * @MODE_NO_DBLESCAN: doublescan mode not supported
  47. * @MODE_NO_VSCAN: multiscan mode not supported
  48. * @MODE_MEM: insufficient video memory
  49. * @MODE_VIRTUAL_X: mode width too large for specified virtual size
  50. * @MODE_VIRTUAL_Y: mode height too large for specified virtual size
  51. * @MODE_MEM_VIRT: insufficient video memory given virtual size
  52. * @MODE_NOCLOCK: no fixed clock available
  53. * @MODE_CLOCK_HIGH: clock required is too high
  54. * @MODE_CLOCK_LOW: clock required is too low
  55. * @MODE_CLOCK_RANGE: clock/mode isn't in a ClockRange
  56. * @MODE_BAD_HVALUE: horizontal timing was out of range
  57. * @MODE_BAD_VVALUE: vertical timing was out of range
  58. * @MODE_BAD_VSCAN: VScan value out of range
  59. * @MODE_HSYNC_NARROW: horizontal sync too narrow
  60. * @MODE_HSYNC_WIDE: horizontal sync too wide
  61. * @MODE_HBLANK_NARROW: horizontal blanking too narrow
  62. * @MODE_HBLANK_WIDE: horizontal blanking too wide
  63. * @MODE_VSYNC_NARROW: vertical sync too narrow
  64. * @MODE_VSYNC_WIDE: vertical sync too wide
  65. * @MODE_VBLANK_NARROW: vertical blanking too narrow
  66. * @MODE_VBLANK_WIDE: vertical blanking too wide
  67. * @MODE_PANEL: exceeds panel dimensions
  68. * @MODE_INTERLACE_WIDTH: width too large for interlaced mode
  69. * @MODE_ONE_WIDTH: only one width is supported
  70. * @MODE_ONE_HEIGHT: only one height is supported
  71. * @MODE_ONE_SIZE: only one resolution is supported
  72. * @MODE_NO_REDUCED: monitor doesn't accept reduced blanking
  73. * @MODE_NO_STEREO: stereo modes not supported
  74. * @MODE_STALE: mode has become stale
  75. * @MODE_BAD: unspecified reason
  76. * @MODE_ERROR: error condition
  77. *
  78. * This enum is used to filter out modes not supported by the driver/hardware
  79. * combination.
  80. */
  81. enum drm_mode_status {
  82. MODE_OK = 0,
  83. MODE_HSYNC,
  84. MODE_VSYNC,
  85. MODE_H_ILLEGAL,
  86. MODE_V_ILLEGAL,
  87. MODE_BAD_WIDTH,
  88. MODE_NOMODE,
  89. MODE_NO_INTERLACE,
  90. MODE_NO_DBLESCAN,
  91. MODE_NO_VSCAN,
  92. MODE_MEM,
  93. MODE_VIRTUAL_X,
  94. MODE_VIRTUAL_Y,
  95. MODE_MEM_VIRT,
  96. MODE_NOCLOCK,
  97. MODE_CLOCK_HIGH,
  98. MODE_CLOCK_LOW,
  99. MODE_CLOCK_RANGE,
  100. MODE_BAD_HVALUE,
  101. MODE_BAD_VVALUE,
  102. MODE_BAD_VSCAN,
  103. MODE_HSYNC_NARROW,
  104. MODE_HSYNC_WIDE,
  105. MODE_HBLANK_NARROW,
  106. MODE_HBLANK_WIDE,
  107. MODE_VSYNC_NARROW,
  108. MODE_VSYNC_WIDE,
  109. MODE_VBLANK_NARROW,
  110. MODE_VBLANK_WIDE,
  111. MODE_PANEL,
  112. MODE_INTERLACE_WIDTH,
  113. MODE_ONE_WIDTH,
  114. MODE_ONE_HEIGHT,
  115. MODE_ONE_SIZE,
  116. MODE_NO_REDUCED,
  117. MODE_NO_STEREO,
  118. MODE_STALE = -3,
  119. MODE_BAD = -2,
  120. MODE_ERROR = -1
  121. };
  122. #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
  123. DRM_MODE_TYPE_CRTC_C)
  124. #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
  125. .name = nm, .status = 0, .type = (t), .clock = (c), \
  126. .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
  127. .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
  128. .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
  129. .vscan = (vs), .flags = (f), \
  130. .base.type = DRM_MODE_OBJECT_MODE
  131. #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
  132. #define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */
  133. #define CRTC_NO_DBLSCAN (1 << 2) /* don't adjust doublescan */
  134. #define CRTC_NO_VSCAN (1 << 3) /* don't adjust doublescan */
  135. #define CRTC_STEREO_DOUBLE_ONLY (CRTC_STEREO_DOUBLE | CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
  136. #define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
  137. /**
  138. * struct drm_display_mode - DRM kernel-internal display mode structure
  139. * @hdisplay: horizontal display size
  140. * @hsync_start: horizontal sync start
  141. * @hsync_end: horizontal sync end
  142. * @htotal: horizontal total size
  143. * @hskew: horizontal skew?!
  144. * @vdisplay: vertical display size
  145. * @vsync_start: vertical sync start
  146. * @vsync_end: vertical sync end
  147. * @vtotal: vertical total size
  148. * @vscan: vertical scan?!
  149. * @crtc_hdisplay: hardware mode horizontal display size
  150. * @crtc_hblank_start: hardware mode horizontal blank start
  151. * @crtc_hblank_end: hardware mode horizontal blank end
  152. * @crtc_hsync_start: hardware mode horizontal sync start
  153. * @crtc_hsync_end: hardware mode horizontal sync end
  154. * @crtc_htotal: hardware mode horizontal total size
  155. * @crtc_hskew: hardware mode horizontal skew?!
  156. * @crtc_vdisplay: hardware mode vertical display size
  157. * @crtc_vblank_start: hardware mode vertical blank start
  158. * @crtc_vblank_end: hardware mode vertical blank end
  159. * @crtc_vsync_start: hardware mode vertical sync start
  160. * @crtc_vsync_end: hardware mode vertical sync end
  161. * @crtc_vtotal: hardware mode vertical total size
  162. *
  163. * The horizontal and vertical timings are defined per the following diagram.
  164. *
  165. * ::
  166. *
  167. *
  168. * Active Front Sync Back
  169. * Region Porch Porch
  170. * <-----------------------><----------------><-------------><-------------->
  171. * //////////////////////|
  172. * ////////////////////// |
  173. * ////////////////////// |.................. ................
  174. * _______________
  175. * <----- [hv]display ----->
  176. * <------------- [hv]sync_start ------------>
  177. * <--------------------- [hv]sync_end --------------------->
  178. * <-------------------------------- [hv]total ----------------------------->*
  179. *
  180. * This structure contains two copies of timings. First are the plain timings,
  181. * which specify the logical mode, as it would be for a progressive 1:1 scanout
  182. * at the refresh rate userspace can observe through vblank timestamps. Then
  183. * there's the hardware timings, which are corrected for interlacing,
  184. * double-clocking and similar things. They are provided as a convenience, and
  185. * can be appropriately computed using drm_mode_set_crtcinfo().
  186. */
  187. struct drm_display_mode {
  188. /**
  189. * @head:
  190. *
  191. * struct list_head for mode lists.
  192. */
  193. struct list_head head;
  194. /**
  195. * @base:
  196. *
  197. * A display mode is a normal modeset object, possibly including public
  198. * userspace id.
  199. *
  200. * FIXME:
  201. *
  202. * This can probably be removed since the entire concept of userspace
  203. * managing modes explicitly has never landed in upstream kernel mode
  204. * setting support.
  205. */
  206. struct drm_mode_object base;
  207. /**
  208. * @name:
  209. *
  210. * Human-readable name of the mode, filled out with drm_mode_set_name().
  211. */
  212. char name[DRM_DISPLAY_MODE_LEN];
  213. /**
  214. * @status:
  215. *
  216. * Status of the mode, used to filter out modes not supported by the
  217. * hardware. See enum &drm_mode_status.
  218. */
  219. enum drm_mode_status status;
  220. /**
  221. * @type:
  222. *
  223. * A bitmask of flags, mostly about the source of a mode. Possible flags
  224. * are:
  225. *
  226. * - DRM_MODE_TYPE_BUILTIN: Meant for hard-coded modes, effectively
  227. * unused.
  228. * - DRM_MODE_TYPE_PREFERRED: Preferred mode, usually the native
  229. * resolution of an LCD panel. There should only be one preferred
  230. * mode per connector at any given time.
  231. * - DRM_MODE_TYPE_DRIVER: Mode created by the driver, which is all of
  232. * them really. Drivers must set this bit for all modes they create
  233. * and expose to userspace.
  234. *
  235. * Plus a big list of flags which shouldn't be used at all, but are
  236. * still around since these flags are also used in the userspace ABI:
  237. *
  238. * - DRM_MODE_TYPE_DEFAULT: Again a leftover, use
  239. * DRM_MODE_TYPE_PREFERRED instead.
  240. * - DRM_MODE_TYPE_CLOCK_C and DRM_MODE_TYPE_CRTC_C: Define leftovers
  241. * which are stuck around for hysterical raisins only. No one has an
  242. * idea what they were meant for. Don't use.
  243. * - DRM_MODE_TYPE_USERDEF: Mode defined by userspace, again a vestige
  244. * from older kms designs where userspace had to first add a custom
  245. * mode to the kernel's mode list before it could use it. Don't use.
  246. */
  247. unsigned int type;
  248. /**
  249. * @clock:
  250. *
  251. * Pixel clock in kHz.
  252. */
  253. int clock; /* in kHz */
  254. int hdisplay;
  255. int hsync_start;
  256. int hsync_end;
  257. int htotal;
  258. int hskew;
  259. int vdisplay;
  260. int vsync_start;
  261. int vsync_end;
  262. int vtotal;
  263. int vscan;
  264. /**
  265. * @flags:
  266. *
  267. * Sync and timing flags:
  268. *
  269. * - DRM_MODE_FLAG_PHSYNC: horizontal sync is active high.
  270. * - DRM_MODE_FLAG_NHSYNC: horizontal sync is active low.
  271. * - DRM_MODE_FLAG_PVSYNC: vertical sync is active high.
  272. * - DRM_MODE_FLAG_NVSYNC: vertical sync is active low.
  273. * - DRM_MODE_FLAG_INTERLACE: mode is interlaced.
  274. * - DRM_MODE_FLAG_DBLSCAN: mode uses doublescan.
  275. * - DRM_MODE_FLAG_CSYNC: mode uses composite sync.
  276. * - DRM_MODE_FLAG_PCSYNC: composite sync is active high.
  277. * - DRM_MODE_FLAG_NCSYNC: composite sync is active low.
  278. * - DRM_MODE_FLAG_HSKEW: hskew provided (not used?).
  279. * - DRM_MODE_FLAG_BCAST: not used?
  280. * - DRM_MODE_FLAG_PIXMUX: not used?
  281. * - DRM_MODE_FLAG_DBLCLK: double-clocked mode.
  282. * - DRM_MODE_FLAG_CLKDIV2: half-clocked mode.
  283. *
  284. * Additionally there's flags to specify how 3D modes are packed:
  285. *
  286. * - DRM_MODE_FLAG_3D_NONE: normal, non-3D mode.
  287. * - DRM_MODE_FLAG_3D_FRAME_PACKING: 2 full frames for left and right.
  288. * - DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE: interleaved like fields.
  289. * - DRM_MODE_FLAG_3D_LINE_ALTERNATIVE: interleaved lines.
  290. * - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL: side-by-side full frames.
  291. * - DRM_MODE_FLAG_3D_L_DEPTH: ?
  292. * - DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH: ?
  293. * - DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: frame split into top and bottom
  294. * parts.
  295. * - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: frame split into left and
  296. * right parts.
  297. */
  298. unsigned int flags;
  299. /**
  300. * @width_mm:
  301. *
  302. * Addressable size of the output in mm, projectors should set this to
  303. * 0.
  304. */
  305. int width_mm;
  306. /**
  307. * @height_mm:
  308. *
  309. * Addressable size of the output in mm, projectors should set this to
  310. * 0.
  311. */
  312. int height_mm;
  313. /**
  314. * @crtc_clock:
  315. *
  316. * Actual pixel or dot clock in the hardware. This differs from the
  317. * logical @clock when e.g. using interlacing, double-clocking, stereo
  318. * modes or other fancy stuff that changes the timings and signals
  319. * actually sent over the wire.
  320. *
  321. * This is again in kHz.
  322. *
  323. * Note that with digital outputs like HDMI or DP there's usually a
  324. * massive confusion between the dot clock and the signal clock at the
  325. * bit encoding level. Especially when a 8b/10b encoding is used and the
  326. * difference is exactly a factor of 10.
  327. */
  328. int crtc_clock;
  329. int crtc_hdisplay;
  330. int crtc_hblank_start;
  331. int crtc_hblank_end;
  332. int crtc_hsync_start;
  333. int crtc_hsync_end;
  334. int crtc_htotal;
  335. int crtc_hskew;
  336. int crtc_vdisplay;
  337. int crtc_vblank_start;
  338. int crtc_vblank_end;
  339. int crtc_vsync_start;
  340. int crtc_vsync_end;
  341. int crtc_vtotal;
  342. /**
  343. * @private:
  344. *
  345. * Pointer for driver private data. This can only be used for mode
  346. * objects passed to drivers in modeset operations. It shouldn't be used
  347. * by atomic drivers since they can store any additional data by
  348. * subclassing state structures.
  349. */
  350. int *private;
  351. /**
  352. * @private_flags:
  353. *
  354. * Similar to @private, but just an integer.
  355. */
  356. int private_flags;
  357. /**
  358. * @vrefresh:
  359. *
  360. * Vertical refresh rate, for debug output in human readable form. Not
  361. * used in a functional way.
  362. *
  363. * This value is in Hz.
  364. */
  365. int vrefresh;
  366. /**
  367. * @hsync:
  368. *
  369. * Horizontal refresh rate, for debug output in human readable form. Not
  370. * used in a functional way.
  371. *
  372. * This value is in kHz.
  373. */
  374. int hsync;
  375. /**
  376. * @picture_aspect_ratio:
  377. *
  378. * Field for setting the HDMI picture aspect ratio of a mode.
  379. */
  380. enum hdmi_picture_aspect picture_aspect_ratio;
  381. };
  382. /* mode specified on the command line */
  383. struct drm_cmdline_mode {
  384. bool specified;
  385. bool refresh_specified;
  386. bool bpp_specified;
  387. int xres, yres;
  388. int bpp;
  389. int refresh;
  390. bool rb;
  391. bool interlace;
  392. bool cvt;
  393. bool margins;
  394. enum drm_connector_force force;
  395. };
  396. /**
  397. * drm_mode_is_stereo - check for stereo mode flags
  398. * @mode: drm_display_mode to check
  399. *
  400. * Returns:
  401. * True if the mode is one of the stereo modes (like side-by-side), false if
  402. * not.
  403. */
  404. static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode)
  405. {
  406. return mode->flags & DRM_MODE_FLAG_3D_MASK;
  407. }
  408. struct drm_connector;
  409. struct drm_cmdline_mode;
  410. struct drm_display_mode *drm_mode_create(struct drm_device *dev);
  411. void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
  412. void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
  413. const struct drm_display_mode *in);
  414. int drm_mode_convert_umode(struct drm_display_mode *out,
  415. const struct drm_mode_modeinfo *in);
  416. void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
  417. void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
  418. struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
  419. int hdisplay, int vdisplay, int vrefresh,
  420. bool reduced, bool interlaced,
  421. bool margins);
  422. struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
  423. int hdisplay, int vdisplay, int vrefresh,
  424. bool interlaced, int margins);
  425. struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
  426. int hdisplay, int vdisplay,
  427. int vrefresh, bool interlaced,
  428. int margins,
  429. int GTF_M, int GTF_2C,
  430. int GTF_K, int GTF_2J);
  431. void drm_display_mode_from_videomode(const struct videomode *vm,
  432. struct drm_display_mode *dmode);
  433. void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
  434. struct videomode *vm);
  435. int of_get_drm_display_mode(struct device_node *np,
  436. struct drm_display_mode *dmode,
  437. int index);
  438. void drm_mode_set_name(struct drm_display_mode *mode);
  439. int drm_mode_hsync(const struct drm_display_mode *mode);
  440. int drm_mode_vrefresh(const struct drm_display_mode *mode);
  441. void drm_mode_set_crtcinfo(struct drm_display_mode *p,
  442. int adjust_flags);
  443. void drm_mode_copy(struct drm_display_mode *dst,
  444. const struct drm_display_mode *src);
  445. struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
  446. const struct drm_display_mode *mode);
  447. bool drm_mode_equal(const struct drm_display_mode *mode1,
  448. const struct drm_display_mode *mode2);
  449. bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
  450. const struct drm_display_mode *mode2);
  451. bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
  452. const struct drm_display_mode *mode2);
  453. /* for use by the crtc helper probe functions */
  454. enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode);
  455. enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
  456. int maxX, int maxY);
  457. void drm_mode_prune_invalid(struct drm_device *dev,
  458. struct list_head *mode_list, bool verbose);
  459. void drm_mode_sort(struct list_head *mode_list);
  460. void drm_mode_connector_list_update(struct drm_connector *connector);
  461. /* parsing cmdline modes */
  462. bool
  463. drm_mode_parse_command_line_for_connector(const char *mode_option,
  464. struct drm_connector *connector,
  465. struct drm_cmdline_mode *mode);
  466. struct drm_display_mode *
  467. drm_mode_create_from_cmdline_mode(struct drm_device *dev,
  468. struct drm_cmdline_mode *cmd);
  469. #endif /* __DRM_MODES_H__ */