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