blob: 2c1d2e49fb6fc0ce6d9d2cf61f0a1b6c4994fb25 [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)
Mario Kleinerbc5b9642014-05-23 21:40:55 +020073/* Force 12bpc */
74#define EDID_QUIRK_FORCE_12BPC (1 << 9)
Alex Deucher3c537882010-02-05 04:21:19 -050075
Adam Jackson13931572010-08-03 14:38:19 -040076struct detailed_mode_closure {
77 struct drm_connector *connector;
78 struct edid *edid;
79 bool preferred;
80 u32 quirks;
81 int modes;
82};
Dave Airlief453ba02008-11-07 14:05:41 -080083
Zhao Yakui5c612592009-06-22 13:17:10 +080084#define LEVEL_DMT 0
85#define LEVEL_GTF 1
Adam Jackson7a374352010-03-29 21:43:30 +000086#define LEVEL_GTF2 2
87#define LEVEL_CVT 3
Zhao Yakui5c612592009-06-22 13:17:10 +080088
Dave Airlief453ba02008-11-07 14:05:41 -080089static struct edid_quirk {
Ian Pilcherc51a3fd62012-04-22 11:40:26 -050090 char vendor[4];
Dave Airlief453ba02008-11-07 14:05:41 -080091 int product_id;
92 u32 quirks;
93} edid_quirk_list[] = {
94 /* Acer AL1706 */
95 { "ACR", 44358, EDID_QUIRK_PREFER_LARGE_60 },
96 /* Acer F51 */
97 { "API", 0x7602, EDID_QUIRK_PREFER_LARGE_60 },
98 /* Unknown Acer */
99 { "ACR", 2423, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
100
101 /* Belinea 10 15 55 */
102 { "MAX", 1516, EDID_QUIRK_PREFER_LARGE_60 },
103 { "MAX", 0x77e, EDID_QUIRK_PREFER_LARGE_60 },
104
105 /* Envision Peripherals, Inc. EN-7100e */
106 { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH },
Adam Jacksonba1163d2010-04-06 16:11:00 +0000107 /* Envision EN2028 */
108 { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 },
Dave Airlief453ba02008-11-07 14:05:41 -0800109
110 /* Funai Electronics PM36B */
111 { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 |
112 EDID_QUIRK_DETAILED_IN_CM },
113
114 /* LG Philips LCD LP154W01-A5 */
115 { "LPL", 0, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
116 { "LPL", 0x2a00, EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE },
117
118 /* Philips 107p5 CRT */
119 { "PHL", 57364, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
120
121 /* Proview AY765C */
122 { "PTS", 765, EDID_QUIRK_FIRST_DETAILED_PREFERRED },
123
124 /* Samsung SyncMaster 205BW. Note: irony */
125 { "SAM", 541, EDID_QUIRK_DETAILED_SYNC_PP },
126 /* Samsung SyncMaster 22[5-6]BW */
127 { "SAM", 596, EDID_QUIRK_PREFER_LARGE_60 },
128 { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 },
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400129
Mario Kleinerbc5b9642014-05-23 21:40:55 +0200130 /* Sony PVM-2541A does up to 12 bpc, but only reports max 8 bpc */
131 { "SNY", 0x2541, EDID_QUIRK_FORCE_12BPC },
132
Adam Jacksonbc42aab2012-05-23 16:26:54 -0400133 /* ViewSonic VA2026w */
134 { "VSC", 5020, EDID_QUIRK_FORCE_REDUCED_BLANKING },
Alex Deucher118bdbd2013-08-12 11:04:29 -0400135
136 /* Medion MD 30217 PG */
137 { "MED", 0x7b8, EDID_QUIRK_PREFER_LARGE_75 },
Rafał Miłecki49d45a312013-12-07 13:22:42 +0100138
139 /* Panel in Samsung NP700G7A-S01PL notebook reports 6bpc */
140 { "SEC", 0xd033, EDID_QUIRK_FORCE_8BPC },
Dave Airlief453ba02008-11-07 14:05:41 -0800141};
142
Thierry Redinga6b21832012-11-23 15:01:42 +0100143/*
144 * Autogenerated from the DMT spec.
145 * This table is copied from xfree86/modes/xf86EdidModes.c.
146 */
147static const struct drm_display_mode drm_dmt_modes[] = {
148 /* 640x350@85Hz */
149 { DRM_MODE("640x350", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
150 736, 832, 0, 350, 382, 385, 445, 0,
151 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
152 /* 640x400@85Hz */
153 { DRM_MODE("640x400", DRM_MODE_TYPE_DRIVER, 31500, 640, 672,
154 736, 832, 0, 400, 401, 404, 445, 0,
155 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
156 /* 720x400@85Hz */
157 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 756,
158 828, 936, 0, 400, 401, 404, 446, 0,
159 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
160 /* 640x480@60Hz */
161 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
162 752, 800, 0, 480, 489, 492, 525, 0,
163 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
164 /* 640x480@72Hz */
165 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
166 704, 832, 0, 480, 489, 492, 520, 0,
167 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
168 /* 640x480@75Hz */
169 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
170 720, 840, 0, 480, 481, 484, 500, 0,
171 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
172 /* 640x480@85Hz */
173 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 36000, 640, 696,
174 752, 832, 0, 480, 481, 484, 509, 0,
175 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
176 /* 800x600@56Hz */
177 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
178 896, 1024, 0, 600, 601, 603, 625, 0,
179 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
180 /* 800x600@60Hz */
181 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
182 968, 1056, 0, 600, 601, 605, 628, 0,
183 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
184 /* 800x600@72Hz */
185 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
186 976, 1040, 0, 600, 637, 643, 666, 0,
187 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
188 /* 800x600@75Hz */
189 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
190 896, 1056, 0, 600, 601, 604, 625, 0,
191 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
192 /* 800x600@85Hz */
193 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 56250, 800, 832,
194 896, 1048, 0, 600, 601, 604, 631, 0,
195 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
196 /* 800x600@120Hz RB */
197 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 73250, 800, 848,
198 880, 960, 0, 600, 603, 607, 636, 0,
199 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
200 /* 848x480@60Hz */
201 { DRM_MODE("848x480", DRM_MODE_TYPE_DRIVER, 33750, 848, 864,
202 976, 1088, 0, 480, 486, 494, 517, 0,
203 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
204 /* 1024x768@43Hz, interlace */
205 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER, 44900, 1024, 1032,
206 1208, 1264, 0, 768, 768, 772, 817, 0,
207 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
208 DRM_MODE_FLAG_INTERLACE) },
209 /* 1024x768@60Hz */
210 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
211 1184, 1344, 0, 768, 771, 777, 806, 0,
212 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
213 /* 1024x768@70Hz */
214 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
215 1184, 1328, 0, 768, 771, 777, 806, 0,
216 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) },
217 /* 1024x768@75Hz */
218 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78750, 1024, 1040,
219 1136, 1312, 0, 768, 769, 772, 800, 0,
220 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
221 /* 1024x768@85Hz */
222 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072,
223 1168, 1376, 0, 768, 769, 772, 808, 0,
224 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
225 /* 1024x768@120Hz RB */
226 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 115500, 1024, 1072,
227 1104, 1184, 0, 768, 771, 775, 813, 0,
228 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
229 /* 1152x864@75Hz */
230 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
231 1344, 1600, 0, 864, 865, 868, 900, 0,
232 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
233 /* 1280x768@60Hz RB */
234 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 68250, 1280, 1328,
235 1360, 1440, 0, 768, 771, 778, 790, 0,
236 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
237 /* 1280x768@60Hz */
238 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 79500, 1280, 1344,
239 1472, 1664, 0, 768, 771, 778, 798, 0,
240 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
241 /* 1280x768@75Hz */
242 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 102250, 1280, 1360,
243 1488, 1696, 0, 768, 771, 778, 805, 0,
244 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
245 /* 1280x768@85Hz */
246 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 117500, 1280, 1360,
247 1496, 1712, 0, 768, 771, 778, 809, 0,
248 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
249 /* 1280x768@120Hz RB */
250 { DRM_MODE("1280x768", DRM_MODE_TYPE_DRIVER, 140250, 1280, 1328,
251 1360, 1440, 0, 768, 771, 778, 813, 0,
252 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
253 /* 1280x800@60Hz RB */
254 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 71000, 1280, 1328,
255 1360, 1440, 0, 800, 803, 809, 823, 0,
256 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
257 /* 1280x800@60Hz */
258 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 83500, 1280, 1352,
259 1480, 1680, 0, 800, 803, 809, 831, 0,
260 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
261 /* 1280x800@75Hz */
262 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 106500, 1280, 1360,
263 1488, 1696, 0, 800, 803, 809, 838, 0,
264 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
265 /* 1280x800@85Hz */
266 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 122500, 1280, 1360,
267 1496, 1712, 0, 800, 803, 809, 843, 0,
268 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
269 /* 1280x800@120Hz RB */
270 { DRM_MODE("1280x800", DRM_MODE_TYPE_DRIVER, 146250, 1280, 1328,
271 1360, 1440, 0, 800, 803, 809, 847, 0,
272 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
273 /* 1280x960@60Hz */
274 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1376,
275 1488, 1800, 0, 960, 961, 964, 1000, 0,
276 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
277 /* 1280x960@85Hz */
278 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1344,
279 1504, 1728, 0, 960, 961, 964, 1011, 0,
280 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
281 /* 1280x960@120Hz RB */
282 { DRM_MODE("1280x960", DRM_MODE_TYPE_DRIVER, 175500, 1280, 1328,
283 1360, 1440, 0, 960, 963, 967, 1017, 0,
284 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
285 /* 1280x1024@60Hz */
286 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 108000, 1280, 1328,
287 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
288 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
289 /* 1280x1024@75Hz */
290 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
291 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
292 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
293 /* 1280x1024@85Hz */
294 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 157500, 1280, 1344,
295 1504, 1728, 0, 1024, 1025, 1028, 1072, 0,
296 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
297 /* 1280x1024@120Hz RB */
298 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 187250, 1280, 1328,
299 1360, 1440, 0, 1024, 1027, 1034, 1084, 0,
300 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
301 /* 1360x768@60Hz */
302 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 85500, 1360, 1424,
303 1536, 1792, 0, 768, 771, 777, 795, 0,
304 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
305 /* 1360x768@120Hz RB */
306 { DRM_MODE("1360x768", DRM_MODE_TYPE_DRIVER, 148250, 1360, 1408,
307 1440, 1520, 0, 768, 771, 776, 813, 0,
308 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
309 /* 1400x1050@60Hz RB */
310 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 101000, 1400, 1448,
311 1480, 1560, 0, 1050, 1053, 1057, 1080, 0,
312 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
313 /* 1400x1050@60Hz */
314 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 121750, 1400, 1488,
315 1632, 1864, 0, 1050, 1053, 1057, 1089, 0,
316 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
317 /* 1400x1050@75Hz */
318 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 156000, 1400, 1504,
319 1648, 1896, 0, 1050, 1053, 1057, 1099, 0,
320 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
321 /* 1400x1050@85Hz */
322 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 179500, 1400, 1504,
323 1656, 1912, 0, 1050, 1053, 1057, 1105, 0,
324 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
325 /* 1400x1050@120Hz RB */
326 { DRM_MODE("1400x1050", DRM_MODE_TYPE_DRIVER, 208000, 1400, 1448,
327 1480, 1560, 0, 1050, 1053, 1057, 1112, 0,
328 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
329 /* 1440x900@60Hz RB */
330 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 88750, 1440, 1488,
331 1520, 1600, 0, 900, 903, 909, 926, 0,
332 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
333 /* 1440x900@60Hz */
334 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 106500, 1440, 1520,
335 1672, 1904, 0, 900, 903, 909, 934, 0,
336 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
337 /* 1440x900@75Hz */
338 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 136750, 1440, 1536,
339 1688, 1936, 0, 900, 903, 909, 942, 0,
340 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
341 /* 1440x900@85Hz */
342 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 157000, 1440, 1544,
343 1696, 1952, 0, 900, 903, 909, 948, 0,
344 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
345 /* 1440x900@120Hz RB */
346 { DRM_MODE("1440x900", DRM_MODE_TYPE_DRIVER, 182750, 1440, 1488,
347 1520, 1600, 0, 900, 903, 909, 953, 0,
348 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
349 /* 1600x1200@60Hz */
350 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 162000, 1600, 1664,
351 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
352 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
353 /* 1600x1200@65Hz */
354 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 175500, 1600, 1664,
355 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
356 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
357 /* 1600x1200@70Hz */
358 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 189000, 1600, 1664,
359 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
360 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
361 /* 1600x1200@75Hz */
362 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 202500, 1600, 1664,
363 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
364 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
365 /* 1600x1200@85Hz */
366 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 229500, 1600, 1664,
367 1856, 2160, 0, 1200, 1201, 1204, 1250, 0,
368 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) },
369 /* 1600x1200@120Hz RB */
370 { DRM_MODE("1600x1200", DRM_MODE_TYPE_DRIVER, 268250, 1600, 1648,
371 1680, 1760, 0, 1200, 1203, 1207, 1271, 0,
372 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
373 /* 1680x1050@60Hz RB */
374 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 119000, 1680, 1728,
375 1760, 1840, 0, 1050, 1053, 1059, 1080, 0,
376 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
377 /* 1680x1050@60Hz */
378 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 146250, 1680, 1784,
379 1960, 2240, 0, 1050, 1053, 1059, 1089, 0,
380 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
381 /* 1680x1050@75Hz */
382 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 187000, 1680, 1800,
383 1976, 2272, 0, 1050, 1053, 1059, 1099, 0,
384 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
385 /* 1680x1050@85Hz */
386 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 214750, 1680, 1808,
387 1984, 2288, 0, 1050, 1053, 1059, 1105, 0,
388 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
389 /* 1680x1050@120Hz RB */
390 { DRM_MODE("1680x1050", DRM_MODE_TYPE_DRIVER, 245500, 1680, 1728,
391 1760, 1840, 0, 1050, 1053, 1059, 1112, 0,
392 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
393 /* 1792x1344@60Hz */
394 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 204750, 1792, 1920,
395 2120, 2448, 0, 1344, 1345, 1348, 1394, 0,
396 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
397 /* 1792x1344@75Hz */
398 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 261000, 1792, 1888,
399 2104, 2456, 0, 1344, 1345, 1348, 1417, 0,
400 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
401 /* 1792x1344@120Hz RB */
402 { DRM_MODE("1792x1344", DRM_MODE_TYPE_DRIVER, 333250, 1792, 1840,
403 1872, 1952, 0, 1344, 1347, 1351, 1423, 0,
404 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
405 /* 1856x1392@60Hz */
406 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 218250, 1856, 1952,
407 2176, 2528, 0, 1392, 1393, 1396, 1439, 0,
408 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
409 /* 1856x1392@75Hz */
410 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 288000, 1856, 1984,
411 2208, 2560, 0, 1392, 1395, 1399, 1500, 0,
412 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
413 /* 1856x1392@120Hz RB */
414 { DRM_MODE("1856x1392", DRM_MODE_TYPE_DRIVER, 356500, 1856, 1904,
415 1936, 2016, 0, 1392, 1395, 1399, 1474, 0,
416 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
417 /* 1920x1200@60Hz RB */
418 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 154000, 1920, 1968,
419 2000, 2080, 0, 1200, 1203, 1209, 1235, 0,
420 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
421 /* 1920x1200@60Hz */
422 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 193250, 1920, 2056,
423 2256, 2592, 0, 1200, 1203, 1209, 1245, 0,
424 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
425 /* 1920x1200@75Hz */
426 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 245250, 1920, 2056,
427 2264, 2608, 0, 1200, 1203, 1209, 1255, 0,
428 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
429 /* 1920x1200@85Hz */
430 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 281250, 1920, 2064,
431 2272, 2624, 0, 1200, 1203, 1209, 1262, 0,
432 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
433 /* 1920x1200@120Hz RB */
434 { DRM_MODE("1920x1200", DRM_MODE_TYPE_DRIVER, 317000, 1920, 1968,
435 2000, 2080, 0, 1200, 1203, 1209, 1271, 0,
436 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
437 /* 1920x1440@60Hz */
438 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 234000, 1920, 2048,
439 2256, 2600, 0, 1440, 1441, 1444, 1500, 0,
440 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
441 /* 1920x1440@75Hz */
442 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2064,
443 2288, 2640, 0, 1440, 1441, 1444, 1500, 0,
444 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
445 /* 1920x1440@120Hz RB */
446 { DRM_MODE("1920x1440", DRM_MODE_TYPE_DRIVER, 380500, 1920, 1968,
447 2000, 2080, 0, 1440, 1443, 1447, 1525, 0,
448 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
449 /* 2560x1600@60Hz RB */
450 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 268500, 2560, 2608,
451 2640, 2720, 0, 1600, 1603, 1609, 1646, 0,
452 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
453 /* 2560x1600@60Hz */
454 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 348500, 2560, 2752,
455 3032, 3504, 0, 1600, 1603, 1609, 1658, 0,
456 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
457 /* 2560x1600@75HZ */
458 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 443250, 2560, 2768,
459 3048, 3536, 0, 1600, 1603, 1609, 1672, 0,
460 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
461 /* 2560x1600@85HZ */
462 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 505250, 2560, 2768,
463 3048, 3536, 0, 1600, 1603, 1609, 1682, 0,
464 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) },
465 /* 2560x1600@120Hz RB */
466 { DRM_MODE("2560x1600", DRM_MODE_TYPE_DRIVER, 552750, 2560, 2608,
467 2640, 2720, 0, 1600, 1603, 1609, 1694, 0,
468 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC) },
469};
470
Ville Syrjäläe7bfa5c2013-10-14 16:44:27 +0300471/*
472 * These more or less come from the DMT spec. The 720x400 modes are
473 * inferred from historical 80x25 practice. The 640x480@67 and 832x624@75
474 * modes are old-school Mac modes. The EDID spec says the 1152x864@75 mode
475 * should be 1152x870, again for the Mac, but instead we use the x864 DMT
476 * mode.
477 *
478 * The DMT modes have been fact-checked; the rest are mild guesses.
479 */
Thierry Redinga6b21832012-11-23 15:01:42 +0100480static const struct drm_display_mode edid_est_modes[] = {
481 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 40000, 800, 840,
482 968, 1056, 0, 600, 601, 605, 628, 0,
483 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@60Hz */
484 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 36000, 800, 824,
485 896, 1024, 0, 600, 601, 603, 625, 0,
486 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@56Hz */
487 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 656,
488 720, 840, 0, 480, 481, 484, 500, 0,
489 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@75Hz */
490 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 31500, 640, 664,
491 704, 832, 0, 480, 489, 491, 520, 0,
492 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@72Hz */
493 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 30240, 640, 704,
494 768, 864, 0, 480, 483, 486, 525, 0,
495 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@67Hz */
496 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25200, 640, 656,
497 752, 800, 0, 480, 490, 492, 525, 0,
498 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 640x480@60Hz */
499 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 35500, 720, 738,
500 846, 900, 0, 400, 421, 423, 449, 0,
501 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 720x400@88Hz */
502 { DRM_MODE("720x400", DRM_MODE_TYPE_DRIVER, 28320, 720, 738,
503 846, 900, 0, 400, 412, 414, 449, 0,
504 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 720x400@70Hz */
505 { DRM_MODE("1280x1024", DRM_MODE_TYPE_DRIVER, 135000, 1280, 1296,
506 1440, 1688, 0, 1024, 1025, 1028, 1066, 0,
507 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1280x1024@75Hz */
508 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 78800, 1024, 1040,
509 1136, 1312, 0, 768, 769, 772, 800, 0,
510 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1024x768@75Hz */
511 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 75000, 1024, 1048,
512 1184, 1328, 0, 768, 771, 777, 806, 0,
513 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@70Hz */
514 { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048,
515 1184, 1344, 0, 768, 771, 777, 806, 0,
516 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 1024x768@60Hz */
517 { DRM_MODE("1024x768i", DRM_MODE_TYPE_DRIVER,44900, 1024, 1032,
518 1208, 1264, 0, 768, 768, 776, 817, 0,
519 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_INTERLACE) }, /* 1024x768@43Hz */
520 { DRM_MODE("832x624", DRM_MODE_TYPE_DRIVER, 57284, 832, 864,
521 928, 1152, 0, 624, 625, 628, 667, 0,
522 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, /* 832x624@75Hz */
523 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 49500, 800, 816,
524 896, 1056, 0, 600, 601, 604, 625, 0,
525 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@75Hz */
526 { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 50000, 800, 856,
527 976, 1040, 0, 600, 637, 643, 666, 0,
528 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 800x600@72Hz */
529 { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216,
530 1344, 1600, 0, 864, 865, 868, 900, 0,
531 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */
532};
533
534struct minimode {
535 short w;
536 short h;
537 short r;
538 short rb;
539};
540
541static const struct minimode est3_modes[] = {
542 /* byte 6 */
543 { 640, 350, 85, 0 },
544 { 640, 400, 85, 0 },
545 { 720, 400, 85, 0 },
546 { 640, 480, 85, 0 },
547 { 848, 480, 60, 0 },
548 { 800, 600, 85, 0 },
549 { 1024, 768, 85, 0 },
550 { 1152, 864, 75, 0 },
551 /* byte 7 */
552 { 1280, 768, 60, 1 },
553 { 1280, 768, 60, 0 },
554 { 1280, 768, 75, 0 },
555 { 1280, 768, 85, 0 },
556 { 1280, 960, 60, 0 },
557 { 1280, 960, 85, 0 },
558 { 1280, 1024, 60, 0 },
559 { 1280, 1024, 85, 0 },
560 /* byte 8 */
561 { 1360, 768, 60, 0 },
562 { 1440, 900, 60, 1 },
563 { 1440, 900, 60, 0 },
564 { 1440, 900, 75, 0 },
565 { 1440, 900, 85, 0 },
566 { 1400, 1050, 60, 1 },
567 { 1400, 1050, 60, 0 },
568 { 1400, 1050, 75, 0 },
569 /* byte 9 */
570 { 1400, 1050, 85, 0 },
571 { 1680, 1050, 60, 1 },
572 { 1680, 1050, 60, 0 },
573 { 1680, 1050, 75, 0 },
574 { 1680, 1050, 85, 0 },
575 { 1600, 1200, 60, 0 },
576 { 1600, 1200, 65, 0 },
577 { 1600, 1200, 70, 0 },
578 /* byte 10 */
579 { 1600, 1200, 75, 0 },
580 { 1600, 1200, 85, 0 },
581 { 1792, 1344, 60, 0 },
Ville Syrjäläc068b322013-10-14 16:44:25 +0300582 { 1792, 1344, 75, 0 },
Thierry Redinga6b21832012-11-23 15:01:42 +0100583 { 1856, 1392, 60, 0 },
584 { 1856, 1392, 75, 0 },
585 { 1920, 1200, 60, 1 },
586 { 1920, 1200, 60, 0 },
587 /* byte 11 */
588 { 1920, 1200, 75, 0 },
589 { 1920, 1200, 85, 0 },
590 { 1920, 1440, 60, 0 },
591 { 1920, 1440, 75, 0 },
592};
593
594static const struct minimode extra_modes[] = {
595 { 1024, 576, 60, 0 },
596 { 1366, 768, 60, 0 },
597 { 1600, 900, 60, 0 },
598 { 1680, 945, 60, 0 },
599 { 1920, 1080, 60, 0 },
600 { 2048, 1152, 60, 0 },
601 { 2048, 1536, 60, 0 },
602};
603
604/*
605 * Probably taken from CEA-861 spec.
606 * This table is converted from xorg's hw/xfree86/modes/xf86EdidModes.c.
607 */
608static const struct drm_display_mode edid_cea_modes[] = {
609 /* 1 - 640x480@60Hz */
610 { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 25175, 640, 656,
611 752, 800, 0, 480, 490, 492, 525, 0,
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 /* 2 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100619 /* 3 - 720x480@60Hz */
620 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 720, 736,
621 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300622 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
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 /* 4 - 1280x720@60Hz */
625 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1390,
626 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300627 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530628 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100629 /* 5 - 1920x1080i@60Hz */
630 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
631 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
632 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300633 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530634 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700635 /* 6 - 720(1440)x480i@60Hz */
636 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
637 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100638 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300639 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530640 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700641 /* 7 - 720(1440)x480i@60Hz */
642 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
643 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100644 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300645 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530646 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700647 /* 8 - 720(1440)x240@60Hz */
648 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
649 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100650 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300651 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530652 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700653 /* 9 - 720(1440)x240@60Hz */
654 { DRM_MODE("720x240", DRM_MODE_TYPE_DRIVER, 13500, 720, 739,
655 801, 858, 0, 240, 244, 247, 262, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100656 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300657 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530658 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100659 /* 10 - 2880x480i@60Hz */
660 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
661 3204, 3432, 0, 480, 488, 494, 525, 0,
662 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300663 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530664 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100665 /* 11 - 2880x480i@60Hz */
666 { DRM_MODE("2880x480i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
667 3204, 3432, 0, 480, 488, 494, 525, 0,
668 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300669 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530670 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100671 /* 12 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100676 /* 13 - 2880x240@60Hz */
677 { DRM_MODE("2880x240", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2956,
678 3204, 3432, 0, 240, 244, 247, 262, 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_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100681 /* 14 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100686 /* 15 - 1440x480@60Hz */
687 { DRM_MODE("1440x480", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1472,
688 1596, 1716, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300689 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
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 /* 16 - 1920x1080@60Hz */
692 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
693 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300694 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530695 .vrefresh = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100696 /* 17 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100701 /* 18 - 720x576@50Hz */
702 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
703 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300704 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
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 /* 19 - 1280x720@50Hz */
707 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 1720,
708 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300709 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530710 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100711 /* 20 - 1920x1080i@50Hz */
712 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
713 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
714 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300715 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530716 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700717 /* 21 - 720(1440)x576i@50Hz */
718 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
719 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100720 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300721 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530722 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700723 /* 22 - 720(1440)x576i@50Hz */
724 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
725 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100726 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300727 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530728 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700729 /* 23 - 720(1440)x288@50Hz */
730 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
731 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100732 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300733 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530734 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700735 /* 24 - 720(1440)x288@50Hz */
736 { DRM_MODE("720x288", DRM_MODE_TYPE_DRIVER, 13500, 720, 732,
737 795, 864, 0, 288, 290, 293, 312, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100738 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300739 DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530740 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100741 /* 25 - 2880x576i@50Hz */
742 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
743 3180, 3456, 0, 576, 580, 586, 625, 0,
744 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300745 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530746 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100747 /* 26 - 2880x576i@50Hz */
748 { DRM_MODE("2880x576i", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
749 3180, 3456, 0, 576, 580, 586, 625, 0,
750 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300751 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530752 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100753 /* 27 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100758 /* 28 - 2880x288@50Hz */
759 { DRM_MODE("2880x288", DRM_MODE_TYPE_DRIVER, 54000, 2880, 2928,
760 3180, 3456, 0, 288, 290, 293, 312, 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_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100763 /* 29 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100768 /* 30 - 1440x576@50Hz */
769 { DRM_MODE("1440x576", DRM_MODE_TYPE_DRIVER, 54000, 1440, 1464,
770 1592, 1728, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300771 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
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 /* 31 - 1920x1080@50Hz */
774 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
775 2492, 2640, 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 = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100778 /* 32 - 1920x1080@24Hz */
779 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2558,
780 2602, 2750, 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 = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100783 /* 33 - 1920x1080@25Hz */
784 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2448,
785 2492, 2640, 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 = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100788 /* 34 - 1920x1080@30Hz */
789 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 1920, 2008,
790 2052, 2200, 0, 1080, 1084, 1089, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300791 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530792 .vrefresh = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100793 /* 35 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100798 /* 36 - 2880x480@60Hz */
799 { DRM_MODE("2880x480", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2944,
800 3192, 3432, 0, 480, 489, 495, 525, 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 = 60, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100803 /* 37 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100808 /* 38 - 2880x576@50Hz */
809 { DRM_MODE("2880x576", DRM_MODE_TYPE_DRIVER, 108000, 2880, 2928,
810 3184, 3456, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300811 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530812 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100813 /* 39 - 1920x1080i@50Hz */
814 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 72000, 1920, 1952,
815 2120, 2304, 0, 1080, 1126, 1136, 1250, 0,
816 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300817 DRM_MODE_FLAG_INTERLACE),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530818 .vrefresh = 50, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100819 /* 40 - 1920x1080i@100Hz */
820 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2448,
821 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
822 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300823 DRM_MODE_FLAG_INTERLACE),
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 /* 41 - 1280x720@100Hz */
826 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1720,
827 1760, 1980, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300828 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530829 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100830 /* 42 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100835 /* 43 - 720x576@100Hz */
836 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
837 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300838 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530839 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700840 /* 44 - 720(1440)x576i@100Hz */
841 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
842 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100843 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700844 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530845 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700846 /* 45 - 720(1440)x576i@100Hz */
847 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 27000, 720, 732,
848 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100849 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Clint Taylor5a11f7f2014-09-26 09:55:24 -0700850 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530851 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100852 /* 46 - 1920x1080i@120Hz */
853 { DRM_MODE("1920x1080i", DRM_MODE_TYPE_DRIVER, 148500, 1920, 2008,
854 2052, 2200, 0, 1080, 1084, 1094, 1125, 0,
855 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300856 DRM_MODE_FLAG_INTERLACE),
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 /* 47 - 1280x720@120Hz */
859 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 148500, 1280, 1390,
860 1430, 1650, 0, 720, 725, 730, 750, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300861 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530862 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100863 /* 48 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100868 /* 49 - 720x480@120Hz */
869 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 54000, 720, 736,
870 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300871 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530872 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700873 /* 50 - 720(1440)x480i@120Hz */
874 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
875 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100876 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300877 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530878 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700879 /* 51 - 720(1440)x480i@120Hz */
880 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 27000, 720, 739,
881 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100882 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300883 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530884 .vrefresh = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100885 /* 52 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100890 /* 53 - 720x576@200Hz */
891 { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 108000, 720, 732,
892 796, 864, 0, 576, 581, 586, 625, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300893 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530894 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700895 /* 54 - 720(1440)x576i@200Hz */
896 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
897 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100898 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300899 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530900 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700901 /* 55 - 720(1440)x576i@200Hz */
902 { DRM_MODE("720x576i", DRM_MODE_TYPE_DRIVER, 54000, 720, 732,
903 795, 864, 0, 576, 580, 586, 625, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100904 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300905 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530906 .vrefresh = 200, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100907 /* 56 - 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_4_3, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100912 /* 57 - 720x480@240Hz */
913 { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 108000, 720, 736,
914 798, 858, 0, 480, 489, 495, 525, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300915 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530916 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700917 /* 58 - 720(1440)x480i@240 */
918 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
919 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100920 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300921 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530922 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_4_3, },
Clint Taylorfb01d282014-09-02 17:03:35 -0700923 /* 59 - 720(1440)x480i@240 */
924 { DRM_MODE("720x480i", DRM_MODE_TYPE_DRIVER, 54000, 720, 739,
925 801, 858, 0, 480, 488, 494, 525, 0,
Thierry Redinga6b21832012-11-23 15:01:42 +0100926 DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC |
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300927 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_DBLCLK),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530928 .vrefresh = 240, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100929 /* 60 - 1280x720@24Hz */
930 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 59400, 1280, 3040,
931 3080, 3300, 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 = 24, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100934 /* 61 - 1280x720@25Hz */
935 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3700,
936 3740, 3960, 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 = 25, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100939 /* 62 - 1280x720@30Hz */
940 { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1280, 3040,
941 3080, 3300, 0, 720, 725, 730, 750, 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 = 30, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100944 /* 63 - 1920x1080@120Hz */
945 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2008,
946 2052, 2200, 0, 1080, 1084, 1089, 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 = 120, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100949 /* 64 - 1920x1080@100Hz */
950 { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 297000, 1920, 2448,
951 2492, 2640, 0, 1080, 1084, 1094, 1125, 0,
Ville Syrjäläee7925b2013-04-24 19:07:17 +0300952 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
Vandana Kannan985e5dc2013-12-19 15:34:07 +0530953 .vrefresh = 100, .picture_aspect_ratio = HDMI_PICTURE_ASPECT_16_9, },
Thierry Redinga6b21832012-11-23 15:01:42 +0100954};
955
Lespiau, Damien7ebe1962013-08-19 16:58:54 +0100956/*
957 * HDMI 1.4 4k modes.
958 */
959static const struct drm_display_mode edid_4k_modes[] = {
960 /* 1 - 3840x2160@30Hz */
961 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
962 3840, 4016, 4104, 4400, 0,
963 2160, 2168, 2178, 2250, 0,
964 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
965 .vrefresh = 30, },
966 /* 2 - 3840x2160@25Hz */
967 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
968 3840, 4896, 4984, 5280, 0,
969 2160, 2168, 2178, 2250, 0,
970 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
971 .vrefresh = 25, },
972 /* 3 - 3840x2160@24Hz */
973 { DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 297000,
974 3840, 5116, 5204, 5500, 0,
975 2160, 2168, 2178, 2250, 0,
976 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
977 .vrefresh = 24, },
978 /* 4 - 4096x2160@24Hz (SMPTE) */
979 { DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 297000,
980 4096, 5116, 5204, 5500, 0,
981 2160, 2168, 2178, 2250, 0,
982 DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC),
983 .vrefresh = 24, },
984};
985
Adam Jackson61e57a82010-03-29 21:43:18 +0000986/*** DDC fetch and block validation ***/
Dave Airlief453ba02008-11-07 14:05:41 -0800987
Adam Jackson083ae052009-09-23 17:30:45 -0400988static const u8 edid_header[] = {
989 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
990};
Dave Airlief453ba02008-11-07 14:05:41 -0800991
Thierry Redingdb6cf8332014-04-29 11:44:34 +0200992/**
993 * drm_edid_header_is_valid - sanity check the header of the base EDID block
994 * @raw_edid: pointer to raw base EDID block
995 *
996 * Sanity check the header of the base EDID block.
997 *
998 * Return: 8 if the header is perfect, down to 0 if it's totally wrong.
Thomas Reim051963d2011-07-29 14:28:57 +0000999 */
1000int drm_edid_header_is_valid(const u8 *raw_edid)
1001{
1002 int i, score = 0;
1003
1004 for (i = 0; i < sizeof(edid_header); i++)
1005 if (raw_edid[i] == edid_header[i])
1006 score++;
1007
1008 return score;
1009}
1010EXPORT_SYMBOL(drm_edid_header_is_valid);
1011
Adam Jackson47819ba2012-05-30 16:42:39 -04001012static int edid_fixup __read_mostly = 6;
1013module_param_named(edid_fixup, edid_fixup, int, 0400);
1014MODULE_PARM_DESC(edid_fixup,
1015 "Minimum number of valid EDID header bytes (0-8, default 6)");
Thomas Reim051963d2011-07-29 14:28:57 +00001016
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001017static int drm_edid_block_checksum(const u8 *raw_edid)
1018{
1019 int i;
1020 u8 csum = 0;
1021 for (i = 0; i < EDID_LENGTH; i++)
1022 csum += raw_edid[i];
1023
1024 return csum;
1025}
1026
Stefan Brünsd6885d62014-11-30 19:57:41 +01001027static bool drm_edid_is_zero(const u8 *in_edid, int length)
1028{
1029 if (memchr_inv(in_edid, 0, length))
1030 return false;
1031
1032 return true;
1033}
1034
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001035/**
1036 * drm_edid_block_valid - Sanity check the EDID block (base or extension)
1037 * @raw_edid: pointer to raw EDID block
1038 * @block: type of block to validate (0 for base, extension otherwise)
1039 * @print_bad_edid: if true, dump bad EDID blocks to the console
1040 *
1041 * Validate a base or extension EDID block and optionally dump bad blocks to
1042 * the console.
1043 *
1044 * Return: True if the block is valid, false otherwise.
Dave Airlief453ba02008-11-07 14:05:41 -08001045 */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001046bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid)
Dave Airlief453ba02008-11-07 14:05:41 -08001047{
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001048 u8 csum;
Adam Jackson61e57a82010-03-29 21:43:18 +00001049 struct edid *edid = (struct edid *)raw_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001050
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001051 if (WARN_ON(!raw_edid))
1052 return false;
1053
Adam Jackson47819ba2012-05-30 16:42:39 -04001054 if (edid_fixup > 8 || edid_fixup < 0)
1055 edid_fixup = 6;
1056
Adam Jacksonf89ec8a2012-04-16 10:40:08 -04001057 if (block == 0) {
Thomas Reim051963d2011-07-29 14:28:57 +00001058 int score = drm_edid_header_is_valid(raw_edid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001059 if (score == 8) ;
Adam Jackson47819ba2012-05-30 16:42:39 -04001060 else if (score >= edid_fixup) {
Adam Jackson61e57a82010-03-29 21:43:18 +00001061 DRM_DEBUG("Fixing EDID header, your hardware may be failing\n");
1062 memcpy(raw_edid, edid_header, sizeof(edid_header));
1063 } else {
1064 goto bad;
1065 }
1066 }
Dave Airlief453ba02008-11-07 14:05:41 -08001067
Stefan Brünsc465bbc2014-11-30 19:57:43 +01001068 csum = drm_edid_block_checksum(raw_edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001069 if (csum) {
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001070 if (print_bad_edid) {
1071 DRM_ERROR("EDID checksum is invalid, remainder is %d\n", csum);
1072 }
Adam Jackson4a638b42010-05-25 16:33:09 -04001073
1074 /* allow CEA to slide through, switches mangle this */
1075 if (raw_edid[0] != 0x02)
1076 goto bad;
Dave Airlief453ba02008-11-07 14:05:41 -08001077 }
1078
Adam Jackson61e57a82010-03-29 21:43:18 +00001079 /* per-block-type checks */
1080 switch (raw_edid[0]) {
1081 case 0: /* base */
1082 if (edid->version != 1) {
1083 DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version);
1084 goto bad;
1085 }
Adam Jackson862b89c2009-11-23 14:23:06 -05001086
Adam Jackson61e57a82010-03-29 21:43:18 +00001087 if (edid->revision > 4)
1088 DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n");
1089 break;
1090
1091 default:
1092 break;
1093 }
Adam Jackson47ee4cc2009-11-23 14:23:05 -05001094
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001095 return true;
Dave Airlief453ba02008-11-07 14:05:41 -08001096
1097bad:
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001098 if (print_bad_edid) {
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001099 if (drm_edid_is_zero(raw_edid, EDID_LENGTH)) {
1100 printk(KERN_ERR "EDID block is all zeroes\n");
1101 } else {
1102 printk(KERN_ERR "Raw EDID:\n");
1103 print_hex_dump(KERN_ERR, " \t", DUMP_PREFIX_NONE, 16, 1,
Tormod Volden0aff47f2011-07-05 20:12:53 +00001104 raw_edid, EDID_LENGTH, false);
Stefan Brünsda4c07b2014-11-30 19:57:42 +01001105 }
Dave Airlief453ba02008-11-07 14:05:41 -08001106 }
Seung-Woo Kimfe2ef782013-07-02 17:57:04 +09001107 return false;
Dave Airlief453ba02008-11-07 14:05:41 -08001108}
Carsten Emdeda0df922012-03-18 22:37:33 +01001109EXPORT_SYMBOL(drm_edid_block_valid);
Adam Jackson61e57a82010-03-29 21:43:18 +00001110
1111/**
1112 * drm_edid_is_valid - sanity check EDID data
1113 * @edid: EDID data
1114 *
1115 * Sanity-check an entire EDID record (including extensions)
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001116 *
1117 * Return: True if the EDID data is valid, false otherwise.
Adam Jackson61e57a82010-03-29 21:43:18 +00001118 */
1119bool drm_edid_is_valid(struct edid *edid)
1120{
1121 int i;
1122 u8 *raw = (u8 *)edid;
1123
1124 if (!edid)
1125 return false;
1126
1127 for (i = 0; i <= edid->extensions; i++)
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001128 if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true))
Adam Jackson61e57a82010-03-29 21:43:18 +00001129 return false;
1130
1131 return true;
1132}
Alex Deucher3c537882010-02-05 04:21:19 -05001133EXPORT_SYMBOL(drm_edid_is_valid);
Dave Airlief453ba02008-11-07 14:05:41 -08001134
Adam Jackson61e57a82010-03-29 21:43:18 +00001135#define DDC_SEGMENT_ADDR 0x30
1136/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001137 * drm_do_probe_ddc_edid() - get EDID information via I2C
1138 * @adapter: I2C device adaptor
Daniel Vetterfc668112014-01-21 12:02:26 +01001139 * @buf: EDID data buffer to be filled
1140 * @block: 128 byte EDID block to start fetching from
1141 * @len: EDID data buffer length to fetch
1142 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001143 * Try to fetch EDID information by calling I2C driver functions.
Daniel Vetterfc668112014-01-21 12:02:26 +01001144 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001145 * Return: 0 on success or -1 on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001146 */
1147static int
1148drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf,
1149 int block, int len)
1150{
1151 unsigned char start = block * EDID_LENGTH;
Shirish Scd004b32012-08-30 07:04:06 +00001152 unsigned char segment = block >> 1;
1153 unsigned char xfers = segment ? 3 : 2;
Chris Wilson4819d2e2011-03-15 11:04:41 +00001154 int ret, retries = 5;
Adam Jackson61e57a82010-03-29 21:43:18 +00001155
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001156 /*
1157 * The core I2C driver will automatically retry the transfer if the
Chris Wilson4819d2e2011-03-15 11:04:41 +00001158 * adapter reports EAGAIN. However, we find that bit-banging transfers
1159 * are susceptible to errors under a heavily loaded machine and
1160 * generate spurious NAKs and timeouts. Retrying the transfer
1161 * of the individual block a few times seems to overcome this.
1162 */
1163 do {
1164 struct i2c_msg msgs[] = {
1165 {
Shirish Scd004b32012-08-30 07:04:06 +00001166 .addr = DDC_SEGMENT_ADDR,
1167 .flags = 0,
1168 .len = 1,
1169 .buf = &segment,
1170 }, {
Chris Wilson4819d2e2011-03-15 11:04:41 +00001171 .addr = DDC_ADDR,
1172 .flags = 0,
1173 .len = 1,
1174 .buf = &start,
1175 }, {
1176 .addr = DDC_ADDR,
1177 .flags = I2C_M_RD,
1178 .len = len,
1179 .buf = buf,
1180 }
1181 };
Shirish Scd004b32012-08-30 07:04:06 +00001182
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001183 /*
1184 * Avoid sending the segment addr to not upset non-compliant
1185 * DDC monitors.
1186 */
Shirish Scd004b32012-08-30 07:04:06 +00001187 ret = i2c_transfer(adapter, &msgs[3 - xfers], xfers);
1188
Eugeni Dodonov9292f372012-01-05 09:34:28 -02001189 if (ret == -ENXIO) {
1190 DRM_DEBUG_KMS("drm: skipping non-existent adapter %s\n",
1191 adapter->name);
1192 break;
1193 }
Shirish Scd004b32012-08-30 07:04:06 +00001194 } while (ret != xfers && --retries);
Adam Jackson61e57a82010-03-29 21:43:18 +00001195
Shirish Scd004b32012-08-30 07:04:06 +00001196 return ret == xfers ? 0 : -1;
Adam Jackson61e57a82010-03-29 21:43:18 +00001197}
1198
1199static u8 *
1200drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
1201{
Sam Tygier0ea75e22010-09-23 10:11:01 +01001202 int i, j = 0, valid_extensions = 0;
Adam Jackson61e57a82010-03-29 21:43:18 +00001203 u8 *block, *new;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001204 bool print_bad_edid = !connector->bad_edid_counter || (drm_debug & DRM_UT_KMS);
Adam Jackson61e57a82010-03-29 21:43:18 +00001205
1206 if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
1207 return NULL;
1208
1209 /* base block fetch */
1210 for (i = 0; i < 4; i++) {
1211 if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH))
1212 goto out;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001213 if (drm_edid_block_valid(block, 0, print_bad_edid))
Adam Jackson61e57a82010-03-29 21:43:18 +00001214 break;
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001215 if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
1216 connector->null_edid_counter++;
1217 goto carp;
1218 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001219 }
1220 if (i == 4)
1221 goto carp;
1222
1223 /* if there's no extensions, we're done */
1224 if (block[0x7e] == 0)
1225 return block;
1226
1227 new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL);
1228 if (!new)
1229 goto out;
1230 block = new;
1231
1232 for (j = 1; j <= block[0x7e]; j++) {
1233 for (i = 0; i < 4; i++) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001234 if (drm_do_probe_ddc_edid(adapter,
1235 block + (valid_extensions + 1) * EDID_LENGTH,
1236 j, EDID_LENGTH))
Adam Jackson61e57a82010-03-29 21:43:18 +00001237 goto out;
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001238 if (drm_edid_block_valid(block + (valid_extensions + 1) * EDID_LENGTH, j, print_bad_edid)) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001239 valid_extensions++;
Adam Jackson61e57a82010-03-29 21:43:18 +00001240 break;
Sam Tygier0ea75e22010-09-23 10:11:01 +01001241 }
Adam Jackson61e57a82010-03-29 21:43:18 +00001242 }
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001243
1244 if (i == 4 && print_bad_edid) {
Sam Tygier0ea75e22010-09-23 10:11:01 +01001245 dev_warn(connector->dev->dev,
1246 "%s: Ignoring invalid EDID block %d.\n",
Jani Nikula25933822014-06-03 14:56:20 +03001247 connector->name, j);
Maarten Lankhorstf934ec8c2013-01-29 14:27:39 +01001248
1249 connector->bad_edid_counter++;
1250 }
Sam Tygier0ea75e22010-09-23 10:11:01 +01001251 }
1252
1253 if (valid_extensions != block[0x7e]) {
1254 block[EDID_LENGTH-1] += block[0x7e] - valid_extensions;
1255 block[0x7e] = valid_extensions;
1256 new = krealloc(block, (valid_extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1257 if (!new)
1258 goto out;
1259 block = new;
Adam Jackson61e57a82010-03-29 21:43:18 +00001260 }
1261
1262 return block;
1263
1264carp:
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001265 if (print_bad_edid) {
1266 dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03001267 connector->name, j);
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001268 }
1269 connector->bad_edid_counter++;
Adam Jackson61e57a82010-03-29 21:43:18 +00001270
1271out:
1272 kfree(block);
1273 return NULL;
1274}
1275
1276/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001277 * drm_probe_ddc() - probe DDC presence
1278 * @adapter: I2C adapter to probe
Adam Jackson61e57a82010-03-29 21:43:18 +00001279 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001280 * Return: True on success, false on failure.
Adam Jackson61e57a82010-03-29 21:43:18 +00001281 */
Adam Jacksonfbff4692012-09-18 10:58:47 -04001282bool
Adam Jackson61e57a82010-03-29 21:43:18 +00001283drm_probe_ddc(struct i2c_adapter *adapter)
1284{
1285 unsigned char out;
1286
1287 return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0);
1288}
Adam Jacksonfbff4692012-09-18 10:58:47 -04001289EXPORT_SYMBOL(drm_probe_ddc);
Adam Jackson61e57a82010-03-29 21:43:18 +00001290
1291/**
1292 * drm_get_edid - get EDID data, if available
1293 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001294 * @adapter: I2C adapter to use for DDC
Adam Jackson61e57a82010-03-29 21:43:18 +00001295 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001296 * Poke the given I2C channel to grab EDID data if possible. If found,
Adam Jackson61e57a82010-03-29 21:43:18 +00001297 * attach it to the connector.
1298 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001299 * Return: Pointer to valid EDID or NULL if we couldn't find any.
Adam Jackson61e57a82010-03-29 21:43:18 +00001300 */
1301struct edid *drm_get_edid(struct drm_connector *connector,
1302 struct i2c_adapter *adapter)
1303{
1304 struct edid *edid = NULL;
1305
1306 if (drm_probe_ddc(adapter))
1307 edid = (struct edid *)drm_do_get_edid(connector, adapter);
1308
Adam Jackson61e57a82010-03-29 21:43:18 +00001309 return edid;
Adam Jackson61e57a82010-03-29 21:43:18 +00001310}
1311EXPORT_SYMBOL(drm_get_edid);
1312
Jani Nikula51f8da52013-09-27 15:08:27 +03001313/**
1314 * drm_edid_duplicate - duplicate an EDID and the extensions
1315 * @edid: EDID to duplicate
1316 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001317 * Return: Pointer to duplicated EDID or NULL on allocation failure.
Jani Nikula51f8da52013-09-27 15:08:27 +03001318 */
1319struct edid *drm_edid_duplicate(const struct edid *edid)
1320{
1321 return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL);
1322}
1323EXPORT_SYMBOL(drm_edid_duplicate);
1324
Adam Jackson61e57a82010-03-29 21:43:18 +00001325/*** EDID parsing ***/
1326
Dave Airlief453ba02008-11-07 14:05:41 -08001327/**
1328 * edid_vendor - match a string against EDID's obfuscated vendor field
1329 * @edid: EDID to match
1330 * @vendor: vendor string
1331 *
1332 * Returns true if @vendor is in @edid, false otherwise
1333 */
1334static bool edid_vendor(struct edid *edid, char *vendor)
1335{
1336 char edid_vendor[3];
1337
1338 edid_vendor[0] = ((edid->mfg_id[0] & 0x7c) >> 2) + '@';
1339 edid_vendor[1] = (((edid->mfg_id[0] & 0x3) << 3) |
1340 ((edid->mfg_id[1] & 0xe0) >> 5)) + '@';
Dave Airlie16456c82009-04-03 09:10:33 +10001341 edid_vendor[2] = (edid->mfg_id[1] & 0x1f) + '@';
Dave Airlief453ba02008-11-07 14:05:41 -08001342
1343 return !strncmp(edid_vendor, vendor, 3);
1344}
1345
1346/**
1347 * edid_get_quirks - return quirk flags for a given EDID
1348 * @edid: EDID to process
1349 *
1350 * This tells subsequent routines what fixes they need to apply.
1351 */
1352static u32 edid_get_quirks(struct edid *edid)
1353{
1354 struct edid_quirk *quirk;
1355 int i;
1356
1357 for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
1358 quirk = &edid_quirk_list[i];
1359
1360 if (edid_vendor(edid, quirk->vendor) &&
1361 (EDID_PRODUCT_ID(edid) == quirk->product_id))
1362 return quirk->quirks;
1363 }
1364
1365 return 0;
1366}
1367
1368#define MODE_SIZE(m) ((m)->hdisplay * (m)->vdisplay)
Alex Deucher339d2022013-08-15 11:42:14 -04001369#define MODE_REFRESH_DIFF(c,t) (abs((c) - (t)))
Dave Airlief453ba02008-11-07 14:05:41 -08001370
Dave Airlief453ba02008-11-07 14:05:41 -08001371/**
1372 * edid_fixup_preferred - set preferred modes based on quirk list
1373 * @connector: has mode list to fix up
1374 * @quirks: quirks list
1375 *
1376 * Walk the mode list for @connector, clearing the preferred status
1377 * on existing modes and setting it anew for the right mode ala @quirks.
1378 */
1379static void edid_fixup_preferred(struct drm_connector *connector,
1380 u32 quirks)
1381{
1382 struct drm_display_mode *t, *cur_mode, *preferred_mode;
Dave Airlief8906072008-12-18 16:59:02 +10001383 int target_refresh = 0;
Alex Deucher339d2022013-08-15 11:42:14 -04001384 int cur_vrefresh, preferred_vrefresh;
Dave Airlief453ba02008-11-07 14:05:41 -08001385
1386 if (list_empty(&connector->probed_modes))
1387 return;
1388
1389 if (quirks & EDID_QUIRK_PREFER_LARGE_60)
1390 target_refresh = 60;
1391 if (quirks & EDID_QUIRK_PREFER_LARGE_75)
1392 target_refresh = 75;
1393
1394 preferred_mode = list_first_entry(&connector->probed_modes,
1395 struct drm_display_mode, head);
1396
1397 list_for_each_entry_safe(cur_mode, t, &connector->probed_modes, head) {
1398 cur_mode->type &= ~DRM_MODE_TYPE_PREFERRED;
1399
1400 if (cur_mode == preferred_mode)
1401 continue;
1402
1403 /* Largest mode is preferred */
1404 if (MODE_SIZE(cur_mode) > MODE_SIZE(preferred_mode))
1405 preferred_mode = cur_mode;
1406
Alex Deucher339d2022013-08-15 11:42:14 -04001407 cur_vrefresh = cur_mode->vrefresh ?
1408 cur_mode->vrefresh : drm_mode_vrefresh(cur_mode);
1409 preferred_vrefresh = preferred_mode->vrefresh ?
1410 preferred_mode->vrefresh : drm_mode_vrefresh(preferred_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08001411 /* At a given size, try to get closest to target refresh */
1412 if ((MODE_SIZE(cur_mode) == MODE_SIZE(preferred_mode)) &&
Alex Deucher339d2022013-08-15 11:42:14 -04001413 MODE_REFRESH_DIFF(cur_vrefresh, target_refresh) <
1414 MODE_REFRESH_DIFF(preferred_vrefresh, target_refresh)) {
Dave Airlief453ba02008-11-07 14:05:41 -08001415 preferred_mode = cur_mode;
1416 }
1417 }
1418
1419 preferred_mode->type |= DRM_MODE_TYPE_PREFERRED;
1420}
1421
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001422static bool
1423mode_is_rb(const struct drm_display_mode *mode)
1424{
1425 return (mode->htotal - mode->hdisplay == 160) &&
1426 (mode->hsync_end - mode->hdisplay == 80) &&
1427 (mode->hsync_end - mode->hsync_start == 32) &&
1428 (mode->vsync_start - mode->vdisplay == 3);
1429}
1430
Adam Jackson33c75312012-04-13 16:33:29 -04001431/*
1432 * drm_mode_find_dmt - Create a copy of a mode if present in DMT
1433 * @dev: Device to duplicate against
1434 * @hsize: Mode width
1435 * @vsize: Mode height
1436 * @fresh: Mode refresh rate
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001437 * @rb: Mode reduced-blanking-ness
Adam Jackson33c75312012-04-13 16:33:29 -04001438 *
1439 * Walk the DMT mode list looking for a match for the given parameters.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02001440 *
1441 * Return: A newly allocated copy of the mode, or NULL if not found.
Adam Jackson33c75312012-04-13 16:33:29 -04001442 */
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001443struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001444 int hsize, int vsize, int fresh,
1445 bool rb)
Zhao Yakui559ee212009-09-03 09:33:47 +08001446{
Adam Jackson07a5e632009-12-03 17:44:38 -05001447 int i;
Zhao Yakui559ee212009-09-03 09:33:47 +08001448
Thierry Redinga6b21832012-11-23 15:01:42 +01001449 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001450 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001451 if (hsize != ptr->hdisplay)
1452 continue;
1453 if (vsize != ptr->vdisplay)
1454 continue;
1455 if (fresh != drm_mode_vrefresh(ptr))
1456 continue;
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001457 if (rb != mode_is_rb(ptr))
1458 continue;
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001459
1460 return drm_mode_duplicate(dev, ptr);
Zhao Yakui559ee212009-09-03 09:33:47 +08001461 }
Adam Jacksonf8b46a02012-04-13 16:33:30 -04001462
1463 return NULL;
Zhao Yakui559ee212009-09-03 09:33:47 +08001464}
Dave Airlie1d42bbc2010-05-07 05:02:30 +00001465EXPORT_SYMBOL(drm_mode_find_dmt);
Adam Jackson23425ca2009-09-23 17:30:58 -04001466
Adam Jacksond1ff6402010-03-29 21:43:26 +00001467typedef void detailed_cb(struct detailed_timing *timing, void *closure);
1468
1469static void
Adam Jackson4d76a222010-08-03 14:38:17 -04001470cea_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1471{
1472 int i, n = 0;
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001473 u8 d = ext[0x02];
Adam Jackson4d76a222010-08-03 14:38:17 -04001474 u8 *det_base = ext + d;
1475
Christian Schmidt4966b2a2011-12-19 20:03:43 +01001476 n = (127 - d) / 18;
Adam Jackson4d76a222010-08-03 14:38:17 -04001477 for (i = 0; i < n; i++)
1478 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1479}
1480
1481static void
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001482vtb_for_each_detailed_block(u8 *ext, detailed_cb *cb, void *closure)
1483{
1484 unsigned int i, n = min((int)ext[0x02], 6);
1485 u8 *det_base = ext + 5;
1486
1487 if (ext[0x01] != 1)
1488 return; /* unknown version */
1489
1490 for (i = 0; i < n; i++)
1491 cb((struct detailed_timing *)(det_base + 18 * i), closure);
1492}
1493
1494static void
Adam Jacksond1ff6402010-03-29 21:43:26 +00001495drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure)
1496{
1497 int i;
1498 struct edid *edid = (struct edid *)raw_edid;
1499
1500 if (edid == NULL)
1501 return;
1502
1503 for (i = 0; i < EDID_DETAILED_TIMINGS; i++)
1504 cb(&(edid->detailed_timings[i]), closure);
1505
Adam Jackson4d76a222010-08-03 14:38:17 -04001506 for (i = 1; i <= raw_edid[0x7e]; i++) {
1507 u8 *ext = raw_edid + (i * EDID_LENGTH);
1508 switch (*ext) {
1509 case CEA_EXT:
1510 cea_for_each_detailed_block(ext, cb, closure);
1511 break;
Adam Jacksoncbba98f2010-08-03 14:38:18 -04001512 case VTB_EXT:
1513 vtb_for_each_detailed_block(ext, cb, closure);
1514 break;
Adam Jackson4d76a222010-08-03 14:38:17 -04001515 default:
1516 break;
1517 }
1518 }
Adam Jacksond1ff6402010-03-29 21:43:26 +00001519}
1520
1521static void
1522is_rb(struct detailed_timing *t, void *data)
1523{
1524 u8 *r = (u8 *)t;
1525 if (r[3] == EDID_DETAIL_MONITOR_RANGE)
1526 if (r[15] & 0x10)
1527 *(bool *)data = true;
1528}
1529
1530/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */
1531static bool
1532drm_monitor_supports_rb(struct edid *edid)
1533{
1534 if (edid->revision >= 4) {
Daniel Vetterb196a492012-06-19 11:33:06 +02001535 bool ret = false;
Adam Jacksond1ff6402010-03-29 21:43:26 +00001536 drm_for_each_detailed_block((u8 *)edid, is_rb, &ret);
1537 return ret;
1538 }
1539
1540 return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0);
1541}
1542
Adam Jackson7a374352010-03-29 21:43:30 +00001543static void
1544find_gtf2(struct detailed_timing *t, void *data)
1545{
1546 u8 *r = (u8 *)t;
1547 if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02)
1548 *(u8 **)data = r;
1549}
1550
1551/* Secondary GTF curve kicks in above some break frequency */
1552static int
1553drm_gtf2_hbreak(struct edid *edid)
1554{
1555 u8 *r = NULL;
1556 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1557 return r ? (r[12] * 2) : 0;
1558}
1559
1560static int
1561drm_gtf2_2c(struct edid *edid)
1562{
1563 u8 *r = NULL;
1564 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1565 return r ? r[13] : 0;
1566}
1567
1568static int
1569drm_gtf2_m(struct edid *edid)
1570{
1571 u8 *r = NULL;
1572 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1573 return r ? (r[15] << 8) + r[14] : 0;
1574}
1575
1576static int
1577drm_gtf2_k(struct edid *edid)
1578{
1579 u8 *r = NULL;
1580 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1581 return r ? r[16] : 0;
1582}
1583
1584static int
1585drm_gtf2_2j(struct edid *edid)
1586{
1587 u8 *r = NULL;
1588 drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r);
1589 return r ? r[17] : 0;
1590}
1591
1592/**
1593 * standard_timing_level - get std. timing level(CVT/GTF/DMT)
1594 * @edid: EDID block to scan
1595 */
1596static int standard_timing_level(struct edid *edid)
1597{
1598 if (edid->revision >= 2) {
1599 if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF))
1600 return LEVEL_CVT;
1601 if (drm_gtf2_hbreak(edid))
1602 return LEVEL_GTF2;
1603 return LEVEL_GTF;
1604 }
1605 return LEVEL_DMT;
1606}
1607
Adam Jackson23425ca2009-09-23 17:30:58 -04001608/*
1609 * 0 is reserved. The spec says 0x01 fill for unused timings. Some old
1610 * monitors fill with ascii space (0x20) instead.
1611 */
1612static int
1613bad_std_timing(u8 a, u8 b)
1614{
1615 return (a == 0x00 && b == 0x00) ||
1616 (a == 0x01 && b == 0x01) ||
1617 (a == 0x20 && b == 0x20);
1618}
1619
Dave Airlief453ba02008-11-07 14:05:41 -08001620/**
1621 * drm_mode_std - convert standard mode info (width, height, refresh) into mode
Daniel Vetterfc668112014-01-21 12:02:26 +01001622 * @connector: connector of for the EDID block
1623 * @edid: EDID block to scan
Dave Airlief453ba02008-11-07 14:05:41 -08001624 * @t: standard timing params
1625 *
1626 * Take the standard timing params (in this case width, aspect, and refresh)
Zhao Yakui5c612592009-06-22 13:17:10 +08001627 * and convert them into a real mode using CVT/GTF/DMT.
Dave Airlief453ba02008-11-07 14:05:41 -08001628 */
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001629static struct drm_display_mode *
Adam Jackson7a374352010-03-29 21:43:30 +00001630drm_mode_std(struct drm_connector *connector, struct edid *edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02001631 struct std_timing *t)
Dave Airlief453ba02008-11-07 14:05:41 -08001632{
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001633 struct drm_device *dev = connector->dev;
1634 struct drm_display_mode *m, *mode = NULL;
Zhao Yakui5c612592009-06-22 13:17:10 +08001635 int hsize, vsize;
1636 int vrefresh_rate;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001637 unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK)
1638 >> EDID_TIMING_ASPECT_SHIFT;
Zhao Yakui5c612592009-06-22 13:17:10 +08001639 unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK)
1640 >> EDID_TIMING_VFREQ_SHIFT;
Adam Jackson7a374352010-03-29 21:43:30 +00001641 int timing_level = standard_timing_level(edid);
Dave Airlief453ba02008-11-07 14:05:41 -08001642
Adam Jackson23425ca2009-09-23 17:30:58 -04001643 if (bad_std_timing(t->hsize, t->vfreq_aspect))
1644 return NULL;
1645
Zhao Yakui5c612592009-06-22 13:17:10 +08001646 /* According to the EDID spec, the hdisplay = hsize * 8 + 248 */
1647 hsize = t->hsize * 8 + 248;
1648 /* vrefresh_rate = vfreq + 60 */
1649 vrefresh_rate = vfreq + 60;
1650 /* the vdisplay is calculated based on the aspect ratio */
Adam Jacksonf066a172009-09-23 17:31:21 -04001651 if (aspect_ratio == 0) {
Thierry Reding464fdec2014-04-29 11:44:33 +02001652 if (edid->revision < 3)
Adam Jacksonf066a172009-09-23 17:31:21 -04001653 vsize = hsize;
1654 else
1655 vsize = (hsize * 10) / 16;
1656 } else if (aspect_ratio == 1)
Dave Airlief453ba02008-11-07 14:05:41 -08001657 vsize = (hsize * 3) / 4;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001658 else if (aspect_ratio == 2)
Dave Airlief453ba02008-11-07 14:05:41 -08001659 vsize = (hsize * 4) / 5;
1660 else
1661 vsize = (hsize * 9) / 16;
Adam Jacksona0910c82010-03-29 21:43:28 +00001662
1663 /* HDTV hack, part 1 */
1664 if (vrefresh_rate == 60 &&
1665 ((hsize == 1360 && vsize == 765) ||
1666 (hsize == 1368 && vsize == 769))) {
1667 hsize = 1366;
1668 vsize = 768;
1669 }
1670
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001671 /*
1672 * If this connector already has a mode for this size and refresh
1673 * rate (because it came from detailed or CVT info), use that
1674 * instead. This way we don't have to guess at interlace or
1675 * reduced blanking.
1676 */
Adam Jackson522032d2010-04-09 16:52:49 +00001677 list_for_each_entry(m, &connector->probed_modes, head)
Adam Jackson7ca6adb2010-03-29 21:43:29 +00001678 if (m->hdisplay == hsize && m->vdisplay == vsize &&
1679 drm_mode_vrefresh(m) == vrefresh_rate)
1680 return NULL;
1681
Adam Jacksona0910c82010-03-29 21:43:28 +00001682 /* HDTV hack, part 2 */
1683 if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) {
1684 mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0,
Dave Airlied50ba252009-09-23 14:44:08 +10001685 false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001686 mode->hdisplay = 1366;
Adam Jacksona4967de2010-07-28 07:40:32 +10001687 mode->hsync_start = mode->hsync_start - 1;
1688 mode->hsync_end = mode->hsync_end - 1;
Zhao Yakui559ee212009-09-03 09:33:47 +08001689 return mode;
1690 }
Adam Jacksona0910c82010-03-29 21:43:28 +00001691
Zhao Yakui559ee212009-09-03 09:33:47 +08001692 /* check whether it can be found in default mode table */
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001693 if (drm_monitor_supports_rb(edid)) {
1694 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate,
1695 true);
1696 if (mode)
1697 return mode;
1698 }
1699 mode = drm_mode_find_dmt(dev, hsize, vsize, vrefresh_rate, false);
Zhao Yakui559ee212009-09-03 09:33:47 +08001700 if (mode)
1701 return mode;
1702
Adam Jacksonf6e252b2012-04-13 16:33:31 -04001703 /* okay, generate it */
Zhao Yakui5c612592009-06-22 13:17:10 +08001704 switch (timing_level) {
1705 case LEVEL_DMT:
Zhao Yakui5c612592009-06-22 13:17:10 +08001706 break;
1707 case LEVEL_GTF:
1708 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
1709 break;
Adam Jackson7a374352010-03-29 21:43:30 +00001710 case LEVEL_GTF2:
1711 /*
1712 * This is potentially wrong if there's ever a monitor with
1713 * more than one ranges section, each claiming a different
1714 * secondary GTF curve. Please don't do that.
1715 */
1716 mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01001717 if (!mode)
1718 return NULL;
Adam Jackson7a374352010-03-29 21:43:30 +00001719 if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) {
Sascha Haueraefd3302012-02-01 11:38:21 +01001720 drm_mode_destroy(dev, mode);
Adam Jackson7a374352010-03-29 21:43:30 +00001721 mode = drm_gtf_mode_complex(dev, hsize, vsize,
1722 vrefresh_rate, 0, 0,
1723 drm_gtf2_m(edid),
1724 drm_gtf2_2c(edid),
1725 drm_gtf2_k(edid),
1726 drm_gtf2_2j(edid));
1727 }
1728 break;
Zhao Yakui5c612592009-06-22 13:17:10 +08001729 case LEVEL_CVT:
Dave Airlied50ba252009-09-23 14:44:08 +10001730 mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0,
1731 false);
Zhao Yakui5c612592009-06-22 13:17:10 +08001732 break;
1733 }
Dave Airlief453ba02008-11-07 14:05:41 -08001734 return mode;
1735}
1736
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001737/*
1738 * EDID is delightfully ambiguous about how interlaced modes are to be
1739 * encoded. Our internal representation is of frame height, but some
1740 * HDTV detailed timings are encoded as field height.
1741 *
1742 * The format list here is from CEA, in frame size. Technically we
1743 * should be checking refresh rate too. Whatever.
1744 */
1745static void
1746drm_mode_do_interlace_quirk(struct drm_display_mode *mode,
1747 struct detailed_pixel_timing *pt)
1748{
1749 int i;
1750 static const struct {
1751 int w, h;
1752 } cea_interlaced[] = {
1753 { 1920, 1080 },
1754 { 720, 480 },
1755 { 1440, 480 },
1756 { 2880, 480 },
1757 { 720, 576 },
1758 { 1440, 576 },
1759 { 2880, 576 },
1760 };
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001761
1762 if (!(pt->misc & DRM_EDID_PT_INTERLACED))
1763 return;
1764
Kulikov Vasiliy3c581412010-06-28 15:54:52 +04001765 for (i = 0; i < ARRAY_SIZE(cea_interlaced); i++) {
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001766 if ((mode->hdisplay == cea_interlaced[i].w) &&
1767 (mode->vdisplay == cea_interlaced[i].h / 2)) {
1768 mode->vdisplay *= 2;
1769 mode->vsync_start *= 2;
1770 mode->vsync_end *= 2;
1771 mode->vtotal *= 2;
1772 mode->vtotal |= 1;
1773 }
1774 }
1775
1776 mode->flags |= DRM_MODE_FLAG_INTERLACE;
1777}
1778
Dave Airlief453ba02008-11-07 14:05:41 -08001779/**
1780 * drm_mode_detailed - create a new mode from an EDID detailed timing section
1781 * @dev: DRM device (needed to create new mode)
1782 * @edid: EDID block
1783 * @timing: EDID detailed timing info
1784 * @quirks: quirks to apply
1785 *
1786 * An EDID detailed timing block contains enough info for us to create and
1787 * return a new struct drm_display_mode.
1788 */
1789static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev,
1790 struct edid *edid,
1791 struct detailed_timing *timing,
1792 u32 quirks)
1793{
1794 struct drm_display_mode *mode;
1795 struct detailed_pixel_timing *pt = &timing->data.pixel_data;
Michel Dänzer0454bea2009-06-15 16:56:07 +02001796 unsigned hactive = (pt->hactive_hblank_hi & 0xf0) << 4 | pt->hactive_lo;
1797 unsigned vactive = (pt->vactive_vblank_hi & 0xf0) << 4 | pt->vactive_lo;
1798 unsigned hblank = (pt->hactive_hblank_hi & 0xf) << 8 | pt->hblank_lo;
1799 unsigned vblank = (pt->vactive_vblank_hi & 0xf) << 8 | pt->vblank_lo;
Michel Dänzere14cbee2009-06-23 12:36:32 +02001800 unsigned hsync_offset = (pt->hsync_vsync_offset_pulse_width_hi & 0xc0) << 2 | pt->hsync_offset_lo;
1801 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 +01001802 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 +02001803 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 -08001804
Adam Jacksonfc438962009-06-04 10:20:34 +10001805 /* ignore tiny modes */
Michel Dänzer0454bea2009-06-15 16:56:07 +02001806 if (hactive < 64 || vactive < 64)
Adam Jacksonfc438962009-06-04 10:20:34 +10001807 return NULL;
1808
Michel Dänzer0454bea2009-06-15 16:56:07 +02001809 if (pt->misc & DRM_EDID_PT_STEREO) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001810 DRM_DEBUG_KMS("stereo mode not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001811 return NULL;
1812 }
Michel Dänzer0454bea2009-06-15 16:56:07 +02001813 if (!(pt->misc & DRM_EDID_PT_SEPARATE_SYNC)) {
Egbert Eichc7d015f32013-06-13 21:01:19 +02001814 DRM_DEBUG_KMS("composite sync not supported\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001815 }
1816
Zhao Yakuifcb45612009-10-14 09:11:25 +08001817 /* it is incorrect if hsync/vsync width is zero */
1818 if (!hsync_pulse_width || !vsync_pulse_width) {
1819 DRM_DEBUG_KMS("Incorrect Detailed timing. "
1820 "Wrong Hsync/Vsync pulse width\n");
1821 return NULL;
1822 }
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001823
1824 if (quirks & EDID_QUIRK_FORCE_REDUCED_BLANKING) {
1825 mode = drm_cvt_mode(dev, hactive, vactive, 60, true, false, false);
1826 if (!mode)
1827 return NULL;
1828
1829 goto set_size;
1830 }
1831
Dave Airlief453ba02008-11-07 14:05:41 -08001832 mode = drm_mode_create(dev);
1833 if (!mode)
1834 return NULL;
1835
Dave Airlief453ba02008-11-07 14:05:41 -08001836 if (quirks & EDID_QUIRK_135_CLOCK_TOO_HIGH)
Michel Dänzer0454bea2009-06-15 16:56:07 +02001837 timing->pixel_clock = cpu_to_le16(1088);
Dave Airlief453ba02008-11-07 14:05:41 -08001838
Michel Dänzer0454bea2009-06-15 16:56:07 +02001839 mode->clock = le16_to_cpu(timing->pixel_clock) * 10;
Dave Airlief453ba02008-11-07 14:05:41 -08001840
Michel Dänzer0454bea2009-06-15 16:56:07 +02001841 mode->hdisplay = hactive;
1842 mode->hsync_start = mode->hdisplay + hsync_offset;
1843 mode->hsync_end = mode->hsync_start + hsync_pulse_width;
1844 mode->htotal = mode->hdisplay + hblank;
Dave Airlief453ba02008-11-07 14:05:41 -08001845
Michel Dänzer0454bea2009-06-15 16:56:07 +02001846 mode->vdisplay = vactive;
1847 mode->vsync_start = mode->vdisplay + vsync_offset;
1848 mode->vsync_end = mode->vsync_start + vsync_pulse_width;
1849 mode->vtotal = mode->vdisplay + vblank;
Dave Airlief453ba02008-11-07 14:05:41 -08001850
Jesse Barnes7064fef2009-11-05 10:12:54 -08001851 /* Some EDIDs have bogus h/vtotal values */
1852 if (mode->hsync_end > mode->htotal)
1853 mode->htotal = mode->hsync_end + 1;
1854 if (mode->vsync_end > mode->vtotal)
1855 mode->vtotal = mode->vsync_end + 1;
1856
Adam Jacksonb58db2c2010-02-15 22:15:39 +00001857 drm_mode_do_interlace_quirk(mode, pt);
Dave Airlief453ba02008-11-07 14:05:41 -08001858
1859 if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) {
Michel Dänzer0454bea2009-06-15 16:56:07 +02001860 pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE;
Dave Airlief453ba02008-11-07 14:05:41 -08001861 }
1862
Michel Dänzer0454bea2009-06-15 16:56:07 +02001863 mode->flags |= (pt->misc & DRM_EDID_PT_HSYNC_POSITIVE) ?
1864 DRM_MODE_FLAG_PHSYNC : DRM_MODE_FLAG_NHSYNC;
1865 mode->flags |= (pt->misc & DRM_EDID_PT_VSYNC_POSITIVE) ?
1866 DRM_MODE_FLAG_PVSYNC : DRM_MODE_FLAG_NVSYNC;
Dave Airlief453ba02008-11-07 14:05:41 -08001867
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001868set_size:
Michel Dänzere14cbee2009-06-23 12:36:32 +02001869 mode->width_mm = pt->width_mm_lo | (pt->width_height_mm_hi & 0xf0) << 4;
1870 mode->height_mm = pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8;
Dave Airlief453ba02008-11-07 14:05:41 -08001871
1872 if (quirks & EDID_QUIRK_DETAILED_IN_CM) {
1873 mode->width_mm *= 10;
1874 mode->height_mm *= 10;
1875 }
1876
1877 if (quirks & EDID_QUIRK_DETAILED_USE_MAXIMUM_SIZE) {
1878 mode->width_mm = edid->width_cm * 10;
1879 mode->height_mm = edid->height_cm * 10;
1880 }
1881
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001882 mode->type = DRM_MODE_TYPE_DRIVER;
Torsten Duwec19b3b0f2013-03-23 15:39:34 +01001883 mode->vrefresh = drm_mode_vrefresh(mode);
Adam Jacksonbc42aab2012-05-23 16:26:54 -04001884 drm_mode_set_name(mode);
1885
Dave Airlief453ba02008-11-07 14:05:41 -08001886 return mode;
1887}
1888
Adam Jackson07a5e632009-12-03 17:44:38 -05001889static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001890mode_in_hsync_range(const struct drm_display_mode *mode,
1891 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001892{
1893 int hsync, hmin, hmax;
Adam Jackson07a5e632009-12-03 17:44:38 -05001894
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001895 hmin = t[7];
1896 if (edid->revision >= 4)
1897 hmin += ((t[4] & 0x04) ? 255 : 0);
1898 hmax = t[8];
1899 if (edid->revision >= 4)
1900 hmax += ((t[4] & 0x08) ? 255 : 0);
Adam Jackson07a5e632009-12-03 17:44:38 -05001901 hsync = drm_mode_hsync(mode);
Adam Jackson07a5e632009-12-03 17:44:38 -05001902
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001903 return (hsync <= hmax && hsync >= hmin);
1904}
1905
1906static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001907mode_in_vsync_range(const struct drm_display_mode *mode,
1908 struct edid *edid, u8 *t)
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001909{
1910 int vsync, vmin, vmax;
1911
1912 vmin = t[5];
1913 if (edid->revision >= 4)
1914 vmin += ((t[4] & 0x01) ? 255 : 0);
1915 vmax = t[6];
1916 if (edid->revision >= 4)
1917 vmax += ((t[4] & 0x02) ? 255 : 0);
1918 vsync = drm_mode_vrefresh(mode);
1919
1920 return (vsync <= vmax && vsync >= vmin);
1921}
1922
1923static u32
1924range_pixel_clock(struct edid *edid, u8 *t)
1925{
1926 /* unspecified */
1927 if (t[9] == 0 || t[9] == 255)
1928 return 0;
1929
1930 /* 1.4 with CVT support gives us real precision, yay */
1931 if (edid->revision >= 4 && t[10] == 0x04)
1932 return (t[9] * 10000) - ((t[12] >> 2) * 250);
1933
1934 /* 1.3 is pathetic, so fuzz up a bit */
1935 return t[9] * 10000 + 5001;
1936}
1937
Adam Jackson07a5e632009-12-03 17:44:38 -05001938static bool
Chris Wilsonb1f559e2011-01-26 09:49:47 +00001939mode_in_range(const struct drm_display_mode *mode, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001940 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05001941{
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001942 u32 max_clock;
1943 u8 *t = (u8 *)timing;
Adam Jackson07a5e632009-12-03 17:44:38 -05001944
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001945 if (!mode_in_hsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05001946 return false;
1947
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001948 if (!mode_in_vsync_range(mode, edid, t))
Adam Jackson07a5e632009-12-03 17:44:38 -05001949 return false;
1950
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001951 if ((max_clock = range_pixel_clock(edid, t)))
Adam Jackson07a5e632009-12-03 17:44:38 -05001952 if (mode->clock > max_clock)
1953 return false;
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001954
1955 /* 1.4 max horizontal check */
1956 if (edid->revision >= 4 && t[10] == 0x04)
1957 if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3))))
1958 return false;
1959
1960 if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid))
1961 return false;
Adam Jackson07a5e632009-12-03 17:44:38 -05001962
1963 return true;
1964}
1965
Takashi Iwai7b668eb2012-07-03 11:22:11 +02001966static bool valid_inferred_mode(const struct drm_connector *connector,
1967 const struct drm_display_mode *mode)
1968{
1969 struct drm_display_mode *m;
1970 bool ok = false;
1971
1972 list_for_each_entry(m, &connector->probed_modes, head) {
1973 if (mode->hdisplay == m->hdisplay &&
1974 mode->vdisplay == m->vdisplay &&
1975 drm_mode_vrefresh(mode) == drm_mode_vrefresh(m))
1976 return false; /* duplicated */
1977 if (mode->hdisplay <= m->hdisplay &&
1978 mode->vdisplay <= m->vdisplay)
1979 ok = true;
1980 }
1981 return ok;
1982}
1983
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001984static int
Adam Jacksoncd4cd3d2012-04-13 16:33:33 -04001985drm_dmt_modes_for_range(struct drm_connector *connector, struct edid *edid,
Adam Jacksonb17e52e2010-03-29 21:43:27 +00001986 struct detailed_timing *timing)
Adam Jackson07a5e632009-12-03 17:44:38 -05001987{
1988 int i, modes = 0;
1989 struct drm_display_mode *newmode;
1990 struct drm_device *dev = connector->dev;
1991
Thierry Redinga6b21832012-11-23 15:01:42 +01001992 for (i = 0; i < ARRAY_SIZE(drm_dmt_modes); i++) {
Takashi Iwai7b668eb2012-07-03 11:22:11 +02001993 if (mode_in_range(drm_dmt_modes + i, edid, timing) &&
1994 valid_inferred_mode(connector, drm_dmt_modes + i)) {
Adam Jackson07a5e632009-12-03 17:44:38 -05001995 newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]);
1996 if (newmode) {
1997 drm_mode_probed_add(connector, newmode);
1998 modes++;
1999 }
2000 }
2001 }
2002
2003 return modes;
2004}
2005
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002006/* fix up 1366x768 mode from 1368x768;
2007 * GFT/CVT can't express 1366 width which isn't dividable by 8
2008 */
2009static void fixup_mode_1366x768(struct drm_display_mode *mode)
2010{
2011 if (mode->hdisplay == 1368 && mode->vdisplay == 768) {
2012 mode->hdisplay = 1366;
2013 mode->hsync_start--;
2014 mode->hsync_end--;
2015 drm_mode_set_name(mode);
2016 }
2017}
2018
Adam Jacksonb309bd32012-04-13 16:33:40 -04002019static int
2020drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid,
2021 struct detailed_timing *timing)
2022{
2023 int i, modes = 0;
2024 struct drm_display_mode *newmode;
2025 struct drm_device *dev = connector->dev;
2026
Thierry Redinga6b21832012-11-23 15:01:42 +01002027 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002028 const struct minimode *m = &extra_modes[i];
2029 newmode = drm_gtf_mode(dev, m->w, m->h, m->r, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002030 if (!newmode)
2031 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002032
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002033 fixup_mode_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002034 if (!mode_in_range(newmode, edid, timing) ||
2035 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002036 drm_mode_destroy(dev, newmode);
2037 continue;
2038 }
2039
2040 drm_mode_probed_add(connector, newmode);
2041 modes++;
2042 }
2043
2044 return modes;
2045}
2046
2047static int
2048drm_cvt_modes_for_range(struct drm_connector *connector, struct edid *edid,
2049 struct detailed_timing *timing)
2050{
2051 int i, modes = 0;
2052 struct drm_display_mode *newmode;
2053 struct drm_device *dev = connector->dev;
2054 bool rb = drm_monitor_supports_rb(edid);
2055
Thierry Redinga6b21832012-11-23 15:01:42 +01002056 for (i = 0; i < ARRAY_SIZE(extra_modes); i++) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002057 const struct minimode *m = &extra_modes[i];
2058 newmode = drm_cvt_mode(dev, m->w, m->h, m->r, rb, 0, 0);
Takashi Iwaifc48f162012-04-20 12:59:33 +01002059 if (!newmode)
2060 return modes;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002061
Takashi Iwaic09dedb2012-04-23 17:40:33 +01002062 fixup_mode_1366x768(newmode);
Takashi Iwai7b668eb2012-07-03 11:22:11 +02002063 if (!mode_in_range(newmode, edid, timing) ||
2064 !valid_inferred_mode(connector, newmode)) {
Adam Jacksonb309bd32012-04-13 16:33:40 -04002065 drm_mode_destroy(dev, newmode);
2066 continue;
2067 }
2068
2069 drm_mode_probed_add(connector, newmode);
2070 modes++;
2071 }
2072
2073 return modes;
2074}
2075
Adam Jackson13931572010-08-03 14:38:19 -04002076static void
2077do_inferred_modes(struct detailed_timing *timing, void *c)
Adam Jackson9340d8c2009-12-03 17:44:40 -05002078{
Adam Jackson13931572010-08-03 14:38:19 -04002079 struct detailed_mode_closure *closure = c;
2080 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jacksonb309bd32012-04-13 16:33:40 -04002081 struct detailed_data_monitor_range *range = &data->data.range;
Adam Jackson9340d8c2009-12-03 17:44:40 -05002082
Adam Jacksoncb21aaf2012-04-13 16:33:36 -04002083 if (data->type != EDID_DETAIL_MONITOR_RANGE)
2084 return;
2085
2086 closure->modes += drm_dmt_modes_for_range(closure->connector,
2087 closure->edid,
2088 timing);
Adam Jacksonb309bd32012-04-13 16:33:40 -04002089
2090 if (!version_greater(closure->edid, 1, 1))
2091 return; /* GTF not defined yet */
2092
2093 switch (range->flags) {
2094 case 0x02: /* secondary gtf, XXX could do more */
2095 case 0x00: /* default gtf */
2096 closure->modes += drm_gtf_modes_for_range(closure->connector,
2097 closure->edid,
2098 timing);
2099 break;
2100 case 0x04: /* cvt, only in 1.4+ */
2101 if (!version_greater(closure->edid, 1, 3))
2102 break;
2103
2104 closure->modes += drm_cvt_modes_for_range(closure->connector,
2105 closure->edid,
2106 timing);
2107 break;
2108 case 0x01: /* just the ranges, no formula */
2109 default:
2110 break;
2111 }
Adam Jackson9340d8c2009-12-03 17:44:40 -05002112}
2113
Adam Jackson13931572010-08-03 14:38:19 -04002114static int
2115add_inferred_modes(struct drm_connector *connector, struct edid *edid)
2116{
2117 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002118 .connector = connector,
2119 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002120 };
2121
2122 if (version_greater(edid, 1, 0))
2123 drm_for_each_detailed_block((u8 *)edid, do_inferred_modes,
2124 &closure);
2125
2126 return closure.modes;
2127}
2128
Adam Jackson2255be12010-03-29 21:43:22 +00002129static int
2130drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing)
2131{
2132 int i, j, m, modes = 0;
2133 struct drm_display_mode *mode;
2134 u8 *est = ((u8 *)timing) + 5;
2135
2136 for (i = 0; i < 6; i++) {
Ville Syrjälä891a7462013-10-14 16:44:26 +03002137 for (j = 7; j >= 0; j--) {
Adam Jackson2255be12010-03-29 21:43:22 +00002138 m = (i * 8) + (7 - j);
Linus Torvaldsaa9f56b2010-08-12 09:21:39 -07002139 if (m >= ARRAY_SIZE(est3_modes))
Adam Jackson2255be12010-03-29 21:43:22 +00002140 break;
2141 if (est[i] & (1 << j)) {
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002142 mode = drm_mode_find_dmt(connector->dev,
2143 est3_modes[m].w,
2144 est3_modes[m].h,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002145 est3_modes[m].r,
2146 est3_modes[m].rb);
Adam Jackson2255be12010-03-29 21:43:22 +00002147 if (mode) {
2148 drm_mode_probed_add(connector, mode);
2149 modes++;
2150 }
2151 }
2152 }
2153 }
2154
2155 return modes;
2156}
2157
Adam Jackson13931572010-08-03 14:38:19 -04002158static void
2159do_established_modes(struct detailed_timing *timing, void *c)
Adam Jackson9cf00972009-12-03 17:44:36 -05002160{
Adam Jackson13931572010-08-03 14:38:19 -04002161 struct detailed_mode_closure *closure = c;
Adam Jackson9cf00972009-12-03 17:44:36 -05002162 struct detailed_non_pixel *data = &timing->data.other_data;
Adam Jackson13931572010-08-03 14:38:19 -04002163
2164 if (data->type == EDID_DETAIL_EST_TIMINGS)
2165 closure->modes += drm_est3_modes(closure->connector, timing);
2166}
2167
2168/**
2169 * add_established_modes - get est. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002170 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002171 * @edid: EDID block to scan
2172 *
2173 * Each EDID block contains a bitmap of the supported "established modes" list
2174 * (defined above). Tease them out and add them to the global modes list.
2175 */
2176static int
2177add_established_modes(struct drm_connector *connector, struct edid *edid)
2178{
Adam Jackson9cf00972009-12-03 17:44:36 -05002179 struct drm_device *dev = connector->dev;
Adam Jackson13931572010-08-03 14:38:19 -04002180 unsigned long est_bits = edid->established_timings.t1 |
2181 (edid->established_timings.t2 << 8) |
2182 ((edid->established_timings.mfg_rsvd & 0x80) << 9);
2183 int i, modes = 0;
2184 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002185 .connector = connector,
2186 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002187 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002188
Adam Jackson13931572010-08-03 14:38:19 -04002189 for (i = 0; i <= EDID_EST_TIMINGS; i++) {
2190 if (est_bits & (1<<i)) {
2191 struct drm_display_mode *newmode;
2192 newmode = drm_mode_duplicate(dev, &edid_est_modes[i]);
2193 if (newmode) {
2194 drm_mode_probed_add(connector, newmode);
2195 modes++;
2196 }
2197 }
Adam Jackson9cf00972009-12-03 17:44:36 -05002198 }
2199
Adam Jackson13931572010-08-03 14:38:19 -04002200 if (version_greater(edid, 1, 0))
2201 drm_for_each_detailed_block((u8 *)edid,
2202 do_established_modes, &closure);
2203
2204 return modes + closure.modes;
2205}
2206
2207static void
2208do_standard_modes(struct detailed_timing *timing, void *c)
2209{
2210 struct detailed_mode_closure *closure = c;
2211 struct detailed_non_pixel *data = &timing->data.other_data;
2212 struct drm_connector *connector = closure->connector;
2213 struct edid *edid = closure->edid;
2214
2215 if (data->type == EDID_DETAIL_STD_MODES) {
2216 int i;
Adam Jackson9cf00972009-12-03 17:44:36 -05002217 for (i = 0; i < 6; i++) {
2218 struct std_timing *std;
2219 struct drm_display_mode *newmode;
2220
2221 std = &data->data.timings[i];
Thierry Reding464fdec2014-04-29 11:44:33 +02002222 newmode = drm_mode_std(connector, edid, std);
Adam Jackson9cf00972009-12-03 17:44:36 -05002223 if (newmode) {
2224 drm_mode_probed_add(connector, newmode);
Adam Jackson13931572010-08-03 14:38:19 -04002225 closure->modes++;
Adam Jackson9cf00972009-12-03 17:44:36 -05002226 }
2227 }
Adam Jackson13931572010-08-03 14:38:19 -04002228 }
2229}
2230
2231/**
2232 * add_standard_modes - get std. modes from EDID and add them
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002233 * @connector: connector to add mode(s) to
Adam Jackson13931572010-08-03 14:38:19 -04002234 * @edid: EDID block to scan
2235 *
2236 * Standard modes can be calculated using the appropriate standard (DMT,
2237 * GTF or CVT. Grab them from @edid and add them to the list.
2238 */
2239static int
2240add_standard_modes(struct drm_connector *connector, struct edid *edid)
2241{
2242 int i, modes = 0;
2243 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002244 .connector = connector,
2245 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002246 };
2247
2248 for (i = 0; i < EDID_STD_TIMINGS; i++) {
2249 struct drm_display_mode *newmode;
2250
2251 newmode = drm_mode_std(connector, edid,
Thierry Reding464fdec2014-04-29 11:44:33 +02002252 &edid->standard_timings[i]);
Adam Jackson13931572010-08-03 14:38:19 -04002253 if (newmode) {
2254 drm_mode_probed_add(connector, newmode);
2255 modes++;
2256 }
2257 }
2258
2259 if (version_greater(edid, 1, 0))
2260 drm_for_each_detailed_block((u8 *)edid, do_standard_modes,
2261 &closure);
2262
2263 /* XXX should also look for standard codes in VTB blocks */
2264
2265 return modes + closure.modes;
2266}
2267
Dave Airlief453ba02008-11-07 14:05:41 -08002268static int drm_cvt_modes(struct drm_connector *connector,
2269 struct detailed_timing *timing)
2270{
2271 int i, j, modes = 0;
2272 struct drm_display_mode *newmode;
2273 struct drm_device *dev = connector->dev;
Zhao Yakui5c612592009-06-22 13:17:10 +08002274 struct cvt_timing *cvt;
2275 const int rates[] = { 60, 85, 75, 60, 50 };
2276 const u8 empty[3] = { 0, 0, 0 };
Dave Airlief453ba02008-11-07 14:05:41 -08002277
2278 for (i = 0; i < 4; i++) {
2279 int uninitialized_var(width), height;
2280 cvt = &(timing->data.other_data.data.cvt[i]);
2281
2282 if (!memcmp(cvt->code, empty, 3))
Michel Dänzer0454bea2009-06-15 16:56:07 +02002283 continue;
Dave Airlief453ba02008-11-07 14:05:41 -08002284
2285 height = (cvt->code[0] + ((cvt->code[1] & 0xf0) << 4) + 1) * 2;
Zhao Yakui5c612592009-06-22 13:17:10 +08002286 switch (cvt->code[1] & 0x0c) {
Adam Jacksonf066a172009-09-23 17:31:21 -04002287 case 0x00:
Dave Airlief453ba02008-11-07 14:05:41 -08002288 width = height * 4 / 3;
2289 break;
2290 case 0x04:
2291 width = height * 16 / 9;
2292 break;
2293 case 0x08:
2294 width = height * 16 / 10;
2295 break;
2296 case 0x0c:
Dave Airlief453ba02008-11-07 14:05:41 -08002297 width = height * 15 / 9;
2298 break;
2299 }
2300
2301 for (j = 1; j < 5; j++) {
2302 if (cvt->code[2] & (1 << j)) {
2303 newmode = drm_cvt_mode(dev, width, height,
2304 rates[j], j == 0,
2305 false, false);
2306 if (newmode) {
2307 drm_mode_probed_add(connector, newmode);
2308 modes++;
2309 }
2310 }
2311 }
2312 }
2313
2314 return modes;
2315}
2316
Adam Jackson13931572010-08-03 14:38:19 -04002317static void
2318do_cvt_mode(struct detailed_timing *timing, void *c)
2319{
2320 struct detailed_mode_closure *closure = c;
2321 struct detailed_non_pixel *data = &timing->data.other_data;
2322
2323 if (data->type == EDID_DETAIL_CVT_3BYTE)
2324 closure->modes += drm_cvt_modes(closure->connector, timing);
2325}
Adam Jackson9cf00972009-12-03 17:44:36 -05002326
2327static int
Adam Jackson13931572010-08-03 14:38:19 -04002328add_cvt_modes(struct drm_connector *connector, struct edid *edid)
2329{
2330 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002331 .connector = connector,
2332 .edid = edid,
Adam Jackson13931572010-08-03 14:38:19 -04002333 };
Adam Jackson9cf00972009-12-03 17:44:36 -05002334
Adam Jackson13931572010-08-03 14:38:19 -04002335 if (version_greater(edid, 1, 2))
2336 drm_for_each_detailed_block((u8 *)edid, do_cvt_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002337
Adam Jackson13931572010-08-03 14:38:19 -04002338 /* XXX should also look for CVT codes in VTB blocks */
2339
2340 return closure.modes;
Dave Airlief453ba02008-11-07 14:05:41 -08002341}
2342
Adam Jackson13931572010-08-03 14:38:19 -04002343static void
2344do_detailed_mode(struct detailed_timing *timing, void *c)
Dave Airlief453ba02008-11-07 14:05:41 -08002345{
Adam Jackson13931572010-08-03 14:38:19 -04002346 struct detailed_mode_closure *closure = c;
Dave Airlief453ba02008-11-07 14:05:41 -08002347 struct drm_display_mode *newmode;
Adam Jackson9cf00972009-12-03 17:44:36 -05002348
2349 if (timing->pixel_clock) {
Adam Jackson13931572010-08-03 14:38:19 -04002350 newmode = drm_mode_detailed(closure->connector->dev,
2351 closure->edid, timing,
2352 closure->quirks);
Dave Airlief453ba02008-11-07 14:05:41 -08002353 if (!newmode)
Adam Jackson13931572010-08-03 14:38:19 -04002354 return;
Adam Jackson9cf00972009-12-03 17:44:36 -05002355
Adam Jackson13931572010-08-03 14:38:19 -04002356 if (closure->preferred)
Dave Airlief453ba02008-11-07 14:05:41 -08002357 newmode->type |= DRM_MODE_TYPE_PREFERRED;
2358
Adam Jackson13931572010-08-03 14:38:19 -04002359 drm_mode_probed_add(closure->connector, newmode);
2360 closure->modes++;
2361 closure->preferred = 0;
Zhao Yakui882f0212009-08-26 18:20:49 +08002362 }
Ma Ling167f3a02009-03-20 14:09:48 +08002363}
2364
Adam Jackson13931572010-08-03 14:38:19 -04002365/*
2366 * add_detailed_modes - Add modes from detailed timings
Dave Airlief453ba02008-11-07 14:05:41 -08002367 * @connector: attached connector
2368 * @edid: EDID block to scan
2369 * @quirks: quirks to apply
Dave Airlief453ba02008-11-07 14:05:41 -08002370 */
Adam Jackson13931572010-08-03 14:38:19 -04002371static int
2372add_detailed_modes(struct drm_connector *connector, struct edid *edid,
2373 u32 quirks)
Dave Airlief453ba02008-11-07 14:05:41 -08002374{
Adam Jackson13931572010-08-03 14:38:19 -04002375 struct detailed_mode_closure closure = {
Julia Lawalld456ea22014-08-23 18:09:56 +02002376 .connector = connector,
2377 .edid = edid,
2378 .preferred = 1,
2379 .quirks = quirks,
Adam Jackson13931572010-08-03 14:38:19 -04002380 };
Dave Airlief453ba02008-11-07 14:05:41 -08002381
Adam Jackson13931572010-08-03 14:38:19 -04002382 if (closure.preferred && !version_greater(edid, 1, 3))
2383 closure.preferred =
2384 (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING);
Adam Jacksona327f6b2010-03-29 21:43:25 +00002385
Adam Jackson13931572010-08-03 14:38:19 -04002386 drm_for_each_detailed_block((u8 *)edid, do_detailed_mode, &closure);
Dave Airlief453ba02008-11-07 14:05:41 -08002387
Adam Jackson13931572010-08-03 14:38:19 -04002388 return closure.modes;
Zhao Yakui882f0212009-08-26 18:20:49 +08002389}
Dave Airlief453ba02008-11-07 14:05:41 -08002390
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002391#define AUDIO_BLOCK 0x01
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002392#define VIDEO_BLOCK 0x02
Ma Lingf23c20c2009-03-26 19:26:23 +08002393#define VENDOR_BLOCK 0x03
Wu Fengguang76adaa342011-09-05 14:23:20 +08002394#define SPEAKER_BLOCK 0x04
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002395#define VIDEO_CAPABILITY_BLOCK 0x07
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002396#define EDID_BASIC_AUDIO (1 << 6)
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02002397#define EDID_CEA_YCRCB444 (1 << 5)
2398#define EDID_CEA_YCRCB422 (1 << 4)
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002399#define EDID_CEA_VCDB_QS (1 << 6)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002400
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002401/*
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002402 * Search EDID for CEA extension block.
2403 */
Lespiau, Damiend4e4a312013-08-19 16:58:52 +01002404static u8 *drm_find_cea_extension(struct edid *edid)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002405{
2406 u8 *edid_ext = NULL;
2407 int i;
2408
2409 /* No EDID or EDID extensions */
2410 if (edid == NULL || edid->extensions == 0)
2411 return NULL;
2412
2413 /* Find CEA extension */
2414 for (i = 0; i < edid->extensions; i++) {
2415 edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
2416 if (edid_ext[0] == CEA_EXT)
2417 break;
2418 }
2419
2420 if (i == edid->extensions)
2421 return NULL;
2422
2423 return edid_ext;
2424}
2425
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002426/*
2427 * Calculate the alternate clock for the CEA mode
2428 * (60Hz vs. 59.94Hz etc.)
2429 */
2430static unsigned int
2431cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
2432{
2433 unsigned int clock = cea_mode->clock;
2434
2435 if (cea_mode->vrefresh % 6 != 0)
2436 return clock;
2437
2438 /*
2439 * edid_cea_modes contains the 59.94Hz
2440 * variant for 240 and 480 line modes,
2441 * and the 60Hz variant otherwise.
2442 */
2443 if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
2444 clock = clock * 1001 / 1000;
2445 else
2446 clock = DIV_ROUND_UP(clock * 1000, 1001);
2447
2448 return clock;
2449}
2450
Thierry Reding18316c82012-12-20 15:41:44 +01002451/**
2452 * drm_match_cea_mode - look for a CEA mode matching given mode
2453 * @to_match: display mode
2454 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02002455 * 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 +01002456 * mode.
Stephane Marchesina4799032012-11-09 16:21:05 +00002457 */
Thierry Reding18316c82012-12-20 15:41:44 +01002458u8 drm_match_cea_mode(const struct drm_display_mode *to_match)
Stephane Marchesina4799032012-11-09 16:21:05 +00002459{
Stephane Marchesina4799032012-11-09 16:21:05 +00002460 u8 mode;
2461
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002462 if (!to_match->clock)
2463 return 0;
Stephane Marchesina4799032012-11-09 16:21:05 +00002464
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002465 for (mode = 0; mode < ARRAY_SIZE(edid_cea_modes); mode++) {
2466 const struct drm_display_mode *cea_mode = &edid_cea_modes[mode];
2467 unsigned int clock1, clock2;
2468
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002469 /* Check both 60Hz and 59.94Hz */
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002470 clock1 = cea_mode->clock;
2471 clock2 = cea_mode_alternate_clock(cea_mode);
Ville Syrjäläa90b5902013-04-24 19:07:18 +03002472
2473 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2474 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01002475 drm_mode_equal_no_clocks_no_stereo(to_match, cea_mode))
Stephane Marchesina4799032012-11-09 16:21:05 +00002476 return mode + 1;
2477 }
2478 return 0;
2479}
2480EXPORT_SYMBOL(drm_match_cea_mode);
2481
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302482/**
2483 * drm_get_cea_aspect_ratio - get the picture aspect ratio corresponding to
2484 * the input VIC from the CEA mode list
2485 * @video_code: ID given to each of the CEA modes
2486 *
2487 * Returns picture aspect ratio
2488 */
2489enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code)
2490{
2491 /* return picture aspect ratio for video_code - 1 to access the
2492 * right array element
2493 */
2494 return edid_cea_modes[video_code-1].picture_aspect_ratio;
2495}
2496EXPORT_SYMBOL(drm_get_cea_aspect_ratio);
2497
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002498/*
2499 * Calculate the alternate clock for HDMI modes (those from the HDMI vendor
2500 * specific block).
2501 *
2502 * It's almost like cea_mode_alternate_clock(), we just need to add an
2503 * exception for the VIC 4 mode (4096x2160@24Hz): no alternate clock for this
2504 * one.
2505 */
2506static unsigned int
2507hdmi_mode_alternate_clock(const struct drm_display_mode *hdmi_mode)
2508{
2509 if (hdmi_mode->vdisplay == 4096 && hdmi_mode->hdisplay == 2160)
2510 return hdmi_mode->clock;
2511
2512 return cea_mode_alternate_clock(hdmi_mode);
2513}
2514
2515/*
2516 * drm_match_hdmi_mode - look for a HDMI mode matching given mode
2517 * @to_match: display mode
2518 *
2519 * An HDMI mode is one defined in the HDMI vendor specific block.
2520 *
2521 * Returns the HDMI Video ID (VIC) of the mode or 0 if it isn't one.
2522 */
2523static u8 drm_match_hdmi_mode(const struct drm_display_mode *to_match)
2524{
2525 u8 mode;
2526
2527 if (!to_match->clock)
2528 return 0;
2529
2530 for (mode = 0; mode < ARRAY_SIZE(edid_4k_modes); mode++) {
2531 const struct drm_display_mode *hdmi_mode = &edid_4k_modes[mode];
2532 unsigned int clock1, clock2;
2533
2534 /* Make sure to also match alternate clocks */
2535 clock1 = hdmi_mode->clock;
2536 clock2 = hdmi_mode_alternate_clock(hdmi_mode);
2537
2538 if ((KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock1) ||
2539 KHZ2PICOS(to_match->clock) == KHZ2PICOS(clock2)) &&
Damien Lespiauf2ecf2e32013-09-25 16:45:27 +01002540 drm_mode_equal_no_clocks_no_stereo(to_match, hdmi_mode))
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002541 return mode + 1;
2542 }
2543 return 0;
2544}
2545
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002546static int
2547add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid)
2548{
2549 struct drm_device *dev = connector->dev;
2550 struct drm_display_mode *mode, *tmp;
2551 LIST_HEAD(list);
2552 int modes = 0;
2553
2554 /* Don't add CEA modes if the CEA extension block is missing */
2555 if (!drm_find_cea_extension(edid))
2556 return 0;
2557
2558 /*
2559 * Go through all probed modes and create a new mode
2560 * with the alternate clock for certain CEA modes.
2561 */
2562 list_for_each_entry(mode, &connector->probed_modes, head) {
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002563 const struct drm_display_mode *cea_mode = NULL;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002564 struct drm_display_mode *newmode;
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002565 u8 mode_idx = drm_match_cea_mode(mode) - 1;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002566 unsigned int clock1, clock2;
2567
Lespiau, Damien3f2f6532013-08-19 16:58:55 +01002568 if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
2569 cea_mode = &edid_cea_modes[mode_idx];
2570 clock2 = cea_mode_alternate_clock(cea_mode);
2571 } else {
2572 mode_idx = drm_match_hdmi_mode(mode) - 1;
2573 if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
2574 cea_mode = &edid_4k_modes[mode_idx];
2575 clock2 = hdmi_mode_alternate_clock(cea_mode);
2576 }
2577 }
2578
2579 if (!cea_mode)
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002580 continue;
2581
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002582 clock1 = cea_mode->clock;
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002583
2584 if (clock1 == clock2)
2585 continue;
2586
2587 if (mode->clock != clock1 && mode->clock != clock2)
2588 continue;
2589
2590 newmode = drm_mode_duplicate(dev, cea_mode);
2591 if (!newmode)
2592 continue;
2593
Damien Lespiau27130212013-09-25 16:45:28 +01002594 /* Carry over the stereo flags */
2595 newmode->flags |= mode->flags & DRM_MODE_FLAG_3D_MASK;
2596
Ville Syrjäläe6e79202013-05-31 15:23:41 +03002597 /*
2598 * The current mode could be either variant. Make
2599 * sure to pick the "other" clock for the new mode.
2600 */
2601 if (mode->clock != clock1)
2602 newmode->clock = clock1;
2603 else
2604 newmode->clock = clock2;
2605
2606 list_add_tail(&newmode->head, &list);
2607 }
2608
2609 list_for_each_entry_safe(mode, tmp, &list, head) {
2610 list_del(&mode->head);
2611 drm_mode_probed_add(connector, mode);
2612 modes++;
2613 }
2614
2615 return modes;
2616}
Stephane Marchesina4799032012-11-09 16:21:05 +00002617
Thomas Woodaff04ac2013-11-29 15:33:27 +00002618static struct drm_display_mode *
2619drm_display_mode_from_vic_index(struct drm_connector *connector,
2620 const u8 *video_db, u8 video_len,
2621 u8 video_index)
2622{
2623 struct drm_device *dev = connector->dev;
2624 struct drm_display_mode *newmode;
2625 u8 cea_mode;
2626
2627 if (video_db == NULL || video_index >= video_len)
2628 return NULL;
2629
2630 /* CEA modes are numbered 1..127 */
2631 cea_mode = (video_db[video_index] & 127) - 1;
2632 if (cea_mode >= ARRAY_SIZE(edid_cea_modes))
2633 return NULL;
2634
2635 newmode = drm_mode_duplicate(dev, &edid_cea_modes[cea_mode]);
Damien Lespiau409bbf12014-03-03 23:59:07 +00002636 if (!newmode)
2637 return NULL;
2638
Thomas Woodaff04ac2013-11-29 15:33:27 +00002639 newmode->vrefresh = 0;
2640
2641 return newmode;
2642}
2643
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002644static int
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01002645do_cea_modes(struct drm_connector *connector, const u8 *db, u8 len)
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002646{
Thomas Woodaff04ac2013-11-29 15:33:27 +00002647 int i, modes = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002648
Thomas Woodaff04ac2013-11-29 15:33:27 +00002649 for (i = 0; i < len; i++) {
2650 struct drm_display_mode *mode;
2651 mode = drm_display_mode_from_vic_index(connector, db, len, i);
2652 if (mode) {
2653 drm_mode_probed_add(connector, mode);
2654 modes++;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002655 }
2656 }
2657
2658 return modes;
2659}
2660
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002661struct stereo_mandatory_mode {
2662 int width, height, vrefresh;
2663 unsigned int flags;
2664};
2665
2666static const struct stereo_mandatory_mode stereo_mandatory_modes[] = {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002667 { 1920, 1080, 24, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2668 { 1920, 1080, 24, DRM_MODE_FLAG_3D_FRAME_PACKING },
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002669 { 1920, 1080, 50,
2670 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
2671 { 1920, 1080, 60,
2672 DRM_MODE_FLAG_INTERLACE | DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF },
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002673 { 1280, 720, 50, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2674 { 1280, 720, 50, DRM_MODE_FLAG_3D_FRAME_PACKING },
2675 { 1280, 720, 60, DRM_MODE_FLAG_3D_TOP_AND_BOTTOM },
2676 { 1280, 720, 60, DRM_MODE_FLAG_3D_FRAME_PACKING }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002677};
2678
2679static bool
2680stereo_match_mandatory(const struct drm_display_mode *mode,
2681 const struct stereo_mandatory_mode *stereo_mode)
2682{
2683 unsigned int interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
2684
2685 return mode->hdisplay == stereo_mode->width &&
2686 mode->vdisplay == stereo_mode->height &&
2687 interlaced == (stereo_mode->flags & DRM_MODE_FLAG_INTERLACE) &&
2688 drm_mode_vrefresh(mode) == stereo_mode->vrefresh;
2689}
2690
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002691static int add_hdmi_mandatory_stereo_modes(struct drm_connector *connector)
2692{
2693 struct drm_device *dev = connector->dev;
2694 const struct drm_display_mode *mode;
2695 struct list_head stereo_modes;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002696 int modes = 0, i;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002697
2698 INIT_LIST_HEAD(&stereo_modes);
2699
2700 list_for_each_entry(mode, &connector->probed_modes, head) {
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002701 for (i = 0; i < ARRAY_SIZE(stereo_mandatory_modes); i++) {
2702 const struct stereo_mandatory_mode *mandatory;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002703 struct drm_display_mode *new_mode;
2704
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002705 if (!stereo_match_mandatory(mode,
2706 &stereo_mandatory_modes[i]))
2707 continue;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002708
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002709 mandatory = &stereo_mandatory_modes[i];
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002710 new_mode = drm_mode_duplicate(dev, mode);
2711 if (!new_mode)
2712 continue;
2713
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002714 new_mode->flags |= mandatory->flags;
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002715 list_add_tail(&new_mode->head, &stereo_modes);
2716 modes++;
Damien Lespiauf7e121b2013-09-27 12:11:48 +01002717 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002718 }
2719
2720 list_splice_tail(&stereo_modes, &connector->probed_modes);
2721
2722 return modes;
2723}
2724
Damien Lespiau1deee8d2013-09-25 16:45:24 +01002725static int add_hdmi_mode(struct drm_connector *connector, u8 vic)
2726{
2727 struct drm_device *dev = connector->dev;
2728 struct drm_display_mode *newmode;
2729
2730 vic--; /* VICs start at 1 */
2731 if (vic >= ARRAY_SIZE(edid_4k_modes)) {
2732 DRM_ERROR("Unknown HDMI VIC: %d\n", vic);
2733 return 0;
2734 }
2735
2736 newmode = drm_mode_duplicate(dev, &edid_4k_modes[vic]);
2737 if (!newmode)
2738 return 0;
2739
2740 drm_mode_probed_add(connector, newmode);
2741
2742 return 1;
2743}
2744
Thomas Woodfbf46022013-10-16 15:58:50 +01002745static int add_3d_struct_modes(struct drm_connector *connector, u16 structure,
2746 const u8 *video_db, u8 video_len, u8 video_index)
2747{
Thomas Woodfbf46022013-10-16 15:58:50 +01002748 struct drm_display_mode *newmode;
2749 int modes = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01002750
2751 if (structure & (1 << 0)) {
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) {
2756 newmode->flags |= DRM_MODE_FLAG_3D_FRAME_PACKING;
2757 drm_mode_probed_add(connector, newmode);
2758 modes++;
2759 }
2760 }
2761 if (structure & (1 << 6)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00002762 newmode = drm_display_mode_from_vic_index(connector, video_db,
2763 video_len,
2764 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01002765 if (newmode) {
2766 newmode->flags |= DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2767 drm_mode_probed_add(connector, newmode);
2768 modes++;
2769 }
2770 }
2771 if (structure & (1 << 8)) {
Thomas Woodaff04ac2013-11-29 15:33:27 +00002772 newmode = drm_display_mode_from_vic_index(connector, video_db,
2773 video_len,
2774 video_index);
Thomas Woodfbf46022013-10-16 15:58:50 +01002775 if (newmode) {
Thomas Wood89570ee2013-11-28 15:35:04 +00002776 newmode->flags |= DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
Thomas Woodfbf46022013-10-16 15:58:50 +01002777 drm_mode_probed_add(connector, newmode);
2778 modes++;
2779 }
2780 }
2781
2782 return modes;
2783}
2784
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002785/*
2786 * do_hdmi_vsdb_modes - Parse the HDMI Vendor Specific data block
2787 * @connector: connector corresponding to the HDMI sink
2788 * @db: start of the CEA vendor specific block
2789 * @len: length of the CEA block payload, ie. one can access up to db[len]
2790 *
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002791 * Parses the HDMI VSDB looking for modes to add to @connector. This function
2792 * also adds the stereo 3d modes when applicable.
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002793 */
2794static int
Thomas Woodfbf46022013-10-16 15:58:50 +01002795do_hdmi_vsdb_modes(struct drm_connector *connector, const u8 *db, u8 len,
2796 const u8 *video_db, u8 video_len)
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002797{
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002798 int modes = 0, offset = 0, i, multi_present = 0, multi_len;
Thomas Woodfbf46022013-10-16 15:58:50 +01002799 u8 vic_len, hdmi_3d_len = 0;
2800 u16 mask;
2801 u16 structure_all;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002802
2803 if (len < 8)
2804 goto out;
2805
2806 /* no HDMI_Video_Present */
2807 if (!(db[8] & (1 << 5)))
2808 goto out;
2809
2810 /* Latency_Fields_Present */
2811 if (db[8] & (1 << 7))
2812 offset += 2;
2813
2814 /* I_Latency_Fields_Present */
2815 if (db[8] & (1 << 6))
2816 offset += 2;
2817
2818 /* the declared length is not long enough for the 2 first bytes
2819 * of additional video format capabilities */
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002820 if (len < (8 + offset + 2))
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002821 goto out;
2822
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002823 /* 3D_Present */
2824 offset++;
Thomas Woodfbf46022013-10-16 15:58:50 +01002825 if (db[8 + offset] & (1 << 7)) {
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002826 modes += add_hdmi_mandatory_stereo_modes(connector);
2827
Thomas Woodfbf46022013-10-16 15:58:50 +01002828 /* 3D_Multi_present */
2829 multi_present = (db[8 + offset] & 0x60) >> 5;
2830 }
2831
Damien Lespiauc858cfc2013-09-25 16:45:23 +01002832 offset++;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002833 vic_len = db[8 + offset] >> 5;
Thomas Woodfbf46022013-10-16 15:58:50 +01002834 hdmi_3d_len = db[8 + offset] & 0x1f;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002835
2836 for (i = 0; i < vic_len && len >= (9 + offset + i); i++) {
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002837 u8 vic;
2838
2839 vic = db[9 + offset + i];
Damien Lespiau1deee8d2013-09-25 16:45:24 +01002840 modes += add_hdmi_mode(connector, vic);
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002841 }
Thomas Woodfbf46022013-10-16 15:58:50 +01002842 offset += 1 + vic_len;
2843
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002844 if (multi_present == 1)
2845 multi_len = 2;
2846 else if (multi_present == 2)
2847 multi_len = 4;
Thomas Woodfbf46022013-10-16 15:58:50 +01002848 else
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002849 multi_len = 0;
Thomas Woodfbf46022013-10-16 15:58:50 +01002850
Thomas Wood0e5083aa2013-11-29 18:18:58 +00002851 if (len < (8 + offset + hdmi_3d_len - 1))
2852 goto out;
2853
2854 if (hdmi_3d_len < multi_len)
2855 goto out;
2856
2857 if (multi_present == 1 || multi_present == 2) {
2858 /* 3D_Structure_ALL */
2859 structure_all = (db[8 + offset] << 8) | db[9 + offset];
2860
2861 /* check if 3D_MASK is present */
2862 if (multi_present == 2)
2863 mask = (db[10 + offset] << 8) | db[11 + offset];
2864 else
2865 mask = 0xffff;
2866
2867 for (i = 0; i < 16; i++) {
2868 if (mask & (1 << i))
2869 modes += add_3d_struct_modes(connector,
2870 structure_all,
2871 video_db,
2872 video_len, i);
2873 }
2874 }
2875
2876 offset += multi_len;
2877
2878 for (i = 0; i < (hdmi_3d_len - multi_len); i++) {
2879 int vic_index;
2880 struct drm_display_mode *newmode = NULL;
2881 unsigned int newflag = 0;
2882 bool detail_present;
2883
2884 detail_present = ((db[8 + offset + i] & 0x0f) > 7);
2885
2886 if (detail_present && (i + 1 == hdmi_3d_len - multi_len))
2887 break;
2888
2889 /* 2D_VIC_order_X */
2890 vic_index = db[8 + offset + i] >> 4;
2891
2892 /* 3D_Structure_X */
2893 switch (db[8 + offset + i] & 0x0f) {
2894 case 0:
2895 newflag = DRM_MODE_FLAG_3D_FRAME_PACKING;
2896 break;
2897 case 6:
2898 newflag = DRM_MODE_FLAG_3D_TOP_AND_BOTTOM;
2899 break;
2900 case 8:
2901 /* 3D_Detail_X */
2902 if ((db[9 + offset + i] >> 4) == 1)
2903 newflag = DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF;
2904 break;
2905 }
2906
2907 if (newflag != 0) {
2908 newmode = drm_display_mode_from_vic_index(connector,
2909 video_db,
2910 video_len,
2911 vic_index);
2912
2913 if (newmode) {
2914 newmode->flags |= newflag;
2915 drm_mode_probed_add(connector, newmode);
2916 modes++;
2917 }
2918 }
2919
2920 if (detail_present)
2921 i++;
Thomas Woodfbf46022013-10-16 15:58:50 +01002922 }
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002923
2924out:
2925 return modes;
2926}
2927
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002928static int
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002929cea_db_payload_len(const u8 *db)
2930{
2931 return db[0] & 0x1f;
2932}
2933
2934static int
2935cea_db_tag(const u8 *db)
2936{
2937 return db[0] >> 5;
2938}
2939
2940static int
2941cea_revision(const u8 *cea)
2942{
2943 return cea[1];
2944}
2945
2946static int
2947cea_db_offsets(const u8 *cea, int *start, int *end)
2948{
2949 /* Data block offset in CEA extension block */
2950 *start = 4;
2951 *end = cea[2];
2952 if (*end == 0)
2953 *end = 127;
2954 if (*end < 4 || *end > 127)
2955 return -ERANGE;
2956 return 0;
2957}
2958
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002959static bool cea_db_is_hdmi_vsdb(const u8 *db)
2960{
2961 int hdmi_id;
2962
2963 if (cea_db_tag(db) != VENDOR_BLOCK)
2964 return false;
2965
2966 if (cea_db_payload_len(db) < 5)
2967 return false;
2968
2969 hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
2970
Lespiau, Damien6cb3b7f2013-08-19 16:59:05 +01002971 return hdmi_id == HDMI_IEEE_OUI;
Lespiau, Damien7ebe1962013-08-19 16:58:54 +01002972}
2973
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002974#define for_each_cea_db(cea, i, start, end) \
2975 for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
2976
2977static int
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002978add_cea_modes(struct drm_connector *connector, struct edid *edid)
2979{
Lespiau, Damien13ac3f52013-08-19 16:58:53 +01002980 const u8 *cea = drm_find_cea_extension(edid);
Thomas Woodfbf46022013-10-16 15:58:50 +01002981 const u8 *db, *hdmi = NULL, *video = NULL;
2982 u8 dbl, hdmi_len, video_len = 0;
Christian Schmidt54ac76f2011-12-19 14:53:16 +00002983 int modes = 0;
2984
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00002985 if (cea && cea_revision(cea) >= 3) {
2986 int i, start, end;
2987
2988 if (cea_db_offsets(cea, &start, &end))
2989 return 0;
2990
2991 for_each_cea_db(cea, i, start, end) {
2992 db = &cea[i];
2993 dbl = cea_db_payload_len(db);
2994
Thomas Woodfbf46022013-10-16 15:58:50 +01002995 if (cea_db_tag(db) == VIDEO_BLOCK) {
2996 video = db + 1;
2997 video_len = dbl;
2998 modes += do_cea_modes(connector, video, dbl);
2999 }
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003000 else if (cea_db_is_hdmi_vsdb(db)) {
3001 hdmi = db;
3002 hdmi_len = dbl;
3003 }
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003004 }
3005 }
3006
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003007 /*
3008 * We parse the HDMI VSDB after having added the cea modes as we will
3009 * be patching their flags when the sink supports stereo 3D.
3010 */
3011 if (hdmi)
Thomas Woodfbf46022013-10-16 15:58:50 +01003012 modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video,
3013 video_len);
Damien Lespiauc858cfc2013-09-25 16:45:23 +01003014
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003015 return modes;
3016}
3017
Wu Fengguang76adaa342011-09-05 14:23:20 +08003018static void
Ville Syrjälä85040722012-08-16 14:55:05 +00003019parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
Wu Fengguang76adaa342011-09-05 14:23:20 +08003020{
Ville Syrjälä85040722012-08-16 14:55:05 +00003021 u8 len = cea_db_payload_len(db);
Wu Fengguang76adaa342011-09-05 14:23:20 +08003022
Ville Syrjälä85040722012-08-16 14:55:05 +00003023 if (len >= 6) {
3024 connector->eld[5] |= (db[6] >> 7) << 1; /* Supports_AI */
3025 connector->dvi_dual = db[6] & 1;
3026 }
3027 if (len >= 7)
3028 connector->max_tmds_clock = db[7] * 5;
3029 if (len >= 8) {
3030 connector->latency_present[0] = db[8] >> 7;
3031 connector->latency_present[1] = (db[8] >> 6) & 1;
3032 }
3033 if (len >= 9)
3034 connector->video_latency[0] = db[9];
3035 if (len >= 10)
3036 connector->audio_latency[0] = db[10];
3037 if (len >= 11)
3038 connector->video_latency[1] = db[11];
3039 if (len >= 12)
3040 connector->audio_latency[1] = db[12];
Wu Fengguang76adaa342011-09-05 14:23:20 +08003041
Daniel Vetter670c1ef2012-11-22 09:53:55 +01003042 DRM_DEBUG_KMS("HDMI: DVI dual %d, "
Wu Fengguang76adaa342011-09-05 14:23:20 +08003043 "max TMDS clock %d, "
3044 "latency present %d %d, "
3045 "video latency %d %d, "
3046 "audio latency %d %d\n",
3047 connector->dvi_dual,
3048 connector->max_tmds_clock,
3049 (int) connector->latency_present[0],
3050 (int) connector->latency_present[1],
3051 connector->video_latency[0],
3052 connector->video_latency[1],
3053 connector->audio_latency[0],
3054 connector->audio_latency[1]);
3055}
3056
3057static void
3058monitor_name(struct detailed_timing *t, void *data)
3059{
3060 if (t->data.other_data.type == EDID_DETAIL_MONITOR_NAME)
3061 *(u8 **)data = t->data.other_data.data.str.str;
3062}
3063
3064/**
3065 * drm_edid_to_eld - build ELD from EDID
3066 * @connector: connector corresponding to the HDMI/DP sink
3067 * @edid: EDID to parse
3068 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003069 * Fill the ELD (EDID-Like Data) buffer for passing to the audio driver. The
3070 * Conn_Type, HDCP and Port_ID ELD fields are left for the graphics driver to
3071 * fill in.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003072 */
3073void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid)
3074{
3075 uint8_t *eld = connector->eld;
3076 u8 *cea;
3077 u8 *name;
3078 u8 *db;
3079 int sad_count = 0;
3080 int mnl;
3081 int dbl;
3082
3083 memset(eld, 0, sizeof(connector->eld));
3084
3085 cea = drm_find_cea_extension(edid);
3086 if (!cea) {
3087 DRM_DEBUG_KMS("ELD: no CEA Extension found\n");
3088 return;
3089 }
3090
3091 name = NULL;
3092 drm_for_each_detailed_block((u8 *)edid, monitor_name, &name);
3093 for (mnl = 0; name && mnl < 13; mnl++) {
3094 if (name[mnl] == 0x0a)
3095 break;
3096 eld[20 + mnl] = name[mnl];
3097 }
3098 eld[4] = (cea[1] << 5) | mnl;
3099 DRM_DEBUG_KMS("ELD monitor %s\n", eld + 20);
3100
3101 eld[0] = 2 << 3; /* ELD version: 2 */
3102
3103 eld[16] = edid->mfg_id[0];
3104 eld[17] = edid->mfg_id[1];
3105 eld[18] = edid->prod_code[0];
3106 eld[19] = edid->prod_code[1];
3107
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003108 if (cea_revision(cea) >= 3) {
3109 int i, start, end;
3110
3111 if (cea_db_offsets(cea, &start, &end)) {
3112 start = 0;
3113 end = 0;
3114 }
3115
3116 for_each_cea_db(cea, i, start, end) {
3117 db = &cea[i];
3118 dbl = cea_db_payload_len(db);
3119
3120 switch (cea_db_tag(db)) {
Christian Schmidta0ab7342011-12-19 20:03:38 +01003121 case AUDIO_BLOCK:
3122 /* Audio Data Block, contains SADs */
3123 sad_count = dbl / 3;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003124 if (dbl >= 1)
3125 memcpy(eld + 20 + mnl, &db[1], dbl);
Christian Schmidta0ab7342011-12-19 20:03:38 +01003126 break;
3127 case SPEAKER_BLOCK:
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003128 /* Speaker Allocation Data Block */
3129 if (dbl >= 1)
3130 eld[7] = db[1];
Christian Schmidta0ab7342011-12-19 20:03:38 +01003131 break;
3132 case VENDOR_BLOCK:
3133 /* HDMI Vendor-Specific Data Block */
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003134 if (cea_db_is_hdmi_vsdb(db))
Christian Schmidta0ab7342011-12-19 20:03:38 +01003135 parse_hdmi_vsdb(connector, db);
3136 break;
3137 default:
3138 break;
3139 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003140 }
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003141 }
Wu Fengguang76adaa342011-09-05 14:23:20 +08003142 eld[5] |= sad_count << 4;
3143 eld[2] = (20 + mnl + sad_count * 3 + 3) / 4;
3144
3145 DRM_DEBUG_KMS("ELD size %d, SAD count %d\n", (int)eld[2], sad_count);
3146}
3147EXPORT_SYMBOL(drm_edid_to_eld);
3148
3149/**
Rafał Miłeckife214162013-04-19 19:01:25 +02003150 * drm_edid_to_sad - extracts SADs from EDID
3151 * @edid: EDID to parse
3152 * @sads: pointer that will be set to the extracted SADs
3153 *
3154 * Looks for CEA EDID block and extracts SADs (Short Audio Descriptors) from it.
Rafał Miłeckife214162013-04-19 19:01:25 +02003155 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003156 * Note: The returned pointer needs to be freed using kfree().
3157 *
3158 * Return: The number of found SADs or negative number on error.
Rafał Miłeckife214162013-04-19 19:01:25 +02003159 */
3160int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads)
3161{
3162 int count = 0;
3163 int i, start, end, dbl;
3164 u8 *cea;
3165
3166 cea = drm_find_cea_extension(edid);
3167 if (!cea) {
3168 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3169 return -ENOENT;
3170 }
3171
3172 if (cea_revision(cea) < 3) {
3173 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3174 return -ENOTSUPP;
3175 }
3176
3177 if (cea_db_offsets(cea, &start, &end)) {
3178 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3179 return -EPROTO;
3180 }
3181
3182 for_each_cea_db(cea, i, start, end) {
3183 u8 *db = &cea[i];
3184
3185 if (cea_db_tag(db) == AUDIO_BLOCK) {
3186 int j;
3187 dbl = cea_db_payload_len(db);
3188
3189 count = dbl / 3; /* SAD is 3B */
3190 *sads = kcalloc(count, sizeof(**sads), GFP_KERNEL);
3191 if (!*sads)
3192 return -ENOMEM;
3193 for (j = 0; j < count; j++) {
3194 u8 *sad = &db[1 + j * 3];
3195
3196 (*sads)[j].format = (sad[0] & 0x78) >> 3;
3197 (*sads)[j].channels = sad[0] & 0x7;
3198 (*sads)[j].freq = sad[1] & 0x7F;
3199 (*sads)[j].byte2 = sad[2];
3200 }
3201 break;
3202 }
3203 }
3204
3205 return count;
3206}
3207EXPORT_SYMBOL(drm_edid_to_sad);
3208
3209/**
Alex Deucherd105f472013-07-25 15:55:32 -04003210 * drm_edid_to_speaker_allocation - extracts Speaker Allocation Data Blocks from EDID
3211 * @edid: EDID to parse
3212 * @sadb: pointer to the speaker block
3213 *
3214 * Looks for CEA EDID block and extracts the Speaker Allocation Data Block from it.
Alex Deucherd105f472013-07-25 15:55:32 -04003215 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003216 * Note: The returned pointer needs to be freed using kfree().
3217 *
3218 * Return: The number of found Speaker Allocation Blocks or negative number on
3219 * error.
Alex Deucherd105f472013-07-25 15:55:32 -04003220 */
3221int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb)
3222{
3223 int count = 0;
3224 int i, start, end, dbl;
3225 const u8 *cea;
3226
3227 cea = drm_find_cea_extension(edid);
3228 if (!cea) {
3229 DRM_DEBUG_KMS("SAD: no CEA Extension found\n");
3230 return -ENOENT;
3231 }
3232
3233 if (cea_revision(cea) < 3) {
3234 DRM_DEBUG_KMS("SAD: wrong CEA revision\n");
3235 return -ENOTSUPP;
3236 }
3237
3238 if (cea_db_offsets(cea, &start, &end)) {
3239 DRM_DEBUG_KMS("SAD: invalid data block offsets\n");
3240 return -EPROTO;
3241 }
3242
3243 for_each_cea_db(cea, i, start, end) {
3244 const u8 *db = &cea[i];
3245
3246 if (cea_db_tag(db) == SPEAKER_BLOCK) {
3247 dbl = cea_db_payload_len(db);
3248
3249 /* Speaker Allocation Data Block */
3250 if (dbl == 3) {
Benoit Taine89086bc2014-05-26 17:21:22 +02003251 *sadb = kmemdup(&db[1], dbl, GFP_KERNEL);
Alex Deucher618e3772013-09-27 18:46:09 -04003252 if (!*sadb)
3253 return -ENOMEM;
Alex Deucherd105f472013-07-25 15:55:32 -04003254 count = dbl;
3255 break;
3256 }
3257 }
3258 }
3259
3260 return count;
3261}
3262EXPORT_SYMBOL(drm_edid_to_speaker_allocation);
3263
3264/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003265 * drm_av_sync_delay - compute the HDMI/DP sink audio-video sync delay
Wu Fengguang76adaa342011-09-05 14:23:20 +08003266 * @connector: connector associated with the HDMI/DP sink
3267 * @mode: the display mode
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003268 *
3269 * Return: The HDMI/DP sink's audio-video sync delay in milliseconds or 0 if
3270 * the sink doesn't support audio or video.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003271 */
3272int drm_av_sync_delay(struct drm_connector *connector,
3273 struct drm_display_mode *mode)
3274{
3275 int i = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
3276 int a, v;
3277
3278 if (!connector->latency_present[0])
3279 return 0;
3280 if (!connector->latency_present[1])
3281 i = 0;
3282
3283 a = connector->audio_latency[i];
3284 v = connector->video_latency[i];
3285
3286 /*
3287 * HDMI/DP sink doesn't support audio or video?
3288 */
3289 if (a == 255 || v == 255)
3290 return 0;
3291
3292 /*
3293 * Convert raw EDID values to millisecond.
3294 * Treat unknown latency as 0ms.
3295 */
3296 if (a)
3297 a = min(2 * (a - 1), 500);
3298 if (v)
3299 v = min(2 * (v - 1), 500);
3300
3301 return max(v - a, 0);
3302}
3303EXPORT_SYMBOL(drm_av_sync_delay);
3304
3305/**
3306 * drm_select_eld - select one ELD from multiple HDMI/DP sinks
3307 * @encoder: the encoder just changed display mode
3308 * @mode: the adjusted display mode
3309 *
3310 * It's possible for one encoder to be associated with multiple HDMI/DP sinks.
3311 * The policy is now hard coded to simply use the first HDMI/DP sink's ELD.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003312 *
3313 * Return: The connector associated with the first HDMI/DP sink that has ELD
3314 * attached to it.
Wu Fengguang76adaa342011-09-05 14:23:20 +08003315 */
3316struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
3317 struct drm_display_mode *mode)
3318{
3319 struct drm_connector *connector;
3320 struct drm_device *dev = encoder->dev;
3321
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003322 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
Sean Paul008f4042014-07-17 11:25:18 -04003323 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003324
Wu Fengguang76adaa342011-09-05 14:23:20 +08003325 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
3326 if (connector->encoder == encoder && connector->eld[0])
3327 return connector;
3328
3329 return NULL;
3330}
3331EXPORT_SYMBOL(drm_select_eld);
3332
Ma Lingf23c20c2009-03-26 19:26:23 +08003333/**
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003334 * drm_detect_hdmi_monitor - detect whether monitor is HDMI
Ma Lingf23c20c2009-03-26 19:26:23 +08003335 * @edid: monitor EDID information
3336 *
3337 * Parse the CEA extension according to CEA-861-B.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003338 *
3339 * Return: True if the monitor is HDMI, false if not or unknown.
Ma Lingf23c20c2009-03-26 19:26:23 +08003340 */
3341bool drm_detect_hdmi_monitor(struct edid *edid)
3342{
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003343 u8 *edid_ext;
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003344 int i;
Ma Lingf23c20c2009-03-26 19:26:23 +08003345 int start_offset, end_offset;
Ma Lingf23c20c2009-03-26 19:26:23 +08003346
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003347 edid_ext = drm_find_cea_extension(edid);
3348 if (!edid_ext)
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003349 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003350
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003351 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003352 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003353
3354 /*
3355 * Because HDMI identifier is in Vendor Specific Block,
3356 * search it from all data blocks of CEA extension.
3357 */
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003358 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003359 if (cea_db_is_hdmi_vsdb(&edid_ext[i]))
3360 return true;
Ma Lingf23c20c2009-03-26 19:26:23 +08003361 }
3362
Ville Syrjälä14f77fd2012-08-16 14:55:06 +00003363 return false;
Ma Lingf23c20c2009-03-26 19:26:23 +08003364}
3365EXPORT_SYMBOL(drm_detect_hdmi_monitor);
3366
Dave Airlief453ba02008-11-07 14:05:41 -08003367/**
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003368 * drm_detect_monitor_audio - check monitor audio capability
Daniel Vetterfc668112014-01-21 12:02:26 +01003369 * @edid: EDID block to scan
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003370 *
3371 * Monitor should have CEA extension block.
3372 * If monitor has 'basic audio', but no CEA audio blocks, it's 'basic
3373 * audio' only. If there is any audio extension block and supported
3374 * audio format, assume at least 'basic audio' support, even if 'basic
3375 * audio' is not defined in EDID.
3376 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003377 * Return: True if the monitor supports audio, false otherwise.
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003378 */
3379bool drm_detect_monitor_audio(struct edid *edid)
3380{
3381 u8 *edid_ext;
3382 int i, j;
3383 bool has_audio = false;
3384 int start_offset, end_offset;
3385
3386 edid_ext = drm_find_cea_extension(edid);
3387 if (!edid_ext)
3388 goto end;
3389
3390 has_audio = ((edid_ext[3] & EDID_BASIC_AUDIO) != 0);
3391
3392 if (has_audio) {
3393 DRM_DEBUG_KMS("Monitor has basic audio support\n");
3394 goto end;
3395 }
3396
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003397 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3398 goto end;
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003399
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003400 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3401 if (cea_db_tag(&edid_ext[i]) == AUDIO_BLOCK) {
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003402 has_audio = true;
Ville Syrjälä9e50b9d2012-08-16 14:55:04 +00003403 for (j = 1; j < cea_db_payload_len(&edid_ext[i]) + 1; j += 3)
Zhenyu Wang8fe97902010-09-19 14:27:28 +08003404 DRM_DEBUG_KMS("CEA audio format %d\n",
3405 (edid_ext[i + j] >> 3) & 0xf);
3406 goto end;
3407 }
3408 }
3409end:
3410 return has_audio;
3411}
3412EXPORT_SYMBOL(drm_detect_monitor_audio);
3413
3414/**
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003415 * drm_rgb_quant_range_selectable - is RGB quantization range selectable?
Daniel Vetterfc668112014-01-21 12:02:26 +01003416 * @edid: EDID block to scan
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003417 *
3418 * Check whether the monitor reports the RGB quantization range selection
3419 * as supported. The AVI infoframe can then be used to inform the monitor
3420 * which quantization range (full or limited) is used.
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003421 *
3422 * Return: True if the RGB quantization range is selectable, false otherwise.
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02003423 */
3424bool drm_rgb_quant_range_selectable(struct edid *edid)
3425{
3426 u8 *edid_ext;
3427 int i, start, end;
3428
3429 edid_ext = drm_find_cea_extension(edid);
3430 if (!edid_ext)
3431 return false;
3432
3433 if (cea_db_offsets(edid_ext, &start, &end))
3434 return false;
3435
3436 for_each_cea_db(edid_ext, i, start, end) {
3437 if (cea_db_tag(&edid_ext[i]) == VIDEO_CAPABILITY_BLOCK &&
3438 cea_db_payload_len(&edid_ext[i]) == 2) {
3439 DRM_DEBUG_KMS("CEA VCDB 0x%02x\n", edid_ext[i + 2]);
3440 return edid_ext[i + 2] & EDID_CEA_VCDB_QS;
3441 }
3442 }
3443
3444 return false;
3445}
3446EXPORT_SYMBOL(drm_rgb_quant_range_selectable);
3447
3448/**
Mario Kleinerd0c94692014-03-27 19:59:39 +01003449 * drm_assign_hdmi_deep_color_info - detect whether monitor supports
3450 * hdmi deep color modes and update drm_display_info if so.
Mario Kleinerd0c94692014-03-27 19:59:39 +01003451 * @edid: monitor EDID information
3452 * @info: Updated with maximum supported deep color bpc and color format
3453 * if deep color supported.
Daniel Vetter295ee852014-07-30 14:23:44 +02003454 * @connector: DRM connector, used only for debug output
Mario Kleinerd0c94692014-03-27 19:59:39 +01003455 *
3456 * Parse the CEA extension according to CEA-861-B.
3457 * Return true if HDMI deep color supported, false if not or unknown.
3458 */
3459static bool drm_assign_hdmi_deep_color_info(struct edid *edid,
3460 struct drm_display_info *info,
3461 struct drm_connector *connector)
3462{
3463 u8 *edid_ext, *hdmi;
3464 int i;
3465 int start_offset, end_offset;
3466 unsigned int dc_bpc = 0;
3467
3468 edid_ext = drm_find_cea_extension(edid);
3469 if (!edid_ext)
3470 return false;
3471
3472 if (cea_db_offsets(edid_ext, &start_offset, &end_offset))
3473 return false;
3474
3475 /*
3476 * Because HDMI identifier is in Vendor Specific Block,
3477 * search it from all data blocks of CEA extension.
3478 */
3479 for_each_cea_db(edid_ext, i, start_offset, end_offset) {
3480 if (cea_db_is_hdmi_vsdb(&edid_ext[i])) {
3481 /* HDMI supports at least 8 bpc */
3482 info->bpc = 8;
3483
3484 hdmi = &edid_ext[i];
3485 if (cea_db_payload_len(hdmi) < 6)
3486 return false;
3487
3488 if (hdmi[6] & DRM_EDID_HDMI_DC_30) {
3489 dc_bpc = 10;
Mario Kleiner5d02626d2014-06-05 09:52:10 -04003490 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_30;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003491 DRM_DEBUG("%s: HDMI sink does deep color 30.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003492 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003493 }
3494
3495 if (hdmi[6] & DRM_EDID_HDMI_DC_36) {
3496 dc_bpc = 12;
Mario Kleiner5d02626d2014-06-05 09:52:10 -04003497 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_36;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003498 DRM_DEBUG("%s: HDMI sink does deep color 36.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003499 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003500 }
3501
3502 if (hdmi[6] & DRM_EDID_HDMI_DC_48) {
3503 dc_bpc = 16;
Mario Kleiner5d02626d2014-06-05 09:52:10 -04003504 info->edid_hdmi_dc_modes |= DRM_EDID_HDMI_DC_48;
Mario Kleinerd0c94692014-03-27 19:59:39 +01003505 DRM_DEBUG("%s: HDMI sink does deep color 48.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003506 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003507 }
3508
3509 if (dc_bpc > 0) {
3510 DRM_DEBUG("%s: Assigning HDMI sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003511 connector->name, dc_bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003512 info->bpc = dc_bpc;
3513
3514 /*
3515 * Deep color support mandates RGB444 support for all video
3516 * modes and forbids YCRCB422 support for all video modes per
3517 * HDMI 1.3 spec.
3518 */
3519 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3520
3521 /* YCRCB444 is optional according to spec. */
3522 if (hdmi[6] & DRM_EDID_HDMI_DC_Y444) {
3523 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3524 DRM_DEBUG("%s: HDMI sink does YCRCB444 in deep color.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003525 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003526 }
3527
3528 /*
3529 * Spec says that if any deep color mode is supported at all,
3530 * then deep color 36 bit must be supported.
3531 */
3532 if (!(hdmi[6] & DRM_EDID_HDMI_DC_36)) {
3533 DRM_DEBUG("%s: HDMI sink should do DC_36, but does not!\n",
Jani Nikula25933822014-06-03 14:56:20 +03003534 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003535 }
3536
3537 return true;
3538 }
3539 else {
3540 DRM_DEBUG("%s: No deep color support on this HDMI sink.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003541 connector->name);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003542 }
3543 }
3544 }
3545
3546 return false;
3547}
3548
3549/**
Jesse Barnes3b112282011-04-15 12:49:23 -07003550 * drm_add_display_info - pull display info out if present
3551 * @edid: EDID data
3552 * @info: display info (attached to connector)
Mario Kleinerd0c94692014-03-27 19:59:39 +01003553 * @connector: connector whose edid is used to build display info
Jesse Barnes3b112282011-04-15 12:49:23 -07003554 *
3555 * Grab any available display info and stuff it into the drm_display_info
3556 * structure that's part of the connector. Useful for tracking bpp and
3557 * color spaces.
3558 */
3559static void drm_add_display_info(struct edid *edid,
Mario Kleinerd0c94692014-03-27 19:59:39 +01003560 struct drm_display_info *info,
3561 struct drm_connector *connector)
Jesse Barnes3b112282011-04-15 12:49:23 -07003562{
Jesse Barnesebec9a72011-08-03 09:22:54 -07003563 u8 *edid_ext;
3564
Jesse Barnes3b112282011-04-15 12:49:23 -07003565 info->width_mm = edid->width_cm * 10;
3566 info->height_mm = edid->height_cm * 10;
3567
3568 /* driver figures it out in this case */
3569 info->bpc = 0;
Jesse Barnesda05a5a72011-04-15 13:48:57 -07003570 info->color_formats = 0;
Jesse Barnes3b112282011-04-15 12:49:23 -07003571
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003572 if (edid->revision < 3)
Jesse Barnes3b112282011-04-15 12:49:23 -07003573 return;
3574
3575 if (!(edid->input & DRM_EDID_INPUT_DIGITAL))
3576 return;
3577
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003578 /* Get data from CEA blocks if present */
3579 edid_ext = drm_find_cea_extension(edid);
3580 if (edid_ext) {
3581 info->cea_rev = edid_ext[1];
3582
3583 /* The existence of a CEA block should imply RGB support */
3584 info->color_formats = DRM_COLOR_FORMAT_RGB444;
3585 if (edid_ext[3] & EDID_CEA_YCRCB444)
3586 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3587 if (edid_ext[3] & EDID_CEA_YCRCB422)
3588 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
3589 }
3590
Mario Kleinerd0c94692014-03-27 19:59:39 +01003591 /* HDMI deep color modes supported? Assign to info, if so */
3592 drm_assign_hdmi_deep_color_info(edid, info, connector);
3593
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003594 /* Only defined for 1.4 with digital displays */
3595 if (edid->revision < 4)
3596 return;
3597
Jesse Barnes3b112282011-04-15 12:49:23 -07003598 switch (edid->input & DRM_EDID_DIGITAL_DEPTH_MASK) {
3599 case DRM_EDID_DIGITAL_DEPTH_6:
3600 info->bpc = 6;
3601 break;
3602 case DRM_EDID_DIGITAL_DEPTH_8:
3603 info->bpc = 8;
3604 break;
3605 case DRM_EDID_DIGITAL_DEPTH_10:
3606 info->bpc = 10;
3607 break;
3608 case DRM_EDID_DIGITAL_DEPTH_12:
3609 info->bpc = 12;
3610 break;
3611 case DRM_EDID_DIGITAL_DEPTH_14:
3612 info->bpc = 14;
3613 break;
3614 case DRM_EDID_DIGITAL_DEPTH_16:
3615 info->bpc = 16;
3616 break;
3617 case DRM_EDID_DIGITAL_DEPTH_UNDEF:
3618 default:
3619 info->bpc = 0;
3620 break;
3621 }
Jesse Barnesda05a5a72011-04-15 13:48:57 -07003622
Mario Kleinerd0c94692014-03-27 19:59:39 +01003623 DRM_DEBUG("%s: Assigning EDID-1.4 digital sink color depth as %d bpc.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003624 connector->name, info->bpc);
Mario Kleinerd0c94692014-03-27 19:59:39 +01003625
Lars-Peter Clausena988bc72012-04-16 15:16:19 +02003626 info->color_formats |= DRM_COLOR_FORMAT_RGB444;
Lars-Peter Clausenee588082012-04-16 15:16:18 +02003627 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB444)
3628 info->color_formats |= DRM_COLOR_FORMAT_YCRCB444;
3629 if (edid->features & DRM_EDID_FEATURE_RGB_YCRCB422)
3630 info->color_formats |= DRM_COLOR_FORMAT_YCRCB422;
Jesse Barnes3b112282011-04-15 12:49:23 -07003631}
3632
3633/**
Dave Airlief453ba02008-11-07 14:05:41 -08003634 * drm_add_edid_modes - add modes from EDID data, if available
3635 * @connector: connector we're probing
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003636 * @edid: EDID data
Dave Airlief453ba02008-11-07 14:05:41 -08003637 *
3638 * Add the specified modes to the connector's mode list.
3639 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003640 * Return: The number of modes added or 0 if we couldn't find any.
Dave Airlief453ba02008-11-07 14:05:41 -08003641 */
3642int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid)
3643{
3644 int num_modes = 0;
3645 u32 quirks;
3646
3647 if (edid == NULL) {
3648 return 0;
3649 }
Alex Deucher3c537882010-02-05 04:21:19 -05003650 if (!drm_edid_is_valid(edid)) {
Jordan Crousedcdb1672010-05-27 13:40:25 -06003651 dev_warn(connector->dev->dev, "%s: EDID invalid.\n",
Jani Nikula25933822014-06-03 14:56:20 +03003652 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -08003653 return 0;
3654 }
3655
3656 quirks = edid_get_quirks(edid);
3657
Adam Jacksonc867df72010-03-29 21:43:21 +00003658 /*
3659 * EDID spec says modes should be preferred in this order:
3660 * - preferred detailed mode
3661 * - other detailed modes from base block
3662 * - detailed modes from extension blocks
3663 * - CVT 3-byte code modes
3664 * - standard timing codes
3665 * - established timing codes
3666 * - modes inferred from GTF or CVT range information
3667 *
Adam Jackson13931572010-08-03 14:38:19 -04003668 * We get this pretty much right.
Adam Jacksonc867df72010-03-29 21:43:21 +00003669 *
3670 * XXX order for additional mode types in extension blocks?
3671 */
Adam Jackson13931572010-08-03 14:38:19 -04003672 num_modes += add_detailed_modes(connector, edid, quirks);
3673 num_modes += add_cvt_modes(connector, edid);
Adam Jacksonc867df72010-03-29 21:43:21 +00003674 num_modes += add_standard_modes(connector, edid);
3675 num_modes += add_established_modes(connector, edid);
Paulo Zanoni196e0772013-02-15 13:36:27 -02003676 if (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)
3677 num_modes += add_inferred_modes(connector, edid);
Christian Schmidt54ac76f2011-12-19 14:53:16 +00003678 num_modes += add_cea_modes(connector, edid);
Ville Syrjäläe6e79202013-05-31 15:23:41 +03003679 num_modes += add_alternate_cea_modes(connector, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08003680
3681 if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75))
3682 edid_fixup_preferred(connector, quirks);
3683
Mario Kleinerd0c94692014-03-27 19:59:39 +01003684 drm_add_display_info(edid, &connector->display_info, connector);
Dave Airlief453ba02008-11-07 14:05:41 -08003685
Rafał Miłecki49d45a312013-12-07 13:22:42 +01003686 if (quirks & EDID_QUIRK_FORCE_8BPC)
3687 connector->display_info.bpc = 8;
3688
Mario Kleinerbc5b9642014-05-23 21:40:55 +02003689 if (quirks & EDID_QUIRK_FORCE_12BPC)
3690 connector->display_info.bpc = 12;
3691
Dave Airlief453ba02008-11-07 14:05:41 -08003692 return num_modes;
3693}
3694EXPORT_SYMBOL(drm_add_edid_modes);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003695
3696/**
3697 * drm_add_modes_noedid - add modes for the connectors without EDID
3698 * @connector: connector we're probing
3699 * @hdisplay: the horizontal display limit
3700 * @vdisplay: the vertical display limit
3701 *
3702 * Add the specified modes to the connector's mode list. Only when the
3703 * hdisplay/vdisplay is not beyond the given limit, it will be added.
3704 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003705 * Return: The number of modes added or 0 if we couldn't find any.
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003706 */
3707int drm_add_modes_noedid(struct drm_connector *connector,
3708 int hdisplay, int vdisplay)
3709{
3710 int i, count, num_modes = 0;
Chris Wilsonb1f559e2011-01-26 09:49:47 +00003711 struct drm_display_mode *mode;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003712 struct drm_device *dev = connector->dev;
3713
3714 count = sizeof(drm_dmt_modes) / sizeof(struct drm_display_mode);
3715 if (hdisplay < 0)
3716 hdisplay = 0;
3717 if (vdisplay < 0)
3718 vdisplay = 0;
3719
3720 for (i = 0; i < count; i++) {
Chris Wilsonb1f559e2011-01-26 09:49:47 +00003721 const struct drm_display_mode *ptr = &drm_dmt_modes[i];
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003722 if (hdisplay && vdisplay) {
3723 /*
3724 * Only when two are valid, they will be used to check
3725 * whether the mode should be added to the mode list of
3726 * the connector.
3727 */
3728 if (ptr->hdisplay > hdisplay ||
3729 ptr->vdisplay > vdisplay)
3730 continue;
3731 }
Adam Jacksonf985ded2009-11-23 14:23:04 -05003732 if (drm_mode_vrefresh(ptr) > 61)
3733 continue;
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08003734 mode = drm_mode_duplicate(dev, ptr);
3735 if (mode) {
3736 drm_mode_probed_add(connector, mode);
3737 num_modes++;
3738 }
3739 }
3740 return num_modes;
3741}
3742EXPORT_SYMBOL(drm_add_modes_noedid);
Thierry Reding10a85122012-11-21 15:31:35 +01003743
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003744/**
3745 * drm_set_preferred_mode - Sets the preferred mode of a connector
3746 * @connector: connector whose mode list should be processed
3747 * @hpref: horizontal resolution of preferred mode
3748 * @vpref: vertical resolution of preferred mode
3749 *
3750 * Marks a mode as preferred if it matches the resolution specified by @hpref
3751 * and @vpref.
3752 */
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02003753void drm_set_preferred_mode(struct drm_connector *connector,
3754 int hpref, int vpref)
3755{
3756 struct drm_display_mode *mode;
3757
3758 list_for_each_entry(mode, &connector->probed_modes, head) {
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003759 if (mode->hdisplay == hpref &&
Daniel Vetter9d3de132014-01-23 16:27:56 +01003760 mode->vdisplay == vpref)
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02003761 mode->type |= DRM_MODE_TYPE_PREFERRED;
3762 }
3763}
3764EXPORT_SYMBOL(drm_set_preferred_mode);
3765
Thierry Reding10a85122012-11-21 15:31:35 +01003766/**
3767 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
3768 * data from a DRM display mode
3769 * @frame: HDMI AVI infoframe
3770 * @mode: DRM display mode
3771 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003772 * Return: 0 on success or a negative error code on failure.
Thierry Reding10a85122012-11-21 15:31:35 +01003773 */
3774int
3775drm_hdmi_avi_infoframe_from_display_mode(struct hdmi_avi_infoframe *frame,
3776 const struct drm_display_mode *mode)
3777{
3778 int err;
3779
3780 if (!frame || !mode)
3781 return -EINVAL;
3782
3783 err = hdmi_avi_infoframe_init(frame);
3784 if (err < 0)
3785 return err;
3786
Damien Lespiaubf02db92013-08-06 20:32:22 +01003787 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
3788 frame->pixel_repeat = 1;
3789
Thierry Reding10a85122012-11-21 15:31:35 +01003790 frame->video_code = drm_match_cea_mode(mode);
Thierry Reding10a85122012-11-21 15:31:35 +01003791
3792 frame->picture_aspect = HDMI_PICTURE_ASPECT_NONE;
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303793
Vandana Kannan69ab6d32014-06-05 14:45:29 +05303794 /*
3795 * Populate picture aspect ratio from either
3796 * user input (if specified) or from the CEA mode list.
3797 */
3798 if (mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_4_3 ||
3799 mode->picture_aspect_ratio == HDMI_PICTURE_ASPECT_16_9)
3800 frame->picture_aspect = mode->picture_aspect_ratio;
3801 else if (frame->video_code > 0)
Vandana Kannan0967e6a2014-04-01 16:26:59 +05303802 frame->picture_aspect = drm_get_cea_aspect_ratio(
3803 frame->video_code);
3804
Thierry Reding10a85122012-11-21 15:31:35 +01003805 frame->active_aspect = HDMI_ACTIVE_ASPECT_PICTURE;
Daniel Drake24d01802014-02-27 09:19:30 -06003806 frame->scan_mode = HDMI_SCAN_MODE_UNDERSCAN;
Thierry Reding10a85122012-11-21 15:31:35 +01003807
3808 return 0;
3809}
3810EXPORT_SYMBOL(drm_hdmi_avi_infoframe_from_display_mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003811
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003812static enum hdmi_3d_structure
3813s3d_structure_from_display_mode(const struct drm_display_mode *mode)
3814{
3815 u32 layout = mode->flags & DRM_MODE_FLAG_3D_MASK;
3816
3817 switch (layout) {
3818 case DRM_MODE_FLAG_3D_FRAME_PACKING:
3819 return HDMI_3D_STRUCTURE_FRAME_PACKING;
3820 case DRM_MODE_FLAG_3D_FIELD_ALTERNATIVE:
3821 return HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE;
3822 case DRM_MODE_FLAG_3D_LINE_ALTERNATIVE:
3823 return HDMI_3D_STRUCTURE_LINE_ALTERNATIVE;
3824 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_FULL:
3825 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL;
3826 case DRM_MODE_FLAG_3D_L_DEPTH:
3827 return HDMI_3D_STRUCTURE_L_DEPTH;
3828 case DRM_MODE_FLAG_3D_L_DEPTH_GFX_GFX_DEPTH:
3829 return HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH;
3830 case DRM_MODE_FLAG_3D_TOP_AND_BOTTOM:
3831 return HDMI_3D_STRUCTURE_TOP_AND_BOTTOM;
3832 case DRM_MODE_FLAG_3D_SIDE_BY_SIDE_HALF:
3833 return HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF;
3834 default:
3835 return HDMI_3D_STRUCTURE_INVALID;
3836 }
3837}
3838
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003839/**
3840 * drm_hdmi_vendor_infoframe_from_display_mode() - fill an HDMI infoframe with
3841 * data from a DRM display mode
3842 * @frame: HDMI vendor infoframe
3843 * @mode: DRM display mode
3844 *
3845 * Note that there's is a need to send HDMI vendor infoframes only when using a
3846 * 4k or stereoscopic 3D mode. So when giving any other mode as input this
3847 * function will return -EINVAL, error that can be safely ignored.
3848 *
Thierry Redingdb6cf8332014-04-29 11:44:34 +02003849 * Return: 0 on success or a negative error code on failure.
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003850 */
3851int
3852drm_hdmi_vendor_infoframe_from_display_mode(struct hdmi_vendor_infoframe *frame,
3853 const struct drm_display_mode *mode)
3854{
3855 int err;
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003856 u32 s3d_flags;
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003857 u8 vic;
3858
3859 if (!frame || !mode)
3860 return -EINVAL;
3861
3862 vic = drm_match_hdmi_mode(mode);
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003863 s3d_flags = mode->flags & DRM_MODE_FLAG_3D_MASK;
3864
3865 if (!vic && !s3d_flags)
3866 return -EINVAL;
3867
3868 if (vic && s3d_flags)
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003869 return -EINVAL;
3870
3871 err = hdmi_vendor_infoframe_init(frame);
3872 if (err < 0)
3873 return err;
3874
Damien Lespiau4eed4a02013-09-25 16:45:26 +01003875 if (vic)
3876 frame->vic = vic;
3877 else
3878 frame->s3d_struct = s3d_structure_from_display_mode(mode);
Lespiau, Damien83dd0002013-08-19 16:59:03 +01003879
3880 return 0;
3881}
3882EXPORT_SYMBOL(drm_hdmi_vendor_infoframe_from_display_mode);