blob: 50bb2c282a2fa9f3be0492da1962e16f034790cb [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;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800299 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700300 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700301 }
302 if (x[4] & 0x04) {
303 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800304 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700305 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700306 }
307 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800308 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700309 }
310
311 /*
312 * despite the values, this is not a bitfield.
313 */
314 switch (x[10]) {
315 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700316 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700317 break;
318 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700319 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800320 if (!c->claims_one_point_four)
321 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700322 break;
323 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700324 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700325 break;
326 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700327 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700328 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800329 if (!c->claims_one_point_four)
330 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700331 break;
332 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800333 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700334 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700335 break;
336 }
337
338 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800339 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700340 if (x[7] + h_min_offset > x[8] + h_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 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700343 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700344 x[5] + v_min_offset, x[6] + v_max_offset,
345 x[7] + h_min_offset, x[8] + h_max_offset);
346 if (x[9])
347 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
348 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800349 if (c->claims_one_point_four)
350 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700351 printk(BIOS_SPEW, "\n");
352 }
353
354 if (is_cvt) {
355 int max_h_pixels = 0;
356
357 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
358
359 if (x[12] & 0xfc) {
360 int raw_offset = (x[12] & 0xfc) >> 2;
Patrick Georgibe71ee5d2014-12-15 22:52:14 +0100361 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
362 (x[9] * 10000) - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700363 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800364 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700365 }
366
367 max_h_pixels = x[12] & 0x03;
368 max_h_pixels <<= 8;
369 max_h_pixels |= x[13];
370 max_h_pixels *= 8;
371 if (max_h_pixels)
372 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
373
374 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
375 x[14] & 0x80 ? "4:3" : "",
376 x[14] & 0x40 ? "16:9" : "",
377 x[14] & 0x20 ? "16:10" : "",
378 x[14] & 0x10 ? "5:4" : "",
379 x[14] & 0x08 ? "15:9" : "");
380 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800381 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700382
383 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800384 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800385 case 0x00:
386 printk(BIOS_SPEW, "4:3");
387 break;
388 case 0x01:
389 printk(BIOS_SPEW, "16:9");
390 break;
391 case 0x02:
392 printk(BIOS_SPEW, "16:10");
393 break;
394 case 0x03:
395 printk(BIOS_SPEW, "5:4");
396 break;
397 case 0x04:
398 printk(BIOS_SPEW, "15:9");
399 break;
400 default:
401 printk(BIOS_SPEW, "(broken)");
402 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700403 }
404 printk(BIOS_SPEW, "\n");
405
406 if (x[15] & 0x04)
407 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
408 if (x[15] & 0x10)
409 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
410
411 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800412 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700413
414 if (x[16] & 0xf0) {
415 printk(BIOS_SPEW, "Supported display scaling:\n");
416 if (x[16] & 0x80)
417 printk(BIOS_SPEW, " Horizontal shrink\n");
418 if (x[16] & 0x40)
419 printk(BIOS_SPEW, " Horizontal stretch\n");
420 if (x[16] & 0x20)
421 printk(BIOS_SPEW, " Vertical shrink\n");
422 if (x[16] & 0x10)
423 printk(BIOS_SPEW, " Vertical stretch\n");
424 }
425
426 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800427 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700428
429 if (x[17])
430 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
431 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800432 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700433 }
434
435 /*
436 * Slightly weird to return a global, but I've never seen any
437 * EDID block wth two range descriptors, so it's harmless.
438 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800439 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700440 }
441 case 0xFE:
442 /*
443 * TODO: Two of these in a row, in the third and fourth slots,
444 * seems to be specified by SPWG: http://www.spwg.org/
445 */
446 printk(BIOS_SPEW, "ASCII string: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800447 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800448 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700449 case 0xFF:
450 printk(BIOS_SPEW, "Serial number: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800451 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800452 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700453 default:
454 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
455 return 0;
456 }
457 }
458
Lee Leahy2f919ec2017-03-08 17:37:06 -0800459 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800460 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700461
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700462 /* Edid contains pixel clock in terms of 10KHz */
463 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
464 /*
465 LVDS supports following pixel clocks
466 25000...112000 kHz: single channel
467 80000...224000 kHz: dual channel
468 There is some overlap in theoretically supported
469 pixel clock between single-channel and dual-channel.
470 In practice with current panels all panels
471 <= 75200 kHz: single channel
472 >= 97750 kHz: dual channel
473 We have no samples between those values, so put a
474 threshold at 95000 kHz. If we get anything over
475 95000 kHz with single channel, we can make this
476 more sofisticated but it's currently not needed.
477 */
478 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
479 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
480 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
481 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
482 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
483 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
484 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
485 out->mode.hborder = x[15];
486 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
487 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
488 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
489 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
490 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700491
Julius Werner69112192016-03-14 17:29:55 -0700492 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700493 * Chipsets that want something else will need to override this with
494 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
495 * heuristic, assume that X86 systems require a 64-byte row alignment
496 * (since that seems to be true for most Intel chipsets). */
497 if (IS_ENABLED(CONFIG_ARCH_X86))
498 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
499 else
500 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700501
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700502 switch ((x[17] & 0x18) >> 3) {
503 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700504 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700505 break;
506 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700507 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700508 break;
509 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700510 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700511 break;
512 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700513 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700514 break;
515 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700516 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
517 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700518 switch (x[17] & 0x61) {
519 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700520 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700521 break;
522 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700523 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700524 break;
525 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700526 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700527 break;
528 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700529 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700530 break;
531 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700532 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700533 break;
534 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700535 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700536 break;
537 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700538 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700539 break;
540 }
541
Furquan Shaikh6b190712013-07-22 16:18:31 -0700542 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700543 " %04x %04x %04x %04x hborder %x\n"
544 " %04x %04x %04x %04x vborder %x\n"
545 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700546 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700547 extra_info.x_mm,
548 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700549 out->mode.ha, out->mode.ha + out->mode.hso,
550 out->mode.ha + out->mode.hso + out->mode.hspw,
551 out->mode.ha + out->mode.hbl, out->mode.hborder,
552 out->mode.va, out->mode.va + out->mode.vso,
553 out->mode.va + out->mode.vso + out->mode.vspw,
554 out->mode.va + out->mode.vbl, out->mode.vborder,
555 out->mode.phsync, out->mode.pvsync,
David Hendricksa3b898a2015-08-02 18:07:48 -0700556 extra_info.syncmethod, x[17] & 0x80 ?" interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700557 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700558
559 if (! c->did_detailed_timing) {
560 printk(BIOS_SPEW, "Did detailed timing\n");
561 c->did_detailed_timing = 1;
562 *result_edid = *out;
563 }
564
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700565 return 1;
566}
567
568static int
569do_checksum(unsigned char *x)
570{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800571 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600572 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700573 {
574 unsigned char sum = 0;
575 int i;
576 for (i = 0; i < 128; i++)
577 sum += x[i];
578 if (sum) {
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600579 printk(BIOS_SPEW, " (should be 0x%hhx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700580 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800581 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700582 printk(BIOS_SPEW, " (valid)");
583 }
584 }
585 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800586 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700587}
588
589/* CEA extension */
590
591static const char *
592audio_format(unsigned char x)
593{
594 switch (x) {
595 case 0: return "RESERVED";
596 case 1: return "Linear PCM";
597 case 2: return "AC-3";
598 case 3: return "MPEG 1 (Layers 1 & 2)";
599 case 4: return "MPEG 1 Layer 3 (MP3)";
600 case 5: return "MPEG2 (multichannel)";
601 case 6: return "AAC";
602 case 7: return "DTS";
603 case 8: return "ATRAC";
604 case 9: return "One Bit Audio";
605 case 10: return "Dolby Digital+";
606 case 11: return "DTS-HD";
607 case 12: return "MAT (MLP)";
608 case 13: return "DST";
609 case 14: return "WMA Pro";
610 case 15: return "RESERVED";
611 }
612 return "BROKEN"; /* can't happen */
613}
614
615static void
616cea_audio_block(unsigned char *x)
617{
618 int i, format;
619 int length = x[0] & 0x1f;
620
621 if (length % 3) {
622 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
623 /* XXX non-conformant */
624 return;
625 }
626
627 for (i = 1; i < length; i += 3) {
628 format = (x[i] & 0x78) >> 3;
629 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
630 x[i] & 0x07);
631 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
632 (x[i+1] & 0x40) ? " 192" : "",
633 (x[i+1] & 0x20) ? " 176.4" : "",
634 (x[i+1] & 0x10) ? " 96" : "",
635 (x[i+1] & 0x08) ? " 88.2" : "",
636 (x[i+1] & 0x04) ? " 48" : "",
637 (x[i+1] & 0x02) ? " 44.1" : "",
638 (x[i+1] & 0x01) ? " 32" : "");
639 if (format == 1) {
640 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
641 (x[2] & 0x04) ? " 24" : "",
642 (x[2] & 0x02) ? " 20" : "",
643 (x[2] & 0x01) ? " 16" : "");
644 } else if (format <= 8) {
645 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
646 }
647 }
648}
649
650static void
651cea_video_block(unsigned char *x)
652{
653 int i;
654 int length = x[0] & 0x1f;
655
656 for (i = 1; i < length; i++)
657 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
658 x[i] & 0x80 ? "(native)" : "");
659}
660
661static void
662cea_hdmi_block(struct edid *out, unsigned char *x)
663{
664 int length = x[0] & 0x1f;
665
Yakir Yang85810cc2015-10-27 16:17:13 +0800666 out->hdmi_monitor_detected = 1;
667
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700668 printk(BIOS_SPEW, " (HDMI)\n");
669 printk(BIOS_SPEW,
670 " Source physical address %d.%d.%d.%d\n",
671 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
672
673 if (length > 5) {
674 if (x[6] & 0x80)
675 printk(BIOS_SPEW, " Supports_AI\n");
676 if (x[6] & 0x40)
677 printk(BIOS_SPEW, " DC_48bit\n");
678 if (x[6] & 0x20)
679 printk(BIOS_SPEW, " DC_36bit\n");
680 if (x[6] & 0x10)
681 printk(BIOS_SPEW, " DC_30bit\n");
682 if (x[6] & 0x08)
683 printk(BIOS_SPEW, " DC_Y444\n");
684 /* two reserved */
685 if (x[6] & 0x01)
686 printk(BIOS_SPEW, " DVI_Dual\n");
687 }
688
689 if (length > 6)
690 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
691
692 /* XXX the walk here is really ugly, and needs to be length-checked */
693 if (length > 7) {
694 int b = 0;
695
696 if (x[8] & 0x80) {
697 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
698 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
699 b += 2;
700 }
701
702 if (x[8] & 0x40) {
703 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
704 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
705 b += 2;
706 }
707
708 if (x[8] & 0x20) {
709 int mask = 0, formats = 0;
710 int len_xx, len_3d;
711 printk(BIOS_SPEW, " Extended HDMI video details:\n");
712 if (x[9 + b] & 0x80)
713 printk(BIOS_SPEW, " 3D present\n");
714 if ((x[9 + b] & 0x60) == 0x20) {
715 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
716 formats = 1;
717 }
718 if ((x[9 + b] & 0x60) == 0x40) {
719 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
720 formats = 1;
721 mask = 1;
722 }
723 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800724 case 0x00:
725 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700726 case 0x08:
727 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
728 break;
729 case 0x10:
730 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
731 break;
732 case 0x18:
733 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
734 break;
735 }
736 len_xx = (x[10 + b] & 0xe0) >> 5;
737 len_3d = (x[10 + b] & 0x1f) >> 0;
738 b += 2;
739
740 if (len_xx) {
741 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
742 " document\n", len_xx);
743 b += len_xx;
744 }
745
746 if (len_3d) {
747 if (formats) {
748 if (x[9 + b] & 0x01)
749 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
750 if (x[10 + b] & 0x40)
751 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
752 if (x[10 + b] & 0x01)
753 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
754 b += 2;
755 }
756 if (mask) {
757 int i;
758 printk(BIOS_SPEW, " 3D VIC indices:");
759 /* worst bit ordering ever */
760 for (i = 0; i < 8; i++)
761 if (x[10 + b] & (1 << i))
762 printk(BIOS_SPEW, " %d", i);
763 for (i = 0; i < 8; i++)
764 if (x[9 + b] & (1 << i))
765 printk(BIOS_SPEW, " %d", i + 8);
766 printk(BIOS_SPEW, "\n");
767 b += 2;
768 }
769
770 /*
771 * XXX list of nibbles:
772 * 2D_VIC_Order_X
773 * 3D_Structure_X
774 * (optionally: 3D_Detail_X and reserved)
775 */
776 }
777
778 }
779 }
780}
781
782static void
783cea_block(struct edid *out, unsigned char *x)
784{
785 unsigned int oui;
786
787 switch ((x[0] & 0xe0) >> 5) {
788 case 0x01:
789 printk(BIOS_SPEW, " Audio data block\n");
790 cea_audio_block(x);
791 break;
792 case 0x02:
793 printk(BIOS_SPEW, " Video data block\n");
794 cea_video_block(x);
795 break;
796 case 0x03:
797 /* yes really, endianness lols */
798 oui = (x[3] << 16) + (x[2] << 8) + x[1];
799 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
800 if (oui == 0x000c03)
801 cea_hdmi_block(out, x);
802 else
803 printk(BIOS_SPEW, "\n");
804 break;
805 case 0x04:
806 printk(BIOS_SPEW, " Speaker allocation data block\n");
807 break;
808 case 0x05:
809 printk(BIOS_SPEW, " VESA DTC data block\n");
810 break;
811 case 0x07:
812 printk(BIOS_SPEW, " Extended tag: ");
813 switch (x[1]) {
814 case 0x00:
815 printk(BIOS_SPEW, "video capability data block\n");
816 break;
817 case 0x01:
818 printk(BIOS_SPEW, "vendor-specific video data block\n");
819 break;
820 case 0x02:
821 printk(BIOS_SPEW, "VESA video display device information data block\n");
822 break;
823 case 0x03:
824 printk(BIOS_SPEW, "VESA video data block\n");
825 break;
826 case 0x04:
827 printk(BIOS_SPEW, "HDMI video data block\n");
828 break;
829 case 0x05:
830 printk(BIOS_SPEW, "Colorimetry data block\n");
831 break;
832 case 0x10:
833 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
834 break;
835 case 0x11:
836 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
837 break;
838 case 0x12:
839 printk(BIOS_SPEW, "HDMI audio data block\n");
840 break;
841 default:
842 if (x[1] >= 6 && x[1] <= 15)
843 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
844 else if (x[1] >= 19 && x[1] <= 31)
845 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
846 else
847 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
848 break;
849 }
850 break;
851 default:
852 {
853 int tag = (*x & 0xe0) >> 5;
854 int length = *x & 0x1f;
855 printk(BIOS_SPEW,
856 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
857 break;
858 }
859 }
860}
861
862static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800863parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700864{
865 int ret = 0;
866 int version = x[1];
867 int offset = x[2];
868 unsigned char *detailed;
869
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800870 if (version >= 1)
871 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700872 if (version == 1 && x[3] != 0)
873 ret = 1;
874
875 if (offset < 4)
876 break;
877
Lee Leahye20a3192017-03-09 16:21:34 -0800878 if (version < 3)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700879 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800880 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700881 int i;
882 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800883 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700884 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700885 }
886
887 if (version >= 2) {
888 if (x[3] & 0x80)
889 printk(BIOS_SPEW, "Underscans PC formats by default\n");
890 if (x[3] & 0x40)
891 printk(BIOS_SPEW, "Basic audio support\n");
892 if (x[3] & 0x20)
893 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
894 if (x[3] & 0x10)
895 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
896 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
897 }
898
899 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
900 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800901 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700902 } while (0);
903
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800904 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700905 return ret;
906}
907
908/* generic extension code */
909
910static void
911extension_version(struct edid *out, unsigned char *x)
912{
913 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
914}
915
916static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800917parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700918{
919 int conformant_extension = 0;
920 printk(BIOS_SPEW, "\n");
921
Lee Leahy45fde702017-03-08 18:02:24 -0800922 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700923 case 0x02:
924 printk(BIOS_SPEW, "CEA extension block\n");
925 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800926 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700927 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800928 case 0x10:
929 printk(BIOS_SPEW, "VTB extension block\n");
930 break;
931 case 0x40:
932 printk(BIOS_SPEW, "DI extension block\n");
933 break;
934 case 0x50:
935 printk(BIOS_SPEW, "LS extension block\n");
936 break;
937 case 0x60:
938 printk(BIOS_SPEW, "DPVL extension block\n");
939 break;
940 case 0xF0:
941 printk(BIOS_SPEW, "Block map\n");
942 break;
943 case 0xFF:
944 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700945 default:
946 printk(BIOS_SPEW, "Unknown extension block\n");
947 break;
948 }
949
950 printk(BIOS_SPEW, "\n");
951
952 return conformant_extension;
953}
954
955static const struct {
956 int x, y, refresh;
957} established_timings[] = {
958 /* 0x23 bit 7 - 0 */
959 {720, 400, 70},
960 {720, 400, 88},
961 {640, 480, 60},
962 {640, 480, 67},
963 {640, 480, 72},
964 {640, 480, 75},
965 {800, 600, 56},
966 {800, 600, 60},
967 /* 0x24 bit 7 - 0 */
968 {800, 600, 72},
969 {800, 600, 75},
970 {832, 624, 75},
971 {1280, 768, 87},
972 {1024, 768, 60},
973 {1024, 768, 70},
974 {1024, 768, 75},
975 {1280, 1024, 75},
976 /* 0x25 bit 7*/
977 {1152, 870, 75},
978};
979
980static void print_subsection(const char *name, unsigned char *edid, int start,
981 int end)
982{
983 int i;
984
985 printk(BIOS_SPEW, "%s:", name);
986 for (i = strlen(name); i < 15; i++)
987 printk(BIOS_SPEW, " ");
988 for (i = start; i <= end; i++)
989 printk(BIOS_SPEW, " %02x", edid[i]);
990 printk(BIOS_SPEW, "\n");
991}
992
993static void dump_breakdown(unsigned char *edid)
994{
995 printk(BIOS_SPEW, "Extracted contents:\n");
996 print_subsection("header", edid, 0, 7);
997 print_subsection("serial number", edid, 8, 17);
998 print_subsection("version", edid,18, 19);
999 print_subsection("basic params", edid, 20, 24);
1000 print_subsection("chroma info", edid, 25, 34);
1001 print_subsection("established", edid, 35, 37);
1002 print_subsection("standard", edid, 38, 53);
1003 print_subsection("descriptor 1", edid, 54, 71);
1004 print_subsection("descriptor 2", edid, 72, 89);
1005 print_subsection("descriptor 3", edid, 90, 107);
1006 print_subsection("descriptor 4", edid, 108, 125);
1007 print_subsection("extensions", edid, 126, 126);
1008 print_subsection("checksum", edid, 127, 127);
1009 printk(BIOS_SPEW, "\n");
1010}
1011
1012/*
David Hendrickse2054102015-08-07 18:41:37 -07001013 * Lookup table of some well-known modes that can be useful in case the
1014 * auto-detected mode is unsuitable.
1015 * ha = hdisplay; va = vdisplay;
1016 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1017 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1018 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1019 */
1020static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1021 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001022 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001023 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001024 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1025 .phsync = '-', .pvsync = '-' },
1026 [EDID_MODE_720x480_60Hz] = {
1027 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001028 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001029 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1030 .phsync = '-', .pvsync = '-' },
1031 [EDID_MODE_1280x720_60Hz] = {
1032 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001033 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001034 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1035 .phsync = '+', .pvsync = '+' },
1036 [EDID_MODE_1920x1080_60Hz] = {
1037 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001038 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001039 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1040 .phsync = '+', .pvsync = '+' },
1041};
1042
1043int set_display_mode(struct edid *edid, enum edid_modes mode)
1044{
1045 if (mode == EDID_MODE_AUTO)
1046 return 0;
1047
1048 if (edid->mode_is_supported[mode]) {
1049 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1050 edid->mode = known_modes[mode];
1051 return 0;
1052 }
1053
1054 printk(BIOS_ERR, "Requested display mode not supported.\n");
1055 return -1;
1056}
1057
1058/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001059 * Given a raw edid bloc, decode it into a form
1060 * that other parts of coreboot can use -- mainly
1061 * graphics bringup functions. The raw block is
1062 * required to be 128 bytes long, per the standard,
1063 * but we have no way of checking this minimum length.
1064 * We accept what we are given.
1065 */
1066int decode_edid(unsigned char *edid, int size, struct edid *out)
1067{
David Hendrickse2054102015-08-07 18:41:37 -07001068 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001069 struct edid_context c = {
1070 .has_valid_cvt = 1,
1071 .has_valid_dummy_block = 1,
1072 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001073 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001074 .has_valid_descriptor_pad = 1,
1075 .has_valid_range_descriptor = 1,
1076 .has_valid_max_dotclock = 1,
1077 .has_valid_string_termination = 1,
1078 .conformant = 1,
1079 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001080
1081 dump_breakdown(edid);
1082
David Hendricks40e89b42015-08-13 15:51:00 -07001083 memset(out, 0, sizeof(*out));
1084
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001085 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1086 printk(BIOS_SPEW, "No header found\n");
1087 return 1;
1088 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001089
David Hendricksa3b898a2015-08-02 18:07:48 -07001090 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001091 c.manufacturer_name_well_formed = 1;
1092
David Hendricksa3b898a2015-08-02 18:07:48 -07001093 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1094 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001095 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1096
1097 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001098 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001099 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1100 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1101 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001102 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001103
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001104 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001105 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001106 if (edid[0x11] > 0x0f) {
1107 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001108 c.has_valid_year = 1;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001109 printk(BIOS_SPEW, "Made week %hhd of model year %hhd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001110 edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001111 extra_info.week = edid[0x10];
1112 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001113 } else {
1114 /* we know it's at least 2013, when this code was written */
1115 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001116 c.has_valid_year = 1;
Alexandru Gagniuc09915c12014-12-21 02:54:33 -06001117 printk(BIOS_SPEW, "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001118 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001119 extra_info.week = edid[0x10];
1120 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001121 }
1122 }
1123 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001124 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001125
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001126 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001127 extra_info.version[0] = edid[0x12];
1128 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001129
1130 if (edid[0x12] == 1) {
1131 if (edid[0x13] > 4) {
1132 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1133 edid[0x13] = 4;
1134 }
1135 switch (edid[0x13]) {
1136 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001137 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001138 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001139 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001140 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001141 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001142 default:
1143 break;
1144 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001145 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001146 }
1147
1148 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001149 if (edid[0x14] & 0x80) {
1150 int conformance_mask;
1151 analog = 0;
1152 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001153 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001154 conformance_mask = 0;
1155 if ((edid[0x14] & 0x70) == 0x00)
1156 printk(BIOS_SPEW, "Color depth is undefined\n");
1157 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001158 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001159 else
1160 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1161 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001162 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1163 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001164
1165 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001166 case 0x00:
1167 printk(BIOS_SPEW, "Digital interface is not defined\n");
1168 break;
1169 case 0x01:
1170 printk(BIOS_SPEW, "DVI interface\n");
1171 break;
1172 case 0x02:
1173 printk(BIOS_SPEW, "HDMI-a interface\n");
1174 break;
1175 case 0x03:
1176 printk(BIOS_SPEW, "HDMI-b interface\n");
1177 break;
1178 case 0x04:
1179 printk(BIOS_SPEW, "MDDI interface\n");
1180 break;
1181 case 0x05:
1182 printk(BIOS_SPEW, "DisplayPort interface\n");
1183 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001184 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001185 c.nonconformant_digital_display = 1;
1186 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001187 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001188 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001189 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001190 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001191 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001192 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001193 } else
1194 conformance_mask = 0x7F;
1195
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001196 if (!c.nonconformant_digital_display)
1197 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001198 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001199 } else {
1200 analog = 1;
1201 int voltage = (edid[0x14] & 0x60) >> 5;
1202 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001203 extra_info.voltage = voltage;
1204 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001205
1206 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1207 voltage == 3 ? "0.7/0.7" :
1208 voltage == 2 ? "1.0/0.4" :
1209 voltage == 1 ? "0.714/0.286" :
1210 "0.7/0.3");
1211
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001212 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001213 if (edid[0x14] & 0x10)
1214 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1215 else
1216 printk(BIOS_SPEW, "Blank level equals black level\n");
1217 } else if (edid[0x14] & 0x10) {
1218 /*
1219 * XXX this is just the X text. 1.3 says "if set, display expects
1220 * a blank-to-black setup or pedestal per appropriate Signal
1221 * Level Standard". Whatever _that_ means.
1222 */
1223 printk(BIOS_SPEW, "Configurable signal levels\n");
1224 }
1225
1226 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1227 sync & 0x04 ? "Composite " : "",
1228 sync & 0x02 ? "SyncOnGreen " : "",
1229 sync & 0x01 ? "Serration " : "");
1230 }
1231
1232
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001233 if (edid[0x15] && edid[0x16]) {
1234 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1235 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001236 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001237 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1238 unsigned int ratio = 100000/(edid[0x15] + 99);
1239 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1240 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001241 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1242 unsigned int ratio = 100000/(edid[0x16] + 99);
1243 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1244 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001245 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001246 } else {
1247 /* Either or both can be zero for 1.3 and before */
1248 printk(BIOS_SPEW, "Image size is variable\n");
1249 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001250
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001251 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001252 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001253 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1254 else
1255 /* XXX Technically 1.3 doesn't say this... */
1256 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001257 } else
1258 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001259 printk(BIOS_SPEW, "Check DPMS levels\n");
1260 if (edid[0x18] & 0xE0) {
1261 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001262 if (edid[0x18] & 0x80)
1263 printk(BIOS_SPEW, " Standby");
1264 if (edid[0x18] & 0x40)
1265 printk(BIOS_SPEW, " Suspend");
1266 if (edid[0x18] & 0x20)
1267 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001268 printk(BIOS_SPEW, "\n");
1269 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001270
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001271 /* FIXME: this is from 1.4 spec, check earlier */
1272 if (analog) {
1273 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001274 case 0x00:
1275 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1276 break;
1277 case 0x08:
1278 printk(BIOS_SPEW, "RGB color display\n");
1279 break;
1280 case 0x10:
1281 printk(BIOS_SPEW, "Non-RGB color display\n");
1282 break;
1283 case 0x18:
1284 printk(BIOS_SPEW, "Undefined display color type\n");
1285 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001286 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001287 } else {
1288 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1289 if (edid[0x18] & 0x10)
1290 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1291 if (edid[0x18] & 0x08)
1292 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1293 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001294 }
1295
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001296 if (edid[0x18] & 0x04)
1297 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1298 if (edid[0x18] & 0x02) {
1299 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001300 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001301 }
1302 if (edid[0x18] & 0x01)
1303 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1304
1305 /* XXX color section */
1306
1307 printk(BIOS_SPEW, "Established timings supported:\n");
1308 /* it's not yet clear we want all this stuff in the edid struct.
1309 * Let's wait.
1310 */
1311 for (i = 0; i < 17; i++) {
1312 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1313 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1314 established_timings[i].y, established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001315
Douglas Anderson9fa07602015-10-28 10:19:52 -07001316 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1317 if (known_modes[j].ha == established_timings[i].x &&
1318 known_modes[j].va == established_timings[i].y &&
1319 known_modes[j].refresh == established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001320 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001321 }
David Hendrickse2054102015-08-07 18:41:37 -07001322 }
1323
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001324 }
1325
1326 printk(BIOS_SPEW, "Standard timings supported:\n");
1327 for (i = 0; i < 8; i++) {
1328 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1329 unsigned int x, y = 0, refresh;
1330
1331 if (b1 == 0x01 && b2 == 0x01)
1332 continue;
1333
1334 if (b1 == 0) {
1335 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1336 continue;
1337 }
1338 x = (b1 + 31) * 8;
1339 switch ((b2 >> 6) & 0x3) {
1340 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001341 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001342 y = x * 10 / 16;
1343 else
1344 y = x;
1345 break;
1346 case 0x01:
1347 y = x * 3 / 4;
1348 break;
1349 case 0x02:
1350 y = x * 4 / 5;
1351 break;
1352 case 0x03:
1353 y = x * 9 / 16;
1354 break;
1355 }
1356 refresh = 60 + (b2 & 0x3f);
1357
1358 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001359 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1360 if (known_modes[j].ha == x && known_modes[j].va == y &&
1361 known_modes[j].refresh == refresh)
1362 out->mode_is_supported[j] = 1;
1363 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001364 }
1365
1366 /* detailed timings */
1367 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001368 for (i = 0; i < 4; i++) {
1369 c.has_valid_detailed_blocks &= detailed_block(
1370 out, edid + 0x36 + i * 18, 0, &c);
1371 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1372 {
1373 /* not really accurate... */
1374 c.has_preferred_timing = 0;
1375 }
1376 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001377
1378 /* check this, 1.4 verification guide says otherwise */
1379 if (edid[0x7e]) {
1380 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1381 /* 2 is impossible because of the block map */
1382 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001383 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001385 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001386 }
1387
1388 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001389 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001390
1391 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1392 * the extension parsing loop below. Since v2.0 was quickly deprecated
1393 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1394 * that case now and can fix it when we need to use a real 2.0 panel.
1395 */
Lee Leahy45fde702017-03-08 18:02:24 -08001396 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001397 c.nonconformant_extension +=
1398 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001399
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001400 if (c.claims_one_point_four) {
1401 if (c.nonconformant_digital_display ||
1402 !c.has_valid_string_termination ||
1403 !c.has_valid_descriptor_pad ||
1404 !c.has_preferred_timing)
1405 c.conformant = 0;
1406 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001407 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001408 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +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 Lin08f6c802014-04-03 21:13:11 +08001412 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001413 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001414 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001415 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001416 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001417 } else if (c.claims_one_point_three) {
1418 if (c.nonconformant_digital_display ||
1419 !c.has_valid_string_termination ||
1420 !c.has_valid_descriptor_pad ||
1421 !c.has_preferred_timing) {
1422 c.conformant = 0;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001423 }
1424 /**
1425 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1426 * has_range_descriptor are both required. These fields are
1427 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1428 * don't have them. As a workaround, we only print warning
1429 * messages.
1430 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001431 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001432 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001433 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001434 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1435 "fully conform to EDID 1.3.\n");
1436
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001437 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001438 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001439 c.nonconformant_digital_display);
1440 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001441 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001442 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001443 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001444 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001445 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001446 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001447 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001448 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001449 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001450 } else if (c.claims_one_point_two) {
1451 if (c.nonconformant_digital_display ||
1452 !c.has_valid_string_termination)
1453 c.conformant = 0;
1454 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001455 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001457 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001458 c.nonconformant_digital_display);
1459 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001460 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001461 } else if (c.claims_one_point_oh) {
1462 if (c.seen_non_detailed_descriptor)
1463 c.conformant = 0;
1464 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001465 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001466 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001467 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1468 }
1469
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001470 if (c.nonconformant_extension ||
1471 !c.has_valid_checksum ||
1472 !c.has_valid_cvt ||
1473 !c.has_valid_year ||
1474 !c.has_valid_week ||
1475 !c.has_valid_detailed_blocks ||
1476 !c.has_valid_dummy_block ||
1477 !c.has_valid_extension_count ||
1478 !c.has_valid_descriptor_ordering ||
1479 !c.has_valid_range_descriptor ||
1480 !c.manufacturer_name_well_formed) {
1481 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001482 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001483 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001484 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001485 c.nonconformant_extension);
1486 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001487 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001488 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001489 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001490 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001491 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001492 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001493 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001494 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001495 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001496 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001497 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001498 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001499 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001500 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001501 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001502 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001503 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001504 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001505 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001506 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001507 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1508 }
1509
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001510 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001511 printk(BIOS_ERR,
1512 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001513 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001514 printk(BIOS_ERR,
1515 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001516 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001517}
1518
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001519/*
1520 * Notes on panel extensions: (TODO, implement me in the code)
1521 *
1522 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1523 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1524 * 0x6c: 00 00 00 0e 00
1525 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1526 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1527 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1528 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1529 * bit 4: DE polarity (0 high active 1 low active)
1530 * bit 3-0: interface (0000 LVDS TFT
1531 * 0001 mono STN 4/8bit
1532 * 0010 color STN 8/16 bit
1533 * 0011 18 bit tft
1534 * 0100 24 bit tft
1535 * 0101 tmds
1536 * else reserved)
1537 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1538 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1539 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1540 * else time in 10ms (10ms to 150ms))
1541 * bit 3-0: total poweron seq delay (as above)
1542 * 0x75: contrast power on/off seq delay, same as 0x74
1543 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1544 * bit 6: backlight enabled at boot (0 on 1 off)
1545 * bit 5-0: backlight brightness control steps (0..63)
1546 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1547 * 0x78 - 0x7c: reserved
1548 * 0x7d: bit 7-4: EPI descriptor major version (1)
1549 * bit 3-0: EPI descriptor minor version (0)
1550 *
1551 * ----
1552 *
1553 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1554 *
1555 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1556 *
1557 * detailed descriptor 3:
1558 * 0x5a - 0x5e: 00 00 00 fe 00
1559 * 0x5f - 0x63: PC maker part number
1560 * 0x64: LCD supplier revision #
1561 * 0x65 - 0x6b: manufacturer part number
1562 *
1563 * detailed descriptor 4:
1564 * 0x6c - 0x70: 00 00 00 fe 00
1565 * 0x71 - 0x78: smbus nits values (whut)
1566 * 0x79: number of lvds channels (1 or 2)
1567 * 0x7A: panel self test (1 if present)
1568 * and then dummy terminator
1569 *
1570 * SPWG also says something strange about the LSB of detailed descriptor 1:
1571 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1572 */
Julius Werner69112192016-03-14 17:29:55 -07001573
1574/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001575void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1576 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001577{
1578 /* Caller should pass a supported value, everything else is BUG(). */
1579 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Julius Werner2b6db972016-04-06 12:50:40 -07001580 row_byte_alignment = max(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001581
1582 edid->framebuffer_bits_per_pixel = fb_bpp;
1583 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Julius Werner2b6db972016-04-06 12:50:40 -07001584 div_round_up(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001585 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1586 edid->y_resolution = edid->mode.va;
1587}
1588
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001589/*
1590 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1591 */
1592
Nico Huber994a4a12016-06-16 05:57:49 +02001593void set_vbe_mode_info_valid(const struct edid *edid, uintptr_t fb_addr)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001594{
1595 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001596 edid_fb.x_resolution = edid->x_resolution;
1597 edid_fb.y_resolution = edid->y_resolution;
1598 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001599 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001600 * seems to be to round it up to the nearest reasonable
1601 * boundary, because otherwise the byte-packing is hideous.
1602 * So, for example, in RGB with no alpha, the bytes are still
1603 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1604 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1605 * and in 4:4:4 mode, they are packed into 16-bit words.
1606 * Good call on the hardware guys part.
1607 * It's not clear we're covering all cases here, but
1608 * I'm not sure with grahpics you ever can.
1609 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001610 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001611 edid_fb.reserved_mask_pos = 0;
1612 edid_fb.reserved_mask_size = 0;
Lee Leahy45fde702017-03-08 18:02:24 -08001613 switch (edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001614 case 32:
1615 case 24:
1616 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001617 edid_fb.reserved_mask_pos = 24;
1618 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001619 edid_fb.red_mask_pos = 16;
1620 edid_fb.red_mask_size = 8;
1621 edid_fb.green_mask_pos = 8;
1622 edid_fb.green_mask_size = 8;
1623 edid_fb.blue_mask_pos = 0;
1624 edid_fb.blue_mask_size = 8;
1625 break;
1626 case 16:
1627 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001628 edid_fb.red_mask_pos = 11;
1629 edid_fb.red_mask_size = 5;
1630 edid_fb.green_mask_pos = 5;
1631 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001632 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001633 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001634 break;
1635 default:
1636 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001637 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001638 return;
1639 }
1640
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001641 vbe_valid = 1;
1642}
1643
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001644#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001645int vbe_mode_info_valid(void)
1646{
1647 return vbe_valid;
1648}
1649
1650void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1651{
1652 *framebuffer = edid_fb;
1653}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001654#endif