Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * Copyright 2006-2012 Red Hat, Inc. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
| 9 | * license, and/or sell copies of the Software, and to permit persons to whom |
| 10 | * the Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 20 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 21 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | /* Author: Adam Jackson <ajax@nwnk.net> */ |
| 24 | |
| 25 | /* this is a pretty robust parser for EDID, and we're tasked with parsing |
| 26 | * an arbitrary panel. We will pass it a raw EDID block and a struct which |
| 27 | * it must fill in with values. The set of values we need is pretty limited |
| 28 | * at present. |
| 29 | */ |
| 30 | |
| 31 | #include <stddef.h> |
| 32 | #include <console/console.h> |
| 33 | #include <arch/io.h> |
| 34 | #include <arch/byteorder.h> |
| 35 | #include <stdint.h> |
| 36 | #include <string.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <edid.h> |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 39 | #include <boot/coreboot_tables.h> |
| 40 | #include <vbe.h> |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 41 | |
| 42 | static int claims_one_point_oh = 0; |
| 43 | static int claims_one_point_two = 0; |
| 44 | static int claims_one_point_three = 0; |
| 45 | static int claims_one_point_four = 0; |
| 46 | static int nonconformant_digital_display = 0; |
| 47 | static int nonconformant_extension = 0; |
| 48 | static int did_detailed_timing = 0; |
| 49 | static int has_name_descriptor = 0; |
| 50 | static int name_descriptor_terminated = 0; |
| 51 | static int has_range_descriptor = 0; |
| 52 | static int has_preferred_timing = 0; |
| 53 | static int has_valid_checksum = 0; |
| 54 | static int has_valid_cvt = 1; |
| 55 | static int has_valid_dummy_block = 1; |
| 56 | static int has_valid_week = 0; |
| 57 | static int has_valid_year = 0; |
| 58 | static int has_valid_detailed_blocks = 0; |
| 59 | static int has_valid_extension_count = 0; |
| 60 | static int has_valid_descriptor_ordering = 1; |
| 61 | static int has_valid_descriptor_pad = 1; |
| 62 | static int has_valid_range_descriptor = 1; |
| 63 | static int has_valid_max_dotclock = 1; |
| 64 | static int has_valid_string_termination = 1; |
| 65 | static int manufacturer_name_well_formed = 0; |
| 66 | static int seen_non_detailed_descriptor = 0; |
| 67 | |
| 68 | static int warning_excessive_dotclock_correction = 0; |
| 69 | static int warning_zero_preferred_refresh = 0; |
| 70 | |
| 71 | static int conformant = 1; |
| 72 | |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 73 | static int vbe_valid; |
| 74 | static struct lb_framebuffer edid_fb; |
| 75 | |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 76 | static char *manufacturer_name(struct edid *out, unsigned char *x) |
| 77 | { |
| 78 | out->manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@'; |
| 79 | out->manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@'; |
| 80 | out->manuf_name[2] = (x[1] & 0x1F) + '@'; |
| 81 | out->manuf_name[3] = 0; |
| 82 | |
| 83 | if (isupper(out->manuf_name[0]) && |
| 84 | isupper(out->manuf_name[1]) && |
| 85 | isupper(out->manuf_name[2])) |
| 86 | manufacturer_name_well_formed = 1; |
| 87 | |
| 88 | return out->manuf_name; |
| 89 | } |
| 90 | |
| 91 | static int |
| 92 | detailed_cvt_descriptor(struct edid *out, unsigned char *x, int first) |
| 93 | { |
| 94 | const unsigned char empty[3] = { 0, 0, 0 }; |
| 95 | const char *names[] = { "50", "60", "75", "85" }; |
| 96 | int width = 0, height = 0; |
| 97 | int valid = 1; |
| 98 | int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0; |
| 99 | |
| 100 | if (!first && !memcmp(x, empty, 3)) |
| 101 | return valid; |
| 102 | |
| 103 | height = x[0]; |
| 104 | height |= (x[1] & 0xf0) << 4; |
| 105 | height++; |
| 106 | height *= 2; |
| 107 | |
| 108 | switch (x[1] & 0x0c) { |
| 109 | case 0x00: |
| 110 | width = (height * 4) / 3; break; |
| 111 | case 0x04: |
| 112 | width = (height * 16) / 9; break; |
| 113 | case 0x08: |
| 114 | width = (height * 16) / 10; break; |
| 115 | case 0x0c: |
| 116 | width = (height * 15) / 9; break; |
| 117 | } |
| 118 | |
| 119 | if (x[1] & 0x03) |
| 120 | valid = 0; |
| 121 | if (x[2] & 0x80) |
| 122 | valid = 0; |
| 123 | if (!(x[2] & 0x1f)) |
| 124 | valid = 0; |
| 125 | |
| 126 | fifty = (x[2] & 0x10); |
| 127 | sixty = (x[2] & 0x08); |
| 128 | seventyfive = (x[2] & 0x04); |
| 129 | eightyfive = (x[2] & 0x02); |
| 130 | reduced = (x[2] & 0x01); |
| 131 | |
| 132 | if (!valid) { |
| 133 | printk(BIOS_SPEW, " (broken)\n"); |
| 134 | } else { |
| 135 | printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n", |
| 136 | width, height, |
| 137 | fifty ? "50 " : "", |
| 138 | sixty ? "60 " : "", |
| 139 | seventyfive ? "75 " : "", |
| 140 | eightyfive ? "85 " : "", |
| 141 | reduced ? "60RB " : "", |
| 142 | names[(x[2] & 0x60) >> 5], |
| 143 | (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : ""); |
| 144 | } |
| 145 | |
| 146 | return valid; |
| 147 | } |
| 148 | |
| 149 | static int isalnum(char x) |
| 150 | { |
| 151 | if (x >= 'a' && x <= 'z') |
| 152 | return 1; |
| 153 | if (x >= 'A' && x <= 'Z') |
| 154 | return 1; |
| 155 | if (x >= '0' && x <= '9') |
| 156 | return 1; |
| 157 | return 0; |
| 158 | |
| 159 | } |
| 160 | /* extract a string from a detailed subblock, checking for termination */ |
| 161 | static char * |
| 162 | extract_string(unsigned char *x, int *valid_termination, int len) |
| 163 | { |
| 164 | static char ret[128]; |
| 165 | int i, seen_newline = 0; |
| 166 | |
| 167 | memset(ret, 0, sizeof(ret)); |
| 168 | |
| 169 | for (i = 0; i < len; i++) { |
| 170 | if (isalnum(x[i])) { |
| 171 | ret[i] = x[i]; |
| 172 | } else if (!seen_newline) { |
| 173 | if (x[i] == 0x0a) { |
| 174 | seen_newline = 1; |
| 175 | } else { |
| 176 | *valid_termination = 0; |
| 177 | return ret; |
| 178 | } |
| 179 | } else { |
| 180 | if (x[i] != 0x20) { |
| 181 | *valid_termination = 0; |
| 182 | return ret; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return ret; |
| 188 | } |
| 189 | |
| 190 | /* 1 means valid data */ |
| 191 | static int |
| 192 | detailed_block(struct edid *out, unsigned char *x, int in_extension) |
| 193 | { |
| 194 | static unsigned char name[53]; |
| 195 | int i; |
| 196 | #if 1 |
| 197 | printk(BIOS_SPEW, "Hex of detail: "); |
| 198 | for (i = 0; i < 18; i++) |
| 199 | printk(BIOS_SPEW, "%02x", x[i]); |
| 200 | printk(BIOS_SPEW, "\n"); |
| 201 | #endif |
| 202 | |
| 203 | if (x[0] == 0 && x[1] == 0) { |
| 204 | /* Monitor descriptor block, not detailed timing descriptor. */ |
| 205 | if (x[2] != 0) { |
| 206 | /* 1.3, 3.10.3 */ |
| 207 | printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n", |
| 208 | x[2]); |
| 209 | has_valid_descriptor_pad = 0; |
| 210 | } |
| 211 | if (x[3] != 0xfd && x[4] != 0x00) { |
| 212 | /* 1.3, 3.10.3 */ |
| 213 | printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n", |
| 214 | x[4]); |
| 215 | has_valid_descriptor_pad = 0; |
| 216 | } |
| 217 | |
| 218 | seen_non_detailed_descriptor = 1; |
| 219 | if (x[3] <= 0xF) { |
| 220 | /* |
| 221 | * in principle we can decode these, if we know what they are. |
| 222 | * 0x0f seems to be common in laptop panels. |
| 223 | * 0x0e is used by EPI: http://www.epi-standard.org/ |
| 224 | */ |
| 225 | printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]); |
| 226 | return 0; |
| 227 | } |
| 228 | switch (x[3]) { |
| 229 | case 0x10: |
| 230 | printk(BIOS_SPEW, "Dummy block\n"); |
| 231 | for (i = 5; i < 18; i++) |
| 232 | if (x[i] != 0x00) |
| 233 | has_valid_dummy_block = 0; |
| 234 | return 0; |
| 235 | case 0xF7: |
| 236 | /* TODO */ |
| 237 | printk(BIOS_SPEW, "Established timings III\n"); |
| 238 | return 0; |
| 239 | case 0xF8: |
| 240 | { |
| 241 | int valid_cvt = 1; /* just this block */ |
| 242 | printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n"); |
| 243 | if (x[5] != 0x01) { |
| 244 | has_valid_cvt = 0; |
| 245 | return 0; |
| 246 | } |
| 247 | for (i = 0; i < 4; i++) |
| 248 | valid_cvt &= detailed_cvt_descriptor(out, x + 6 + (i * 3), (i == 0)); |
| 249 | has_valid_cvt &= valid_cvt; |
| 250 | return 0; |
| 251 | } |
| 252 | case 0xF9: |
| 253 | /* TODO */ |
| 254 | printk(BIOS_SPEW, "Color management data\n"); |
| 255 | return 0; |
| 256 | case 0xFA: |
| 257 | /* TODO */ |
| 258 | printk(BIOS_SPEW, "More standard timings\n"); |
| 259 | return 0; |
| 260 | case 0xFB: |
| 261 | /* TODO */ |
| 262 | printk(BIOS_SPEW, "Color point\n"); |
| 263 | return 0; |
| 264 | case 0xFC: |
| 265 | /* XXX should check for spaces after the \n */ |
| 266 | /* XXX check: terminated with 0x0A, padded with 0x20 */ |
| 267 | has_name_descriptor = 1; |
| 268 | if (strchr((char *)name, '\n')) return 0; |
| 269 | /* avoid strncat |
| 270 | strncat((char *)name, (char *)x + 5, 13); |
| 271 | */ |
| 272 | if (strchr((char *)name, '\n') || strchr((char *)x+5, '\n')) { |
| 273 | name_descriptor_terminated = 1; |
| 274 | /* later. |
| 275 | printk(BIOS_SPEW, "Monitor name: %s\n", |
| 276 | extract_string(name, &has_valid_string_termination, |
| 277 | strlen((char *)name))); |
| 278 | */ |
| 279 | } |
| 280 | return 0; |
| 281 | case 0xFD: |
| 282 | { |
| 283 | int h_max_offset = 0, h_min_offset = 0; |
| 284 | int v_max_offset = 0, v_min_offset = 0; |
| 285 | int is_cvt = 0; |
| 286 | has_range_descriptor = 1; |
| 287 | out->range_class = ""; |
| 288 | /* |
| 289 | * XXX todo: implement feature flags, vtd blocks |
| 290 | * XXX check: ranges are well-formed; block termination if no vtd |
| 291 | */ |
| 292 | if (claims_one_point_four) { |
| 293 | if (x[4] & 0x02) { |
| 294 | v_max_offset = 255; |
| 295 | if (x[4] & 0x01) { |
| 296 | v_min_offset = 255; |
| 297 | } |
| 298 | } |
| 299 | if (x[4] & 0x04) { |
| 300 | h_max_offset = 255; |
| 301 | if (x[4] & 0x03) { |
| 302 | h_min_offset = 255; |
| 303 | } |
| 304 | } |
| 305 | } else if (x[4]) { |
| 306 | has_valid_range_descriptor = 0; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * despite the values, this is not a bitfield. |
| 311 | */ |
| 312 | switch (x[10]) { |
| 313 | case 0x00: /* default gtf */ |
| 314 | out->range_class = "GTF"; |
| 315 | break; |
| 316 | case 0x01: /* range limits only */ |
| 317 | out->range_class = "bare limits"; |
| 318 | if (!claims_one_point_four) |
| 319 | has_valid_range_descriptor = 0; |
| 320 | break; |
| 321 | case 0x02: /* secondary gtf curve */ |
| 322 | out->range_class = "GTF with icing"; |
| 323 | break; |
| 324 | case 0x04: /* cvt */ |
| 325 | out->range_class = "CVT"; |
| 326 | is_cvt = 1; |
| 327 | if (!claims_one_point_four) |
| 328 | has_valid_range_descriptor = 0; |
| 329 | break; |
| 330 | default: /* invalid */ |
| 331 | has_valid_range_descriptor = 0; |
| 332 | out->range_class = "invalid"; |
| 333 | break; |
| 334 | } |
| 335 | |
| 336 | if (x[5] + v_min_offset > x[6] + v_max_offset) |
| 337 | has_valid_range_descriptor = 0; |
| 338 | if (x[7] + h_min_offset > x[8] + h_max_offset) |
| 339 | has_valid_range_descriptor = 0; |
| 340 | printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H", |
| 341 | out->range_class, |
| 342 | x[5] + v_min_offset, x[6] + v_max_offset, |
| 343 | x[7] + h_min_offset, x[8] + h_max_offset); |
| 344 | if (x[9]) |
| 345 | printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10); |
| 346 | else { |
| 347 | if (claims_one_point_four) |
| 348 | has_valid_max_dotclock = 0; |
| 349 | printk(BIOS_SPEW, "\n"); |
| 350 | } |
| 351 | |
| 352 | if (is_cvt) { |
| 353 | int max_h_pixels = 0; |
| 354 | |
| 355 | printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f); |
| 356 | |
| 357 | if (x[12] & 0xfc) { |
| 358 | int raw_offset = (x[12] & 0xfc) >> 2; |
| 359 | printk(BIOS_SPEW, "Real max dotclock: %.2fMHz\n", |
| 360 | (x[9] * 10) - (raw_offset * 0.25)); |
| 361 | if (raw_offset >= 40) |
| 362 | warning_excessive_dotclock_correction = 1; |
| 363 | } |
| 364 | |
| 365 | max_h_pixels = x[12] & 0x03; |
| 366 | max_h_pixels <<= 8; |
| 367 | max_h_pixels |= x[13]; |
| 368 | max_h_pixels *= 8; |
| 369 | if (max_h_pixels) |
| 370 | printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels); |
| 371 | |
| 372 | printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n", |
| 373 | x[14] & 0x80 ? "4:3" : "", |
| 374 | x[14] & 0x40 ? "16:9" : "", |
| 375 | x[14] & 0x20 ? "16:10" : "", |
| 376 | x[14] & 0x10 ? "5:4" : "", |
| 377 | x[14] & 0x08 ? "15:9" : ""); |
| 378 | if (x[14] & 0x07) |
| 379 | has_valid_range_descriptor = 0; |
| 380 | |
| 381 | printk(BIOS_SPEW, "Preferred aspect ratio: "); |
| 382 | switch((x[15] & 0xe0) >> 5) { |
| 383 | case 0x00: printk(BIOS_SPEW, "4:3"); break; |
| 384 | case 0x01: printk(BIOS_SPEW, "16:9"); break; |
| 385 | case 0x02: printk(BIOS_SPEW, "16:10"); break; |
| 386 | case 0x03: printk(BIOS_SPEW, "5:4"); break; |
| 387 | case 0x04: printk(BIOS_SPEW, "15:9"); break; |
| 388 | default: printk(BIOS_SPEW, "(broken)"); break; |
| 389 | } |
| 390 | printk(BIOS_SPEW, "\n"); |
| 391 | |
| 392 | if (x[15] & 0x04) |
| 393 | printk(BIOS_SPEW, "Supports CVT standard blanking\n"); |
| 394 | if (x[15] & 0x10) |
| 395 | printk(BIOS_SPEW, "Supports CVT reduced blanking\n"); |
| 396 | |
| 397 | if (x[15] & 0x07) |
| 398 | has_valid_range_descriptor = 0; |
| 399 | |
| 400 | if (x[16] & 0xf0) { |
| 401 | printk(BIOS_SPEW, "Supported display scaling:\n"); |
| 402 | if (x[16] & 0x80) |
| 403 | printk(BIOS_SPEW, " Horizontal shrink\n"); |
| 404 | if (x[16] & 0x40) |
| 405 | printk(BIOS_SPEW, " Horizontal stretch\n"); |
| 406 | if (x[16] & 0x20) |
| 407 | printk(BIOS_SPEW, " Vertical shrink\n"); |
| 408 | if (x[16] & 0x10) |
| 409 | printk(BIOS_SPEW, " Vertical stretch\n"); |
| 410 | } |
| 411 | |
| 412 | if (x[16] & 0x0f) |
| 413 | has_valid_range_descriptor = 0; |
| 414 | |
| 415 | if (x[17]) |
| 416 | printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]); |
| 417 | else |
| 418 | warning_zero_preferred_refresh = 1; |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | * Slightly weird to return a global, but I've never seen any |
| 423 | * EDID block wth two range descriptors, so it's harmless. |
| 424 | */ |
| 425 | return 0; |
| 426 | } |
| 427 | case 0xFE: |
| 428 | /* |
| 429 | * TODO: Two of these in a row, in the third and fourth slots, |
| 430 | * seems to be specified by SPWG: http://www.spwg.org/ |
| 431 | */ |
| 432 | printk(BIOS_SPEW, "ASCII string: %s\n", |
| 433 | extract_string(x + 5, &has_valid_string_termination, 13)); |
| 434 | return 0; |
| 435 | case 0xFF: |
| 436 | printk(BIOS_SPEW, "Serial number: %s\n", |
| 437 | extract_string(x + 5, &has_valid_string_termination, 13)); |
| 438 | return 0; |
| 439 | default: |
| 440 | printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]); |
| 441 | return 0; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if (seen_non_detailed_descriptor && !in_extension) { |
| 446 | has_valid_descriptor_ordering = 0; |
| 447 | } |
| 448 | |
| 449 | if (! did_detailed_timing){ |
Furquan Shaikh | 6b19071 | 2013-07-22 16:18:31 -0700 | [diff] [blame] | 450 | /* Edid contains pixel clock in terms of 10KHz */ |
| 451 | out->pixel_clock = (x[0] + (x[1] << 8)) * 10; |
Furquan Shaikh | aa04ed6 | 2013-07-23 15:53:02 -0700 | [diff] [blame] | 452 | out->x_mm = (x[12] + ((x[14] & 0xF0) << 4)); |
| 453 | out->y_mm = (x[13] + ((x[14] & 0x0F) << 8)); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 454 | out->ha = (x[2] + ((x[4] & 0xF0) << 4)); |
| 455 | out->hbl = (x[3] + ((x[4] & 0x0F) << 8)); |
| 456 | out->hso = (x[8] + ((x[11] & 0xC0) << 2)); |
| 457 | out->hspw = (x[9] + ((x[11] & 0x30) << 4)); |
| 458 | out->hborder = x[15]; |
| 459 | out->va = (x[5] + ((x[7] & 0xF0) << 4)); |
| 460 | out->vbl = (x[6] + ((x[7] & 0x0F) << 8)); |
| 461 | out->vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2)); |
| 462 | out->vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4)); |
| 463 | out->vborder = x[16]; |
Ronald G. Minnich | 4c5b161 | 2013-06-28 14:33:30 -0700 | [diff] [blame] | 464 | /* set up some reasonable defaults for payloads. |
| 465 | * We observe that most modern chipsets we work with |
| 466 | * tend to support rgb888 without regard to the |
| 467 | * panel bits per color or other settings. The rgb888 |
| 468 | * is a convenient layout for software because |
| 469 | * it avoids the messy bit stuffing of rgb565 or rgb444. |
| 470 | * It makes a reasonable trade of memory for speed. |
| 471 | * So, set up the default for |
| 472 | * 32 bits per pixel |
| 473 | * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries) |
| 474 | * The mainboard can modify these if needed, though |
| 475 | * we have yet to see a case where that will happen. |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 476 | * The existing ARM mainboards don't even call this function |
| 477 | * so this will not affect them. |
Ronald G. Minnich | 4c5b161 | 2013-06-28 14:33:30 -0700 | [diff] [blame] | 478 | */ |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 479 | out->framebuffer_bits_per_pixel = 32; |
Furquan Shaikh | d0a81f7 | 2013-07-30 12:41:08 -0700 | [diff] [blame] | 480 | |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 481 | out->x_resolution = ALIGN(out->ha * |
| 482 | ((out->framebuffer_bits_per_pixel + 7) / 8), |
| 483 | 64) / (out->framebuffer_bits_per_pixel/8); |
Ronald G. Minnich | 4c5b161 | 2013-06-28 14:33:30 -0700 | [diff] [blame] | 484 | out->y_resolution = out->va; |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 485 | out->bytes_per_line = ALIGN(out->ha * |
| 486 | ((out->framebuffer_bits_per_pixel + 7)/8), |
| 487 | 64); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 488 | printk(BIOS_SPEW, "Did detailed timing\n"); |
| 489 | } |
| 490 | did_detailed_timing = 1; |
| 491 | switch ((x[17] & 0x18) >> 3) { |
| 492 | case 0x00: |
| 493 | out->syncmethod = " analog composite"; |
| 494 | break; |
| 495 | case 0x01: |
| 496 | out->syncmethod = " bipolar analog composite"; |
| 497 | break; |
| 498 | case 0x02: |
| 499 | out->syncmethod = " digital composite"; |
| 500 | break; |
| 501 | case 0x03: |
| 502 | out->syncmethod = ""; |
| 503 | break; |
| 504 | } |
| 505 | out->pvsync = (x[17] & (1 << 2)) ? '+' : '-'; |
| 506 | out->phsync = (x[17] & (1 << 1)) ? '+' : '-'; |
| 507 | switch (x[17] & 0x61) { |
| 508 | case 0x20: |
| 509 | out->stereo = "field sequential L/R"; |
| 510 | break; |
| 511 | case 0x40: |
| 512 | out->stereo = "field sequential R/L"; |
| 513 | break; |
| 514 | case 0x21: |
| 515 | out->stereo = "interleaved right even"; |
| 516 | break; |
| 517 | case 0x41: |
| 518 | out->stereo = "interleaved left even"; |
| 519 | break; |
| 520 | case 0x60: |
| 521 | out->stereo = "four way interleaved"; |
| 522 | break; |
| 523 | case 0x61: |
| 524 | out->stereo = "side by side interleaved"; |
| 525 | break; |
| 526 | default: |
| 527 | out->stereo = ""; |
| 528 | break; |
| 529 | } |
| 530 | |
Furquan Shaikh | 6b19071 | 2013-07-22 16:18:31 -0700 | [diff] [blame] | 531 | printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n" |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 532 | " %04x %04x %04x %04x hborder %x\n" |
| 533 | " %04x %04x %04x %04x vborder %x\n" |
| 534 | " %chsync %cvsync%s%s %s\n", |
Furquan Shaikh | 6b19071 | 2013-07-22 16:18:31 -0700 | [diff] [blame] | 535 | out->pixel_clock, |
Furquan Shaikh | aa04ed6 | 2013-07-23 15:53:02 -0700 | [diff] [blame] | 536 | out->x_mm, |
| 537 | out->y_mm, |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 538 | out->ha, out->ha + out->hso, out->ha + out->hso + out->hspw, |
| 539 | out->ha + out->hbl, out->hborder, |
| 540 | out->va, out->va + out->vso, out->va + out->vso + out->vspw, |
| 541 | out->va + out->vbl, out->vborder, |
| 542 | out->phsync, out->pvsync, |
| 543 | out->syncmethod, x[17] & 0x80 ?" interlaced" : "", |
| 544 | out->stereo |
| 545 | ); |
| 546 | return 1; |
| 547 | } |
| 548 | |
| 549 | static int |
| 550 | do_checksum(unsigned char *x) |
| 551 | { |
Patrick Georgi | d01ed75 | 2014-01-18 16:56:36 +0100 | [diff] [blame] | 552 | printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 553 | { |
| 554 | unsigned char sum = 0; |
| 555 | int i; |
| 556 | for (i = 0; i < 128; i++) |
| 557 | sum += x[i]; |
| 558 | if (sum) { |
Patrick Georgi | d01ed75 | 2014-01-18 16:56:36 +0100 | [diff] [blame] | 559 | printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum)); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 560 | has_valid_checksum = 0; |
| 561 | } else { |
| 562 | has_valid_checksum = 1; |
| 563 | printk(BIOS_SPEW, " (valid)"); |
| 564 | } |
| 565 | } |
| 566 | printk(BIOS_SPEW, "\n"); |
| 567 | return has_valid_checksum; |
| 568 | } |
| 569 | |
| 570 | /* CEA extension */ |
| 571 | |
| 572 | static const char * |
| 573 | audio_format(unsigned char x) |
| 574 | { |
| 575 | switch (x) { |
| 576 | case 0: return "RESERVED"; |
| 577 | case 1: return "Linear PCM"; |
| 578 | case 2: return "AC-3"; |
| 579 | case 3: return "MPEG 1 (Layers 1 & 2)"; |
| 580 | case 4: return "MPEG 1 Layer 3 (MP3)"; |
| 581 | case 5: return "MPEG2 (multichannel)"; |
| 582 | case 6: return "AAC"; |
| 583 | case 7: return "DTS"; |
| 584 | case 8: return "ATRAC"; |
| 585 | case 9: return "One Bit Audio"; |
| 586 | case 10: return "Dolby Digital+"; |
| 587 | case 11: return "DTS-HD"; |
| 588 | case 12: return "MAT (MLP)"; |
| 589 | case 13: return "DST"; |
| 590 | case 14: return "WMA Pro"; |
| 591 | case 15: return "RESERVED"; |
| 592 | } |
| 593 | return "BROKEN"; /* can't happen */ |
| 594 | } |
| 595 | |
| 596 | static void |
| 597 | cea_audio_block(unsigned char *x) |
| 598 | { |
| 599 | int i, format; |
| 600 | int length = x[0] & 0x1f; |
| 601 | |
| 602 | if (length % 3) { |
| 603 | printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length); |
| 604 | /* XXX non-conformant */ |
| 605 | return; |
| 606 | } |
| 607 | |
| 608 | for (i = 1; i < length; i += 3) { |
| 609 | format = (x[i] & 0x78) >> 3; |
| 610 | printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format), |
| 611 | x[i] & 0x07); |
| 612 | printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n", |
| 613 | (x[i+1] & 0x40) ? " 192" : "", |
| 614 | (x[i+1] & 0x20) ? " 176.4" : "", |
| 615 | (x[i+1] & 0x10) ? " 96" : "", |
| 616 | (x[i+1] & 0x08) ? " 88.2" : "", |
| 617 | (x[i+1] & 0x04) ? " 48" : "", |
| 618 | (x[i+1] & 0x02) ? " 44.1" : "", |
| 619 | (x[i+1] & 0x01) ? " 32" : ""); |
| 620 | if (format == 1) { |
| 621 | printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n", |
| 622 | (x[2] & 0x04) ? " 24" : "", |
| 623 | (x[2] & 0x02) ? " 20" : "", |
| 624 | (x[2] & 0x01) ? " 16" : ""); |
| 625 | } else if (format <= 8) { |
| 626 | printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8); |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | static void |
| 632 | cea_video_block(unsigned char *x) |
| 633 | { |
| 634 | int i; |
| 635 | int length = x[0] & 0x1f; |
| 636 | |
| 637 | for (i = 1; i < length; i++) |
| 638 | printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f, |
| 639 | x[i] & 0x80 ? "(native)" : ""); |
| 640 | } |
| 641 | |
| 642 | static void |
| 643 | cea_hdmi_block(struct edid *out, unsigned char *x) |
| 644 | { |
| 645 | int length = x[0] & 0x1f; |
| 646 | |
| 647 | printk(BIOS_SPEW, " (HDMI)\n"); |
| 648 | printk(BIOS_SPEW, |
| 649 | " Source physical address %d.%d.%d.%d\n", |
| 650 | x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f); |
| 651 | |
| 652 | if (length > 5) { |
| 653 | if (x[6] & 0x80) |
| 654 | printk(BIOS_SPEW, " Supports_AI\n"); |
| 655 | if (x[6] & 0x40) |
| 656 | printk(BIOS_SPEW, " DC_48bit\n"); |
| 657 | if (x[6] & 0x20) |
| 658 | printk(BIOS_SPEW, " DC_36bit\n"); |
| 659 | if (x[6] & 0x10) |
| 660 | printk(BIOS_SPEW, " DC_30bit\n"); |
| 661 | if (x[6] & 0x08) |
| 662 | printk(BIOS_SPEW, " DC_Y444\n"); |
| 663 | /* two reserved */ |
| 664 | if (x[6] & 0x01) |
| 665 | printk(BIOS_SPEW, " DVI_Dual\n"); |
| 666 | } |
| 667 | |
| 668 | if (length > 6) |
| 669 | printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5); |
| 670 | |
| 671 | /* XXX the walk here is really ugly, and needs to be length-checked */ |
| 672 | if (length > 7) { |
| 673 | int b = 0; |
| 674 | |
| 675 | if (x[8] & 0x80) { |
| 676 | printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]); |
| 677 | printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]); |
| 678 | b += 2; |
| 679 | } |
| 680 | |
| 681 | if (x[8] & 0x40) { |
| 682 | printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]); |
| 683 | printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]); |
| 684 | b += 2; |
| 685 | } |
| 686 | |
| 687 | if (x[8] & 0x20) { |
| 688 | int mask = 0, formats = 0; |
| 689 | int len_xx, len_3d; |
| 690 | printk(BIOS_SPEW, " Extended HDMI video details:\n"); |
| 691 | if (x[9 + b] & 0x80) |
| 692 | printk(BIOS_SPEW, " 3D present\n"); |
| 693 | if ((x[9 + b] & 0x60) == 0x20) { |
| 694 | printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n"); |
| 695 | formats = 1; |
| 696 | } |
| 697 | if ((x[9 + b] & 0x60) == 0x40) { |
| 698 | printk(BIOS_SPEW, " 3D-capable-VIC mask present\n"); |
| 699 | formats = 1; |
| 700 | mask = 1; |
| 701 | } |
| 702 | switch (x[9 + b] & 0x18) { |
| 703 | case 0x00: break; |
| 704 | case 0x08: |
| 705 | printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n"); |
| 706 | break; |
| 707 | case 0x10: |
| 708 | printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n"); |
| 709 | break; |
| 710 | case 0x18: |
| 711 | printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n"); |
| 712 | break; |
| 713 | } |
| 714 | len_xx = (x[10 + b] & 0xe0) >> 5; |
| 715 | len_3d = (x[10 + b] & 0x1f) >> 0; |
| 716 | b += 2; |
| 717 | |
| 718 | if (len_xx) { |
| 719 | printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly" |
| 720 | " document\n", len_xx); |
| 721 | b += len_xx; |
| 722 | } |
| 723 | |
| 724 | if (len_3d) { |
| 725 | if (formats) { |
| 726 | if (x[9 + b] & 0x01) |
| 727 | printk(BIOS_SPEW, " Side-by-side 3D supported\n"); |
| 728 | if (x[10 + b] & 0x40) |
| 729 | printk(BIOS_SPEW, " Top-and-bottom 3D supported\n"); |
| 730 | if (x[10 + b] & 0x01) |
| 731 | printk(BIOS_SPEW, " Frame-packing 3D supported\n"); |
| 732 | b += 2; |
| 733 | } |
| 734 | if (mask) { |
| 735 | int i; |
| 736 | printk(BIOS_SPEW, " 3D VIC indices:"); |
| 737 | /* worst bit ordering ever */ |
| 738 | for (i = 0; i < 8; i++) |
| 739 | if (x[10 + b] & (1 << i)) |
| 740 | printk(BIOS_SPEW, " %d", i); |
| 741 | for (i = 0; i < 8; i++) |
| 742 | if (x[9 + b] & (1 << i)) |
| 743 | printk(BIOS_SPEW, " %d", i + 8); |
| 744 | printk(BIOS_SPEW, "\n"); |
| 745 | b += 2; |
| 746 | } |
| 747 | |
| 748 | /* |
| 749 | * XXX list of nibbles: |
| 750 | * 2D_VIC_Order_X |
| 751 | * 3D_Structure_X |
| 752 | * (optionally: 3D_Detail_X and reserved) |
| 753 | */ |
| 754 | } |
| 755 | |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | static void |
| 761 | cea_block(struct edid *out, unsigned char *x) |
| 762 | { |
| 763 | unsigned int oui; |
| 764 | |
| 765 | switch ((x[0] & 0xe0) >> 5) { |
| 766 | case 0x01: |
| 767 | printk(BIOS_SPEW, " Audio data block\n"); |
| 768 | cea_audio_block(x); |
| 769 | break; |
| 770 | case 0x02: |
| 771 | printk(BIOS_SPEW, " Video data block\n"); |
| 772 | cea_video_block(x); |
| 773 | break; |
| 774 | case 0x03: |
| 775 | /* yes really, endianness lols */ |
| 776 | oui = (x[3] << 16) + (x[2] << 8) + x[1]; |
| 777 | printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui); |
| 778 | if (oui == 0x000c03) |
| 779 | cea_hdmi_block(out, x); |
| 780 | else |
| 781 | printk(BIOS_SPEW, "\n"); |
| 782 | break; |
| 783 | case 0x04: |
| 784 | printk(BIOS_SPEW, " Speaker allocation data block\n"); |
| 785 | break; |
| 786 | case 0x05: |
| 787 | printk(BIOS_SPEW, " VESA DTC data block\n"); |
| 788 | break; |
| 789 | case 0x07: |
| 790 | printk(BIOS_SPEW, " Extended tag: "); |
| 791 | switch (x[1]) { |
| 792 | case 0x00: |
| 793 | printk(BIOS_SPEW, "video capability data block\n"); |
| 794 | break; |
| 795 | case 0x01: |
| 796 | printk(BIOS_SPEW, "vendor-specific video data block\n"); |
| 797 | break; |
| 798 | case 0x02: |
| 799 | printk(BIOS_SPEW, "VESA video display device information data block\n"); |
| 800 | break; |
| 801 | case 0x03: |
| 802 | printk(BIOS_SPEW, "VESA video data block\n"); |
| 803 | break; |
| 804 | case 0x04: |
| 805 | printk(BIOS_SPEW, "HDMI video data block\n"); |
| 806 | break; |
| 807 | case 0x05: |
| 808 | printk(BIOS_SPEW, "Colorimetry data block\n"); |
| 809 | break; |
| 810 | case 0x10: |
| 811 | printk(BIOS_SPEW, "CEA miscellaneous audio fields\n"); |
| 812 | break; |
| 813 | case 0x11: |
| 814 | printk(BIOS_SPEW, "Vendor-specific audio data block\n"); |
| 815 | break; |
| 816 | case 0x12: |
| 817 | printk(BIOS_SPEW, "HDMI audio data block\n"); |
| 818 | break; |
| 819 | default: |
| 820 | if (x[1] >= 6 && x[1] <= 15) |
| 821 | printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]); |
| 822 | else if (x[1] >= 19 && x[1] <= 31) |
| 823 | printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]); |
| 824 | else |
| 825 | printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]); |
| 826 | break; |
| 827 | } |
| 828 | break; |
| 829 | default: |
| 830 | { |
| 831 | int tag = (*x & 0xe0) >> 5; |
| 832 | int length = *x & 0x1f; |
| 833 | printk(BIOS_SPEW, |
| 834 | " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x); |
| 835 | break; |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static int |
| 841 | parse_cea(struct edid *out, unsigned char *x) |
| 842 | { |
| 843 | int ret = 0; |
| 844 | int version = x[1]; |
| 845 | int offset = x[2]; |
| 846 | unsigned char *detailed; |
| 847 | |
| 848 | if (version >= 1) do { |
| 849 | if (version == 1 && x[3] != 0) |
| 850 | ret = 1; |
| 851 | |
| 852 | if (offset < 4) |
| 853 | break; |
| 854 | |
| 855 | if (version < 3) { |
| 856 | printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8); |
| 857 | if (offset - 4 > 0) |
| 858 | /* do stuff */ ; |
| 859 | } else if (version == 3) { |
| 860 | int i; |
| 861 | printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4); |
| 862 | for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) { |
| 863 | cea_block(out, x + i); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | if (version >= 2) { |
| 868 | if (x[3] & 0x80) |
| 869 | printk(BIOS_SPEW, "Underscans PC formats by default\n"); |
| 870 | if (x[3] & 0x40) |
| 871 | printk(BIOS_SPEW, "Basic audio support\n"); |
| 872 | if (x[3] & 0x20) |
| 873 | printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n"); |
| 874 | if (x[3] & 0x10) |
| 875 | printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n"); |
| 876 | printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f); |
| 877 | } |
| 878 | |
| 879 | for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18) |
| 880 | if (detailed[0]) |
| 881 | detailed_block(out, detailed, 1); |
| 882 | } while (0); |
| 883 | |
| 884 | do_checksum(x); |
| 885 | |
| 886 | return ret; |
| 887 | } |
| 888 | |
| 889 | /* generic extension code */ |
| 890 | |
| 891 | static void |
| 892 | extension_version(struct edid *out, unsigned char *x) |
| 893 | { |
| 894 | printk(BIOS_SPEW, "Extension version: %d\n", x[1]); |
| 895 | } |
| 896 | |
| 897 | static int |
| 898 | parse_extension(struct edid *out, unsigned char *x) |
| 899 | { |
| 900 | int conformant_extension = 0; |
| 901 | printk(BIOS_SPEW, "\n"); |
| 902 | |
| 903 | switch(x[0]) { |
| 904 | case 0x02: |
| 905 | printk(BIOS_SPEW, "CEA extension block\n"); |
| 906 | extension_version(out, x); |
| 907 | conformant_extension = parse_cea(out, x); |
| 908 | break; |
| 909 | case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break; |
| 910 | case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break; |
| 911 | case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break; |
| 912 | case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break; |
| 913 | case 0xF0: printk(BIOS_SPEW, "Block map\n"); break; |
Patrick Georgi | e211bd9 | 2014-08-09 17:16:24 +0200 | [diff] [blame] | 914 | case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n"); break; |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 915 | default: |
| 916 | printk(BIOS_SPEW, "Unknown extension block\n"); |
| 917 | break; |
| 918 | } |
| 919 | |
| 920 | printk(BIOS_SPEW, "\n"); |
| 921 | |
| 922 | return conformant_extension; |
| 923 | } |
| 924 | |
| 925 | static const struct { |
| 926 | int x, y, refresh; |
| 927 | } established_timings[] = { |
| 928 | /* 0x23 bit 7 - 0 */ |
| 929 | {720, 400, 70}, |
| 930 | {720, 400, 88}, |
| 931 | {640, 480, 60}, |
| 932 | {640, 480, 67}, |
| 933 | {640, 480, 72}, |
| 934 | {640, 480, 75}, |
| 935 | {800, 600, 56}, |
| 936 | {800, 600, 60}, |
| 937 | /* 0x24 bit 7 - 0 */ |
| 938 | {800, 600, 72}, |
| 939 | {800, 600, 75}, |
| 940 | {832, 624, 75}, |
| 941 | {1280, 768, 87}, |
| 942 | {1024, 768, 60}, |
| 943 | {1024, 768, 70}, |
| 944 | {1024, 768, 75}, |
| 945 | {1280, 1024, 75}, |
| 946 | /* 0x25 bit 7*/ |
| 947 | {1152, 870, 75}, |
| 948 | }; |
| 949 | |
| 950 | static void print_subsection(const char *name, unsigned char *edid, int start, |
| 951 | int end) |
| 952 | { |
| 953 | int i; |
| 954 | |
| 955 | printk(BIOS_SPEW, "%s:", name); |
| 956 | for (i = strlen(name); i < 15; i++) |
| 957 | printk(BIOS_SPEW, " "); |
| 958 | for (i = start; i <= end; i++) |
| 959 | printk(BIOS_SPEW, " %02x", edid[i]); |
| 960 | printk(BIOS_SPEW, "\n"); |
| 961 | } |
| 962 | |
| 963 | static void dump_breakdown(unsigned char *edid) |
| 964 | { |
| 965 | printk(BIOS_SPEW, "Extracted contents:\n"); |
| 966 | print_subsection("header", edid, 0, 7); |
| 967 | print_subsection("serial number", edid, 8, 17); |
| 968 | print_subsection("version", edid,18, 19); |
| 969 | print_subsection("basic params", edid, 20, 24); |
| 970 | print_subsection("chroma info", edid, 25, 34); |
| 971 | print_subsection("established", edid, 35, 37); |
| 972 | print_subsection("standard", edid, 38, 53); |
| 973 | print_subsection("descriptor 1", edid, 54, 71); |
| 974 | print_subsection("descriptor 2", edid, 72, 89); |
| 975 | print_subsection("descriptor 3", edid, 90, 107); |
| 976 | print_subsection("descriptor 4", edid, 108, 125); |
| 977 | print_subsection("extensions", edid, 126, 126); |
| 978 | print_subsection("checksum", edid, 127, 127); |
| 979 | printk(BIOS_SPEW, "\n"); |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | * Given a raw edid bloc, decode it into a form |
| 984 | * that other parts of coreboot can use -- mainly |
| 985 | * graphics bringup functions. The raw block is |
| 986 | * required to be 128 bytes long, per the standard, |
| 987 | * but we have no way of checking this minimum length. |
| 988 | * We accept what we are given. |
| 989 | */ |
| 990 | int decode_edid(unsigned char *edid, int size, struct edid *out) |
| 991 | { |
| 992 | int analog, i; |
| 993 | |
| 994 | dump_breakdown(edid); |
| 995 | |
| 996 | if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) { |
| 997 | printk(BIOS_SPEW, "No header found\n"); |
| 998 | return 1; |
| 999 | } |
| 1000 | memset(out, 0, sizeof(*out)); |
| 1001 | manufacturer_name(out, edid + 0x08); |
| 1002 | out->model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)); |
| 1003 | out->serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8) |
| 1004 | + (edid[0x0E] << 16) + (edid[0x0F] << 24)); |
| 1005 | |
| 1006 | printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n", |
| 1007 | out->manuf_name, |
| 1008 | (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)), |
| 1009 | (unsigned int)(edid[0x0C] + (edid[0x0D] << 8) |
| 1010 | + (edid[0x0E] << 16) + (edid[0x0F] << 24))); |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1011 | /* XXX need manufacturer ID table */ |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1012 | |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1013 | if (edid[0x10] < 55 || edid[0x10] == 0xff) { |
| 1014 | has_valid_week = 1; |
| 1015 | if (edid[0x11] > 0x0f) { |
| 1016 | if (edid[0x10] == 0xff) { |
| 1017 | has_valid_year = 1; |
| 1018 | printk(BIOS_SPEW, "Made week %hhu of model year %hhu\n", edid[0x10], |
| 1019 | edid[0x11]); |
| 1020 | out->week = edid[0x10]; |
| 1021 | out->year = edid[0x11]; |
| 1022 | } else { |
| 1023 | /* we know it's at least 2013, when this code was written */ |
| 1024 | if (edid[0x11] + 90 <= 2013) { |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1025 | has_valid_year = 1; |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1026 | printk(BIOS_SPEW, "Made week %hhu of %d\n", |
| 1027 | edid[0x10], edid[0x11] + 1990); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1028 | out->week = edid[0x10]; |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1029 | out->year = edid[0x11] + 1990; |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1030 | } |
| 1031 | } |
| 1032 | } |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1033 | } |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1034 | |
| 1035 | |
Patrick Georgi | d01ed75 | 2014-01-18 16:56:36 +0100 | [diff] [blame] | 1036 | printk(BIOS_SPEW, "EDID version: %hhu.%hhu\n", edid[0x12], edid[0x13]); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1037 | out->version[0] = edid[0x12]; |
| 1038 | out->version[1] = edid[0x13]; |
| 1039 | |
| 1040 | if (edid[0x12] == 1) { |
| 1041 | if (edid[0x13] > 4) { |
| 1042 | printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n"); |
| 1043 | edid[0x13] = 4; |
| 1044 | } |
| 1045 | switch (edid[0x13]) { |
| 1046 | case 4: |
| 1047 | claims_one_point_four = 1; |
| 1048 | case 3: |
| 1049 | claims_one_point_three = 1; |
| 1050 | case 2: |
| 1051 | claims_one_point_two = 1; |
| 1052 | default: |
| 1053 | break; |
| 1054 | } |
| 1055 | claims_one_point_oh = 1; |
| 1056 | } |
| 1057 | |
| 1058 | /* display section */ |
| 1059 | |
| 1060 | if (edid[0x14] & 0x80) { |
| 1061 | int conformance_mask; |
| 1062 | analog = 0; |
| 1063 | printk(BIOS_SPEW, "Digital display\n"); |
| 1064 | if (claims_one_point_four) { |
| 1065 | conformance_mask = 0; |
| 1066 | if ((edid[0x14] & 0x70) == 0x00) |
| 1067 | printk(BIOS_SPEW, "Color depth is undefined\n"); |
| 1068 | else if ((edid[0x14] & 0x70) == 0x70) |
| 1069 | nonconformant_digital_display = 1; |
| 1070 | else |
| 1071 | printk(BIOS_SPEW, "%d bits per primary color channel\n", |
| 1072 | ((edid[0x14] & 0x70) >> 3) + 4); |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 1073 | out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4; |
| 1074 | out->panel_bits_per_pixel = 3*out->panel_bits_per_color; |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1075 | |
| 1076 | switch (edid[0x14] & 0x0f) { |
| 1077 | case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break; |
| 1078 | case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break; |
| 1079 | case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break; |
| 1080 | case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break; |
| 1081 | case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break; |
| 1082 | case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break; |
| 1083 | default: |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1084 | nonconformant_digital_display = 1; |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1085 | } |
| 1086 | out->type = edid[0x14] & 0x0f; |
| 1087 | } else if (claims_one_point_two) { |
| 1088 | conformance_mask = 0x7E; |
| 1089 | if (edid[0x14] & 0x01) { |
| 1090 | printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n"); |
| 1091 | } |
| 1092 | } else |
| 1093 | conformance_mask = 0x7F; |
| 1094 | |
| 1095 | if (!nonconformant_digital_display) |
| 1096 | nonconformant_digital_display = edid[0x14] & conformance_mask; |
| 1097 | out->nonconformant = nonconformant_digital_display; |
| 1098 | } else { |
| 1099 | analog = 1; |
| 1100 | int voltage = (edid[0x14] & 0x60) >> 5; |
| 1101 | int sync = (edid[0x14] & 0x0F); |
| 1102 | out->voltage = voltage; |
| 1103 | out->sync = sync; |
| 1104 | |
| 1105 | printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n", |
| 1106 | voltage == 3 ? "0.7/0.7" : |
| 1107 | voltage == 2 ? "1.0/0.4" : |
| 1108 | voltage == 1 ? "0.714/0.286" : |
| 1109 | "0.7/0.3"); |
| 1110 | |
| 1111 | if (claims_one_point_four) { |
| 1112 | if (edid[0x14] & 0x10) |
| 1113 | printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n"); |
| 1114 | else |
| 1115 | printk(BIOS_SPEW, "Blank level equals black level\n"); |
| 1116 | } else if (edid[0x14] & 0x10) { |
| 1117 | /* |
| 1118 | * XXX this is just the X text. 1.3 says "if set, display expects |
| 1119 | * a blank-to-black setup or pedestal per appropriate Signal |
| 1120 | * Level Standard". Whatever _that_ means. |
| 1121 | */ |
| 1122 | printk(BIOS_SPEW, "Configurable signal levels\n"); |
| 1123 | } |
| 1124 | |
| 1125 | printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "", |
| 1126 | sync & 0x04 ? "Composite " : "", |
| 1127 | sync & 0x02 ? "SyncOnGreen " : "", |
| 1128 | sync & 0x01 ? "Serration " : ""); |
| 1129 | } |
| 1130 | |
| 1131 | |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1132 | if (edid[0x15] && edid[0x16]) { |
| 1133 | printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n", |
| 1134 | edid[0x15], edid[0x16]); |
| 1135 | out->xsize_cm = edid[0x15]; |
| 1136 | out->ysize_cm = edid[0x16]; |
| 1137 | } else if (claims_one_point_four && (edid[0x15] || edid[0x16])) { |
| 1138 | if (edid[0x15]) { |
| 1139 | printk(BIOS_SPEW, "Aspect ratio is %f (landscape)\n", |
| 1140 | 100.0/(edid[0x16] + 99)); |
| 1141 | /* truncated to integer %. We try to avoid floating point */ |
| 1142 | out->aspect_landscape = 10000 /(edid[0x16] + 99); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1143 | } else { |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1144 | printk(BIOS_SPEW, "Aspect ratio is %f (portrait)\n", |
| 1145 | 100.0/(edid[0x15] + 99)); |
| 1146 | out->aspect_portrait = 10000 /(edid[0x16] + 99); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1147 | } |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1148 | } else { |
| 1149 | /* Either or both can be zero for 1.3 and before */ |
| 1150 | printk(BIOS_SPEW, "Image size is variable\n"); |
| 1151 | } |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1152 | |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1153 | if (edid[0x17] == 0xff) { |
| 1154 | if (claims_one_point_four) |
| 1155 | printk(BIOS_SPEW, "Gamma is defined in an extension block\n"); |
| 1156 | else |
| 1157 | /* XXX Technically 1.3 doesn't say this... */ |
| 1158 | printk(BIOS_SPEW, "Gamma: 1.0\n"); |
| 1159 | } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100))); |
| 1160 | printk(BIOS_SPEW, "Check DPMS levels\n"); |
| 1161 | if (edid[0x18] & 0xE0) { |
| 1162 | printk(BIOS_SPEW, "DPMS levels:"); |
| 1163 | if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby"); |
| 1164 | if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend"); |
| 1165 | if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off"); |
| 1166 | printk(BIOS_SPEW, "\n"); |
| 1167 | } |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1168 | |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1169 | /* FIXME: this is from 1.4 spec, check earlier */ |
| 1170 | if (analog) { |
| 1171 | switch (edid[0x18] & 0x18) { |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1172 | case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break; |
| 1173 | case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break; |
| 1174 | case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break; |
| 1175 | case 0x18: printk(BIOS_SPEW, "Undefined display color type\n"); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1176 | } |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1177 | } else { |
| 1178 | printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4"); |
| 1179 | if (edid[0x18] & 0x10) |
| 1180 | printk(BIOS_SPEW, ", YCrCb 4:4:4"); |
| 1181 | if (edid[0x18] & 0x08) |
| 1182 | printk(BIOS_SPEW, ", YCrCb 4:2:2"); |
| 1183 | printk(BIOS_SPEW, "\n"); |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1186 | if (edid[0x18] & 0x04) |
| 1187 | printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n"); |
| 1188 | if (edid[0x18] & 0x02) { |
| 1189 | printk(BIOS_SPEW, "First detailed timing is preferred timing\n"); |
| 1190 | has_preferred_timing = 1; |
| 1191 | } |
| 1192 | if (edid[0x18] & 0x01) |
| 1193 | printk(BIOS_SPEW, "Supports GTF timings within operating range\n"); |
| 1194 | |
| 1195 | /* XXX color section */ |
| 1196 | |
| 1197 | printk(BIOS_SPEW, "Established timings supported:\n"); |
| 1198 | /* it's not yet clear we want all this stuff in the edid struct. |
| 1199 | * Let's wait. |
| 1200 | */ |
| 1201 | for (i = 0; i < 17; i++) { |
| 1202 | if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) { |
| 1203 | printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x, |
| 1204 | established_timings[i].y, established_timings[i].refresh); |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | printk(BIOS_SPEW, "Standard timings supported:\n"); |
| 1209 | for (i = 0; i < 8; i++) { |
| 1210 | uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1]; |
| 1211 | unsigned int x, y = 0, refresh; |
| 1212 | |
| 1213 | if (b1 == 0x01 && b2 == 0x01) |
| 1214 | continue; |
| 1215 | |
| 1216 | if (b1 == 0) { |
| 1217 | printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n"); |
| 1218 | continue; |
| 1219 | } |
| 1220 | x = (b1 + 31) * 8; |
| 1221 | switch ((b2 >> 6) & 0x3) { |
| 1222 | case 0x00: |
| 1223 | if (claims_one_point_three) |
| 1224 | y = x * 10 / 16; |
| 1225 | else |
| 1226 | y = x; |
| 1227 | break; |
| 1228 | case 0x01: |
| 1229 | y = x * 3 / 4; |
| 1230 | break; |
| 1231 | case 0x02: |
| 1232 | y = x * 4 / 5; |
| 1233 | break; |
| 1234 | case 0x03: |
| 1235 | y = x * 9 / 16; |
| 1236 | break; |
| 1237 | } |
| 1238 | refresh = 60 + (b2 & 0x3f); |
| 1239 | |
| 1240 | printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh); |
| 1241 | } |
| 1242 | |
| 1243 | /* detailed timings */ |
| 1244 | printk(BIOS_SPEW, "Detailed timings\n"); |
| 1245 | has_valid_detailed_blocks = detailed_block(out, edid + 0x36, 0); |
| 1246 | if (has_preferred_timing && !did_detailed_timing) |
| 1247 | has_preferred_timing = 0; /* not really accurate... */ |
| 1248 | has_valid_detailed_blocks &= detailed_block(out, edid + 0x48, 0); |
| 1249 | has_valid_detailed_blocks &= detailed_block(out, edid + 0x5A, 0); |
| 1250 | has_valid_detailed_blocks &= detailed_block(out, edid + 0x6C, 0); |
| 1251 | |
| 1252 | /* check this, 1.4 verification guide says otherwise */ |
| 1253 | if (edid[0x7e]) { |
| 1254 | printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]); |
| 1255 | /* 2 is impossible because of the block map */ |
| 1256 | if (edid[0x7e] != 2) |
| 1257 | has_valid_extension_count = 1; |
| 1258 | } else { |
| 1259 | has_valid_extension_count = 1; |
| 1260 | } |
| 1261 | |
| 1262 | printk(BIOS_SPEW, "Checksum\n"); |
| 1263 | do_checksum(edid); |
Hung-Te Lin | 7944581 | 2014-04-03 18:35:58 +0800 | [diff] [blame] | 1264 | |
| 1265 | /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in |
| 1266 | * the extension parsing loop below. Since v2.0 was quickly deprecated |
| 1267 | * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore |
| 1268 | * that case now and can fix it when we need to use a real 2.0 panel. |
| 1269 | */ |
| 1270 | for(i = 128; i < size; i += 128) |
| 1271 | nonconformant_extension += parse_extension(out, &edid[i]); |
Hung-Te Lin | fc0d244 | 2014-04-03 18:33:01 +0800 | [diff] [blame] | 1272 | /* |
| 1273 | * x = edid; |
| 1274 | * for (edid_lines /= 8; edid_lines > 1; edid_lines--) { |
| 1275 | * x += 128; |
| 1276 | * nonconformant_extension += parse_extension(x); |
| 1277 | * } |
| 1278 | */ |
| 1279 | |
| 1280 | if (claims_one_point_three) { |
| 1281 | if (nonconformant_digital_display || |
| 1282 | !has_valid_string_termination || |
| 1283 | !has_valid_descriptor_pad || |
| 1284 | !has_name_descriptor || |
| 1285 | !name_descriptor_terminated || |
| 1286 | !has_preferred_timing || |
| 1287 | !has_range_descriptor) |
| 1288 | conformant = 0; |
| 1289 | if (!conformant) |
| 1290 | printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n"); |
| 1291 | if (nonconformant_digital_display) |
| 1292 | printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n", |
| 1293 | nonconformant_digital_display); |
| 1294 | if (!has_name_descriptor) |
| 1295 | printk(BIOS_ERR, "\tMissing name descriptor\n"); |
| 1296 | else if (!name_descriptor_terminated) |
| 1297 | printk(BIOS_ERR, "\tName descriptor not terminated with a newline\n"); |
| 1298 | if (!has_preferred_timing) |
| 1299 | printk(BIOS_ERR, "\tMissing preferred timing\n"); |
| 1300 | if (!has_range_descriptor) |
| 1301 | printk(BIOS_ERR, "\tMissing monitor ranges\n"); |
| 1302 | if (!has_valid_descriptor_pad) /* Might be more than just 1.3 */ |
| 1303 | printk(BIOS_ERR, "\tInvalid descriptor block padding\n"); |
| 1304 | if (!has_valid_string_termination) /* Likewise */ |
| 1305 | printk(BIOS_ERR, "\tDetailed block string not properly terminated\n"); |
| 1306 | } else if (claims_one_point_two) { |
| 1307 | if (nonconformant_digital_display || |
| 1308 | (has_name_descriptor && !name_descriptor_terminated)) |
| 1309 | conformant = 0; |
| 1310 | if (!conformant) |
| 1311 | printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n"); |
| 1312 | if (nonconformant_digital_display) |
| 1313 | printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n", |
| 1314 | nonconformant_digital_display); |
| 1315 | if (has_name_descriptor && !name_descriptor_terminated) |
| 1316 | printk(BIOS_ERR, "\tName descriptor not terminated with a newline\n"); |
| 1317 | } else if (claims_one_point_oh) { |
| 1318 | if (seen_non_detailed_descriptor) |
| 1319 | conformant = 0; |
| 1320 | if (!conformant) |
| 1321 | printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n"); |
| 1322 | if (seen_non_detailed_descriptor) |
| 1323 | printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n"); |
| 1324 | } |
| 1325 | |
| 1326 | if (nonconformant_extension || |
| 1327 | !has_valid_checksum || |
| 1328 | !has_valid_cvt || |
| 1329 | !has_valid_year || |
| 1330 | !has_valid_week || |
| 1331 | !has_valid_detailed_blocks || |
| 1332 | !has_valid_dummy_block || |
| 1333 | !has_valid_extension_count || |
| 1334 | !has_valid_descriptor_ordering || |
| 1335 | !has_valid_range_descriptor || |
| 1336 | !manufacturer_name_well_formed) { |
| 1337 | conformant = 0; |
| 1338 | printk(BIOS_ERR, "EDID block does not conform at all!\n"); |
| 1339 | if (nonconformant_extension) |
| 1340 | printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n", |
| 1341 | nonconformant_extension); |
| 1342 | if (!has_valid_checksum) |
| 1343 | printk(BIOS_ERR, "\tBlock has broken checksum\n"); |
| 1344 | if (!has_valid_cvt) |
| 1345 | printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n"); |
| 1346 | if (!has_valid_year) |
| 1347 | printk(BIOS_ERR, "\tBad year of manufacture\n"); |
| 1348 | if (!has_valid_week) |
| 1349 | printk(BIOS_ERR, "\tBad week of manufacture\n"); |
| 1350 | if (!has_valid_detailed_blocks) |
| 1351 | printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n"); |
| 1352 | if (!has_valid_dummy_block) |
| 1353 | printk(BIOS_ERR, "\tDummy block filled with garbage\n"); |
| 1354 | if (!has_valid_extension_count) |
| 1355 | printk(BIOS_ERR, "\tImpossible extension block count\n"); |
| 1356 | if (!manufacturer_name_well_formed) |
| 1357 | printk(BIOS_ERR, "\tManufacturer name field contains garbage\n"); |
| 1358 | if (!has_valid_descriptor_ordering) |
| 1359 | printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n"); |
| 1360 | if (!has_valid_range_descriptor) |
| 1361 | printk(BIOS_ERR, "\tRange descriptor contains garbage\n"); |
| 1362 | if (!has_valid_max_dotclock) |
| 1363 | printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n"); |
| 1364 | } |
| 1365 | |
| 1366 | if (warning_excessive_dotclock_correction) |
| 1367 | printk(BIOS_ERR, |
| 1368 | "Warning: CVT block corrects dotclock by more than 9.75MHz\n"); |
| 1369 | if (warning_zero_preferred_refresh) |
| 1370 | printk(BIOS_ERR, |
| 1371 | "Warning: CVT block does not set preferred refresh rate\n"); |
| 1372 | return !conformant; |
| 1373 | } |
| 1374 | |
Ronald G. Minnich | b3b72f3 | 2013-03-13 14:35:01 -0700 | [diff] [blame] | 1375 | /* |
| 1376 | * Notes on panel extensions: (TODO, implement me in the code) |
| 1377 | * |
| 1378 | * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf |
| 1379 | * at offset 0x6c (fourth detailed block): (all other bits reserved) |
| 1380 | * 0x6c: 00 00 00 0e 00 |
| 1381 | * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi) |
| 1382 | * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved) |
| 1383 | * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved) |
| 1384 | * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted) |
| 1385 | * bit 4: DE polarity (0 high active 1 low active) |
| 1386 | * bit 3-0: interface (0000 LVDS TFT |
| 1387 | * 0001 mono STN 4/8bit |
| 1388 | * 0010 color STN 8/16 bit |
| 1389 | * 0011 18 bit tft |
| 1390 | * 0100 24 bit tft |
| 1391 | * 0101 tmds |
| 1392 | * else reserved) |
| 1393 | * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse) |
| 1394 | * bit 0: vertical display mode (0 normal 1 up/down reverse) |
| 1395 | * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default |
| 1396 | * else time in 10ms (10ms to 150ms)) |
| 1397 | * bit 3-0: total poweron seq delay (as above) |
| 1398 | * 0x75: contrast power on/off seq delay, same as 0x74 |
| 1399 | * 0x76: bit 7: backlight control enable (1 means this field is valid) |
| 1400 | * bit 6: backlight enabled at boot (0 on 1 off) |
| 1401 | * bit 5-0: backlight brightness control steps (0..63) |
| 1402 | * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd |
| 1403 | * 0x78 - 0x7c: reserved |
| 1404 | * 0x7d: bit 7-4: EPI descriptor major version (1) |
| 1405 | * bit 3-0: EPI descriptor minor version (0) |
| 1406 | * |
| 1407 | * ---- |
| 1408 | * |
| 1409 | * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf |
| 1410 | * |
| 1411 | * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual |
| 1412 | * |
| 1413 | * detailed descriptor 3: |
| 1414 | * 0x5a - 0x5e: 00 00 00 fe 00 |
| 1415 | * 0x5f - 0x63: PC maker part number |
| 1416 | * 0x64: LCD supplier revision # |
| 1417 | * 0x65 - 0x6b: manufacturer part number |
| 1418 | * |
| 1419 | * detailed descriptor 4: |
| 1420 | * 0x6c - 0x70: 00 00 00 fe 00 |
| 1421 | * 0x71 - 0x78: smbus nits values (whut) |
| 1422 | * 0x79: number of lvds channels (1 or 2) |
| 1423 | * 0x7A: panel self test (1 if present) |
| 1424 | * and then dummy terminator |
| 1425 | * |
| 1426 | * SPWG also says something strange about the LSB of detailed descriptor 1: |
| 1427 | * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored." |
| 1428 | */ |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1429 | /* |
| 1430 | * Take an edid, and create a framebuffer. Set vbe_valid to 1. |
| 1431 | */ |
| 1432 | |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1433 | void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr) |
| 1434 | { |
| 1435 | edid_fb.physical_address = fb_addr; |
Ronald G. Minnich | 4c5b161 | 2013-06-28 14:33:30 -0700 | [diff] [blame] | 1436 | edid_fb.x_resolution = edid->x_resolution; |
| 1437 | edid_fb.y_resolution = edid->y_resolution; |
| 1438 | edid_fb.bytes_per_line = edid->bytes_per_line; |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 1439 | /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1440 | * seems to be to round it up to the nearest reasonable |
| 1441 | * boundary, because otherwise the byte-packing is hideous. |
| 1442 | * So, for example, in RGB with no alpha, the bytes are still |
| 1443 | * packed into 32-bit words, the so-called 32bpp-no-alpha mode. |
| 1444 | * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words, |
| 1445 | * and in 4:4:4 mode, they are packed into 16-bit words. |
| 1446 | * Good call on the hardware guys part. |
| 1447 | * It's not clear we're covering all cases here, but |
| 1448 | * I'm not sure with grahpics you ever can. |
| 1449 | */ |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 1450 | edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel; |
| 1451 | switch(edid->framebuffer_bits_per_pixel){ |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1452 | case 32: |
| 1453 | case 24: |
| 1454 | /* packed into 4-byte words */ |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1455 | edid_fb.red_mask_pos = 16; |
| 1456 | edid_fb.red_mask_size = 8; |
| 1457 | edid_fb.green_mask_pos = 8; |
| 1458 | edid_fb.green_mask_size = 8; |
| 1459 | edid_fb.blue_mask_pos = 0; |
| 1460 | edid_fb.blue_mask_size = 8; |
| 1461 | break; |
| 1462 | case 16: |
| 1463 | /* packed into 2-byte words */ |
Ronald G. Minnich | c0d5eb2 | 2013-08-01 11:38:05 -0700 | [diff] [blame] | 1464 | edid_fb.red_mask_pos = 11; |
| 1465 | edid_fb.red_mask_size = 5; |
| 1466 | edid_fb.green_mask_pos = 5; |
| 1467 | edid_fb.green_mask_size = 6; |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1468 | edid_fb.blue_mask_pos = 0; |
Ronald G. Minnich | c0d5eb2 | 2013-08-01 11:38:05 -0700 | [diff] [blame] | 1469 | edid_fb.blue_mask_size = 5; |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1470 | break; |
| 1471 | default: |
| 1472 | printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__, |
Ronald G. Minnich | 9518b56 | 2013-09-19 16:45:22 -0700 | [diff] [blame] | 1473 | edid->framebuffer_bits_per_pixel); |
Ronald G. Minnich | b2893a01 | 2013-04-23 10:59:11 -0700 | [diff] [blame] | 1474 | return; |
| 1475 | } |
| 1476 | |
| 1477 | edid_fb.reserved_mask_pos = 0; |
| 1478 | edid_fb.reserved_mask_size = 0; |
| 1479 | vbe_valid = 1; |
| 1480 | } |
| 1481 | |
| 1482 | int vbe_mode_info_valid(void) |
| 1483 | { |
| 1484 | return vbe_valid; |
| 1485 | } |
| 1486 | |
| 1487 | void fill_lb_framebuffer(struct lb_framebuffer *framebuffer) |
| 1488 | { |
| 1489 | *framebuffer = edid_fb; |
| 1490 | } |