soc/intel/skylake: Correct address of I2C5 Device
[coreboot.git] / src / lib / edid.c
blob8bcb95630f9f775c6833a90118f7a403b49b5f72
1 /*
2 * Copyright 2013 Google Inc.
3 * Copyright 2006-2012 Red Hat, Inc.
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:
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.
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.
23 /* Author: Adam Jackson <ajax@nwnk.net> */
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.
31 #include <assert.h>
32 #include <stddef.h>
33 #include <console/console.h>
34 #include <arch/io.h>
35 #include <stdint.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <edid.h>
39 #include <boot/coreboot_tables.h>
40 #include <vbe.h>
42 struct edid_context {
43 int claims_one_point_oh;
44 int claims_one_point_two;
45 int claims_one_point_three;
46 int claims_one_point_four;
47 int nonconformant_digital_display;
48 int nonconformant_extension;
49 int did_detailed_timing;
50 int has_name_descriptor;
51 int has_range_descriptor;
52 int has_preferred_timing;
53 int has_valid_checksum;
54 int has_valid_cvt;
55 int has_valid_dummy_block;
56 int has_valid_week;
57 int has_valid_year;
58 int has_valid_detailed_blocks;
59 int has_valid_extension_count;
60 int has_valid_descriptor_ordering;
61 int has_valid_descriptor_pad;
62 int has_valid_range_descriptor;
63 int has_valid_max_dotclock;
64 int has_valid_string_termination;
65 int manufacturer_name_well_formed;
66 int seen_non_detailed_descriptor;
67 int warning_excessive_dotclock_correction;
68 int warning_zero_preferred_refresh;
69 int conformant;
72 /* Stuff that isn't used anywhere but is nice to pretty-print while
73 we're decoding everything else. */
74 static struct {
75 char manuf_name[4];
76 unsigned int model;
77 unsigned int serial;
78 unsigned int year;
79 unsigned int week;
80 unsigned int version[2];
81 unsigned int nonconformant;
82 unsigned int type;
84 unsigned int x_mm;
85 unsigned int y_mm;
87 unsigned int voltage;
88 unsigned int sync;
90 const char *syncmethod;
91 const char *range_class;
92 const char *stereo;
93 } extra_info;
95 static struct edid tmp_edid;
97 static int vbe_valid;
98 static struct lb_framebuffer edid_fb;
100 static char *manufacturer_name(unsigned char *x)
102 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
103 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
104 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
105 extra_info.manuf_name[3] = 0;
107 if (isupper(extra_info.manuf_name[0]) &&
108 isupper(extra_info.manuf_name[1]) &&
109 isupper(extra_info.manuf_name[2]))
110 return extra_info.manuf_name;
112 return NULL;
115 static int
116 detailed_cvt_descriptor(unsigned char *x, int first)
118 const unsigned char empty[3] = { 0, 0, 0 };
119 const char *names[] = { "50", "60", "75", "85" };
120 int width = 0, height = 0;
121 int valid = 1;
122 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
124 if (!first && !memcmp(x, empty, 3))
125 return valid;
127 height = x[0];
128 height |= (x[1] & 0xf0) << 4;
129 height++;
130 height *= 2;
132 switch (x[1] & 0x0c) {
133 case 0x00:
134 width = (height * 4) / 3; break;
135 case 0x04:
136 width = (height * 16) / 9; break;
137 case 0x08:
138 width = (height * 16) / 10; break;
139 case 0x0c:
140 width = (height * 15) / 9; break;
143 if (x[1] & 0x03)
144 valid = 0;
145 if (x[2] & 0x80)
146 valid = 0;
147 if (!(x[2] & 0x1f))
148 valid = 0;
150 fifty = (x[2] & 0x10);
151 sixty = (x[2] & 0x08);
152 seventyfive = (x[2] & 0x04);
153 eightyfive = (x[2] & 0x02);
154 reduced = (x[2] & 0x01);
156 if (!valid) {
157 printk(BIOS_SPEW, " (broken)\n");
158 } else {
159 printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
160 width, height,
161 fifty ? "50 " : "",
162 sixty ? "60 " : "",
163 seventyfive ? "75 " : "",
164 eightyfive ? "85 " : "",
165 reduced ? "60RB " : "",
166 names[(x[2] & 0x60) >> 5],
167 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
170 return valid;
173 /* extract a CP437 string from a detailed subblock, checking for termination (if
174 * less than len of bytes) with LF and padded with SP.
176 static char *
177 extract_string(unsigned char *x, int *valid_termination, int len)
179 static char ret[128];
180 int i, seen_newline = 0;
182 memset(ret, 0, sizeof(ret));
184 for (i = 0; i < len; i++) {
185 if (seen_newline) {
186 if (x[i] != 0x20) {
187 *valid_termination = 0;
188 return ret;
190 } else if (x[i] == 0x0a) {
191 seen_newline = 1;
192 } else {
193 /* normal characters */
194 ret[i] = x[i];
198 return ret;
201 /* 1 means valid data */
202 static int
203 detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
204 struct edid_context *c)
206 struct edid *out = &tmp_edid;
207 int i;
208 #if 1
209 printk(BIOS_SPEW, "Hex of detail: ");
210 for (i = 0; i < 18; i++)
211 printk(BIOS_SPEW, "%02x", x[i]);
212 printk(BIOS_SPEW, "\n");
213 #endif
215 /* Result might already have some valid fields like mode_is_supported */
216 *out = *result_edid;
218 if (x[0] == 0 && x[1] == 0) {
219 /* Monitor descriptor block, not detailed timing descriptor. */
220 if (x[2] != 0) {
221 /* 1.3, 3.10.3 */
222 printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
223 x[2]);
224 c->has_valid_descriptor_pad = 0;
226 if (x[3] != 0xfd && x[4] != 0x00) {
227 /* 1.3, 3.10.3 */
228 printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
229 x[4]);
230 c->has_valid_descriptor_pad = 0;
233 c->seen_non_detailed_descriptor = 1;
234 if (x[3] <= 0xF) {
236 * in principle we can decode these, if we know what they are.
237 * 0x0f seems to be common in laptop panels.
238 * 0x0e is used by EPI: http://www.epi-standard.org/
240 printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]);
241 return 1;
243 switch (x[3]) {
244 case 0x10:
245 printk(BIOS_SPEW, "Dummy block\n");
246 for (i = 5; i < 18; i++)
247 if (x[i] != 0x00)
248 c->has_valid_dummy_block = 0;
249 return 1;
250 case 0xF7:
251 /* TODO */
252 printk(BIOS_SPEW, "Established timings III\n");
253 return 1;
254 case 0xF8:
256 int valid_cvt = 1; /* just this block */
257 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
258 if (x[5] != 0x01) {
259 c->has_valid_cvt = 0;
260 return 0;
262 for (i = 0; i < 4; i++)
263 valid_cvt &= detailed_cvt_descriptor(x + 6 + (i * 3), (i == 0));
264 c->has_valid_cvt &= valid_cvt;
265 return 1;
267 case 0xF9:
268 /* TODO */
269 printk(BIOS_SPEW, "Color management data\n");
270 return 1;
271 case 0xFA:
272 /* TODO */
273 printk(BIOS_SPEW, "More standard timings\n");
274 return 1;
275 case 0xFB:
276 /* TODO */
277 printk(BIOS_SPEW, "Color point\n");
278 return 1;
279 case 0xFC:
280 printk(BIOS_SPEW, "Monitor name: %s\n",
281 extract_string(x + 5,
282 &c->has_valid_string_termination,
283 13));
284 return 1;
285 case 0xFD:
287 int h_max_offset = 0, h_min_offset = 0;
288 int v_max_offset = 0, v_min_offset = 0;
289 int is_cvt = 0;
290 c->has_range_descriptor = 1;
291 extra_info.range_class = "";
293 * XXX todo: implement feature flags, vtd blocks
294 * XXX check: ranges are well-formed; block termination if no vtd
296 if (c->claims_one_point_four) {
297 if (x[4] & 0x02) {
298 v_max_offset = 255;
299 if (x[4] & 0x01) {
300 v_min_offset = 255;
303 if (x[4] & 0x04) {
304 h_max_offset = 255;
305 if (x[4] & 0x03) {
306 h_min_offset = 255;
309 } else if (x[4]) {
310 c->has_valid_range_descriptor = 0;
314 * despite the values, this is not a bitfield.
316 switch (x[10]) {
317 case 0x00: /* default gtf */
318 extra_info.range_class = "GTF";
319 break;
320 case 0x01: /* range limits only */
321 extra_info.range_class = "bare limits";
322 if (!c->claims_one_point_four)
323 c->has_valid_range_descriptor = 0;
324 break;
325 case 0x02: /* secondary gtf curve */
326 extra_info.range_class = "GTF with icing";
327 break;
328 case 0x04: /* cvt */
329 extra_info.range_class = "CVT";
330 is_cvt = 1;
331 if (!c->claims_one_point_four)
332 c->has_valid_range_descriptor = 0;
333 break;
334 default: /* invalid */
335 c->has_valid_range_descriptor = 0;
336 extra_info.range_class = "invalid";
337 break;
340 if (x[5] + v_min_offset > x[6] + v_max_offset)
341 c->has_valid_range_descriptor = 0;
342 if (x[7] + h_min_offset > x[8] + h_max_offset)
343 c->has_valid_range_descriptor = 0;
344 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
345 extra_info.range_class,
346 x[5] + v_min_offset, x[6] + v_max_offset,
347 x[7] + h_min_offset, x[8] + h_max_offset);
348 if (x[9])
349 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
350 else {
351 if (c->claims_one_point_four)
352 c->has_valid_max_dotclock = 0;
353 printk(BIOS_SPEW, "\n");
356 if (is_cvt) {
357 int max_h_pixels = 0;
359 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
361 if (x[12] & 0xfc) {
362 int raw_offset = (x[12] & 0xfc) >> 2;
363 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
364 (x[9] * 10000) - (raw_offset * 250));
365 if (raw_offset >= 40)
366 c->warning_excessive_dotclock_correction = 1;
369 max_h_pixels = x[12] & 0x03;
370 max_h_pixels <<= 8;
371 max_h_pixels |= x[13];
372 max_h_pixels *= 8;
373 if (max_h_pixels)
374 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
376 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
377 x[14] & 0x80 ? "4:3" : "",
378 x[14] & 0x40 ? "16:9" : "",
379 x[14] & 0x20 ? "16:10" : "",
380 x[14] & 0x10 ? "5:4" : "",
381 x[14] & 0x08 ? "15:9" : "");
382 if (x[14] & 0x07)
383 c->has_valid_range_descriptor = 0;
385 printk(BIOS_SPEW, "Preferred aspect ratio: ");
386 switch((x[15] & 0xe0) >> 5) {
387 case 0x00: printk(BIOS_SPEW, "4:3"); break;
388 case 0x01: printk(BIOS_SPEW, "16:9"); break;
389 case 0x02: printk(BIOS_SPEW, "16:10"); break;
390 case 0x03: printk(BIOS_SPEW, "5:4"); break;
391 case 0x04: printk(BIOS_SPEW, "15:9"); break;
392 default: printk(BIOS_SPEW, "(broken)"); break;
394 printk(BIOS_SPEW, "\n");
396 if (x[15] & 0x04)
397 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
398 if (x[15] & 0x10)
399 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
401 if (x[15] & 0x07)
402 c->has_valid_range_descriptor = 0;
404 if (x[16] & 0xf0) {
405 printk(BIOS_SPEW, "Supported display scaling:\n");
406 if (x[16] & 0x80)
407 printk(BIOS_SPEW, " Horizontal shrink\n");
408 if (x[16] & 0x40)
409 printk(BIOS_SPEW, " Horizontal stretch\n");
410 if (x[16] & 0x20)
411 printk(BIOS_SPEW, " Vertical shrink\n");
412 if (x[16] & 0x10)
413 printk(BIOS_SPEW, " Vertical stretch\n");
416 if (x[16] & 0x0f)
417 c->has_valid_range_descriptor = 0;
419 if (x[17])
420 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
421 else
422 c->warning_zero_preferred_refresh = 1;
426 * Slightly weird to return a global, but I've never seen any
427 * EDID block wth two range descriptors, so it's harmless.
429 return 1;
431 case 0xFE:
433 * TODO: Two of these in a row, in the third and fourth slots,
434 * seems to be specified by SPWG: http://www.spwg.org/
436 printk(BIOS_SPEW, "ASCII string: %s\n",
437 extract_string(x + 5, &c->has_valid_string_termination, 13));
438 return 1;
439 case 0xFF:
440 printk(BIOS_SPEW, "Serial number: %s\n",
441 extract_string(x + 5, &c->has_valid_string_termination, 13));
442 return 1;
443 default:
444 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
445 return 0;
449 if (c->seen_non_detailed_descriptor && !in_extension) {
450 c->has_valid_descriptor_ordering = 0;
453 /* Edid contains pixel clock in terms of 10KHz */
454 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
456 LVDS supports following pixel clocks
457 25000...112000 kHz: single channel
458 80000...224000 kHz: dual channel
459 There is some overlap in theoretically supported
460 pixel clock between single-channel and dual-channel.
461 In practice with current panels all panels
462 <= 75200 kHz: single channel
463 >= 97750 kHz: dual channel
464 We have no samples between those values, so put a
465 threshold at 95000 kHz. If we get anything over
466 95000 kHz with single channel, we can make this
467 more sofisticated but it's currently not needed.
469 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
470 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
471 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
472 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
473 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
474 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
475 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
476 out->mode.hborder = x[15];
477 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
478 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
479 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
480 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
481 out->mode.vborder = x[16];
483 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
484 * Chipsets that want something else will need to override this with
485 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
486 * heuristic, assume that X86 systems require a 64-byte row alignment
487 * (since that seems to be true for most Intel chipsets). */
488 if (IS_ENABLED(CONFIG_ARCH_X86))
489 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
490 else
491 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
493 switch ((x[17] & 0x18) >> 3) {
494 case 0x00:
495 extra_info.syncmethod = " analog composite";
496 break;
497 case 0x01:
498 extra_info.syncmethod = " bipolar analog composite";
499 break;
500 case 0x02:
501 extra_info.syncmethod = " digital composite";
502 break;
503 case 0x03:
504 extra_info.syncmethod = "";
505 break;
507 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
508 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
509 switch (x[17] & 0x61) {
510 case 0x20:
511 extra_info.stereo = "field sequential L/R";
512 break;
513 case 0x40:
514 extra_info.stereo = "field sequential R/L";
515 break;
516 case 0x21:
517 extra_info.stereo = "interleaved right even";
518 break;
519 case 0x41:
520 extra_info.stereo = "interleaved left even";
521 break;
522 case 0x60:
523 extra_info.stereo = "four way interleaved";
524 break;
525 case 0x61:
526 extra_info.stereo = "side by side interleaved";
527 break;
528 default:
529 extra_info.stereo = "";
530 break;
533 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
534 " %04x %04x %04x %04x hborder %x\n"
535 " %04x %04x %04x %04x vborder %x\n"
536 " %chsync %cvsync%s%s %s\n",
537 out->mode.pixel_clock,
538 extra_info.x_mm,
539 extra_info.y_mm,
540 out->mode.ha, out->mode.ha + out->mode.hso,
541 out->mode.ha + out->mode.hso + out->mode.hspw,
542 out->mode.ha + out->mode.hbl, out->mode.hborder,
543 out->mode.va, out->mode.va + out->mode.vso,
544 out->mode.va + out->mode.vso + out->mode.vspw,
545 out->mode.va + out->mode.vbl, out->mode.vborder,
546 out->mode.phsync, out->mode.pvsync,
547 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
548 extra_info.stereo);
550 if (! c->did_detailed_timing) {
551 printk(BIOS_SPEW, "Did detailed timing\n");
552 c->did_detailed_timing = 1;
553 *result_edid = *out;
556 return 1;
559 static int
560 do_checksum(unsigned char *x)
562 int valid = 0;
563 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
565 unsigned char sum = 0;
566 int i;
567 for (i = 0; i < 128; i++)
568 sum += x[i];
569 if (sum) {
570 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
571 } else {
572 valid = 1;
573 printk(BIOS_SPEW, " (valid)");
576 printk(BIOS_SPEW, "\n");
577 return valid;
580 /* CEA extension */
582 static const char *
583 audio_format(unsigned char x)
585 switch (x) {
586 case 0: return "RESERVED";
587 case 1: return "Linear PCM";
588 case 2: return "AC-3";
589 case 3: return "MPEG 1 (Layers 1 & 2)";
590 case 4: return "MPEG 1 Layer 3 (MP3)";
591 case 5: return "MPEG2 (multichannel)";
592 case 6: return "AAC";
593 case 7: return "DTS";
594 case 8: return "ATRAC";
595 case 9: return "One Bit Audio";
596 case 10: return "Dolby Digital+";
597 case 11: return "DTS-HD";
598 case 12: return "MAT (MLP)";
599 case 13: return "DST";
600 case 14: return "WMA Pro";
601 case 15: return "RESERVED";
603 return "BROKEN"; /* can't happen */
606 static void
607 cea_audio_block(unsigned char *x)
609 int i, format;
610 int length = x[0] & 0x1f;
612 if (length % 3) {
613 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
614 /* XXX non-conformant */
615 return;
618 for (i = 1; i < length; i += 3) {
619 format = (x[i] & 0x78) >> 3;
620 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
621 x[i] & 0x07);
622 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
623 (x[i+1] & 0x40) ? " 192" : "",
624 (x[i+1] & 0x20) ? " 176.4" : "",
625 (x[i+1] & 0x10) ? " 96" : "",
626 (x[i+1] & 0x08) ? " 88.2" : "",
627 (x[i+1] & 0x04) ? " 48" : "",
628 (x[i+1] & 0x02) ? " 44.1" : "",
629 (x[i+1] & 0x01) ? " 32" : "");
630 if (format == 1) {
631 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
632 (x[2] & 0x04) ? " 24" : "",
633 (x[2] & 0x02) ? " 20" : "",
634 (x[2] & 0x01) ? " 16" : "");
635 } else if (format <= 8) {
636 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
641 static void
642 cea_video_block(unsigned char *x)
644 int i;
645 int length = x[0] & 0x1f;
647 for (i = 1; i < length; i++)
648 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
649 x[i] & 0x80 ? "(native)" : "");
652 static void
653 cea_hdmi_block(struct edid *out, unsigned char *x)
655 int length = x[0] & 0x1f;
657 out->hdmi_monitor_detected = 1;
659 printk(BIOS_SPEW, " (HDMI)\n");
660 printk(BIOS_SPEW,
661 " Source physical address %d.%d.%d.%d\n",
662 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
664 if (length > 5) {
665 if (x[6] & 0x80)
666 printk(BIOS_SPEW, " Supports_AI\n");
667 if (x[6] & 0x40)
668 printk(BIOS_SPEW, " DC_48bit\n");
669 if (x[6] & 0x20)
670 printk(BIOS_SPEW, " DC_36bit\n");
671 if (x[6] & 0x10)
672 printk(BIOS_SPEW, " DC_30bit\n");
673 if (x[6] & 0x08)
674 printk(BIOS_SPEW, " DC_Y444\n");
675 /* two reserved */
676 if (x[6] & 0x01)
677 printk(BIOS_SPEW, " DVI_Dual\n");
680 if (length > 6)
681 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
683 /* XXX the walk here is really ugly, and needs to be length-checked */
684 if (length > 7) {
685 int b = 0;
687 if (x[8] & 0x80) {
688 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
689 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
690 b += 2;
693 if (x[8] & 0x40) {
694 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
695 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
696 b += 2;
699 if (x[8] & 0x20) {
700 int mask = 0, formats = 0;
701 int len_xx, len_3d;
702 printk(BIOS_SPEW, " Extended HDMI video details:\n");
703 if (x[9 + b] & 0x80)
704 printk(BIOS_SPEW, " 3D present\n");
705 if ((x[9 + b] & 0x60) == 0x20) {
706 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
707 formats = 1;
709 if ((x[9 + b] & 0x60) == 0x40) {
710 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
711 formats = 1;
712 mask = 1;
714 switch (x[9 + b] & 0x18) {
715 case 0x00: break;
716 case 0x08:
717 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
718 break;
719 case 0x10:
720 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
721 break;
722 case 0x18:
723 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
724 break;
726 len_xx = (x[10 + b] & 0xe0) >> 5;
727 len_3d = (x[10 + b] & 0x1f) >> 0;
728 b += 2;
730 if (len_xx) {
731 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
732 " document\n", len_xx);
733 b += len_xx;
736 if (len_3d) {
737 if (formats) {
738 if (x[9 + b] & 0x01)
739 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
740 if (x[10 + b] & 0x40)
741 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
742 if (x[10 + b] & 0x01)
743 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
744 b += 2;
746 if (mask) {
747 int i;
748 printk(BIOS_SPEW, " 3D VIC indices:");
749 /* worst bit ordering ever */
750 for (i = 0; i < 8; i++)
751 if (x[10 + b] & (1 << i))
752 printk(BIOS_SPEW, " %d", i);
753 for (i = 0; i < 8; i++)
754 if (x[9 + b] & (1 << i))
755 printk(BIOS_SPEW, " %d", i + 8);
756 printk(BIOS_SPEW, "\n");
757 b += 2;
761 * XXX list of nibbles:
762 * 2D_VIC_Order_X
763 * 3D_Structure_X
764 * (optionally: 3D_Detail_X and reserved)
772 static void
773 cea_block(struct edid *out, unsigned char *x)
775 unsigned int oui;
777 switch ((x[0] & 0xe0) >> 5) {
778 case 0x01:
779 printk(BIOS_SPEW, " Audio data block\n");
780 cea_audio_block(x);
781 break;
782 case 0x02:
783 printk(BIOS_SPEW, " Video data block\n");
784 cea_video_block(x);
785 break;
786 case 0x03:
787 /* yes really, endianness lols */
788 oui = (x[3] << 16) + (x[2] << 8) + x[1];
789 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
790 if (oui == 0x000c03)
791 cea_hdmi_block(out, x);
792 else
793 printk(BIOS_SPEW, "\n");
794 break;
795 case 0x04:
796 printk(BIOS_SPEW, " Speaker allocation data block\n");
797 break;
798 case 0x05:
799 printk(BIOS_SPEW, " VESA DTC data block\n");
800 break;
801 case 0x07:
802 printk(BIOS_SPEW, " Extended tag: ");
803 switch (x[1]) {
804 case 0x00:
805 printk(BIOS_SPEW, "video capability data block\n");
806 break;
807 case 0x01:
808 printk(BIOS_SPEW, "vendor-specific video data block\n");
809 break;
810 case 0x02:
811 printk(BIOS_SPEW, "VESA video display device information data block\n");
812 break;
813 case 0x03:
814 printk(BIOS_SPEW, "VESA video data block\n");
815 break;
816 case 0x04:
817 printk(BIOS_SPEW, "HDMI video data block\n");
818 break;
819 case 0x05:
820 printk(BIOS_SPEW, "Colorimetry data block\n");
821 break;
822 case 0x10:
823 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
824 break;
825 case 0x11:
826 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
827 break;
828 case 0x12:
829 printk(BIOS_SPEW, "HDMI audio data block\n");
830 break;
831 default:
832 if (x[1] >= 6 && x[1] <= 15)
833 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
834 else if (x[1] >= 19 && x[1] <= 31)
835 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
836 else
837 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
838 break;
840 break;
841 default:
843 int tag = (*x & 0xe0) >> 5;
844 int length = *x & 0x1f;
845 printk(BIOS_SPEW,
846 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
847 break;
852 static int
853 parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
855 int ret = 0;
856 int version = x[1];
857 int offset = x[2];
858 unsigned char *detailed;
860 if (version >= 1) do {
861 if (version == 1 && x[3] != 0)
862 ret = 1;
864 if (offset < 4)
865 break;
867 if (version < 3) {
868 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
869 if (offset - 4 > 0)
870 /* do stuff */ ;
871 } else if (version == 3) {
872 int i;
873 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
874 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
875 cea_block(out, x + i);
879 if (version >= 2) {
880 if (x[3] & 0x80)
881 printk(BIOS_SPEW, "Underscans PC formats by default\n");
882 if (x[3] & 0x40)
883 printk(BIOS_SPEW, "Basic audio support\n");
884 if (x[3] & 0x20)
885 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
886 if (x[3] & 0x10)
887 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
888 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
891 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
892 if (detailed[0])
893 detailed_block(out, detailed, 1, c);
894 } while (0);
896 c->has_valid_checksum &= do_checksum(x);
897 return ret;
900 /* generic extension code */
902 static void
903 extension_version(struct edid *out, unsigned char *x)
905 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
908 static int
909 parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
911 int conformant_extension = 0;
912 printk(BIOS_SPEW, "\n");
914 switch(x[0]) {
915 case 0x02:
916 printk(BIOS_SPEW, "CEA extension block\n");
917 extension_version(out, x);
918 conformant_extension = parse_cea(out, x, c);
919 break;
920 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
921 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
922 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
923 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
924 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
925 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
926 default:
927 printk(BIOS_SPEW, "Unknown extension block\n");
928 break;
931 printk(BIOS_SPEW, "\n");
933 return conformant_extension;
936 static const struct {
937 int x, y, refresh;
938 } established_timings[] = {
939 /* 0x23 bit 7 - 0 */
940 {720, 400, 70},
941 {720, 400, 88},
942 {640, 480, 60},
943 {640, 480, 67},
944 {640, 480, 72},
945 {640, 480, 75},
946 {800, 600, 56},
947 {800, 600, 60},
948 /* 0x24 bit 7 - 0 */
949 {800, 600, 72},
950 {800, 600, 75},
951 {832, 624, 75},
952 {1280, 768, 87},
953 {1024, 768, 60},
954 {1024, 768, 70},
955 {1024, 768, 75},
956 {1280, 1024, 75},
957 /* 0x25 bit 7*/
958 {1152, 870, 75},
961 static void print_subsection(const char *name, unsigned char *edid, int start,
962 int end)
964 int i;
966 printk(BIOS_SPEW, "%s:", name);
967 for (i = strlen(name); i < 15; i++)
968 printk(BIOS_SPEW, " ");
969 for (i = start; i <= end; i++)
970 printk(BIOS_SPEW, " %02x", edid[i]);
971 printk(BIOS_SPEW, "\n");
974 static void dump_breakdown(unsigned char *edid)
976 printk(BIOS_SPEW, "Extracted contents:\n");
977 print_subsection("header", edid, 0, 7);
978 print_subsection("serial number", edid, 8, 17);
979 print_subsection("version", edid,18, 19);
980 print_subsection("basic params", edid, 20, 24);
981 print_subsection("chroma info", edid, 25, 34);
982 print_subsection("established", edid, 35, 37);
983 print_subsection("standard", edid, 38, 53);
984 print_subsection("descriptor 1", edid, 54, 71);
985 print_subsection("descriptor 2", edid, 72, 89);
986 print_subsection("descriptor 3", edid, 90, 107);
987 print_subsection("descriptor 4", edid, 108, 125);
988 print_subsection("extensions", edid, 126, 126);
989 print_subsection("checksum", edid, 127, 127);
990 printk(BIOS_SPEW, "\n");
994 * Lookup table of some well-known modes that can be useful in case the
995 * auto-detected mode is unsuitable.
996 * ha = hdisplay; va = vdisplay;
997 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
998 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
999 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1001 static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1002 [EDID_MODE_640x480_60Hz] = {
1003 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
1004 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
1005 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1006 .phsync = '-', .pvsync = '-' },
1007 [EDID_MODE_720x480_60Hz] = {
1008 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
1009 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
1010 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1011 .phsync = '-', .pvsync = '-' },
1012 [EDID_MODE_1280x720_60Hz] = {
1013 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
1014 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
1015 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1016 .phsync = '+', .pvsync = '+' },
1017 [EDID_MODE_1920x1080_60Hz] = {
1018 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
1019 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
1020 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1021 .phsync = '+', .pvsync = '+' },
1024 int set_display_mode(struct edid *edid, enum edid_modes mode)
1026 if (mode == EDID_MODE_AUTO)
1027 return 0;
1029 if (edid->mode_is_supported[mode]) {
1030 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1031 edid->mode = known_modes[mode];
1032 return 0;
1035 printk(BIOS_ERR, "Requested display mode not supported.\n");
1036 return -1;
1040 * Given a raw edid bloc, decode it into a form
1041 * that other parts of coreboot can use -- mainly
1042 * graphics bringup functions. The raw block is
1043 * required to be 128 bytes long, per the standard,
1044 * but we have no way of checking this minimum length.
1045 * We accept what we are given.
1047 int decode_edid(unsigned char *edid, int size, struct edid *out)
1049 int analog, i, j;
1050 struct edid_context c = {
1051 .has_valid_cvt = 1,
1052 .has_valid_dummy_block = 1,
1053 .has_valid_descriptor_ordering = 1,
1054 .has_valid_detailed_blocks = 1,
1055 .has_valid_descriptor_pad = 1,
1056 .has_valid_range_descriptor = 1,
1057 .has_valid_max_dotclock = 1,
1058 .has_valid_string_termination = 1,
1059 .conformant = 1,
1062 dump_breakdown(edid);
1064 memset(out, 0, sizeof(*out));
1066 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1067 printk(BIOS_SPEW, "No header found\n");
1068 return 1;
1071 if (manufacturer_name(edid + 0x08))
1072 c.manufacturer_name_well_formed = 1;
1074 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1075 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1076 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1078 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
1079 extra_info.manuf_name,
1080 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1081 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1082 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
1083 /* XXX need manufacturer ID table */
1085 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
1086 c.has_valid_week = 1;
1087 if (edid[0x11] > 0x0f) {
1088 if (edid[0x10] == 0xff) {
1089 c.has_valid_year = 1;
1090 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
1091 edid[0x11]);
1092 extra_info.week = edid[0x10];
1093 extra_info.year = edid[0x11];
1094 } else {
1095 /* we know it's at least 2013, when this code was written */
1096 if (edid[0x11] + 90 <= 2013) {
1097 c.has_valid_year = 1;
1098 printk(BIOS_SPEW, "Made week %hhd of %d\n",
1099 edid[0x10], edid[0x11] + 1990);
1100 extra_info.week = edid[0x10];
1101 extra_info.year = edid[0x11] + 1990;
1107 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
1108 extra_info.version[0] = edid[0x12];
1109 extra_info.version[1] = edid[0x13];
1111 if (edid[0x12] == 1) {
1112 if (edid[0x13] > 4) {
1113 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1114 edid[0x13] = 4;
1116 switch (edid[0x13]) {
1117 case 4:
1118 c.claims_one_point_four = 1;
1119 case 3:
1120 c.claims_one_point_three = 1;
1121 case 2:
1122 c.claims_one_point_two = 1;
1123 default:
1124 break;
1126 c.claims_one_point_oh = 1;
1129 /* display section */
1130 if (edid[0x14] & 0x80) {
1131 int conformance_mask;
1132 analog = 0;
1133 printk(BIOS_SPEW, "Digital display\n");
1134 if (c.claims_one_point_four) {
1135 conformance_mask = 0;
1136 if ((edid[0x14] & 0x70) == 0x00)
1137 printk(BIOS_SPEW, "Color depth is undefined\n");
1138 else if ((edid[0x14] & 0x70) == 0x70)
1139 c.nonconformant_digital_display = 1;
1140 else
1141 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1142 ((edid[0x14] & 0x70) >> 3) + 4);
1143 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1144 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
1146 switch (edid[0x14] & 0x0f) {
1147 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1148 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1149 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1150 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1151 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1152 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1153 default:
1154 c.nonconformant_digital_display = 1;
1156 extra_info.type = edid[0x14] & 0x0f;
1157 } else if (c.claims_one_point_two) {
1158 conformance_mask = 0x7E;
1159 if (edid[0x14] & 0x01) {
1160 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1162 } else
1163 conformance_mask = 0x7F;
1165 if (!c.nonconformant_digital_display)
1166 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
1167 extra_info.nonconformant = c.nonconformant_digital_display;
1168 } else {
1169 analog = 1;
1170 int voltage = (edid[0x14] & 0x60) >> 5;
1171 int sync = (edid[0x14] & 0x0F);
1172 extra_info.voltage = voltage;
1173 extra_info.sync = sync;
1175 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1176 voltage == 3 ? "0.7/0.7" :
1177 voltage == 2 ? "1.0/0.4" :
1178 voltage == 1 ? "0.714/0.286" :
1179 "0.7/0.3");
1181 if (c.claims_one_point_four) {
1182 if (edid[0x14] & 0x10)
1183 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1184 else
1185 printk(BIOS_SPEW, "Blank level equals black level\n");
1186 } else if (edid[0x14] & 0x10) {
1188 * XXX this is just the X text. 1.3 says "if set, display expects
1189 * a blank-to-black setup or pedestal per appropriate Signal
1190 * Level Standard". Whatever _that_ means.
1192 printk(BIOS_SPEW, "Configurable signal levels\n");
1195 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1196 sync & 0x04 ? "Composite " : "",
1197 sync & 0x02 ? "SyncOnGreen " : "",
1198 sync & 0x01 ? "Serration " : "");
1202 if (edid[0x15] && edid[0x16]) {
1203 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1204 edid[0x15], edid[0x16]);
1205 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
1206 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1207 unsigned int ratio = 100000/(edid[0x15] + 99);
1208 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1209 ratio / 1000, ratio % 1000);
1210 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1211 unsigned int ratio = 100000/(edid[0x16] + 99);
1212 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1213 ratio / 1000, ratio % 1000);
1215 } else {
1216 /* Either or both can be zero for 1.3 and before */
1217 printk(BIOS_SPEW, "Image size is variable\n");
1220 if (edid[0x17] == 0xff) {
1221 if (c.claims_one_point_four)
1222 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1223 else
1224 /* XXX Technically 1.3 doesn't say this... */
1225 printk(BIOS_SPEW, "Gamma: 1.0\n");
1226 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1227 printk(BIOS_SPEW, "Check DPMS levels\n");
1228 if (edid[0x18] & 0xE0) {
1229 printk(BIOS_SPEW, "DPMS levels:");
1230 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1231 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1232 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1233 printk(BIOS_SPEW, "\n");
1236 /* FIXME: this is from 1.4 spec, check earlier */
1237 if (analog) {
1238 switch (edid[0x18] & 0x18) {
1239 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1240 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1241 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1242 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
1244 } else {
1245 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1246 if (edid[0x18] & 0x10)
1247 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1248 if (edid[0x18] & 0x08)
1249 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1250 printk(BIOS_SPEW, "\n");
1253 if (edid[0x18] & 0x04)
1254 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1255 if (edid[0x18] & 0x02) {
1256 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
1257 c.has_preferred_timing = 1;
1259 if (edid[0x18] & 0x01)
1260 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1262 /* XXX color section */
1264 printk(BIOS_SPEW, "Established timings supported:\n");
1265 /* it's not yet clear we want all this stuff in the edid struct.
1266 * Let's wait.
1268 for (i = 0; i < 17; i++) {
1269 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1270 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1271 established_timings[i].y, established_timings[i].refresh);
1273 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1274 if (known_modes[j].ha == established_timings[i].x &&
1275 known_modes[j].va == established_timings[i].y &&
1276 known_modes[j].refresh == established_timings[i].refresh)
1277 out->mode_is_supported[j] = 1;
1283 printk(BIOS_SPEW, "Standard timings supported:\n");
1284 for (i = 0; i < 8; i++) {
1285 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1286 unsigned int x, y = 0, refresh;
1288 if (b1 == 0x01 && b2 == 0x01)
1289 continue;
1291 if (b1 == 0) {
1292 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1293 continue;
1295 x = (b1 + 31) * 8;
1296 switch ((b2 >> 6) & 0x3) {
1297 case 0x00:
1298 if (c.claims_one_point_three)
1299 y = x * 10 / 16;
1300 else
1301 y = x;
1302 break;
1303 case 0x01:
1304 y = x * 3 / 4;
1305 break;
1306 case 0x02:
1307 y = x * 4 / 5;
1308 break;
1309 case 0x03:
1310 y = x * 9 / 16;
1311 break;
1313 refresh = 60 + (b2 & 0x3f);
1315 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
1316 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1317 if (known_modes[j].ha == x && known_modes[j].va == y &&
1318 known_modes[j].refresh == refresh)
1319 out->mode_is_supported[j] = 1;
1323 /* detailed timings */
1324 printk(BIOS_SPEW, "Detailed timings\n");
1325 for (i = 0; i < 4; i++) {
1326 c.has_valid_detailed_blocks &= detailed_block(
1327 out, edid + 0x36 + i * 18, 0, &c);
1328 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1330 /* not really accurate... */
1331 c.has_preferred_timing = 0;
1335 /* check this, 1.4 verification guide says otherwise */
1336 if (edid[0x7e]) {
1337 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1338 /* 2 is impossible because of the block map */
1339 if (edid[0x7e] != 2)
1340 c.has_valid_extension_count = 1;
1341 } else {
1342 c.has_valid_extension_count = 1;
1345 printk(BIOS_SPEW, "Checksum\n");
1346 c.has_valid_checksum = do_checksum(edid);
1348 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1349 * the extension parsing loop below. Since v2.0 was quickly deprecated
1350 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1351 * that case now and can fix it when we need to use a real 2.0 panel.
1353 for(i = 128; i < size; i += 128)
1354 c.nonconformant_extension +=
1355 parse_extension(out, &edid[i], &c);
1357 if (c.claims_one_point_four) {
1358 if (c.nonconformant_digital_display ||
1359 !c.has_valid_string_termination ||
1360 !c.has_valid_descriptor_pad ||
1361 !c.has_preferred_timing)
1362 c.conformant = 0;
1363 if (!c.conformant)
1364 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
1365 if (c.nonconformant_digital_display)
1366 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
1367 c.nonconformant_digital_display);
1368 if (!c.has_valid_string_termination)
1369 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
1370 if (!c.has_valid_descriptor_pad)
1371 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
1372 if (!c.has_preferred_timing)
1373 printk(BIOS_ERR, "\tMissing preferred timing\n");
1374 } else if (c.claims_one_point_three) {
1375 if (c.nonconformant_digital_display ||
1376 !c.has_valid_string_termination ||
1377 !c.has_valid_descriptor_pad ||
1378 !c.has_preferred_timing) {
1379 c.conformant = 0;
1382 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1383 * has_range_descriptor are both required. These fields are
1384 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1385 * don't have them. As a workaround, we only print warning
1386 * messages.
1388 if (!c.conformant)
1389 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
1390 else if (!c.has_name_descriptor || !c.has_range_descriptor)
1391 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1392 "fully conform to EDID 1.3.\n");
1394 if (c.nonconformant_digital_display)
1395 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
1396 c.nonconformant_digital_display);
1397 if (!c.has_name_descriptor)
1398 printk(BIOS_ERR, "\tMissing name descriptor\n");
1399 if (!c.has_preferred_timing)
1400 printk(BIOS_ERR, "\tMissing preferred timing\n");
1401 if (!c.has_range_descriptor)
1402 printk(BIOS_ERR, "\tMissing monitor ranges\n");
1403 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
1404 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
1405 if (!c.has_valid_string_termination) /* Likewise */
1406 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
1407 } else if (c.claims_one_point_two) {
1408 if (c.nonconformant_digital_display ||
1409 !c.has_valid_string_termination)
1410 c.conformant = 0;
1411 if (!c.conformant)
1412 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
1413 if (c.nonconformant_digital_display)
1414 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
1415 c.nonconformant_digital_display);
1416 if (!c.has_valid_string_termination)
1417 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
1418 } else if (c.claims_one_point_oh) {
1419 if (c.seen_non_detailed_descriptor)
1420 c.conformant = 0;
1421 if (!c.conformant)
1422 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
1423 if (c.seen_non_detailed_descriptor)
1424 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1427 if (c.nonconformant_extension ||
1428 !c.has_valid_checksum ||
1429 !c.has_valid_cvt ||
1430 !c.has_valid_year ||
1431 !c.has_valid_week ||
1432 !c.has_valid_detailed_blocks ||
1433 !c.has_valid_dummy_block ||
1434 !c.has_valid_extension_count ||
1435 !c.has_valid_descriptor_ordering ||
1436 !c.has_valid_range_descriptor ||
1437 !c.manufacturer_name_well_formed) {
1438 c.conformant = 0;
1439 printk(BIOS_ERR, "EDID block does not conform at all!\n");
1440 if (c.nonconformant_extension)
1441 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
1442 c.nonconformant_extension);
1443 if (!c.has_valid_checksum)
1444 printk(BIOS_ERR, "\tBlock has broken checksum\n");
1445 if (!c.has_valid_cvt)
1446 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
1447 if (!c.has_valid_year)
1448 printk(BIOS_ERR, "\tBad year of manufacture\n");
1449 if (!c.has_valid_week)
1450 printk(BIOS_ERR, "\tBad week of manufacture\n");
1451 if (!c.has_valid_detailed_blocks)
1452 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
1453 if (!c.has_valid_dummy_block)
1454 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
1455 if (!c.has_valid_extension_count)
1456 printk(BIOS_ERR, "\tImpossible extension block count\n");
1457 if (!c.manufacturer_name_well_formed)
1458 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
1459 if (!c.has_valid_descriptor_ordering)
1460 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
1461 if (!c.has_valid_range_descriptor)
1462 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
1463 if (!c.has_valid_max_dotclock)
1464 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1467 if (c.warning_excessive_dotclock_correction)
1468 printk(BIOS_ERR,
1469 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
1470 if (c.warning_zero_preferred_refresh)
1471 printk(BIOS_ERR,
1472 "Warning: CVT block does not set preferred refresh rate\n");
1473 return !c.conformant;
1477 * Notes on panel extensions: (TODO, implement me in the code)
1479 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1480 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1481 * 0x6c: 00 00 00 0e 00
1482 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1483 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1484 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1485 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1486 * bit 4: DE polarity (0 high active 1 low active)
1487 * bit 3-0: interface (0000 LVDS TFT
1488 * 0001 mono STN 4/8bit
1489 * 0010 color STN 8/16 bit
1490 * 0011 18 bit tft
1491 * 0100 24 bit tft
1492 * 0101 tmds
1493 * else reserved)
1494 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1495 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1496 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1497 * else time in 10ms (10ms to 150ms))
1498 * bit 3-0: total poweron seq delay (as above)
1499 * 0x75: contrast power on/off seq delay, same as 0x74
1500 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1501 * bit 6: backlight enabled at boot (0 on 1 off)
1502 * bit 5-0: backlight brightness control steps (0..63)
1503 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1504 * 0x78 - 0x7c: reserved
1505 * 0x7d: bit 7-4: EPI descriptor major version (1)
1506 * bit 3-0: EPI descriptor minor version (0)
1508 * ----
1510 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1512 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1514 * detailed descriptor 3:
1515 * 0x5a - 0x5e: 00 00 00 fe 00
1516 * 0x5f - 0x63: PC maker part number
1517 * 0x64: LCD supplier revision #
1518 * 0x65 - 0x6b: manufacturer part number
1520 * detailed descriptor 4:
1521 * 0x6c - 0x70: 00 00 00 fe 00
1522 * 0x71 - 0x78: smbus nits values (whut)
1523 * 0x79: number of lvds channels (1 or 2)
1524 * 0x7A: panel self test (1 if present)
1525 * and then dummy terminator
1527 * SPWG also says something strange about the LSB of detailed descriptor 1:
1528 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1531 /* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
1532 void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1533 int row_byte_alignment)
1535 /* Caller should pass a supported value, everything else is BUG(). */
1536 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
1537 row_byte_alignment = max(row_byte_alignment, 1);
1539 edid->framebuffer_bits_per_pixel = fb_bpp;
1540 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
1541 div_round_up(fb_bpp, 8), row_byte_alignment);
1542 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1543 edid->y_resolution = edid->mode.va;
1547 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1550 void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1552 edid_fb.physical_address = fb_addr;
1553 edid_fb.x_resolution = edid->x_resolution;
1554 edid_fb.y_resolution = edid->y_resolution;
1555 edid_fb.bytes_per_line = edid->bytes_per_line;
1556 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
1557 * seems to be to round it up to the nearest reasonable
1558 * boundary, because otherwise the byte-packing is hideous.
1559 * So, for example, in RGB with no alpha, the bytes are still
1560 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1561 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1562 * and in 4:4:4 mode, they are packed into 16-bit words.
1563 * Good call on the hardware guys part.
1564 * It's not clear we're covering all cases here, but
1565 * I'm not sure with grahpics you ever can.
1567 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
1568 edid_fb.reserved_mask_pos = 0;
1569 edid_fb.reserved_mask_size = 0;
1570 switch(edid->framebuffer_bits_per_pixel){
1571 case 32:
1572 case 24:
1573 /* packed into 4-byte words */
1574 edid_fb.reserved_mask_pos = 24;
1575 edid_fb.reserved_mask_size = 8;
1576 edid_fb.red_mask_pos = 16;
1577 edid_fb.red_mask_size = 8;
1578 edid_fb.green_mask_pos = 8;
1579 edid_fb.green_mask_size = 8;
1580 edid_fb.blue_mask_pos = 0;
1581 edid_fb.blue_mask_size = 8;
1582 break;
1583 case 16:
1584 /* packed into 2-byte words */
1585 edid_fb.red_mask_pos = 11;
1586 edid_fb.red_mask_size = 5;
1587 edid_fb.green_mask_pos = 5;
1588 edid_fb.green_mask_size = 6;
1589 edid_fb.blue_mask_pos = 0;
1590 edid_fb.blue_mask_size = 5;
1591 break;
1592 default:
1593 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
1594 edid->framebuffer_bits_per_pixel);
1595 return;
1598 vbe_valid = 1;
1601 #if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
1602 int vbe_mode_info_valid(void)
1604 return vbe_valid;
1607 void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1609 *framebuffer = edid_fb;
1611 #endif