Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 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 | /* |
| 31 | * Note on terminology: here, for brevity and convenience, we refer to connector |
| 32 | * control chips as 'CRTCs'. They can control any type of connector, VGA, LVDS, |
| 33 | * DVI, etc. And 'screen' refers to the whole of the visible display, which |
| 34 | * may span multiple monitors (and therefore multiple CRTC and connector |
| 35 | * structures). |
| 36 | */ |
| 37 | |
| 38 | enum drm_mode_status { |
| 39 | MODE_OK = 0, /* Mode OK */ |
| 40 | MODE_HSYNC, /* hsync out of range */ |
| 41 | MODE_VSYNC, /* vsync out of range */ |
| 42 | MODE_H_ILLEGAL, /* mode has illegal horizontal timings */ |
| 43 | MODE_V_ILLEGAL, /* mode has illegal horizontal timings */ |
| 44 | MODE_BAD_WIDTH, /* requires an unsupported linepitch */ |
| 45 | MODE_NOMODE, /* no mode with a matching name */ |
| 46 | MODE_NO_INTERLACE, /* interlaced mode not supported */ |
| 47 | MODE_NO_DBLESCAN, /* doublescan mode not supported */ |
| 48 | MODE_NO_VSCAN, /* multiscan mode not supported */ |
| 49 | MODE_MEM, /* insufficient video memory */ |
| 50 | MODE_VIRTUAL_X, /* mode width too large for specified virtual size */ |
| 51 | MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */ |
| 52 | MODE_MEM_VIRT, /* insufficient video memory given virtual size */ |
| 53 | MODE_NOCLOCK, /* no fixed clock available */ |
| 54 | MODE_CLOCK_HIGH, /* clock required is too high */ |
| 55 | MODE_CLOCK_LOW, /* clock required is too low */ |
| 56 | MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */ |
| 57 | MODE_BAD_HVALUE, /* horizontal timing was out of range */ |
| 58 | MODE_BAD_VVALUE, /* vertical timing was out of range */ |
| 59 | MODE_BAD_VSCAN, /* VScan value out of range */ |
| 60 | MODE_HSYNC_NARROW, /* horizontal sync too narrow */ |
| 61 | MODE_HSYNC_WIDE, /* horizontal sync too wide */ |
| 62 | MODE_HBLANK_NARROW, /* horizontal blanking too narrow */ |
| 63 | MODE_HBLANK_WIDE, /* horizontal blanking too wide */ |
| 64 | MODE_VSYNC_NARROW, /* vertical sync too narrow */ |
| 65 | MODE_VSYNC_WIDE, /* vertical sync too wide */ |
| 66 | MODE_VBLANK_NARROW, /* vertical blanking too narrow */ |
| 67 | MODE_VBLANK_WIDE, /* vertical blanking too wide */ |
| 68 | MODE_PANEL, /* exceeds panel dimensions */ |
| 69 | MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */ |
| 70 | MODE_ONE_WIDTH, /* only one width is supported */ |
| 71 | MODE_ONE_HEIGHT, /* only one height is supported */ |
| 72 | MODE_ONE_SIZE, /* only one resolution is supported */ |
| 73 | MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */ |
| 74 | MODE_NO_STEREO, /* stereo modes not supported */ |
| 75 | MODE_UNVERIFIED = -3, /* mode needs to reverified */ |
| 76 | MODE_BAD = -2, /* unspecified reason */ |
| 77 | MODE_ERROR = -1 /* error condition */ |
| 78 | }; |
| 79 | |
| 80 | #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \ |
| 81 | DRM_MODE_TYPE_CRTC_C) |
| 82 | |
| 83 | #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \ |
| 84 | .name = nm, .status = 0, .type = (t), .clock = (c), \ |
| 85 | .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \ |
| 86 | .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \ |
| 87 | .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \ |
| 88 | .vscan = (vs), .flags = (f), \ |
| 89 | .base.type = DRM_MODE_OBJECT_MODE |
| 90 | |
| 91 | #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */ |
| 92 | #define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */ |
| 93 | |
| 94 | #define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF |
| 95 | |
| 96 | struct drm_display_mode { |
| 97 | /* Header */ |
| 98 | struct list_head head; |
| 99 | struct drm_mode_object base; |
| 100 | |
| 101 | char name[DRM_DISPLAY_MODE_LEN]; |
| 102 | |
| 103 | enum drm_mode_status status; |
| 104 | unsigned int type; |
| 105 | |
| 106 | /* Proposed mode values */ |
| 107 | int clock; /* in kHz */ |
| 108 | int hdisplay; |
| 109 | int hsync_start; |
| 110 | int hsync_end; |
| 111 | int htotal; |
| 112 | int hskew; |
| 113 | int vdisplay; |
| 114 | int vsync_start; |
| 115 | int vsync_end; |
| 116 | int vtotal; |
| 117 | int vscan; |
| 118 | unsigned int flags; |
| 119 | |
| 120 | /* Addressable image size (may be 0 for projectors, etc.) */ |
| 121 | int width_mm; |
| 122 | int height_mm; |
| 123 | |
| 124 | /* Actual mode we give to hw */ |
| 125 | int crtc_clock; /* in KHz */ |
| 126 | int crtc_hdisplay; |
| 127 | int crtc_hblank_start; |
| 128 | int crtc_hblank_end; |
| 129 | int crtc_hsync_start; |
| 130 | int crtc_hsync_end; |
| 131 | int crtc_htotal; |
| 132 | int crtc_hskew; |
| 133 | int crtc_vdisplay; |
| 134 | int crtc_vblank_start; |
| 135 | int crtc_vblank_end; |
| 136 | int crtc_vsync_start; |
| 137 | int crtc_vsync_end; |
| 138 | int crtc_vtotal; |
| 139 | |
| 140 | /* Driver private mode info */ |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 141 | int *private; |
| 142 | int private_flags; |
| 143 | |
| 144 | int vrefresh; /* in Hz */ |
| 145 | int hsync; /* in kHz */ |
| 146 | enum hdmi_picture_aspect picture_aspect_ratio; |
| 147 | }; |
| 148 | |
| 149 | /* mode specified on the command line */ |
| 150 | struct drm_cmdline_mode { |
| 151 | bool specified; |
| 152 | bool refresh_specified; |
| 153 | bool bpp_specified; |
| 154 | int xres, yres; |
| 155 | int bpp; |
| 156 | int refresh; |
| 157 | bool rb; |
| 158 | bool interlace; |
| 159 | bool cvt; |
| 160 | bool margins; |
| 161 | enum drm_connector_force force; |
| 162 | }; |
| 163 | |
Daniel Vetter | f5aabb9 | 2014-01-23 20:05:00 +0100 | [diff] [blame] | 164 | /** |
| 165 | * drm_mode_is_stereo - check for stereo mode flags |
| 166 | * @mode: drm_display_mode to check |
| 167 | * |
| 168 | * Returns: |
| 169 | * True if the mode is one of the stereo modes (like side-by-side), false if |
| 170 | * not. |
| 171 | */ |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 172 | static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode) |
| 173 | { |
| 174 | return mode->flags & DRM_MODE_FLAG_3D_MASK; |
| 175 | } |
| 176 | |
| 177 | struct drm_connector; |
| 178 | struct drm_cmdline_mode; |
| 179 | |
| 180 | struct drm_display_mode *drm_mode_create(struct drm_device *dev); |
| 181 | void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode); |
| 182 | void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); |
| 183 | void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); |
| 184 | |
| 185 | struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, |
| 186 | int hdisplay, int vdisplay, int vrefresh, |
| 187 | bool reduced, bool interlaced, |
| 188 | bool margins); |
| 189 | struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, |
| 190 | int hdisplay, int vdisplay, int vrefresh, |
| 191 | bool interlaced, int margins); |
| 192 | struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev, |
| 193 | int hdisplay, int vdisplay, |
| 194 | int vrefresh, bool interlaced, |
| 195 | int margins, |
| 196 | int GTF_M, int GTF_2C, |
| 197 | int GTF_K, int GTF_2J); |
Daniel Vetter | ba0c242 | 2014-01-23 16:28:50 +0100 | [diff] [blame] | 198 | void drm_display_mode_from_videomode(const struct videomode *vm, |
| 199 | struct drm_display_mode *dmode); |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 200 | int of_get_drm_display_mode(struct device_node *np, |
| 201 | struct drm_display_mode *dmode, |
| 202 | int index); |
| 203 | |
| 204 | void drm_mode_set_name(struct drm_display_mode *mode); |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 205 | int drm_mode_hsync(const struct drm_display_mode *mode); |
| 206 | int drm_mode_vrefresh(const struct drm_display_mode *mode); |
| 207 | |
| 208 | void drm_mode_set_crtcinfo(struct drm_display_mode *p, |
| 209 | int adjust_flags); |
| 210 | void drm_mode_copy(struct drm_display_mode *dst, |
| 211 | const struct drm_display_mode *src); |
| 212 | struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev, |
| 213 | const struct drm_display_mode *mode); |
| 214 | bool drm_mode_equal(const struct drm_display_mode *mode1, |
| 215 | const struct drm_display_mode *mode2); |
| 216 | bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1, |
| 217 | const struct drm_display_mode *mode2); |
| 218 | |
| 219 | /* for use by the crtc helper probe functions */ |
| 220 | void drm_mode_validate_size(struct drm_device *dev, |
| 221 | struct list_head *mode_list, |
Daniel Vetter | 3e70292 | 2014-01-23 16:39:31 +0100 | [diff] [blame] | 222 | int maxX, int maxY); |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 223 | void drm_mode_prune_invalid(struct drm_device *dev, |
| 224 | struct list_head *mode_list, bool verbose); |
| 225 | void drm_mode_sort(struct list_head *mode_list); |
Dave Airlie | b87577b | 2014-05-01 09:26:53 +1000 | [diff] [blame] | 226 | void drm_mode_connector_list_update(struct drm_connector *connector, bool merge_type_bits); |
Daniel Vetter | 5531000 | 2014-01-23 15:52:20 +0100 | [diff] [blame] | 227 | |
| 228 | /* parsing cmdline modes */ |
| 229 | bool |
| 230 | drm_mode_parse_command_line_for_connector(const char *mode_option, |
| 231 | struct drm_connector *connector, |
| 232 | struct drm_cmdline_mode *mode); |
| 233 | struct drm_display_mode * |
| 234 | drm_mode_create_from_cmdline_mode(struct drm_device *dev, |
| 235 | struct drm_cmdline_mode *cmd); |
| 236 | |
| 237 | #endif /* __DRM_MODES_H__ */ |