blob: f265797307bcd8f7596e8cb9425aed09aaaa3db3 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/*
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.
6 *
7 * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from
8 * FB layer.
9 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
10 *
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:
17 *
18 * The above copyright notice and this permission notice (including the
19 * next paragraph) shall be included in all copies or substantial portions
20 * of the Software.
21 *
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.
29 */
30
31#include <linux/hdmi.h>
32#include <linux/i2c.h>
33#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/slab.h>
36#include <linux/vga_switcheroo.h>
37
38#include <drm/drm_displayid.h>
39#include <drm/drm_drv.h>
40#include <drm/drm_edid.h>
41#include <drm/drm_encoder.h>
42#include <drm/drm_print.h>
43#include <drm/drm_scdc_helper.h>
44
45#include "drm_crtc_internal.h"
46
47#define version_greater(edid, maj, min) \
48 (((edid)->version > (maj)) || \
49 ((edid)->version == (maj) && (edid)->revision > (min)))
50
51#define EDID_EST_TIMINGS 16
52#define EDID_STD_TIMINGS 8
53#define EDID_DETAILED_TIMINGS 4
54
55/*
56 * EDID blocks out in the wild have a variety of bugs, try to collect
57 * them here (note that userspace may work around broken monitors first,
58 * but fixes should make their way here so that the kernel "just works"
59 * on as many displays as possible).
60 */
61
62/* First detailed mode wrong, use largest 60Hz mode */
63#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
64/* Reported 135MHz pixel clock is too high, needs adjustment */
65#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
66/* Prefer the largest mode at 75 Hz */
67#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
68/* Detail timing is in cm not mm */
69#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
70/* Detailed timing descriptors have bogus size values, so just take the
71 * maximum size and use that.
72 */
73#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
74/* use +hsync +vsync for detailed mode */
75#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
76/* Force reduced-blanking timings for detailed modes */
77#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
78/* Force 8bpc */
79#define EDID_QUIRK_FORCE_8BPC (1 << 8)
80/* Force 12bpc */
81#define EDID_QUIRK_FORCE_12BPC (1 << 9)
82/* Force 6bpc */
83#define EDID_QUIRK_FORCE_6BPC (1 << 10)
84/* Force 10bpc */
85#define EDID_QUIRK_FORCE_10BPC (1 << 11)
86/* Non desktop display (i.e. HMD) */
87#define EDID_QUIRK_NON_DESKTOP (1 << 12)
88
89struct detailed_mode_closure {
90 struct drm_connector *connector;
91 struct edid *edid;
92 bool preferred;
93 u32 quirks;
94 int modes;
95};
96
97#define LEVEL_DMT 0
98#define LEVEL_GTF 1
99#define LEVEL_GTF2 2
100#define LEVEL_CVT 3
101
102static const struct edid_quirk {
103 char vendor[4];
104 int product_id;
105 u32 quirks;
106} edid_quirk_list[] = {
107 /* Acer AL1706 */
108 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
109 /* Acer F51 */
110 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
111
112 /* AEO model 0 reports 8 bpc, but is a 6 bpc panel */
113 { "AEO", 0, EDID_QUIRK_FORCE_6BPC },
114
115 /* BOE model on HP Pavilion 15-n233sl reports 8 bpc, but is a 6 bpc panel */
116 { "BOE", 0x78b, EDID_QUIRK_FORCE_6BPC },
117
118 /* CPT panel of Asus UX303LA reports 8 bpc, but is a 6 bpc panel */
119 { "CPT", 0x17df, EDID_QUIRK_FORCE_6BPC },
120
121 /* SDC panel of Lenovo B50-80 reports 8 bpc, but is a 6 bpc panel */
122 { "SDC", 0x3652, EDID_QUIRK_FORCE_6BPC },
123
124 /* BOE model 0x0771 reports 8 bpc, but is a 6 bpc panel */
125 { "BOE", 0x0771, EDID_QUIRK_FORCE_6BPC },
126
127 /* Belinea 10 15 55 */
128 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
129 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
130
131 /* Envision Peripherals, Inc. EN-7100e */
132 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
133 /* Envision EN2028 */
134 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
135
136 /* Funai Electronics PM36B */
137 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
138 EDID_QUIRK_DETAILED_IN_CM },
139
140 /* LGD panel of HP zBook 17 G2, eDP 10 bpc, but reports unknown bpc */
141 { "LGD", 764, EDID_QUIRK_FORCE_10BPC },
142
143 /* LG Philips LCD LP154W01-A5 */
144 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
145 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
146
147 /* Samsung SyncMaster 205BW. Note: irony */
148 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
149 /* Samsung SyncMaster 22[5-6]BW */
150 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
151 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
152
153 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
154 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
155
156 /* ViewSonic VA2026w */
157 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
158
159 /* Medion MD 30217 PG */
160 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
161
162 /* Lenovo G50 */
163 { "SDC", 18514, EDID_QUIRK_FORCE_6BPC },
164
165 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
166 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
167
168 /* Rotel RSX-1058 forwards sink's EDID but only does HDMI 1.1*/
169 { "ETR", 13896, EDID_QUIRK_FORCE_8BPC },
170
171 /* Valve Index Headset */
172 { "VLV", 0x91a8, EDID_QUIRK_NON_DESKTOP },
173 { "VLV", 0x91b0, EDID_QUIRK_NON_DESKTOP },
174 { "VLV", 0x91b1, EDID_QUIRK_NON_DESKTOP },
175 { "VLV", 0x91b2, EDID_QUIRK_NON_DESKTOP },
176 { "VLV", 0x91b3, EDID_QUIRK_NON_DESKTOP },
177 { "VLV", 0x91b4, EDID_QUIRK_NON_DESKTOP },
178 { "VLV", 0x91b5, EDID_QUIRK_NON_DESKTOP },
179 { "VLV", 0x91b6, EDID_QUIRK_NON_DESKTOP },
180 { "VLV", 0x91b7, EDID_QUIRK_NON_DESKTOP },
181 { "VLV", 0x91b8, EDID_QUIRK_NON_DESKTOP },
182 { "VLV", 0x91b9, EDID_QUIRK_NON_DESKTOP },
183 { "VLV", 0x91ba, EDID_QUIRK_NON_DESKTOP },
184 { "VLV", 0x91bb, EDID_QUIRK_NON_DESKTOP },
185 { "VLV", 0x91bc, EDID_QUIRK_NON_DESKTOP },
186 { "VLV", 0x91bd, EDID_QUIRK_NON_DESKTOP },
187 { "VLV", 0x91be, EDID_QUIRK_NON_DESKTOP },
188 { "VLV", 0x91bf, EDID_QUIRK_NON_DESKTOP },
189
190 /* HTC Vive and Vive Pro VR Headsets */
191 { "HVR", 0xaa01, EDID_QUIRK_NON_DESKTOP },
192 { "HVR", 0xaa02, EDID_QUIRK_NON_DESKTOP },
193
194 /* Oculus Rift DK1, DK2, CV1 and Rift S VR Headsets */
195 { "OVR", 0x0001, EDID_QUIRK_NON_DESKTOP },
196 { "OVR", 0x0003, EDID_QUIRK_NON_DESKTOP },
197 { "OVR", 0x0004, EDID_QUIRK_NON_DESKTOP },
198 { "OVR", 0x0012, EDID_QUIRK_NON_DESKTOP },
199
200 /* Windows Mixed Reality Headsets */
201 { "ACR", 0x7fce, EDID_QUIRK_NON_DESKTOP },
202 { "HPN", 0x3515, EDID_QUIRK_NON_DESKTOP },
203 { "LEN", 0x0408, EDID_QUIRK_NON_DESKTOP },
204 { "LEN", 0xb800, EDID_QUIRK_NON_DESKTOP },
205 { "FUJ", 0x1970, EDID_QUIRK_NON_DESKTOP },
206 { "DEL", 0x7fce, EDID_QUIRK_NON_DESKTOP },
207 { "SEC", 0x144a, EDID_QUIRK_NON_DESKTOP },
208 { "AUS", 0xc102, EDID_QUIRK_NON_DESKTOP },
209
210 /* Sony PlayStation VR Headset */
211 { "SNY", 0x0704, EDID_QUIRK_NON_DESKTOP },
212
213 /* Sensics VR Headsets */
214 { "SEN", 0x1019, EDID_QUIRK_NON_DESKTOP },
215
216 /* OSVR HDK and HDK2 VR Headsets */
217 { "SVR", 0x1019, EDID_QUIRK_NON_DESKTOP },
218};
219
220/*
221 * Autogenerated from the DMT spec.
222 * This table is copied from xfree86/modes/xf86EdidModes.c.
223 */
224static const struct drm_display_mode drm_dmt_modes[] = {
225 /* 0x01 - 640x350@85Hz */
226 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
227 736, 832, 0, 350, 382, 385, 445, 0,
228 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
229 /* 0x02 - 640x400@85Hz */
230 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
231 736, 832, 0, 400, 401, 404, 445, 0,
232 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
233 /* 0x03 - 720x400@85Hz */
234 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
235 828, 936, 0, 400, 401, 404, 446, 0,
236 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
237 /* 0x04 - 640x480@60Hz */
238 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
239 752, 800, 0, 480, 490, 492, 525, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
241 /* 0x05 - 640x480@72Hz */
242 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
243 704, 832, 0, 480, 489, 492, 520, 0,
244 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
245 /* 0x06 - 640x480@75Hz */
246 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
247 720, 840, 0, 480, 481, 484, 500, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
249 /* 0x07 - 640x480@85Hz */
250 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
251 752, 832, 0, 480, 481, 484, 509, 0,
252 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
253 /* 0x08 - 800x600@56Hz */
254 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
255 896, 1024, 0, 600, 601, 603, 625, 0,
256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
257 /* 0x09 - 800x600@60Hz */
258 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
259 968, 1056, 0, 600, 601, 605, 628, 0,
260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
261 /* 0x0a - 800x600@72Hz */
262 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
263 976, 1040, 0, 600, 637, 643, 666, 0,
264 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
265 /* 0x0b - 800x600@75Hz */
266 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
267 896, 1056, 0, 600, 601, 604, 625, 0,
268 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
269 /* 0x0c - 800x600@85Hz */
270 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
271 896, 1048, 0, 600, 601, 604, 631, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
273 /* 0x0d - 800x600@120Hz RB */
274 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
275 880, 960, 0, 600, 603, 607, 636, 0,
276 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
277 /* 0x0e - 848x480@60Hz */
278 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
279 976, 1088, 0, 480, 486, 494, 517, 0,
280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
281 /* 0x0f - 1024x768@43Hz, interlace */
282 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
283 1208, 1264, 0, 768, 768, 776, 817, 0,
284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
285 DRM_MODE_FLAG_INTERLACE) },
286 /* 0x10 - 1024x768@60Hz */
287 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
288 1184, 1344, 0, 768, 771, 777, 806, 0,
289 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
290 /* 0x11 - 1024x768@70Hz */
291 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
292 1184, 1328, 0, 768, 771, 777, 806, 0,
293 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
294 /* 0x12 - 1024x768@75Hz */
295 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
296 1136, 1312, 0, 768, 769, 772, 800, 0,
297 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
298 /* 0x13 - 1024x768@85Hz */
299 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
300 1168, 1376, 0, 768, 769, 772, 808, 0,
301 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
302 /* 0x14 - 1024x768@120Hz RB */
303 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
304 1104, 1184, 0, 768, 771, 775, 813, 0,
305 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
306 /* 0x15 - 1152x864@75Hz */
307 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
308 1344, 1600, 0, 864, 865, 868, 900, 0,
309 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
310 /* 0x55 - 1280x720@60Hz */
311 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
312 1430, 1650, 0, 720, 725, 730, 750, 0,
313 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
314 /* 0x16 - 1280x768@60Hz RB */
315 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
316 1360, 1440, 0, 768, 771, 778, 790, 0,
317 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
318 /* 0x17 - 1280x768@60Hz */
319 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
320 1472, 1664, 0, 768, 771, 778, 798, 0,
321 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
322 /* 0x18 - 1280x768@75Hz */
323 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
324 1488, 1696, 0, 768, 771, 778, 805, 0,
325 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
326 /* 0x19 - 1280x768@85Hz */
327 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
328 1496, 1712, 0, 768, 771, 778, 809, 0,
329 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
330 /* 0x1a - 1280x768@120Hz RB */
331 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
332 1360, 1440, 0, 768, 771, 778, 813, 0,
333 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
334 /* 0x1b - 1280x800@60Hz RB */
335 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
336 1360, 1440, 0, 800, 803, 809, 823, 0,
337 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
338 /* 0x1c - 1280x800@60Hz */
339 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
340 1480, 1680, 0, 800, 803, 809, 831, 0,
341 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
342 /* 0x1d - 1280x800@75Hz */
343 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
344 1488, 1696, 0, 800, 803, 809, 838, 0,
345 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
346 /* 0x1e - 1280x800@85Hz */
347 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
348 1496, 1712, 0, 800, 803, 809, 843, 0,
349 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
350 /* 0x1f - 1280x800@120Hz RB */
351 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
352 1360, 1440, 0, 800, 803, 809, 847, 0,
353 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
354 /* 0x20 - 1280x960@60Hz */
355 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
356 1488, 1800, 0, 960, 961, 964, 1000, 0,
357 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
358 /* 0x21 - 1280x960@85Hz */
359 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
360 1504, 1728, 0, 960, 961, 964, 1011, 0,
361 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
362 /* 0x22 - 1280x960@120Hz RB */
363 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
364 1360, 1440, 0, 960, 963, 967, 1017, 0,
365 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
366 /* 0x23 - 1280x1024@60Hz */
367 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
368 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
369 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
370 /* 0x24 - 1280x1024@75Hz */
371 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
372 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
373 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
374 /* 0x25 - 1280x1024@85Hz */
375 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
376 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
377 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
378 /* 0x26 - 1280x1024@120Hz RB */
379 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
380 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
381 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
382 /* 0x27 - 1360x768@60Hz */
383 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
384 1536, 1792, 0, 768, 771, 777, 795, 0,
385 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
386 /* 0x28 - 1360x768@120Hz RB */
387 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
388 1440, 1520, 0, 768, 771, 776, 813, 0,
389 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
390 /* 0x51 - 1366x768@60Hz */
391 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 85500, 1366, 1436,
392 1579, 1792, 0, 768, 771, 774, 798, 0,
393 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
394 /* 0x56 - 1366x768@60Hz */
395 { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 72000, 1366, 1380,
396 1436, 1500, 0, 768, 769, 772, 800, 0,
397 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
398 /* 0x29 - 1400x1050@60Hz RB */
399 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
400 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
401 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
402 /* 0x2a - 1400x1050@60Hz */
403 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
404 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
405 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
406 /* 0x2b - 1400x1050@75Hz */
407 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
408 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
409 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
410 /* 0x2c - 1400x1050@85Hz */
411 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
412 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
413 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
414 /* 0x2d - 1400x1050@120Hz RB */
415 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
416 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
417 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
418 /* 0x2e - 1440x900@60Hz RB */
419 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
420 1520, 1600, 0, 900, 903, 909, 926, 0,
421 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
422 /* 0x2f - 1440x900@60Hz */
423 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
424 1672, 1904, 0, 900, 903, 909, 934, 0,
425 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
426 /* 0x30 - 1440x900@75Hz */
427 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
428 1688, 1936, 0, 900, 903, 909, 942, 0,
429 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
430 /* 0x31 - 1440x900@85Hz */
431 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
432 1696, 1952, 0, 900, 903, 909, 948, 0,
433 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
434 /* 0x32 - 1440x900@120Hz RB */
435 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
436 1520, 1600, 0, 900, 903, 909, 953, 0,
437 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
438 /* 0x53 - 1600x900@60Hz */
439 { DRM_MODE("1600x900", DRM_MODE_TYPE_DRIVER, 108000, 1600, 1624,
440 1704, 1800, 0, 900, 901, 904, 1000, 0,
441 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
442 /* 0x33 - 1600x1200@60Hz */
443 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
444 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
445 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
446 /* 0x34 - 1600x1200@65Hz */
447 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
448 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
449 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
450 /* 0x35 - 1600x1200@70Hz */
451 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
452 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
453 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
454 /* 0x36 - 1600x1200@75Hz */
455 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
456 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
457 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
458 /* 0x37 - 1600x1200@85Hz */
459 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
460 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
461 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
462 /* 0x38 - 1600x1200@120Hz RB */
463 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
464 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
465 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
466 /* 0x39 - 1680x1050@60Hz RB */
467 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
468 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
469 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
470 /* 0x3a - 1680x1050@60Hz */
471 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
472 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
473 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
474 /* 0x3b - 1680x1050@75Hz */
475 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
476 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
477 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
478 /* 0x3c - 1680x1050@85Hz */
479 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
480 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
481 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
482 /* 0x3d - 1680x1050@120Hz RB */
483 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
484 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
485 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
486 /* 0x3e - 1792x1344@60Hz */
487 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
488 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
489 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
490 /* 0x3f - 1792x1344@75Hz */
491 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
492 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
493 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
494 /* 0x40 - 1792x1344@120Hz RB */
495 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
496 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
497 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
498 /* 0x41 - 1856x1392@60Hz */
499 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
500 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
501 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
502 /* 0x42 - 1856x1392@75Hz */
503 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
504 2208, 2560, 0, 1392, 1393, 1396, 1500, 0,
505 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
506 /* 0x43 - 1856x1392@120Hz RB */
507 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
508 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
509 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
510 /* 0x52 - 1920x1080@60Hz */
511 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
512 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
513 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
514 /* 0x44 - 1920x1200@60Hz RB */
515 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
516 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
517 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
518 /* 0x45 - 1920x1200@60Hz */
519 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
520 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
521 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
522 /* 0x46 - 1920x1200@75Hz */
523 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
524 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
525 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
526 /* 0x47 - 1920x1200@85Hz */
527 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
528 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
529 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
530 /* 0x48 - 1920x1200@120Hz RB */
531 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
532 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
533 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
534 /* 0x49 - 1920x1440@60Hz */
535 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
536 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
537 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
538 /* 0x4a - 1920x1440@75Hz */
539 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
540 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
541 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
542 /* 0x4b - 1920x1440@120Hz RB */
543 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
544 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
545 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
546 /* 0x54 - 2048x1152@60Hz */
547 { DRM_MODE("2048x1152", DRM_MODE_TYPE_DRIVER, 162000, 2048, 2074,
548 2154, 2250, 0, 1152, 1153, 1156, 1200, 0,
549 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
550 /* 0x4c - 2560x1600@60Hz RB */
551 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
552 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
553 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
554 /* 0x4d - 2560x1600@60Hz */
555 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
556 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
557 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
558 /* 0x4e - 2560x1600@75Hz */
559 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
560 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
561 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
562 /* 0x4f - 2560x1600@85Hz */
563 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
564 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
565 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
566 /* 0x50 - 2560x1600@120Hz RB */
567 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
568 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
569 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
570 /* 0x57 - 4096x2160@60Hz RB */
571 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556744, 4096, 4104,
572 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
573 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
574 /* 0x58 - 4096x2160@59.94Hz RB */
575 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 556188, 4096, 4104,
576 4136, 4176, 0, 2160, 2208, 2216, 2222, 0,
577 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
578};
579
580/*
581 * These more or less come from the DMT spec. The 720x400 modes are
582 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
583 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
584 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
585 * mode.
586 *
587 * The DMT modes have been fact-checked; the rest are mild guesses.
588 */
589static const struct drm_display_mode edid_est_modes[] = {
590 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
591 968, 1056, 0, 600, 601, 605, 628, 0,
592 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
593 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
594 896, 1024, 0, 600, 601, 603, 625, 0,
595 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
596 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
597 720, 840, 0, 480, 481, 484, 500, 0,
598 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
599 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
600 704, 832, 0, 480, 489, 492, 520, 0,
601 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
602 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
603 768, 864, 0, 480, 483, 486, 525, 0,
604 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
605 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
606 752, 800, 0, 480, 490, 492, 525, 0,
607 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
608 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
609 846, 900, 0, 400, 421, 423, 449, 0,
610 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
611 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
612 846, 900, 0, 400, 412, 414, 449, 0,
613 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
614 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
615 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
616 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
617 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
618 1136, 1312, 0, 768, 769, 772, 800, 0,
619 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
620 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
621 1184, 1328, 0, 768, 771, 777, 806, 0,
622 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
623 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
624 1184, 1344, 0, 768, 771, 777, 806, 0,
625 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
626 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
627 1208, 1264, 0, 768, 768, 776, 817, 0,
628 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
629 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
630 928, 1152, 0, 624, 625, 628, 667, 0,
631 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
632 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
633 896, 1056, 0, 600, 601, 604, 625, 0,
634 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
635 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
636 976, 1040, 0, 600, 637, 643, 666, 0,
637 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
638 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
639 1344, 1600, 0, 864, 865, 868, 900, 0,
640 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
641};
642
643struct minimode {
644 short w;
645 short h;
646 short r;
647 short rb;
648};
649
650static const struct minimode est3_modes[] = {
651 /* byte 6 */
652 { 640, 350, 85, 0 },
653 { 640, 400, 85, 0 },
654 { 720, 400, 85, 0 },
655 { 640, 480, 85, 0 },
656 { 848, 480, 60, 0 },
657 { 800, 600, 85, 0 },
658 { 1024, 768, 85, 0 },
659 { 1152, 864, 75, 0 },
660 /* byte 7 */
661 { 1280, 768, 60, 1 },
662 { 1280, 768, 60, 0 },
663 { 1280, 768, 75, 0 },
664 { 1280, 768, 85, 0 },
665 { 1280, 960, 60, 0 },
666 { 1280, 960, 85, 0 },
667 { 1280, 1024, 60, 0 },
668 { 1280, 1024, 85, 0 },
669 /* byte 8 */
670 { 1360, 768, 60, 0 },
671 { 1440, 900, 60, 1 },
672 { 1440, 900, 60, 0 },
673 { 1440, 900, 75, 0 },
674 { 1440, 900, 85, 0 },
675 { 1400, 1050, 60, 1 },
676 { 1400, 1050, 60, 0 },
677 { 1400, 1050, 75, 0 },
678 /* byte 9 */
679 { 1400, 1050, 85, 0 },
680 { 1680, 1050, 60, 1 },
681 { 1680, 1050, 60, 0 },
682 { 1680, 1050, 75, 0 },
683 { 1680, 1050, 85, 0 },
684 { 1600, 1200, 60, 0 },
685 { 1600, 1200, 65, 0 },
686 { 1600, 1200, 70, 0 },
687 /* byte 10 */
688 { 1600, 1200, 75, 0 },
689 { 1600, 1200, 85, 0 },
690 { 1792, 1344, 60, 0 },
691 { 1792, 1344, 75, 0 },
692 { 1856, 1392, 60, 0 },
693 { 1856, 1392, 75, 0 },
694 { 1920, 1200, 60, 1 },
695 { 1920, 1200, 60, 0 },
696 /* byte 11 */
697 { 1920, 1200, 75, 0 },
698 { 1920, 1200, 85, 0 },
699 { 1920, 1440, 60, 0 },
700 { 1920, 1440, 75, 0 },
701};
702
703static const struct minimode extra_modes[] = {
704 { 1024, 576, 60, 0 },
705 { 1366, 768, 60, 0 },
706 { 1600, 900, 60, 0 },
707 { 1680, 945, 60, 0 },
708 { 1920, 1080, 60, 0 },
709 { 2048, 1152, 60, 0 },
710 { 2048, 1536, 60, 0 },
711};
712
713/*
714 * Probably taken from CEA-861 spec.
715 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
716 *
717 * Index using the VIC.
718 */
719static const struct drm_display_mode edid_cea_modes[] = {
720 /* 0 - dummy, VICs start at 1 */
721 { },
722 /* 1 - 640x480@60Hz 4:3 */
723 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
724 752, 800, 0, 480, 490, 492, 525, 0,
725 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
726 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
727 /* 2 - 720x480@60Hz 4:3 */
728 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
729 798, 858, 0, 480, 489, 495, 525, 0,
730 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
731 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
732 /* 3 - 720x480@60Hz 16:9 */
733 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
734 798, 858, 0, 480, 489, 495, 525, 0,
735 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
736 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
737 /* 4 - 1280x720@60Hz 16:9 */
738 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
739 1430, 1650, 0, 720, 725, 730, 750, 0,
740 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
741 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
742 /* 5 - 1920x1080i@60Hz 16:9 */
743 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
744 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
745 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
746 DRM_MODE_FLAG_INTERLACE),
747 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
748 /* 6 - 720(1440)x480i@60Hz 4:3 */
749 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
750 801, 858, 0, 480, 488, 494, 525, 0,
751 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
752 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
753 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
754 /* 7 - 720(1440)x480i@60Hz 16:9 */
755 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
756 801, 858, 0, 480, 488, 494, 525, 0,
757 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
758 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
759 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
760 /* 8 - 720(1440)x240@60Hz 4:3 */
761 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
762 801, 858, 0, 240, 244, 247, 262, 0,
763 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
764 DRM_MODE_FLAG_DBLCLK),
765 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
766 /* 9 - 720(1440)x240@60Hz 16:9 */
767 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
768 801, 858, 0, 240, 244, 247, 262, 0,
769 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
770 DRM_MODE_FLAG_DBLCLK),
771 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
772 /* 10 - 2880x480i@60Hz 4:3 */
773 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
774 3204, 3432, 0, 480, 488, 494, 525, 0,
775 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
776 DRM_MODE_FLAG_INTERLACE),
777 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
778 /* 11 - 2880x480i@60Hz 16:9 */
779 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
780 3204, 3432, 0, 480, 488, 494, 525, 0,
781 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
782 DRM_MODE_FLAG_INTERLACE),
783 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
784 /* 12 - 2880x240@60Hz 4:3 */
785 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
786 3204, 3432, 0, 240, 244, 247, 262, 0,
787 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
788 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
789 /* 13 - 2880x240@60Hz 16:9 */
790 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
791 3204, 3432, 0, 240, 244, 247, 262, 0,
792 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
793 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
794 /* 14 - 1440x480@60Hz 4:3 */
795 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
796 1596, 1716, 0, 480, 489, 495, 525, 0,
797 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
798 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
799 /* 15 - 1440x480@60Hz 16:9 */
800 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
801 1596, 1716, 0, 480, 489, 495, 525, 0,
802 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
803 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
804 /* 16 - 1920x1080@60Hz 16:9 */
805 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
806 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
807 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
808 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
809 /* 17 - 720x576@50Hz 4:3 */
810 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
811 796, 864, 0, 576, 581, 586, 625, 0,
812 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
813 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
814 /* 18 - 720x576@50Hz 16:9 */
815 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
816 796, 864, 0, 576, 581, 586, 625, 0,
817 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
818 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
819 /* 19 - 1280x720@50Hz 16:9 */
820 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
821 1760, 1980, 0, 720, 725, 730, 750, 0,
822 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
823 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
824 /* 20 - 1920x1080i@50Hz 16:9 */
825 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
826 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
827 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
828 DRM_MODE_FLAG_INTERLACE),
829 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
830 /* 21 - 720(1440)x576i@50Hz 4:3 */
831 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
832 795, 864, 0, 576, 580, 586, 625, 0,
833 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
834 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
835 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
836 /* 22 - 720(1440)x576i@50Hz 16:9 */
837 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
838 795, 864, 0, 576, 580, 586, 625, 0,
839 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
840 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
841 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
842 /* 23 - 720(1440)x288@50Hz 4:3 */
843 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
844 795, 864, 0, 288, 290, 293, 312, 0,
845 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
846 DRM_MODE_FLAG_DBLCLK),
847 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
848 /* 24 - 720(1440)x288@50Hz 16:9 */
849 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
850 795, 864, 0, 288, 290, 293, 312, 0,
851 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
852 DRM_MODE_FLAG_DBLCLK),
853 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
854 /* 25 - 2880x576i@50Hz 4:3 */
855 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
856 3180, 3456, 0, 576, 580, 586, 625, 0,
857 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
858 DRM_MODE_FLAG_INTERLACE),
859 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
860 /* 26 - 2880x576i@50Hz 16:9 */
861 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
862 3180, 3456, 0, 576, 580, 586, 625, 0,
863 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
864 DRM_MODE_FLAG_INTERLACE),
865 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
866 /* 27 - 2880x288@50Hz 4:3 */
867 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
868 3180, 3456, 0, 288, 290, 293, 312, 0,
869 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
870 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
871 /* 28 - 2880x288@50Hz 16:9 */
872 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
873 3180, 3456, 0, 288, 290, 293, 312, 0,
874 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
875 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
876 /* 29 - 1440x576@50Hz 4:3 */
877 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
878 1592, 1728, 0, 576, 581, 586, 625, 0,
879 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
880 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
881 /* 30 - 1440x576@50Hz 16:9 */
882 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
883 1592, 1728, 0, 576, 581, 586, 625, 0,
884 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
885 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
886 /* 31 - 1920x1080@50Hz 16:9 */
887 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
888 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
889 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
890 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
891 /* 32 - 1920x1080@24Hz 16:9 */
892 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
893 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
894 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
895 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
896 /* 33 - 1920x1080@25Hz 16:9 */
897 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
898 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
899 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
900 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
901 /* 34 - 1920x1080@30Hz 16:9 */
902 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
903 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
904 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
905 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
906 /* 35 - 2880x480@60Hz 4:3 */
907 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
908 3192, 3432, 0, 480, 489, 495, 525, 0,
909 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
910 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
911 /* 36 - 2880x480@60Hz 16:9 */
912 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
913 3192, 3432, 0, 480, 489, 495, 525, 0,
914 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
915 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
916 /* 37 - 2880x576@50Hz 4:3 */
917 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
918 3184, 3456, 0, 576, 581, 586, 625, 0,
919 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
920 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
921 /* 38 - 2880x576@50Hz 16:9 */
922 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
923 3184, 3456, 0, 576, 581, 586, 625, 0,
924 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
925 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
926 /* 39 - 1920x1080i@50Hz 16:9 */
927 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
928 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
929 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
930 DRM_MODE_FLAG_INTERLACE),
931 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
932 /* 40 - 1920x1080i@100Hz 16:9 */
933 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
934 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
935 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
936 DRM_MODE_FLAG_INTERLACE),
937 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
938 /* 41 - 1280x720@100Hz 16:9 */
939 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
940 1760, 1980, 0, 720, 725, 730, 750, 0,
941 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
942 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
943 /* 42 - 720x576@100Hz 4:3 */
944 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
945 796, 864, 0, 576, 581, 586, 625, 0,
946 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
947 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
948 /* 43 - 720x576@100Hz 16:9 */
949 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
950 796, 864, 0, 576, 581, 586, 625, 0,
951 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
952 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
953 /* 44 - 720(1440)x576i@100Hz 4:3 */
954 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
955 795, 864, 0, 576, 580, 586, 625, 0,
956 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
957 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
958 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
959 /* 45 - 720(1440)x576i@100Hz 16:9 */
960 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
961 795, 864, 0, 576, 580, 586, 625, 0,
962 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
963 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
964 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
965 /* 46 - 1920x1080i@120Hz 16:9 */
966 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
967 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
968 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
969 DRM_MODE_FLAG_INTERLACE),
970 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
971 /* 47 - 1280x720@120Hz 16:9 */
972 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
973 1430, 1650, 0, 720, 725, 730, 750, 0,
974 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
975 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
976 /* 48 - 720x480@120Hz 4:3 */
977 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
978 798, 858, 0, 480, 489, 495, 525, 0,
979 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
980 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
981 /* 49 - 720x480@120Hz 16:9 */
982 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
983 798, 858, 0, 480, 489, 495, 525, 0,
984 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
985 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
986 /* 50 - 720(1440)x480i@120Hz 4:3 */
987 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
988 801, 858, 0, 480, 488, 494, 525, 0,
989 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
990 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
991 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
992 /* 51 - 720(1440)x480i@120Hz 16:9 */
993 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
994 801, 858, 0, 480, 488, 494, 525, 0,
995 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
996 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
997 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
998 /* 52 - 720x576@200Hz 4:3 */
999 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1000 796, 864, 0, 576, 581, 586, 625, 0,
1001 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
1002 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
1003 /* 53 - 720x576@200Hz 16:9 */
1004 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
1005 796, 864, 0, 576, 581, 586, 625, 0,
1006 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
1007 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1008 /* 54 - 720(1440)x576i@200Hz 4:3 */
1009 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1010 795, 864, 0, 576, 580, 586, 625, 0,
1011 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
1012 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
1013 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
1014 /* 55 - 720(1440)x576i@200Hz 16:9 */
1015 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
1016 795, 864, 0, 576, 580, 586, 625, 0,
1017 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
1018 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
1019 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1020 /* 56 - 720x480@240Hz 4:3 */
1021 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1022 798, 858, 0, 480, 489, 495, 525, 0,
1023 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
1024 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
1025 /* 57 - 720x480@240Hz 16:9 */
1026 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
1027 798, 858, 0, 480, 489, 495, 525, 0,
1028 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
1029 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1030 /* 58 - 720(1440)x480i@240Hz 4:3 */
1031 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1032 801, 858, 0, 480, 488, 494, 525, 0,
1033 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
1034 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
1035 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
1036 /* 59 - 720(1440)x480i@240Hz 16:9 */
1037 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
1038 801, 858, 0, 480, 488, 494, 525, 0,
1039 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
1040 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
1041 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1042 /* 60 - 1280x720@24Hz 16:9 */
1043 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1044 3080, 3300, 0, 720, 725, 730, 750, 0,
1045 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1046 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1047 /* 61 - 1280x720@25Hz 16:9 */
1048 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1049 3740, 3960, 0, 720, 725, 730, 750, 0,
1050 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1051 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1052 /* 62 - 1280x720@30Hz 16:9 */
1053 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1054 3080, 3300, 0, 720, 725, 730, 750, 0,
1055 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1056 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1057 /* 63 - 1920x1080@120Hz 16:9 */
1058 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1059 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1060 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1061 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1062 /* 64 - 1920x1080@100Hz 16:9 */
1063 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1064 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1065 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1066 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1067 /* 65 - 1280x720@24Hz 64:27 */
1068 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
1069 3080, 3300, 0, 720, 725, 730, 750, 0,
1070 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1071 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1072 /* 66 - 1280x720@25Hz 64:27 */
1073 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
1074 3740, 3960, 0, 720, 725, 730, 750, 0,
1075 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1076 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1077 /* 67 - 1280x720@30Hz 64:27 */
1078 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
1079 3080, 3300, 0, 720, 725, 730, 750, 0,
1080 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1081 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1082 /* 68 - 1280x720@50Hz 64:27 */
1083 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
1084 1760, 1980, 0, 720, 725, 730, 750, 0,
1085 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1086 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1087 /* 69 - 1280x720@60Hz 64:27 */
1088 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
1089 1430, 1650, 0, 720, 725, 730, 750, 0,
1090 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1091 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1092 /* 70 - 1280x720@100Hz 64:27 */
1093 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
1094 1760, 1980, 0, 720, 725, 730, 750, 0,
1095 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1096 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1097 /* 71 - 1280x720@120Hz 64:27 */
1098 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
1099 1430, 1650, 0, 720, 725, 730, 750, 0,
1100 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1101 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1102 /* 72 - 1920x1080@24Hz 64:27 */
1103 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
1104 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
1105 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1106 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1107 /* 73 - 1920x1080@25Hz 64:27 */
1108 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
1109 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1110 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1111 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1112 /* 74 - 1920x1080@30Hz 64:27 */
1113 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
1114 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1115 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1116 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1117 /* 75 - 1920x1080@50Hz 64:27 */
1118 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
1119 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1120 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1121 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1122 /* 76 - 1920x1080@60Hz 64:27 */
1123 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
1124 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1125 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1126 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1127 /* 77 - 1920x1080@100Hz 64:27 */
1128 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
1129 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
1130 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1131 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1132 /* 78 - 1920x1080@120Hz 64:27 */
1133 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
1134 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
1135 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1136 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1137 /* 79 - 1680x720@24Hz 64:27 */
1138 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 3040,
1139 3080, 3300, 0, 720, 725, 730, 750, 0,
1140 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1141 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1142 /* 80 - 1680x720@25Hz 64:27 */
1143 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2908,
1144 2948, 3168, 0, 720, 725, 730, 750, 0,
1145 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1146 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1147 /* 81 - 1680x720@30Hz 64:27 */
1148 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 59400, 1680, 2380,
1149 2420, 2640, 0, 720, 725, 730, 750, 0,
1150 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1151 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1152 /* 82 - 1680x720@50Hz 64:27 */
1153 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 82500, 1680, 1940,
1154 1980, 2200, 0, 720, 725, 730, 750, 0,
1155 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1156 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1157 /* 83 - 1680x720@60Hz 64:27 */
1158 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 99000, 1680, 1940,
1159 1980, 2200, 0, 720, 725, 730, 750, 0,
1160 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1161 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1162 /* 84 - 1680x720@100Hz 64:27 */
1163 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 165000, 1680, 1740,
1164 1780, 2000, 0, 720, 725, 730, 825, 0,
1165 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1166 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1167 /* 85 - 1680x720@120Hz 64:27 */
1168 { DRM_MODE("1680x720", DRM_MODE_TYPE_DRIVER, 198000, 1680, 1740,
1169 1780, 2000, 0, 720, 725, 730, 825, 0,
1170 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1171 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1172 /* 86 - 2560x1080@24Hz 64:27 */
1173 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 99000, 2560, 3558,
1174 3602, 3750, 0, 1080, 1084, 1089, 1100, 0,
1175 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1176 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1177 /* 87 - 2560x1080@25Hz 64:27 */
1178 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 90000, 2560, 3008,
1179 3052, 3200, 0, 1080, 1084, 1089, 1125, 0,
1180 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1181 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1182 /* 88 - 2560x1080@30Hz 64:27 */
1183 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 118800, 2560, 3328,
1184 3372, 3520, 0, 1080, 1084, 1089, 1125, 0,
1185 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1186 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1187 /* 89 - 2560x1080@50Hz 64:27 */
1188 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 185625, 2560, 3108,
1189 3152, 3300, 0, 1080, 1084, 1089, 1125, 0,
1190 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1191 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1192 /* 90 - 2560x1080@60Hz 64:27 */
1193 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 198000, 2560, 2808,
1194 2852, 3000, 0, 1080, 1084, 1089, 1100, 0,
1195 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1196 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1197 /* 91 - 2560x1080@100Hz 64:27 */
1198 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 371250, 2560, 2778,
1199 2822, 2970, 0, 1080, 1084, 1089, 1250, 0,
1200 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1201 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1202 /* 92 - 2560x1080@120Hz 64:27 */
1203 { DRM_MODE("2560x1080", DRM_MODE_TYPE_DRIVER, 495000, 2560, 3108,
1204 3152, 3300, 0, 1080, 1084, 1089, 1250, 0,
1205 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1206 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1207 /* 93 - 3840x2160@24Hz 16:9 */
1208 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1209 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1210 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1211 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1212 /* 94 - 3840x2160@25Hz 16:9 */
1213 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1214 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1215 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1216 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1217 /* 95 - 3840x2160@30Hz 16:9 */
1218 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1219 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1221 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1222 /* 96 - 3840x2160@50Hz 16:9 */
1223 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1224 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1225 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1226 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1227 /* 97 - 3840x2160@60Hz 16:9 */
1228 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1229 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1230 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1231 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
1232 /* 98 - 4096x2160@24Hz 256:135 */
1233 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5116,
1234 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1235 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1236 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1237 /* 99 - 4096x2160@25Hz 256:135 */
1238 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 5064,
1239 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1240 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1241 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1242 /* 100 - 4096x2160@30Hz 256:135 */
1243 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000, 4096, 4184,
1244 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1245 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1246 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1247 /* 101 - 4096x2160@50Hz 256:135 */
1248 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 5064,
1249 5152, 5280, 0, 2160, 2168, 2178, 2250, 0,
1250 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1251 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1252 /* 102 - 4096x2160@60Hz 256:135 */
1253 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184,
1254 4272, 4400, 0, 2160, 2168, 2178, 2250, 0,
1255 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1256 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_256_135, },
1257 /* 103 - 3840x2160@24Hz 64:27 */
1258 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 5116,
1259 5204, 5500, 0, 2160, 2168, 2178, 2250, 0,
1260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1261 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1262 /* 104 - 3840x2160@25Hz 64:27 */
1263 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4896,
1264 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1265 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1266 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1267 /* 105 - 3840x2160@30Hz 64:27 */
1268 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000, 3840, 4016,
1269 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1270 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1271 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1272 /* 106 - 3840x2160@50Hz 64:27 */
1273 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4896,
1274 4984, 5280, 0, 2160, 2168, 2178, 2250, 0,
1275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1276 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1277 /* 107 - 3840x2160@60Hz 64:27 */
1278 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016,
1279 4104, 4400, 0, 2160, 2168, 2178, 2250, 0,
1280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1281 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_64_27, },
1282};
1283
1284/*
1285 * HDMI 1.4 4k modes. Index using the VIC.
1286 */
1287static const struct drm_display_mode edid_4k_modes[] = {
1288 /* 0 - dummy, VICs start at 1 */
1289 { },
1290 /* 1 - 3840x2160@30Hz */
1291 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1292 3840, 4016, 4104, 4400, 0,
1293 2160, 2168, 2178, 2250, 0,
1294 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1295 .vrefresh = 30, },
1296 /* 2 - 3840x2160@25Hz */
1297 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1298 3840, 4896, 4984, 5280, 0,
1299 2160, 2168, 2178, 2250, 0,
1300 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1301 .vrefresh = 25, },
1302 /* 3 - 3840x2160@24Hz */
1303 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
1304 3840, 5116, 5204, 5500, 0,
1305 2160, 2168, 2178, 2250, 0,
1306 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1307 .vrefresh = 24, },
1308 /* 4 - 4096x2160@24Hz (SMPTE) */
1309 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
1310 4096, 5116, 5204, 5500, 0,
1311 2160, 2168, 2178, 2250, 0,
1312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
1313 .vrefresh = 24, },
1314};
1315
1316/*** DDC fetch and block validation ***/
1317
1318static const u8 edid_header[] = {
1319 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
1320};
1321
1322/**
1323 * drm_edid_header_is_valid - sanity check the header of the base EDID block
1324 * @raw_edid: pointer to raw base EDID block
1325 *
1326 * Sanity check the header of the base EDID block.
1327 *
1328 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
1329 */
1330int drm_edid_header_is_valid(const u8 *raw_edid)
1331{
1332 int i, score = 0;
1333
1334 for (i = 0; i < sizeof(edid_header); i++)
1335 if (raw_edid[i] == edid_header[i])
1336 score++;
1337
1338 return score;
1339}
1340EXPORT_SYMBOL(drm_edid_header_is_valid);
1341
1342static int edid_fixup __read_mostly = 6;
1343module_param_named(edid_fixup, edid_fixup, int, 0400);
1344MODULE_PARM_DESC(edid_fixup,
1345 "Minimum number of valid EDID header bytes (0-8, default 6)");
1346
1347static void drm_get_displayid(struct drm_connector *connector,
1348 struct edid *edid);
1349static int validate_displayid(u8 *displayid, int length, int idx);
1350
1351static int drm_edid_block_checksum(const u8 *raw_edid)
1352{
1353 int i;
1354 u8 csum = 0, crc = 0;
1355
1356 for (i = 0; i < EDID_LENGTH - 1; i++)
1357 csum += raw_edid[i];
1358
1359 crc = 0x100 - csum;
1360
1361 return crc;
1362}
1363
1364static bool drm_edid_block_checksum_diff(const u8 *raw_edid, u8 real_checksum)
1365{
1366 if (raw_edid[EDID_LENGTH - 1] != real_checksum)
1367 return true;
1368 else
1369 return false;
1370}
1371
1372static bool drm_edid_is_zero(const u8 *in_edid, int length)
1373{
1374 if (memchr_inv(in_edid, 0, length))
1375 return false;
1376
1377 return true;
1378}
1379
1380/**
1381 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1382 * @raw_edid: pointer to raw EDID block
1383 * @block: type of block to validate (0 for base, extension otherwise)
1384 * @print_bad_edid: if true, dump bad EDID blocks to the console
1385 * @edid_corrupt: if true, the header or checksum is invalid
1386 *
1387 * Validate a base or extension EDID block and optionally dump bad blocks to
1388 * the console.
1389 *
1390 * Return: True if the block is valid, false otherwise.
1391 */
1392bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1393 bool *edid_corrupt)
1394{
1395 u8 csum;
1396 struct edid *edid = (struct edid *)raw_edid;
1397
1398 if (WARN_ON(!raw_edid))
1399 return false;
1400
1401 if (edid_fixup > 8 || edid_fixup < 0)
1402 edid_fixup = 6;
1403
1404 if (block == 0) {
1405 int score = drm_edid_header_is_valid(raw_edid);
1406 if (score == 8) {
1407 if (edid_corrupt)
1408 *edid_corrupt = false;
1409 } else if (score >= edid_fixup) {
1410 /* Displayport Link CTS Core 1.2 rev1.1 test 4.2.2.6
1411 * The corrupt flag needs to be set here otherwise, the
1412 * fix-up code here will correct the problem, the
1413 * checksum is correct and the test fails
1414 */
1415 if (edid_corrupt)
1416 *edid_corrupt = true;
1417 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1418 memcpy(raw_edid, edid_header, sizeof(edid_header));
1419 } else {
1420 if (edid_corrupt)
1421 *edid_corrupt = true;
1422 goto bad;
1423 }
1424 }
1425
1426 csum = drm_edid_block_checksum(raw_edid);
1427 if (drm_edid_block_checksum_diff(raw_edid, csum)) {
1428 if (edid_corrupt)
1429 *edid_corrupt = true;
1430
1431 /* allow CEA to slide through, switches mangle this */
1432 if (raw_edid[0] == CEA_EXT) {
1433 DRM_DEBUG("EDID checksum is invalid, remainder is %d\n", csum);
1434 DRM_DEBUG("Assuming a KVM switch modified the CEA block but left the original checksum\n");
1435 } else {
1436 if (print_bad_edid)
1437 DRM_NOTE("EDID checksum is invalid, remainder is %d\n", csum);
1438
1439 goto bad;
1440 }
1441 }
1442
1443 /* per-block-type checks */
1444 switch (raw_edid[0]) {
1445 case 0: /* base */
1446 if (edid->version != 1) {
1447 DRM_NOTE("EDID has major version %d, instead of 1\n", edid->version);
1448 goto bad;
1449 }
1450
1451 if (edid->revision > 4)
1452 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1453 break;
1454
1455 default:
1456 break;
1457 }
1458
1459 return true;
1460
1461bad:
1462 if (print_bad_edid) {
1463 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
1464 pr_notice("EDID block is all zeroes\n");
1465 } else {
1466 pr_notice("Raw EDID:\n");
1467 print_hex_dump(KERN_NOTICE,
1468 " \t", DUMP_PREFIX_NONE, 16, 1,
1469 raw_edid, EDID_LENGTH, false);
1470 }
1471 }
1472 return false;
1473}
1474EXPORT_SYMBOL(drm_edid_block_valid);
1475
1476/**
1477 * drm_edid_is_valid - sanity check EDID data
1478 * @edid: EDID data
1479 *
1480 * Sanity-check an entire EDID record (including extensions)
1481 *
1482 * Return: True if the EDID data is valid, false otherwise.
1483 */
1484bool drm_edid_is_valid(struct edid *edid)
1485{
1486 int i;
1487 u8 *raw = (u8 *)edid;
1488
1489 if (!edid)
1490 return false;
1491
1492 for (i = 0; i <= edid->extensions; i++)
1493 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL))
1494 return false;
1495
1496 return true;
1497}
1498EXPORT_SYMBOL(drm_edid_is_valid);
1499
1500#define DDC_SEGMENT_ADDR 0x30
1501/**
1502 * drm_do_probe_ddc_edid() - get EDID information via I2C
1503 * @data: I2C device adapter
1504 * @buf: EDID data buffer to be filled
1505 * @block: 128 byte EDID block to start fetching from
1506 * @len: EDID data buffer length to fetch
1507 *
1508 * Try to fetch EDID information by calling I2C driver functions.
1509 *
1510 * Return: 0 on success or -1 on failure.
1511 */
1512static int
1513drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
1514{
1515 struct i2c_adapter *adapter = data;
1516 unsigned char start = block * EDID_LENGTH;
1517 unsigned char segment = block >> 1;
1518 unsigned char xfers = segment ? 3 : 2;
1519 int ret, retries = 5;
1520
1521 /*
1522 * The core I2C driver will automatically retry the transfer if the
1523 * adapter reports EAGAIN. However, we find that bit-banging transfers
1524 * are susceptible to errors under a heavily loaded machine and
1525 * generate spurious NAKs and timeouts. Retrying the transfer
1526 * of the individual block a few times seems to overcome this.
1527 */
1528 do {
1529 struct i2c_msg msgs[] = {
1530 {
1531 .addr = DDC_SEGMENT_ADDR,
1532 .flags = 0,
1533 .len = 1,
1534 .buf = &segment,
1535 }, {
1536 .addr = DDC_ADDR,
1537 .flags = 0,
1538 .len = 1,
1539 .buf = &start,
1540 }, {
1541 .addr = DDC_ADDR,
1542 .flags = I2C_M_RD,
1543 .len = len,
1544 .buf = buf,
1545 }
1546 };
1547
1548 /*
1549 * Avoid sending the segment addr to not upset non-compliant
1550 * DDC monitors.
1551 */
1552 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1553
1554 if (ret == -ENXIO) {
1555 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1556 adapter->name);
1557 break;
1558 }
1559 } while (ret != xfers && --retries);
1560
1561 return ret == xfers ? 0 : -1;
1562}
1563
1564static void connector_bad_edid(struct drm_connector *connector,
1565 u8 *edid, int num_blocks)
1566{
1567 int i;
1568 u8 num_of_ext = edid[0x7e];
1569
1570 /* Calculate real checksum for the last edid extension block data */
1571 connector->real_edid_checksum =
1572 drm_edid_block_checksum(edid + num_of_ext * EDID_LENGTH);
1573
1574 if (connector->bad_edid_counter++ && !(drm_debug & DRM_UT_KMS))
1575 return;
1576
1577 dev_warn(connector->dev->dev,
1578 "%s: EDID is invalid:\n",
1579 connector->name);
1580 for (i = 0; i < num_blocks; i++) {
1581 u8 *block = edid + i * EDID_LENGTH;
1582 char prefix[20];
1583
1584 if (drm_edid_is_zero(block, EDID_LENGTH))
1585 sprintf(prefix, "\t[%02x] ZERO ", i);
1586 else if (!drm_edid_block_valid(block, i, false, NULL))
1587 sprintf(prefix, "\t[%02x] BAD ", i);
1588 else
1589 sprintf(prefix, "\t[%02x] GOOD ", i);
1590
1591 print_hex_dump(KERN_WARNING,
1592 prefix, DUMP_PREFIX_NONE, 16, 1,
1593 block, EDID_LENGTH, false);
1594 }
1595}
1596
1597/* Get override or firmware EDID */
1598static struct edid *drm_get_override_edid(struct drm_connector *connector)
1599{
1600 struct edid *override = NULL;
1601
1602 if (connector->override_edid)
1603 override = drm_edid_duplicate(connector->edid_blob_ptr->data);
1604
1605 if (!override)
1606 override = drm_load_edid_firmware(connector);
1607
1608 return IS_ERR(override) ? NULL : override;
1609}
1610
1611/**
1612 * drm_add_override_edid_modes - add modes from override/firmware EDID
1613 * @connector: connector we're probing
1614 *
1615 * Add modes from the override/firmware EDID, if available. Only to be used from
1616 * drm_helper_probe_single_connector_modes() as a fallback for when DDC probe
1617 * failed during drm_get_edid() and caused the override/firmware EDID to be
1618 * skipped.
1619 *
1620 * Return: The number of modes added or 0 if we couldn't find any.
1621 */
1622int drm_add_override_edid_modes(struct drm_connector *connector)
1623{
1624 struct edid *override;
1625 int num_modes = 0;
1626
1627 override = drm_get_override_edid(connector);
1628 if (override) {
1629 drm_connector_update_edid_property(connector, override);
1630 num_modes = drm_add_edid_modes(connector, override);
1631 kfree(override);
1632
1633 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] adding %d modes via fallback override/firmware EDID\n",
1634 connector->base.id, connector->name, num_modes);
1635 }
1636
1637 return num_modes;
1638}
1639EXPORT_SYMBOL(drm_add_override_edid_modes);
1640
1641/**
1642 * drm_do_get_edid - get EDID data using a custom EDID block read function
1643 * @connector: connector we're probing
1644 * @get_edid_block: EDID block read function
1645 * @data: private data passed to the block read function
1646 *
1647 * When the I2C adapter connected to the DDC bus is hidden behind a device that
1648 * exposes a different interface to read EDID blocks this function can be used
1649 * to get EDID data using a custom block read function.
1650 *
1651 * As in the general case the DDC bus is accessible by the kernel at the I2C
1652 * level, drivers must make all reasonable efforts to expose it as an I2C
1653 * adapter and use drm_get_edid() instead of abusing this function.
1654 *
1655 * The EDID may be overridden using debugfs override_edid or firmare EDID
1656 * (drm_load_edid_firmware() and drm.edid_firmware parameter), in this priority
1657 * order. Having either of them bypasses actual EDID reads.
1658 *
1659 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1660 */
1661struct edid *drm_do_get_edid(struct drm_connector *connector,
1662 int (*get_edid_block)(void *data, u8 *buf, unsigned int block,
1663 size_t len),
1664 void *data)
1665{
1666 int i, j = 0, valid_extensions = 0;
1667 u8 *edid, *new;
1668 struct edid *override;
1669
1670 override = drm_get_override_edid(connector);
1671 if (override)
1672 return override;
1673
1674 if ((edid = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
1675 return NULL;
1676
1677 /* base block fetch */
1678 for (i = 0; i < 4; i++) {
1679 if (get_edid_block(data, edid, 0, EDID_LENGTH))
1680 goto out;
1681 if (drm_edid_block_valid(edid, 0, false,
1682 &connector->edid_corrupt))
1683 break;
1684 if (i == 0 && drm_edid_is_zero(edid, EDID_LENGTH)) {
1685 connector->null_edid_counter++;
1686 goto carp;
1687 }
1688 }
1689 if (i == 4)
1690 goto carp;
1691
1692 /* if there's no extensions, we're done */
1693 valid_extensions = edid[0x7e];
1694 if (valid_extensions == 0)
1695 return (struct edid *)edid;
1696
1697 new = krealloc(edid, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1698 if (!new)
1699 goto out;
1700 edid = new;
1701
1702 for (j = 1; j <= edid[0x7e]; j++) {
1703 u8 *block = edid + j * EDID_LENGTH;
1704
1705 for (i = 0; i < 4; i++) {
1706 if (get_edid_block(data, block, j, EDID_LENGTH))
1707 goto out;
1708 if (drm_edid_block_valid(block, j, false, NULL))
1709 break;
1710 }
1711
1712 if (i == 4)
1713 valid_extensions--;
1714 }
1715
1716 if (valid_extensions != edid[0x7e]) {
1717 u8 *base;
1718
1719 connector_bad_edid(connector, edid, edid[0x7e] + 1);
1720
1721 new = kmalloc_array(valid_extensions + 1, EDID_LENGTH,
1722 GFP_KERNEL);
1723 if (!new)
1724 goto out;
1725
1726 base = new;
1727 for (i = 0; i <= edid[0x7e]; i++) {
1728 u8 *block = edid + i * EDID_LENGTH;
1729
1730 if (!drm_edid_block_valid(block, i, false, NULL))
1731 continue;
1732
1733 memcpy(base, block, EDID_LENGTH);
1734 base += EDID_LENGTH;
1735 }
1736
1737 new[EDID_LENGTH - 1] += new[0x7e] - valid_extensions;
1738 new[0x7e] = valid_extensions;
1739
1740 kfree(edid);
1741 edid = new;
1742 }
1743
1744 return (struct edid *)edid;
1745
1746carp:
1747 connector_bad_edid(connector, edid, 1);
1748out:
1749 kfree(edid);
1750 return NULL;
1751}
1752EXPORT_SYMBOL_GPL(drm_do_get_edid);
1753
1754/**
1755 * drm_probe_ddc() - probe DDC presence
1756 * @adapter: I2C adapter to probe
1757 *
1758 * Return: True on success, false on failure.
1759 */
1760bool
1761drm_probe_ddc(struct i2c_adapter *adapter)
1762{
1763 unsigned char out;
1764
1765 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1766}
1767EXPORT_SYMBOL(drm_probe_ddc);
1768
1769/**
1770 * drm_get_edid - get EDID data, if available
1771 * @connector: connector we're probing
1772 * @adapter: I2C adapter to use for DDC
1773 *
1774 * Poke the given I2C channel to grab EDID data if possible. If found,
1775 * attach it to the connector.
1776 *
1777 * Return: Pointer to valid EDID or NULL if we couldn't find any.
1778 */
1779struct edid *drm_get_edid(struct drm_connector *connector,
1780 struct i2c_adapter *adapter)
1781{
1782 struct edid *edid;
1783
1784 if (connector->force == DRM_FORCE_OFF)
1785 return NULL;
1786
1787 if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
1788 return NULL;
1789
1790 edid = drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter);
1791 if (edid)
1792 drm_get_displayid(connector, edid);
1793 return edid;
1794}
1795EXPORT_SYMBOL(drm_get_edid);
1796
1797/**
1798 * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
1799 * @connector: connector we're probing
1800 * @adapter: I2C adapter to use for DDC
1801 *
1802 * Wrapper around drm_get_edid() for laptops with dual GPUs using one set of
1803 * outputs. The wrapper adds the requisite vga_switcheroo calls to temporarily
1804 * switch DDC to the GPU which is retrieving EDID.
1805 *
1806 * Return: Pointer to valid EDID or %NULL if we couldn't find any.
1807 */
1808struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
1809 struct i2c_adapter *adapter)
1810{
1811 struct pci_dev *pdev = connector->dev->pdev;
1812 struct edid *edid;
1813
1814 vga_switcheroo_lock_ddc(pdev);
1815 edid = drm_get_edid(connector, adapter);
1816 vga_switcheroo_unlock_ddc(pdev);
1817
1818 return edid;
1819}
1820EXPORT_SYMBOL(drm_get_edid_switcheroo);
1821
1822/**
1823 * drm_edid_duplicate - duplicate an EDID and the extensions
1824 * @edid: EDID to duplicate
1825 *
1826 * Return: Pointer to duplicated EDID or NULL on allocation failure.
1827 */
1828struct edid *drm_edid_duplicate(const struct edid *edid)
1829{
1830 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1831}
1832EXPORT_SYMBOL(drm_edid_duplicate);
1833
1834/*** EDID parsing ***/
1835
1836/**
1837 * edid_vendor - match a string against EDID's obfuscated vendor field
1838 * @edid: EDID to match
1839 * @vendor: vendor string
1840 *
1841 * Returns true if @vendor is in @edid, false otherwise
1842 */
1843static bool edid_vendor(const struct edid *edid, const char *vendor)
1844{
1845 char edid_vendor[3];
1846
1847 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1848 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1849 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
1850 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
1851
1852 return !strncmp(edid_vendor, vendor, 3);
1853}
1854
1855/**
1856 * edid_get_quirks - return quirk flags for a given EDID
1857 * @edid: EDID to process
1858 *
1859 * This tells subsequent routines what fixes they need to apply.
1860 */
1861static u32 edid_get_quirks(const struct edid *edid)
1862{
1863 const struct edid_quirk *quirk;
1864 int i;
1865
1866 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1867 quirk = &edid_quirk_list[i];
1868
1869 if (edid_vendor(edid, quirk->vendor) &&
1870 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1871 return quirk->quirks;
1872 }
1873
1874 return 0;
1875}
1876
1877#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
1878#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
1879
1880/**
1881 * edid_fixup_preferred - set preferred modes based on quirk list
1882 * @connector: has mode list to fix up
1883 * @quirks: quirks list
1884 *
1885 * Walk the mode list for @connector, clearing the preferred status
1886 * on existing modes and setting it anew for the right mode ala @quirks.
1887 */
1888static void edid_fixup_preferred(struct drm_connector *connector,
1889 u32 quirks)
1890{
1891 struct drm_display_mode *t, *cur_mode, *preferred_mode;
1892 int target_refresh = 0;
1893 int cur_vrefresh, preferred_vrefresh;
1894
1895 if (list_empty(&connector->probed_modes))
1896 return;
1897
1898 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1899 target_refresh = 60;
1900 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1901 target_refresh = 75;
1902
1903 preferred_mode = list_first_entry(&connector->probed_modes,
1904 struct drm_display_mode, head);
1905
1906 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1907 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1908
1909 if (cur_mode == preferred_mode)
1910 continue;
1911
1912 /* Largest mode is preferred */
1913 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1914 preferred_mode = cur_mode;
1915
1916 cur_vrefresh = cur_mode->vrefresh ?
1917 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1918 preferred_vrefresh = preferred_mode->vrefresh ?
1919 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
1920 /* At a given size, try to get closest to target refresh */
1921 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
1922 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1923 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
1924 preferred_mode = cur_mode;
1925 }
1926 }
1927
1928 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1929}
1930
1931static bool
1932mode_is_rb(const struct drm_display_mode *mode)
1933{
1934 return (mode->htotal - mode->hdisplay == 160) &&
1935 (mode->hsync_end - mode->hdisplay == 80) &&
1936 (mode->hsync_end - mode->hsync_start == 32) &&
1937 (mode->vsync_start - mode->vdisplay == 3);
1938}
1939
1940/*
1941 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1942 * @dev: Device to duplicate against
1943 * @hsize: Mode width
1944 * @vsize: Mode height
1945 * @fresh: Mode refresh rate
1946 * @rb: Mode reduced-blanking-ness
1947 *
1948 * Walk the DMT mode list looking for a match for the given parameters.
1949 *
1950 * Return: A newly allocated copy of the mode, or NULL if not found.
1951 */
1952struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1953 int hsize, int vsize, int fresh,
1954 bool rb)
1955{
1956 int i;
1957
1958 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
1959 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
1960 if (hsize != ptr->hdisplay)
1961 continue;
1962 if (vsize != ptr->vdisplay)
1963 continue;
1964 if (fresh != drm_mode_vrefresh(ptr))
1965 continue;
1966 if (rb != mode_is_rb(ptr))
1967 continue;
1968
1969 return drm_mode_duplicate(dev, ptr);
1970 }
1971
1972 return NULL;
1973}
1974EXPORT_SYMBOL(drm_mode_find_dmt);
1975
1976typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1977
1978static void
1979cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1980{
1981 int i, n = 0;
1982 u8 d = ext[0x02];
1983 u8 *det_base = ext + d;
1984
1985 n = (127 - d) / 18;
1986 for (i = 0; i < n; i++)
1987 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1988}
1989
1990static void
1991vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1992{
1993 unsigned int i, n = min((int)ext[0x02], 6);
1994 u8 *det_base = ext + 5;
1995
1996 if (ext[0x01] != 1)
1997 return; /* unknown version */
1998
1999 for (i = 0; i < n; i++)
2000 cb((struct detailed_timing *)(det_base + 18 * i), closure);
2001}
2002
2003static void
2004drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
2005{
2006 int i;
2007 struct edid *edid = (struct edid *)raw_edid;
2008
2009 if (edid == NULL)
2010 return;
2011
2012 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
2013 cb(&(edid->detailed_timings[i]), closure);
2014
2015 for (i = 1; i <= raw_edid[0x7e]; i++) {
2016 u8 *ext = raw_edid + (i * EDID_LENGTH);
2017 switch (*ext) {
2018 case CEA_EXT:
2019 cea_for_each_detailed_block(ext, cb, closure);
2020 break;
2021 case VTB_EXT:
2022 vtb_for_each_detailed_block(ext, cb, closure);
2023 break;
2024 default:
2025 break;
2026 }
2027 }
2028}
2029
2030static void
2031is_rb(struct detailed_timing *t, void *data)
2032{
2033 u8 *r = (u8 *)t;
2034 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
2035 if (r[15] & 0x10)
2036 *(bool *)data = true;
2037}
2038
2039/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
2040static bool
2041drm_monitor_supports_rb(struct edid *edid)
2042{
2043 if (edid->revision >= 4) {
2044 bool ret = false;
2045 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
2046 return ret;
2047 }
2048
2049 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
2050}
2051
2052static void
2053find_gtf2(struct detailed_timing *t, void *data)
2054{
2055 u8 *r = (u8 *)t;
2056 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
2057 *(u8 **)data = r;
2058}
2059
2060/* Secondary GTF curve kicks in above some break frequency */
2061static int
2062drm_gtf2_hbreak(struct edid *edid)
2063{
2064 u8 *r = NULL;
2065 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2066 return r ? (r[12] * 2) : 0;
2067}
2068
2069static int
2070drm_gtf2_2c(struct edid *edid)
2071{
2072 u8 *r = NULL;
2073 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2074 return r ? r[13] : 0;
2075}
2076
2077static int
2078drm_gtf2_m(struct edid *edid)
2079{
2080 u8 *r = NULL;
2081 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2082 return r ? (r[15] << 8) + r[14] : 0;
2083}
2084
2085static int
2086drm_gtf2_k(struct edid *edid)
2087{
2088 u8 *r = NULL;
2089 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2090 return r ? r[16] : 0;
2091}
2092
2093static int
2094drm_gtf2_2j(struct edid *edid)
2095{
2096 u8 *r = NULL;
2097 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
2098 return r ? r[17] : 0;
2099}
2100
2101/**
2102 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
2103 * @edid: EDID block to scan
2104 */
2105static int standard_timing_level(struct edid *edid)
2106{
2107 if (edid->revision >= 2) {
2108 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
2109 return LEVEL_CVT;
2110 if (drm_gtf2_hbreak(edid))
2111 return LEVEL_GTF2;
2112 return LEVEL_GTF;
2113 }
2114 return LEVEL_DMT;
2115}
2116
2117/*
2118 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
2119 * monitors fill with ascii space (0x20) instead.
2120 */
2121static int
2122bad_std_timing(u8 a, u8 b)
2123{
2124 return (a == 0x00 && b == 0x00) ||
2125 (a == 0x01 && b == 0x01) ||
2126 (a == 0x20 && b == 0x20);
2127}
2128
2129/**
2130 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
2131 * @connector: connector of for the EDID block
2132 * @edid: EDID block to scan
2133 * @t: standard timing params
2134 *
2135 * Take the standard timing params (in this case width, aspect, and refresh)
2136 * and convert them into a real mode using CVT/GTF/DMT.
2137 */
2138static struct drm_display_mode *
2139drm_mode_std(struct drm_connector *connector, struct edid *edid,
2140 struct std_timing *t)
2141{
2142 struct drm_device *dev = connector->dev;
2143 struct drm_display_mode *m, *mode = NULL;
2144 int hsize, vsize;
2145 int vrefresh_rate;
2146 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
2147 >> EDID_TIMING_ASPECT_SHIFT;
2148 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
2149 >> EDID_TIMING_VFREQ_SHIFT;
2150 int timing_level = standard_timing_level(edid);
2151
2152 if (bad_std_timing(t->hsize, t->vfreq_aspect))
2153 return NULL;
2154
2155 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
2156 hsize = t->hsize * 8 + 248;
2157 /* vrefresh_rate = vfreq + 60 */
2158 vrefresh_rate = vfreq + 60;
2159 /* the vdisplay is calculated based on the aspect ratio */
2160 if (aspect_ratio == 0) {
2161 if (edid->revision < 3)
2162 vsize = hsize;
2163 else
2164 vsize = (hsize * 10) / 16;
2165 } else if (aspect_ratio == 1)
2166 vsize = (hsize * 3) / 4;
2167 else if (aspect_ratio == 2)
2168 vsize = (hsize * 4) / 5;
2169 else
2170 vsize = (hsize * 9) / 16;
2171
2172 /* HDTV hack, part 1 */
2173 if (vrefresh_rate == 60 &&
2174 ((hsize == 1360 && vsize == 765) ||
2175 (hsize == 1368 && vsize == 769))) {
2176 hsize = 1366;
2177 vsize = 768;
2178 }
2179
2180 /*
2181 * If this connector already has a mode for this size and refresh
2182 * rate (because it came from detailed or CVT info), use that
2183 * instead. This way we don't have to guess at interlace or
2184 * reduced blanking.
2185 */
2186 list_for_each_entry(m, &connector->probed_modes, head)
2187 if (m->hdisplay == hsize && m->vdisplay == vsize &&
2188 drm_mode_vrefresh(m) == vrefresh_rate)
2189 return NULL;
2190
2191 /* HDTV hack, part 2 */
2192 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
2193 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
2194 false);
2195 if (!mode)
2196 return NULL;
2197 mode->hdisplay = 1366;
2198 mode->hsync_start = mode->hsync_start - 1;
2199 mode->hsync_end = mode->hsync_end - 1;
2200 return mode;
2201 }
2202
2203 /* check whether it can be found in default mode table */
2204 if (drm_monitor_supports_rb(edid)) {
2205 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
2206 true);
2207 if (mode)
2208 return mode;
2209 }
2210 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
2211 if (mode)
2212 return mode;
2213
2214 /* okay, generate it */
2215 switch (timing_level) {
2216 case LEVEL_DMT:
2217 break;
2218 case LEVEL_GTF:
2219 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2220 break;
2221 case LEVEL_GTF2:
2222 /*
2223 * This is potentially wrong if there's ever a monitor with
2224 * more than one ranges section, each claiming a different
2225 * secondary GTF curve. Please don't do that.
2226 */
2227 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
2228 if (!mode)
2229 return NULL;
2230 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
2231 drm_mode_destroy(dev, mode);
2232 mode = drm_gtf_mode_complex(dev, hsize, vsize,
2233 vrefresh_rate, 0, 0,
2234 drm_gtf2_m(edid),
2235 drm_gtf2_2c(edid),
2236 drm_gtf2_k(edid),
2237 drm_gtf2_2j(edid));
2238 }
2239 break;
2240 case LEVEL_CVT:
2241 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
2242 false);
2243 break;
2244 }
2245 return mode;
2246}
2247
2248/*
2249 * EDID is delightfully ambiguous about how interlaced modes are to be
2250 * encoded. Our internal representation is of frame height, but some
2251 * HDTV detailed timings are encoded as field height.
2252 *
2253 * The format list here is from CEA, in frame size. Technically we
2254 * should be checking refresh rate too. Whatever.
2255 */
2256static void
2257drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
2258 struct detailed_pixel_timing *pt)
2259{
2260 int i;
2261 static const struct {
2262 int w, h;
2263 } cea_interlaced[] = {
2264 { 1920, 1080 },
2265 { 720, 480 },
2266 { 1440, 480 },
2267 { 2880, 480 },
2268 { 720, 576 },
2269 { 1440, 576 },
2270 { 2880, 576 },
2271 };
2272
2273 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
2274 return;
2275
2276 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
2277 if ((mode->hdisplay == cea_interlaced[i].w) &&
2278 (mode->vdisplay == cea_interlaced[i].h / 2)) {
2279 mode->vdisplay *= 2;
2280 mode->vsync_start *= 2;
2281 mode->vsync_end *= 2;
2282 mode->vtotal *= 2;
2283 mode->vtotal |= 1;
2284 }
2285 }
2286
2287 mode->flags |= DRM_MODE_FLAG_INTERLACE;
2288}
2289
2290/**
2291 * drm_mode_detailed - create a new mode from an EDID detailed timing section
2292 * @dev: DRM device (needed to create new mode)
2293 * @edid: EDID block
2294 * @timing: EDID detailed timing info
2295 * @quirks: quirks to apply
2296 *
2297 * An EDID detailed timing block contains enough info for us to create and
2298 * return a new struct drm_display_mode.
2299 */
2300static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
2301 struct edid *edid,
2302 struct detailed_timing *timing,
2303 u32 quirks)
2304{
2305 struct drm_display_mode *mode;
2306 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
2307 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
2308 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
2309 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
2310 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
2311 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
2312 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
2313 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
2314 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
2315
2316 /* ignore tiny modes */
2317 if (hactive < 64 || vactive < 64)
2318 return NULL;
2319
2320 if (pt->misc & DRM_EDID_PT_STEREO) {
2321 DRM_DEBUG_KMS("stereo mode not supported\n");
2322 return NULL;
2323 }
2324 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
2325 DRM_DEBUG_KMS("composite sync not supported\n");
2326 }
2327
2328 /* it is incorrect if hsync/vsync width is zero */
2329 if (!hsync_pulse_width || !vsync_pulse_width) {
2330 DRM_DEBUG_KMS("Incorrect Detailed timing. "
2331 "Wrong Hsync/Vsync pulse width\n");
2332 return NULL;
2333 }
2334
2335 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
2336 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
2337 if (!mode)
2338 return NULL;
2339
2340 goto set_size;
2341 }
2342
2343 mode = drm_mode_create(dev);
2344 if (!mode)
2345 return NULL;
2346
2347 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
2348 timing->pixel_clock = cpu_to_le16(1088);
2349
2350 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
2351
2352 mode->hdisplay = hactive;
2353 mode->hsync_start = mode->hdisplay + hsync_offset;
2354 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
2355 mode->htotal = mode->hdisplay + hblank;
2356
2357 mode->vdisplay = vactive;
2358 mode->vsync_start = mode->vdisplay + vsync_offset;
2359 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
2360 mode->vtotal = mode->vdisplay + vblank;
2361
2362 /* Some EDIDs have bogus h/vtotal values */
2363 if (mode->hsync_end > mode->htotal)
2364 mode->htotal = mode->hsync_end + 1;
2365 if (mode->vsync_end > mode->vtotal)
2366 mode->vtotal = mode->vsync_end + 1;
2367
2368 drm_mode_do_interlace_quirk(mode, pt);
2369
2370 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
2371 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
2372 }
2373
2374 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
2375 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
2376 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
2377 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
2378
2379set_size:
2380 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
2381 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
2382
2383 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
2384 mode->width_mm *= 10;
2385 mode->height_mm *= 10;
2386 }
2387
2388 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
2389 mode->width_mm = edid->width_cm * 10;
2390 mode->height_mm = edid->height_cm * 10;
2391 }
2392
2393 mode->type = DRM_MODE_TYPE_DRIVER;
2394 mode->vrefresh = drm_mode_vrefresh(mode);
2395 drm_mode_set_name(mode);
2396
2397 return mode;
2398}
2399
2400static bool
2401mode_in_hsync_range(const struct drm_display_mode *mode,
2402 struct edid *edid, u8 *t)
2403{
2404 int hsync, hmin, hmax;
2405
2406 hmin = t[7];
2407 if (edid->revision >= 4)
2408 hmin += ((t[4] & 0x04) ? 255 : 0);
2409 hmax = t[8];
2410 if (edid->revision >= 4)
2411 hmax += ((t[4] & 0x08) ? 255 : 0);
2412 hsync = drm_mode_hsync(mode);
2413
2414 return (hsync <= hmax && hsync >= hmin);
2415}
2416
2417static bool
2418mode_in_vsync_range(const struct drm_display_mode *mode,
2419 struct edid *edid, u8 *t)
2420{
2421 int vsync, vmin, vmax;
2422
2423 vmin = t[5];
2424 if (edid->revision >= 4)
2425 vmin += ((t[4] & 0x01) ? 255 : 0);
2426 vmax = t[6];
2427 if (edid->revision >= 4)
2428 vmax += ((t[4] & 0x02) ? 255 : 0);
2429 vsync = drm_mode_vrefresh(mode);
2430
2431 return (vsync <= vmax && vsync >= vmin);
2432}
2433
2434static u32
2435range_pixel_clock(struct edid *edid, u8 *t)
2436{
2437 /* unspecified */
2438 if (t[9] == 0 || t[9] == 255)
2439 return 0;
2440
2441 /* 1.4 with CVT support gives us real precision, yay */
2442 if (edid->revision >= 4 && t[10] == 0x04)
2443 return (t[9] * 10000) - ((t[12] >> 2) * 250);
2444
2445 /* 1.3 is pathetic, so fuzz up a bit */
2446 return t[9] * 10000 + 5001;
2447}
2448
2449static bool
2450mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
2451 struct detailed_timing *timing)
2452{
2453 u32 max_clock;
2454 u8 *t = (u8 *)timing;
2455
2456 if (!mode_in_hsync_range(mode, edid, t))
2457 return false;
2458
2459 if (!mode_in_vsync_range(mode, edid, t))
2460 return false;
2461
2462 if ((max_clock = range_pixel_clock(edid, t)))
2463 if (mode->clock > max_clock)
2464 return false;
2465
2466 /* 1.4 max horizontal check */
2467 if (edid->revision >= 4 && t[10] == 0x04)
2468 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
2469 return false;
2470
2471 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
2472 return false;
2473
2474 return true;
2475}
2476
2477static bool valid_inferred_mode(const struct drm_connector *connector,
2478 const struct drm_display_mode *mode)
2479{
2480 const struct drm_display_mode *m;
2481 bool ok = false;
2482
2483 list_for_each_entry(m, &connector->probed_modes, head) {
2484 if (mode->hdisplay == m->hdisplay &&
2485 mode->vdisplay == m->vdisplay &&
2486 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
2487 return false; /* duplicated */
2488 if (mode->hdisplay <= m->hdisplay &&
2489 mode->vdisplay <= m->vdisplay)
2490 ok = true;
2491 }
2492 return ok;
2493}
2494
2495static int
2496drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2497 struct detailed_timing *timing)
2498{
2499 int i, modes = 0;
2500 struct drm_display_mode *newmode;
2501 struct drm_device *dev = connector->dev;
2502
2503 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
2504 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
2505 valid_inferred_mode(connector, drm_dmt_modes + i)) {
2506 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
2507 if (newmode) {
2508 drm_mode_probed_add(connector, newmode);
2509 modes++;
2510 }
2511 }
2512 }
2513
2514 return modes;
2515}
2516
2517/* fix up 1366x768 mode from 1368x768;
2518 * GFT/CVT can't express 1366 width which isn't dividable by 8
2519 */
2520void drm_mode_fixup_1366x768(struct drm_display_mode *mode)
2521{
2522 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2523 mode->hdisplay = 1366;
2524 mode->hsync_start--;
2525 mode->hsync_end--;
2526 drm_mode_set_name(mode);
2527 }
2528}
2529
2530static int
2531drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2532 struct detailed_timing *timing)
2533{
2534 int i, modes = 0;
2535 struct drm_display_mode *newmode;
2536 struct drm_device *dev = connector->dev;
2537
2538 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
2539 const struct minimode *m = &extra_modes[i];
2540 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
2541 if (!newmode)
2542 return modes;
2543
2544 drm_mode_fixup_1366x768(newmode);
2545 if (!mode_in_range(newmode, edid, timing) ||
2546 !valid_inferred_mode(connector, newmode)) {
2547 drm_mode_destroy(dev, newmode);
2548 continue;
2549 }
2550
2551 drm_mode_probed_add(connector, newmode);
2552 modes++;
2553 }
2554
2555 return modes;
2556}
2557
2558static int
2559drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2560 struct detailed_timing *timing)
2561{
2562 int i, modes = 0;
2563 struct drm_display_mode *newmode;
2564 struct drm_device *dev = connector->dev;
2565 bool rb = drm_monitor_supports_rb(edid);
2566
2567 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
2568 const struct minimode *m = &extra_modes[i];
2569 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
2570 if (!newmode)
2571 return modes;
2572
2573 drm_mode_fixup_1366x768(newmode);
2574 if (!mode_in_range(newmode, edid, timing) ||
2575 !valid_inferred_mode(connector, newmode)) {
2576 drm_mode_destroy(dev, newmode);
2577 continue;
2578 }
2579
2580 drm_mode_probed_add(connector, newmode);
2581 modes++;
2582 }
2583
2584 return modes;
2585}
2586
2587static void
2588do_inferred_modes(struct detailed_timing *timing, void *c)
2589{
2590 struct detailed_mode_closure *closure = c;
2591 struct detailed_non_pixel *data = &timing->data.other_data;
2592 struct detailed_data_monitor_range *range = &data->data.range;
2593
2594 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2595 return;
2596
2597 closure->modes += drm_dmt_modes_for_range(closure->connector,
2598 closure->edid,
2599 timing);
2600
2601 if (!version_greater(closure->edid, 1, 1))
2602 return; /* GTF not defined yet */
2603
2604 switch (range->flags) {
2605 case 0x02: /* secondary gtf, XXX could do more */
2606 case 0x00: /* default gtf */
2607 closure->modes += drm_gtf_modes_for_range(closure->connector,
2608 closure->edid,
2609 timing);
2610 break;
2611 case 0x04: /* cvt, only in 1.4+ */
2612 if (!version_greater(closure->edid, 1, 3))
2613 break;
2614
2615 closure->modes += drm_cvt_modes_for_range(closure->connector,
2616 closure->edid,
2617 timing);
2618 break;
2619 case 0x01: /* just the ranges, no formula */
2620 default:
2621 break;
2622 }
2623}
2624
2625static int
2626add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2627{
2628 struct detailed_mode_closure closure = {
2629 .connector = connector,
2630 .edid = edid,
2631 };
2632
2633 if (version_greater(edid, 1, 0))
2634 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2635 &closure);
2636
2637 return closure.modes;
2638}
2639
2640static int
2641drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2642{
2643 int i, j, m, modes = 0;
2644 struct drm_display_mode *mode;
2645 u8 *est = ((u8 *)timing) + 6;
2646
2647 for (i = 0; i < 6; i++) {
2648 for (j = 7; j >= 0; j--) {
2649 m = (i * 8) + (7 - j);
2650 if (m >= ARRAY_SIZE(est3_modes))
2651 break;
2652 if (est[i] & (1 << j)) {
2653 mode = drm_mode_find_dmt(connector->dev,
2654 est3_modes[m].w,
2655 est3_modes[m].h,
2656 est3_modes[m].r,
2657 est3_modes[m].rb);
2658 if (mode) {
2659 drm_mode_probed_add(connector, mode);
2660 modes++;
2661 }
2662 }
2663 }
2664 }
2665
2666 return modes;
2667}
2668
2669static void
2670do_established_modes(struct detailed_timing *timing, void *c)
2671{
2672 struct detailed_mode_closure *closure = c;
2673 struct detailed_non_pixel *data = &timing->data.other_data;
2674
2675 if (data->type == EDID_DETAIL_EST_TIMINGS)
2676 closure->modes += drm_est3_modes(closure->connector, timing);
2677}
2678
2679/**
2680 * add_established_modes - get est. modes from EDID and add them
2681 * @connector: connector to add mode(s) to
2682 * @edid: EDID block to scan
2683 *
2684 * Each EDID block contains a bitmap of the supported "established modes" list
2685 * (defined above). Tease them out and add them to the global modes list.
2686 */
2687static int
2688add_established_modes(struct drm_connector *connector, struct edid *edid)
2689{
2690 struct drm_device *dev = connector->dev;
2691 unsigned long est_bits = edid->established_timings.t1 |
2692 (edid->established_timings.t2 << 8) |
2693 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2694 int i, modes = 0;
2695 struct detailed_mode_closure closure = {
2696 .connector = connector,
2697 .edid = edid,
2698 };
2699
2700 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2701 if (est_bits & (1<<i)) {
2702 struct drm_display_mode *newmode;
2703 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2704 if (newmode) {
2705 drm_mode_probed_add(connector, newmode);
2706 modes++;
2707 }
2708 }
2709 }
2710
2711 if (version_greater(edid, 1, 0))
2712 drm_for_each_detailed_block((u8 *)edid,
2713 do_established_modes, &closure);
2714
2715 return modes + closure.modes;
2716}
2717
2718static void
2719do_standard_modes(struct detailed_timing *timing, void *c)
2720{
2721 struct detailed_mode_closure *closure = c;
2722 struct detailed_non_pixel *data = &timing->data.other_data;
2723 struct drm_connector *connector = closure->connector;
2724 struct edid *edid = closure->edid;
2725
2726 if (data->type == EDID_DETAIL_STD_MODES) {
2727 int i;
2728 for (i = 0; i < 6; i++) {
2729 struct std_timing *std;
2730 struct drm_display_mode *newmode;
2731
2732 std = &data->data.timings[i];
2733 newmode = drm_mode_std(connector, edid, std);
2734 if (newmode) {
2735 drm_mode_probed_add(connector, newmode);
2736 closure->modes++;
2737 }
2738 }
2739 }
2740}
2741
2742/**
2743 * add_standard_modes - get std. modes from EDID and add them
2744 * @connector: connector to add mode(s) to
2745 * @edid: EDID block to scan
2746 *
2747 * Standard modes can be calculated using the appropriate standard (DMT,
2748 * GTF or CVT. Grab them from @edid and add them to the list.
2749 */
2750static int
2751add_standard_modes(struct drm_connector *connector, struct edid *edid)
2752{
2753 int i, modes = 0;
2754 struct detailed_mode_closure closure = {
2755 .connector = connector,
2756 .edid = edid,
2757 };
2758
2759 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2760 struct drm_display_mode *newmode;
2761
2762 newmode = drm_mode_std(connector, edid,
2763 &edid->standard_timings[i]);
2764 if (newmode) {
2765 drm_mode_probed_add(connector, newmode);
2766 modes++;
2767 }
2768 }
2769
2770 if (version_greater(edid, 1, 0))
2771 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2772 &closure);
2773
2774 /* XXX should also look for standard codes in VTB blocks */
2775
2776 return modes + closure.modes;
2777}
2778
2779static int drm_cvt_modes(struct drm_connector *connector,
2780 struct detailed_timing *timing)
2781{
2782 int i, j, modes = 0;
2783 struct drm_display_mode *newmode;
2784 struct drm_device *dev = connector->dev;
2785 struct cvt_timing *cvt;
2786 const int rates[] = { 60, 85, 75, 60, 50 };
2787 const u8 empty[3] = { 0, 0, 0 };
2788
2789 for (i = 0; i < 4; i++) {
2790 int width, height;
2791 cvt = &(timing->data.other_data.data.cvt[i]);
2792
2793 if (!memcmp(cvt->code, empty, 3))
2794 continue;
2795
2796 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
2797 switch (cvt->code[1] & 0x0c) {
2798 /* default - because compiler doesn't see that we've enumerated all cases */
2799 default:
2800 case 0x00:
2801 width = height * 4 / 3;
2802 break;
2803 case 0x04:
2804 width = height * 16 / 9;
2805 break;
2806 case 0x08:
2807 width = height * 16 / 10;
2808 break;
2809 case 0x0c:
2810 width = height * 15 / 9;
2811 break;
2812 }
2813
2814 for (j = 1; j < 5; j++) {
2815 if (cvt->code[2] & (1 << j)) {
2816 newmode = drm_cvt_mode(dev, width, height,
2817 rates[j], j == 0,
2818 false, false);
2819 if (newmode) {
2820 drm_mode_probed_add(connector, newmode);
2821 modes++;
2822 }
2823 }
2824 }
2825 }
2826
2827 return modes;
2828}
2829
2830static void
2831do_cvt_mode(struct detailed_timing *timing, void *c)
2832{
2833 struct detailed_mode_closure *closure = c;
2834 struct detailed_non_pixel *data = &timing->data.other_data;
2835
2836 if (data->type == EDID_DETAIL_CVT_3BYTE)
2837 closure->modes += drm_cvt_modes(closure->connector, timing);
2838}
2839
2840static int
2841add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2842{
2843 struct detailed_mode_closure closure = {
2844 .connector = connector,
2845 .edid = edid,
2846 };
2847
2848 if (version_greater(edid, 1, 2))
2849 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
2850
2851 /* XXX should also look for CVT codes in VTB blocks */
2852
2853 return closure.modes;
2854}
2855
2856static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
2857
2858static void
2859do_detailed_mode(struct detailed_timing *timing, void *c)
2860{
2861 struct detailed_mode_closure *closure = c;
2862 struct drm_display_mode *newmode;
2863
2864 if (timing->pixel_clock) {
2865 newmode = drm_mode_detailed(closure->connector->dev,
2866 closure->edid, timing,
2867 closure->quirks);
2868 if (!newmode)
2869 return;
2870
2871 if (closure->preferred)
2872 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2873
2874 /*
2875 * Detailed modes are limited to 10kHz pixel clock resolution,
2876 * so fix up anything that looks like CEA/HDMI mode, but the clock
2877 * is just slightly off.
2878 */
2879 fixup_detailed_cea_mode_clock(newmode);
2880
2881 drm_mode_probed_add(closure->connector, newmode);
2882 closure->modes++;
2883 closure->preferred = false;
2884 }
2885}
2886
2887/*
2888 * add_detailed_modes - Add modes from detailed timings
2889 * @connector: attached connector
2890 * @edid: EDID block to scan
2891 * @quirks: quirks to apply
2892 */
2893static int
2894add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2895 u32 quirks)
2896{
2897 struct detailed_mode_closure closure = {
2898 .connector = connector,
2899 .edid = edid,
2900 .preferred = true,
2901 .quirks = quirks,
2902 };
2903
2904 if (closure.preferred && !version_greater(edid, 1, 3))
2905 closure.preferred =
2906 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
2907
2908 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
2909
2910 return closure.modes;
2911}
2912
2913#define AUDIO_BLOCK 0x01
2914#define VIDEO_BLOCK 0x02
2915#define VENDOR_BLOCK 0x03
2916#define SPEAKER_BLOCK 0x04
2917#define HDR_STATIC_METADATA_BLOCK 0x6
2918#define USE_EXTENDED_TAG 0x07
2919#define EXT_VIDEO_CAPABILITY_BLOCK 0x00
2920#define EXT_VIDEO_DATA_BLOCK_420 0x0E
2921#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F
2922#define EDID_BASIC_AUDIO (1 << 6)
2923#define EDID_CEA_YCRCB444 (1 << 5)
2924#define EDID_CEA_YCRCB422 (1 << 4)
2925#define EDID_CEA_VCDB_QS (1 << 6)
2926
2927/*
2928 * Search EDID for CEA extension block.
2929 */
2930static u8 *drm_find_edid_extension(const struct edid *edid, int ext_id)
2931{
2932 u8 *edid_ext = NULL;
2933 int i;
2934
2935 /* No EDID or EDID extensions */
2936 if (edid == NULL || edid->extensions == 0)
2937 return NULL;
2938
2939 /* Find CEA extension */
2940 for (i = 0; i < edid->extensions; i++) {
2941 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
2942 if (edid_ext[0] == ext_id)
2943 break;
2944 }
2945
2946 if (i == edid->extensions)
2947 return NULL;
2948
2949 return edid_ext;
2950}
2951
2952
2953static u8 *drm_find_displayid_extension(const struct edid *edid)
2954{
2955 return drm_find_edid_extension(edid, DISPLAYID_EXT);
2956}
2957
2958static u8 *drm_find_cea_extension(const struct edid *edid)
2959{
2960 int ret;
2961 int idx = 1;
2962 int length = EDID_LENGTH;
2963 struct displayid_block *block;
2964 u8 *cea;
2965 u8 *displayid;
2966
2967 /* Look for a top level CEA extension block */
2968 cea = drm_find_edid_extension(edid, CEA_EXT);
2969 if (cea)
2970 return cea;
2971
2972 /* CEA blocks can also be found embedded in a DisplayID block */
2973 displayid = drm_find_displayid_extension(edid);
2974 if (!displayid)
2975 return NULL;
2976
2977 ret = validate_displayid(displayid, length, idx);
2978 if (ret)
2979 return NULL;
2980
2981 idx += sizeof(struct displayid_hdr);
2982 for_each_displayid_db(displayid, block, idx, length) {
2983 if (block->tag == DATA_BLOCK_CTA) {
2984 cea = (u8 *)block;
2985 break;
2986 }
2987 }
2988
2989 return cea;
2990}
2991
2992/*
2993 * Calculate the alternate clock for the CEA mode
2994 * (60Hz vs. 59.94Hz etc.)
2995 */
2996static unsigned int
2997cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2998{
2999 unsigned int clock = cea_mode->clock;
3000
3001 if (cea_mode->vrefresh % 6 != 0)
3002 return clock;
3003
3004 /*
3005 * edid_cea_modes contains the 59.94Hz
3006 * variant for 240 and 480 line modes,
3007 * and the 60Hz variant otherwise.
3008 */
3009 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
3010 clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
3011 else
3012 clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
3013
3014 return clock;
3015}
3016
3017static bool
3018cea_mode_alternate_timings(u8 vic, struct drm_display_mode *mode)
3019{
3020 /*
3021 * For certain VICs the spec allows the vertical
3022 * front porch to vary by one or two lines.
3023 *
3024 * cea_modes[] stores the variant with the shortest
3025 * vertical front porch. We can adjust the mode to
3026 * get the other variants by simply increasing the
3027 * vertical front porch length.
3028 */
3029 BUILD_BUG_ON(edid_cea_modes[8].vtotal != 262 ||
3030 edid_cea_modes[9].vtotal != 262 ||
3031 edid_cea_modes[12].vtotal != 262 ||
3032 edid_cea_modes[13].vtotal != 262 ||
3033 edid_cea_modes[23].vtotal != 312 ||
3034 edid_cea_modes[24].vtotal != 312 ||
3035 edid_cea_modes[27].vtotal != 312 ||
3036 edid_cea_modes[28].vtotal != 312);
3037
3038 if (((vic == 8 || vic == 9 ||
3039 vic == 12 || vic == 13) && mode->vtotal < 263) ||
3040 ((vic == 23 || vic == 24 ||
3041 vic == 27 || vic == 28) && mode->vtotal < 314)) {
3042 mode->vsync_start++;
3043 mode->vsync_end++;
3044 mode->vtotal++;
3045
3046 return true;
3047 }
3048
3049 return false;
3050}
3051
3052static u8 drm_match_cea_mode_clock_tolerance(const struct drm_display_mode *to_match,
3053 unsigned int clock_tolerance)
3054{
3055 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
3056 u8 vic;
3057
3058 if (!to_match->clock)
3059 return 0;
3060
3061 if (to_match->picture_aspect_ratio)
3062 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3063
3064 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
3065 struct drm_display_mode cea_mode = edid_cea_modes[vic];
3066 unsigned int clock1, clock2;
3067
3068 /* Check both 60Hz and 59.94Hz */
3069 clock1 = cea_mode.clock;
3070 clock2 = cea_mode_alternate_clock(&cea_mode);
3071
3072 if (abs(to_match->clock - clock1) > clock_tolerance &&
3073 abs(to_match->clock - clock2) > clock_tolerance)
3074 continue;
3075
3076 do {
3077 if (drm_mode_match(to_match, &cea_mode, match_flags))
3078 return vic;
3079 } while (cea_mode_alternate_timings(vic, &cea_mode));
3080 }
3081
3082 return 0;
3083}
3084
3085/**
3086 * drm_match_cea_mode - look for a CEA mode matching given mode
3087 * @to_match: display mode
3088 *
3089 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
3090 * mode.
3091 */
3092u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
3093{
3094 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
3095 u8 vic;
3096
3097 if (!to_match->clock)
3098 return 0;
3099
3100 if (to_match->picture_aspect_ratio)
3101 match_flags |= DRM_MODE_MATCH_ASPECT_RATIO;
3102
3103 for (vic = 1; vic < ARRAY_SIZE(edid_cea_modes); vic++) {
3104 struct drm_display_mode cea_mode = edid_cea_modes[vic];
3105 unsigned int clock1, clock2;
3106
3107 /* Check both 60Hz and 59.94Hz */
3108 clock1 = cea_mode.clock;
3109 clock2 = cea_mode_alternate_clock(&cea_mode);
3110
3111 if (KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock1) &&
3112 KHZ2PICOS(to_match->clock) != KHZ2PICOS(clock2))
3113 continue;
3114
3115 do {
3116 if (drm_mode_match(to_match, &cea_mode, match_flags))
3117 return vic;
3118 } while (cea_mode_alternate_timings(vic, &cea_mode));
3119 }
3120
3121 return 0;
3122}
3123EXPORT_SYMBOL(drm_match_cea_mode);
3124
3125static bool drm_valid_cea_vic(u8 vic)
3126{
3127 return vic > 0 && vic < ARRAY_SIZE(edid_cea_modes);
3128}
3129
3130/**
3131 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
3132 * the input VIC from the CEA mode list
3133 * @video_code: ID given to each of the CEA modes
3134 *
3135 * Returns picture aspect ratio
3136 */
3137enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
3138{
3139 return edid_cea_modes[video_code].picture_aspect_ratio;
3140}
3141EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
3142
3143/*
3144 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
3145 * specific block).
3146 *
3147 * It's almost like cea_mode_alternate_clock(), we just need to add an
3148 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
3149 * one.
3150 */
3151static unsigned int
3152hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
3153{
3154 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
3155 return hdmi_mode->clock;
3156
3157 return cea_mode_alternate_clock(hdmi_mode);
3158}
3159
3160static u8 drm_match_hdmi_mode_clock_tolerance(const struct drm_display_mode *to_match,
3161 unsigned int clock_tolerance)
3162{
3163 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
3164 u8 vic;
3165
3166 if (!to_match->clock)
3167 return 0;
3168
3169 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3170 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
3171 unsigned int clock1, clock2;
3172
3173 /* Make sure to also match alternate clocks */
3174 clock1 = hdmi_mode->clock;
3175 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3176
3177 if (abs(to_match->clock - clock1) > clock_tolerance &&
3178 abs(to_match->clock - clock2) > clock_tolerance)
3179 continue;
3180
3181 if (drm_mode_match(to_match, hdmi_mode, match_flags))
3182 return vic;
3183 }
3184
3185 return 0;
3186}
3187
3188/*
3189 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
3190 * @to_match: display mode
3191 *
3192 * An HDMI mode is one defined in the HDMI vendor specific block.
3193 *
3194 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
3195 */
3196static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
3197{
3198 unsigned int match_flags = DRM_MODE_MATCH_TIMINGS | DRM_MODE_MATCH_FLAGS;
3199 u8 vic;
3200
3201 if (!to_match->clock)
3202 return 0;
3203
3204 for (vic = 1; vic < ARRAY_SIZE(edid_4k_modes); vic++) {
3205 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[vic];
3206 unsigned int clock1, clock2;
3207
3208 /* Make sure to also match alternate clocks */
3209 clock1 = hdmi_mode->clock;
3210 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
3211
3212 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
3213 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
3214 drm_mode_match(to_match, hdmi_mode, match_flags))
3215 return vic;
3216 }
3217 return 0;
3218}
3219
3220static bool drm_valid_hdmi_vic(u8 vic)
3221{
3222 return vic > 0 && vic < ARRAY_SIZE(edid_4k_modes);
3223}
3224
3225static int
3226add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
3227{
3228 struct drm_device *dev = connector->dev;
3229 struct drm_display_mode *mode, *tmp;
3230 LIST_HEAD(list);
3231 int modes = 0;
3232
3233 /* Don't add CEA modes if the CEA extension block is missing */
3234 if (!drm_find_cea_extension(edid))
3235 return 0;
3236
3237 /*
3238 * Go through all probed modes and create a new mode
3239 * with the alternate clock for certain CEA modes.
3240 */
3241 list_for_each_entry(mode, &connector->probed_modes, head) {
3242 const struct drm_display_mode *cea_mode = NULL;
3243 struct drm_display_mode *newmode;
3244 u8 vic = drm_match_cea_mode(mode);
3245 unsigned int clock1, clock2;
3246
3247 if (drm_valid_cea_vic(vic)) {
3248 cea_mode = &edid_cea_modes[vic];
3249 clock2 = cea_mode_alternate_clock(cea_mode);
3250 } else {
3251 vic = drm_match_hdmi_mode(mode);
3252 if (drm_valid_hdmi_vic(vic)) {
3253 cea_mode = &edid_4k_modes[vic];
3254 clock2 = hdmi_mode_alternate_clock(cea_mode);
3255 }
3256 }
3257
3258 if (!cea_mode)
3259 continue;
3260
3261 clock1 = cea_mode->clock;
3262
3263 if (clock1 == clock2)
3264 continue;
3265
3266 if (mode->clock != clock1 && mode->clock != clock2)
3267 continue;
3268
3269 newmode = drm_mode_duplicate(dev, cea_mode);
3270 if (!newmode)
3271 continue;
3272
3273 /* Carry over the stereo flags */
3274 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
3275
3276 /*
3277 * The current mode could be either variant. Make
3278 * sure to pick the "other" clock for the new mode.
3279 */
3280 if (mode->clock != clock1)
3281 newmode->clock = clock1;
3282 else
3283 newmode->clock = clock2;
3284
3285 list_add_tail(&newmode->head, &list);
3286 }
3287
3288 list_for_each_entry_safe(mode, tmp, &list, head) {
3289 list_del(&mode->head);
3290 drm_mode_probed_add(connector, mode);
3291 modes++;
3292 }
3293
3294 return modes;
3295}
3296
3297static u8 svd_to_vic(u8 svd)
3298{
3299 /* 0-6 bit vic, 7th bit native mode indicator */
3300 if ((svd >= 1 && svd <= 64) || (svd >= 129 && svd <= 192))
3301 return svd & 127;
3302
3303 return svd;
3304}
3305
3306static struct drm_display_mode *
3307drm_display_mode_from_vic_index(struct drm_connector *connector,
3308 const u8 *video_db, u8 video_len,
3309 u8 video_index)
3310{
3311 struct drm_device *dev = connector->dev;
3312 struct drm_display_mode *newmode;
3313 u8 vic;
3314
3315 if (video_db == NULL || video_index >= video_len)
3316 return NULL;
3317
3318 /* CEA modes are numbered 1..127 */
3319 vic = svd_to_vic(video_db[video_index]);
3320 if (!drm_valid_cea_vic(vic))
3321 return NULL;
3322
3323 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3324 if (!newmode)
3325 return NULL;
3326
3327 newmode->vrefresh = 0;
3328
3329 return newmode;
3330}
3331
3332/*
3333 * do_y420vdb_modes - Parse YCBCR 420 only modes
3334 * @connector: connector corresponding to the HDMI sink
3335 * @svds: start of the data block of CEA YCBCR 420 VDB
3336 * @len: length of the CEA YCBCR 420 VDB
3337 *
3338 * Parse the CEA-861-F YCBCR 420 Video Data Block (Y420VDB)
3339 * which contains modes which can be supported in YCBCR 420
3340 * output format only.
3341 */
3342static int do_y420vdb_modes(struct drm_connector *connector,
3343 const u8 *svds, u8 svds_len)
3344{
3345 int modes = 0, i;
3346 struct drm_device *dev = connector->dev;
3347 struct drm_display_info *info = &connector->display_info;
3348 struct drm_hdmi_info *hdmi = &info->hdmi;
3349
3350 for (i = 0; i < svds_len; i++) {
3351 u8 vic = svd_to_vic(svds[i]);
3352 struct drm_display_mode *newmode;
3353
3354 if (!drm_valid_cea_vic(vic))
3355 continue;
3356
3357 newmode = drm_mode_duplicate(dev, &edid_cea_modes[vic]);
3358 if (!newmode)
3359 break;
3360 bitmap_set(hdmi->y420_vdb_modes, vic, 1);
3361 drm_mode_probed_add(connector, newmode);
3362 modes++;
3363 }
3364
3365 if (modes > 0)
3366 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3367 return modes;
3368}
3369
3370/*
3371 * drm_add_cmdb_modes - Add a YCBCR 420 mode into bitmap
3372 * @connector: connector corresponding to the HDMI sink
3373 * @vic: CEA vic for the video mode to be added in the map
3374 *
3375 * Makes an entry for a videomode in the YCBCR 420 bitmap
3376 */
3377static void
3378drm_add_cmdb_modes(struct drm_connector *connector, u8 svd)
3379{
3380 u8 vic = svd_to_vic(svd);
3381 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3382
3383 if (!drm_valid_cea_vic(vic))
3384 return;
3385
3386 bitmap_set(hdmi->y420_cmdb_modes, vic, 1);
3387}
3388
3389static int
3390do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
3391{
3392 int i, modes = 0;
3393 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
3394
3395 for (i = 0; i < len; i++) {
3396 struct drm_display_mode *mode;
3397 mode = drm_display_mode_from_vic_index(connector, db, len, i);
3398 if (mode) {
3399 /*
3400 * YCBCR420 capability block contains a bitmap which
3401 * gives the index of CEA modes from CEA VDB, which
3402 * can support YCBCR 420 sampling output also (apart
3403 * from RGB/YCBCR444 etc).
3404 * For example, if the bit 0 in bitmap is set,
3405 * first mode in VDB can support YCBCR420 output too.
3406 * Add YCBCR420 modes only if sink is HDMI 2.0 capable.
3407 */
3408 if (i < 64 && hdmi->y420_cmdb_map & (1ULL << i))
3409 drm_add_cmdb_modes(connector, db[i]);
3410
3411 drm_mode_probed_add(connector, mode);
3412 modes++;
3413 }
3414 }
3415
3416 return modes;
3417}
3418
3419struct stereo_mandatory_mode {
3420 int width, height, vrefresh;
3421 unsigned int flags;
3422};
3423
3424static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
3425 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3426 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
3427 { 1920, 1080, 50,
3428 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3429 { 1920, 1080, 60,
3430 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
3431 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3432 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
3433 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
3434 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
3435};
3436
3437static bool
3438stereo_match_mandatory(const struct drm_display_mode *mode,
3439 const struct stereo_mandatory_mode *stereo_mode)
3440{
3441 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
3442
3443 return mode->hdisplay == stereo_mode->width &&
3444 mode->vdisplay == stereo_mode->height &&
3445 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
3446 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
3447}
3448
3449static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
3450{
3451 struct drm_device *dev = connector->dev;
3452 const struct drm_display_mode *mode;
3453 struct list_head stereo_modes;
3454 int modes = 0, i;
3455
3456 INIT_LIST_HEAD(&stereo_modes);
3457
3458 list_for_each_entry(mode, &connector->probed_modes, head) {
3459 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
3460 const struct stereo_mandatory_mode *mandatory;
3461 struct drm_display_mode *new_mode;
3462
3463 if (!stereo_match_mandatory(mode,
3464 &stereo_mandatory_modes[i]))
3465 continue;
3466
3467 mandatory = &stereo_mandatory_modes[i];
3468 new_mode = drm_mode_duplicate(dev, mode);
3469 if (!new_mode)
3470 continue;
3471
3472 new_mode->flags |= mandatory->flags;
3473 list_add_tail(&new_mode->head, &stereo_modes);
3474 modes++;
3475 }
3476 }
3477
3478 list_splice_tail(&stereo_modes, &connector->probed_modes);
3479
3480 return modes;
3481}
3482
3483static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
3484{
3485 struct drm_device *dev = connector->dev;
3486 struct drm_display_mode *newmode;
3487
3488 if (!drm_valid_hdmi_vic(vic)) {
3489 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
3490 return 0;
3491 }
3492
3493 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
3494 if (!newmode)
3495 return 0;
3496
3497 drm_mode_probed_add(connector, newmode);
3498
3499 return 1;
3500}
3501
3502static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
3503 const u8 *video_db, u8 video_len, u8 video_index)
3504{
3505 struct drm_display_mode *newmode;
3506 int modes = 0;
3507
3508 if (structure & (1 << 0)) {
3509 newmode = drm_display_mode_from_vic_index(connector, video_db,
3510 video_len,
3511 video_index);
3512 if (newmode) {
3513 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
3514 drm_mode_probed_add(connector, newmode);
3515 modes++;
3516 }
3517 }
3518 if (structure & (1 << 6)) {
3519 newmode = drm_display_mode_from_vic_index(connector, video_db,
3520 video_len,
3521 video_index);
3522 if (newmode) {
3523 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3524 drm_mode_probed_add(connector, newmode);
3525 modes++;
3526 }
3527 }
3528 if (structure & (1 << 8)) {
3529 newmode = drm_display_mode_from_vic_index(connector, video_db,
3530 video_len,
3531 video_index);
3532 if (newmode) {
3533 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3534 drm_mode_probed_add(connector, newmode);
3535 modes++;
3536 }
3537 }
3538
3539 return modes;
3540}
3541
3542/*
3543 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
3544 * @connector: connector corresponding to the HDMI sink
3545 * @db: start of the CEA vendor specific block
3546 * @len: length of the CEA block payload, ie. one can access up to db[len]
3547 *
3548 * Parses the HDMI VSDB looking for modes to add to @connector. This function
3549 * also adds the stereo 3d modes when applicable.
3550 */
3551static int
3552do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
3553 const u8 *video_db, u8 video_len)
3554{
3555 struct drm_display_info *info = &connector->display_info;
3556 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
3557 u8 vic_len, hdmi_3d_len = 0;
3558 u16 mask;
3559 u16 structure_all;
3560
3561 if (len < 8)
3562 goto out;
3563
3564 /* no HDMI_Video_Present */
3565 if (!(db[8] & (1 << 5)))
3566 goto out;
3567
3568 /* Latency_Fields_Present */
3569 if (db[8] & (1 << 7))
3570 offset += 2;
3571
3572 /* I_Latency_Fields_Present */
3573 if (db[8] & (1 << 6))
3574 offset += 2;
3575
3576 /* the declared length is not long enough for the 2 first bytes
3577 * of additional video format capabilities */
3578 if (len < (8 + offset + 2))
3579 goto out;
3580
3581 /* 3D_Present */
3582 offset++;
3583 if (db[8 + offset] & (1 << 7)) {
3584 modes += add_hdmi_mandatory_stereo_modes(connector);
3585
3586 /* 3D_Multi_present */
3587 multi_present = (db[8 + offset] & 0x60) >> 5;
3588 }
3589
3590 offset++;
3591 vic_len = db[8 + offset] >> 5;
3592 hdmi_3d_len = db[8 + offset] & 0x1f;
3593
3594 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
3595 u8 vic;
3596
3597 vic = db[9 + offset + i];
3598 modes += add_hdmi_mode(connector, vic);
3599 }
3600 offset += 1 + vic_len;
3601
3602 if (multi_present == 1)
3603 multi_len = 2;
3604 else if (multi_present == 2)
3605 multi_len = 4;
3606 else
3607 multi_len = 0;
3608
3609 if (len < (8 + offset + hdmi_3d_len - 1))
3610 goto out;
3611
3612 if (hdmi_3d_len < multi_len)
3613 goto out;
3614
3615 if (multi_present == 1 || multi_present == 2) {
3616 /* 3D_Structure_ALL */
3617 structure_all = (db[8 + offset] << 8) | db[9 + offset];
3618
3619 /* check if 3D_MASK is present */
3620 if (multi_present == 2)
3621 mask = (db[10 + offset] << 8) | db[11 + offset];
3622 else
3623 mask = 0xffff;
3624
3625 for (i = 0; i < 16; i++) {
3626 if (mask & (1 << i))
3627 modes += add_3d_struct_modes(connector,
3628 structure_all,
3629 video_db,
3630 video_len, i);
3631 }
3632 }
3633
3634 offset += multi_len;
3635
3636 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
3637 int vic_index;
3638 struct drm_display_mode *newmode = NULL;
3639 unsigned int newflag = 0;
3640 bool detail_present;
3641
3642 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
3643
3644 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
3645 break;
3646
3647 /* 2D_VIC_order_X */
3648 vic_index = db[8 + offset + i] >> 4;
3649
3650 /* 3D_Structure_X */
3651 switch (db[8 + offset + i] & 0x0f) {
3652 case 0:
3653 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
3654 break;
3655 case 6:
3656 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
3657 break;
3658 case 8:
3659 /* 3D_Detail_X */
3660 if ((db[9 + offset + i] >> 4) == 1)
3661 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
3662 break;
3663 }
3664
3665 if (newflag != 0) {
3666 newmode = drm_display_mode_from_vic_index(connector,
3667 video_db,
3668 video_len,
3669 vic_index);
3670
3671 if (newmode) {
3672 newmode->flags |= newflag;
3673 drm_mode_probed_add(connector, newmode);
3674 modes++;
3675 }
3676 }
3677
3678 if (detail_present)
3679 i++;
3680 }
3681
3682out:
3683 if (modes > 0)
3684 info->has_hdmi_infoframe = true;
3685 return modes;
3686}
3687
3688static int
3689cea_db_payload_len(const u8 *db)
3690{
3691 return db[0] & 0x1f;
3692}
3693
3694static int
3695cea_db_extended_tag(const u8 *db)
3696{
3697 return db[1];
3698}
3699
3700static int
3701cea_db_tag(const u8 *db)
3702{
3703 return db[0] >> 5;
3704}
3705
3706static int
3707cea_revision(const u8 *cea)
3708{
3709 return cea[1];
3710}
3711
3712static int
3713cea_db_offsets(const u8 *cea, int *start, int *end)
3714{
3715 /* DisplayID CTA extension blocks and top-level CEA EDID
3716 * block header definitions differ in the following bytes:
3717 * 1) Byte 2 of the header specifies length differently,
3718 * 2) Byte 3 is only present in the CEA top level block.
3719 *
3720 * The different definitions for byte 2 follow.
3721 *
3722 * DisplayID CTA extension block defines byte 2 as:
3723 * Number of payload bytes
3724 *
3725 * CEA EDID block defines byte 2 as:
3726 * Byte number (decimal) within this block where the 18-byte
3727 * DTDs begin. If no non-DTD data is present in this extension
3728 * block, the value should be set to 04h (the byte after next).
3729 * If set to 00h, there are no DTDs present in this block and
3730 * no non-DTD data.
3731 */
3732 if (cea[0] == DATA_BLOCK_CTA) {
3733 *start = 3;
3734 *end = *start + cea[2];
3735 } else if (cea[0] == CEA_EXT) {
3736 /* Data block offset in CEA extension block */
3737 *start = 4;
3738 *end = cea[2];
3739 if (*end == 0)
3740 *end = 127;
3741 if (*end < 4 || *end > 127)
3742 return -ERANGE;
3743 } else {
3744 return -EOPNOTSUPP;
3745 }
3746
3747 return 0;
3748}
3749
3750static bool cea_db_is_hdmi_vsdb(const u8 *db)
3751{
3752 int hdmi_id;
3753
3754 if (cea_db_tag(db) != VENDOR_BLOCK)
3755 return false;
3756
3757 if (cea_db_payload_len(db) < 5)
3758 return false;
3759
3760 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
3761
3762 return hdmi_id == HDMI_IEEE_OUI;
3763}
3764
3765static bool cea_db_is_hdmi_forum_vsdb(const u8 *db)
3766{
3767 unsigned int oui;
3768
3769 if (cea_db_tag(db) != VENDOR_BLOCK)
3770 return false;
3771
3772 if (cea_db_payload_len(db) < 7)
3773 return false;
3774
3775 oui = db[3] << 16 | db[2] << 8 | db[1];
3776
3777 return oui == HDMI_FORUM_IEEE_OUI;
3778}
3779
3780static bool cea_db_is_vcdb(const u8 *db)
3781{
3782 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3783 return false;
3784
3785 if (cea_db_payload_len(db) != 2)
3786 return false;
3787
3788 if (cea_db_extended_tag(db) != EXT_VIDEO_CAPABILITY_BLOCK)
3789 return false;
3790
3791 return true;
3792}
3793
3794static bool cea_db_is_y420cmdb(const u8 *db)
3795{
3796 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3797 return false;
3798
3799 if (!cea_db_payload_len(db))
3800 return false;
3801
3802 if (cea_db_extended_tag(db) != EXT_VIDEO_CAP_BLOCK_Y420CMDB)
3803 return false;
3804
3805 return true;
3806}
3807
3808static bool cea_db_is_y420vdb(const u8 *db)
3809{
3810 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3811 return false;
3812
3813 if (!cea_db_payload_len(db))
3814 return false;
3815
3816 if (cea_db_extended_tag(db) != EXT_VIDEO_DATA_BLOCK_420)
3817 return false;
3818
3819 return true;
3820}
3821
3822#define for_each_cea_db(cea, i, start, end) \
3823 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
3824
3825static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector,
3826 const u8 *db)
3827{
3828 struct drm_display_info *info = &connector->display_info;
3829 struct drm_hdmi_info *hdmi = &info->hdmi;
3830 u8 map_len = cea_db_payload_len(db) - 1;
3831 u8 count;
3832 u64 map = 0;
3833
3834 if (map_len == 0) {
3835 /* All CEA modes support ycbcr420 sampling also.*/
3836 hdmi->y420_cmdb_map = U64_MAX;
3837 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3838 return;
3839 }
3840
3841 /*
3842 * This map indicates which of the existing CEA block modes
3843 * from VDB can support YCBCR420 output too. So if bit=0 is
3844 * set, first mode from VDB can support YCBCR420 output too.
3845 * We will parse and keep this map, before parsing VDB itself
3846 * to avoid going through the same block again and again.
3847 *
3848 * Spec is not clear about max possible size of this block.
3849 * Clamping max bitmap block size at 8 bytes. Every byte can
3850 * address 8 CEA modes, in this way this map can address
3851 * 8*8 = first 64 SVDs.
3852 */
3853 if (WARN_ON_ONCE(map_len > 8))
3854 map_len = 8;
3855
3856 for (count = 0; count < map_len; count++)
3857 map |= (u64)db[2 + count] << (8 * count);
3858
3859 if (map)
3860 info->color_formats |= DRM_COLOR_FORMAT_YCRCB420;
3861
3862 hdmi->y420_cmdb_map = map;
3863}
3864
3865static int
3866add_cea_modes(struct drm_connector *connector, struct edid *edid)
3867{
3868 const u8 *cea = drm_find_cea_extension(edid);
3869 const u8 *db, *hdmi = NULL, *video = NULL;
3870 u8 dbl, hdmi_len, video_len = 0;
3871 int modes = 0;
3872
3873 if (cea && cea_revision(cea) >= 3) {
3874 int i, start, end;
3875
3876 if (cea_db_offsets(cea, &start, &end))
3877 return 0;
3878
3879 for_each_cea_db(cea, i, start, end) {
3880 db = &cea[i];
3881 dbl = cea_db_payload_len(db);
3882
3883 if (cea_db_tag(db) == VIDEO_BLOCK) {
3884 video = db + 1;
3885 video_len = dbl;
3886 modes += do_cea_modes(connector, video, dbl);
3887 } else if (cea_db_is_hdmi_vsdb(db)) {
3888 hdmi = db;
3889 hdmi_len = dbl;
3890 } else if (cea_db_is_y420vdb(db)) {
3891 const u8 *vdb420 = &db[2];
3892
3893 /* Add 4:2:0(only) modes present in EDID */
3894 modes += do_y420vdb_modes(connector,
3895 vdb420,
3896 dbl - 1);
3897 }
3898 }
3899 }
3900
3901 /*
3902 * We parse the HDMI VSDB after having added the cea modes as we will
3903 * be patching their flags when the sink supports stereo 3D.
3904 */
3905 if (hdmi)
3906 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3907 video_len);
3908
3909 return modes;
3910}
3911
3912static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
3913{
3914 const struct drm_display_mode *cea_mode;
3915 int clock1, clock2, clock;
3916 u8 vic;
3917 const char *type;
3918
3919 /*
3920 * allow 5kHz clock difference either way to account for
3921 * the 10kHz clock resolution limit of detailed timings.
3922 */
3923 vic = drm_match_cea_mode_clock_tolerance(mode, 5);
3924 if (drm_valid_cea_vic(vic)) {
3925 type = "CEA";
3926 cea_mode = &edid_cea_modes[vic];
3927 clock1 = cea_mode->clock;
3928 clock2 = cea_mode_alternate_clock(cea_mode);
3929 } else {
3930 vic = drm_match_hdmi_mode_clock_tolerance(mode, 5);
3931 if (drm_valid_hdmi_vic(vic)) {
3932 type = "HDMI";
3933 cea_mode = &edid_4k_modes[vic];
3934 clock1 = cea_mode->clock;
3935 clock2 = hdmi_mode_alternate_clock(cea_mode);
3936 } else {
3937 return;
3938 }
3939 }
3940
3941 /* pick whichever is closest */
3942 if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
3943 clock = clock1;
3944 else
3945 clock = clock2;
3946
3947 if (mode->clock == clock)
3948 return;
3949
3950 DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
3951 type, vic, mode->clock, clock);
3952 mode->clock = clock;
3953}
3954
3955static bool cea_db_is_hdmi_hdr_metadata_block(const u8 *db)
3956{
3957 if (cea_db_tag(db) != USE_EXTENDED_TAG)
3958 return false;
3959
3960 if (db[1] != HDR_STATIC_METADATA_BLOCK)
3961 return false;
3962
3963 if (cea_db_payload_len(db) < 3)
3964 return false;
3965
3966 return true;
3967}
3968
3969static uint8_t eotf_supported(const u8 *edid_ext)
3970{
3971 return edid_ext[2] &
3972 (BIT(HDMI_EOTF_TRADITIONAL_GAMMA_SDR) |
3973 BIT(HDMI_EOTF_TRADITIONAL_GAMMA_HDR) |
3974 BIT(HDMI_EOTF_SMPTE_ST2084) |
3975 BIT(HDMI_EOTF_BT_2100_HLG));
3976}
3977
3978static uint8_t hdr_metadata_type(const u8 *edid_ext)
3979{
3980 return edid_ext[3] &
3981 BIT(HDMI_STATIC_METADATA_TYPE1);
3982}
3983
3984static void
3985drm_parse_hdr_metadata_block(struct drm_connector *connector, const u8 *db)
3986{
3987 u16 len;
3988
3989 len = cea_db_payload_len(db);
3990
3991 connector->hdr_sink_metadata.hdmi_type1.eotf =
3992 eotf_supported(db);
3993 connector->hdr_sink_metadata.hdmi_type1.metadata_type =
3994 hdr_metadata_type(db);
3995
3996 if (len >= 4)
3997 connector->hdr_sink_metadata.hdmi_type1.max_cll = db[4];
3998 if (len >= 5)
3999 connector->hdr_sink_metadata.hdmi_type1.max_fall = db[5];
4000 if (len >= 6)
4001 connector->hdr_sink_metadata.hdmi_type1.min_cll = db[6];
4002}
4003
4004static void
4005drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
4006{
4007 u8 len = cea_db_payload_len(db);
4008
4009 if (len >= 6 && (db[6] & (1 << 7)))
4010 connector->eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_SUPPORTS_AI;
4011 if (len >= 8) {
4012 connector->latency_present[0] = db[8] >> 7;
4013 connector->latency_present[1] = (db[8] >> 6) & 1;
4014 }
4015 if (len >= 9)
4016 connector->video_latency[0] = db[9];
4017 if (len >= 10)
4018 connector->audio_latency[0] = db[10];
4019 if (len >= 11)
4020 connector->video_latency[1] = db[11];
4021 if (len >= 12)
4022 connector->audio_latency[1] = db[12];
4023
4024 DRM_DEBUG_KMS("HDMI: latency present %d %d, "
4025 "video latency %d %d, "
4026 "audio latency %d %d\n",
4027 connector->latency_present[0],
4028 connector->latency_present[1],
4029 connector->video_latency[0],
4030 connector->video_latency[1],
4031 connector->audio_latency[0],
4032 connector->audio_latency[1]);
4033}
4034
4035static void
4036monitor_name(struct detailed_timing *t, void *data)
4037{
4038 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
4039 *(u8 **)data = t->data.other_data.data.str.str;
4040}
4041
4042static int get_monitor_name(struct edid *edid, char name[13])
4043{
4044 char *edid_name = NULL;
4045 int mnl;
4046
4047 if (!edid || !name)
4048 return 0;
4049
4050 drm_for_each_detailed_block((u8 *)edid, monitor_name, &edid_name);
4051 for (mnl = 0; edid_name && mnl < 13; mnl++) {
4052 if (edid_name[mnl] == 0x0a)
4053 break;
4054
4055 name[mnl] = edid_name[mnl];
4056 }
4057
4058 return mnl;
4059}
4060
4061/**
4062 * drm_edid_get_monitor_name - fetch the monitor name from the edid
4063 * @edid: monitor EDID information
4064 * @name: pointer to a character array to hold the name of the monitor
4065 * @bufsize: The size of the name buffer (should be at least 14 chars.)
4066 *
4067 */
4068void drm_edid_get_monitor_name(struct edid *edid, char *name, int bufsize)
4069{
4070 int name_length;
4071 char buf[13];
4072
4073 if (bufsize <= 0)
4074 return;
4075
4076 name_length = min(get_monitor_name(edid, buf), bufsize - 1);
4077 memcpy(name, buf, name_length);
4078 name[name_length] = '\0';
4079}
4080EXPORT_SYMBOL(drm_edid_get_monitor_name);
4081
4082static void clear_eld(struct drm_connector *connector)
4083{
4084 memset(connector->eld, 0, sizeof(connector->eld));
4085
4086 connector->latency_present[0] = false;
4087 connector->latency_present[1] = false;
4088 connector->video_latency[0] = 0;
4089 connector->audio_latency[0] = 0;
4090 connector->video_latency[1] = 0;
4091 connector->audio_latency[1] = 0;
4092}
4093
4094/*
4095 * drm_edid_to_eld - build ELD from EDID
4096 * @connector: connector corresponding to the HDMI/DP sink
4097 * @edid: EDID to parse
4098 *
4099 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
4100 * HDCP and Port_ID ELD fields are left for the graphics driver to fill in.
4101 */
4102static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
4103{
4104 uint8_t *eld = connector->eld;
4105 u8 *cea;
4106 u8 *db;
4107 int total_sad_count = 0;
4108 int mnl;
4109 int dbl;
4110
4111 clear_eld(connector);
4112
4113 if (!edid)
4114 return;
4115
4116 cea = drm_find_cea_extension(edid);
4117 if (!cea) {
4118 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
4119 return;
4120 }
4121
4122 mnl = get_monitor_name(edid, &eld[DRM_ELD_MONITOR_NAME_STRING]);
4123 DRM_DEBUG_KMS("ELD monitor %s\n", &eld[DRM_ELD_MONITOR_NAME_STRING]);
4124
4125 eld[DRM_ELD_CEA_EDID_VER_MNL] = cea[1] << DRM_ELD_CEA_EDID_VER_SHIFT;
4126 eld[DRM_ELD_CEA_EDID_VER_MNL] |= mnl;
4127
4128 eld[DRM_ELD_VER] = DRM_ELD_VER_CEA861D;
4129
4130 eld[DRM_ELD_MANUFACTURER_NAME0] = edid->mfg_id[0];
4131 eld[DRM_ELD_MANUFACTURER_NAME1] = edid->mfg_id[1];
4132 eld[DRM_ELD_PRODUCT_CODE0] = edid->prod_code[0];
4133 eld[DRM_ELD_PRODUCT_CODE1] = edid->prod_code[1];
4134
4135 if (cea_revision(cea) >= 3) {
4136 int i, start, end;
4137
4138 if (cea_db_offsets(cea, &start, &end)) {
4139 start = 0;
4140 end = 0;
4141 }
4142
4143 for_each_cea_db(cea, i, start, end) {
4144 db = &cea[i];
4145 dbl = cea_db_payload_len(db);
4146
4147 switch (cea_db_tag(db)) {
4148 int sad_count;
4149
4150 case AUDIO_BLOCK:
4151 /* Audio Data Block, contains SADs */
4152 sad_count = min(dbl / 3, 15 - total_sad_count);
4153 if (sad_count >= 1)
4154 memcpy(&eld[DRM_ELD_CEA_SAD(mnl, total_sad_count)],
4155 &db[1], sad_count * 3);
4156 total_sad_count += sad_count;
4157 break;
4158 case SPEAKER_BLOCK:
4159 /* Speaker Allocation Data Block */
4160 if (dbl >= 1)
4161 eld[DRM_ELD_SPEAKER] = db[1];
4162 break;
4163 case VENDOR_BLOCK:
4164 /* HDMI Vendor-Specific Data Block */
4165 if (cea_db_is_hdmi_vsdb(db))
4166 drm_parse_hdmi_vsdb_audio(connector, db);
4167 break;
4168 default:
4169 break;
4170 }
4171 }
4172 }
4173 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= total_sad_count << DRM_ELD_SAD_COUNT_SHIFT;
4174
4175 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4176 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4177 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_DP;
4178 else
4179 eld[DRM_ELD_SAD_COUNT_CONN_TYPE] |= DRM_ELD_CONN_TYPE_HDMI;
4180
4181 eld[DRM_ELD_BASELINE_ELD_LEN] =
4182 DIV_ROUND_UP(drm_eld_calc_baseline_block_size(eld), 4);
4183
4184 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n",
4185 drm_eld_size(eld), total_sad_count);
4186}
4187
4188/**
4189 * drm_edid_to_sad - extracts SADs from EDID
4190 * @edid: EDID to parse
4191 * @sads: pointer that will be set to the extracted SADs
4192 *
4193 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
4194 *
4195 * Note: The returned pointer needs to be freed using kfree().
4196 *
4197 * Return: The number of found SADs or negative number on error.
4198 */
4199int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
4200{
4201 int count = 0;
4202 int i, start, end, dbl;
4203 u8 *cea;
4204
4205 cea = drm_find_cea_extension(edid);
4206 if (!cea) {
4207 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4208 return -ENOENT;
4209 }
4210
4211 if (cea_revision(cea) < 3) {
4212 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4213 return -EOPNOTSUPP;
4214 }
4215
4216 if (cea_db_offsets(cea, &start, &end)) {
4217 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4218 return -EPROTO;
4219 }
4220
4221 for_each_cea_db(cea, i, start, end) {
4222 u8 *db = &cea[i];
4223
4224 if (cea_db_tag(db) == AUDIO_BLOCK) {
4225 int j;
4226 dbl = cea_db_payload_len(db);
4227
4228 count = dbl / 3; /* SAD is 3B */
4229 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
4230 if (!*sads)
4231 return -ENOMEM;
4232 for (j = 0; j < count; j++) {
4233 u8 *sad = &db[1 + j * 3];
4234
4235 (*sads)[j].format = (sad[0] & 0x78) >> 3;
4236 (*sads)[j].channels = sad[0] & 0x7;
4237 (*sads)[j].freq = sad[1] & 0x7F;
4238 (*sads)[j].byte2 = sad[2];
4239 }
4240 break;
4241 }
4242 }
4243
4244 return count;
4245}
4246EXPORT_SYMBOL(drm_edid_to_sad);
4247
4248/**
4249 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
4250 * @edid: EDID to parse
4251 * @sadb: pointer to the speaker block
4252 *
4253 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
4254 *
4255 * Note: The returned pointer needs to be freed using kfree().
4256 *
4257 * Return: The number of found Speaker Allocation Blocks or negative number on
4258 * error.
4259 */
4260int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
4261{
4262 int count = 0;
4263 int i, start, end, dbl;
4264 const u8 *cea;
4265
4266 cea = drm_find_cea_extension(edid);
4267 if (!cea) {
4268 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
4269 return -ENOENT;
4270 }
4271
4272 if (cea_revision(cea) < 3) {
4273 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
4274 return -EOPNOTSUPP;
4275 }
4276
4277 if (cea_db_offsets(cea, &start, &end)) {
4278 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
4279 return -EPROTO;
4280 }
4281
4282 for_each_cea_db(cea, i, start, end) {
4283 const u8 *db = &cea[i];
4284
4285 if (cea_db_tag(db) == SPEAKER_BLOCK) {
4286 dbl = cea_db_payload_len(db);
4287
4288 /* Speaker Allocation Data Block */
4289 if (dbl == 3) {
4290 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
4291 if (!*sadb)
4292 return -ENOMEM;
4293 count = dbl;
4294 break;
4295 }
4296 }
4297 }
4298
4299 return count;
4300}
4301EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
4302
4303/**
4304 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
4305 * @connector: connector associated with the HDMI/DP sink
4306 * @mode: the display mode
4307 *
4308 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
4309 * the sink doesn't support audio or video.
4310 */
4311int drm_av_sync_delay(struct drm_connector *connector,
4312 const struct drm_display_mode *mode)
4313{
4314 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
4315 int a, v;
4316
4317 if (!connector->latency_present[0])
4318 return 0;
4319 if (!connector->latency_present[1])
4320 i = 0;
4321
4322 a = connector->audio_latency[i];
4323 v = connector->video_latency[i];
4324
4325 /*
4326 * HDMI/DP sink doesn't support audio or video?
4327 */
4328 if (a == 255 || v == 255)
4329 return 0;
4330
4331 /*
4332 * Convert raw EDID values to millisecond.
4333 * Treat unknown latency as 0ms.
4334 */
4335 if (a)
4336 a = min(2 * (a - 1), 500);
4337 if (v)
4338 v = min(2 * (v - 1), 500);
4339
4340 return max(v - a, 0);
4341}
4342EXPORT_SYMBOL(drm_av_sync_delay);
4343
4344/**
4345 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
4346 * @edid: monitor EDID information
4347 *
4348 * Parse the CEA extension according to CEA-861-B.
4349 *
4350 * Return: True if the monitor is HDMI, false if not or unknown.
4351 */
4352bool drm_detect_hdmi_monitor(struct edid *edid)
4353{
4354 u8 *edid_ext;
4355 int i;
4356 int start_offset, end_offset;
4357
4358 edid_ext = drm_find_cea_extension(edid);
4359 if (!edid_ext)
4360 return false;
4361
4362 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4363 return false;
4364
4365 /*
4366 * Because HDMI identifier is in Vendor Specific Block,
4367 * search it from all data blocks of CEA extension.
4368 */
4369 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4370 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
4371 return true;
4372 }
4373
4374 return false;
4375}
4376EXPORT_SYMBOL(drm_detect_hdmi_monitor);
4377
4378/**
4379 * drm_detect_monitor_audio - check monitor audio capability
4380 * @edid: EDID block to scan
4381 *
4382 * Monitor should have CEA extension block.
4383 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
4384 * audio' only. If there is any audio extension block and supported
4385 * audio format, assume at least 'basic audio' support, even if 'basic
4386 * audio' is not defined in EDID.
4387 *
4388 * Return: True if the monitor supports audio, false otherwise.
4389 */
4390bool drm_detect_monitor_audio(struct edid *edid)
4391{
4392 u8 *edid_ext;
4393 int i, j;
4394 bool has_audio = false;
4395 int start_offset, end_offset;
4396
4397 edid_ext = drm_find_cea_extension(edid);
4398 if (!edid_ext)
4399 goto end;
4400
4401 has_audio = (edid_ext[0] == CEA_EXT &&
4402 (edid_ext[3] & EDID_BASIC_AUDIO) != 0);
4403
4404 if (has_audio) {
4405 DRM_DEBUG_KMS("Monitor has basic audio support\n");
4406 goto end;
4407 }
4408
4409 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
4410 goto end;
4411
4412 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
4413 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
4414 has_audio = true;
4415 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
4416 DRM_DEBUG_KMS("CEA audio format %d\n",
4417 (edid_ext[i + j] >> 3) & 0xf);
4418 goto end;
4419 }
4420 }
4421end:
4422 return has_audio;
4423}
4424EXPORT_SYMBOL(drm_detect_monitor_audio);
4425
4426
4427/**
4428 * drm_default_rgb_quant_range - default RGB quantization range
4429 * @mode: display mode
4430 *
4431 * Determine the default RGB quantization range for the mode,
4432 * as specified in CEA-861.
4433 *
4434 * Return: The default RGB quantization range for the mode
4435 */
4436enum hdmi_quantization_range
4437drm_default_rgb_quant_range(const struct drm_display_mode *mode)
4438{
4439 /* All CEA modes other than VIC 1 use limited quantization range. */
4440 return drm_match_cea_mode(mode) > 1 ?
4441 HDMI_QUANTIZATION_RANGE_LIMITED :
4442 HDMI_QUANTIZATION_RANGE_FULL;
4443}
4444EXPORT_SYMBOL(drm_default_rgb_quant_range);
4445
4446static void drm_parse_vcdb(struct drm_connector *connector, const u8 *db)
4447{
4448 struct drm_display_info *info = &connector->display_info;
4449
4450 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", db[2]);
4451
4452 if (db[2] & EDID_CEA_VCDB_QS)
4453 info->rgb_quant_range_selectable = true;
4454}
4455
4456static void drm_parse_ycbcr420_deep_color_info(struct drm_connector *connector,
4457 const u8 *db)
4458{
4459 u8 dc_mask;
4460 struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
4461
4462 dc_mask = db[7] & DRM_EDID_YCBCR420_DC_MASK;
4463 hdmi->y420_dc_modes = dc_mask;
4464}
4465
4466static void drm_parse_hdmi_forum_vsdb(struct drm_connector *connector,
4467 const u8 *hf_vsdb)
4468{
4469 struct drm_display_info *display = &connector->display_info;
4470 struct drm_hdmi_info *hdmi = &display->hdmi;
4471
4472 display->has_hdmi_infoframe = true;
4473
4474 if (hf_vsdb[6] & 0x80) {
4475 hdmi->scdc.supported = true;
4476 if (hf_vsdb[6] & 0x40)
4477 hdmi->scdc.read_request = true;
4478 }
4479
4480 /*
4481 * All HDMI 2.0 monitors must support scrambling at rates > 340 MHz.
4482 * And as per the spec, three factors confirm this:
4483 * * Availability of a HF-VSDB block in EDID (check)
4484 * * Non zero Max_TMDS_Char_Rate filed in HF-VSDB (let's check)
4485 * * SCDC support available (let's check)
4486 * Lets check it out.
4487 */
4488
4489 if (hf_vsdb[5]) {
4490 /* max clock is 5000 KHz times block value */
4491 u32 max_tmds_clock = hf_vsdb[5] * 5000;
4492 struct drm_scdc *scdc = &hdmi->scdc;
4493
4494 if (max_tmds_clock > 340000) {
4495 display->max_tmds_clock = max_tmds_clock;
4496 DRM_DEBUG_KMS("HF-VSDB: max TMDS clock %d kHz\n",
4497 display->max_tmds_clock);
4498 }
4499
4500 if (scdc->supported) {
4501 scdc->scrambling.supported = true;
4502
4503 /* Few sinks support scrambling for cloks < 340M */
4504 if ((hf_vsdb[6] & 0x8))
4505 scdc->scrambling.low_rates = true;
4506 }
4507 }
4508
4509 drm_parse_ycbcr420_deep_color_info(connector, hf_vsdb);
4510}
4511
4512static void drm_parse_hdmi_deep_color_info(struct drm_connector *connector,
4513 const u8 *hdmi)
4514{
4515 struct drm_display_info *info = &connector->display_info;
4516 unsigned int dc_bpc = 0;
4517
4518 /* HDMI supports at least 8 bpc */
4519 info->bpc = 8;
4520
4521 if (cea_db_payload_len(hdmi) < 6)
4522 return;
4523
4524 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
4525 dc_bpc = 10;
4526 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
4527 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
4528 connector->name);
4529 }
4530
4531 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
4532 dc_bpc = 12;
4533 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
4534 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
4535 connector->name);
4536 }
4537
4538 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
4539 dc_bpc = 16;
4540 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
4541 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
4542 connector->name);
4543 }
4544
4545 if (dc_bpc == 0) {
4546 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
4547 connector->name);
4548 return;
4549 }
4550
4551 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
4552 connector->name, dc_bpc);
4553 info->bpc = dc_bpc;
4554
4555 /* YCRCB444 is optional according to spec. */
4556 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
4557 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
4558 connector->name);
4559 }
4560
4561 /*
4562 * Spec says that if any deep color mode is supported at all,
4563 * then deep color 36 bit must be supported.
4564 */
4565 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
4566 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
4567 connector->name);
4568 }
4569}
4570
4571static void
4572drm_parse_hdmi_vsdb_video(struct drm_connector *connector, const u8 *db)
4573{
4574 struct drm_display_info *info = &connector->display_info;
4575 u8 len = cea_db_payload_len(db);
4576
4577 if (len >= 6)
4578 info->dvi_dual = db[6] & 1;
4579 if (len >= 7)
4580 info->max_tmds_clock = db[7] * 5000;
4581
4582 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
4583 "max TMDS clock %d kHz\n",
4584 info->dvi_dual,
4585 info->max_tmds_clock);
4586
4587 drm_parse_hdmi_deep_color_info(connector, db);
4588}
4589
4590static void drm_parse_cea_ext(struct drm_connector *connector,
4591 const struct edid *edid)
4592{
4593 struct drm_display_info *info = &connector->display_info;
4594 const u8 *edid_ext;
4595 int i, start, end;
4596
4597 edid_ext = drm_find_cea_extension(edid);
4598 if (!edid_ext)
4599 return;
4600
4601 info->cea_rev = edid_ext[1];
4602
4603 /* The existence of a CEA block should imply RGB support */
4604 info->color_formats = DRM_COLOR_FORMAT_RGB444;
4605 if (edid_ext[3] & EDID_CEA_YCRCB444)
4606 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4607 if (edid_ext[3] & EDID_CEA_YCRCB422)
4608 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
4609
4610 if (cea_db_offsets(edid_ext, &start, &end))
4611 return;
4612
4613 for_each_cea_db(edid_ext, i, start, end) {
4614 const u8 *db = &edid_ext[i];
4615
4616 if (cea_db_is_hdmi_vsdb(db))
4617 drm_parse_hdmi_vsdb_video(connector, db);
4618 if (cea_db_is_hdmi_forum_vsdb(db))
4619 drm_parse_hdmi_forum_vsdb(connector, db);
4620 if (cea_db_is_y420cmdb(db))
4621 drm_parse_y420cmdb_bitmap(connector, db);
4622 if (cea_db_is_vcdb(db))
4623 drm_parse_vcdb(connector, db);
4624 if (cea_db_is_hdmi_hdr_metadata_block(db))
4625 drm_parse_hdr_metadata_block(connector, db);
4626 }
4627}
4628
4629/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset
4630 * all of the values which would have been set from EDID
4631 */
4632void
4633drm_reset_display_info(struct drm_connector *connector)
4634{
4635 struct drm_display_info *info = &connector->display_info;
4636
4637 info->width_mm = 0;
4638 info->height_mm = 0;
4639
4640 info->bpc = 0;
4641 info->color_formats = 0;
4642 info->cea_rev = 0;
4643 info->max_tmds_clock = 0;
4644 info->dvi_dual = false;
4645 info->has_hdmi_infoframe = false;
4646 info->rgb_quant_range_selectable = false;
4647 memset(&info->hdmi, 0, sizeof(info->hdmi));
4648
4649 info->non_desktop = 0;
4650}
4651
4652u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edid)
4653{
4654 struct drm_display_info *info = &connector->display_info;
4655
4656 u32 quirks = edid_get_quirks(edid);
4657
4658 drm_reset_display_info(connector);
4659
4660 info->width_mm = edid->width_cm * 10;
4661 info->height_mm = edid->height_cm * 10;
4662
4663 info->non_desktop = !!(quirks & EDID_QUIRK_NON_DESKTOP);
4664
4665 DRM_DEBUG_KMS("non_desktop set to %d\n", info->non_desktop);
4666
4667 if (edid->revision < 3)
4668 return quirks;
4669
4670 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
4671 return quirks;
4672
4673 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
4674 drm_parse_cea_ext(connector, edid);
4675
4676 /*
4677 * Digital sink with "DFP 1.x compliant TMDS" according to EDID 1.3?
4678 *
4679 * For such displays, the DFP spec 1.0, section 3.10 "EDID support"
4680 * tells us to assume 8 bpc color depth if the EDID doesn't have
4681 * extensions which tell otherwise.
4682 */
4683 if (info->bpc == 0 && edid->revision == 3 &&
4684 edid->input & DRM_EDID_DIGITAL_DFP_1_X) {
4685 info->bpc = 8;
4686 DRM_DEBUG("%s: Assigning DFP sink color depth as %d bpc.\n",
4687 connector->name, info->bpc);
4688 }
4689
4690 /* Only defined for 1.4 with digital displays */
4691 if (edid->revision < 4)
4692 return quirks;
4693
4694 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
4695 case DRM_EDID_DIGITAL_DEPTH_6:
4696 info->bpc = 6;
4697 break;
4698 case DRM_EDID_DIGITAL_DEPTH_8:
4699 info->bpc = 8;
4700 break;
4701 case DRM_EDID_DIGITAL_DEPTH_10:
4702 info->bpc = 10;
4703 break;
4704 case DRM_EDID_DIGITAL_DEPTH_12:
4705 info->bpc = 12;
4706 break;
4707 case DRM_EDID_DIGITAL_DEPTH_14:
4708 info->bpc = 14;
4709 break;
4710 case DRM_EDID_DIGITAL_DEPTH_16:
4711 info->bpc = 16;
4712 break;
4713 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
4714 default:
4715 info->bpc = 0;
4716 break;
4717 }
4718
4719 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
4720 connector->name, info->bpc);
4721
4722 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
4723 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
4724 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
4725 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
4726 return quirks;
4727}
4728
4729static int validate_displayid(u8 *displayid, int length, int idx)
4730{
4731 int i;
4732 u8 csum = 0;
4733 struct displayid_hdr *base;
4734
4735 base = (struct displayid_hdr *)&displayid[idx];
4736
4737 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
4738 base->rev, base->bytes, base->prod_id, base->ext_count);
4739
4740 if (base->bytes + 5 > length - idx)
4741 return -EINVAL;
4742 for (i = idx; i <= base->bytes + 5; i++) {
4743 csum += displayid[i];
4744 }
4745 if (csum) {
4746 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
4747 return -EINVAL;
4748 }
4749 return 0;
4750}
4751
4752static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
4753 struct displayid_detailed_timings_1 *timings)
4754{
4755 struct drm_display_mode *mode;
4756 unsigned pixel_clock = (timings->pixel_clock[0] |
4757 (timings->pixel_clock[1] << 8) |
4758 (timings->pixel_clock[2] << 16)) + 1;
4759 unsigned hactive = (timings->hactive[0] | timings->hactive[1] << 8) + 1;
4760 unsigned hblank = (timings->hblank[0] | timings->hblank[1] << 8) + 1;
4761 unsigned hsync = (timings->hsync[0] | (timings->hsync[1] & 0x7f) << 8) + 1;
4762 unsigned hsync_width = (timings->hsw[0] | timings->hsw[1] << 8) + 1;
4763 unsigned vactive = (timings->vactive[0] | timings->vactive[1] << 8) + 1;
4764 unsigned vblank = (timings->vblank[0] | timings->vblank[1] << 8) + 1;
4765 unsigned vsync = (timings->vsync[0] | (timings->vsync[1] & 0x7f) << 8) + 1;
4766 unsigned vsync_width = (timings->vsw[0] | timings->vsw[1] << 8) + 1;
4767 bool hsync_positive = (timings->hsync[1] >> 7) & 0x1;
4768 bool vsync_positive = (timings->vsync[1] >> 7) & 0x1;
4769 mode = drm_mode_create(dev);
4770 if (!mode)
4771 return NULL;
4772
4773 mode->clock = pixel_clock * 10;
4774 mode->hdisplay = hactive;
4775 mode->hsync_start = mode->hdisplay + hsync;
4776 mode->hsync_end = mode->hsync_start + hsync_width;
4777 mode->htotal = mode->hdisplay + hblank;
4778
4779 mode->vdisplay = vactive;
4780 mode->vsync_start = mode->vdisplay + vsync;
4781 mode->vsync_end = mode->vsync_start + vsync_width;
4782 mode->vtotal = mode->vdisplay + vblank;
4783
4784 mode->flags = 0;
4785 mode->flags |= hsync_positive ? DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
4786 mode->flags |= vsync_positive ? DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
4787 mode->type = DRM_MODE_TYPE_DRIVER;
4788
4789 if (timings->flags & 0x80)
4790 mode->type |= DRM_MODE_TYPE_PREFERRED;
4791 mode->vrefresh = drm_mode_vrefresh(mode);
4792 drm_mode_set_name(mode);
4793
4794 return mode;
4795}
4796
4797static int add_displayid_detailed_1_modes(struct drm_connector *connector,
4798 struct displayid_block *block)
4799{
4800 struct displayid_detailed_timing_block *det = (struct displayid_detailed_timing_block *)block;
4801 int i;
4802 int num_timings;
4803 struct drm_display_mode *newmode;
4804 int num_modes = 0;
4805 /* blocks must be multiple of 20 bytes length */
4806 if (block->num_bytes % 20)
4807 return 0;
4808
4809 num_timings = block->num_bytes / 20;
4810 for (i = 0; i < num_timings; i++) {
4811 struct displayid_detailed_timings_1 *timings = &det->timings[i];
4812
4813 newmode = drm_mode_displayid_detailed(connector->dev, timings);
4814 if (!newmode)
4815 continue;
4816
4817 drm_mode_probed_add(connector, newmode);
4818 num_modes++;
4819 }
4820 return num_modes;
4821}
4822
4823static int add_displayid_detailed_modes(struct drm_connector *connector,
4824 struct edid *edid)
4825{
4826 u8 *displayid;
4827 int ret;
4828 int idx = 1;
4829 int length = EDID_LENGTH;
4830 struct displayid_block *block;
4831 int num_modes = 0;
4832
4833 displayid = drm_find_displayid_extension(edid);
4834 if (!displayid)
4835 return 0;
4836
4837 ret = validate_displayid(displayid, length, idx);
4838 if (ret)
4839 return 0;
4840
4841 idx += sizeof(struct displayid_hdr);
4842 for_each_displayid_db(displayid, block, idx, length) {
4843 switch (block->tag) {
4844 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
4845 num_modes += add_displayid_detailed_1_modes(connector, block);
4846 break;
4847 }
4848 }
4849 return num_modes;
4850}
4851
4852/**
4853 * drm_add_edid_modes - add modes from EDID data, if available
4854 * @connector: connector we're probing
4855 * @edid: EDID data
4856 *
4857 * Add the specified modes to the connector's mode list. Also fills out the
4858 * &drm_display_info structure and ELD in @connector with any information which
4859 * can be derived from the edid.
4860 *
4861 * Return: The number of modes added or 0 if we couldn't find any.
4862 */
4863int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
4864{
4865 int num_modes = 0;
4866 u32 quirks;
4867
4868 if (edid == NULL) {
4869 clear_eld(connector);
4870 return 0;
4871 }
4872 if (!drm_edid_is_valid(edid)) {
4873 clear_eld(connector);
4874 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
4875 connector->name);
4876 return 0;
4877 }
4878
4879 drm_edid_to_eld(connector, edid);
4880
4881 /*
4882 * CEA-861-F adds ycbcr capability map block, for HDMI 2.0 sinks.
4883 * To avoid multiple parsing of same block, lets parse that map
4884 * from sink info, before parsing CEA modes.
4885 */
4886 quirks = drm_add_display_info(connector, edid);
4887
4888 /*
4889 * EDID spec says modes should be preferred in this order:
4890 * - preferred detailed mode
4891 * - other detailed modes from base block
4892 * - detailed modes from extension blocks
4893 * - CVT 3-byte code modes
4894 * - standard timing codes
4895 * - established timing codes
4896 * - modes inferred from GTF or CVT range information
4897 *
4898 * We get this pretty much right.
4899 *
4900 * XXX order for additional mode types in extension blocks?
4901 */
4902 num_modes += add_detailed_modes(connector, edid, quirks);
4903 num_modes += add_cvt_modes(connector, edid);
4904 num_modes += add_standard_modes(connector, edid);
4905 num_modes += add_established_modes(connector, edid);
4906 num_modes += add_cea_modes(connector, edid);
4907 num_modes += add_alternate_cea_modes(connector, edid);
4908 num_modes += add_displayid_detailed_modes(connector, edid);
4909 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
4910 num_modes += add_inferred_modes(connector, edid);
4911
4912 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
4913 edid_fixup_preferred(connector, quirks);
4914
4915 if (quirks & EDID_QUIRK_FORCE_6BPC)
4916 connector->display_info.bpc = 6;
4917
4918 if (quirks & EDID_QUIRK_FORCE_8BPC)
4919 connector->display_info.bpc = 8;
4920
4921 if (quirks & EDID_QUIRK_FORCE_10BPC)
4922 connector->display_info.bpc = 10;
4923
4924 if (quirks & EDID_QUIRK_FORCE_12BPC)
4925 connector->display_info.bpc = 12;
4926
4927 return num_modes;
4928}
4929EXPORT_SYMBOL(drm_add_edid_modes);
4930
4931/**
4932 * drm_add_modes_noedid - add modes for the connectors without EDID
4933 * @connector: connector we're probing
4934 * @hdisplay: the horizontal display limit
4935 * @vdisplay: the vertical display limit
4936 *
4937 * Add the specified modes to the connector's mode list. Only when the
4938 * hdisplay/vdisplay is not beyond the given limit, it will be added.
4939 *
4940 * Return: The number of modes added or 0 if we couldn't find any.
4941 */
4942int drm_add_modes_noedid(struct drm_connector *connector,
4943 int hdisplay, int vdisplay)
4944{
4945 int i, count, num_modes = 0;
4946 struct drm_display_mode *mode;
4947 struct drm_device *dev = connector->dev;
4948
4949 count = ARRAY_SIZE(drm_dmt_modes);
4950 if (hdisplay < 0)
4951 hdisplay = 0;
4952 if (vdisplay < 0)
4953 vdisplay = 0;
4954
4955 for (i = 0; i < count; i++) {
4956 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
4957 if (hdisplay && vdisplay) {
4958 /*
4959 * Only when two are valid, they will be used to check
4960 * whether the mode should be added to the mode list of
4961 * the connector.
4962 */
4963 if (ptr->hdisplay > hdisplay ||
4964 ptr->vdisplay > vdisplay)
4965 continue;
4966 }
4967 if (drm_mode_vrefresh(ptr) > 61)
4968 continue;
4969 mode = drm_mode_duplicate(dev, ptr);
4970 if (mode) {
4971 drm_mode_probed_add(connector, mode);
4972 num_modes++;
4973 }
4974 }
4975 return num_modes;
4976}
4977EXPORT_SYMBOL(drm_add_modes_noedid);
4978
4979/**
4980 * drm_set_preferred_mode - Sets the preferred mode of a connector
4981 * @connector: connector whose mode list should be processed
4982 * @hpref: horizontal resolution of preferred mode
4983 * @vpref: vertical resolution of preferred mode
4984 *
4985 * Marks a mode as preferred if it matches the resolution specified by @hpref
4986 * and @vpref.
4987 */
4988void drm_set_preferred_mode(struct drm_connector *connector,
4989 int hpref, int vpref)
4990{
4991 struct drm_display_mode *mode;
4992
4993 list_for_each_entry(mode, &connector->probed_modes, head) {
4994 if (mode->hdisplay == hpref &&
4995 mode->vdisplay == vpref)
4996 mode->type |= DRM_MODE_TYPE_PREFERRED;
4997 }
4998}
4999EXPORT_SYMBOL(drm_set_preferred_mode);
5000
5001static bool is_hdmi2_sink(struct drm_connector *connector)
5002{
5003 /*
5004 * FIXME: sil-sii8620 doesn't have a connector around when
5005 * we need one, so we have to be prepared for a NULL connector.
5006 */
5007 if (!connector)
5008 return true;
5009
5010 return connector->display_info.hdmi.scdc.supported ||
5011 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
5012}
5013
5014static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
5015{
5016 return sink_eotf & BIT(output_eotf);
5017}
5018
5019/**
5020 * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
5021 * HDR metadata from userspace
5022 * @frame: HDMI DRM infoframe
5023 * @conn_state: Connector state containing HDR metadata
5024 *
5025 * Return: 0 on success or a negative error code on failure.
5026 */
5027int
5028drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
5029 const struct drm_connector_state *conn_state)
5030{
5031 struct drm_connector *connector;
5032 struct hdr_output_metadata *hdr_metadata;
5033 int err;
5034
5035 if (!frame || !conn_state)
5036 return -EINVAL;
5037
5038 connector = conn_state->connector;
5039
5040 if (!conn_state->hdr_output_metadata)
5041 return -EINVAL;
5042
5043 hdr_metadata = conn_state->hdr_output_metadata->data;
5044
5045 if (!hdr_metadata || !connector)
5046 return -EINVAL;
5047
5048 /* Sink EOTF is Bit map while infoframe is absolute values */
5049 if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
5050 connector->hdr_sink_metadata.hdmi_type1.eotf)) {
5051 DRM_DEBUG_KMS("EOTF Not Supported\n");
5052 return -EINVAL;
5053 }
5054
5055 err = hdmi_drm_infoframe_init(frame);
5056 if (err < 0)
5057 return err;
5058
5059 frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
5060 frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
5061
5062 BUILD_BUG_ON(sizeof(frame->display_primaries) !=
5063 sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
5064 BUILD_BUG_ON(sizeof(frame->white_point) !=
5065 sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
5066
5067 memcpy(&frame->display_primaries,
5068 &hdr_metadata->hdmi_metadata_type1.display_primaries,
5069 sizeof(frame->display_primaries));
5070
5071 memcpy(&frame->white_point,
5072 &hdr_metadata->hdmi_metadata_type1.white_point,
5073 sizeof(frame->white_point));
5074
5075 frame->max_display_mastering_luminance =
5076 hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
5077 frame->min_display_mastering_luminance =
5078 hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
5079 frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
5080 frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
5081
5082 return 0;
5083}
5084EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
5085
5086/**
5087 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
5088 * data from a DRM display mode
5089 * @frame: HDMI AVI infoframe
5090 * @connector: the connector
5091 * @mode: DRM display mode
5092 *
5093 * Return: 0 on success or a negative error code on failure.
5094 */
5095int
5096drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
5097 struct drm_connector *connector,
5098 const struct drm_display_mode *mode)
5099{
5100 enum hdmi_picture_aspect picture_aspect;
5101 int err;
5102
5103 if (!frame || !mode)
5104 return -EINVAL;
5105
5106 err = hdmi_avi_infoframe_init(frame);
5107 if (err < 0)
5108 return err;
5109
5110 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
5111 frame->pixel_repeat = 1;
5112
5113 frame->video_code = drm_match_cea_mode(mode);
5114
5115 /*
5116 * HDMI 1.4 VIC range: 1 <= VIC <= 64 (CEA-861-D) but
5117 * HDMI 2.0 VIC range: 1 <= VIC <= 107 (CEA-861-F). So we
5118 * have to make sure we dont break HDMI 1.4 sinks.
5119 */
5120 if (!is_hdmi2_sink(connector) && frame->video_code > 64)
5121 frame->video_code = 0;
5122
5123 /*
5124 * HDMI spec says if a mode is found in HDMI 1.4b 4K modes
5125 * we should send its VIC in vendor infoframes, else send the
5126 * VIC in AVI infoframes. Lets check if this mode is present in
5127 * HDMI 1.4b 4K modes
5128 */
5129 if (frame->video_code) {
5130 u8 vendor_if_vic = drm_match_hdmi_mode(mode);
5131 bool is_s3d = mode->flags & DRM_MODE_FLAG_3D_MASK;
5132
5133 if (drm_valid_hdmi_vic(vendor_if_vic) && !is_s3d)
5134 frame->video_code = 0;
5135 }
5136
5137 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5138
5139 /*
5140 * As some drivers don't support atomic, we can't use connector state.
5141 * So just initialize the frame with default values, just the same way
5142 * as it's done with other properties here.
5143 */
5144 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
5145 frame->itc = 0;
5146
5147 /*
5148 * Populate picture aspect ratio from either
5149 * user input (if specified) or from the CEA mode list.
5150 */
5151 picture_aspect = mode->picture_aspect_ratio;
5152 if (picture_aspect == HDMI_PICTURE_ASPECT_NONE)
5153 picture_aspect = drm_get_cea_aspect_ratio(frame->video_code);
5154
5155 /*
5156 * The infoframe can't convey anything but none, 4:3
5157 * and 16:9, so if the user has asked for anything else
5158 * we can only satisfy it by specifying the right VIC.
5159 */
5160 if (picture_aspect > HDMI_PICTURE_ASPECT_16_9) {
5161 if (picture_aspect !=
5162 drm_get_cea_aspect_ratio(frame->video_code))
5163 return -EINVAL;
5164 picture_aspect = HDMI_PICTURE_ASPECT_NONE;
5165 }
5166
5167 frame->picture_aspect = picture_aspect;
5168 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
5169 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
5170
5171 return 0;
5172}
5173EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
5174
5175/* HDMI Colorspace Spec Definitions */
5176#define FULL_COLORIMETRY_MASK 0x1FF
5177#define NORMAL_COLORIMETRY_MASK 0x3
5178#define EXTENDED_COLORIMETRY_MASK 0x7
5179#define EXTENDED_ACE_COLORIMETRY_MASK 0xF
5180
5181#define C(x) ((x) << 0)
5182#define EC(x) ((x) << 2)
5183#define ACE(x) ((x) << 5)
5184
5185#define HDMI_COLORIMETRY_NO_DATA 0x0
5186#define HDMI_COLORIMETRY_SMPTE_170M_YCC (C(1) | EC(0) | ACE(0))
5187#define HDMI_COLORIMETRY_BT709_YCC (C(2) | EC(0) | ACE(0))
5188#define HDMI_COLORIMETRY_XVYCC_601 (C(3) | EC(0) | ACE(0))
5189#define HDMI_COLORIMETRY_XVYCC_709 (C(3) | EC(1) | ACE(0))
5190#define HDMI_COLORIMETRY_SYCC_601 (C(3) | EC(2) | ACE(0))
5191#define HDMI_COLORIMETRY_OPYCC_601 (C(3) | EC(3) | ACE(0))
5192#define HDMI_COLORIMETRY_OPRGB (C(3) | EC(4) | ACE(0))
5193#define HDMI_COLORIMETRY_BT2020_CYCC (C(3) | EC(5) | ACE(0))
5194#define HDMI_COLORIMETRY_BT2020_RGB (C(3) | EC(6) | ACE(0))
5195#define HDMI_COLORIMETRY_BT2020_YCC (C(3) | EC(6) | ACE(0))
5196#define HDMI_COLORIMETRY_DCI_P3_RGB_D65 (C(3) | EC(7) | ACE(0))
5197#define HDMI_COLORIMETRY_DCI_P3_RGB_THEATER (C(3) | EC(7) | ACE(1))
5198
5199static const u32 hdmi_colorimetry_val[] = {
5200 [DRM_MODE_COLORIMETRY_NO_DATA] = HDMI_COLORIMETRY_NO_DATA,
5201 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = HDMI_COLORIMETRY_SMPTE_170M_YCC,
5202 [DRM_MODE_COLORIMETRY_BT709_YCC] = HDMI_COLORIMETRY_BT709_YCC,
5203 [DRM_MODE_COLORIMETRY_XVYCC_601] = HDMI_COLORIMETRY_XVYCC_601,
5204 [DRM_MODE_COLORIMETRY_XVYCC_709] = HDMI_COLORIMETRY_XVYCC_709,
5205 [DRM_MODE_COLORIMETRY_SYCC_601] = HDMI_COLORIMETRY_SYCC_601,
5206 [DRM_MODE_COLORIMETRY_OPYCC_601] = HDMI_COLORIMETRY_OPYCC_601,
5207 [DRM_MODE_COLORIMETRY_OPRGB] = HDMI_COLORIMETRY_OPRGB,
5208 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = HDMI_COLORIMETRY_BT2020_CYCC,
5209 [DRM_MODE_COLORIMETRY_BT2020_RGB] = HDMI_COLORIMETRY_BT2020_RGB,
5210 [DRM_MODE_COLORIMETRY_BT2020_YCC] = HDMI_COLORIMETRY_BT2020_YCC,
5211};
5212
5213#undef C
5214#undef EC
5215#undef ACE
5216
5217/**
5218 * drm_hdmi_avi_infoframe_colorspace() - fill the HDMI AVI infoframe
5219 * colorspace information
5220 * @frame: HDMI AVI infoframe
5221 * @conn_state: connector state
5222 */
5223void
5224drm_hdmi_avi_infoframe_colorspace(struct hdmi_avi_infoframe *frame,
5225 const struct drm_connector_state *conn_state)
5226{
5227 u32 colorimetry_val;
5228 u32 colorimetry_index = conn_state->colorspace & FULL_COLORIMETRY_MASK;
5229
5230 if (colorimetry_index >= ARRAY_SIZE(hdmi_colorimetry_val))
5231 colorimetry_val = HDMI_COLORIMETRY_NO_DATA;
5232 else
5233 colorimetry_val = hdmi_colorimetry_val[colorimetry_index];
5234
5235 frame->colorimetry = colorimetry_val & NORMAL_COLORIMETRY_MASK;
5236 /*
5237 * ToDo: Extend it for ACE formats as well. Modify the infoframe
5238 * structure and extend it in drivers/video/hdmi
5239 */
5240 frame->extended_colorimetry = (colorimetry_val >> 2) &
5241 EXTENDED_COLORIMETRY_MASK;
5242}
5243EXPORT_SYMBOL(drm_hdmi_avi_infoframe_colorspace);
5244
5245/**
5246 * drm_hdmi_avi_infoframe_quant_range() - fill the HDMI AVI infoframe
5247 * quantization range information
5248 * @frame: HDMI AVI infoframe
5249 * @connector: the connector
5250 * @mode: DRM display mode
5251 * @rgb_quant_range: RGB quantization range (Q)
5252 */
5253void
5254drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame,
5255 struct drm_connector *connector,
5256 const struct drm_display_mode *mode,
5257 enum hdmi_quantization_range rgb_quant_range)
5258{
5259 const struct drm_display_info *info = &connector->display_info;
5260
5261 /*
5262 * CEA-861:
5263 * "A Source shall not send a non-zero Q value that does not correspond
5264 * to the default RGB Quantization Range for the transmitted Picture
5265 * unless the Sink indicates support for the Q bit in a Video
5266 * Capabilities Data Block."
5267 *
5268 * HDMI 2.0 recommends sending non-zero Q when it does match the
5269 * default RGB quantization range for the mode, even when QS=0.
5270 */
5271 if (info->rgb_quant_range_selectable ||
5272 rgb_quant_range == drm_default_rgb_quant_range(mode))
5273 frame->quantization_range = rgb_quant_range;
5274 else
5275 frame->quantization_range = HDMI_QUANTIZATION_RANGE_DEFAULT;
5276
5277 /*
5278 * CEA-861-F:
5279 * "When transmitting any RGB colorimetry, the Source should set the
5280 * YQ-field to match the RGB Quantization Range being transmitted
5281 * (e.g., when Limited Range RGB, set YQ=0 or when Full Range RGB,
5282 * set YQ=1) and the Sink shall ignore the YQ-field."
5283 *
5284 * Unfortunate certain sinks (eg. VIZ Model 67/E261VA) get confused
5285 * by non-zero YQ when receiving RGB. There doesn't seem to be any
5286 * good way to tell which version of CEA-861 the sink supports, so
5287 * we limit non-zero YQ to HDMI 2.0 sinks only as HDMI 2.0 is based
5288 * on on CEA-861-F.
5289 */
5290 if (!is_hdmi2_sink(connector) ||
5291 rgb_quant_range == HDMI_QUANTIZATION_RANGE_LIMITED)
5292 frame->ycc_quantization_range =
5293 HDMI_YCC_QUANTIZATION_RANGE_LIMITED;
5294 else
5295 frame->ycc_quantization_range =
5296 HDMI_YCC_QUANTIZATION_RANGE_FULL;
5297}
5298EXPORT_SYMBOL(drm_hdmi_avi_infoframe_quant_range);
5299
5300static enum hdmi_3d_structure
5301s3d_structure_from_display_mode(const struct drm_display_mode *mode)
5302{
5303 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
5304
5305 switch (layout) {
5306 case DRM_MODE_FLAG_3D_FRAME_PACKING:
5307 return HDMI_3D_STRUCTURE_FRAME_PACKING;
5308 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
5309 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
5310 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
5311 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
5312 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
5313 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
5314 case DRM_MODE_FLAG_3D_L_DEPTH:
5315 return HDMI_3D_STRUCTURE_L_DEPTH;
5316 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
5317 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
5318 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
5319 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
5320 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
5321 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
5322 default:
5323 return HDMI_3D_STRUCTURE_INVALID;
5324 }
5325}
5326
5327/**
5328 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
5329 * data from a DRM display mode
5330 * @frame: HDMI vendor infoframe
5331 * @connector: the connector
5332 * @mode: DRM display mode
5333 *
5334 * Note that there's is a need to send HDMI vendor infoframes only when using a
5335 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
5336 * function will return -EINVAL, error that can be safely ignored.
5337 *
5338 * Return: 0 on success or a negative error code on failure.
5339 */
5340int
5341drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
5342 struct drm_connector *connector,
5343 const struct drm_display_mode *mode)
5344{
5345 /*
5346 * FIXME: sil-sii8620 doesn't have a connector around when
5347 * we need one, so we have to be prepared for a NULL connector.
5348 */
5349 bool has_hdmi_infoframe = connector ?
5350 connector->display_info.has_hdmi_infoframe : false;
5351 int err;
5352 u32 s3d_flags;
5353 u8 vic;
5354
5355 if (!frame || !mode)
5356 return -EINVAL;
5357
5358 if (!has_hdmi_infoframe)
5359 return -EINVAL;
5360
5361 vic = drm_match_hdmi_mode(mode);
5362 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
5363
5364 /*
5365 * Even if it's not absolutely necessary to send the infoframe
5366 * (ie.vic==0 and s3d_struct==0) we will still send it if we
5367 * know that the sink can handle it. This is based on a
5368 * suggestion in HDMI 2.0 Appendix F. Apparently some sinks
5369 * have trouble realizing that they shuld switch from 3D to 2D
5370 * mode if the source simply stops sending the infoframe when
5371 * it wants to switch from 3D to 2D.
5372 */
5373
5374 if (vic && s3d_flags)
5375 return -EINVAL;
5376
5377 err = hdmi_vendor_infoframe_init(frame);
5378 if (err < 0)
5379 return err;
5380
5381 frame->vic = vic;
5382 frame->s3d_struct = s3d_structure_from_display_mode(mode);
5383
5384 return 0;
5385}
5386EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);
5387
5388static int drm_parse_tiled_block(struct drm_connector *connector,
5389 struct displayid_block *block)
5390{
5391 struct displayid_tiled_block *tile = (struct displayid_tiled_block *)block;
5392 u16 w, h;
5393 u8 tile_v_loc, tile_h_loc;
5394 u8 num_v_tile, num_h_tile;
5395 struct drm_tile_group *tg;
5396
5397 w = tile->tile_size[0] | tile->tile_size[1] << 8;
5398 h = tile->tile_size[2] | tile->tile_size[3] << 8;
5399
5400 num_v_tile = (tile->topo[0] & 0xf) | (tile->topo[2] & 0x30);
5401 num_h_tile = (tile->topo[0] >> 4) | ((tile->topo[2] >> 2) & 0x30);
5402 tile_v_loc = (tile->topo[1] & 0xf) | ((tile->topo[2] & 0x3) << 4);
5403 tile_h_loc = (tile->topo[1] >> 4) | (((tile->topo[2] >> 2) & 0x3) << 4);
5404
5405 connector->has_tile = true;
5406 if (tile->tile_cap & 0x80)
5407 connector->tile_is_single_monitor = true;
5408
5409 connector->num_h_tile = num_h_tile + 1;
5410 connector->num_v_tile = num_v_tile + 1;
5411 connector->tile_h_loc = tile_h_loc;
5412 connector->tile_v_loc = tile_v_loc;
5413 connector->tile_h_size = w + 1;
5414 connector->tile_v_size = h + 1;
5415
5416 DRM_DEBUG_KMS("tile cap 0x%x\n", tile->tile_cap);
5417 DRM_DEBUG_KMS("tile_size %d x %d\n", w + 1, h + 1);
5418 DRM_DEBUG_KMS("topo num tiles %dx%d, location %dx%d\n",
5419 num_h_tile + 1, num_v_tile + 1, tile_h_loc, tile_v_loc);
5420 DRM_DEBUG_KMS("vend %c%c%c\n", tile->topology_id[0], tile->topology_id[1], tile->topology_id[2]);
5421
5422 tg = drm_mode_get_tile_group(connector->dev, tile->topology_id);
5423 if (!tg) {
5424 tg = drm_mode_create_tile_group(connector->dev, tile->topology_id);
5425 }
5426 if (!tg)
5427 return -ENOMEM;
5428
5429 if (connector->tile_group != tg) {
5430 /* if we haven't got a pointer,
5431 take the reference, drop ref to old tile group */
5432 if (connector->tile_group) {
5433 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5434 }
5435 connector->tile_group = tg;
5436 } else
5437 /* if same tile group, then release the ref we just took. */
5438 drm_mode_put_tile_group(connector->dev, tg);
5439 return 0;
5440}
5441
5442static int drm_parse_display_id(struct drm_connector *connector,
5443 u8 *displayid, int length,
5444 bool is_edid_extension)
5445{
5446 /* if this is an EDID extension the first byte will be 0x70 */
5447 int idx = 0;
5448 struct displayid_block *block;
5449 int ret;
5450
5451 if (is_edid_extension)
5452 idx = 1;
5453
5454 ret = validate_displayid(displayid, length, idx);
5455 if (ret)
5456 return ret;
5457
5458 idx += sizeof(struct displayid_hdr);
5459 for_each_displayid_db(displayid, block, idx, length) {
5460 DRM_DEBUG_KMS("block id 0x%x, rev %d, len %d\n",
5461 block->tag, block->rev, block->num_bytes);
5462
5463 switch (block->tag) {
5464 case DATA_BLOCK_TILED_DISPLAY:
5465 ret = drm_parse_tiled_block(connector, block);
5466 if (ret)
5467 return ret;
5468 break;
5469 case DATA_BLOCK_TYPE_1_DETAILED_TIMING:
5470 /* handled in mode gathering code. */
5471 break;
5472 case DATA_BLOCK_CTA:
5473 /* handled in the cea parser code. */
5474 break;
5475 default:
5476 DRM_DEBUG_KMS("found DisplayID tag 0x%x, unhandled\n", block->tag);
5477 break;
5478 }
5479 }
5480 return 0;
5481}
5482
5483static void drm_get_displayid(struct drm_connector *connector,
5484 struct edid *edid)
5485{
5486 void *displayid = NULL;
5487 int ret;
5488 connector->has_tile = false;
5489 displayid = drm_find_displayid_extension(edid);
5490 if (!displayid) {
5491 /* drop reference to any tile group we had */
5492 goto out_drop_ref;
5493 }
5494
5495 ret = drm_parse_display_id(connector, displayid, EDID_LENGTH, true);
5496 if (ret < 0)
5497 goto out_drop_ref;
5498 if (!connector->has_tile)
5499 goto out_drop_ref;
5500 return;
5501out_drop_ref:
5502 if (connector->tile_group) {
5503 drm_mode_put_tile_group(connector->dev, connector->tile_group);
5504 connector->tile_group = NULL;
5505 }
5506 return;
5507}