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