edid-decode: bit 1 of DTS-HD value indicates DTS:X
[edid-decode.git] / parse-base-block.cpp
blob61468d0f531d366bb8abcfde4a4491111f924f54
1 // SPDX-License-Identifier: MIT
2 /*
3 * Copyright 2006-2012 Red Hat, Inc.
4 * Copyright 2018-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * Author: Adam Jackson <ajax@nwnk.net>
7 * Maintainer: Hans Verkuil <hverkuil-cisco@xs4all.nl>
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <math.h>
13 #include <time.h>
15 #include "edid-decode.h"
17 static char *manufacturer_name(const unsigned char *x)
19 static char name[4];
21 name[0] = ((x[0] & 0x7c) >> 2) + '@';
22 name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xe0) >> 5) + '@';
23 name[2] = (x[1] & 0x1f) + '@';
24 name[3] = 0;
26 if (!isupper(name[0]) || !isupper(name[1]) || !isupper(name[2]))
27 fail("Manufacturer name field contains garbage.\n");
29 return name;
32 static const struct {
33 unsigned dmt_id;
34 unsigned std_id;
35 unsigned cvt_id;
36 struct timings t;
37 } dmt_timings[] = {
38 { 0x01, 0x0000, 0x000000, { 640, 350, 64, 35, 31500, 0, false,
39 32, 64, 96, true, 32, 3, 60, false } },
41 { 0x02, 0x3119, 0x000000, { 640, 400, 16, 10, 31500, 0, false,
42 32, 64, 96, false, 1, 3, 41, true } },
44 { 0x03, 0x0000, 0x000000, { 720, 400, 9, 5, 35500, 0, false,
45 36, 72, 108, false, 1, 3, 42, true } },
47 { 0x04, 0x3140, 0x000000, { 640, 480, 4, 3, 25175, 0, false,
48 8, 96, 40, false, 2, 2, 25, false, 8, 8 } },
49 { 0x05, 0x314c, 0x000000, { 640, 480, 4, 3, 31500, 0, false,
50 16, 40, 120, false, 1, 3, 20, false, 8, 8 } },
51 { 0x06, 0x314f, 0x000000, { 640, 480, 4, 3, 31500, 0, false,
52 16, 64, 120, false, 1, 3, 16, false } },
53 { 0x07, 0x3159, 0x000000, { 640, 480, 4, 3, 36000, 0, false,
54 56, 56, 80, false, 1, 3, 25, false } },
56 { 0x08, 0x0000, 0x000000, { 800, 600, 4, 3, 36000, 0, false,
57 24, 72, 128, true, 1, 2, 22, true } },
58 { 0x09, 0x4540, 0x000000, { 800, 600, 4, 3, 40000, 0, false,
59 40, 128, 88, true, 1, 4, 23, true } },
60 { 0x0a, 0x454c, 0x000000, { 800, 600, 4, 3, 50000, 0, false,
61 56, 120, 64, true, 37, 6, 23, true } },
62 { 0x0b, 0x454f, 0x000000, { 800, 600, 4, 3, 49500, 0, false,
63 16, 80, 160, true, 1, 3, 21, true } },
64 { 0x0c, 0x4559, 0x000000, { 800, 600, 4, 3, 56250, 0, false,
65 32, 64, 152, true, 1, 3, 27, true } },
66 { 0x0d, 0x0000, 0x000000, { 800, 600, 4, 3, 73250, 1, false,
67 48, 32, 80, true, 3, 4, 29, false } },
69 { 0x0e, 0x0000, 0x000000, { 848, 480, 16, 9, 33750, 0, false,
70 16, 112, 112, true, 6, 8, 23, true } },
72 { 0x0f, 0x0000, 0x000000, { 1024, 768, 4, 3, 44900, 0, true,
73 8, 176, 56, true, 0, 4, 20, true } },
74 { 0x10, 0x6140, 0x000000, { 1024, 768, 4, 3, 65000, 0, false,
75 24, 136, 160, false, 3, 6, 29, false } },
76 { 0x11, 0x614c, 0x000000, { 1024, 768, 4, 3, 75000, 0, false,
77 24, 136, 144, false, 3, 6, 29, false } },
78 { 0x12, 0x614f, 0x000000, { 1024, 768, 4, 3, 78750, 0, false,
79 16, 96, 176, true, 1, 3, 28, true } },
80 { 0x13, 0x6159, 0x000000, { 1024, 768, 4, 3, 94500, 0, false,
81 48, 96, 208, true, 1, 3, 36, true } },
82 { 0x14, 0x0000, 0x000000, { 1024, 768, 4, 3, 115500, 1, false,
83 48, 32, 80, true, 3, 4, 38, false } },
85 { 0x15, 0x714f, 0x000000, { 1152, 864, 4, 3, 108000, 0, false,
86 64, 128, 256, true, 1, 3, 32, true } },
88 { 0x55, 0x81c0, 0x000000, { 1280, 720, 16, 9, 74250, 0, false,
89 110, 40, 220, true, 5, 5, 20, true } },
91 { 0x16, 0x0000, 0x7f1c21, { 1280, 768, 5, 3, 68250, 1, false,
92 48, 32, 80, true, 3, 7, 12, false } },
93 { 0x17, 0x0000, 0x7f1c28, { 1280, 768, 5, 3, 79500, 0, false,
94 64, 128, 192, false, 3, 7, 20, true } },
95 { 0x18, 0x0000, 0x7f1c44, { 1280, 768, 5, 3, 102250, 0, false,
96 80, 128, 208, false, 3, 7, 27, true } },
97 { 0x19, 0x0000, 0x7f1c62, { 1280, 768, 5, 3, 117500, 0, false,
98 80, 136, 216, false, 3, 7, 31, true } },
99 { 0x1a, 0x0000, 0x000000, { 1280, 768, 5, 3, 140250, 0, false,
100 48, 32, 80, true, 3, 7, 35, false } },
102 { 0x1b, 0x0000, 0x8f1821, { 1280, 800, 16, 10, 71000, 1, false,
103 48, 32, 80, true, 3, 6, 14, false } },
104 { 0x1c, 0x8100, 0x8f1828, { 1280, 800, 16, 10, 83500, 0, false,
105 72, 128, 200, false, 3, 6, 22, true } },
106 { 0x1d, 0x810f, 0x8f1844, { 1280, 800, 16, 10, 106500, 0, false,
107 80, 128, 208, false, 3, 6, 29, true } },
108 { 0x1e, 0x8119, 0x8f1862, { 1280, 800, 16, 10, 122500, 0, false,
109 80, 136, 216, false, 3, 6, 34, true } },
110 { 0x1f, 0x0000, 0x000000, { 1280, 800, 16, 10, 146250, 1, false,
111 48, 32, 80, true, 3, 6, 38, false } },
113 { 0x20, 0x8140, 0x000000, { 1280, 960, 4, 3, 108000, 0, false,
114 96, 112, 312, true, 1, 3, 36, true } },
115 { 0x21, 0x8159, 0x000000, { 1280, 960, 4, 3, 148500, 0, false,
116 64, 160, 224, true, 1, 3, 47, true } },
117 { 0x22, 0x0000, 0x000000, { 1280, 960, 4, 3, 175500, 1, false,
118 48, 32, 80, true, 3, 4, 50, false } },
120 { 0x23, 0x8180, 0x000000, { 1280, 1024, 5, 4, 108000, 0, false,
121 48, 112, 248, true, 1, 3, 38, true } },
122 { 0x24, 0x818f, 0x000000, { 1280, 1024, 5, 4, 135000, 0, false,
123 16, 144, 248, true, 1, 3, 38, true } },
124 { 0x25, 0x8199, 0x000000, { 1280, 1024, 5, 4, 157500, 0, false,
125 64, 160, 224, true, 1, 3, 44, true } },
126 { 0x26, 0x0000, 0x000000, { 1280, 1024, 5, 4, 187250, 1, false,
127 48, 32, 80, true, 3, 7, 50, false } },
129 { 0x27, 0x0000, 0x000000, { 1360, 768, 85, 48, 85500, 0, false,
130 64, 112, 256, true, 3, 6, 18, true } },
131 { 0x28, 0x0000, 0x000000, { 1360, 768, 85, 48, 148250, 1, false,
132 48, 32, 80, true, 3, 5, 37, false } },
134 { 0x51, 0x0000, 0x000000, { 1366, 768, 85, 48, 85500, 0, false,
135 70, 143, 213, true, 3, 3, 24, true } },
136 { 0x56, 0x0000, 0x000000, { 1366, 768, 85, 48, 72000, 1, false,
137 14, 56, 64, true, 1, 3, 28, true } },
139 { 0x29, 0x0000, 0x0c2021, { 1400, 1050, 4, 3, 101000, 1, false,
140 48, 32, 80, true, 3, 4, 23, false } },
141 { 0x2a, 0x9040, 0x0c2028, { 1400, 1050, 4, 3, 121750, 0, false,
142 88, 144, 232, false, 3, 4, 32, true } },
143 { 0x2b, 0x904f, 0x0c2044, { 1400, 1050, 4, 3, 156000, 0, false,
144 104, 144, 248, false, 3, 4, 42, true } },
145 { 0x2c, 0x9059, 0x0c2062, { 1400, 1050, 4, 3, 179500, 0, false,
146 104, 152, 256, false, 3, 4, 48, true } },
147 { 0x2d, 0x0000, 0x000000, { 1400, 1050, 4, 3, 208000, 1, false,
148 48, 32, 80, true, 3, 4, 55, false } },
150 { 0x2e, 0x0000, 0xc11821, { 1440, 900, 16, 10, 88750, 1, false,
151 48, 32, 80, true, 3, 6, 17, false } },
152 { 0x2f, 0x9500, 0xc11828, { 1440, 900, 16, 10, 106500, 0, false,
153 80, 152, 232, false, 3, 6, 25, true } },
154 { 0x30, 0x950f, 0xc11844, { 1440, 900, 16, 10, 136750, 0, false,
155 96, 152, 248, false, 3, 6, 33, true } },
156 { 0x31, 0x9519, 0xc11868, { 1440, 900, 16, 10, 157000, 0, false,
157 104, 152, 256, false, 3, 6, 39, true } },
158 { 0x32, 0x0000, 0x000000, { 1440, 900, 16, 10, 182750, 1, false,
159 48, 32, 80, true, 3, 6, 44, false } },
161 { 0x53, 0xa9c0, 0x000000, { 1600, 900, 16, 9, 108000, 1, false,
162 24, 80, 96, true, 1, 3, 96, true } },
164 { 0x33, 0xa940, 0x000000, { 1600, 1200, 4, 3, 162000, 0, false,
165 64, 192, 304, true, 1, 3, 46, true } },
166 { 0x34, 0xa945, 0x000000, { 1600, 1200, 4, 3, 175500, 0, false,
167 64, 192, 304, true, 1, 3, 46, true } },
168 { 0x35, 0xa94a, 0x000000, { 1600, 1200, 4, 3, 189000, 0, false,
169 64, 192, 304, true, 1, 3, 46, true } },
170 { 0x36, 0xa94f, 0x000000, { 1600, 1200, 4, 3, 202500, 0, false,
171 64, 192, 304, true, 1, 3, 46, true } },
172 { 0x37, 0xa959, 0x000000, { 1600, 1200, 4, 3, 229500, 0, false,
173 64, 192, 304, true, 1, 3, 46, true } },
174 { 0x38, 0x0000, 0x000000, { 1600, 1200, 4, 3, 268250, 1, false,
175 48, 32, 80, true, 3, 4, 64, false } },
177 { 0x39, 0x0000, 0x0c2821, { 1680, 1050, 16, 10, 119000, 1, false,
178 48, 32, 80, true, 3, 6, 21, false } },
179 { 0x3a, 0xb300, 0x0c2828, { 1680, 1050, 16, 10, 146250, 0, false,
180 104, 176, 280, false, 3, 6, 30, true } },
181 { 0x3b, 0xb30f, 0x0c2844, { 1680, 1050, 16, 10, 187000, 0, false,
182 120, 176, 296, false, 3, 6, 40, true } },
183 { 0x3c, 0xb319, 0x0c2868, { 1680, 1050, 16, 10, 214750, 0, false,
184 128, 176, 304, false, 3, 6, 46, true } },
185 { 0x3d, 0x0000, 0x000000, { 1680, 1050, 16, 10, 245500, 1, false,
186 48, 32, 80, true, 3, 6, 53, false } },
188 { 0x3e, 0xc140, 0x000000, { 1792, 1344, 4, 3, 204750, 0, false,
189 128, 200, 328, false, 1, 3, 46, true } },
190 { 0x3f, 0xc14f, 0x000000, { 1792, 1344, 4, 3, 261000, 0, false,
191 96, 216, 352, false, 1, 3, 69, true } },
192 { 0x40, 0x0000, 0x000000, { 1792, 1344, 4, 3, 333250, 1, false,
193 48, 32, 80, true, 3, 4, 72, false } },
195 { 0x41, 0xc940, 0x000000, { 1856, 1392, 4, 3, 218250, 0, false,
196 96, 224, 352, false, 1, 3, 43, true } },
197 { 0x42, 0xc94f, 0x000000, { 1856, 1392, 4, 3, 288000, 0, false,
198 128, 224, 352, false, 1, 3, 104, true } },
199 { 0x43, 0x0000, 0x000000, { 1856, 1392, 4, 3, 356500, 1, false,
200 48, 32, 80, true, 3, 4, 74, false } },
202 { 0x52, 0xd1c0, 0x000000, { 1920, 1080, 16, 9, 148500, 0, false,
203 88, 44, 148, true, 4, 5, 36, true } },
205 { 0x44, 0x0000, 0x572821, { 1920, 1200, 16, 10, 154000, 1, false,
206 48, 32, 80, true, 3, 6, 26, false } },
207 { 0x45, 0xd100, 0x572828, { 1920, 1200, 16, 10, 193250, 0, false,
208 136, 200, 336, false, 3, 6, 36, true } },
209 { 0x46, 0xd10f, 0x572844, { 1920, 1200, 16, 10, 245250, 0, false,
210 136, 208, 344, false, 3, 6, 46, true } },
211 { 0x47, 0xd119, 0x572862, { 1920, 1200, 16, 10, 281250, 0, false,
212 144, 208, 352, false, 3, 6, 53, true } },
213 { 0x48, 0x0000, 0x000000, { 1920, 1200, 16, 10, 317000, 1, false,
214 48, 32, 80, true, 3, 6, 62, false } },
216 { 0x49, 0xd140, 0x000000, { 1920, 1440, 4, 3, 234000, 0, false,
217 128, 208, 344, false, 1, 3, 56, true } },
218 { 0x4a, 0xd14f, 0x000000, { 1920, 1440, 4, 3, 297000, 0, false,
219 144, 224, 352, false, 1, 3, 56, true } },
220 { 0x4b, 0x0000, 0x000000, { 1920, 1440, 4, 3, 380500, 1, false,
221 48, 32, 80, true, 2, 3, 78, false } },
223 { 0x54, 0xe1c0, 0x000000, { 2048, 1152, 16, 9, 162000, 1, false,
224 26, 80, 96, true, 1, 3, 44, true } },
226 { 0x4c, 0x0000, 0x1f3821, { 2560, 1600, 16, 10, 268500, 1, false,
227 48, 32, 80, true, 3, 6, 37, false } },
228 { 0x4d, 0x0000, 0x1f3828, { 2560, 1600, 16, 10, 348500, 0, false,
229 192, 280, 472, false, 3, 6, 49, true } },
230 { 0x4e, 0x0000, 0x1f3844, { 2560, 1600, 16, 10, 443250, 0, false,
231 208, 280, 488, false, 3, 6, 63, true } },
232 { 0x4f, 0x0000, 0x1f3862, { 2560, 1600, 16, 10, 505250, 0, false,
233 208, 280, 488, false, 3, 6, 73, true } },
234 { 0x50, 0x0000, 0x000000, { 2560, 1600, 16, 10, 552750, 1, false,
235 48, 32, 80, true, 3, 6, 85, false } },
237 { 0x57, 0x0000, 0x000000, { 4096, 2160, 256, 135, 556744, 1, false,
238 8, 32, 40, true, 48, 8, 6, false } },
239 { 0x58, 0x0000, 0x000000, { 4096, 2160, 256, 135, 556188, 1, false,
240 8, 32, 40, true, 48, 8, 6, false } },
243 // The timings for the IBM/Apple modes are copied from the linux
244 // kernel timings in drivers/gpu/drm/drm_edid.c, except for the
245 // 1152x870 Apple format, which is copied from
246 // drivers/video/fbdev/macmodes.c since the drm_edid.c version
247 // describes a 1152x864 format.
248 static const struct {
249 unsigned dmt_id;
250 struct timings t;
251 const char *type;
252 } established_timings12[] = {
253 /* 0x23 bit 7 - 0 */
254 { 0x00, { 720, 400, 9, 5, 28320, 0, false,
255 18, 108, 54, false, 21, 2, 26, true }, "IBM" },
256 { 0x00, { 720, 400, 9, 5, 35500, 0, false,
257 18, 108, 54, false, 12, 2, 35, true }, "IBM" },
258 { 0x04 },
259 { 0x00, { 640, 480, 4, 3, 30240, 0, false,
260 64, 64, 96, false, 3, 3, 39, false }, "Apple" },
261 { 0x05 },
262 { 0x06 },
263 { 0x08 },
264 { 0x09 },
265 /* 0x24 bit 7 - 0 */
266 { 0x0a },
267 { 0x0b },
268 { 0x00, { 832, 624, 4, 3, 57284, 0, false,
269 32, 64, 224, false, 1, 3, 39, false }, "Apple" },
270 { 0x0f },
271 { 0x10 },
272 { 0x11 },
273 { 0x12 },
274 { 0x24 },
275 /* 0x25 bit 7 */
276 { 0x00, { 1152, 870, 192, 145, 100000, 0, false,
277 48, 128, 128, true, 3, 3, 39, true }, "Apple" },
280 // The bits in the Established Timings III map to DMT timings,
281 // this array has the DMT IDs.
282 static const unsigned char established_timings3_dmt_ids[] = {
283 /* 0x06 bit 7 - 0 */
284 0x01, // 640x350@85
285 0x02, // 640x400@85
286 0x03, // 720x400@85
287 0x07, // 640x480@85
288 0x0e, // 848x480@60
289 0x0c, // 800x600@85
290 0x13, // 1024x768@85
291 0x15, // 1152x864@75
292 /* 0x07 bit 7 - 0 */
293 0x16, // 1280x768@60 RB
294 0x17, // 1280x768@60
295 0x18, // 1280x768@75
296 0x19, // 1280x768@85
297 0x20, // 1280x960@60
298 0x21, // 1280x960@85
299 0x23, // 1280x1024@60
300 0x25, // 1280x1024@85
301 /* 0x08 bit 7 - 0 */
302 0x27, // 1360x768@60
303 0x2e, // 1440x900@60 RB
304 0x2f, // 1440x900@60
305 0x30, // 1440x900@75
306 0x31, // 1440x900@85
307 0x29, // 1400x1050@60 RB
308 0x2a, // 1400x1050@60
309 0x2b, // 1400x1050@75
310 /* 0x09 bit 7 - 0 */
311 0x2c, // 1400x1050@85
312 0x39, // 1680x1050@60 RB
313 0x3a, // 1680x1050@60
314 0x3b, // 1680x1050@75
315 0x3c, // 1680x1050@85
316 0x33, // 1600x1200@60
317 0x34, // 1600x1200@65
318 0x35, // 1600x1200@70
319 /* 0x0a bit 7 - 0 */
320 0x36, // 1600x1200@75
321 0x37, // 1600x1200@85
322 0x3e, // 1792x1344@60
323 0x3f, // 1792x1344@75
324 0x41, // 1856x1392@60
325 0x42, // 1856x1392@75
326 0x44, // 1920x1200@60 RB
327 0x45, // 1920x1200@60
328 /* 0x0b bit 7 - 4 */
329 0x46, // 1920x1200@75
330 0x47, // 1920x1200@85
331 0x49, // 1920x1440@60
332 0x4a, // 1920x1440@75
335 const struct timings *find_dmt_id(unsigned char dmt_id)
337 unsigned i;
339 for (i = 0; i < ARRAY_SIZE(dmt_timings); i++)
340 if (dmt_timings[i].dmt_id == dmt_id)
341 return &dmt_timings[i].t;
342 return NULL;
345 static const struct timings *find_std_id(unsigned short std_id, unsigned char &dmt_id)
347 unsigned i;
349 for (i = 0; i < ARRAY_SIZE(dmt_timings); i++)
350 if (dmt_timings[i].std_id == std_id) {
351 dmt_id = dmt_timings[i].dmt_id;
352 return &dmt_timings[i].t;
354 return NULL;
357 void edid_state::list_established_timings()
359 printf("Established Timings I & II, 'Byte' is the EDID address:\n\n");
360 for (unsigned i = 0; i < ARRAY_SIZE(established_timings12); i++) {
361 unsigned char dmt_id = established_timings12[i].dmt_id;
362 const struct timings *t;
363 char type[16];
365 if (dmt_id) {
366 sprintf(type, "DMT 0x%02x", dmt_id);
367 t = find_dmt_id(dmt_id);
368 } else {
369 t = &established_timings12[i].t;
370 sprintf(type, "%-8s", established_timings12[i].type);
372 printf("Byte 0x%02x, Bit %u: ", 0x23 + i / 8, 7 - i % 8);
373 print_timings("", t, type, "", false, false);
375 printf("\nEstablished timings III, 'Byte' is the offset from the start of the descriptor:\n\n");
376 for (unsigned i = 0; i < ARRAY_SIZE(established_timings3_dmt_ids); i++) {
377 unsigned char dmt_id = established_timings3_dmt_ids[i];
378 char type[16];
380 sprintf(type, "DMT 0x%02x", dmt_id);
381 printf("Byte 0x%02x, Bit %u: ", 6 + i / 8, 7 - i % 8);
382 print_timings("", find_dmt_id(dmt_id), type, "", false, false);
386 const struct timings *close_match_to_dmt(const timings &t, unsigned &dmt)
388 for (unsigned i = 0; i < ARRAY_SIZE(dmt_timings); i++) {
389 if (timings_close_match(t, dmt_timings[i].t)) {
390 dmt = dmt_timings[i].dmt_id;
391 return &dmt_timings[i].t;
394 dmt = 0;
395 return NULL;
398 void edid_state::list_dmts()
400 char type[16];
402 for (unsigned i = 0; i < ARRAY_SIZE(dmt_timings); i++) {
403 sprintf(type, "DMT 0x%02x", dmt_timings[i].dmt_id);
404 std::string flags;
405 if (dmt_timings[i].std_id)
406 flags += std::string("STD: ") +
407 utohex(dmt_timings[i].std_id >> 8) + " " +
408 utohex(dmt_timings[i].std_id & 0xff);
409 if (dmt_timings[i].cvt_id)
410 add_str(flags, std::string("CVT: ") +
411 utohex(dmt_timings[i].cvt_id >> 16) + " " +
412 utohex((dmt_timings[i].cvt_id >> 8) & 0xff) + " " +
413 utohex(dmt_timings[i].cvt_id & 0xff));
414 print_timings("", &dmt_timings[i].t, type, flags.c_str(), false, false);
418 void edid_state::detailed_cvt_descriptor(const char *prefix, const unsigned char *x, bool first)
420 static const unsigned char empty[3] = { 0, 0, 0 };
421 struct timings cvt_t = {};
422 unsigned char preferred;
424 if (!first && !memcmp(x, empty, 3))
425 return;
427 cvt_t.vact = x[0];
428 if (!cvt_t.vact)
429 fail("CVT byte 0 is 0, which is a reserved value.\n");
430 cvt_t.vact |= (x[1] & 0xf0) << 4;
431 cvt_t.vact++;
432 cvt_t.vact *= 2;
434 switch (x[1] & 0x0c) {
435 case 0x00:
436 default: /* avoids 'width/ratio may be used uninitialized' warnings */
437 cvt_t.hratio = 4;
438 cvt_t.vratio = 3;
439 break;
440 case 0x04:
441 cvt_t.hratio = 16;
442 cvt_t.vratio = 9;
443 break;
444 case 0x08:
445 cvt_t.hratio = 16;
446 cvt_t.vratio = 10;
447 break;
448 case 0x0c:
449 cvt_t.hratio = 15;
450 cvt_t.vratio = 9;
451 break;
453 cvt_t.hact = 8 * (((cvt_t.vact * cvt_t.hratio) / cvt_t.vratio) / 8);
455 if (x[1] & 0x03)
456 fail("Reserved bits of CVT byte 1 are non-zero.\n");
457 if (x[2] & 0x80)
458 fail("Reserved bit of CVT byte 2 is non-zero.\n");
459 if (!(x[2] & 0x1f))
460 fail("CVT byte 2 does not support any vertical rates.\n");
461 preferred = (x[2] & 0x60) >> 5;
462 if (preferred == 1 && (x[2] & 0x01))
463 preferred = 4;
464 if (!(x[2] & (1 << (4 - preferred))))
465 fail("The preferred CVT Vertical Rate is not supported.\n");
467 static const char *s_pref = "preferred vertical rate";
469 if (x[2] & 0x10) {
470 edid_cvt_mode(50, cvt_t);
471 print_timings(prefix, &cvt_t, "CVT", preferred == 0 ? s_pref : "");
473 if (x[2] & 0x08) {
474 edid_cvt_mode(60, cvt_t);
475 print_timings(prefix, &cvt_t, "CVT", preferred == 1 ? s_pref : "");
477 if (x[2] & 0x04) {
478 edid_cvt_mode(75, cvt_t);
479 print_timings(prefix, &cvt_t, "CVT", preferred == 2 ? s_pref : "");
481 if (x[2] & 0x02) {
482 edid_cvt_mode(85, cvt_t);
483 print_timings(prefix, &cvt_t, "CVT", preferred == 3 ? s_pref : "");
485 if (x[2] & 0x01) {
486 cvt_t.rb = RB_CVT_V1;
487 edid_cvt_mode(60, cvt_t);
488 print_timings(prefix, &cvt_t, "CVT", preferred == 4 ? s_pref : "");
492 /* extract a string from a detailed subblock, checking for termination */
493 char *extract_string(const unsigned char *x, unsigned len)
495 static char s[EDID_PAGE_SIZE];
496 int seen_newline = 0;
497 unsigned i;
499 memset(s, 0, sizeof(s));
501 for (i = 0; i < len; i++) {
502 if (isgraph(x[i])) {
503 s[i] = x[i];
504 } else if (!seen_newline) {
505 if (x[i] == 0x0a) {
506 seen_newline = 1;
507 if (!i)
508 fail("Empty string.\n");
509 else if (s[i - 1] == 0x20)
510 fail("One or more trailing spaces.\n");
511 } else if (x[i] == 0x20) {
512 s[i] = x[i];
513 } else {
514 fail("Non-printable character.\n");
515 return s;
517 } else if (x[i] != 0x20) {
518 fail("Non-space after newline.\n");
519 return s;
522 /* Does the string end with a space? */
523 if (!seen_newline && s[len - 1] == 0x20)
524 fail("One or more trailing spaces.\n");
526 return s;
529 void edid_state::print_standard_timing(const char *prefix, unsigned char b1, unsigned char b2,
530 bool gtf_only, bool show_both)
532 const struct timings *t;
533 struct timings formula = {};
534 unsigned hratio, vratio;
535 unsigned hact, vact, refresh;
536 unsigned char dmt_id = 0;
538 if (b1 <= 0x01) {
539 if (b1 != 0x01 || b2 != 0x01)
540 fail("Use 0x0101 as the invalid Standard Timings code, not 0x%02x%02x.\n", b1, b2);
541 return;
544 t = find_std_id((b1 << 8) | b2, dmt_id);
545 if (t) {
546 char type[16];
547 sprintf(type, "DMT 0x%02x", dmt_id);
548 print_timings(prefix, t, type);
549 return;
551 hact = (b1 + 31) * 8;
552 switch ((b2 >> 6) & 0x3) {
553 case 0x00:
554 if (gtf_only || show_both || base.edid_minor >= 3) {
555 hratio = 16;
556 vratio = 10;
557 } else {
558 hratio = 1;
559 vratio = 1;
561 break;
562 case 0x01:
563 hratio = 4;
564 vratio = 3;
565 break;
566 case 0x02:
567 hratio = 5;
568 vratio = 4;
569 break;
570 case 0x03:
571 hratio = 16;
572 vratio = 9;
573 break;
575 vact = (double)hact * vratio / hratio;
576 refresh = (b2 & 0x3f) + 60;
578 formula.hact = hact;
579 formula.vact = vact;
580 formula.hratio = hratio;
581 formula.vratio = vratio;
583 if (!gtf_only && (show_both || base.edid_minor >= 4)) {
584 if (show_both || base.supports_cvt) {
585 edid_cvt_mode(refresh, formula);
586 print_timings(prefix, &formula, "CVT ",
587 show_both ? "" : "EDID 1.4 source");
590 * An EDID 1.3 source will assume GTF, so both GTF and CVT
591 * have to be supported.
593 edid_gtf_mode(refresh, formula);
594 if (base.supports_cvt)
595 print_timings(prefix, &formula, "GTF ", "EDID 1.3 source");
596 else
597 print_timings(prefix, &formula, "GTF ");
598 } else if (gtf_only || base.edid_minor >= 2) {
599 edid_gtf_mode(refresh, formula);
600 print_timings(prefix, &formula, "GTF ");
601 } else {
602 printf("%sUnknown : %5ux%-5u %3u.000 Hz %3u:%u\n",
603 prefix, hact, vact, refresh, hratio, vratio);
604 min_vert_freq_hz = min(min_vert_freq_hz, refresh);
605 max_vert_freq_hz = max(max_vert_freq_hz, refresh);
608 // See Ref. D-8 in the EDID-1.4 spec
609 if (vact & 1)
610 warn("Standard Timing %ux%u has a dubious odd vertical resolution.\n", hact, vact);
613 void edid_state::detailed_display_range_limits(const unsigned char *x)
615 int h_max_offset = 0, h_min_offset = 0;
616 int v_max_offset = 0, v_min_offset = 0;
617 int is_cvt = 0;
618 bool has_sec_gtf = false;
619 std::string range_class;
621 data_block = "Display Range Limits";
622 printf(" %s:\n", data_block.c_str());
623 base.has_display_range_descriptor = 1;
625 if (base.edid_minor >= 4) {
626 if (x[4] & 0x02) {
627 v_max_offset = 255;
628 if (x[4] & 0x01) {
629 v_min_offset = 255;
632 if (x[4] & 0x08) {
633 h_max_offset = 255;
634 if (x[4] & 0x04) {
635 h_min_offset = 255;
641 * despite the values, this is not a bitfield.
643 switch (x[10]) {
644 case 0x00: /* default gtf */
645 range_class = "GTF";
646 if (base.edid_minor >= 4 && !base.supports_continuous_freq)
647 fail("GTF can't be combined with non-continuous frequencies.\n");
648 if (base.edid_minor >= 4)
649 warn("GTF support is deprecated in EDID 1.4.\n");
650 break;
651 case 0x01: /* range limits only */
652 range_class = "Bare Limits";
653 if (base.edid_minor < 4)
654 fail("'%s' is not allowed for EDID < 1.4.\n", range_class.c_str());
655 break;
656 case 0x02: /* secondary gtf curve */
657 range_class = "Secondary GTF";
658 if (base.edid_minor >= 4 && !base.supports_continuous_freq)
659 fail("GTF can't be combined with non-continuous frequencies.\n");
660 if (base.edid_minor >= 4)
661 warn("GTF support is deprecated in EDID 1.4.\n");
662 has_sec_gtf = true;
663 break;
664 case 0x04: /* cvt */
665 range_class = "CVT";
666 is_cvt = 1;
667 if (base.edid_minor < 4)
668 fail("'%s' is not allowed for EDID < 1.4.\n", range_class.c_str());
669 else if (!base.supports_continuous_freq)
670 fail("CVT can't be combined with non-continuous frequencies.\n");
671 break;
672 default: /* invalid */
673 fail("Unknown range class (0x%02x).\n", x[10]);
674 range_class = std::string("Unknown (") + utohex(x[10]) + ")";
675 break;
678 if (x[5] + v_min_offset > x[6] + v_max_offset)
679 fail("Min vertical rate > max vertical rate.\n");
680 base.min_display_vert_freq_hz = x[5] + v_min_offset;
681 base.max_display_vert_freq_hz = x[6] + v_max_offset;
682 if (x[7] + h_min_offset > x[8] + h_max_offset)
683 fail("Min horizontal freq > max horizontal freq.\n");
684 base.min_display_hor_freq_hz = (x[7] + h_min_offset) * 1000;
685 base.max_display_hor_freq_hz = (x[8] + h_max_offset) * 1000;
686 printf(" Monitor ranges (%s): %d-%d Hz V, %d-%d kHz H",
687 range_class.c_str(),
688 x[5] + v_min_offset, x[6] + v_max_offset,
689 x[7] + h_min_offset, x[8] + h_max_offset);
691 // For EDID 1.3 the horizontal frequency maxes out at 255 kHz.
692 // So to avoid false range-check warnings due to this limitation,
693 // just double the max_display_hor_freq_hz in this case.
694 if (base.edid_minor < 4 && x[8] == 0xff)
695 base.max_display_hor_freq_hz *= 2;
697 // For EDID 1.3 the vertical frequency maxes out at 255 Hz.
698 // So to avoid false range-check warnings due to this limitation,
699 // just double the max_display_vert_freq_hz in this case.
700 if (base.edid_minor < 4 && x[6] == 0xff)
701 base.max_display_vert_freq_hz *= 2;
703 if (x[9]) {
704 base.max_display_pixclk_khz = x[9] * 10000;
705 printf(", max dotclock %d MHz\n", x[9] * 10);
706 } else {
707 printf("\n");
708 if (base.edid_minor >= 4)
709 fail("EDID 1.4 block does not set max dotclock.\n");
712 if (has_sec_gtf) {
713 if (x[11])
714 fail("Byte 11 is 0x%02x instead of 0x00.\n", x[11]);
715 if (memchk(x + 12, 6)) {
716 fail("Zeroed Secondary Curve Block.\n");
717 } else {
718 printf(" GTF Secondary Curve Block:\n");
719 printf(" Start frequency: %u kHz\n", x[12] * 2);
720 printf(" C: %.1f%%\n", x[13] / 2.0);
721 printf(" M: %u%%/kHz\n", (x[15] << 8) | x[14]);
722 printf(" K: %u\n", x[16]);
723 printf(" J: %.1f%%\n", x[17] / 2.0);
725 } else if (is_cvt) {
726 int max_h_pixels = 0;
728 printf(" CVT version %d.%d\n", (x[11] & 0xf0) >> 4, x[11] & 0x0f);
730 if (x[12] & 0xfc) {
731 unsigned raw_offset = (x[12] & 0xfc) >> 2;
733 printf(" Real max dotclock: %.2f MHz\n",
734 (x[9] * 10) - (raw_offset * 0.25));
735 if (raw_offset >= 40)
736 warn("CVT block corrects dotclock by more than 9.75 MHz.\n");
739 max_h_pixels = x[12] & 0x03;
740 max_h_pixels <<= 8;
741 max_h_pixels |= x[13];
742 max_h_pixels *= 8;
743 if (max_h_pixels)
744 printf(" Max active pixels per line: %d\n", max_h_pixels);
746 printf(" Supported aspect ratios:%s%s%s%s%s\n",
747 x[14] & 0x80 ? " 4:3" : "",
748 x[14] & 0x40 ? " 16:9" : "",
749 x[14] & 0x20 ? " 16:10" : "",
750 x[14] & 0x10 ? " 5:4" : "",
751 x[14] & 0x08 ? " 15:9" : "");
752 if (x[14] & 0x07)
753 fail("Reserved bits of byte 14 are non-zero.\n");
755 printf(" Preferred aspect ratio: ");
756 switch ((x[15] & 0xe0) >> 5) {
757 case 0x00:
758 printf("4:3");
759 break;
760 case 0x01:
761 printf("16:9");
762 break;
763 case 0x02:
764 printf("16:10");
765 break;
766 case 0x03:
767 printf("5:4");
768 break;
769 case 0x04:
770 printf("15:9");
771 break;
772 default:
773 printf("Unknown (0x%02x)", (x[15] & 0xe0) >> 5);
774 fail("Invalid preferred aspect ratio 0x%02x.\n",
775 (x[15] & 0xe0) >> 5);
776 break;
778 printf("\n");
780 if (x[15] & 0x08)
781 printf(" Supports CVT standard blanking\n");
782 if (x[15] & 0x10)
783 printf(" Supports CVT reduced blanking\n");
785 if (x[15] & 0x07)
786 fail("Reserved bits of byte 15 are non-zero.\n");
788 if (x[16] & 0xf0) {
789 printf(" Supported display scaling:\n");
790 if (x[16] & 0x80)
791 printf(" Horizontal shrink\n");
792 if (x[16] & 0x40)
793 printf(" Horizontal stretch\n");
794 if (x[16] & 0x20)
795 printf(" Vertical shrink\n");
796 if (x[16] & 0x10)
797 printf(" Vertical stretch\n");
800 if (x[16] & 0x0f)
801 fail("Reserved bits of byte 16 are non-zero.\n");
803 if (x[17])
804 printf(" Preferred vertical refresh: %d Hz\n", x[17]);
805 else
806 warn("CVT block does not set preferred refresh rate.\n");
807 } else {
808 if (x[11] != 0x0a)
809 fail("Byte 11 is 0x%02x instead of 0x0a.\n", x[11]);
810 for (unsigned i = 12; i <= 17; i++) {
811 if (x[i] != 0x20) {
812 fail("Bytes 12-17 must be 0x20.\n");
813 break;
819 void edid_state::detailed_epi(const unsigned char *x)
821 data_block = "EPI Descriptor";
822 printf(" %s:\n", data_block.c_str());
824 unsigned v = x[5] & 0x07;
826 printf(" Bits per pixel: %u\n", 18 + v * 6);
827 if (v > 2)
828 fail("Invalid bits per pixel.\n");
829 v = (x[5] & 0x18) >> 3;
830 printf(" Pixels per clock: %u\n", 1 << v);
831 if (v > 2)
832 fail("Invalid pixels per clock.\n");
833 v = (x[5] & 0x60) >> 5;
834 printf(" Data color mapping: %sconventional\n", v ? "non-" : "");
835 if (v > 1)
836 fail("Unknown data color mapping (0x%02x).\n", v);
837 if (x[5] & 0x80)
838 fail("Non-zero reserved field in byte 5.\n");
840 v = x[6] & 0x0f;
841 printf(" Interface type: ");
842 switch (v) {
843 case 0x00: printf("LVDS TFT\n"); break;
844 case 0x01: printf("monoSTN 4/8 Bit\n"); break;
845 case 0x02: printf("colorSTN 8/16 Bit\n"); break;
846 case 0x03: printf("18 Bit TFT\n"); break;
847 case 0x04: printf("24 Bit TFT\n"); break;
848 case 0x05: printf("TMDS\n"); break;
849 default:
850 printf("Unknown (0x%02x)\n", v);
851 fail("Invalid interface type 0x%02x.\n", v);
852 break;
854 printf(" DE polarity: DE %s active\n",
855 (x[6] & 0x10) ? "low" : "high");
856 printf(" FPSCLK polarity: FPSCLK %sinverted\n",
857 (x[6] & 0x20) ? "" : "not ");
858 if (x[6] & 0xc0)
859 fail("Non-zero reserved field in byte 6.\n");
861 printf(" Vertical display mode: %s\n",
862 (x[7] & 0x01) ? "Up/Down reverse mode" : "normal");
863 printf(" Horizontal display mode: %s\n",
864 (x[7] & 0x02) ? "Left/Right reverse mode" : "normal");
865 if (x[7] & 0xfc)
866 fail("Non-zero reserved field in byte 7.\n");
868 v = x[8] & 0x0f;
869 printf(" Total power on sequencing delay: ");
870 if (v)
871 printf("%u ms\n", v * 10);
872 else
873 printf("VGA controller default\n");
874 v = (x[8] & 0xf0) >> 4;
875 printf(" Total power off sequencing delay: ");
876 if (v)
877 printf("%u ms\n", v * 10);
878 else
879 printf("VGA controller default\n");
881 v = x[9] & 0x0f;
882 printf(" Contrast power on sequencing delay: ");
883 if (v)
884 printf("%u ms\n", v * 10);
885 else
886 printf("VGA controller default\n");
887 v = (x[9] & 0xf0) >> 4;
888 printf(" Contrast power off sequencing delay: ");
889 if (v)
890 printf("%u ms\n", v * 10);
891 else
892 printf("VGA controller default\n");
894 v = x[10] & 0x2f;
895 const char *s = (x[10] & 0x80) ? "" : " (ignored)";
897 printf(" Backlight brightness control: %u steps%s\n", v, s);
898 printf(" Backlight enable at boot: %s%s\n",
899 (x[10] & 0x40) ? "off" : "on", s);
900 printf(" Backlight control enable: %s\n",
901 (x[10] & 0x80) ? "enabled" : "disabled");
903 v = x[11] & 0x2f;
904 s = (x[11] & 0x80) ? "" : " (ignored)";
906 printf(" Contrast voltable control: %u steps%s\n", v, s);
907 if (x[11] & 0x40)
908 fail("Non-zero reserved field in byte 11.\n");
909 printf(" Contrast control enable: %s\n",
910 (x[11] & 0x80) ? "enabled" : "disabled");
912 if (x[12] || x[13] || x[14] || x[15] || x[16])
913 fail("Non-zero values in reserved bytes 12-16.\n");
915 printf(" EPI Version: %u.%u\n", (x[17] & 0xf0) >> 4, x[17] & 0x0f);
918 void edid_state::detailed_timings(const char *prefix, const unsigned char *x,
919 bool base_or_cta)
921 struct timings t = {};
922 unsigned hbl, vbl;
923 std::string s_sync, s_flags;
925 // Only count DTDs in base block 0 or CTA-861 extension blocks
926 if (base_or_cta)
927 base.dtd_cnt++;
928 data_block = "Detailed Timing Descriptor #" + std::to_string(base.dtd_cnt);
929 t.pixclk_khz = (x[0] + (x[1] << 8)) * 10;
930 if (t.pixclk_khz < 10000) {
931 printf("%sDetailed mode: ", prefix);
932 hex_block("", x, 18, true, 18);
933 if (!t.pixclk_khz)
934 fail("First two bytes are 0, invalid data.\n");
935 else
936 fail("Pixelclock < 10 MHz, assuming invalid data 0x%02x 0x%02x.\n",
937 x[0], x[1]);
938 return;
942 * If the borders are non-zero, then it is unclear how to interpret
943 * the DTD blanking parameters.
945 * According to EDID 1.3 (3.12) the Hor/Vert Blanking includes the
946 * borders, and so does the Hor/Vert Sync Offset.
948 * According to EDID 1.4 (3.12) the Hor/Vert Blanking excludes the
949 * borders, and they are also excluded from the Hor/Vert Front Porch.
951 * But looking at what is really done in EDIDs is that the Hor/Vert
952 * Blanking follows EDID 1.3, but the Hor/Vert Front Porch does not
953 * include the border.
955 * So hbl/vbl includes the borders, so those need to be subtracted,
956 * but hfp/vfp is used as-is.
958 * In practice you really shouldn't use non-zero borders in DTDs
959 * since clearly nobody knows how to interpret the timing.
961 t.hact = (x[2] + ((x[4] & 0xf0) << 4));
962 t.hborder = x[15];
963 hbl = (x[3] + ((x[4] & 0x0f) << 8)) - t.hborder * 2;
964 t.hfp = (x[8] + ((x[11] & 0xc0) << 2));
965 t.hsync = (x[9] + ((x[11] & 0x30) << 4));
966 t.hbp = hbl - t.hsync - t.hfp;
967 t.vact = (x[5] + ((x[7] & 0xf0) << 4));
968 t.vborder = x[16];
969 vbl = (x[6] + ((x[7] & 0x0f) << 8)) - t.vborder * 2;
970 t.vfp = ((x[10] >> 4) + ((x[11] & 0x0c) << 2));
971 t.vsync = ((x[10] & 0x0f) + ((x[11] & 0x03) << 4));
972 t.vbp = vbl - t.vsync - t.vfp;
974 unsigned char flags = x[17];
976 if (base.has_spwg && base.detailed_block_cnt == 2)
977 flags = *(x - 1);
979 switch ((flags & 0x18) >> 3) {
980 case 0x00:
981 s_flags = "analog composite";
982 #ifdef __EMSCRIPTEN__
983 [[clang::fallthrough]];
984 #endif
985 /* fall-through */
986 case 0x01:
987 if (s_flags.empty())
988 s_flags = "bipolar analog composite";
989 switch ((flags & 0x06) >> 1) {
990 case 0x00:
991 add_str(s_flags, "sync-on-green");
992 break;
993 case 0x01:
994 break;
995 case 0x02:
996 add_str(s_flags, "serrate, sync-on-green");
997 break;
998 case 0x03:
999 add_str(s_flags, "serrate");
1000 break;
1002 break;
1003 case 0x02:
1004 if (flags & (1 << 1))
1005 t.pos_pol_hsync = true;
1006 t.no_pol_vsync = true;
1007 s_flags = "digital composite";
1008 if (flags & (1 << 2))
1009 add_str(s_flags, "serrate");
1010 break;
1011 case 0x03:
1012 if (flags & (1 << 1))
1013 t.pos_pol_hsync = true;
1014 if (flags & (1 << 2))
1015 t.pos_pol_vsync = true;
1016 s_sync = t.pos_pol_hsync ? "+hsync " : "-hsync ";
1017 s_sync += t.pos_pol_vsync ? "+vsync " : "-vsync ";
1018 if (base.has_spwg && (flags & 0x01))
1019 s_flags = "DE timing only";
1020 break;
1022 if (flags & 0x80) {
1023 t.interlaced = true;
1024 t.vact *= 2;
1026 * Check if this DTD matches VIC code 39 with special
1027 * interlaced timings.
1029 if (t.hact == 1920 && t.vact == 1080 && t.pixclk_khz == 72000 &&
1030 t.hfp == 32 && t.hsync == 168 && t.hbp == 184 && !t.hborder &&
1031 t.vfp == 23 && t.vsync == 5 && t.vbp == 57 && !t.vborder &&
1032 !base.has_spwg && cta.preparsed_has_vic[0][39] && (flags & 0x1e) == 0x1a)
1033 t.even_vtotal = true;
1035 switch (flags & 0x61) {
1036 case 0x20:
1037 add_str(s_flags, "field sequential L/R");
1038 break;
1039 case 0x40:
1040 add_str(s_flags, "field sequential R/L");
1041 break;
1042 case 0x21:
1043 add_str(s_flags, "interleaved right even");
1044 break;
1045 case 0x41:
1046 add_str(s_flags, "interleaved left even");
1047 break;
1048 case 0x60:
1049 add_str(s_flags, "four way interleaved");
1050 break;
1051 case 0x61:
1052 add_str(s_flags, "side by side interleaved");
1053 break;
1054 default:
1055 break;
1058 t.hsize_mm = x[12] + ((x[14] & 0xf0) << 4);
1059 t.vsize_mm = x[13] + ((x[14] & 0x0f) << 8);
1061 calc_ratio(&t);
1063 std::string s_type = base_or_cta ? dtd_type() : "DTD";
1064 bool ok = print_timings(prefix, &t, s_type.c_str(), s_flags.c_str(), true);
1065 timings_ext te(t, s_type, s_flags);
1067 if (block_nr == 0 && base.dtd_cnt == 1) {
1068 te.type = "DTD 1";
1069 base.preferred_timing = te;
1070 if (has_cta) {
1071 cta.preferred_timings.push_back(te);
1072 cta.native_timings.push_back(te);
1075 if (base_or_cta)
1076 cta.vec_dtds.push_back(te);
1078 if (t.hborder || t.vborder)
1079 warn("The use of non-zero borders in a DTD is not recommended.\n");
1080 if ((base.max_display_width_mm && !t.hsize_mm) ||
1081 (base.max_display_height_mm && !t.vsize_mm)) {
1082 fail("Mismatch of image size vs display size: image size is not set, but display size is.\n");
1084 if (base.has_spwg && base.detailed_block_cnt == 2)
1085 printf("%sSPWG Module Revision: %hhu\n", prefix, x[17]);
1086 if (!ok) {
1087 std::string s = prefix;
1089 s += " ";
1090 hex_block(s.c_str(), x, 18, true, 18);
1094 bool edid_state::preparse_detailed_block(unsigned char *x)
1096 if (x[0] || x[1])
1097 return false;
1099 switch (x[3]) {
1100 case 0xfd:
1101 switch (x[10]) {
1102 case 0x00: /* default gtf */
1103 base.supports_gtf = true;
1104 break;
1105 case 0x02: /* secondary gtf curve */
1106 base.supports_gtf = true;
1107 base.supports_sec_gtf = !memchk(x + 12, 6);
1108 base.sec_gtf_start_freq = x[12] * 2;
1109 base.C = x[13] / 2.0;
1110 base.M = (x[15] << 8) | x[14];
1111 base.K = x[16];
1112 base.J = x[17] / 2.0;
1113 break;
1114 case 0x04: /* cvt */
1115 if (base.edid_minor >= 4) {
1116 /* GTF is implied if CVT is signaled */
1117 base.supports_gtf = true;
1118 base.supports_cvt = true;
1120 break;
1122 break;
1123 case 0xff:
1124 if (replace_unique_ids) {
1125 // Replace with 123456
1126 static const unsigned char sernum[13] = {
1127 '1', '2', '3', '4', '5', '6',
1128 '\n', ' ', ' ', ' ', ' ', ' ', ' '
1130 memcpy(x + 5, sernum, sizeof(sernum));
1131 return true;
1133 break;
1135 return false;
1138 void edid_state::detailed_block(const unsigned char *x)
1140 static const unsigned char zero_descr[18] = { 0 };
1141 unsigned cnt;
1142 unsigned i;
1144 base.detailed_block_cnt++;
1145 if (x[0] || x[1]) {
1146 detailed_timings(" ", x);
1147 if (base.seen_non_detailed_descriptor)
1148 fail("Invalid detailed timing descriptor ordering.\n");
1149 return;
1152 data_block = "Display Descriptor #" + std::to_string(base.detailed_block_cnt);
1153 /* Monitor descriptor block, not detailed timing descriptor. */
1154 if (x[2] != 0) {
1155 /* 1.3, 3.10.3 */
1156 fail("Monitor descriptor block has byte 2 nonzero (0x%02x).\n", x[2]);
1158 if ((base.edid_minor < 4 || x[3] != 0xfd) && x[4] != 0x00) {
1159 /* 1.3, 3.10.3 */
1160 fail("Monitor descriptor block has byte 4 nonzero (0x%02x).\n", x[4]);
1163 base.seen_non_detailed_descriptor = true;
1164 if (base.edid_minor == 0)
1165 fail("Has descriptor blocks other than detailed timings.\n");
1167 if (!memcmp(x, zero_descr, sizeof(zero_descr))) {
1168 data_block = "Empty Descriptor";
1169 printf(" %s\n", data_block.c_str());
1170 fail("Use Dummy Descriptor instead of all zeroes.\n");
1171 return;
1174 switch (x[3]) {
1175 case 0x0e:
1176 detailed_epi(x);
1177 return;
1178 case 0x10:
1179 data_block = "Dummy Descriptor";
1180 printf(" %s:\n", data_block.c_str());
1181 for (i = 5; i < 18; i++) {
1182 if (x[i]) {
1183 fail("Dummy block filled with garbage.\n");
1184 break;
1187 return;
1188 case 0xf7:
1189 data_block = "Established timings III";
1190 printf(" %s:\n", data_block.c_str());
1191 for (i = 0; i < ARRAY_SIZE(established_timings3_dmt_ids); i++)
1192 if (x[6 + i / 8] & (1 << (7 - i % 8))) {
1193 unsigned char dmt_id = established_timings3_dmt_ids[i];
1194 char type[16];
1196 sprintf(type, "DMT 0x%02x", dmt_id);
1197 print_timings(" ", find_dmt_id(dmt_id), type);
1199 if (base.edid_minor < 4)
1200 fail("Not allowed for EDID < 1.4.\n");
1201 return;
1202 case 0xf8:
1203 data_block = "CVT 3 Byte Timing Codes";
1204 printf(" %s:\n", data_block.c_str());
1205 if (x[5] != 0x01) {
1206 fail("Invalid version number %u.\n", x[5]);
1207 return;
1209 for (i = 0; i < 4; i++)
1210 detailed_cvt_descriptor(" ", x + 6 + (i * 3), !i);
1211 if (base.edid_minor < 4)
1212 fail("Not allowed for EDID < 1.4.\n");
1213 return;
1214 case 0xf9:
1215 data_block = "Display Color Management Data";
1216 printf(" %s:\n", data_block.c_str());
1217 printf(" Version : %d\n", x[5]);
1218 printf(" Red a3 : %.2f\n", (short)(x[6] | (x[7] << 8)) / 100.0);
1219 printf(" Red a2 : %.2f\n", (short)(x[8] | (x[9] << 8)) / 100.0);
1220 printf(" Green a3: %.2f\n", (short)(x[10] | (x[11] << 8)) / 100.0);
1221 printf(" Green a2: %.2f\n", (short)(x[12] | (x[13] << 8)) / 100.0);
1222 printf(" Blue a3 : %.2f\n", (short)(x[14] | (x[15] << 8)) / 100.0);
1223 printf(" Blue a2 : %.2f\n", (short)(x[16] | (x[17] << 8)) / 100.0);
1224 return;
1225 case 0xfa:
1226 data_block = "Standard Timing Identifications";
1227 printf(" %s:\n", data_block.c_str());
1228 for (cnt = i = 0; i < 6; i++) {
1229 if (x[5 + i * 2] != 0x01 || x[5 + i * 2 + 1] != 0x01)
1230 cnt++;
1231 print_standard_timing(" ", x[5 + i * 2], x[5 + i * 2 + 1]);
1233 if (!cnt)
1234 warn("%s block without any timings.\n", data_block.c_str());
1235 return;
1236 case 0xfb: {
1237 unsigned w_x, w_y;
1238 unsigned gamma;
1240 data_block = "Color Point Data";
1241 printf(" %s:\n", data_block.c_str());
1242 w_x = (x[7] << 2) | ((x[6] >> 2) & 3);
1243 w_y = (x[8] << 2) | (x[6] & 3);
1244 gamma = x[9];
1245 printf(" Index: %u White: 0.%04u, 0.%04u", x[5],
1246 (w_x * 10000) / 1024, (w_y * 10000) / 1024);
1247 if (gamma == 0xff)
1248 printf(" Gamma: is defined in an extension block");
1249 else
1250 printf(" Gamma: %.2f", ((gamma + 100.0) / 100.0));
1251 printf("\n");
1252 if (x[10] == 0)
1253 return;
1254 w_x = (x[12] << 2) | ((x[11] >> 2) & 3);
1255 w_y = (x[13] << 2) | (x[11] & 3);
1256 gamma = x[14];
1257 printf(" Index: %u White: 0.%04u, 0.%04u", x[10],
1258 (w_x * 10000) / 1024, (w_y * 10000) / 1024);
1259 if (gamma == 0xff)
1260 printf(" Gamma: is defined in an extension block");
1261 else
1262 printf(" Gamma: %.2f", ((gamma + 100.0) / 100.0));
1263 printf("\n");
1264 return;
1266 case 0xfc:
1267 data_block = "Display Product Name";
1268 base.has_name_descriptor = 1;
1269 printf(" %s: '%s'\n", data_block.c_str(), extract_string(x + 5, 13));
1270 return;
1271 case 0xfd:
1272 detailed_display_range_limits(x);
1273 return;
1274 case 0xfe:
1275 if (!base.has_spwg || base.detailed_block_cnt < 3) {
1276 data_block = "Alphanumeric Data String";
1277 printf(" %s: '%s'\n", data_block.c_str(),
1278 extract_string(x + 5, 13));
1279 return;
1281 if (base.detailed_block_cnt == 3) {
1282 char buf[6] = { 0 };
1284 data_block = "SPWG Descriptor #3";
1285 printf(" %s:\n", data_block.c_str());
1286 memcpy(buf, x + 5, 5);
1287 if (strlen(buf) != 5)
1288 fail("Invalid PC Maker P/N length.\n");
1289 printf(" SPWG PC Maker P/N: '%s'\n", buf);
1290 printf(" SPWG LCD Supplier EEDID Revision: %hhu\n", x[10]);
1291 printf(" SPWG Manufacturer P/N: '%s'\n", extract_string(x + 11, 7));
1292 } else {
1293 data_block = "SPWG Descriptor #4";
1294 printf(" %s:\n", data_block.c_str());
1295 printf(" SMBUS Values: 0x%02hhx 0x%02hhx 0x%02hhx 0x%02hhx"
1296 " 0x%02hhx 0x%02hhx 0x%02hhx 0x%02hhx\n",
1297 x[5], x[6], x[7], x[8], x[9], x[10], x[11], x[12]);
1298 printf(" LVDS Channels: %hhu\n", x[13]);
1299 printf(" Panel Self Test %sPresent\n", x[14] ? "" : "Not ");
1300 if (x[15] != 0x0a || x[16] != 0x20 || x[17] != 0x20)
1301 fail("Invalid trailing data.\n");
1303 return;
1304 case 0xff: {
1305 data_block = "Display Product Serial Number";
1306 char *sn = extract_string(x + 5, 13);
1307 if (hide_serial_numbers)
1308 printf(" %s: ...\n", data_block.c_str());
1309 else
1310 printf(" %s: '%s'\n", data_block.c_str(), sn);
1311 base.has_serial_string = 1;
1312 return;
1314 default:
1315 printf(" %s Display Descriptor (0x%02hhx):",
1316 x[3] <= 0x0f ? "Manufacturer-Specified" : "Unknown", x[3]);
1317 hex_block(" ", x + 2, 16);
1318 if (x[3] > 0x0f)
1319 fail("Unknown Type 0x%02hhx.\n", x[3]);
1320 return;
1325 * The sRGB chromaticities are (x, y):
1326 * red: 0.640, 0.330
1327 * green: 0.300, 0.600
1328 * blue: 0.150, 0.060
1329 * white: 0.3127, 0.3290
1331 static const unsigned char srgb_chromaticity[10] = {
1332 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54
1335 void edid_state::preparse_base_block(unsigned char *x)
1337 bool update_checksum = false;
1339 base.has_serial_number = x[0x0c] || x[0x0d] || x[0x0e] || x[0x0f];
1341 if (base.has_serial_number && replace_unique_ids) {
1342 // Replace by 123456
1343 x[0x0c] = 0x40;
1344 x[0x0d] = 0xe2;
1345 x[0x0e] = 0x01;
1346 x[0x0f] = 0x00;
1347 update_checksum = true;
1351 * Need to find the Display Range Limit info before reading
1352 * the standard timings.
1354 update_checksum |= preparse_detailed_block(x + 0x36);
1355 update_checksum |= preparse_detailed_block(x + 0x48);
1356 update_checksum |= preparse_detailed_block(x + 0x5a);
1357 update_checksum |= preparse_detailed_block(x + 0x6c);
1359 if (update_checksum)
1360 replace_checksum(x, EDID_PAGE_SIZE);
1363 void edid_state::parse_base_block(const unsigned char *x)
1365 time_t the_time;
1366 struct tm *ptm;
1367 int analog;
1368 unsigned col_x, col_y;
1369 bool has_preferred_timing = false;
1371 data_block = "EDID Structure Version & Revision";
1372 printf(" %s: %hhu.%hhu\n", data_block.c_str(), x[0x12], x[0x13]);
1373 if (x[0x12] == 1) {
1374 base.edid_minor = x[0x13];
1375 if (base.edid_minor > 4)
1376 warn("Unknown EDID minor version %u, assuming 1.4 conformance.\n", base.edid_minor);
1377 if (base.edid_minor < 3)
1378 warn("EDID 1.%u is deprecated, do not use.\n", base.edid_minor);
1379 } else {
1380 fail("Unknown EDID major version.\n");
1383 data_block = "Vendor & Product Identification";
1384 printf(" %s:\n", data_block.c_str());
1385 printf(" Manufacturer: %s\n Model: %u\n",
1386 manufacturer_name(x + 0x08),
1387 (unsigned short)(x[0x0a] + (x[0x0b] << 8)));
1388 if (base.has_serial_number) {
1389 if (hide_serial_numbers)
1390 printf(" Serial Number: ...\n");
1391 else
1392 printf(" Serial Number: %u\n",
1393 (unsigned)(x[0x0c] + (x[0x0d] << 8) +
1394 (x[0x0e] << 16) + (x[0x0f] << 24)));
1397 time(&the_time);
1398 ptm = localtime(&the_time);
1400 unsigned char week = x[0x10];
1401 int year = 1990 + x[0x11];
1403 if (week) {
1404 if (base.edid_minor <= 3 && week == 0xff)
1405 fail("EDID 1.3 does not support week 0xff.\n");
1406 // The max week is 53 in EDID 1.3 and 54 in EDID 1.4.
1407 // No idea why there is a difference.
1408 if (base.edid_minor <= 3 && week == 54)
1409 fail("EDID 1.3 does not support week 54.\n");
1410 if (week != 0xff && week > 54)
1411 fail("Invalid week %u of manufacture.\n", week);
1412 if (week != 0xff)
1413 printf(" Made in: week %hhu of %d\n", week, year);
1415 if (week == 0xff)
1416 printf(" Model year: %d\n", year);
1417 else if (!week)
1418 printf(" Made in: %d\n", year);
1419 if (year - 1 > ptm->tm_year + 1900)
1420 fail("The year %d is more than one year in the future.\n", year);
1422 /* display section */
1424 data_block = "Basic Display Parameters & Features";
1425 printf(" %s:\n", data_block.c_str());
1426 if (x[0x14] & 0x80) {
1427 analog = 0;
1428 printf(" Digital display\n");
1429 if (base.edid_minor >= 4) {
1430 if ((x[0x14] & 0x70) == 0x00)
1431 printf(" Color depth is undefined\n");
1432 else if ((x[0x14] & 0x70) == 0x70)
1433 fail("Color Bit Depth set to reserved value.\n");
1434 else
1435 printf(" Bits per primary color channel: %u\n",
1436 ((x[0x14] & 0x70) >> 3) + 4);
1438 printf(" ");
1439 switch (x[0x14] & 0x0f) {
1440 case 0x00: printf("Digital interface is not defined\n"); break;
1441 case 0x01: printf("DVI interface\n"); break;
1442 case 0x02: printf("HDMI-a interface\n"); break;
1443 case 0x03: printf("HDMI-b interface\n"); break;
1444 case 0x04: printf("MDDI interface\n"); break;
1445 case 0x05: printf("DisplayPort interface\n"); break;
1446 default:
1447 printf("Unknown interface: 0x%02x\n", x[0x14] & 0x0f);
1448 fail("Digital Video Interface Standard set to reserved value 0x%02x.\n", x[0x14] & 0x0f);
1449 break;
1451 } else if (base.edid_minor >= 2) {
1452 if (x[0x14] & 0x01) {
1453 printf(" DFP 1.x compatible TMDS\n");
1455 if (x[0x14] & 0x7e)
1456 fail("Digital Video Interface Standard set to reserved value 0x%02x.\n", x[0x14] & 0x7e);
1457 } else if (x[0x14] & 0x7f) {
1458 fail("Digital Video Interface Standard set to reserved value 0x%02x.\n", x[0x14] & 0x7f);
1460 } else {
1461 static const char * const voltages[] = {
1462 "0.700 : 0.300 : 1.000 V p-p",
1463 "0.714 : 0.286 : 1.000 V p-p",
1464 "1.000 : 0.400 : 1.400 V p-p",
1465 "0.700 : 0.000 : 0.700 V p-p"
1467 unsigned voltage = (x[0x14] & 0x60) >> 5;
1468 unsigned sync = (x[0x14] & 0x0f);
1470 analog = 1;
1471 printf(" Analog display\n");
1472 printf(" Signal Level Standard: %s\n", voltages[voltage]);
1474 if (x[0x14] & 0x10)
1475 printf(" Blank-to-black setup/pedestal\n");
1476 else
1477 printf(" Blank level equals black level\n");
1479 if (sync)
1480 printf(" Sync:%s%s%s%s\n",
1481 sync & 0x08 ? " Separate" : "",
1482 sync & 0x04 ? " Composite" : "",
1483 sync & 0x02 ? " SyncOnGreen" : "",
1484 sync & 0x01 ? " Serration" : "");
1487 if (x[0x15] && x[0x16]) {
1488 printf(" Maximum image size: %u cm x %u cm\n", x[0x15], x[0x16]);
1489 base.max_display_width_mm = x[0x15] * 10;
1490 base.max_display_height_mm = x[0x16] * 10;
1491 image_width = base.max_display_width_mm * 10;
1492 image_height = base.max_display_height_mm * 10;
1493 if (x[0x15] < 10 || x[0x16] < 10)
1494 warn("Dubious maximum image size (%ux%u is smaller than 10x10 cm).\n",
1495 x[0x15], x[0x16]);
1497 else if (base.edid_minor >= 4 && (x[0x15] || x[0x16])) {
1498 if (x[0x15])
1499 printf(" Aspect ratio: %.2f (landscape)\n", (x[0x15] + 99) / 100.0);
1500 else
1501 printf(" Aspect ratio: %.2f (portrait)\n", 100.0 / (x[0x16] + 99));
1502 } else {
1503 /* Either or both can be zero for 1.3 and before */
1504 printf(" Image size is variable\n");
1507 if (x[0x17] == 0xff)
1508 printf(" Gamma is defined in an extension block\n");
1509 else
1510 printf(" Gamma: %.2f\n", (x[0x17] + 100.0) / 100.0);
1512 if (x[0x18] & 0xe0) {
1513 printf(" DPMS levels:");
1514 if (x[0x18] & 0x80) printf(" Standby");
1515 if (x[0x18] & 0x40) printf(" Suspend");
1516 if (x[0x18] & 0x20) printf(" Off");
1517 printf("\n");
1520 if (analog || base.edid_minor < 4) {
1521 printf(" ");
1522 switch (x[0x18] & 0x18) {
1523 case 0x00: printf("Monochrome or grayscale display\n"); break;
1524 case 0x08: printf("RGB color display\n"); break;
1525 case 0x10: printf("Non-RGB color display\n"); break;
1526 case 0x18: printf("Undefined display color type\n"); break;
1528 } else {
1529 printf(" Supported color formats: RGB 4:4:4");
1530 if (x[0x18] & 0x08)
1531 printf(", YCrCb 4:4:4");
1532 if (x[0x18] & 0x10)
1533 printf(", YCrCb 4:2:2");
1534 printf("\n");
1537 if (x[0x18] & 0x04) {
1538 printf(" Default (sRGB) color space is primary color space\n");
1539 if (memcmp(x + 0x19, srgb_chromaticity, sizeof(srgb_chromaticity)))
1540 fail("sRGB is signaled, but the chromaticities do not match.\n");
1541 if (x[0x17] != 120)
1542 warn("sRGB is signaled, but the gamma != 2.2.\n");
1543 base.uses_srgb = true;
1544 } else if (!memcmp(x + 0x19, srgb_chromaticity, sizeof(srgb_chromaticity))) {
1545 fail("The chromaticities match sRGB, but sRGB is not signaled.\n");
1546 base.uses_srgb = true;
1549 if (base.edid_minor >= 4) {
1550 /* 1.4 always has a preferred timing and this bit means something else. */
1551 has_preferred_timing = true;
1552 base.preferred_is_also_native = x[0x18] & 0x02;
1553 printf(" First detailed timing %s the native pixel format and preferred refresh rate\n",
1554 base.preferred_is_also_native ? "includes" : "does not include");
1555 } else {
1556 if (x[0x18] & 0x02) {
1557 printf(" First detailed timing is the preferred timing\n");
1558 has_preferred_timing = true;
1559 // 1.3 recommends that the preferred timing corresponds to the
1560 // native timing, but it is not a requirement.
1561 // That said, we continue with the assumption that it actually
1562 // is the native timing.
1563 base.preferred_is_also_native = true;
1564 } else if (base.edid_minor == 3) {
1565 fail("EDID 1.3 requires that the first detailed timing is the preferred timing.\n");
1569 if (x[0x18] & 0x01) {
1570 if (base.edid_minor >= 4) {
1571 base.supports_continuous_freq = true;
1572 printf(" Display is continuous frequency\n");
1573 } else {
1574 printf(" Supports GTF timings within operating range\n");
1575 base.supports_gtf = true;
1579 data_block = "Color Characteristics";
1580 printf(" %s:\n", data_block.c_str());
1581 col_x = (x[0x1b] << 2) | (x[0x19] >> 6);
1582 col_y = (x[0x1c] << 2) | ((x[0x19] >> 4) & 3);
1583 printf(" Red : 0.%04u, 0.%04u\n",
1584 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1585 col_x = (x[0x1d] << 2) | ((x[0x19] >> 2) & 3);
1586 col_y = (x[0x1e] << 2) | (x[0x19] & 3);
1587 printf(" Green: 0.%04u, 0.%04u\n",
1588 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1589 col_x = (x[0x1f] << 2) | (x[0x1a] >> 6);
1590 col_y = (x[0x20] << 2) | ((x[0x1a] >> 4) & 3);
1591 printf(" Blue : 0.%04u, 0.%04u\n",
1592 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1593 col_x = (x[0x21] << 2) | ((x[0x1a] >> 2) & 3);
1594 col_y = (x[0x22] << 2) | (x[0x1a] & 3);
1595 printf(" White: 0.%04u, 0.%04u\n",
1596 (col_x * 10000) / 1024, (col_y * 10000) / 1024);
1598 data_block = "Established Timings I & II";
1599 if (x[0x23] || x[0x24] || x[0x25]) {
1600 printf(" %s:\n", data_block.c_str());
1601 for (unsigned i = 0; i < ARRAY_SIZE(established_timings12); i++) {
1602 if (x[0x23 + i / 8] & (1 << (7 - i % 8))) {
1603 unsigned char dmt_id = established_timings12[i].dmt_id;
1604 const struct timings *t;
1605 char type[16];
1607 if (dmt_id) {
1608 sprintf(type, "DMT 0x%02x", dmt_id);
1609 t = find_dmt_id(dmt_id);
1610 } else {
1611 t = &established_timings12[i].t;
1612 sprintf(type, "%-8s", established_timings12[i].type);
1614 print_timings(" ", t, type);
1617 } else {
1618 printf(" %s: none\n", data_block.c_str());
1620 base.has_640x480p60_est_timing = x[0x23] & 0x20;
1622 data_block = "Standard Timings";
1623 bool found = false;
1624 for (unsigned i = 0; i < 8; i++) {
1625 if (x[0x26 + i * 2] != 0x01 || x[0x26 + i * 2 + 1] != 0x01) {
1626 found = true;
1627 break;
1630 if (found) {
1631 printf(" %s:\n", data_block.c_str());
1632 for (unsigned i = 0; i < 8; i++)
1633 print_standard_timing(" ", x[0x26 + i * 2], x[0x26 + i * 2 + 1]);
1634 } else {
1635 printf(" %s: none\n", data_block.c_str());
1638 /* 18 byte descriptors */
1639 if (has_preferred_timing && !x[0x36] && !x[0x37])
1640 fail("Missing preferred timing.\n");
1642 /* Look for SPWG Noteboook Panel EDID data blocks */
1643 if ((x[0x36] || x[0x37]) &&
1644 (x[0x48] || x[0x49]) &&
1645 !x[0x5a] && !x[0x5b] && x[0x5d] == 0xfe &&
1646 !x[0x6c] && !x[0x6d] && x[0x6f] == 0xfe &&
1647 (x[0x79] == 1 || x[0x79] == 2) && x[0x7a] <= 1)
1648 base.has_spwg = true;
1650 for (unsigned i = 0; i < (base.has_spwg ? 2 : 4); i++)
1651 if (x[0x36 + i * 18] || x[0x37 + i * 18])
1652 cta.preparsed_total_dtds++;
1654 data_block = "Detailed Timing Descriptors";
1655 printf(" %s:\n", data_block.c_str());
1656 detailed_block(x + 0x36);
1657 detailed_block(x + 0x48);
1658 detailed_block(x + 0x5a);
1659 detailed_block(x + 0x6c);
1660 base.has_spwg = false;
1661 if (!base.preferred_is_also_native) {
1662 cta.native_timings.clear();
1663 base.preferred_timing = timings_ext();
1666 data_block = block;
1667 if (x[0x7e])
1668 printf(" Extension blocks: %u\n", x[0x7e]);
1670 block = block_name(0x00);
1671 data_block.clear();
1672 do_checksum("", x, EDID_PAGE_SIZE);
1673 if (base.edid_minor >= 3) {
1674 if (!base.has_name_descriptor)
1675 msg(base.edid_minor >= 4, "Missing Display Product Name.\n");
1676 if ((base.edid_minor == 3 || base.supports_continuous_freq) &&
1677 !base.has_display_range_descriptor)
1678 fail("Missing Display Range Limits Descriptor.\n");
1682 void edid_state::check_base_block(const unsigned char *x)
1684 data_block = "Base EDID";
1687 * Allow for regular rounding of vertical and horizontal frequencies.
1688 * The spec says that the pixelclock shall be rounded up, so there is
1689 * no need to take rounding into account.
1691 if (base.has_display_range_descriptor &&
1692 (min_vert_freq_hz + 0.5 < base.min_display_vert_freq_hz ||
1693 (max_vert_freq_hz >= base.max_display_vert_freq_hz + 0.5 && base.max_display_vert_freq_hz) ||
1694 min_hor_freq_hz + 500 < base.min_display_hor_freq_hz ||
1695 (max_hor_freq_hz >= base.max_display_hor_freq_hz + 500 && base.max_display_hor_freq_hz) ||
1696 (max_pixclk_khz > base.max_display_pixclk_khz && base.max_display_pixclk_khz))) {
1698 * Check if it is really out of range, or if it could be a rounding error.
1699 * The EDID spec is not very clear about rounding.
1701 bool out_of_range =
1702 min_vert_freq_hz + 1.0 <= base.min_display_vert_freq_hz ||
1703 (max_vert_freq_hz >= base.max_display_vert_freq_hz + 1.0 && base.max_display_vert_freq_hz) ||
1704 min_hor_freq_hz + 1000 <= base.min_display_hor_freq_hz ||
1705 (max_hor_freq_hz >= base.max_display_hor_freq_hz + 1000 && base.max_display_hor_freq_hz) ||
1706 (max_pixclk_khz >= base.max_display_pixclk_khz + 10000 && base.max_display_pixclk_khz);
1708 std::string err("Some timings are out of range of the Monitor Ranges:\n");
1709 char buf[512];
1711 if (min_vert_freq_hz + 0.5 < base.min_display_vert_freq_hz ||
1712 (max_vert_freq_hz >= base.max_display_vert_freq_hz + 0.5 && base.max_display_vert_freq_hz)) {
1713 sprintf(buf, " Vertical Freq: %.3f - %.3f Hz (Monitor: %u.000 - %u.000 Hz)\n",
1714 min_vert_freq_hz, max_vert_freq_hz,
1715 base.min_display_vert_freq_hz, base.max_display_vert_freq_hz);
1716 err += buf;
1719 if (min_hor_freq_hz + 500 < base.min_display_hor_freq_hz ||
1720 (max_hor_freq_hz >= base.max_display_hor_freq_hz + 500 && base.max_display_hor_freq_hz)) {
1721 sprintf(buf, " Horizontal Freq: %.3f - %.3f kHz (Monitor: %.3f - %.3f kHz)\n",
1722 min_hor_freq_hz / 1000.0, max_hor_freq_hz / 1000.0,
1723 base.min_display_hor_freq_hz / 1000.0, base.max_display_hor_freq_hz / 1000.0);
1724 err += buf;
1727 if (max_pixclk_khz >= base.max_display_pixclk_khz && base.max_display_pixclk_khz) {
1728 sprintf(buf, " Maximum Clock: %.3f MHz (Monitor: %.3f MHz)\n",
1729 max_pixclk_khz / 1000.0, base.max_display_pixclk_khz / 1000.0);
1730 err += buf;
1733 if (!out_of_range)
1734 err += " Could be due to a Monitor Range off-by-one rounding issue\n";
1737 * EDID 1.4 states (in an Errata) that explicitly defined
1738 * timings supersede the monitor range definition.
1740 msg(!out_of_range || base.edid_minor >= 4, "%s", err.c_str());
1743 if ((image_width && dtd_max_hsize_mm >= 10 + image_width / 10) ||
1744 (image_height && dtd_max_vsize_mm >= 10 + image_height / 10))
1745 fail("The DTD max image size is %ux%umm, which is larger than the display size %.1fx%.1fmm.\n",
1746 dtd_max_hsize_mm, dtd_max_vsize_mm,
1747 image_width / 10.0, image_height / 10.0);
1748 if ((!image_width && dtd_max_hsize_mm) || (!image_height && dtd_max_vsize_mm))
1749 fail("The DTD max image size is %ux%umm, but the display size is not specified anywhere.\n",
1750 dtd_max_hsize_mm, dtd_max_vsize_mm);
1752 // Secondary GTF curves start at a specific frequency. Any legacy timings
1753 // that have a positive hsync and negative vsync must be less than that
1754 // frequency to avoid confusion.
1755 if (base.supports_sec_gtf && base.max_pos_neg_hor_freq_khz >= base.sec_gtf_start_freq)
1756 fail("Second GTF start frequency %u is less than the highest P/N frequency %u.\n",
1757 base.sec_gtf_start_freq, base.max_pos_neg_hor_freq_khz);
1758 if (x[0x7e] + 1U != num_blocks && !cta.hf_eeodb_blocks)
1759 fail("EDID specified %u extension block(s), but found %u extension block(s).\n",
1760 x[0x7e], num_blocks - 1);
1761 else if (x[0x7e] != 1 && cta.hf_eeodb_blocks)
1762 fail("HDMI Forum EDID Extension Override Data Block is present, but Block 0 defined %u instead of 1 Extension Blocks.\n",
1763 x[0x7e]);
1764 else if (x[0x7e] == 1 && cta.hf_eeodb_blocks && cta.hf_eeodb_blocks + 1 != num_blocks)
1765 fail("HDMI Forum EDID Extension Override Data Block specified %u extension block(s), but found %u extension block(s).\n",
1766 cta.hf_eeodb_blocks, num_blocks - 1);
1768 if (base.edid_minor == 3 && num_blocks > 2 && !block_map.saw_block_1 && !cta.hf_eeodb_blocks)
1769 fail("EDID 1.3 requires a Block Map Extension in Block 1 if there are more than 2 blocks in the EDID.\n");
1770 if (base.edid_minor == 3 && num_blocks > 128 && !block_map.saw_block_128 && !cta.hf_eeodb_blocks)
1771 fail("EDID 1.3 requires a Block Map Extension in Block 128 if there are more than 128 blocks in the EDID.\n");
1772 if (block_map.saw_block_128 && num_blocks > 255)
1773 fail("If there is a Block Map Extension in Block 128 then the maximum number of blocks is 255.\n");