blob: 3aebc65e00bd4d64b9cb3987c9488ced13f141b3 [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
Douglas Andersonbca67fb2015-10-28 09:18:28 -070094static struct edid tmp_edid;
95
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070096static int vbe_valid;
97static struct lb_framebuffer edid_fb;
98
David Hendricksa3b898a2015-08-02 18:07:48 -070099static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700100{
David Hendricksa3b898a2015-08-02 18:07:48 -0700101 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
102 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
103 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
104 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700105
David Hendricksa3b898a2015-08-02 18:07:48 -0700106 if (isupper(extra_info.manuf_name[0]) &&
107 isupper(extra_info.manuf_name[1]) &&
108 isupper(extra_info.manuf_name[2]))
109 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700110
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800111 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700112}
113
114static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700115detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700116{
117 const unsigned char empty[3] = { 0, 0, 0 };
118 const char *names[] = { "50", "60", "75", "85" };
119 int width = 0, height = 0;
120 int valid = 1;
121 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
122
123 if (!first && !memcmp(x, empty, 3))
124 return valid;
125
126 height = x[0];
127 height |= (x[1] & 0xf0) << 4;
128 height++;
129 height *= 2;
130
131 switch (x[1] & 0x0c) {
132 case 0x00:
133 width = (height * 4) / 3; break;
134 case 0x04:
135 width = (height * 16) / 9; break;
136 case 0x08:
137 width = (height * 16) / 10; break;
138 case 0x0c:
139 width = (height * 15) / 9; break;
140 }
141
142 if (x[1] & 0x03)
143 valid = 0;
144 if (x[2] & 0x80)
145 valid = 0;
146 if (!(x[2] & 0x1f))
147 valid = 0;
148
149 fifty = (x[2] & 0x10);
150 sixty = (x[2] & 0x08);
151 seventyfive = (x[2] & 0x04);
152 eightyfive = (x[2] & 0x02);
153 reduced = (x[2] & 0x01);
154
155 if (!valid) {
156 printk(BIOS_SPEW, " (broken)\n");
157 } else {
158 printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
159 width, height,
160 fifty ? "50 " : "",
161 sixty ? "60 " : "",
162 seventyfive ? "75 " : "",
163 eightyfive ? "85 " : "",
164 reduced ? "60RB " : "",
165 names[(x[2] & 0x60) >> 5],
166 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
167 }
168
169 return valid;
170}
171
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800172/* extract a CP437 string from a detailed subblock, checking for termination (if
173 * less than len of bytes) with LF and padded with SP.
174 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700175static char *
176extract_string(unsigned char *x, int *valid_termination, int len)
177{
178 static char ret[128];
179 int i, seen_newline = 0;
180
181 memset(ret, 0, sizeof(ret));
182
183 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800184 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700185 if (x[i] != 0x20) {
186 *valid_termination = 0;
187 return ret;
188 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800189 } else if (x[i] == 0x0a) {
190 seen_newline = 1;
191 } else {
192 /* normal characters */
193 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700194 }
195 }
196
197 return ret;
198}
199
200/* 1 means valid data */
201static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700202detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800203 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700204{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700205 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700206 int i;
207#if 1
208 printk(BIOS_SPEW, "Hex of detail: ");
209 for (i = 0; i < 18; i++)
210 printk(BIOS_SPEW, "%02x", x[i]);
211 printk(BIOS_SPEW, "\n");
212#endif
213
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700214 /* Result might already have some valid fields like mode_is_supported */
215 *out = *result_edid;
216
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700217 if (x[0] == 0 && x[1] == 0) {
218 /* Monitor descriptor block, not detailed timing descriptor. */
219 if (x[2] != 0) {
220 /* 1.3, 3.10.3 */
221 printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
222 x[2]);
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 if (x[3] != 0xfd && x[4] != 0x00) {
226 /* 1.3, 3.10.3 */
227 printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
228 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800229 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700230 }
231
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800232 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700233 if (x[3] <= 0xF) {
234 /*
235 * in principle we can decode these, if we know what they are.
236 * 0x0f seems to be common in laptop panels.
237 * 0x0e is used by EPI: http://www.epi-standard.org/
238 */
239 printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800240 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700241 }
242 switch (x[3]) {
243 case 0x10:
244 printk(BIOS_SPEW, "Dummy block\n");
245 for (i = 5; i < 18; i++)
246 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800247 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800248 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700249 case 0xF7:
250 /* TODO */
251 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800252 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700253 case 0xF8:
254 {
255 int valid_cvt = 1; /* just this block */
256 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
257 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800258 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700259 return 0;
260 }
261 for (i = 0; i < 4; i++)
Douglas Anderson14dd3702015-10-28 11:19:57 -0700262 valid_cvt &= detailed_cvt_descriptor(x + 6 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800263 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800264 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700265 }
266 case 0xF9:
267 /* TODO */
268 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800269 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700270 case 0xFA:
271 /* TODO */
272 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800273 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700274 case 0xFB:
275 /* TODO */
276 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800277 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700278 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800279 printk(BIOS_SPEW, "Monitor name: %s\n",
280 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800281 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800282 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800283 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700284 case 0xFD:
285 {
286 int h_max_offset = 0, h_min_offset = 0;
287 int v_max_offset = 0, v_min_offset = 0;
288 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800289 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700290 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700291 /*
292 * XXX todo: implement feature flags, vtd blocks
293 * XXX check: ranges are well-formed; block termination if no vtd
294 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800295 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700296 if (x[4] & 0x02) {
297 v_max_offset = 255;
298 if (x[4] & 0x01) {
299 v_min_offset = 255;
300 }
301 }
302 if (x[4] & 0x04) {
303 h_max_offset = 255;
304 if (x[4] & 0x03) {
305 h_min_offset = 255;
306 }
307 }
308 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800309 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700310 }
311
312 /*
313 * despite the values, this is not a bitfield.
314 */
315 switch (x[10]) {
316 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700317 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700318 break;
319 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700320 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800321 if (!c->claims_one_point_four)
322 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700323 break;
324 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700325 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700326 break;
327 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700328 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700329 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800330 if (!c->claims_one_point_four)
331 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700332 break;
333 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800334 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700335 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700336 break;
337 }
338
339 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800340 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700341 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800342 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700343 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700344 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700345 x[5] + v_min_offset, x[6] + v_max_offset,
346 x[7] + h_min_offset, x[8] + h_max_offset);
347 if (x[9])
348 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
349 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800350 if (c->claims_one_point_four)
351 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700352 printk(BIOS_SPEW, "\n");
353 }
354
355 if (is_cvt) {
356 int max_h_pixels = 0;
357
358 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
359
360 if (x[12] & 0xfc) {
361 int raw_offset = (x[12] & 0xfc) >> 2;
Patrick Georgibe71ee5d2014-12-15 22:52:14 +0100362 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
363 (x[9] * 10000) - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700364 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800365 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700366 }
367
368 max_h_pixels = x[12] & 0x03;
369 max_h_pixels <<= 8;
370 max_h_pixels |= x[13];
371 max_h_pixels *= 8;
372 if (max_h_pixels)
373 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
374
375 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
376 x[14] & 0x80 ? "4:3" : "",
377 x[14] & 0x40 ? "16:9" : "",
378 x[14] & 0x20 ? "16:10" : "",
379 x[14] & 0x10 ? "5:4" : "",
380 x[14] & 0x08 ? "15:9" : "");
381 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800382 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700383
384 printk(BIOS_SPEW, "Preferred aspect ratio: ");
385 switch((x[15] & 0xe0) >> 5) {
386 case 0x00: printk(BIOS_SPEW, "4:3"); break;
387 case 0x01: printk(BIOS_SPEW, "16:9"); break;
388 case 0x02: printk(BIOS_SPEW, "16:10"); break;
389 case 0x03: printk(BIOS_SPEW, "5:4"); break;
390 case 0x04: printk(BIOS_SPEW, "15:9"); break;
391 default: printk(BIOS_SPEW, "(broken)"); break;
392 }
393 printk(BIOS_SPEW, "\n");
394
395 if (x[15] & 0x04)
396 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
397 if (x[15] & 0x10)
398 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
399
400 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800401 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700402
403 if (x[16] & 0xf0) {
404 printk(BIOS_SPEW, "Supported display scaling:\n");
405 if (x[16] & 0x80)
406 printk(BIOS_SPEW, " Horizontal shrink\n");
407 if (x[16] & 0x40)
408 printk(BIOS_SPEW, " Horizontal stretch\n");
409 if (x[16] & 0x20)
410 printk(BIOS_SPEW, " Vertical shrink\n");
411 if (x[16] & 0x10)
412 printk(BIOS_SPEW, " Vertical stretch\n");
413 }
414
415 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800416 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700417
418 if (x[17])
419 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
420 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800421 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700422 }
423
424 /*
425 * Slightly weird to return a global, but I've never seen any
426 * EDID block wth two range descriptors, so it's harmless.
427 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800428 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700429 }
430 case 0xFE:
431 /*
432 * TODO: Two of these in a row, in the third and fourth slots,
433 * seems to be specified by SPWG: http://www.spwg.org/
434 */
435 printk(BIOS_SPEW, "ASCII string: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800436 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800437 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700438 case 0xFF:
439 printk(BIOS_SPEW, "Serial number: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800440 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800441 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700442 default:
443 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
444 return 0;
445 }
446 }
447
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800448 if (c->seen_non_detailed_descriptor && !in_extension) {
449 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700450 }
451
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700452 /* Edid contains pixel clock in terms of 10KHz */
453 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
454 /*
455 LVDS supports following pixel clocks
456 25000...112000 kHz: single channel
457 80000...224000 kHz: dual channel
458 There is some overlap in theoretically supported
459 pixel clock between single-channel and dual-channel.
460 In practice with current panels all panels
461 <= 75200 kHz: single channel
462 >= 97750 kHz: dual channel
463 We have no samples between those values, so put a
464 threshold at 95000 kHz. If we get anything over
465 95000 kHz with single channel, we can make this
466 more sofisticated but it's currently not needed.
467 */
468 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
469 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
470 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
471 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
472 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
473 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
474 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
475 out->mode.hborder = x[15];
476 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
477 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
478 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
479 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
480 out->mode.vborder = x[16];
481 /* set up some reasonable defaults for payloads.
482 * We observe that most modern chipsets we work with
483 * tend to support rgb888 without regard to the
484 * panel bits per color or other settings. The rgb888
485 * is a convenient layout for software because
486 * it avoids the messy bit stuffing of rgb565 or rgb444.
487 * It makes a reasonable trade of memory for speed.
488 * So, set up the default for
489 * 32 bits per pixel
490 * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries)
491 * The mainboard can modify these if needed, though
492 * we have yet to see a case where that will happen.
493 * The existing ARM mainboards don't even call this function
494 * so this will not affect them.
495 */
496 out->framebuffer_bits_per_pixel = 32;
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700497
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700498 out->x_resolution = ALIGN(out->mode.ha *
499 ((out->framebuffer_bits_per_pixel + 7) / 8),
500 64) / (out->framebuffer_bits_per_pixel/8);
501 out->y_resolution = out->mode.va;
502 out->bytes_per_line = ALIGN(out->mode.ha *
503 ((out->framebuffer_bits_per_pixel + 7)/8),
504 64);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700505 switch ((x[17] & 0x18) >> 3) {
506 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700507 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700508 break;
509 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700510 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700511 break;
512 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700513 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700514 break;
515 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700516 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700517 break;
518 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700519 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
520 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700521 switch (x[17] & 0x61) {
522 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700523 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700524 break;
525 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700526 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700527 break;
528 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700529 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700530 break;
531 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700532 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700533 break;
534 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700535 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700536 break;
537 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700538 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700539 break;
540 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700541 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700542 break;
543 }
544
Furquan Shaikh6b190712013-07-22 16:18:31 -0700545 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700546 " %04x %04x %04x %04x hborder %x\n"
547 " %04x %04x %04x %04x vborder %x\n"
548 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700549 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700550 extra_info.x_mm,
551 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700552 out->mode.ha, out->mode.ha + out->mode.hso,
553 out->mode.ha + out->mode.hso + out->mode.hspw,
554 out->mode.ha + out->mode.hbl, out->mode.hborder,
555 out->mode.va, out->mode.va + out->mode.vso,
556 out->mode.va + out->mode.vso + out->mode.vspw,
557 out->mode.va + out->mode.vbl, out->mode.vborder,
558 out->mode.phsync, out->mode.pvsync,
David Hendricksa3b898a2015-08-02 18:07:48 -0700559 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700560 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700561
562 if (! c->did_detailed_timing) {
563 printk(BIOS_SPEW, "Did detailed timing\n");
564 c->did_detailed_timing = 1;
565 *result_edid = *out;
566 }
567
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700568 return 1;
569}
570
571static int
572do_checksum(unsigned char *x)
573{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800574 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600575 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700576 {
577 unsigned char sum = 0;
578 int i;
579 for (i = 0; i < 128; i++)
580 sum += x[i];
581 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600582 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700583 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800584 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700585 printk(BIOS_SPEW, " (valid)");
586 }
587 }
588 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800589 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700590}
591
592/* CEA extension */
593
594static const char *
595audio_format(unsigned char x)
596{
597 switch (x) {
598 case 0: return "RESERVED";
599 case 1: return "Linear PCM";
600 case 2: return "AC-3";
601 case 3: return "MPEG 1 (Layers 1 & 2)";
602 case 4: return "MPEG 1 Layer 3 (MP3)";
603 case 5: return "MPEG2 (multichannel)";
604 case 6: return "AAC";
605 case 7: return "DTS";
606 case 8: return "ATRAC";
607 case 9: return "One Bit Audio";
608 case 10: return "Dolby Digital+";
609 case 11: return "DTS-HD";
610 case 12: return "MAT (MLP)";
611 case 13: return "DST";
612 case 14: return "WMA Pro";
613 case 15: return "RESERVED";
614 }
615 return "BROKEN"; /* can't happen */
616}
617
618static void
619cea_audio_block(unsigned char *x)
620{
621 int i, format;
622 int length = x[0] & 0x1f;
623
624 if (length % 3) {
625 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
626 /* XXX non-conformant */
627 return;
628 }
629
630 for (i = 1; i < length; i += 3) {
631 format = (x[i] & 0x78) >> 3;
632 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
633 x[i] & 0x07);
634 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
635 (x[i+1] & 0x40) ? " 192" : "",
636 (x[i+1] & 0x20) ? " 176.4" : "",
637 (x[i+1] & 0x10) ? " 96" : "",
638 (x[i+1] & 0x08) ? " 88.2" : "",
639 (x[i+1] & 0x04) ? " 48" : "",
640 (x[i+1] & 0x02) ? " 44.1" : "",
641 (x[i+1] & 0x01) ? " 32" : "");
642 if (format == 1) {
643 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
644 (x[2] & 0x04) ? " 24" : "",
645 (x[2] & 0x02) ? " 20" : "",
646 (x[2] & 0x01) ? " 16" : "");
647 } else if (format <= 8) {
648 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
649 }
650 }
651}
652
653static void
654cea_video_block(unsigned char *x)
655{
656 int i;
657 int length = x[0] & 0x1f;
658
659 for (i = 1; i < length; i++)
660 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
661 x[i] & 0x80 ? "(native)" : "");
662}
663
664static void
665cea_hdmi_block(struct edid *out, unsigned char *x)
666{
667 int length = x[0] & 0x1f;
668
Yakir Yang85810cc2015-10-27 16:17:13 +0800669 out->hdmi_monitor_detected = 1;
670
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700671 printk(BIOS_SPEW, " (HDMI)\n");
672 printk(BIOS_SPEW,
673 " Source physical address %d.%d.%d.%d\n",
674 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
675
676 if (length > 5) {
677 if (x[6] & 0x80)
678 printk(BIOS_SPEW, " Supports_AI\n");
679 if (x[6] & 0x40)
680 printk(BIOS_SPEW, " DC_48bit\n");
681 if (x[6] & 0x20)
682 printk(BIOS_SPEW, " DC_36bit\n");
683 if (x[6] & 0x10)
684 printk(BIOS_SPEW, " DC_30bit\n");
685 if (x[6] & 0x08)
686 printk(BIOS_SPEW, " DC_Y444\n");
687 /* two reserved */
688 if (x[6] & 0x01)
689 printk(BIOS_SPEW, " DVI_Dual\n");
690 }
691
692 if (length > 6)
693 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
694
695 /* XXX the walk here is really ugly, and needs to be length-checked */
696 if (length > 7) {
697 int b = 0;
698
699 if (x[8] & 0x80) {
700 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
701 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
702 b += 2;
703 }
704
705 if (x[8] & 0x40) {
706 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
707 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
708 b += 2;
709 }
710
711 if (x[8] & 0x20) {
712 int mask = 0, formats = 0;
713 int len_xx, len_3d;
714 printk(BIOS_SPEW, " Extended HDMI video details:\n");
715 if (x[9 + b] & 0x80)
716 printk(BIOS_SPEW, " 3D present\n");
717 if ((x[9 + b] & 0x60) == 0x20) {
718 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
719 formats = 1;
720 }
721 if ((x[9 + b] & 0x60) == 0x40) {
722 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
723 formats = 1;
724 mask = 1;
725 }
726 switch (x[9 + b] & 0x18) {
727 case 0x00: break;
728 case 0x08:
729 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
730 break;
731 case 0x10:
732 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
733 break;
734 case 0x18:
735 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
736 break;
737 }
738 len_xx = (x[10 + b] & 0xe0) >> 5;
739 len_3d = (x[10 + b] & 0x1f) >> 0;
740 b += 2;
741
742 if (len_xx) {
743 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
744 " document\n", len_xx);
745 b += len_xx;
746 }
747
748 if (len_3d) {
749 if (formats) {
750 if (x[9 + b] & 0x01)
751 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
752 if (x[10 + b] & 0x40)
753 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
754 if (x[10 + b] & 0x01)
755 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
756 b += 2;
757 }
758 if (mask) {
759 int i;
760 printk(BIOS_SPEW, " 3D VIC indices:");
761 /* worst bit ordering ever */
762 for (i = 0; i < 8; i++)
763 if (x[10 + b] & (1 << i))
764 printk(BIOS_SPEW, " %d", i);
765 for (i = 0; i < 8; i++)
766 if (x[9 + b] & (1 << i))
767 printk(BIOS_SPEW, " %d", i + 8);
768 printk(BIOS_SPEW, "\n");
769 b += 2;
770 }
771
772 /*
773 * XXX list of nibbles:
774 * 2D_VIC_Order_X
775 * 3D_Structure_X
776 * (optionally: 3D_Detail_X and reserved)
777 */
778 }
779
780 }
781 }
782}
783
784static void
785cea_block(struct edid *out, unsigned char *x)
786{
787 unsigned int oui;
788
789 switch ((x[0] & 0xe0) >> 5) {
790 case 0x01:
791 printk(BIOS_SPEW, " Audio data block\n");
792 cea_audio_block(x);
793 break;
794 case 0x02:
795 printk(BIOS_SPEW, " Video data block\n");
796 cea_video_block(x);
797 break;
798 case 0x03:
799 /* yes really, endianness lols */
800 oui = (x[3] << 16) + (x[2] << 8) + x[1];
801 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
802 if (oui == 0x000c03)
803 cea_hdmi_block(out, x);
804 else
805 printk(BIOS_SPEW, "\n");
806 break;
807 case 0x04:
808 printk(BIOS_SPEW, " Speaker allocation data block\n");
809 break;
810 case 0x05:
811 printk(BIOS_SPEW, " VESA DTC data block\n");
812 break;
813 case 0x07:
814 printk(BIOS_SPEW, " Extended tag: ");
815 switch (x[1]) {
816 case 0x00:
817 printk(BIOS_SPEW, "video capability data block\n");
818 break;
819 case 0x01:
820 printk(BIOS_SPEW, "vendor-specific video data block\n");
821 break;
822 case 0x02:
823 printk(BIOS_SPEW, "VESA video display device information data block\n");
824 break;
825 case 0x03:
826 printk(BIOS_SPEW, "VESA video data block\n");
827 break;
828 case 0x04:
829 printk(BIOS_SPEW, "HDMI video data block\n");
830 break;
831 case 0x05:
832 printk(BIOS_SPEW, "Colorimetry data block\n");
833 break;
834 case 0x10:
835 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
836 break;
837 case 0x11:
838 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
839 break;
840 case 0x12:
841 printk(BIOS_SPEW, "HDMI audio data block\n");
842 break;
843 default:
844 if (x[1] >= 6 && x[1] <= 15)
845 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
846 else if (x[1] >= 19 && x[1] <= 31)
847 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
848 else
849 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
850 break;
851 }
852 break;
853 default:
854 {
855 int tag = (*x & 0xe0) >> 5;
856 int length = *x & 0x1f;
857 printk(BIOS_SPEW,
858 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
859 break;
860 }
861 }
862}
863
864static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800865parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700866{
867 int ret = 0;
868 int version = x[1];
869 int offset = x[2];
870 unsigned char *detailed;
871
872 if (version >= 1) do {
873 if (version == 1 && x[3] != 0)
874 ret = 1;
875
876 if (offset < 4)
877 break;
878
879 if (version < 3) {
880 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
881 if (offset - 4 > 0)
882 /* do stuff */ ;
883 } else if (version == 3) {
884 int i;
885 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
886 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
887 cea_block(out, x + i);
888 }
889 }
890
891 if (version >= 2) {
892 if (x[3] & 0x80)
893 printk(BIOS_SPEW, "Underscans PC formats by default\n");
894 if (x[3] & 0x40)
895 printk(BIOS_SPEW, "Basic audio support\n");
896 if (x[3] & 0x20)
897 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
898 if (x[3] & 0x10)
899 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
900 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
901 }
902
903 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
904 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800905 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700906 } while (0);
907
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800908 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700909 return ret;
910}
911
912/* generic extension code */
913
914static void
915extension_version(struct edid *out, unsigned char *x)
916{
917 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
918}
919
920static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800921parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700922{
923 int conformant_extension = 0;
924 printk(BIOS_SPEW, "\n");
925
926 switch(x[0]) {
927 case 0x02:
928 printk(BIOS_SPEW, "CEA extension block\n");
929 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800930 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700931 break;
932 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
933 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
934 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
935 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
936 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800937 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700938 default:
939 printk(BIOS_SPEW, "Unknown extension block\n");
940 break;
941 }
942
943 printk(BIOS_SPEW, "\n");
944
945 return conformant_extension;
946}
947
948static const struct {
949 int x, y, refresh;
950} established_timings[] = {
951 /* 0x23 bit 7 - 0 */
952 {720, 400, 70},
953 {720, 400, 88},
954 {640, 480, 60},
955 {640, 480, 67},
956 {640, 480, 72},
957 {640, 480, 75},
958 {800, 600, 56},
959 {800, 600, 60},
960 /* 0x24 bit 7 - 0 */
961 {800, 600, 72},
962 {800, 600, 75},
963 {832, 624, 75},
964 {1280, 768, 87},
965 {1024, 768, 60},
966 {1024, 768, 70},
967 {1024, 768, 75},
968 {1280, 1024, 75},
969 /* 0x25 bit 7*/
970 {1152, 870, 75},
971};
972
973static void print_subsection(const char *name, unsigned char *edid, int start,
974 int end)
975{
976 int i;
977
978 printk(BIOS_SPEW, "%s:", name);
979 for (i = strlen(name); i < 15; i++)
980 printk(BIOS_SPEW, " ");
981 for (i = start; i <= end; i++)
982 printk(BIOS_SPEW, " %02x", edid[i]);
983 printk(BIOS_SPEW, "\n");
984}
985
986static void dump_breakdown(unsigned char *edid)
987{
988 printk(BIOS_SPEW, "Extracted contents:\n");
989 print_subsection("header", edid, 0, 7);
990 print_subsection("serial number", edid, 8, 17);
991 print_subsection("version", edid,18, 19);
992 print_subsection("basic params", edid, 20, 24);
993 print_subsection("chroma info", edid, 25, 34);
994 print_subsection("established", edid, 35, 37);
995 print_subsection("standard", edid, 38, 53);
996 print_subsection("descriptor 1", edid, 54, 71);
997 print_subsection("descriptor 2", edid, 72, 89);
998 print_subsection("descriptor 3", edid, 90, 107);
999 print_subsection("descriptor 4", edid, 108, 125);
1000 print_subsection("extensions", edid, 126, 126);
1001 print_subsection("checksum", edid, 127, 127);
1002 printk(BIOS_SPEW, "\n");
1003}
1004
1005/*
David Hendrickse2054102015-08-07 18:41:37 -07001006 * Lookup table of some well-known modes that can be useful in case the
1007 * auto-detected mode is unsuitable.
1008 * ha = hdisplay; va = vdisplay;
1009 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1010 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1011 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1012 */
1013static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1014 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001015 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001016 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001017 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1018 .phsync = '-', .pvsync = '-' },
1019 [EDID_MODE_720x480_60Hz] = {
1020 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001021 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001022 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1023 .phsync = '-', .pvsync = '-' },
1024 [EDID_MODE_1280x720_60Hz] = {
1025 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001026 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001027 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1028 .phsync = '+', .pvsync = '+' },
1029 [EDID_MODE_1920x1080_60Hz] = {
1030 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001031 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001032 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1033 .phsync = '+', .pvsync = '+' },
1034};
1035
1036int set_display_mode(struct edid *edid, enum edid_modes mode)
1037{
1038 if (mode == EDID_MODE_AUTO)
1039 return 0;
1040
1041 if (edid->mode_is_supported[mode]) {
1042 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1043 edid->mode = known_modes[mode];
1044 return 0;
1045 }
1046
1047 printk(BIOS_ERR, "Requested display mode not supported.\n");
1048 return -1;
1049}
1050
1051/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001052 * Given a raw edid bloc, decode it into a form
1053 * that other parts of coreboot can use -- mainly
1054 * graphics bringup functions. The raw block is
1055 * required to be 128 bytes long, per the standard,
1056 * but we have no way of checking this minimum length.
1057 * We accept what we are given.
1058 */
1059int decode_edid(unsigned char *edid, int size, struct edid *out)
1060{
David Hendrickse2054102015-08-07 18:41:37 -07001061 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001062 struct edid_context c = {
1063 .has_valid_cvt = 1,
1064 .has_valid_dummy_block = 1,
1065 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001066 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001067 .has_valid_descriptor_pad = 1,
1068 .has_valid_range_descriptor = 1,
1069 .has_valid_max_dotclock = 1,
1070 .has_valid_string_termination = 1,
1071 .conformant = 1,
1072 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001073
1074 dump_breakdown(edid);
1075
David Hendricks40e89b42015-08-13 15:51:00 -07001076 memset(out, 0, sizeof(*out));
1077
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001078 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1079 printk(BIOS_SPEW, "No header found\n");
1080 return 1;
1081 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001082
David Hendricksa3b898a2015-08-02 18:07:48 -07001083 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001084 c.manufacturer_name_well_formed = 1;
1085
David Hendricksa3b898a2015-08-02 18:07:48 -07001086 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1087 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001088 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1089
1090 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001091 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001092 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1093 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1094 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001095 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001096
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001097 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001098 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001099 if (edid[0x11] > 0x0f) {
1100 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001101 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001102 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001103 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001104 extra_info.week = edid[0x10];
1105 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001106 } else {
1107 /* we know it's at least 2013, when this code was written */
1108 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001109 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001110 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001111 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001112 extra_info.week = edid[0x10];
1113 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001114 }
1115 }
1116 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001117 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001118
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001119 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001120 extra_info.version[0] = edid[0x12];
1121 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001122
1123 if (edid[0x12] == 1) {
1124 if (edid[0x13] > 4) {
1125 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1126 edid[0x13] = 4;
1127 }
1128 switch (edid[0x13]) {
1129 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001130 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001131 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001132 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001133 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001134 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001135 default:
1136 break;
1137 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001138 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001139 }
1140
1141 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001142 if (edid[0x14] & 0x80) {
1143 int conformance_mask;
1144 analog = 0;
1145 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001146 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001147 conformance_mask = 0;
1148 if ((edid[0x14] & 0x70) == 0x00)
1149 printk(BIOS_SPEW, "Color depth is undefined\n");
1150 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001151 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001152 else
1153 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1154 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001155 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1156 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001157
1158 switch (edid[0x14] & 0x0f) {
1159 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1160 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1161 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1162 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1163 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1164 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1165 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001166 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001167 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001168 extra_info.type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001169 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001170 conformance_mask = 0x7E;
1171 if (edid[0x14] & 0x01) {
1172 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1173 }
1174 } else
1175 conformance_mask = 0x7F;
1176
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001177 if (!c.nonconformant_digital_display)
1178 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001179 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001180 } else {
1181 analog = 1;
1182 int voltage = (edid[0x14] & 0x60) >> 5;
1183 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001184 extra_info.voltage = voltage;
1185 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001186
1187 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1188 voltage == 3 ? "0.7/0.7" :
1189 voltage == 2 ? "1.0/0.4" :
1190 voltage == 1 ? "0.714/0.286" :
1191 "0.7/0.3");
1192
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001193 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001194 if (edid[0x14] & 0x10)
1195 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1196 else
1197 printk(BIOS_SPEW, "Blank level equals black level\n");
1198 } else if (edid[0x14] & 0x10) {
1199 /*
1200 * XXX this is just the X text. 1.3 says "if set, display expects
1201 * a blank-to-black setup or pedestal per appropriate Signal
1202 * Level Standard". Whatever _that_ means.
1203 */
1204 printk(BIOS_SPEW, "Configurable signal levels\n");
1205 }
1206
1207 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1208 sync & 0x04 ? "Composite " : "",
1209 sync & 0x02 ? "SyncOnGreen " : "",
1210 sync & 0x01 ? "Serration " : "");
1211 }
1212
1213
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001214 if (edid[0x15] && edid[0x16]) {
1215 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1216 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001217 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001218 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1219 unsigned int ratio = 100000/(edid[0x15] + 99);
1220 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1221 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001222 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1223 unsigned int ratio = 100000/(edid[0x16] + 99);
1224 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1225 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001226 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001227 } else {
1228 /* Either or both can be zero for 1.3 and before */
1229 printk(BIOS_SPEW, "Image size is variable\n");
1230 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001231
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001232 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001233 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001234 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1235 else
1236 /* XXX Technically 1.3 doesn't say this... */
1237 printk(BIOS_SPEW, "Gamma: 1.0\n");
1238 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1239 printk(BIOS_SPEW, "Check DPMS levels\n");
1240 if (edid[0x18] & 0xE0) {
1241 printk(BIOS_SPEW, "DPMS levels:");
1242 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1243 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1244 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1245 printk(BIOS_SPEW, "\n");
1246 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001247
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001248 /* FIXME: this is from 1.4 spec, check earlier */
1249 if (analog) {
1250 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001251 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1252 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1253 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1254 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001255 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001256 } else {
1257 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1258 if (edid[0x18] & 0x10)
1259 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1260 if (edid[0x18] & 0x08)
1261 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1262 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001263 }
1264
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001265 if (edid[0x18] & 0x04)
1266 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1267 if (edid[0x18] & 0x02) {
1268 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001269 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001270 }
1271 if (edid[0x18] & 0x01)
1272 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1273
1274 /* XXX color section */
1275
1276 printk(BIOS_SPEW, "Established timings supported:\n");
1277 /* it's not yet clear we want all this stuff in the edid struct.
1278 * Let's wait.
1279 */
1280 for (i = 0; i < 17; i++) {
1281 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1282 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1283 established_timings[i].y, established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001284
Douglas Anderson9fa07602015-10-28 10:19:52 -07001285 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1286 if (known_modes[j].ha == established_timings[i].x &&
1287 known_modes[j].va == established_timings[i].y &&
1288 known_modes[j].refresh == established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001289 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001290 }
David Hendrickse2054102015-08-07 18:41:37 -07001291 }
1292
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001293 }
1294
1295 printk(BIOS_SPEW, "Standard timings supported:\n");
1296 for (i = 0; i < 8; i++) {
1297 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1298 unsigned int x, y = 0, refresh;
1299
1300 if (b1 == 0x01 && b2 == 0x01)
1301 continue;
1302
1303 if (b1 == 0) {
1304 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1305 continue;
1306 }
1307 x = (b1 + 31) * 8;
1308 switch ((b2 >> 6) & 0x3) {
1309 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001310 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001311 y = x * 10 / 16;
1312 else
1313 y = x;
1314 break;
1315 case 0x01:
1316 y = x * 3 / 4;
1317 break;
1318 case 0x02:
1319 y = x * 4 / 5;
1320 break;
1321 case 0x03:
1322 y = x * 9 / 16;
1323 break;
1324 }
1325 refresh = 60 + (b2 & 0x3f);
1326
1327 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001328 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1329 if (known_modes[j].ha == x && known_modes[j].va == y &&
1330 known_modes[j].refresh == refresh)
1331 out->mode_is_supported[j] = 1;
1332 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001333 }
1334
1335 /* detailed timings */
1336 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001337 for (i = 0; i < 4; i++) {
1338 c.has_valid_detailed_blocks &= detailed_block(
1339 out, edid + 0x36 + i * 18, 0, &c);
1340 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1341 {
1342 /* not really accurate... */
1343 c.has_preferred_timing = 0;
1344 }
1345 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001346
1347 /* check this, 1.4 verification guide says otherwise */
1348 if (edid[0x7e]) {
1349 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1350 /* 2 is impossible because of the block map */
1351 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001352 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001353 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001354 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001355 }
1356
1357 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001358 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001359
1360 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1361 * the extension parsing loop below. Since v2.0 was quickly deprecated
1362 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1363 * that case now and can fix it when we need to use a real 2.0 panel.
1364 */
1365 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001366 c.nonconformant_extension +=
1367 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001368
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001369 if (c.claims_one_point_four) {
1370 if (c.nonconformant_digital_display ||
1371 !c.has_valid_string_termination ||
1372 !c.has_valid_descriptor_pad ||
1373 !c.has_preferred_timing)
1374 c.conformant = 0;
1375 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001376 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001377 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001378 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001379 c.nonconformant_digital_display);
1380 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001381 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001382 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001383 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001384 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001385 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001386 } else if (c.claims_one_point_three) {
1387 if (c.nonconformant_digital_display ||
1388 !c.has_valid_string_termination ||
1389 !c.has_valid_descriptor_pad ||
1390 !c.has_preferred_timing) {
1391 c.conformant = 0;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001392 }
1393 /**
1394 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1395 * has_range_descriptor are both required. These fields are
1396 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1397 * don't have them. As a workaround, we only print warning
1398 * messages.
1399 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001400 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001401 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001402 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001403 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1404 "fully conform to EDID 1.3.\n");
1405
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001406 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001407 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001408 c.nonconformant_digital_display);
1409 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001410 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001411 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001412 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001413 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001414 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001415 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001416 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001417 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001418 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001419 } else if (c.claims_one_point_two) {
1420 if (c.nonconformant_digital_display ||
1421 !c.has_valid_string_termination)
1422 c.conformant = 0;
1423 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001424 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001425 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001426 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001427 c.nonconformant_digital_display);
1428 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001429 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001430 } else if (c.claims_one_point_oh) {
1431 if (c.seen_non_detailed_descriptor)
1432 c.conformant = 0;
1433 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001434 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001435 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001436 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1437 }
1438
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001439 if (c.nonconformant_extension ||
1440 !c.has_valid_checksum ||
1441 !c.has_valid_cvt ||
1442 !c.has_valid_year ||
1443 !c.has_valid_week ||
1444 !c.has_valid_detailed_blocks ||
1445 !c.has_valid_dummy_block ||
1446 !c.has_valid_extension_count ||
1447 !c.has_valid_descriptor_ordering ||
1448 !c.has_valid_range_descriptor ||
1449 !c.manufacturer_name_well_formed) {
1450 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001451 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001452 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001453 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001454 c.nonconformant_extension);
1455 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001456 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001457 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001458 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001459 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001460 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001461 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001462 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001463 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001464 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001465 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001466 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001467 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001468 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001469 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001470 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001471 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001472 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001473 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001474 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001475 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001476 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1477 }
1478
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001479 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001480 printk(BIOS_ERR,
1481 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001482 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001483 printk(BIOS_ERR,
1484 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001485 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001486}
1487
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001488/*
1489 * Notes on panel extensions: (TODO, implement me in the code)
1490 *
1491 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1492 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1493 * 0x6c: 00 00 00 0e 00
1494 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1495 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1496 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1497 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1498 * bit 4: DE polarity (0 high active 1 low active)
1499 * bit 3-0: interface (0000 LVDS TFT
1500 * 0001 mono STN 4/8bit
1501 * 0010 color STN 8/16 bit
1502 * 0011 18 bit tft
1503 * 0100 24 bit tft
1504 * 0101 tmds
1505 * else reserved)
1506 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1507 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1508 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1509 * else time in 10ms (10ms to 150ms))
1510 * bit 3-0: total poweron seq delay (as above)
1511 * 0x75: contrast power on/off seq delay, same as 0x74
1512 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1513 * bit 6: backlight enabled at boot (0 on 1 off)
1514 * bit 5-0: backlight brightness control steps (0..63)
1515 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1516 * 0x78 - 0x7c: reserved
1517 * 0x7d: bit 7-4: EPI descriptor major version (1)
1518 * bit 3-0: EPI descriptor minor version (0)
1519 *
1520 * ----
1521 *
1522 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1523 *
1524 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1525 *
1526 * detailed descriptor 3:
1527 * 0x5a - 0x5e: 00 00 00 fe 00
1528 * 0x5f - 0x63: PC maker part number
1529 * 0x64: LCD supplier revision #
1530 * 0x65 - 0x6b: manufacturer part number
1531 *
1532 * detailed descriptor 4:
1533 * 0x6c - 0x70: 00 00 00 fe 00
1534 * 0x71 - 0x78: smbus nits values (whut)
1535 * 0x79: number of lvds channels (1 or 2)
1536 * 0x7A: panel self test (1 if present)
1537 * and then dummy terminator
1538 *
1539 * SPWG also says something strange about the LSB of detailed descriptor 1:
1540 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1541 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001542/*
1543 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1544 */
1545
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001546void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1547{
1548 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001549 edid_fb.x_resolution = edid->x_resolution;
1550 edid_fb.y_resolution = edid->y_resolution;
1551 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001552 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001553 * seems to be to round it up to the nearest reasonable
1554 * boundary, because otherwise the byte-packing is hideous.
1555 * So, for example, in RGB with no alpha, the bytes are still
1556 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1557 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1558 * and in 4:4:4 mode, they are packed into 16-bit words.
1559 * Good call on the hardware guys part.
1560 * It's not clear we're covering all cases here, but
1561 * I'm not sure with grahpics you ever can.
1562 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001563 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001564 edid_fb.reserved_mask_pos = 0;
1565 edid_fb.reserved_mask_size = 0;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001566 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001567 case 32:
1568 case 24:
1569 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001570 edid_fb.reserved_mask_pos = 24;
1571 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001572 edid_fb.red_mask_pos = 16;
1573 edid_fb.red_mask_size = 8;
1574 edid_fb.green_mask_pos = 8;
1575 edid_fb.green_mask_size = 8;
1576 edid_fb.blue_mask_pos = 0;
1577 edid_fb.blue_mask_size = 8;
1578 break;
1579 case 16:
1580 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001581 edid_fb.red_mask_pos = 11;
1582 edid_fb.red_mask_size = 5;
1583 edid_fb.green_mask_pos = 5;
1584 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001585 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001586 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001587 break;
1588 default:
1589 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001590 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001591 return;
1592 }
1593
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001594 vbe_valid = 1;
1595}
1596
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001597#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001598int vbe_mode_info_valid(void)
1599{
1600 return vbe_valid;
1601}
1602
1603void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1604{
1605 *framebuffer = edid_fb;
1606}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001607#endif