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