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