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>
36 #include <drm/drm_edid.h>
38 #define version_greater(edid, maj, min) \
39 (((edid)->version > (maj)) || \
40 ((edid)->version == (maj) && (edid)->revision > (min)))
42 #define EDID_EST_TIMINGS 16
43 #define EDID_STD_TIMINGS 8
44 #define EDID_DETAILED_TIMINGS 4
47 * EDID blocks out in the wild have a variety of bugs, try to collect
48 * them here (note that userspace may work around broken monitors first,
49 * but fixes should make their way here so that the kernel "just works"
50 * on as many displays as possible).
53 /* First detailed mode wrong, use largest 60Hz mode */
54 #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
55 /* Reported 135MHz pixel clock is too high, needs adjustment */
56 #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
57 /* Prefer the largest mode at 75 Hz */
58 #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
59 /* Detail timing is in cm not mm */
60 #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
61 /* Detailed timing descriptors have bogus size values, so just take the
62 * maximum size and use that.
64 #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
65 /* Monitor forgot to set the first detailed is preferred bit. */
66 #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
67 /* use +hsync +vsync for detailed mode */
68 #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
69 /* Force reduced-blanking timings for detailed modes */
70 #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
72 #define EDID_QUIRK_FORCE_8BPC (1 << 8)
74 #define EDID_QUIRK_FORCE_12BPC (1 << 9)
76 struct detailed_mode_closure {
77 struct drm_connector *connector;
89 static struct edid_quirk {
93 } edid_quirk_list[] = {
95 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
97 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
99 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
101 /* Belinea 10 15 55 */
102 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
103 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
105 /* Envision Peripherals, Inc. EN-7100e */
106 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
107 /* Envision EN2028 */
108 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
110 /* Funai Electronics PM36B */
111 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
112 EDID_QUIRK_DETAILED_IN_CM },
114 /* LG Philips LCD LP154W01-A5 */
115 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
116 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
118 /* Philips 107p5 CRT */
119 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
122 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
124 /* Samsung SyncMaster 205BW. Note: irony */
125 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
126 /* Samsung SyncMaster 22[5-6]BW */
127 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
128 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
130 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
131 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
133 /* ViewSonic VA2026w */
134 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
136 /* Medion MD 30217 PG */
137 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
139 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
140 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
144 * Autogenerated from the DMT spec.
145 * This table is copied from xfree86/modes/xf86EdidModes.c.
147 static const struct drm_display_mode drm_dmt_modes[] = {
149 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
150 736, 832, 0, 350, 382, 385, 445, 0,
151 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
153 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
154 736, 832, 0, 400, 401, 404, 445, 0,
155 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
157 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
158 828, 936, 0, 400, 401, 404, 446, 0,
159 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
161 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
162 752, 800, 0, 480, 489, 492, 525, 0,
163 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
165 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
166 704, 832, 0, 480, 489, 492, 520, 0,
167 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
169 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
170 720, 840, 0, 480, 481, 484, 500, 0,
171 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
173 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
174 752, 832, 0, 480, 481, 484, 509, 0,
175 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
177 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
178 896, 1024, 0, 600, 601, 603, 625, 0,
179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
181 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
182 968, 1056, 0, 600, 601, 605, 628, 0,
183 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
185 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
186 976, 1040, 0, 600, 637, 643, 666, 0,
187 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
189 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
190 896, 1056, 0, 600, 601, 604, 625, 0,
191 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
193 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
194 896, 1048, 0, 600, 601, 604, 631, 0,
195 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
196 /* 800x600@120Hz RB */
197 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
198 880, 960, 0, 600, 603, 607, 636, 0,
199 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
201 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
202 976, 1088, 0, 480, 486, 494, 517, 0,
203 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
204 /* 1024x768@43Hz, interlace */
205 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
206 1208, 1264, 0, 768, 768, 772, 817, 0,
207 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
208 DRM_MODE_FLAG_INTERLACE) },
210 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
211 1184, 1344, 0, 768, 771, 777, 806, 0,
212 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
214 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
215 1184, 1328, 0, 768, 771, 777, 806, 0,
216 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
218 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
219 1136, 1312, 0, 768, 769, 772, 800, 0,
220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
222 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
223 1168, 1376, 0, 768, 769, 772, 808, 0,
224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
225 /* 1024x768@120Hz RB */
226 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
227 1104, 1184, 0, 768, 771, 775, 813, 0,
228 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
230 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
231 1344, 1600, 0, 864, 865, 868, 900, 0,
232 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
233 /* 1280x768@60Hz RB */
234 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
235 1360, 1440, 0, 768, 771, 778, 790, 0,
236 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
238 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
239 1472, 1664, 0, 768, 771, 778, 798, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
242 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
243 1488, 1696, 0, 768, 771, 778, 805, 0,
244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
246 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
247 1496, 1712, 0, 768, 771, 778, 809, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
249 /* 1280x768@120Hz RB */
250 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
251 1360, 1440, 0, 768, 771, 778, 813, 0,
252 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
253 /* 1280x800@60Hz RB */
254 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
255 1360, 1440, 0, 800, 803, 809, 823, 0,
256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
258 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
259 1480, 1680, 0, 800, 803, 809, 831, 0,
260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
262 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
263 1488, 1696, 0, 800, 803, 809, 838, 0,
264 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
266 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
267 1496, 1712, 0, 800, 803, 809, 843, 0,
268 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
269 /* 1280x800@120Hz RB */
270 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
271 1360, 1440, 0, 800, 803, 809, 847, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
274 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
275 1488, 1800, 0, 960, 961, 964, 1000, 0,
276 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
278 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
279 1504, 1728, 0, 960, 961, 964, 1011, 0,
280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
281 /* 1280x960@120Hz RB */
282 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
283 1360, 1440, 0, 960, 963, 967, 1017, 0,
284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
286 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
287 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
288 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
290 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
291 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
292 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
294 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
295 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
297 /* 1280x1024@120Hz RB */
298 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
299 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
300 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
302 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
303 1536, 1792, 0, 768, 771, 777, 795, 0,
304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
305 /* 1360x768@120Hz RB */
306 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
307 1440, 1520, 0, 768, 771, 776, 813, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
309 /* 1400x1050@60Hz RB */
310 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
311 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
314 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
315 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
316 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
318 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
319 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
320 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
322 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
323 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
324 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
325 /* 1400x1050@120Hz RB */
326 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
327 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
328 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
329 /* 1440x900@60Hz RB */
330 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
331 1520, 1600, 0, 900, 903, 909, 926, 0,
332 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
334 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
335 1672, 1904, 0, 900, 903, 909, 934, 0,
336 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
338 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
339 1688, 1936, 0, 900, 903, 909, 942, 0,
340 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
342 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
343 1696, 1952, 0, 900, 903, 909, 948, 0,
344 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
345 /* 1440x900@120Hz RB */
346 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
347 1520, 1600, 0, 900, 903, 909, 953, 0,
348 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
350 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
351 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
352 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
354 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
355 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
356 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
358 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
359 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
360 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
362 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
363 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
366 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
367 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
369 /* 1600x1200@120Hz RB */
370 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
371 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
372 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
373 /* 1680x1050@60Hz RB */
374 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
375 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
376 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
378 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
379 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
380 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
382 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
383 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
384 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
386 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
387 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
388 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
389 /* 1680x1050@120Hz RB */
390 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
391 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
394 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
395 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
396 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
398 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
399 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
400 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
401 /* 1792x1344@120Hz RB */
402 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
403 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
404 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
406 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
407 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
408 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
410 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
411 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
412 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
413 /* 1856x1392@120Hz RB */
414 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
415 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
416 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
417 /* 1920x1200@60Hz RB */
418 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
419 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
420 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
422 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
423 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
424 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
426 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
427 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
428 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
430 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
431 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
432 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
433 /* 1920x1200@120Hz RB */
434 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
435 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
436 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
438 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
439 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
440 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
442 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
443 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
444 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
445 /* 1920x1440@120Hz RB */
446 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
447 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
448 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
449 /* 2560x1600@60Hz RB */
450 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
451 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
452 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
454 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
455 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
456 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
458 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
459 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
460 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
462 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
463 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
464 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
465 /* 2560x1600@120Hz RB */
466 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
467 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
468 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
472 * These more or less come from the DMT spec. The 720x400 modes are
473 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
474 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
475 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
478 * The DMT modes have been fact-checked; the rest are mild guesses.
480 static const struct drm_display_mode edid_est_modes[] = {
481 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
482 968, 1056, 0, 600, 601, 605, 628, 0,
483 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
484 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
485 896, 1024, 0, 600, 601, 603, 625, 0,
486 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
487 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
488 720, 840, 0, 480, 481, 484, 500, 0,
489 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
490 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
491 704, 832, 0, 480, 489, 491, 520, 0,
492 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
493 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
494 768, 864, 0, 480, 483, 486, 525, 0,
495 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
496 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
497 752, 800, 0, 480, 490, 492, 525, 0,
498 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
499 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
500 846, 900, 0, 400, 421, 423, 449, 0,
501 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
502 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
503 846, 900, 0, 400, 412, 414, 449, 0,
504 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
505 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
506 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
508 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
509 1136, 1312, 0, 768, 769, 772, 800, 0,
510 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
511 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
512 1184, 1328, 0, 768, 771, 777, 806, 0,
513 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
514 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
515 1184, 1344, 0, 768, 771, 777, 806, 0,
516 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
517 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
518 1208, 1264, 0, 768, 768, 776, 817, 0,
519 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
520 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
521 928, 1152, 0, 624, 625, 628, 667, 0,
522 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
523 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
524 896, 1056, 0, 600, 601, 604, 625, 0,
525 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
526 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
527 976, 1040, 0, 600, 637, 643, 666, 0,
528 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
529 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
530 1344, 1600, 0, 864, 865, 868, 900, 0,
531 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
541 static const struct minimode est3_modes[] = {
549 { 1024, 768, 85, 0 },
550 { 1152, 864, 75, 0 },
552 { 1280, 768, 60, 1 },
553 { 1280, 768, 60, 0 },
554 { 1280, 768, 75, 0 },
555 { 1280, 768, 85, 0 },
556 { 1280, 960, 60, 0 },
557 { 1280, 960, 85, 0 },
558 { 1280, 1024, 60, 0 },
559 { 1280, 1024, 85, 0 },
561 { 1360, 768, 60, 0 },
562 { 1440, 900, 60, 1 },
563 { 1440, 900, 60, 0 },
564 { 1440, 900, 75, 0 },
565 { 1440, 900, 85, 0 },
566 { 1400, 1050, 60, 1 },
567 { 1400, 1050, 60, 0 },
568 { 1400, 1050, 75, 0 },
570 { 1400, 1050, 85, 0 },
571 { 1680, 1050, 60, 1 },
572 { 1680, 1050, 60, 0 },
573 { 1680, 1050, 75, 0 },
574 { 1680, 1050, 85, 0 },
575 { 1600, 1200, 60, 0 },
576 { 1600, 1200, 65, 0 },
577 { 1600, 1200, 70, 0 },
579 { 1600, 1200, 75, 0 },
580 { 1600, 1200, 85, 0 },
581 { 1792, 1344, 60, 0 },
582 { 1792, 1344, 75, 0 },
583 { 1856, 1392, 60, 0 },
584 { 1856, 1392, 75, 0 },
585 { 1920, 1200, 60, 1 },
586 { 1920, 1200, 60, 0 },
588 { 1920, 1200, 75, 0 },
589 { 1920, 1200, 85, 0 },
590 { 1920, 1440, 60, 0 },
591 { 1920, 1440, 75, 0 },
594 static const struct minimode extra_modes[] = {
595 { 1024, 576, 60, 0 },
596 { 1366, 768, 60, 0 },
597 { 1600, 900, 60, 0 },
598 { 1680, 945, 60, 0 },
599 { 1920, 1080, 60, 0 },
600 { 2048, 1152, 60, 0 },
601 { 2048, 1536, 60, 0 },
605 * Probably taken from CEA-861 spec.
606 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
608 static const struct drm_display_mode edid_cea_modes[] = {
609 /* 1 - 640x480@60Hz */
610 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
611 752, 800, 0, 480, 490, 492, 525, 0,
612 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
613 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
614 /* 2 - 720x480@60Hz */
615 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
616 798, 858, 0, 480, 489, 495, 525, 0,
617 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
618 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
619 /* 3 - 720x480@60Hz */
620 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
621 798, 858, 0, 480, 489, 495, 525, 0,
622 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
623 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
624 /* 4 - 1280x720@60Hz */
625 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
626 1430, 1650, 0, 720, 725, 730, 750, 0,
627 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
628 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
629 /* 5 - 1920x1080i@60Hz */
630 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
631 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
632 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
633 DRM_MODE_FLAG_INTERLACE),
634 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
635 /* 6 - 720(1440)x480i@60Hz */
636 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
637 801, 858, 0, 480, 488, 494, 525, 0,
638 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
639 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
640 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
641 /* 7 - 720(1440)x480i@60Hz */
642 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
643 801, 858, 0, 480, 488, 494, 525, 0,
644 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
645 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
646 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
647 /* 8 - 720(1440)x240@60Hz */
648 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
649 801, 858, 0, 240, 244, 247, 262, 0,
650 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
651 DRM_MODE_FLAG_DBLCLK),
652 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
653 /* 9 - 720(1440)x240@60Hz */
654 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
655 801, 858, 0, 240, 244, 247, 262, 0,
656 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
657 DRM_MODE_FLAG_DBLCLK),
658 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
659 /* 10 - 2880x480i@60Hz */
660 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
661 3204, 3432, 0, 480, 488, 494, 525, 0,
662 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
663 DRM_MODE_FLAG_INTERLACE),
664 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
665 /* 11 - 2880x480i@60Hz */
666 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
667 3204, 3432, 0, 480, 488, 494, 525, 0,
668 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
669 DRM_MODE_FLAG_INTERLACE),
670 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
671 /* 12 - 2880x240@60Hz */
672 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
673 3204, 3432, 0, 240, 244, 247, 262, 0,
674 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
675 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
676 /* 13 - 2880x240@60Hz */
677 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
678 3204, 3432, 0, 240, 244, 247, 262, 0,
679 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
680 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
681 /* 14 - 1440x480@60Hz */
682 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
683 1596, 1716, 0, 480, 489, 495, 525, 0,
684 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
685 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
686 /* 15 - 1440x480@60Hz */
687 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
688 1596, 1716, 0, 480, 489, 495, 525, 0,
689 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
690 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
691 /* 16 - 1920x1080@60Hz */
692 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
693 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
694 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
695 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
696 /* 17 - 720x576@50Hz */
697 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
698 796, 864, 0, 576, 581, 586, 625, 0,
699 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
700 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
701 /* 18 - 720x576@50Hz */
702 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
703 796, 864, 0, 576, 581, 586, 625, 0,
704 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
705 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
706 /* 19 - 1280x720@50Hz */
707 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
708 1760, 1980, 0, 720, 725, 730, 750, 0,
709 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
710 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
711 /* 20 - 1920x1080i@50Hz */
712 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
713 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
714 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
715 DRM_MODE_FLAG_INTERLACE),
716 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
717 /* 21 - 720(1440)x576i@50Hz */
718 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
719 795, 864, 0, 576, 580, 586, 625, 0,
720 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
721 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
722 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
723 /* 22 - 720(1440)x576i@50Hz */
724 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
725 795, 864, 0, 576, 580, 586, 625, 0,
726 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
727 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
728 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
729 /* 23 - 720(1440)x288@50Hz */
730 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
731 795, 864, 0, 288, 290, 293, 312, 0,
732 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
733 DRM_MODE_FLAG_DBLCLK),
734 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
735 /* 24 - 720(1440)x288@50Hz */
736 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
737 795, 864, 0, 288, 290, 293, 312, 0,
738 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
739 DRM_MODE_FLAG_DBLCLK),
740 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
741 /* 25 - 2880x576i@50Hz */
742 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
743 3180, 3456, 0, 576, 580, 586, 625, 0,
744 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
745 DRM_MODE_FLAG_INTERLACE),
746 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
747 /* 26 - 2880x576i@50Hz */
748 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
749 3180, 3456, 0, 576, 580, 586, 625, 0,
750 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
751 DRM_MODE_FLAG_INTERLACE),
752 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
753 /* 27 - 2880x288@50Hz */
754 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
755 3180, 3456, 0, 288, 290, 293, 312, 0,
756 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
757 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
758 /* 28 - 2880x288@50Hz */
759 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
760 3180, 3456, 0, 288, 290, 293, 312, 0,
761 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
762 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
763 /* 29 - 1440x576@50Hz */
764 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
765 1592, 1728, 0, 576, 581, 586, 625, 0,
766 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
767 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
768 /* 30 - 1440x576@50Hz */
769 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
770 1592, 1728, 0, 576, 581, 586, 625, 0,
771 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
772 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
773 /* 31 - 1920x1080@50Hz */
774 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
775 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
776 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
777 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
778 /* 32 - 1920x1080@24Hz */
779 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
780 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
781 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
782 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
783 /* 33 - 1920x1080@25Hz */
784 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
785 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
786 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
787 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
788 /* 34 - 1920x1080@30Hz */
789 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
790 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
791 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
792 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
793 /* 35 - 2880x480@60Hz */
794 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
795 3192, 3432, 0, 480, 489, 495, 525, 0,
796 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
797 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
798 /* 36 - 2880x480@60Hz */
799 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
800 3192, 3432, 0, 480, 489, 495, 525, 0,
801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
802 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
803 /* 37 - 2880x576@50Hz */
804 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
805 3184, 3456, 0, 576, 581, 586, 625, 0,
806 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
807 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
808 /* 38 - 2880x576@50Hz */
809 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
810 3184, 3456, 0, 576, 581, 586, 625, 0,
811 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
812 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
813 /* 39 - 1920x1080i@50Hz */
814 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
815 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
816 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
817 DRM_MODE_FLAG_INTERLACE),
818 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
819 /* 40 - 1920x1080i@100Hz */
820 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
821 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
822 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
823 DRM_MODE_FLAG_INTERLACE),
824 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
825 /* 41 - 1280x720@100Hz */
826 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
827 1760, 1980, 0, 720, 725, 730, 750, 0,
828 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
829 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
830 /* 42 - 720x576@100Hz */
831 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
832 796, 864, 0, 576, 581, 586, 625, 0,
833 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
834 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
835 /* 43 - 720x576@100Hz */
836 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
837 796, 864, 0, 576, 581, 586, 625, 0,
838 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
839 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
840 /* 44 - 720(1440)x576i@100Hz */
841 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
842 795, 864, 0, 576, 580, 586, 625, 0,
843 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
844 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
845 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
846 /* 45 - 720(1440)x576i@100Hz */
847 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
848 795, 864, 0, 576, 580, 586, 625, 0,
849 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
850 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
851 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
852 /* 46 - 1920x1080i@120Hz */
853 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
854 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
855 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
856 DRM_MODE_FLAG_INTERLACE),
857 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
858 /* 47 - 1280x720@120Hz */
859 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
860 1430, 1650, 0, 720, 725, 730, 750, 0,
861 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
862 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
863 /* 48 - 720x480@120Hz */
864 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
865 798, 858, 0, 480, 489, 495, 525, 0,
866 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
867 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
868 /* 49 - 720x480@120Hz */
869 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
870 798, 858, 0, 480, 489, 495, 525, 0,
871 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
872 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
873 /* 50 - 720(1440)x480i@120Hz */
874 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
875 801, 858, 0, 480, 488, 494, 525, 0,
876 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
877 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
878 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
879 /* 51 - 720(1440)x480i@120Hz */
880 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
881 801, 858, 0, 480, 488, 494, 525, 0,
882 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
883 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
884 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
885 /* 52 - 720x576@200Hz */
886 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
887 796, 864, 0, 576, 581, 586, 625, 0,
888 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
889 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
890 /* 53 - 720x576@200Hz */
891 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
892 796, 864, 0, 576, 581, 586, 625, 0,
893 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
894 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
895 /* 54 - 720(1440)x576i@200Hz */
896 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 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 = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
901 /* 55 - 720(1440)x576i@200Hz */
902 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
903 795, 864, 0, 576, 580, 586, 625, 0,
904 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
905 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
906 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
907 /* 56 - 720x480@240Hz */
908 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
909 798, 858, 0, 480, 489, 495, 525, 0,
910 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
911 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
912 /* 57 - 720x480@240Hz */
913 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
914 798, 858, 0, 480, 489, 495, 525, 0,
915 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
916 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
917 /* 58 - 720(1440)x480i@240 */
918 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
919 801, 858, 0, 480, 488, 494, 525, 0,
920 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
921 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
922 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
923 /* 59 - 720(1440)x480i@240 */
924 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
925 801, 858, 0, 480, 488, 494, 525, 0,
926 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
927 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
928 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
929 /* 60 - 1280x720@24Hz */
930 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
931 3080, 3300, 0, 720, 725, 730, 750, 0,
932 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
933 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
934 /* 61 - 1280x720@25Hz */
935 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
936 3740, 3960, 0, 720, 725, 730, 750, 0,
937 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
938 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
939 /* 62 - 1280x720@30Hz */
940 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
941 3080, 3300, 0, 720, 725, 730, 750, 0,
942 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
943 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
944 /* 63 - 1920x1080@120Hz */
945 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
946 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
947 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
948 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
949 /* 64 - 1920x1080@100Hz */
950 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
951 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
952 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
953 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
959 static const struct drm_display_mode edid_4k_modes[] = {
960 /* 1 - 3840x2160@30Hz */
961 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
962 3840, 4016, 4104, 4400, 0,
963 2160, 2168, 2178, 2250, 0,
964 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
966 /* 2 - 3840x2160@25Hz */
967 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
968 3840, 4896, 4984, 5280, 0,
969 2160, 2168, 2178, 2250, 0,
970 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
972 /* 3 - 3840x2160@24Hz */
973 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
974 3840, 5116, 5204, 5500, 0,
975 2160, 2168, 2178, 2250, 0,
976 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
978 /* 4 - 4096x2160@24Hz (SMPTE) */
979 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
980 4096, 5116, 5204, 5500, 0,
981 2160, 2168, 2178, 2250, 0,
982 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
986 /*** DDC fetch and block validation ***/
988 static const u8 edid_header[] = {
989 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
993 * drm_edid_header_is_valid - sanity check the header of the base EDID block
994 * @raw_edid: pointer to raw base EDID block
996 * Sanity check the header of the base EDID block.
998 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
1000 int drm_edid_header_is_valid(const u8 *raw_edid)
1004 for (i = 0; i < sizeof(edid_header); i++)
1005 if (raw_edid[i] == edid_header[i])
1010 EXPORT_SYMBOL(drm_edid_header_is_valid);
1012 static int edid_fixup __read_mostly = 6;
1013 module_param_named(edid_fixup, edid_fixup, int, 0400);
1014 MODULE_PARM_DESC(edid_fixup,
1015 "Minimum number of valid EDID header bytes (0-8, default 6)");
1018 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1019 * @raw_edid: pointer to raw EDID block
1020 * @block: type of block to validate (0 for base, extension otherwise)
1021 * @print_bad_edid: if true, dump bad EDID blocks to the console
1023 * Validate a base or extension EDID block and optionally dump bad blocks to
1026 * Return: True if the block is valid, false otherwise.
1028 bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid)
1032 struct edid *edid = (struct edid *)raw_edid;
1034 if (WARN_ON(!raw_edid))
1037 if (edid_fixup > 8 || edid_fixup < 0)
1041 int score = drm_edid_header_is_valid(raw_edid);
1043 else if (score >= edid_fixup) {
1044 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1045 memcpy(raw_edid, edid_header, sizeof(edid_header));
1051 for (i = 0; i < EDID_LENGTH; i++)
1052 csum += raw_edid[i];
1054 if (print_bad_edid) {
1055 DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
1058 /* allow CEA to slide through, switches mangle this */
1059 if (raw_edid[0] != 0x02)
1063 /* per-block-type checks */
1064 switch (raw_edid[0]) {
1066 if (edid->version != 1) {
1067 DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
1071 if (edid->revision > 4)
1072 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1082 if (print_bad_edid) {
1083 printk(KERN_ERR "Raw EDID:\n");
1084 print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
1085 raw_edid, EDID_LENGTH, false);
1089 EXPORT_SYMBOL(drm_edid_block_valid);
1092 * drm_edid_is_valid - sanity check EDID data
1095 * Sanity-check an entire EDID record (including extensions)
1097 * Return: True if the EDID data is valid, false otherwise.
1099 bool drm_edid_is_valid(struct edid *edid)
1102 u8 *raw = (u8 *)edid;
1107 for (i = 0; i <= edid->extensions; i++)
1108 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true))
1113 EXPORT_SYMBOL(drm_edid_is_valid);
1115 #define DDC_SEGMENT_ADDR 0x30
1117 * drm_do_probe_ddc_edid() - get EDID information via I2C
1118 * @adapter: I2C device adaptor
1119 * @buf: EDID data buffer to be filled
1120 * @block: 128 byte EDID block to start fetching from
1121 * @len: EDID data buffer length to fetch
1123 * Try to fetch EDID information by calling I2C driver functions.
1125 * Return: 0 on success or -1 on failure.
1128 drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
1130 struct i2c_adapter *adapter = data;
1131 unsigned char start = block * EDID_LENGTH;
1132 unsigned char segment = block >> 1;
1133 unsigned char xfers = segment ? 3 : 2;
1134 int ret, retries = 5;
1137 * The core I2C driver will automatically retry the transfer if the
1138 * adapter reports EAGAIN. However, we find that bit-banging transfers
1139 * are susceptible to errors under a heavily loaded machine and
1140 * generate spurious NAKs and timeouts. Retrying the transfer
1141 * of the individual block a few times seems to overcome this.
1144 struct i2c_msg msgs[] = {
1146 .addr = DDC_SEGMENT_ADDR,
1164 * Avoid sending the segment addr to not upset non-compliant
1167 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1169 if (ret == -ENXIO) {
1170 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1174 } while (ret != xfers && --retries);
1176 return ret == xfers ? 0 : -1;
1179 static bool drm_edid_is_zero(u8 *in_edid, int length)
1181 if (memchr_inv(in_edid, 0, length))
1188 * drm_do_get_edid - get EDID data using a custom EDID block read function
1189 * @connector: connector we're probing
1190 * @get_edid_block: EDID block read function
1191 * @data: private data passed to the block read function
1193 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1194 * exposes a different interface to read EDID blocks this function can be used
1195 * to get EDID data using a custom block read function.
1197 * As in the general case the DDC bus is accessible by the kernel at the I2C
1198 * level, drivers must make all reasonable efforts to expose it as an I2C
1199 * adapter and use drm_get_edid() instead of abusing this function.
1201 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1203 struct edid *drm_do_get_edid(struct drm_connector *connector,
1204 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1208 int i, j = 0, valid_extensions = 0;
1210 bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
1212 if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
1215 /* base block fetch */
1216 for (i = 0; i < 4; i++) {
1217 if (get_edid_block(data, block, 0, EDID_LENGTH))
1219 if (drm_edid_block_valid(block, 0, print_bad_edid))
1221 if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
1222 connector->null_edid_counter++;
1229 /* if there's no extensions, we're done */
1230 if (block[0x7e] == 0)
1231 return (struct edid *)block;
1233 new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
1238 for (j = 1; j <= block[0x7e]; j++) {
1239 for (i = 0; i < 4; i++) {
1240 if (get_edid_block(data,
1241 block + (valid_extensions + 1) * EDID_LENGTH,
1244 if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH, j, print_bad_edid)) {
1250 if (i == 4 && print_bad_edid) {
1251 dev_warn(connector->dev->dev,
1252 "%s: Ignoring invalid EDID block %d.\n",
1253 connector->name, j);
1255 connector->bad_edid_counter++;
1259 if (valid_extensions != block[0x7e]) {
1260 block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
1261 block[0x7e] = valid_extensions;
1262 new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1268 return (struct edid *)block;
1271 if (print_bad_edid) {
1272 dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
1273 connector->name, j);
1275 connector->bad_edid_counter++;
1281 EXPORT_SYMBOL_GPL(drm_do_get_edid);
1284 * drm_probe_ddc() - probe DDC presence
1285 * @adapter: I2C adapter to probe
1287 * Return: True on success, false on failure.
1290 drm_probe_ddc(struct i2c_adapter *adapter)
1294 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1296 EXPORT_SYMBOL(drm_probe_ddc);
1299 * drm_get_edid - get EDID data, if available
1300 * @connector: connector we're probing
1301 * @adapter: I2C adapter to use for DDC
1303 * Poke the given I2C channel to grab EDID data if possible. If found,
1304 * attach it to the connector.
1306 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1308 struct edid *drm_get_edid(struct drm_connector *connector,
1309 struct i2c_adapter *adapter)
1311 if (!drm_probe_ddc(adapter))
1314 return drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1316 EXPORT_SYMBOL(drm_get_edid);
1319 * drm_edid_duplicate - duplicate an EDID and the extensions
1320 * @edid: EDID to duplicate
1322 * Return: Pointer to duplicated EDID or NULL on allocation failure.
1324 struct edid *drm_edid_duplicate(const struct edid *edid)
1326 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1328 EXPORT_SYMBOL(drm_edid_duplicate);
1330 /*** EDID parsing ***/
1333 * edid_vendor - match a string against EDID's obfuscated vendor field
1334 * @edid: EDID to match
1335 * @vendor: vendor string
1337 * Returns true if @vendor is in @edid, false otherwise
1339 static bool edid_vendor(struct edid *edid, char *vendor)
1341 char edid_vendor[3];
1343 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1344 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1345 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
1346 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
1348 return !strncmp(edid_vendor, vendor, 3);
1352 * edid_get_quirks - return quirk flags for a given EDID
1353 * @edid: EDID to process
1355 * This tells subsequent routines what fixes they need to apply.
1357 static u32 edid_get_quirks(struct edid *edid)
1359 struct edid_quirk *quirk;
1362 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1363 quirk = &edid_quirk_list[i];
1365 if (edid_vendor(edid, quirk->vendor) &&
1366 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1367 return quirk->quirks;
1373 #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
1374 #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
1377 * edid_fixup_preferred - set preferred modes based on quirk list
1378 * @connector: has mode list to fix up
1379 * @quirks: quirks list
1381 * Walk the mode list for @connector, clearing the preferred status
1382 * on existing modes and setting it anew for the right mode ala @quirks.
1384 static void edid_fixup_preferred(struct drm_connector *connector,
1387 struct drm_display_mode *t, *cur_mode, *preferred_mode;
1388 int target_refresh = 0;
1389 int cur_vrefresh, preferred_vrefresh;
1391 if (list_empty(&connector->probed_modes))
1394 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1395 target_refresh = 60;
1396 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1397 target_refresh = 75;
1399 preferred_mode = list_first_entry(&connector->probed_modes,
1400 struct drm_display_mode, head);
1402 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1403 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1405 if (cur_mode == preferred_mode)
1408 /* Largest mode is preferred */
1409 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1410 preferred_mode = cur_mode;
1412 cur_vrefresh = cur_mode->vrefresh ?
1413 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1414 preferred_vrefresh = preferred_mode->vrefresh ?
1415 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
1416 /* At a given size, try to get closest to target refresh */
1417 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
1418 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1419 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
1420 preferred_mode = cur_mode;
1424 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1428 mode_is_rb(const struct drm_display_mode *mode)
1430 return (mode->htotal - mode->hdisplay == 160) &&
1431 (mode->hsync_end - mode->hdisplay == 80) &&
1432 (mode->hsync_end - mode->hsync_start == 32) &&
1433 (mode->vsync_start - mode->vdisplay == 3);
1437 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1438 * @dev: Device to duplicate against
1439 * @hsize: Mode width
1440 * @vsize: Mode height
1441 * @fresh: Mode refresh rate
1442 * @rb: Mode reduced-blanking-ness
1444 * Walk the DMT mode list looking for a match for the given parameters.
1446 * Return: A newly allocated copy of the mode, or NULL if not found.
1448 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1449 int hsize, int vsize, int fresh,
1454 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
1455 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
1456 if (hsize != ptr->hdisplay)
1458 if (vsize != ptr->vdisplay)
1460 if (fresh != drm_mode_vrefresh(ptr))
1462 if (rb != mode_is_rb(ptr))
1465 return drm_mode_duplicate(dev, ptr);
1470 EXPORT_SYMBOL(drm_mode_find_dmt);
1472 typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1475 cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1479 u8 *det_base = ext + d;
1482 for (i = 0; i < n; i++)
1483 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1487 vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1489 unsigned int i, n = min((int)ext[0x02], 6);
1490 u8 *det_base = ext + 5;
1493 return; /* unknown version */
1495 for (i = 0; i < n; i++)
1496 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1500 drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1503 struct edid *edid = (struct edid *)raw_edid;
1508 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1509 cb(&(edid->detailed_timings[i]), closure);
1511 for (i = 1; i <= raw_edid[0x7e]; i++) {
1512 u8 *ext = raw_edid + (i * EDID_LENGTH);
1515 cea_for_each_detailed_block(ext, cb, closure);
1518 vtb_for_each_detailed_block(ext, cb, closure);
1527 is_rb(struct detailed_timing *t, void *data)
1530 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1532 *(bool *)data = true;
1535 /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1537 drm_monitor_supports_rb(struct edid *edid)
1539 if (edid->revision >= 4) {
1541 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1545 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1549 find_gtf2(struct detailed_timing *t, void *data)
1552 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1556 /* Secondary GTF curve kicks in above some break frequency */
1558 drm_gtf2_hbreak(struct edid *edid)
1561 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1562 return r ? (r[12] * 2) : 0;
1566 drm_gtf2_2c(struct edid *edid)
1569 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1570 return r ? r[13] : 0;
1574 drm_gtf2_m(struct edid *edid)
1577 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1578 return r ? (r[15] << 8) + r[14] : 0;
1582 drm_gtf2_k(struct edid *edid)
1585 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1586 return r ? r[16] : 0;
1590 drm_gtf2_2j(struct edid *edid)
1593 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1594 return r ? r[17] : 0;
1598 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1599 * @edid: EDID block to scan
1601 static int standard_timing_level(struct edid *edid)
1603 if (edid->revision >= 2) {
1604 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1606 if (drm_gtf2_hbreak(edid))
1614 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1615 * monitors fill with ascii space (0x20) instead.
1618 bad_std_timing(u8 a, u8 b)
1620 return (a == 0x00 && b == 0x00) ||
1621 (a == 0x01 && b == 0x01) ||
1622 (a == 0x20 && b == 0x20);
1626 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
1627 * @connector: connector of for the EDID block
1628 * @edid: EDID block to scan
1629 * @t: standard timing params
1631 * Take the standard timing params (in this case width, aspect, and refresh)
1632 * and convert them into a real mode using CVT/GTF/DMT.
1634 static struct drm_display_mode *
1635 drm_mode_std(struct drm_connector *connector, struct edid *edid,
1636 struct std_timing *t)
1638 struct drm_device *dev = connector->dev;
1639 struct drm_display_mode *m, *mode = NULL;
1642 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
1643 >> EDID_TIMING_ASPECT_SHIFT;
1644 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
1645 >> EDID_TIMING_VFREQ_SHIFT;
1646 int timing_level = standard_timing_level(edid);
1648 if (bad_std_timing(t->hsize, t->vfreq_aspect))
1651 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1652 hsize = t->hsize * 8 + 248;
1653 /* vrefresh_rate = vfreq + 60 */
1654 vrefresh_rate = vfreq + 60;
1655 /* the vdisplay is calculated based on the aspect ratio */
1656 if (aspect_ratio == 0) {
1657 if (edid->revision < 3)
1660 vsize = (hsize * 10) / 16;
1661 } else if (aspect_ratio == 1)
1662 vsize = (hsize * 3) / 4;
1663 else if (aspect_ratio == 2)
1664 vsize = (hsize * 4) / 5;
1666 vsize = (hsize * 9) / 16;
1668 /* HDTV hack, part 1 */
1669 if (vrefresh_rate == 60 &&
1670 ((hsize == 1360 && vsize == 765) ||
1671 (hsize == 1368 && vsize == 769))) {
1677 * If this connector already has a mode for this size and refresh
1678 * rate (because it came from detailed or CVT info), use that
1679 * instead. This way we don't have to guess at interlace or
1682 list_for_each_entry(m, &connector->probed_modes, head)
1683 if (m->hdisplay == hsize && m->vdisplay == vsize &&
1684 drm_mode_vrefresh(m) == vrefresh_rate)
1687 /* HDTV hack, part 2 */
1688 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
1689 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
1691 mode->hdisplay = 1366;
1692 mode->hsync_start = mode->hsync_start - 1;
1693 mode->hsync_end = mode->hsync_end - 1;
1697 /* check whether it can be found in default mode table */
1698 if (drm_monitor_supports_rb(edid)) {
1699 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
1704 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
1708 /* okay, generate it */
1709 switch (timing_level) {
1713 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
1717 * This is potentially wrong if there's ever a monitor with
1718 * more than one ranges section, each claiming a different
1719 * secondary GTF curve. Please don't do that.
1721 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
1724 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
1725 drm_mode_destroy(dev, mode);
1726 mode = drm_gtf_mode_complex(dev, hsize, vsize,
1727 vrefresh_rate, 0, 0,
1735 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
1743 * EDID is delightfully ambiguous about how interlaced modes are to be
1744 * encoded. Our internal representation is of frame height, but some
1745 * HDTV detailed timings are encoded as field height.
1747 * The format list here is from CEA, in frame size. Technically we
1748 * should be checking refresh rate too. Whatever.
1751 drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
1752 struct detailed_pixel_timing *pt)
1755 static const struct {
1757 } cea_interlaced[] = {
1767 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
1770 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
1771 if ((mode->hdisplay == cea_interlaced[i].w) &&
1772 (mode->vdisplay == cea_interlaced[i].h / 2)) {
1773 mode->vdisplay *= 2;
1774 mode->vsync_start *= 2;
1775 mode->vsync_end *= 2;
1781 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1785 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1786 * @dev: DRM device (needed to create new mode)
1788 * @timing: EDID detailed timing info
1789 * @quirks: quirks to apply
1791 * An EDID detailed timing block contains enough info for us to create and
1792 * return a new struct drm_display_mode.
1794 static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1796 struct detailed_timing *timing,
1799 struct drm_display_mode *mode;
1800 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
1801 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
1802 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
1803 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
1804 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
1805 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
1806 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
1807 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
1808 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
1810 /* ignore tiny modes */
1811 if (hactive < 64 || vactive < 64)
1814 if (pt->misc & DRM_EDID_PT_STEREO) {
1815 DRM_DEBUG_KMS("stereo mode not supported\n");
1818 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
1819 DRM_DEBUG_KMS("composite sync not supported\n");
1822 /* it is incorrect if hsync/vsync width is zero */
1823 if (!hsync_pulse_width || !vsync_pulse_width) {
1824 DRM_DEBUG_KMS("Incorrect Detailed timing. "
1825 "Wrong Hsync/Vsync pulse width\n");
1829 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
1830 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
1837 mode = drm_mode_create(dev);
1841 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
1842 timing->pixel_clock = cpu_to_le16(1088);
1844 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
1846 mode->hdisplay = hactive;
1847 mode->hsync_start = mode->hdisplay + hsync_offset;
1848 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
1849 mode->htotal = mode->hdisplay + hblank;
1851 mode->vdisplay = vactive;
1852 mode->vsync_start = mode->vdisplay + vsync_offset;
1853 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
1854 mode->vtotal = mode->vdisplay + vblank;
1856 /* Some EDIDs have bogus h/vtotal values */
1857 if (mode->hsync_end > mode->htotal)
1858 mode->htotal = mode->hsync_end + 1;
1859 if (mode->vsync_end > mode->vtotal)
1860 mode->vtotal = mode->vsync_end + 1;
1862 drm_mode_do_interlace_quirk(mode, pt);
1864 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
1865 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
1868 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
1869 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
1870 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
1871 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
1874 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
1875 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
1877 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
1878 mode->width_mm *= 10;
1879 mode->height_mm *= 10;
1882 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
1883 mode->width_mm = edid->width_cm * 10;
1884 mode->height_mm = edid->height_cm * 10;
1887 mode->type = DRM_MODE_TYPE_DRIVER;
1888 mode->vrefresh = drm_mode_vrefresh(mode);
1889 drm_mode_set_name(mode);
1895 mode_in_hsync_range(const struct drm_display_mode *mode,
1896 struct edid *edid, u8 *t)
1898 int hsync, hmin, hmax;
1901 if (edid->revision >= 4)
1902 hmin += ((t[4] & 0x04) ? 255 : 0);
1904 if (edid->revision >= 4)
1905 hmax += ((t[4] & 0x08) ? 255 : 0);
1906 hsync = drm_mode_hsync(mode);
1908 return (hsync <= hmax && hsync >= hmin);
1912 mode_in_vsync_range(const struct drm_display_mode *mode,
1913 struct edid *edid, u8 *t)
1915 int vsync, vmin, vmax;
1918 if (edid->revision >= 4)
1919 vmin += ((t[4] & 0x01) ? 255 : 0);
1921 if (edid->revision >= 4)
1922 vmax += ((t[4] & 0x02) ? 255 : 0);
1923 vsync = drm_mode_vrefresh(mode);
1925 return (vsync <= vmax && vsync >= vmin);
1929 range_pixel_clock(struct edid *edid, u8 *t)
1932 if (t[9] == 0 || t[9] == 255)
1935 /* 1.4 with CVT support gives us real precision, yay */
1936 if (edid->revision >= 4 && t[10] == 0x04)
1937 return (t[9] * 10000) - ((t[12] >> 2) * 250);
1939 /* 1.3 is pathetic, so fuzz up a bit */
1940 return t[9] * 10000 + 5001;
1944 mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
1945 struct detailed_timing *timing)
1948 u8 *t = (u8 *)timing;
1950 if (!mode_in_hsync_range(mode, edid, t))
1953 if (!mode_in_vsync_range(mode, edid, t))
1956 if ((max_clock = range_pixel_clock(edid, t)))
1957 if (mode->clock > max_clock)
1960 /* 1.4 max horizontal check */
1961 if (edid->revision >= 4 && t[10] == 0x04)
1962 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
1965 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
1971 static bool valid_inferred_mode(const struct drm_connector *connector,
1972 const struct drm_display_mode *mode)
1974 struct drm_display_mode *m;
1977 list_for_each_entry(m, &connector->probed_modes, head) {
1978 if (mode->hdisplay == m->hdisplay &&
1979 mode->vdisplay == m->vdisplay &&
1980 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
1981 return false; /* duplicated */
1982 if (mode->hdisplay <= m->hdisplay &&
1983 mode->vdisplay <= m->vdisplay)
1990 drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
1991 struct detailed_timing *timing)
1994 struct drm_display_mode *newmode;
1995 struct drm_device *dev = connector->dev;
1997 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
1998 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
1999 valid_inferred_mode(connector, drm_dmt_modes + i)) {
2000 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2002 drm_mode_probed_add(connector, newmode);
2011 /* fix up 1366x768 mode from 1368x768;
2012 * GFT/CVT can't express 1366 width which isn't dividable by 8
2014 static void fixup_mode_1366x768(struct drm_display_mode *mode)
2016 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2017 mode->hdisplay = 1366;
2018 mode->hsync_start--;
2020 drm_mode_set_name(mode);
2025 drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2026 struct detailed_timing *timing)
2029 struct drm_display_mode *newmode;
2030 struct drm_device *dev = connector->dev;
2032 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
2033 const struct minimode *m = &extra_modes[i];
2034 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
2038 fixup_mode_1366x768(newmode);
2039 if (!mode_in_range(newmode, edid, timing) ||
2040 !valid_inferred_mode(connector, newmode)) {
2041 drm_mode_destroy(dev, newmode);
2045 drm_mode_probed_add(connector, newmode);
2053 drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2054 struct detailed_timing *timing)
2057 struct drm_display_mode *newmode;
2058 struct drm_device *dev = connector->dev;
2059 bool rb = drm_monitor_supports_rb(edid);
2061 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
2062 const struct minimode *m = &extra_modes[i];
2063 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
2067 fixup_mode_1366x768(newmode);
2068 if (!mode_in_range(newmode, edid, timing) ||
2069 !valid_inferred_mode(connector, newmode)) {
2070 drm_mode_destroy(dev, newmode);
2074 drm_mode_probed_add(connector, newmode);
2082 do_inferred_modes(struct detailed_timing *timing, void *c)
2084 struct detailed_mode_closure *closure = c;
2085 struct detailed_non_pixel *data = &timing->data.other_data;
2086 struct detailed_data_monitor_range *range = &data->data.range;
2088 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2091 closure->modes += drm_dmt_modes_for_range(closure->connector,
2095 if (!version_greater(closure->edid, 1, 1))
2096 return; /* GTF not defined yet */
2098 switch (range->flags) {
2099 case 0x02: /* secondary gtf, XXX could do more */
2100 case 0x00: /* default gtf */
2101 closure->modes += drm_gtf_modes_for_range(closure->connector,
2105 case 0x04: /* cvt, only in 1.4+ */
2106 if (!version_greater(closure->edid, 1, 3))
2109 closure->modes += drm_cvt_modes_for_range(closure->connector,
2113 case 0x01: /* just the ranges, no formula */
2120 add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2122 struct detailed_mode_closure closure = {
2123 .connector = connector,
2127 if (version_greater(edid, 1, 0))
2128 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2131 return closure.modes;
2135 drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2137 int i, j, m, modes = 0;
2138 struct drm_display_mode *mode;
2139 u8 *est = ((u8 *)timing) + 5;
2141 for (i = 0; i < 6; i++) {
2142 for (j = 7; j >= 0; j--) {
2143 m = (i * 8) + (7 - j);
2144 if (m >= ARRAY_SIZE(est3_modes))
2146 if (est[i] & (1 << j)) {
2147 mode = drm_mode_find_dmt(connector->dev,
2153 drm_mode_probed_add(connector, mode);
2164 do_established_modes(struct detailed_timing *timing, void *c)
2166 struct detailed_mode_closure *closure = c;
2167 struct detailed_non_pixel *data = &timing->data.other_data;
2169 if (data->type == EDID_DETAIL_EST_TIMINGS)
2170 closure->modes += drm_est3_modes(closure->connector, timing);
2174 * add_established_modes - get est. modes from EDID and add them
2175 * @connector: connector to add mode(s) to
2176 * @edid: EDID block to scan
2178 * Each EDID block contains a bitmap of the supported "established modes" list
2179 * (defined above). Tease them out and add them to the global modes list.
2182 add_established_modes(struct drm_connector *connector, struct edid *edid)
2184 struct drm_device *dev = connector->dev;
2185 unsigned long est_bits = edid->established_timings.t1 |
2186 (edid->established_timings.t2 << 8) |
2187 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2189 struct detailed_mode_closure closure = {
2190 .connector = connector,
2194 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2195 if (est_bits & (1<<i)) {
2196 struct drm_display_mode *newmode;
2197 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2199 drm_mode_probed_add(connector, newmode);
2205 if (version_greater(edid, 1, 0))
2206 drm_for_each_detailed_block((u8 *)edid,
2207 do_established_modes, &closure);
2209 return modes + closure.modes;
2213 do_standard_modes(struct detailed_timing *timing, void *c)
2215 struct detailed_mode_closure *closure = c;
2216 struct detailed_non_pixel *data = &timing->data.other_data;
2217 struct drm_connector *connector = closure->connector;
2218 struct edid *edid = closure->edid;
2220 if (data->type == EDID_DETAIL_STD_MODES) {
2222 for (i = 0; i < 6; i++) {
2223 struct std_timing *std;
2224 struct drm_display_mode *newmode;
2226 std = &data->data.timings[i];
2227 newmode = drm_mode_std(connector, edid, std);
2229 drm_mode_probed_add(connector, newmode);
2237 * add_standard_modes - get std. modes from EDID and add them
2238 * @connector: connector to add mode(s) to
2239 * @edid: EDID block to scan
2241 * Standard modes can be calculated using the appropriate standard (DMT,
2242 * GTF or CVT. Grab them from @edid and add them to the list.
2245 add_standard_modes(struct drm_connector *connector, struct edid *edid)
2248 struct detailed_mode_closure closure = {
2249 .connector = connector,
2253 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2254 struct drm_display_mode *newmode;
2256 newmode = drm_mode_std(connector, edid,
2257 &edid->standard_timings[i]);
2259 drm_mode_probed_add(connector, newmode);
2264 if (version_greater(edid, 1, 0))
2265 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2268 /* XXX should also look for standard codes in VTB blocks */
2270 return modes + closure.modes;
2273 static int drm_cvt_modes(struct drm_connector *connector,
2274 struct detailed_timing *timing)
2276 int i, j, modes = 0;
2277 struct drm_display_mode *newmode;
2278 struct drm_device *dev = connector->dev;
2279 struct cvt_timing *cvt;
2280 const int rates[] = { 60, 85, 75, 60, 50 };
2281 const u8 empty[3] = { 0, 0, 0 };
2283 for (i = 0; i < 4; i++) {
2284 int uninitialized_var(width), height;
2285 cvt = &(timing->data.other_data.data.cvt[i]);
2287 if (!memcmp(cvt->code, empty, 3))
2290 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
2291 switch (cvt->code[1] & 0x0c) {
2293 width = height * 4 / 3;
2296 width = height * 16 / 9;
2299 width = height * 16 / 10;
2302 width = height * 15 / 9;
2306 for (j = 1; j < 5; j++) {
2307 if (cvt->code[2] & (1 << j)) {
2308 newmode = drm_cvt_mode(dev, width, height,
2312 drm_mode_probed_add(connector, newmode);
2323 do_cvt_mode(struct detailed_timing *timing, void *c)
2325 struct detailed_mode_closure *closure = c;
2326 struct detailed_non_pixel *data = &timing->data.other_data;
2328 if (data->type == EDID_DETAIL_CVT_3BYTE)
2329 closure->modes += drm_cvt_modes(closure->connector, timing);
2333 add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2335 struct detailed_mode_closure closure = {
2336 .connector = connector,
2340 if (version_greater(edid, 1, 2))
2341 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
2343 /* XXX should also look for CVT codes in VTB blocks */
2345 return closure.modes;
2349 do_detailed_mode(struct detailed_timing *timing, void *c)
2351 struct detailed_mode_closure *closure = c;
2352 struct drm_display_mode *newmode;
2354 if (timing->pixel_clock) {
2355 newmode = drm_mode_detailed(closure->connector->dev,
2356 closure->edid, timing,
2361 if (closure->preferred)
2362 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2364 drm_mode_probed_add(closure->connector, newmode);
2366 closure->preferred = 0;
2371 * add_detailed_modes - Add modes from detailed timings
2372 * @connector: attached connector
2373 * @edid: EDID block to scan
2374 * @quirks: quirks to apply
2377 add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2380 struct detailed_mode_closure closure = {
2381 .connector = connector,
2387 if (closure.preferred && !version_greater(edid, 1, 3))
2389 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
2391 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
2393 return closure.modes;
2396 #define AUDIO_BLOCK 0x01
2397 #define VIDEO_BLOCK 0x02
2398 #define VENDOR_BLOCK 0x03
2399 #define SPEAKER_BLOCK 0x04
2400 #define VIDEO_CAPABILITY_BLOCK 0x07
2401 #define EDID_BASIC_AUDIO (1 << 6)
2402 #define EDID_CEA_YCRCB444 (1 << 5)
2403 #define EDID_CEA_YCRCB422 (1 << 4)
2404 #define EDID_CEA_VCDB_QS (1 << 6)
2407 * Search EDID for CEA extension block.
2409 static u8 *drm_find_cea_extension(struct edid *edid)
2411 u8 *edid_ext = NULL;
2414 /* No EDID or EDID extensions */
2415 if (edid == NULL || edid->extensions == 0)
2418 /* Find CEA extension */
2419 for (i = 0; i < edid->extensions; i++) {
2420 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
2421 if (edid_ext[0] == CEA_EXT)
2425 if (i == edid->extensions)
2432 * Calculate the alternate clock for the CEA mode
2433 * (60Hz vs. 59.94Hz etc.)
2436 cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2438 unsigned int clock = cea_mode->clock;
2440 if (cea_mode->vrefresh % 6 != 0)
2444 * edid_cea_modes contains the 59.94Hz
2445 * variant for 240 and 480 line modes,
2446 * and the 60Hz variant otherwise.
2448 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
2449 clock = clock * 1001 / 1000;
2451 clock = DIV_ROUND_UP(clock * 1000, 1001);
2457 * drm_match_cea_mode - look for a CEA mode matching given mode
2458 * @to_match: display mode
2460 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
2463 u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
2467 if (!to_match->clock)
2470 for (mode = 0; mode < ARRAY_SIZE(edid_cea_modes); mode++) {
2471 const struct drm_display_mode *cea_mode = &edid_cea_modes[mode];
2472 unsigned int clock1, clock2;
2474 /* Check both 60Hz and 59.94Hz */
2475 clock1 = cea_mode->clock;
2476 clock2 = cea_mode_alternate_clock(cea_mode);
2478 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2479 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
2480 drm_mode_equal_no_clocks_no_stereo(to_match, cea_mode))
2485 EXPORT_SYMBOL(drm_match_cea_mode);
2488 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2489 * the input VIC from the CEA mode list
2490 * @video_code: ID given to each of the CEA modes
2492 * Returns picture aspect ratio
2494 enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2496 /* return picture aspect ratio for video_code - 1 to access the
2497 * right array element
2499 return edid_cea_modes[video_code-1].picture_aspect_ratio;
2501 EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2504 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2507 * It's almost like cea_mode_alternate_clock(), we just need to add an
2508 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2512 hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
2514 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
2515 return hdmi_mode->clock;
2517 return cea_mode_alternate_clock(hdmi_mode);
2521 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2522 * @to_match: display mode
2524 * An HDMI mode is one defined in the HDMI vendor specific block.
2526 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2528 static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
2532 if (!to_match->clock)
2535 for (mode = 0; mode < ARRAY_SIZE(edid_4k_modes); mode++) {
2536 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[mode];
2537 unsigned int clock1, clock2;
2539 /* Make sure to also match alternate clocks */
2540 clock1 = hdmi_mode->clock;
2541 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
2543 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2544 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
2545 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
2552 add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
2554 struct drm_device *dev = connector->dev;
2555 struct drm_display_mode *mode, *tmp;
2559 /* Don't add CEA modes if the CEA extension block is missing */
2560 if (!drm_find_cea_extension(edid))
2564 * Go through all probed modes and create a new mode
2565 * with the alternate clock for certain CEA modes.
2567 list_for_each_entry(mode, &connector->probed_modes, head) {
2568 const struct drm_display_mode *cea_mode = NULL;
2569 struct drm_display_mode *newmode;
2570 u8 mode_idx = drm_match_cea_mode(mode) - 1;
2571 unsigned int clock1, clock2;
2573 if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
2574 cea_mode = &edid_cea_modes[mode_idx];
2575 clock2 = cea_mode_alternate_clock(cea_mode);
2577 mode_idx = drm_match_hdmi_mode(mode) - 1;
2578 if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
2579 cea_mode = &edid_4k_modes[mode_idx];
2580 clock2 = hdmi_mode_alternate_clock(cea_mode);
2587 clock1 = cea_mode->clock;
2589 if (clock1 == clock2)
2592 if (mode->clock != clock1 && mode->clock != clock2)
2595 newmode = drm_mode_duplicate(dev, cea_mode);
2599 /* Carry over the stereo flags */
2600 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
2603 * The current mode could be either variant. Make
2604 * sure to pick the "other" clock for the new mode.
2606 if (mode->clock != clock1)
2607 newmode->clock = clock1;
2609 newmode->clock = clock2;
2611 list_add_tail(&newmode->head, &list);
2614 list_for_each_entry_safe(mode, tmp, &list, head) {
2615 list_del(&mode->head);
2616 drm_mode_probed_add(connector, mode);
2623 static struct drm_display_mode *
2624 drm_display_mode_from_vic_index(struct drm_connector *connector,
2625 const u8 *video_db, u8 video_len,
2628 struct drm_device *dev = connector->dev;
2629 struct drm_display_mode *newmode;
2632 if (video_db == NULL || video_index >= video_len)
2635 /* CEA modes are numbered 1..127 */
2636 cea_mode = (video_db[video_index] & 127) - 1;
2637 if (cea_mode >= ARRAY_SIZE(edid_cea_modes))
2640 newmode = drm_mode_duplicate(dev, &edid_cea_modes[cea_mode]);
2644 newmode->vrefresh = 0;
2650 do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
2654 for (i = 0; i < len; i++) {
2655 struct drm_display_mode *mode;
2656 mode = drm_display_mode_from_vic_index(connector, db, len, i);
2658 drm_mode_probed_add(connector, mode);
2666 struct stereo_mandatory_mode {
2667 int width, height, vrefresh;
2671 static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
2672 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2673 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
2675 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
2677 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
2678 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2679 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
2680 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2681 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
2685 stereo_match_mandatory(const struct drm_display_mode *mode,
2686 const struct stereo_mandatory_mode *stereo_mode)
2688 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
2690 return mode->hdisplay == stereo_mode->width &&
2691 mode->vdisplay == stereo_mode->height &&
2692 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
2693 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
2696 static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
2698 struct drm_device *dev = connector->dev;
2699 const struct drm_display_mode *mode;
2700 struct list_head stereo_modes;
2703 INIT_LIST_HEAD(&stereo_modes);
2705 list_for_each_entry(mode, &connector->probed_modes, head) {
2706 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
2707 const struct stereo_mandatory_mode *mandatory;
2708 struct drm_display_mode *new_mode;
2710 if (!stereo_match_mandatory(mode,
2711 &stereo_mandatory_modes[i]))
2714 mandatory = &stereo_mandatory_modes[i];
2715 new_mode = drm_mode_duplicate(dev, mode);
2719 new_mode->flags |= mandatory->flags;
2720 list_add_tail(&new_mode->head, &stereo_modes);
2725 list_splice_tail(&stereo_modes, &connector->probed_modes);
2730 static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
2732 struct drm_device *dev = connector->dev;
2733 struct drm_display_mode *newmode;
2735 vic--; /* VICs start at 1 */
2736 if (vic >= ARRAY_SIZE(edid_4k_modes)) {
2737 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
2741 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
2745 drm_mode_probed_add(connector, newmode);
2750 static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
2751 const u8 *video_db, u8 video_len, u8 video_index)
2753 struct drm_display_mode *newmode;
2756 if (structure & (1 << 0)) {
2757 newmode = drm_display_mode_from_vic_index(connector, video_db,
2761 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
2762 drm_mode_probed_add(connector, newmode);
2766 if (structure & (1 << 6)) {
2767 newmode = drm_display_mode_from_vic_index(connector, video_db,
2771 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2772 drm_mode_probed_add(connector, newmode);
2776 if (structure & (1 << 8)) {
2777 newmode = drm_display_mode_from_vic_index(connector, video_db,
2781 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
2782 drm_mode_probed_add(connector, newmode);
2791 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
2792 * @connector: connector corresponding to the HDMI sink
2793 * @db: start of the CEA vendor specific block
2794 * @len: length of the CEA block payload, ie. one can access up to db[len]
2796 * Parses the HDMI VSDB looking for modes to add to @connector. This function
2797 * also adds the stereo 3d modes when applicable.
2800 do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
2801 const u8 *video_db, u8 video_len)
2803 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
2804 u8 vic_len, hdmi_3d_len = 0;
2811 /* no HDMI_Video_Present */
2812 if (!(db[8] & (1 << 5)))
2815 /* Latency_Fields_Present */
2816 if (db[8] & (1 << 7))
2819 /* I_Latency_Fields_Present */
2820 if (db[8] & (1 << 6))
2823 /* the declared length is not long enough for the 2 first bytes
2824 * of additional video format capabilities */
2825 if (len < (8 + offset + 2))
2830 if (db[8 + offset] & (1 << 7)) {
2831 modes += add_hdmi_mandatory_stereo_modes(connector);
2833 /* 3D_Multi_present */
2834 multi_present = (db[8 + offset] & 0x60) >> 5;
2838 vic_len = db[8 + offset] >> 5;
2839 hdmi_3d_len = db[8 + offset] & 0x1f;
2841 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
2844 vic = db[9 + offset + i];
2845 modes += add_hdmi_mode(connector, vic);
2847 offset += 1 + vic_len;
2849 if (multi_present == 1)
2851 else if (multi_present == 2)
2856 if (len < (8 + offset + hdmi_3d_len - 1))
2859 if (hdmi_3d_len < multi_len)
2862 if (multi_present == 1 || multi_present == 2) {
2863 /* 3D_Structure_ALL */
2864 structure_all = (db[8 + offset] << 8) | db[9 + offset];
2866 /* check if 3D_MASK is present */
2867 if (multi_present == 2)
2868 mask = (db[10 + offset] << 8) | db[11 + offset];
2872 for (i = 0; i < 16; i++) {
2873 if (mask & (1 << i))
2874 modes += add_3d_struct_modes(connector,
2881 offset += multi_len;
2883 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
2885 struct drm_display_mode *newmode = NULL;
2886 unsigned int newflag = 0;
2887 bool detail_present;
2889 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
2891 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
2894 /* 2D_VIC_order_X */
2895 vic_index = db[8 + offset + i] >> 4;
2897 /* 3D_Structure_X */
2898 switch (db[8 + offset + i] & 0x0f) {
2900 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
2903 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2907 if ((db[9 + offset + i] >> 4) == 1)
2908 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
2913 newmode = drm_display_mode_from_vic_index(connector,
2919 newmode->flags |= newflag;
2920 drm_mode_probed_add(connector, newmode);
2934 cea_db_payload_len(const u8 *db)
2936 return db[0] & 0x1f;
2940 cea_db_tag(const u8 *db)
2946 cea_revision(const u8 *cea)
2952 cea_db_offsets(const u8 *cea, int *start, int *end)
2954 /* Data block offset in CEA extension block */
2959 if (*end < 4 || *end > 127)
2964 static bool cea_db_is_hdmi_vsdb(const u8 *db)
2968 if (cea_db_tag(db) != VENDOR_BLOCK)
2971 if (cea_db_payload_len(db) < 5)
2974 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
2976 return hdmi_id == HDMI_IEEE_OUI;
2979 #define for_each_cea_db(cea, i, start, end) \
2980 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
2983 add_cea_modes(struct drm_connector *connector, struct edid *edid)
2985 const u8 *cea = drm_find_cea_extension(edid);
2986 const u8 *db, *hdmi = NULL, *video = NULL;
2987 u8 dbl, hdmi_len, video_len = 0;
2990 if (cea && cea_revision(cea) >= 3) {
2993 if (cea_db_offsets(cea, &start, &end))
2996 for_each_cea_db(cea, i, start, end) {
2998 dbl = cea_db_payload_len(db);
3000 if (cea_db_tag(db) == VIDEO_BLOCK) {
3003 modes += do_cea_modes(connector, video, dbl);
3005 else if (cea_db_is_hdmi_vsdb(db)) {
3013 * We parse the HDMI VSDB after having added the cea modes as we will
3014 * be patching their flags when the sink supports stereo 3D.
3017 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3024 parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
3026 u8 len = cea_db_payload_len(db);
3029 connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
3030 connector->dvi_dual = db[6] & 1;
3033 connector->max_tmds_clock = db[7] * 5;
3035 connector->latency_present[0] = db[8] >> 7;
3036 connector->latency_present[1] = (db[8] >> 6) & 1;
3039 connector->video_latency[0] = db[9];
3041 connector->audio_latency[0] = db[10];
3043 connector->video_latency[1] = db[11];
3045 connector->audio_latency[1] = db[12];
3047 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
3048 "max TMDS clock %d, "
3049 "latency present %d %d, "
3050 "video latency %d %d, "
3051 "audio latency %d %d\n",
3052 connector->dvi_dual,
3053 connector->max_tmds_clock,
3054 (int) connector->latency_present[0],
3055 (int) connector->latency_present[1],
3056 connector->video_latency[0],
3057 connector->video_latency[1],
3058 connector->audio_latency[0],
3059 connector->audio_latency[1]);
3063 monitor_name(struct detailed_timing *t, void *data)
3065 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3066 *(u8 **)data = t->data.other_data.data.str.str;
3070 * drm_edid_to_eld - build ELD from EDID
3071 * @connector: connector corresponding to the HDMI/DP sink
3072 * @edid: EDID to parse
3074 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3075 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3078 void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
3080 uint8_t *eld = connector->eld;
3088 memset(eld, 0, sizeof(connector->eld));
3090 cea = drm_find_cea_extension(edid);
3092 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3097 drm_for_each_detailed_block((u8 *)edid, monitor_name, &name);
3098 for (mnl = 0; name && mnl < 13; mnl++) {
3099 if (name[mnl] == 0x0a)
3101 eld[20 + mnl] = name[mnl];
3103 eld[4] = (cea[1] << 5) | mnl;
3104 DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
3106 eld[0] = 2 << 3; /* ELD version: 2 */
3108 eld[16] = edid->mfg_id[0];
3109 eld[17] = edid->mfg_id[1];
3110 eld[18] = edid->prod_code[0];
3111 eld[19] = edid->prod_code[1];
3113 if (cea_revision(cea) >= 3) {
3116 if (cea_db_offsets(cea, &start, &end)) {
3121 for_each_cea_db(cea, i, start, end) {
3123 dbl = cea_db_payload_len(db);
3125 switch (cea_db_tag(db)) {
3127 /* Audio Data Block, contains SADs */
3128 sad_count = dbl / 3;
3130 memcpy(eld + 20 + mnl, &db[1], dbl);
3133 /* Speaker Allocation Data Block */
3138 /* HDMI Vendor-Specific Data Block */
3139 if (cea_db_is_hdmi_vsdb(db))
3140 parse_hdmi_vsdb(connector, db);
3147 eld[5] |= sad_count << 4;
3149 eld[DRM_ELD_BASELINE_ELD_LEN] =
3150 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
3152 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
3153 drm_eld_size(eld), sad_count);
3155 EXPORT_SYMBOL(drm_edid_to_eld);
3158 * drm_edid_to_sad - extracts SADs from EDID
3159 * @edid: EDID to parse
3160 * @sads: pointer that will be set to the extracted SADs
3162 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
3164 * Note: The returned pointer needs to be freed using kfree().
3166 * Return: The number of found SADs or negative number on error.
3168 int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3171 int i, start, end, dbl;
3174 cea = drm_find_cea_extension(edid);
3176 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3180 if (cea_revision(cea) < 3) {
3181 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3185 if (cea_db_offsets(cea, &start, &end)) {
3186 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3190 for_each_cea_db(cea, i, start, end) {
3193 if (cea_db_tag(db) == AUDIO_BLOCK) {
3195 dbl = cea_db_payload_len(db);
3197 count = dbl / 3; /* SAD is 3B */
3198 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3201 for (j = 0; j < count; j++) {
3202 u8 *sad = &db[1 + j * 3];
3204 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3205 (*sads)[j].channels = sad[0] & 0x7;
3206 (*sads)[j].freq = sad[1] & 0x7F;
3207 (*sads)[j].byte2 = sad[2];
3215 EXPORT_SYMBOL(drm_edid_to_sad);
3218 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3219 * @edid: EDID to parse
3220 * @sadb: pointer to the speaker block
3222 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
3224 * Note: The returned pointer needs to be freed using kfree().
3226 * Return: The number of found Speaker Allocation Blocks or negative number on
3229 int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
3232 int i, start, end, dbl;
3235 cea = drm_find_cea_extension(edid);
3237 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3241 if (cea_revision(cea) < 3) {
3242 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3246 if (cea_db_offsets(cea, &start, &end)) {
3247 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3251 for_each_cea_db(cea, i, start, end) {
3252 const u8 *db = &cea[i];
3254 if (cea_db_tag(db) == SPEAKER_BLOCK) {
3255 dbl = cea_db_payload_len(db);
3257 /* Speaker Allocation Data Block */
3259 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
3270 EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
3273 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
3274 * @connector: connector associated with the HDMI/DP sink
3275 * @mode: the display mode
3277 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3278 * the sink doesn't support audio or video.
3280 int drm_av_sync_delay(struct drm_connector *connector,
3281 struct drm_display_mode *mode)
3283 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
3286 if (!connector->latency_present[0])
3288 if (!connector->latency_present[1])
3291 a = connector->audio_latency[i];
3292 v = connector->video_latency[i];
3295 * HDMI/DP sink doesn't support audio or video?
3297 if (a == 255 || v == 255)
3301 * Convert raw EDID values to millisecond.
3302 * Treat unknown latency as 0ms.
3305 a = min(2 * (a - 1), 500);
3307 v = min(2 * (v - 1), 500);
3309 return max(v - a, 0);
3311 EXPORT_SYMBOL(drm_av_sync_delay);
3314 * drm_select_eld - select one ELD from multiple HDMI/DP sinks
3315 * @encoder: the encoder just changed display mode
3316 * @mode: the adjusted display mode
3318 * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
3319 * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
3321 * Return: The connector associated with the first HDMI/DP sink that has ELD
3324 struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
3325 struct drm_display_mode *mode)
3327 struct drm_connector *connector;
3328 struct drm_device *dev = encoder->dev;
3330 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
3331 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
3333 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
3334 if (connector->encoder == encoder && connector->eld[0])
3339 EXPORT_SYMBOL(drm_select_eld);
3342 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
3343 * @edid: monitor EDID information
3345 * Parse the CEA extension according to CEA-861-B.
3347 * Return: True if the monitor is HDMI, false if not or unknown.
3349 bool drm_detect_hdmi_monitor(struct edid *edid)
3353 int start_offset, end_offset;
3355 edid_ext = drm_find_cea_extension(edid);
3359 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3363 * Because HDMI identifier is in Vendor Specific Block,
3364 * search it from all data blocks of CEA extension.
3366 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3367 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
3373 EXPORT_SYMBOL(drm_detect_hdmi_monitor);
3376 * drm_detect_monitor_audio - check monitor audio capability
3377 * @edid: EDID block to scan
3379 * Monitor should have CEA extension block.
3380 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3381 * audio' only. If there is any audio extension block and supported
3382 * audio format, assume at least 'basic audio' support, even if 'basic
3383 * audio' is not defined in EDID.
3385 * Return: True if the monitor supports audio, false otherwise.
3387 bool drm_detect_monitor_audio(struct edid *edid)
3391 bool has_audio = false;
3392 int start_offset, end_offset;
3394 edid_ext = drm_find_cea_extension(edid);
3398 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
3401 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3405 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3408 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3409 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
3411 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
3412 DRM_DEBUG_KMS("CEA audio format %d\n",
3413 (edid_ext[i + j] >> 3) & 0xf);
3420 EXPORT_SYMBOL(drm_detect_monitor_audio);
3423 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
3424 * @edid: EDID block to scan
3426 * Check whether the monitor reports the RGB quantization range selection
3427 * as supported. The AVI infoframe can then be used to inform the monitor
3428 * which quantization range (full or limited) is used.
3430 * Return: True if the RGB quantization range is selectable, false otherwise.
3432 bool drm_rgb_quant_range_selectable(struct edid *edid)
3437 edid_ext = drm_find_cea_extension(edid);
3441 if (cea_db_offsets(edid_ext, &start, &end))
3444 for_each_cea_db(edid_ext, i, start, end) {
3445 if (cea_db_tag(&edid_ext[i]) == VIDEO_CAPABILITY_BLOCK &&
3446 cea_db_payload_len(&edid_ext[i]) == 2) {
3447 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
3448 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
3454 EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
3457 * drm_assign_hdmi_deep_color_info - detect whether monitor supports
3458 * hdmi deep color modes and update drm_display_info if so.
3459 * @edid: monitor EDID information
3460 * @info: Updated with maximum supported deep color bpc and color format
3461 * if deep color supported.
3462 * @connector: DRM connector, used only for debug output
3464 * Parse the CEA extension according to CEA-861-B.
3465 * Return true if HDMI deep color supported, false if not or unknown.
3467 static bool drm_assign_hdmi_deep_color_info(struct edid *edid,
3468 struct drm_display_info *info,
3469 struct drm_connector *connector)
3471 u8 *edid_ext, *hdmi;
3473 int start_offset, end_offset;
3474 unsigned int dc_bpc = 0;
3476 edid_ext = drm_find_cea_extension(edid);
3480 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3484 * Because HDMI identifier is in Vendor Specific Block,
3485 * search it from all data blocks of CEA extension.
3487 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3488 if (cea_db_is_hdmi_vsdb(&edid_ext[i])) {
3489 /* HDMI supports at least 8 bpc */
3492 hdmi = &edid_ext[i];
3493 if (cea_db_payload_len(hdmi) < 6)
3496 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
3498 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
3499 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
3503 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
3505 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
3506 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
3510 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
3512 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
3513 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
3518 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
3519 connector->name, dc_bpc);
3523 * Deep color support mandates RGB444 support for all video
3524 * modes and forbids YCRCB422 support for all video modes per
3527 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3529 /* YCRCB444 is optional according to spec. */
3530 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
3531 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3532 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
3537 * Spec says that if any deep color mode is supported at all,
3538 * then deep color 36 bit must be supported.
3540 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
3541 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
3548 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
3558 * drm_add_display_info - pull display info out if present
3560 * @info: display info (attached to connector)
3561 * @connector: connector whose edid is used to build display info
3563 * Grab any available display info and stuff it into the drm_display_info
3564 * structure that's part of the connector. Useful for tracking bpp and
3567 static void drm_add_display_info(struct edid *edid,
3568 struct drm_display_info *info,
3569 struct drm_connector *connector)
3573 info->width_mm = edid->width_cm * 10;
3574 info->height_mm = edid->height_cm * 10;
3576 /* driver figures it out in this case */
3578 info->color_formats = 0;
3580 if (edid->revision < 3)
3583 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
3586 /* Get data from CEA blocks if present */
3587 edid_ext = drm_find_cea_extension(edid);
3589 info->cea_rev = edid_ext[1];
3591 /* The existence of a CEA block should imply RGB support */
3592 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3593 if (edid_ext[3] & EDID_CEA_YCRCB444)
3594 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3595 if (edid_ext[3] & EDID_CEA_YCRCB422)
3596 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
3599 /* HDMI deep color modes supported? Assign to info, if so */
3600 drm_assign_hdmi_deep_color_info(edid, info, connector);
3602 /* Only defined for 1.4 with digital displays */
3603 if (edid->revision < 4)
3606 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
3607 case DRM_EDID_DIGITAL_DEPTH_6:
3610 case DRM_EDID_DIGITAL_DEPTH_8:
3613 case DRM_EDID_DIGITAL_DEPTH_10:
3616 case DRM_EDID_DIGITAL_DEPTH_12:
3619 case DRM_EDID_DIGITAL_DEPTH_14:
3622 case DRM_EDID_DIGITAL_DEPTH_16:
3625 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
3631 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
3632 connector->name, info->bpc);
3634 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
3635 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
3636 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3637 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
3638 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
3642 * drm_add_edid_modes - add modes from EDID data, if available
3643 * @connector: connector we're probing
3646 * Add the specified modes to the connector's mode list.
3648 * Return: The number of modes added or 0 if we couldn't find any.
3650 int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
3658 if (!drm_edid_is_valid(edid)) {
3659 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
3664 quirks = edid_get_quirks(edid);
3667 * EDID spec says modes should be preferred in this order:
3668 * - preferred detailed mode
3669 * - other detailed modes from base block
3670 * - detailed modes from extension blocks
3671 * - CVT 3-byte code modes
3672 * - standard timing codes
3673 * - established timing codes
3674 * - modes inferred from GTF or CVT range information
3676 * We get this pretty much right.
3678 * XXX order for additional mode types in extension blocks?
3680 num_modes += add_detailed_modes(connector, edid, quirks);
3681 num_modes += add_cvt_modes(connector, edid);
3682 num_modes += add_standard_modes(connector, edid);
3683 num_modes += add_established_modes(connector, edid);
3684 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
3685 num_modes += add_inferred_modes(connector, edid);
3686 num_modes += add_cea_modes(connector, edid);
3687 num_modes += add_alternate_cea_modes(connector, edid);
3689 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
3690 edid_fixup_preferred(connector, quirks);
3692 drm_add_display_info(edid, &connector->display_info, connector);
3694 if (quirks & EDID_QUIRK_FORCE_8BPC)
3695 connector->display_info.bpc = 8;
3697 if (quirks & EDID_QUIRK_FORCE_12BPC)
3698 connector->display_info.bpc = 12;
3702 EXPORT_SYMBOL(drm_add_edid_modes);
3705 * drm_add_modes_noedid - add modes for the connectors without EDID
3706 * @connector: connector we're probing
3707 * @hdisplay: the horizontal display limit
3708 * @vdisplay: the vertical display limit
3710 * Add the specified modes to the connector's mode list. Only when the
3711 * hdisplay/vdisplay is not beyond the given limit, it will be added.
3713 * Return: The number of modes added or 0 if we couldn't find any.
3715 int drm_add_modes_noedid(struct drm_connector *connector,
3716 int hdisplay, int vdisplay)
3718 int i, count, num_modes = 0;
3719 struct drm_display_mode *mode;
3720 struct drm_device *dev = connector->dev;
3722 count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
3728 for (i = 0; i < count; i++) {
3729 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
3730 if (hdisplay && vdisplay) {
3732 * Only when two are valid, they will be used to check
3733 * whether the mode should be added to the mode list of
3736 if (ptr->hdisplay > hdisplay ||
3737 ptr->vdisplay > vdisplay)
3740 if (drm_mode_vrefresh(ptr) > 61)
3742 mode = drm_mode_duplicate(dev, ptr);
3744 drm_mode_probed_add(connector, mode);
3750 EXPORT_SYMBOL(drm_add_modes_noedid);
3753 * drm_set_preferred_mode - Sets the preferred mode of a connector
3754 * @connector: connector whose mode list should be processed
3755 * @hpref: horizontal resolution of preferred mode
3756 * @vpref: vertical resolution of preferred mode
3758 * Marks a mode as preferred if it matches the resolution specified by @hpref
3761 void drm_set_preferred_mode(struct drm_connector *connector,
3762 int hpref, int vpref)
3764 struct drm_display_mode *mode;
3766 list_for_each_entry(mode, &connector->probed_modes, head) {
3767 if (mode->hdisplay == hpref &&
3768 mode->vdisplay == vpref)
3769 mode->type |= DRM_MODE_TYPE_PREFERRED;
3772 EXPORT_SYMBOL(drm_set_preferred_mode);
3775 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
3776 * data from a DRM display mode
3777 * @frame: HDMI AVI infoframe
3778 * @mode: DRM display mode
3780 * Return: 0 on success or a negative error code on failure.
3783 drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
3784 const struct drm_display_mode *mode)
3788 if (!frame || !mode)
3791 err = hdmi_avi_infoframe_init(frame);
3795 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
3796 frame->pixel_repeat = 1;
3798 frame->video_code = drm_match_cea_mode(mode);
3800 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
3803 * Populate picture aspect ratio from either
3804 * user input (if specified) or from the CEA mode list.
3806 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
3807 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
3808 frame->picture_aspect = mode->picture_aspect_ratio;
3809 else if (frame->video_code > 0)
3810 frame->picture_aspect = drm_get_cea_aspect_ratio(
3813 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
3814 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
3818 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
3820 static enum hdmi_3d_structure
3821 s3d_structure_from_display_mode(const struct drm_display_mode *mode)
3823 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
3826 case DRM_MODE_FLAG_3D_FRAME_PACKING:
3827 return HDMI_3D_STRUCTURE_FRAME_PACKING;
3828 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
3829 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
3830 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
3831 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
3832 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
3833 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
3834 case DRM_MODE_FLAG_3D_L_DEPTH:
3835 return HDMI_3D_STRUCTURE_L_DEPTH;
3836 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
3837 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
3838 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
3839 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
3840 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
3841 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
3843 return HDMI_3D_STRUCTURE_INVALID;
3848 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
3849 * data from a DRM display mode
3850 * @frame: HDMI vendor infoframe
3851 * @mode: DRM display mode
3853 * Note that there's is a need to send HDMI vendor infoframes only when using a
3854 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
3855 * function will return -EINVAL, error that can be safely ignored.
3857 * Return: 0 on success or a negative error code on failure.
3860 drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
3861 const struct drm_display_mode *mode)
3867 if (!frame || !mode)
3870 vic = drm_match_hdmi_mode(mode);
3871 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
3873 if (!vic && !s3d_flags)
3876 if (vic && s3d_flags)
3879 err = hdmi_vendor_infoframe_init(frame);
3886 frame->s3d_struct = s3d_structure_from_display_mode(mode);
3890 EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);