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.
32 #include <linux/kernel.h>
33 #include <linux/hdmi.h>
34 #include <linux/i2c.h>
35 #include <linux/module.h>
36 #include <linux/vga_switcheroo.h>
38 #include <drm/drm_edid.h>
39 #include <drm/drm_displayid.h>
40 #include <linux/string.h>
42 #include <bus/iicbus/iic.h>
43 #include <bus/iicbus/iiconf.h>
44 #include "iicbus_if.h"
46 #define version_greater(edid, maj, min) \
47 (((edid)->version > (maj)) || \
48 ((edid)->version == (maj) && (edid)->revision > (min)))
50 #define EDID_EST_TIMINGS 16
51 #define EDID_STD_TIMINGS 8
52 #define EDID_DETAILED_TIMINGS 4
55 * EDID blocks out in the wild have a variety of bugs, try to collect
56 * them here (note that userspace may work around broken monitors first,
57 * but fixes should make their way here so that the kernel "just works"
58 * on as many displays as possible).
61 /* First detailed mode wrong, use largest 60Hz mode */
62 #define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
63 /* Reported 135MHz pixel clock is too high, needs adjustment */
64 #define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
65 /* Prefer the largest mode at 75 Hz */
66 #define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
67 /* Detail timing is in cm not mm */
68 #define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
69 /* Detailed timing descriptors have bogus size values, so just take the
70 * maximum size and use that.
72 #define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
73 /* Monitor forgot to set the first detailed is preferred bit. */
74 #define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
75 /* use +hsync +vsync for detailed mode */
76 #define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
77 /* Force reduced-blanking timings for detailed modes */
78 #define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
80 #define EDID_QUIRK_FORCE_8BPC (1 << 8)
82 #define EDID_QUIRK_FORCE_12BPC (1 << 9)
84 #define EDID_QUIRK_FORCE_6BPC (1 << 10)
86 struct detailed_mode_closure
{
87 struct drm_connector
*connector
;
99 static struct edid_quirk
{
103 } edid_quirk_list
[] = {
105 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60
},
107 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60
},
109 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
111 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
112 { "AEO", 0, EDID_QUIRK_FORCE_6BPC
},
114 /* Belinea 10 15 55 */
115 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60
},
116 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60
},
118 /* Envision Peripherals, Inc. EN-7100e */
119 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH
},
120 /* Envision EN2028 */
121 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60
},
123 /* Funai Electronics PM36B */
124 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75
|
125 EDID_QUIRK_DETAILED_IN_CM
},
127 /* LG Philips LCD LP154W01-A5 */
128 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
},
129 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
},
131 /* Philips 107p5 CRT */
132 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
135 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED
},
137 /* Samsung SyncMaster 205BW. Note: irony */
138 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP
},
139 /* Samsung SyncMaster 22[5-6]BW */
140 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60
},
141 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60
},
143 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
144 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC
},
146 /* ViewSonic VA2026w */
147 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING
},
149 /* Medion MD 30217 PG */
150 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75
},
152 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
153 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC
},
157 * Autogenerated from the DMT spec.
158 * This table is copied from xfree86/modes/xf86EdidModes.c.
160 static const struct drm_display_mode drm_dmt_modes
[] = {
161 /* 0x01 - 640x350@85Hz */
162 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER
, 31500, 640, 672,
163 736, 832, 0, 350, 382, 385, 445, 0,
164 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
165 /* 0x02 - 640x400@85Hz */
166 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER
, 31500, 640, 672,
167 736, 832, 0, 400, 401, 404, 445, 0,
168 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
169 /* 0x03 - 720x400@85Hz */
170 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 35500, 720, 756,
171 828, 936, 0, 400, 401, 404, 446, 0,
172 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
173 /* 0x04 - 640x480@60Hz */
174 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
175 752, 800, 0, 480, 490, 492, 525, 0,
176 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
177 /* 0x05 - 640x480@72Hz */
178 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 664,
179 704, 832, 0, 480, 489, 492, 520, 0,
180 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
181 /* 0x06 - 640x480@75Hz */
182 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 656,
183 720, 840, 0, 480, 481, 484, 500, 0,
184 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
185 /* 0x07 - 640x480@85Hz */
186 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 36000, 640, 696,
187 752, 832, 0, 480, 481, 484, 509, 0,
188 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
189 /* 0x08 - 800x600@56Hz */
190 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 36000, 800, 824,
191 896, 1024, 0, 600, 601, 603, 625, 0,
192 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
193 /* 0x09 - 800x600@60Hz */
194 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 40000, 800, 840,
195 968, 1056, 0, 600, 601, 605, 628, 0,
196 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
197 /* 0x0a - 800x600@72Hz */
198 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 50000, 800, 856,
199 976, 1040, 0, 600, 637, 643, 666, 0,
200 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
201 /* 0x0b - 800x600@75Hz */
202 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 49500, 800, 816,
203 896, 1056, 0, 600, 601, 604, 625, 0,
204 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
205 /* 0x0c - 800x600@85Hz */
206 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 56250, 800, 832,
207 896, 1048, 0, 600, 601, 604, 631, 0,
208 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
209 /* 0x0d - 800x600@120Hz RB */
210 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 73250, 800, 848,
211 880, 960, 0, 600, 603, 607, 636, 0,
212 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
213 /* 0x0e - 848x480@60Hz */
214 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER
, 33750, 848, 864,
215 976, 1088, 0, 480, 486, 494, 517, 0,
216 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
217 /* 0x0f - 1024x768@43Hz, interlace */
218 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER
, 44900, 1024, 1032,
219 1208, 1264, 0, 768, 768, 776, 817, 0,
220 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
221 DRM_MODE_FLAG_INTERLACE
) },
222 /* 0x10 - 1024x768@60Hz */
223 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
224 1184, 1344, 0, 768, 771, 777, 806, 0,
225 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
226 /* 0x11 - 1024x768@70Hz */
227 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 75000, 1024, 1048,
228 1184, 1328, 0, 768, 771, 777, 806, 0,
229 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
230 /* 0x12 - 1024x768@75Hz */
231 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 78750, 1024, 1040,
232 1136, 1312, 0, 768, 769, 772, 800, 0,
233 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
234 /* 0x13 - 1024x768@85Hz */
235 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 94500, 1024, 1072,
236 1168, 1376, 0, 768, 769, 772, 808, 0,
237 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
238 /* 0x14 - 1024x768@120Hz RB */
239 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 115500, 1024, 1072,
240 1104, 1184, 0, 768, 771, 775, 813, 0,
241 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
242 /* 0x15 - 1152x864@75Hz */
243 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER
, 108000, 1152, 1216,
244 1344, 1600, 0, 864, 865, 868, 900, 0,
245 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
246 /* 0x55 - 1280x720@60Hz */
247 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1390,
248 1430, 1650, 0, 720, 725, 730, 750, 0,
249 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
250 /* 0x16 - 1280x768@60Hz RB */
251 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 68250, 1280, 1328,
252 1360, 1440, 0, 768, 771, 778, 790, 0,
253 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
254 /* 0x17 - 1280x768@60Hz */
255 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 79500, 1280, 1344,
256 1472, 1664, 0, 768, 771, 778, 798, 0,
257 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
258 /* 0x18 - 1280x768@75Hz */
259 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 102250, 1280, 1360,
260 1488, 1696, 0, 768, 771, 778, 805, 0,
261 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
262 /* 0x19 - 1280x768@85Hz */
263 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 117500, 1280, 1360,
264 1496, 1712, 0, 768, 771, 778, 809, 0,
265 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
266 /* 0x1a - 1280x768@120Hz RB */
267 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER
, 140250, 1280, 1328,
268 1360, 1440, 0, 768, 771, 778, 813, 0,
269 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
270 /* 0x1b - 1280x800@60Hz RB */
271 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 71000, 1280, 1328,
272 1360, 1440, 0, 800, 803, 809, 823, 0,
273 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
274 /* 0x1c - 1280x800@60Hz */
275 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 83500, 1280, 1352,
276 1480, 1680, 0, 800, 803, 809, 831, 0,
277 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
278 /* 0x1d - 1280x800@75Hz */
279 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 106500, 1280, 1360,
280 1488, 1696, 0, 800, 803, 809, 838, 0,
281 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
282 /* 0x1e - 1280x800@85Hz */
283 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 122500, 1280, 1360,
284 1496, 1712, 0, 800, 803, 809, 843, 0,
285 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
286 /* 0x1f - 1280x800@120Hz RB */
287 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER
, 146250, 1280, 1328,
288 1360, 1440, 0, 800, 803, 809, 847, 0,
289 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
290 /* 0x20 - 1280x960@60Hz */
291 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1376,
292 1488, 1800, 0, 960, 961, 964, 1000, 0,
293 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
294 /* 0x21 - 1280x960@85Hz */
295 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1344,
296 1504, 1728, 0, 960, 961, 964, 1011, 0,
297 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
298 /* 0x22 - 1280x960@120Hz RB */
299 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER
, 175500, 1280, 1328,
300 1360, 1440, 0, 960, 963, 967, 1017, 0,
301 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
302 /* 0x23 - 1280x1024@60Hz */
303 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 108000, 1280, 1328,
304 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
305 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
306 /* 0x24 - 1280x1024@75Hz */
307 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 135000, 1280, 1296,
308 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
309 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
310 /* 0x25 - 1280x1024@85Hz */
311 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 157500, 1280, 1344,
312 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
313 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
314 /* 0x26 - 1280x1024@120Hz RB */
315 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 187250, 1280, 1328,
316 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
317 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
318 /* 0x27 - 1360x768@60Hz */
319 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER
, 85500, 1360, 1424,
320 1536, 1792, 0, 768, 771, 777, 795, 0,
321 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
322 /* 0x28 - 1360x768@120Hz RB */
323 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER
, 148250, 1360, 1408,
324 1440, 1520, 0, 768, 771, 776, 813, 0,
325 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
326 /* 0x51 - 1366x768@60Hz */
327 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER
, 85500, 1366, 1436,
328 1579, 1792, 0, 768, 771, 774, 798, 0,
329 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
330 /* 0x56 - 1366x768@60Hz */
331 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER
, 72000, 1366, 1380,
332 1436, 1500, 0, 768, 769, 772, 800, 0,
333 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
334 /* 0x29 - 1400x1050@60Hz RB */
335 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 101000, 1400, 1448,
336 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
337 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
338 /* 0x2a - 1400x1050@60Hz */
339 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 121750, 1400, 1488,
340 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
341 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
342 /* 0x2b - 1400x1050@75Hz */
343 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 156000, 1400, 1504,
344 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
345 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
346 /* 0x2c - 1400x1050@85Hz */
347 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 179500, 1400, 1504,
348 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
349 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
350 /* 0x2d - 1400x1050@120Hz RB */
351 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER
, 208000, 1400, 1448,
352 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
353 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
354 /* 0x2e - 1440x900@60Hz RB */
355 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 88750, 1440, 1488,
356 1520, 1600, 0, 900, 903, 909, 926, 0,
357 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
358 /* 0x2f - 1440x900@60Hz */
359 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 106500, 1440, 1520,
360 1672, 1904, 0, 900, 903, 909, 934, 0,
361 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
362 /* 0x30 - 1440x900@75Hz */
363 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 136750, 1440, 1536,
364 1688, 1936, 0, 900, 903, 909, 942, 0,
365 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
366 /* 0x31 - 1440x900@85Hz */
367 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 157000, 1440, 1544,
368 1696, 1952, 0, 900, 903, 909, 948, 0,
369 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
370 /* 0x32 - 1440x900@120Hz RB */
371 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER
, 182750, 1440, 1488,
372 1520, 1600, 0, 900, 903, 909, 953, 0,
373 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
374 /* 0x53 - 1600x900@60Hz */
375 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER
, 108000, 1600, 1624,
376 1704, 1800, 0, 900, 901, 904, 1000, 0,
377 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
378 /* 0x33 - 1600x1200@60Hz */
379 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 162000, 1600, 1664,
380 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
381 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
382 /* 0x34 - 1600x1200@65Hz */
383 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 175500, 1600, 1664,
384 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
385 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
386 /* 0x35 - 1600x1200@70Hz */
387 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 189000, 1600, 1664,
388 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
389 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
390 /* 0x36 - 1600x1200@75Hz */
391 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 202500, 1600, 1664,
392 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
393 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
394 /* 0x37 - 1600x1200@85Hz */
395 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 229500, 1600, 1664,
396 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
397 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
398 /* 0x38 - 1600x1200@120Hz RB */
399 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER
, 268250, 1600, 1648,
400 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
401 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
402 /* 0x39 - 1680x1050@60Hz RB */
403 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 119000, 1680, 1728,
404 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
405 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
406 /* 0x3a - 1680x1050@60Hz */
407 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 146250, 1680, 1784,
408 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
409 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
410 /* 0x3b - 1680x1050@75Hz */
411 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 187000, 1680, 1800,
412 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
413 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
414 /* 0x3c - 1680x1050@85Hz */
415 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 214750, 1680, 1808,
416 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
417 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
418 /* 0x3d - 1680x1050@120Hz RB */
419 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER
, 245500, 1680, 1728,
420 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
421 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
422 /* 0x3e - 1792x1344@60Hz */
423 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 204750, 1792, 1920,
424 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
425 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
426 /* 0x3f - 1792x1344@75Hz */
427 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 261000, 1792, 1888,
428 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
429 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
430 /* 0x40 - 1792x1344@120Hz RB */
431 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER
, 333250, 1792, 1840,
432 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
433 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
434 /* 0x41 - 1856x1392@60Hz */
435 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 218250, 1856, 1952,
436 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
437 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
438 /* 0x42 - 1856x1392@75Hz */
439 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 288000, 1856, 1984,
440 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
441 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
442 /* 0x43 - 1856x1392@120Hz RB */
443 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER
, 356500, 1856, 1904,
444 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
445 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
446 /* 0x52 - 1920x1080@60Hz */
447 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
448 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
449 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
450 /* 0x44 - 1920x1200@60Hz RB */
451 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 154000, 1920, 1968,
452 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
453 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
454 /* 0x45 - 1920x1200@60Hz */
455 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 193250, 1920, 2056,
456 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
457 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
458 /* 0x46 - 1920x1200@75Hz */
459 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 245250, 1920, 2056,
460 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
461 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
462 /* 0x47 - 1920x1200@85Hz */
463 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 281250, 1920, 2064,
464 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
465 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
466 /* 0x48 - 1920x1200@120Hz RB */
467 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER
, 317000, 1920, 1968,
468 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
469 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
470 /* 0x49 - 1920x1440@60Hz */
471 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 234000, 1920, 2048,
472 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
473 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
474 /* 0x4a - 1920x1440@75Hz */
475 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2064,
476 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
477 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
478 /* 0x4b - 1920x1440@120Hz RB */
479 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER
, 380500, 1920, 1968,
480 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
481 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
482 /* 0x54 - 2048x1152@60Hz */
483 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER
, 162000, 2048, 2074,
484 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
485 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
486 /* 0x4c - 2560x1600@60Hz RB */
487 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 268500, 2560, 2608,
488 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
489 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
490 /* 0x4d - 2560x1600@60Hz */
491 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 348500, 2560, 2752,
492 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
493 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
494 /* 0x4e - 2560x1600@75Hz */
495 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 443250, 2560, 2768,
496 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
497 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
498 /* 0x4f - 2560x1600@85Hz */
499 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 505250, 2560, 2768,
500 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
501 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) },
502 /* 0x50 - 2560x1600@120Hz RB */
503 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER
, 552750, 2560, 2608,
504 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
505 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
506 /* 0x57 - 4096x2160@60Hz RB */
507 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 556744, 4096, 4104,
508 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
509 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
510 /* 0x58 - 4096x2160@59.94Hz RB */
511 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 556188, 4096, 4104,
512 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
513 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
) },
517 * These more or less come from the DMT spec. The 720x400 modes are
518 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
519 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
520 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
523 * The DMT modes have been fact-checked; the rest are mild guesses.
525 static const struct drm_display_mode edid_est_modes
[] = {
526 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 40000, 800, 840,
527 968, 1056, 0, 600, 601, 605, 628, 0,
528 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@60Hz */
529 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 36000, 800, 824,
530 896, 1024, 0, 600, 601, 603, 625, 0,
531 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@56Hz */
532 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 656,
533 720, 840, 0, 480, 481, 484, 500, 0,
534 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@75Hz */
535 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 31500, 640, 664,
536 704, 832, 0, 480, 489, 492, 520, 0,
537 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@72Hz */
538 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 30240, 640, 704,
539 768, 864, 0, 480, 483, 486, 525, 0,
540 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@67Hz */
541 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
542 752, 800, 0, 480, 490, 492, 525, 0,
543 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 640x480@60Hz */
544 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 35500, 720, 738,
545 846, 900, 0, 400, 421, 423, 449, 0,
546 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 720x400@88Hz */
547 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER
, 28320, 720, 738,
548 846, 900, 0, 400, 412, 414, 449, 0,
549 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 720x400@70Hz */
550 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER
, 135000, 1280, 1296,
551 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
552 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1280x1024@75Hz */
553 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 78750, 1024, 1040,
554 1136, 1312, 0, 768, 769, 772, 800, 0,
555 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1024x768@75Hz */
556 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 75000, 1024, 1048,
557 1184, 1328, 0, 768, 771, 777, 806, 0,
558 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 1024x768@70Hz */
559 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER
, 65000, 1024, 1048,
560 1184, 1344, 0, 768, 771, 777, 806, 0,
561 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 1024x768@60Hz */
562 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER
,44900, 1024, 1032,
563 1208, 1264, 0, 768, 768, 776, 817, 0,
564 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
| DRM_MODE_FLAG_INTERLACE
) }, /* 1024x768@43Hz */
565 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER
, 57284, 832, 864,
566 928, 1152, 0, 624, 625, 628, 667, 0,
567 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
) }, /* 832x624@75Hz */
568 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 49500, 800, 816,
569 896, 1056, 0, 600, 601, 604, 625, 0,
570 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@75Hz */
571 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER
, 50000, 800, 856,
572 976, 1040, 0, 600, 637, 643, 666, 0,
573 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 800x600@72Hz */
574 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER
, 108000, 1152, 1216,
575 1344, 1600, 0, 864, 865, 868, 900, 0,
576 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
) }, /* 1152x864@75Hz */
586 static const struct minimode est3_modes
[] = {
594 { 1024, 768, 85, 0 },
595 { 1152, 864, 75, 0 },
597 { 1280, 768, 60, 1 },
598 { 1280, 768, 60, 0 },
599 { 1280, 768, 75, 0 },
600 { 1280, 768, 85, 0 },
601 { 1280, 960, 60, 0 },
602 { 1280, 960, 85, 0 },
603 { 1280, 1024, 60, 0 },
604 { 1280, 1024, 85, 0 },
606 { 1360, 768, 60, 0 },
607 { 1440, 900, 60, 1 },
608 { 1440, 900, 60, 0 },
609 { 1440, 900, 75, 0 },
610 { 1440, 900, 85, 0 },
611 { 1400, 1050, 60, 1 },
612 { 1400, 1050, 60, 0 },
613 { 1400, 1050, 75, 0 },
615 { 1400, 1050, 85, 0 },
616 { 1680, 1050, 60, 1 },
617 { 1680, 1050, 60, 0 },
618 { 1680, 1050, 75, 0 },
619 { 1680, 1050, 85, 0 },
620 { 1600, 1200, 60, 0 },
621 { 1600, 1200, 65, 0 },
622 { 1600, 1200, 70, 0 },
624 { 1600, 1200, 75, 0 },
625 { 1600, 1200, 85, 0 },
626 { 1792, 1344, 60, 0 },
627 { 1792, 1344, 75, 0 },
628 { 1856, 1392, 60, 0 },
629 { 1856, 1392, 75, 0 },
630 { 1920, 1200, 60, 1 },
631 { 1920, 1200, 60, 0 },
633 { 1920, 1200, 75, 0 },
634 { 1920, 1200, 85, 0 },
635 { 1920, 1440, 60, 0 },
636 { 1920, 1440, 75, 0 },
639 static const struct minimode extra_modes
[] = {
640 { 1024, 576, 60, 0 },
641 { 1366, 768, 60, 0 },
642 { 1600, 900, 60, 0 },
643 { 1680, 945, 60, 0 },
644 { 1920, 1080, 60, 0 },
645 { 2048, 1152, 60, 0 },
646 { 2048, 1536, 60, 0 },
650 * Probably taken from CEA-861 spec.
651 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
653 * Index using the VIC.
655 static const struct drm_display_mode edid_cea_modes
[] = {
656 /* 0 - dummy, VICs start at 1 */
658 /* 1 - 640x480@60Hz */
659 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER
, 25175, 640, 656,
660 752, 800, 0, 480, 490, 492, 525, 0,
661 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
662 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
663 /* 2 - 720x480@60Hz */
664 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 27000, 720, 736,
665 798, 858, 0, 480, 489, 495, 525, 0,
666 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
667 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
668 /* 3 - 720x480@60Hz */
669 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 27000, 720, 736,
670 798, 858, 0, 480, 489, 495, 525, 0,
671 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
672 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
673 /* 4 - 1280x720@60Hz */
674 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1390,
675 1430, 1650, 0, 720, 725, 730, 750, 0,
676 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
677 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
678 /* 5 - 1920x1080i@60Hz */
679 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2008,
680 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
681 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
682 DRM_MODE_FLAG_INTERLACE
),
683 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
684 /* 6 - 720(1440)x480i@60Hz */
685 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
686 801, 858, 0, 480, 488, 494, 525, 0,
687 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
688 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
689 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
690 /* 7 - 720(1440)x480i@60Hz */
691 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
692 801, 858, 0, 480, 488, 494, 525, 0,
693 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
694 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
695 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
696 /* 8 - 720(1440)x240@60Hz */
697 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
698 801, 858, 0, 240, 244, 247, 262, 0,
699 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
700 DRM_MODE_FLAG_DBLCLK
),
701 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
702 /* 9 - 720(1440)x240@60Hz */
703 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER
, 13500, 720, 739,
704 801, 858, 0, 240, 244, 247, 262, 0,
705 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
706 DRM_MODE_FLAG_DBLCLK
),
707 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
708 /* 10 - 2880x480i@60Hz */
709 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
710 3204, 3432, 0, 480, 488, 494, 525, 0,
711 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
712 DRM_MODE_FLAG_INTERLACE
),
713 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
714 /* 11 - 2880x480i@60Hz */
715 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
716 3204, 3432, 0, 480, 488, 494, 525, 0,
717 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
718 DRM_MODE_FLAG_INTERLACE
),
719 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
720 /* 12 - 2880x240@60Hz */
721 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
722 3204, 3432, 0, 240, 244, 247, 262, 0,
723 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
724 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
725 /* 13 - 2880x240@60Hz */
726 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2956,
727 3204, 3432, 0, 240, 244, 247, 262, 0,
728 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
729 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
730 /* 14 - 1440x480@60Hz */
731 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1472,
732 1596, 1716, 0, 480, 489, 495, 525, 0,
733 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
734 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
735 /* 15 - 1440x480@60Hz */
736 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1472,
737 1596, 1716, 0, 480, 489, 495, 525, 0,
738 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
739 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
740 /* 16 - 1920x1080@60Hz */
741 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
742 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
743 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
744 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
745 /* 17 - 720x576@50Hz */
746 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
747 796, 864, 0, 576, 581, 586, 625, 0,
748 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
749 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
750 /* 18 - 720x576@50Hz */
751 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
752 796, 864, 0, 576, 581, 586, 625, 0,
753 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
754 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
755 /* 19 - 1280x720@50Hz */
756 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 1720,
757 1760, 1980, 0, 720, 725, 730, 750, 0,
758 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
759 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
760 /* 20 - 1920x1080i@50Hz */
761 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2448,
762 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
763 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
764 DRM_MODE_FLAG_INTERLACE
),
765 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
766 /* 21 - 720(1440)x576i@50Hz */
767 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
768 795, 864, 0, 576, 580, 586, 625, 0,
769 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
770 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
771 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
772 /* 22 - 720(1440)x576i@50Hz */
773 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
774 795, 864, 0, 576, 580, 586, 625, 0,
775 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
776 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
777 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
778 /* 23 - 720(1440)x288@50Hz */
779 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
780 795, 864, 0, 288, 290, 293, 312, 0,
781 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
782 DRM_MODE_FLAG_DBLCLK
),
783 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
784 /* 24 - 720(1440)x288@50Hz */
785 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER
, 13500, 720, 732,
786 795, 864, 0, 288, 290, 293, 312, 0,
787 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
788 DRM_MODE_FLAG_DBLCLK
),
789 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
790 /* 25 - 2880x576i@50Hz */
791 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
792 3180, 3456, 0, 576, 580, 586, 625, 0,
793 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
794 DRM_MODE_FLAG_INTERLACE
),
795 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
796 /* 26 - 2880x576i@50Hz */
797 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
798 3180, 3456, 0, 576, 580, 586, 625, 0,
799 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
800 DRM_MODE_FLAG_INTERLACE
),
801 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
802 /* 27 - 2880x288@50Hz */
803 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
804 3180, 3456, 0, 288, 290, 293, 312, 0,
805 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
806 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
807 /* 28 - 2880x288@50Hz */
808 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER
, 54000, 2880, 2928,
809 3180, 3456, 0, 288, 290, 293, 312, 0,
810 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
811 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
812 /* 29 - 1440x576@50Hz */
813 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1464,
814 1592, 1728, 0, 576, 581, 586, 625, 0,
815 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
816 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
817 /* 30 - 1440x576@50Hz */
818 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER
, 54000, 1440, 1464,
819 1592, 1728, 0, 576, 581, 586, 625, 0,
820 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
821 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
822 /* 31 - 1920x1080@50Hz */
823 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2448,
824 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
825 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
826 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
827 /* 32 - 1920x1080@24Hz */
828 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2558,
829 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
830 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
831 .vrefresh
= 24, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
832 /* 33 - 1920x1080@25Hz */
833 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2448,
834 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
835 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
836 .vrefresh
= 25, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
837 /* 34 - 1920x1080@30Hz */
838 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 74250, 1920, 2008,
839 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
840 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
841 .vrefresh
= 30, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
842 /* 35 - 2880x480@60Hz */
843 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2944,
844 3192, 3432, 0, 480, 489, 495, 525, 0,
845 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
846 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
847 /* 36 - 2880x480@60Hz */
848 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2944,
849 3192, 3432, 0, 480, 489, 495, 525, 0,
850 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
851 .vrefresh
= 60, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
852 /* 37 - 2880x576@50Hz */
853 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2928,
854 3184, 3456, 0, 576, 581, 586, 625, 0,
855 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
856 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
857 /* 38 - 2880x576@50Hz */
858 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER
, 108000, 2880, 2928,
859 3184, 3456, 0, 576, 581, 586, 625, 0,
860 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
861 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
862 /* 39 - 1920x1080i@50Hz */
863 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 72000, 1920, 1952,
864 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
865 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_NVSYNC
|
866 DRM_MODE_FLAG_INTERLACE
),
867 .vrefresh
= 50, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
868 /* 40 - 1920x1080i@100Hz */
869 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2448,
870 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
871 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
872 DRM_MODE_FLAG_INTERLACE
),
873 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
874 /* 41 - 1280x720@100Hz */
875 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1720,
876 1760, 1980, 0, 720, 725, 730, 750, 0,
877 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
878 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
879 /* 42 - 720x576@100Hz */
880 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
881 796, 864, 0, 576, 581, 586, 625, 0,
882 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
883 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
884 /* 43 - 720x576@100Hz */
885 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
886 796, 864, 0, 576, 581, 586, 625, 0,
887 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
888 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
889 /* 44 - 720(1440)x576i@100Hz */
890 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
891 795, 864, 0, 576, 580, 586, 625, 0,
892 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
893 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
894 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
895 /* 45 - 720(1440)x576i@100Hz */
896 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 732,
897 795, 864, 0, 576, 580, 586, 625, 0,
898 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
899 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
900 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
901 /* 46 - 1920x1080i@120Hz */
902 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER
, 148500, 1920, 2008,
903 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
904 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
|
905 DRM_MODE_FLAG_INTERLACE
),
906 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
907 /* 47 - 1280x720@120Hz */
908 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 148500, 1280, 1390,
909 1430, 1650, 0, 720, 725, 730, 750, 0,
910 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
911 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
912 /* 48 - 720x480@120Hz */
913 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 54000, 720, 736,
914 798, 858, 0, 480, 489, 495, 525, 0,
915 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
916 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
917 /* 49 - 720x480@120Hz */
918 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 54000, 720, 736,
919 798, 858, 0, 480, 489, 495, 525, 0,
920 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
921 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
922 /* 50 - 720(1440)x480i@120Hz */
923 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 739,
924 801, 858, 0, 480, 488, 494, 525, 0,
925 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
926 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
927 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
928 /* 51 - 720(1440)x480i@120Hz */
929 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 27000, 720, 739,
930 801, 858, 0, 480, 488, 494, 525, 0,
931 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
932 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
933 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
934 /* 52 - 720x576@200Hz */
935 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 108000, 720, 732,
936 796, 864, 0, 576, 581, 586, 625, 0,
937 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
938 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
939 /* 53 - 720x576@200Hz */
940 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER
, 108000, 720, 732,
941 796, 864, 0, 576, 581, 586, 625, 0,
942 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
943 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
944 /* 54 - 720(1440)x576i@200Hz */
945 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
946 795, 864, 0, 576, 580, 586, 625, 0,
947 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
948 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
949 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
950 /* 55 - 720(1440)x576i@200Hz */
951 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 732,
952 795, 864, 0, 576, 580, 586, 625, 0,
953 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
954 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
955 .vrefresh
= 200, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
956 /* 56 - 720x480@240Hz */
957 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 108000, 720, 736,
958 798, 858, 0, 480, 489, 495, 525, 0,
959 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
960 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
961 /* 57 - 720x480@240Hz */
962 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER
, 108000, 720, 736,
963 798, 858, 0, 480, 489, 495, 525, 0,
964 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
),
965 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
966 /* 58 - 720(1440)x480i@240 */
967 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 739,
968 801, 858, 0, 480, 488, 494, 525, 0,
969 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
970 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
971 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_4_3
, },
972 /* 59 - 720(1440)x480i@240 */
973 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER
, 54000, 720, 739,
974 801, 858, 0, 480, 488, 494, 525, 0,
975 DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
|
976 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_DBLCLK
),
977 .vrefresh
= 240, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
978 /* 60 - 1280x720@24Hz */
979 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 59400, 1280, 3040,
980 3080, 3300, 0, 720, 725, 730, 750, 0,
981 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
982 .vrefresh
= 24, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
983 /* 61 - 1280x720@25Hz */
984 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 3700,
985 3740, 3960, 0, 720, 725, 730, 750, 0,
986 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
987 .vrefresh
= 25, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
988 /* 62 - 1280x720@30Hz */
989 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER
, 74250, 1280, 3040,
990 3080, 3300, 0, 720, 725, 730, 750, 0,
991 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
992 .vrefresh
= 30, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
993 /* 63 - 1920x1080@120Hz */
994 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2008,
995 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
996 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
997 .vrefresh
= 120, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
998 /* 64 - 1920x1080@100Hz */
999 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER
, 297000, 1920, 2448,
1000 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
1001 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1002 .vrefresh
= 100, .picture_aspect_ratio
= HDMI_PICTURE_ASPECT_16_9
, },
1006 * HDMI 1.4 4k modes. Index using the VIC.
1008 static const struct drm_display_mode edid_4k_modes
[] = {
1009 /* 0 - dummy, VICs start at 1 */
1011 /* 1 - 3840x2160@30Hz */
1012 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1013 3840, 4016, 4104, 4400, 0,
1014 2160, 2168, 2178, 2250, 0,
1015 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1017 /* 2 - 3840x2160@25Hz */
1018 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1019 3840, 4896, 4984, 5280, 0,
1020 2160, 2168, 2178, 2250, 0,
1021 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1023 /* 3 - 3840x2160@24Hz */
1024 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1025 3840, 5116, 5204, 5500, 0,
1026 2160, 2168, 2178, 2250, 0,
1027 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1029 /* 4 - 4096x2160@24Hz (SMPTE) */
1030 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER
, 297000,
1031 4096, 5116, 5204, 5500, 0,
1032 2160, 2168, 2178, 2250, 0,
1033 DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
),
1037 /*** DDC fetch and block validation ***/
1039 static const u8 edid_header
[] = {
1040 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1044 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1045 * @raw_edid: pointer to raw base EDID block
1047 * Sanity check the header of the base EDID block.
1049 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
1051 int drm_edid_header_is_valid(const u8
*raw_edid
)
1055 for (i
= 0; i
< sizeof(edid_header
); i
++)
1056 if (raw_edid
[i
] == edid_header
[i
])
1061 EXPORT_SYMBOL(drm_edid_header_is_valid
);
1063 static int edid_fixup __read_mostly
= 6;
1064 module_param_named(edid_fixup
, edid_fixup
, int, 0400);
1065 MODULE_PARM_DESC(edid_fixup
,
1066 "Minimum number of valid EDID header bytes (0-8, default 6)");
1068 static void drm_get_displayid(struct drm_connector
*connector
,
1071 static int drm_edid_block_checksum(const u8
*raw_edid
)
1075 for (i
= 0; i
< EDID_LENGTH
; i
++)
1076 csum
+= raw_edid
[i
];
1081 static bool drm_edid_is_zero(const u8
*in_edid
, int length
)
1083 if (memchr_inv(in_edid
, 0, length
))
1090 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1091 * @raw_edid: pointer to raw EDID block
1092 * @block: type of block to validate (0 for base, extension otherwise)
1093 * @print_bad_edid: if true, dump bad EDID blocks to the console
1094 * @edid_corrupt: if true, the header or checksum is invalid
1096 * Validate a base or extension EDID block and optionally dump bad blocks to
1099 * Return: True if the block is valid, false otherwise.
1101 bool drm_edid_block_valid(u8
*raw_edid
, int block
, bool print_bad_edid
,
1105 struct edid
*edid
= (struct edid
*)raw_edid
;
1107 if (WARN_ON(!raw_edid
))
1110 if (edid_fixup
> 8 || edid_fixup
< 0)
1114 int score
= drm_edid_header_is_valid(raw_edid
);
1117 *edid_corrupt
= false;
1118 } else if (score
>= edid_fixup
) {
1119 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1120 * The corrupt flag needs to be set here otherwise, the
1121 * fix-up code here will correct the problem, the
1122 * checksum is correct and the test fails
1125 *edid_corrupt
= true;
1126 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1127 memcpy(raw_edid
, edid_header
, sizeof(edid_header
));
1130 *edid_corrupt
= true;
1135 csum
= drm_edid_block_checksum(raw_edid
);
1137 if (print_bad_edid
) {
1138 DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum
);
1142 *edid_corrupt
= true;
1144 /* allow CEA to slide through, switches mangle this */
1145 if (raw_edid
[0] != 0x02)
1149 /* per-block-type checks */
1150 switch (raw_edid
[0]) {
1152 if (edid
->version
!= 1) {
1153 DRM_ERROR("EDID has major version %d, instead of 1\n", edid
->version
);
1157 if (edid
->revision
> 4)
1158 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1168 if (print_bad_edid
) {
1169 if (drm_edid_is_zero(raw_edid
, EDID_LENGTH
)) {
1170 printk(KERN_ERR
"EDID block is all zeroes\n");
1172 printk(KERN_ERR
"Raw EDID:\n");
1173 for (int i
= 0; i
< EDID_LENGTH
; ) {
1174 kprintf("%02x", raw_edid
[i
]);
1176 if (i
% 16 == 0 || i
== EDID_LENGTH
)
1178 else if (i
% 8 == 0)
1187 EXPORT_SYMBOL(drm_edid_block_valid
);
1190 * drm_edid_is_valid - sanity check EDID data
1193 * Sanity-check an entire EDID record (including extensions)
1195 * Return: True if the EDID data is valid, false otherwise.
1197 bool drm_edid_is_valid(struct edid
*edid
)
1200 u8
*raw
= (u8
*)edid
;
1205 for (i
= 0; i
<= edid
->extensions
; i
++)
1206 if (!drm_edid_block_valid(raw
+ i
* EDID_LENGTH
, i
, true, NULL
))
1211 EXPORT_SYMBOL(drm_edid_is_valid
);
1213 #define DDC_SEGMENT_ADDR 0x30
1215 * drm_do_probe_ddc_edid() - get EDID information via I2C
1216 * @data: I2C device adapter
1217 * @buf: EDID data buffer to be filled
1218 * @block: 128 byte EDID block to start fetching from
1219 * @len: EDID data buffer length to fetch
1221 * Try to fetch EDID information by calling I2C driver functions.
1223 * Return: 0 on success or -1 on failure.
1226 drm_do_probe_ddc_edid(void *data
, u8
*buf
, unsigned int block
, size_t len
)
1228 struct i2c_adapter
*adapter
= data
;
1229 unsigned char start
= block
* EDID_LENGTH
;
1230 unsigned char segment
= block
>> 1;
1231 unsigned char xfers
= segment
? 3 : 2;
1232 int ret
, retries
= 5;
1235 * The core I2C driver will automatically retry the transfer if the
1236 * adapter reports EAGAIN. However, we find that bit-banging transfers
1237 * are susceptible to errors under a heavily loaded machine and
1238 * generate spurious NAKs and timeouts. Retrying the transfer
1239 * of the individual block a few times seems to overcome this.
1242 struct i2c_msg msgs
[] = {
1244 .addr
= DDC_SEGMENT_ADDR
,
1262 * Avoid sending the segment addr to not upset non-compliant
1265 ret
= i2c_transfer(adapter
, &msgs
[3 - xfers
], xfers
);
1267 if (ret
== -ENXIO
) {
1268 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1272 } while (ret
!= xfers
&& --retries
);
1274 return ret
== xfers
? 0 : -1;
1278 * Old version of drm_do_probe_ddc_edid, still using
1279 * the FreeBSD/DragonFly iic API
1282 drm_do_probe_ddc_edid_iic(void *data
, u8
*buf
, unsigned int block
, size_t len
)
1284 device_t adapter
= data
;
1285 unsigned char start
= block
* EDID_LENGTH
;
1286 unsigned char segment
= block
>> 1;
1287 unsigned char xfers
= segment
? 3 : 2;
1288 int ret
, retries
= 5;
1291 * The core I2C driver will automatically retry the transfer if the
1292 * adapter reports EAGAIN. However, we find that bit-banging transfers
1293 * are susceptible to errors under a heavily loaded machine and
1294 * generate spurious NAKs and timeouts. Retrying the transfer
1295 * of the individual block a few times seems to overcome this.
1298 struct iic_msg msgs
[] = {
1300 .slave
= DDC_SEGMENT_ADDR
<< 1,
1305 .slave
= DDC_ADDR
<< 1,
1310 .slave
= DDC_ADDR
<< 1,
1318 * Avoid sending the segment addr to not upset non-compliant
1321 ret
= iicbus_transfer(adapter
, &msgs
[3 - xfers
], xfers
);
1323 DRM_DEBUG_KMS("iicbus_transfer countdown %d error %d\n",
1325 } while (ret
!= 0 && --retries
);
1327 return (ret
== 0 ? 0 : -1);
1331 * Old version of drm_probe_ddc(), still using
1332 * the FreeBSD/DragonFly iic API
1335 drm_probe_ddc_iic(device_t adapter
)
1339 return (drm_do_probe_ddc_edid_iic(adapter
, &out
, 0, 1) == 0);
1343 * Old version of drm_get_edid(), still using
1344 * the FreeBSD/DragonFly iic API
1346 struct edid
*drm_get_edid_iic(struct drm_connector
*connector
,
1349 if (!drm_probe_ddc_iic(adapter
))
1352 return drm_do_get_edid(connector
, drm_do_probe_ddc_edid_iic
, adapter
);
1356 * drm_do_get_edid - get EDID data using a custom EDID block read function
1357 * @connector: connector we're probing
1358 * @get_edid_block: EDID block read function
1359 * @data: private data passed to the block read function
1361 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1362 * exposes a different interface to read EDID blocks this function can be used
1363 * to get EDID data using a custom block read function.
1365 * As in the general case the DDC bus is accessible by the kernel at the I2C
1366 * level, drivers must make all reasonable efforts to expose it as an I2C
1367 * adapter and use drm_get_edid() instead of abusing this function.
1369 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1371 struct edid
*drm_do_get_edid(struct drm_connector
*connector
,
1372 int (*get_edid_block
)(void *data
, u8
*buf
, unsigned int block
,
1376 int i
, j
= 0, valid_extensions
= 0;
1378 bool print_bad_edid
= !connector
->bad_edid_counter
|| (drm_debug
& DRM_UT_KMS
);
1380 if ((block
= kmalloc(EDID_LENGTH
, M_DRM
, M_WAITOK
)) == NULL
)
1383 /* base block fetch */
1384 for (i
= 0; i
< 4; i
++) {
1385 if (get_edid_block(data
, block
, 0, EDID_LENGTH
))
1387 if (drm_edid_block_valid(block
, 0, print_bad_edid
,
1388 &connector
->edid_corrupt
))
1390 if (i
== 0 && drm_edid_is_zero(block
, EDID_LENGTH
)) {
1391 connector
->null_edid_counter
++;
1398 /* if there's no extensions, we're done */
1399 if (block
[0x7e] == 0)
1400 return (struct edid
*)block
;
1402 new = krealloc(block
, (block
[0x7e] + 1) * EDID_LENGTH
, M_DRM
, M_WAITOK
);
1407 for (j
= 1; j
<= block
[0x7e]; j
++) {
1408 for (i
= 0; i
< 4; i
++) {
1409 if (get_edid_block(data
,
1410 block
+ (valid_extensions
+ 1) * EDID_LENGTH
,
1413 if (drm_edid_block_valid(block
+ (valid_extensions
+ 1)
1422 if (i
== 4 && print_bad_edid
) {
1423 dev_warn(connector
->dev
->dev
,
1424 "%s: Ignoring invalid EDID block %d.\n",
1425 connector
->name
, j
);
1427 connector
->bad_edid_counter
++;
1431 if (valid_extensions
!= block
[0x7e]) {
1432 block
[EDID_LENGTH
-1] += block
[0x7e] - valid_extensions
;
1433 block
[0x7e] = valid_extensions
;
1434 new = krealloc(block
, (valid_extensions
+ 1) * EDID_LENGTH
, M_DRM
, M_WAITOK
);
1440 return (struct edid
*)block
;
1443 if (print_bad_edid
) {
1444 dev_warn(connector
->dev
->dev
, "%s: EDID block %d invalid.\n",
1445 connector
->name
, j
);
1447 connector
->bad_edid_counter
++;
1455 * drm_probe_ddc() - probe DDC presence
1456 * @adapter: I2C adapter to probe
1458 * Return: True on success, false on failure.
1461 drm_probe_ddc(struct i2c_adapter
*adapter
)
1465 return (drm_do_probe_ddc_edid(adapter
, &out
, 0, 1) == 0);
1467 EXPORT_SYMBOL(drm_probe_ddc
);
1470 * drm_get_edid - get EDID data, if available
1471 * @connector: connector we're probing
1472 * @adapter: I2C adapter to use for DDC
1474 * Poke the given I2C channel to grab EDID data if possible. If found,
1475 * attach it to the connector.
1477 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1479 struct edid
*drm_get_edid(struct drm_connector
*connector
,
1480 struct i2c_adapter
*adapter
)
1484 if (!drm_probe_ddc(adapter
))
1487 edid
= drm_do_get_edid(connector
, drm_do_probe_ddc_edid
, adapter
);
1489 drm_get_displayid(connector
, edid
);
1492 EXPORT_SYMBOL(drm_get_edid
);
1495 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1496 * @connector: connector we're probing
1497 * @adapter: I2C adapter to use for DDC
1499 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1500 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1501 * switch DDC to the GPU which is retrieving EDID.
1503 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1505 struct edid
*drm_get_edid_switcheroo(struct drm_connector
*connector
,
1506 struct i2c_adapter
*adapter
)
1508 struct pci_dev
*pdev
= connector
->dev
->pdev
;
1511 vga_switcheroo_lock_ddc(pdev
);
1512 edid
= drm_get_edid(connector
, adapter
);
1513 vga_switcheroo_unlock_ddc(pdev
);
1517 EXPORT_SYMBOL(drm_get_edid_switcheroo
);
1520 * drm_edid_duplicate - duplicate an EDID and the extensions
1521 * @edid: EDID to duplicate
1523 * Return: Pointer to duplicated EDID or NULL on allocation failure.
1525 struct edid
*drm_edid_duplicate(const struct edid
*edid
)
1527 return kmemdup(edid
, (edid
->extensions
+ 1) * EDID_LENGTH
, GFP_KERNEL
);
1529 EXPORT_SYMBOL(drm_edid_duplicate
);
1531 /*** EDID parsing ***/
1534 * edid_vendor - match a string against EDID's obfuscated vendor field
1535 * @edid: EDID to match
1536 * @vendor: vendor string
1538 * Returns true if @vendor is in @edid, false otherwise
1540 static bool edid_vendor(struct edid
*edid
, char *vendor
)
1542 char edid_vendor
[3];
1544 edid_vendor
[0] = ((edid
->mfg_id
[0] & 0x7c) >> 2) + '@';
1545 edid_vendor
[1] = (((edid
->mfg_id
[0] & 0x3) << 3) |
1546 ((edid
->mfg_id
[1] & 0xe0) >> 5)) + '@';
1547 edid_vendor
[2] = (edid
->mfg_id
[1] & 0x1f) + '@';
1549 return !strncmp(edid_vendor
, vendor
, 3);
1553 * edid_get_quirks - return quirk flags for a given EDID
1554 * @edid: EDID to process
1556 * This tells subsequent routines what fixes they need to apply.
1558 static u32
edid_get_quirks(struct edid
*edid
)
1560 struct edid_quirk
*quirk
;
1563 for (i
= 0; i
< ARRAY_SIZE(edid_quirk_list
); i
++) {
1564 quirk
= &edid_quirk_list
[i
];
1566 if (edid_vendor(edid
, quirk
->vendor
) &&
1567 (EDID_PRODUCT_ID(edid
) == quirk
->product_id
))
1568 return quirk
->quirks
;
1574 #define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
1575 #define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
1578 * edid_fixup_preferred - set preferred modes based on quirk list
1579 * @connector: has mode list to fix up
1580 * @quirks: quirks list
1582 * Walk the mode list for @connector, clearing the preferred status
1583 * on existing modes and setting it anew for the right mode ala @quirks.
1585 static void edid_fixup_preferred(struct drm_connector
*connector
,
1588 struct drm_display_mode
*t
, *cur_mode
, *preferred_mode
;
1589 int target_refresh
= 0;
1590 int cur_vrefresh
, preferred_vrefresh
;
1592 if (list_empty(&connector
->probed_modes
))
1595 if (quirks
& EDID_QUIRK_PREFER_LARGE_60
)
1596 target_refresh
= 60;
1597 if (quirks
& EDID_QUIRK_PREFER_LARGE_75
)
1598 target_refresh
= 75;
1600 preferred_mode
= list_first_entry(&connector
->probed_modes
,
1601 struct drm_display_mode
, head
);
1603 list_for_each_entry_safe(cur_mode
, t
, &connector
->probed_modes
, head
) {
1604 cur_mode
->type
&= ~DRM_MODE_TYPE_PREFERRED
;
1606 if (cur_mode
== preferred_mode
)
1609 /* Largest mode is preferred */
1610 if (MODE_SIZE(cur_mode
) > MODE_SIZE(preferred_mode
))
1611 preferred_mode
= cur_mode
;
1613 cur_vrefresh
= cur_mode
->vrefresh
?
1614 cur_mode
->vrefresh
: drm_mode_vrefresh(cur_mode
);
1615 preferred_vrefresh
= preferred_mode
->vrefresh
?
1616 preferred_mode
->vrefresh
: drm_mode_vrefresh(preferred_mode
);
1617 /* At a given size, try to get closest to target refresh */
1618 if ((MODE_SIZE(cur_mode
) == MODE_SIZE(preferred_mode
)) &&
1619 MODE_REFRESH_DIFF(cur_vrefresh
, target_refresh
) <
1620 MODE_REFRESH_DIFF(preferred_vrefresh
, target_refresh
)) {
1621 preferred_mode
= cur_mode
;
1625 preferred_mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
1629 mode_is_rb(const struct drm_display_mode
*mode
)
1631 return (mode
->htotal
- mode
->hdisplay
== 160) &&
1632 (mode
->hsync_end
- mode
->hdisplay
== 80) &&
1633 (mode
->hsync_end
- mode
->hsync_start
== 32) &&
1634 (mode
->vsync_start
- mode
->vdisplay
== 3);
1638 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1639 * @dev: Device to duplicate against
1640 * @hsize: Mode width
1641 * @vsize: Mode height
1642 * @fresh: Mode refresh rate
1643 * @rb: Mode reduced-blanking-ness
1645 * Walk the DMT mode list looking for a match for the given parameters.
1647 * Return: A newly allocated copy of the mode, or NULL if not found.
1649 struct drm_display_mode
*drm_mode_find_dmt(struct drm_device
*dev
,
1650 int hsize
, int vsize
, int fresh
,
1655 for (i
= 0; i
< ARRAY_SIZE(drm_dmt_modes
); i
++) {
1656 const struct drm_display_mode
*ptr
= &drm_dmt_modes
[i
];
1657 if (hsize
!= ptr
->hdisplay
)
1659 if (vsize
!= ptr
->vdisplay
)
1661 if (fresh
!= drm_mode_vrefresh(ptr
))
1663 if (rb
!= mode_is_rb(ptr
))
1666 return drm_mode_duplicate(dev
, ptr
);
1671 EXPORT_SYMBOL(drm_mode_find_dmt
);
1673 typedef void detailed_cb(struct detailed_timing
*timing
, void *closure
);
1676 cea_for_each_detailed_block(u8
*ext
, detailed_cb
*cb
, void *closure
)
1680 u8
*det_base
= ext
+ d
;
1683 for (i
= 0; i
< n
; i
++)
1684 cb((struct detailed_timing
*)(det_base
+ 18 * i
), closure
);
1688 vtb_for_each_detailed_block(u8
*ext
, detailed_cb
*cb
, void *closure
)
1690 unsigned int i
, n
= min((int)ext
[0x02], 6);
1691 u8
*det_base
= ext
+ 5;
1694 return; /* unknown version */
1696 for (i
= 0; i
< n
; i
++)
1697 cb((struct detailed_timing
*)(det_base
+ 18 * i
), closure
);
1701 drm_for_each_detailed_block(u8
*raw_edid
, detailed_cb
*cb
, void *closure
)
1704 struct edid
*edid
= (struct edid
*)raw_edid
;
1709 for (i
= 0; i
< EDID_DETAILED_TIMINGS
; i
++)
1710 cb(&(edid
->detailed_timings
[i
]), closure
);
1712 for (i
= 1; i
<= raw_edid
[0x7e]; i
++) {
1713 u8
*ext
= raw_edid
+ (i
* EDID_LENGTH
);
1716 cea_for_each_detailed_block(ext
, cb
, closure
);
1719 vtb_for_each_detailed_block(ext
, cb
, closure
);
1728 is_rb(struct detailed_timing
*t
, void *data
)
1731 if (r
[3] == EDID_DETAIL_MONITOR_RANGE
)
1733 *(bool *)data
= true;
1736 /* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1738 drm_monitor_supports_rb(struct edid
*edid
)
1740 if (edid
->revision
>= 4) {
1742 drm_for_each_detailed_block((u8
*)edid
, is_rb
, &ret
);
1746 return ((edid
->input
& DRM_EDID_INPUT_DIGITAL
) != 0);
1750 find_gtf2(struct detailed_timing
*t
, void *data
)
1753 if (r
[3] == EDID_DETAIL_MONITOR_RANGE
&& r
[10] == 0x02)
1757 /* Secondary GTF curve kicks in above some break frequency */
1759 drm_gtf2_hbreak(struct edid
*edid
)
1762 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1763 return r
? (r
[12] * 2) : 0;
1767 drm_gtf2_2c(struct edid
*edid
)
1770 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1771 return r
? r
[13] : 0;
1775 drm_gtf2_m(struct edid
*edid
)
1778 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1779 return r
? (r
[15] << 8) + r
[14] : 0;
1783 drm_gtf2_k(struct edid
*edid
)
1786 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1787 return r
? r
[16] : 0;
1791 drm_gtf2_2j(struct edid
*edid
)
1794 drm_for_each_detailed_block((u8
*)edid
, find_gtf2
, &r
);
1795 return r
? r
[17] : 0;
1799 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1800 * @edid: EDID block to scan
1802 static int standard_timing_level(struct edid
*edid
)
1804 if (edid
->revision
>= 2) {
1805 if (edid
->revision
>= 4 && (edid
->features
& DRM_EDID_FEATURE_DEFAULT_GTF
))
1807 if (drm_gtf2_hbreak(edid
))
1815 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1816 * monitors fill with ascii space (0x20) instead.
1819 bad_std_timing(u8 a
, u8 b
)
1821 return (a
== 0x00 && b
== 0x00) ||
1822 (a
== 0x01 && b
== 0x01) ||
1823 (a
== 0x20 && b
== 0x20);
1827 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
1828 * @connector: connector of for the EDID block
1829 * @edid: EDID block to scan
1830 * @t: standard timing params
1832 * Take the standard timing params (in this case width, aspect, and refresh)
1833 * and convert them into a real mode using CVT/GTF/DMT.
1835 static struct drm_display_mode
*
1836 drm_mode_std(struct drm_connector
*connector
, struct edid
*edid
,
1837 struct std_timing
*t
)
1839 struct drm_device
*dev
= connector
->dev
;
1840 struct drm_display_mode
*m
, *mode
= NULL
;
1843 unsigned aspect_ratio
= (t
->vfreq_aspect
& EDID_TIMING_ASPECT_MASK
)
1844 >> EDID_TIMING_ASPECT_SHIFT
;
1845 unsigned vfreq
= (t
->vfreq_aspect
& EDID_TIMING_VFREQ_MASK
)
1846 >> EDID_TIMING_VFREQ_SHIFT
;
1847 int timing_level
= standard_timing_level(edid
);
1849 if (bad_std_timing(t
->hsize
, t
->vfreq_aspect
))
1852 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1853 hsize
= t
->hsize
* 8 + 248;
1854 /* vrefresh_rate = vfreq + 60 */
1855 vrefresh_rate
= vfreq
+ 60;
1856 /* the vdisplay is calculated based on the aspect ratio */
1857 if (aspect_ratio
== 0) {
1858 if (edid
->revision
< 3)
1861 vsize
= (hsize
* 10) / 16;
1862 } else if (aspect_ratio
== 1)
1863 vsize
= (hsize
* 3) / 4;
1864 else if (aspect_ratio
== 2)
1865 vsize
= (hsize
* 4) / 5;
1867 vsize
= (hsize
* 9) / 16;
1869 /* HDTV hack, part 1 */
1870 if (vrefresh_rate
== 60 &&
1871 ((hsize
== 1360 && vsize
== 765) ||
1872 (hsize
== 1368 && vsize
== 769))) {
1878 * If this connector already has a mode for this size and refresh
1879 * rate (because it came from detailed or CVT info), use that
1880 * instead. This way we don't have to guess at interlace or
1883 list_for_each_entry(m
, &connector
->probed_modes
, head
)
1884 if (m
->hdisplay
== hsize
&& m
->vdisplay
== vsize
&&
1885 drm_mode_vrefresh(m
) == vrefresh_rate
)
1888 /* HDTV hack, part 2 */
1889 if (hsize
== 1366 && vsize
== 768 && vrefresh_rate
== 60) {
1890 mode
= drm_cvt_mode(dev
, 1366, 768, vrefresh_rate
, 0, 0,
1892 mode
->hdisplay
= 1366;
1893 mode
->hsync_start
= mode
->hsync_start
- 1;
1894 mode
->hsync_end
= mode
->hsync_end
- 1;
1898 /* check whether it can be found in default mode table */
1899 if (drm_monitor_supports_rb(edid
)) {
1900 mode
= drm_mode_find_dmt(dev
, hsize
, vsize
, vrefresh_rate
,
1905 mode
= drm_mode_find_dmt(dev
, hsize
, vsize
, vrefresh_rate
, false);
1909 /* okay, generate it */
1910 switch (timing_level
) {
1914 mode
= drm_gtf_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0);
1918 * This is potentially wrong if there's ever a monitor with
1919 * more than one ranges section, each claiming a different
1920 * secondary GTF curve. Please don't do that.
1922 mode
= drm_gtf_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0);
1925 if (drm_mode_hsync(mode
) > drm_gtf2_hbreak(edid
)) {
1926 drm_mode_destroy(dev
, mode
);
1927 mode
= drm_gtf_mode_complex(dev
, hsize
, vsize
,
1928 vrefresh_rate
, 0, 0,
1936 mode
= drm_cvt_mode(dev
, hsize
, vsize
, vrefresh_rate
, 0, 0,
1944 * EDID is delightfully ambiguous about how interlaced modes are to be
1945 * encoded. Our internal representation is of frame height, but some
1946 * HDTV detailed timings are encoded as field height.
1948 * The format list here is from CEA, in frame size. Technically we
1949 * should be checking refresh rate too. Whatever.
1952 drm_mode_do_interlace_quirk(struct drm_display_mode
*mode
,
1953 struct detailed_pixel_timing
*pt
)
1956 static const struct {
1958 } cea_interlaced
[] = {
1968 if (!(pt
->misc
& DRM_EDID_PT_INTERLACED
))
1971 for (i
= 0; i
< ARRAY_SIZE(cea_interlaced
); i
++) {
1972 if ((mode
->hdisplay
== cea_interlaced
[i
].w
) &&
1973 (mode
->vdisplay
== cea_interlaced
[i
].h
/ 2)) {
1974 mode
->vdisplay
*= 2;
1975 mode
->vsync_start
*= 2;
1976 mode
->vsync_end
*= 2;
1982 mode
->flags
|= DRM_MODE_FLAG_INTERLACE
;
1986 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1987 * @dev: DRM device (needed to create new mode)
1989 * @timing: EDID detailed timing info
1990 * @quirks: quirks to apply
1992 * An EDID detailed timing block contains enough info for us to create and
1993 * return a new struct drm_display_mode.
1995 static struct drm_display_mode
*drm_mode_detailed(struct drm_device
*dev
,
1997 struct detailed_timing
*timing
,
2000 struct drm_display_mode
*mode
;
2001 struct detailed_pixel_timing
*pt
= &timing
->data
.pixel_data
;
2002 unsigned hactive
= (pt
->hactive_hblank_hi
& 0xf0) << 4 | pt
->hactive_lo
;
2003 unsigned vactive
= (pt
->vactive_vblank_hi
& 0xf0) << 4 | pt
->vactive_lo
;
2004 unsigned hblank
= (pt
->hactive_hblank_hi
& 0xf) << 8 | pt
->hblank_lo
;
2005 unsigned vblank
= (pt
->vactive_vblank_hi
& 0xf) << 8 | pt
->vblank_lo
;
2006 unsigned hsync_offset
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0xc0) << 2 | pt
->hsync_offset_lo
;
2007 unsigned hsync_pulse_width
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0x30) << 4 | pt
->hsync_pulse_width_lo
;
2008 unsigned vsync_offset
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0xc) << 2 | pt
->vsync_offset_pulse_width_lo
>> 4;
2009 unsigned vsync_pulse_width
= (pt
->hsync_vsync_offset_pulse_width_hi
& 0x3) << 4 | (pt
->vsync_offset_pulse_width_lo
& 0xf);
2011 /* ignore tiny modes */
2012 if (hactive
< 64 || vactive
< 64)
2015 if (pt
->misc
& DRM_EDID_PT_STEREO
) {
2016 DRM_DEBUG_KMS("stereo mode not supported\n");
2019 if (!(pt
->misc
& DRM_EDID_PT_SEPARATE_SYNC
)) {
2020 DRM_DEBUG_KMS("composite sync not supported\n");
2023 /* it is incorrect if hsync/vsync width is zero */
2024 if (!hsync_pulse_width
|| !vsync_pulse_width
) {
2025 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2026 "Wrong Hsync/Vsync pulse width\n");
2030 if (quirks
& EDID_QUIRK_FORCE_REDUCED_BLANKING
) {
2031 mode
= drm_cvt_mode(dev
, hactive
, vactive
, 60, true, false, false);
2038 mode
= drm_mode_create(dev
);
2042 if (quirks
& EDID_QUIRK_135_CLOCK_TOO_HIGH
)
2043 timing
->pixel_clock
= cpu_to_le16(1088);
2045 mode
->clock
= le16_to_cpu(timing
->pixel_clock
) * 10;
2047 mode
->hdisplay
= hactive
;
2048 mode
->hsync_start
= mode
->hdisplay
+ hsync_offset
;
2049 mode
->hsync_end
= mode
->hsync_start
+ hsync_pulse_width
;
2050 mode
->htotal
= mode
->hdisplay
+ hblank
;
2052 mode
->vdisplay
= vactive
;
2053 mode
->vsync_start
= mode
->vdisplay
+ vsync_offset
;
2054 mode
->vsync_end
= mode
->vsync_start
+ vsync_pulse_width
;
2055 mode
->vtotal
= mode
->vdisplay
+ vblank
;
2057 /* Some EDIDs have bogus h/vtotal values */
2058 if (mode
->hsync_end
> mode
->htotal
)
2059 mode
->htotal
= mode
->hsync_end
+ 1;
2060 if (mode
->vsync_end
> mode
->vtotal
)
2061 mode
->vtotal
= mode
->vsync_end
+ 1;
2063 drm_mode_do_interlace_quirk(mode
, pt
);
2065 if (quirks
& EDID_QUIRK_DETAILED_SYNC_PP
) {
2066 pt
->misc
|= DRM_EDID_PT_HSYNC_POSITIVE
| DRM_EDID_PT_VSYNC_POSITIVE
;
2069 mode
->flags
|= (pt
->misc
& DRM_EDID_PT_HSYNC_POSITIVE
) ?
2070 DRM_MODE_FLAG_PHSYNC
: DRM_MODE_FLAG_NHSYNC
;
2071 mode
->flags
|= (pt
->misc
& DRM_EDID_PT_VSYNC_POSITIVE
) ?
2072 DRM_MODE_FLAG_PVSYNC
: DRM_MODE_FLAG_NVSYNC
;
2075 mode
->width_mm
= pt
->width_mm_lo
| (pt
->width_height_mm_hi
& 0xf0) << 4;
2076 mode
->height_mm
= pt
->height_mm_lo
| (pt
->width_height_mm_hi
& 0xf) << 8;
2078 if (quirks
& EDID_QUIRK_DETAILED_IN_CM
) {
2079 mode
->width_mm
*= 10;
2080 mode
->height_mm
*= 10;
2083 if (quirks
& EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE
) {
2084 mode
->width_mm
= edid
->width_cm
* 10;
2085 mode
->height_mm
= edid
->height_cm
* 10;
2088 mode
->type
= DRM_MODE_TYPE_DRIVER
;
2089 mode
->vrefresh
= drm_mode_vrefresh(mode
);
2090 drm_mode_set_name(mode
);
2096 mode_in_hsync_range(const struct drm_display_mode
*mode
,
2097 struct edid
*edid
, u8
*t
)
2099 int hsync
, hmin
, hmax
;
2102 if (edid
->revision
>= 4)
2103 hmin
+= ((t
[4] & 0x04) ? 255 : 0);
2105 if (edid
->revision
>= 4)
2106 hmax
+= ((t
[4] & 0x08) ? 255 : 0);
2107 hsync
= drm_mode_hsync(mode
);
2109 return (hsync
<= hmax
&& hsync
>= hmin
);
2113 mode_in_vsync_range(const struct drm_display_mode
*mode
,
2114 struct edid
*edid
, u8
*t
)
2116 int vsync
, vmin
, vmax
;
2119 if (edid
->revision
>= 4)
2120 vmin
+= ((t
[4] & 0x01) ? 255 : 0);
2122 if (edid
->revision
>= 4)
2123 vmax
+= ((t
[4] & 0x02) ? 255 : 0);
2124 vsync
= drm_mode_vrefresh(mode
);
2126 return (vsync
<= vmax
&& vsync
>= vmin
);
2130 range_pixel_clock(struct edid
*edid
, u8
*t
)
2133 if (t
[9] == 0 || t
[9] == 255)
2136 /* 1.4 with CVT support gives us real precision, yay */
2137 if (edid
->revision
>= 4 && t
[10] == 0x04)
2138 return (t
[9] * 10000) - ((t
[12] >> 2) * 250);
2140 /* 1.3 is pathetic, so fuzz up a bit */
2141 return t
[9] * 10000 + 5001;
2145 mode_in_range(const struct drm_display_mode
*mode
, struct edid
*edid
,
2146 struct detailed_timing
*timing
)
2149 u8
*t
= (u8
*)timing
;
2151 if (!mode_in_hsync_range(mode
, edid
, t
))
2154 if (!mode_in_vsync_range(mode
, edid
, t
))
2157 if ((max_clock
= range_pixel_clock(edid
, t
)))
2158 if (mode
->clock
> max_clock
)
2161 /* 1.4 max horizontal check */
2162 if (edid
->revision
>= 4 && t
[10] == 0x04)
2163 if (t
[13] && mode
->hdisplay
> 8 * (t
[13] + (256 * (t
[12]&0x3))))
2166 if (mode_is_rb(mode
) && !drm_monitor_supports_rb(edid
))
2172 static bool valid_inferred_mode(const struct drm_connector
*connector
,
2173 const struct drm_display_mode
*mode
)
2175 struct drm_display_mode
*m
;
2178 list_for_each_entry(m
, &connector
->probed_modes
, head
) {
2179 if (mode
->hdisplay
== m
->hdisplay
&&
2180 mode
->vdisplay
== m
->vdisplay
&&
2181 drm_mode_vrefresh(mode
) == drm_mode_vrefresh(m
))
2182 return false; /* duplicated */
2183 if (mode
->hdisplay
<= m
->hdisplay
&&
2184 mode
->vdisplay
<= m
->vdisplay
)
2191 drm_dmt_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2192 struct detailed_timing
*timing
)
2195 struct drm_display_mode
*newmode
;
2196 struct drm_device
*dev
= connector
->dev
;
2198 for (i
= 0; i
< ARRAY_SIZE(drm_dmt_modes
); i
++) {
2199 if (mode_in_range(drm_dmt_modes
+ i
, edid
, timing
) &&
2200 valid_inferred_mode(connector
, drm_dmt_modes
+ i
)) {
2201 newmode
= drm_mode_duplicate(dev
, &drm_dmt_modes
[i
]);
2203 drm_mode_probed_add(connector
, newmode
);
2212 /* fix up 1366x768 mode from 1368x768;
2213 * GFT/CVT can't express 1366 width which isn't dividable by 8
2215 static void fixup_mode_1366x768(struct drm_display_mode
*mode
)
2217 if (mode
->hdisplay
== 1368 && mode
->vdisplay
== 768) {
2218 mode
->hdisplay
= 1366;
2219 mode
->hsync_start
--;
2221 drm_mode_set_name(mode
);
2226 drm_gtf_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2227 struct detailed_timing
*timing
)
2230 struct drm_display_mode
*newmode
;
2231 struct drm_device
*dev
= connector
->dev
;
2233 for (i
= 0; i
< ARRAY_SIZE(extra_modes
); i
++) {
2234 const struct minimode
*m
= &extra_modes
[i
];
2235 newmode
= drm_gtf_mode(dev
, m
->w
, m
->h
, m
->r
, 0, 0);
2239 fixup_mode_1366x768(newmode
);
2240 if (!mode_in_range(newmode
, edid
, timing
) ||
2241 !valid_inferred_mode(connector
, newmode
)) {
2242 drm_mode_destroy(dev
, newmode
);
2246 drm_mode_probed_add(connector
, newmode
);
2254 drm_cvt_modes_for_range(struct drm_connector
*connector
, struct edid
*edid
,
2255 struct detailed_timing
*timing
)
2258 struct drm_display_mode
*newmode
;
2259 struct drm_device
*dev
= connector
->dev
;
2260 bool rb
= drm_monitor_supports_rb(edid
);
2262 for (i
= 0; i
< ARRAY_SIZE(extra_modes
); i
++) {
2263 const struct minimode
*m
= &extra_modes
[i
];
2264 newmode
= drm_cvt_mode(dev
, m
->w
, m
->h
, m
->r
, rb
, 0, 0);
2268 fixup_mode_1366x768(newmode
);
2269 if (!mode_in_range(newmode
, edid
, timing
) ||
2270 !valid_inferred_mode(connector
, newmode
)) {
2271 drm_mode_destroy(dev
, newmode
);
2275 drm_mode_probed_add(connector
, newmode
);
2283 do_inferred_modes(struct detailed_timing
*timing
, void *c
)
2285 struct detailed_mode_closure
*closure
= c
;
2286 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2287 struct detailed_data_monitor_range
*range
= &data
->data
.range
;
2289 if (data
->type
!= EDID_DETAIL_MONITOR_RANGE
)
2292 closure
->modes
+= drm_dmt_modes_for_range(closure
->connector
,
2296 if (!version_greater(closure
->edid
, 1, 1))
2297 return; /* GTF not defined yet */
2299 switch (range
->flags
) {
2300 case 0x02: /* secondary gtf, XXX could do more */
2301 case 0x00: /* default gtf */
2302 closure
->modes
+= drm_gtf_modes_for_range(closure
->connector
,
2306 case 0x04: /* cvt, only in 1.4+ */
2307 if (!version_greater(closure
->edid
, 1, 3))
2310 closure
->modes
+= drm_cvt_modes_for_range(closure
->connector
,
2314 case 0x01: /* just the ranges, no formula */
2321 add_inferred_modes(struct drm_connector
*connector
, struct edid
*edid
)
2323 struct detailed_mode_closure closure
= {
2324 .connector
= connector
,
2328 if (version_greater(edid
, 1, 0))
2329 drm_for_each_detailed_block((u8
*)edid
, do_inferred_modes
,
2332 return closure
.modes
;
2336 drm_est3_modes(struct drm_connector
*connector
, struct detailed_timing
*timing
)
2338 int i
, j
, m
, modes
= 0;
2339 struct drm_display_mode
*mode
;
2340 u8
*est
= ((u8
*)timing
) + 6;
2342 for (i
= 0; i
< 6; i
++) {
2343 for (j
= 7; j
>= 0; j
--) {
2344 m
= (i
* 8) + (7 - j
);
2345 if (m
>= ARRAY_SIZE(est3_modes
))
2347 if (est
[i
] & (1 << j
)) {
2348 mode
= drm_mode_find_dmt(connector
->dev
,
2354 drm_mode_probed_add(connector
, mode
);
2365 do_established_modes(struct detailed_timing
*timing
, void *c
)
2367 struct detailed_mode_closure
*closure
= c
;
2368 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2370 if (data
->type
== EDID_DETAIL_EST_TIMINGS
)
2371 closure
->modes
+= drm_est3_modes(closure
->connector
, timing
);
2375 * add_established_modes - get est. modes from EDID and add them
2376 * @connector: connector to add mode(s) to
2377 * @edid: EDID block to scan
2379 * Each EDID block contains a bitmap of the supported "established modes" list
2380 * (defined above). Tease them out and add them to the global modes list.
2383 add_established_modes(struct drm_connector
*connector
, struct edid
*edid
)
2385 struct drm_device
*dev
= connector
->dev
;
2386 unsigned long est_bits
= edid
->established_timings
.t1
|
2387 (edid
->established_timings
.t2
<< 8) |
2388 ((edid
->established_timings
.mfg_rsvd
& 0x80) << 9);
2390 struct detailed_mode_closure closure
= {
2391 .connector
= connector
,
2395 for (i
= 0; i
<= EDID_EST_TIMINGS
; i
++) {
2396 if (est_bits
& (1<<i
)) {
2397 struct drm_display_mode
*newmode
;
2398 newmode
= drm_mode_duplicate(dev
, &edid_est_modes
[i
]);
2400 drm_mode_probed_add(connector
, newmode
);
2406 if (version_greater(edid
, 1, 0))
2407 drm_for_each_detailed_block((u8
*)edid
,
2408 do_established_modes
, &closure
);
2410 return modes
+ closure
.modes
;
2414 do_standard_modes(struct detailed_timing
*timing
, void *c
)
2416 struct detailed_mode_closure
*closure
= c
;
2417 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2418 struct drm_connector
*connector
= closure
->connector
;
2419 struct edid
*edid
= closure
->edid
;
2421 if (data
->type
== EDID_DETAIL_STD_MODES
) {
2423 for (i
= 0; i
< 6; i
++) {
2424 struct std_timing
*std
;
2425 struct drm_display_mode
*newmode
;
2427 std
= &data
->data
.timings
[i
];
2428 newmode
= drm_mode_std(connector
, edid
, std
);
2430 drm_mode_probed_add(connector
, newmode
);
2438 * add_standard_modes - get std. modes from EDID and add them
2439 * @connector: connector to add mode(s) to
2440 * @edid: EDID block to scan
2442 * Standard modes can be calculated using the appropriate standard (DMT,
2443 * GTF or CVT. Grab them from @edid and add them to the list.
2446 add_standard_modes(struct drm_connector
*connector
, struct edid
*edid
)
2449 struct detailed_mode_closure closure
= {
2450 .connector
= connector
,
2454 for (i
= 0; i
< EDID_STD_TIMINGS
; i
++) {
2455 struct drm_display_mode
*newmode
;
2457 newmode
= drm_mode_std(connector
, edid
,
2458 &edid
->standard_timings
[i
]);
2460 drm_mode_probed_add(connector
, newmode
);
2465 if (version_greater(edid
, 1, 0))
2466 drm_for_each_detailed_block((u8
*)edid
, do_standard_modes
,
2469 /* XXX should also look for standard codes in VTB blocks */
2471 return modes
+ closure
.modes
;
2474 static int drm_cvt_modes(struct drm_connector
*connector
,
2475 struct detailed_timing
*timing
)
2477 int i
, j
, modes
= 0;
2478 struct drm_display_mode
*newmode
;
2479 struct drm_device
*dev
= connector
->dev
;
2480 struct cvt_timing
*cvt
;
2481 const int rates
[] = { 60, 85, 75, 60, 50 };
2482 const u8 empty
[3] = { 0, 0, 0 };
2484 for (i
= 0; i
< 4; i
++) {
2485 int width
= 0, height
;
2486 cvt
= &(timing
->data
.other_data
.data
.cvt
[i
]);
2488 if (!memcmp(cvt
->code
, empty
, 3))
2491 height
= (cvt
->code
[0] + ((cvt
->code
[1] & 0xf0) << 4) + 1) * 2;
2492 switch (cvt
->code
[1] & 0x0c) {
2494 width
= height
* 4 / 3;
2497 width
= height
* 16 / 9;
2500 width
= height
* 16 / 10;
2503 width
= height
* 15 / 9;
2507 for (j
= 1; j
< 5; j
++) {
2508 if (cvt
->code
[2] & (1 << j
)) {
2509 newmode
= drm_cvt_mode(dev
, width
, height
,
2513 drm_mode_probed_add(connector
, newmode
);
2524 do_cvt_mode(struct detailed_timing
*timing
, void *c
)
2526 struct detailed_mode_closure
*closure
= c
;
2527 struct detailed_non_pixel
*data
= &timing
->data
.other_data
;
2529 if (data
->type
== EDID_DETAIL_CVT_3BYTE
)
2530 closure
->modes
+= drm_cvt_modes(closure
->connector
, timing
);
2534 add_cvt_modes(struct drm_connector
*connector
, struct edid
*edid
)
2536 struct detailed_mode_closure closure
= {
2537 .connector
= connector
,
2541 if (version_greater(edid
, 1, 2))
2542 drm_for_each_detailed_block((u8
*)edid
, do_cvt_mode
, &closure
);
2544 /* XXX should also look for CVT codes in VTB blocks */
2546 return closure
.modes
;
2549 static void fixup_detailed_cea_mode_clock(struct drm_display_mode
*mode
);
2552 do_detailed_mode(struct detailed_timing
*timing
, void *c
)
2554 struct detailed_mode_closure
*closure
= c
;
2555 struct drm_display_mode
*newmode
;
2557 if (timing
->pixel_clock
) {
2558 newmode
= drm_mode_detailed(closure
->connector
->dev
,
2559 closure
->edid
, timing
,
2564 if (closure
->preferred
)
2565 newmode
->type
|= DRM_MODE_TYPE_PREFERRED
;
2568 * Detailed modes are limited to 10kHz pixel clock resolution,
2569 * so fix up anything that looks like CEA/HDMI mode, but the clock
2570 * is just slightly off.
2572 fixup_detailed_cea_mode_clock(newmode
);
2574 drm_mode_probed_add(closure
->connector
, newmode
);
2576 closure
->preferred
= 0;
2581 * add_detailed_modes - Add modes from detailed timings
2582 * @connector: attached connector
2583 * @edid: EDID block to scan
2584 * @quirks: quirks to apply
2587 add_detailed_modes(struct drm_connector
*connector
, struct edid
*edid
,
2590 struct detailed_mode_closure closure
= {
2591 .connector
= connector
,
2597 if (closure
.preferred
&& !version_greater(edid
, 1, 3))
2599 (edid
->features
& DRM_EDID_FEATURE_PREFERRED_TIMING
);
2601 drm_for_each_detailed_block((u8
*)edid
, do_detailed_mode
, &closure
);
2603 return closure
.modes
;
2606 #define AUDIO_BLOCK 0x01
2607 #define VIDEO_BLOCK 0x02
2608 #define VENDOR_BLOCK 0x03
2609 #define SPEAKER_BLOCK 0x04
2610 #define VIDEO_CAPABILITY_BLOCK 0x07
2611 #define EDID_BASIC_AUDIO (1 << 6)
2612 #define EDID_CEA_YCRCB444 (1 << 5)
2613 #define EDID_CEA_YCRCB422 (1 << 4)
2614 #define EDID_CEA_VCDB_QS (1 << 6)
2617 * Search EDID for CEA extension block.
2619 static u8
*drm_find_edid_extension(struct edid
*edid
, int ext_id
)
2621 u8
*edid_ext
= NULL
;
2624 /* No EDID or EDID extensions */
2625 if (edid
== NULL
|| edid
->extensions
== 0)
2628 /* Find CEA extension */
2629 for (i
= 0; i
< edid
->extensions
; i
++) {
2630 edid_ext
= (u8
*)edid
+ EDID_LENGTH
* (i
+ 1);
2631 if (edid_ext
[0] == ext_id
)
2635 if (i
== edid
->extensions
)
2641 static u8
*drm_find_cea_extension(struct edid
*edid
)
2643 return drm_find_edid_extension(edid
, CEA_EXT
);
2646 static u8
*drm_find_displayid_extension(struct edid
*edid
)
2648 return drm_find_edid_extension(edid
, DISPLAYID_EXT
);
2652 * Calculate the alternate clock for the CEA mode
2653 * (60Hz vs. 59.94Hz etc.)
2656 cea_mode_alternate_clock(const struct drm_display_mode
*cea_mode
)
2658 unsigned int clock
= cea_mode
->clock
;
2660 if (cea_mode
->vrefresh
% 6 != 0)
2664 * edid_cea_modes contains the 59.94Hz
2665 * variant for 240 and 480 line modes,
2666 * and the 60Hz variant otherwise.
2668 if (cea_mode
->vdisplay
== 240 || cea_mode
->vdisplay
== 480)
2669 clock
= DIV_ROUND_CLOSEST(clock
* 1001, 1000);
2671 clock
= DIV_ROUND_CLOSEST(clock
* 1000, 1001);
2676 static u8
drm_match_cea_mode_clock_tolerance(const struct drm_display_mode
*to_match
,
2677 unsigned int clock_tolerance
)
2681 if (!to_match
->clock
)
2684 for (vic
= 1; vic
< ARRAY_SIZE(edid_cea_modes
); vic
++) {
2685 const struct drm_display_mode
*cea_mode
= &edid_cea_modes
[vic
];
2686 unsigned int clock1
, clock2
;
2688 /* Check both 60Hz and 59.94Hz */
2689 clock1
= cea_mode
->clock
;
2690 clock2
= cea_mode_alternate_clock(cea_mode
);
2692 if (abs(to_match
->clock
- clock1
) > clock_tolerance
&&
2693 abs(to_match
->clock
- clock2
) > clock_tolerance
)
2696 if (drm_mode_equal_no_clocks(to_match
, cea_mode
))
2704 * drm_match_cea_mode - look for a CEA mode matching given mode
2705 * @to_match: display mode
2707 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
2710 u8
drm_match_cea_mode(const struct drm_display_mode
*to_match
)
2714 if (!to_match
->clock
)
2717 for (vic
= 1; vic
< ARRAY_SIZE(edid_cea_modes
); vic
++) {
2718 const struct drm_display_mode
*cea_mode
= &edid_cea_modes
[vic
];
2719 unsigned int clock1
, clock2
;
2721 /* Check both 60Hz and 59.94Hz */
2722 clock1
= cea_mode
->clock
;
2723 clock2
= cea_mode_alternate_clock(cea_mode
);
2725 if ((KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock1
) ||
2726 KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock2
)) &&
2727 drm_mode_equal_no_clocks_no_stereo(to_match
, cea_mode
))
2732 EXPORT_SYMBOL(drm_match_cea_mode
);
2734 static bool drm_valid_cea_vic(u8 vic
)
2736 return vic
> 0 && vic
< ARRAY_SIZE(edid_cea_modes
);
2740 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2741 * the input VIC from the CEA mode list
2742 * @video_code: ID given to each of the CEA modes
2744 * Returns picture aspect ratio
2746 enum hdmi_picture_aspect
drm_get_cea_aspect_ratio(const u8 video_code
)
2748 return edid_cea_modes
[video_code
].picture_aspect_ratio
;
2750 EXPORT_SYMBOL(drm_get_cea_aspect_ratio
);
2753 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2756 * It's almost like cea_mode_alternate_clock(), we just need to add an
2757 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2761 hdmi_mode_alternate_clock(const struct drm_display_mode
*hdmi_mode
)
2763 if (hdmi_mode
->vdisplay
== 4096 && hdmi_mode
->hdisplay
== 2160)
2764 return hdmi_mode
->clock
;
2766 return cea_mode_alternate_clock(hdmi_mode
);
2769 static u8
drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode
*to_match
,
2770 unsigned int clock_tolerance
)
2774 if (!to_match
->clock
)
2777 for (vic
= 1; vic
< ARRAY_SIZE(edid_4k_modes
); vic
++) {
2778 const struct drm_display_mode
*hdmi_mode
= &edid_4k_modes
[vic
];
2779 unsigned int clock1
, clock2
;
2781 /* Make sure to also match alternate clocks */
2782 clock1
= hdmi_mode
->clock
;
2783 clock2
= hdmi_mode_alternate_clock(hdmi_mode
);
2785 if (abs(to_match
->clock
- clock1
) > clock_tolerance
&&
2786 abs(to_match
->clock
- clock2
) > clock_tolerance
)
2789 if (drm_mode_equal_no_clocks(to_match
, hdmi_mode
))
2797 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2798 * @to_match: display mode
2800 * An HDMI mode is one defined in the HDMI vendor specific block.
2802 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2804 static u8
drm_match_hdmi_mode(const struct drm_display_mode
*to_match
)
2808 if (!to_match
->clock
)
2811 for (vic
= 1; vic
< ARRAY_SIZE(edid_4k_modes
); vic
++) {
2812 const struct drm_display_mode
*hdmi_mode
= &edid_4k_modes
[vic
];
2813 unsigned int clock1
, clock2
;
2815 /* Make sure to also match alternate clocks */
2816 clock1
= hdmi_mode
->clock
;
2817 clock2
= hdmi_mode_alternate_clock(hdmi_mode
);
2819 if ((KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock1
) ||
2820 KHZ2PICOS(to_match
->clock
) == KHZ2PICOS(clock2
)) &&
2821 drm_mode_equal_no_clocks_no_stereo(to_match
, hdmi_mode
))
2827 static bool drm_valid_hdmi_vic(u8 vic
)
2829 return vic
> 0 && vic
< ARRAY_SIZE(edid_4k_modes
);
2833 add_alternate_cea_modes(struct drm_connector
*connector
, struct edid
*edid
)
2835 struct drm_device
*dev
= connector
->dev
;
2836 struct drm_display_mode
*mode
, *tmp
;
2837 LINUX_LIST_HEAD(list
);
2840 /* Don't add CEA modes if the CEA extension block is missing */
2841 if (!drm_find_cea_extension(edid
))
2845 * Go through all probed modes and create a new mode
2846 * with the alternate clock for certain CEA modes.
2848 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
2849 const struct drm_display_mode
*cea_mode
= NULL
;
2850 struct drm_display_mode
*newmode
;
2851 u8 vic
= drm_match_cea_mode(mode
);
2852 unsigned int clock1
, clock2
;
2854 if (drm_valid_cea_vic(vic
)) {
2855 cea_mode
= &edid_cea_modes
[vic
];
2856 clock2
= cea_mode_alternate_clock(cea_mode
);
2858 vic
= drm_match_hdmi_mode(mode
);
2859 if (drm_valid_hdmi_vic(vic
)) {
2860 cea_mode
= &edid_4k_modes
[vic
];
2861 clock2
= hdmi_mode_alternate_clock(cea_mode
);
2868 clock1
= cea_mode
->clock
;
2870 if (clock1
== clock2
)
2873 if (mode
->clock
!= clock1
&& mode
->clock
!= clock2
)
2876 newmode
= drm_mode_duplicate(dev
, cea_mode
);
2880 /* Carry over the stereo flags */
2881 newmode
->flags
|= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
2884 * The current mode could be either variant. Make
2885 * sure to pick the "other" clock for the new mode.
2887 if (mode
->clock
!= clock1
)
2888 newmode
->clock
= clock1
;
2890 newmode
->clock
= clock2
;
2892 list_add_tail(&newmode
->head
, &list
);
2895 list_for_each_entry_safe(mode
, tmp
, &list
, head
) {
2896 list_del(&mode
->head
);
2897 drm_mode_probed_add(connector
, mode
);
2904 static struct drm_display_mode
*
2905 drm_display_mode_from_vic_index(struct drm_connector
*connector
,
2906 const u8
*video_db
, u8 video_len
,
2909 struct drm_device
*dev
= connector
->dev
;
2910 struct drm_display_mode
*newmode
;
2913 if (video_db
== NULL
|| video_index
>= video_len
)
2916 /* CEA modes are numbered 1..127 */
2917 vic
= (video_db
[video_index
] & 127);
2918 if (!drm_valid_cea_vic(vic
))
2921 newmode
= drm_mode_duplicate(dev
, &edid_cea_modes
[vic
]);
2925 newmode
->vrefresh
= 0;
2931 do_cea_modes(struct drm_connector
*connector
, const u8
*db
, u8 len
)
2935 for (i
= 0; i
< len
; i
++) {
2936 struct drm_display_mode
*mode
;
2937 mode
= drm_display_mode_from_vic_index(connector
, db
, len
, i
);
2939 drm_mode_probed_add(connector
, mode
);
2947 struct stereo_mandatory_mode
{
2948 int width
, height
, vrefresh
;
2952 static const struct stereo_mandatory_mode stereo_mandatory_modes
[] = {
2953 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2954 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING
},
2956 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
},
2958 DRM_MODE_FLAG_INTERLACE
| DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
},
2959 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2960 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING
},
2961 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
},
2962 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING
}
2966 stereo_match_mandatory(const struct drm_display_mode
*mode
,
2967 const struct stereo_mandatory_mode
*stereo_mode
)
2969 unsigned int interlaced
= mode
->flags
& DRM_MODE_FLAG_INTERLACE
;
2971 return mode
->hdisplay
== stereo_mode
->width
&&
2972 mode
->vdisplay
== stereo_mode
->height
&&
2973 interlaced
== (stereo_mode
->flags
& DRM_MODE_FLAG_INTERLACE
) &&
2974 drm_mode_vrefresh(mode
) == stereo_mode
->vrefresh
;
2977 static int add_hdmi_mandatory_stereo_modes(struct drm_connector
*connector
)
2979 struct drm_device
*dev
= connector
->dev
;
2980 struct drm_display_mode
*mode
;
2981 struct list_head stereo_modes
;
2984 INIT_LIST_HEAD(&stereo_modes
);
2986 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
2987 for (i
= 0; i
< ARRAY_SIZE(stereo_mandatory_modes
); i
++) {
2988 const struct stereo_mandatory_mode
*mandatory
;
2989 struct drm_display_mode
*new_mode
;
2991 if (!stereo_match_mandatory(mode
,
2992 &stereo_mandatory_modes
[i
]))
2995 mandatory
= &stereo_mandatory_modes
[i
];
2996 new_mode
= drm_mode_duplicate(dev
, mode
);
3000 new_mode
->flags
|= mandatory
->flags
;
3001 list_add_tail(&new_mode
->head
, &stereo_modes
);
3006 list_splice_tail(&stereo_modes
, &connector
->probed_modes
);
3011 static int add_hdmi_mode(struct drm_connector
*connector
, u8 vic
)
3013 struct drm_device
*dev
= connector
->dev
;
3014 struct drm_display_mode
*newmode
;
3016 if (!drm_valid_hdmi_vic(vic
)) {
3017 DRM_ERROR("Unknown HDMI VIC: %d\n", vic
);
3021 newmode
= drm_mode_duplicate(dev
, &edid_4k_modes
[vic
]);
3025 drm_mode_probed_add(connector
, newmode
);
3030 static int add_3d_struct_modes(struct drm_connector
*connector
, u16 structure
,
3031 const u8
*video_db
, u8 video_len
, u8 video_index
)
3033 struct drm_display_mode
*newmode
;
3036 if (structure
& (1 << 0)) {
3037 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3041 newmode
->flags
|= DRM_MODE_FLAG_3D_FRAME_PACKING
;
3042 drm_mode_probed_add(connector
, newmode
);
3046 if (structure
& (1 << 6)) {
3047 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3051 newmode
->flags
|= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
;
3052 drm_mode_probed_add(connector
, newmode
);
3056 if (structure
& (1 << 8)) {
3057 newmode
= drm_display_mode_from_vic_index(connector
, video_db
,
3061 newmode
->flags
|= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
;
3062 drm_mode_probed_add(connector
, newmode
);
3071 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3072 * @connector: connector corresponding to the HDMI sink
3073 * @db: start of the CEA vendor specific block
3074 * @len: length of the CEA block payload, ie. one can access up to db[len]
3076 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3077 * also adds the stereo 3d modes when applicable.
3080 do_hdmi_vsdb_modes(struct drm_connector
*connector
, const u8
*db
, u8 len
,
3081 const u8
*video_db
, u8 video_len
)
3083 int modes
= 0, offset
= 0, i
, multi_present
= 0, multi_len
;
3084 u8 vic_len
, hdmi_3d_len
= 0;
3091 /* no HDMI_Video_Present */
3092 if (!(db
[8] & (1 << 5)))
3095 /* Latency_Fields_Present */
3096 if (db
[8] & (1 << 7))
3099 /* I_Latency_Fields_Present */
3100 if (db
[8] & (1 << 6))
3103 /* the declared length is not long enough for the 2 first bytes
3104 * of additional video format capabilities */
3105 if (len
< (8 + offset
+ 2))
3110 if (db
[8 + offset
] & (1 << 7)) {
3111 modes
+= add_hdmi_mandatory_stereo_modes(connector
);
3113 /* 3D_Multi_present */
3114 multi_present
= (db
[8 + offset
] & 0x60) >> 5;
3118 vic_len
= db
[8 + offset
] >> 5;
3119 hdmi_3d_len
= db
[8 + offset
] & 0x1f;
3121 for (i
= 0; i
< vic_len
&& len
>= (9 + offset
+ i
); i
++) {
3124 vic
= db
[9 + offset
+ i
];
3125 modes
+= add_hdmi_mode(connector
, vic
);
3127 offset
+= 1 + vic_len
;
3129 if (multi_present
== 1)
3131 else if (multi_present
== 2)
3136 if (len
< (8 + offset
+ hdmi_3d_len
- 1))
3139 if (hdmi_3d_len
< multi_len
)
3142 if (multi_present
== 1 || multi_present
== 2) {
3143 /* 3D_Structure_ALL */
3144 structure_all
= (db
[8 + offset
] << 8) | db
[9 + offset
];
3146 /* check if 3D_MASK is present */
3147 if (multi_present
== 2)
3148 mask
= (db
[10 + offset
] << 8) | db
[11 + offset
];
3152 for (i
= 0; i
< 16; i
++) {
3153 if (mask
& (1 << i
))
3154 modes
+= add_3d_struct_modes(connector
,
3161 offset
+= multi_len
;
3163 for (i
= 0; i
< (hdmi_3d_len
- multi_len
); i
++) {
3165 struct drm_display_mode
*newmode
= NULL
;
3166 unsigned int newflag
= 0;
3167 bool detail_present
;
3169 detail_present
= ((db
[8 + offset
+ i
] & 0x0f) > 7);
3171 if (detail_present
&& (i
+ 1 == hdmi_3d_len
- multi_len
))
3174 /* 2D_VIC_order_X */
3175 vic_index
= db
[8 + offset
+ i
] >> 4;
3177 /* 3D_Structure_X */
3178 switch (db
[8 + offset
+ i
] & 0x0f) {
3180 newflag
= DRM_MODE_FLAG_3D_FRAME_PACKING
;
3183 newflag
= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
;
3187 if ((db
[9 + offset
+ i
] >> 4) == 1)
3188 newflag
= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
;
3193 newmode
= drm_display_mode_from_vic_index(connector
,
3199 newmode
->flags
|= newflag
;
3200 drm_mode_probed_add(connector
, newmode
);
3214 cea_db_payload_len(const u8
*db
)
3216 return db
[0] & 0x1f;
3220 cea_db_tag(const u8
*db
)
3226 cea_revision(const u8
*cea
)
3232 cea_db_offsets(const u8
*cea
, int *start
, int *end
)
3234 /* Data block offset in CEA extension block */
3239 if (*end
< 4 || *end
> 127)
3244 static bool cea_db_is_hdmi_vsdb(const u8
*db
)
3248 if (cea_db_tag(db
) != VENDOR_BLOCK
)
3251 if (cea_db_payload_len(db
) < 5)
3254 hdmi_id
= db
[1] | (db
[2] << 8) | (db
[3] << 16);
3256 return hdmi_id
== HDMI_IEEE_OUI
;
3259 #define for_each_cea_db(cea, i, start, end) \
3260 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3263 add_cea_modes(struct drm_connector
*connector
, struct edid
*edid
)
3265 const u8
*cea
= drm_find_cea_extension(edid
);
3266 const u8
*db
, *hdmi
= NULL
, *video
= NULL
;
3267 u8 dbl
, hdmi_len
, video_len
= 0;
3270 if (cea
&& cea_revision(cea
) >= 3) {
3273 if (cea_db_offsets(cea
, &start
, &end
))
3276 for_each_cea_db(cea
, i
, start
, end
) {
3278 dbl
= cea_db_payload_len(db
);
3280 if (cea_db_tag(db
) == VIDEO_BLOCK
) {
3283 modes
+= do_cea_modes(connector
, video
, dbl
);
3285 else if (cea_db_is_hdmi_vsdb(db
)) {
3293 * We parse the HDMI VSDB after having added the cea modes as we will
3294 * be patching their flags when the sink supports stereo 3D.
3297 modes
+= do_hdmi_vsdb_modes(connector
, hdmi
, hdmi_len
, video
,
3303 static void fixup_detailed_cea_mode_clock(struct drm_display_mode
*mode
)
3305 const struct drm_display_mode
*cea_mode
;
3306 int clock1
, clock2
, clock
;
3311 * allow 5kHz clock difference either way to account for
3312 * the 10kHz clock resolution limit of detailed timings.
3314 vic
= drm_match_cea_mode_clock_tolerance(mode
, 5);
3315 if (drm_valid_cea_vic(vic
)) {
3317 cea_mode
= &edid_cea_modes
[vic
];
3318 clock1
= cea_mode
->clock
;
3319 clock2
= cea_mode_alternate_clock(cea_mode
);
3321 vic
= drm_match_hdmi_mode_clock_tolerance(mode
, 5);
3322 if (drm_valid_hdmi_vic(vic
)) {
3324 cea_mode
= &edid_4k_modes
[vic
];
3325 clock1
= cea_mode
->clock
;
3326 clock2
= hdmi_mode_alternate_clock(cea_mode
);
3332 /* pick whichever is closest */
3333 if (abs(mode
->clock
- clock1
) < abs(mode
->clock
- clock2
))
3338 if (mode
->clock
== clock
)
3341 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
3342 type
, vic
, mode
->clock
, clock
);
3343 mode
->clock
= clock
;
3347 parse_hdmi_vsdb(struct drm_connector
*connector
, const u8
*db
)
3349 u8 len
= cea_db_payload_len(db
);
3352 connector
->eld
[5] |= (db
[6] >> 7) << 1; /* Supports_AI */
3353 connector
->dvi_dual
= db
[6] & 1;
3356 connector
->max_tmds_clock
= db
[7] * 5;
3358 connector
->latency_present
[0] = db
[8] >> 7;
3359 connector
->latency_present
[1] = (db
[8] >> 6) & 1;
3362 connector
->video_latency
[0] = db
[9];
3364 connector
->audio_latency
[0] = db
[10];
3366 connector
->video_latency
[1] = db
[11];
3368 connector
->audio_latency
[1] = db
[12];
3370 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
3371 "max TMDS clock %d, "
3372 "latency present %d %d, "
3373 "video latency %d %d, "
3374 "audio latency %d %d\n",
3375 connector
->dvi_dual
,
3376 connector
->max_tmds_clock
,
3377 (int) connector
->latency_present
[0],
3378 (int) connector
->latency_present
[1],
3379 connector
->video_latency
[0],
3380 connector
->video_latency
[1],
3381 connector
->audio_latency
[0],
3382 connector
->audio_latency
[1]);
3386 monitor_name(struct detailed_timing
*t
, void *data
)
3388 if (t
->data
.other_data
.type
== EDID_DETAIL_MONITOR_NAME
)
3389 *(u8
**)data
= t
->data
.other_data
.data
.str
.str
;
3392 static int get_monitor_name(struct edid
*edid
, char name
[13])
3394 char *edid_name
= NULL
;
3400 drm_for_each_detailed_block((u8
*)edid
, monitor_name
, &edid_name
);
3401 for (mnl
= 0; edid_name
&& mnl
< 13; mnl
++) {
3402 if (edid_name
[mnl
] == 0x0a)
3405 name
[mnl
] = edid_name
[mnl
];
3412 * drm_edid_get_monitor_name - fetch the monitor name from the edid
3413 * @edid: monitor EDID information
3414 * @name: pointer to a character array to hold the name of the monitor
3415 * @bufsize: The size of the name buffer (should be at least 14 chars.)
3418 void drm_edid_get_monitor_name(struct edid
*edid
, char *name
, int bufsize
)
3426 name_length
= min(get_monitor_name(edid
, buf
), bufsize
- 1);
3427 memcpy(name
, buf
, name_length
);
3428 name
[name_length
] = '\0';
3430 EXPORT_SYMBOL(drm_edid_get_monitor_name
);
3433 * drm_edid_to_eld - build ELD from EDID
3434 * @connector: connector corresponding to the HDMI/DP sink
3435 * @edid: EDID to parse
3437 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3438 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3441 void drm_edid_to_eld(struct drm_connector
*connector
, struct edid
*edid
)
3443 uint8_t *eld
= connector
->eld
;
3446 int total_sad_count
= 0;
3450 memset(eld
, 0, sizeof(connector
->eld
));
3452 cea
= drm_find_cea_extension(edid
);
3454 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3458 mnl
= get_monitor_name(edid
, eld
+ 20);
3460 eld
[4] = (cea
[1] << 5) | mnl
;
3461 DRM_DEBUG_KMS("ELD monitor %s\n", eld
+ 20);
3463 eld
[0] = 2 << 3; /* ELD version: 2 */
3465 eld
[16] = edid
->mfg_id
[0];
3466 eld
[17] = edid
->mfg_id
[1];
3467 eld
[18] = edid
->prod_code
[0];
3468 eld
[19] = edid
->prod_code
[1];
3470 if (cea_revision(cea
) >= 3) {
3473 if (cea_db_offsets(cea
, &start
, &end
)) {
3478 for_each_cea_db(cea
, i
, start
, end
) {
3480 dbl
= cea_db_payload_len(db
);
3482 switch (cea_db_tag(db
)) {
3486 /* Audio Data Block, contains SADs */
3487 sad_count
= min(dbl
/ 3, 15 - total_sad_count
);
3489 memcpy(eld
+ 20 + mnl
+ total_sad_count
* 3,
3490 &db
[1], sad_count
* 3);
3491 total_sad_count
+= sad_count
;
3494 /* Speaker Allocation Data Block */
3499 /* HDMI Vendor-Specific Data Block */
3500 if (cea_db_is_hdmi_vsdb(db
))
3501 parse_hdmi_vsdb(connector
, db
);
3508 eld
[5] |= total_sad_count
<< 4;
3510 eld
[DRM_ELD_BASELINE_ELD_LEN
] =
3511 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld
), 4);
3513 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
3514 drm_eld_size(eld
), total_sad_count
);
3516 EXPORT_SYMBOL(drm_edid_to_eld
);
3519 * drm_edid_to_sad - extracts SADs from EDID
3520 * @edid: EDID to parse
3521 * @sads: pointer that will be set to the extracted SADs
3523 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
3525 * Note: The returned pointer needs to be freed using kfree().
3527 * Return: The number of found SADs or negative number on error.
3529 int drm_edid_to_sad(struct edid
*edid
, struct cea_sad
**sads
)
3532 int i
, start
, end
, dbl
;
3535 cea
= drm_find_cea_extension(edid
);
3537 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3541 if (cea_revision(cea
) < 3) {
3542 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3546 if (cea_db_offsets(cea
, &start
, &end
)) {
3547 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3551 for_each_cea_db(cea
, i
, start
, end
) {
3554 if (cea_db_tag(db
) == AUDIO_BLOCK
) {
3556 dbl
= cea_db_payload_len(db
);
3558 count
= dbl
/ 3; /* SAD is 3B */
3559 *sads
= kcalloc(count
, sizeof(**sads
), GFP_KERNEL
);
3562 for (j
= 0; j
< count
; j
++) {
3563 u8
*sad
= &db
[1 + j
* 3];
3565 (*sads
)[j
].format
= (sad
[0] & 0x78) >> 3;
3566 (*sads
)[j
].channels
= sad
[0] & 0x7;
3567 (*sads
)[j
].freq
= sad
[1] & 0x7F;
3568 (*sads
)[j
].byte2
= sad
[2];
3576 EXPORT_SYMBOL(drm_edid_to_sad
);
3579 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3580 * @edid: EDID to parse
3581 * @sadb: pointer to the speaker block
3583 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
3585 * Note: The returned pointer needs to be freed using kfree().
3587 * Return: The number of found Speaker Allocation Blocks or negative number on
3590 int drm_edid_to_speaker_allocation(struct edid
*edid
, u8
**sadb
)
3593 int i
, start
, end
, dbl
;
3596 cea
= drm_find_cea_extension(edid
);
3598 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3602 if (cea_revision(cea
) < 3) {
3603 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3607 if (cea_db_offsets(cea
, &start
, &end
)) {
3608 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3612 for_each_cea_db(cea
, i
, start
, end
) {
3613 const u8
*db
= &cea
[i
];
3615 if (cea_db_tag(db
) == SPEAKER_BLOCK
) {
3616 dbl
= cea_db_payload_len(db
);
3618 /* Speaker Allocation Data Block */
3620 *sadb
= kmemdup(&db
[1], dbl
, GFP_KERNEL
);
3631 EXPORT_SYMBOL(drm_edid_to_speaker_allocation
);
3634 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
3635 * @connector: connector associated with the HDMI/DP sink
3636 * @mode: the display mode
3638 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3639 * the sink doesn't support audio or video.
3641 int drm_av_sync_delay(struct drm_connector
*connector
,
3642 const struct drm_display_mode
*mode
)
3644 int i
= !!(mode
->flags
& DRM_MODE_FLAG_INTERLACE
);
3647 if (!connector
->latency_present
[0])
3649 if (!connector
->latency_present
[1])
3652 a
= connector
->audio_latency
[i
];
3653 v
= connector
->video_latency
[i
];
3656 * HDMI/DP sink doesn't support audio or video?
3658 if (a
== 255 || v
== 255)
3662 * Convert raw EDID values to millisecond.
3663 * Treat unknown latency as 0ms.
3666 a
= min(2 * (a
- 1), 500);
3668 v
= min(2 * (v
- 1), 500);
3670 return max(v
- a
, 0);
3672 EXPORT_SYMBOL(drm_av_sync_delay
);
3675 * drm_select_eld - select one ELD from multiple HDMI/DP sinks
3676 * @encoder: the encoder just changed display mode
3678 * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
3679 * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
3681 * Return: The connector associated with the first HDMI/DP sink that has ELD
3684 struct drm_connector
*drm_select_eld(struct drm_encoder
*encoder
)
3686 struct drm_connector
*connector
;
3687 struct drm_device
*dev
= encoder
->dev
;
3689 WARN_ON(!mutex_is_locked(&dev
->mode_config
.mutex
));
3690 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
3692 drm_for_each_connector(connector
, dev
)
3693 if (connector
->encoder
== encoder
&& connector
->eld
[0])
3698 EXPORT_SYMBOL(drm_select_eld
);
3701 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
3702 * @edid: monitor EDID information
3704 * Parse the CEA extension according to CEA-861-B.
3706 * Return: True if the monitor is HDMI, false if not or unknown.
3708 bool drm_detect_hdmi_monitor(struct edid
*edid
)
3712 int start_offset
, end_offset
;
3714 edid_ext
= drm_find_cea_extension(edid
);
3718 if (cea_db_offsets(edid_ext
, &start_offset
, &end_offset
))
3722 * Because HDMI identifier is in Vendor Specific Block,
3723 * search it from all data blocks of CEA extension.
3725 for_each_cea_db(edid_ext
, i
, start_offset
, end_offset
) {
3726 if (cea_db_is_hdmi_vsdb(&edid_ext
[i
]))
3732 EXPORT_SYMBOL(drm_detect_hdmi_monitor
);
3735 * drm_detect_monitor_audio - check monitor audio capability
3736 * @edid: EDID block to scan
3738 * Monitor should have CEA extension block.
3739 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3740 * audio' only. If there is any audio extension block and supported
3741 * audio format, assume at least 'basic audio' support, even if 'basic
3742 * audio' is not defined in EDID.
3744 * Return: True if the monitor supports audio, false otherwise.
3746 bool drm_detect_monitor_audio(struct edid
*edid
)
3750 bool has_audio
= false;
3751 int start_offset
, end_offset
;
3753 edid_ext
= drm_find_cea_extension(edid
);
3757 has_audio
= ((edid_ext
[3] & EDID_BASIC_AUDIO
) != 0);
3760 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3764 if (cea_db_offsets(edid_ext
, &start_offset
, &end_offset
))
3767 for_each_cea_db(edid_ext
, i
, start_offset
, end_offset
) {
3768 if (cea_db_tag(&edid_ext
[i
]) == AUDIO_BLOCK
) {
3770 for (j
= 1; j
< cea_db_payload_len(&edid_ext
[i
]) + 1; j
+= 3)
3771 DRM_DEBUG_KMS("CEA audio format %d\n",
3772 (edid_ext
[i
+ j
] >> 3) & 0xf);
3779 EXPORT_SYMBOL(drm_detect_monitor_audio
);
3782 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
3783 * @edid: EDID block to scan
3785 * Check whether the monitor reports the RGB quantization range selection
3786 * as supported. The AVI infoframe can then be used to inform the monitor
3787 * which quantization range (full or limited) is used.
3789 * Return: True if the RGB quantization range is selectable, false otherwise.
3791 bool drm_rgb_quant_range_selectable(struct edid
*edid
)
3796 edid_ext
= drm_find_cea_extension(edid
);
3800 if (cea_db_offsets(edid_ext
, &start
, &end
))
3803 for_each_cea_db(edid_ext
, i
, start
, end
) {
3804 if (cea_db_tag(&edid_ext
[i
]) == VIDEO_CAPABILITY_BLOCK
&&
3805 cea_db_payload_len(&edid_ext
[i
]) == 2) {
3806 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext
[i
+ 2]);
3807 return edid_ext
[i
+ 2] & EDID_CEA_VCDB_QS
;
3813 EXPORT_SYMBOL(drm_rgb_quant_range_selectable
);
3816 * drm_assign_hdmi_deep_color_info - detect whether monitor supports
3817 * hdmi deep color modes and update drm_display_info if so.
3818 * @edid: monitor EDID information
3819 * @info: Updated with maximum supported deep color bpc and color format
3820 * if deep color supported.
3821 * @connector: DRM connector, used only for debug output
3823 * Parse the CEA extension according to CEA-861-B.
3824 * Return true if HDMI deep color supported, false if not or unknown.
3826 static bool drm_assign_hdmi_deep_color_info(struct edid
*edid
,
3827 struct drm_display_info
*info
,
3828 struct drm_connector
*connector
)
3830 u8
*edid_ext
, *hdmi
;
3832 int start_offset
, end_offset
;
3833 unsigned int dc_bpc
= 0;
3835 edid_ext
= drm_find_cea_extension(edid
);
3839 if (cea_db_offsets(edid_ext
, &start_offset
, &end_offset
))
3843 * Because HDMI identifier is in Vendor Specific Block,
3844 * search it from all data blocks of CEA extension.
3846 for_each_cea_db(edid_ext
, i
, start_offset
, end_offset
) {
3847 if (cea_db_is_hdmi_vsdb(&edid_ext
[i
])) {
3848 /* HDMI supports at least 8 bpc */
3851 hdmi
= &edid_ext
[i
];
3852 if (cea_db_payload_len(hdmi
) < 6)
3855 if (hdmi
[6] & DRM_EDID_HDMI_DC_30
) {
3857 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_30
;
3858 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
3862 if (hdmi
[6] & DRM_EDID_HDMI_DC_36
) {
3864 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_36
;
3865 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
3869 if (hdmi
[6] & DRM_EDID_HDMI_DC_48
) {
3871 info
->edid_hdmi_dc_modes
|= DRM_EDID_HDMI_DC_48
;
3872 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
3877 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
3878 connector
->name
, dc_bpc
);
3882 * Deep color support mandates RGB444 support for all video
3883 * modes and forbids YCRCB422 support for all video modes per
3886 info
->color_formats
= DRM_COLOR_FORMAT_RGB444
;
3888 /* YCRCB444 is optional according to spec. */
3889 if (hdmi
[6] & DRM_EDID_HDMI_DC_Y444
) {
3890 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3891 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
3896 * Spec says that if any deep color mode is supported at all,
3897 * then deep color 36 bit must be supported.
3899 if (!(hdmi
[6] & DRM_EDID_HDMI_DC_36
)) {
3900 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
3907 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
3917 * drm_add_display_info - pull display info out if present
3919 * @info: display info (attached to connector)
3920 * @connector: connector whose edid is used to build display info
3922 * Grab any available display info and stuff it into the drm_display_info
3923 * structure that's part of the connector. Useful for tracking bpp and
3926 static void drm_add_display_info(struct edid
*edid
,
3927 struct drm_display_info
*info
,
3928 struct drm_connector
*connector
)
3932 info
->width_mm
= edid
->width_cm
* 10;
3933 info
->height_mm
= edid
->height_cm
* 10;
3935 /* driver figures it out in this case */
3937 info
->color_formats
= 0;
3939 if (edid
->revision
< 3)
3942 if (!(edid
->input
& DRM_EDID_INPUT_DIGITAL
))
3945 /* Get data from CEA blocks if present */
3946 edid_ext
= drm_find_cea_extension(edid
);
3948 info
->cea_rev
= edid_ext
[1];
3950 /* The existence of a CEA block should imply RGB support */
3951 info
->color_formats
= DRM_COLOR_FORMAT_RGB444
;
3952 if (edid_ext
[3] & EDID_CEA_YCRCB444
)
3953 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3954 if (edid_ext
[3] & EDID_CEA_YCRCB422
)
3955 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB422
;
3958 /* HDMI deep color modes supported? Assign to info, if so */
3959 drm_assign_hdmi_deep_color_info(edid
, info
, connector
);
3961 /* Only defined for 1.4 with digital displays */
3962 if (edid
->revision
< 4)
3965 switch (edid
->input
& DRM_EDID_DIGITAL_DEPTH_MASK
) {
3966 case DRM_EDID_DIGITAL_DEPTH_6
:
3969 case DRM_EDID_DIGITAL_DEPTH_8
:
3972 case DRM_EDID_DIGITAL_DEPTH_10
:
3975 case DRM_EDID_DIGITAL_DEPTH_12
:
3978 case DRM_EDID_DIGITAL_DEPTH_14
:
3981 case DRM_EDID_DIGITAL_DEPTH_16
:
3984 case DRM_EDID_DIGITAL_DEPTH_UNDEF
:
3990 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
3991 connector
->name
, info
->bpc
);
3993 info
->color_formats
|= DRM_COLOR_FORMAT_RGB444
;
3994 if (edid
->features
& DRM_EDID_FEATURE_RGB_YCRCB444
)
3995 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB444
;
3996 if (edid
->features
& DRM_EDID_FEATURE_RGB_YCRCB422
)
3997 info
->color_formats
|= DRM_COLOR_FORMAT_YCRCB422
;
4000 static int validate_displayid(u8
*displayid
, int length
, int idx
)
4004 struct displayid_hdr
*base
;
4006 base
= (struct displayid_hdr
*)&displayid
[idx
];
4008 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4009 base
->rev
, base
->bytes
, base
->prod_id
, base
->ext_count
);
4011 if (base
->bytes
+ 5 > length
- idx
)
4013 for (i
= idx
; i
<= base
->bytes
+ 5; i
++) {
4014 csum
+= displayid
[i
];
4017 DRM_ERROR("DisplayID checksum invalid, remainder is %d\n", csum
);
4023 static struct drm_display_mode
*drm_mode_displayid_detailed(struct drm_device
*dev
,
4024 struct displayid_detailed_timings_1
*timings
)
4026 struct drm_display_mode
*mode
;
4027 unsigned pixel_clock
= (timings
->pixel_clock
[0] |
4028 (timings
->pixel_clock
[1] << 8) |
4029 (timings
->pixel_clock
[2] << 16));
4030 unsigned hactive
= (timings
->hactive
[0] | timings
->hactive
[1] << 8) + 1;
4031 unsigned hblank
= (timings
->hblank
[0] | timings
->hblank
[1] << 8) + 1;
4032 unsigned hsync
= (timings
->hsync
[0] | (timings
->hsync
[1] & 0x7f) << 8) + 1;
4033 unsigned hsync_width
= (timings
->hsw
[0] | timings
->hsw
[1] << 8) + 1;
4034 unsigned vactive
= (timings
->vactive
[0] | timings
->vactive
[1] << 8) + 1;
4035 unsigned vblank
= (timings
->vblank
[0] | timings
->vblank
[1] << 8) + 1;
4036 unsigned vsync
= (timings
->vsync
[0] | (timings
->vsync
[1] & 0x7f) << 8) + 1;
4037 unsigned vsync_width
= (timings
->vsw
[0] | timings
->vsw
[1] << 8) + 1;
4038 bool hsync_positive
= (timings
->hsync
[1] >> 7) & 0x1;
4039 bool vsync_positive
= (timings
->vsync
[1] >> 7) & 0x1;
4040 mode
= drm_mode_create(dev
);
4044 mode
->clock
= pixel_clock
* 10;
4045 mode
->hdisplay
= hactive
;
4046 mode
->hsync_start
= mode
->hdisplay
+ hsync
;
4047 mode
->hsync_end
= mode
->hsync_start
+ hsync_width
;
4048 mode
->htotal
= mode
->hdisplay
+ hblank
;
4050 mode
->vdisplay
= vactive
;
4051 mode
->vsync_start
= mode
->vdisplay
+ vsync
;
4052 mode
->vsync_end
= mode
->vsync_start
+ vsync_width
;
4053 mode
->vtotal
= mode
->vdisplay
+ vblank
;
4056 mode
->flags
|= hsync_positive
? DRM_MODE_FLAG_PHSYNC
: DRM_MODE_FLAG_NHSYNC
;
4057 mode
->flags
|= vsync_positive
? DRM_MODE_FLAG_PVSYNC
: DRM_MODE_FLAG_NVSYNC
;
4058 mode
->type
= DRM_MODE_TYPE_DRIVER
;
4060 if (timings
->flags
& 0x80)
4061 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
4062 mode
->vrefresh
= drm_mode_vrefresh(mode
);
4063 drm_mode_set_name(mode
);
4068 static int add_displayid_detailed_1_modes(struct drm_connector
*connector
,
4069 struct displayid_block
*block
)
4071 struct displayid_detailed_timing_block
*det
= (struct displayid_detailed_timing_block
*)block
;
4074 struct drm_display_mode
*newmode
;
4076 /* blocks must be multiple of 20 bytes length */
4077 if (block
->num_bytes
% 20)
4080 num_timings
= block
->num_bytes
/ 20;
4081 for (i
= 0; i
< num_timings
; i
++) {
4082 struct displayid_detailed_timings_1
*timings
= &det
->timings
[i
];
4084 newmode
= drm_mode_displayid_detailed(connector
->dev
, timings
);
4088 drm_mode_probed_add(connector
, newmode
);
4094 static int add_displayid_detailed_modes(struct drm_connector
*connector
,
4100 int length
= EDID_LENGTH
;
4101 struct displayid_block
*block
;
4104 displayid
= drm_find_displayid_extension(edid
);
4108 ret
= validate_displayid(displayid
, length
, idx
);
4112 idx
+= sizeof(struct displayid_hdr
);
4113 while (block
= (struct displayid_block
*)&displayid
[idx
],
4114 idx
+ sizeof(struct displayid_block
) <= length
&&
4115 idx
+ sizeof(struct displayid_block
) + block
->num_bytes
<= length
&&
4116 block
->num_bytes
> 0) {
4117 idx
+= block
->num_bytes
+ sizeof(struct displayid_block
);
4118 switch (block
->tag
) {
4119 case DATA_BLOCK_TYPE_1_DETAILED_TIMING
:
4120 num_modes
+= add_displayid_detailed_1_modes(connector
, block
);
4128 * drm_add_edid_modes - add modes from EDID data, if available
4129 * @connector: connector we're probing
4132 * Add the specified modes to the connector's mode list.
4134 * Return: The number of modes added or 0 if we couldn't find any.
4136 int drm_add_edid_modes(struct drm_connector
*connector
, struct edid
*edid
)
4144 if (!drm_edid_is_valid(edid
)) {
4145 dev_warn(connector
->dev
->dev
, "%s: EDID invalid.\n",
4150 quirks
= edid_get_quirks(edid
);
4153 * EDID spec says modes should be preferred in this order:
4154 * - preferred detailed mode
4155 * - other detailed modes from base block
4156 * - detailed modes from extension blocks
4157 * - CVT 3-byte code modes
4158 * - standard timing codes
4159 * - established timing codes
4160 * - modes inferred from GTF or CVT range information
4162 * We get this pretty much right.
4164 * XXX order for additional mode types in extension blocks?
4166 num_modes
+= add_detailed_modes(connector
, edid
, quirks
);
4167 num_modes
+= add_cvt_modes(connector
, edid
);
4168 num_modes
+= add_standard_modes(connector
, edid
);
4169 num_modes
+= add_established_modes(connector
, edid
);
4170 num_modes
+= add_cea_modes(connector
, edid
);
4171 num_modes
+= add_alternate_cea_modes(connector
, edid
);
4172 num_modes
+= add_displayid_detailed_modes(connector
, edid
);
4173 if (edid
->features
& DRM_EDID_FEATURE_DEFAULT_GTF
)
4174 num_modes
+= add_inferred_modes(connector
, edid
);
4176 if (quirks
& (EDID_QUIRK_PREFER_LARGE_60
| EDID_QUIRK_PREFER_LARGE_75
))
4177 edid_fixup_preferred(connector
, quirks
);
4179 drm_add_display_info(edid
, &connector
->display_info
, connector
);
4181 if (quirks
& EDID_QUIRK_FORCE_6BPC
)
4182 connector
->display_info
.bpc
= 6;
4184 if (quirks
& EDID_QUIRK_FORCE_8BPC
)
4185 connector
->display_info
.bpc
= 8;
4187 if (quirks
& EDID_QUIRK_FORCE_12BPC
)
4188 connector
->display_info
.bpc
= 12;
4192 EXPORT_SYMBOL(drm_add_edid_modes
);
4195 * drm_add_modes_noedid - add modes for the connectors without EDID
4196 * @connector: connector we're probing
4197 * @hdisplay: the horizontal display limit
4198 * @vdisplay: the vertical display limit
4200 * Add the specified modes to the connector's mode list. Only when the
4201 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4203 * Return: The number of modes added or 0 if we couldn't find any.
4205 int drm_add_modes_noedid(struct drm_connector
*connector
,
4206 int hdisplay
, int vdisplay
)
4208 int i
, count
, num_modes
= 0;
4209 struct drm_display_mode
*mode
;
4210 struct drm_device
*dev
= connector
->dev
;
4212 count
= ARRAY_SIZE(drm_dmt_modes
);
4218 for (i
= 0; i
< count
; i
++) {
4219 const struct drm_display_mode
*ptr
= &drm_dmt_modes
[i
];
4220 if (hdisplay
&& vdisplay
) {
4222 * Only when two are valid, they will be used to check
4223 * whether the mode should be added to the mode list of
4226 if (ptr
->hdisplay
> hdisplay
||
4227 ptr
->vdisplay
> vdisplay
)
4230 if (drm_mode_vrefresh(ptr
) > 61)
4232 mode
= drm_mode_duplicate(dev
, ptr
);
4234 drm_mode_probed_add(connector
, mode
);
4240 EXPORT_SYMBOL(drm_add_modes_noedid
);
4243 * drm_set_preferred_mode - Sets the preferred mode of a connector
4244 * @connector: connector whose mode list should be processed
4245 * @hpref: horizontal resolution of preferred mode
4246 * @vpref: vertical resolution of preferred mode
4248 * Marks a mode as preferred if it matches the resolution specified by @hpref
4251 void drm_set_preferred_mode(struct drm_connector
*connector
,
4252 int hpref
, int vpref
)
4254 struct drm_display_mode
*mode
;
4256 list_for_each_entry(mode
, &connector
->probed_modes
, head
) {
4257 if (mode
->hdisplay
== hpref
&&
4258 mode
->vdisplay
== vpref
)
4259 mode
->type
|= DRM_MODE_TYPE_PREFERRED
;
4262 EXPORT_SYMBOL(drm_set_preferred_mode
);
4265 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
4266 * data from a DRM display mode
4267 * @frame: HDMI AVI infoframe
4268 * @mode: DRM display mode
4270 * Return: 0 on success or a negative error code on failure.
4273 drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe
*frame
,
4274 const struct drm_display_mode
*mode
)
4278 if (!frame
|| !mode
)
4281 err
= hdmi_avi_infoframe_init(frame
);
4285 if (mode
->flags
& DRM_MODE_FLAG_DBLCLK
)
4286 frame
->pixel_repeat
= 1;
4288 frame
->video_code
= drm_match_cea_mode(mode
);
4290 frame
->picture_aspect
= HDMI_PICTURE_ASPECT_NONE
;
4293 * Populate picture aspect ratio from either
4294 * user input (if specified) or from the CEA mode list.
4296 if (mode
->picture_aspect_ratio
== HDMI_PICTURE_ASPECT_4_3
||
4297 mode
->picture_aspect_ratio
== HDMI_PICTURE_ASPECT_16_9
)
4298 frame
->picture_aspect
= mode
->picture_aspect_ratio
;
4299 else if (frame
->video_code
> 0)
4300 frame
->picture_aspect
= drm_get_cea_aspect_ratio(
4303 frame
->active_aspect
= HDMI_ACTIVE_ASPECT_PICTURE
;
4304 frame
->scan_mode
= HDMI_SCAN_MODE_UNDERSCAN
;
4308 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode
);
4310 static enum hdmi_3d_structure
4311 s3d_structure_from_display_mode(const struct drm_display_mode
*mode
)
4313 u32 layout
= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
4316 case DRM_MODE_FLAG_3D_FRAME_PACKING
:
4317 return HDMI_3D_STRUCTURE_FRAME_PACKING
;
4318 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE
:
4319 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE
;
4320 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE
:
4321 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE
;
4322 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL
:
4323 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL
;
4324 case DRM_MODE_FLAG_3D_L_DEPTH
:
4325 return HDMI_3D_STRUCTURE_L_DEPTH
;
4326 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH
:
4327 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH
;
4328 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM
:
4329 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM
;
4330 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF
:
4331 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
;
4333 return HDMI_3D_STRUCTURE_INVALID
;
4338 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
4339 * data from a DRM display mode
4340 * @frame: HDMI vendor infoframe
4341 * @mode: DRM display mode
4343 * Note that there's is a need to send HDMI vendor infoframes only when using a
4344 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
4345 * function will return -EINVAL, error that can be safely ignored.
4347 * Return: 0 on success or a negative error code on failure.
4350 drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe
*frame
,
4351 const struct drm_display_mode
*mode
)
4357 if (!frame
|| !mode
)
4360 vic
= drm_match_hdmi_mode(mode
);
4361 s3d_flags
= mode
->flags
& DRM_MODE_FLAG_3D_MASK
;
4363 if (!vic
&& !s3d_flags
)
4366 if (vic
&& s3d_flags
)
4369 err
= hdmi_vendor_infoframe_init(frame
);
4376 frame
->s3d_struct
= s3d_structure_from_display_mode(mode
);
4380 EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode
);
4382 static int drm_parse_tiled_block(struct drm_connector
*connector
,
4383 struct displayid_block
*block
)
4385 struct displayid_tiled_block
*tile
= (struct displayid_tiled_block
*)block
;
4387 u8 tile_v_loc
, tile_h_loc
;
4388 u8 num_v_tile
, num_h_tile
;
4389 struct drm_tile_group
*tg
;
4391 w
= tile
->tile_size
[0] | tile
->tile_size
[1] << 8;
4392 h
= tile
->tile_size
[2] | tile
->tile_size
[3] << 8;
4394 num_v_tile
= (tile
->topo
[0] & 0xf) | (tile
->topo
[2] & 0x30);
4395 num_h_tile
= (tile
->topo
[0] >> 4) | ((tile
->topo
[2] >> 2) & 0x30);
4396 tile_v_loc
= (tile
->topo
[1] & 0xf) | ((tile
->topo
[2] & 0x3) << 4);
4397 tile_h_loc
= (tile
->topo
[1] >> 4) | (((tile
->topo
[2] >> 2) & 0x3) << 4);
4399 connector
->has_tile
= true;
4400 if (tile
->tile_cap
& 0x80)
4401 connector
->tile_is_single_monitor
= true;
4403 connector
->num_h_tile
= num_h_tile
+ 1;
4404 connector
->num_v_tile
= num_v_tile
+ 1;
4405 connector
->tile_h_loc
= tile_h_loc
;
4406 connector
->tile_v_loc
= tile_v_loc
;
4407 connector
->tile_h_size
= w
+ 1;
4408 connector
->tile_v_size
= h
+ 1;
4410 DRM_DEBUG_KMS("tile cap 0x%x\n", tile
->tile_cap
);
4411 DRM_DEBUG_KMS("tile_size %d x %d\n", w
+ 1, h
+ 1);
4412 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
4413 num_h_tile
+ 1, num_v_tile
+ 1, tile_h_loc
, tile_v_loc
);
4414 DRM_DEBUG_KMS("vend %c%c%c\n", tile
->topology_id
[0], tile
->topology_id
[1], tile
->topology_id
[2]);
4416 tg
= drm_mode_get_tile_group(connector
->dev
, tile
->topology_id
);
4418 tg
= drm_mode_create_tile_group(connector
->dev
, tile
->topology_id
);
4423 if (connector
->tile_group
!= tg
) {
4424 /* if we haven't got a pointer,
4425 take the reference, drop ref to old tile group */
4426 if (connector
->tile_group
) {
4427 drm_mode_put_tile_group(connector
->dev
, connector
->tile_group
);
4429 connector
->tile_group
= tg
;
4431 /* if same tile group, then release the ref we just took. */
4432 drm_mode_put_tile_group(connector
->dev
, tg
);
4436 static int drm_parse_display_id(struct drm_connector
*connector
,
4437 u8
*displayid
, int length
,
4438 bool is_edid_extension
)
4440 /* if this is an EDID extension the first byte will be 0x70 */
4442 struct displayid_block
*block
;
4445 if (is_edid_extension
)
4448 ret
= validate_displayid(displayid
, length
, idx
);
4452 idx
+= sizeof(struct displayid_hdr
);
4453 while (block
= (struct displayid_block
*)&displayid
[idx
],
4454 idx
+ sizeof(struct displayid_block
) <= length
&&
4455 idx
+ sizeof(struct displayid_block
) + block
->num_bytes
<= length
&&
4456 block
->num_bytes
> 0) {
4457 idx
+= block
->num_bytes
+ sizeof(struct displayid_block
);
4458 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
4459 block
->tag
, block
->rev
, block
->num_bytes
);
4461 switch (block
->tag
) {
4462 case DATA_BLOCK_TILED_DISPLAY
:
4463 ret
= drm_parse_tiled_block(connector
, block
);
4467 case DATA_BLOCK_TYPE_1_DETAILED_TIMING
:
4468 /* handled in mode gathering code. */
4471 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block
->tag
);
4478 static void drm_get_displayid(struct drm_connector
*connector
,
4481 void *displayid
= NULL
;
4483 connector
->has_tile
= false;
4484 displayid
= drm_find_displayid_extension(edid
);
4486 /* drop reference to any tile group we had */
4490 ret
= drm_parse_display_id(connector
, displayid
, EDID_LENGTH
, true);
4493 if (!connector
->has_tile
)
4497 if (connector
->tile_group
) {
4498 drm_mode_put_tile_group(connector
->dev
, connector
->tile_group
);
4499 connector
->tile_group
= NULL
;