blob: 8018967bf12636c29167ddfd30787f12442f8817 [file] [log] [blame]
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001/*
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. Minnichb2893a012013-04-23 10:59:11 -070039#include <boot/coreboot_tables.h>
40#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070041
42static int claims_one_point_oh = 0;
43static int claims_one_point_two = 0;
44static int claims_one_point_three = 0;
45static int claims_one_point_four = 0;
46static int nonconformant_digital_display = 0;
47static int nonconformant_extension = 0;
48static int did_detailed_timing = 0;
49static int has_name_descriptor = 0;
50static int name_descriptor_terminated = 0;
51static int has_range_descriptor = 0;
52static int has_preferred_timing = 0;
53static int has_valid_checksum = 0;
54static int has_valid_cvt = 1;
55static int has_valid_dummy_block = 1;
56static int has_valid_week = 0;
57static int has_valid_year = 0;
58static int has_valid_detailed_blocks = 0;
59static int has_valid_extension_count = 0;
60static int has_valid_descriptor_ordering = 1;
61static int has_valid_descriptor_pad = 1;
62static int has_valid_range_descriptor = 1;
63static int has_valid_max_dotclock = 1;
64static int has_valid_string_termination = 1;
65static int manufacturer_name_well_formed = 0;
66static int seen_non_detailed_descriptor = 0;
67
68static int warning_excessive_dotclock_correction = 0;
69static int warning_zero_preferred_refresh = 0;
70
71static int conformant = 1;
72
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070073static int vbe_valid;
74static struct lb_framebuffer edid_fb;
75
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070076static 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
91static int
92detailed_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
149static 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 */
161static char *
162extract_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 */
191static int
192detailed_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 Shaikh6b190712013-07-22 16:18:31 -0700450 /* Edid contains pixel clock in terms of 10KHz */
451 out->pixel_clock = (x[0] + (x[1] << 8)) * 10;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700452 out->ha = (x[2] + ((x[4] & 0xF0) << 4));
453 out->hbl = (x[3] + ((x[4] & 0x0F) << 8));
454 out->hso = (x[8] + ((x[11] & 0xC0) << 2));
455 out->hspw = (x[9] + ((x[11] & 0x30) << 4));
456 out->hborder = x[15];
457 out->va = (x[5] + ((x[7] & 0xF0) << 4));
458 out->vbl = (x[6] + ((x[7] & 0x0F) << 8));
459 out->vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
460 out->vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
461 out->vborder = x[16];
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700462 /* set up some reasonable defaults for payloads.
463 * We observe that most modern chipsets we work with
464 * tend to support rgb888 without regard to the
465 * panel bits per color or other settings. The rgb888
466 * is a convenient layout for software because
467 * it avoids the messy bit stuffing of rgb565 or rgb444.
468 * It makes a reasonable trade of memory for speed.
469 * So, set up the default for
470 * 32 bits per pixel
471 * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries)
472 * The mainboard can modify these if needed, though
473 * we have yet to see a case where that will happen.
474 */
475 out->bpp = 32;
476 out->x_resolution = ALIGN(out->ha * ((out->bpp + 7) / 8),64) / (out->bpp/8);
477 out->y_resolution = out->va;
478 out->bytes_per_line = ALIGN(out->ha * ((out->bpp + 7) / 8),64);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700479 printk(BIOS_SPEW, "Did detailed timing\n");
480 }
481 did_detailed_timing = 1;
482 switch ((x[17] & 0x18) >> 3) {
483 case 0x00:
484 out->syncmethod = " analog composite";
485 break;
486 case 0x01:
487 out->syncmethod = " bipolar analog composite";
488 break;
489 case 0x02:
490 out->syncmethod = " digital composite";
491 break;
492 case 0x03:
493 out->syncmethod = "";
494 break;
495 }
496 out->pvsync = (x[17] & (1 << 2)) ? '+' : '-';
497 out->phsync = (x[17] & (1 << 1)) ? '+' : '-';
498 switch (x[17] & 0x61) {
499 case 0x20:
500 out->stereo = "field sequential L/R";
501 break;
502 case 0x40:
503 out->stereo = "field sequential R/L";
504 break;
505 case 0x21:
506 out->stereo = "interleaved right even";
507 break;
508 case 0x41:
509 out->stereo = "interleaved left even";
510 break;
511 case 0x60:
512 out->stereo = "four way interleaved";
513 break;
514 case 0x61:
515 out->stereo = "side by side interleaved";
516 break;
517 default:
518 out->stereo = "";
519 break;
520 }
521
Furquan Shaikh6b190712013-07-22 16:18:31 -0700522 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700523 " %04x %04x %04x %04x hborder %x\n"
524 " %04x %04x %04x %04x vborder %x\n"
525 " %chsync %cvsync%s%s %s\n",
Furquan Shaikh6b190712013-07-22 16:18:31 -0700526 out->pixel_clock,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700527 (x[12] + ((x[14] & 0xF0) << 4)),
528 (x[13] + ((x[14] & 0x0F) << 8)),
529 out->ha, out->ha + out->hso, out->ha + out->hso + out->hspw,
530 out->ha + out->hbl, out->hborder,
531 out->va, out->va + out->vso, out->va + out->vso + out->vspw,
532 out->va + out->vbl, out->vborder,
533 out->phsync, out->pvsync,
534 out->syncmethod, x[17] & 0x80 ?" interlaced" : "",
535 out->stereo
536 );
537 return 1;
538}
539
540static int
541do_checksum(unsigned char *x)
542{
543 printk(BIOS_SPEW, "Checksum: 0x%hx", x[0x7f]);
544 {
545 unsigned char sum = 0;
546 int i;
547 for (i = 0; i < 128; i++)
548 sum += x[i];
549 if (sum) {
550 printk(BIOS_SPEW, " (should be 0x%hx)", (unsigned char)(x[0x7f] - sum));
551 has_valid_checksum = 0;
552 } else {
553 has_valid_checksum = 1;
554 printk(BIOS_SPEW, " (valid)");
555 }
556 }
557 printk(BIOS_SPEW, "\n");
558 return has_valid_checksum;
559}
560
561/* CEA extension */
562
563static const char *
564audio_format(unsigned char x)
565{
566 switch (x) {
567 case 0: return "RESERVED";
568 case 1: return "Linear PCM";
569 case 2: return "AC-3";
570 case 3: return "MPEG 1 (Layers 1 & 2)";
571 case 4: return "MPEG 1 Layer 3 (MP3)";
572 case 5: return "MPEG2 (multichannel)";
573 case 6: return "AAC";
574 case 7: return "DTS";
575 case 8: return "ATRAC";
576 case 9: return "One Bit Audio";
577 case 10: return "Dolby Digital+";
578 case 11: return "DTS-HD";
579 case 12: return "MAT (MLP)";
580 case 13: return "DST";
581 case 14: return "WMA Pro";
582 case 15: return "RESERVED";
583 }
584 return "BROKEN"; /* can't happen */
585}
586
587static void
588cea_audio_block(unsigned char *x)
589{
590 int i, format;
591 int length = x[0] & 0x1f;
592
593 if (length % 3) {
594 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
595 /* XXX non-conformant */
596 return;
597 }
598
599 for (i = 1; i < length; i += 3) {
600 format = (x[i] & 0x78) >> 3;
601 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
602 x[i] & 0x07);
603 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
604 (x[i+1] & 0x40) ? " 192" : "",
605 (x[i+1] & 0x20) ? " 176.4" : "",
606 (x[i+1] & 0x10) ? " 96" : "",
607 (x[i+1] & 0x08) ? " 88.2" : "",
608 (x[i+1] & 0x04) ? " 48" : "",
609 (x[i+1] & 0x02) ? " 44.1" : "",
610 (x[i+1] & 0x01) ? " 32" : "");
611 if (format == 1) {
612 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
613 (x[2] & 0x04) ? " 24" : "",
614 (x[2] & 0x02) ? " 20" : "",
615 (x[2] & 0x01) ? " 16" : "");
616 } else if (format <= 8) {
617 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
618 }
619 }
620}
621
622static void
623cea_video_block(unsigned char *x)
624{
625 int i;
626 int length = x[0] & 0x1f;
627
628 for (i = 1; i < length; i++)
629 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
630 x[i] & 0x80 ? "(native)" : "");
631}
632
633static void
634cea_hdmi_block(struct edid *out, unsigned char *x)
635{
636 int length = x[0] & 0x1f;
637
638 printk(BIOS_SPEW, " (HDMI)\n");
639 printk(BIOS_SPEW,
640 " Source physical address %d.%d.%d.%d\n",
641 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
642
643 if (length > 5) {
644 if (x[6] & 0x80)
645 printk(BIOS_SPEW, " Supports_AI\n");
646 if (x[6] & 0x40)
647 printk(BIOS_SPEW, " DC_48bit\n");
648 if (x[6] & 0x20)
649 printk(BIOS_SPEW, " DC_36bit\n");
650 if (x[6] & 0x10)
651 printk(BIOS_SPEW, " DC_30bit\n");
652 if (x[6] & 0x08)
653 printk(BIOS_SPEW, " DC_Y444\n");
654 /* two reserved */
655 if (x[6] & 0x01)
656 printk(BIOS_SPEW, " DVI_Dual\n");
657 }
658
659 if (length > 6)
660 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
661
662 /* XXX the walk here is really ugly, and needs to be length-checked */
663 if (length > 7) {
664 int b = 0;
665
666 if (x[8] & 0x80) {
667 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
668 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
669 b += 2;
670 }
671
672 if (x[8] & 0x40) {
673 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
674 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
675 b += 2;
676 }
677
678 if (x[8] & 0x20) {
679 int mask = 0, formats = 0;
680 int len_xx, len_3d;
681 printk(BIOS_SPEW, " Extended HDMI video details:\n");
682 if (x[9 + b] & 0x80)
683 printk(BIOS_SPEW, " 3D present\n");
684 if ((x[9 + b] & 0x60) == 0x20) {
685 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
686 formats = 1;
687 }
688 if ((x[9 + b] & 0x60) == 0x40) {
689 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
690 formats = 1;
691 mask = 1;
692 }
693 switch (x[9 + b] & 0x18) {
694 case 0x00: break;
695 case 0x08:
696 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
697 break;
698 case 0x10:
699 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
700 break;
701 case 0x18:
702 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
703 break;
704 }
705 len_xx = (x[10 + b] & 0xe0) >> 5;
706 len_3d = (x[10 + b] & 0x1f) >> 0;
707 b += 2;
708
709 if (len_xx) {
710 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
711 " document\n", len_xx);
712 b += len_xx;
713 }
714
715 if (len_3d) {
716 if (formats) {
717 if (x[9 + b] & 0x01)
718 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
719 if (x[10 + b] & 0x40)
720 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
721 if (x[10 + b] & 0x01)
722 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
723 b += 2;
724 }
725 if (mask) {
726 int i;
727 printk(BIOS_SPEW, " 3D VIC indices:");
728 /* worst bit ordering ever */
729 for (i = 0; i < 8; i++)
730 if (x[10 + b] & (1 << i))
731 printk(BIOS_SPEW, " %d", i);
732 for (i = 0; i < 8; i++)
733 if (x[9 + b] & (1 << i))
734 printk(BIOS_SPEW, " %d", i + 8);
735 printk(BIOS_SPEW, "\n");
736 b += 2;
737 }
738
739 /*
740 * XXX list of nibbles:
741 * 2D_VIC_Order_X
742 * 3D_Structure_X
743 * (optionally: 3D_Detail_X and reserved)
744 */
745 }
746
747 }
748 }
749}
750
751static void
752cea_block(struct edid *out, unsigned char *x)
753{
754 unsigned int oui;
755
756 switch ((x[0] & 0xe0) >> 5) {
757 case 0x01:
758 printk(BIOS_SPEW, " Audio data block\n");
759 cea_audio_block(x);
760 break;
761 case 0x02:
762 printk(BIOS_SPEW, " Video data block\n");
763 cea_video_block(x);
764 break;
765 case 0x03:
766 /* yes really, endianness lols */
767 oui = (x[3] << 16) + (x[2] << 8) + x[1];
768 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
769 if (oui == 0x000c03)
770 cea_hdmi_block(out, x);
771 else
772 printk(BIOS_SPEW, "\n");
773 break;
774 case 0x04:
775 printk(BIOS_SPEW, " Speaker allocation data block\n");
776 break;
777 case 0x05:
778 printk(BIOS_SPEW, " VESA DTC data block\n");
779 break;
780 case 0x07:
781 printk(BIOS_SPEW, " Extended tag: ");
782 switch (x[1]) {
783 case 0x00:
784 printk(BIOS_SPEW, "video capability data block\n");
785 break;
786 case 0x01:
787 printk(BIOS_SPEW, "vendor-specific video data block\n");
788 break;
789 case 0x02:
790 printk(BIOS_SPEW, "VESA video display device information data block\n");
791 break;
792 case 0x03:
793 printk(BIOS_SPEW, "VESA video data block\n");
794 break;
795 case 0x04:
796 printk(BIOS_SPEW, "HDMI video data block\n");
797 break;
798 case 0x05:
799 printk(BIOS_SPEW, "Colorimetry data block\n");
800 break;
801 case 0x10:
802 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
803 break;
804 case 0x11:
805 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
806 break;
807 case 0x12:
808 printk(BIOS_SPEW, "HDMI audio data block\n");
809 break;
810 default:
811 if (x[1] >= 6 && x[1] <= 15)
812 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
813 else if (x[1] >= 19 && x[1] <= 31)
814 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
815 else
816 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
817 break;
818 }
819 break;
820 default:
821 {
822 int tag = (*x & 0xe0) >> 5;
823 int length = *x & 0x1f;
824 printk(BIOS_SPEW,
825 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
826 break;
827 }
828 }
829}
830
831static int
832parse_cea(struct edid *out, unsigned char *x)
833{
834 int ret = 0;
835 int version = x[1];
836 int offset = x[2];
837 unsigned char *detailed;
838
839 if (version >= 1) do {
840 if (version == 1 && x[3] != 0)
841 ret = 1;
842
843 if (offset < 4)
844 break;
845
846 if (version < 3) {
847 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
848 if (offset - 4 > 0)
849 /* do stuff */ ;
850 } else if (version == 3) {
851 int i;
852 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
853 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
854 cea_block(out, x + i);
855 }
856 }
857
858 if (version >= 2) {
859 if (x[3] & 0x80)
860 printk(BIOS_SPEW, "Underscans PC formats by default\n");
861 if (x[3] & 0x40)
862 printk(BIOS_SPEW, "Basic audio support\n");
863 if (x[3] & 0x20)
864 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
865 if (x[3] & 0x10)
866 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
867 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
868 }
869
870 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
871 if (detailed[0])
872 detailed_block(out, detailed, 1);
873 } while (0);
874
875 do_checksum(x);
876
877 return ret;
878}
879
880/* generic extension code */
881
882static void
883extension_version(struct edid *out, unsigned char *x)
884{
885 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
886}
887
888static int
889parse_extension(struct edid *out, unsigned char *x)
890{
891 int conformant_extension = 0;
892 printk(BIOS_SPEW, "\n");
893
894 switch(x[0]) {
895 case 0x02:
896 printk(BIOS_SPEW, "CEA extension block\n");
897 extension_version(out, x);
898 conformant_extension = parse_cea(out, x);
899 break;
900 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
901 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
902 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
903 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
904 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
905 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
906 default:
907 printk(BIOS_SPEW, "Unknown extension block\n");
908 break;
909 }
910
911 printk(BIOS_SPEW, "\n");
912
913 return conformant_extension;
914}
915
916static const struct {
917 int x, y, refresh;
918} established_timings[] = {
919 /* 0x23 bit 7 - 0 */
920 {720, 400, 70},
921 {720, 400, 88},
922 {640, 480, 60},
923 {640, 480, 67},
924 {640, 480, 72},
925 {640, 480, 75},
926 {800, 600, 56},
927 {800, 600, 60},
928 /* 0x24 bit 7 - 0 */
929 {800, 600, 72},
930 {800, 600, 75},
931 {832, 624, 75},
932 {1280, 768, 87},
933 {1024, 768, 60},
934 {1024, 768, 70},
935 {1024, 768, 75},
936 {1280, 1024, 75},
937 /* 0x25 bit 7*/
938 {1152, 870, 75},
939};
940
941static void print_subsection(const char *name, unsigned char *edid, int start,
942 int end)
943{
944 int i;
945
946 printk(BIOS_SPEW, "%s:", name);
947 for (i = strlen(name); i < 15; i++)
948 printk(BIOS_SPEW, " ");
949 for (i = start; i <= end; i++)
950 printk(BIOS_SPEW, " %02x", edid[i]);
951 printk(BIOS_SPEW, "\n");
952}
953
954static void dump_breakdown(unsigned char *edid)
955{
956 printk(BIOS_SPEW, "Extracted contents:\n");
957 print_subsection("header", edid, 0, 7);
958 print_subsection("serial number", edid, 8, 17);
959 print_subsection("version", edid,18, 19);
960 print_subsection("basic params", edid, 20, 24);
961 print_subsection("chroma info", edid, 25, 34);
962 print_subsection("established", edid, 35, 37);
963 print_subsection("standard", edid, 38, 53);
964 print_subsection("descriptor 1", edid, 54, 71);
965 print_subsection("descriptor 2", edid, 72, 89);
966 print_subsection("descriptor 3", edid, 90, 107);
967 print_subsection("descriptor 4", edid, 108, 125);
968 print_subsection("extensions", edid, 126, 126);
969 print_subsection("checksum", edid, 127, 127);
970 printk(BIOS_SPEW, "\n");
971}
972
973/*
974 * Given a raw edid bloc, decode it into a form
975 * that other parts of coreboot can use -- mainly
976 * graphics bringup functions. The raw block is
977 * required to be 128 bytes long, per the standard,
978 * but we have no way of checking this minimum length.
979 * We accept what we are given.
980 */
981int decode_edid(unsigned char *edid, int size, struct edid *out)
982{
983 int analog, i;
984
985 dump_breakdown(edid);
986
987 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
988 printk(BIOS_SPEW, "No header found\n");
989 return 1;
990 }
991 memset(out, 0, sizeof(*out));
992 manufacturer_name(out, edid + 0x08);
993 out->model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
994 out->serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
995 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
996
997 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
998 out->manuf_name,
999 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1000 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1001 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
1002 /* XXX need manufacturer ID table */
1003
1004 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
1005 has_valid_week = 1;
1006 if (edid[0x11] > 0x0f) {
1007 if (edid[0x10] == 0xff) {
1008 has_valid_year = 1;
1009 printk(BIOS_SPEW, "Made week %hd of model year %hd\n", edid[0x10],
1010 edid[0x11]);
1011 out->week = edid[0x10];
1012 out->year = edid[0x11];
1013 } else {
1014 /* we know it's at least 2013, when this code was written */
1015 if (edid[0x11] + 90 <= 2013) {
1016 has_valid_year = 1;
1017 printk(BIOS_SPEW, "Made week %hd of %hd\n",
1018 edid[0x10], edid[0x11] + 1990);
1019 out->week = edid[0x10];
1020 out->year = edid[0x11] + 1990;
1021 }
1022 }
1023 }
1024 }
1025
1026
1027 printk(BIOS_SPEW, "EDID version: %hd.%hd\n", edid[0x12], edid[0x13]);
1028 out->version[0] = edid[0x12];
1029 out->version[1] = edid[0x13];
1030
1031 if (edid[0x12] == 1) {
1032 if (edid[0x13] > 4) {
1033 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1034 edid[0x13] = 4;
1035 }
1036 switch (edid[0x13]) {
1037 case 4:
1038 claims_one_point_four = 1;
1039 case 3:
1040 claims_one_point_three = 1;
1041 case 2:
1042 claims_one_point_two = 1;
1043 default:
1044 break;
1045 }
1046 claims_one_point_oh = 1;
1047 }
1048
1049 /* display section */
1050
1051 if (edid[0x14] & 0x80) {
1052 int conformance_mask;
1053 analog = 0;
1054 printk(BIOS_SPEW, "Digital display\n");
1055 if (claims_one_point_four) {
1056 conformance_mask = 0;
1057 if ((edid[0x14] & 0x70) == 0x00)
1058 printk(BIOS_SPEW, "Color depth is undefined\n");
1059 else if ((edid[0x14] & 0x70) == 0x70)
1060 nonconformant_digital_display = 1;
1061 else
1062 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1063 ((edid[0x14] & 0x70) >> 3) + 4);
1064 out->bpp = ((edid[0x14] & 0x70) >> 3) + 4;
1065
1066 switch (edid[0x14] & 0x0f) {
1067 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1068 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1069 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1070 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1071 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1072 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1073 default:
1074 nonconformant_digital_display = 1;
1075 }
1076 out->type = edid[0x14] & 0x0f;
1077 } else if (claims_one_point_two) {
1078 conformance_mask = 0x7E;
1079 if (edid[0x14] & 0x01) {
1080 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1081 }
1082 } else
1083 conformance_mask = 0x7F;
1084
1085 if (!nonconformant_digital_display)
1086 nonconformant_digital_display = edid[0x14] & conformance_mask;
1087 out->nonconformant = nonconformant_digital_display;
1088 } else {
1089 analog = 1;
1090 int voltage = (edid[0x14] & 0x60) >> 5;
1091 int sync = (edid[0x14] & 0x0F);
1092 out->voltage = voltage;
1093 out->sync = sync;
1094
1095 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1096 voltage == 3 ? "0.7/0.7" :
1097 voltage == 2 ? "1.0/0.4" :
1098 voltage == 1 ? "0.714/0.286" :
1099 "0.7/0.3");
1100
1101 if (claims_one_point_four) {
1102 if (edid[0x14] & 0x10)
1103 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1104 else
1105 printk(BIOS_SPEW, "Blank level equals black level\n");
1106 } else if (edid[0x14] & 0x10) {
1107 /*
1108 * XXX this is just the X text. 1.3 says "if set, display expects
1109 * a blank-to-black setup or pedestal per appropriate Signal
1110 * Level Standard". Whatever _that_ means.
1111 */
1112 printk(BIOS_SPEW, "Configurable signal levels\n");
1113 }
1114
1115 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1116 sync & 0x04 ? "Composite " : "",
1117 sync & 0x02 ? "SyncOnGreen " : "",
1118 sync & 0x01 ? "Serration " : "");
1119 }
1120
1121
1122 if (edid[0x15] && edid[0x16]) {
1123 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1124 edid[0x15], edid[0x16]);
1125 out->xsize_cm = edid[0x15];
1126 out->ysize_cm = edid[0x16];
1127 } else if (claims_one_point_four && (edid[0x15] || edid[0x16])) {
1128 if (edid[0x15]) {
1129 printk(BIOS_SPEW, "Aspect ratio is %f (landscape)\n",
1130 100.0/(edid[0x16] + 99));
1131 /* truncated to integer %. We try to avoid floating point */
1132 out->aspect_landscape = 10000 /(edid[0x16] + 99);
1133 } else {
1134 printk(BIOS_SPEW, "Aspect ratio is %f (portrait)\n",
1135 100.0/(edid[0x15] + 99));
1136 out->aspect_portrait = 10000 /(edid[0x16] + 99);
1137 }
1138 } else {
1139 /* Either or both can be zero for 1.3 and before */
1140 printk(BIOS_SPEW, "Image size is variable\n");
1141 }
1142
1143 if (edid[0x17] == 0xff) {
1144 if (claims_one_point_four)
1145 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1146 else
1147 /* XXX Technically 1.3 doesn't say this... */
1148 printk(BIOS_SPEW, "Gamma: 1.0\n");
1149 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1150 printk(BIOS_SPEW, "Check DPMS levels\n");
1151 if (edid[0x18] & 0xE0) {
1152 printk(BIOS_SPEW, "DPMS levels:");
1153 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1154 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1155 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1156 printk(BIOS_SPEW, "\n");
1157 }
1158
1159/* FIXME: this is from 1.4 spec, check earlier */
1160 if (analog) {
1161 switch (edid[0x18] & 0x18) {
1162 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1163 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1164 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1165 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
1166 }
1167 } else {
1168 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1169 if (edid[0x18] & 0x10)
1170 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1171 if (edid[0x18] & 0x08)
1172 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1173 printk(BIOS_SPEW, "\n");
1174 }
1175
1176 if (edid[0x18] & 0x04)
1177 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1178 if (edid[0x18] & 0x02) {
1179 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
1180 has_preferred_timing = 1;
1181 }
1182 if (edid[0x18] & 0x01)
1183 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1184
1185 /* XXX color section */
1186
1187 printk(BIOS_SPEW, "Established timings supported:\n");
1188 /* it's not yet clear we want all this stuff in the edid struct.
1189 * Let's wait.
1190 */
1191 for (i = 0; i < 17; i++) {
1192 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1193 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1194 established_timings[i].y, established_timings[i].refresh);
1195 }
1196 }
1197
1198 printk(BIOS_SPEW, "Standard timings supported:\n");
1199 for (i = 0; i < 8; i++) {
1200 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
Gerd Hoffmann0ea36642013-06-18 23:52:26 +02001201 unsigned int x, y = 0, refresh;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001202
1203 if (b1 == 0x01 && b2 == 0x01)
1204 continue;
1205
1206 if (b1 == 0) {
1207 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1208 continue;
1209 }
1210 x = (b1 + 31) * 8;
1211 switch ((b2 >> 6) & 0x3) {
1212 case 0x00:
1213 if (claims_one_point_three)
1214 y = x * 10 / 16;
1215 else
1216 y = x;
1217 break;
1218 case 0x01:
1219 y = x * 3 / 4;
1220 break;
1221 case 0x02:
1222 y = x * 4 / 5;
1223 break;
1224 case 0x03:
1225 y = x * 9 / 16;
1226 break;
1227 }
1228 refresh = 60 + (b2 & 0x3f);
1229
1230 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
1231 }
1232
1233 /* detailed timings */
1234 printk(BIOS_SPEW, "Detailed timings\n");
1235 has_valid_detailed_blocks = detailed_block(out, edid + 0x36, 0);
1236 if (has_preferred_timing && !did_detailed_timing)
1237 has_preferred_timing = 0; /* not really accurate... */
1238 has_valid_detailed_blocks &= detailed_block(out, edid + 0x48, 0);
1239 has_valid_detailed_blocks &= detailed_block(out, edid + 0x5A, 0);
1240 has_valid_detailed_blocks &= detailed_block(out, edid + 0x6C, 0);
1241
1242 /* check this, 1.4 verification guide says otherwise */
1243 if (edid[0x7e]) {
1244 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1245 /* 2 is impossible because of the block map */
1246 if (edid[0x7e] != 2)
1247 has_valid_extension_count = 1;
1248 } else {
1249 has_valid_extension_count = 1;
1250 }
1251
1252 printk(BIOS_SPEW, "Checksum\n");
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001253 vbe_valid = do_checksum(edid);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001254 for(i = 0; i < size; i += 128)
1255 nonconformant_extension = parse_extension(out, &edid[i]);
1256/*
1257 x = edid;
1258 for (edid_lines /= 8; edid_lines > 1; edid_lines--) {
1259 x += 128;
1260 nonconformant_extension += parse_extension(x);
1261 }
1262*/
1263
1264 if (claims_one_point_three) {
1265 if (nonconformant_digital_display ||
1266 !has_valid_string_termination ||
1267 !has_valid_descriptor_pad ||
1268 !has_name_descriptor ||
1269 !name_descriptor_terminated ||
1270 !has_preferred_timing ||
1271 !has_range_descriptor)
1272 conformant = 0;
1273 if (!conformant)
1274 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
1275 if (nonconformant_digital_display)
1276 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
1277 nonconformant_digital_display);
1278 if (!has_name_descriptor)
1279 printk(BIOS_ERR, "\tMissing name descriptor\n");
1280 else if (!name_descriptor_terminated)
1281 printk(BIOS_ERR, "\tName descriptor not terminated with a newline\n");
1282 if (!has_preferred_timing)
1283 printk(BIOS_ERR, "\tMissing preferred timing\n");
1284 if (!has_range_descriptor)
1285 printk(BIOS_ERR, "\tMissing monitor ranges\n");
1286 if (!has_valid_descriptor_pad) /* Might be more than just 1.3 */
1287 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
1288 if (!has_valid_string_termination) /* Likewise */
1289 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
1290 } else if (claims_one_point_two) {
1291 if (nonconformant_digital_display ||
1292 (has_name_descriptor && !name_descriptor_terminated))
1293 conformant = 0;
1294 if (!conformant)
1295 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
1296 if (nonconformant_digital_display)
1297 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
1298 nonconformant_digital_display);
1299 if (has_name_descriptor && !name_descriptor_terminated)
1300 printk(BIOS_ERR, "\tName descriptor not terminated with a newline\n");
1301 } else if (claims_one_point_oh) {
1302 if (seen_non_detailed_descriptor)
1303 conformant = 0;
1304 if (!conformant)
1305 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
1306 if (seen_non_detailed_descriptor)
1307 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1308 }
1309
1310 if (nonconformant_extension ||
1311 !has_valid_checksum ||
1312 !has_valid_cvt ||
1313 !has_valid_year ||
1314 !has_valid_week ||
1315 !has_valid_detailed_blocks ||
1316 !has_valid_dummy_block ||
1317 !has_valid_extension_count ||
1318 !has_valid_descriptor_ordering ||
1319 !has_valid_range_descriptor ||
1320 !manufacturer_name_well_formed) {
1321 conformant = 0;
1322 printk(BIOS_ERR, "EDID block does not conform at all!\n");
1323 if (nonconformant_extension)
1324 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
1325 nonconformant_extension);
1326 if (!has_valid_checksum)
1327 printk(BIOS_ERR, "\tBlock has broken checksum\n");
1328 if (!has_valid_cvt)
1329 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
1330 if (!has_valid_year)
1331 printk(BIOS_ERR, "\tBad year of manufacture\n");
1332 if (!has_valid_week)
1333 printk(BIOS_ERR, "\tBad week of manufacture\n");
1334 if (!has_valid_detailed_blocks)
1335 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
1336 if (!has_valid_dummy_block)
1337 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
1338 if (!has_valid_extension_count)
1339 printk(BIOS_ERR, "\tImpossible extension block count\n");
1340 if (!manufacturer_name_well_formed)
1341 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
1342 if (!has_valid_descriptor_ordering)
1343 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
1344 if (!has_valid_range_descriptor)
1345 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
1346 if (!has_valid_max_dotclock)
1347 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1348 }
1349
1350 if (warning_excessive_dotclock_correction)
1351 printk(BIOS_ERR,
1352 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
1353 if (warning_zero_preferred_refresh)
1354 printk(BIOS_ERR,
1355 "Warning: CVT block does not set preferred refresh rate\n");
1356 return !conformant;
1357 }
1358
1359/*
1360 * Notes on panel extensions: (TODO, implement me in the code)
1361 *
1362 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1363 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1364 * 0x6c: 00 00 00 0e 00
1365 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1366 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1367 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1368 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1369 * bit 4: DE polarity (0 high active 1 low active)
1370 * bit 3-0: interface (0000 LVDS TFT
1371 * 0001 mono STN 4/8bit
1372 * 0010 color STN 8/16 bit
1373 * 0011 18 bit tft
1374 * 0100 24 bit tft
1375 * 0101 tmds
1376 * else reserved)
1377 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1378 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1379 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1380 * else time in 10ms (10ms to 150ms))
1381 * bit 3-0: total poweron seq delay (as above)
1382 * 0x75: contrast power on/off seq delay, same as 0x74
1383 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1384 * bit 6: backlight enabled at boot (0 on 1 off)
1385 * bit 5-0: backlight brightness control steps (0..63)
1386 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1387 * 0x78 - 0x7c: reserved
1388 * 0x7d: bit 7-4: EPI descriptor major version (1)
1389 * bit 3-0: EPI descriptor minor version (0)
1390 *
1391 * ----
1392 *
1393 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1394 *
1395 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1396 *
1397 * detailed descriptor 3:
1398 * 0x5a - 0x5e: 00 00 00 fe 00
1399 * 0x5f - 0x63: PC maker part number
1400 * 0x64: LCD supplier revision #
1401 * 0x65 - 0x6b: manufacturer part number
1402 *
1403 * detailed descriptor 4:
1404 * 0x6c - 0x70: 00 00 00 fe 00
1405 * 0x71 - 0x78: smbus nits values (whut)
1406 * 0x79: number of lvds channels (1 or 2)
1407 * 0x7A: panel self test (1 if present)
1408 * and then dummy terminator
1409 *
1410 * SPWG also says something strange about the LSB of detailed descriptor 1:
1411 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1412 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001413/*
1414 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1415 */
1416
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001417void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1418{
1419 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001420 edid_fb.x_resolution = edid->x_resolution;
1421 edid_fb.y_resolution = edid->y_resolution;
1422 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001423 /* In the case of (e.g.) 24bpp, the convention nowadays
1424 * seems to be to round it up to the nearest reasonable
1425 * boundary, because otherwise the byte-packing is hideous.
1426 * So, for example, in RGB with no alpha, the bytes are still
1427 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1428 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1429 * and in 4:4:4 mode, they are packed into 16-bit words.
1430 * Good call on the hardware guys part.
1431 * It's not clear we're covering all cases here, but
1432 * I'm not sure with grahpics you ever can.
1433 */
1434 edid_fb.bits_per_pixel = edid->bpp;
1435 switch(edid->bpp){
1436 case 32:
1437 case 24:
1438 /* packed into 4-byte words */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001439 edid_fb.red_mask_pos = 16;
1440 edid_fb.red_mask_size = 8;
1441 edid_fb.green_mask_pos = 8;
1442 edid_fb.green_mask_size = 8;
1443 edid_fb.blue_mask_pos = 0;
1444 edid_fb.blue_mask_size = 8;
1445 break;
1446 case 16:
1447 /* packed into 2-byte words */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001448 edid_fb.red_mask_pos = 12;
1449 edid_fb.red_mask_size = 4;
1450 edid_fb.green_mask_pos = 8;
1451 edid_fb.green_mask_size = 4;
1452 edid_fb.blue_mask_pos = 0;
1453 edid_fb.blue_mask_size = 4;
1454 break;
1455 default:
1456 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
1457 edid->bpp);
1458 return;
1459 }
1460
1461 edid_fb.reserved_mask_pos = 0;
1462 edid_fb.reserved_mask_size = 0;
1463 vbe_valid = 1;
1464}
1465
1466int vbe_mode_info_valid(void)
1467{
1468 return vbe_valid;
1469}
1470
1471void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1472{
1473 *framebuffer = edid_fb;
1474}