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