1 /* $NetBSD: drm_modes.h,v 1.4 2018/08/27 04:58:38 riastradh Exp $ */ 2 3 /* 4 * Copyright © 2006 Keith Packard 5 * Copyright © 2007-2008 Dave Airlie 6 * Copyright © 2007-2008 Intel Corporation 7 * Jesse Barnes <jesse.barnes@intel.com> 8 * Copyright © 2014 Intel Corporation 9 * Daniel Vetter <daniel.vetter@ffwll.ch> 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a 12 * copy of this software and associated documentation files (the "Software"), 13 * to deal in the Software without restriction, including without limitation 14 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 * and/or sell copies of the Software, and to permit persons to whom the 16 * Software is furnished to do so, subject to the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be included in 19 * all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 * OTHER DEALINGS IN THE SOFTWARE. 28 */ 29 #ifndef __DRM_MODES_H__ 30 #define __DRM_MODES_H__ 31 32 #include <linux/list.h> 33 34 struct device_node; 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 enum drm_mode_status { 46 MODE_OK = 0, /* Mode OK */ 47 MODE_HSYNC, /* hsync out of range */ 48 MODE_VSYNC, /* vsync out of range */ 49 MODE_H_ILLEGAL, /* mode has illegal horizontal timings */ 50 MODE_V_ILLEGAL, /* mode has illegal horizontal timings */ 51 MODE_BAD_WIDTH, /* requires an unsupported linepitch */ 52 MODE_NOMODE, /* no mode with a matching name */ 53 MODE_NO_INTERLACE, /* interlaced mode not supported */ 54 MODE_NO_DBLESCAN, /* doublescan mode not supported */ 55 MODE_NO_VSCAN, /* multiscan mode not supported */ 56 MODE_MEM, /* insufficient video memory */ 57 MODE_VIRTUAL_X, /* mode width too large for specified virtual size */ 58 MODE_VIRTUAL_Y, /* mode height too large for specified virtual size */ 59 MODE_MEM_VIRT, /* insufficient video memory given virtual size */ 60 MODE_NOCLOCK, /* no fixed clock available */ 61 MODE_CLOCK_HIGH, /* clock required is too high */ 62 MODE_CLOCK_LOW, /* clock required is too low */ 63 MODE_CLOCK_RANGE, /* clock/mode isn't in a ClockRange */ 64 MODE_BAD_HVALUE, /* horizontal timing was out of range */ 65 MODE_BAD_VVALUE, /* vertical timing was out of range */ 66 MODE_BAD_VSCAN, /* VScan value out of range */ 67 MODE_HSYNC_NARROW, /* horizontal sync too narrow */ 68 MODE_HSYNC_WIDE, /* horizontal sync too wide */ 69 MODE_HBLANK_NARROW, /* horizontal blanking too narrow */ 70 MODE_HBLANK_WIDE, /* horizontal blanking too wide */ 71 MODE_VSYNC_NARROW, /* vertical sync too narrow */ 72 MODE_VSYNC_WIDE, /* vertical sync too wide */ 73 MODE_VBLANK_NARROW, /* vertical blanking too narrow */ 74 MODE_VBLANK_WIDE, /* vertical blanking too wide */ 75 MODE_PANEL, /* exceeds panel dimensions */ 76 MODE_INTERLACE_WIDTH, /* width too large for interlaced mode */ 77 MODE_ONE_WIDTH, /* only one width is supported */ 78 MODE_ONE_HEIGHT, /* only one height is supported */ 79 MODE_ONE_SIZE, /* only one resolution is supported */ 80 MODE_NO_REDUCED, /* monitor doesn't accept reduced blanking */ 81 MODE_NO_STEREO, /* stereo modes not supported */ 82 MODE_UNVERIFIED = -3, /* mode needs to reverified */ 83 MODE_BAD = -2, /* unspecified reason */ 84 MODE_ERROR = -1 /* error condition */ 85 }; 86 87 #define DRM_MODE_TYPE_CLOCK_CRTC_C (DRM_MODE_TYPE_CLOCK_C | \ 88 DRM_MODE_TYPE_CRTC_C) 89 90 #define DRM_MODE(nm, t, c, hd, hss, hse, ht, hsk, vd, vss, vse, vt, vs, f) \ 91 .name = nm, .status = 0, .type = (t), .clock = (c), \ 92 .hdisplay = (hd), .hsync_start = (hss), .hsync_end = (hse), \ 93 .htotal = (ht), .hskew = (hsk), .vdisplay = (vd), \ 94 .vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \ 95 .vscan = (vs), .flags = (f), \ 96 .base = { .type = DRM_MODE_OBJECT_MODE } 97 98 #define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */ 99 #define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */ 100 #define CRTC_NO_DBLSCAN (1 << 2) /* don't adjust doublescan */ 101 #define CRTC_NO_VSCAN (1 << 3) /* don't adjust doublescan */ 102 #define CRTC_STEREO_DOUBLE_ONLY (CRTC_STEREO_DOUBLE | CRTC_NO_DBLSCAN | CRTC_NO_VSCAN) 103 104 #define DRM_MODE_FLAG_3D_MAX DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF 105 106 struct drm_display_mode { 107 /* Header */ 108 struct list_head head; 109 struct drm_mode_object base; 110 111 char name[DRM_DISPLAY_MODE_LEN]; 112 113 enum drm_mode_status status; 114 unsigned int type; 115 116 /* Proposed mode values */ 117 int clock; /* in kHz */ 118 int hdisplay; 119 int hsync_start; 120 int hsync_end; 121 int htotal; 122 int hskew; 123 int vdisplay; 124 int vsync_start; 125 int vsync_end; 126 int vtotal; 127 int vscan; 128 unsigned int flags; 129 130 /* Addressable image size (may be 0 for projectors, etc.) */ 131 int width_mm; 132 int height_mm; 133 134 /* Actual mode we give to hw */ 135 int crtc_clock; /* in KHz */ 136 int crtc_hdisplay; 137 int crtc_hblank_start; 138 int crtc_hblank_end; 139 int crtc_hsync_start; 140 int crtc_hsync_end; 141 int crtc_htotal; 142 int crtc_hskew; 143 int crtc_vdisplay; 144 int crtc_vblank_start; 145 int crtc_vblank_end; 146 int crtc_vsync_start; 147 int crtc_vsync_end; 148 int crtc_vtotal; 149 150 /* Driver private mode info */ 151 int *private; 152 int private_flags; 153 154 int vrefresh; /* in Hz */ 155 int hsync; /* in kHz */ 156 enum hdmi_picture_aspect picture_aspect_ratio; 157 }; 158 159 /* mode specified on the command line */ 160 struct drm_cmdline_mode { 161 bool specified; 162 bool refresh_specified; 163 bool bpp_specified; 164 int xres, yres; 165 int bpp; 166 int refresh; 167 bool rb; 168 bool interlace; 169 bool cvt; 170 bool margins; 171 enum drm_connector_force force; 172 }; 173 174 /** 175 * drm_mode_is_stereo - check for stereo mode flags 176 * @mode: drm_display_mode to check 177 * 178 * Returns: 179 * True if the mode is one of the stereo modes (like side-by-side), false if 180 * not. 181 */ 182 static inline bool drm_mode_is_stereo(const struct drm_display_mode *mode) 183 { 184 return mode->flags & DRM_MODE_FLAG_3D_MASK; 185 } 186 187 struct drm_connector; 188 struct drm_cmdline_mode; 189 190 struct drm_display_mode *drm_mode_create(struct drm_device *dev); 191 void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode); 192 void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out, 193 const struct drm_display_mode *in); 194 int drm_mode_convert_umode(struct drm_display_mode *out, 195 const struct drm_mode_modeinfo *in); 196 void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); 197 void drm_mode_debug_printmodeline(const struct drm_display_mode *mode); 198 199 struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, 200 int hdisplay, int vdisplay, int vrefresh, 201 bool reduced, bool interlaced, 202 bool margins); 203 struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, 204 int hdisplay, int vdisplay, int vrefresh, 205 bool interlaced, int margins); 206 struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev, 207 int hdisplay, int vdisplay, 208 int vrefresh, bool interlaced, 209 int margins, 210 int GTF_M, int GTF_2C, 211 int GTF_K, int GTF_2J); 212 void drm_display_mode_from_videomode(const struct videomode *vm, 213 struct drm_display_mode *dmode); 214 void drm_display_mode_to_videomode(const struct drm_display_mode *dmode, 215 struct videomode *vm); 216 int of_get_drm_display_mode(struct device_node *np, 217 struct drm_display_mode *dmode, 218 int index); 219 220 void drm_mode_set_name(struct drm_display_mode *mode); 221 int drm_mode_hsync(const struct drm_display_mode *mode); 222 int drm_mode_vrefresh(const struct drm_display_mode *mode); 223 224 void drm_mode_set_crtcinfo(struct drm_display_mode *p, 225 int adjust_flags); 226 void drm_mode_copy(struct drm_display_mode *dst, 227 const struct drm_display_mode *src); 228 struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev, 229 const struct drm_display_mode *mode); 230 bool drm_mode_equal(const struct drm_display_mode *mode1, 231 const struct drm_display_mode *mode2); 232 bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1, 233 const struct drm_display_mode *mode2); 234 235 /* for use by the crtc helper probe functions */ 236 enum drm_mode_status drm_mode_validate_basic(const struct drm_display_mode *mode); 237 enum drm_mode_status drm_mode_validate_size(const struct drm_display_mode *mode, 238 int maxX, int maxY); 239 void drm_mode_prune_invalid(struct drm_device *dev, 240 struct list_head *mode_list, bool verbose); 241 void drm_mode_sort(struct list_head *mode_list); 242 void drm_mode_connector_list_update(struct drm_connector *connector, bool merge_type_bits); 243 244 /* parsing cmdline modes */ 245 bool 246 drm_mode_parse_command_line_for_connector(const char *mode_option, 247 struct drm_connector *connector, 248 struct drm_cmdline_mode *mode); 249 struct drm_display_mode * 250 drm_mode_create_from_cmdline_mode(struct drm_device *dev, 251 struct drm_cmdline_mode *cmd); 252 253 #endif /* __DRM_MODES_H__ */ 254