xref: /dragonfly/sys/dev/drm/include/drm/drm_modes.h (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
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_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \
135                                             DRM_MODE_TYPE_CRTC_C)
136 
137 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \
138           .name = nm, .status = 0, .type = (t), .clock = (c), \
139           .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \
140           .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \
141           .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
142           .vscan = (vs), .flags = (f), \
143           .base.type = DRM_MODE_OBJECT_MODE
144 
145 #define CRTC_INTERLACE_HALVE_V          (1 << 0) /* halve V values for interlacing */
146 #define CRTC_STEREO_DOUBLE    (1 << 1) /* adjust timings for stereo modes */
147 #define CRTC_NO_DBLSCAN                 (1 << 2) /* don't adjust doublescan */
148 #define CRTC_NO_VSCAN                   (1 << 3) /* don't adjust doublescan */
149 #define CRTC_STEREO_DOUBLE_ONLY         (CRTC_STEREO_DOUBLE | CRTC_NO_DBLSCAN | CRTC_NO_VSCAN)
150 
151 #define DRM_MODE_FLAG_3D_MAX  DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
152 
153 /**
154  * struct drm_display_mode - DRM kernel-internal display mode structure
155  * @hdisplay: horizontal display size
156  * @hsync_start: horizontal sync start
157  * @hsync_end: horizontal sync end
158  * @htotal: horizontal total size
159  * @hskew: horizontal skew?!
160  * @vdisplay: vertical display size
161  * @vsync_start: vertical sync start
162  * @vsync_end: vertical sync end
163  * @vtotal: vertical total size
164  * @vscan: vertical scan?!
165  * @crtc_hdisplay: hardware mode horizontal display size
166  * @crtc_hblank_start: hardware mode horizontal blank start
167  * @crtc_hblank_end: hardware mode horizontal blank end
168  * @crtc_hsync_start: hardware mode horizontal sync start
169  * @crtc_hsync_end: hardware mode horizontal sync end
170  * @crtc_htotal: hardware mode horizontal total size
171  * @crtc_hskew: hardware mode horizontal skew?!
172  * @crtc_vdisplay: hardware mode vertical display size
173  * @crtc_vblank_start: hardware mode vertical blank start
174  * @crtc_vblank_end: hardware mode vertical blank end
175  * @crtc_vsync_start: hardware mode vertical sync start
176  * @crtc_vsync_end: hardware mode vertical sync end
177  * @crtc_vtotal: hardware mode vertical total size
178  *
179  * The horizontal and vertical timings are defined per the following diagram.
180  *
181  * ::
182  *
183  *
184  *               Active                 Front           Sync           Back
185  *              Region                 Porch                          Porch
186  *     <-----------------------><----------------><-------------><-------------->
187  *       //////////////////////|
188  *      ////////////////////// |
189  *     //////////////////////  |..................               ................
190  *                                                _______________
191  *     <----- [hv]display ----->
192  *     <------------- [hv]sync_start ------------>
193  *     <--------------------- [hv]sync_end --------------------->
194  *     <-------------------------------- [hv]total ----------------------------->*
195  *
196  * This structure contains two copies of timings. First are the plain timings,
197  * which specify the logical mode, as it would be for a progressive 1:1 scanout
198  * at the refresh rate userspace can observe through vblank timestamps. Then
199  * there's the hardware timings, which are corrected for interlacing,
200  * double-clocking and similar things. They are provided as a convenience, and
201  * can be appropriately computed using drm_mode_set_crtcinfo().
202  *
203  * For printing you can use %DRM_MODE_FMT and DRM_MODE_ARG().
204  */
205 struct drm_display_mode {
206           /**
207            * @head:
208            *
209            * struct list_head for mode lists.
210            */
211           struct list_head head;
212 
213           /**
214            * @base:
215            *
216            * A display mode is a normal modeset object, possibly including public
217            * userspace id.
218            *
219            * FIXME:
220            *
221            * This can probably be removed since the entire concept of userspace
222            * managing modes explicitly has never landed in upstream kernel mode
223            * setting support.
224            */
225           struct drm_mode_object base;
226 
227           /**
228            * @name:
229            *
230            * Human-readable name of the mode, filled out with drm_mode_set_name().
231            */
232           char name[DRM_DISPLAY_MODE_LEN];
233 
234           /**
235            * @status:
236            *
237            * Status of the mode, used to filter out modes not supported by the
238            * hardware. See enum &drm_mode_status.
239            */
240           enum drm_mode_status status;
241 
242           /**
243            * @type:
244            *
245            * A bitmask of flags, mostly about the source of a mode. Possible flags
246            * are:
247            *
248            *  - DRM_MODE_TYPE_BUILTIN: Meant for hard-coded modes, effectively
249            *    unused.
250            *  - DRM_MODE_TYPE_PREFERRED: Preferred mode, usually the native
251            *    resolution of an LCD panel. There should only be one preferred
252            *    mode per connector at any given time.
253            *  - DRM_MODE_TYPE_DRIVER: Mode created by the driver, which is all of
254            *    them really. Drivers must set this bit for all modes they create
255            *    and expose to userspace.
256            *
257            * Plus a big list of flags which shouldn't be used at all, but are
258            * still around since these flags are also used in the userspace ABI:
259            *
260            *  - DRM_MODE_TYPE_DEFAULT: Again a leftover, use
261            *    DRM_MODE_TYPE_PREFERRED instead.
262            *  - DRM_MODE_TYPE_CLOCK_C and DRM_MODE_TYPE_CRTC_C: Define leftovers
263            *    which are stuck around for hysterical raisins only. No one has an
264            *    idea what they were meant for. Don't use.
265            *  - DRM_MODE_TYPE_USERDEF: Mode defined by userspace, again a vestige
266            *    from older kms designs where userspace had to first add a custom
267            *    mode to the kernel's mode list before it could use it. Don't use.
268            */
269           unsigned int type;
270 
271           /**
272            * @clock:
273            *
274            * Pixel clock in kHz.
275            */
276           int clock;                    /* in kHz */
277           int hdisplay;
278           int hsync_start;
279           int hsync_end;
280           int htotal;
281           int hskew;
282           int vdisplay;
283           int vsync_start;
284           int vsync_end;
285           int vtotal;
286           int vscan;
287           /**
288            * @flags:
289            *
290            * Sync and timing flags:
291            *
292            *  - DRM_MODE_FLAG_PHSYNC: horizontal sync is active high.
293            *  - DRM_MODE_FLAG_NHSYNC: horizontal sync is active low.
294            *  - DRM_MODE_FLAG_PVSYNC: vertical sync is active high.
295            *  - DRM_MODE_FLAG_NVSYNC: vertical sync is active low.
296            *  - DRM_MODE_FLAG_INTERLACE: mode is interlaced.
297            *  - DRM_MODE_FLAG_DBLSCAN: mode uses doublescan.
298            *  - DRM_MODE_FLAG_CSYNC: mode uses composite sync.
299            *  - DRM_MODE_FLAG_PCSYNC: composite sync is active high.
300            *  - DRM_MODE_FLAG_NCSYNC: composite sync is active low.
301            *  - DRM_MODE_FLAG_HSKEW: hskew provided (not used?).
302            *  - DRM_MODE_FLAG_BCAST: not used?
303            *  - DRM_MODE_FLAG_PIXMUX: not used?
304            *  - DRM_MODE_FLAG_DBLCLK: double-clocked mode.
305            *  - DRM_MODE_FLAG_CLKDIV2: half-clocked mode.
306            *
307            * Additionally there's flags to specify how 3D modes are packed:
308            *
309            *  - DRM_MODE_FLAG_3D_NONE: normal, non-3D mode.
310            *  - DRM_MODE_FLAG_3D_FRAME_PACKING: 2 full frames for left and right.
311            *  - DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE: interleaved like fields.
312            *  - DRM_MODE_FLAG_3D_LINE_ALTERNATIVE: interleaved lines.
313            *  - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL: side-by-side full frames.
314            *  - DRM_MODE_FLAG_3D_L_DEPTH: ?
315            *  - DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH: ?
316            *  - DRM_MODE_FLAG_3D_TOP_AND_BOTTOM: frame split into top and bottom
317            *    parts.
318            *  - DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF: frame split into left and
319            *    right parts.
320            */
321           unsigned int flags;
322 
323           /**
324            * @width_mm:
325            *
326            * Addressable size of the output in mm, projectors should set this to
327            * 0.
328            */
329           int width_mm;
330 
331           /**
332            * @height_mm:
333            *
334            * Addressable size of the output in mm, projectors should set this to
335            * 0.
336            */
337           int height_mm;
338 
339           /**
340            * @crtc_clock:
341            *
342            * Actual pixel or dot clock in the hardware. This differs from the
343            * logical @clock when e.g. using interlacing, double-clocking, stereo
344            * modes or other fancy stuff that changes the timings and signals
345            * actually sent over the wire.
346            *
347            * This is again in kHz.
348            *
349            * Note that with digital outputs like HDMI or DP there's usually a
350            * massive confusion between the dot clock and the signal clock at the
351            * bit encoding level. Especially when a 8b/10b encoding is used and the
352            * difference is exactly a factor of 10.
353            */
354           int crtc_clock;
355           int crtc_hdisplay;
356           int crtc_hblank_start;
357           int crtc_hblank_end;
358           int crtc_hsync_start;
359           int crtc_hsync_end;
360           int crtc_htotal;
361           int crtc_hskew;
362           int crtc_vdisplay;
363           int crtc_vblank_start;
364           int crtc_vblank_end;
365           int crtc_vsync_start;
366           int crtc_vsync_end;
367           int crtc_vtotal;
368 
369           /**
370            * @private:
371            *
372            * Pointer for driver private data. This can only be used for mode
373            * objects passed to drivers in modeset operations. It shouldn't be used
374            * by atomic drivers since they can store any additional data by
375            * subclassing state structures.
376            */
377           int *private;
378 
379           /**
380            * @private_flags:
381            *
382            * Similar to @private, but just an integer.
383            */
384           int private_flags;
385 
386           /**
387            * @vrefresh:
388            *
389            * Vertical refresh rate, for debug output in human readable form. Not
390            * used in a functional way.
391            *
392            * This value is in Hz.
393            */
394           int vrefresh;
395 
396           /**
397            * @hsync:
398            *
399            * Horizontal refresh rate, for debug output in human readable form. Not
400            * used in a functional way.
401            *
402            * This value is in kHz.
403            */
404           int hsync;
405 
406           /**
407            * @picture_aspect_ratio:
408            *
409            * Field for setting the HDMI picture aspect ratio of a mode.
410            */
411           enum hdmi_picture_aspect picture_aspect_ratio;
412 };
413 
414 /**
415  * DRM_MODE_FMT - printf string for &struct drm_display_mode
416  */
417 #define DRM_MODE_FMT    "%d:\"%s\" %d %d %d %d %d %d %d %d %d %d 0x%x 0x%x"
418 
419 /**
420  * DRM_MODE_ARG - printf arguments for &struct drm_display_mode
421  * @m: display mode
422  */
423 #define DRM_MODE_ARG(m) \
424           (m)->base.id, (m)->name, (m)->vrefresh, (m)->clock, \
425           (m)->hdisplay, (m)->hsync_start, (m)->hsync_end, (m)->htotal, \
426           (m)->vdisplay, (m)->vsync_start, (m)->vsync_end, (m)->vtotal, \
427           (m)->type, (m)->flags
428 
429 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
430 
431 /**
432  * drm_mode_is_stereo - check for stereo mode flags
433  * @mode: drm_display_mode to check
434  *
435  * Returns:
436  * True if the mode is one of the stereo modes (like side-by-side), false if
437  * not.
438  */
drm_mode_is_stereo(const struct drm_display_mode * mode)439 static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode)
440 {
441           return mode->flags & DRM_MODE_FLAG_3D_MASK;
442 }
443 
444 struct drm_connector;
445 struct drm_cmdline_mode;
446 
447 struct drm_display_mode *drm_mode_create(struct drm_device *dev);
448 void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode);
449 void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
450                                      const struct drm_display_mode *in);
451 int drm_mode_convert_umode(struct drm_display_mode *out,
452                                  const struct drm_mode_modeinfo *in);
453 void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode);
454 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode);
455 bool drm_mode_is_420_only(const struct drm_display_info *display,
456                                 const struct drm_display_mode *mode);
457 bool drm_mode_is_420_also(const struct drm_display_info *display,
458                                 const struct drm_display_mode *mode);
459 bool drm_mode_is_420(const struct drm_display_info *display,
460                          const struct drm_display_mode *mode);
461 
462 struct drm_display_mode *drm_cvt_mode(struct drm_device *dev,
463                                               int hdisplay, int vdisplay, int vrefresh,
464                                               bool reduced, bool interlaced,
465                                               bool margins);
466 struct drm_display_mode *drm_gtf_mode(struct drm_device *dev,
467                                               int hdisplay, int vdisplay, int vrefresh,
468                                               bool interlaced, int margins);
469 struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev,
470                                                         int hdisplay, int vdisplay,
471                                                         int vrefresh, bool interlaced,
472                                                         int margins,
473                                                         int GTF_M, int GTF_2C,
474                                                         int GTF_K, int GTF_2J);
475 void drm_display_mode_from_videomode(const struct videomode *vm,
476                                              struct drm_display_mode *dmode);
477 void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
478                                            struct videomode *vm);
479 void drm_bus_flags_from_videomode(const struct videomode *vm, u32 *bus_flags);
480 int of_get_drm_display_mode(struct device_node *np,
481                                   struct drm_display_mode *dmode, u32 *bus_flags,
482                                   int index);
483 
484 void drm_mode_set_name(struct drm_display_mode *mode);
485 int drm_mode_hsync(const struct drm_display_mode *mode);
486 int drm_mode_vrefresh(const struct drm_display_mode *mode);
487 void drm_mode_get_hv_timing(const struct drm_display_mode *mode,
488                                   int *hdisplay, int *vdisplay);
489 
490 void drm_mode_set_crtcinfo(struct drm_display_mode *p,
491                                  int adjust_flags);
492 void drm_mode_copy(struct drm_display_mode *dst,
493                        const struct drm_display_mode *src);
494 struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
495                                                       const struct drm_display_mode *mode);
496 bool drm_mode_equal(const struct drm_display_mode *mode1,
497                         const struct drm_display_mode *mode2);
498 bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
499                                     const struct drm_display_mode *mode2);
500 bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
501                                                   const struct drm_display_mode *mode2);
502 
503 /* for use by the crtc helper probe functions */
504 enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode);
505 enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode,
506                                                       int maxX, int maxY);
507 enum drm_mode_status
508 drm_mode_validate_ycbcr420(const struct drm_display_mode *mode,
509                                  struct drm_connector *connector);
510 void drm_mode_prune_invalid(struct drm_device *dev,
511                                   struct list_head *mode_list, bool verbose);
512 void drm_mode_sort(struct list_head *mode_list);
513 void drm_mode_connector_list_update(struct drm_connector *connector);
514 
515 /* parsing cmdline modes */
516 bool
517 drm_mode_parse_command_line_for_connector(const char *mode_option,
518                                                     struct drm_connector *connector,
519                                                     struct drm_cmdline_mode *mode);
520 struct drm_display_mode *
521 drm_mode_create_from_cmdline_mode(struct drm_device *dev,
522                                           struct drm_cmdline_mode *cmd);
523 
524 #endif /* __DRM_MODES_H__ */
525