blob: 7a4fd2ed1280b5d23e1ac46a0c70672a873986e2 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright (c) 2006 Luc Verhaegen (quirks list)
3 * Copyright (c) 2007-2008 Intel Corporation
4 * Jesse Barnes <jesse.barnes@intel.com>
Adam Jackson61e57a82010-03-29 21:43:18 +00005 * Copyright 2010 Red Hat, Inc.
Dave Airlief453ba02008-11-07 14:05:41 -08006 *
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#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Thierry Reding10a85122012-11-21 15:31:35 +010032#include <linux/hdmi.h>
Dave Airlief453ba02008-11-07 14:05:41 -080033#include <linux/i2c.h>
Adam Jackson47819ba2012-05-30 16:42:39 -040034#include <linux/module.h>
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
36#include <drm/drm_edid.h>
Dave Airlief453ba02008-11-07 14:05:41 -080037
Adam Jackson13931572010-08-03 14:38:19 -040038#define version_greater(edid, maj, min) \
39 (((edid)->version > (maj)) || \
40 ((edid)->version == (maj) && (edid)->revision > (min)))
Dave Airlief453ba02008-11-07 14:05:41 -080041
Adam Jacksond1ff6402010-03-29 21:43:26 +000042#define EDID_EST_TIMINGS 16
43#define EDID_STD_TIMINGS 8
44#define EDID_DETAILED_TIMINGS 4
Dave Airlief453ba02008-11-07 14:05:41 -080045
46/*
47 * EDID blocks out in the wild have a variety of bugs, try to collect
48 * them here (note that userspace may work around broken monitors first,
49 * but fixes should make their way here so that the kernel "just works"
50 * on as many displays as possible).
51 */
52
53/* First detailed mode wrong, use largest 60Hz mode */
54#define EDID_QUIRK_PREFER_LARGE_60 (1 << 0)
55/* Reported 135MHz pixel clock is too high, needs adjustment */
56#define EDID_QUIRK_135_CLOCK_TOO_HIGH (1 << 1)
57/* Prefer the largest mode at 75 Hz */
58#define EDID_QUIRK_PREFER_LARGE_75 (1 << 2)
59/* Detail timing is in cm not mm */
60#define EDID_QUIRK_DETAILED_IN_CM (1 << 3)
61/* Detailed timing descriptors have bogus size values, so just take the
62 * maximum size and use that.
63 */
64#define EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE (1 << 4)
65/* Monitor forgot to set the first detailed is preferred bit. */
66#define EDID_QUIRK_FIRST_DETAILED_PREFERRED (1 << 5)
67/* use +hsync +vsync for detailed mode */
68#define EDID_QUIRK_DETAILED_SYNC_PP (1 << 6)
Adam Jacksonbc42aab2012-05-23 16:26:54 -040069/* Force reduced-blanking timings for detailed modes */
70#define EDID_QUIRK_FORCE_REDUCED_BLANKING (1 << 7)
Rafał Miłecki49d45a312013-12-07 13:22:42 +010071/* Force 8bpc */
72#define EDID_QUIRK_FORCE_8BPC (1 << 8)
Alex Deucher3c537882010-02-05 04:21:19 -050073
Adam Jackson13931572010-08-03 14:38:19 -040074struct detailed_mode_closure {
75 struct drm_connector *connector;
76 struct edid *edid;
77 bool preferred;
78 u32 quirks;
79 int modes;
80};
Dave Airlief453ba02008-11-07 14:05:41 -080081
Zhao Yakui5c612592009-06-22 13:17:10 +080082#define LEVEL_DMT 0
83#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000084#define LEVEL_GTF2 2
85#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +080086
Dave Airlief453ba02008-11-07 14:05:41 -080087static struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -050088 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -080089 int product_id;
90 u32 quirks;
91} edid_quirk_list[] = {
92 /* Acer AL1706 */
93 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
94 /* Acer F51 */
95 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
96 /* Unknown Acer */
97 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
98
99 /* Belinea 10 15 55 */
100 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
101 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
102
103 /* Envision Peripherals, Inc. EN-7100e */
104 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000105 /* Envision EN2028 */
106 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800107
108 /* Funai Electronics PM36B */
109 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
110 EDID_QUIRK_DETAILED_IN_CM },
111
112 /* LG Philips LCD LP154W01-A5 */
113 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
114 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
115
116 /* Philips 107p5 CRT */
117 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
118
119 /* Proview AY765C */
120 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
121
122 /* Samsung SyncMaster 205BW. Note: irony */
123 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
124 /* Samsung SyncMaster 22[5-6]BW */
125 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
126 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400127
128 /* ViewSonic VA2026w */
129 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400130
131 /* Medion MD 30217 PG */
132 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100133
134 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
135 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Dave Airlief453ba02008-11-07 14:05:41 -0800136};
137
Thierry Redinga6b21832012-11-23 15:01:42 +0100138/*
139 * Autogenerated from the DMT spec.
140 * This table is copied from xfree86/modes/xf86EdidModes.c.
141 */
142static const struct drm_display_mode drm_dmt_modes[] = {
143 /* 640x350@85Hz */
144 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
145 736, 832, 0, 350, 382, 385, 445, 0,
146 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
147 /* 640x400@85Hz */
148 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
149 736, 832, 0, 400, 401, 404, 445, 0,
150 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
151 /* 720x400@85Hz */
152 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
153 828, 936, 0, 400, 401, 404, 446, 0,
154 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
155 /* 640x480@60Hz */
156 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
157 752, 800, 0, 480, 489, 492, 525, 0,
158 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
159 /* 640x480@72Hz */
160 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
161 704, 832, 0, 480, 489, 492, 520, 0,
162 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
163 /* 640x480@75Hz */
164 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
165 720, 840, 0, 480, 481, 484, 500, 0,
166 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
167 /* 640x480@85Hz */
168 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
169 752, 832, 0, 480, 481, 484, 509, 0,
170 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
171 /* 800x600@56Hz */
172 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
173 896, 1024, 0, 600, 601, 603, 625, 0,
174 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
175 /* 800x600@60Hz */
176 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
177 968, 1056, 0, 600, 601, 605, 628, 0,
178 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
179 /* 800x600@72Hz */
180 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
181 976, 1040, 0, 600, 637, 643, 666, 0,
182 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
183 /* 800x600@75Hz */
184 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
185 896, 1056, 0, 600, 601, 604, 625, 0,
186 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
187 /* 800x600@85Hz */
188 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
189 896, 1048, 0, 600, 601, 604, 631, 0,
190 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
191 /* 800x600@120Hz RB */
192 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
193 880, 960, 0, 600, 603, 607, 636, 0,
194 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
195 /* 848x480@60Hz */
196 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
197 976, 1088, 0, 480, 486, 494, 517, 0,
198 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
199 /* 1024x768@43Hz, interlace */
200 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
201 1208, 1264, 0, 768, 768, 772, 817, 0,
202 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
203 DRM_MODE_FLAG_INTERLACE) },
204 /* 1024x768@60Hz */
205 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
206 1184, 1344, 0, 768, 771, 777, 806, 0,
207 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
208 /* 1024x768@70Hz */
209 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
210 1184, 1328, 0, 768, 771, 777, 806, 0,
211 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
212 /* 1024x768@75Hz */
213 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
214 1136, 1312, 0, 768, 769, 772, 800, 0,
215 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
216 /* 1024x768@85Hz */
217 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
218 1168, 1376, 0, 768, 769, 772, 808, 0,
219 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
220 /* 1024x768@120Hz RB */
221 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
222 1104, 1184, 0, 768, 771, 775, 813, 0,
223 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
224 /* 1152x864@75Hz */
225 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
226 1344, 1600, 0, 864, 865, 868, 900, 0,
227 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
228 /* 1280x768@60Hz RB */
229 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
230 1360, 1440, 0, 768, 771, 778, 790, 0,
231 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
232 /* 1280x768@60Hz */
233 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
234 1472, 1664, 0, 768, 771, 778, 798, 0,
235 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
236 /* 1280x768@75Hz */
237 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
238 1488, 1696, 0, 768, 771, 778, 805, 0,
239 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
240 /* 1280x768@85Hz */
241 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
242 1496, 1712, 0, 768, 771, 778, 809, 0,
243 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
244 /* 1280x768@120Hz RB */
245 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
246 1360, 1440, 0, 768, 771, 778, 813, 0,
247 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
248 /* 1280x800@60Hz RB */
249 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
250 1360, 1440, 0, 800, 803, 809, 823, 0,
251 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
252 /* 1280x800@60Hz */
253 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
254 1480, 1680, 0, 800, 803, 809, 831, 0,
255 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
256 /* 1280x800@75Hz */
257 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
258 1488, 1696, 0, 800, 803, 809, 838, 0,
259 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
260 /* 1280x800@85Hz */
261 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
262 1496, 1712, 0, 800, 803, 809, 843, 0,
263 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
264 /* 1280x800@120Hz RB */
265 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
266 1360, 1440, 0, 800, 803, 809, 847, 0,
267 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
268 /* 1280x960@60Hz */
269 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
270 1488, 1800, 0, 960, 961, 964, 1000, 0,
271 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
272 /* 1280x960@85Hz */
273 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
274 1504, 1728, 0, 960, 961, 964, 1011, 0,
275 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
276 /* 1280x960@120Hz RB */
277 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
278 1360, 1440, 0, 960, 963, 967, 1017, 0,
279 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
280 /* 1280x1024@60Hz */
281 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
282 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
283 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
284 /* 1280x1024@75Hz */
285 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
286 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
287 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
288 /* 1280x1024@85Hz */
289 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
290 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
291 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
292 /* 1280x1024@120Hz RB */
293 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
294 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
295 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
296 /* 1360x768@60Hz */
297 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
298 1536, 1792, 0, 768, 771, 777, 795, 0,
299 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
300 /* 1360x768@120Hz RB */
301 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
302 1440, 1520, 0, 768, 771, 776, 813, 0,
303 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
304 /* 1400x1050@60Hz RB */
305 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
306 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
307 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
308 /* 1400x1050@60Hz */
309 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
310 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
311 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
312 /* 1400x1050@75Hz */
313 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
314 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
315 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
316 /* 1400x1050@85Hz */
317 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
318 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
319 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
320 /* 1400x1050@120Hz RB */
321 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
322 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
323 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
324 /* 1440x900@60Hz RB */
325 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
326 1520, 1600, 0, 900, 903, 909, 926, 0,
327 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
328 /* 1440x900@60Hz */
329 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
330 1672, 1904, 0, 900, 903, 909, 934, 0,
331 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
332 /* 1440x900@75Hz */
333 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
334 1688, 1936, 0, 900, 903, 909, 942, 0,
335 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
336 /* 1440x900@85Hz */
337 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
338 1696, 1952, 0, 900, 903, 909, 948, 0,
339 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
340 /* 1440x900@120Hz RB */
341 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
342 1520, 1600, 0, 900, 903, 909, 953, 0,
343 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
344 /* 1600x1200@60Hz */
345 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
346 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
347 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
348 /* 1600x1200@65Hz */
349 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
350 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
351 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
352 /* 1600x1200@70Hz */
353 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
354 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
355 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
356 /* 1600x1200@75Hz */
357 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
358 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
359 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
360 /* 1600x1200@85Hz */
361 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
362 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
363 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
364 /* 1600x1200@120Hz RB */
365 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
366 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
367 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
368 /* 1680x1050@60Hz RB */
369 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
370 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
371 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
372 /* 1680x1050@60Hz */
373 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
374 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
375 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
376 /* 1680x1050@75Hz */
377 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
378 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
379 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
380 /* 1680x1050@85Hz */
381 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
382 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
383 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
384 /* 1680x1050@120Hz RB */
385 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
386 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
387 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
388 /* 1792x1344@60Hz */
389 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
390 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
391 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
392 /* 1792x1344@75Hz */
393 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
394 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
395 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
396 /* 1792x1344@120Hz RB */
397 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
398 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
399 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
400 /* 1856x1392@60Hz */
401 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
402 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
403 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
404 /* 1856x1392@75Hz */
405 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
406 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
407 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
408 /* 1856x1392@120Hz RB */
409 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
410 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
411 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
412 /* 1920x1200@60Hz RB */
413 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
414 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
415 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
416 /* 1920x1200@60Hz */
417 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
418 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
419 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
420 /* 1920x1200@75Hz */
421 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
422 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
423 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
424 /* 1920x1200@85Hz */
425 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
426 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
427 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
428 /* 1920x1200@120Hz RB */
429 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
430 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
431 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
432 /* 1920x1440@60Hz */
433 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
434 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
435 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
436 /* 1920x1440@75Hz */
437 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
438 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
439 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
440 /* 1920x1440@120Hz RB */
441 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
442 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
443 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
444 /* 2560x1600@60Hz RB */
445 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
446 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
447 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
448 /* 2560x1600@60Hz */
449 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
450 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
451 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
452 /* 2560x1600@75HZ */
453 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
454 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
455 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
456 /* 2560x1600@85HZ */
457 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
458 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
459 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
460 /* 2560x1600@120Hz RB */
461 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
462 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
463 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
464};
465
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300466/*
467 * These more or less come from the DMT spec. The 720x400 modes are
468 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
469 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
470 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
471 * mode.
472 *
473 * The DMT modes have been fact-checked; the rest are mild guesses.
474 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100475static const struct drm_display_mode edid_est_modes[] = {
476 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
477 968, 1056, 0, 600, 601, 605, 628, 0,
478 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
479 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
480 896, 1024, 0, 600, 601, 603, 625, 0,
481 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
482 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
483 720, 840, 0, 480, 481, 484, 500, 0,
484 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
485 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
486 704, 832, 0, 480, 489, 491, 520, 0,
487 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
488 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
489 768, 864, 0, 480, 483, 486, 525, 0,
490 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
491 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
492 752, 800, 0, 480, 490, 492, 525, 0,
493 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
494 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
495 846, 900, 0, 400, 421, 423, 449, 0,
496 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
497 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
498 846, 900, 0, 400, 412, 414, 449, 0,
499 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
500 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
501 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
502 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
503 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
504 1136, 1312, 0, 768, 769, 772, 800, 0,
505 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
506 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
507 1184, 1328, 0, 768, 771, 777, 806, 0,
508 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
509 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
510 1184, 1344, 0, 768, 771, 777, 806, 0,
511 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
512 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
513 1208, 1264, 0, 768, 768, 776, 817, 0,
514 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
515 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
516 928, 1152, 0, 624, 625, 628, 667, 0,
517 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
518 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
519 896, 1056, 0, 600, 601, 604, 625, 0,
520 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
521 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
522 976, 1040, 0, 600, 637, 643, 666, 0,
523 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
524 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
525 1344, 1600, 0, 864, 865, 868, 900, 0,
526 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
527};
528
529struct minimode {
530 short w;
531 short h;
532 short r;
533 short rb;
534};
535
536static const struct minimode est3_modes[] = {
537 /* byte 6 */
538 { 640, 350, 85, 0 },
539 { 640, 400, 85, 0 },
540 { 720, 400, 85, 0 },
541 { 640, 480, 85, 0 },
542 { 848, 480, 60, 0 },
543 { 800, 600, 85, 0 },
544 { 1024, 768, 85, 0 },
545 { 1152, 864, 75, 0 },
546 /* byte 7 */
547 { 1280, 768, 60, 1 },
548 { 1280, 768, 60, 0 },
549 { 1280, 768, 75, 0 },
550 { 1280, 768, 85, 0 },
551 { 1280, 960, 60, 0 },
552 { 1280, 960, 85, 0 },
553 { 1280, 1024, 60, 0 },
554 { 1280, 1024, 85, 0 },
555 /* byte 8 */
556 { 1360, 768, 60, 0 },
557 { 1440, 900, 60, 1 },
558 { 1440, 900, 60, 0 },
559 { 1440, 900, 75, 0 },
560 { 1440, 900, 85, 0 },
561 { 1400, 1050, 60, 1 },
562 { 1400, 1050, 60, 0 },
563 { 1400, 1050, 75, 0 },
564 /* byte 9 */
565 { 1400, 1050, 85, 0 },
566 { 1680, 1050, 60, 1 },
567 { 1680, 1050, 60, 0 },
568 { 1680, 1050, 75, 0 },
569 { 1680, 1050, 85, 0 },
570 { 1600, 1200, 60, 0 },
571 { 1600, 1200, 65, 0 },
572 { 1600, 1200, 70, 0 },
573 /* byte 10 */
574 { 1600, 1200, 75, 0 },
575 { 1600, 1200, 85, 0 },
576 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300577 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100578 { 1856, 1392, 60, 0 },
579 { 1856, 1392, 75, 0 },
580 { 1920, 1200, 60, 1 },
581 { 1920, 1200, 60, 0 },
582 /* byte 11 */
583 { 1920, 1200, 75, 0 },
584 { 1920, 1200, 85, 0 },
585 { 1920, 1440, 60, 0 },
586 { 1920, 1440, 75, 0 },
587};
588
589static const struct minimode extra_modes[] = {
590 { 1024, 576, 60, 0 },
591 { 1366, 768, 60, 0 },
592 { 1600, 900, 60, 0 },
593 { 1680, 945, 60, 0 },
594 { 1920, 1080, 60, 0 },
595 { 2048, 1152, 60, 0 },
596 { 2048, 1536, 60, 0 },
597};
598
599/*
600 * Probably taken from CEA-861 spec.
601 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
602 */
603static const struct drm_display_mode edid_cea_modes[] = {
604 /* 1 - 640x480@60Hz */
605 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
606 752, 800, 0, 480, 490, 492, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300607 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530608 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100609 /* 2 - 720x480@60Hz */
610 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
611 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300612 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530613 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100614 /* 3 - 720x480@60Hz */
615 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
616 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300617 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530618 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100619 /* 4 - 1280x720@60Hz */
620 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
621 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300622 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530623 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100624 /* 5 - 1920x1080i@60Hz */
625 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
626 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
627 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300628 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530629 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100630 /* 6 - 1440x480i@60Hz */
631 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1478,
632 1602, 1716, 0, 480, 488, 494, 525, 0,
633 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300634 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530635 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100636 /* 7 - 1440x480i@60Hz */
637 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1478,
638 1602, 1716, 0, 480, 488, 494, 525, 0,
639 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300640 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530641 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100642 /* 8 - 1440x240@60Hz */
643 { DRM_MODE("1440x240", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1478,
644 1602, 1716, 0, 240, 244, 247, 262, 0,
645 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300646 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530647 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100648 /* 9 - 1440x240@60Hz */
649 { DRM_MODE("1440x240", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1478,
650 1602, 1716, 0, 240, 244, 247, 262, 0,
651 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300652 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530653 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100654 /* 10 - 2880x480i@60Hz */
655 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
656 3204, 3432, 0, 480, 488, 494, 525, 0,
657 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300658 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530659 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100660 /* 11 - 2880x480i@60Hz */
661 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
662 3204, 3432, 0, 480, 488, 494, 525, 0,
663 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300664 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530665 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100666 /* 12 - 2880x240@60Hz */
667 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
668 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300669 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530670 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100671 /* 13 - 2880x240@60Hz */
672 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
673 3204, 3432, 0, 240, 244, 247, 262, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300674 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530675 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100676 /* 14 - 1440x480@60Hz */
677 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
678 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300679 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530680 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100681 /* 15 - 1440x480@60Hz */
682 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
683 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300684 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530685 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100686 /* 16 - 1920x1080@60Hz */
687 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
688 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300689 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530690 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100691 /* 17 - 720x576@50Hz */
692 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
693 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300694 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530695 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100696 /* 18 - 720x576@50Hz */
697 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
698 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300699 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530700 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100701 /* 19 - 1280x720@50Hz */
702 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
703 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300704 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530705 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100706 /* 20 - 1920x1080i@50Hz */
707 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
708 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
709 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300710 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530711 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100712 /* 21 - 1440x576i@50Hz */
713 { DRM_MODE("1440x576i", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1464,
714 1590, 1728, 0, 576, 580, 586, 625, 0,
715 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300716 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530717 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100718 /* 22 - 1440x576i@50Hz */
719 { DRM_MODE("1440x576i", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1464,
720 1590, 1728, 0, 576, 580, 586, 625, 0,
721 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300722 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530723 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100724 /* 23 - 1440x288@50Hz */
725 { DRM_MODE("1440x288", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1464,
726 1590, 1728, 0, 288, 290, 293, 312, 0,
727 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300728 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530729 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100730 /* 24 - 1440x288@50Hz */
731 { DRM_MODE("1440x288", DRM_MODE_TYPE_DRIVER, 27000, 1440, 1464,
732 1590, 1728, 0, 288, 290, 293, 312, 0,
733 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300734 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530735 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100736 /* 25 - 2880x576i@50Hz */
737 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
738 3180, 3456, 0, 576, 580, 586, 625, 0,
739 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300740 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530741 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100742 /* 26 - 2880x576i@50Hz */
743 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
744 3180, 3456, 0, 576, 580, 586, 625, 0,
745 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300746 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530747 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100748 /* 27 - 2880x288@50Hz */
749 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
750 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300751 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530752 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100753 /* 28 - 2880x288@50Hz */
754 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
755 3180, 3456, 0, 288, 290, 293, 312, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300756 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530757 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100758 /* 29 - 1440x576@50Hz */
759 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
760 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300761 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530762 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100763 /* 30 - 1440x576@50Hz */
764 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
765 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300766 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530767 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100768 /* 31 - 1920x1080@50Hz */
769 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
770 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300771 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530772 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100773 /* 32 - 1920x1080@24Hz */
774 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
775 2602, 2750, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300776 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530777 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100778 /* 33 - 1920x1080@25Hz */
779 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
780 2492, 2640, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300781 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530782 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100783 /* 34 - 1920x1080@30Hz */
784 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
785 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300786 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530787 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100788 /* 35 - 2880x480@60Hz */
789 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
790 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300791 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530792 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100793 /* 36 - 2880x480@60Hz */
794 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
795 3192, 3432, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300796 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530797 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100798 /* 37 - 2880x576@50Hz */
799 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
800 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300801 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530802 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100803 /* 38 - 2880x576@50Hz */
804 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
805 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300806 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530807 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100808 /* 39 - 1920x1080i@50Hz */
809 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
810 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
811 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300812 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530813 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100814 /* 40 - 1920x1080i@100Hz */
815 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
816 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
817 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300818 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530819 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100820 /* 41 - 1280x720@100Hz */
821 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
822 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300823 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530824 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100825 /* 42 - 720x576@100Hz */
826 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
827 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300828 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530829 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100830 /* 43 - 720x576@100Hz */
831 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
832 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300833 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530834 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100835 /* 44 - 1440x576i@100Hz */
836 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
837 1590, 1728, 0, 576, 580, 586, 625, 0,
838 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300839 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530840 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100841 /* 45 - 1440x576i@100Hz */
842 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
843 1590, 1728, 0, 576, 580, 586, 625, 0,
844 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300845 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530846 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100847 /* 46 - 1920x1080i@120Hz */
848 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
849 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
850 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300851 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530852 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100853 /* 47 - 1280x720@120Hz */
854 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
855 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300856 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530857 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100858 /* 48 - 720x480@120Hz */
859 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
860 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300861 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530862 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100863 /* 49 - 720x480@120Hz */
864 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
865 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300866 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530867 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100868 /* 50 - 1440x480i@120Hz */
869 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1478,
870 1602, 1716, 0, 480, 488, 494, 525, 0,
871 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300872 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530873 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100874 /* 51 - 1440x480i@120Hz */
875 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1478,
876 1602, 1716, 0, 480, 488, 494, 525, 0,
877 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300878 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530879 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100880 /* 52 - 720x576@200Hz */
881 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
882 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300883 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530884 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100885 /* 53 - 720x576@200Hz */
886 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
887 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300888 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530889 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100890 /* 54 - 1440x576i@200Hz */
891 { DRM_MODE("1440x576i", DRM_MODE_TYPE_DRIVER, 108000, 1440, 1464,
892 1590, 1728, 0, 576, 580, 586, 625, 0,
893 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300894 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530895 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100896 /* 55 - 1440x576i@200Hz */
897 { DRM_MODE("1440x576i", DRM_MODE_TYPE_DRIVER, 108000, 1440, 1464,
898 1590, 1728, 0, 576, 580, 586, 625, 0,
899 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300900 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530901 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100902 /* 56 - 720x480@240Hz */
903 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
904 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300905 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530906 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100907 /* 57 - 720x480@240Hz */
908 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
909 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300910 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530911 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100912 /* 58 - 1440x480i@240 */
913 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 108000, 1440, 1478,
914 1602, 1716, 0, 480, 488, 494, 525, 0,
915 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300916 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530917 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100918 /* 59 - 1440x480i@240 */
919 { DRM_MODE("1440x480i", DRM_MODE_TYPE_DRIVER, 108000, 1440, 1478,
920 1602, 1716, 0, 480, 488, 494, 525, 0,
921 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300922 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530923 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100924 /* 60 - 1280x720@24Hz */
925 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
926 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300927 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530928 .vrefresh = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100929 /* 61 - 1280x720@25Hz */
930 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
931 3740, 3960, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300932 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530933 .vrefresh = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100934 /* 62 - 1280x720@30Hz */
935 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
936 3080, 3300, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300937 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530938 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100939 /* 63 - 1920x1080@120Hz */
940 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
941 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300942 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530943 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100944 /* 64 - 1920x1080@100Hz */
945 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
946 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300947 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530948 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100949};
950
Lespiau, Damien7ebe1962013-08-19 16:58:54 +0100951/*
952 * HDMI 1.4 4k modes.
953 */
954static const struct drm_display_mode edid_4k_modes[] = {
955 /* 1 - 3840x2160@30Hz */
956 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
957 3840, 4016, 4104, 4400, 0,
958 2160, 2168, 2178, 2250, 0,
959 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
960 .vrefresh = 30, },
961 /* 2 - 3840x2160@25Hz */
962 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
963 3840, 4896, 4984, 5280, 0,
964 2160, 2168, 2178, 2250, 0,
965 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
966 .vrefresh = 25, },
967 /* 3 - 3840x2160@24Hz */
968 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
969 3840, 5116, 5204, 5500, 0,
970 2160, 2168, 2178, 2250, 0,
971 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
972 .vrefresh = 24, },
973 /* 4 - 4096x2160@24Hz (SMPTE) */
974 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
975 4096, 5116, 5204, 5500, 0,
976 2160, 2168, 2178, 2250, 0,
977 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
978 .vrefresh = 24, },
979};
980
Adam Jackson61e57a82010-03-29 21:43:18 +0000981/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -0800982
Adam Jackson083ae052009-09-23 17:30:45 -0400983static const u8 edid_header[] = {
984 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
985};
Dave Airlief453ba02008-11-07 14:05:41 -0800986
Thierry Redingdb6cf8332014-04-29 11:44:34 +0200987/**
988 * drm_edid_header_is_valid - sanity check the header of the base EDID block
989 * @raw_edid: pointer to raw base EDID block
990 *
991 * Sanity check the header of the base EDID block.
992 *
993 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +0000994 */
995int drm_edid_header_is_valid(const u8 *raw_edid)
996{
997 int i, score = 0;
998
999 for (i = 0; i < sizeof(edid_header); i++)
1000 if (raw_edid[i] == edid_header[i])
1001 score++;
1002
1003 return score;
1004}
1005EXPORT_SYMBOL(drm_edid_header_is_valid);
1006
Adam Jackson47819ba2012-05-30 16:42:39 -04001007static int edid_fixup __read_mostly = 6;
1008module_param_named(edid_fixup, edid_fixup, int, 0400);
1009MODULE_PARM_DESC(edid_fixup,
1010 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001011
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001012/**
1013 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1014 * @raw_edid: pointer to raw EDID block
1015 * @block: type of block to validate (0 for base, extension otherwise)
1016 * @print_bad_edid: if true, dump bad EDID blocks to the console
1017 *
1018 * Validate a base or extension EDID block and optionally dump bad blocks to
1019 * the console.
1020 *
1021 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001022 */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001023bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001024{
Adam Jackson61e57a82010-03-29 21:43:18 +00001025 int i;
Dave Airlief453ba02008-11-07 14:05:41 -08001026 u8 csum = 0;
Adam Jackson61e57a82010-03-29 21:43:18 +00001027 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001028
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001029 if (WARN_ON(!raw_edid))
1030 return false;
1031
Adam Jackson47819ba2012-05-30 16:42:39 -04001032 if (edid_fixup > 8 || edid_fixup < 0)
1033 edid_fixup = 6;
1034
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001035 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001036 int score = drm_edid_header_is_valid(raw_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001037 if (score == 8) ;
Adam Jackson47819ba2012-05-30 16:42:39 -04001038 else if (score >= edid_fixup) {
Adam Jackson61e57a82010-03-29 21:43:18 +00001039 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1040 memcpy(raw_edid, edid_header, sizeof(edid_header));
1041 } else {
1042 goto bad;
1043 }
1044 }
Dave Airlief453ba02008-11-07 14:05:41 -08001045
1046 for (i = 0; i < EDID_LENGTH; i++)
1047 csum += raw_edid[i];
1048 if (csum) {
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001049 if (print_bad_edid) {
1050 DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
1051 }
Adam Jackson4a638b42010-05-25 16:33:09 -04001052
1053 /* allow CEA to slide through, switches mangle this */
1054 if (raw_edid[0] != 0x02)
1055 goto bad;
Dave Airlief453ba02008-11-07 14:05:41 -08001056 }
1057
Adam Jackson61e57a82010-03-29 21:43:18 +00001058 /* per-block-type checks */
1059 switch (raw_edid[0]) {
1060 case 0: /* base */
1061 if (edid->version != 1) {
1062 DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
1063 goto bad;
1064 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001065
Adam Jackson61e57a82010-03-29 21:43:18 +00001066 if (edid->revision > 4)
1067 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1068 break;
1069
1070 default:
1071 break;
1072 }
Adam Jackson47ee4ccf2009-11-23 14:23:05 -05001073
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001074 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001075
1076bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001077 if (print_bad_edid) {
Dave Airlief49dadb2011-06-14 06:13:54 +00001078 printk(KERN_ERR "Raw EDID:\n");
Tormod Volden0aff47f2011-07-05 20:12:53 +00001079 print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
1080 raw_edid, EDID_LENGTH, false);
Dave Airlief453ba02008-11-07 14:05:41 -08001081 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001082 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001083}
Carsten Emdeda0df922012-03-18 22:37:33 +01001084EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001085
1086/**
1087 * drm_edid_is_valid - sanity check EDID data
1088 * @edid: EDID data
1089 *
1090 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001091 *
1092 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001093 */
1094bool drm_edid_is_valid(struct edid *edid)
1095{
1096 int i;
1097 u8 *raw = (u8 *)edid;
1098
1099 if (!edid)
1100 return false;
1101
1102 for (i = 0; i <= edid->extensions; i++)
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001103 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true))
Adam Jackson61e57a82010-03-29 21:43:18 +00001104 return false;
1105
1106 return true;
1107}
Alex Deucher3c537882010-02-05 04:21:19 -05001108EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001109
Adam Jackson61e57a82010-03-29 21:43:18 +00001110#define DDC_SEGMENT_ADDR 0x30
1111/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001112 * drm_do_probe_ddc_edid() - get EDID information via I2C
1113 * @adapter: I2C device adaptor
Daniel Vetterfc668112014-01-21 12:02:26 +01001114 * @buf: EDID data buffer to be filled
1115 * @block: 128 byte EDID block to start fetching from
1116 * @len: EDID data buffer length to fetch
1117 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001118 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001119 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001120 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001121 */
1122static int
1123drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
1124 int block, int len)
1125{
1126 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001127 unsigned char segment = block >> 1;
1128 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001129 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001130
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001131 /*
1132 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001133 * adapter reports EAGAIN. However, we find that bit-banging transfers
1134 * are susceptible to errors under a heavily loaded machine and
1135 * generate spurious NAKs and timeouts. Retrying the transfer
1136 * of the individual block a few times seems to overcome this.
1137 */
1138 do {
1139 struct i2c_msg msgs[] = {
1140 {
Shirish Scd004b32012-08-30 07:04:06 +00001141 .addr = DDC_SEGMENT_ADDR,
1142 .flags = 0,
1143 .len = 1,
1144 .buf = &segment,
1145 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001146 .addr = DDC_ADDR,
1147 .flags = 0,
1148 .len = 1,
1149 .buf = &start,
1150 }, {
1151 .addr = DDC_ADDR,
1152 .flags = I2C_M_RD,
1153 .len = len,
1154 .buf = buf,
1155 }
1156 };
Shirish Scd004b32012-08-30 07:04:06 +00001157
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001158 /*
1159 * Avoid sending the segment addr to not upset non-compliant
1160 * DDC monitors.
1161 */
Shirish Scd004b32012-08-30 07:04:06 +00001162 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1163
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001164 if (ret == -ENXIO) {
1165 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1166 adapter->name);
1167 break;
1168 }
Shirish Scd004b32012-08-30 07:04:06 +00001169 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001170
Shirish Scd004b32012-08-30 07:04:06 +00001171 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001172}
1173
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001174static bool drm_edid_is_zero(u8 *in_edid, int length)
1175{
Akinobu Mita63118032012-11-09 12:10:42 +00001176 if (memchr_inv(in_edid, 0, length))
1177 return false;
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001178
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001179 return true;
1180}
1181
Adam Jackson61e57a82010-03-29 21:43:18 +00001182static u8 *
1183drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
1184{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001185 int i, j = 0, valid_extensions = 0;
Adam Jackson61e57a82010-03-29 21:43:18 +00001186 u8 *block, *new;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001187 bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
Adam Jackson61e57a82010-03-29 21:43:18 +00001188
1189 if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
1190 return NULL;
1191
1192 /* base block fetch */
1193 for (i = 0; i < 4; i++) {
1194 if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH))
1195 goto out;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001196 if (drm_edid_block_valid(block, 0, print_bad_edid))
Adam Jackson61e57a82010-03-29 21:43:18 +00001197 break;
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001198 if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
1199 connector->null_edid_counter++;
1200 goto carp;
1201 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001202 }
1203 if (i == 4)
1204 goto carp;
1205
1206 /* if there's no extensions, we're done */
1207 if (block[0x7e] == 0)
1208 return block;
1209
1210 new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
1211 if (!new)
1212 goto out;
1213 block = new;
1214
1215 for (j = 1; j <= block[0x7e]; j++) {
1216 for (i = 0; i < 4; i++) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001217 if (drm_do_probe_ddc_edid(adapter,
1218 block + (valid_extensions + 1) * EDID_LENGTH,
1219 j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001220 goto out;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001221 if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH, j, print_bad_edid)) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001222 valid_extensions++;
Adam Jackson61e57a82010-03-29 21:43:18 +00001223 break;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001224 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001225 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001226
1227 if (i == 4 && print_bad_edid) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001228 dev_warn(connector->dev->dev,
1229 "%s: Ignoring invalid EDID block %d.\n",
1230 drm_get_connector_name(connector), j);
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001231
1232 connector->bad_edid_counter++;
1233 }
Sam Tygier0ea75e22010-09-23 10:11:01 +01001234 }
1235
1236 if (valid_extensions != block[0x7e]) {
1237 block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
1238 block[0x7e] = valid_extensions;
1239 new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1240 if (!new)
1241 goto out;
1242 block = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001243 }
1244
1245 return block;
1246
1247carp:
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001248 if (print_bad_edid) {
1249 dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
1250 drm_get_connector_name(connector), j);
1251 }
1252 connector->bad_edid_counter++;
Adam Jackson61e57a82010-03-29 21:43:18 +00001253
1254out:
1255 kfree(block);
1256 return NULL;
1257}
1258
1259/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001260 * drm_probe_ddc() - probe DDC presence
1261 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001262 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001263 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001264 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001265bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001266drm_probe_ddc(struct i2c_adapter *adapter)
1267{
1268 unsigned char out;
1269
1270 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1271}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001272EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001273
1274/**
1275 * drm_get_edid - get EDID data, if available
1276 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001277 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001278 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001279 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001280 * attach it to the connector.
1281 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001282 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001283 */
1284struct edid *drm_get_edid(struct drm_connector *connector,
1285 struct i2c_adapter *adapter)
1286{
1287 struct edid *edid = NULL;
1288
1289 if (drm_probe_ddc(adapter))
1290 edid = (struct edid *)drm_do_get_edid(connector, adapter);
1291
Adam Jackson61e57a82010-03-29 21:43:18 +00001292 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001293}
1294EXPORT_SYMBOL(drm_get_edid);
1295
Jani Nikula51f8da52013-09-27 15:08:27 +03001296/**
1297 * drm_edid_duplicate - duplicate an EDID and the extensions
1298 * @edid: EDID to duplicate
1299 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001300 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001301 */
1302struct edid *drm_edid_duplicate(const struct edid *edid)
1303{
1304 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1305}
1306EXPORT_SYMBOL(drm_edid_duplicate);
1307
Adam Jackson61e57a82010-03-29 21:43:18 +00001308/*** EDID parsing ***/
1309
Dave Airlief453ba02008-11-07 14:05:41 -08001310/**
1311 * edid_vendor - match a string against EDID's obfuscated vendor field
1312 * @edid: EDID to match
1313 * @vendor: vendor string
1314 *
1315 * Returns true if @vendor is in @edid, false otherwise
1316 */
1317static bool edid_vendor(struct edid *edid, char *vendor)
1318{
1319 char edid_vendor[3];
1320
1321 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1322 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1323 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001324 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001325
1326 return !strncmp(edid_vendor, vendor, 3);
1327}
1328
1329/**
1330 * edid_get_quirks - return quirk flags for a given EDID
1331 * @edid: EDID to process
1332 *
1333 * This tells subsequent routines what fixes they need to apply.
1334 */
1335static u32 edid_get_quirks(struct edid *edid)
1336{
1337 struct edid_quirk *quirk;
1338 int i;
1339
1340 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1341 quirk = &edid_quirk_list[i];
1342
1343 if (edid_vendor(edid, quirk->vendor) &&
1344 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1345 return quirk->quirks;
1346 }
1347
1348 return 0;
1349}
1350
1351#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001352#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001353
Dave Airlief453ba02008-11-07 14:05:41 -08001354/**
1355 * edid_fixup_preferred - set preferred modes based on quirk list
1356 * @connector: has mode list to fix up
1357 * @quirks: quirks list
1358 *
1359 * Walk the mode list for @connector, clearing the preferred status
1360 * on existing modes and setting it anew for the right mode ala @quirks.
1361 */
1362static void edid_fixup_preferred(struct drm_connector *connector,
1363 u32 quirks)
1364{
1365 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001366 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001367 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001368
1369 if (list_empty(&connector->probed_modes))
1370 return;
1371
1372 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1373 target_refresh = 60;
1374 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1375 target_refresh = 75;
1376
1377 preferred_mode = list_first_entry(&connector->probed_modes,
1378 struct drm_display_mode, head);
1379
1380 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1381 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1382
1383 if (cur_mode == preferred_mode)
1384 continue;
1385
1386 /* Largest mode is preferred */
1387 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1388 preferred_mode = cur_mode;
1389
Alex Deucher339d2022013-08-15 11:42:14 -04001390 cur_vrefresh = cur_mode->vrefresh ?
1391 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1392 preferred_vrefresh = preferred_mode->vrefresh ?
1393 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001394 /* At a given size, try to get closest to target refresh */
1395 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001396 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1397 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001398 preferred_mode = cur_mode;
1399 }
1400 }
1401
1402 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1403}
1404
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001405static bool
1406mode_is_rb(const struct drm_display_mode *mode)
1407{
1408 return (mode->htotal - mode->hdisplay == 160) &&
1409 (mode->hsync_end - mode->hdisplay == 80) &&
1410 (mode->hsync_end - mode->hsync_start == 32) &&
1411 (mode->vsync_start - mode->vdisplay == 3);
1412}
1413
Adam Jackson33c75312012-04-13 16:33:29 -04001414/*
1415 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1416 * @dev: Device to duplicate against
1417 * @hsize: Mode width
1418 * @vsize: Mode height
1419 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001420 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001421 *
1422 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001423 *
1424 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001425 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001426struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001427 int hsize, int vsize, int fresh,
1428 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001429{
Adam Jackson07a5e632009-12-03 17:44:38 -05001430 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001431
Thierry Redinga6b21832012-11-23 15:01:42 +01001432 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001433 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001434 if (hsize != ptr->hdisplay)
1435 continue;
1436 if (vsize != ptr->vdisplay)
1437 continue;
1438 if (fresh != drm_mode_vrefresh(ptr))
1439 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001440 if (rb != mode_is_rb(ptr))
1441 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001442
1443 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001444 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001445
1446 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001447}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001448EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001449
Adam Jacksond1ff6402010-03-29 21:43:26 +00001450typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1451
1452static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001453cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1454{
1455 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001456 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001457 u8 *det_base = ext + d;
1458
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001459 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001460 for (i = 0; i < n; i++)
1461 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1462}
1463
1464static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001465vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1466{
1467 unsigned int i, n = min((int)ext[0x02], 6);
1468 u8 *det_base = ext + 5;
1469
1470 if (ext[0x01] != 1)
1471 return; /* unknown version */
1472
1473 for (i = 0; i < n; i++)
1474 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1475}
1476
1477static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001478drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1479{
1480 int i;
1481 struct edid *edid = (struct edid *)raw_edid;
1482
1483 if (edid == NULL)
1484 return;
1485
1486 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1487 cb(&(edid->detailed_timings[i]), closure);
1488
Adam Jackson4d76a222010-08-03 14:38:17 -04001489 for (i = 1; i <= raw_edid[0x7e]; i++) {
1490 u8 *ext = raw_edid + (i * EDID_LENGTH);
1491 switch (*ext) {
1492 case CEA_EXT:
1493 cea_for_each_detailed_block(ext, cb, closure);
1494 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001495 case VTB_EXT:
1496 vtb_for_each_detailed_block(ext, cb, closure);
1497 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001498 default:
1499 break;
1500 }
1501 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001502}
1503
1504static void
1505is_rb(struct detailed_timing *t, void *data)
1506{
1507 u8 *r = (u8 *)t;
1508 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1509 if (r[15] & 0x10)
1510 *(bool *)data = true;
1511}
1512
1513/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1514static bool
1515drm_monitor_supports_rb(struct edid *edid)
1516{
1517 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001518 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001519 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1520 return ret;
1521 }
1522
1523 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1524}
1525
Adam Jackson7a374352010-03-29 21:43:30 +00001526static void
1527find_gtf2(struct detailed_timing *t, void *data)
1528{
1529 u8 *r = (u8 *)t;
1530 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1531 *(u8 **)data = r;
1532}
1533
1534/* Secondary GTF curve kicks in above some break frequency */
1535static int
1536drm_gtf2_hbreak(struct edid *edid)
1537{
1538 u8 *r = NULL;
1539 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1540 return r ? (r[12] * 2) : 0;
1541}
1542
1543static int
1544drm_gtf2_2c(struct edid *edid)
1545{
1546 u8 *r = NULL;
1547 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1548 return r ? r[13] : 0;
1549}
1550
1551static int
1552drm_gtf2_m(struct edid *edid)
1553{
1554 u8 *r = NULL;
1555 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1556 return r ? (r[15] << 8) + r[14] : 0;
1557}
1558
1559static int
1560drm_gtf2_k(struct edid *edid)
1561{
1562 u8 *r = NULL;
1563 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1564 return r ? r[16] : 0;
1565}
1566
1567static int
1568drm_gtf2_2j(struct edid *edid)
1569{
1570 u8 *r = NULL;
1571 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1572 return r ? r[17] : 0;
1573}
1574
1575/**
1576 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1577 * @edid: EDID block to scan
1578 */
1579static int standard_timing_level(struct edid *edid)
1580{
1581 if (edid->revision >= 2) {
1582 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1583 return LEVEL_CVT;
1584 if (drm_gtf2_hbreak(edid))
1585 return LEVEL_GTF2;
1586 return LEVEL_GTF;
1587 }
1588 return LEVEL_DMT;
1589}
1590
Adam Jackson23425ca2009-09-23 17:30:58 -04001591/*
1592 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1593 * monitors fill with ascii space (0x20) instead.
1594 */
1595static int
1596bad_std_timing(u8 a, u8 b)
1597{
1598 return (a == 0x00 && b == 0x00) ||
1599 (a == 0x01 && b == 0x01) ||
1600 (a == 0x20 && b == 0x20);
1601}
1602
Dave Airlief453ba02008-11-07 14:05:41 -08001603/**
1604 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01001605 * @connector: connector of for the EDID block
1606 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08001607 * @t: standard timing params
1608 *
1609 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08001610 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08001611 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001612static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00001613drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02001614 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08001615{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001616 struct drm_device *dev = connector->dev;
1617 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08001618 int hsize, vsize;
1619 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001620 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
1621 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08001622 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
1623 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00001624 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001625
Adam Jackson23425ca2009-09-23 17:30:58 -04001626 if (bad_std_timing(t->hsize, t->vfreq_aspect))
1627 return NULL;
1628
Zhao Yakui5c612592009-06-22 13:17:10 +08001629 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1630 hsize = t->hsize * 8 + 248;
1631 /* vrefresh_rate = vfreq + 60 */
1632 vrefresh_rate = vfreq + 60;
1633 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04001634 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02001635 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04001636 vsize = hsize;
1637 else
1638 vsize = (hsize * 10) / 16;
1639 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08001640 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001641 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08001642 vsize = (hsize * 4) / 5;
1643 else
1644 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00001645
1646 /* HDTV hack, part 1 */
1647 if (vrefresh_rate == 60 &&
1648 ((hsize == 1360 && vsize == 765) ||
1649 (hsize == 1368 && vsize == 769))) {
1650 hsize = 1366;
1651 vsize = 768;
1652 }
1653
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001654 /*
1655 * If this connector already has a mode for this size and refresh
1656 * rate (because it came from detailed or CVT info), use that
1657 * instead. This way we don't have to guess at interlace or
1658 * reduced blanking.
1659 */
Adam Jackson522032d2010-04-09 16:52:49 +00001660 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001661 if (m->hdisplay == hsize && m->vdisplay == vsize &&
1662 drm_mode_vrefresh(m) == vrefresh_rate)
1663 return NULL;
1664
Adam Jacksona0910c82010-03-29 21:43:28 +00001665 /* HDTV hack, part 2 */
1666 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
1667 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10001668 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001669 mode->hdisplay = 1366;
Adam Jacksona4967de62010-07-28 07:40:32 +10001670 mode->hsync_start = mode->hsync_start - 1;
1671 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08001672 return mode;
1673 }
Adam Jacksona0910c82010-03-29 21:43:28 +00001674
Zhao Yakui559ee212009-09-03 09:33:47 +08001675 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001676 if (drm_monitor_supports_rb(edid)) {
1677 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
1678 true);
1679 if (mode)
1680 return mode;
1681 }
1682 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001683 if (mode)
1684 return mode;
1685
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001686 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08001687 switch (timing_level) {
1688 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08001689 break;
1690 case LEVEL_GTF:
1691 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
1692 break;
Adam Jackson7a374352010-03-29 21:43:30 +00001693 case LEVEL_GTF2:
1694 /*
1695 * This is potentially wrong if there's ever a monitor with
1696 * more than one ranges section, each claiming a different
1697 * secondary GTF curve. Please don't do that.
1698 */
1699 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01001700 if (!mode)
1701 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00001702 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01001703 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00001704 mode = drm_gtf_mode_complex(dev, hsize, vsize,
1705 vrefresh_rate, 0, 0,
1706 drm_gtf2_m(edid),
1707 drm_gtf2_2c(edid),
1708 drm_gtf2_k(edid),
1709 drm_gtf2_2j(edid));
1710 }
1711 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08001712 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10001713 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
1714 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08001715 break;
1716 }
Dave Airlief453ba02008-11-07 14:05:41 -08001717 return mode;
1718}
1719
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001720/*
1721 * EDID is delightfully ambiguous about how interlaced modes are to be
1722 * encoded. Our internal representation is of frame height, but some
1723 * HDTV detailed timings are encoded as field height.
1724 *
1725 * The format list here is from CEA, in frame size. Technically we
1726 * should be checking refresh rate too. Whatever.
1727 */
1728static void
1729drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
1730 struct detailed_pixel_timing *pt)
1731{
1732 int i;
1733 static const struct {
1734 int w, h;
1735 } cea_interlaced[] = {
1736 { 1920, 1080 },
1737 { 720, 480 },
1738 { 1440, 480 },
1739 { 2880, 480 },
1740 { 720, 576 },
1741 { 1440, 576 },
1742 { 2880, 576 },
1743 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001744
1745 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
1746 return;
1747
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04001748 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001749 if ((mode->hdisplay == cea_interlaced[i].w) &&
1750 (mode->vdisplay == cea_interlaced[i].h / 2)) {
1751 mode->vdisplay *= 2;
1752 mode->vsync_start *= 2;
1753 mode->vsync_end *= 2;
1754 mode->vtotal *= 2;
1755 mode->vtotal |= 1;
1756 }
1757 }
1758
1759 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1760}
1761
Dave Airlief453ba02008-11-07 14:05:41 -08001762/**
1763 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1764 * @dev: DRM device (needed to create new mode)
1765 * @edid: EDID block
1766 * @timing: EDID detailed timing info
1767 * @quirks: quirks to apply
1768 *
1769 * An EDID detailed timing block contains enough info for us to create and
1770 * return a new struct drm_display_mode.
1771 */
1772static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1773 struct edid *edid,
1774 struct detailed_timing *timing,
1775 u32 quirks)
1776{
1777 struct drm_display_mode *mode;
1778 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001779 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
1780 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
1781 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
1782 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02001783 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
1784 unsigned hsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x30) << 4 | pt->hsync_pulse_width_lo;
Torsten Duwe16dad1d2013-03-23 15:38:22 +01001785 unsigned vsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc) << 2 | pt->vsync_offset_pulse_width_lo >> 4;
Michel Dänzere14cbee2009-06-23 12:36:32 +02001786 unsigned vsync_pulse_width = (pt->hsync_vsync_offset_pulse_width_hi & 0x3) << 4 | (pt->vsync_offset_pulse_width_lo & 0xf);
Dave Airlief453ba02008-11-07 14:05:41 -08001787
Adam Jacksonfc438962009-06-04 10:20:34 +10001788 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02001789 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10001790 return NULL;
1791
Michel Dänzer0454bea2009-06-15 16:56:07 +02001792 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001793 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001794 return NULL;
1795 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02001796 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001797 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001798 }
1799
Zhao Yakuifcb45612009-10-14 09:11:25 +08001800 /* it is incorrect if hsync/vsync width is zero */
1801 if (!hsync_pulse_width || !vsync_pulse_width) {
1802 DRM_DEBUG_KMS("Incorrect Detailed timing. "
1803 "Wrong Hsync/Vsync pulse width\n");
1804 return NULL;
1805 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001806
1807 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
1808 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
1809 if (!mode)
1810 return NULL;
1811
1812 goto set_size;
1813 }
1814
Dave Airlief453ba02008-11-07 14:05:41 -08001815 mode = drm_mode_create(dev);
1816 if (!mode)
1817 return NULL;
1818
Dave Airlief453ba02008-11-07 14:05:41 -08001819 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02001820 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08001821
Michel Dänzer0454bea2009-06-15 16:56:07 +02001822 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08001823
Michel Dänzer0454bea2009-06-15 16:56:07 +02001824 mode->hdisplay = hactive;
1825 mode->hsync_start = mode->hdisplay + hsync_offset;
1826 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
1827 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08001828
Michel Dänzer0454bea2009-06-15 16:56:07 +02001829 mode->vdisplay = vactive;
1830 mode->vsync_start = mode->vdisplay + vsync_offset;
1831 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
1832 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08001833
Jesse Barnes7064fef2009-11-05 10:12:54 -08001834 /* Some EDIDs have bogus h/vtotal values */
1835 if (mode->hsync_end > mode->htotal)
1836 mode->htotal = mode->hsync_end + 1;
1837 if (mode->vsync_end > mode->vtotal)
1838 mode->vtotal = mode->vsync_end + 1;
1839
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001840 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08001841
1842 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02001843 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08001844 }
1845
Michel Dänzer0454bea2009-06-15 16:56:07 +02001846 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
1847 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
1848 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
1849 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08001850
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001851set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02001852 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
1853 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08001854
1855 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
1856 mode->width_mm *= 10;
1857 mode->height_mm *= 10;
1858 }
1859
1860 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
1861 mode->width_mm = edid->width_cm * 10;
1862 mode->height_mm = edid->height_cm * 10;
1863 }
1864
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001865 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01001866 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001867 drm_mode_set_name(mode);
1868
Dave Airlief453ba02008-11-07 14:05:41 -08001869 return mode;
1870}
1871
Adam Jackson07a5e632009-12-03 17:44:38 -05001872static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001873mode_in_hsync_range(const struct drm_display_mode *mode,
1874 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001875{
1876 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05001877
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001878 hmin = t[7];
1879 if (edid->revision >= 4)
1880 hmin += ((t[4] & 0x04) ? 255 : 0);
1881 hmax = t[8];
1882 if (edid->revision >= 4)
1883 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05001884 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05001885
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001886 return (hsync <= hmax && hsync >= hmin);
1887}
1888
1889static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001890mode_in_vsync_range(const struct drm_display_mode *mode,
1891 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001892{
1893 int vsync, vmin, vmax;
1894
1895 vmin = t[5];
1896 if (edid->revision >= 4)
1897 vmin += ((t[4] & 0x01) ? 255 : 0);
1898 vmax = t[6];
1899 if (edid->revision >= 4)
1900 vmax += ((t[4] & 0x02) ? 255 : 0);
1901 vsync = drm_mode_vrefresh(mode);
1902
1903 return (vsync <= vmax && vsync >= vmin);
1904}
1905
1906static u32
1907range_pixel_clock(struct edid *edid, u8 *t)
1908{
1909 /* unspecified */
1910 if (t[9] == 0 || t[9] == 255)
1911 return 0;
1912
1913 /* 1.4 with CVT support gives us real precision, yay */
1914 if (edid->revision >= 4 && t[10] == 0x04)
1915 return (t[9] * 10000) - ((t[12] >> 2) * 250);
1916
1917 /* 1.3 is pathetic, so fuzz up a bit */
1918 return t[9] * 10000 + 5001;
1919}
1920
Adam Jackson07a5e632009-12-03 17:44:38 -05001921static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001922mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001923 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05001924{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001925 u32 max_clock;
1926 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05001927
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001928 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05001929 return false;
1930
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001931 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05001932 return false;
1933
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001934 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05001935 if (mode->clock > max_clock)
1936 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001937
1938 /* 1.4 max horizontal check */
1939 if (edid->revision >= 4 && t[10] == 0x04)
1940 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
1941 return false;
1942
1943 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
1944 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05001945
1946 return true;
1947}
1948
Takashi Iwai7b668eb2012-07-03 11:22:11 +02001949static bool valid_inferred_mode(const struct drm_connector *connector,
1950 const struct drm_display_mode *mode)
1951{
1952 struct drm_display_mode *m;
1953 bool ok = false;
1954
1955 list_for_each_entry(m, &connector->probed_modes, head) {
1956 if (mode->hdisplay == m->hdisplay &&
1957 mode->vdisplay == m->vdisplay &&
1958 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
1959 return false; /* duplicated */
1960 if (mode->hdisplay <= m->hdisplay &&
1961 mode->vdisplay <= m->vdisplay)
1962 ok = true;
1963 }
1964 return ok;
1965}
1966
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001967static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04001968drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001969 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05001970{
1971 int i, modes = 0;
1972 struct drm_display_mode *newmode;
1973 struct drm_device *dev = connector->dev;
1974
Thierry Redinga6b21832012-11-23 15:01:42 +01001975 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02001976 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
1977 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05001978 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
1979 if (newmode) {
1980 drm_mode_probed_add(connector, newmode);
1981 modes++;
1982 }
1983 }
1984 }
1985
1986 return modes;
1987}
1988
Takashi Iwaic09dedb2012-04-23 17:40:33 +01001989/* fix up 1366x768 mode from 1368x768;
1990 * GFT/CVT can't express 1366 width which isn't dividable by 8
1991 */
1992static void fixup_mode_1366x768(struct drm_display_mode *mode)
1993{
1994 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
1995 mode->hdisplay = 1366;
1996 mode->hsync_start--;
1997 mode->hsync_end--;
1998 drm_mode_set_name(mode);
1999 }
2000}
2001
Adam Jacksonb309bd32012-04-13 16:33:40 -04002002static int
2003drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2004 struct detailed_timing *timing)
2005{
2006 int i, modes = 0;
2007 struct drm_display_mode *newmode;
2008 struct drm_device *dev = connector->dev;
2009
Thierry Redinga6b21832012-11-23 15:01:42 +01002010 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002011 const struct minimode *m = &extra_modes[i];
2012 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002013 if (!newmode)
2014 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002015
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002016 fixup_mode_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002017 if (!mode_in_range(newmode, edid, timing) ||
2018 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002019 drm_mode_destroy(dev, newmode);
2020 continue;
2021 }
2022
2023 drm_mode_probed_add(connector, newmode);
2024 modes++;
2025 }
2026
2027 return modes;
2028}
2029
2030static int
2031drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2032 struct detailed_timing *timing)
2033{
2034 int i, modes = 0;
2035 struct drm_display_mode *newmode;
2036 struct drm_device *dev = connector->dev;
2037 bool rb = drm_monitor_supports_rb(edid);
2038
Thierry Redinga6b21832012-11-23 15:01:42 +01002039 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002040 const struct minimode *m = &extra_modes[i];
2041 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002042 if (!newmode)
2043 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002044
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002045 fixup_mode_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002046 if (!mode_in_range(newmode, edid, timing) ||
2047 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002048 drm_mode_destroy(dev, newmode);
2049 continue;
2050 }
2051
2052 drm_mode_probed_add(connector, newmode);
2053 modes++;
2054 }
2055
2056 return modes;
2057}
2058
Adam Jackson13931572010-08-03 14:38:19 -04002059static void
2060do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002061{
Adam Jackson13931572010-08-03 14:38:19 -04002062 struct detailed_mode_closure *closure = c;
2063 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002064 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002065
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002066 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2067 return;
2068
2069 closure->modes += drm_dmt_modes_for_range(closure->connector,
2070 closure->edid,
2071 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002072
2073 if (!version_greater(closure->edid, 1, 1))
2074 return; /* GTF not defined yet */
2075
2076 switch (range->flags) {
2077 case 0x02: /* secondary gtf, XXX could do more */
2078 case 0x00: /* default gtf */
2079 closure->modes += drm_gtf_modes_for_range(closure->connector,
2080 closure->edid,
2081 timing);
2082 break;
2083 case 0x04: /* cvt, only in 1.4+ */
2084 if (!version_greater(closure->edid, 1, 3))
2085 break;
2086
2087 closure->modes += drm_cvt_modes_for_range(closure->connector,
2088 closure->edid,
2089 timing);
2090 break;
2091 case 0x01: /* just the ranges, no formula */
2092 default:
2093 break;
2094 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002095}
2096
Adam Jackson13931572010-08-03 14:38:19 -04002097static int
2098add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2099{
2100 struct detailed_mode_closure closure = {
2101 connector, edid, 0, 0, 0
2102 };
2103
2104 if (version_greater(edid, 1, 0))
2105 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2106 &closure);
2107
2108 return closure.modes;
2109}
2110
Adam Jackson2255be12010-03-29 21:43:22 +00002111static int
2112drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2113{
2114 int i, j, m, modes = 0;
2115 struct drm_display_mode *mode;
2116 u8 *est = ((u8 *)timing) + 5;
2117
2118 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002119 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002120 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002121 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002122 break;
2123 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002124 mode = drm_mode_find_dmt(connector->dev,
2125 est3_modes[m].w,
2126 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002127 est3_modes[m].r,
2128 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002129 if (mode) {
2130 drm_mode_probed_add(connector, mode);
2131 modes++;
2132 }
2133 }
2134 }
2135 }
2136
2137 return modes;
2138}
2139
Adam Jackson13931572010-08-03 14:38:19 -04002140static void
2141do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002142{
Adam Jackson13931572010-08-03 14:38:19 -04002143 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002144 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002145
2146 if (data->type == EDID_DETAIL_EST_TIMINGS)
2147 closure->modes += drm_est3_modes(closure->connector, timing);
2148}
2149
2150/**
2151 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002152 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002153 * @edid: EDID block to scan
2154 *
2155 * Each EDID block contains a bitmap of the supported "established modes" list
2156 * (defined above). Tease them out and add them to the global modes list.
2157 */
2158static int
2159add_established_modes(struct drm_connector *connector, struct edid *edid)
2160{
Adam Jackson9cf00972009-12-03 17:44:36 -05002161 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002162 unsigned long est_bits = edid->established_timings.t1 |
2163 (edid->established_timings.t2 << 8) |
2164 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2165 int i, modes = 0;
2166 struct detailed_mode_closure closure = {
2167 connector, edid, 0, 0, 0
2168 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002169
Adam Jackson13931572010-08-03 14:38:19 -04002170 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2171 if (est_bits & (1<<i)) {
2172 struct drm_display_mode *newmode;
2173 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2174 if (newmode) {
2175 drm_mode_probed_add(connector, newmode);
2176 modes++;
2177 }
2178 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002179 }
2180
Adam Jackson13931572010-08-03 14:38:19 -04002181 if (version_greater(edid, 1, 0))
2182 drm_for_each_detailed_block((u8 *)edid,
2183 do_established_modes, &closure);
2184
2185 return modes + closure.modes;
2186}
2187
2188static void
2189do_standard_modes(struct detailed_timing *timing, void *c)
2190{
2191 struct detailed_mode_closure *closure = c;
2192 struct detailed_non_pixel *data = &timing->data.other_data;
2193 struct drm_connector *connector = closure->connector;
2194 struct edid *edid = closure->edid;
2195
2196 if (data->type == EDID_DETAIL_STD_MODES) {
2197 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002198 for (i = 0; i < 6; i++) {
2199 struct std_timing *std;
2200 struct drm_display_mode *newmode;
2201
2202 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002203 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002204 if (newmode) {
2205 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002206 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002207 }
2208 }
Adam Jackson13931572010-08-03 14:38:19 -04002209 }
2210}
2211
2212/**
2213 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002214 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002215 * @edid: EDID block to scan
2216 *
2217 * Standard modes can be calculated using the appropriate standard (DMT,
2218 * GTF or CVT. Grab them from @edid and add them to the list.
2219 */
2220static int
2221add_standard_modes(struct drm_connector *connector, struct edid *edid)
2222{
2223 int i, modes = 0;
2224 struct detailed_mode_closure closure = {
2225 connector, edid, 0, 0, 0
2226 };
2227
2228 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2229 struct drm_display_mode *newmode;
2230
2231 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002232 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002233 if (newmode) {
2234 drm_mode_probed_add(connector, newmode);
2235 modes++;
2236 }
2237 }
2238
2239 if (version_greater(edid, 1, 0))
2240 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2241 &closure);
2242
2243 /* XXX should also look for standard codes in VTB blocks */
2244
2245 return modes + closure.modes;
2246}
2247
Dave Airlief453ba02008-11-07 14:05:41 -08002248static int drm_cvt_modes(struct drm_connector *connector,
2249 struct detailed_timing *timing)
2250{
2251 int i, j, modes = 0;
2252 struct drm_display_mode *newmode;
2253 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002254 struct cvt_timing *cvt;
2255 const int rates[] = { 60, 85, 75, 60, 50 };
2256 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002257
2258 for (i = 0; i < 4; i++) {
2259 int uninitialized_var(width), height;
2260 cvt = &(timing->data.other_data.data.cvt[i]);
2261
2262 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002263 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002264
2265 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002266 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002267 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002268 width = height * 4 / 3;
2269 break;
2270 case 0x04:
2271 width = height * 16 / 9;
2272 break;
2273 case 0x08:
2274 width = height * 16 / 10;
2275 break;
2276 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002277 width = height * 15 / 9;
2278 break;
2279 }
2280
2281 for (j = 1; j < 5; j++) {
2282 if (cvt->code[2] & (1 << j)) {
2283 newmode = drm_cvt_mode(dev, width, height,
2284 rates[j], j == 0,
2285 false, false);
2286 if (newmode) {
2287 drm_mode_probed_add(connector, newmode);
2288 modes++;
2289 }
2290 }
2291 }
2292 }
2293
2294 return modes;
2295}
2296
Adam Jackson13931572010-08-03 14:38:19 -04002297static void
2298do_cvt_mode(struct detailed_timing *timing, void *c)
2299{
2300 struct detailed_mode_closure *closure = c;
2301 struct detailed_non_pixel *data = &timing->data.other_data;
2302
2303 if (data->type == EDID_DETAIL_CVT_3BYTE)
2304 closure->modes += drm_cvt_modes(closure->connector, timing);
2305}
Adam Jackson9cf00972009-12-03 17:44:36 -05002306
2307static int
Adam Jackson13931572010-08-03 14:38:19 -04002308add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2309{
2310 struct detailed_mode_closure closure = {
2311 connector, edid, 0, 0, 0
2312 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002313
Adam Jackson13931572010-08-03 14:38:19 -04002314 if (version_greater(edid, 1, 2))
2315 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002316
Adam Jackson13931572010-08-03 14:38:19 -04002317 /* XXX should also look for CVT codes in VTB blocks */
2318
2319 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002320}
2321
Adam Jackson13931572010-08-03 14:38:19 -04002322static void
2323do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002324{
Adam Jackson13931572010-08-03 14:38:19 -04002325 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002326 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002327
2328 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002329 newmode = drm_mode_detailed(closure->connector->dev,
2330 closure->edid, timing,
2331 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002332 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002333 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002334
Adam Jackson13931572010-08-03 14:38:19 -04002335 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002336 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2337
Adam Jackson13931572010-08-03 14:38:19 -04002338 drm_mode_probed_add(closure->connector, newmode);
2339 closure->modes++;
2340 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002341 }
Ma Ling167f3a02009-03-20 14:09:48 +08002342}
2343
Adam Jackson13931572010-08-03 14:38:19 -04002344/*
2345 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002346 * @connector: attached connector
2347 * @edid: EDID block to scan
2348 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002349 */
Adam Jackson13931572010-08-03 14:38:19 -04002350static int
2351add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2352 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002353{
Adam Jackson13931572010-08-03 14:38:19 -04002354 struct detailed_mode_closure closure = {
2355 connector,
2356 edid,
2357 1,
2358 quirks,
2359 0
2360 };
Dave Airlief453ba02008-11-07 14:05:41 -08002361
Adam Jackson13931572010-08-03 14:38:19 -04002362 if (closure.preferred && !version_greater(edid, 1, 3))
2363 closure.preferred =
2364 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002365
Adam Jackson13931572010-08-03 14:38:19 -04002366 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002367
Adam Jackson13931572010-08-03 14:38:19 -04002368 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002369}
Dave Airlief453ba02008-11-07 14:05:41 -08002370
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002371#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002372#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002373#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002374#define SPEAKER_BLOCK 0x04
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002375#define VIDEO_CAPABILITY_BLOCK 0x07
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002376#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002377#define EDID_CEA_YCRCB444 (1 << 5)
2378#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002379#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002380
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002381/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002382 * Search EDID for CEA extension block.
2383 */
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002384static u8 *drm_find_cea_extension(struct edid *edid)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002385{
2386 u8 *edid_ext = NULL;
2387 int i;
2388
2389 /* No EDID or EDID extensions */
2390 if (edid == NULL || edid->extensions == 0)
2391 return NULL;
2392
2393 /* Find CEA extension */
2394 for (i = 0; i < edid->extensions; i++) {
2395 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
2396 if (edid_ext[0] == CEA_EXT)
2397 break;
2398 }
2399
2400 if (i == edid->extensions)
2401 return NULL;
2402
2403 return edid_ext;
2404}
2405
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002406/*
2407 * Calculate the alternate clock for the CEA mode
2408 * (60Hz vs. 59.94Hz etc.)
2409 */
2410static unsigned int
2411cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2412{
2413 unsigned int clock = cea_mode->clock;
2414
2415 if (cea_mode->vrefresh % 6 != 0)
2416 return clock;
2417
2418 /*
2419 * edid_cea_modes contains the 59.94Hz
2420 * variant for 240 and 480 line modes,
2421 * and the 60Hz variant otherwise.
2422 */
2423 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
2424 clock = clock * 1001 / 1000;
2425 else
2426 clock = DIV_ROUND_UP(clock * 1000, 1001);
2427
2428 return clock;
2429}
2430
Thierry Reding18316c82012-12-20 15:41:44 +01002431/**
2432 * drm_match_cea_mode - look for a CEA mode matching given mode
2433 * @to_match: display mode
2434 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002435 * Return: The CEA Video ID (VIC) of the mode or 0 if it isn't a CEA-861
Thierry Reding18316c82012-12-20 15:41:44 +01002436 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002437 */
Thierry Reding18316c82012-12-20 15:41:44 +01002438u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002439{
Stephane Marchesina4799032012-11-09 16:21:05 +00002440 u8 mode;
2441
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002442 if (!to_match->clock)
2443 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002444
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002445 for (mode = 0; mode < ARRAY_SIZE(edid_cea_modes); mode++) {
2446 const struct drm_display_mode *cea_mode = &edid_cea_modes[mode];
2447 unsigned int clock1, clock2;
2448
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002449 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002450 clock1 = cea_mode->clock;
2451 clock2 = cea_mode_alternate_clock(cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002452
2453 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2454 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01002455 drm_mode_equal_no_clocks_no_stereo(to_match, cea_mode))
Stephane Marchesina4799032012-11-09 16:21:05 +00002456 return mode + 1;
2457 }
2458 return 0;
2459}
2460EXPORT_SYMBOL(drm_match_cea_mode);
2461
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302462/**
2463 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2464 * the input VIC from the CEA mode list
2465 * @video_code: ID given to each of the CEA modes
2466 *
2467 * Returns picture aspect ratio
2468 */
2469enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2470{
2471 /* return picture aspect ratio for video_code - 1 to access the
2472 * right array element
2473 */
2474 return edid_cea_modes[video_code-1].picture_aspect_ratio;
2475}
2476EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2477
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002478/*
2479 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2480 * specific block).
2481 *
2482 * It's almost like cea_mode_alternate_clock(), we just need to add an
2483 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2484 * one.
2485 */
2486static unsigned int
2487hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
2488{
2489 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
2490 return hdmi_mode->clock;
2491
2492 return cea_mode_alternate_clock(hdmi_mode);
2493}
2494
2495/*
2496 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2497 * @to_match: display mode
2498 *
2499 * An HDMI mode is one defined in the HDMI vendor specific block.
2500 *
2501 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2502 */
2503static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
2504{
2505 u8 mode;
2506
2507 if (!to_match->clock)
2508 return 0;
2509
2510 for (mode = 0; mode < ARRAY_SIZE(edid_4k_modes); mode++) {
2511 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[mode];
2512 unsigned int clock1, clock2;
2513
2514 /* Make sure to also match alternate clocks */
2515 clock1 = hdmi_mode->clock;
2516 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
2517
2518 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2519 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01002520 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002521 return mode + 1;
2522 }
2523 return 0;
2524}
2525
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002526static int
2527add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
2528{
2529 struct drm_device *dev = connector->dev;
2530 struct drm_display_mode *mode, *tmp;
2531 LIST_HEAD(list);
2532 int modes = 0;
2533
2534 /* Don't add CEA modes if the CEA extension block is missing */
2535 if (!drm_find_cea_extension(edid))
2536 return 0;
2537
2538 /*
2539 * Go through all probed modes and create a new mode
2540 * with the alternate clock for certain CEA modes.
2541 */
2542 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002543 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002544 struct drm_display_mode *newmode;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002545 u8 mode_idx = drm_match_cea_mode(mode) - 1;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002546 unsigned int clock1, clock2;
2547
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002548 if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
2549 cea_mode = &edid_cea_modes[mode_idx];
2550 clock2 = cea_mode_alternate_clock(cea_mode);
2551 } else {
2552 mode_idx = drm_match_hdmi_mode(mode) - 1;
2553 if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
2554 cea_mode = &edid_4k_modes[mode_idx];
2555 clock2 = hdmi_mode_alternate_clock(cea_mode);
2556 }
2557 }
2558
2559 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002560 continue;
2561
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002562 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002563
2564 if (clock1 == clock2)
2565 continue;
2566
2567 if (mode->clock != clock1 && mode->clock != clock2)
2568 continue;
2569
2570 newmode = drm_mode_duplicate(dev, cea_mode);
2571 if (!newmode)
2572 continue;
2573
Damien Lespiau27130212013-09-25 16:45:28 +01002574 /* Carry over the stereo flags */
2575 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
2576
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002577 /*
2578 * The current mode could be either variant. Make
2579 * sure to pick the "other" clock for the new mode.
2580 */
2581 if (mode->clock != clock1)
2582 newmode->clock = clock1;
2583 else
2584 newmode->clock = clock2;
2585
2586 list_add_tail(&newmode->head, &list);
2587 }
2588
2589 list_for_each_entry_safe(mode, tmp, &list, head) {
2590 list_del(&mode->head);
2591 drm_mode_probed_add(connector, mode);
2592 modes++;
2593 }
2594
2595 return modes;
2596}
Stephane Marchesina4799032012-11-09 16:21:05 +00002597
Thomas Woodaff04ac2013-11-29 15:33:27 +00002598static struct drm_display_mode *
2599drm_display_mode_from_vic_index(struct drm_connector *connector,
2600 const u8 *video_db, u8 video_len,
2601 u8 video_index)
2602{
2603 struct drm_device *dev = connector->dev;
2604 struct drm_display_mode *newmode;
2605 u8 cea_mode;
2606
2607 if (video_db == NULL || video_index >= video_len)
2608 return NULL;
2609
2610 /* CEA modes are numbered 1..127 */
2611 cea_mode = (video_db[video_index] & 127) - 1;
2612 if (cea_mode >= ARRAY_SIZE(edid_cea_modes))
2613 return NULL;
2614
2615 newmode = drm_mode_duplicate(dev, &edid_cea_modes[cea_mode]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00002616 if (!newmode)
2617 return NULL;
2618
Thomas Woodaff04ac2013-11-29 15:33:27 +00002619 newmode->vrefresh = 0;
2620
2621 return newmode;
2622}
2623
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002624static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01002625do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002626{
Thomas Woodaff04ac2013-11-29 15:33:27 +00002627 int i, modes = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002628
Thomas Woodaff04ac2013-11-29 15:33:27 +00002629 for (i = 0; i < len; i++) {
2630 struct drm_display_mode *mode;
2631 mode = drm_display_mode_from_vic_index(connector, db, len, i);
2632 if (mode) {
2633 drm_mode_probed_add(connector, mode);
2634 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002635 }
2636 }
2637
2638 return modes;
2639}
2640
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002641struct stereo_mandatory_mode {
2642 int width, height, vrefresh;
2643 unsigned int flags;
2644};
2645
2646static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002647 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2648 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002649 { 1920, 1080, 50,
2650 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
2651 { 1920, 1080, 60,
2652 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002653 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2654 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
2655 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2656 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002657};
2658
2659static bool
2660stereo_match_mandatory(const struct drm_display_mode *mode,
2661 const struct stereo_mandatory_mode *stereo_mode)
2662{
2663 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
2664
2665 return mode->hdisplay == stereo_mode->width &&
2666 mode->vdisplay == stereo_mode->height &&
2667 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
2668 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
2669}
2670
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002671static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
2672{
2673 struct drm_device *dev = connector->dev;
2674 const struct drm_display_mode *mode;
2675 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002676 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002677
2678 INIT_LIST_HEAD(&stereo_modes);
2679
2680 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002681 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
2682 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002683 struct drm_display_mode *new_mode;
2684
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002685 if (!stereo_match_mandatory(mode,
2686 &stereo_mandatory_modes[i]))
2687 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002688
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002689 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002690 new_mode = drm_mode_duplicate(dev, mode);
2691 if (!new_mode)
2692 continue;
2693
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002694 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002695 list_add_tail(&new_mode->head, &stereo_modes);
2696 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002697 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002698 }
2699
2700 list_splice_tail(&stereo_modes, &connector->probed_modes);
2701
2702 return modes;
2703}
2704
Damien Lespiau1deee8d2013-09-25 16:45:24 +01002705static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
2706{
2707 struct drm_device *dev = connector->dev;
2708 struct drm_display_mode *newmode;
2709
2710 vic--; /* VICs start at 1 */
2711 if (vic >= ARRAY_SIZE(edid_4k_modes)) {
2712 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
2713 return 0;
2714 }
2715
2716 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
2717 if (!newmode)
2718 return 0;
2719
2720 drm_mode_probed_add(connector, newmode);
2721
2722 return 1;
2723}
2724
Thomas Woodfbf46022013-10-16 15:58:50 +01002725static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
2726 const u8 *video_db, u8 video_len, u8 video_index)
2727{
Thomas Woodfbf46022013-10-16 15:58:50 +01002728 struct drm_display_mode *newmode;
2729 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01002730
2731 if (structure & (1 << 0)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00002732 newmode = drm_display_mode_from_vic_index(connector, video_db,
2733 video_len,
2734 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01002735 if (newmode) {
2736 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
2737 drm_mode_probed_add(connector, newmode);
2738 modes++;
2739 }
2740 }
2741 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00002742 newmode = drm_display_mode_from_vic_index(connector, video_db,
2743 video_len,
2744 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01002745 if (newmode) {
2746 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2747 drm_mode_probed_add(connector, newmode);
2748 modes++;
2749 }
2750 }
2751 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00002752 newmode = drm_display_mode_from_vic_index(connector, video_db,
2753 video_len,
2754 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01002755 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00002756 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01002757 drm_mode_probed_add(connector, newmode);
2758 modes++;
2759 }
2760 }
2761
2762 return modes;
2763}
2764
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002765/*
2766 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
2767 * @connector: connector corresponding to the HDMI sink
2768 * @db: start of the CEA vendor specific block
2769 * @len: length of the CEA block payload, ie. one can access up to db[len]
2770 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002771 * Parses the HDMI VSDB looking for modes to add to @connector. This function
2772 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002773 */
2774static int
Thomas Woodfbf46022013-10-16 15:58:50 +01002775do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
2776 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002777{
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002778 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01002779 u8 vic_len, hdmi_3d_len = 0;
2780 u16 mask;
2781 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002782
2783 if (len < 8)
2784 goto out;
2785
2786 /* no HDMI_Video_Present */
2787 if (!(db[8] & (1 << 5)))
2788 goto out;
2789
2790 /* Latency_Fields_Present */
2791 if (db[8] & (1 << 7))
2792 offset += 2;
2793
2794 /* I_Latency_Fields_Present */
2795 if (db[8] & (1 << 6))
2796 offset += 2;
2797
2798 /* the declared length is not long enough for the 2 first bytes
2799 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002800 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002801 goto out;
2802
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002803 /* 3D_Present */
2804 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01002805 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002806 modes += add_hdmi_mandatory_stereo_modes(connector);
2807
Thomas Woodfbf46022013-10-16 15:58:50 +01002808 /* 3D_Multi_present */
2809 multi_present = (db[8 + offset] & 0x60) >> 5;
2810 }
2811
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002812 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002813 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01002814 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002815
2816 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002817 u8 vic;
2818
2819 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01002820 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002821 }
Thomas Woodfbf46022013-10-16 15:58:50 +01002822 offset += 1 + vic_len;
2823
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002824 if (multi_present == 1)
2825 multi_len = 2;
2826 else if (multi_present == 2)
2827 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01002828 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002829 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01002830
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002831 if (len < (8 + offset + hdmi_3d_len - 1))
2832 goto out;
2833
2834 if (hdmi_3d_len < multi_len)
2835 goto out;
2836
2837 if (multi_present == 1 || multi_present == 2) {
2838 /* 3D_Structure_ALL */
2839 structure_all = (db[8 + offset] << 8) | db[9 + offset];
2840
2841 /* check if 3D_MASK is present */
2842 if (multi_present == 2)
2843 mask = (db[10 + offset] << 8) | db[11 + offset];
2844 else
2845 mask = 0xffff;
2846
2847 for (i = 0; i < 16; i++) {
2848 if (mask & (1 << i))
2849 modes += add_3d_struct_modes(connector,
2850 structure_all,
2851 video_db,
2852 video_len, i);
2853 }
2854 }
2855
2856 offset += multi_len;
2857
2858 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
2859 int vic_index;
2860 struct drm_display_mode *newmode = NULL;
2861 unsigned int newflag = 0;
2862 bool detail_present;
2863
2864 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
2865
2866 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
2867 break;
2868
2869 /* 2D_VIC_order_X */
2870 vic_index = db[8 + offset + i] >> 4;
2871
2872 /* 3D_Structure_X */
2873 switch (db[8 + offset + i] & 0x0f) {
2874 case 0:
2875 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
2876 break;
2877 case 6:
2878 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2879 break;
2880 case 8:
2881 /* 3D_Detail_X */
2882 if ((db[9 + offset + i] >> 4) == 1)
2883 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
2884 break;
2885 }
2886
2887 if (newflag != 0) {
2888 newmode = drm_display_mode_from_vic_index(connector,
2889 video_db,
2890 video_len,
2891 vic_index);
2892
2893 if (newmode) {
2894 newmode->flags |= newflag;
2895 drm_mode_probed_add(connector, newmode);
2896 modes++;
2897 }
2898 }
2899
2900 if (detail_present)
2901 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01002902 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002903
2904out:
2905 return modes;
2906}
2907
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002908static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002909cea_db_payload_len(const u8 *db)
2910{
2911 return db[0] & 0x1f;
2912}
2913
2914static int
2915cea_db_tag(const u8 *db)
2916{
2917 return db[0] >> 5;
2918}
2919
2920static int
2921cea_revision(const u8 *cea)
2922{
2923 return cea[1];
2924}
2925
2926static int
2927cea_db_offsets(const u8 *cea, int *start, int *end)
2928{
2929 /* Data block offset in CEA extension block */
2930 *start = 4;
2931 *end = cea[2];
2932 if (*end == 0)
2933 *end = 127;
2934 if (*end < 4 || *end > 127)
2935 return -ERANGE;
2936 return 0;
2937}
2938
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002939static bool cea_db_is_hdmi_vsdb(const u8 *db)
2940{
2941 int hdmi_id;
2942
2943 if (cea_db_tag(db) != VENDOR_BLOCK)
2944 return false;
2945
2946 if (cea_db_payload_len(db) < 5)
2947 return false;
2948
2949 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
2950
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01002951 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002952}
2953
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002954#define for_each_cea_db(cea, i, start, end) \
2955 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
2956
2957static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002958add_cea_modes(struct drm_connector *connector, struct edid *edid)
2959{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01002960 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01002961 const u8 *db, *hdmi = NULL, *video = NULL;
2962 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002963 int modes = 0;
2964
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002965 if (cea && cea_revision(cea) >= 3) {
2966 int i, start, end;
2967
2968 if (cea_db_offsets(cea, &start, &end))
2969 return 0;
2970
2971 for_each_cea_db(cea, i, start, end) {
2972 db = &cea[i];
2973 dbl = cea_db_payload_len(db);
2974
Thomas Woodfbf46022013-10-16 15:58:50 +01002975 if (cea_db_tag(db) == VIDEO_BLOCK) {
2976 video = db + 1;
2977 video_len = dbl;
2978 modes += do_cea_modes(connector, video, dbl);
2979 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002980 else if (cea_db_is_hdmi_vsdb(db)) {
2981 hdmi = db;
2982 hdmi_len = dbl;
2983 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002984 }
2985 }
2986
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002987 /*
2988 * We parse the HDMI VSDB after having added the cea modes as we will
2989 * be patching their flags when the sink supports stereo 3D.
2990 */
2991 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01002992 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
2993 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002994
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002995 return modes;
2996}
2997
Wu Fengguang76adaa342011-09-05 14:23:20 +08002998static void
Ville Syrjälä85040722012-08-16 14:55:05 +00002999parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003000{
Ville Syrjälä85040722012-08-16 14:55:05 +00003001 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003002
Ville Syrjälä85040722012-08-16 14:55:05 +00003003 if (len >= 6) {
3004 connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
3005 connector->dvi_dual = db[6] & 1;
3006 }
3007 if (len >= 7)
3008 connector->max_tmds_clock = db[7] * 5;
3009 if (len >= 8) {
3010 connector->latency_present[0] = db[8] >> 7;
3011 connector->latency_present[1] = (db[8] >> 6) & 1;
3012 }
3013 if (len >= 9)
3014 connector->video_latency[0] = db[9];
3015 if (len >= 10)
3016 connector->audio_latency[0] = db[10];
3017 if (len >= 11)
3018 connector->video_latency[1] = db[11];
3019 if (len >= 12)
3020 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003021
Daniel Vetter670c1ef2012-11-22 09:53:55 +01003022 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
Wu Fengguang76adaa342011-09-05 14:23:20 +08003023 "max TMDS clock %d, "
3024 "latency present %d %d, "
3025 "video latency %d %d, "
3026 "audio latency %d %d\n",
3027 connector->dvi_dual,
3028 connector->max_tmds_clock,
3029 (int) connector->latency_present[0],
3030 (int) connector->latency_present[1],
3031 connector->video_latency[0],
3032 connector->video_latency[1],
3033 connector->audio_latency[0],
3034 connector->audio_latency[1]);
3035}
3036
3037static void
3038monitor_name(struct detailed_timing *t, void *data)
3039{
3040 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3041 *(u8 **)data = t->data.other_data.data.str.str;
3042}
3043
3044/**
3045 * drm_edid_to_eld - build ELD from EDID
3046 * @connector: connector corresponding to the HDMI/DP sink
3047 * @edid: EDID to parse
3048 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003049 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3050 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3051 * fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003052 */
3053void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
3054{
3055 uint8_t *eld = connector->eld;
3056 u8 *cea;
3057 u8 *name;
3058 u8 *db;
3059 int sad_count = 0;
3060 int mnl;
3061 int dbl;
3062
3063 memset(eld, 0, sizeof(connector->eld));
3064
3065 cea = drm_find_cea_extension(edid);
3066 if (!cea) {
3067 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3068 return;
3069 }
3070
3071 name = NULL;
3072 drm_for_each_detailed_block((u8 *)edid, monitor_name, &name);
3073 for (mnl = 0; name && mnl < 13; mnl++) {
3074 if (name[mnl] == 0x0a)
3075 break;
3076 eld[20 + mnl] = name[mnl];
3077 }
3078 eld[4] = (cea[1] << 5) | mnl;
3079 DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
3080
3081 eld[0] = 2 << 3; /* ELD version: 2 */
3082
3083 eld[16] = edid->mfg_id[0];
3084 eld[17] = edid->mfg_id[1];
3085 eld[18] = edid->prod_code[0];
3086 eld[19] = edid->prod_code[1];
3087
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003088 if (cea_revision(cea) >= 3) {
3089 int i, start, end;
3090
3091 if (cea_db_offsets(cea, &start, &end)) {
3092 start = 0;
3093 end = 0;
3094 }
3095
3096 for_each_cea_db(cea, i, start, end) {
3097 db = &cea[i];
3098 dbl = cea_db_payload_len(db);
3099
3100 switch (cea_db_tag(db)) {
Christian Schmidta0ab7342011-12-19 20:03:38 +01003101 case AUDIO_BLOCK:
3102 /* Audio Data Block, contains SADs */
3103 sad_count = dbl / 3;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003104 if (dbl >= 1)
3105 memcpy(eld + 20 + mnl, &db[1], dbl);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003106 break;
3107 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003108 /* Speaker Allocation Data Block */
3109 if (dbl >= 1)
3110 eld[7] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003111 break;
3112 case VENDOR_BLOCK:
3113 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003114 if (cea_db_is_hdmi_vsdb(db))
Christian Schmidta0ab7342011-12-19 20:03:38 +01003115 parse_hdmi_vsdb(connector, db);
3116 break;
3117 default:
3118 break;
3119 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003120 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003121 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003122 eld[5] |= sad_count << 4;
3123 eld[2] = (20 + mnl + sad_count * 3 + 3) / 4;
3124
3125 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n", (int)eld[2], sad_count);
3126}
3127EXPORT_SYMBOL(drm_edid_to_eld);
3128
3129/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003130 * drm_edid_to_sad - extracts SADs from EDID
3131 * @edid: EDID to parse
3132 * @sads: pointer that will be set to the extracted SADs
3133 *
3134 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003135 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003136 * Note: The returned pointer needs to be freed using kfree().
3137 *
3138 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003139 */
3140int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3141{
3142 int count = 0;
3143 int i, start, end, dbl;
3144 u8 *cea;
3145
3146 cea = drm_find_cea_extension(edid);
3147 if (!cea) {
3148 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3149 return -ENOENT;
3150 }
3151
3152 if (cea_revision(cea) < 3) {
3153 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3154 return -ENOTSUPP;
3155 }
3156
3157 if (cea_db_offsets(cea, &start, &end)) {
3158 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3159 return -EPROTO;
3160 }
3161
3162 for_each_cea_db(cea, i, start, end) {
3163 u8 *db = &cea[i];
3164
3165 if (cea_db_tag(db) == AUDIO_BLOCK) {
3166 int j;
3167 dbl = cea_db_payload_len(db);
3168
3169 count = dbl / 3; /* SAD is 3B */
3170 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3171 if (!*sads)
3172 return -ENOMEM;
3173 for (j = 0; j < count; j++) {
3174 u8 *sad = &db[1 + j * 3];
3175
3176 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3177 (*sads)[j].channels = sad[0] & 0x7;
3178 (*sads)[j].freq = sad[1] & 0x7F;
3179 (*sads)[j].byte2 = sad[2];
3180 }
3181 break;
3182 }
3183 }
3184
3185 return count;
3186}
3187EXPORT_SYMBOL(drm_edid_to_sad);
3188
3189/**
Alex Deucherd105f472013-07-25 15:55:32 -04003190 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3191 * @edid: EDID to parse
3192 * @sadb: pointer to the speaker block
3193 *
3194 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04003195 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003196 * Note: The returned pointer needs to be freed using kfree().
3197 *
3198 * Return: The number of found Speaker Allocation Blocks or negative number on
3199 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04003200 */
3201int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
3202{
3203 int count = 0;
3204 int i, start, end, dbl;
3205 const u8 *cea;
3206
3207 cea = drm_find_cea_extension(edid);
3208 if (!cea) {
3209 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3210 return -ENOENT;
3211 }
3212
3213 if (cea_revision(cea) < 3) {
3214 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3215 return -ENOTSUPP;
3216 }
3217
3218 if (cea_db_offsets(cea, &start, &end)) {
3219 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3220 return -EPROTO;
3221 }
3222
3223 for_each_cea_db(cea, i, start, end) {
3224 const u8 *db = &cea[i];
3225
3226 if (cea_db_tag(db) == SPEAKER_BLOCK) {
3227 dbl = cea_db_payload_len(db);
3228
3229 /* Speaker Allocation Data Block */
3230 if (dbl == 3) {
3231 *sadb = kmalloc(dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04003232 if (!*sadb)
3233 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04003234 memcpy(*sadb, &db[1], dbl);
3235 count = dbl;
3236 break;
3237 }
3238 }
3239 }
3240
3241 return count;
3242}
3243EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
3244
3245/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003246 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08003247 * @connector: connector associated with the HDMI/DP sink
3248 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003249 *
3250 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3251 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003252 */
3253int drm_av_sync_delay(struct drm_connector *connector,
3254 struct drm_display_mode *mode)
3255{
3256 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
3257 int a, v;
3258
3259 if (!connector->latency_present[0])
3260 return 0;
3261 if (!connector->latency_present[1])
3262 i = 0;
3263
3264 a = connector->audio_latency[i];
3265 v = connector->video_latency[i];
3266
3267 /*
3268 * HDMI/DP sink doesn't support audio or video?
3269 */
3270 if (a == 255 || v == 255)
3271 return 0;
3272
3273 /*
3274 * Convert raw EDID values to millisecond.
3275 * Treat unknown latency as 0ms.
3276 */
3277 if (a)
3278 a = min(2 * (a - 1), 500);
3279 if (v)
3280 v = min(2 * (v - 1), 500);
3281
3282 return max(v - a, 0);
3283}
3284EXPORT_SYMBOL(drm_av_sync_delay);
3285
3286/**
3287 * drm_select_eld - select one ELD from multiple HDMI/DP sinks
3288 * @encoder: the encoder just changed display mode
3289 * @mode: the adjusted display mode
3290 *
3291 * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
3292 * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003293 *
3294 * Return: The connector associated with the first HDMI/DP sink that has ELD
3295 * attached to it.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003296 */
3297struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
3298 struct drm_display_mode *mode)
3299{
3300 struct drm_connector *connector;
3301 struct drm_device *dev = encoder->dev;
3302
3303 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
3304 if (connector->encoder == encoder && connector->eld[0])
3305 return connector;
3306
3307 return NULL;
3308}
3309EXPORT_SYMBOL(drm_select_eld);
3310
Ma Lingf23c20c2009-03-26 19:26:23 +08003311/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003312 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08003313 * @edid: monitor EDID information
3314 *
3315 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003316 *
3317 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08003318 */
3319bool drm_detect_hdmi_monitor(struct edid *edid)
3320{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003321 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003322 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08003323 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08003324
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003325 edid_ext = drm_find_cea_extension(edid);
3326 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003327 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003328
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003329 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003330 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003331
3332 /*
3333 * Because HDMI identifier is in Vendor Specific Block,
3334 * search it from all data blocks of CEA extension.
3335 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003336 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003337 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
3338 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08003339 }
3340
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003341 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003342}
3343EXPORT_SYMBOL(drm_detect_hdmi_monitor);
3344
Dave Airlief453ba02008-11-07 14:05:41 -08003345/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003346 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01003347 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003348 *
3349 * Monitor should have CEA extension block.
3350 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3351 * audio' only. If there is any audio extension block and supported
3352 * audio format, assume at least 'basic audio' support, even if 'basic
3353 * audio' is not defined in EDID.
3354 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003355 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003356 */
3357bool drm_detect_monitor_audio(struct edid *edid)
3358{
3359 u8 *edid_ext;
3360 int i, j;
3361 bool has_audio = false;
3362 int start_offset, end_offset;
3363
3364 edid_ext = drm_find_cea_extension(edid);
3365 if (!edid_ext)
3366 goto end;
3367
3368 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
3369
3370 if (has_audio) {
3371 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3372 goto end;
3373 }
3374
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003375 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3376 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003377
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003378 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3379 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003380 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003381 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003382 DRM_DEBUG_KMS("CEA audio format %d\n",
3383 (edid_ext[i + j] >> 3) & 0xf);
3384 goto end;
3385 }
3386 }
3387end:
3388 return has_audio;
3389}
3390EXPORT_SYMBOL(drm_detect_monitor_audio);
3391
3392/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003393 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01003394 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003395 *
3396 * Check whether the monitor reports the RGB quantization range selection
3397 * as supported. The AVI infoframe can then be used to inform the monitor
3398 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003399 *
3400 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003401 */
3402bool drm_rgb_quant_range_selectable(struct edid *edid)
3403{
3404 u8 *edid_ext;
3405 int i, start, end;
3406
3407 edid_ext = drm_find_cea_extension(edid);
3408 if (!edid_ext)
3409 return false;
3410
3411 if (cea_db_offsets(edid_ext, &start, &end))
3412 return false;
3413
3414 for_each_cea_db(edid_ext, i, start, end) {
3415 if (cea_db_tag(&edid_ext[i]) == VIDEO_CAPABILITY_BLOCK &&
3416 cea_db_payload_len(&edid_ext[i]) == 2) {
3417 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
3418 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
3419 }
3420 }
3421
3422 return false;
3423}
3424EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
3425
3426/**
Jesse Barnes3b112282011-04-15 12:49:23 -07003427 * drm_add_display_info - pull display info out if present
3428 * @edid: EDID data
3429 * @info: display info (attached to connector)
3430 *
3431 * Grab any available display info and stuff it into the drm_display_info
3432 * structure that's part of the connector. Useful for tracking bpp and
3433 * color spaces.
3434 */
3435static void drm_add_display_info(struct edid *edid,
3436 struct drm_display_info *info)
3437{
Jesse Barnesebec9a7b2011-08-03 09:22:54 -07003438 u8 *edid_ext;
3439
Jesse Barnes3b112282011-04-15 12:49:23 -07003440 info->width_mm = edid->width_cm * 10;
3441 info->height_mm = edid->height_cm * 10;
3442
3443 /* driver figures it out in this case */
3444 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07003445 info->color_formats = 0;
Jesse Barnes3b112282011-04-15 12:49:23 -07003446
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003447 if (edid->revision < 3)
Jesse Barnes3b112282011-04-15 12:49:23 -07003448 return;
3449
3450 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
3451 return;
3452
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003453 /* Get data from CEA blocks if present */
3454 edid_ext = drm_find_cea_extension(edid);
3455 if (edid_ext) {
3456 info->cea_rev = edid_ext[1];
3457
3458 /* The existence of a CEA block should imply RGB support */
3459 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3460 if (edid_ext[3] & EDID_CEA_YCRCB444)
3461 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3462 if (edid_ext[3] & EDID_CEA_YCRCB422)
3463 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
3464 }
3465
3466 /* Only defined for 1.4 with digital displays */
3467 if (edid->revision < 4)
3468 return;
3469
Jesse Barnes3b112282011-04-15 12:49:23 -07003470 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
3471 case DRM_EDID_DIGITAL_DEPTH_6:
3472 info->bpc = 6;
3473 break;
3474 case DRM_EDID_DIGITAL_DEPTH_8:
3475 info->bpc = 8;
3476 break;
3477 case DRM_EDID_DIGITAL_DEPTH_10:
3478 info->bpc = 10;
3479 break;
3480 case DRM_EDID_DIGITAL_DEPTH_12:
3481 info->bpc = 12;
3482 break;
3483 case DRM_EDID_DIGITAL_DEPTH_14:
3484 info->bpc = 14;
3485 break;
3486 case DRM_EDID_DIGITAL_DEPTH_16:
3487 info->bpc = 16;
3488 break;
3489 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
3490 default:
3491 info->bpc = 0;
3492 break;
3493 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07003494
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003495 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02003496 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
3497 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3498 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
3499 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Jesse Barnes3b112282011-04-15 12:49:23 -07003500}
3501
3502/**
Dave Airlief453ba02008-11-07 14:05:41 -08003503 * drm_add_edid_modes - add modes from EDID data, if available
3504 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003505 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08003506 *
3507 * Add the specified modes to the connector's mode list.
3508 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003509 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08003510 */
3511int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
3512{
3513 int num_modes = 0;
3514 u32 quirks;
3515
3516 if (edid == NULL) {
3517 return 0;
3518 }
Alex Deucher3c537882010-02-05 04:21:19 -05003519 if (!drm_edid_is_valid(edid)) {
Jordan Crousedcdb1672010-05-27 13:40:25 -06003520 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Dave Airlief453ba02008-11-07 14:05:41 -08003521 drm_get_connector_name(connector));
3522 return 0;
3523 }
3524
3525 quirks = edid_get_quirks(edid);
3526
Adam Jacksonc867df72010-03-29 21:43:21 +00003527 /*
3528 * EDID spec says modes should be preferred in this order:
3529 * - preferred detailed mode
3530 * - other detailed modes from base block
3531 * - detailed modes from extension blocks
3532 * - CVT 3-byte code modes
3533 * - standard timing codes
3534 * - established timing codes
3535 * - modes inferred from GTF or CVT range information
3536 *
Adam Jackson13931572010-08-03 14:38:19 -04003537 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00003538 *
3539 * XXX order for additional mode types in extension blocks?
3540 */
Adam Jackson13931572010-08-03 14:38:19 -04003541 num_modes += add_detailed_modes(connector, edid, quirks);
3542 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00003543 num_modes += add_standard_modes(connector, edid);
3544 num_modes += add_established_modes(connector, edid);
Paulo Zanoni196e0772013-02-15 13:36:27 -02003545 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
3546 num_modes += add_inferred_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003547 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003548 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08003549
3550 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
3551 edid_fixup_preferred(connector, quirks);
3552
Jesse Barnes3b112282011-04-15 12:49:23 -07003553 drm_add_display_info(edid, &connector->display_info);
Dave Airlief453ba02008-11-07 14:05:41 -08003554
Rafał Miłecki49d45a312013-12-07 13:22:42 +01003555 if (quirks & EDID_QUIRK_FORCE_8BPC)
3556 connector->display_info.bpc = 8;
3557
Dave Airlief453ba02008-11-07 14:05:41 -08003558 return num_modes;
3559}
3560EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003561
3562/**
3563 * drm_add_modes_noedid - add modes for the connectors without EDID
3564 * @connector: connector we're probing
3565 * @hdisplay: the horizontal display limit
3566 * @vdisplay: the vertical display limit
3567 *
3568 * Add the specified modes to the connector's mode list. Only when the
3569 * hdisplay/vdisplay is not beyond the given limit, it will be added.
3570 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003571 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003572 */
3573int drm_add_modes_noedid(struct drm_connector *connector,
3574 int hdisplay, int vdisplay)
3575{
3576 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00003577 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003578 struct drm_device *dev = connector->dev;
3579
3580 count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
3581 if (hdisplay < 0)
3582 hdisplay = 0;
3583 if (vdisplay < 0)
3584 vdisplay = 0;
3585
3586 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00003587 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003588 if (hdisplay && vdisplay) {
3589 /*
3590 * Only when two are valid, they will be used to check
3591 * whether the mode should be added to the mode list of
3592 * the connector.
3593 */
3594 if (ptr->hdisplay > hdisplay ||
3595 ptr->vdisplay > vdisplay)
3596 continue;
3597 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05003598 if (drm_mode_vrefresh(ptr) > 61)
3599 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003600 mode = drm_mode_duplicate(dev, ptr);
3601 if (mode) {
3602 drm_mode_probed_add(connector, mode);
3603 num_modes++;
3604 }
3605 }
3606 return num_modes;
3607}
3608EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01003609
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003610/**
3611 * drm_set_preferred_mode - Sets the preferred mode of a connector
3612 * @connector: connector whose mode list should be processed
3613 * @hpref: horizontal resolution of preferred mode
3614 * @vpref: vertical resolution of preferred mode
3615 *
3616 * Marks a mode as preferred if it matches the resolution specified by @hpref
3617 * and @vpref.
3618 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02003619void drm_set_preferred_mode(struct drm_connector *connector,
3620 int hpref, int vpref)
3621{
3622 struct drm_display_mode *mode;
3623
3624 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003625 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01003626 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02003627 mode->type |= DRM_MODE_TYPE_PREFERRED;
3628 }
3629}
3630EXPORT_SYMBOL(drm_set_preferred_mode);
3631
Thierry Reding10a85122012-11-21 15:31:35 +01003632/**
3633 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
3634 * data from a DRM display mode
3635 * @frame: HDMI AVI infoframe
3636 * @mode: DRM display mode
3637 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003638 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01003639 */
3640int
3641drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
3642 const struct drm_display_mode *mode)
3643{
3644 int err;
3645
3646 if (!frame || !mode)
3647 return -EINVAL;
3648
3649 err = hdmi_avi_infoframe_init(frame);
3650 if (err < 0)
3651 return err;
3652
Damien Lespiaubf02db92013-08-06 20:32:22 +01003653 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
3654 frame->pixel_repeat = 1;
3655
Thierry Reding10a85122012-11-21 15:31:35 +01003656 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01003657
3658 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303659
3660 /* Populate picture aspect ratio from CEA mode list */
3661 if (frame->video_code > 0)
3662 frame->picture_aspect = drm_get_cea_aspect_ratio(
3663 frame->video_code);
3664
Thierry Reding10a85122012-11-21 15:31:35 +01003665 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d01802014-02-27 09:19:30 -06003666 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01003667
3668 return 0;
3669}
3670EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003671
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003672static enum hdmi_3d_structure
3673s3d_structure_from_display_mode(const struct drm_display_mode *mode)
3674{
3675 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
3676
3677 switch (layout) {
3678 case DRM_MODE_FLAG_3D_FRAME_PACKING:
3679 return HDMI_3D_STRUCTURE_FRAME_PACKING;
3680 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
3681 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
3682 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
3683 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
3684 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
3685 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
3686 case DRM_MODE_FLAG_3D_L_DEPTH:
3687 return HDMI_3D_STRUCTURE_L_DEPTH;
3688 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
3689 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
3690 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
3691 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
3692 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
3693 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
3694 default:
3695 return HDMI_3D_STRUCTURE_INVALID;
3696 }
3697}
3698
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003699/**
3700 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
3701 * data from a DRM display mode
3702 * @frame: HDMI vendor infoframe
3703 * @mode: DRM display mode
3704 *
3705 * Note that there's is a need to send HDMI vendor infoframes only when using a
3706 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
3707 * function will return -EINVAL, error that can be safely ignored.
3708 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003709 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003710 */
3711int
3712drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
3713 const struct drm_display_mode *mode)
3714{
3715 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003716 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003717 u8 vic;
3718
3719 if (!frame || !mode)
3720 return -EINVAL;
3721
3722 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003723 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
3724
3725 if (!vic && !s3d_flags)
3726 return -EINVAL;
3727
3728 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003729 return -EINVAL;
3730
3731 err = hdmi_vendor_infoframe_init(frame);
3732 if (err < 0)
3733 return err;
3734
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003735 if (vic)
3736 frame->vic = vic;
3737 else
3738 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003739
3740 return 0;
3741}
3742EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);