2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
5 * Copyright 2010 Red Hat, Inc.
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
9 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
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, sub license,
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:
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 * DEALINGS IN THE SOFTWARE.
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/hdmi.h>
33 #include <linux/i2c.h>
34 #include <linux/module.h>
35 #include <linux/vga_switcheroo.h>
37 #include <drm/drm_edid.h>
38 #include <drm/drm_encoder.h>
39 #include <drm/drm_displayid.h>
41 #include "drm_crtc_internal.h"
43 #define version_greater(edid, maj, min) \
44 (((edid)->version > (maj)) || \
45 ((edid)->version == (maj) && (edid)->revision > (min)))
47 #define EDID_EST_TIMINGS 16
48 #define EDID_STD_TIMINGS 8
49 #define EDID_DETAILED_TIMINGS 4
52 * EDID blocks out in the wild have a variety of bugs, try to collect
53 * them here (note that userspace may work around broken monitors first,
54 * but fixes should make their way here so that the kernel "just works"
55 * on as many displays as possible).
58 /* First detailed mode wrong, use largest 60Hz mode */
59 #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
60 /* Reported 135MHz pixel clock is too high, needs adjustment */
61 #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
62 /* Prefer the largest mode at 75 Hz */
63 #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
64 /* Detail timing is in cm not mm */
65 #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
66 /* Detailed timing descriptors have bogus size values, so just take the
67 * maximum size and use that.
69 #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
70 /* Monitor forgot to set the first detailed is preferred bit. */
71 #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
72 /* use +hsync +vsync for detailed mode */
73 #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
74 /* Force reduced-blanking timings for detailed modes */
75 #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
77 #define EDID_QUIRK_FORCE_8BPC (1 << 8)
79 #define EDID_QUIRK_FORCE_12BPC (1 << 9)
81 #define EDID_QUIRK_FORCE_6BPC (1 << 10)
83 struct detailed_mode_closure
{
84 struct drm_connector
*connector
;
96 static const struct edid_quirk
{
100 } edid_quirk_list
[] = {
102 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60
},
104 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60
},
106 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
108 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
109 { "AEO", 0, EDID_QUIRK_FORCE_6BPC
},
111 /* Belinea 10 15 55 */
112 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60
},
113 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60
},
115 /* Envision Peripherals, Inc. EN-7100e */
116 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH
},
117 /* Envision EN2028 */
118 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60
},
120 /* Funai Electronics PM36B */
121 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75
|
122 EDID_QUIRK_DETAILED_IN_CM
},
124 /* LG Philips LCD LP154W01-A5 */
125 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
},
126 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
},
128 /* Philips 107p5 CRT */
129 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
132 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
134 /* Samsung SyncMaster 205BW. Note: irony */
135 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP
},
136 /* Samsung SyncMaster 22[5-6]BW */
137 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60
},
138 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60
},
140 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
141 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC
},
143 /* ViewSonic VA2026w */
144 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING
},
146 /* Medion MD 30217 PG */
147 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75
},
149 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
150 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC
},
152 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
153 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC
},
157 * Autogenerated from the DMT spec.
158 * This table is copied from xfree86/modes/xf86EdidModes.c.
160 static const struct drm_display_mode drm_dmt_modes
[] = {
161 /* 0x01 - 640x350@85Hz */
162 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 31500, 640, 672,
163 736, 832, 0, 350, 382, 385, 445, 0,
164 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
165 /* 0x02 - 640x400@85Hz */
166 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 31500, 640, 672,
167 736, 832, 0, 400, 401, 404, 445, 0,
168 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
169 /* 0x03 - 720x400@85Hz */
170 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 35500, 720, 756,
171 828, 936, 0, 400, 401, 404, 446, 0,
172 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
173 /* 0x04 - 640x480@60Hz */
174 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
175 752, 800, 0, 480, 490, 492, 525, 0,
176 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
177 /* 0x05 - 640x480@72Hz */
178 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 664,
179 704, 832, 0, 480, 489, 492, 520, 0,
180 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
181 /* 0x06 - 640x480@75Hz */
182 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 656,
183 720, 840, 0, 480, 481, 484, 500, 0,
184 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
185 /* 0x07 - 640x480@85Hz */
186 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 36000, 640, 696,
187 752, 832, 0, 480, 481, 484, 509, 0,
188 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
189 /* 0x08 - 800x600@56Hz */
190 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 36000, 800, 824,
191 896, 1024, 0, 600, 601, 603, 625, 0,
192 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
193 /* 0x09 - 800x600@60Hz */
194 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 40000, 800, 840,
195 968, 1056, 0, 600, 601, 605, 628, 0,
196 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
197 /* 0x0a - 800x600@72Hz */
198 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 50000, 800, 856,
199 976, 1040, 0, 600, 637, 643, 666, 0,
200 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
201 /* 0x0b - 800x600@75Hz */
202 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 49500, 800, 816,
203 896, 1056, 0, 600, 601, 604, 625, 0,
204 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
205 /* 0x0c - 800x600@85Hz */
206 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 56250, 800, 832,
207 896, 1048, 0, 600, 601, 604, 631, 0,
208 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
209 /* 0x0d - 800x600@120Hz RB */
210 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 73250, 800, 848,
211 880, 960, 0, 600, 603, 607, 636, 0,
212 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
213 /* 0x0e - 848x480@60Hz */
214 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER
, 33750, 848, 864,
215 976, 1088, 0, 480, 486, 494, 517, 0,
216 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
217 /* 0x0f - 1024x768@43Hz, interlace */
218 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER
, 44900, 1024, 1032,
219 1208, 1264, 0, 768, 768, 776, 817, 0,
220 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
221 DRM_MODE_FLAG_INTERLACE
) },
222 /* 0x10 - 1024x768@60Hz */
223 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
224 1184, 1344, 0, 768, 771, 777, 806, 0,
225 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
226 /* 0x11 - 1024x768@70Hz */
227 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 75000, 1024, 1048,
228 1184, 1328, 0, 768, 771, 777, 806, 0,
229 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
230 /* 0x12 - 1024x768@75Hz */
231 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 78750, 1024, 1040,
232 1136, 1312, 0, 768, 769, 772, 800, 0,
233 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
234 /* 0x13 - 1024x768@85Hz */
235 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 94500, 1024, 1072,
236 1168, 1376, 0, 768, 769, 772, 808, 0,
237 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
238 /* 0x14 - 1024x768@120Hz RB */
239 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 115500, 1024, 1072,
240 1104, 1184, 0, 768, 771, 775, 813, 0,
241 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
242 /* 0x15 - 1152x864@75Hz */
243 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER
, 108000, 1152, 1216,
244 1344, 1600, 0, 864, 865, 868, 900, 0,
245 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
246 /* 0x55 - 1280x720@60Hz */
247 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1390,
248 1430, 1650, 0, 720, 725, 730, 750, 0,
249 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
250 /* 0x16 - 1280x768@60Hz RB */
251 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 68250, 1280, 1328,
252 1360, 1440, 0, 768, 771, 778, 790, 0,
253 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
254 /* 0x17 - 1280x768@60Hz */
255 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 79500, 1280, 1344,
256 1472, 1664, 0, 768, 771, 778, 798, 0,
257 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
258 /* 0x18 - 1280x768@75Hz */
259 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 102250, 1280, 1360,
260 1488, 1696, 0, 768, 771, 778, 805, 0,
261 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
262 /* 0x19 - 1280x768@85Hz */
263 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 117500, 1280, 1360,
264 1496, 1712, 0, 768, 771, 778, 809, 0,
265 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
266 /* 0x1a - 1280x768@120Hz RB */
267 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 140250, 1280, 1328,
268 1360, 1440, 0, 768, 771, 778, 813, 0,
269 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
270 /* 0x1b - 1280x800@60Hz RB */
271 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 71000, 1280, 1328,
272 1360, 1440, 0, 800, 803, 809, 823, 0,
273 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
274 /* 0x1c - 1280x800@60Hz */
275 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 83500, 1280, 1352,
276 1480, 1680, 0, 800, 803, 809, 831, 0,
277 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
278 /* 0x1d - 1280x800@75Hz */
279 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 106500, 1280, 1360,
280 1488, 1696, 0, 800, 803, 809, 838, 0,
281 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
282 /* 0x1e - 1280x800@85Hz */
283 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 122500, 1280, 1360,
284 1496, 1712, 0, 800, 803, 809, 843, 0,
285 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
286 /* 0x1f - 1280x800@120Hz RB */
287 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 146250, 1280, 1328,
288 1360, 1440, 0, 800, 803, 809, 847, 0,
289 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
290 /* 0x20 - 1280x960@60Hz */
291 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1376,
292 1488, 1800, 0, 960, 961, 964, 1000, 0,
293 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
294 /* 0x21 - 1280x960@85Hz */
295 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1344,
296 1504, 1728, 0, 960, 961, 964, 1011, 0,
297 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
298 /* 0x22 - 1280x960@120Hz RB */
299 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 175500, 1280, 1328,
300 1360, 1440, 0, 960, 963, 967, 1017, 0,
301 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
302 /* 0x23 - 1280x1024@60Hz */
303 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1328,
304 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
305 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
306 /* 0x24 - 1280x1024@75Hz */
307 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 135000, 1280, 1296,
308 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
309 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
310 /* 0x25 - 1280x1024@85Hz */
311 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 157500, 1280, 1344,
312 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
313 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
314 /* 0x26 - 1280x1024@120Hz RB */
315 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 187250, 1280, 1328,
316 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
317 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
318 /* 0x27 - 1360x768@60Hz */
319 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER
, 85500, 1360, 1424,
320 1536, 1792, 0, 768, 771, 777, 795, 0,
321 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
322 /* 0x28 - 1360x768@120Hz RB */
323 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER
, 148250, 1360, 1408,
324 1440, 1520, 0, 768, 771, 776, 813, 0,
325 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
326 /* 0x51 - 1366x768@60Hz */
327 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER
, 85500, 1366, 1436,
328 1579, 1792, 0, 768, 771, 774, 798, 0,
329 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
330 /* 0x56 - 1366x768@60Hz */
331 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER
, 72000, 1366, 1380,
332 1436, 1500, 0, 768, 769, 772, 800, 0,
333 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
334 /* 0x29 - 1400x1050@60Hz RB */
335 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 101000, 1400, 1448,
336 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
337 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
338 /* 0x2a - 1400x1050@60Hz */
339 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 121750, 1400, 1488,
340 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
341 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
342 /* 0x2b - 1400x1050@75Hz */
343 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 156000, 1400, 1504,
344 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
345 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
346 /* 0x2c - 1400x1050@85Hz */
347 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 179500, 1400, 1504,
348 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
349 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
350 /* 0x2d - 1400x1050@120Hz RB */
351 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 208000, 1400, 1448,
352 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
353 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
354 /* 0x2e - 1440x900@60Hz RB */
355 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 88750, 1440, 1488,
356 1520, 1600, 0, 900, 903, 909, 926, 0,
357 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
358 /* 0x2f - 1440x900@60Hz */
359 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 106500, 1440, 1520,
360 1672, 1904, 0, 900, 903, 909, 934, 0,
361 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
362 /* 0x30 - 1440x900@75Hz */
363 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 136750, 1440, 1536,
364 1688, 1936, 0, 900, 903, 909, 942, 0,
365 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
366 /* 0x31 - 1440x900@85Hz */
367 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 157000, 1440, 1544,
368 1696, 1952, 0, 900, 903, 909, 948, 0,
369 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
370 /* 0x32 - 1440x900@120Hz RB */
371 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 182750, 1440, 1488,
372 1520, 1600, 0, 900, 903, 909, 953, 0,
373 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
374 /* 0x53 - 1600x900@60Hz */
375 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER
, 108000, 1600, 1624,
376 1704, 1800, 0, 900, 901, 904, 1000, 0,
377 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
378 /* 0x33 - 1600x1200@60Hz */
379 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 162000, 1600, 1664,
380 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
381 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
382 /* 0x34 - 1600x1200@65Hz */
383 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 175500, 1600, 1664,
384 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
385 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
386 /* 0x35 - 1600x1200@70Hz */
387 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 189000, 1600, 1664,
388 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
389 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
390 /* 0x36 - 1600x1200@75Hz */
391 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 202500, 1600, 1664,
392 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
393 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
394 /* 0x37 - 1600x1200@85Hz */
395 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 229500, 1600, 1664,
396 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
397 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
398 /* 0x38 - 1600x1200@120Hz RB */
399 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 268250, 1600, 1648,
400 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
401 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
402 /* 0x39 - 1680x1050@60Hz RB */
403 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 119000, 1680, 1728,
404 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
405 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
406 /* 0x3a - 1680x1050@60Hz */
407 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 146250, 1680, 1784,
408 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
409 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
410 /* 0x3b - 1680x1050@75Hz */
411 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 187000, 1680, 1800,
412 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
413 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
414 /* 0x3c - 1680x1050@85Hz */
415 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 214750, 1680, 1808,
416 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
417 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
418 /* 0x3d - 1680x1050@120Hz RB */
419 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 245500, 1680, 1728,
420 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
421 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
422 /* 0x3e - 1792x1344@60Hz */
423 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 204750, 1792, 1920,
424 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
425 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
426 /* 0x3f - 1792x1344@75Hz */
427 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 261000, 1792, 1888,
428 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
429 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
430 /* 0x40 - 1792x1344@120Hz RB */
431 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 333250, 1792, 1840,
432 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
433 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
434 /* 0x41 - 1856x1392@60Hz */
435 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 218250, 1856, 1952,
436 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
437 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
438 /* 0x42 - 1856x1392@75Hz */
439 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 288000, 1856, 1984,
440 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
441 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
442 /* 0x43 - 1856x1392@120Hz RB */
443 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 356500, 1856, 1904,
444 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
445 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
446 /* 0x52 - 1920x1080@60Hz */
447 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
448 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
449 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
450 /* 0x44 - 1920x1200@60Hz RB */
451 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 154000, 1920, 1968,
452 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
453 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
454 /* 0x45 - 1920x1200@60Hz */
455 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 193250, 1920, 2056,
456 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
457 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
458 /* 0x46 - 1920x1200@75Hz */
459 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 245250, 1920, 2056,
460 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
461 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
462 /* 0x47 - 1920x1200@85Hz */
463 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 281250, 1920, 2064,
464 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
465 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
466 /* 0x48 - 1920x1200@120Hz RB */
467 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 317000, 1920, 1968,
468 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
469 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
470 /* 0x49 - 1920x1440@60Hz */
471 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 234000, 1920, 2048,
472 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
473 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
474 /* 0x4a - 1920x1440@75Hz */
475 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2064,
476 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
477 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
478 /* 0x4b - 1920x1440@120Hz RB */
479 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 380500, 1920, 1968,
480 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
481 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
482 /* 0x54 - 2048x1152@60Hz */
483 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER
, 162000, 2048, 2074,
484 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
485 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
486 /* 0x4c - 2560x1600@60Hz RB */
487 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 268500, 2560, 2608,
488 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
489 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
490 /* 0x4d - 2560x1600@60Hz */
491 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 348500, 2560, 2752,
492 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
493 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
494 /* 0x4e - 2560x1600@75Hz */
495 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 443250, 2560, 2768,
496 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
497 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
498 /* 0x4f - 2560x1600@85Hz */
499 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 505250, 2560, 2768,
500 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
501 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
502 /* 0x50 - 2560x1600@120Hz RB */
503 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 552750, 2560, 2608,
504 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
505 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
506 /* 0x57 - 4096x2160@60Hz RB */
507 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 556744, 4096, 4104,
508 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
509 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
510 /* 0x58 - 4096x2160@59.94Hz RB */
511 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 556188, 4096, 4104,
512 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
513 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
517 * These more or less come from the DMT spec. The 720x400 modes are
518 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
519 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
520 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
523 * The DMT modes have been fact-checked; the rest are mild guesses.
525 static const struct drm_display_mode edid_est_modes
[] = {
526 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 40000, 800, 840,
527 968, 1056, 0, 600, 601, 605, 628, 0,
528 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@60Hz */
529 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 36000, 800, 824,
530 896, 1024, 0, 600, 601, 603, 625, 0,
531 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@56Hz */
532 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 656,
533 720, 840, 0, 480, 481, 484, 500, 0,
534 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@75Hz */
535 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 664,
536 704, 832, 0, 480, 489, 492, 520, 0,
537 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@72Hz */
538 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 30240, 640, 704,
539 768, 864, 0, 480, 483, 486, 525, 0,
540 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@67Hz */
541 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
542 752, 800, 0, 480, 490, 492, 525, 0,
543 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@60Hz */
544 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 35500, 720, 738,
545 846, 900, 0, 400, 421, 423, 449, 0,
546 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 720x400@88Hz */
547 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 28320, 720, 738,
548 846, 900, 0, 400, 412, 414, 449, 0,
549 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 720x400@70Hz */
550 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 135000, 1280, 1296,
551 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
552 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1280x1024@75Hz */
553 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 78750, 1024, 1040,
554 1136, 1312, 0, 768, 769, 772, 800, 0,
555 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1024x768@75Hz */
556 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 75000, 1024, 1048,
557 1184, 1328, 0, 768, 771, 777, 806, 0,
558 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 1024x768@70Hz */
559 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
560 1184, 1344, 0, 768, 771, 777, 806, 0,
561 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 1024x768@60Hz */
562 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER
,44900, 1024, 1032,
563 1208, 1264, 0, 768, 768, 776, 817, 0,
564 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_INTERLACE
) }, /* 1024x768@43Hz */
565 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 57284, 832, 864,
566 928, 1152, 0, 624, 625, 628, 667, 0,
567 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 832x624@75Hz */
568 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 49500, 800, 816,
569 896, 1056, 0, 600, 601, 604, 625, 0,
570 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@75Hz */
571 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 50000, 800, 856,
572 976, 1040, 0, 600, 637, 643, 666, 0,
573 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@72Hz */
574 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER
, 108000, 1152, 1216,
575 1344, 1600, 0, 864, 865, 868, 900, 0,
576 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1152x864@75Hz */
586 static const struct minimode est3_modes
[] = {
594 { 1024, 768, 85, 0 },
595 { 1152, 864, 75, 0 },
597 { 1280, 768, 60, 1 },
598 { 1280, 768, 60, 0 },
599 { 1280, 768, 75, 0 },
600 { 1280, 768, 85, 0 },
601 { 1280, 960, 60, 0 },
602 { 1280, 960, 85, 0 },
603 { 1280, 1024, 60, 0 },
604 { 1280, 1024, 85, 0 },
606 { 1360, 768, 60, 0 },
607 { 1440, 900, 60, 1 },
608 { 1440, 900, 60, 0 },
609 { 1440, 900, 75, 0 },
610 { 1440, 900, 85, 0 },
611 { 1400, 1050, 60, 1 },
612 { 1400, 1050, 60, 0 },
613 { 1400, 1050, 75, 0 },
615 { 1400, 1050, 85, 0 },
616 { 1680, 1050, 60, 1 },
617 { 1680, 1050, 60, 0 },
618 { 1680, 1050, 75, 0 },
619 { 1680, 1050, 85, 0 },
620 { 1600, 1200, 60, 0 },
621 { 1600, 1200, 65, 0 },
622 { 1600, 1200, 70, 0 },
624 { 1600, 1200, 75, 0 },
625 { 1600, 1200, 85, 0 },
626 { 1792, 1344, 60, 0 },
627 { 1792, 1344, 75, 0 },
628 { 1856, 1392, 60, 0 },
629 { 1856, 1392, 75, 0 },
630 { 1920, 1200, 60, 1 },
631 { 1920, 1200, 60, 0 },
633 { 1920, 1200, 75, 0 },
634 { 1920, 1200, 85, 0 },
635 { 1920, 1440, 60, 0 },
636 { 1920, 1440, 75, 0 },
639 static const struct minimode extra_modes
[] = {
640 { 1024, 576, 60, 0 },
641 { 1366, 768, 60, 0 },
642 { 1600, 900, 60, 0 },
643 { 1680, 945, 60, 0 },
644 { 1920, 1080, 60, 0 },
645 { 2048, 1152, 60, 0 },
646 { 2048, 1536, 60, 0 },
650 * Probably taken from CEA-861 spec.
651 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
653 * Index using the VIC.
655 static const struct drm_display_mode edid_cea_modes
[] = {
656 /* 0 - dummy, VICs start at 1 */
658 /* 1 - 640x480@60Hz */
659 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
660 752, 800, 0, 480, 490, 492, 525, 0,
661 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
662 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
663 /* 2 - 720x480@60Hz */
664 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 27000, 720, 736,
665 798, 858, 0, 480, 489, 495, 525, 0,
666 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
667 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
668 /* 3 - 720x480@60Hz */
669 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 27000, 720, 736,
670 798, 858, 0, 480, 489, 495, 525, 0,
671 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
672 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
673 /* 4 - 1280x720@60Hz */
674 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1390,
675 1430, 1650, 0, 720, 725, 730, 750, 0,
676 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
677 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
678 /* 5 - 1920x1080i@60Hz */
679 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2008,
680 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
681 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
682 DRM_MODE_FLAG_INTERLACE
),
683 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
684 /* 6 - 720(1440)x480i@60Hz */
685 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
686 801, 858, 0, 480, 488, 494, 525, 0,
687 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
688 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
689 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
690 /* 7 - 720(1440)x480i@60Hz */
691 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
692 801, 858, 0, 480, 488, 494, 525, 0,
693 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
694 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
695 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
696 /* 8 - 720(1440)x240@60Hz */
697 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
698 801, 858, 0, 240, 244, 247, 262, 0,
699 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
700 DRM_MODE_FLAG_DBLCLK
),
701 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
702 /* 9 - 720(1440)x240@60Hz */
703 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
704 801, 858, 0, 240, 244, 247, 262, 0,
705 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
706 DRM_MODE_FLAG_DBLCLK
),
707 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
708 /* 10 - 2880x480i@60Hz */
709 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
710 3204, 3432, 0, 480, 488, 494, 525, 0,
711 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
712 DRM_MODE_FLAG_INTERLACE
),
713 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
714 /* 11 - 2880x480i@60Hz */
715 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
716 3204, 3432, 0, 480, 488, 494, 525, 0,
717 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
718 DRM_MODE_FLAG_INTERLACE
),
719 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
720 /* 12 - 2880x240@60Hz */
721 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
722 3204, 3432, 0, 240, 244, 247, 262, 0,
723 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
724 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
725 /* 13 - 2880x240@60Hz */
726 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
727 3204, 3432, 0, 240, 244, 247, 262, 0,
728 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
729 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
730 /* 14 - 1440x480@60Hz */
731 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1472,
732 1596, 1716, 0, 480, 489, 495, 525, 0,
733 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
734 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
735 /* 15 - 1440x480@60Hz */
736 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1472,
737 1596, 1716, 0, 480, 489, 495, 525, 0,
738 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
739 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
740 /* 16 - 1920x1080@60Hz */
741 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
742 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
743 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
744 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
745 /* 17 - 720x576@50Hz */
746 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
747 796, 864, 0, 576, 581, 586, 625, 0,
748 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
749 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
750 /* 18 - 720x576@50Hz */
751 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
752 796, 864, 0, 576, 581, 586, 625, 0,
753 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
754 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
755 /* 19 - 1280x720@50Hz */
756 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1720,
757 1760, 1980, 0, 720, 725, 730, 750, 0,
758 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
759 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
760 /* 20 - 1920x1080i@50Hz */
761 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2448,
762 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
763 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
764 DRM_MODE_FLAG_INTERLACE
),
765 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
766 /* 21 - 720(1440)x576i@50Hz */
767 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
768 795, 864, 0, 576, 580, 586, 625, 0,
769 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
770 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
771 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
772 /* 22 - 720(1440)x576i@50Hz */
773 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
774 795, 864, 0, 576, 580, 586, 625, 0,
775 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
776 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
777 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
778 /* 23 - 720(1440)x288@50Hz */
779 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
780 795, 864, 0, 288, 290, 293, 312, 0,
781 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
782 DRM_MODE_FLAG_DBLCLK
),
783 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
784 /* 24 - 720(1440)x288@50Hz */
785 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
786 795, 864, 0, 288, 290, 293, 312, 0,
787 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
788 DRM_MODE_FLAG_DBLCLK
),
789 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
790 /* 25 - 2880x576i@50Hz */
791 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
792 3180, 3456, 0, 576, 580, 586, 625, 0,
793 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
794 DRM_MODE_FLAG_INTERLACE
),
795 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
796 /* 26 - 2880x576i@50Hz */
797 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
798 3180, 3456, 0, 576, 580, 586, 625, 0,
799 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
800 DRM_MODE_FLAG_INTERLACE
),
801 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
802 /* 27 - 2880x288@50Hz */
803 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
804 3180, 3456, 0, 288, 290, 293, 312, 0,
805 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
806 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
807 /* 28 - 2880x288@50Hz */
808 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
809 3180, 3456, 0, 288, 290, 293, 312, 0,
810 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
811 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
812 /* 29 - 1440x576@50Hz */
813 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1464,
814 1592, 1728, 0, 576, 581, 586, 625, 0,
815 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
816 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
817 /* 30 - 1440x576@50Hz */
818 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1464,
819 1592, 1728, 0, 576, 581, 586, 625, 0,
820 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
821 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
822 /* 31 - 1920x1080@50Hz */
823 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2448,
824 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
825 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
826 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
827 /* 32 - 1920x1080@24Hz */
828 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2558,
829 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
830 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
831 .vrefresh
= 24, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
832 /* 33 - 1920x1080@25Hz */
833 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2448,
834 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
835 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
836 .vrefresh
= 25, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
837 /* 34 - 1920x1080@30Hz */
838 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2008,
839 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
840 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
841 .vrefresh
= 30, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
842 /* 35 - 2880x480@60Hz */
843 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2944,
844 3192, 3432, 0, 480, 489, 495, 525, 0,
845 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
846 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
847 /* 36 - 2880x480@60Hz */
848 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2944,
849 3192, 3432, 0, 480, 489, 495, 525, 0,
850 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
851 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
852 /* 37 - 2880x576@50Hz */
853 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2928,
854 3184, 3456, 0, 576, 581, 586, 625, 0,
855 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
856 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
857 /* 38 - 2880x576@50Hz */
858 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2928,
859 3184, 3456, 0, 576, 581, 586, 625, 0,
860 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
861 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
862 /* 39 - 1920x1080i@50Hz */
863 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 72000, 1920, 1952,
864 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
865 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
|
866 DRM_MODE_FLAG_INTERLACE
),
867 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
868 /* 40 - 1920x1080i@100Hz */
869 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2448,
870 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
871 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
872 DRM_MODE_FLAG_INTERLACE
),
873 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
874 /* 41 - 1280x720@100Hz */
875 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1720,
876 1760, 1980, 0, 720, 725, 730, 750, 0,
877 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
878 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
879 /* 42 - 720x576@100Hz */
880 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
881 796, 864, 0, 576, 581, 586, 625, 0,
882 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
883 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
884 /* 43 - 720x576@100Hz */
885 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
886 796, 864, 0, 576, 581, 586, 625, 0,
887 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
888 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
889 /* 44 - 720(1440)x576i@100Hz */
890 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
891 795, 864, 0, 576, 580, 586, 625, 0,
892 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
893 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
894 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
895 /* 45 - 720(1440)x576i@100Hz */
896 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
897 795, 864, 0, 576, 580, 586, 625, 0,
898 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
899 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
900 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
901 /* 46 - 1920x1080i@120Hz */
902 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
903 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
904 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
905 DRM_MODE_FLAG_INTERLACE
),
906 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
907 /* 47 - 1280x720@120Hz */
908 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1390,
909 1430, 1650, 0, 720, 725, 730, 750, 0,
910 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
911 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
912 /* 48 - 720x480@120Hz */
913 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 54000, 720, 736,
914 798, 858, 0, 480, 489, 495, 525, 0,
915 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
916 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
917 /* 49 - 720x480@120Hz */
918 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 54000, 720, 736,
919 798, 858, 0, 480, 489, 495, 525, 0,
920 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
921 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
922 /* 50 - 720(1440)x480i@120Hz */
923 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 739,
924 801, 858, 0, 480, 488, 494, 525, 0,
925 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
926 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
927 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
928 /* 51 - 720(1440)x480i@120Hz */
929 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 739,
930 801, 858, 0, 480, 488, 494, 525, 0,
931 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
932 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
933 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
934 /* 52 - 720x576@200Hz */
935 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 108000, 720, 732,
936 796, 864, 0, 576, 581, 586, 625, 0,
937 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
938 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
939 /* 53 - 720x576@200Hz */
940 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 108000, 720, 732,
941 796, 864, 0, 576, 581, 586, 625, 0,
942 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
943 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
944 /* 54 - 720(1440)x576i@200Hz */
945 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
946 795, 864, 0, 576, 580, 586, 625, 0,
947 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
948 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
949 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
950 /* 55 - 720(1440)x576i@200Hz */
951 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
952 795, 864, 0, 576, 580, 586, 625, 0,
953 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
954 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
955 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
956 /* 56 - 720x480@240Hz */
957 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 108000, 720, 736,
958 798, 858, 0, 480, 489, 495, 525, 0,
959 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
960 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
961 /* 57 - 720x480@240Hz */
962 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 108000, 720, 736,
963 798, 858, 0, 480, 489, 495, 525, 0,
964 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
965 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
966 /* 58 - 720(1440)x480i@240Hz */
967 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 739,
968 801, 858, 0, 480, 488, 494, 525, 0,
969 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
970 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
971 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
972 /* 59 - 720(1440)x480i@240Hz */
973 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 739,
974 801, 858, 0, 480, 488, 494, 525, 0,
975 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
976 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
977 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
978 /* 60 - 1280x720@24Hz */
979 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 59400, 1280, 3040,
980 3080, 3300, 0, 720, 725, 730, 750, 0,
981 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
982 .vrefresh
= 24, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
983 /* 61 - 1280x720@25Hz */
984 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 3700,
985 3740, 3960, 0, 720, 725, 730, 750, 0,
986 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
987 .vrefresh
= 25, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
988 /* 62 - 1280x720@30Hz */
989 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 3040,
990 3080, 3300, 0, 720, 725, 730, 750, 0,
991 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
992 .vrefresh
= 30, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
993 /* 63 - 1920x1080@120Hz */
994 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2008,
995 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
996 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
997 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
998 /* 64 - 1920x1080@100Hz */
999 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2448,
1000 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1001 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1002 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
1006 * HDMI 1.4 4k modes. Index using the VIC.
1008 static const struct drm_display_mode edid_4k_modes
[] = {
1009 /* 0 - dummy, VICs start at 1 */
1011 /* 1 - 3840x2160@30Hz */
1012 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1013 3840, 4016, 4104, 4400, 0,
1014 2160, 2168, 2178, 2250, 0,
1015 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1017 /* 2 - 3840x2160@25Hz */
1018 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1019 3840, 4896, 4984, 5280, 0,
1020 2160, 2168, 2178, 2250, 0,
1021 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1023 /* 3 - 3840x2160@24Hz */
1024 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1025 3840, 5116, 5204, 5500, 0,
1026 2160, 2168, 2178, 2250, 0,
1027 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1029 /* 4 - 4096x2160@24Hz (SMPTE) */
1030 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1031 4096, 5116, 5204, 5500, 0,
1032 2160, 2168, 2178, 2250, 0,
1033 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1037 /*** DDC fetch and block validation ***/
1039 static const u8 edid_header
[] = {
1040 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1044 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1045 * @raw_edid: pointer to raw base EDID block
1047 * Sanity check the header of the base EDID block.
1049 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
1051 int drm_edid_header_is_valid(const u8
*raw_edid
)
1055 for (i
= 0; i
< sizeof(edid_header
); i
++)
1056 if (raw_edid
[i
] == edid_header
[i
])
1061 EXPORT_SYMBOL(drm_edid_header_is_valid
);
1063 static int edid_fixup __read_mostly
= 6;
1064 module_param_named(edid_fixup
, edid_fixup
, int, 0400);
1065 MODULE_PARM_DESC(edid_fixup
,
1066 "Minimum number of valid EDID header bytes (0-8, default 6)");
1068 static void drm_get_displayid(struct drm_connector
*connector
,
1071 static int drm_edid_block_checksum(const u8
*raw_edid
)
1075 for (i
= 0; i
< EDID_LENGTH
; i
++)
1076 csum
+= raw_edid
[i
];
1081 static bool drm_edid_is_zero(const u8
*in_edid
, int length
)
1083 if (memchr_inv(in_edid
, 0, length
))
1090 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1091 * @raw_edid: pointer to raw EDID block
1092 * @block: type of block to validate (0 for base, extension otherwise)
1093 * @print_bad_edid: if true, dump bad EDID blocks to the console
1094 * @edid_corrupt: if true, the header or checksum is invalid
1096 * Validate a base or extension EDID block and optionally dump bad blocks to
1099 * Return: True if the block is valid, false otherwise.
1101 bool drm_edid_block_valid(u8
*raw_edid
, int block
, bool print_bad_edid
,
1105 struct edid
*edid
= (struct edid
*)raw_edid
;
1107 if (WARN_ON(!raw_edid
))
1110 if (edid_fixup
> 8 || edid_fixup
< 0)
1114 int score
= drm_edid_header_is_valid(raw_edid
);
1117 *edid_corrupt
= false;
1118 } else if (score
>= edid_fixup
) {
1119 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1120 * The corrupt flag needs to be set here otherwise, the
1121 * fix-up code here will correct the problem, the
1122 * checksum is correct and the test fails
1125 *edid_corrupt
= true;
1126 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1127 memcpy(raw_edid
, edid_header
, sizeof(edid_header
));
1130 *edid_corrupt
= true;
1135 csum
= drm_edid_block_checksum(raw_edid
);
1137 if (print_bad_edid
) {
1138 DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum
);
1142 *edid_corrupt
= true;
1144 /* allow CEA to slide through, switches mangle this */
1145 if (raw_edid
[0] != 0x02)
1149 /* per-block-type checks */
1150 switch (raw_edid
[0]) {
1152 if (edid
->version
!= 1) {
1153 DRM_ERROR("EDID has major version %d, instead of 1\n", edid
->version
);
1157 if (edid
->revision
> 4)
1158 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1168 if (print_bad_edid
) {
1169 if (drm_edid_is_zero(raw_edid
, EDID_LENGTH
)) {
1170 printk(KERN_ERR
"EDID block is all zeroes\n");
1172 printk(KERN_ERR
"Raw EDID:\n");
1173 print_hex_dump(KERN_ERR
, " \t", DUMP_PREFIX_NONE
, 16, 1,
1174 raw_edid
, EDID_LENGTH
, false);
1179 EXPORT_SYMBOL(drm_edid_block_valid
);
1182 * drm_edid_is_valid - sanity check EDID data
1185 * Sanity-check an entire EDID record (including extensions)
1187 * Return: True if the EDID data is valid, false otherwise.
1189 bool drm_edid_is_valid(struct edid
*edid
)
1192 u8
*raw
= (u8
*)edid
;
1197 for (i
= 0; i
<= edid
->extensions
; i
++)
1198 if (!drm_edid_block_valid(raw
+ i
* EDID_LENGTH
, i
, true, NULL
))
1203 EXPORT_SYMBOL(drm_edid_is_valid
);
1205 #define DDC_SEGMENT_ADDR 0x30
1207 * drm_do_probe_ddc_edid() - get EDID information via I2C
1208 * @data: I2C device adapter
1209 * @buf: EDID data buffer to be filled
1210 * @block: 128 byte EDID block to start fetching from
1211 * @len: EDID data buffer length to fetch
1213 * Try to fetch EDID information by calling I2C driver functions.
1215 * Return: 0 on success or -1 on failure.
1218 drm_do_probe_ddc_edid(void *data
, u8
*buf
, unsigned int block
, size_t len
)
1220 struct i2c_adapter
*adapter
= data
;
1221 unsigned char start
= block
* EDID_LENGTH
;
1222 unsigned char segment
= block
>> 1;
1223 unsigned char xfers
= segment
? 3 : 2;
1224 int ret
, retries
= 5;
1227 * The core I2C driver will automatically retry the transfer if the
1228 * adapter reports EAGAIN. However, we find that bit-banging transfers
1229 * are susceptible to errors under a heavily loaded machine and
1230 * generate spurious NAKs and timeouts. Retrying the transfer
1231 * of the individual block a few times seems to overcome this.
1234 struct i2c_msg msgs
[] = {
1236 .addr
= DDC_SEGMENT_ADDR
,
1254 * Avoid sending the segment addr to not upset non-compliant
1257 ret
= i2c_transfer(adapter
, &msgs
[3 - xfers
], xfers
);
1259 if (ret
== -ENXIO
) {
1260 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1264 } while (ret
!= xfers
&& --retries
);
1266 return ret
== xfers
? 0 : -1;
1269 static void connector_bad_edid(struct drm_connector
*connector
,
1270 u8
*edid
, int num_blocks
)
1274 if (connector
->bad_edid_counter
++ && !(drm_debug
& DRM_UT_KMS
))
1277 dev_warn(connector
->dev
->dev
,
1278 "%s: EDID is invalid:\n",
1280 for (i
= 0; i
< num_blocks
; i
++) {
1281 u8
*block
= edid
+ i
* EDID_LENGTH
;
1284 if (drm_edid_is_zero(block
, EDID_LENGTH
))
1285 sprintf(prefix
, "\t[%02x] ZERO ", i
);
1286 else if (!drm_edid_block_valid(block
, i
, false, NULL
))
1287 sprintf(prefix
, "\t[%02x] BAD ", i
);
1289 sprintf(prefix
, "\t[%02x] GOOD ", i
);
1291 print_hex_dump(KERN_WARNING
,
1292 prefix
, DUMP_PREFIX_NONE
, 16, 1,
1293 block
, EDID_LENGTH
, false);
1298 * drm_do_get_edid - get EDID data using a custom EDID block read function
1299 * @connector: connector we're probing
1300 * @get_edid_block: EDID block read function
1301 * @data: private data passed to the block read function
1303 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1304 * exposes a different interface to read EDID blocks this function can be used
1305 * to get EDID data using a custom block read function.
1307 * As in the general case the DDC bus is accessible by the kernel at the I2C
1308 * level, drivers must make all reasonable efforts to expose it as an I2C
1309 * adapter and use drm_get_edid() instead of abusing this function.
1311 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1313 struct edid
*drm_do_get_edid(struct drm_connector
*connector
,
1314 int (*get_edid_block
)(void *data
, u8
*buf
, unsigned int block
,
1318 int i
, j
= 0, valid_extensions
= 0;
1321 if ((edid
= kmalloc(EDID_LENGTH
, GFP_KERNEL
)) == NULL
)
1324 /* base block fetch */
1325 for (i
= 0; i
< 4; i
++) {
1326 if (get_edid_block(data
, edid
, 0, EDID_LENGTH
))
1328 if (drm_edid_block_valid(edid
, 0, false,
1329 &connector
->edid_corrupt
))
1331 if (i
== 0 && drm_edid_is_zero(edid
, EDID_LENGTH
)) {
1332 connector
->null_edid_counter
++;
1339 /* if there's no extensions, we're done */
1340 valid_extensions
= edid
[0x7e];
1341 if (valid_extensions
== 0)
1342 return (struct edid
*)edid
;
1344 new = krealloc(edid
, (valid_extensions
+ 1) * EDID_LENGTH
, GFP_KERNEL
);
1349 for (j
= 1; j
<= edid
[0x7e]; j
++) {
1350 u8
*block
= edid
+ j
* EDID_LENGTH
;
1352 for (i
= 0; i
< 4; i
++) {
1353 if (get_edid_block(data
, block
, j
, EDID_LENGTH
))
1355 if (drm_edid_block_valid(block
, j
, false, NULL
))
1363 if (valid_extensions
!= edid
[0x7e]) {
1366 connector_bad_edid(connector
, edid
, edid
[0x7e] + 1);
1368 edid
[EDID_LENGTH
-1] += edid
[0x7e] - valid_extensions
;
1369 edid
[0x7e] = valid_extensions
;
1371 new = kmalloc((valid_extensions
+ 1) * EDID_LENGTH
, GFP_KERNEL
);
1376 for (i
= 0; i
<= edid
[0x7e]; i
++) {
1377 u8
*block
= edid
+ i
* EDID_LENGTH
;
1379 if (!drm_edid_block_valid(block
, i
, false, NULL
))
1382 memcpy(base
, block
, EDID_LENGTH
);
1383 base
+= EDID_LENGTH
;
1390 return (struct edid
*)edid
;
1393 connector_bad_edid(connector
, edid
, 1);
1398 EXPORT_SYMBOL_GPL(drm_do_get_edid
);
1401 * drm_probe_ddc() - probe DDC presence
1402 * @adapter: I2C adapter to probe
1404 * Return: True on success, false on failure.
1407 drm_probe_ddc(struct i2c_adapter
*adapter
)
1411 return (drm_do_probe_ddc_edid(adapter
, &out
, 0, 1) == 0);
1413 EXPORT_SYMBOL(drm_probe_ddc
);
1416 * drm_get_edid - get EDID data, if available
1417 * @connector: connector we're probing
1418 * @adapter: I2C adapter to use for DDC
1420 * Poke the given I2C channel to grab EDID data if possible. If found,
1421 * attach it to the connector.
1423 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1425 struct edid
*drm_get_edid(struct drm_connector
*connector
,
1426 struct i2c_adapter
*adapter
)
1430 if (!drm_probe_ddc(adapter
))
1433 edid
= drm_do_get_edid(connector
, drm_do_probe_ddc_edid
, adapter
);
1435 drm_get_displayid(connector
, edid
);
1438 EXPORT_SYMBOL(drm_get_edid
);
1441 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1442 * @connector: connector we're probing
1443 * @adapter: I2C adapter to use for DDC
1445 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1446 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1447 * switch DDC to the GPU which is retrieving EDID.
1449 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1451 struct edid
*drm_get_edid_switcheroo(struct drm_connector
*connector
,
1452 struct i2c_adapter
*adapter
)
1454 struct pci_dev
*pdev
= connector
->dev
->pdev
;
1457 vga_switcheroo_lock_ddc(pdev
);
1458 edid
= drm_get_edid(connector
, adapter
);
1459 vga_switcheroo_unlock_ddc(pdev
);
1463 EXPORT_SYMBOL(drm_get_edid_switcheroo
);
1466 * drm_edid_duplicate - duplicate an EDID and the extensions
1467 * @edid: EDID to duplicate
1469 * Return: Pointer to duplicated EDID or NULL on allocation failure.
1471 struct edid
*drm_edid_duplicate(const struct edid
*edid
)
1473 return kmemdup(edid
, (edid
->extensions
+ 1) * EDID_LENGTH
, GFP_KERNEL
);
1475 EXPORT_SYMBOL(drm_edid_duplicate
);
1477 /*** EDID parsing ***/
1480 * edid_vendor - match a string against EDID's obfuscated vendor field
1481 * @edid: EDID to match
1482 * @vendor: vendor string
1484 * Returns true if @vendor is in @edid, false otherwise
1486 static bool edid_vendor(struct edid
*edid
, const char *vendor
)
1488 char edid_vendor
[3];
1490 edid_vendor
[0] = ((edid
->mfg_id
[0] & 0x7c) >> 2) + '@';
1491 edid_vendor
[1] = (((edid
->mfg_id
[0] & 0x3) << 3) |
1492 ((edid
->mfg_id
[1] & 0xe0) >> 5)) + '@';
1493 edid_vendor
[2] = (edid
->mfg_id
[1] & 0x1f) + '@';
1495 return !strncmp(edid_vendor
, vendor
, 3);
1499 * edid_get_quirks - return quirk flags for a given EDID
1500 * @edid: EDID to process
1502 * This tells subsequent routines what fixes they need to apply.
1504 static u32
edid_get_quirks(struct edid
*edid
)
1506 const struct edid_quirk
*quirk
;
1509 for (i
= 0; i
< ARRAY_SIZE(edid_quirk_list
); i
++) {
1510 quirk
= &edid_quirk_list
[i
];
1512 if (edid_vendor(edid
, quirk
->vendor
) &&
1513 (EDID_PRODUCT_ID(edid
) == quirk
->product_id
))
1514 return quirk
->quirks
;
1520 #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
1521 #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
1524 * edid_fixup_preferred - set preferred modes based on quirk list
1525 * @connector: has mode list to fix up
1526 * @quirks: quirks list
1528 * Walk the mode list for @connector, clearing the preferred status
1529 * on existing modes and setting it anew for the right mode ala @quirks.
1531 static void edid_fixup_preferred(struct drm_connector
*connector
,
1534 struct drm_display_mode
*t
, *cur_mode
, *preferred_mode
;
1535 int target_refresh
= 0;
1536 int cur_vrefresh
, preferred_vrefresh
;
1538 if (list_empty(&connector
->probed_modes
))
1541 if (quirks
& EDID_QUIRK_PREFER_LARGE_60
)
1542 target_refresh
= 60;
1543 if (quirks
& EDID_QUIRK_PREFER_LARGE_75
)
1544 target_refresh
= 75;
1546 preferred_mode
= list_first_entry(&connector
->probed_modes
,
1547 struct drm_display_mode
, head
);
1549 list_for_each_entry_safe(cur_mode
, t
, &connector
->probed_modes
, head
) {
1550 cur_mode
->type
&= ~DRM_MODE_TYPE_PREFERRED
;
1552 if (cur_mode
== preferred_mode
)
1555 /* Largest mode is preferred */
1556 if (MODE_SIZE(cur_mode
) > MODE_SIZE(preferred_mode
))
1557 preferred_mode
= cur_mode
;
1559 cur_vrefresh
= cur_mode
->vrefresh
?
1560 cur_mode
->vrefresh
: drm_mode_vrefresh(cur_mode
);
1561 preferred_vrefresh
= preferred_mode
->vrefresh
?
1562 preferred_mode
->vrefresh
: drm_mode_vrefresh(preferred_mode
);
1563 /* At a given size, try to get closest to target refresh */
1564 if ((MODE_SIZE(cur_mode
) == MODE_SIZE(preferred_mode
)) &&
1565 MODE_REFRESH_DIFF(cur_vrefresh
, target_refresh
) <
1566 MODE_REFRESH_DIFF(preferred_vrefresh
, target_refresh
)) {
1567 preferred_mode
= cur_mode
;
1571 preferred_mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
1575 mode_is_rb(const struct drm_display_mode
*mode
)
1577 return (mode
->htotal
- mode
->hdisplay
== 160) &&
1578 (mode
->hsync_end
- mode
->hdisplay
== 80) &&
1579 (mode
->hsync_end
- mode
->hsync_start
== 32) &&
1580 (mode
->vsync_start
- mode
->vdisplay
== 3);
1584 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1585 * @dev: Device to duplicate against
1586 * @hsize: Mode width
1587 * @vsize: Mode height
1588 * @fresh: Mode refresh rate
1589 * @rb: Mode reduced-blanking-ness
1591 * Walk the DMT mode list looking for a match for the given parameters.
1593 * Return: A newly allocated copy of the mode, or NULL if not found.
1595 struct drm_display_mode
*drm_mode_find_dmt(struct drm_device
*dev
,
1596 int hsize
, int vsize
, int fresh
,
1601 for (i
= 0; i
< ARRAY_SIZE(drm_dmt_modes
); i
++) {
1602 const struct drm_display_mode
*ptr
= &drm_dmt_modes
[i
];
1603 if (hsize
!= ptr
->hdisplay
)
1605 if (vsize
!= ptr
->vdisplay
)
1607 if (fresh
!= drm_mode_vrefresh(ptr
))
1609 if (rb
!= mode_is_rb(ptr
))
1612 return drm_mode_duplicate(dev
, ptr
);
1617 EXPORT_SYMBOL(drm_mode_find_dmt
);
1619 typedef void detailed_cb(struct detailed_timing
*timing
, void *closure
);
1622 cea_for_each_detailed_block(u8
*ext
, detailed_cb
*cb
, void *closure
)
1626 u8
*det_base
= ext
+ d
;
1629 for (i
= 0; i
< n
; i
++)
1630 cb((struct detailed_timing
*)(det_base
+ 18 * i
), closure
);
1634 vtb_for_each_detailed_block(u8
*ext
, detailed_cb
*cb
, void *closure
)
1636 unsigned int i
, n
= min((int)ext
[0x02], 6);
1637 u8
*det_base
= ext
+ 5;
1640 return; /* unknown version */
1642 for (i
= 0; i
< n
; i
++)
1643 cb((struct detailed_timing
*)(det_base
+ 18 * i
), closure
);
1647 drm_for_each_detailed_block(u8
*raw_edid
, detailed_cb
*cb
, void *closure
)
1650 struct edid
*edid
= (struct edid
*)raw_edid
;
1655 for (i
= 0; i
< EDID_DETAILED_TIMINGS
; i
++)
1656 cb(&(edid
->detailed_timings
[i
]), closure
);
1658 for (i
= 1; i
<= raw_edid
[0x7e]; i
++) {
1659 u8
*ext
= raw_edid
+ (i
* EDID_LENGTH
);
1662 cea_for_each_detailed_block(ext
, cb
, closure
);
1665 vtb_for_each_detailed_block(ext
, cb
, closure
);
1674 is_rb(struct detailed_timing
*t
, void *data
)
1677 if (r
[3] == EDID_DETAIL_MONITOR_RANGE
)
1679 *(bool *)data
= true;
1682 /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1684 drm_monitor_supports_rb(struct edid
*edid
)
1686 if (edid
->revision
>= 4) {
1688 drm_for_each_detailed_block((u8
*)edid
, is_rb
, &ret
);
1692 return ((edid
->input
& DRM_EDID_INPUT_DIGITAL
) != 0);
1696 find_gtf2(struct detailed_timing
*t
, void *data
)
1699 if (r
[3] == EDID_DETAIL_MONITOR_RANGE
&& r
[10] == 0x02)
1703 /* Secondary GTF curve kicks in above some break frequency */
1705 drm_gtf2_hbreak(struct edid
*edid
)
1708 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1709 return r
? (r
[12] * 2) : 0;
1713 drm_gtf2_2c(struct edid
*edid
)
1716 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1717 return r
? r
[13] : 0;
1721 drm_gtf2_m(struct edid
*edid
)
1724 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1725 return r
? (r
[15] << 8) + r
[14] : 0;
1729 drm_gtf2_k(struct edid
*edid
)
1732 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1733 return r
? r
[16] : 0;
1737 drm_gtf2_2j(struct edid
*edid
)
1740 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1741 return r
? r
[17] : 0;
1745 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1746 * @edid: EDID block to scan
1748 static int standard_timing_level(struct edid
*edid
)
1750 if (edid
->revision
>= 2) {
1751 if (edid
->revision
>= 4 && (edid
->features
& DRM_EDID_FEATURE_DEFAULT_GTF
))
1753 if (drm_gtf2_hbreak(edid
))
1761 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1762 * monitors fill with ascii space (0x20) instead.
1765 bad_std_timing(u8 a
, u8 b
)
1767 return (a
== 0x00 && b
== 0x00) ||
1768 (a
== 0x01 && b
== 0x01) ||
1769 (a
== 0x20 && b
== 0x20);
1773 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
1774 * @connector: connector of for the EDID block
1775 * @edid: EDID block to scan
1776 * @t: standard timing params
1778 * Take the standard timing params (in this case width, aspect, and refresh)
1779 * and convert them into a real mode using CVT/GTF/DMT.
1781 static struct drm_display_mode
*
1782 drm_mode_std(struct drm_connector
*connector
, struct edid
*edid
,
1783 struct std_timing
*t
)
1785 struct drm_device
*dev
= connector
->dev
;
1786 struct drm_display_mode
*m
, *mode
= NULL
;
1789 unsigned aspect_ratio
= (t
->vfreq_aspect
& EDID_TIMING_ASPECT_MASK
)
1790 >> EDID_TIMING_ASPECT_SHIFT
;
1791 unsigned vfreq
= (t
->vfreq_aspect
& EDID_TIMING_VFREQ_MASK
)
1792 >> EDID_TIMING_VFREQ_SHIFT
;
1793 int timing_level
= standard_timing_level(edid
);
1795 if (bad_std_timing(t
->hsize
, t
->vfreq_aspect
))
1798 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1799 hsize
= t
->hsize
* 8 + 248;
1800 /* vrefresh_rate = vfreq + 60 */
1801 vrefresh_rate
= vfreq
+ 60;
1802 /* the vdisplay is calculated based on the aspect ratio */
1803 if (aspect_ratio
== 0) {
1804 if (edid
->revision
< 3)
1807 vsize
= (hsize
* 10) / 16;
1808 } else if (aspect_ratio
== 1)
1809 vsize
= (hsize
* 3) / 4;
1810 else if (aspect_ratio
== 2)
1811 vsize
= (hsize
* 4) / 5;
1813 vsize
= (hsize
* 9) / 16;
1815 /* HDTV hack, part 1 */
1816 if (vrefresh_rate
== 60 &&
1817 ((hsize
== 1360 && vsize
== 765) ||
1818 (hsize
== 1368 && vsize
== 769))) {
1824 * If this connector already has a mode for this size and refresh
1825 * rate (because it came from detailed or CVT info), use that
1826 * instead. This way we don't have to guess at interlace or
1829 list_for_each_entry(m
, &connector
->probed_modes
, head
)
1830 if (m
->hdisplay
== hsize
&& m
->vdisplay
== vsize
&&
1831 drm_mode_vrefresh(m
) == vrefresh_rate
)
1834 /* HDTV hack, part 2 */
1835 if (hsize
== 1366 && vsize
== 768 && vrefresh_rate
== 60) {
1836 mode
= drm_cvt_mode(dev
, 1366, 768, vrefresh_rate
, 0, 0,
1838 mode
->hdisplay
= 1366;
1839 mode
->hsync_start
= mode
->hsync_start
- 1;
1840 mode
->hsync_end
= mode
->hsync_end
- 1;
1844 /* check whether it can be found in default mode table */
1845 if (drm_monitor_supports_rb(edid
)) {
1846 mode
= drm_mode_find_dmt(dev
, hsize
, vsize
, vrefresh_rate
,
1851 mode
= drm_mode_find_dmt(dev
, hsize
, vsize
, vrefresh_rate
, false);
1855 /* okay, generate it */
1856 switch (timing_level
) {
1860 mode
= drm_gtf_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0);
1864 * This is potentially wrong if there's ever a monitor with
1865 * more than one ranges section, each claiming a different
1866 * secondary GTF curve. Please don't do that.
1868 mode
= drm_gtf_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0);
1871 if (drm_mode_hsync(mode
) > drm_gtf2_hbreak(edid
)) {
1872 drm_mode_destroy(dev
, mode
);
1873 mode
= drm_gtf_mode_complex(dev
, hsize
, vsize
,
1874 vrefresh_rate
, 0, 0,
1882 mode
= drm_cvt_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0,
1890 * EDID is delightfully ambiguous about how interlaced modes are to be
1891 * encoded. Our internal representation is of frame height, but some
1892 * HDTV detailed timings are encoded as field height.
1894 * The format list here is from CEA, in frame size. Technically we
1895 * should be checking refresh rate too. Whatever.
1898 drm_mode_do_interlace_quirk(struct drm_display_mode
*mode
,
1899 struct detailed_pixel_timing
*pt
)
1902 static const struct {
1904 } cea_interlaced
[] = {
1914 if (!(pt
->misc
& DRM_EDID_PT_INTERLACED
))
1917 for (i
= 0; i
< ARRAY_SIZE(cea_interlaced
); i
++) {
1918 if ((mode
->hdisplay
== cea_interlaced
[i
].w
) &&
1919 (mode
->vdisplay
== cea_interlaced
[i
].h
/ 2)) {
1920 mode
->vdisplay
*= 2;
1921 mode
->vsync_start
*= 2;
1922 mode
->vsync_end
*= 2;
1928 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1932 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1933 * @dev: DRM device (needed to create new mode)
1935 * @timing: EDID detailed timing info
1936 * @quirks: quirks to apply
1938 * An EDID detailed timing block contains enough info for us to create and
1939 * return a new struct drm_display_mode.
1941 static struct drm_display_mode
*drm_mode_detailed(struct drm_device
*dev
,
1943 struct detailed_timing
*timing
,
1946 struct drm_display_mode
*mode
;
1947 struct detailed_pixel_timing
*pt
= &timing
->data
.pixel_data
;
1948 unsigned hactive
= (pt
->hactive_hblank_hi
& 0xf0) << 4 | pt
->hactive_lo
;
1949 unsigned vactive
= (pt
->vactive_vblank_hi
& 0xf0) << 4 | pt
->vactive_lo
;
1950 unsigned hblank
= (pt
->hactive_hblank_hi
& 0xf) << 8 | pt
->hblank_lo
;
1951 unsigned vblank
= (pt
->vactive_vblank_hi
& 0xf) << 8 | pt
->vblank_lo
;
1952 unsigned hsync_offset
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0xc0) << 2 | pt
->hsync_offset_lo
;
1953 unsigned hsync_pulse_width
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0x30) << 4 | pt
->hsync_pulse_width_lo
;
1954 unsigned vsync_offset
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0xc) << 2 | pt
->vsync_offset_pulse_width_lo
>> 4;
1955 unsigned vsync_pulse_width
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0x3) << 4 | (pt
->vsync_offset_pulse_width_lo
& 0xf);
1957 /* ignore tiny modes */
1958 if (hactive
< 64 || vactive
< 64)
1961 if (pt
->misc
& DRM_EDID_PT_STEREO
) {
1962 DRM_DEBUG_KMS("stereo mode not supported\n");
1965 if (!(pt
->misc
& DRM_EDID_PT_SEPARATE_SYNC
)) {
1966 DRM_DEBUG_KMS("composite sync not supported\n");
1969 /* it is incorrect if hsync/vsync width is zero */
1970 if (!hsync_pulse_width
|| !vsync_pulse_width
) {
1971 DRM_DEBUG_KMS("Incorrect Detailed timing. "
1972 "Wrong Hsync/Vsync pulse width\n");
1976 if (quirks
& EDID_QUIRK_FORCE_REDUCED_BLANKING
) {
1977 mode
= drm_cvt_mode(dev
, hactive
, vactive
, 60, true, false, false);
1984 mode
= drm_mode_create(dev
);
1988 if (quirks
& EDID_QUIRK_135_CLOCK_TOO_HIGH
)
1989 timing
->pixel_clock
= cpu_to_le16(1088);
1991 mode
->clock
= le16_to_cpu(timing
->pixel_clock
) * 10;
1993 mode
->hdisplay
= hactive
;
1994 mode
->hsync_start
= mode
->hdisplay
+ hsync_offset
;
1995 mode
->hsync_end
= mode
->hsync_start
+ hsync_pulse_width
;
1996 mode
->htotal
= mode
->hdisplay
+ hblank
;
1998 mode
->vdisplay
= vactive
;
1999 mode
->vsync_start
= mode
->vdisplay
+ vsync_offset
;
2000 mode
->vsync_end
= mode
->vsync_start
+ vsync_pulse_width
;
2001 mode
->vtotal
= mode
->vdisplay
+ vblank
;
2003 /* Some EDIDs have bogus h/vtotal values */
2004 if (mode
->hsync_end
> mode
->htotal
)
2005 mode
->htotal
= mode
->hsync_end
+ 1;
2006 if (mode
->vsync_end
> mode
->vtotal
)
2007 mode
->vtotal
= mode
->vsync_end
+ 1;
2009 drm_mode_do_interlace_quirk(mode
, pt
);
2011 if (quirks
& EDID_QUIRK_DETAILED_SYNC_PP
) {
2012 pt
->misc
|= DRM_EDID_PT_HSYNC_POSITIVE
| DRM_EDID_PT_VSYNC_POSITIVE
;
2015 mode
->flags
|= (pt
->misc
& DRM_EDID_PT_HSYNC_POSITIVE
) ?
2016 DRM_MODE_FLAG_PHSYNC
: DRM_MODE_FLAG_NHSYNC
;
2017 mode
->flags
|= (pt
->misc
& DRM_EDID_PT_VSYNC_POSITIVE
) ?
2018 DRM_MODE_FLAG_PVSYNC
: DRM_MODE_FLAG_NVSYNC
;
2021 mode
->width_mm
= pt
->width_mm_lo
| (pt
->width_height_mm_hi
& 0xf0) << 4;
2022 mode
->height_mm
= pt
->height_mm_lo
| (pt
->width_height_mm_hi
& 0xf) << 8;
2024 if (quirks
& EDID_QUIRK_DETAILED_IN_CM
) {
2025 mode
->width_mm
*= 10;
2026 mode
->height_mm
*= 10;
2029 if (quirks
& EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
) {
2030 mode
->width_mm
= edid
->width_cm
* 10;
2031 mode
->height_mm
= edid
->height_cm
* 10;
2034 mode
->type
= DRM_MODE_TYPE_DRIVER
;
2035 mode
->vrefresh
= drm_mode_vrefresh(mode
);
2036 drm_mode_set_name(mode
);
2042 mode_in_hsync_range(const struct drm_display_mode
*mode
,
2043 struct edid
*edid
, u8
*t
)
2045 int hsync
, hmin
, hmax
;
2048 if (edid
->revision
>= 4)
2049 hmin
+= ((t
[4] & 0x04) ? 255 : 0);
2051 if (edid
->revision
>= 4)
2052 hmax
+= ((t
[4] & 0x08) ? 255 : 0);
2053 hsync
= drm_mode_hsync(mode
);
2055 return (hsync
<= hmax
&& hsync
>= hmin
);
2059 mode_in_vsync_range(const struct drm_display_mode
*mode
,
2060 struct edid
*edid
, u8
*t
)
2062 int vsync
, vmin
, vmax
;
2065 if (edid
->revision
>= 4)
2066 vmin
+= ((t
[4] & 0x01) ? 255 : 0);
2068 if (edid
->revision
>= 4)
2069 vmax
+= ((t
[4] & 0x02) ? 255 : 0);
2070 vsync
= drm_mode_vrefresh(mode
);
2072 return (vsync
<= vmax
&& vsync
>= vmin
);
2076 range_pixel_clock(struct edid
*edid
, u8
*t
)
2079 if (t
[9] == 0 || t
[9] == 255)
2082 /* 1.4 with CVT support gives us real precision, yay */
2083 if (edid
->revision
>= 4 && t
[10] == 0x04)
2084 return (t
[9] * 10000) - ((t
[12] >> 2) * 250);
2086 /* 1.3 is pathetic, so fuzz up a bit */
2087 return t
[9] * 10000 + 5001;
2091 mode_in_range(const struct drm_display_mode
*mode
, struct edid
*edid
,
2092 struct detailed_timing
*timing
)
2095 u8
*t
= (u8
*)timing
;
2097 if (!mode_in_hsync_range(mode
, edid
, t
))
2100 if (!mode_in_vsync_range(mode
, edid
, t
))
2103 if ((max_clock
= range_pixel_clock(edid
, t
)))
2104 if (mode
->clock
> max_clock
)
2107 /* 1.4 max horizontal check */
2108 if (edid
->revision
>= 4 && t
[10] == 0x04)
2109 if (t
[13] && mode
->hdisplay
> 8 * (t
[13] + (256 * (t
[12]&0x3))))
2112 if (mode_is_rb(mode
) && !drm_monitor_supports_rb(edid
))
2118 static bool valid_inferred_mode(const struct drm_connector
*connector
,
2119 const struct drm_display_mode
*mode
)
2121 const struct drm_display_mode
*m
;
2124 list_for_each_entry(m
, &connector
->probed_modes
, head
) {
2125 if (mode
->hdisplay
== m
->hdisplay
&&
2126 mode
->vdisplay
== m
->vdisplay
&&
2127 drm_mode_vrefresh(mode
) == drm_mode_vrefresh(m
))
2128 return false; /* duplicated */
2129 if (mode
->hdisplay
<= m
->hdisplay
&&
2130 mode
->vdisplay
<= m
->vdisplay
)
2137 drm_dmt_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2138 struct detailed_timing
*timing
)
2141 struct drm_display_mode
*newmode
;
2142 struct drm_device
*dev
= connector
->dev
;
2144 for (i
= 0; i
< ARRAY_SIZE(drm_dmt_modes
); i
++) {
2145 if (mode_in_range(drm_dmt_modes
+ i
, edid
, timing
) &&
2146 valid_inferred_mode(connector
, drm_dmt_modes
+ i
)) {
2147 newmode
= drm_mode_duplicate(dev
, &drm_dmt_modes
[i
]);
2149 drm_mode_probed_add(connector
, newmode
);
2158 /* fix up 1366x768 mode from 1368x768;
2159 * GFT/CVT can't express 1366 width which isn't dividable by 8
2161 void drm_mode_fixup_1366x768(struct drm_display_mode
*mode
)
2163 if (mode
->hdisplay
== 1368 && mode
->vdisplay
== 768) {
2164 mode
->hdisplay
= 1366;
2165 mode
->hsync_start
--;
2167 drm_mode_set_name(mode
);
2172 drm_gtf_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2173 struct detailed_timing
*timing
)
2176 struct drm_display_mode
*newmode
;
2177 struct drm_device
*dev
= connector
->dev
;
2179 for (i
= 0; i
< ARRAY_SIZE(extra_modes
); i
++) {
2180 const struct minimode
*m
= &extra_modes
[i
];
2181 newmode
= drm_gtf_mode(dev
, m
->w
, m
->h
, m
->r
, 0, 0);
2185 drm_mode_fixup_1366x768(newmode
);
2186 if (!mode_in_range(newmode
, edid
, timing
) ||
2187 !valid_inferred_mode(connector
, newmode
)) {
2188 drm_mode_destroy(dev
, newmode
);
2192 drm_mode_probed_add(connector
, newmode
);
2200 drm_cvt_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2201 struct detailed_timing
*timing
)
2204 struct drm_display_mode
*newmode
;
2205 struct drm_device
*dev
= connector
->dev
;
2206 bool rb
= drm_monitor_supports_rb(edid
);
2208 for (i
= 0; i
< ARRAY_SIZE(extra_modes
); i
++) {
2209 const struct minimode
*m
= &extra_modes
[i
];
2210 newmode
= drm_cvt_mode(dev
, m
->w
, m
->h
, m
->r
, rb
, 0, 0);
2214 drm_mode_fixup_1366x768(newmode
);
2215 if (!mode_in_range(newmode
, edid
, timing
) ||
2216 !valid_inferred_mode(connector
, newmode
)) {
2217 drm_mode_destroy(dev
, newmode
);
2221 drm_mode_probed_add(connector
, newmode
);
2229 do_inferred_modes(struct detailed_timing
*timing
, void *c
)
2231 struct detailed_mode_closure
*closure
= c
;
2232 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2233 struct detailed_data_monitor_range
*range
= &data
->data
.range
;
2235 if (data
->type
!= EDID_DETAIL_MONITOR_RANGE
)
2238 closure
->modes
+= drm_dmt_modes_for_range(closure
->connector
,
2242 if (!version_greater(closure
->edid
, 1, 1))
2243 return; /* GTF not defined yet */
2245 switch (range
->flags
) {
2246 case 0x02: /* secondary gtf, XXX could do more */
2247 case 0x00: /* default gtf */
2248 closure
->modes
+= drm_gtf_modes_for_range(closure
->connector
,
2252 case 0x04: /* cvt, only in 1.4+ */
2253 if (!version_greater(closure
->edid
, 1, 3))
2256 closure
->modes
+= drm_cvt_modes_for_range(closure
->connector
,
2260 case 0x01: /* just the ranges, no formula */
2267 add_inferred_modes(struct drm_connector
*connector
, struct edid
*edid
)
2269 struct detailed_mode_closure closure
= {
2270 .connector
= connector
,
2274 if (version_greater(edid
, 1, 0))
2275 drm_for_each_detailed_block((u8
*)edid
, do_inferred_modes
,
2278 return closure
.modes
;
2282 drm_est3_modes(struct drm_connector
*connector
, struct detailed_timing
*timing
)
2284 int i
, j
, m
, modes
= 0;
2285 struct drm_display_mode
*mode
;
2286 u8
*est
= ((u8
*)timing
) + 6;
2288 for (i
= 0; i
< 6; i
++) {
2289 for (j
= 7; j
>= 0; j
--) {
2290 m
= (i
* 8) + (7 - j
);
2291 if (m
>= ARRAY_SIZE(est3_modes
))
2293 if (est
[i
] & (1 << j
)) {
2294 mode
= drm_mode_find_dmt(connector
->dev
,
2300 drm_mode_probed_add(connector
, mode
);
2311 do_established_modes(struct detailed_timing
*timing
, void *c
)
2313 struct detailed_mode_closure
*closure
= c
;
2314 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2316 if (data
->type
== EDID_DETAIL_EST_TIMINGS
)
2317 closure
->modes
+= drm_est3_modes(closure
->connector
, timing
);
2321 * add_established_modes - get est. modes from EDID and add them
2322 * @connector: connector to add mode(s) to
2323 * @edid: EDID block to scan
2325 * Each EDID block contains a bitmap of the supported "established modes" list
2326 * (defined above). Tease them out and add them to the global modes list.
2329 add_established_modes(struct drm_connector
*connector
, struct edid
*edid
)
2331 struct drm_device
*dev
= connector
->dev
;
2332 unsigned long est_bits
= edid
->established_timings
.t1
|
2333 (edid
->established_timings
.t2
<< 8) |
2334 ((edid
->established_timings
.mfg_rsvd
& 0x80) << 9);
2336 struct detailed_mode_closure closure
= {
2337 .connector
= connector
,
2341 for (i
= 0; i
<= EDID_EST_TIMINGS
; i
++) {
2342 if (est_bits
& (1<<i
)) {
2343 struct drm_display_mode
*newmode
;
2344 newmode
= drm_mode_duplicate(dev
, &edid_est_modes
[i
]);
2346 drm_mode_probed_add(connector
, newmode
);
2352 if (version_greater(edid
, 1, 0))
2353 drm_for_each_detailed_block((u8
*)edid
,
2354 do_established_modes
, &closure
);
2356 return modes
+ closure
.modes
;
2360 do_standard_modes(struct detailed_timing
*timing
, void *c
)
2362 struct detailed_mode_closure
*closure
= c
;
2363 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2364 struct drm_connector
*connector
= closure
->connector
;
2365 struct edid
*edid
= closure
->edid
;
2367 if (data
->type
== EDID_DETAIL_STD_MODES
) {
2369 for (i
= 0; i
< 6; i
++) {
2370 struct std_timing
*std
;
2371 struct drm_display_mode
*newmode
;
2373 std
= &data
->data
.timings
[i
];
2374 newmode
= drm_mode_std(connector
, edid
, std
);
2376 drm_mode_probed_add(connector
, newmode
);
2384 * add_standard_modes - get std. modes from EDID and add them
2385 * @connector: connector to add mode(s) to
2386 * @edid: EDID block to scan
2388 * Standard modes can be calculated using the appropriate standard (DMT,
2389 * GTF or CVT. Grab them from @edid and add them to the list.
2392 add_standard_modes(struct drm_connector
*connector
, struct edid
*edid
)
2395 struct detailed_mode_closure closure
= {
2396 .connector
= connector
,
2400 for (i
= 0; i
< EDID_STD_TIMINGS
; i
++) {
2401 struct drm_display_mode
*newmode
;
2403 newmode
= drm_mode_std(connector
, edid
,
2404 &edid
->standard_timings
[i
]);
2406 drm_mode_probed_add(connector
, newmode
);
2411 if (version_greater(edid
, 1, 0))
2412 drm_for_each_detailed_block((u8
*)edid
, do_standard_modes
,
2415 /* XXX should also look for standard codes in VTB blocks */
2417 return modes
+ closure
.modes
;
2420 static int drm_cvt_modes(struct drm_connector
*connector
,
2421 struct detailed_timing
*timing
)
2423 int i
, j
, modes
= 0;
2424 struct drm_display_mode
*newmode
;
2425 struct drm_device
*dev
= connector
->dev
;
2426 struct cvt_timing
*cvt
;
2427 const int rates
[] = { 60, 85, 75, 60, 50 };
2428 const u8 empty
[3] = { 0, 0, 0 };
2430 for (i
= 0; i
< 4; i
++) {
2431 int uninitialized_var(width
), height
;
2432 cvt
= &(timing
->data
.other_data
.data
.cvt
[i
]);
2434 if (!memcmp(cvt
->code
, empty
, 3))
2437 height
= (cvt
->code
[0] + ((cvt
->code
[1] & 0xf0) << 4) + 1) * 2;
2438 switch (cvt
->code
[1] & 0x0c) {
2440 width
= height
* 4 / 3;
2443 width
= height
* 16 / 9;
2446 width
= height
* 16 / 10;
2449 width
= height
* 15 / 9;
2453 for (j
= 1; j
< 5; j
++) {
2454 if (cvt
->code
[2] & (1 << j
)) {
2455 newmode
= drm_cvt_mode(dev
, width
, height
,
2459 drm_mode_probed_add(connector
, newmode
);
2470 do_cvt_mode(struct detailed_timing
*timing
, void *c
)
2472 struct detailed_mode_closure
*closure
= c
;
2473 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2475 if (data
->type
== EDID_DETAIL_CVT_3BYTE
)
2476 closure
->modes
+= drm_cvt_modes(closure
->connector
, timing
);
2480 add_cvt_modes(struct drm_connector
*connector
, struct edid
*edid
)
2482 struct detailed_mode_closure closure
= {
2483 .connector
= connector
,
2487 if (version_greater(edid
, 1, 2))
2488 drm_for_each_detailed_block((u8
*)edid
, do_cvt_mode
, &closure
);
2490 /* XXX should also look for CVT codes in VTB blocks */
2492 return closure
.modes
;
2495 static void fixup_detailed_cea_mode_clock(struct drm_display_mode
*mode
);
2498 do_detailed_mode(struct detailed_timing
*timing
, void *c
)
2500 struct detailed_mode_closure
*closure
= c
;
2501 struct drm_display_mode
*newmode
;
2503 if (timing
->pixel_clock
) {
2504 newmode
= drm_mode_detailed(closure
->connector
->dev
,
2505 closure
->edid
, timing
,
2510 if (closure
->preferred
)
2511 newmode
->type
|= DRM_MODE_TYPE_PREFERRED
;
2514 * Detailed modes are limited to 10kHz pixel clock resolution,
2515 * so fix up anything that looks like CEA/HDMI mode, but the clock
2516 * is just slightly off.
2518 fixup_detailed_cea_mode_clock(newmode
);
2520 drm_mode_probed_add(closure
->connector
, newmode
);
2522 closure
->preferred
= 0;
2527 * add_detailed_modes - Add modes from detailed timings
2528 * @connector: attached connector
2529 * @edid: EDID block to scan
2530 * @quirks: quirks to apply
2533 add_detailed_modes(struct drm_connector
*connector
, struct edid
*edid
,
2536 struct detailed_mode_closure closure
= {
2537 .connector
= connector
,
2543 if (closure
.preferred
&& !version_greater(edid
, 1, 3))
2545 (edid
->features
& DRM_EDID_FEATURE_PREFERRED_TIMING
);
2547 drm_for_each_detailed_block((u8
*)edid
, do_detailed_mode
, &closure
);
2549 return closure
.modes
;
2552 #define AUDIO_BLOCK 0x01
2553 #define VIDEO_BLOCK 0x02
2554 #define VENDOR_BLOCK 0x03
2555 #define SPEAKER_BLOCK 0x04
2556 #define VIDEO_CAPABILITY_BLOCK 0x07
2557 #define EDID_BASIC_AUDIO (1 << 6)
2558 #define EDID_CEA_YCRCB444 (1 << 5)
2559 #define EDID_CEA_YCRCB422 (1 << 4)
2560 #define EDID_CEA_VCDB_QS (1 << 6)
2563 * Search EDID for CEA extension block.
2565 static u8
*drm_find_edid_extension(struct edid
*edid
, int ext_id
)
2567 u8
*edid_ext
= NULL
;
2570 /* No EDID or EDID extensions */
2571 if (edid
== NULL
|| edid
->extensions
== 0)
2574 /* Find CEA extension */
2575 for (i
= 0; i
< edid
->extensions
; i
++) {
2576 edid_ext
= (u8
*)edid
+ EDID_LENGTH
* (i
+ 1);
2577 if (edid_ext
[0] == ext_id
)
2581 if (i
== edid
->extensions
)
2587 static u8
*drm_find_cea_extension(struct edid
*edid
)
2589 return drm_find_edid_extension(edid
, CEA_EXT
);
2592 static u8
*drm_find_displayid_extension(struct edid
*edid
)
2594 return drm_find_edid_extension(edid
, DISPLAYID_EXT
);
2598 * Calculate the alternate clock for the CEA mode
2599 * (60Hz vs. 59.94Hz etc.)
2602 cea_mode_alternate_clock(const struct drm_display_mode
*cea_mode
)
2604 unsigned int clock
= cea_mode
->clock
;
2606 if (cea_mode
->vrefresh
% 6 != 0)
2610 * edid_cea_modes contains the 59.94Hz
2611 * variant for 240 and 480 line modes,
2612 * and the 60Hz variant otherwise.
2614 if (cea_mode
->vdisplay
== 240 || cea_mode
->vdisplay
== 480)
2615 clock
= DIV_ROUND_CLOSEST(clock
* 1001, 1000);
2617 clock
= DIV_ROUND_CLOSEST(clock
* 1000, 1001);
2623 cea_mode_alternate_timings(u8 vic
, struct drm_display_mode
*mode
)
2626 * For certain VICs the spec allows the vertical
2627 * front porch to vary by one or two lines.
2629 * cea_modes[] stores the variant with the shortest
2630 * vertical front porch. We can adjust the mode to
2631 * get the other variants by simply increasing the
2632 * vertical front porch length.
2634 BUILD_BUG_ON(edid_cea_modes
[8].vtotal
!= 262 ||
2635 edid_cea_modes
[9].vtotal
!= 262 ||
2636 edid_cea_modes
[12].vtotal
!= 262 ||
2637 edid_cea_modes
[13].vtotal
!= 262 ||
2638 edid_cea_modes
[23].vtotal
!= 312 ||
2639 edid_cea_modes
[24].vtotal
!= 312 ||
2640 edid_cea_modes
[27].vtotal
!= 312 ||
2641 edid_cea_modes
[28].vtotal
!= 312);
2643 if (((vic
== 8 || vic
== 9 ||
2644 vic
== 12 || vic
== 13) && mode
->vtotal
< 263) ||
2645 ((vic
== 23 || vic
== 24 ||
2646 vic
== 27 || vic
== 28) && mode
->vtotal
< 314)) {
2647 mode
->vsync_start
++;
2657 static u8
drm_match_cea_mode_clock_tolerance(const struct drm_display_mode
*to_match
,
2658 unsigned int clock_tolerance
)
2662 if (!to_match
->clock
)
2665 for (vic
= 1; vic
< ARRAY_SIZE(edid_cea_modes
); vic
++) {
2666 struct drm_display_mode cea_mode
= edid_cea_modes
[vic
];
2667 unsigned int clock1
, clock2
;
2669 /* Check both 60Hz and 59.94Hz */
2670 clock1
= cea_mode
.clock
;
2671 clock2
= cea_mode_alternate_clock(&cea_mode
);
2673 if (abs(to_match
->clock
- clock1
) > clock_tolerance
&&
2674 abs(to_match
->clock
- clock2
) > clock_tolerance
)
2678 if (drm_mode_equal_no_clocks_no_stereo(to_match
, &cea_mode
))
2680 } while (cea_mode_alternate_timings(vic
, &cea_mode
));
2687 * drm_match_cea_mode - look for a CEA mode matching given mode
2688 * @to_match: display mode
2690 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
2693 u8
drm_match_cea_mode(const struct drm_display_mode
*to_match
)
2697 if (!to_match
->clock
)
2700 for (vic
= 1; vic
< ARRAY_SIZE(edid_cea_modes
); vic
++) {
2701 struct drm_display_mode cea_mode
= edid_cea_modes
[vic
];
2702 unsigned int clock1
, clock2
;
2704 /* Check both 60Hz and 59.94Hz */
2705 clock1
= cea_mode
.clock
;
2706 clock2
= cea_mode_alternate_clock(&cea_mode
);
2708 if (KHZ2PICOS(to_match
->clock
) != KHZ2PICOS(clock1
) &&
2709 KHZ2PICOS(to_match
->clock
) != KHZ2PICOS(clock2
))
2713 if (drm_mode_equal_no_clocks_no_stereo(to_match
, &cea_mode
))
2715 } while (cea_mode_alternate_timings(vic
, &cea_mode
));
2720 EXPORT_SYMBOL(drm_match_cea_mode
);
2722 static bool drm_valid_cea_vic(u8 vic
)
2724 return vic
> 0 && vic
< ARRAY_SIZE(edid_cea_modes
);
2728 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2729 * the input VIC from the CEA mode list
2730 * @video_code: ID given to each of the CEA modes
2732 * Returns picture aspect ratio
2734 enum hdmi_picture_aspect
drm_get_cea_aspect_ratio(const u8 video_code
)
2736 return edid_cea_modes
[video_code
].picture_aspect_ratio
;
2738 EXPORT_SYMBOL(drm_get_cea_aspect_ratio
);
2741 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2744 * It's almost like cea_mode_alternate_clock(), we just need to add an
2745 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2749 hdmi_mode_alternate_clock(const struct drm_display_mode
*hdmi_mode
)
2751 if (hdmi_mode
->vdisplay
== 4096 && hdmi_mode
->hdisplay
== 2160)
2752 return hdmi_mode
->clock
;
2754 return cea_mode_alternate_clock(hdmi_mode
);
2757 static u8
drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode
*to_match
,
2758 unsigned int clock_tolerance
)
2762 if (!to_match
->clock
)
2765 for (vic
= 1; vic
< ARRAY_SIZE(edid_4k_modes
); vic
++) {
2766 const struct drm_display_mode
*hdmi_mode
= &edid_4k_modes
[vic
];
2767 unsigned int clock1
, clock2
;
2769 /* Make sure to also match alternate clocks */
2770 clock1
= hdmi_mode
->clock
;
2771 clock2
= hdmi_mode_alternate_clock(hdmi_mode
);
2773 if (abs(to_match
->clock
- clock1
) > clock_tolerance
&&
2774 abs(to_match
->clock
- clock2
) > clock_tolerance
)
2777 if (drm_mode_equal_no_clocks(to_match
, hdmi_mode
))
2785 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2786 * @to_match: display mode
2788 * An HDMI mode is one defined in the HDMI vendor specific block.
2790 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2792 static u8
drm_match_hdmi_mode(const struct drm_display_mode
*to_match
)
2796 if (!to_match
->clock
)
2799 for (vic
= 1; vic
< ARRAY_SIZE(edid_4k_modes
); vic
++) {
2800 const struct drm_display_mode
*hdmi_mode
= &edid_4k_modes
[vic
];
2801 unsigned int clock1
, clock2
;
2803 /* Make sure to also match alternate clocks */
2804 clock1
= hdmi_mode
->clock
;
2805 clock2
= hdmi_mode_alternate_clock(hdmi_mode
);
2807 if ((KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock1
) ||
2808 KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock2
)) &&
2809 drm_mode_equal_no_clocks_no_stereo(to_match
, hdmi_mode
))
2815 static bool drm_valid_hdmi_vic(u8 vic
)
2817 return vic
> 0 && vic
< ARRAY_SIZE(edid_4k_modes
);
2821 add_alternate_cea_modes(struct drm_connector
*connector
, struct edid
*edid
)
2823 struct drm_device
*dev
= connector
->dev
;
2824 struct drm_display_mode
*mode
, *tmp
;
2828 /* Don't add CEA modes if the CEA extension block is missing */
2829 if (!drm_find_cea_extension(edid
))
2833 * Go through all probed modes and create a new mode
2834 * with the alternate clock for certain CEA modes.
2836 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
2837 const struct drm_display_mode
*cea_mode
= NULL
;
2838 struct drm_display_mode
*newmode
;
2839 u8 vic
= drm_match_cea_mode(mode
);
2840 unsigned int clock1
, clock2
;
2842 if (drm_valid_cea_vic(vic
)) {
2843 cea_mode
= &edid_cea_modes
[vic
];
2844 clock2
= cea_mode_alternate_clock(cea_mode
);
2846 vic
= drm_match_hdmi_mode(mode
);
2847 if (drm_valid_hdmi_vic(vic
)) {
2848 cea_mode
= &edid_4k_modes
[vic
];
2849 clock2
= hdmi_mode_alternate_clock(cea_mode
);
2856 clock1
= cea_mode
->clock
;
2858 if (clock1
== clock2
)
2861 if (mode
->clock
!= clock1
&& mode
->clock
!= clock2
)
2864 newmode
= drm_mode_duplicate(dev
, cea_mode
);
2868 /* Carry over the stereo flags */
2869 newmode
->flags
|= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
2872 * The current mode could be either variant. Make
2873 * sure to pick the "other" clock for the new mode.
2875 if (mode
->clock
!= clock1
)
2876 newmode
->clock
= clock1
;
2878 newmode
->clock
= clock2
;
2880 list_add_tail(&newmode
->head
, &list
);
2883 list_for_each_entry_safe(mode
, tmp
, &list
, head
) {
2884 list_del(&mode
->head
);
2885 drm_mode_probed_add(connector
, mode
);
2892 static struct drm_display_mode
*
2893 drm_display_mode_from_vic_index(struct drm_connector
*connector
,
2894 const u8
*video_db
, u8 video_len
,
2897 struct drm_device
*dev
= connector
->dev
;
2898 struct drm_display_mode
*newmode
;
2901 if (video_db
== NULL
|| video_index
>= video_len
)
2904 /* CEA modes are numbered 1..127 */
2905 vic
= (video_db
[video_index
] & 127);
2906 if (!drm_valid_cea_vic(vic
))
2909 newmode
= drm_mode_duplicate(dev
, &edid_cea_modes
[vic
]);
2913 newmode
->vrefresh
= 0;
2919 do_cea_modes(struct drm_connector
*connector
, const u8
*db
, u8 len
)
2923 for (i
= 0; i
< len
; i
++) {
2924 struct drm_display_mode
*mode
;
2925 mode
= drm_display_mode_from_vic_index(connector
, db
, len
, i
);
2927 drm_mode_probed_add(connector
, mode
);
2935 struct stereo_mandatory_mode
{
2936 int width
, height
, vrefresh
;
2940 static const struct stereo_mandatory_mode stereo_mandatory_modes
[] = {
2941 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2942 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING
},
2944 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
},
2946 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
},
2947 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2948 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING
},
2949 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2950 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING
}
2954 stereo_match_mandatory(const struct drm_display_mode
*mode
,
2955 const struct stereo_mandatory_mode
*stereo_mode
)
2957 unsigned int interlaced
= mode
->flags
& DRM_MODE_FLAG_INTERLACE
;
2959 return mode
->hdisplay
== stereo_mode
->width
&&
2960 mode
->vdisplay
== stereo_mode
->height
&&
2961 interlaced
== (stereo_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) &&
2962 drm_mode_vrefresh(mode
) == stereo_mode
->vrefresh
;
2965 static int add_hdmi_mandatory_stereo_modes(struct drm_connector
*connector
)
2967 struct drm_device
*dev
= connector
->dev
;
2968 const struct drm_display_mode
*mode
;
2969 struct list_head stereo_modes
;
2972 INIT_LIST_HEAD(&stereo_modes
);
2974 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
2975 for (i
= 0; i
< ARRAY_SIZE(stereo_mandatory_modes
); i
++) {
2976 const struct stereo_mandatory_mode
*mandatory
;
2977 struct drm_display_mode
*new_mode
;
2979 if (!stereo_match_mandatory(mode
,
2980 &stereo_mandatory_modes
[i
]))
2983 mandatory
= &stereo_mandatory_modes
[i
];
2984 new_mode
= drm_mode_duplicate(dev
, mode
);
2988 new_mode
->flags
|= mandatory
->flags
;
2989 list_add_tail(&new_mode
->head
, &stereo_modes
);
2994 list_splice_tail(&stereo_modes
, &connector
->probed_modes
);
2999 static int add_hdmi_mode(struct drm_connector
*connector
, u8 vic
)
3001 struct drm_device
*dev
= connector
->dev
;
3002 struct drm_display_mode
*newmode
;
3004 if (!drm_valid_hdmi_vic(vic
)) {
3005 DRM_ERROR("Unknown HDMI VIC: %d\n", vic
);
3009 newmode
= drm_mode_duplicate(dev
, &edid_4k_modes
[vic
]);
3013 drm_mode_probed_add(connector
, newmode
);
3018 static int add_3d_struct_modes(struct drm_connector
*connector
, u16 structure
,
3019 const u8
*video_db
, u8 video_len
, u8 video_index
)
3021 struct drm_display_mode
*newmode
;
3024 if (structure
& (1 << 0)) {
3025 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3029 newmode
->flags
|= DRM_MODE_FLAG_3D_FRAME_PACKING
;
3030 drm_mode_probed_add(connector
, newmode
);
3034 if (structure
& (1 << 6)) {
3035 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3039 newmode
->flags
|= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
;
3040 drm_mode_probed_add(connector
, newmode
);
3044 if (structure
& (1 << 8)) {
3045 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3049 newmode
->flags
|= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
;
3050 drm_mode_probed_add(connector
, newmode
);
3059 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3060 * @connector: connector corresponding to the HDMI sink
3061 * @db: start of the CEA vendor specific block
3062 * @len: length of the CEA block payload, ie. one can access up to db[len]
3064 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3065 * also adds the stereo 3d modes when applicable.
3068 do_hdmi_vsdb_modes(struct drm_connector
*connector
, const u8
*db
, u8 len
,
3069 const u8
*video_db
, u8 video_len
)
3071 int modes
= 0, offset
= 0, i
, multi_present
= 0, multi_len
;
3072 u8 vic_len
, hdmi_3d_len
= 0;
3079 /* no HDMI_Video_Present */
3080 if (!(db
[8] & (1 << 5)))
3083 /* Latency_Fields_Present */
3084 if (db
[8] & (1 << 7))
3087 /* I_Latency_Fields_Present */
3088 if (db
[8] & (1 << 6))
3091 /* the declared length is not long enough for the 2 first bytes
3092 * of additional video format capabilities */
3093 if (len
< (8 + offset
+ 2))
3098 if (db
[8 + offset
] & (1 << 7)) {
3099 modes
+= add_hdmi_mandatory_stereo_modes(connector
);
3101 /* 3D_Multi_present */
3102 multi_present
= (db
[8 + offset
] & 0x60) >> 5;
3106 vic_len
= db
[8 + offset
] >> 5;
3107 hdmi_3d_len
= db
[8 + offset
] & 0x1f;
3109 for (i
= 0; i
< vic_len
&& len
>= (9 + offset
+ i
); i
++) {
3112 vic
= db
[9 + offset
+ i
];
3113 modes
+= add_hdmi_mode(connector
, vic
);
3115 offset
+= 1 + vic_len
;
3117 if (multi_present
== 1)
3119 else if (multi_present
== 2)
3124 if (len
< (8 + offset
+ hdmi_3d_len
- 1))
3127 if (hdmi_3d_len
< multi_len
)
3130 if (multi_present
== 1 || multi_present
== 2) {
3131 /* 3D_Structure_ALL */
3132 structure_all
= (db
[8 + offset
] << 8) | db
[9 + offset
];
3134 /* check if 3D_MASK is present */
3135 if (multi_present
== 2)
3136 mask
= (db
[10 + offset
] << 8) | db
[11 + offset
];
3140 for (i
= 0; i
< 16; i
++) {
3141 if (mask
& (1 << i
))
3142 modes
+= add_3d_struct_modes(connector
,
3149 offset
+= multi_len
;
3151 for (i
= 0; i
< (hdmi_3d_len
- multi_len
); i
++) {
3153 struct drm_display_mode
*newmode
= NULL
;
3154 unsigned int newflag
= 0;
3155 bool detail_present
;
3157 detail_present
= ((db
[8 + offset
+ i
] & 0x0f) > 7);
3159 if (detail_present
&& (i
+ 1 == hdmi_3d_len
- multi_len
))
3162 /* 2D_VIC_order_X */
3163 vic_index
= db
[8 + offset
+ i
] >> 4;
3165 /* 3D_Structure_X */
3166 switch (db
[8 + offset
+ i
] & 0x0f) {
3168 newflag
= DRM_MODE_FLAG_3D_FRAME_PACKING
;
3171 newflag
= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
;
3175 if ((db
[9 + offset
+ i
] >> 4) == 1)
3176 newflag
= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
;
3181 newmode
= drm_display_mode_from_vic_index(connector
,
3187 newmode
->flags
|= newflag
;
3188 drm_mode_probed_add(connector
, newmode
);
3202 cea_db_payload_len(const u8
*db
)
3204 return db
[0] & 0x1f;
3208 cea_db_tag(const u8
*db
)
3214 cea_revision(const u8
*cea
)
3220 cea_db_offsets(const u8
*cea
, int *start
, int *end
)
3222 /* Data block offset in CEA extension block */
3227 if (*end
< 4 || *end
> 127)
3232 static bool cea_db_is_hdmi_vsdb(const u8
*db
)
3236 if (cea_db_tag(db
) != VENDOR_BLOCK
)
3239 if (cea_db_payload_len(db
) < 5)
3242 hdmi_id
= db
[1] | (db
[2] << 8) | (db
[3] << 16);
3244 return hdmi_id
== HDMI_IEEE_OUI
;
3247 #define for_each_cea_db(cea, i, start, end) \
3248 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3251 add_cea_modes(struct drm_connector
*connector
, struct edid
*edid
)
3253 const u8
*cea
= drm_find_cea_extension(edid
);
3254 const u8
*db
, *hdmi
= NULL
, *video
= NULL
;
3255 u8 dbl
, hdmi_len
, video_len
= 0;
3258 if (cea
&& cea_revision(cea
) >= 3) {
3261 if (cea_db_offsets(cea
, &start
, &end
))
3264 for_each_cea_db(cea
, i
, start
, end
) {
3266 dbl
= cea_db_payload_len(db
);
3268 if (cea_db_tag(db
) == VIDEO_BLOCK
) {
3271 modes
+= do_cea_modes(connector
, video
, dbl
);
3273 else if (cea_db_is_hdmi_vsdb(db
)) {
3281 * We parse the HDMI VSDB after having added the cea modes as we will
3282 * be patching their flags when the sink supports stereo 3D.
3285 modes
+= do_hdmi_vsdb_modes(connector
, hdmi
, hdmi_len
, video
,
3291 static void fixup_detailed_cea_mode_clock(struct drm_display_mode
*mode
)
3293 const struct drm_display_mode
*cea_mode
;
3294 int clock1
, clock2
, clock
;
3299 * allow 5kHz clock difference either way to account for
3300 * the 10kHz clock resolution limit of detailed timings.
3302 vic
= drm_match_cea_mode_clock_tolerance(mode
, 5);
3303 if (drm_valid_cea_vic(vic
)) {
3305 cea_mode
= &edid_cea_modes
[vic
];
3306 clock1
= cea_mode
->clock
;
3307 clock2
= cea_mode_alternate_clock(cea_mode
);
3309 vic
= drm_match_hdmi_mode_clock_tolerance(mode
, 5);
3310 if (drm_valid_hdmi_vic(vic
)) {
3312 cea_mode
= &edid_4k_modes
[vic
];
3313 clock1
= cea_mode
->clock
;
3314 clock2
= hdmi_mode_alternate_clock(cea_mode
);
3320 /* pick whichever is closest */
3321 if (abs(mode
->clock
- clock1
) < abs(mode
->clock
- clock2
))
3326 if (mode
->clock
== clock
)
3329 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
3330 type
, vic
, mode
->clock
, clock
);
3331 mode
->clock
= clock
;
3335 drm_parse_hdmi_vsdb_audio(struct drm_connector
*connector
, const u8
*db
)
3337 u8 len
= cea_db_payload_len(db
);
3340 connector
->eld
[5] |= (db
[6] >> 7) << 1; /* Supports_AI */
3342 connector
->latency_present
[0] = db
[8] >> 7;
3343 connector
->latency_present
[1] = (db
[8] >> 6) & 1;
3346 connector
->video_latency
[0] = db
[9];
3348 connector
->audio_latency
[0] = db
[10];
3350 connector
->video_latency
[1] = db
[11];
3352 connector
->audio_latency
[1] = db
[12];
3354 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
3355 "video latency %d %d, "
3356 "audio latency %d %d\n",
3357 connector
->latency_present
[0],
3358 connector
->latency_present
[1],
3359 connector
->video_latency
[0],
3360 connector
->video_latency
[1],
3361 connector
->audio_latency
[0],
3362 connector
->audio_latency
[1]);
3366 monitor_name(struct detailed_timing
*t
, void *data
)
3368 if (t
->data
.other_data
.type
== EDID_DETAIL_MONITOR_NAME
)
3369 *(u8
**)data
= t
->data
.other_data
.data
.str
.str
;
3372 static int get_monitor_name(struct edid
*edid
, char name
[13])
3374 char *edid_name
= NULL
;
3380 drm_for_each_detailed_block((u8
*)edid
, monitor_name
, &edid_name
);
3381 for (mnl
= 0; edid_name
&& mnl
< 13; mnl
++) {
3382 if (edid_name
[mnl
] == 0x0a)
3385 name
[mnl
] = edid_name
[mnl
];
3392 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3393 * @edid: monitor EDID information
3394 * @name: pointer to a character array to hold the name of the monitor
3395 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3398 void drm_edid_get_monitor_name(struct edid
*edid
, char *name
, int bufsize
)
3406 name_length
= min(get_monitor_name(edid
, buf
), bufsize
- 1);
3407 memcpy(name
, buf
, name_length
);
3408 name
[name_length
] = '\0';
3410 EXPORT_SYMBOL(drm_edid_get_monitor_name
);
3413 * drm_edid_to_eld - build ELD from EDID
3414 * @connector: connector corresponding to the HDMI/DP sink
3415 * @edid: EDID to parse
3417 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3418 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3421 void drm_edid_to_eld(struct drm_connector
*connector
, struct edid
*edid
)
3423 uint8_t *eld
= connector
->eld
;
3426 int total_sad_count
= 0;
3430 memset(eld
, 0, sizeof(connector
->eld
));
3432 connector
->latency_present
[0] = false;
3433 connector
->latency_present
[1] = false;
3434 connector
->video_latency
[0] = 0;
3435 connector
->audio_latency
[0] = 0;
3436 connector
->video_latency
[1] = 0;
3437 connector
->audio_latency
[1] = 0;
3439 cea
= drm_find_cea_extension(edid
);
3441 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3445 mnl
= get_monitor_name(edid
, eld
+ 20);
3447 eld
[4] = (cea
[1] << 5) | mnl
;
3448 DRM_DEBUG_KMS("ELD monitor %s\n", eld
+ 20);
3450 eld
[0] = 2 << 3; /* ELD version: 2 */
3452 eld
[16] = edid
->mfg_id
[0];
3453 eld
[17] = edid
->mfg_id
[1];
3454 eld
[18] = edid
->prod_code
[0];
3455 eld
[19] = edid
->prod_code
[1];
3457 if (cea_revision(cea
) >= 3) {
3460 if (cea_db_offsets(cea
, &start
, &end
)) {
3465 for_each_cea_db(cea
, i
, start
, end
) {
3467 dbl
= cea_db_payload_len(db
);
3469 switch (cea_db_tag(db
)) {
3473 /* Audio Data Block, contains SADs */
3474 sad_count
= min(dbl
/ 3, 15 - total_sad_count
);
3476 memcpy(eld
+ 20 + mnl
+ total_sad_count
* 3,
3477 &db
[1], sad_count
* 3);
3478 total_sad_count
+= sad_count
;
3481 /* Speaker Allocation Data Block */
3486 /* HDMI Vendor-Specific Data Block */
3487 if (cea_db_is_hdmi_vsdb(db
))
3488 drm_parse_hdmi_vsdb_audio(connector
, db
);
3495 eld
[5] |= total_sad_count
<< 4;
3497 eld
[DRM_ELD_BASELINE_ELD_LEN
] =
3498 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld
), 4);
3500 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
3501 drm_eld_size(eld
), total_sad_count
);
3503 EXPORT_SYMBOL(drm_edid_to_eld
);
3506 * drm_edid_to_sad - extracts SADs from EDID
3507 * @edid: EDID to parse
3508 * @sads: pointer that will be set to the extracted SADs
3510 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
3512 * Note: The returned pointer needs to be freed using kfree().
3514 * Return: The number of found SADs or negative number on error.
3516 int drm_edid_to_sad(struct edid
*edid
, struct cea_sad
**sads
)
3519 int i
, start
, end
, dbl
;
3522 cea
= drm_find_cea_extension(edid
);
3524 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3528 if (cea_revision(cea
) < 3) {
3529 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3533 if (cea_db_offsets(cea
, &start
, &end
)) {
3534 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3538 for_each_cea_db(cea
, i
, start
, end
) {
3541 if (cea_db_tag(db
) == AUDIO_BLOCK
) {
3543 dbl
= cea_db_payload_len(db
);
3545 count
= dbl
/ 3; /* SAD is 3B */
3546 *sads
= kcalloc(count
, sizeof(**sads
), GFP_KERNEL
);
3549 for (j
= 0; j
< count
; j
++) {
3550 u8
*sad
= &db
[1 + j
* 3];
3552 (*sads
)[j
].format
= (sad
[0] & 0x78) >> 3;
3553 (*sads
)[j
].channels
= sad
[0] & 0x7;
3554 (*sads
)[j
].freq
= sad
[1] & 0x7F;
3555 (*sads
)[j
].byte2
= sad
[2];
3563 EXPORT_SYMBOL(drm_edid_to_sad
);
3566 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3567 * @edid: EDID to parse
3568 * @sadb: pointer to the speaker block
3570 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
3572 * Note: The returned pointer needs to be freed using kfree().
3574 * Return: The number of found Speaker Allocation Blocks or negative number on
3577 int drm_edid_to_speaker_allocation(struct edid
*edid
, u8
**sadb
)
3580 int i
, start
, end
, dbl
;
3583 cea
= drm_find_cea_extension(edid
);
3585 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3589 if (cea_revision(cea
) < 3) {
3590 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3594 if (cea_db_offsets(cea
, &start
, &end
)) {
3595 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3599 for_each_cea_db(cea
, i
, start
, end
) {
3600 const u8
*db
= &cea
[i
];
3602 if (cea_db_tag(db
) == SPEAKER_BLOCK
) {
3603 dbl
= cea_db_payload_len(db
);
3605 /* Speaker Allocation Data Block */
3607 *sadb
= kmemdup(&db
[1], dbl
, GFP_KERNEL
);
3618 EXPORT_SYMBOL(drm_edid_to_speaker_allocation
);
3621 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
3622 * @connector: connector associated with the HDMI/DP sink
3623 * @mode: the display mode
3625 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3626 * the sink doesn't support audio or video.
3628 int drm_av_sync_delay(struct drm_connector
*connector
,
3629 const struct drm_display_mode
*mode
)
3631 int i
= !!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
);
3634 if (!connector
->latency_present
[0])
3636 if (!connector
->latency_present
[1])
3639 a
= connector
->audio_latency
[i
];
3640 v
= connector
->video_latency
[i
];
3643 * HDMI/DP sink doesn't support audio or video?
3645 if (a
== 255 || v
== 255)
3649 * Convert raw EDID values to millisecond.
3650 * Treat unknown latency as 0ms.
3653 a
= min(2 * (a
- 1), 500);
3655 v
= min(2 * (v
- 1), 500);
3657 return max(v
- a
, 0);
3659 EXPORT_SYMBOL(drm_av_sync_delay
);
3662 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
3663 * @edid: monitor EDID information
3665 * Parse the CEA extension according to CEA-861-B.
3667 * Return: True if the monitor is HDMI, false if not or unknown.
3669 bool drm_detect_hdmi_monitor(struct edid
*edid
)
3673 int start_offset
, end_offset
;
3675 edid_ext
= drm_find_cea_extension(edid
);
3679 if (cea_db_offsets(edid_ext
, &start_offset
, &end_offset
))
3683 * Because HDMI identifier is in Vendor Specific Block,
3684 * search it from all data blocks of CEA extension.
3686 for_each_cea_db(edid_ext
, i
, start_offset
, end_offset
) {
3687 if (cea_db_is_hdmi_vsdb(&edid_ext
[i
]))
3693 EXPORT_SYMBOL(drm_detect_hdmi_monitor
);
3696 * drm_detect_monitor_audio - check monitor audio capability
3697 * @edid: EDID block to scan
3699 * Monitor should have CEA extension block.
3700 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3701 * audio' only. If there is any audio extension block and supported
3702 * audio format, assume at least 'basic audio' support, even if 'basic
3703 * audio' is not defined in EDID.
3705 * Return: True if the monitor supports audio, false otherwise.
3707 bool drm_detect_monitor_audio(struct edid
*edid
)
3711 bool has_audio
= false;
3712 int start_offset
, end_offset
;
3714 edid_ext
= drm_find_cea_extension(edid
);
3718 has_audio
= ((edid_ext
[3] & EDID_BASIC_AUDIO
) != 0);
3721 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3725 if (cea_db_offsets(edid_ext
, &start_offset
, &end_offset
))
3728 for_each_cea_db(edid_ext
, i
, start_offset
, end_offset
) {
3729 if (cea_db_tag(&edid_ext
[i
]) == AUDIO_BLOCK
) {
3731 for (j
= 1; j
< cea_db_payload_len(&edid_ext
[i
]) + 1; j
+= 3)
3732 DRM_DEBUG_KMS("CEA audio format %d\n",
3733 (edid_ext
[i
+ j
] >> 3) & 0xf);
3740 EXPORT_SYMBOL(drm_detect_monitor_audio
);
3743 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
3744 * @edid: EDID block to scan
3746 * Check whether the monitor reports the RGB quantization range selection
3747 * as supported. The AVI infoframe can then be used to inform the monitor
3748 * which quantization range (full or limited) is used.
3750 * Return: True if the RGB quantization range is selectable, false otherwise.
3752 bool drm_rgb_quant_range_selectable(struct edid
*edid
)
3757 edid_ext
= drm_find_cea_extension(edid
);
3761 if (cea_db_offsets(edid_ext
, &start
, &end
))
3764 for_each_cea_db(edid_ext
, i
, start
, end
) {
3765 if (cea_db_tag(&edid_ext
[i
]) == VIDEO_CAPABILITY_BLOCK
&&
3766 cea_db_payload_len(&edid_ext
[i
]) == 2) {
3767 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext
[i
+ 2]);
3768 return edid_ext
[i
+ 2] & EDID_CEA_VCDB_QS
;
3774 EXPORT_SYMBOL(drm_rgb_quant_range_selectable
);
3777 * drm_default_rgb_quant_range - default RGB quantization range
3778 * @mode: display mode
3780 * Determine the default RGB quantization range for the mode,
3781 * as specified in CEA-861.
3783 * Return: The default RGB quantization range for the mode
3785 enum hdmi_quantization_range
3786 drm_default_rgb_quant_range(const struct drm_display_mode
*mode
)
3788 /* All CEA modes other than VIC 1 use limited quantization range. */
3789 return drm_match_cea_mode(mode
) > 1 ?
3790 HDMI_QUANTIZATION_RANGE_LIMITED
:
3791 HDMI_QUANTIZATION_RANGE_FULL
;
3793 EXPORT_SYMBOL(drm_default_rgb_quant_range
);
3795 static void drm_parse_hdmi_deep_color_info(struct drm_connector
*connector
,
3798 struct drm_display_info
*info
= &connector
->display_info
;
3799 unsigned int dc_bpc
= 0;
3801 /* HDMI supports at least 8 bpc */
3804 if (cea_db_payload_len(hdmi
) < 6)
3807 if (hdmi
[6] & DRM_EDID_HDMI_DC_30
) {
3809 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_30
;
3810 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
3814 if (hdmi
[6] & DRM_EDID_HDMI_DC_36
) {
3816 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_36
;
3817 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
3821 if (hdmi
[6] & DRM_EDID_HDMI_DC_48
) {
3823 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_48
;
3824 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
3829 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
3834 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
3835 connector
->name
, dc_bpc
);
3839 * Deep color support mandates RGB444 support for all video
3840 * modes and forbids YCRCB422 support for all video modes per
3843 info
->color_formats
= DRM_COLOR_FORMAT_RGB444
;
3845 /* YCRCB444 is optional according to spec. */
3846 if (hdmi
[6] & DRM_EDID_HDMI_DC_Y444
) {
3847 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3848 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
3853 * Spec says that if any deep color mode is supported at all,
3854 * then deep color 36 bit must be supported.
3856 if (!(hdmi
[6] & DRM_EDID_HDMI_DC_36
)) {
3857 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
3863 drm_parse_hdmi_vsdb_video(struct drm_connector
*connector
, const u8
*db
)
3865 struct drm_display_info
*info
= &connector
->display_info
;
3866 u8 len
= cea_db_payload_len(db
);
3869 info
->dvi_dual
= db
[6] & 1;
3871 info
->max_tmds_clock
= db
[7] * 5000;
3873 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
3874 "max TMDS clock %d kHz\n",
3876 info
->max_tmds_clock
);
3878 drm_parse_hdmi_deep_color_info(connector
, db
);
3881 static void drm_parse_cea_ext(struct drm_connector
*connector
,
3884 struct drm_display_info
*info
= &connector
->display_info
;
3888 edid_ext
= drm_find_cea_extension(edid
);
3892 info
->cea_rev
= edid_ext
[1];
3894 /* The existence of a CEA block should imply RGB support */
3895 info
->color_formats
= DRM_COLOR_FORMAT_RGB444
;
3896 if (edid_ext
[3] & EDID_CEA_YCRCB444
)
3897 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3898 if (edid_ext
[3] & EDID_CEA_YCRCB422
)
3899 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB422
;
3901 if (cea_db_offsets(edid_ext
, &start
, &end
))
3904 for_each_cea_db(edid_ext
, i
, start
, end
) {
3905 const u8
*db
= &edid_ext
[i
];
3907 if (cea_db_is_hdmi_vsdb(db
))
3908 drm_parse_hdmi_vsdb_video(connector
, db
);
3912 static void drm_add_display_info(struct drm_connector
*connector
,
3915 struct drm_display_info
*info
= &connector
->display_info
;
3917 info
->width_mm
= edid
->width_cm
* 10;
3918 info
->height_mm
= edid
->height_cm
* 10;
3920 /* driver figures it out in this case */
3922 info
->color_formats
= 0;
3924 info
->max_tmds_clock
= 0;
3925 info
->dvi_dual
= false;
3927 if (edid
->revision
< 3)
3930 if (!(edid
->input
& DRM_EDID_INPUT_DIGITAL
))
3933 drm_parse_cea_ext(connector
, edid
);
3936 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
3938 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
3939 * tells us to assume 8 bpc color depth if the EDID doesn't have
3940 * extensions which tell otherwise.
3942 if ((info
->bpc
== 0) && (edid
->revision
< 4) &&
3943 (edid
->input
& DRM_EDID_DIGITAL_TYPE_DVI
)) {
3945 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
3946 connector
->name
, info
->bpc
);
3949 /* Only defined for 1.4 with digital displays */
3950 if (edid
->revision
< 4)
3953 switch (edid
->input
& DRM_EDID_DIGITAL_DEPTH_MASK
) {
3954 case DRM_EDID_DIGITAL_DEPTH_6
:
3957 case DRM_EDID_DIGITAL_DEPTH_8
:
3960 case DRM_EDID_DIGITAL_DEPTH_10
:
3963 case DRM_EDID_DIGITAL_DEPTH_12
:
3966 case DRM_EDID_DIGITAL_DEPTH_14
:
3969 case DRM_EDID_DIGITAL_DEPTH_16
:
3972 case DRM_EDID_DIGITAL_DEPTH_UNDEF
:
3978 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
3979 connector
->name
, info
->bpc
);
3981 info
->color_formats
|= DRM_COLOR_FORMAT_RGB444
;
3982 if (edid
->features
& DRM_EDID_FEATURE_RGB_YCRCB444
)
3983 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3984 if (edid
->features
& DRM_EDID_FEATURE_RGB_YCRCB422
)
3985 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB422
;
3988 static int validate_displayid(u8
*displayid
, int length
, int idx
)
3992 struct displayid_hdr
*base
;
3994 base
= (struct displayid_hdr
*)&displayid
[idx
];
3996 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
3997 base
->rev
, base
->bytes
, base
->prod_id
, base
->ext_count
);
3999 if (base
->bytes
+ 5 > length
- idx
)
4001 for (i
= idx
; i
<= base
->bytes
+ 5; i
++) {
4002 csum
+= displayid
[i
];
4005 DRM_ERROR("DisplayID checksum invalid, remainder is %d\n", csum
);
4011 static struct drm_display_mode
*drm_mode_displayid_detailed(struct drm_device
*dev
,
4012 struct displayid_detailed_timings_1
*timings
)
4014 struct drm_display_mode
*mode
;
4015 unsigned pixel_clock
= (timings
->pixel_clock
[0] |
4016 (timings
->pixel_clock
[1] << 8) |
4017 (timings
->pixel_clock
[2] << 16));
4018 unsigned hactive
= (timings
->hactive
[0] | timings
->hactive
[1] << 8) + 1;
4019 unsigned hblank
= (timings
->hblank
[0] | timings
->hblank
[1] << 8) + 1;
4020 unsigned hsync
= (timings
->hsync
[0] | (timings
->hsync
[1] & 0x7f) << 8) + 1;
4021 unsigned hsync_width
= (timings
->hsw
[0] | timings
->hsw
[1] << 8) + 1;
4022 unsigned vactive
= (timings
->vactive
[0] | timings
->vactive
[1] << 8) + 1;
4023 unsigned vblank
= (timings
->vblank
[0] | timings
->vblank
[1] << 8) + 1;
4024 unsigned vsync
= (timings
->vsync
[0] | (timings
->vsync
[1] & 0x7f) << 8) + 1;
4025 unsigned vsync_width
= (timings
->vsw
[0] | timings
->vsw
[1] << 8) + 1;
4026 bool hsync_positive
= (timings
->hsync
[1] >> 7) & 0x1;
4027 bool vsync_positive
= (timings
->vsync
[1] >> 7) & 0x1;
4028 mode
= drm_mode_create(dev
);
4032 mode
->clock
= pixel_clock
* 10;
4033 mode
->hdisplay
= hactive
;
4034 mode
->hsync_start
= mode
->hdisplay
+ hsync
;
4035 mode
->hsync_end
= mode
->hsync_start
+ hsync_width
;
4036 mode
->htotal
= mode
->hdisplay
+ hblank
;
4038 mode
->vdisplay
= vactive
;
4039 mode
->vsync_start
= mode
->vdisplay
+ vsync
;
4040 mode
->vsync_end
= mode
->vsync_start
+ vsync_width
;
4041 mode
->vtotal
= mode
->vdisplay
+ vblank
;
4044 mode
->flags
|= hsync_positive
? DRM_MODE_FLAG_PHSYNC
: DRM_MODE_FLAG_NHSYNC
;
4045 mode
->flags
|= vsync_positive
? DRM_MODE_FLAG_PVSYNC
: DRM_MODE_FLAG_NVSYNC
;
4046 mode
->type
= DRM_MODE_TYPE_DRIVER
;
4048 if (timings
->flags
& 0x80)
4049 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
4050 mode
->vrefresh
= drm_mode_vrefresh(mode
);
4051 drm_mode_set_name(mode
);
4056 static int add_displayid_detailed_1_modes(struct drm_connector
*connector
,
4057 struct displayid_block
*block
)
4059 struct displayid_detailed_timing_block
*det
= (struct displayid_detailed_timing_block
*)block
;
4062 struct drm_display_mode
*newmode
;
4064 /* blocks must be multiple of 20 bytes length */
4065 if (block
->num_bytes
% 20)
4068 num_timings
= block
->num_bytes
/ 20;
4069 for (i
= 0; i
< num_timings
; i
++) {
4070 struct displayid_detailed_timings_1
*timings
= &det
->timings
[i
];
4072 newmode
= drm_mode_displayid_detailed(connector
->dev
, timings
);
4076 drm_mode_probed_add(connector
, newmode
);
4082 static int add_displayid_detailed_modes(struct drm_connector
*connector
,
4088 int length
= EDID_LENGTH
;
4089 struct displayid_block
*block
;
4092 displayid
= drm_find_displayid_extension(edid
);
4096 ret
= validate_displayid(displayid
, length
, idx
);
4100 idx
+= sizeof(struct displayid_hdr
);
4101 while (block
= (struct displayid_block
*)&displayid
[idx
],
4102 idx
+ sizeof(struct displayid_block
) <= length
&&
4103 idx
+ sizeof(struct displayid_block
) + block
->num_bytes
<= length
&&
4104 block
->num_bytes
> 0) {
4105 idx
+= block
->num_bytes
+ sizeof(struct displayid_block
);
4106 switch (block
->tag
) {
4107 case DATA_BLOCK_TYPE_1_DETAILED_TIMING
:
4108 num_modes
+= add_displayid_detailed_1_modes(connector
, block
);
4116 * drm_add_edid_modes - add modes from EDID data, if available
4117 * @connector: connector we're probing
4120 * Add the specified modes to the connector's mode list. Also fills out the
4121 * &drm_display_info structure in @connector with any information which can be
4122 * derived from the edid.
4124 * Return: The number of modes added or 0 if we couldn't find any.
4126 int drm_add_edid_modes(struct drm_connector
*connector
, struct edid
*edid
)
4134 if (!drm_edid_is_valid(edid
)) {
4135 dev_warn(connector
->dev
->dev
, "%s: EDID invalid.\n",
4140 quirks
= edid_get_quirks(edid
);
4143 * EDID spec says modes should be preferred in this order:
4144 * - preferred detailed mode
4145 * - other detailed modes from base block
4146 * - detailed modes from extension blocks
4147 * - CVT 3-byte code modes
4148 * - standard timing codes
4149 * - established timing codes
4150 * - modes inferred from GTF or CVT range information
4152 * We get this pretty much right.
4154 * XXX order for additional mode types in extension blocks?
4156 num_modes
+= add_detailed_modes(connector
, edid
, quirks
);
4157 num_modes
+= add_cvt_modes(connector
, edid
);
4158 num_modes
+= add_standard_modes(connector
, edid
);
4159 num_modes
+= add_established_modes(connector
, edid
);
4160 num_modes
+= add_cea_modes(connector
, edid
);
4161 num_modes
+= add_alternate_cea_modes(connector
, edid
);
4162 num_modes
+= add_displayid_detailed_modes(connector
, edid
);
4163 if (edid
->features
& DRM_EDID_FEATURE_DEFAULT_GTF
)
4164 num_modes
+= add_inferred_modes(connector
, edid
);
4166 if (quirks
& (EDID_QUIRK_PREFER_LARGE_60
| EDID_QUIRK_PREFER_LARGE_75
))
4167 edid_fixup_preferred(connector
, quirks
);
4169 drm_add_display_info(connector
, edid
);
4171 if (quirks
& EDID_QUIRK_FORCE_6BPC
)
4172 connector
->display_info
.bpc
= 6;
4174 if (quirks
& EDID_QUIRK_FORCE_8BPC
)
4175 connector
->display_info
.bpc
= 8;
4177 if (quirks
& EDID_QUIRK_FORCE_12BPC
)
4178 connector
->display_info
.bpc
= 12;
4182 EXPORT_SYMBOL(drm_add_edid_modes
);
4185 * drm_add_modes_noedid - add modes for the connectors without EDID
4186 * @connector: connector we're probing
4187 * @hdisplay: the horizontal display limit
4188 * @vdisplay: the vertical display limit
4190 * Add the specified modes to the connector's mode list. Only when the
4191 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4193 * Return: The number of modes added or 0 if we couldn't find any.
4195 int drm_add_modes_noedid(struct drm_connector
*connector
,
4196 int hdisplay
, int vdisplay
)
4198 int i
, count
, num_modes
= 0;
4199 struct drm_display_mode
*mode
;
4200 struct drm_device
*dev
= connector
->dev
;
4202 count
= ARRAY_SIZE(drm_dmt_modes
);
4208 for (i
= 0; i
< count
; i
++) {
4209 const struct drm_display_mode
*ptr
= &drm_dmt_modes
[i
];
4210 if (hdisplay
&& vdisplay
) {
4212 * Only when two are valid, they will be used to check
4213 * whether the mode should be added to the mode list of
4216 if (ptr
->hdisplay
> hdisplay
||
4217 ptr
->vdisplay
> vdisplay
)
4220 if (drm_mode_vrefresh(ptr
) > 61)
4222 mode
= drm_mode_duplicate(dev
, ptr
);
4224 drm_mode_probed_add(connector
, mode
);
4230 EXPORT_SYMBOL(drm_add_modes_noedid
);
4233 * drm_set_preferred_mode - Sets the preferred mode of a connector
4234 * @connector: connector whose mode list should be processed
4235 * @hpref: horizontal resolution of preferred mode
4236 * @vpref: vertical resolution of preferred mode
4238 * Marks a mode as preferred if it matches the resolution specified by @hpref
4241 void drm_set_preferred_mode(struct drm_connector
*connector
,
4242 int hpref
, int vpref
)
4244 struct drm_display_mode
*mode
;
4246 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
4247 if (mode
->hdisplay
== hpref
&&
4248 mode
->vdisplay
== vpref
)
4249 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
4252 EXPORT_SYMBOL(drm_set_preferred_mode
);
4255 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4256 * data from a DRM display mode
4257 * @frame: HDMI AVI infoframe
4258 * @mode: DRM display mode
4260 * Return: 0 on success or a negative error code on failure.
4263 drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe
*frame
,
4264 const struct drm_display_mode
*mode
)
4268 if (!frame
|| !mode
)
4271 err
= hdmi_avi_infoframe_init(frame
);
4275 if (mode
->flags
& DRM_MODE_FLAG_DBLCLK
)
4276 frame
->pixel_repeat
= 1;
4278 frame
->video_code
= drm_match_cea_mode(mode
);
4280 frame
->picture_aspect
= HDMI_PICTURE_ASPECT_NONE
;
4283 * Populate picture aspect ratio from either
4284 * user input (if specified) or from the CEA mode list.
4286 if (mode
->picture_aspect_ratio
== HDMI_PICTURE_ASPECT_4_3
||
4287 mode
->picture_aspect_ratio
== HDMI_PICTURE_ASPECT_16_9
)
4288 frame
->picture_aspect
= mode
->picture_aspect_ratio
;
4289 else if (frame
->video_code
> 0)
4290 frame
->picture_aspect
= drm_get_cea_aspect_ratio(
4293 frame
->active_aspect
= HDMI_ACTIVE_ASPECT_PICTURE
;
4294 frame
->scan_mode
= HDMI_SCAN_MODE_UNDERSCAN
;
4298 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode
);
4301 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
4302 * quantization range information
4303 * @frame: HDMI AVI infoframe
4304 * @mode: DRM display mode
4305 * @rgb_quant_range: RGB quantization range (Q)
4306 * @rgb_quant_range_selectable: Sink support selectable RGB quantization range (QS)
4309 drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe
*frame
,
4310 const struct drm_display_mode
*mode
,
4311 enum hdmi_quantization_range rgb_quant_range
,
4312 bool rgb_quant_range_selectable
)
4316 * "A Source shall not send a non-zero Q value that does not correspond
4317 * to the default RGB Quantization Range for the transmitted Picture
4318 * unless the Sink indicates support for the Q bit in a Video
4319 * Capabilities Data Block."
4321 * HDMI 2.0 recommends sending non-zero Q when it does match the
4322 * default RGB quantization range for the mode, even when QS=0.
4324 if (rgb_quant_range_selectable
||
4325 rgb_quant_range
== drm_default_rgb_quant_range(mode
))
4326 frame
->quantization_range
= rgb_quant_range
;
4328 frame
->quantization_range
= HDMI_QUANTIZATION_RANGE_DEFAULT
;
4332 * "When transmitting any RGB colorimetry, the Source should set the
4333 * YQ-field to match the RGB Quantization Range being transmitted
4334 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
4335 * set YQ=1) and the Sink shall ignore the YQ-field."
4337 if (rgb_quant_range
== HDMI_QUANTIZATION_RANGE_LIMITED
)
4338 frame
->ycc_quantization_range
=
4339 HDMI_YCC_QUANTIZATION_RANGE_LIMITED
;
4341 frame
->ycc_quantization_range
=
4342 HDMI_YCC_QUANTIZATION_RANGE_FULL
;
4344 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range
);
4346 static enum hdmi_3d_structure
4347 s3d_structure_from_display_mode(const struct drm_display_mode
*mode
)
4349 u32 layout
= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
4352 case DRM_MODE_FLAG_3D_FRAME_PACKING
:
4353 return HDMI_3D_STRUCTURE_FRAME_PACKING
;
4354 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE
:
4355 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE
;
4356 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE
:
4357 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE
;
4358 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL
:
4359 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL
;
4360 case DRM_MODE_FLAG_3D_L_DEPTH
:
4361 return HDMI_3D_STRUCTURE_L_DEPTH
;
4362 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH
:
4363 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH
;
4364 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
:
4365 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM
;
4366 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
:
4367 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
;
4369 return HDMI_3D_STRUCTURE_INVALID
;
4374 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4375 * data from a DRM display mode
4376 * @frame: HDMI vendor infoframe
4377 * @mode: DRM display mode
4379 * Note that there's is a need to send HDMI vendor infoframes only when using a
4380 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4381 * function will return -EINVAL, error that can be safely ignored.
4383 * Return: 0 on success or a negative error code on failure.
4386 drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe
*frame
,
4387 const struct drm_display_mode
*mode
)
4393 if (!frame
|| !mode
)
4396 vic
= drm_match_hdmi_mode(mode
);
4397 s3d_flags
= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
4399 if (!vic
&& !s3d_flags
)
4402 if (vic
&& s3d_flags
)
4405 err
= hdmi_vendor_infoframe_init(frame
);
4412 frame
->s3d_struct
= s3d_structure_from_display_mode(mode
);
4416 EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode
);
4418 static int drm_parse_tiled_block(struct drm_connector
*connector
,
4419 struct displayid_block
*block
)
4421 struct displayid_tiled_block
*tile
= (struct displayid_tiled_block
*)block
;
4423 u8 tile_v_loc
, tile_h_loc
;
4424 u8 num_v_tile
, num_h_tile
;
4425 struct drm_tile_group
*tg
;
4427 w
= tile
->tile_size
[0] | tile
->tile_size
[1] << 8;
4428 h
= tile
->tile_size
[2] | tile
->tile_size
[3] << 8;
4430 num_v_tile
= (tile
->topo
[0] & 0xf) | (tile
->topo
[2] & 0x30);
4431 num_h_tile
= (tile
->topo
[0] >> 4) | ((tile
->topo
[2] >> 2) & 0x30);
4432 tile_v_loc
= (tile
->topo
[1] & 0xf) | ((tile
->topo
[2] & 0x3) << 4);
4433 tile_h_loc
= (tile
->topo
[1] >> 4) | (((tile
->topo
[2] >> 2) & 0x3) << 4);
4435 connector
->has_tile
= true;
4436 if (tile
->tile_cap
& 0x80)
4437 connector
->tile_is_single_monitor
= true;
4439 connector
->num_h_tile
= num_h_tile
+ 1;
4440 connector
->num_v_tile
= num_v_tile
+ 1;
4441 connector
->tile_h_loc
= tile_h_loc
;
4442 connector
->tile_v_loc
= tile_v_loc
;
4443 connector
->tile_h_size
= w
+ 1;
4444 connector
->tile_v_size
= h
+ 1;
4446 DRM_DEBUG_KMS("tile cap 0x%x\n", tile
->tile_cap
);
4447 DRM_DEBUG_KMS("tile_size %d x %d\n", w
+ 1, h
+ 1);
4448 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
4449 num_h_tile
+ 1, num_v_tile
+ 1, tile_h_loc
, tile_v_loc
);
4450 DRM_DEBUG_KMS("vend %c%c%c\n", tile
->topology_id
[0], tile
->topology_id
[1], tile
->topology_id
[2]);
4452 tg
= drm_mode_get_tile_group(connector
->dev
, tile
->topology_id
);
4454 tg
= drm_mode_create_tile_group(connector
->dev
, tile
->topology_id
);
4459 if (connector
->tile_group
!= tg
) {
4460 /* if we haven't got a pointer,
4461 take the reference, drop ref to old tile group */
4462 if (connector
->tile_group
) {
4463 drm_mode_put_tile_group(connector
->dev
, connector
->tile_group
);
4465 connector
->tile_group
= tg
;
4467 /* if same tile group, then release the ref we just took. */
4468 drm_mode_put_tile_group(connector
->dev
, tg
);
4472 static int drm_parse_display_id(struct drm_connector
*connector
,
4473 u8
*displayid
, int length
,
4474 bool is_edid_extension
)
4476 /* if this is an EDID extension the first byte will be 0x70 */
4478 struct displayid_block
*block
;
4481 if (is_edid_extension
)
4484 ret
= validate_displayid(displayid
, length
, idx
);
4488 idx
+= sizeof(struct displayid_hdr
);
4489 while (block
= (struct displayid_block
*)&displayid
[idx
],
4490 idx
+ sizeof(struct displayid_block
) <= length
&&
4491 idx
+ sizeof(struct displayid_block
) + block
->num_bytes
<= length
&&
4492 block
->num_bytes
> 0) {
4493 idx
+= block
->num_bytes
+ sizeof(struct displayid_block
);
4494 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
4495 block
->tag
, block
->rev
, block
->num_bytes
);
4497 switch (block
->tag
) {
4498 case DATA_BLOCK_TILED_DISPLAY
:
4499 ret
= drm_parse_tiled_block(connector
, block
);
4503 case DATA_BLOCK_TYPE_1_DETAILED_TIMING
:
4504 /* handled in mode gathering code. */
4507 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block
->tag
);
4514 static void drm_get_displayid(struct drm_connector
*connector
,
4517 void *displayid
= NULL
;
4519 connector
->has_tile
= false;
4520 displayid
= drm_find_displayid_extension(edid
);
4522 /* drop reference to any tile group we had */
4526 ret
= drm_parse_display_id(connector
, displayid
, EDID_LENGTH
, true);
4529 if (!connector
->has_tile
)
4533 if (connector
->tile_group
) {
4534 drm_mode_put_tile_group(connector
->dev
, connector
->tile_group
);
4535 connector
->tile_group
= NULL
;