1 /* $NetBSD: edid.c,v 1.12 2013/02/08 16:35:10 skrll Exp $ */
2
3 /*-
4 * Copyright (c) 2006 Itronix Inc.
5 * All rights reserved.
6 *
7 * Written by Garrett D'Amore for Itronix Inc.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of Itronix Inc. may not be used to endorse
18 * or promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/libkern.h>
39 #include <dev/videomode/videomode.h>
40 #include <dev/videomode/ediddevs.h>
41 #include <dev/videomode/edidreg.h>
42 #include <dev/videomode/edidvar.h>
43 #include <dev/videomode/vesagtf.h>
44
45 #define EDIDVERBOSE 1
46 #define DIVIDE(x,y) (((x) + ((y) / 2)) / (y))
47
48 /* These are reversed established timing order */
49 static const char *_edid_modes[] = {
50 "1280x1024x75",
51 "1024x768x75",
52 "1024x768x70",
53 "1024x768x60",
54 "1024x768x87i",
55 "832x624x74", /* rounding error, 74.55 Hz aka "832x624x75" */
56 "800x600x75",
57 "800x600x72",
58 "800x600x60",
59 "800x600x56",
60 "640x480x75",
61 "640x480x72",
62 "640x480x67",
63 "640x480x60",
64 "720x400x87", /* rounding error, 87.85 Hz aka "720x400x88" */
65 "720x400x70",
66 };
67
68 #ifdef EDIDVERBOSE
69 struct edid_vendor {
70 const char *vendor;
71 const char *name;
72 };
73
74 struct edid_product {
75 const char *vendor;
76 uint16_t product;
77 const char *name;
78 };
79
80 #include <dev/videomode/ediddevs_data.h>
81 #endif /* EDIDVERBOSE */
82
83 static const char *
edid_findvendor(const char * vendor)84 edid_findvendor(const char *vendor)
85 {
86 #ifdef EDIDVERBOSE
87 int n;
88
89 for (n = 0; n < edid_nvendors; n++)
90 if (memcmp(edid_vendors[n].vendor, vendor, 3) == 0)
91 return edid_vendors[n].name;
92 #endif
93 return NULL;
94 }
95
96 static const char *
edid_findproduct(const char * vendor,uint16_t product)97 edid_findproduct(const char *vendor, uint16_t product)
98 {
99 #ifdef EDIDVERBOSE
100 int n;
101
102 for (n = 0; n < edid_nproducts; n++)
103 if (edid_products[n].product == product &&
104 memcmp(edid_products[n].vendor, vendor, 3) == 0)
105 return edid_products[n].name;
106 #endif /* EDIDVERBOSE */
107 return NULL;
108
109 }
110
111 static void
edid_strchomp(char * ptr)112 edid_strchomp(char *ptr)
113 {
114 for (;;) {
115 switch (*ptr) {
116 case '\0':
117 return;
118 case '\r':
119 case '\n':
120 *ptr = '\0';
121 return;
122 }
123 ptr++;
124 }
125 }
126
127 int
edid_is_valid(uint8_t * d)128 edid_is_valid(uint8_t *d)
129 {
130 int sum = 0, i;
131 uint8_t sig[8] = EDID_SIGNATURE;
132
133 if (memcmp(d, sig, 8) != 0)
134 return EINVAL;
135
136 for (i = 0; i < 128; i++)
137 sum += d[i];
138 if ((sum & 0xff) != 0)
139 return EINVAL;
140
141 return 0;
142 }
143
144 void
edid_print(struct edid_info * edid)145 edid_print(struct edid_info *edid)
146 {
147 int i;
148
149 if (edid == NULL)
150 return;
151 printf("Vendor: [%s] %s\n", edid->edid_vendor, edid->edid_vendorname);
152 printf("Product: [%04X] %s\n", edid->edid_product,
153 edid->edid_productname);
154 printf("Serial number: %s\n", edid->edid_serial);
155 printf("Manufactured %d Week %d\n",
156 edid->edid_year, edid->edid_week);
157 printf("EDID Version %d.%d\n", edid->edid_version,
158 edid->edid_revision);
159 printf("EDID Comment: %s\n", edid->edid_comment);
160
161 printf("Video Input: %x\n", edid->edid_video_input);
162 if (edid->edid_video_input & EDID_VIDEO_INPUT_DIGITAL) {
163 printf("\tDigital");
164 if (edid->edid_video_input & EDID_VIDEO_INPUT_DFP1_COMPAT)
165 printf(" (DFP 1.x compatible)");
166 printf("\n");
167 } else {
168 printf("\tAnalog\n");
169 switch (EDID_VIDEO_INPUT_LEVEL(edid->edid_video_input)) {
170 case 0:
171 printf("\t-0.7, 0.3V\n");
172 break;
173 case 1:
174 printf("\t-0.714, 0.286V\n");
175 break;
176 case 2:
177 printf("\t-1.0, 0.4V\n");
178 break;
179 case 3:
180 printf("\t-0.7, 0.0V\n");
181 break;
182 }
183 if (edid->edid_video_input & EDID_VIDEO_INPUT_BLANK_TO_BLACK)
184 printf("\tBlank-to-black setup\n");
185 if (edid->edid_video_input & EDID_VIDEO_INPUT_SEPARATE_SYNCS)
186 printf("\tSeparate syncs\n");
187 if (edid->edid_video_input & EDID_VIDEO_INPUT_COMPOSITE_SYNC)
188 printf("\tComposite sync\n");
189 if (edid->edid_video_input & EDID_VIDEO_INPUT_SYNC_ON_GRN)
190 printf("\tSync on green\n");
191 if (edid->edid_video_input & EDID_VIDEO_INPUT_SERRATION)
192 printf("\tSerration vsync\n");
193 }
194
195 printf("Gamma: %d.%02d\n",
196 edid->edid_gamma / 100, edid->edid_gamma % 100);
197
198 printf("Max Size: %d cm x %d cm\n",
199 edid->edid_max_hsize, edid->edid_max_vsize);
200
201 printf("Features: %x\n", edid->edid_features);
202 if (edid->edid_features & EDID_FEATURES_STANDBY)
203 printf("\tDPMS standby\n");
204 if (edid->edid_features & EDID_FEATURES_SUSPEND)
205 printf("\tDPMS suspend\n");
206 if (edid->edid_features & EDID_FEATURES_ACTIVE_OFF)
207 printf("\tDPMS active-off\n");
208 switch (EDID_FEATURES_DISP_TYPE(edid->edid_features)) {
209 case EDID_FEATURES_DISP_TYPE_MONO:
210 printf("\tMonochrome\n");
211 break;
212 case EDID_FEATURES_DISP_TYPE_RGB:
213 printf("\tRGB\n");
214 break;
215 case EDID_FEATURES_DISP_TYPE_NON_RGB:
216 printf("\tMulticolor\n");
217 break;
218 case EDID_FEATURES_DISP_TYPE_UNDEFINED:
219 printf("\tUndefined monitor type\n");
220 break;
221 }
222 if (edid->edid_features & EDID_FEATURES_STD_COLOR)
223 printf("\tStandard color space\n");
224 if (edid->edid_features & EDID_FEATURES_PREFERRED_TIMING)
225 printf("\tPreferred timing\n");
226 if (edid->edid_features & EDID_FEATURES_DEFAULT_GTF)
227 printf("\tDefault GTF supported\n");
228
229 printf("Chroma Info:\n");
230 printf("\tRed X: 0.%03d\n", edid->edid_chroma.ec_redx);
231 printf("\tRed Y: 0.%03d\n", edid->edid_chroma.ec_redy);
232 printf("\tGrn X: 0.%03d\n", edid->edid_chroma.ec_greenx);
233 printf("\tGrn Y: 0.%03d\n", edid->edid_chroma.ec_greeny);
234 printf("\tBlu X: 0.%03d\n", edid->edid_chroma.ec_bluex);
235 printf("\tBlu Y: 0.%03d\n", edid->edid_chroma.ec_bluey);
236 printf("\tWht X: 0.%03d\n", edid->edid_chroma.ec_whitex);
237 printf("\tWht Y: 0.%03d\n", edid->edid_chroma.ec_whitey);
238
239 if (edid->edid_have_range) {
240 printf("Range:\n");
241 printf("\tHorizontal: %d - %d kHz\n",
242 edid->edid_range.er_min_hfreq,
243 edid->edid_range.er_max_hfreq);
244 printf("\tVertical: %d - %d Hz\n",
245 edid->edid_range.er_min_vfreq,
246 edid->edid_range.er_max_vfreq);
247 printf("\tMax Dot Clock: %d MHz\n",
248 edid->edid_range.er_max_clock);
249 if (edid->edid_range.er_have_gtf2) {
250 printf("\tGTF2 hfreq: %d\n",
251 edid->edid_range.er_gtf2_hfreq);
252 printf("\tGTF2 C: %d\n", edid->edid_range.er_gtf2_c);
253 printf("\tGTF2 M: %d\n", edid->edid_range.er_gtf2_m);
254 printf("\tGTF2 J: %d\n", edid->edid_range.er_gtf2_j);
255 printf("\tGTF2 K: %d\n", edid->edid_range.er_gtf2_k);
256 }
257 }
258 printf("Video modes:\n");
259 for (i = 0; i < edid->edid_nmodes; i++) {
260 printf("\t%dx%d @ %dHz",
261 edid->edid_modes[i].hdisplay,
262 edid->edid_modes[i].vdisplay,
263 DIVIDE(DIVIDE(edid->edid_modes[i].dot_clock * 1000,
264 edid->edid_modes[i].htotal), edid->edid_modes[i].vtotal));
265 printf(" (%d %d %d %d %d %d %d",
266 edid->edid_modes[i].dot_clock,
267 edid->edid_modes[i].hsync_start,
268 edid->edid_modes[i].hsync_end,
269 edid->edid_modes[i].htotal,
270 edid->edid_modes[i].vsync_start,
271 edid->edid_modes[i].vsync_end,
272 edid->edid_modes[i].vtotal);
273 printf(" %s%sH %s%sV)\n",
274 edid->edid_modes[i].flags & VID_PHSYNC ? "+" : "",
275 edid->edid_modes[i].flags & VID_NHSYNC ? "-" : "",
276 edid->edid_modes[i].flags & VID_PVSYNC ? "+" : "",
277 edid->edid_modes[i].flags & VID_NVSYNC ? "-" : "");
278 }
279 if (edid->edid_preferred_mode)
280 printf("Preferred mode: %dx%d @ %dHz\n",
281 edid->edid_preferred_mode->hdisplay,
282 edid->edid_preferred_mode->vdisplay,
283 DIVIDE(DIVIDE(edid->edid_preferred_mode->dot_clock * 1000,
284 edid->edid_preferred_mode->htotal),
285 edid->edid_preferred_mode->vtotal));
286
287 printf("Number of extension blocks: %d\n", edid->edid_ext_block_count);
288 }
289
290 static const struct videomode *
edid_mode_lookup_list(const char * name)291 edid_mode_lookup_list(const char *name)
292 {
293 int i;
294
295 for (i = 0; i < videomode_count; i++)
296 if (strcmp(name, videomode_list[i].name) == 0)
297 return &videomode_list[i];
298 return NULL;
299 }
300
301 static struct videomode *
edid_search_mode(struct edid_info * edid,const struct videomode * mode)302 edid_search_mode(struct edid_info *edid, const struct videomode *mode)
303 {
304 int refresh, i;
305
306 refresh = DIVIDE(DIVIDE(mode->dot_clock * 1000,
307 mode->htotal), mode->vtotal);
308 for (i = 0; i < edid->edid_nmodes; i++) {
309 if (mode->hdisplay == edid->edid_modes[i].hdisplay &&
310 mode->vdisplay == edid->edid_modes[i].vdisplay &&
311 refresh == DIVIDE(DIVIDE(
312 edid->edid_modes[i].dot_clock * 1000,
313 edid->edid_modes[i].htotal), edid->edid_modes[i].vtotal)) {
314 return &edid->edid_modes[i];
315 }
316 }
317 return NULL;
318 }
319
320 static int
edid_std_timing(uint8_t * data,struct videomode * vmp)321 edid_std_timing(uint8_t *data, struct videomode *vmp)
322 {
323 unsigned x, y, f;
324 const struct videomode *lookup;
325 char name[80];
326
327 if ((data[0] == 1 && data[1] == 1) ||
328 (data[0] == 0 && data[1] == 0) ||
329 (data[0] == 0x20 && data[1] == 0x20))
330 return 0;
331
332 x = EDID_STD_TIMING_HRES(data);
333 switch (EDID_STD_TIMING_RATIO(data)) {
334 case EDID_STD_TIMING_RATIO_16_10:
335 y = x * 10 / 16;
336 break;
337 case EDID_STD_TIMING_RATIO_4_3:
338 y = x * 3 / 4;
339 break;
340 case EDID_STD_TIMING_RATIO_5_4:
341 y = x * 4 / 5;
342 break;
343 case EDID_STD_TIMING_RATIO_16_9:
344 default:
345 y = x * 9 / 16;
346 break;
347 }
348 f = EDID_STD_TIMING_VFREQ(data);
349
350 /* first try to lookup the mode as a DMT timing */
351 snprintf(name, sizeof(name), "%dx%dx%d", x, y, f);
352 if ((lookup = edid_mode_lookup_list(name)) != NULL) {
353 *vmp = *lookup;
354 } else {
355 /* failing that, calculate it using gtf */
356 /*
357 * Hmm. I'm not using alternate GTF timings, which
358 * could, in theory, be present.
359 */
360 vesagtf_mode(x, y, f, vmp);
361 }
362 return 1;
363 }
364
365 static int
edid_det_timing(uint8_t * data,struct videomode * vmp)366 edid_det_timing(uint8_t *data, struct videomode *vmp)
367 {
368 unsigned hactive, hblank, hsyncwid, hsyncoff;
369 unsigned vactive, vblank, vsyncwid, vsyncoff;
370 uint8_t flags;
371
372 flags = EDID_DET_TIMING_FLAGS(data);
373
374 /* we don't support stereo modes (for now) */
375 if (flags & (EDID_DET_TIMING_FLAG_STEREO |
376 EDID_DET_TIMING_FLAG_STEREO_MODE))
377 return 0;
378
379 vmp->dot_clock = EDID_DET_TIMING_DOT_CLOCK(data) / 1000;
380
381 hactive = EDID_DET_TIMING_HACTIVE(data);
382 hblank = EDID_DET_TIMING_HBLANK(data);
383 hsyncwid = EDID_DET_TIMING_HSYNC_WIDTH(data);
384 hsyncoff = EDID_DET_TIMING_HSYNC_OFFSET(data);
385
386 vactive = EDID_DET_TIMING_VACTIVE(data);
387 vblank = EDID_DET_TIMING_VBLANK(data);
388 vsyncwid = EDID_DET_TIMING_VSYNC_WIDTH(data);
389 vsyncoff = EDID_DET_TIMING_VSYNC_OFFSET(data);
390
391 /* Borders are contained within the blank areas. */
392
393 vmp->hdisplay = hactive;
394 vmp->htotal = hactive + hblank;
395 vmp->hsync_start = hactive + hsyncoff;
396 vmp->hsync_end = vmp->hsync_start + hsyncwid;
397
398 vmp->vdisplay = vactive;
399 vmp->vtotal = vactive + vblank;
400 vmp->vsync_start = vactive + vsyncoff;
401 vmp->vsync_end = vmp->vsync_start + vsyncwid;
402
403 vmp->flags = 0;
404
405 if (flags & EDID_DET_TIMING_FLAG_INTERLACE)
406 vmp->flags |= VID_INTERLACE;
407 if (flags & EDID_DET_TIMING_FLAG_HSYNC_POSITIVE)
408 vmp->flags |= VID_PHSYNC;
409 else
410 vmp->flags |= VID_NHSYNC;
411
412 if (flags & EDID_DET_TIMING_FLAG_VSYNC_POSITIVE)
413 vmp->flags |= VID_PVSYNC;
414 else
415 vmp->flags |= VID_NVSYNC;
416
417 return 1;
418 }
419
420 static void
edid_block(struct edid_info * edid,uint8_t * data)421 edid_block(struct edid_info *edid, uint8_t *data)
422 {
423 int i;
424 struct videomode mode, *exist_mode;
425
426 if (EDID_BLOCK_IS_DET_TIMING(data)) {
427 if (!edid_det_timing(data, &mode))
428 return;
429 /* Does this mode already exist? */
430 exist_mode = edid_search_mode(edid, &mode);
431 if (exist_mode != NULL) {
432 *exist_mode = mode;
433 if (edid->edid_preferred_mode == NULL)
434 edid->edid_preferred_mode = exist_mode;
435 } else {
436 edid->edid_modes[edid->edid_nmodes] = mode;
437 if (edid->edid_preferred_mode == NULL)
438 edid->edid_preferred_mode =
439 &edid->edid_modes[edid->edid_nmodes];
440 edid->edid_nmodes++;
441 }
442 return;
443 }
444
445 switch (EDID_BLOCK_TYPE(data)) {
446 case EDID_DESC_BLOCK_TYPE_SERIAL:
447 memcpy(edid->edid_serial, data + EDID_DESC_ASCII_DATA_OFFSET,
448 EDID_DESC_ASCII_DATA_LEN);
449 edid->edid_serial[sizeof(edid->edid_serial) - 1] = 0;
450 break;
451
452 case EDID_DESC_BLOCK_TYPE_ASCII:
453 memcpy(edid->edid_comment, data + EDID_DESC_ASCII_DATA_OFFSET,
454 EDID_DESC_ASCII_DATA_LEN);
455 edid->edid_comment[sizeof(edid->edid_comment) - 1] = 0;
456 break;
457
458 case EDID_DESC_BLOCK_TYPE_RANGE:
459 edid->edid_have_range = 1;
460 edid->edid_range.er_min_vfreq = EDID_DESC_RANGE_MIN_VFREQ(data);
461 edid->edid_range.er_max_vfreq = EDID_DESC_RANGE_MAX_VFREQ(data);
462 edid->edid_range.er_min_hfreq = EDID_DESC_RANGE_MIN_HFREQ(data);
463 edid->edid_range.er_max_hfreq = EDID_DESC_RANGE_MAX_HFREQ(data);
464 edid->edid_range.er_max_clock = EDID_DESC_RANGE_MAX_CLOCK(data);
465 if (!EDID_DESC_RANGE_HAVE_GTF2(data))
466 break;
467 edid->edid_range.er_have_gtf2 = 1;
468 edid->edid_range.er_gtf2_hfreq =
469 EDID_DESC_RANGE_GTF2_HFREQ(data);
470 edid->edid_range.er_gtf2_c = EDID_DESC_RANGE_GTF2_C(data);
471 edid->edid_range.er_gtf2_m = EDID_DESC_RANGE_GTF2_M(data);
472 edid->edid_range.er_gtf2_j = EDID_DESC_RANGE_GTF2_J(data);
473 edid->edid_range.er_gtf2_k = EDID_DESC_RANGE_GTF2_K(data);
474 break;
475
476 case EDID_DESC_BLOCK_TYPE_NAME:
477 /* copy the product name into place */
478 memcpy(edid->edid_productname,
479 data + EDID_DESC_ASCII_DATA_OFFSET,
480 EDID_DESC_ASCII_DATA_LEN);
481 break;
482
483 case EDID_DESC_BLOCK_TYPE_STD_TIMING:
484 data += EDID_DESC_STD_TIMING_START;
485 for (i = 0; i < EDID_DESC_STD_TIMING_COUNT; i++) {
486 if (edid_std_timing(data, &mode)) {
487 /* Does this mode already exist? */
488 exist_mode = edid_search_mode(edid, &mode);
489 if (exist_mode == NULL) {
490 edid->edid_modes[edid->edid_nmodes] =
491 mode;
492 edid->edid_nmodes++;
493 }
494 }
495 data += 2;
496 }
497 break;
498
499 case EDID_DESC_BLOCK_TYPE_COLOR_POINT:
500 /* XXX: not implemented yet */
501 break;
502 }
503 }
504
505 /*
506 * Gets EDID version in BCD, e.g. EDID v1.3 returned as 0x0103
507 */
508 int
edid_parse(uint8_t * data,struct edid_info * edid)509 edid_parse(uint8_t *data, struct edid_info *edid)
510 {
511 uint16_t manfid, estmodes;
512 const struct videomode *vmp;
513 int i;
514 const char *name;
515 int max_dotclock = 0;
516 int mhz;
517
518 if (edid_is_valid(data) != 0)
519 return -1;
520
521 /* get product identification */
522 manfid = EDID_VENDOR_ID(data);
523 edid->edid_vendor[0] = EDID_MANFID_0(manfid);
524 edid->edid_vendor[1] = EDID_MANFID_1(manfid);
525 edid->edid_vendor[2] = EDID_MANFID_2(manfid);
526 edid->edid_vendor[3] = 0; /* null terminate for convenience */
527
528 edid->edid_product = data[EDID_OFFSET_PRODUCT_ID] +
529 (data[EDID_OFFSET_PRODUCT_ID + 1] << 8);
530
531 name = edid_findvendor(edid->edid_vendor);
532 if (name != NULL)
533 strlcpy(edid->edid_vendorname, name,
534 sizeof(edid->edid_vendorname));
535 else
536 edid->edid_vendorname[0] = '\0';
537
538 name = edid_findproduct(edid->edid_vendor, edid->edid_product);
539 if (name != NULL)
540 strlcpy(edid->edid_productname, name,
541 sizeof(edid->edid_productname));
542 else
543 edid->edid_productname[0] = '\0';
544
545 snprintf(edid->edid_serial, sizeof(edid->edid_serial), "%08x",
546 EDID_SERIAL_NUMBER(data));
547
548 edid->edid_week = EDID_WEEK(data);
549 edid->edid_year = EDID_YEAR(data);
550
551 /* get edid revision */
552 edid->edid_version = EDID_VERSION(data);
553 edid->edid_revision = EDID_REVISION(data);
554
555 edid->edid_video_input = EDID_VIDEO_INPUT(data);
556 edid->edid_max_hsize = EDID_MAX_HSIZE(data);
557 edid->edid_max_vsize = EDID_MAX_VSIZE(data);
558
559 edid->edid_gamma = EDID_GAMMA(data);
560 edid->edid_features = EDID_FEATURES(data);
561
562 edid->edid_chroma.ec_redx = EDID_CHROMA_REDX(data);
563 edid->edid_chroma.ec_redy = EDID_CHROMA_REDX(data);
564 edid->edid_chroma.ec_greenx = EDID_CHROMA_GREENX(data);
565 edid->edid_chroma.ec_greeny = EDID_CHROMA_GREENY(data);
566 edid->edid_chroma.ec_bluex = EDID_CHROMA_BLUEX(data);
567 edid->edid_chroma.ec_bluey = EDID_CHROMA_BLUEY(data);
568 edid->edid_chroma.ec_whitex = EDID_CHROMA_WHITEX(data);
569 edid->edid_chroma.ec_whitey = EDID_CHROMA_WHITEY(data);
570
571 edid->edid_ext_block_count = EDID_EXT_BLOCK_COUNT(data);
572
573 /* lookup established modes */
574 edid->edid_nmodes = 0;
575 edid->edid_preferred_mode = NULL;
576 estmodes = EDID_EST_TIMING(data);
577 /* Iterate in esztablished timing order */
578 for (i = 15; i >= 0; i--) {
579 if (estmodes & (1 << i)) {
580 vmp = edid_mode_lookup_list(_edid_modes[i]);
581 if (vmp != NULL) {
582 edid->edid_modes[edid->edid_nmodes] = *vmp;
583 edid->edid_nmodes++;
584 }
585 #ifdef DIAGNOSTIC
586 else
587 printf("no data for est. mode %s\n",
588 _edid_modes[i]);
589 #endif
590 }
591 }
592
593 /* do standard timing section */
594 for (i = 0; i < EDID_STD_TIMING_COUNT; i++) {
595 struct videomode mode, *exist_mode;
596 if (edid_std_timing(data + EDID_OFFSET_STD_TIMING + i * 2,
597 &mode)) {
598 /* Does this mode already exist? */
599 exist_mode = edid_search_mode(edid, &mode);
600 if (exist_mode == NULL) {
601 edid->edid_modes[edid->edid_nmodes] = mode;
602 edid->edid_nmodes++;
603 }
604 }
605 }
606
607 /* do detailed timings and descriptors */
608 for (i = 0; i < EDID_BLOCK_COUNT; i++) {
609 edid_block(edid, data + EDID_OFFSET_DESC_BLOCK +
610 i * EDID_BLOCK_SIZE);
611 }
612
613 edid_strchomp(edid->edid_vendorname);
614 edid_strchomp(edid->edid_productname);
615 edid_strchomp(edid->edid_serial);
616 edid_strchomp(edid->edid_comment);
617
618 /*
619 * XXX
620 * some monitors lie about their maximum supported dot clock
621 * by claiming to support modes which need a higher dot clock
622 * than the stated maximum.
623 * For sanity's sake we bump it to the highest dot clock we find
624 * in the list of supported modes
625 */
626 for (i = 0; i < edid->edid_nmodes; i++)
627 if (edid->edid_modes[i].dot_clock > max_dotclock)
628 max_dotclock = edid->edid_modes[i].dot_clock;
629 if (bootverbose) {
630 printf("edid: max_dotclock according to supported modes: %d\n",
631 max_dotclock);
632 }
633 mhz = (max_dotclock + 999) / 1000;
634
635 if (edid->edid_have_range) {
636 if (mhz > edid->edid_range.er_max_clock)
637 edid->edid_range.er_max_clock = mhz;
638 } else
639 edid->edid_range.er_max_clock = mhz;
640
641 return 0;
642 }
643