blob: e08535dd7a82f11d4faee0c54769b5ededa5b164 [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>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070034#include <stdint.h>
35#include <string.h>
36#include <stdlib.h>
37#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070038#include <boot/coreboot_tables.h>
39#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070040
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080041struct edid_context {
42 int claims_one_point_oh;
43 int claims_one_point_two;
44 int claims_one_point_three;
45 int claims_one_point_four;
46 int nonconformant_digital_display;
47 int nonconformant_extension;
48 int did_detailed_timing;
49 int has_name_descriptor;
50 int has_range_descriptor;
51 int has_preferred_timing;
52 int has_valid_checksum;
53 int has_valid_cvt;
54 int has_valid_dummy_block;
55 int has_valid_week;
56 int has_valid_year;
57 int has_valid_detailed_blocks;
58 int has_valid_extension_count;
59 int has_valid_descriptor_ordering;
60 int has_valid_descriptor_pad;
61 int has_valid_range_descriptor;
62 int has_valid_max_dotclock;
63 int has_valid_string_termination;
64 int manufacturer_name_well_formed;
65 int seen_non_detailed_descriptor;
66 int warning_excessive_dotclock_correction;
67 int warning_zero_preferred_refresh;
68 int conformant;
69};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070070
David Hendricksa3b898a2015-08-02 18:07:48 -070071/* Stuff that isn't used anywhere but is nice to pretty-print while
72 we're decoding everything else. */
73static struct {
74 char manuf_name[4];
75 unsigned int model;
76 unsigned int serial;
77 unsigned int year;
78 unsigned int week;
79 unsigned int version[2];
80 unsigned int nonconformant;
81 unsigned int type;
82
83 unsigned int x_mm;
84 unsigned int y_mm;
85
86 unsigned int voltage;
87 unsigned int sync;
88
89 const char *syncmethod;
90 const char *range_class;
91 const char *stereo;
92} extra_info;
93
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070094static int vbe_valid;
95static struct lb_framebuffer edid_fb;
96
David Hendricksa3b898a2015-08-02 18:07:48 -070097static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070098{
David Hendricksa3b898a2015-08-02 18:07:48 -070099 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
100 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
101 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
102 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700103
David Hendricksa3b898a2015-08-02 18:07:48 -0700104 if (isupper(extra_info.manuf_name[0]) &&
105 isupper(extra_info.manuf_name[1]) &&
106 isupper(extra_info.manuf_name[2]))
107 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700108
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800109 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700110}
111
112static int
113detailed_cvt_descriptor(struct edid *out, unsigned char *x, int first)
114{
115 const unsigned char empty[3] = { 0, 0, 0 };
116 const char *names[] = { "50", "60", "75", "85" };
117 int width = 0, height = 0;
118 int valid = 1;
119 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
120
121 if (!first && !memcmp(x, empty, 3))
122 return valid;
123
124 height = x[0];
125 height |= (x[1] & 0xf0) << 4;
126 height++;
127 height *= 2;
128
129 switch (x[1] & 0x0c) {
130 case 0x00:
131 width = (height * 4) / 3; break;
132 case 0x04:
133 width = (height * 16) / 9; break;
134 case 0x08:
135 width = (height * 16) / 10; break;
136 case 0x0c:
137 width = (height * 15) / 9; break;
138 }
139
140 if (x[1] & 0x03)
141 valid = 0;
142 if (x[2] & 0x80)
143 valid = 0;
144 if (!(x[2] & 0x1f))
145 valid = 0;
146
147 fifty = (x[2] & 0x10);
148 sixty = (x[2] & 0x08);
149 seventyfive = (x[2] & 0x04);
150 eightyfive = (x[2] & 0x02);
151 reduced = (x[2] & 0x01);
152
153 if (!valid) {
154 printk(BIOS_SPEW, " (broken)\n");
155 } else {
156 printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
157 width, height,
158 fifty ? "50 " : "",
159 sixty ? "60 " : "",
160 seventyfive ? "75 " : "",
161 eightyfive ? "85 " : "",
162 reduced ? "60RB " : "",
163 names[(x[2] & 0x60) >> 5],
164 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
165 }
166
167 return valid;
168}
169
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800170/* extract a CP437 string from a detailed subblock, checking for termination (if
171 * less than len of bytes) with LF and padded with SP.
172 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700173static char *
174extract_string(unsigned char *x, int *valid_termination, int len)
175{
176 static char ret[128];
177 int i, seen_newline = 0;
178
179 memset(ret, 0, sizeof(ret));
180
181 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800182 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700183 if (x[i] != 0x20) {
184 *valid_termination = 0;
185 return ret;
186 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800187 } else if (x[i] == 0x0a) {
188 seen_newline = 1;
189 } else {
190 /* normal characters */
191 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700192 }
193 }
194
195 return ret;
196}
197
198/* 1 means valid data */
199static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800200detailed_block(struct edid *out, unsigned char *x, int in_extension,
201 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700202{
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700203 int i;
204#if 1
205 printk(BIOS_SPEW, "Hex of detail: ");
206 for (i = 0; i < 18; i++)
207 printk(BIOS_SPEW, "%02x", x[i]);
208 printk(BIOS_SPEW, "\n");
209#endif
210
211 if (x[0] == 0 && x[1] == 0) {
212 /* Monitor descriptor block, not detailed timing descriptor. */
213 if (x[2] != 0) {
214 /* 1.3, 3.10.3 */
215 printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
216 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800217 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700218 }
219 if (x[3] != 0xfd && x[4] != 0x00) {
220 /* 1.3, 3.10.3 */
221 printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
222 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800223 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700224 }
225
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800226 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700227 if (x[3] <= 0xF) {
228 /*
229 * in principle we can decode these, if we know what they are.
230 * 0x0f seems to be common in laptop panels.
231 * 0x0e is used by EPI: http://www.epi-standard.org/
232 */
233 printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800234 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700235 }
236 switch (x[3]) {
237 case 0x10:
238 printk(BIOS_SPEW, "Dummy block\n");
239 for (i = 5; i < 18; i++)
240 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800241 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800242 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700243 case 0xF7:
244 /* TODO */
245 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800246 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700247 case 0xF8:
248 {
249 int valid_cvt = 1; /* just this block */
250 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
251 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800252 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700253 return 0;
254 }
255 for (i = 0; i < 4; i++)
256 valid_cvt &= detailed_cvt_descriptor(out, x + 6 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800257 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800258 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700259 }
260 case 0xF9:
261 /* TODO */
262 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800263 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700264 case 0xFA:
265 /* TODO */
266 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800267 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700268 case 0xFB:
269 /* TODO */
270 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800271 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700272 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800273 printk(BIOS_SPEW, "Monitor name: %s\n",
274 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800275 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800276 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800277 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700278 case 0xFD:
279 {
280 int h_max_offset = 0, h_min_offset = 0;
281 int v_max_offset = 0, v_min_offset = 0;
282 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800283 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700284 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700285 /*
286 * XXX todo: implement feature flags, vtd blocks
287 * XXX check: ranges are well-formed; block termination if no vtd
288 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800289 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700290 if (x[4] & 0x02) {
291 v_max_offset = 255;
292 if (x[4] & 0x01) {
293 v_min_offset = 255;
294 }
295 }
296 if (x[4] & 0x04) {
297 h_max_offset = 255;
298 if (x[4] & 0x03) {
299 h_min_offset = 255;
300 }
301 }
302 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800303 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700304 }
305
306 /*
307 * despite the values, this is not a bitfield.
308 */
309 switch (x[10]) {
310 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700311 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700312 break;
313 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700314 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800315 if (!c->claims_one_point_four)
316 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700317 break;
318 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700319 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700320 break;
321 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700322 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700323 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800324 if (!c->claims_one_point_four)
325 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700326 break;
327 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800328 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700329 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700330 break;
331 }
332
333 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800334 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700335 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800336 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700337 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700338 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700339 x[5] + v_min_offset, x[6] + v_max_offset,
340 x[7] + h_min_offset, x[8] + h_max_offset);
341 if (x[9])
342 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
343 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800344 if (c->claims_one_point_four)
345 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700346 printk(BIOS_SPEW, "\n");
347 }
348
349 if (is_cvt) {
350 int max_h_pixels = 0;
351
352 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
353
354 if (x[12] & 0xfc) {
355 int raw_offset = (x[12] & 0xfc) >> 2;
Patrick Georgibe71ee5d2014-12-15 22:52:14 +0100356 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
357 (x[9] * 10000) - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700358 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800359 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700360 }
361
362 max_h_pixels = x[12] & 0x03;
363 max_h_pixels <<= 8;
364 max_h_pixels |= x[13];
365 max_h_pixels *= 8;
366 if (max_h_pixels)
367 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
368
369 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
370 x[14] & 0x80 ? "4:3" : "",
371 x[14] & 0x40 ? "16:9" : "",
372 x[14] & 0x20 ? "16:10" : "",
373 x[14] & 0x10 ? "5:4" : "",
374 x[14] & 0x08 ? "15:9" : "");
375 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800376 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700377
378 printk(BIOS_SPEW, "Preferred aspect ratio: ");
379 switch((x[15] & 0xe0) >> 5) {
380 case 0x00: printk(BIOS_SPEW, "4:3"); break;
381 case 0x01: printk(BIOS_SPEW, "16:9"); break;
382 case 0x02: printk(BIOS_SPEW, "16:10"); break;
383 case 0x03: printk(BIOS_SPEW, "5:4"); break;
384 case 0x04: printk(BIOS_SPEW, "15:9"); break;
385 default: printk(BIOS_SPEW, "(broken)"); break;
386 }
387 printk(BIOS_SPEW, "\n");
388
389 if (x[15] & 0x04)
390 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
391 if (x[15] & 0x10)
392 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
393
394 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800395 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700396
397 if (x[16] & 0xf0) {
398 printk(BIOS_SPEW, "Supported display scaling:\n");
399 if (x[16] & 0x80)
400 printk(BIOS_SPEW, " Horizontal shrink\n");
401 if (x[16] & 0x40)
402 printk(BIOS_SPEW, " Horizontal stretch\n");
403 if (x[16] & 0x20)
404 printk(BIOS_SPEW, " Vertical shrink\n");
405 if (x[16] & 0x10)
406 printk(BIOS_SPEW, " Vertical stretch\n");
407 }
408
409 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800410 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700411
412 if (x[17])
413 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
414 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800415 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700416 }
417
418 /*
419 * Slightly weird to return a global, but I've never seen any
420 * EDID block wth two range descriptors, so it's harmless.
421 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800422 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700423 }
424 case 0xFE:
425 /*
426 * TODO: Two of these in a row, in the third and fourth slots,
427 * seems to be specified by SPWG: http://www.spwg.org/
428 */
429 printk(BIOS_SPEW, "ASCII string: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800430 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800431 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700432 case 0xFF:
433 printk(BIOS_SPEW, "Serial number: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800434 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800435 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700436 default:
437 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
438 return 0;
439 }
440 }
441
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800442 if (c->seen_non_detailed_descriptor && !in_extension) {
443 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700444 }
445
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800446 if (! c->did_detailed_timing){
Furquan Shaikh6b190712013-07-22 16:18:31 -0700447 /* Edid contains pixel clock in terms of 10KHz */
448 out->pixel_clock = (x[0] + (x[1] << 8)) * 10;
David Hendricksa3b898a2015-08-02 18:07:48 -0700449 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
450 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700451 out->ha = (x[2] + ((x[4] & 0xF0) << 4));
452 out->hbl = (x[3] + ((x[4] & 0x0F) << 8));
453 out->hso = (x[8] + ((x[11] & 0xC0) << 2));
454 out->hspw = (x[9] + ((x[11] & 0x30) << 4));
455 out->hborder = x[15];
456 out->va = (x[5] + ((x[7] & 0xF0) << 4));
457 out->vbl = (x[6] + ((x[7] & 0x0F) << 8));
458 out->vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
459 out->vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
460 out->vborder = x[16];
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700461 /* set up some reasonable defaults for payloads.
462 * We observe that most modern chipsets we work with
463 * tend to support rgb888 without regard to the
464 * panel bits per color or other settings. The rgb888
465 * is a convenient layout for software because
466 * it avoids the messy bit stuffing of rgb565 or rgb444.
467 * It makes a reasonable trade of memory for speed.
468 * So, set up the default for
469 * 32 bits per pixel
470 * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries)
471 * The mainboard can modify these if needed, though
472 * we have yet to see a case where that will happen.
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700473 * The existing ARM mainboards don't even call this function
474 * so this will not affect them.
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700475 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700476 out->framebuffer_bits_per_pixel = 32;
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700477
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700478 out->x_resolution = ALIGN(out->ha *
479 ((out->framebuffer_bits_per_pixel + 7) / 8),
480 64) / (out->framebuffer_bits_per_pixel/8);
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700481 out->y_resolution = out->va;
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700482 out->bytes_per_line = ALIGN(out->ha *
483 ((out->framebuffer_bits_per_pixel + 7)/8),
484 64);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700485 printk(BIOS_SPEW, "Did detailed timing\n");
486 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800487 c->did_detailed_timing = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700488 switch ((x[17] & 0x18) >> 3) {
489 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700490 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700491 break;
492 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700493 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700494 break;
495 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700496 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700497 break;
498 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700499 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700500 break;
501 }
502 out->pvsync = (x[17] & (1 << 2)) ? '+' : '-';
503 out->phsync = (x[17] & (1 << 1)) ? '+' : '-';
504 switch (x[17] & 0x61) {
505 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700506 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700507 break;
508 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700509 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700510 break;
511 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700512 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700513 break;
514 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700515 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700516 break;
517 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700518 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700519 break;
520 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700521 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700522 break;
523 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700524 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700525 break;
526 }
527
Furquan Shaikh6b190712013-07-22 16:18:31 -0700528 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700529 " %04x %04x %04x %04x hborder %x\n"
530 " %04x %04x %04x %04x vborder %x\n"
531 " %chsync %cvsync%s%s %s\n",
Furquan Shaikh6b190712013-07-22 16:18:31 -0700532 out->pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700533 extra_info.x_mm,
534 extra_info.y_mm,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700535 out->ha, out->ha + out->hso, out->ha + out->hso + out->hspw,
536 out->ha + out->hbl, out->hborder,
537 out->va, out->va + out->vso, out->va + out->vso + out->vspw,
538 out->va + out->vbl, out->vborder,
539 out->phsync, out->pvsync,
David Hendricksa3b898a2015-08-02 18:07:48 -0700540 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
541 extra_info.stereo
542 );
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700543 return 1;
544}
545
546static int
547do_checksum(unsigned char *x)
548{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800549 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600550 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700551 {
552 unsigned char sum = 0;
553 int i;
554 for (i = 0; i < 128; i++)
555 sum += x[i];
556 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600557 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700558 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800559 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700560 printk(BIOS_SPEW, " (valid)");
561 }
562 }
563 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800564 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700565}
566
567/* CEA extension */
568
569static const char *
570audio_format(unsigned char x)
571{
572 switch (x) {
573 case 0: return "RESERVED";
574 case 1: return "Linear PCM";
575 case 2: return "AC-3";
576 case 3: return "MPEG 1 (Layers 1 & 2)";
577 case 4: return "MPEG 1 Layer 3 (MP3)";
578 case 5: return "MPEG2 (multichannel)";
579 case 6: return "AAC";
580 case 7: return "DTS";
581 case 8: return "ATRAC";
582 case 9: return "One Bit Audio";
583 case 10: return "Dolby Digital+";
584 case 11: return "DTS-HD";
585 case 12: return "MAT (MLP)";
586 case 13: return "DST";
587 case 14: return "WMA Pro";
588 case 15: return "RESERVED";
589 }
590 return "BROKEN"; /* can't happen */
591}
592
593static void
594cea_audio_block(unsigned char *x)
595{
596 int i, format;
597 int length = x[0] & 0x1f;
598
599 if (length % 3) {
600 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
601 /* XXX non-conformant */
602 return;
603 }
604
605 for (i = 1; i < length; i += 3) {
606 format = (x[i] & 0x78) >> 3;
607 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
608 x[i] & 0x07);
609 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
610 (x[i+1] & 0x40) ? " 192" : "",
611 (x[i+1] & 0x20) ? " 176.4" : "",
612 (x[i+1] & 0x10) ? " 96" : "",
613 (x[i+1] & 0x08) ? " 88.2" : "",
614 (x[i+1] & 0x04) ? " 48" : "",
615 (x[i+1] & 0x02) ? " 44.1" : "",
616 (x[i+1] & 0x01) ? " 32" : "");
617 if (format == 1) {
618 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
619 (x[2] & 0x04) ? " 24" : "",
620 (x[2] & 0x02) ? " 20" : "",
621 (x[2] & 0x01) ? " 16" : "");
622 } else if (format <= 8) {
623 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
624 }
625 }
626}
627
628static void
629cea_video_block(unsigned char *x)
630{
631 int i;
632 int length = x[0] & 0x1f;
633
634 for (i = 1; i < length; i++)
635 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
636 x[i] & 0x80 ? "(native)" : "");
637}
638
639static void
640cea_hdmi_block(struct edid *out, unsigned char *x)
641{
642 int length = x[0] & 0x1f;
643
644 printk(BIOS_SPEW, " (HDMI)\n");
645 printk(BIOS_SPEW,
646 " Source physical address %d.%d.%d.%d\n",
647 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
648
649 if (length > 5) {
650 if (x[6] & 0x80)
651 printk(BIOS_SPEW, " Supports_AI\n");
652 if (x[6] & 0x40)
653 printk(BIOS_SPEW, " DC_48bit\n");
654 if (x[6] & 0x20)
655 printk(BIOS_SPEW, " DC_36bit\n");
656 if (x[6] & 0x10)
657 printk(BIOS_SPEW, " DC_30bit\n");
658 if (x[6] & 0x08)
659 printk(BIOS_SPEW, " DC_Y444\n");
660 /* two reserved */
661 if (x[6] & 0x01)
662 printk(BIOS_SPEW, " DVI_Dual\n");
663 }
664
665 if (length > 6)
666 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
667
668 /* XXX the walk here is really ugly, and needs to be length-checked */
669 if (length > 7) {
670 int b = 0;
671
672 if (x[8] & 0x80) {
673 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
674 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
675 b += 2;
676 }
677
678 if (x[8] & 0x40) {
679 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
680 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
681 b += 2;
682 }
683
684 if (x[8] & 0x20) {
685 int mask = 0, formats = 0;
686 int len_xx, len_3d;
687 printk(BIOS_SPEW, " Extended HDMI video details:\n");
688 if (x[9 + b] & 0x80)
689 printk(BIOS_SPEW, " 3D present\n");
690 if ((x[9 + b] & 0x60) == 0x20) {
691 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
692 formats = 1;
693 }
694 if ((x[9 + b] & 0x60) == 0x40) {
695 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
696 formats = 1;
697 mask = 1;
698 }
699 switch (x[9 + b] & 0x18) {
700 case 0x00: break;
701 case 0x08:
702 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
703 break;
704 case 0x10:
705 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
706 break;
707 case 0x18:
708 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
709 break;
710 }
711 len_xx = (x[10 + b] & 0xe0) >> 5;
712 len_3d = (x[10 + b] & 0x1f) >> 0;
713 b += 2;
714
715 if (len_xx) {
716 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
717 " document\n", len_xx);
718 b += len_xx;
719 }
720
721 if (len_3d) {
722 if (formats) {
723 if (x[9 + b] & 0x01)
724 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
725 if (x[10 + b] & 0x40)
726 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
727 if (x[10 + b] & 0x01)
728 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
729 b += 2;
730 }
731 if (mask) {
732 int i;
733 printk(BIOS_SPEW, " 3D VIC indices:");
734 /* worst bit ordering ever */
735 for (i = 0; i < 8; i++)
736 if (x[10 + b] & (1 << i))
737 printk(BIOS_SPEW, " %d", i);
738 for (i = 0; i < 8; i++)
739 if (x[9 + b] & (1 << i))
740 printk(BIOS_SPEW, " %d", i + 8);
741 printk(BIOS_SPEW, "\n");
742 b += 2;
743 }
744
745 /*
746 * XXX list of nibbles:
747 * 2D_VIC_Order_X
748 * 3D_Structure_X
749 * (optionally: 3D_Detail_X and reserved)
750 */
751 }
752
753 }
754 }
755}
756
757static void
758cea_block(struct edid *out, unsigned char *x)
759{
760 unsigned int oui;
761
762 switch ((x[0] & 0xe0) >> 5) {
763 case 0x01:
764 printk(BIOS_SPEW, " Audio data block\n");
765 cea_audio_block(x);
766 break;
767 case 0x02:
768 printk(BIOS_SPEW, " Video data block\n");
769 cea_video_block(x);
770 break;
771 case 0x03:
772 /* yes really, endianness lols */
773 oui = (x[3] << 16) + (x[2] << 8) + x[1];
774 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
775 if (oui == 0x000c03)
776 cea_hdmi_block(out, x);
777 else
778 printk(BIOS_SPEW, "\n");
779 break;
780 case 0x04:
781 printk(BIOS_SPEW, " Speaker allocation data block\n");
782 break;
783 case 0x05:
784 printk(BIOS_SPEW, " VESA DTC data block\n");
785 break;
786 case 0x07:
787 printk(BIOS_SPEW, " Extended tag: ");
788 switch (x[1]) {
789 case 0x00:
790 printk(BIOS_SPEW, "video capability data block\n");
791 break;
792 case 0x01:
793 printk(BIOS_SPEW, "vendor-specific video data block\n");
794 break;
795 case 0x02:
796 printk(BIOS_SPEW, "VESA video display device information data block\n");
797 break;
798 case 0x03:
799 printk(BIOS_SPEW, "VESA video data block\n");
800 break;
801 case 0x04:
802 printk(BIOS_SPEW, "HDMI video data block\n");
803 break;
804 case 0x05:
805 printk(BIOS_SPEW, "Colorimetry data block\n");
806 break;
807 case 0x10:
808 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
809 break;
810 case 0x11:
811 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
812 break;
813 case 0x12:
814 printk(BIOS_SPEW, "HDMI audio data block\n");
815 break;
816 default:
817 if (x[1] >= 6 && x[1] <= 15)
818 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
819 else if (x[1] >= 19 && x[1] <= 31)
820 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
821 else
822 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
823 break;
824 }
825 break;
826 default:
827 {
828 int tag = (*x & 0xe0) >> 5;
829 int length = *x & 0x1f;
830 printk(BIOS_SPEW,
831 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
832 break;
833 }
834 }
835}
836
837static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800838parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700839{
840 int ret = 0;
841 int version = x[1];
842 int offset = x[2];
843 unsigned char *detailed;
844
845 if (version >= 1) do {
846 if (version == 1 && x[3] != 0)
847 ret = 1;
848
849 if (offset < 4)
850 break;
851
852 if (version < 3) {
853 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
854 if (offset - 4 > 0)
855 /* do stuff */ ;
856 } else if (version == 3) {
857 int i;
858 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
859 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
860 cea_block(out, x + i);
861 }
862 }
863
864 if (version >= 2) {
865 if (x[3] & 0x80)
866 printk(BIOS_SPEW, "Underscans PC formats by default\n");
867 if (x[3] & 0x40)
868 printk(BIOS_SPEW, "Basic audio support\n");
869 if (x[3] & 0x20)
870 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
871 if (x[3] & 0x10)
872 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
873 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
874 }
875
876 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
877 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800878 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700879 } while (0);
880
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800881 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700882 return ret;
883}
884
885/* generic extension code */
886
887static void
888extension_version(struct edid *out, unsigned char *x)
889{
890 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
891}
892
893static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800894parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700895{
896 int conformant_extension = 0;
897 printk(BIOS_SPEW, "\n");
898
899 switch(x[0]) {
900 case 0x02:
901 printk(BIOS_SPEW, "CEA extension block\n");
902 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800903 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700904 break;
905 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
906 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
907 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
908 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
909 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800910 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700911 default:
912 printk(BIOS_SPEW, "Unknown extension block\n");
913 break;
914 }
915
916 printk(BIOS_SPEW, "\n");
917
918 return conformant_extension;
919}
920
921static const struct {
922 int x, y, refresh;
923} established_timings[] = {
924 /* 0x23 bit 7 - 0 */
925 {720, 400, 70},
926 {720, 400, 88},
927 {640, 480, 60},
928 {640, 480, 67},
929 {640, 480, 72},
930 {640, 480, 75},
931 {800, 600, 56},
932 {800, 600, 60},
933 /* 0x24 bit 7 - 0 */
934 {800, 600, 72},
935 {800, 600, 75},
936 {832, 624, 75},
937 {1280, 768, 87},
938 {1024, 768, 60},
939 {1024, 768, 70},
940 {1024, 768, 75},
941 {1280, 1024, 75},
942 /* 0x25 bit 7*/
943 {1152, 870, 75},
944};
945
946static void print_subsection(const char *name, unsigned char *edid, int start,
947 int end)
948{
949 int i;
950
951 printk(BIOS_SPEW, "%s:", name);
952 for (i = strlen(name); i < 15; i++)
953 printk(BIOS_SPEW, " ");
954 for (i = start; i <= end; i++)
955 printk(BIOS_SPEW, " %02x", edid[i]);
956 printk(BIOS_SPEW, "\n");
957}
958
959static void dump_breakdown(unsigned char *edid)
960{
961 printk(BIOS_SPEW, "Extracted contents:\n");
962 print_subsection("header", edid, 0, 7);
963 print_subsection("serial number", edid, 8, 17);
964 print_subsection("version", edid,18, 19);
965 print_subsection("basic params", edid, 20, 24);
966 print_subsection("chroma info", edid, 25, 34);
967 print_subsection("established", edid, 35, 37);
968 print_subsection("standard", edid, 38, 53);
969 print_subsection("descriptor 1", edid, 54, 71);
970 print_subsection("descriptor 2", edid, 72, 89);
971 print_subsection("descriptor 3", edid, 90, 107);
972 print_subsection("descriptor 4", edid, 108, 125);
973 print_subsection("extensions", edid, 126, 126);
974 print_subsection("checksum", edid, 127, 127);
975 printk(BIOS_SPEW, "\n");
976}
977
978/*
979 * Given a raw edid bloc, decode it into a form
980 * that other parts of coreboot can use -- mainly
981 * graphics bringup functions. The raw block is
982 * required to be 128 bytes long, per the standard,
983 * but we have no way of checking this minimum length.
984 * We accept what we are given.
985 */
986int decode_edid(unsigned char *edid, int size, struct edid *out)
987{
988 int analog, i;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800989 struct edid_context c = {
990 .has_valid_cvt = 1,
991 .has_valid_dummy_block = 1,
992 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +0800993 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800994 .has_valid_descriptor_pad = 1,
995 .has_valid_range_descriptor = 1,
996 .has_valid_max_dotclock = 1,
997 .has_valid_string_termination = 1,
998 .conformant = 1,
999 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001000
1001 dump_breakdown(edid);
1002
1003 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1004 printk(BIOS_SPEW, "No header found\n");
1005 return 1;
1006 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001007
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001008 memset(out, 0, sizeof(*out));
David Hendricksa3b898a2015-08-02 18:07:48 -07001009 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001010 c.manufacturer_name_well_formed = 1;
1011
David Hendricksa3b898a2015-08-02 18:07:48 -07001012 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1013 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001014 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1015
1016 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001017 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001018 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1019 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1020 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001021 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001022
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001023 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001024 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001025 if (edid[0x11] > 0x0f) {
1026 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001027 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001028 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001029 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001030 extra_info.week = edid[0x10];
1031 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001032 } else {
1033 /* we know it's at least 2013, when this code was written */
1034 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001035 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001036 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001037 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001038 extra_info.week = edid[0x10];
1039 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001040 }
1041 }
1042 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001043 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001044
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001045 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001046 extra_info.version[0] = edid[0x12];
1047 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001048
1049 if (edid[0x12] == 1) {
1050 if (edid[0x13] > 4) {
1051 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1052 edid[0x13] = 4;
1053 }
1054 switch (edid[0x13]) {
1055 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001056 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001057 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001058 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001059 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001060 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001061 default:
1062 break;
1063 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001064 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001065 }
1066
1067 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001068 if (edid[0x14] & 0x80) {
1069 int conformance_mask;
1070 analog = 0;
1071 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001072 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001073 conformance_mask = 0;
1074 if ((edid[0x14] & 0x70) == 0x00)
1075 printk(BIOS_SPEW, "Color depth is undefined\n");
1076 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001077 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001078 else
1079 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1080 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001081 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1082 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001083
1084 switch (edid[0x14] & 0x0f) {
1085 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1086 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1087 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1088 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1089 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1090 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1091 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001092 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001093 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001094 extra_info.type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001095 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001096 conformance_mask = 0x7E;
1097 if (edid[0x14] & 0x01) {
1098 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1099 }
1100 } else
1101 conformance_mask = 0x7F;
1102
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001103 if (!c.nonconformant_digital_display)
1104 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001105 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001106 } else {
1107 analog = 1;
1108 int voltage = (edid[0x14] & 0x60) >> 5;
1109 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001110 extra_info.voltage = voltage;
1111 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001112
1113 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1114 voltage == 3 ? "0.7/0.7" :
1115 voltage == 2 ? "1.0/0.4" :
1116 voltage == 1 ? "0.714/0.286" :
1117 "0.7/0.3");
1118
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001119 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001120 if (edid[0x14] & 0x10)
1121 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1122 else
1123 printk(BIOS_SPEW, "Blank level equals black level\n");
1124 } else if (edid[0x14] & 0x10) {
1125 /*
1126 * XXX this is just the X text. 1.3 says "if set, display expects
1127 * a blank-to-black setup or pedestal per appropriate Signal
1128 * Level Standard". Whatever _that_ means.
1129 */
1130 printk(BIOS_SPEW, "Configurable signal levels\n");
1131 }
1132
1133 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1134 sync & 0x04 ? "Composite " : "",
1135 sync & 0x02 ? "SyncOnGreen " : "",
1136 sync & 0x01 ? "Serration " : "");
1137 }
1138
1139
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001140 if (edid[0x15] && edid[0x16]) {
1141 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1142 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001143 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001144 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1145 unsigned int ratio = 100000/(edid[0x15] + 99);
1146 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1147 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001148 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1149 unsigned int ratio = 100000/(edid[0x16] + 99);
1150 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1151 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001152 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001153 } else {
1154 /* Either or both can be zero for 1.3 and before */
1155 printk(BIOS_SPEW, "Image size is variable\n");
1156 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001157
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001158 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001159 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001160 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1161 else
1162 /* XXX Technically 1.3 doesn't say this... */
1163 printk(BIOS_SPEW, "Gamma: 1.0\n");
1164 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1165 printk(BIOS_SPEW, "Check DPMS levels\n");
1166 if (edid[0x18] & 0xE0) {
1167 printk(BIOS_SPEW, "DPMS levels:");
1168 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1169 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1170 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1171 printk(BIOS_SPEW, "\n");
1172 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001173
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001174 /* FIXME: this is from 1.4 spec, check earlier */
1175 if (analog) {
1176 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001177 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1178 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1179 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1180 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001181 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001182 } else {
1183 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1184 if (edid[0x18] & 0x10)
1185 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1186 if (edid[0x18] & 0x08)
1187 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1188 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001189 }
1190
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001191 if (edid[0x18] & 0x04)
1192 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1193 if (edid[0x18] & 0x02) {
1194 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001195 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001196 }
1197 if (edid[0x18] & 0x01)
1198 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1199
1200 /* XXX color section */
1201
1202 printk(BIOS_SPEW, "Established timings supported:\n");
1203 /* it's not yet clear we want all this stuff in the edid struct.
1204 * Let's wait.
1205 */
1206 for (i = 0; i < 17; i++) {
1207 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1208 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1209 established_timings[i].y, established_timings[i].refresh);
1210 }
1211 }
1212
1213 printk(BIOS_SPEW, "Standard timings supported:\n");
1214 for (i = 0; i < 8; i++) {
1215 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1216 unsigned int x, y = 0, refresh;
1217
1218 if (b1 == 0x01 && b2 == 0x01)
1219 continue;
1220
1221 if (b1 == 0) {
1222 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1223 continue;
1224 }
1225 x = (b1 + 31) * 8;
1226 switch ((b2 >> 6) & 0x3) {
1227 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001228 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001229 y = x * 10 / 16;
1230 else
1231 y = x;
1232 break;
1233 case 0x01:
1234 y = x * 3 / 4;
1235 break;
1236 case 0x02:
1237 y = x * 4 / 5;
1238 break;
1239 case 0x03:
1240 y = x * 9 / 16;
1241 break;
1242 }
1243 refresh = 60 + (b2 & 0x3f);
1244
1245 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
1246 }
1247
1248 /* detailed timings */
1249 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001250 for (i = 0; i < 4; i++) {
1251 c.has_valid_detailed_blocks &= detailed_block(
1252 out, edid + 0x36 + i * 18, 0, &c);
1253 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1254 {
1255 /* not really accurate... */
1256 c.has_preferred_timing = 0;
1257 }
1258 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001259
1260 /* check this, 1.4 verification guide says otherwise */
1261 if (edid[0x7e]) {
1262 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1263 /* 2 is impossible because of the block map */
1264 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001265 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001266 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001267 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001268 }
1269
1270 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001271 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001272
1273 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1274 * the extension parsing loop below. Since v2.0 was quickly deprecated
1275 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1276 * that case now and can fix it when we need to use a real 2.0 panel.
1277 */
1278 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001279 c.nonconformant_extension +=
1280 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001281
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001282 if (c.claims_one_point_four) {
1283 if (c.nonconformant_digital_display ||
1284 !c.has_valid_string_termination ||
1285 !c.has_valid_descriptor_pad ||
1286 !c.has_preferred_timing)
1287 c.conformant = 0;
1288 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001289 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001290 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001291 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001292 c.nonconformant_digital_display);
1293 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001294 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001295 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001296 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001297 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001298 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001299 } else if (c.claims_one_point_three) {
1300 if (c.nonconformant_digital_display ||
1301 !c.has_valid_string_termination ||
1302 !c.has_valid_descriptor_pad ||
1303 !c.has_preferred_timing) {
1304 c.conformant = 0;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001305 }
1306 /**
1307 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1308 * has_range_descriptor are both required. These fields are
1309 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1310 * don't have them. As a workaround, we only print warning
1311 * messages.
1312 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001313 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001314 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001315 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001316 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1317 "fully conform to EDID 1.3.\n");
1318
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001319 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001320 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001321 c.nonconformant_digital_display);
1322 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001323 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001324 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001325 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001326 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001327 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001328 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001329 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001330 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001331 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001332 } else if (c.claims_one_point_two) {
1333 if (c.nonconformant_digital_display ||
1334 !c.has_valid_string_termination)
1335 c.conformant = 0;
1336 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001337 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001338 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001339 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001340 c.nonconformant_digital_display);
1341 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001342 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001343 } else if (c.claims_one_point_oh) {
1344 if (c.seen_non_detailed_descriptor)
1345 c.conformant = 0;
1346 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001347 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001348 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001349 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1350 }
1351
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001352 if (c.nonconformant_extension ||
1353 !c.has_valid_checksum ||
1354 !c.has_valid_cvt ||
1355 !c.has_valid_year ||
1356 !c.has_valid_week ||
1357 !c.has_valid_detailed_blocks ||
1358 !c.has_valid_dummy_block ||
1359 !c.has_valid_extension_count ||
1360 !c.has_valid_descriptor_ordering ||
1361 !c.has_valid_range_descriptor ||
1362 !c.manufacturer_name_well_formed) {
1363 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001364 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001365 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001366 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001367 c.nonconformant_extension);
1368 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001369 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001370 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001371 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001372 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001373 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001374 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001375 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001376 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001377 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001378 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001379 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001380 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001381 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001382 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001383 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001384 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001385 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001386 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001387 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001388 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001389 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1390 }
1391
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001392 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001393 printk(BIOS_ERR,
1394 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001395 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001396 printk(BIOS_ERR,
1397 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001398 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001399}
1400
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001401/*
1402 * Notes on panel extensions: (TODO, implement me in the code)
1403 *
1404 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1405 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1406 * 0x6c: 00 00 00 0e 00
1407 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1408 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1409 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1410 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1411 * bit 4: DE polarity (0 high active 1 low active)
1412 * bit 3-0: interface (0000 LVDS TFT
1413 * 0001 mono STN 4/8bit
1414 * 0010 color STN 8/16 bit
1415 * 0011 18 bit tft
1416 * 0100 24 bit tft
1417 * 0101 tmds
1418 * else reserved)
1419 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1420 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1421 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1422 * else time in 10ms (10ms to 150ms))
1423 * bit 3-0: total poweron seq delay (as above)
1424 * 0x75: contrast power on/off seq delay, same as 0x74
1425 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1426 * bit 6: backlight enabled at boot (0 on 1 off)
1427 * bit 5-0: backlight brightness control steps (0..63)
1428 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1429 * 0x78 - 0x7c: reserved
1430 * 0x7d: bit 7-4: EPI descriptor major version (1)
1431 * bit 3-0: EPI descriptor minor version (0)
1432 *
1433 * ----
1434 *
1435 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1436 *
1437 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1438 *
1439 * detailed descriptor 3:
1440 * 0x5a - 0x5e: 00 00 00 fe 00
1441 * 0x5f - 0x63: PC maker part number
1442 * 0x64: LCD supplier revision #
1443 * 0x65 - 0x6b: manufacturer part number
1444 *
1445 * detailed descriptor 4:
1446 * 0x6c - 0x70: 00 00 00 fe 00
1447 * 0x71 - 0x78: smbus nits values (whut)
1448 * 0x79: number of lvds channels (1 or 2)
1449 * 0x7A: panel self test (1 if present)
1450 * and then dummy terminator
1451 *
1452 * SPWG also says something strange about the LSB of detailed descriptor 1:
1453 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1454 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001455/*
1456 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1457 */
1458
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001459void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1460{
1461 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001462 edid_fb.x_resolution = edid->x_resolution;
1463 edid_fb.y_resolution = edid->y_resolution;
1464 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001465 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001466 * seems to be to round it up to the nearest reasonable
1467 * boundary, because otherwise the byte-packing is hideous.
1468 * So, for example, in RGB with no alpha, the bytes are still
1469 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1470 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1471 * and in 4:4:4 mode, they are packed into 16-bit words.
1472 * Good call on the hardware guys part.
1473 * It's not clear we're covering all cases here, but
1474 * I'm not sure with grahpics you ever can.
1475 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001476 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001477 edid_fb.reserved_mask_pos = 0;
1478 edid_fb.reserved_mask_size = 0;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001479 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001480 case 32:
1481 case 24:
1482 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001483 edid_fb.reserved_mask_pos = 24;
1484 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001485 edid_fb.red_mask_pos = 16;
1486 edid_fb.red_mask_size = 8;
1487 edid_fb.green_mask_pos = 8;
1488 edid_fb.green_mask_size = 8;
1489 edid_fb.blue_mask_pos = 0;
1490 edid_fb.blue_mask_size = 8;
1491 break;
1492 case 16:
1493 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001494 edid_fb.red_mask_pos = 11;
1495 edid_fb.red_mask_size = 5;
1496 edid_fb.green_mask_pos = 5;
1497 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001498 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001499 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001500 break;
1501 default:
1502 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001503 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001504 return;
1505 }
1506
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001507 vbe_valid = 1;
1508}
1509
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001510#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001511int vbe_mode_info_valid(void)
1512{
1513 return vbe_valid;
1514}
1515
1516void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1517{
1518 *framebuffer = edid_fb;
1519}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001520#endif