blob: 52898fbfa6e6df0a6dc6a5cd46597541ded2430f [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
Julius Werner69112192016-03-14 17:29:55 -070031#include <assert.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070032#include <stddef.h>
33#include <console/console.h>
34#include <arch/io.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070035#include <stdint.h>
36#include <string.h>
37#include <stdlib.h>
38#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070039#include <boot/coreboot_tables.h>
40#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070041
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080042struct edid_context {
43 int claims_one_point_oh;
44 int claims_one_point_two;
45 int claims_one_point_three;
46 int claims_one_point_four;
47 int nonconformant_digital_display;
48 int nonconformant_extension;
49 int did_detailed_timing;
50 int has_name_descriptor;
51 int has_range_descriptor;
52 int has_preferred_timing;
53 int has_valid_checksum;
54 int has_valid_cvt;
55 int has_valid_dummy_block;
56 int has_valid_week;
57 int has_valid_year;
58 int has_valid_detailed_blocks;
59 int has_valid_extension_count;
60 int has_valid_descriptor_ordering;
61 int has_valid_descriptor_pad;
62 int has_valid_range_descriptor;
63 int has_valid_max_dotclock;
64 int has_valid_string_termination;
65 int manufacturer_name_well_formed;
66 int seen_non_detailed_descriptor;
67 int warning_excessive_dotclock_correction;
68 int warning_zero_preferred_refresh;
69 int conformant;
70};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070071
David Hendricksa3b898a2015-08-02 18:07:48 -070072/* Stuff that isn't used anywhere but is nice to pretty-print while
73 we're decoding everything else. */
74static struct {
75 char manuf_name[4];
76 unsigned int model;
77 unsigned int serial;
78 unsigned int year;
79 unsigned int week;
80 unsigned int version[2];
81 unsigned int nonconformant;
82 unsigned int type;
83
84 unsigned int x_mm;
85 unsigned int y_mm;
86
87 unsigned int voltage;
88 unsigned int sync;
89
90 const char *syncmethod;
91 const char *range_class;
92 const char *stereo;
93} extra_info;
94
Douglas Andersonbca67fb2015-10-28 09:18:28 -070095static struct edid tmp_edid;
96
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070097static int vbe_valid;
98static struct lb_framebuffer edid_fb;
99
David Hendricksa3b898a2015-08-02 18:07:48 -0700100static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700101{
David Hendricksa3b898a2015-08-02 18:07:48 -0700102 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
103 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
104 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
105 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700106
David Hendricksa3b898a2015-08-02 18:07:48 -0700107 if (isupper(extra_info.manuf_name[0]) &&
108 isupper(extra_info.manuf_name[1]) &&
109 isupper(extra_info.manuf_name[2]))
110 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700111
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800112 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700113}
114
115static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700116detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700117{
118 const unsigned char empty[3] = { 0, 0, 0 };
119 const char *names[] = { "50", "60", "75", "85" };
120 int width = 0, height = 0;
121 int valid = 1;
122 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
123
124 if (!first && !memcmp(x, empty, 3))
125 return valid;
126
127 height = x[0];
128 height |= (x[1] & 0xf0) << 4;
129 height++;
130 height *= 2;
131
132 switch (x[1] & 0x0c) {
133 case 0x00:
134 width = (height * 4) / 3; break;
135 case 0x04:
136 width = (height * 16) / 9; break;
137 case 0x08:
138 width = (height * 16) / 10; break;
139 case 0x0c:
140 width = (height * 15) / 9; break;
141 }
142
143 if (x[1] & 0x03)
144 valid = 0;
145 if (x[2] & 0x80)
146 valid = 0;
147 if (!(x[2] & 0x1f))
148 valid = 0;
149
150 fifty = (x[2] & 0x10);
151 sixty = (x[2] & 0x08);
152 seventyfive = (x[2] & 0x04);
153 eightyfive = (x[2] & 0x02);
154 reduced = (x[2] & 0x01);
155
156 if (!valid) {
157 printk(BIOS_SPEW, " (broken)\n");
158 } else {
159 printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
160 width, height,
161 fifty ? "50 " : "",
162 sixty ? "60 " : "",
163 seventyfive ? "75 " : "",
164 eightyfive ? "85 " : "",
165 reduced ? "60RB " : "",
166 names[(x[2] & 0x60) >> 5],
167 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
168 }
169
170 return valid;
171}
172
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800173/* extract a CP437 string from a detailed subblock, checking for termination (if
174 * less than len of bytes) with LF and padded with SP.
175 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700176static char *
177extract_string(unsigned char *x, int *valid_termination, int len)
178{
179 static char ret[128];
180 int i, seen_newline = 0;
181
182 memset(ret, 0, sizeof(ret));
183
184 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800185 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700186 if (x[i] != 0x20) {
187 *valid_termination = 0;
188 return ret;
189 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800190 } else if (x[i] == 0x0a) {
191 seen_newline = 1;
192 } else {
193 /* normal characters */
194 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700195 }
196 }
197
198 return ret;
199}
200
201/* 1 means valid data */
202static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700203detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800204 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700205{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700206 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700207 int i;
208#if 1
209 printk(BIOS_SPEW, "Hex of detail: ");
210 for (i = 0; i < 18; i++)
211 printk(BIOS_SPEW, "%02x", x[i]);
212 printk(BIOS_SPEW, "\n");
213#endif
214
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700215 /* Result might already have some valid fields like mode_is_supported */
216 *out = *result_edid;
217
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700218 if (x[0] == 0 && x[1] == 0) {
219 /* Monitor descriptor block, not detailed timing descriptor. */
220 if (x[2] != 0) {
221 /* 1.3, 3.10.3 */
222 printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
223 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800224 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700225 }
226 if (x[3] != 0xfd && x[4] != 0x00) {
227 /* 1.3, 3.10.3 */
228 printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
229 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800230 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700231 }
232
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800233 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700234 if (x[3] <= 0xF) {
235 /*
236 * in principle we can decode these, if we know what they are.
237 * 0x0f seems to be common in laptop panels.
238 * 0x0e is used by EPI: http://www.epi-standard.org/
239 */
240 printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800241 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700242 }
243 switch (x[3]) {
244 case 0x10:
245 printk(BIOS_SPEW, "Dummy block\n");
246 for (i = 5; i < 18; i++)
247 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800248 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800249 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700250 case 0xF7:
251 /* TODO */
252 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800253 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700254 case 0xF8:
255 {
256 int valid_cvt = 1; /* just this block */
257 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
258 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800259 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700260 return 0;
261 }
262 for (i = 0; i < 4; i++)
Douglas Anderson14dd3702015-10-28 11:19:57 -0700263 valid_cvt &= detailed_cvt_descriptor(x + 6 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800264 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800265 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700266 }
267 case 0xF9:
268 /* TODO */
269 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800270 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700271 case 0xFA:
272 /* TODO */
273 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800274 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700275 case 0xFB:
276 /* TODO */
277 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800278 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700279 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800280 printk(BIOS_SPEW, "Monitor name: %s\n",
281 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800282 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800283 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800284 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700285 case 0xFD:
286 {
287 int h_max_offset = 0, h_min_offset = 0;
288 int v_max_offset = 0, v_min_offset = 0;
289 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800290 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700291 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700292 /*
293 * XXX todo: implement feature flags, vtd blocks
294 * XXX check: ranges are well-formed; block termination if no vtd
295 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800296 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700297 if (x[4] & 0x02) {
298 v_max_offset = 255;
299 if (x[4] & 0x01) {
300 v_min_offset = 255;
301 }
302 }
303 if (x[4] & 0x04) {
304 h_max_offset = 255;
305 if (x[4] & 0x03) {
306 h_min_offset = 255;
307 }
308 }
309 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800310 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700311 }
312
313 /*
314 * despite the values, this is not a bitfield.
315 */
316 switch (x[10]) {
317 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700318 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700319 break;
320 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700321 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800322 if (!c->claims_one_point_four)
323 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700324 break;
325 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700326 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700327 break;
328 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700329 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700330 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800331 if (!c->claims_one_point_four)
332 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700333 break;
334 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800335 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700336 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700337 break;
338 }
339
340 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800341 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700342 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800343 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700344 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700345 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700346 x[5] + v_min_offset, x[6] + v_max_offset,
347 x[7] + h_min_offset, x[8] + h_max_offset);
348 if (x[9])
349 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
350 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800351 if (c->claims_one_point_four)
352 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700353 printk(BIOS_SPEW, "\n");
354 }
355
356 if (is_cvt) {
357 int max_h_pixels = 0;
358
359 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
360
361 if (x[12] & 0xfc) {
362 int raw_offset = (x[12] & 0xfc) >> 2;
Patrick Georgibe71ee5d2014-12-15 22:52:14 +0100363 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
364 (x[9] * 10000) - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700365 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800366 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700367 }
368
369 max_h_pixels = x[12] & 0x03;
370 max_h_pixels <<= 8;
371 max_h_pixels |= x[13];
372 max_h_pixels *= 8;
373 if (max_h_pixels)
374 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
375
376 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
377 x[14] & 0x80 ? "4:3" : "",
378 x[14] & 0x40 ? "16:9" : "",
379 x[14] & 0x20 ? "16:10" : "",
380 x[14] & 0x10 ? "5:4" : "",
381 x[14] & 0x08 ? "15:9" : "");
382 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800383 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700384
385 printk(BIOS_SPEW, "Preferred aspect ratio: ");
386 switch((x[15] & 0xe0) >> 5) {
387 case 0x00: printk(BIOS_SPEW, "4:3"); break;
388 case 0x01: printk(BIOS_SPEW, "16:9"); break;
389 case 0x02: printk(BIOS_SPEW, "16:10"); break;
390 case 0x03: printk(BIOS_SPEW, "5:4"); break;
391 case 0x04: printk(BIOS_SPEW, "15:9"); break;
392 default: printk(BIOS_SPEW, "(broken)"); break;
393 }
394 printk(BIOS_SPEW, "\n");
395
396 if (x[15] & 0x04)
397 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
398 if (x[15] & 0x10)
399 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
400
401 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800402 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700403
404 if (x[16] & 0xf0) {
405 printk(BIOS_SPEW, "Supported display scaling:\n");
406 if (x[16] & 0x80)
407 printk(BIOS_SPEW, " Horizontal shrink\n");
408 if (x[16] & 0x40)
409 printk(BIOS_SPEW, " Horizontal stretch\n");
410 if (x[16] & 0x20)
411 printk(BIOS_SPEW, " Vertical shrink\n");
412 if (x[16] & 0x10)
413 printk(BIOS_SPEW, " Vertical stretch\n");
414 }
415
416 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800417 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700418
419 if (x[17])
420 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
421 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800422 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700423 }
424
425 /*
426 * Slightly weird to return a global, but I've never seen any
427 * EDID block wth two range descriptors, so it's harmless.
428 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800429 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700430 }
431 case 0xFE:
432 /*
433 * TODO: Two of these in a row, in the third and fourth slots,
434 * seems to be specified by SPWG: http://www.spwg.org/
435 */
436 printk(BIOS_SPEW, "ASCII string: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800437 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800438 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700439 case 0xFF:
440 printk(BIOS_SPEW, "Serial number: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800441 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800442 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700443 default:
444 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
445 return 0;
446 }
447 }
448
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800449 if (c->seen_non_detailed_descriptor && !in_extension) {
450 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700451 }
452
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700453 /* Edid contains pixel clock in terms of 10KHz */
454 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
455 /*
456 LVDS supports following pixel clocks
457 25000...112000 kHz: single channel
458 80000...224000 kHz: dual channel
459 There is some overlap in theoretically supported
460 pixel clock between single-channel and dual-channel.
461 In practice with current panels all panels
462 <= 75200 kHz: single channel
463 >= 97750 kHz: dual channel
464 We have no samples between those values, so put a
465 threshold at 95000 kHz. If we get anything over
466 95000 kHz with single channel, we can make this
467 more sofisticated but it's currently not needed.
468 */
469 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
470 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
471 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
472 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
473 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
474 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
475 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
476 out->mode.hborder = x[15];
477 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
478 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
479 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
480 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
481 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700482
Julius Werner69112192016-03-14 17:29:55 -0700483 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
484 * Chipsets that want something else will need to override this
485 * with another call to edid_set_framebuffer_bits_per_pixel(). */
486 edid_set_framebuffer_bits_per_pixel(out, 32);
487
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);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700544
545 if (! c->did_detailed_timing) {
546 printk(BIOS_SPEW, "Did detailed timing\n");
547 c->did_detailed_timing = 1;
548 *result_edid = *out;
549 }
550
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700551 return 1;
552}
553
554static int
555do_checksum(unsigned char *x)
556{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800557 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600558 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700559 {
560 unsigned char sum = 0;
561 int i;
562 for (i = 0; i < 128; i++)
563 sum += x[i];
564 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600565 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700566 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800567 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700568 printk(BIOS_SPEW, " (valid)");
569 }
570 }
571 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800572 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700573}
574
575/* CEA extension */
576
577static const char *
578audio_format(unsigned char x)
579{
580 switch (x) {
581 case 0: return "RESERVED";
582 case 1: return "Linear PCM";
583 case 2: return "AC-3";
584 case 3: return "MPEG 1 (Layers 1 & 2)";
585 case 4: return "MPEG 1 Layer 3 (MP3)";
586 case 5: return "MPEG2 (multichannel)";
587 case 6: return "AAC";
588 case 7: return "DTS";
589 case 8: return "ATRAC";
590 case 9: return "One Bit Audio";
591 case 10: return "Dolby Digital+";
592 case 11: return "DTS-HD";
593 case 12: return "MAT (MLP)";
594 case 13: return "DST";
595 case 14: return "WMA Pro";
596 case 15: return "RESERVED";
597 }
598 return "BROKEN"; /* can't happen */
599}
600
601static void
602cea_audio_block(unsigned char *x)
603{
604 int i, format;
605 int length = x[0] & 0x1f;
606
607 if (length % 3) {
608 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
609 /* XXX non-conformant */
610 return;
611 }
612
613 for (i = 1; i < length; i += 3) {
614 format = (x[i] & 0x78) >> 3;
615 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
616 x[i] & 0x07);
617 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
618 (x[i+1] & 0x40) ? " 192" : "",
619 (x[i+1] & 0x20) ? " 176.4" : "",
620 (x[i+1] & 0x10) ? " 96" : "",
621 (x[i+1] & 0x08) ? " 88.2" : "",
622 (x[i+1] & 0x04) ? " 48" : "",
623 (x[i+1] & 0x02) ? " 44.1" : "",
624 (x[i+1] & 0x01) ? " 32" : "");
625 if (format == 1) {
626 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
627 (x[2] & 0x04) ? " 24" : "",
628 (x[2] & 0x02) ? " 20" : "",
629 (x[2] & 0x01) ? " 16" : "");
630 } else if (format <= 8) {
631 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
632 }
633 }
634}
635
636static void
637cea_video_block(unsigned char *x)
638{
639 int i;
640 int length = x[0] & 0x1f;
641
642 for (i = 1; i < length; i++)
643 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
644 x[i] & 0x80 ? "(native)" : "");
645}
646
647static void
648cea_hdmi_block(struct edid *out, unsigned char *x)
649{
650 int length = x[0] & 0x1f;
651
Yakir Yang85810cc2015-10-27 16:17:13 +0800652 out->hdmi_monitor_detected = 1;
653
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700654 printk(BIOS_SPEW, " (HDMI)\n");
655 printk(BIOS_SPEW,
656 " Source physical address %d.%d.%d.%d\n",
657 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
658
659 if (length > 5) {
660 if (x[6] & 0x80)
661 printk(BIOS_SPEW, " Supports_AI\n");
662 if (x[6] & 0x40)
663 printk(BIOS_SPEW, " DC_48bit\n");
664 if (x[6] & 0x20)
665 printk(BIOS_SPEW, " DC_36bit\n");
666 if (x[6] & 0x10)
667 printk(BIOS_SPEW, " DC_30bit\n");
668 if (x[6] & 0x08)
669 printk(BIOS_SPEW, " DC_Y444\n");
670 /* two reserved */
671 if (x[6] & 0x01)
672 printk(BIOS_SPEW, " DVI_Dual\n");
673 }
674
675 if (length > 6)
676 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
677
678 /* XXX the walk here is really ugly, and needs to be length-checked */
679 if (length > 7) {
680 int b = 0;
681
682 if (x[8] & 0x80) {
683 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
684 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
685 b += 2;
686 }
687
688 if (x[8] & 0x40) {
689 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
690 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
691 b += 2;
692 }
693
694 if (x[8] & 0x20) {
695 int mask = 0, formats = 0;
696 int len_xx, len_3d;
697 printk(BIOS_SPEW, " Extended HDMI video details:\n");
698 if (x[9 + b] & 0x80)
699 printk(BIOS_SPEW, " 3D present\n");
700 if ((x[9 + b] & 0x60) == 0x20) {
701 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
702 formats = 1;
703 }
704 if ((x[9 + b] & 0x60) == 0x40) {
705 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
706 formats = 1;
707 mask = 1;
708 }
709 switch (x[9 + b] & 0x18) {
710 case 0x00: break;
711 case 0x08:
712 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
713 break;
714 case 0x10:
715 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
716 break;
717 case 0x18:
718 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
719 break;
720 }
721 len_xx = (x[10 + b] & 0xe0) >> 5;
722 len_3d = (x[10 + b] & 0x1f) >> 0;
723 b += 2;
724
725 if (len_xx) {
726 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
727 " document\n", len_xx);
728 b += len_xx;
729 }
730
731 if (len_3d) {
732 if (formats) {
733 if (x[9 + b] & 0x01)
734 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
735 if (x[10 + b] & 0x40)
736 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
737 if (x[10 + b] & 0x01)
738 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
739 b += 2;
740 }
741 if (mask) {
742 int i;
743 printk(BIOS_SPEW, " 3D VIC indices:");
744 /* worst bit ordering ever */
745 for (i = 0; i < 8; i++)
746 if (x[10 + b] & (1 << i))
747 printk(BIOS_SPEW, " %d", i);
748 for (i = 0; i < 8; i++)
749 if (x[9 + b] & (1 << i))
750 printk(BIOS_SPEW, " %d", i + 8);
751 printk(BIOS_SPEW, "\n");
752 b += 2;
753 }
754
755 /*
756 * XXX list of nibbles:
757 * 2D_VIC_Order_X
758 * 3D_Structure_X
759 * (optionally: 3D_Detail_X and reserved)
760 */
761 }
762
763 }
764 }
765}
766
767static void
768cea_block(struct edid *out, unsigned char *x)
769{
770 unsigned int oui;
771
772 switch ((x[0] & 0xe0) >> 5) {
773 case 0x01:
774 printk(BIOS_SPEW, " Audio data block\n");
775 cea_audio_block(x);
776 break;
777 case 0x02:
778 printk(BIOS_SPEW, " Video data block\n");
779 cea_video_block(x);
780 break;
781 case 0x03:
782 /* yes really, endianness lols */
783 oui = (x[3] << 16) + (x[2] << 8) + x[1];
784 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
785 if (oui == 0x000c03)
786 cea_hdmi_block(out, x);
787 else
788 printk(BIOS_SPEW, "\n");
789 break;
790 case 0x04:
791 printk(BIOS_SPEW, " Speaker allocation data block\n");
792 break;
793 case 0x05:
794 printk(BIOS_SPEW, " VESA DTC data block\n");
795 break;
796 case 0x07:
797 printk(BIOS_SPEW, " Extended tag: ");
798 switch (x[1]) {
799 case 0x00:
800 printk(BIOS_SPEW, "video capability data block\n");
801 break;
802 case 0x01:
803 printk(BIOS_SPEW, "vendor-specific video data block\n");
804 break;
805 case 0x02:
806 printk(BIOS_SPEW, "VESA video display device information data block\n");
807 break;
808 case 0x03:
809 printk(BIOS_SPEW, "VESA video data block\n");
810 break;
811 case 0x04:
812 printk(BIOS_SPEW, "HDMI video data block\n");
813 break;
814 case 0x05:
815 printk(BIOS_SPEW, "Colorimetry data block\n");
816 break;
817 case 0x10:
818 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
819 break;
820 case 0x11:
821 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
822 break;
823 case 0x12:
824 printk(BIOS_SPEW, "HDMI audio data block\n");
825 break;
826 default:
827 if (x[1] >= 6 && x[1] <= 15)
828 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
829 else if (x[1] >= 19 && x[1] <= 31)
830 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
831 else
832 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
833 break;
834 }
835 break;
836 default:
837 {
838 int tag = (*x & 0xe0) >> 5;
839 int length = *x & 0x1f;
840 printk(BIOS_SPEW,
841 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
842 break;
843 }
844 }
845}
846
847static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800848parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700849{
850 int ret = 0;
851 int version = x[1];
852 int offset = x[2];
853 unsigned char *detailed;
854
855 if (version >= 1) do {
856 if (version == 1 && x[3] != 0)
857 ret = 1;
858
859 if (offset < 4)
860 break;
861
862 if (version < 3) {
863 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
864 if (offset - 4 > 0)
865 /* do stuff */ ;
866 } else if (version == 3) {
867 int i;
868 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
869 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
870 cea_block(out, x + i);
871 }
872 }
873
874 if (version >= 2) {
875 if (x[3] & 0x80)
876 printk(BIOS_SPEW, "Underscans PC formats by default\n");
877 if (x[3] & 0x40)
878 printk(BIOS_SPEW, "Basic audio support\n");
879 if (x[3] & 0x20)
880 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
881 if (x[3] & 0x10)
882 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
883 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
884 }
885
886 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
887 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800888 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700889 } while (0);
890
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800891 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700892 return ret;
893}
894
895/* generic extension code */
896
897static void
898extension_version(struct edid *out, unsigned char *x)
899{
900 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
901}
902
903static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800904parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700905{
906 int conformant_extension = 0;
907 printk(BIOS_SPEW, "\n");
908
909 switch(x[0]) {
910 case 0x02:
911 printk(BIOS_SPEW, "CEA extension block\n");
912 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800913 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700914 break;
915 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
916 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
917 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
918 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
919 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800920 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700921 default:
922 printk(BIOS_SPEW, "Unknown extension block\n");
923 break;
924 }
925
926 printk(BIOS_SPEW, "\n");
927
928 return conformant_extension;
929}
930
931static const struct {
932 int x, y, refresh;
933} established_timings[] = {
934 /* 0x23 bit 7 - 0 */
935 {720, 400, 70},
936 {720, 400, 88},
937 {640, 480, 60},
938 {640, 480, 67},
939 {640, 480, 72},
940 {640, 480, 75},
941 {800, 600, 56},
942 {800, 600, 60},
943 /* 0x24 bit 7 - 0 */
944 {800, 600, 72},
945 {800, 600, 75},
946 {832, 624, 75},
947 {1280, 768, 87},
948 {1024, 768, 60},
949 {1024, 768, 70},
950 {1024, 768, 75},
951 {1280, 1024, 75},
952 /* 0x25 bit 7*/
953 {1152, 870, 75},
954};
955
956static void print_subsection(const char *name, unsigned char *edid, int start,
957 int end)
958{
959 int i;
960
961 printk(BIOS_SPEW, "%s:", name);
962 for (i = strlen(name); i < 15; i++)
963 printk(BIOS_SPEW, " ");
964 for (i = start; i <= end; i++)
965 printk(BIOS_SPEW, " %02x", edid[i]);
966 printk(BIOS_SPEW, "\n");
967}
968
969static void dump_breakdown(unsigned char *edid)
970{
971 printk(BIOS_SPEW, "Extracted contents:\n");
972 print_subsection("header", edid, 0, 7);
973 print_subsection("serial number", edid, 8, 17);
974 print_subsection("version", edid,18, 19);
975 print_subsection("basic params", edid, 20, 24);
976 print_subsection("chroma info", edid, 25, 34);
977 print_subsection("established", edid, 35, 37);
978 print_subsection("standard", edid, 38, 53);
979 print_subsection("descriptor 1", edid, 54, 71);
980 print_subsection("descriptor 2", edid, 72, 89);
981 print_subsection("descriptor 3", edid, 90, 107);
982 print_subsection("descriptor 4", edid, 108, 125);
983 print_subsection("extensions", edid, 126, 126);
984 print_subsection("checksum", edid, 127, 127);
985 printk(BIOS_SPEW, "\n");
986}
987
988/*
David Hendrickse2054102015-08-07 18:41:37 -0700989 * Lookup table of some well-known modes that can be useful in case the
990 * auto-detected mode is unsuitable.
991 * ha = hdisplay; va = vdisplay;
992 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
993 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
994 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
995 */
996static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
997 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -0700998 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -0500999 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001000 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1001 .phsync = '-', .pvsync = '-' },
1002 [EDID_MODE_720x480_60Hz] = {
1003 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001004 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001005 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1006 .phsync = '-', .pvsync = '-' },
1007 [EDID_MODE_1280x720_60Hz] = {
1008 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001009 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001010 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1011 .phsync = '+', .pvsync = '+' },
1012 [EDID_MODE_1920x1080_60Hz] = {
1013 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001014 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001015 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1016 .phsync = '+', .pvsync = '+' },
1017};
1018
1019int set_display_mode(struct edid *edid, enum edid_modes mode)
1020{
1021 if (mode == EDID_MODE_AUTO)
1022 return 0;
1023
1024 if (edid->mode_is_supported[mode]) {
1025 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1026 edid->mode = known_modes[mode];
1027 return 0;
1028 }
1029
1030 printk(BIOS_ERR, "Requested display mode not supported.\n");
1031 return -1;
1032}
1033
1034/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001035 * Given a raw edid bloc, decode it into a form
1036 * that other parts of coreboot can use -- mainly
1037 * graphics bringup functions. The raw block is
1038 * required to be 128 bytes long, per the standard,
1039 * but we have no way of checking this minimum length.
1040 * We accept what we are given.
1041 */
1042int decode_edid(unsigned char *edid, int size, struct edid *out)
1043{
David Hendrickse2054102015-08-07 18:41:37 -07001044 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001045 struct edid_context c = {
1046 .has_valid_cvt = 1,
1047 .has_valid_dummy_block = 1,
1048 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001049 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001050 .has_valid_descriptor_pad = 1,
1051 .has_valid_range_descriptor = 1,
1052 .has_valid_max_dotclock = 1,
1053 .has_valid_string_termination = 1,
1054 .conformant = 1,
1055 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001056
1057 dump_breakdown(edid);
1058
David Hendricks40e89b42015-08-13 15:51:00 -07001059 memset(out, 0, sizeof(*out));
1060
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001061 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1062 printk(BIOS_SPEW, "No header found\n");
1063 return 1;
1064 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001065
David Hendricksa3b898a2015-08-02 18:07:48 -07001066 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001067 c.manufacturer_name_well_formed = 1;
1068
David Hendricksa3b898a2015-08-02 18:07:48 -07001069 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1070 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001071 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1072
1073 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001074 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001075 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1076 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1077 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001078 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001079
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001080 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001081 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001082 if (edid[0x11] > 0x0f) {
1083 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001084 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001085 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001086 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001087 extra_info.week = edid[0x10];
1088 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001089 } else {
1090 /* we know it's at least 2013, when this code was written */
1091 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001092 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001093 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001094 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001095 extra_info.week = edid[0x10];
1096 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001097 }
1098 }
1099 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001100 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001101
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001102 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001103 extra_info.version[0] = edid[0x12];
1104 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001105
1106 if (edid[0x12] == 1) {
1107 if (edid[0x13] > 4) {
1108 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1109 edid[0x13] = 4;
1110 }
1111 switch (edid[0x13]) {
1112 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001113 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001114 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001115 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001116 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001117 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001118 default:
1119 break;
1120 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001121 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001122 }
1123
1124 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001125 if (edid[0x14] & 0x80) {
1126 int conformance_mask;
1127 analog = 0;
1128 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001129 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001130 conformance_mask = 0;
1131 if ((edid[0x14] & 0x70) == 0x00)
1132 printk(BIOS_SPEW, "Color depth is undefined\n");
1133 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001134 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001135 else
1136 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1137 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001138 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1139 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001140
1141 switch (edid[0x14] & 0x0f) {
1142 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1143 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1144 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1145 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1146 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1147 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1148 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001149 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001150 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001151 extra_info.type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001152 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001153 conformance_mask = 0x7E;
1154 if (edid[0x14] & 0x01) {
1155 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1156 }
1157 } else
1158 conformance_mask = 0x7F;
1159
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001160 if (!c.nonconformant_digital_display)
1161 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001162 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001163 } else {
1164 analog = 1;
1165 int voltage = (edid[0x14] & 0x60) >> 5;
1166 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001167 extra_info.voltage = voltage;
1168 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001169
1170 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1171 voltage == 3 ? "0.7/0.7" :
1172 voltage == 2 ? "1.0/0.4" :
1173 voltage == 1 ? "0.714/0.286" :
1174 "0.7/0.3");
1175
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001176 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001177 if (edid[0x14] & 0x10)
1178 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1179 else
1180 printk(BIOS_SPEW, "Blank level equals black level\n");
1181 } else if (edid[0x14] & 0x10) {
1182 /*
1183 * XXX this is just the X text. 1.3 says "if set, display expects
1184 * a blank-to-black setup or pedestal per appropriate Signal
1185 * Level Standard". Whatever _that_ means.
1186 */
1187 printk(BIOS_SPEW, "Configurable signal levels\n");
1188 }
1189
1190 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1191 sync & 0x04 ? "Composite " : "",
1192 sync & 0x02 ? "SyncOnGreen " : "",
1193 sync & 0x01 ? "Serration " : "");
1194 }
1195
1196
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001197 if (edid[0x15] && edid[0x16]) {
1198 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1199 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001200 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001201 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1202 unsigned int ratio = 100000/(edid[0x15] + 99);
1203 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1204 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001205 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1206 unsigned int ratio = 100000/(edid[0x16] + 99);
1207 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1208 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001209 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001210 } else {
1211 /* Either or both can be zero for 1.3 and before */
1212 printk(BIOS_SPEW, "Image size is variable\n");
1213 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001214
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001215 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001216 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001217 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1218 else
1219 /* XXX Technically 1.3 doesn't say this... */
1220 printk(BIOS_SPEW, "Gamma: 1.0\n");
1221 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1222 printk(BIOS_SPEW, "Check DPMS levels\n");
1223 if (edid[0x18] & 0xE0) {
1224 printk(BIOS_SPEW, "DPMS levels:");
1225 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1226 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1227 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1228 printk(BIOS_SPEW, "\n");
1229 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001230
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001231 /* FIXME: this is from 1.4 spec, check earlier */
1232 if (analog) {
1233 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001234 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1235 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1236 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1237 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001238 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001239 } else {
1240 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1241 if (edid[0x18] & 0x10)
1242 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1243 if (edid[0x18] & 0x08)
1244 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1245 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001246 }
1247
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001248 if (edid[0x18] & 0x04)
1249 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1250 if (edid[0x18] & 0x02) {
1251 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001252 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001253 }
1254 if (edid[0x18] & 0x01)
1255 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1256
1257 /* XXX color section */
1258
1259 printk(BIOS_SPEW, "Established timings supported:\n");
1260 /* it's not yet clear we want all this stuff in the edid struct.
1261 * Let's wait.
1262 */
1263 for (i = 0; i < 17; i++) {
1264 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1265 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1266 established_timings[i].y, established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001267
Douglas Anderson9fa07602015-10-28 10:19:52 -07001268 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1269 if (known_modes[j].ha == established_timings[i].x &&
1270 known_modes[j].va == established_timings[i].y &&
1271 known_modes[j].refresh == established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001272 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001273 }
David Hendrickse2054102015-08-07 18:41:37 -07001274 }
1275
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001276 }
1277
1278 printk(BIOS_SPEW, "Standard timings supported:\n");
1279 for (i = 0; i < 8; i++) {
1280 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1281 unsigned int x, y = 0, refresh;
1282
1283 if (b1 == 0x01 && b2 == 0x01)
1284 continue;
1285
1286 if (b1 == 0) {
1287 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1288 continue;
1289 }
1290 x = (b1 + 31) * 8;
1291 switch ((b2 >> 6) & 0x3) {
1292 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001293 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001294 y = x * 10 / 16;
1295 else
1296 y = x;
1297 break;
1298 case 0x01:
1299 y = x * 3 / 4;
1300 break;
1301 case 0x02:
1302 y = x * 4 / 5;
1303 break;
1304 case 0x03:
1305 y = x * 9 / 16;
1306 break;
1307 }
1308 refresh = 60 + (b2 & 0x3f);
1309
1310 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001311 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1312 if (known_modes[j].ha == x && known_modes[j].va == y &&
1313 known_modes[j].refresh == refresh)
1314 out->mode_is_supported[j] = 1;
1315 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001316 }
1317
1318 /* detailed timings */
1319 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001320 for (i = 0; i < 4; i++) {
1321 c.has_valid_detailed_blocks &= detailed_block(
1322 out, edid + 0x36 + i * 18, 0, &c);
1323 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1324 {
1325 /* not really accurate... */
1326 c.has_preferred_timing = 0;
1327 }
1328 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001329
1330 /* check this, 1.4 verification guide says otherwise */
1331 if (edid[0x7e]) {
1332 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1333 /* 2 is impossible because of the block map */
1334 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001335 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001336 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001337 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001338 }
1339
1340 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001341 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001342
1343 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1344 * the extension parsing loop below. Since v2.0 was quickly deprecated
1345 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1346 * that case now and can fix it when we need to use a real 2.0 panel.
1347 */
1348 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001349 c.nonconformant_extension +=
1350 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001351
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001352 if (c.claims_one_point_four) {
1353 if (c.nonconformant_digital_display ||
1354 !c.has_valid_string_termination ||
1355 !c.has_valid_descriptor_pad ||
1356 !c.has_preferred_timing)
1357 c.conformant = 0;
1358 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001359 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001360 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001361 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001362 c.nonconformant_digital_display);
1363 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001364 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001365 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001366 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001367 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001368 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001369 } else if (c.claims_one_point_three) {
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;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001375 }
1376 /**
1377 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1378 * has_range_descriptor are both required. These fields are
1379 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1380 * don't have them. As a workaround, we only print warning
1381 * messages.
1382 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001383 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001385 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001386 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1387 "fully conform to EDID 1.3.\n");
1388
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001389 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001390 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001391 c.nonconformant_digital_display);
1392 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001393 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001394 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001395 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001396 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001397 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001398 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001399 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001400 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001401 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001402 } else if (c.claims_one_point_two) {
1403 if (c.nonconformant_digital_display ||
1404 !c.has_valid_string_termination)
1405 c.conformant = 0;
1406 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001407 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001408 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001409 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001410 c.nonconformant_digital_display);
1411 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001412 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001413 } else if (c.claims_one_point_oh) {
1414 if (c.seen_non_detailed_descriptor)
1415 c.conformant = 0;
1416 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001417 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001418 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001419 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1420 }
1421
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001422 if (c.nonconformant_extension ||
1423 !c.has_valid_checksum ||
1424 !c.has_valid_cvt ||
1425 !c.has_valid_year ||
1426 !c.has_valid_week ||
1427 !c.has_valid_detailed_blocks ||
1428 !c.has_valid_dummy_block ||
1429 !c.has_valid_extension_count ||
1430 !c.has_valid_descriptor_ordering ||
1431 !c.has_valid_range_descriptor ||
1432 !c.manufacturer_name_well_formed) {
1433 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001434 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001435 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001436 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001437 c.nonconformant_extension);
1438 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001439 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001440 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001441 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001442 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001443 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001444 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001445 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001446 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001447 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001448 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001449 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001450 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001451 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001452 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001453 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001454 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001455 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001457 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001458 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001459 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1460 }
1461
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001462 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001463 printk(BIOS_ERR,
1464 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001465 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001466 printk(BIOS_ERR,
1467 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001468 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001469}
1470
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001471/*
1472 * Notes on panel extensions: (TODO, implement me in the code)
1473 *
1474 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1475 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1476 * 0x6c: 00 00 00 0e 00
1477 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1478 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1479 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1480 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1481 * bit 4: DE polarity (0 high active 1 low active)
1482 * bit 3-0: interface (0000 LVDS TFT
1483 * 0001 mono STN 4/8bit
1484 * 0010 color STN 8/16 bit
1485 * 0011 18 bit tft
1486 * 0100 24 bit tft
1487 * 0101 tmds
1488 * else reserved)
1489 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1490 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1491 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1492 * else time in 10ms (10ms to 150ms))
1493 * bit 3-0: total poweron seq delay (as above)
1494 * 0x75: contrast power on/off seq delay, same as 0x74
1495 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1496 * bit 6: backlight enabled at boot (0 on 1 off)
1497 * bit 5-0: backlight brightness control steps (0..63)
1498 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1499 * 0x78 - 0x7c: reserved
1500 * 0x7d: bit 7-4: EPI descriptor major version (1)
1501 * bit 3-0: EPI descriptor minor version (0)
1502 *
1503 * ----
1504 *
1505 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1506 *
1507 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1508 *
1509 * detailed descriptor 3:
1510 * 0x5a - 0x5e: 00 00 00 fe 00
1511 * 0x5f - 0x63: PC maker part number
1512 * 0x64: LCD supplier revision #
1513 * 0x65 - 0x6b: manufacturer part number
1514 *
1515 * detailed descriptor 4:
1516 * 0x6c - 0x70: 00 00 00 fe 00
1517 * 0x71 - 0x78: smbus nits values (whut)
1518 * 0x79: number of lvds channels (1 or 2)
1519 * 0x7A: panel self test (1 if present)
1520 * and then dummy terminator
1521 *
1522 * SPWG also says something strange about the LSB of detailed descriptor 1:
1523 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1524 */
Julius Werner69112192016-03-14 17:29:55 -07001525
1526/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
1527void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp)
1528{
1529 /* Caller should pass a supported value, everything else is BUG(). */
1530 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
1531
1532 edid->framebuffer_bits_per_pixel = fb_bpp;
1533 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
1534 div_round_up(fb_bpp, 8), 64);
1535 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1536 edid->y_resolution = edid->mode.va;
1537}
1538
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001539/*
1540 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1541 */
1542
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001543void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1544{
1545 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001546 edid_fb.x_resolution = edid->x_resolution;
1547 edid_fb.y_resolution = edid->y_resolution;
1548 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001549 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001550 * seems to be to round it up to the nearest reasonable
1551 * boundary, because otherwise the byte-packing is hideous.
1552 * So, for example, in RGB with no alpha, the bytes are still
1553 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1554 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1555 * and in 4:4:4 mode, they are packed into 16-bit words.
1556 * Good call on the hardware guys part.
1557 * It's not clear we're covering all cases here, but
1558 * I'm not sure with grahpics you ever can.
1559 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001560 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001561 edid_fb.reserved_mask_pos = 0;
1562 edid_fb.reserved_mask_size = 0;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001563 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001564 case 32:
1565 case 24:
1566 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001567 edid_fb.reserved_mask_pos = 24;
1568 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001569 edid_fb.red_mask_pos = 16;
1570 edid_fb.red_mask_size = 8;
1571 edid_fb.green_mask_pos = 8;
1572 edid_fb.green_mask_size = 8;
1573 edid_fb.blue_mask_pos = 0;
1574 edid_fb.blue_mask_size = 8;
1575 break;
1576 case 16:
1577 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001578 edid_fb.red_mask_pos = 11;
1579 edid_fb.red_mask_size = 5;
1580 edid_fb.green_mask_pos = 5;
1581 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001582 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001583 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001584 break;
1585 default:
1586 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001587 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001588 return;
1589 }
1590
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001591 vbe_valid = 1;
1592}
1593
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001594#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001595int vbe_mode_info_valid(void)
1596{
1597 return vbe_valid;
1598}
1599
1600void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1601{
1602 *framebuffer = edid_fb;
1603}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001604#endif