blob: be3d90602a940a70362c650185960ea887e81da8 [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 */
David Hendricks7dbf9c62015-07-30 18:49:48 -0700448 out->mode.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));
David Hendricks7dbf9c62015-07-30 18:49:48 -0700451 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
452 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
453 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
454 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
455 out->mode.hborder = x[15];
456 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
457 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
458 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
459 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
460 out->mode.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
David Hendricks7dbf9c62015-07-30 18:49:48 -0700478 out->x_resolution = ALIGN(out->mode.ha *
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700479 ((out->framebuffer_bits_per_pixel + 7) / 8),
480 64) / (out->framebuffer_bits_per_pixel/8);
David Hendricks7dbf9c62015-07-30 18:49:48 -0700481 out->y_resolution = out->mode.va;
482 out->bytes_per_line = ALIGN(out->mode.ha *
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700483 ((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 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700502 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
503 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700504 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",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700532 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700533 extra_info.x_mm,
534 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700535 out->mode.ha, out->mode.ha + out->mode.hso,
536 out->mode.ha + out->mode.hso + out->mode.hspw,
537 out->mode.ha + out->mode.hbl, out->mode.hborder,
538 out->mode.va, out->mode.va + out->mode.vso,
539 out->mode.va + out->mode.vso + out->mode.vspw,
540 out->mode.va + out->mode.vbl, out->mode.vborder,
541 out->mode.phsync, out->mode.pvsync,
David Hendricksa3b898a2015-08-02 18:07:48 -0700542 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700543 extra_info.stereo);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700544 return 1;
545}
546
547static int
548do_checksum(unsigned char *x)
549{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800550 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600551 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700552 {
553 unsigned char sum = 0;
554 int i;
555 for (i = 0; i < 128; i++)
556 sum += x[i];
557 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600558 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700559 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800560 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700561 printk(BIOS_SPEW, " (valid)");
562 }
563 }
564 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800565 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700566}
567
568/* CEA extension */
569
570static const char *
571audio_format(unsigned char x)
572{
573 switch (x) {
574 case 0: return "RESERVED";
575 case 1: return "Linear PCM";
576 case 2: return "AC-3";
577 case 3: return "MPEG 1 (Layers 1 & 2)";
578 case 4: return "MPEG 1 Layer 3 (MP3)";
579 case 5: return "MPEG2 (multichannel)";
580 case 6: return "AAC";
581 case 7: return "DTS";
582 case 8: return "ATRAC";
583 case 9: return "One Bit Audio";
584 case 10: return "Dolby Digital+";
585 case 11: return "DTS-HD";
586 case 12: return "MAT (MLP)";
587 case 13: return "DST";
588 case 14: return "WMA Pro";
589 case 15: return "RESERVED";
590 }
591 return "BROKEN"; /* can't happen */
592}
593
594static void
595cea_audio_block(unsigned char *x)
596{
597 int i, format;
598 int length = x[0] & 0x1f;
599
600 if (length % 3) {
601 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
602 /* XXX non-conformant */
603 return;
604 }
605
606 for (i = 1; i < length; i += 3) {
607 format = (x[i] & 0x78) >> 3;
608 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
609 x[i] & 0x07);
610 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
611 (x[i+1] & 0x40) ? " 192" : "",
612 (x[i+1] & 0x20) ? " 176.4" : "",
613 (x[i+1] & 0x10) ? " 96" : "",
614 (x[i+1] & 0x08) ? " 88.2" : "",
615 (x[i+1] & 0x04) ? " 48" : "",
616 (x[i+1] & 0x02) ? " 44.1" : "",
617 (x[i+1] & 0x01) ? " 32" : "");
618 if (format == 1) {
619 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
620 (x[2] & 0x04) ? " 24" : "",
621 (x[2] & 0x02) ? " 20" : "",
622 (x[2] & 0x01) ? " 16" : "");
623 } else if (format <= 8) {
624 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
625 }
626 }
627}
628
629static void
630cea_video_block(unsigned char *x)
631{
632 int i;
633 int length = x[0] & 0x1f;
634
635 for (i = 1; i < length; i++)
636 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
637 x[i] & 0x80 ? "(native)" : "");
638}
639
640static void
641cea_hdmi_block(struct edid *out, unsigned char *x)
642{
643 int length = x[0] & 0x1f;
644
645 printk(BIOS_SPEW, " (HDMI)\n");
646 printk(BIOS_SPEW,
647 " Source physical address %d.%d.%d.%d\n",
648 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
649
650 if (length > 5) {
651 if (x[6] & 0x80)
652 printk(BIOS_SPEW, " Supports_AI\n");
653 if (x[6] & 0x40)
654 printk(BIOS_SPEW, " DC_48bit\n");
655 if (x[6] & 0x20)
656 printk(BIOS_SPEW, " DC_36bit\n");
657 if (x[6] & 0x10)
658 printk(BIOS_SPEW, " DC_30bit\n");
659 if (x[6] & 0x08)
660 printk(BIOS_SPEW, " DC_Y444\n");
661 /* two reserved */
662 if (x[6] & 0x01)
663 printk(BIOS_SPEW, " DVI_Dual\n");
664 }
665
666 if (length > 6)
667 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
668
669 /* XXX the walk here is really ugly, and needs to be length-checked */
670 if (length > 7) {
671 int b = 0;
672
673 if (x[8] & 0x80) {
674 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
675 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
676 b += 2;
677 }
678
679 if (x[8] & 0x40) {
680 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
681 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
682 b += 2;
683 }
684
685 if (x[8] & 0x20) {
686 int mask = 0, formats = 0;
687 int len_xx, len_3d;
688 printk(BIOS_SPEW, " Extended HDMI video details:\n");
689 if (x[9 + b] & 0x80)
690 printk(BIOS_SPEW, " 3D present\n");
691 if ((x[9 + b] & 0x60) == 0x20) {
692 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
693 formats = 1;
694 }
695 if ((x[9 + b] & 0x60) == 0x40) {
696 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
697 formats = 1;
698 mask = 1;
699 }
700 switch (x[9 + b] & 0x18) {
701 case 0x00: break;
702 case 0x08:
703 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
704 break;
705 case 0x10:
706 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
707 break;
708 case 0x18:
709 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
710 break;
711 }
712 len_xx = (x[10 + b] & 0xe0) >> 5;
713 len_3d = (x[10 + b] & 0x1f) >> 0;
714 b += 2;
715
716 if (len_xx) {
717 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
718 " document\n", len_xx);
719 b += len_xx;
720 }
721
722 if (len_3d) {
723 if (formats) {
724 if (x[9 + b] & 0x01)
725 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
726 if (x[10 + b] & 0x40)
727 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
728 if (x[10 + b] & 0x01)
729 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
730 b += 2;
731 }
732 if (mask) {
733 int i;
734 printk(BIOS_SPEW, " 3D VIC indices:");
735 /* worst bit ordering ever */
736 for (i = 0; i < 8; i++)
737 if (x[10 + b] & (1 << i))
738 printk(BIOS_SPEW, " %d", i);
739 for (i = 0; i < 8; i++)
740 if (x[9 + b] & (1 << i))
741 printk(BIOS_SPEW, " %d", i + 8);
742 printk(BIOS_SPEW, "\n");
743 b += 2;
744 }
745
746 /*
747 * XXX list of nibbles:
748 * 2D_VIC_Order_X
749 * 3D_Structure_X
750 * (optionally: 3D_Detail_X and reserved)
751 */
752 }
753
754 }
755 }
756}
757
758static void
759cea_block(struct edid *out, unsigned char *x)
760{
761 unsigned int oui;
762
763 switch ((x[0] & 0xe0) >> 5) {
764 case 0x01:
765 printk(BIOS_SPEW, " Audio data block\n");
766 cea_audio_block(x);
767 break;
768 case 0x02:
769 printk(BIOS_SPEW, " Video data block\n");
770 cea_video_block(x);
771 break;
772 case 0x03:
773 /* yes really, endianness lols */
774 oui = (x[3] << 16) + (x[2] << 8) + x[1];
775 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
776 if (oui == 0x000c03)
777 cea_hdmi_block(out, x);
778 else
779 printk(BIOS_SPEW, "\n");
780 break;
781 case 0x04:
782 printk(BIOS_SPEW, " Speaker allocation data block\n");
783 break;
784 case 0x05:
785 printk(BIOS_SPEW, " VESA DTC data block\n");
786 break;
787 case 0x07:
788 printk(BIOS_SPEW, " Extended tag: ");
789 switch (x[1]) {
790 case 0x00:
791 printk(BIOS_SPEW, "video capability data block\n");
792 break;
793 case 0x01:
794 printk(BIOS_SPEW, "vendor-specific video data block\n");
795 break;
796 case 0x02:
797 printk(BIOS_SPEW, "VESA video display device information data block\n");
798 break;
799 case 0x03:
800 printk(BIOS_SPEW, "VESA video data block\n");
801 break;
802 case 0x04:
803 printk(BIOS_SPEW, "HDMI video data block\n");
804 break;
805 case 0x05:
806 printk(BIOS_SPEW, "Colorimetry data block\n");
807 break;
808 case 0x10:
809 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
810 break;
811 case 0x11:
812 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
813 break;
814 case 0x12:
815 printk(BIOS_SPEW, "HDMI audio data block\n");
816 break;
817 default:
818 if (x[1] >= 6 && x[1] <= 15)
819 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
820 else if (x[1] >= 19 && x[1] <= 31)
821 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
822 else
823 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
824 break;
825 }
826 break;
827 default:
828 {
829 int tag = (*x & 0xe0) >> 5;
830 int length = *x & 0x1f;
831 printk(BIOS_SPEW,
832 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
833 break;
834 }
835 }
836}
837
838static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800839parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700840{
841 int ret = 0;
842 int version = x[1];
843 int offset = x[2];
844 unsigned char *detailed;
845
846 if (version >= 1) do {
847 if (version == 1 && x[3] != 0)
848 ret = 1;
849
850 if (offset < 4)
851 break;
852
853 if (version < 3) {
854 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
855 if (offset - 4 > 0)
856 /* do stuff */ ;
857 } else if (version == 3) {
858 int i;
859 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
860 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
861 cea_block(out, x + i);
862 }
863 }
864
865 if (version >= 2) {
866 if (x[3] & 0x80)
867 printk(BIOS_SPEW, "Underscans PC formats by default\n");
868 if (x[3] & 0x40)
869 printk(BIOS_SPEW, "Basic audio support\n");
870 if (x[3] & 0x20)
871 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
872 if (x[3] & 0x10)
873 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
874 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
875 }
876
877 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
878 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800879 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700880 } while (0);
881
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800882 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700883 return ret;
884}
885
886/* generic extension code */
887
888static void
889extension_version(struct edid *out, unsigned char *x)
890{
891 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
892}
893
894static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800895parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700896{
897 int conformant_extension = 0;
898 printk(BIOS_SPEW, "\n");
899
900 switch(x[0]) {
901 case 0x02:
902 printk(BIOS_SPEW, "CEA extension block\n");
903 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800904 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700905 break;
906 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
907 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
908 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
909 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
910 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800911 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700912 default:
913 printk(BIOS_SPEW, "Unknown extension block\n");
914 break;
915 }
916
917 printk(BIOS_SPEW, "\n");
918
919 return conformant_extension;
920}
921
922static const struct {
923 int x, y, refresh;
924} established_timings[] = {
925 /* 0x23 bit 7 - 0 */
926 {720, 400, 70},
927 {720, 400, 88},
928 {640, 480, 60},
929 {640, 480, 67},
930 {640, 480, 72},
931 {640, 480, 75},
932 {800, 600, 56},
933 {800, 600, 60},
934 /* 0x24 bit 7 - 0 */
935 {800, 600, 72},
936 {800, 600, 75},
937 {832, 624, 75},
938 {1280, 768, 87},
939 {1024, 768, 60},
940 {1024, 768, 70},
941 {1024, 768, 75},
942 {1280, 1024, 75},
943 /* 0x25 bit 7*/
944 {1152, 870, 75},
945};
946
947static void print_subsection(const char *name, unsigned char *edid, int start,
948 int end)
949{
950 int i;
951
952 printk(BIOS_SPEW, "%s:", name);
953 for (i = strlen(name); i < 15; i++)
954 printk(BIOS_SPEW, " ");
955 for (i = start; i <= end; i++)
956 printk(BIOS_SPEW, " %02x", edid[i]);
957 printk(BIOS_SPEW, "\n");
958}
959
960static void dump_breakdown(unsigned char *edid)
961{
962 printk(BIOS_SPEW, "Extracted contents:\n");
963 print_subsection("header", edid, 0, 7);
964 print_subsection("serial number", edid, 8, 17);
965 print_subsection("version", edid,18, 19);
966 print_subsection("basic params", edid, 20, 24);
967 print_subsection("chroma info", edid, 25, 34);
968 print_subsection("established", edid, 35, 37);
969 print_subsection("standard", edid, 38, 53);
970 print_subsection("descriptor 1", edid, 54, 71);
971 print_subsection("descriptor 2", edid, 72, 89);
972 print_subsection("descriptor 3", edid, 90, 107);
973 print_subsection("descriptor 4", edid, 108, 125);
974 print_subsection("extensions", edid, 126, 126);
975 print_subsection("checksum", edid, 127, 127);
976 printk(BIOS_SPEW, "\n");
977}
978
979/*
David Hendrickse2054102015-08-07 18:41:37 -0700980 * Lookup table of some well-known modes that can be useful in case the
981 * auto-detected mode is unsuitable.
982 * ha = hdisplay; va = vdisplay;
983 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
984 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
985 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
986 */
987static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
988 [EDID_MODE_640x480_60Hz] = {
989 .name = "640x480@60Hz", .pixel_clock = 25175, .refresh = 60,
990 .ha = 640, .hbl = 160, .hso = 16, .hborder = 96,
991 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
992 .phsync = '-', .pvsync = '-' },
993 [EDID_MODE_720x480_60Hz] = {
994 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
995 .ha = 720, .hbl = 78, .hso = 16, .hborder = 62,
996 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
997 .phsync = '-', .pvsync = '-' },
998 [EDID_MODE_1280x720_60Hz] = {
999 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
1000 .ha = 1280, .hbl = 370, .hso = 110, .hborder = 40,
1001 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1002 .phsync = '+', .pvsync = '+' },
1003 [EDID_MODE_1920x1080_60Hz] = {
1004 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
1005 .ha = 1920, .hbl = 280, .hso = 88, .hborder = 44,
1006 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1007 .phsync = '+', .pvsync = '+' },
1008};
1009
1010int set_display_mode(struct edid *edid, enum edid_modes mode)
1011{
1012 if (mode == EDID_MODE_AUTO)
1013 return 0;
1014
1015 if (edid->mode_is_supported[mode]) {
1016 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1017 edid->mode = known_modes[mode];
1018 return 0;
1019 }
1020
1021 printk(BIOS_ERR, "Requested display mode not supported.\n");
1022 return -1;
1023}
1024
1025/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001026 * Given a raw edid bloc, decode it into a form
1027 * that other parts of coreboot can use -- mainly
1028 * graphics bringup functions. The raw block is
1029 * required to be 128 bytes long, per the standard,
1030 * but we have no way of checking this minimum length.
1031 * We accept what we are given.
1032 */
1033int decode_edid(unsigned char *edid, int size, struct edid *out)
1034{
David Hendrickse2054102015-08-07 18:41:37 -07001035 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001036 struct edid_context c = {
1037 .has_valid_cvt = 1,
1038 .has_valid_dummy_block = 1,
1039 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001040 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001041 .has_valid_descriptor_pad = 1,
1042 .has_valid_range_descriptor = 1,
1043 .has_valid_max_dotclock = 1,
1044 .has_valid_string_termination = 1,
1045 .conformant = 1,
1046 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001047
1048 dump_breakdown(edid);
1049
David Hendricks40e89b42015-08-13 15:51:00 -07001050 memset(out, 0, sizeof(*out));
1051
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001052 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1053 printk(BIOS_SPEW, "No header found\n");
1054 return 1;
1055 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001056
David Hendricksa3b898a2015-08-02 18:07:48 -07001057 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001058 c.manufacturer_name_well_formed = 1;
1059
David Hendricksa3b898a2015-08-02 18:07:48 -07001060 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1061 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001062 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1063
1064 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001065 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001066 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1067 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1068 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001069 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001070
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001071 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001072 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001073 if (edid[0x11] > 0x0f) {
1074 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001075 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001076 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001077 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001078 extra_info.week = edid[0x10];
1079 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001080 } else {
1081 /* we know it's at least 2013, when this code was written */
1082 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001083 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001084 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001085 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001086 extra_info.week = edid[0x10];
1087 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001088 }
1089 }
1090 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001091 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001092
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001093 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001094 extra_info.version[0] = edid[0x12];
1095 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001096
1097 if (edid[0x12] == 1) {
1098 if (edid[0x13] > 4) {
1099 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1100 edid[0x13] = 4;
1101 }
1102 switch (edid[0x13]) {
1103 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001104 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001105 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001106 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001107 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001108 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001109 default:
1110 break;
1111 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001112 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001113 }
1114
1115 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001116 if (edid[0x14] & 0x80) {
1117 int conformance_mask;
1118 analog = 0;
1119 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001120 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001121 conformance_mask = 0;
1122 if ((edid[0x14] & 0x70) == 0x00)
1123 printk(BIOS_SPEW, "Color depth is undefined\n");
1124 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001125 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001126 else
1127 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1128 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001129 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1130 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001131
1132 switch (edid[0x14] & 0x0f) {
1133 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1134 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1135 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1136 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1137 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1138 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1139 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001140 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001141 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001142 extra_info.type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001143 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001144 conformance_mask = 0x7E;
1145 if (edid[0x14] & 0x01) {
1146 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1147 }
1148 } else
1149 conformance_mask = 0x7F;
1150
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001151 if (!c.nonconformant_digital_display)
1152 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001153 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001154 } else {
1155 analog = 1;
1156 int voltage = (edid[0x14] & 0x60) >> 5;
1157 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001158 extra_info.voltage = voltage;
1159 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001160
1161 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1162 voltage == 3 ? "0.7/0.7" :
1163 voltage == 2 ? "1.0/0.4" :
1164 voltage == 1 ? "0.714/0.286" :
1165 "0.7/0.3");
1166
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001167 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001168 if (edid[0x14] & 0x10)
1169 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1170 else
1171 printk(BIOS_SPEW, "Blank level equals black level\n");
1172 } else if (edid[0x14] & 0x10) {
1173 /*
1174 * XXX this is just the X text. 1.3 says "if set, display expects
1175 * a blank-to-black setup or pedestal per appropriate Signal
1176 * Level Standard". Whatever _that_ means.
1177 */
1178 printk(BIOS_SPEW, "Configurable signal levels\n");
1179 }
1180
1181 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1182 sync & 0x04 ? "Composite " : "",
1183 sync & 0x02 ? "SyncOnGreen " : "",
1184 sync & 0x01 ? "Serration " : "");
1185 }
1186
1187
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001188 if (edid[0x15] && edid[0x16]) {
1189 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1190 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001191 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001192 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1193 unsigned int ratio = 100000/(edid[0x15] + 99);
1194 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1195 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001196 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1197 unsigned int ratio = 100000/(edid[0x16] + 99);
1198 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1199 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001200 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001201 } else {
1202 /* Either or both can be zero for 1.3 and before */
1203 printk(BIOS_SPEW, "Image size is variable\n");
1204 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001205
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001206 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001207 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001208 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1209 else
1210 /* XXX Technically 1.3 doesn't say this... */
1211 printk(BIOS_SPEW, "Gamma: 1.0\n");
1212 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1213 printk(BIOS_SPEW, "Check DPMS levels\n");
1214 if (edid[0x18] & 0xE0) {
1215 printk(BIOS_SPEW, "DPMS levels:");
1216 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1217 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1218 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1219 printk(BIOS_SPEW, "\n");
1220 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001221
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001222 /* FIXME: this is from 1.4 spec, check earlier */
1223 if (analog) {
1224 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001225 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1226 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1227 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1228 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001229 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001230 } else {
1231 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1232 if (edid[0x18] & 0x10)
1233 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1234 if (edid[0x18] & 0x08)
1235 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1236 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001237 }
1238
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001239 if (edid[0x18] & 0x04)
1240 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1241 if (edid[0x18] & 0x02) {
1242 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001243 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001244 }
1245 if (edid[0x18] & 0x01)
1246 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1247
1248 /* XXX color section */
1249
1250 printk(BIOS_SPEW, "Established timings supported:\n");
1251 /* it's not yet clear we want all this stuff in the edid struct.
1252 * Let's wait.
1253 */
1254 for (i = 0; i < 17; i++) {
1255 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1256 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1257 established_timings[i].y, established_timings[i].refresh);
1258 }
David Hendrickse2054102015-08-07 18:41:37 -07001259
1260 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1261 if (known_modes[j].ha == established_timings[i].x &&
1262 known_modes[j].va == established_timings[i].y &&
1263 known_modes[j].refresh == established_timings[i].refresh)
1264 out->mode_is_supported[j] = 1;
1265 }
1266
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001267 }
1268
1269 printk(BIOS_SPEW, "Standard timings supported:\n");
1270 for (i = 0; i < 8; i++) {
1271 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1272 unsigned int x, y = 0, refresh;
1273
1274 if (b1 == 0x01 && b2 == 0x01)
1275 continue;
1276
1277 if (b1 == 0) {
1278 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1279 continue;
1280 }
1281 x = (b1 + 31) * 8;
1282 switch ((b2 >> 6) & 0x3) {
1283 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001284 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001285 y = x * 10 / 16;
1286 else
1287 y = x;
1288 break;
1289 case 0x01:
1290 y = x * 3 / 4;
1291 break;
1292 case 0x02:
1293 y = x * 4 / 5;
1294 break;
1295 case 0x03:
1296 y = x * 9 / 16;
1297 break;
1298 }
1299 refresh = 60 + (b2 & 0x3f);
1300
1301 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001302 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1303 if (known_modes[j].ha == x && known_modes[j].va == y &&
1304 known_modes[j].refresh == refresh)
1305 out->mode_is_supported[j] = 1;
1306 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001307 }
1308
1309 /* detailed timings */
1310 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001311 for (i = 0; i < 4; i++) {
1312 c.has_valid_detailed_blocks &= detailed_block(
1313 out, edid + 0x36 + i * 18, 0, &c);
1314 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1315 {
1316 /* not really accurate... */
1317 c.has_preferred_timing = 0;
1318 }
1319 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001320
1321 /* check this, 1.4 verification guide says otherwise */
1322 if (edid[0x7e]) {
1323 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1324 /* 2 is impossible because of the block map */
1325 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001326 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001327 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001328 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001329 }
1330
1331 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001332 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001333
1334 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1335 * the extension parsing loop below. Since v2.0 was quickly deprecated
1336 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1337 * that case now and can fix it when we need to use a real 2.0 panel.
1338 */
1339 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001340 c.nonconformant_extension +=
1341 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001342
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001343 if (c.claims_one_point_four) {
1344 if (c.nonconformant_digital_display ||
1345 !c.has_valid_string_termination ||
1346 !c.has_valid_descriptor_pad ||
1347 !c.has_preferred_timing)
1348 c.conformant = 0;
1349 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001350 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001351 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001352 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001353 c.nonconformant_digital_display);
1354 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001355 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001356 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001357 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001358 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001359 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001360 } else if (c.claims_one_point_three) {
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;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001366 }
1367 /**
1368 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1369 * has_range_descriptor are both required. These fields are
1370 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1371 * don't have them. As a workaround, we only print warning
1372 * messages.
1373 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001374 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001375 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001376 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001377 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1378 "fully conform to EDID 1.3.\n");
1379
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001380 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001381 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001382 c.nonconformant_digital_display);
1383 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001385 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001386 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001387 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001388 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001389 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001390 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001391 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001392 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001393 } else if (c.claims_one_point_two) {
1394 if (c.nonconformant_digital_display ||
1395 !c.has_valid_string_termination)
1396 c.conformant = 0;
1397 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001398 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001399 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001400 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001401 c.nonconformant_digital_display);
1402 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001403 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001404 } else if (c.claims_one_point_oh) {
1405 if (c.seen_non_detailed_descriptor)
1406 c.conformant = 0;
1407 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001408 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001409 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001410 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1411 }
1412
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001413 if (c.nonconformant_extension ||
1414 !c.has_valid_checksum ||
1415 !c.has_valid_cvt ||
1416 !c.has_valid_year ||
1417 !c.has_valid_week ||
1418 !c.has_valid_detailed_blocks ||
1419 !c.has_valid_dummy_block ||
1420 !c.has_valid_extension_count ||
1421 !c.has_valid_descriptor_ordering ||
1422 !c.has_valid_range_descriptor ||
1423 !c.manufacturer_name_well_formed) {
1424 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001425 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001426 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001427 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001428 c.nonconformant_extension);
1429 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001430 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001431 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001432 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001433 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001434 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001435 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001436 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001437 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001438 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001439 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001440 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001441 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001442 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001443 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001444 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001445 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001446 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001447 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001448 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001449 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001450 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1451 }
1452
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001453 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001454 printk(BIOS_ERR,
1455 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001457 printk(BIOS_ERR,
1458 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001459 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001460}
1461
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001462/*
1463 * Notes on panel extensions: (TODO, implement me in the code)
1464 *
1465 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1466 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1467 * 0x6c: 00 00 00 0e 00
1468 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1469 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1470 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1471 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1472 * bit 4: DE polarity (0 high active 1 low active)
1473 * bit 3-0: interface (0000 LVDS TFT
1474 * 0001 mono STN 4/8bit
1475 * 0010 color STN 8/16 bit
1476 * 0011 18 bit tft
1477 * 0100 24 bit tft
1478 * 0101 tmds
1479 * else reserved)
1480 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1481 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1482 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1483 * else time in 10ms (10ms to 150ms))
1484 * bit 3-0: total poweron seq delay (as above)
1485 * 0x75: contrast power on/off seq delay, same as 0x74
1486 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1487 * bit 6: backlight enabled at boot (0 on 1 off)
1488 * bit 5-0: backlight brightness control steps (0..63)
1489 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1490 * 0x78 - 0x7c: reserved
1491 * 0x7d: bit 7-4: EPI descriptor major version (1)
1492 * bit 3-0: EPI descriptor minor version (0)
1493 *
1494 * ----
1495 *
1496 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1497 *
1498 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1499 *
1500 * detailed descriptor 3:
1501 * 0x5a - 0x5e: 00 00 00 fe 00
1502 * 0x5f - 0x63: PC maker part number
1503 * 0x64: LCD supplier revision #
1504 * 0x65 - 0x6b: manufacturer part number
1505 *
1506 * detailed descriptor 4:
1507 * 0x6c - 0x70: 00 00 00 fe 00
1508 * 0x71 - 0x78: smbus nits values (whut)
1509 * 0x79: number of lvds channels (1 or 2)
1510 * 0x7A: panel self test (1 if present)
1511 * and then dummy terminator
1512 *
1513 * SPWG also says something strange about the LSB of detailed descriptor 1:
1514 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1515 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001516/*
1517 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1518 */
1519
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001520void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1521{
1522 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001523 edid_fb.x_resolution = edid->x_resolution;
1524 edid_fb.y_resolution = edid->y_resolution;
1525 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001526 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001527 * seems to be to round it up to the nearest reasonable
1528 * boundary, because otherwise the byte-packing is hideous.
1529 * So, for example, in RGB with no alpha, the bytes are still
1530 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1531 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1532 * and in 4:4:4 mode, they are packed into 16-bit words.
1533 * Good call on the hardware guys part.
1534 * It's not clear we're covering all cases here, but
1535 * I'm not sure with grahpics you ever can.
1536 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001537 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001538 edid_fb.reserved_mask_pos = 0;
1539 edid_fb.reserved_mask_size = 0;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001540 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001541 case 32:
1542 case 24:
1543 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001544 edid_fb.reserved_mask_pos = 24;
1545 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001546 edid_fb.red_mask_pos = 16;
1547 edid_fb.red_mask_size = 8;
1548 edid_fb.green_mask_pos = 8;
1549 edid_fb.green_mask_size = 8;
1550 edid_fb.blue_mask_pos = 0;
1551 edid_fb.blue_mask_size = 8;
1552 break;
1553 case 16:
1554 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001555 edid_fb.red_mask_pos = 11;
1556 edid_fb.red_mask_size = 5;
1557 edid_fb.green_mask_pos = 5;
1558 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001559 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001560 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001561 break;
1562 default:
1563 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001564 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001565 return;
1566 }
1567
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001568 vbe_valid = 1;
1569}
1570
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001571#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001572int vbe_mode_info_valid(void)
1573{
1574 return vbe_valid;
1575}
1576
1577void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1578{
1579 *framebuffer = edid_fb;
1580}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001581#endif