Rev 4560 | Rev 5271 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1123 | serge | 1 | /* |
2 | * Copyright © 1997-2003 by The XFree86 Project, Inc. |
||
3 | * Copyright © 2007 Dave Airlie |
||
4 | * Copyright © 2007-2008 Intel Corporation |
||
5 | * Jesse Barnes |
||
1179 | serge | 6 | * Copyright 2005-2006 Luc Verhaegen |
7 | * Copyright (c) 2001, Andy Ritger aritger@nvidia.com |
||
1123 | serge | 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 | * Except as contained in this notice, the name of the copyright holder(s) |
||
28 | * and author(s) shall not be used in advertising or otherwise to promote |
||
29 | * the sale, use or other dealings in this Software without prior written |
||
30 | * authorization from the copyright holder(s) and author(s). |
||
31 | */ |
||
32 | |||
1179 | serge | 33 | #include |
1404 | serge | 34 | #include |
3031 | serge | 35 | #include |
36 | #include |
||
37 | #include |
||
5060 | serge | 38 | #include |
1123 | serge | 39 | |
5060 | serge | 40 | #include "drm_crtc_internal.h" |
41 | |||
1123 | serge | 42 | /** |
5060 | serge | 43 | * drm_mode_debug_printmodeline - print a mode to dmesg |
1123 | serge | 44 | * @mode: mode to print |
45 | * |
||
46 | * Describe @mode using DRM_DEBUG. |
||
47 | */ |
||
3192 | Serge | 48 | void drm_mode_debug_printmodeline(const struct drm_display_mode *mode) |
1123 | serge | 49 | { |
1179 | serge | 50 | DRM_DEBUG_KMS("Modeline %d:\"%s\" %d %d %d %d %d %d %d %d %d %d " |
51 | "0x%x 0x%x\n", |
||
1123 | serge | 52 | mode->base.id, mode->name, mode->vrefresh, mode->clock, |
53 | mode->hdisplay, mode->hsync_start, |
||
54 | mode->hsync_end, mode->htotal, |
||
55 | mode->vdisplay, mode->vsync_start, |
||
56 | mode->vsync_end, mode->vtotal, mode->type, mode->flags); |
||
57 | } |
||
58 | EXPORT_SYMBOL(drm_mode_debug_printmodeline); |
||
59 | |||
60 | /** |
||
5060 | serge | 61 | * drm_mode_create - create a new display mode |
1179 | serge | 62 | * @dev: DRM device |
5060 | serge | 63 | * |
64 | * Create a new, cleared drm_display_mode with kzalloc, allocate an ID for it |
||
65 | * and return it. |
||
66 | * |
||
67 | * Returns: |
||
68 | * Pointer to new mode on success, NULL on error. |
||
69 | */ |
||
70 | struct drm_display_mode *drm_mode_create(struct drm_device *dev) |
||
71 | { |
||
72 | struct drm_display_mode *nmode; |
||
73 | |||
74 | nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL); |
||
75 | if (!nmode) |
||
76 | return NULL; |
||
77 | |||
78 | if (drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE)) { |
||
79 | kfree(nmode); |
||
80 | return NULL; |
||
81 | } |
||
82 | |||
83 | return nmode; |
||
84 | } |
||
85 | EXPORT_SYMBOL(drm_mode_create); |
||
86 | |||
87 | /** |
||
88 | * drm_mode_destroy - remove a mode |
||
89 | * @dev: DRM device |
||
90 | * @mode: mode to remove |
||
91 | * |
||
92 | * Release @mode's unique ID, then free it @mode structure itself using kfree. |
||
93 | */ |
||
94 | void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode) |
||
95 | { |
||
96 | if (!mode) |
||
97 | return; |
||
98 | |||
99 | drm_mode_object_put(dev, &mode->base); |
||
100 | |||
101 | kfree(mode); |
||
102 | } |
||
103 | EXPORT_SYMBOL(drm_mode_destroy); |
||
104 | |||
105 | /** |
||
106 | * drm_mode_probed_add - add a mode to a connector's probed_mode list |
||
107 | * @connector: connector the new mode |
||
108 | * @mode: mode data |
||
109 | * |
||
110 | * Add @mode to @connector's probed_mode list for later use. This list should |
||
111 | * then in a second step get filtered and all the modes actually supported by |
||
112 | * the hardware moved to the @connector's modes list. |
||
113 | */ |
||
114 | void drm_mode_probed_add(struct drm_connector *connector, |
||
115 | struct drm_display_mode *mode) |
||
116 | { |
||
117 | WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex)); |
||
118 | |||
119 | list_add_tail(&mode->head, &connector->probed_modes); |
||
120 | } |
||
121 | EXPORT_SYMBOL(drm_mode_probed_add); |
||
122 | |||
123 | /** |
||
124 | * drm_cvt_mode -create a modeline based on the CVT algorithm |
||
125 | * @dev: drm device |
||
1179 | serge | 126 | * @hdisplay: hdisplay size |
127 | * @vdisplay: vdisplay size |
||
5060 | serge | 128 | * @vrefresh: vrefresh rate |
129 | * @reduced: whether to use reduced blanking |
||
130 | * @interlaced: whether to compute an interlaced mode |
||
131 | * @margins: whether to add margins (borders) |
||
1179 | serge | 132 | * |
133 | * This function is called to generate the modeline based on CVT algorithm |
||
134 | * according to the hdisplay, vdisplay, vrefresh. |
||
135 | * It is based from the VESA(TM) Coordinated Video Timing Generator by |
||
136 | * Graham Loveridge April 9, 2003 available at |
||
1963 | serge | 137 | * http://www.elo.utfsm.cl/~elo212/docs/CVTd6r1.xls |
1179 | serge | 138 | * |
139 | * And it is copied from xf86CVTmode in xserver/hw/xfree86/modes/xf86cvt.c. |
||
140 | * What I have done is to translate it by using integer calculation. |
||
5060 | serge | 141 | * |
142 | * Returns: |
||
143 | * The modeline based on the CVT algorithm stored in a drm_display_mode object. |
||
144 | * The display mode object is allocated with drm_mode_create(). Returns NULL |
||
145 | * when no mode could be allocated. |
||
1179 | serge | 146 | */ |
147 | struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay, |
||
148 | int vdisplay, int vrefresh, |
||
1221 | serge | 149 | bool reduced, bool interlaced, bool margins) |
1179 | serge | 150 | { |
5060 | serge | 151 | #define HV_FACTOR 1000 |
1179 | serge | 152 | /* 1) top/bottom margin size (% of height) - default: 1.8, */ |
153 | #define CVT_MARGIN_PERCENTAGE 18 |
||
154 | /* 2) character cell horizontal granularity (pixels) - default 8 */ |
||
155 | #define CVT_H_GRANULARITY 8 |
||
156 | /* 3) Minimum vertical porch (lines) - default 3 */ |
||
157 | #define CVT_MIN_V_PORCH 3 |
||
158 | /* 4) Minimum number of vertical back porch lines - default 6 */ |
||
159 | #define CVT_MIN_V_BPORCH 6 |
||
160 | /* Pixel Clock step (kHz) */ |
||
161 | #define CVT_CLOCK_STEP 250 |
||
162 | struct drm_display_mode *drm_mode; |
||
163 | unsigned int vfieldrate, hperiod; |
||
164 | int hdisplay_rnd, hmargin, vdisplay_rnd, vmargin, vsync; |
||
165 | int interlace; |
||
166 | |||
167 | /* allocate the drm_display_mode structure. If failure, we will |
||
168 | * return directly |
||
169 | */ |
||
170 | drm_mode = drm_mode_create(dev); |
||
171 | if (!drm_mode) |
||
172 | return NULL; |
||
173 | |||
174 | /* the CVT default refresh rate is 60Hz */ |
||
175 | if (!vrefresh) |
||
176 | vrefresh = 60; |
||
177 | |||
178 | /* the required field fresh rate */ |
||
179 | if (interlaced) |
||
180 | vfieldrate = vrefresh * 2; |
||
181 | else |
||
182 | vfieldrate = vrefresh; |
||
183 | |||
184 | /* horizontal pixels */ |
||
185 | hdisplay_rnd = hdisplay - (hdisplay % CVT_H_GRANULARITY); |
||
186 | |||
187 | /* determine the left&right borders */ |
||
188 | hmargin = 0; |
||
189 | if (margins) { |
||
190 | hmargin = hdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000; |
||
191 | hmargin -= hmargin % CVT_H_GRANULARITY; |
||
192 | } |
||
193 | /* find the total active pixels */ |
||
194 | drm_mode->hdisplay = hdisplay_rnd + 2 * hmargin; |
||
195 | |||
196 | /* find the number of lines per field */ |
||
197 | if (interlaced) |
||
198 | vdisplay_rnd = vdisplay / 2; |
||
199 | else |
||
200 | vdisplay_rnd = vdisplay; |
||
201 | |||
202 | /* find the top & bottom borders */ |
||
203 | vmargin = 0; |
||
204 | if (margins) |
||
205 | vmargin = vdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000; |
||
206 | |||
207 | drm_mode->vdisplay = vdisplay + 2 * vmargin; |
||
208 | |||
209 | /* Interlaced */ |
||
210 | if (interlaced) |
||
211 | interlace = 1; |
||
212 | else |
||
213 | interlace = 0; |
||
214 | |||
215 | /* Determine VSync Width from aspect ratio */ |
||
216 | if (!(vdisplay % 3) && ((vdisplay * 4 / 3) == hdisplay)) |
||
217 | vsync = 4; |
||
218 | else if (!(vdisplay % 9) && ((vdisplay * 16 / 9) == hdisplay)) |
||
219 | vsync = 5; |
||
220 | else if (!(vdisplay % 10) && ((vdisplay * 16 / 10) == hdisplay)) |
||
221 | vsync = 6; |
||
222 | else if (!(vdisplay % 4) && ((vdisplay * 5 / 4) == hdisplay)) |
||
223 | vsync = 7; |
||
224 | else if (!(vdisplay % 9) && ((vdisplay * 15 / 9) == hdisplay)) |
||
225 | vsync = 7; |
||
226 | else /* custom */ |
||
227 | vsync = 10; |
||
228 | |||
229 | if (!reduced) { |
||
230 | /* simplify the GTF calculation */ |
||
231 | /* 4) Minimum time of vertical sync + back porch interval (µs) |
||
232 | * default 550.0 |
||
233 | */ |
||
234 | int tmp1, tmp2; |
||
235 | #define CVT_MIN_VSYNC_BP 550 |
||
236 | /* 3) Nominal HSync width (% of line period) - default 8 */ |
||
237 | #define CVT_HSYNC_PERCENTAGE 8 |
||
238 | unsigned int hblank_percentage; |
||
239 | int vsyncandback_porch, vback_porch, hblank; |
||
240 | |||
241 | /* estimated the horizontal period */ |
||
242 | tmp1 = HV_FACTOR * 1000000 - |
||
243 | CVT_MIN_VSYNC_BP * HV_FACTOR * vfieldrate; |
||
244 | tmp2 = (vdisplay_rnd + 2 * vmargin + CVT_MIN_V_PORCH) * 2 + |
||
245 | interlace; |
||
246 | hperiod = tmp1 * 2 / (tmp2 * vfieldrate); |
||
247 | |||
248 | tmp1 = CVT_MIN_VSYNC_BP * HV_FACTOR / hperiod + 1; |
||
249 | /* 9. Find number of lines in sync + backporch */ |
||
250 | if (tmp1 < (vsync + CVT_MIN_V_PORCH)) |
||
251 | vsyncandback_porch = vsync + CVT_MIN_V_PORCH; |
||
252 | else |
||
253 | vsyncandback_porch = tmp1; |
||
254 | /* 10. Find number of lines in back porch */ |
||
255 | vback_porch = vsyncandback_porch - vsync; |
||
256 | drm_mode->vtotal = vdisplay_rnd + 2 * vmargin + |
||
257 | vsyncandback_porch + CVT_MIN_V_PORCH; |
||
258 | /* 5) Definition of Horizontal blanking time limitation */ |
||
259 | /* Gradient (%/kHz) - default 600 */ |
||
260 | #define CVT_M_FACTOR 600 |
||
261 | /* Offset (%) - default 40 */ |
||
262 | #define CVT_C_FACTOR 40 |
||
263 | /* Blanking time scaling factor - default 128 */ |
||
264 | #define CVT_K_FACTOR 128 |
||
265 | /* Scaling factor weighting - default 20 */ |
||
266 | #define CVT_J_FACTOR 20 |
||
267 | #define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256) |
||
268 | #define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \ |
||
269 | CVT_J_FACTOR) |
||
270 | /* 12. Find ideal blanking duty cycle from formula */ |
||
271 | hblank_percentage = CVT_C_PRIME * HV_FACTOR - CVT_M_PRIME * |
||
272 | hperiod / 1000; |
||
273 | /* 13. Blanking time */ |
||
274 | if (hblank_percentage < 20 * HV_FACTOR) |
||
275 | hblank_percentage = 20 * HV_FACTOR; |
||
276 | hblank = drm_mode->hdisplay * hblank_percentage / |
||
277 | (100 * HV_FACTOR - hblank_percentage); |
||
278 | hblank -= hblank % (2 * CVT_H_GRANULARITY); |
||
279 | /* 14. find the total pixes per line */ |
||
280 | drm_mode->htotal = drm_mode->hdisplay + hblank; |
||
281 | drm_mode->hsync_end = drm_mode->hdisplay + hblank / 2; |
||
282 | drm_mode->hsync_start = drm_mode->hsync_end - |
||
283 | (drm_mode->htotal * CVT_HSYNC_PERCENTAGE) / 100; |
||
284 | drm_mode->hsync_start += CVT_H_GRANULARITY - |
||
285 | drm_mode->hsync_start % CVT_H_GRANULARITY; |
||
286 | /* fill the Vsync values */ |
||
287 | drm_mode->vsync_start = drm_mode->vdisplay + CVT_MIN_V_PORCH; |
||
288 | drm_mode->vsync_end = drm_mode->vsync_start + vsync; |
||
289 | } else { |
||
290 | /* Reduced blanking */ |
||
291 | /* Minimum vertical blanking interval time (µs)- default 460 */ |
||
292 | #define CVT_RB_MIN_VBLANK 460 |
||
293 | /* Fixed number of clocks for horizontal sync */ |
||
294 | #define CVT_RB_H_SYNC 32 |
||
295 | /* Fixed number of clocks for horizontal blanking */ |
||
296 | #define CVT_RB_H_BLANK 160 |
||
297 | /* Fixed number of lines for vertical front porch - default 3*/ |
||
298 | #define CVT_RB_VFPORCH 3 |
||
299 | int vbilines; |
||
300 | int tmp1, tmp2; |
||
301 | /* 8. Estimate Horizontal period. */ |
||
302 | tmp1 = HV_FACTOR * 1000000 - |
||
303 | CVT_RB_MIN_VBLANK * HV_FACTOR * vfieldrate; |
||
304 | tmp2 = vdisplay_rnd + 2 * vmargin; |
||
305 | hperiod = tmp1 / (tmp2 * vfieldrate); |
||
306 | /* 9. Find number of lines in vertical blanking */ |
||
307 | vbilines = CVT_RB_MIN_VBLANK * HV_FACTOR / hperiod + 1; |
||
308 | /* 10. Check if vertical blanking is sufficient */ |
||
309 | if (vbilines < (CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH)) |
||
310 | vbilines = CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH; |
||
311 | /* 11. Find total number of lines in vertical field */ |
||
312 | drm_mode->vtotal = vdisplay_rnd + 2 * vmargin + vbilines; |
||
313 | /* 12. Find total number of pixels in a line */ |
||
314 | drm_mode->htotal = drm_mode->hdisplay + CVT_RB_H_BLANK; |
||
315 | /* Fill in HSync values */ |
||
316 | drm_mode->hsync_end = drm_mode->hdisplay + CVT_RB_H_BLANK / 2; |
||
1963 | serge | 317 | drm_mode->hsync_start = drm_mode->hsync_end - CVT_RB_H_SYNC; |
318 | /* Fill in VSync values */ |
||
319 | drm_mode->vsync_start = drm_mode->vdisplay + CVT_RB_VFPORCH; |
||
320 | drm_mode->vsync_end = drm_mode->vsync_start + vsync; |
||
1179 | serge | 321 | } |
322 | /* 15/13. Find pixel clock frequency (kHz for xf86) */ |
||
323 | drm_mode->clock = drm_mode->htotal * HV_FACTOR * 1000 / hperiod; |
||
324 | drm_mode->clock -= drm_mode->clock % CVT_CLOCK_STEP; |
||
325 | /* 18/16. Find actual vertical frame frequency */ |
||
326 | /* ignore - just set the mode flag for interlaced */ |
||
1963 | serge | 327 | if (interlaced) { |
1179 | serge | 328 | drm_mode->vtotal *= 2; |
1963 | serge | 329 | drm_mode->flags |= DRM_MODE_FLAG_INTERLACE; |
330 | } |
||
1179 | serge | 331 | /* Fill the mode line name */ |
332 | drm_mode_set_name(drm_mode); |
||
333 | if (reduced) |
||
334 | drm_mode->flags |= (DRM_MODE_FLAG_PHSYNC | |
||
335 | DRM_MODE_FLAG_NVSYNC); |
||
336 | else |
||
337 | drm_mode->flags |= (DRM_MODE_FLAG_PVSYNC | |
||
338 | DRM_MODE_FLAG_NHSYNC); |
||
339 | |||
340 | return drm_mode; |
||
341 | } |
||
342 | EXPORT_SYMBOL(drm_cvt_mode); |
||
343 | |||
344 | /** |
||
5060 | serge | 345 | * drm_gtf_mode_complex - create the modeline based on the full GTF algorithm |
346 | * @dev: drm device |
||
347 | * @hdisplay: hdisplay size |
||
348 | * @vdisplay: vdisplay size |
||
349 | * @vrefresh: vrefresh rate. |
||
350 | * @interlaced: whether to compute an interlaced mode |
||
351 | * @margins: desired margin (borders) size |
||
352 | * @GTF_M: extended GTF formula parameters |
||
353 | * @GTF_2C: extended GTF formula parameters |
||
354 | * @GTF_K: extended GTF formula parameters |
||
355 | * @GTF_2J: extended GTF formula parameters |
||
1179 | serge | 356 | * |
1963 | serge | 357 | * GTF feature blocks specify C and J in multiples of 0.5, so we pass them |
358 | * in here multiplied by two. For a C of 40, pass in 80. |
||
5060 | serge | 359 | * |
360 | * Returns: |
||
361 | * The modeline based on the full GTF algorithm stored in a drm_display_mode object. |
||
362 | * The display mode object is allocated with drm_mode_create(). Returns NULL |
||
363 | * when no mode could be allocated. |
||
1179 | serge | 364 | */ |
1963 | serge | 365 | struct drm_display_mode * |
366 | drm_gtf_mode_complex(struct drm_device *dev, int hdisplay, int vdisplay, |
||
367 | int vrefresh, bool interlaced, int margins, |
||
368 | int GTF_M, int GTF_2C, int GTF_K, int GTF_2J) |
||
369 | { /* 1) top/bottom margin size (% of height) - default: 1.8, */ |
||
1179 | serge | 370 | #define GTF_MARGIN_PERCENTAGE 18 |
371 | /* 2) character cell horizontal granularity (pixels) - default 8 */ |
||
372 | #define GTF_CELL_GRAN 8 |
||
373 | /* 3) Minimum vertical porch (lines) - default 3 */ |
||
374 | #define GTF_MIN_V_PORCH 1 |
||
375 | /* width of vsync in lines */ |
||
376 | #define V_SYNC_RQD 3 |
||
377 | /* width of hsync as % of total line */ |
||
378 | #define H_SYNC_PERCENT 8 |
||
379 | /* min time of vsync + back porch (microsec) */ |
||
380 | #define MIN_VSYNC_PLUS_BP 550 |
||
381 | /* C' and M' are part of the Blanking Duty Cycle computation */ |
||
1963 | serge | 382 | #define GTF_C_PRIME ((((GTF_2C - GTF_2J) * GTF_K / 256) + GTF_2J) / 2) |
1179 | serge | 383 | #define GTF_M_PRIME (GTF_K * GTF_M / 256) |
384 | struct drm_display_mode *drm_mode; |
||
385 | unsigned int hdisplay_rnd, vdisplay_rnd, vfieldrate_rqd; |
||
386 | int top_margin, bottom_margin; |
||
387 | int interlace; |
||
388 | unsigned int hfreq_est; |
||
389 | int vsync_plus_bp, vback_porch; |
||
390 | unsigned int vtotal_lines, vfieldrate_est, hperiod; |
||
391 | unsigned int vfield_rate, vframe_rate; |
||
392 | int left_margin, right_margin; |
||
393 | unsigned int total_active_pixels, ideal_duty_cycle; |
||
394 | unsigned int hblank, total_pixels, pixel_freq; |
||
395 | int hsync, hfront_porch, vodd_front_porch_lines; |
||
396 | unsigned int tmp1, tmp2; |
||
397 | |||
398 | drm_mode = drm_mode_create(dev); |
||
399 | if (!drm_mode) |
||
400 | return NULL; |
||
401 | |||
402 | /* 1. In order to give correct results, the number of horizontal |
||
403 | * pixels requested is first processed to ensure that it is divisible |
||
404 | * by the character size, by rounding it to the nearest character |
||
405 | * cell boundary: |
||
406 | */ |
||
407 | hdisplay_rnd = (hdisplay + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN; |
||
408 | hdisplay_rnd = hdisplay_rnd * GTF_CELL_GRAN; |
||
409 | |||
410 | /* 2. If interlace is requested, the number of vertical lines assumed |
||
411 | * by the calculation must be halved, as the computation calculates |
||
412 | * the number of vertical lines per field. |
||
413 | */ |
||
414 | if (interlaced) |
||
415 | vdisplay_rnd = vdisplay / 2; |
||
416 | else |
||
417 | vdisplay_rnd = vdisplay; |
||
418 | |||
419 | /* 3. Find the frame rate required: */ |
||
420 | if (interlaced) |
||
421 | vfieldrate_rqd = vrefresh * 2; |
||
422 | else |
||
423 | vfieldrate_rqd = vrefresh; |
||
424 | |||
425 | /* 4. Find number of lines in Top margin: */ |
||
426 | top_margin = 0; |
||
427 | if (margins) |
||
428 | top_margin = (vdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) / |
||
429 | 1000; |
||
430 | /* 5. Find number of lines in bottom margin: */ |
||
431 | bottom_margin = top_margin; |
||
432 | |||
433 | /* 6. If interlace is required, then set variable interlace: */ |
||
434 | if (interlaced) |
||
435 | interlace = 1; |
||
436 | else |
||
437 | interlace = 0; |
||
438 | |||
439 | /* 7. Estimate the Horizontal frequency */ |
||
440 | { |
||
441 | tmp1 = (1000000 - MIN_VSYNC_PLUS_BP * vfieldrate_rqd) / 500; |
||
442 | tmp2 = (vdisplay_rnd + 2 * top_margin + GTF_MIN_V_PORCH) * |
||
443 | 2 + interlace; |
||
444 | hfreq_est = (tmp2 * 1000 * vfieldrate_rqd) / tmp1; |
||
445 | } |
||
446 | |||
447 | /* 8. Find the number of lines in V sync + back porch */ |
||
448 | /* [V SYNC+BP] = RINT(([MIN VSYNC+BP] * hfreq_est / 1000000)) */ |
||
449 | vsync_plus_bp = MIN_VSYNC_PLUS_BP * hfreq_est / 1000; |
||
450 | vsync_plus_bp = (vsync_plus_bp + 500) / 1000; |
||
451 | /* 9. Find the number of lines in V back porch alone: */ |
||
452 | vback_porch = vsync_plus_bp - V_SYNC_RQD; |
||
453 | /* 10. Find the total number of lines in Vertical field period: */ |
||
454 | vtotal_lines = vdisplay_rnd + top_margin + bottom_margin + |
||
455 | vsync_plus_bp + GTF_MIN_V_PORCH; |
||
456 | /* 11. Estimate the Vertical field frequency: */ |
||
457 | vfieldrate_est = hfreq_est / vtotal_lines; |
||
458 | /* 12. Find the actual horizontal period: */ |
||
459 | hperiod = 1000000 / (vfieldrate_rqd * vtotal_lines); |
||
460 | |||
461 | /* 13. Find the actual Vertical field frequency: */ |
||
462 | vfield_rate = hfreq_est / vtotal_lines; |
||
463 | /* 14. Find the Vertical frame frequency: */ |
||
464 | if (interlaced) |
||
465 | vframe_rate = vfield_rate / 2; |
||
466 | else |
||
467 | vframe_rate = vfield_rate; |
||
468 | /* 15. Find number of pixels in left margin: */ |
||
469 | if (margins) |
||
470 | left_margin = (hdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) / |
||
471 | 1000; |
||
472 | else |
||
473 | left_margin = 0; |
||
474 | |||
475 | /* 16.Find number of pixels in right margin: */ |
||
476 | right_margin = left_margin; |
||
477 | /* 17.Find total number of active pixels in image and left and right */ |
||
478 | total_active_pixels = hdisplay_rnd + left_margin + right_margin; |
||
479 | /* 18.Find the ideal blanking duty cycle from blanking duty cycle */ |
||
480 | ideal_duty_cycle = GTF_C_PRIME * 1000 - |
||
481 | (GTF_M_PRIME * 1000000 / hfreq_est); |
||
482 | /* 19.Find the number of pixels in the blanking time to the nearest |
||
483 | * double character cell: */ |
||
484 | hblank = total_active_pixels * ideal_duty_cycle / |
||
485 | (100000 - ideal_duty_cycle); |
||
486 | hblank = (hblank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN); |
||
487 | hblank = hblank * 2 * GTF_CELL_GRAN; |
||
488 | /* 20.Find total number of pixels: */ |
||
489 | total_pixels = total_active_pixels + hblank; |
||
490 | /* 21.Find pixel clock frequency: */ |
||
491 | pixel_freq = total_pixels * hfreq_est / 1000; |
||
492 | /* Stage 1 computations are now complete; I should really pass |
||
493 | * the results to another function and do the Stage 2 computations, |
||
494 | * but I only need a few more values so I'll just append the |
||
495 | * computations here for now */ |
||
496 | /* 17. Find the number of pixels in the horizontal sync period: */ |
||
497 | hsync = H_SYNC_PERCENT * total_pixels / 100; |
||
498 | hsync = (hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN; |
||
499 | hsync = hsync * GTF_CELL_GRAN; |
||
500 | /* 18. Find the number of pixels in horizontal front porch period */ |
||
501 | hfront_porch = hblank / 2 - hsync; |
||
502 | /* 36. Find the number of lines in the odd front porch period: */ |
||
503 | vodd_front_porch_lines = GTF_MIN_V_PORCH ; |
||
504 | |||
505 | /* finally, pack the results in the mode struct */ |
||
506 | drm_mode->hdisplay = hdisplay_rnd; |
||
507 | drm_mode->hsync_start = hdisplay_rnd + hfront_porch; |
||
508 | drm_mode->hsync_end = drm_mode->hsync_start + hsync; |
||
509 | drm_mode->htotal = total_pixels; |
||
510 | drm_mode->vdisplay = vdisplay_rnd; |
||
511 | drm_mode->vsync_start = vdisplay_rnd + vodd_front_porch_lines; |
||
512 | drm_mode->vsync_end = drm_mode->vsync_start + V_SYNC_RQD; |
||
513 | drm_mode->vtotal = vtotal_lines; |
||
514 | |||
515 | drm_mode->clock = pixel_freq; |
||
516 | |||
517 | if (interlaced) { |
||
518 | drm_mode->vtotal *= 2; |
||
519 | drm_mode->flags |= DRM_MODE_FLAG_INTERLACE; |
||
520 | } |
||
521 | |||
1963 | serge | 522 | drm_mode_set_name(drm_mode); |
523 | if (GTF_M == 600 && GTF_2C == 80 && GTF_K == 128 && GTF_2J == 40) |
||
524 | drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC; |
||
525 | else |
||
526 | drm_mode->flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC; |
||
527 | |||
1179 | serge | 528 | return drm_mode; |
529 | } |
||
1963 | serge | 530 | EXPORT_SYMBOL(drm_gtf_mode_complex); |
531 | |||
532 | /** |
||
5060 | serge | 533 | * drm_gtf_mode - create the modeline based on the GTF algorithm |
534 | * @dev: drm device |
||
535 | * @hdisplay: hdisplay size |
||
536 | * @vdisplay: vdisplay size |
||
537 | * @vrefresh: vrefresh rate. |
||
538 | * @interlaced: whether to compute an interlaced mode |
||
539 | * @margins: desired margin (borders) size |
||
1963 | serge | 540 | * |
541 | * return the modeline based on GTF algorithm |
||
542 | * |
||
543 | * This function is to create the modeline based on the GTF algorithm. |
||
544 | * Generalized Timing Formula is derived from: |
||
545 | * GTF Spreadsheet by Andy Morrish (1/5/97) |
||
546 | * available at http://www.vesa.org |
||
547 | * |
||
548 | * And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c. |
||
549 | * What I have done is to translate it by using integer calculation. |
||
550 | * I also refer to the function of fb_get_mode in the file of |
||
551 | * drivers/video/fbmon.c |
||
552 | * |
||
553 | * Standard GTF parameters: |
||
554 | * M = 600 |
||
555 | * C = 40 |
||
556 | * K = 128 |
||
557 | * J = 20 |
||
5060 | serge | 558 | * |
559 | * Returns: |
||
560 | * The modeline based on the GTF algorithm stored in a drm_display_mode object. |
||
561 | * The display mode object is allocated with drm_mode_create(). Returns NULL |
||
562 | * when no mode could be allocated. |
||
1963 | serge | 563 | */ |
564 | struct drm_display_mode * |
||
565 | drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh, |
||
5060 | serge | 566 | bool interlaced, int margins) |
1963 | serge | 567 | { |
5060 | serge | 568 | return drm_gtf_mode_complex(dev, hdisplay, vdisplay, vrefresh, |
569 | interlaced, margins, |
||
570 | 600, 40 * 2, 128, 20 * 2); |
||
1963 | serge | 571 | } |
1179 | serge | 572 | EXPORT_SYMBOL(drm_gtf_mode); |
1963 | serge | 573 | |
3746 | Serge | 574 | #ifdef CONFIG_VIDEOMODE_HELPERS |
5060 | serge | 575 | /** |
576 | * drm_display_mode_from_videomode - fill in @dmode using @vm, |
||
577 | * @vm: videomode structure to use as source |
||
578 | * @dmode: drm_display_mode structure to use as destination |
||
579 | * |
||
580 | * Fills out @dmode using the display mode specified in @vm. |
||
581 | */ |
||
582 | void drm_display_mode_from_videomode(const struct videomode *vm, |
||
3480 | Serge | 583 | struct drm_display_mode *dmode) |
584 | { |
||
585 | dmode->hdisplay = vm->hactive; |
||
586 | dmode->hsync_start = dmode->hdisplay + vm->hfront_porch; |
||
587 | dmode->hsync_end = dmode->hsync_start + vm->hsync_len; |
||
588 | dmode->htotal = dmode->hsync_end + vm->hback_porch; |
||
589 | |||
590 | dmode->vdisplay = vm->vactive; |
||
591 | dmode->vsync_start = dmode->vdisplay + vm->vfront_porch; |
||
592 | dmode->vsync_end = dmode->vsync_start + vm->vsync_len; |
||
593 | dmode->vtotal = dmode->vsync_end + vm->vback_porch; |
||
594 | |||
595 | dmode->clock = vm->pixelclock / 1000; |
||
596 | |||
597 | dmode->flags = 0; |
||
3746 | Serge | 598 | if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH) |
3480 | Serge | 599 | dmode->flags |= DRM_MODE_FLAG_PHSYNC; |
3746 | Serge | 600 | else if (vm->flags & DISPLAY_FLAGS_HSYNC_LOW) |
3480 | Serge | 601 | dmode->flags |= DRM_MODE_FLAG_NHSYNC; |
3746 | Serge | 602 | if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH) |
3480 | Serge | 603 | dmode->flags |= DRM_MODE_FLAG_PVSYNC; |
3746 | Serge | 604 | else if (vm->flags & DISPLAY_FLAGS_VSYNC_LOW) |
3480 | Serge | 605 | dmode->flags |= DRM_MODE_FLAG_NVSYNC; |
3746 | Serge | 606 | if (vm->flags & DISPLAY_FLAGS_INTERLACED) |
3480 | Serge | 607 | dmode->flags |= DRM_MODE_FLAG_INTERLACE; |
3746 | Serge | 608 | if (vm->flags & DISPLAY_FLAGS_DOUBLESCAN) |
3480 | Serge | 609 | dmode->flags |= DRM_MODE_FLAG_DBLSCAN; |
4075 | Serge | 610 | if (vm->flags & DISPLAY_FLAGS_DOUBLECLK) |
611 | dmode->flags |= DRM_MODE_FLAG_DBLCLK; |
||
3480 | Serge | 612 | drm_mode_set_name(dmode); |
613 | } |
||
614 | EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode); |
||
615 | |||
3746 | Serge | 616 | #ifdef CONFIG_OF |
1179 | serge | 617 | /** |
3480 | Serge | 618 | * of_get_drm_display_mode - get a drm_display_mode from devicetree |
619 | * @np: device_node with the timing specification |
||
620 | * @dmode: will be set to the return value |
||
621 | * @index: index into the list of display timings in devicetree |
||
622 | * |
||
623 | * This function is expensive and should only be used, if only one mode is to be |
||
624 | * read from DT. To get multiple modes start with of_get_display_timings and |
||
625 | * work with that instead. |
||
5060 | serge | 626 | * |
627 | * Returns: |
||
628 | * 0 on success, a negative errno code when no of videomode node was found. |
||
3480 | Serge | 629 | */ |
630 | int of_get_drm_display_mode(struct device_node *np, |
||
631 | struct drm_display_mode *dmode, int index) |
||
632 | { |
||
633 | struct videomode vm; |
||
634 | int ret; |
||
635 | |||
636 | ret = of_get_videomode(np, &vm, index); |
||
637 | if (ret) |
||
638 | return ret; |
||
639 | |||
640 | drm_display_mode_from_videomode(&vm, dmode); |
||
641 | |||
642 | pr_debug("%s: got %dx%d display mode from %s\n", |
||
643 | of_node_full_name(np), vm.hactive, vm.vactive, np->name); |
||
644 | drm_mode_debug_printmodeline(dmode); |
||
645 | |||
646 | return 0; |
||
647 | } |
||
648 | EXPORT_SYMBOL_GPL(of_get_drm_display_mode); |
||
3746 | Serge | 649 | #endif /* CONFIG_OF */ |
650 | #endif /* CONFIG_VIDEOMODE_HELPERS */ |
||
3480 | Serge | 651 | |
652 | /** |
||
1123 | serge | 653 | * drm_mode_set_name - set the name on a mode |
654 | * @mode: name will be set in this mode |
||
655 | * |
||
5060 | serge | 656 | * Set the name of @mode to a standard format which is |
657 | * with an optional 'i' suffix for interlaced modes. |
||
1123 | serge | 658 | */ |
659 | void drm_mode_set_name(struct drm_display_mode *mode) |
||
660 | { |
||
1963 | serge | 661 | bool interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE); |
662 | |||
663 | snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d%s", |
||
664 | mode->hdisplay, mode->vdisplay, |
||
665 | interlaced ? "i" : ""); |
||
1123 | serge | 666 | } |
667 | EXPORT_SYMBOL(drm_mode_set_name); |
||
668 | |||
1321 | serge | 669 | /** drm_mode_hsync - get the hsync of a mode |
670 | * @mode: mode |
||
671 | * |
||
5060 | serge | 672 | * Returns: |
673 | * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the |
||
674 | * value first if it is not yet set. |
||
1321 | serge | 675 | */ |
1963 | serge | 676 | int drm_mode_hsync(const struct drm_display_mode *mode) |
1321 | serge | 677 | { |
678 | unsigned int calc_val; |
||
679 | |||
680 | if (mode->hsync) |
||
681 | return mode->hsync; |
||
682 | |||
683 | if (mode->htotal < 0) |
||
684 | return 0; |
||
685 | |||
686 | calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */ |
||
687 | calc_val += 500; /* round to 1000Hz */ |
||
688 | calc_val /= 1000; /* truncate to kHz */ |
||
689 | |||
690 | return calc_val; |
||
691 | } |
||
692 | EXPORT_SYMBOL(drm_mode_hsync); |
||
693 | |||
1123 | serge | 694 | /** |
695 | * drm_mode_vrefresh - get the vrefresh of a mode |
||
696 | * @mode: mode |
||
697 | * |
||
5060 | serge | 698 | * Returns: |
699 | * @modes's vrefresh rate in Hz, rounded to the nearest integer. Calculates the |
||
700 | * value first if it is not yet set. |
||
1123 | serge | 701 | */ |
1963 | serge | 702 | int drm_mode_vrefresh(const struct drm_display_mode *mode) |
1123 | serge | 703 | { |
704 | int refresh = 0; |
||
705 | unsigned int calc_val; |
||
706 | |||
707 | if (mode->vrefresh > 0) |
||
708 | refresh = mode->vrefresh; |
||
709 | else if (mode->htotal > 0 && mode->vtotal > 0) { |
||
1179 | serge | 710 | int vtotal; |
711 | vtotal = mode->vtotal; |
||
1123 | serge | 712 | /* work out vrefresh the value will be x1000 */ |
713 | calc_val = (mode->clock * 1000); |
||
714 | calc_val /= mode->htotal; |
||
1179 | serge | 715 | refresh = (calc_val + vtotal / 2) / vtotal; |
1123 | serge | 716 | |
717 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
||
718 | refresh *= 2; |
||
719 | if (mode->flags & DRM_MODE_FLAG_DBLSCAN) |
||
720 | refresh /= 2; |
||
721 | if (mode->vscan > 1) |
||
722 | refresh /= mode->vscan; |
||
723 | } |
||
724 | return refresh; |
||
725 | } |
||
726 | EXPORT_SYMBOL(drm_mode_vrefresh); |
||
727 | |||
728 | /** |
||
5060 | serge | 729 | * drm_mode_set_crtcinfo - set CRTC modesetting timing parameters |
1123 | serge | 730 | * @p: mode |
4560 | Serge | 731 | * @adjust_flags: a combination of adjustment flags |
1123 | serge | 732 | * |
5060 | serge | 733 | * Setup the CRTC modesetting timing parameters for @p, adjusting if necessary. |
1123 | serge | 734 | * |
4560 | Serge | 735 | * - The CRTC_INTERLACE_HALVE_V flag can be used to halve vertical timings of |
736 | * interlaced modes. |
||
737 | * - The CRTC_STEREO_DOUBLE flag can be used to compute the timings for |
||
738 | * buffers containing two eyes (only adjust the timings when needed, eg. for |
||
739 | * "frame packing" or "side by side full"). |
||
1123 | serge | 740 | */ |
741 | void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags) |
||
742 | { |
||
743 | if ((p == NULL) || ((p->type & DRM_MODE_TYPE_CRTC_C) == DRM_MODE_TYPE_BUILTIN)) |
||
744 | return; |
||
745 | |||
4560 | Serge | 746 | p->crtc_clock = p->clock; |
1123 | serge | 747 | p->crtc_hdisplay = p->hdisplay; |
748 | p->crtc_hsync_start = p->hsync_start; |
||
749 | p->crtc_hsync_end = p->hsync_end; |
||
750 | p->crtc_htotal = p->htotal; |
||
751 | p->crtc_hskew = p->hskew; |
||
752 | p->crtc_vdisplay = p->vdisplay; |
||
753 | p->crtc_vsync_start = p->vsync_start; |
||
754 | p->crtc_vsync_end = p->vsync_end; |
||
755 | p->crtc_vtotal = p->vtotal; |
||
756 | |||
757 | if (p->flags & DRM_MODE_FLAG_INTERLACE) { |
||
758 | if (adjust_flags & CRTC_INTERLACE_HALVE_V) { |
||
759 | p->crtc_vdisplay /= 2; |
||
760 | p->crtc_vsync_start /= 2; |
||
761 | p->crtc_vsync_end /= 2; |
||
762 | p->crtc_vtotal /= 2; |
||
763 | } |
||
764 | } |
||
765 | |||
766 | if (p->flags & DRM_MODE_FLAG_DBLSCAN) { |
||
767 | p->crtc_vdisplay *= 2; |
||
768 | p->crtc_vsync_start *= 2; |
||
769 | p->crtc_vsync_end *= 2; |
||
770 | p->crtc_vtotal *= 2; |
||
771 | } |
||
772 | |||
773 | if (p->vscan > 1) { |
||
774 | p->crtc_vdisplay *= p->vscan; |
||
775 | p->crtc_vsync_start *= p->vscan; |
||
776 | p->crtc_vsync_end *= p->vscan; |
||
777 | p->crtc_vtotal *= p->vscan; |
||
778 | } |
||
779 | |||
4560 | Serge | 780 | if (adjust_flags & CRTC_STEREO_DOUBLE) { |
781 | unsigned int layout = p->flags & DRM_MODE_FLAG_3D_MASK; |
||
782 | |||
783 | switch (layout) { |
||
784 | case DRM_MODE_FLAG_3D_FRAME_PACKING: |
||
785 | p->crtc_clock *= 2; |
||
786 | p->crtc_vdisplay += p->crtc_vtotal; |
||
787 | p->crtc_vsync_start += p->crtc_vtotal; |
||
788 | p->crtc_vsync_end += p->crtc_vtotal; |
||
789 | p->crtc_vtotal += p->crtc_vtotal; |
||
790 | break; |
||
791 | } |
||
792 | } |
||
793 | |||
1123 | serge | 794 | p->crtc_vblank_start = min(p->crtc_vsync_start, p->crtc_vdisplay); |
795 | p->crtc_vblank_end = max(p->crtc_vsync_end, p->crtc_vtotal); |
||
796 | p->crtc_hblank_start = min(p->crtc_hsync_start, p->crtc_hdisplay); |
||
797 | p->crtc_hblank_end = max(p->crtc_hsync_end, p->crtc_htotal); |
||
798 | } |
||
799 | EXPORT_SYMBOL(drm_mode_set_crtcinfo); |
||
800 | |||
801 | /** |
||
3031 | serge | 802 | * drm_mode_copy - copy the mode |
803 | * @dst: mode to overwrite |
||
804 | * @src: mode to copy |
||
805 | * |
||
4075 | Serge | 806 | * Copy an existing mode into another mode, preserving the object id and |
807 | * list head of the destination mode. |
||
3031 | serge | 808 | */ |
809 | void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src) |
||
810 | { |
||
811 | int id = dst->base.id; |
||
4075 | Serge | 812 | struct list_head head = dst->head; |
3031 | serge | 813 | |
814 | *dst = *src; |
||
815 | dst->base.id = id; |
||
4075 | Serge | 816 | dst->head = head; |
3031 | serge | 817 | } |
818 | EXPORT_SYMBOL(drm_mode_copy); |
||
819 | |||
820 | /** |
||
1123 | serge | 821 | * drm_mode_duplicate - allocate and duplicate an existing mode |
5060 | serge | 822 | * @dev: drm_device to allocate the duplicated mode for |
823 | * @mode: mode to duplicate |
||
1123 | serge | 824 | * |
825 | * Just allocate a new mode, copy the existing mode into it, and return |
||
826 | * a pointer to it. Used to create new instances of established modes. |
||
5060 | serge | 827 | * |
828 | * Returns: |
||
829 | * Pointer to duplicated mode on success, NULL on error. |
||
1123 | serge | 830 | */ |
831 | struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev, |
||
1963 | serge | 832 | const struct drm_display_mode *mode) |
1123 | serge | 833 | { |
834 | struct drm_display_mode *nmode; |
||
835 | |||
836 | nmode = drm_mode_create(dev); |
||
837 | if (!nmode) |
||
838 | return NULL; |
||
839 | |||
3031 | serge | 840 | drm_mode_copy(nmode, mode); |
841 | |||
1123 | serge | 842 | return nmode; |
843 | } |
||
844 | EXPORT_SYMBOL(drm_mode_duplicate); |
||
845 | |||
846 | /** |
||
847 | * drm_mode_equal - test modes for equality |
||
848 | * @mode1: first mode |
||
849 | * @mode2: second mode |
||
850 | * |
||
851 | * Check to see if @mode1 and @mode2 are equivalent. |
||
852 | * |
||
5060 | serge | 853 | * Returns: |
1123 | serge | 854 | * True if the modes are equal, false otherwise. |
855 | */ |
||
3192 | Serge | 856 | bool drm_mode_equal(const struct drm_display_mode *mode1, const struct drm_display_mode *mode2) |
1123 | serge | 857 | { |
858 | /* do clock check convert to PICOS so fb modes get matched |
||
859 | * the same */ |
||
860 | if (mode1->clock && mode2->clock) { |
||
861 | if (KHZ2PICOS(mode1->clock) != KHZ2PICOS(mode2->clock)) |
||
862 | return false; |
||
863 | } else if (mode1->clock != mode2->clock) |
||
864 | return false; |
||
865 | |||
4560 | Serge | 866 | if ((mode1->flags & DRM_MODE_FLAG_3D_MASK) != |
867 | (mode2->flags & DRM_MODE_FLAG_3D_MASK)) |
||
868 | return false; |
||
869 | |||
870 | return drm_mode_equal_no_clocks_no_stereo(mode1, mode2); |
||
3746 | Serge | 871 | } |
872 | EXPORT_SYMBOL(drm_mode_equal); |
||
873 | |||
874 | /** |
||
4560 | Serge | 875 | * drm_mode_equal_no_clocks_no_stereo - test modes for equality |
3746 | Serge | 876 | * @mode1: first mode |
877 | * @mode2: second mode |
||
878 | * |
||
879 | * Check to see if @mode1 and @mode2 are equivalent, but |
||
4560 | Serge | 880 | * don't check the pixel clocks nor the stereo layout. |
3746 | Serge | 881 | * |
5060 | serge | 882 | * Returns: |
3746 | Serge | 883 | * True if the modes are equal, false otherwise. |
884 | */ |
||
4560 | Serge | 885 | bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1, |
886 | const struct drm_display_mode *mode2) |
||
3746 | Serge | 887 | { |
1123 | serge | 888 | if (mode1->hdisplay == mode2->hdisplay && |
889 | mode1->hsync_start == mode2->hsync_start && |
||
890 | mode1->hsync_end == mode2->hsync_end && |
||
891 | mode1->htotal == mode2->htotal && |
||
892 | mode1->hskew == mode2->hskew && |
||
893 | mode1->vdisplay == mode2->vdisplay && |
||
894 | mode1->vsync_start == mode2->vsync_start && |
||
895 | mode1->vsync_end == mode2->vsync_end && |
||
896 | mode1->vtotal == mode2->vtotal && |
||
897 | mode1->vscan == mode2->vscan && |
||
4560 | Serge | 898 | (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) == |
899 | (mode2->flags & ~DRM_MODE_FLAG_3D_MASK)) |
||
1123 | serge | 900 | return true; |
901 | |||
902 | return false; |
||
903 | } |
||
4560 | Serge | 904 | EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo); |
1123 | serge | 905 | |
906 | /** |
||
907 | * drm_mode_validate_size - make sure modes adhere to size constraints |
||
908 | * @dev: DRM device |
||
909 | * @mode_list: list of modes to check |
||
910 | * @maxX: maximum width |
||
911 | * @maxY: maximum height |
||
912 | * |
||
5060 | serge | 913 | * This function is a helper which can be used to validate modes against size |
914 | * limitations of the DRM device/connector. If a mode is too big its status |
||
915 | * memeber is updated with the appropriate validation failure code. The list |
||
916 | * itself is not changed. |
||
1123 | serge | 917 | */ |
918 | void drm_mode_validate_size(struct drm_device *dev, |
||
919 | struct list_head *mode_list, |
||
5060 | serge | 920 | int maxX, int maxY) |
1123 | serge | 921 | { |
922 | struct drm_display_mode *mode; |
||
923 | |||
924 | list_for_each_entry(mode, mode_list, head) { |
||
925 | if (maxX > 0 && mode->hdisplay > maxX) |
||
926 | mode->status = MODE_VIRTUAL_X; |
||
927 | |||
928 | if (maxY > 0 && mode->vdisplay > maxY) |
||
929 | mode->status = MODE_VIRTUAL_Y; |
||
930 | } |
||
931 | } |
||
932 | EXPORT_SYMBOL(drm_mode_validate_size); |
||
933 | |||
934 | /** |
||
935 | * drm_mode_prune_invalid - remove invalid modes from mode list |
||
936 | * @dev: DRM device |
||
937 | * @mode_list: list of modes to check |
||
938 | * @verbose: be verbose about it |
||
939 | * |
||
5060 | serge | 940 | * This helper function can be used to prune a display mode list after |
941 | * validation has been completed. All modes who's status is not MODE_OK will be |
||
942 | * removed from the list, and if @verbose the status code and mode name is also |
||
943 | * printed to dmesg. |
||
1123 | serge | 944 | */ |
945 | void drm_mode_prune_invalid(struct drm_device *dev, |
||
946 | struct list_head *mode_list, bool verbose) |
||
947 | { |
||
948 | struct drm_display_mode *mode, *t; |
||
949 | |||
950 | list_for_each_entry_safe(mode, t, mode_list, head) { |
||
951 | if (mode->status != MODE_OK) { |
||
952 | list_del(&mode->head); |
||
953 | if (verbose) { |
||
954 | drm_mode_debug_printmodeline(mode); |
||
1179 | serge | 955 | DRM_DEBUG_KMS("Not using %s mode %d\n", |
1123 | serge | 956 | mode->name, mode->status); |
957 | } |
||
958 | drm_mode_destroy(dev, mode); |
||
959 | } |
||
960 | } |
||
961 | } |
||
962 | EXPORT_SYMBOL(drm_mode_prune_invalid); |
||
963 | |||
964 | /** |
||
965 | * drm_mode_compare - compare modes for favorability |
||
1404 | serge | 966 | * @priv: unused |
1123 | serge | 967 | * @lh_a: list_head for first mode |
968 | * @lh_b: list_head for second mode |
||
969 | * |
||
970 | * Compare two modes, given by @lh_a and @lh_b, returning a value indicating |
||
971 | * which is better. |
||
972 | * |
||
5060 | serge | 973 | * Returns: |
1123 | serge | 974 | * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or |
975 | * positive if @lh_b is better than @lh_a. |
||
976 | */ |
||
1404 | serge | 977 | static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b) |
1123 | serge | 978 | { |
979 | struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head); |
||
980 | struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head); |
||
981 | int diff; |
||
982 | |||
983 | diff = ((b->type & DRM_MODE_TYPE_PREFERRED) != 0) - |
||
984 | ((a->type & DRM_MODE_TYPE_PREFERRED) != 0); |
||
985 | if (diff) |
||
986 | return diff; |
||
987 | diff = b->hdisplay * b->vdisplay - a->hdisplay * a->vdisplay; |
||
988 | if (diff) |
||
989 | return diff; |
||
4075 | Serge | 990 | |
991 | diff = b->vrefresh - a->vrefresh; |
||
992 | if (diff) |
||
993 | return diff; |
||
994 | |||
1123 | serge | 995 | diff = b->clock - a->clock; |
996 | return diff; |
||
997 | } |
||
998 | |||
999 | /** |
||
1000 | * drm_mode_sort - sort mode list |
||
5060 | serge | 1001 | * @mode_list: list of drm_display_mode structures to sort |
1123 | serge | 1002 | * |
5060 | serge | 1003 | * Sort @mode_list by favorability, moving good modes to the head of the list. |
1123 | serge | 1004 | */ |
1005 | void drm_mode_sort(struct list_head *mode_list) |
||
1006 | { |
||
1404 | serge | 1007 | list_sort(NULL, mode_list, drm_mode_compare); |
1123 | serge | 1008 | } |
1009 | EXPORT_SYMBOL(drm_mode_sort); |
||
1010 | |||
1011 | /** |
||
1012 | * drm_mode_connector_list_update - update the mode list for the connector |
||
1013 | * @connector: the connector to update |
||
5060 | serge | 1014 | * @merge_type_bits: whether to merge or overright type bits. |
1123 | serge | 1015 | * |
1016 | * This moves the modes from the @connector probed_modes list |
||
1017 | * to the actual mode list. It compares the probed mode against the current |
||
5060 | serge | 1018 | * list and only adds different/new modes. |
1019 | * |
||
1020 | * This is just a helper functions doesn't validate any modes itself and also |
||
1021 | * doesn't prune any invalid modes. Callers need to do that themselves. |
||
1123 | serge | 1022 | */ |
5060 | serge | 1023 | void drm_mode_connector_list_update(struct drm_connector *connector, |
1024 | bool merge_type_bits) |
||
1123 | serge | 1025 | { |
1026 | struct drm_display_mode *mode; |
||
1027 | struct drm_display_mode *pmode, *pt; |
||
1028 | int found_it; |
||
1029 | |||
5060 | serge | 1030 | WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex)); |
1031 | |||
1123 | serge | 1032 | list_for_each_entry_safe(pmode, pt, &connector->probed_modes, |
1033 | head) { |
||
1034 | found_it = 0; |
||
1035 | /* go through current modes checking for the new probed mode */ |
||
1036 | list_for_each_entry(mode, &connector->modes, head) { |
||
1037 | if (drm_mode_equal(pmode, mode)) { |
||
1038 | found_it = 1; |
||
1039 | /* if equal delete the probed mode */ |
||
1040 | mode->status = pmode->status; |
||
1179 | serge | 1041 | /* Merge type bits together */ |
5060 | serge | 1042 | if (merge_type_bits) |
1179 | serge | 1043 | mode->type |= pmode->type; |
5060 | serge | 1044 | else |
1045 | mode->type = pmode->type; |
||
1123 | serge | 1046 | list_del(&pmode->head); |
1047 | drm_mode_destroy(connector->dev, pmode); |
||
1048 | break; |
||
1049 | } |
||
1050 | } |
||
1051 | |||
1052 | if (!found_it) { |
||
1053 | list_move_tail(&pmode->head, &connector->modes); |
||
1054 | } |
||
1055 | } |
||
1056 | } |
||
1057 | EXPORT_SYMBOL(drm_mode_connector_list_update);>>>> |