blob: 8c8ab6f38d119720d7e1a8cf57376d3db87570cc [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
Douglas Anderson14dd3702015-10-28 11:19:57 -0700113detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700114{
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++)
Douglas Anderson14dd3702015-10-28 11:19:57 -0700256 valid_cvt &= detailed_cvt_descriptor(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 */
David Hendricks7dbf9c62015-07-30 18:49:48 -0700448 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
Vladimir Serbinenko551cff02015-10-10 23:58:08 +0200449 /*
450 LVDS supports following pixel clocks
451 25000...112000 kHz: single channel
452 80000...224000 kHz: dual channel
453 There is some overlap in theoretically supported
454 pixel clock between single-channel and dual-channel.
455 In practice with current panels all panels
456 <= 75200 kHz: single channel
457 >= 97750 kHz: dual channel
458 We have no samples between those values, so put a
459 threshold at 95000 kHz. If we get anything over
460 95000 kHz with single channel, we can make this
461 more sofisticated but it's currently not needed.
462 */
463 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
David Hendricksa3b898a2015-08-02 18:07:48 -0700464 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
465 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
David Hendricks7dbf9c62015-07-30 18:49:48 -0700466 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
467 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
468 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
469 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
470 out->mode.hborder = x[15];
471 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
472 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
473 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
474 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
475 out->mode.vborder = x[16];
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700476 /* set up some reasonable defaults for payloads.
477 * We observe that most modern chipsets we work with
478 * tend to support rgb888 without regard to the
479 * panel bits per color or other settings. The rgb888
480 * is a convenient layout for software because
481 * it avoids the messy bit stuffing of rgb565 or rgb444.
482 * It makes a reasonable trade of memory for speed.
483 * So, set up the default for
484 * 32 bits per pixel
485 * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries)
486 * The mainboard can modify these if needed, though
487 * we have yet to see a case where that will happen.
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700488 * The existing ARM mainboards don't even call this function
489 * so this will not affect them.
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700490 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700491 out->framebuffer_bits_per_pixel = 32;
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700492
David Hendricks7dbf9c62015-07-30 18:49:48 -0700493 out->x_resolution = ALIGN(out->mode.ha *
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700494 ((out->framebuffer_bits_per_pixel + 7) / 8),
495 64) / (out->framebuffer_bits_per_pixel/8);
David Hendricks7dbf9c62015-07-30 18:49:48 -0700496 out->y_resolution = out->mode.va;
497 out->bytes_per_line = ALIGN(out->mode.ha *
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700498 ((out->framebuffer_bits_per_pixel + 7)/8),
499 64);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700500 printk(BIOS_SPEW, "Did detailed timing\n");
501 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800502 c->did_detailed_timing = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700503 switch ((x[17] & 0x18) >> 3) {
504 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700505 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700506 break;
507 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700508 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700509 break;
510 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700511 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700512 break;
513 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700514 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700515 break;
516 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700517 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
518 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700519 switch (x[17] & 0x61) {
520 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700521 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700522 break;
523 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700524 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700525 break;
526 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700527 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700528 break;
529 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700530 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700531 break;
532 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700533 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700534 break;
535 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700536 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700537 break;
538 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700539 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700540 break;
541 }
542
Furquan Shaikh6b190712013-07-22 16:18:31 -0700543 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700544 " %04x %04x %04x %04x hborder %x\n"
545 " %04x %04x %04x %04x vborder %x\n"
546 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700547 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700548 extra_info.x_mm,
549 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700550 out->mode.ha, out->mode.ha + out->mode.hso,
551 out->mode.ha + out->mode.hso + out->mode.hspw,
552 out->mode.ha + out->mode.hbl, out->mode.hborder,
553 out->mode.va, out->mode.va + out->mode.vso,
554 out->mode.va + out->mode.vso + out->mode.vspw,
555 out->mode.va + out->mode.vbl, out->mode.vborder,
556 out->mode.phsync, out->mode.pvsync,
David Hendricksa3b898a2015-08-02 18:07:48 -0700557 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700558 extra_info.stereo);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700559 return 1;
560}
561
562static int
563do_checksum(unsigned char *x)
564{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800565 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600566 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700567 {
568 unsigned char sum = 0;
569 int i;
570 for (i = 0; i < 128; i++)
571 sum += x[i];
572 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600573 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700574 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800575 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700576 printk(BIOS_SPEW, " (valid)");
577 }
578 }
579 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800580 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700581}
582
583/* CEA extension */
584
585static const char *
586audio_format(unsigned char x)
587{
588 switch (x) {
589 case 0: return "RESERVED";
590 case 1: return "Linear PCM";
591 case 2: return "AC-3";
592 case 3: return "MPEG 1 (Layers 1 & 2)";
593 case 4: return "MPEG 1 Layer 3 (MP3)";
594 case 5: return "MPEG2 (multichannel)";
595 case 6: return "AAC";
596 case 7: return "DTS";
597 case 8: return "ATRAC";
598 case 9: return "One Bit Audio";
599 case 10: return "Dolby Digital+";
600 case 11: return "DTS-HD";
601 case 12: return "MAT (MLP)";
602 case 13: return "DST";
603 case 14: return "WMA Pro";
604 case 15: return "RESERVED";
605 }
606 return "BROKEN"; /* can't happen */
607}
608
609static void
610cea_audio_block(unsigned char *x)
611{
612 int i, format;
613 int length = x[0] & 0x1f;
614
615 if (length % 3) {
616 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
617 /* XXX non-conformant */
618 return;
619 }
620
621 for (i = 1; i < length; i += 3) {
622 format = (x[i] & 0x78) >> 3;
623 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
624 x[i] & 0x07);
625 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
626 (x[i+1] & 0x40) ? " 192" : "",
627 (x[i+1] & 0x20) ? " 176.4" : "",
628 (x[i+1] & 0x10) ? " 96" : "",
629 (x[i+1] & 0x08) ? " 88.2" : "",
630 (x[i+1] & 0x04) ? " 48" : "",
631 (x[i+1] & 0x02) ? " 44.1" : "",
632 (x[i+1] & 0x01) ? " 32" : "");
633 if (format == 1) {
634 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
635 (x[2] & 0x04) ? " 24" : "",
636 (x[2] & 0x02) ? " 20" : "",
637 (x[2] & 0x01) ? " 16" : "");
638 } else if (format <= 8) {
639 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
640 }
641 }
642}
643
644static void
645cea_video_block(unsigned char *x)
646{
647 int i;
648 int length = x[0] & 0x1f;
649
650 for (i = 1; i < length; i++)
651 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
652 x[i] & 0x80 ? "(native)" : "");
653}
654
655static void
656cea_hdmi_block(struct edid *out, unsigned char *x)
657{
658 int length = x[0] & 0x1f;
659
Yakir Yang85810cc2015-10-27 16:17:13 +0800660 out->hdmi_monitor_detected = 1;
661
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700662 printk(BIOS_SPEW, " (HDMI)\n");
663 printk(BIOS_SPEW,
664 " Source physical address %d.%d.%d.%d\n",
665 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
666
667 if (length > 5) {
668 if (x[6] & 0x80)
669 printk(BIOS_SPEW, " Supports_AI\n");
670 if (x[6] & 0x40)
671 printk(BIOS_SPEW, " DC_48bit\n");
672 if (x[6] & 0x20)
673 printk(BIOS_SPEW, " DC_36bit\n");
674 if (x[6] & 0x10)
675 printk(BIOS_SPEW, " DC_30bit\n");
676 if (x[6] & 0x08)
677 printk(BIOS_SPEW, " DC_Y444\n");
678 /* two reserved */
679 if (x[6] & 0x01)
680 printk(BIOS_SPEW, " DVI_Dual\n");
681 }
682
683 if (length > 6)
684 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
685
686 /* XXX the walk here is really ugly, and needs to be length-checked */
687 if (length > 7) {
688 int b = 0;
689
690 if (x[8] & 0x80) {
691 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
692 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
693 b += 2;
694 }
695
696 if (x[8] & 0x40) {
697 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
698 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
699 b += 2;
700 }
701
702 if (x[8] & 0x20) {
703 int mask = 0, formats = 0;
704 int len_xx, len_3d;
705 printk(BIOS_SPEW, " Extended HDMI video details:\n");
706 if (x[9 + b] & 0x80)
707 printk(BIOS_SPEW, " 3D present\n");
708 if ((x[9 + b] & 0x60) == 0x20) {
709 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
710 formats = 1;
711 }
712 if ((x[9 + b] & 0x60) == 0x40) {
713 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
714 formats = 1;
715 mask = 1;
716 }
717 switch (x[9 + b] & 0x18) {
718 case 0x00: break;
719 case 0x08:
720 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
721 break;
722 case 0x10:
723 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
724 break;
725 case 0x18:
726 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
727 break;
728 }
729 len_xx = (x[10 + b] & 0xe0) >> 5;
730 len_3d = (x[10 + b] & 0x1f) >> 0;
731 b += 2;
732
733 if (len_xx) {
734 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
735 " document\n", len_xx);
736 b += len_xx;
737 }
738
739 if (len_3d) {
740 if (formats) {
741 if (x[9 + b] & 0x01)
742 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
743 if (x[10 + b] & 0x40)
744 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
745 if (x[10 + b] & 0x01)
746 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
747 b += 2;
748 }
749 if (mask) {
750 int i;
751 printk(BIOS_SPEW, " 3D VIC indices:");
752 /* worst bit ordering ever */
753 for (i = 0; i < 8; i++)
754 if (x[10 + b] & (1 << i))
755 printk(BIOS_SPEW, " %d", i);
756 for (i = 0; i < 8; i++)
757 if (x[9 + b] & (1 << i))
758 printk(BIOS_SPEW, " %d", i + 8);
759 printk(BIOS_SPEW, "\n");
760 b += 2;
761 }
762
763 /*
764 * XXX list of nibbles:
765 * 2D_VIC_Order_X
766 * 3D_Structure_X
767 * (optionally: 3D_Detail_X and reserved)
768 */
769 }
770
771 }
772 }
773}
774
775static void
776cea_block(struct edid *out, unsigned char *x)
777{
778 unsigned int oui;
779
780 switch ((x[0] & 0xe0) >> 5) {
781 case 0x01:
782 printk(BIOS_SPEW, " Audio data block\n");
783 cea_audio_block(x);
784 break;
785 case 0x02:
786 printk(BIOS_SPEW, " Video data block\n");
787 cea_video_block(x);
788 break;
789 case 0x03:
790 /* yes really, endianness lols */
791 oui = (x[3] << 16) + (x[2] << 8) + x[1];
792 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
793 if (oui == 0x000c03)
794 cea_hdmi_block(out, x);
795 else
796 printk(BIOS_SPEW, "\n");
797 break;
798 case 0x04:
799 printk(BIOS_SPEW, " Speaker allocation data block\n");
800 break;
801 case 0x05:
802 printk(BIOS_SPEW, " VESA DTC data block\n");
803 break;
804 case 0x07:
805 printk(BIOS_SPEW, " Extended tag: ");
806 switch (x[1]) {
807 case 0x00:
808 printk(BIOS_SPEW, "video capability data block\n");
809 break;
810 case 0x01:
811 printk(BIOS_SPEW, "vendor-specific video data block\n");
812 break;
813 case 0x02:
814 printk(BIOS_SPEW, "VESA video display device information data block\n");
815 break;
816 case 0x03:
817 printk(BIOS_SPEW, "VESA video data block\n");
818 break;
819 case 0x04:
820 printk(BIOS_SPEW, "HDMI video data block\n");
821 break;
822 case 0x05:
823 printk(BIOS_SPEW, "Colorimetry data block\n");
824 break;
825 case 0x10:
826 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
827 break;
828 case 0x11:
829 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
830 break;
831 case 0x12:
832 printk(BIOS_SPEW, "HDMI audio data block\n");
833 break;
834 default:
835 if (x[1] >= 6 && x[1] <= 15)
836 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
837 else if (x[1] >= 19 && x[1] <= 31)
838 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
839 else
840 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
841 break;
842 }
843 break;
844 default:
845 {
846 int tag = (*x & 0xe0) >> 5;
847 int length = *x & 0x1f;
848 printk(BIOS_SPEW,
849 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
850 break;
851 }
852 }
853}
854
855static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800856parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700857{
858 int ret = 0;
859 int version = x[1];
860 int offset = x[2];
861 unsigned char *detailed;
862
863 if (version >= 1) do {
864 if (version == 1 && x[3] != 0)
865 ret = 1;
866
867 if (offset < 4)
868 break;
869
870 if (version < 3) {
871 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
872 if (offset - 4 > 0)
873 /* do stuff */ ;
874 } else if (version == 3) {
875 int i;
876 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
877 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
878 cea_block(out, x + i);
879 }
880 }
881
882 if (version >= 2) {
883 if (x[3] & 0x80)
884 printk(BIOS_SPEW, "Underscans PC formats by default\n");
885 if (x[3] & 0x40)
886 printk(BIOS_SPEW, "Basic audio support\n");
887 if (x[3] & 0x20)
888 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
889 if (x[3] & 0x10)
890 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
891 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
892 }
893
894 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
895 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800896 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700897 } while (0);
898
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800899 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700900 return ret;
901}
902
903/* generic extension code */
904
905static void
906extension_version(struct edid *out, unsigned char *x)
907{
908 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
909}
910
911static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800912parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700913{
914 int conformant_extension = 0;
915 printk(BIOS_SPEW, "\n");
916
917 switch(x[0]) {
918 case 0x02:
919 printk(BIOS_SPEW, "CEA extension block\n");
920 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800921 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700922 break;
923 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
924 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
925 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
926 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
927 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800928 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700929 default:
930 printk(BIOS_SPEW, "Unknown extension block\n");
931 break;
932 }
933
934 printk(BIOS_SPEW, "\n");
935
936 return conformant_extension;
937}
938
939static const struct {
940 int x, y, refresh;
941} established_timings[] = {
942 /* 0x23 bit 7 - 0 */
943 {720, 400, 70},
944 {720, 400, 88},
945 {640, 480, 60},
946 {640, 480, 67},
947 {640, 480, 72},
948 {640, 480, 75},
949 {800, 600, 56},
950 {800, 600, 60},
951 /* 0x24 bit 7 - 0 */
952 {800, 600, 72},
953 {800, 600, 75},
954 {832, 624, 75},
955 {1280, 768, 87},
956 {1024, 768, 60},
957 {1024, 768, 70},
958 {1024, 768, 75},
959 {1280, 1024, 75},
960 /* 0x25 bit 7*/
961 {1152, 870, 75},
962};
963
964static void print_subsection(const char *name, unsigned char *edid, int start,
965 int end)
966{
967 int i;
968
969 printk(BIOS_SPEW, "%s:", name);
970 for (i = strlen(name); i < 15; i++)
971 printk(BIOS_SPEW, " ");
972 for (i = start; i <= end; i++)
973 printk(BIOS_SPEW, " %02x", edid[i]);
974 printk(BIOS_SPEW, "\n");
975}
976
977static void dump_breakdown(unsigned char *edid)
978{
979 printk(BIOS_SPEW, "Extracted contents:\n");
980 print_subsection("header", edid, 0, 7);
981 print_subsection("serial number", edid, 8, 17);
982 print_subsection("version", edid,18, 19);
983 print_subsection("basic params", edid, 20, 24);
984 print_subsection("chroma info", edid, 25, 34);
985 print_subsection("established", edid, 35, 37);
986 print_subsection("standard", edid, 38, 53);
987 print_subsection("descriptor 1", edid, 54, 71);
988 print_subsection("descriptor 2", edid, 72, 89);
989 print_subsection("descriptor 3", edid, 90, 107);
990 print_subsection("descriptor 4", edid, 108, 125);
991 print_subsection("extensions", edid, 126, 126);
992 print_subsection("checksum", edid, 127, 127);
993 printk(BIOS_SPEW, "\n");
994}
995
996/*
David Hendrickse2054102015-08-07 18:41:37 -0700997 * Lookup table of some well-known modes that can be useful in case the
998 * auto-detected mode is unsuitable.
999 * ha = hdisplay; va = vdisplay;
1000 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1001 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1002 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1003 */
1004static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1005 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001006 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001007 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001008 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1009 .phsync = '-', .pvsync = '-' },
1010 [EDID_MODE_720x480_60Hz] = {
1011 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001012 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001013 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1014 .phsync = '-', .pvsync = '-' },
1015 [EDID_MODE_1280x720_60Hz] = {
1016 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001017 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001018 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1019 .phsync = '+', .pvsync = '+' },
1020 [EDID_MODE_1920x1080_60Hz] = {
1021 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001022 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001023 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1024 .phsync = '+', .pvsync = '+' },
1025};
1026
1027int set_display_mode(struct edid *edid, enum edid_modes mode)
1028{
1029 if (mode == EDID_MODE_AUTO)
1030 return 0;
1031
1032 if (edid->mode_is_supported[mode]) {
1033 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1034 edid->mode = known_modes[mode];
1035 return 0;
1036 }
1037
1038 printk(BIOS_ERR, "Requested display mode not supported.\n");
1039 return -1;
1040}
1041
1042/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001043 * Given a raw edid bloc, decode it into a form
1044 * that other parts of coreboot can use -- mainly
1045 * graphics bringup functions. The raw block is
1046 * required to be 128 bytes long, per the standard,
1047 * but we have no way of checking this minimum length.
1048 * We accept what we are given.
1049 */
1050int decode_edid(unsigned char *edid, int size, struct edid *out)
1051{
David Hendrickse2054102015-08-07 18:41:37 -07001052 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001053 struct edid_context c = {
1054 .has_valid_cvt = 1,
1055 .has_valid_dummy_block = 1,
1056 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001057 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001058 .has_valid_descriptor_pad = 1,
1059 .has_valid_range_descriptor = 1,
1060 .has_valid_max_dotclock = 1,
1061 .has_valid_string_termination = 1,
1062 .conformant = 1,
1063 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001064
1065 dump_breakdown(edid);
1066
David Hendricks40e89b42015-08-13 15:51:00 -07001067 memset(out, 0, sizeof(*out));
1068
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001069 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1070 printk(BIOS_SPEW, "No header found\n");
1071 return 1;
1072 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001073
David Hendricksa3b898a2015-08-02 18:07:48 -07001074 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001075 c.manufacturer_name_well_formed = 1;
1076
David Hendricksa3b898a2015-08-02 18:07:48 -07001077 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1078 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001079 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1080
1081 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001082 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001083 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1084 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1085 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001086 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001087
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001088 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001089 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001090 if (edid[0x11] > 0x0f) {
1091 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001092 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001093 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001094 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001095 extra_info.week = edid[0x10];
1096 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001097 } else {
1098 /* we know it's at least 2013, when this code was written */
1099 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001100 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001101 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001102 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001103 extra_info.week = edid[0x10];
1104 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001105 }
1106 }
1107 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001108 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001109
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001110 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001111 extra_info.version[0] = edid[0x12];
1112 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001113
1114 if (edid[0x12] == 1) {
1115 if (edid[0x13] > 4) {
1116 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1117 edid[0x13] = 4;
1118 }
1119 switch (edid[0x13]) {
1120 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001121 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001122 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001123 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001124 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001125 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001126 default:
1127 break;
1128 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001129 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001130 }
1131
1132 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001133 if (edid[0x14] & 0x80) {
1134 int conformance_mask;
1135 analog = 0;
1136 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001137 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001138 conformance_mask = 0;
1139 if ((edid[0x14] & 0x70) == 0x00)
1140 printk(BIOS_SPEW, "Color depth is undefined\n");
1141 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001142 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001143 else
1144 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1145 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001146 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1147 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001148
1149 switch (edid[0x14] & 0x0f) {
1150 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1151 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1152 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1153 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1154 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1155 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1156 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001157 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001158 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001159 extra_info.type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001160 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001161 conformance_mask = 0x7E;
1162 if (edid[0x14] & 0x01) {
1163 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1164 }
1165 } else
1166 conformance_mask = 0x7F;
1167
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001168 if (!c.nonconformant_digital_display)
1169 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001170 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001171 } else {
1172 analog = 1;
1173 int voltage = (edid[0x14] & 0x60) >> 5;
1174 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001175 extra_info.voltage = voltage;
1176 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001177
1178 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1179 voltage == 3 ? "0.7/0.7" :
1180 voltage == 2 ? "1.0/0.4" :
1181 voltage == 1 ? "0.714/0.286" :
1182 "0.7/0.3");
1183
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001184 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001185 if (edid[0x14] & 0x10)
1186 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1187 else
1188 printk(BIOS_SPEW, "Blank level equals black level\n");
1189 } else if (edid[0x14] & 0x10) {
1190 /*
1191 * XXX this is just the X text. 1.3 says "if set, display expects
1192 * a blank-to-black setup or pedestal per appropriate Signal
1193 * Level Standard". Whatever _that_ means.
1194 */
1195 printk(BIOS_SPEW, "Configurable signal levels\n");
1196 }
1197
1198 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1199 sync & 0x04 ? "Composite " : "",
1200 sync & 0x02 ? "SyncOnGreen " : "",
1201 sync & 0x01 ? "Serration " : "");
1202 }
1203
1204
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001205 if (edid[0x15] && edid[0x16]) {
1206 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1207 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001208 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001209 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1210 unsigned int ratio = 100000/(edid[0x15] + 99);
1211 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1212 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001213 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1214 unsigned int ratio = 100000/(edid[0x16] + 99);
1215 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1216 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001217 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001218 } else {
1219 /* Either or both can be zero for 1.3 and before */
1220 printk(BIOS_SPEW, "Image size is variable\n");
1221 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001222
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001223 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001224 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001225 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1226 else
1227 /* XXX Technically 1.3 doesn't say this... */
1228 printk(BIOS_SPEW, "Gamma: 1.0\n");
1229 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1230 printk(BIOS_SPEW, "Check DPMS levels\n");
1231 if (edid[0x18] & 0xE0) {
1232 printk(BIOS_SPEW, "DPMS levels:");
1233 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1234 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1235 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1236 printk(BIOS_SPEW, "\n");
1237 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001238
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001239 /* FIXME: this is from 1.4 spec, check earlier */
1240 if (analog) {
1241 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001242 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1243 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1244 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1245 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001246 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001247 } else {
1248 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1249 if (edid[0x18] & 0x10)
1250 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1251 if (edid[0x18] & 0x08)
1252 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1253 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001254 }
1255
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001256 if (edid[0x18] & 0x04)
1257 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1258 if (edid[0x18] & 0x02) {
1259 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001260 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001261 }
1262 if (edid[0x18] & 0x01)
1263 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1264
1265 /* XXX color section */
1266
1267 printk(BIOS_SPEW, "Established timings supported:\n");
1268 /* it's not yet clear we want all this stuff in the edid struct.
1269 * Let's wait.
1270 */
1271 for (i = 0; i < 17; i++) {
1272 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1273 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1274 established_timings[i].y, established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001275
Douglas Anderson9fa07602015-10-28 10:19:52 -07001276 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1277 if (known_modes[j].ha == established_timings[i].x &&
1278 known_modes[j].va == established_timings[i].y &&
1279 known_modes[j].refresh == established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001280 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001281 }
David Hendrickse2054102015-08-07 18:41:37 -07001282 }
1283
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001284 }
1285
1286 printk(BIOS_SPEW, "Standard timings supported:\n");
1287 for (i = 0; i < 8; i++) {
1288 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1289 unsigned int x, y = 0, refresh;
1290
1291 if (b1 == 0x01 && b2 == 0x01)
1292 continue;
1293
1294 if (b1 == 0) {
1295 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1296 continue;
1297 }
1298 x = (b1 + 31) * 8;
1299 switch ((b2 >> 6) & 0x3) {
1300 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001301 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001302 y = x * 10 / 16;
1303 else
1304 y = x;
1305 break;
1306 case 0x01:
1307 y = x * 3 / 4;
1308 break;
1309 case 0x02:
1310 y = x * 4 / 5;
1311 break;
1312 case 0x03:
1313 y = x * 9 / 16;
1314 break;
1315 }
1316 refresh = 60 + (b2 & 0x3f);
1317
1318 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001319 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1320 if (known_modes[j].ha == x && known_modes[j].va == y &&
1321 known_modes[j].refresh == refresh)
1322 out->mode_is_supported[j] = 1;
1323 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001324 }
1325
1326 /* detailed timings */
1327 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001328 for (i = 0; i < 4; i++) {
1329 c.has_valid_detailed_blocks &= detailed_block(
1330 out, edid + 0x36 + i * 18, 0, &c);
1331 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1332 {
1333 /* not really accurate... */
1334 c.has_preferred_timing = 0;
1335 }
1336 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001337
1338 /* check this, 1.4 verification guide says otherwise */
1339 if (edid[0x7e]) {
1340 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1341 /* 2 is impossible because of the block map */
1342 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001343 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001344 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001345 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001346 }
1347
1348 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001349 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001350
1351 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1352 * the extension parsing loop below. Since v2.0 was quickly deprecated
1353 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1354 * that case now and can fix it when we need to use a real 2.0 panel.
1355 */
1356 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001357 c.nonconformant_extension +=
1358 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001359
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001360 if (c.claims_one_point_four) {
1361 if (c.nonconformant_digital_display ||
1362 !c.has_valid_string_termination ||
1363 !c.has_valid_descriptor_pad ||
1364 !c.has_preferred_timing)
1365 c.conformant = 0;
1366 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001367 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001368 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001369 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001370 c.nonconformant_digital_display);
1371 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001372 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001373 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001374 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001375 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001376 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001377 } else if (c.claims_one_point_three) {
1378 if (c.nonconformant_digital_display ||
1379 !c.has_valid_string_termination ||
1380 !c.has_valid_descriptor_pad ||
1381 !c.has_preferred_timing) {
1382 c.conformant = 0;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001383 }
1384 /**
1385 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1386 * has_range_descriptor are both required. These fields are
1387 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1388 * don't have them. As a workaround, we only print warning
1389 * messages.
1390 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001391 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001392 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001393 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001394 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1395 "fully conform to EDID 1.3.\n");
1396
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001397 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001398 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001399 c.nonconformant_digital_display);
1400 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001401 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001402 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001403 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001404 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001405 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001406 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001407 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001408 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001409 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001410 } else if (c.claims_one_point_two) {
1411 if (c.nonconformant_digital_display ||
1412 !c.has_valid_string_termination)
1413 c.conformant = 0;
1414 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001415 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001416 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001417 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001418 c.nonconformant_digital_display);
1419 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001420 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001421 } else if (c.claims_one_point_oh) {
1422 if (c.seen_non_detailed_descriptor)
1423 c.conformant = 0;
1424 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001425 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001426 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001427 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1428 }
1429
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001430 if (c.nonconformant_extension ||
1431 !c.has_valid_checksum ||
1432 !c.has_valid_cvt ||
1433 !c.has_valid_year ||
1434 !c.has_valid_week ||
1435 !c.has_valid_detailed_blocks ||
1436 !c.has_valid_dummy_block ||
1437 !c.has_valid_extension_count ||
1438 !c.has_valid_descriptor_ordering ||
1439 !c.has_valid_range_descriptor ||
1440 !c.manufacturer_name_well_formed) {
1441 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001442 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001443 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001444 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001445 c.nonconformant_extension);
1446 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001447 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001448 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001449 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001450 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001451 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001452 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001453 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001454 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001455 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001457 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001458 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001459 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001460 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001461 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001462 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001463 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001464 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001465 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001466 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001467 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1468 }
1469
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001470 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001471 printk(BIOS_ERR,
1472 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001473 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001474 printk(BIOS_ERR,
1475 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001476 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001477}
1478
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001479/*
1480 * Notes on panel extensions: (TODO, implement me in the code)
1481 *
1482 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1483 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1484 * 0x6c: 00 00 00 0e 00
1485 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1486 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1487 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1488 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1489 * bit 4: DE polarity (0 high active 1 low active)
1490 * bit 3-0: interface (0000 LVDS TFT
1491 * 0001 mono STN 4/8bit
1492 * 0010 color STN 8/16 bit
1493 * 0011 18 bit tft
1494 * 0100 24 bit tft
1495 * 0101 tmds
1496 * else reserved)
1497 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1498 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1499 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1500 * else time in 10ms (10ms to 150ms))
1501 * bit 3-0: total poweron seq delay (as above)
1502 * 0x75: contrast power on/off seq delay, same as 0x74
1503 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1504 * bit 6: backlight enabled at boot (0 on 1 off)
1505 * bit 5-0: backlight brightness control steps (0..63)
1506 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1507 * 0x78 - 0x7c: reserved
1508 * 0x7d: bit 7-4: EPI descriptor major version (1)
1509 * bit 3-0: EPI descriptor minor version (0)
1510 *
1511 * ----
1512 *
1513 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1514 *
1515 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1516 *
1517 * detailed descriptor 3:
1518 * 0x5a - 0x5e: 00 00 00 fe 00
1519 * 0x5f - 0x63: PC maker part number
1520 * 0x64: LCD supplier revision #
1521 * 0x65 - 0x6b: manufacturer part number
1522 *
1523 * detailed descriptor 4:
1524 * 0x6c - 0x70: 00 00 00 fe 00
1525 * 0x71 - 0x78: smbus nits values (whut)
1526 * 0x79: number of lvds channels (1 or 2)
1527 * 0x7A: panel self test (1 if present)
1528 * and then dummy terminator
1529 *
1530 * SPWG also says something strange about the LSB of detailed descriptor 1:
1531 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1532 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001533/*
1534 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1535 */
1536
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001537void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1538{
1539 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001540 edid_fb.x_resolution = edid->x_resolution;
1541 edid_fb.y_resolution = edid->y_resolution;
1542 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001543 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001544 * seems to be to round it up to the nearest reasonable
1545 * boundary, because otherwise the byte-packing is hideous.
1546 * So, for example, in RGB with no alpha, the bytes are still
1547 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1548 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1549 * and in 4:4:4 mode, they are packed into 16-bit words.
1550 * Good call on the hardware guys part.
1551 * It's not clear we're covering all cases here, but
1552 * I'm not sure with grahpics you ever can.
1553 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001554 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001555 edid_fb.reserved_mask_pos = 0;
1556 edid_fb.reserved_mask_size = 0;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001557 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001558 case 32:
1559 case 24:
1560 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001561 edid_fb.reserved_mask_pos = 24;
1562 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001563 edid_fb.red_mask_pos = 16;
1564 edid_fb.red_mask_size = 8;
1565 edid_fb.green_mask_pos = 8;
1566 edid_fb.green_mask_size = 8;
1567 edid_fb.blue_mask_pos = 0;
1568 edid_fb.blue_mask_size = 8;
1569 break;
1570 case 16:
1571 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001572 edid_fb.red_mask_pos = 11;
1573 edid_fb.red_mask_size = 5;
1574 edid_fb.green_mask_pos = 5;
1575 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001576 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001577 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001578 break;
1579 default:
1580 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001581 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001582 return;
1583 }
1584
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001585 vbe_valid = 1;
1586}
1587
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001588#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001589int vbe_mode_info_valid(void)
1590{
1591 return vbe_valid;
1592}
1593
1594void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1595{
1596 *framebuffer = edid_fb;
1597}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001598#endif