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