blob: 07850ee10fa2fd9c15e468ff64a43510aeb9094e [file] [log] [blame]
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001/*
2 * Copyright 2013 Google Inc.
3 * Copyright 2006-2012 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23/* Author: Adam Jackson <ajax@nwnk.net> */
24
25/* this is a pretty robust parser for EDID, and we're tasked with parsing
26 * an arbitrary panel. We will pass it a raw EDID block and a struct which
27 * it must fill in with values. The set of values we need is pretty limited
28 * at present.
29 */
30
31#include <stddef.h>
32#include <console/console.h>
33#include <arch/io.h>
34#include <arch/byteorder.h>
35#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
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070072static int vbe_valid;
73static struct lb_framebuffer edid_fb;
74
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070075static char *manufacturer_name(struct edid *out, unsigned char *x)
76{
77 out->manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
78 out->manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
79 out->manuf_name[2] = (x[1] & 0x1F) + '@';
80 out->manuf_name[3] = 0;
81
82 if (isupper(out->manuf_name[0]) &&
83 isupper(out->manuf_name[1]) &&
84 isupper(out->manuf_name[2]))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080085 return out->manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070086
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080087 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070088}
89
90static int
91detailed_cvt_descriptor(struct edid *out, unsigned char *x, int first)
92{
93 const unsigned char empty[3] = { 0, 0, 0 };
94 const char *names[] = { "50", "60", "75", "85" };
95 int width = 0, height = 0;
96 int valid = 1;
97 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
98
99 if (!first && !memcmp(x, empty, 3))
100 return valid;
101
102 height = x[0];
103 height |= (x[1] & 0xf0) << 4;
104 height++;
105 height *= 2;
106
107 switch (x[1] & 0x0c) {
108 case 0x00:
109 width = (height * 4) / 3; break;
110 case 0x04:
111 width = (height * 16) / 9; break;
112 case 0x08:
113 width = (height * 16) / 10; break;
114 case 0x0c:
115 width = (height * 15) / 9; break;
116 }
117
118 if (x[1] & 0x03)
119 valid = 0;
120 if (x[2] & 0x80)
121 valid = 0;
122 if (!(x[2] & 0x1f))
123 valid = 0;
124
125 fifty = (x[2] & 0x10);
126 sixty = (x[2] & 0x08);
127 seventyfive = (x[2] & 0x04);
128 eightyfive = (x[2] & 0x02);
129 reduced = (x[2] & 0x01);
130
131 if (!valid) {
132 printk(BIOS_SPEW, " (broken)\n");
133 } else {
134 printk(BIOS_SPEW, " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
135 width, height,
136 fifty ? "50 " : "",
137 sixty ? "60 " : "",
138 seventyfive ? "75 " : "",
139 eightyfive ? "85 " : "",
140 reduced ? "60RB " : "",
141 names[(x[2] & 0x60) >> 5],
142 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
143 }
144
145 return valid;
146}
147
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800148/* extract a CP437 string from a detailed subblock, checking for termination (if
149 * less than len of bytes) with LF and padded with SP.
150 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700151static char *
152extract_string(unsigned char *x, int *valid_termination, int len)
153{
154 static char ret[128];
155 int i, seen_newline = 0;
156
157 memset(ret, 0, sizeof(ret));
158
159 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800160 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700161 if (x[i] != 0x20) {
162 *valid_termination = 0;
163 return ret;
164 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800165 } else if (x[i] == 0x0a) {
166 seen_newline = 1;
167 } else {
168 /* normal characters */
169 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700170 }
171 }
172
173 return ret;
174}
175
176/* 1 means valid data */
177static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800178detailed_block(struct edid *out, unsigned char *x, int in_extension,
179 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700180{
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700181 int i;
182#if 1
183 printk(BIOS_SPEW, "Hex of detail: ");
184 for (i = 0; i < 18; i++)
185 printk(BIOS_SPEW, "%02x", x[i]);
186 printk(BIOS_SPEW, "\n");
187#endif
188
189 if (x[0] == 0 && x[1] == 0) {
190 /* Monitor descriptor block, not detailed timing descriptor. */
191 if (x[2] != 0) {
192 /* 1.3, 3.10.3 */
193 printk(BIOS_SPEW, "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
194 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800195 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700196 }
197 if (x[3] != 0xfd && x[4] != 0x00) {
198 /* 1.3, 3.10.3 */
199 printk(BIOS_SPEW, "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
200 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800201 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700202 }
203
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800204 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700205 if (x[3] <= 0xF) {
206 /*
207 * in principle we can decode these, if we know what they are.
208 * 0x0f seems to be common in laptop panels.
209 * 0x0e is used by EPI: http://www.epi-standard.org/
210 */
211 printk(BIOS_SPEW, "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800212 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700213 }
214 switch (x[3]) {
215 case 0x10:
216 printk(BIOS_SPEW, "Dummy block\n");
217 for (i = 5; i < 18; i++)
218 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800219 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800220 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700221 case 0xF7:
222 /* TODO */
223 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800224 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700225 case 0xF8:
226 {
227 int valid_cvt = 1; /* just this block */
228 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
229 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800230 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700231 return 0;
232 }
233 for (i = 0; i < 4; i++)
234 valid_cvt &= detailed_cvt_descriptor(out, x + 6 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800235 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800236 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700237 }
238 case 0xF9:
239 /* TODO */
240 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800241 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700242 case 0xFA:
243 /* TODO */
244 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800245 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700246 case 0xFB:
247 /* TODO */
248 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800249 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700250 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800251 printk(BIOS_SPEW, "Monitor name: %s\n",
252 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800253 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800254 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800255 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700256 case 0xFD:
257 {
258 int h_max_offset = 0, h_min_offset = 0;
259 int v_max_offset = 0, v_min_offset = 0;
260 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800261 c->has_range_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700262 out->range_class = "";
263 /*
264 * XXX todo: implement feature flags, vtd blocks
265 * XXX check: ranges are well-formed; block termination if no vtd
266 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800267 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700268 if (x[4] & 0x02) {
269 v_max_offset = 255;
270 if (x[4] & 0x01) {
271 v_min_offset = 255;
272 }
273 }
274 if (x[4] & 0x04) {
275 h_max_offset = 255;
276 if (x[4] & 0x03) {
277 h_min_offset = 255;
278 }
279 }
280 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800281 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700282 }
283
284 /*
285 * despite the values, this is not a bitfield.
286 */
287 switch (x[10]) {
288 case 0x00: /* default gtf */
289 out->range_class = "GTF";
290 break;
291 case 0x01: /* range limits only */
292 out->range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800293 if (!c->claims_one_point_four)
294 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700295 break;
296 case 0x02: /* secondary gtf curve */
297 out->range_class = "GTF with icing";
298 break;
299 case 0x04: /* cvt */
300 out->range_class = "CVT";
301 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800302 if (!c->claims_one_point_four)
303 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700304 break;
305 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800306 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700307 out->range_class = "invalid";
308 break;
309 }
310
311 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800312 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700313 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800314 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700315 printk(BIOS_SPEW, "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
316 out->range_class,
317 x[5] + v_min_offset, x[6] + v_max_offset,
318 x[7] + h_min_offset, x[8] + h_max_offset);
319 if (x[9])
320 printk(BIOS_SPEW, ", max dotclock %dMHz\n", x[9] * 10);
321 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800322 if (c->claims_one_point_four)
323 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700324 printk(BIOS_SPEW, "\n");
325 }
326
327 if (is_cvt) {
328 int max_h_pixels = 0;
329
330 printk(BIOS_SPEW, "CVT version %d.%d\n", x[11] & 0xf0 >> 4, x[11] & 0x0f);
331
332 if (x[12] & 0xfc) {
333 int raw_offset = (x[12] & 0xfc) >> 2;
Patrick Georgibe71ee5d2014-12-15 22:52:14 +0100334 printk(BIOS_SPEW, "Real max dotclock: %dKHz\n",
335 (x[9] * 10000) - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700336 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800337 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700338 }
339
340 max_h_pixels = x[12] & 0x03;
341 max_h_pixels <<= 8;
342 max_h_pixels |= x[13];
343 max_h_pixels *= 8;
344 if (max_h_pixels)
345 printk(BIOS_SPEW, "Max active pixels per line: %d\n", max_h_pixels);
346
347 printk(BIOS_SPEW, "Supported aspect ratios: %s %s %s %s %s\n",
348 x[14] & 0x80 ? "4:3" : "",
349 x[14] & 0x40 ? "16:9" : "",
350 x[14] & 0x20 ? "16:10" : "",
351 x[14] & 0x10 ? "5:4" : "",
352 x[14] & 0x08 ? "15:9" : "");
353 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800354 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700355
356 printk(BIOS_SPEW, "Preferred aspect ratio: ");
357 switch((x[15] & 0xe0) >> 5) {
358 case 0x00: printk(BIOS_SPEW, "4:3"); break;
359 case 0x01: printk(BIOS_SPEW, "16:9"); break;
360 case 0x02: printk(BIOS_SPEW, "16:10"); break;
361 case 0x03: printk(BIOS_SPEW, "5:4"); break;
362 case 0x04: printk(BIOS_SPEW, "15:9"); break;
363 default: printk(BIOS_SPEW, "(broken)"); break;
364 }
365 printk(BIOS_SPEW, "\n");
366
367 if (x[15] & 0x04)
368 printk(BIOS_SPEW, "Supports CVT standard blanking\n");
369 if (x[15] & 0x10)
370 printk(BIOS_SPEW, "Supports CVT reduced blanking\n");
371
372 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800373 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700374
375 if (x[16] & 0xf0) {
376 printk(BIOS_SPEW, "Supported display scaling:\n");
377 if (x[16] & 0x80)
378 printk(BIOS_SPEW, " Horizontal shrink\n");
379 if (x[16] & 0x40)
380 printk(BIOS_SPEW, " Horizontal stretch\n");
381 if (x[16] & 0x20)
382 printk(BIOS_SPEW, " Vertical shrink\n");
383 if (x[16] & 0x10)
384 printk(BIOS_SPEW, " Vertical stretch\n");
385 }
386
387 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800388 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700389
390 if (x[17])
391 printk(BIOS_SPEW, "Preferred vertical refresh: %d Hz\n", x[17]);
392 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800393 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700394 }
395
396 /*
397 * Slightly weird to return a global, but I've never seen any
398 * EDID block wth two range descriptors, so it's harmless.
399 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800400 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700401 }
402 case 0xFE:
403 /*
404 * TODO: Two of these in a row, in the third and fourth slots,
405 * seems to be specified by SPWG: http://www.spwg.org/
406 */
407 printk(BIOS_SPEW, "ASCII string: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800408 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800409 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700410 case 0xFF:
411 printk(BIOS_SPEW, "Serial number: %s\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800412 extract_string(x + 5, &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800413 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700414 default:
415 printk(BIOS_SPEW, "Unknown monitor description type %d\n", x[3]);
416 return 0;
417 }
418 }
419
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800420 if (c->seen_non_detailed_descriptor && !in_extension) {
421 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700422 }
423
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800424 if (! c->did_detailed_timing){
Furquan Shaikh6b190712013-07-22 16:18:31 -0700425 /* Edid contains pixel clock in terms of 10KHz */
426 out->pixel_clock = (x[0] + (x[1] << 8)) * 10;
Furquan Shaikhaa04ed62013-07-23 15:53:02 -0700427 out->x_mm = (x[12] + ((x[14] & 0xF0) << 4));
428 out->y_mm = (x[13] + ((x[14] & 0x0F) << 8));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700429 out->ha = (x[2] + ((x[4] & 0xF0) << 4));
430 out->hbl = (x[3] + ((x[4] & 0x0F) << 8));
431 out->hso = (x[8] + ((x[11] & 0xC0) << 2));
432 out->hspw = (x[9] + ((x[11] & 0x30) << 4));
433 out->hborder = x[15];
434 out->va = (x[5] + ((x[7] & 0xF0) << 4));
435 out->vbl = (x[6] + ((x[7] & 0x0F) << 8));
436 out->vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
437 out->vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
438 out->vborder = x[16];
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700439 /* set up some reasonable defaults for payloads.
440 * We observe that most modern chipsets we work with
441 * tend to support rgb888 without regard to the
442 * panel bits per color or other settings. The rgb888
443 * is a convenient layout for software because
444 * it avoids the messy bit stuffing of rgb565 or rgb444.
445 * It makes a reasonable trade of memory for speed.
446 * So, set up the default for
447 * 32 bits per pixel
448 * rgb888 (i.e. no alpha, but pixels on 32-bit boundaries)
449 * The mainboard can modify these if needed, though
450 * we have yet to see a case where that will happen.
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700451 * The existing ARM mainboards don't even call this function
452 * so this will not affect them.
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700453 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700454 out->framebuffer_bits_per_pixel = 32;
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700455
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700456 out->x_resolution = ALIGN(out->ha *
457 ((out->framebuffer_bits_per_pixel + 7) / 8),
458 64) / (out->framebuffer_bits_per_pixel/8);
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -0700459 out->y_resolution = out->va;
Ronald G. Minnich9518b562013-09-19 16:45:22 -0700460 out->bytes_per_line = ALIGN(out->ha *
461 ((out->framebuffer_bits_per_pixel + 7)/8),
462 64);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700463 printk(BIOS_SPEW, "Did detailed timing\n");
464 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800465 c->did_detailed_timing = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700466 switch ((x[17] & 0x18) >> 3) {
467 case 0x00:
468 out->syncmethod = " analog composite";
469 break;
470 case 0x01:
471 out->syncmethod = " bipolar analog composite";
472 break;
473 case 0x02:
474 out->syncmethod = " digital composite";
475 break;
476 case 0x03:
477 out->syncmethod = "";
478 break;
479 }
480 out->pvsync = (x[17] & (1 << 2)) ? '+' : '-';
481 out->phsync = (x[17] & (1 << 1)) ? '+' : '-';
482 switch (x[17] & 0x61) {
483 case 0x20:
484 out->stereo = "field sequential L/R";
485 break;
486 case 0x40:
487 out->stereo = "field sequential R/L";
488 break;
489 case 0x21:
490 out->stereo = "interleaved right even";
491 break;
492 case 0x41:
493 out->stereo = "interleaved left even";
494 break;
495 case 0x60:
496 out->stereo = "four way interleaved";
497 break;
498 case 0x61:
499 out->stereo = "side by side interleaved";
500 break;
501 default:
502 out->stereo = "";
503 break;
504 }
505
Furquan Shaikh6b190712013-07-22 16:18:31 -0700506 printk(BIOS_SPEW, "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700507 " %04x %04x %04x %04x hborder %x\n"
508 " %04x %04x %04x %04x vborder %x\n"
509 " %chsync %cvsync%s%s %s\n",
Furquan Shaikh6b190712013-07-22 16:18:31 -0700510 out->pixel_clock,
Furquan Shaikhaa04ed62013-07-23 15:53:02 -0700511 out->x_mm,
512 out->y_mm,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700513 out->ha, out->ha + out->hso, out->ha + out->hso + out->hspw,
514 out->ha + out->hbl, out->hborder,
515 out->va, out->va + out->vso, out->va + out->vso + out->vspw,
516 out->va + out->vbl, out->vborder,
517 out->phsync, out->pvsync,
518 out->syncmethod, x[17] & 0x80 ?" interlaced" : "",
519 out->stereo
520 );
521 return 1;
522}
523
524static int
525do_checksum(unsigned char *x)
526{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800527 int valid = 0;
528 printk(BIOS_SPEW, "Checksum: 0x%hx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700529 {
530 unsigned char sum = 0;
531 int i;
532 for (i = 0; i < 128; i++)
533 sum += x[i];
534 if (sum) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800535 printk(BIOS_SPEW, " (should be 0x%hx)", (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700536 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800537 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700538 printk(BIOS_SPEW, " (valid)");
539 }
540 }
541 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800542 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700543}
544
545/* CEA extension */
546
547static const char *
548audio_format(unsigned char x)
549{
550 switch (x) {
551 case 0: return "RESERVED";
552 case 1: return "Linear PCM";
553 case 2: return "AC-3";
554 case 3: return "MPEG 1 (Layers 1 & 2)";
555 case 4: return "MPEG 1 Layer 3 (MP3)";
556 case 5: return "MPEG2 (multichannel)";
557 case 6: return "AAC";
558 case 7: return "DTS";
559 case 8: return "ATRAC";
560 case 9: return "One Bit Audio";
561 case 10: return "Dolby Digital+";
562 case 11: return "DTS-HD";
563 case 12: return "MAT (MLP)";
564 case 13: return "DST";
565 case 14: return "WMA Pro";
566 case 15: return "RESERVED";
567 }
568 return "BROKEN"; /* can't happen */
569}
570
571static void
572cea_audio_block(unsigned char *x)
573{
574 int i, format;
575 int length = x[0] & 0x1f;
576
577 if (length % 3) {
578 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
579 /* XXX non-conformant */
580 return;
581 }
582
583 for (i = 1; i < length; i += 3) {
584 format = (x[i] & 0x78) >> 3;
585 printk(BIOS_SPEW, " %s, max channels %d\n", audio_format(format),
586 x[i] & 0x07);
587 printk(BIOS_SPEW, " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
588 (x[i+1] & 0x40) ? " 192" : "",
589 (x[i+1] & 0x20) ? " 176.4" : "",
590 (x[i+1] & 0x10) ? " 96" : "",
591 (x[i+1] & 0x08) ? " 88.2" : "",
592 (x[i+1] & 0x04) ? " 48" : "",
593 (x[i+1] & 0x02) ? " 44.1" : "",
594 (x[i+1] & 0x01) ? " 32" : "");
595 if (format == 1) {
596 printk(BIOS_SPEW, " Supported sample sizes (bits):%s%s%s\n",
597 (x[2] & 0x04) ? " 24" : "",
598 (x[2] & 0x02) ? " 20" : "",
599 (x[2] & 0x01) ? " 16" : "");
600 } else if (format <= 8) {
601 printk(BIOS_SPEW, " Maximum bit rate: %d kHz\n", x[2] * 8);
602 }
603 }
604}
605
606static void
607cea_video_block(unsigned char *x)
608{
609 int i;
610 int length = x[0] & 0x1f;
611
612 for (i = 1; i < length; i++)
613 printk(BIOS_SPEW," VIC %02d %s\n", x[i] & 0x7f,
614 x[i] & 0x80 ? "(native)" : "");
615}
616
617static void
618cea_hdmi_block(struct edid *out, unsigned char *x)
619{
620 int length = x[0] & 0x1f;
621
622 printk(BIOS_SPEW, " (HDMI)\n");
623 printk(BIOS_SPEW,
624 " Source physical address %d.%d.%d.%d\n",
625 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
626
627 if (length > 5) {
628 if (x[6] & 0x80)
629 printk(BIOS_SPEW, " Supports_AI\n");
630 if (x[6] & 0x40)
631 printk(BIOS_SPEW, " DC_48bit\n");
632 if (x[6] & 0x20)
633 printk(BIOS_SPEW, " DC_36bit\n");
634 if (x[6] & 0x10)
635 printk(BIOS_SPEW, " DC_30bit\n");
636 if (x[6] & 0x08)
637 printk(BIOS_SPEW, " DC_Y444\n");
638 /* two reserved */
639 if (x[6] & 0x01)
640 printk(BIOS_SPEW, " DVI_Dual\n");
641 }
642
643 if (length > 6)
644 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
645
646 /* XXX the walk here is really ugly, and needs to be length-checked */
647 if (length > 7) {
648 int b = 0;
649
650 if (x[8] & 0x80) {
651 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
652 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
653 b += 2;
654 }
655
656 if (x[8] & 0x40) {
657 printk(BIOS_SPEW, " Interlaced video latency: %d\n", x[9 + b]);
658 printk(BIOS_SPEW, " Interlaced audio latency: %d\n", x[10 + b]);
659 b += 2;
660 }
661
662 if (x[8] & 0x20) {
663 int mask = 0, formats = 0;
664 int len_xx, len_3d;
665 printk(BIOS_SPEW, " Extended HDMI video details:\n");
666 if (x[9 + b] & 0x80)
667 printk(BIOS_SPEW, " 3D present\n");
668 if ((x[9 + b] & 0x60) == 0x20) {
669 printk(BIOS_SPEW, " All advertised VICs are 3D-capable\n");
670 formats = 1;
671 }
672 if ((x[9 + b] & 0x60) == 0x40) {
673 printk(BIOS_SPEW, " 3D-capable-VIC mask present\n");
674 formats = 1;
675 mask = 1;
676 }
677 switch (x[9 + b] & 0x18) {
678 case 0x00: break;
679 case 0x08:
680 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
681 break;
682 case 0x10:
683 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
684 break;
685 case 0x18:
686 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
687 break;
688 }
689 len_xx = (x[10 + b] & 0xe0) >> 5;
690 len_3d = (x[10 + b] & 0x1f) >> 0;
691 b += 2;
692
693 if (len_xx) {
694 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
695 " document\n", len_xx);
696 b += len_xx;
697 }
698
699 if (len_3d) {
700 if (formats) {
701 if (x[9 + b] & 0x01)
702 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
703 if (x[10 + b] & 0x40)
704 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
705 if (x[10 + b] & 0x01)
706 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
707 b += 2;
708 }
709 if (mask) {
710 int i;
711 printk(BIOS_SPEW, " 3D VIC indices:");
712 /* worst bit ordering ever */
713 for (i = 0; i < 8; i++)
714 if (x[10 + b] & (1 << i))
715 printk(BIOS_SPEW, " %d", i);
716 for (i = 0; i < 8; i++)
717 if (x[9 + b] & (1 << i))
718 printk(BIOS_SPEW, " %d", i + 8);
719 printk(BIOS_SPEW, "\n");
720 b += 2;
721 }
722
723 /*
724 * XXX list of nibbles:
725 * 2D_VIC_Order_X
726 * 3D_Structure_X
727 * (optionally: 3D_Detail_X and reserved)
728 */
729 }
730
731 }
732 }
733}
734
735static void
736cea_block(struct edid *out, unsigned char *x)
737{
738 unsigned int oui;
739
740 switch ((x[0] & 0xe0) >> 5) {
741 case 0x01:
742 printk(BIOS_SPEW, " Audio data block\n");
743 cea_audio_block(x);
744 break;
745 case 0x02:
746 printk(BIOS_SPEW, " Video data block\n");
747 cea_video_block(x);
748 break;
749 case 0x03:
750 /* yes really, endianness lols */
751 oui = (x[3] << 16) + (x[2] << 8) + x[1];
752 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x", oui);
753 if (oui == 0x000c03)
754 cea_hdmi_block(out, x);
755 else
756 printk(BIOS_SPEW, "\n");
757 break;
758 case 0x04:
759 printk(BIOS_SPEW, " Speaker allocation data block\n");
760 break;
761 case 0x05:
762 printk(BIOS_SPEW, " VESA DTC data block\n");
763 break;
764 case 0x07:
765 printk(BIOS_SPEW, " Extended tag: ");
766 switch (x[1]) {
767 case 0x00:
768 printk(BIOS_SPEW, "video capability data block\n");
769 break;
770 case 0x01:
771 printk(BIOS_SPEW, "vendor-specific video data block\n");
772 break;
773 case 0x02:
774 printk(BIOS_SPEW, "VESA video display device information data block\n");
775 break;
776 case 0x03:
777 printk(BIOS_SPEW, "VESA video data block\n");
778 break;
779 case 0x04:
780 printk(BIOS_SPEW, "HDMI video data block\n");
781 break;
782 case 0x05:
783 printk(BIOS_SPEW, "Colorimetry data block\n");
784 break;
785 case 0x10:
786 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
787 break;
788 case 0x11:
789 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
790 break;
791 case 0x12:
792 printk(BIOS_SPEW, "HDMI audio data block\n");
793 break;
794 default:
795 if (x[1] >= 6 && x[1] <= 15)
796 printk(BIOS_SPEW, "Reserved video block (%02x)\n", x[1]);
797 else if (x[1] >= 19 && x[1] <= 31)
798 printk(BIOS_SPEW, "Reserved audio block (%02x)\n", x[1]);
799 else
800 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
801 break;
802 }
803 break;
804 default:
805 {
806 int tag = (*x & 0xe0) >> 5;
807 int length = *x & 0x1f;
808 printk(BIOS_SPEW,
809 " Unknown tag %d, length %d (raw %02x)\n", tag, length, *x);
810 break;
811 }
812 }
813}
814
815static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800816parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700817{
818 int ret = 0;
819 int version = x[1];
820 int offset = x[2];
821 unsigned char *detailed;
822
823 if (version >= 1) do {
824 if (version == 1 && x[3] != 0)
825 ret = 1;
826
827 if (offset < 4)
828 break;
829
830 if (version < 3) {
831 printk(BIOS_SPEW, "%d 8-byte timing descriptors\n", (offset - 4) / 8);
832 if (offset - 4 > 0)
833 /* do stuff */ ;
834 } else if (version == 3) {
835 int i;
836 printk(BIOS_SPEW, "%d bytes of CEA data\n", offset - 4);
837 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1) {
838 cea_block(out, x + i);
839 }
840 }
841
842 if (version >= 2) {
843 if (x[3] & 0x80)
844 printk(BIOS_SPEW, "Underscans PC formats by default\n");
845 if (x[3] & 0x40)
846 printk(BIOS_SPEW, "Basic audio support\n");
847 if (x[3] & 0x20)
848 printk(BIOS_SPEW, "Supports YCbCr 4:4:4\n");
849 if (x[3] & 0x10)
850 printk(BIOS_SPEW, "Supports YCbCr 4:2:2\n");
851 printk(BIOS_SPEW, "%d native detailed modes\n", x[3] & 0x0f);
852 }
853
854 for (detailed = x + offset; detailed + 18 < x + 127; detailed += 18)
855 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800856 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700857 } while (0);
858
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800859 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700860 return ret;
861}
862
863/* generic extension code */
864
865static void
866extension_version(struct edid *out, unsigned char *x)
867{
868 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
869}
870
871static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800872parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700873{
874 int conformant_extension = 0;
875 printk(BIOS_SPEW, "\n");
876
877 switch(x[0]) {
878 case 0x02:
879 printk(BIOS_SPEW, "CEA extension block\n");
880 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800881 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700882 break;
883 case 0x10: printk(BIOS_SPEW, "VTB extension block\n"); break;
884 case 0x40: printk(BIOS_SPEW, "DI extension block\n"); break;
885 case 0x50: printk(BIOS_SPEW, "LS extension block\n"); break;
886 case 0x60: printk(BIOS_SPEW, "DPVL extension block\n"); break;
887 case 0xF0: printk(BIOS_SPEW, "Block map\n"); break;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800888 case 0xFF: printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700889 default:
890 printk(BIOS_SPEW, "Unknown extension block\n");
891 break;
892 }
893
894 printk(BIOS_SPEW, "\n");
895
896 return conformant_extension;
897}
898
899static const struct {
900 int x, y, refresh;
901} established_timings[] = {
902 /* 0x23 bit 7 - 0 */
903 {720, 400, 70},
904 {720, 400, 88},
905 {640, 480, 60},
906 {640, 480, 67},
907 {640, 480, 72},
908 {640, 480, 75},
909 {800, 600, 56},
910 {800, 600, 60},
911 /* 0x24 bit 7 - 0 */
912 {800, 600, 72},
913 {800, 600, 75},
914 {832, 624, 75},
915 {1280, 768, 87},
916 {1024, 768, 60},
917 {1024, 768, 70},
918 {1024, 768, 75},
919 {1280, 1024, 75},
920 /* 0x25 bit 7*/
921 {1152, 870, 75},
922};
923
924static void print_subsection(const char *name, unsigned char *edid, int start,
925 int end)
926{
927 int i;
928
929 printk(BIOS_SPEW, "%s:", name);
930 for (i = strlen(name); i < 15; i++)
931 printk(BIOS_SPEW, " ");
932 for (i = start; i <= end; i++)
933 printk(BIOS_SPEW, " %02x", edid[i]);
934 printk(BIOS_SPEW, "\n");
935}
936
937static void dump_breakdown(unsigned char *edid)
938{
939 printk(BIOS_SPEW, "Extracted contents:\n");
940 print_subsection("header", edid, 0, 7);
941 print_subsection("serial number", edid, 8, 17);
942 print_subsection("version", edid,18, 19);
943 print_subsection("basic params", edid, 20, 24);
944 print_subsection("chroma info", edid, 25, 34);
945 print_subsection("established", edid, 35, 37);
946 print_subsection("standard", edid, 38, 53);
947 print_subsection("descriptor 1", edid, 54, 71);
948 print_subsection("descriptor 2", edid, 72, 89);
949 print_subsection("descriptor 3", edid, 90, 107);
950 print_subsection("descriptor 4", edid, 108, 125);
951 print_subsection("extensions", edid, 126, 126);
952 print_subsection("checksum", edid, 127, 127);
953 printk(BIOS_SPEW, "\n");
954}
955
956/*
957 * Given a raw edid bloc, decode it into a form
958 * that other parts of coreboot can use -- mainly
959 * graphics bringup functions. The raw block is
960 * required to be 128 bytes long, per the standard,
961 * but we have no way of checking this minimum length.
962 * We accept what we are given.
963 */
964int decode_edid(unsigned char *edid, int size, struct edid *out)
965{
966 int analog, i;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800967 struct edid_context c = {
968 .has_valid_cvt = 1,
969 .has_valid_dummy_block = 1,
970 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +0800971 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800972 .has_valid_descriptor_pad = 1,
973 .has_valid_range_descriptor = 1,
974 .has_valid_max_dotclock = 1,
975 .has_valid_string_termination = 1,
976 .conformant = 1,
977 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700978
979 dump_breakdown(edid);
980
981 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
982 printk(BIOS_SPEW, "No header found\n");
983 return 1;
984 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800985
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700986 memset(out, 0, sizeof(*out));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800987 if (manufacturer_name(out, edid + 0x08))
988 c.manufacturer_name_well_formed = 1;
989
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700990 out->model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
991 out->serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
992 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
993
994 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
995 out->manuf_name,
996 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
997 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
998 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +0800999 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001000
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001001 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001002 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001003 if (edid[0x11] > 0x0f) {
1004 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001005 c.has_valid_year = 1;
1006 printk(BIOS_SPEW, "Made week %hd of model year %hd\n", edid[0x10],
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001007 edid[0x11]);
1008 out->week = edid[0x10];
1009 out->year = edid[0x11];
1010 } else {
1011 /* we know it's at least 2013, when this code was written */
1012 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001013 c.has_valid_year = 1;
1014 printk(BIOS_SPEW, "Made week %hd of %hd\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001015 edid[0x10], edid[0x11] + 1990);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001016 out->week = edid[0x10];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001017 out->year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001018 }
1019 }
1020 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001021 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001022
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001023 printk(BIOS_SPEW, "EDID version: %hd.%hd\n", edid[0x12], edid[0x13]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001024 out->version[0] = edid[0x12];
1025 out->version[1] = edid[0x13];
1026
1027 if (edid[0x12] == 1) {
1028 if (edid[0x13] > 4) {
1029 printk(BIOS_SPEW, "Claims > 1.4, assuming 1.4 conformance\n");
1030 edid[0x13] = 4;
1031 }
1032 switch (edid[0x13]) {
1033 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001034 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001035 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001036 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001037 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001038 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001039 default:
1040 break;
1041 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001042 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001043 }
1044
1045 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001046 if (edid[0x14] & 0x80) {
1047 int conformance_mask;
1048 analog = 0;
1049 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001050 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001051 conformance_mask = 0;
1052 if ((edid[0x14] & 0x70) == 0x00)
1053 printk(BIOS_SPEW, "Color depth is undefined\n");
1054 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001055 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001056 else
1057 printk(BIOS_SPEW, "%d bits per primary color channel\n",
1058 ((edid[0x14] & 0x70) >> 3) + 4);
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001059 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3) + 4;
1060 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001061
1062 switch (edid[0x14] & 0x0f) {
1063 case 0x00: printk(BIOS_SPEW, "Digital interface is not defined\n"); break;
1064 case 0x01: printk(BIOS_SPEW, "DVI interface\n"); break;
1065 case 0x02: printk(BIOS_SPEW, "HDMI-a interface\n"); break;
1066 case 0x03: printk(BIOS_SPEW, "HDMI-b interface\n"); break;
1067 case 0x04: printk(BIOS_SPEW, "MDDI interface\n"); break;
1068 case 0x05: printk(BIOS_SPEW, "DisplayPort interface\n"); break;
1069 default:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001070 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001071 }
1072 out->type = edid[0x14] & 0x0f;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001073 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001074 conformance_mask = 0x7E;
1075 if (edid[0x14] & 0x01) {
1076 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
1077 }
1078 } else
1079 conformance_mask = 0x7F;
1080
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001081 if (!c.nonconformant_digital_display)
1082 c.nonconformant_digital_display = edid[0x14] & conformance_mask;
1083 out->nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001084 } else {
1085 analog = 1;
1086 int voltage = (edid[0x14] & 0x60) >> 5;
1087 int sync = (edid[0x14] & 0x0F);
1088 out->voltage = voltage;
1089 out->sync = sync;
1090
1091 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1092 voltage == 3 ? "0.7/0.7" :
1093 voltage == 2 ? "1.0/0.4" :
1094 voltage == 1 ? "0.714/0.286" :
1095 "0.7/0.3");
1096
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001097 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001098 if (edid[0x14] & 0x10)
1099 printk(BIOS_SPEW, "Blank-to-black setup/pedestal\n");
1100 else
1101 printk(BIOS_SPEW, "Blank level equals black level\n");
1102 } else if (edid[0x14] & 0x10) {
1103 /*
1104 * XXX this is just the X text. 1.3 says "if set, display expects
1105 * a blank-to-black setup or pedestal per appropriate Signal
1106 * Level Standard". Whatever _that_ means.
1107 */
1108 printk(BIOS_SPEW, "Configurable signal levels\n");
1109 }
1110
1111 printk(BIOS_SPEW, "Sync: %s%s%s%s\n", sync & 0x08 ? "Separate " : "",
1112 sync & 0x04 ? "Composite " : "",
1113 sync & 0x02 ? "SyncOnGreen " : "",
1114 sync & 0x01 ? "Serration " : "");
1115 }
1116
1117
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001118 if (edid[0x15] && edid[0x16]) {
1119 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1120 edid[0x15], edid[0x16]);
1121 out->xsize_cm = edid[0x15];
1122 out->ysize_cm = edid[0x16];
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001123 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001124 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1125 unsigned int ratio = 100000/(edid[0x15] + 99);
1126 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (landscape)\n",
1127 ratio / 1000, ratio % 1000);
1128 out->aspect_landscape = ratio / 100;
1129 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1130 unsigned int ratio = 100000/(edid[0x16] + 99);
1131 printk(BIOS_SPEW, "Aspect ratio is %u.%03u (portrait)\n",
1132 ratio / 1000, ratio % 1000);
1133 out->aspect_portrait = ratio / 100;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001134 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001135 } else {
1136 /* Either or both can be zero for 1.3 and before */
1137 printk(BIOS_SPEW, "Image size is variable\n");
1138 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001139
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001140 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001141 if (c.claims_one_point_four)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001142 printk(BIOS_SPEW, "Gamma is defined in an extension block\n");
1143 else
1144 /* XXX Technically 1.3 doesn't say this... */
1145 printk(BIOS_SPEW, "Gamma: 1.0\n");
1146 } else printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
1147 printk(BIOS_SPEW, "Check DPMS levels\n");
1148 if (edid[0x18] & 0xE0) {
1149 printk(BIOS_SPEW, "DPMS levels:");
1150 if (edid[0x18] & 0x80) printk(BIOS_SPEW, " Standby");
1151 if (edid[0x18] & 0x40) printk(BIOS_SPEW, " Suspend");
1152 if (edid[0x18] & 0x20) printk(BIOS_SPEW, " Off");
1153 printk(BIOS_SPEW, "\n");
1154 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001155
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001156 /* FIXME: this is from 1.4 spec, check earlier */
1157 if (analog) {
1158 switch (edid[0x18] & 0x18) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001159 case 0x00: printk(BIOS_SPEW, "Monochrome or grayscale display\n"); break;
1160 case 0x08: printk(BIOS_SPEW, "RGB color display\n"); break;
1161 case 0x10: printk(BIOS_SPEW, "Non-RGB color display\n"); break;
1162 case 0x18: printk(BIOS_SPEW, "Undefined display color type\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001163 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001164 } else {
1165 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1166 if (edid[0x18] & 0x10)
1167 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1168 if (edid[0x18] & 0x08)
1169 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1170 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001171 }
1172
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001173 if (edid[0x18] & 0x04)
1174 printk(BIOS_SPEW, "Default (sRGB) color space is primary color space\n");
1175 if (edid[0x18] & 0x02) {
1176 printk(BIOS_SPEW, "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001177 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001178 }
1179 if (edid[0x18] & 0x01)
1180 printk(BIOS_SPEW, "Supports GTF timings within operating range\n");
1181
1182 /* XXX color section */
1183
1184 printk(BIOS_SPEW, "Established timings supported:\n");
1185 /* it's not yet clear we want all this stuff in the edid struct.
1186 * Let's wait.
1187 */
1188 for (i = 0; i < 17; i++) {
1189 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
1190 printk(BIOS_SPEW, " %dx%d@%dHz\n", established_timings[i].x,
1191 established_timings[i].y, established_timings[i].refresh);
1192 }
1193 }
1194
1195 printk(BIOS_SPEW, "Standard timings supported:\n");
1196 for (i = 0; i < 8; i++) {
1197 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1198 unsigned int x, y = 0, refresh;
1199
1200 if (b1 == 0x01 && b2 == 0x01)
1201 continue;
1202
1203 if (b1 == 0) {
1204 printk(BIOS_SPEW, "non-conformant standard timing (0 horiz)\n");
1205 continue;
1206 }
1207 x = (b1 + 31) * 8;
1208 switch ((b2 >> 6) & 0x3) {
1209 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001210 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001211 y = x * 10 / 16;
1212 else
1213 y = x;
1214 break;
1215 case 0x01:
1216 y = x * 3 / 4;
1217 break;
1218 case 0x02:
1219 y = x * 4 / 5;
1220 break;
1221 case 0x03:
1222 y = x * 9 / 16;
1223 break;
1224 }
1225 refresh = 60 + (b2 & 0x3f);
1226
1227 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
1228 }
1229
1230 /* detailed timings */
1231 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001232 for (i = 0; i < 4; i++) {
1233 c.has_valid_detailed_blocks &= detailed_block(
1234 out, edid + 0x36 + i * 18, 0, &c);
1235 if (i == 0 && c.has_preferred_timing && !c.did_detailed_timing)
1236 {
1237 /* not really accurate... */
1238 c.has_preferred_timing = 0;
1239 }
1240 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001241
1242 /* check this, 1.4 verification guide says otherwise */
1243 if (edid[0x7e]) {
1244 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1245 /* 2 is impossible because of the block map */
1246 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001247 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001248 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001249 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001250 }
1251
1252 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001253 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001254
1255 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1256 * the extension parsing loop below. Since v2.0 was quickly deprecated
1257 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1258 * that case now and can fix it when we need to use a real 2.0 panel.
1259 */
1260 for(i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001261 c.nonconformant_extension +=
1262 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001263
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001264 if (c.claims_one_point_four) {
1265 if (c.nonconformant_digital_display ||
1266 !c.has_valid_string_termination ||
1267 !c.has_valid_descriptor_pad ||
1268 !c.has_preferred_timing)
1269 c.conformant = 0;
1270 if (!c.conformant)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001271 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.4!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001272 if (c.nonconformant_digital_display)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001273 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001274 c.nonconformant_digital_display);
1275 if (!c.has_valid_string_termination)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001276 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001277 if (!c.has_valid_descriptor_pad)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001278 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001279 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001280 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001281 } else if (c.claims_one_point_three) {
1282 if (c.nonconformant_digital_display ||
1283 !c.has_valid_string_termination ||
1284 !c.has_valid_descriptor_pad ||
1285 !c.has_preferred_timing) {
1286 c.conformant = 0;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001287 }
1288 /**
1289 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1290 * has_range_descriptor are both required. These fields are
1291 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1292 * don't have them. As a workaround, we only print warning
1293 * messages.
1294 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001295 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001296 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001297 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001298 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1299 "fully conform to EDID 1.3.\n");
1300
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001301 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001302 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001303 c.nonconformant_digital_display);
1304 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001305 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001306 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001307 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001308 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001309 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001310 if (!c.has_valid_descriptor_pad) /* Might be more than just 1.3 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001311 printk(BIOS_ERR, "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001312 if (!c.has_valid_string_termination) /* Likewise */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001313 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001314 } else if (c.claims_one_point_two) {
1315 if (c.nonconformant_digital_display ||
1316 !c.has_valid_string_termination)
1317 c.conformant = 0;
1318 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001319 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.2!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001320 if (c.nonconformant_digital_display)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001321 printk(BIOS_ERR, "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001322 c.nonconformant_digital_display);
1323 if (!c.has_valid_string_termination)
Hung-Te Lin2536c1a2014-04-03 19:21:03 +08001324 printk(BIOS_ERR, "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001325 } else if (c.claims_one_point_oh) {
1326 if (c.seen_non_detailed_descriptor)
1327 c.conformant = 0;
1328 if (!c.conformant)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001329 printk(BIOS_ERR, "EDID block does NOT conform to EDID 1.0!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001330 if (c.seen_non_detailed_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001331 printk(BIOS_ERR, "\tHas descriptor blocks other than detailed timings\n");
1332 }
1333
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001334 if (c.nonconformant_extension ||
1335 !c.has_valid_checksum ||
1336 !c.has_valid_cvt ||
1337 !c.has_valid_year ||
1338 !c.has_valid_week ||
1339 !c.has_valid_detailed_blocks ||
1340 !c.has_valid_dummy_block ||
1341 !c.has_valid_extension_count ||
1342 !c.has_valid_descriptor_ordering ||
1343 !c.has_valid_range_descriptor ||
1344 !c.manufacturer_name_well_formed) {
1345 c.conformant = 0;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001346 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001347 if (c.nonconformant_extension)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001348 printk(BIOS_ERR, "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001349 c.nonconformant_extension);
1350 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001351 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001352 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001353 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001354 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001355 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001356 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001357 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001358 if (!c.has_valid_detailed_blocks)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001359 printk(BIOS_ERR, "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001360 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001361 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001362 if (!c.has_valid_extension_count)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001363 printk(BIOS_ERR, "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001364 if (!c.manufacturer_name_well_formed)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001365 printk(BIOS_ERR, "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001366 if (!c.has_valid_descriptor_ordering)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001367 printk(BIOS_ERR, "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001368 if (!c.has_valid_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001369 printk(BIOS_ERR, "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001370 if (!c.has_valid_max_dotclock)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001371 printk(BIOS_ERR, "\tEDID 1.4 block does not set max dotclock\n");
1372 }
1373
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001374 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001375 printk(BIOS_ERR,
1376 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001377 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001378 printk(BIOS_ERR,
1379 "Warning: CVT block does not set preferred refresh rate\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001380 return !c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001381}
1382
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001383/*
1384 * Notes on panel extensions: (TODO, implement me in the code)
1385 *
1386 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1387 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1388 * 0x6c: 00 00 00 0e 00
1389 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1390 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1391 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1392 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1393 * bit 4: DE polarity (0 high active 1 low active)
1394 * bit 3-0: interface (0000 LVDS TFT
1395 * 0001 mono STN 4/8bit
1396 * 0010 color STN 8/16 bit
1397 * 0011 18 bit tft
1398 * 0100 24 bit tft
1399 * 0101 tmds
1400 * else reserved)
1401 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1402 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1403 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1404 * else time in 10ms (10ms to 150ms))
1405 * bit 3-0: total poweron seq delay (as above)
1406 * 0x75: contrast power on/off seq delay, same as 0x74
1407 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1408 * bit 6: backlight enabled at boot (0 on 1 off)
1409 * bit 5-0: backlight brightness control steps (0..63)
1410 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1411 * 0x78 - 0x7c: reserved
1412 * 0x7d: bit 7-4: EPI descriptor major version (1)
1413 * bit 3-0: EPI descriptor minor version (0)
1414 *
1415 * ----
1416 *
1417 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1418 *
1419 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1420 *
1421 * detailed descriptor 3:
1422 * 0x5a - 0x5e: 00 00 00 fe 00
1423 * 0x5f - 0x63: PC maker part number
1424 * 0x64: LCD supplier revision #
1425 * 0x65 - 0x6b: manufacturer part number
1426 *
1427 * detailed descriptor 4:
1428 * 0x6c - 0x70: 00 00 00 fe 00
1429 * 0x71 - 0x78: smbus nits values (whut)
1430 * 0x79: number of lvds channels (1 or 2)
1431 * 0x7A: panel self test (1 if present)
1432 * and then dummy terminator
1433 *
1434 * SPWG also says something strange about the LSB of detailed descriptor 1:
1435 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1436 */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001437/*
1438 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1439 */
1440
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001441void set_vbe_mode_info_valid(struct edid *edid, uintptr_t fb_addr)
1442{
1443 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001444 edid_fb.x_resolution = edid->x_resolution;
1445 edid_fb.y_resolution = edid->y_resolution;
1446 edid_fb.bytes_per_line = edid->bytes_per_line;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001447 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention nowadays
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001448 * seems to be to round it up to the nearest reasonable
1449 * boundary, because otherwise the byte-packing is hideous.
1450 * So, for example, in RGB with no alpha, the bytes are still
1451 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1452 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1453 * and in 4:4:4 mode, they are packed into 16-bit words.
1454 * Good call on the hardware guys part.
1455 * It's not clear we're covering all cases here, but
1456 * I'm not sure with grahpics you ever can.
1457 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001458 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
1459 switch(edid->framebuffer_bits_per_pixel){
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001460 case 32:
1461 case 24:
1462 /* packed into 4-byte words */
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001463 edid_fb.red_mask_pos = 16;
1464 edid_fb.red_mask_size = 8;
1465 edid_fb.green_mask_pos = 8;
1466 edid_fb.green_mask_size = 8;
1467 edid_fb.blue_mask_pos = 0;
1468 edid_fb.blue_mask_size = 8;
1469 break;
1470 case 16:
1471 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001472 edid_fb.red_mask_pos = 11;
1473 edid_fb.red_mask_size = 5;
1474 edid_fb.green_mask_pos = 5;
1475 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001476 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001477 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001478 break;
1479 default:
1480 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001481 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001482 return;
1483 }
1484
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001485 edid_fb.reserved_mask_pos = 0;
1486 edid_fb.reserved_mask_size = 0;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001487 vbe_valid = 1;
1488}
1489
1490int vbe_mode_info_valid(void)
1491{
1492 return vbe_valid;
1493}
1494
1495void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1496{
1497 *framebuffer = edid_fb;
1498}