blob: 405b3fdbc1cf004ddc2a2fc29fbe859f7db6a759 [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;
Arthur Heymans8c5884e2017-04-30 08:28:05 +020069 enum edid_status conformant;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080070};
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) + '@';
Lee Leahy73402172017-03-10 15:23:24 -0800103 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5)
104 + '@';
David Hendricksa3b898a2015-08-02 18:07:48 -0700105 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
106 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700107
David Hendricksa3b898a2015-08-02 18:07:48 -0700108 if (isupper(extra_info.manuf_name[0]) &&
109 isupper(extra_info.manuf_name[1]) &&
110 isupper(extra_info.manuf_name[2]))
111 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700112
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800113 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700114}
115
116static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700117detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700118{
119 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -0800120 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700121 int width = 0, height = 0;
122 int valid = 1;
123 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
124
125 if (!first && !memcmp(x, empty, 3))
126 return valid;
127
128 height = x[0];
129 height |= (x[1] & 0xf0) << 4;
130 height++;
131 height *= 2;
132
133 switch (x[1] & 0x0c) {
134 case 0x00:
135 width = (height * 4) / 3; break;
136 case 0x04:
137 width = (height * 16) / 9; break;
138 case 0x08:
139 width = (height * 16) / 10; break;
140 case 0x0c:
141 width = (height * 15) / 9; break;
142 }
143
144 if (x[1] & 0x03)
145 valid = 0;
146 if (x[2] & 0x80)
147 valid = 0;
148 if (!(x[2] & 0x1f))
149 valid = 0;
150
151 fifty = (x[2] & 0x10);
152 sixty = (x[2] & 0x08);
153 seventyfive = (x[2] & 0x04);
154 eightyfive = (x[2] & 0x02);
155 reduced = (x[2] & 0x01);
156
157 if (!valid) {
158 printk(BIOS_SPEW, " (broken)\n");
159 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800160 printk(BIOS_SPEW,
161 " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700162 width, height,
163 fifty ? "50 " : "",
164 sixty ? "60 " : "",
165 seventyfive ? "75 " : "",
166 eightyfive ? "85 " : "",
167 reduced ? "60RB " : "",
168 names[(x[2] & 0x60) >> 5],
169 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
170 }
171
172 return valid;
173}
174
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800175/* extract a CP437 string from a detailed subblock, checking for termination (if
176 * less than len of bytes) with LF and padded with SP.
177 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700178static char *
179extract_string(unsigned char *x, int *valid_termination, int len)
180{
181 static char ret[128];
182 int i, seen_newline = 0;
183
184 memset(ret, 0, sizeof(ret));
185
186 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800187 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700188 if (x[i] != 0x20) {
189 *valid_termination = 0;
190 return ret;
191 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800192 } else if (x[i] == 0x0a) {
193 seen_newline = 1;
194 } else {
195 /* normal characters */
196 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700197 }
198 }
199
200 return ret;
201}
202
203/* 1 means valid data */
204static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700205detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800206 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700207{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700208 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700209 int i;
210#if 1
211 printk(BIOS_SPEW, "Hex of detail: ");
212 for (i = 0; i < 18; i++)
213 printk(BIOS_SPEW, "%02x", x[i]);
214 printk(BIOS_SPEW, "\n");
215#endif
216
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700217 /* Result might already have some valid fields like mode_is_supported */
218 *out = *result_edid;
219
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700220 if (x[0] == 0 && x[1] == 0) {
221 /* Monitor descriptor block, not detailed timing descriptor. */
222 if (x[2] != 0) {
223 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800224 printk(BIOS_SPEW,
225 "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700226 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800227 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700228 }
229 if (x[3] != 0xfd && x[4] != 0x00) {
230 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800231 printk(BIOS_SPEW,
232 "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700233 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800234 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700235 }
236
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800237 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700238 if (x[3] <= 0xF) {
239 /*
Lee Leahy73402172017-03-10 15:23:24 -0800240 * in principle we can decode these, if we know what
241 * they are.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700242 * 0x0f seems to be common in laptop panels.
243 * 0x0e is used by EPI: http://www.epi-standard.org/
244 */
Lee Leahy73402172017-03-10 15:23:24 -0800245 printk(BIOS_SPEW,
246 "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800247 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700248 }
249 switch (x[3]) {
250 case 0x10:
251 printk(BIOS_SPEW, "Dummy block\n");
252 for (i = 5; i < 18; i++)
253 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800254 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800255 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700256 case 0xF7:
257 /* TODO */
258 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800259 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700260 case 0xF8:
261 {
262 int valid_cvt = 1; /* just this block */
263 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
264 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800265 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700266 return 0;
267 }
268 for (i = 0; i < 4; i++)
Lee Leahy73402172017-03-10 15:23:24 -0800269 valid_cvt &= detailed_cvt_descriptor(x + 6
270 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800271 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800272 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700273 }
274 case 0xF9:
275 /* TODO */
276 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800277 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700278 case 0xFA:
279 /* TODO */
280 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800281 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700282 case 0xFB:
283 /* TODO */
284 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800285 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700286 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800287 printk(BIOS_SPEW, "Monitor name: %s\n",
288 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800289 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800290 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800291 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700292 case 0xFD:
293 {
294 int h_max_offset = 0, h_min_offset = 0;
295 int v_max_offset = 0, v_min_offset = 0;
296 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800297 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700298 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700299 /*
300 * XXX todo: implement feature flags, vtd blocks
Lee Leahy73402172017-03-10 15:23:24 -0800301 * XXX check: ranges are well-formed; block termination
302 * if no vtd
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700303 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800304 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700305 if (x[4] & 0x02) {
306 v_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800307 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700308 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700309 }
310 if (x[4] & 0x04) {
311 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800312 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700313 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700314 }
315 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800316 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700317 }
318
319 /*
320 * despite the values, this is not a bitfield.
321 */
322 switch (x[10]) {
323 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700324 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700325 break;
326 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700327 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800328 if (!c->claims_one_point_four)
329 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700330 break;
331 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700332 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700333 break;
334 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700335 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700336 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800337 if (!c->claims_one_point_four)
338 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700339 break;
340 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800341 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700342 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700343 break;
344 }
345
346 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800347 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700348 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800349 c->has_valid_range_descriptor = 0;
Lee Leahy73402172017-03-10 15:23:24 -0800350 printk(BIOS_SPEW,
351 "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700352 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700353 x[5] + v_min_offset, x[6] + v_max_offset,
354 x[7] + h_min_offset, x[8] + h_max_offset);
355 if (x[9])
Lee Leahy73402172017-03-10 15:23:24 -0800356 printk(BIOS_SPEW,
357 ", max dotclock %dMHz\n", x[9] * 10);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700358 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800359 if (c->claims_one_point_four)
360 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700361 printk(BIOS_SPEW, "\n");
362 }
363
364 if (is_cvt) {
365 int max_h_pixels = 0;
366
Lee Leahy73402172017-03-10 15:23:24 -0800367 printk(BIOS_SPEW, "CVT version %d.%d\n",
368 x[11] & 0xf0 >> 4, x[11] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700369
370 if (x[12] & 0xfc) {
371 int raw_offset = (x[12] & 0xfc) >> 2;
Lee Leahy73402172017-03-10 15:23:24 -0800372 printk(BIOS_SPEW,
373 "Real max dotclock: %dKHz\n",
374 (x[9] * 10000)
375 - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700376 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800377 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700378 }
379
380 max_h_pixels = x[12] & 0x03;
381 max_h_pixels <<= 8;
382 max_h_pixels |= x[13];
383 max_h_pixels *= 8;
384 if (max_h_pixels)
Lee Leahy73402172017-03-10 15:23:24 -0800385 printk(BIOS_SPEW,
386 "Max active pixels per line: %d\n",
387 max_h_pixels);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700388
Lee Leahy73402172017-03-10 15:23:24 -0800389 printk(BIOS_SPEW,
390 "Supported aspect ratios: %s %s %s %s %s\n",
391 x[14] & 0x80 ? "4:3" : "",
392 x[14] & 0x40 ? "16:9" : "",
393 x[14] & 0x20 ? "16:10" : "",
394 x[14] & 0x10 ? "5:4" : "",
395 x[14] & 0x08 ? "15:9" : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700396 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800397 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700398
399 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800400 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800401 case 0x00:
402 printk(BIOS_SPEW, "4:3");
403 break;
404 case 0x01:
405 printk(BIOS_SPEW, "16:9");
406 break;
407 case 0x02:
408 printk(BIOS_SPEW, "16:10");
409 break;
410 case 0x03:
411 printk(BIOS_SPEW, "5:4");
412 break;
413 case 0x04:
414 printk(BIOS_SPEW, "15:9");
415 break;
416 default:
417 printk(BIOS_SPEW, "(broken)");
418 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700419 }
420 printk(BIOS_SPEW, "\n");
421
422 if (x[15] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -0800423 printk(BIOS_SPEW,
424 "Supports CVT standard blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700425 if (x[15] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800426 printk(BIOS_SPEW,
427 "Supports CVT reduced blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700428
429 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800430 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700431
432 if (x[16] & 0xf0) {
Lee Leahy73402172017-03-10 15:23:24 -0800433 printk(BIOS_SPEW,
434 "Supported display scaling:\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700435 if (x[16] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800436 printk(BIOS_SPEW,
437 " Horizontal shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700438 if (x[16] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800439 printk(BIOS_SPEW,
440 " Horizontal stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700441 if (x[16] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800442 printk(BIOS_SPEW,
443 " Vertical shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700444 if (x[16] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800445 printk(BIOS_SPEW,
446 " Vertical stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700447 }
448
449 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800450 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700451
452 if (x[17])
Lee Leahy73402172017-03-10 15:23:24 -0800453 printk(BIOS_SPEW,
454 "Preferred vertical refresh: %d Hz\n",
455 x[17]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700456 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800457 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700458 }
459
460 /*
Lee Leahy73402172017-03-10 15:23:24 -0800461 * Slightly weird to return a global, but I've never
462 * seen any EDID block wth two range descriptors, so
463 * it's harmless.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700464 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800465 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700466 }
467 case 0xFE:
468 /*
Lee Leahy73402172017-03-10 15:23:24 -0800469 * TODO: Two of these in a row, in the third and fourth
470 * slots, seems to be specified by SPWG:
471 * http://www.spwg.org/
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700472 */
Arthur Heymansdbe81612017-04-29 14:00:47 +0200473 strcpy(result_edid->ascii_string, extract_string(x + 5,
474 &c->has_valid_string_termination,
475 EDID_ASCII_STRING_LENGTH));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700476 printk(BIOS_SPEW, "ASCII string: %s\n",
Arthur Heymansdbe81612017-04-29 14:00:47 +0200477 result_edid->ascii_string);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800478 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700479 case 0xFF:
480 printk(BIOS_SPEW, "Serial number: %s\n",
Lee Leahy73402172017-03-10 15:23:24 -0800481 extract_string(x + 5,
482 &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800483 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700484 default:
Lee Leahy73402172017-03-10 15:23:24 -0800485 printk(BIOS_SPEW,
486 "Unknown monitor description type %d\n",
487 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700488 return 0;
489 }
490 }
491
Lee Leahy2f919ec2017-03-08 17:37:06 -0800492 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800493 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700494
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700495 /* Edid contains pixel clock in terms of 10KHz */
496 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
497 /*
498 LVDS supports following pixel clocks
499 25000...112000 kHz: single channel
500 80000...224000 kHz: dual channel
501 There is some overlap in theoretically supported
502 pixel clock between single-channel and dual-channel.
503 In practice with current panels all panels
504 <= 75200 kHz: single channel
505 >= 97750 kHz: dual channel
506 We have no samples between those values, so put a
507 threshold at 95000 kHz. If we get anything over
508 95000 kHz with single channel, we can make this
509 more sofisticated but it's currently not needed.
510 */
511 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
512 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
513 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
514 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
515 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
516 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
517 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
518 out->mode.hborder = x[15];
519 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
520 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
521 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
522 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
523 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700524
Julius Werner69112192016-03-14 17:29:55 -0700525 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700526 * Chipsets that want something else will need to override this with
527 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
528 * heuristic, assume that X86 systems require a 64-byte row alignment
529 * (since that seems to be true for most Intel chipsets). */
530 if (IS_ENABLED(CONFIG_ARCH_X86))
531 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
532 else
533 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700534
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700535 switch ((x[17] & 0x18) >> 3) {
536 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700537 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700538 break;
539 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700540 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700541 break;
542 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700543 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700544 break;
545 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700546 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700547 break;
548 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700549 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
550 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700551 switch (x[17] & 0x61) {
552 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700553 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700554 break;
555 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700556 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700557 break;
558 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700559 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700560 break;
561 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700562 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700563 break;
564 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700565 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700566 break;
567 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700568 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700569 break;
570 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700571 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700572 break;
573 }
574
Lee Leahy73402172017-03-10 15:23:24 -0800575 printk(BIOS_SPEW,
576 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700577 " %04x %04x %04x %04x hborder %x\n"
578 " %04x %04x %04x %04x vborder %x\n"
579 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700580 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700581 extra_info.x_mm,
582 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700583 out->mode.ha, out->mode.ha + out->mode.hso,
584 out->mode.ha + out->mode.hso + out->mode.hspw,
585 out->mode.ha + out->mode.hbl, out->mode.hborder,
586 out->mode.va, out->mode.va + out->mode.vso,
587 out->mode.va + out->mode.vso + out->mode.vspw,
588 out->mode.va + out->mode.vbl, out->mode.vborder,
589 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800590 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700591 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700592
Lee Leahy35af5c42017-03-09 17:35:28 -0800593 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700594 printk(BIOS_SPEW, "Did detailed timing\n");
595 c->did_detailed_timing = 1;
596 *result_edid = *out;
597 }
598
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700599 return 1;
600}
601
602static int
603do_checksum(unsigned char *x)
604{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800605 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600606 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700607 {
608 unsigned char sum = 0;
609 int i;
610 for (i = 0; i < 128; i++)
611 sum += x[i];
612 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800613 printk(BIOS_SPEW, " (should be 0x%hhx)",
614 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700615 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800616 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700617 printk(BIOS_SPEW, " (valid)");
618 }
619 }
620 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800621 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700622}
623
624/* CEA extension */
625
626static const char *
627audio_format(unsigned char x)
628{
629 switch (x) {
630 case 0: return "RESERVED";
631 case 1: return "Linear PCM";
632 case 2: return "AC-3";
633 case 3: return "MPEG 1 (Layers 1 & 2)";
634 case 4: return "MPEG 1 Layer 3 (MP3)";
635 case 5: return "MPEG2 (multichannel)";
636 case 6: return "AAC";
637 case 7: return "DTS";
638 case 8: return "ATRAC";
639 case 9: return "One Bit Audio";
640 case 10: return "Dolby Digital+";
641 case 11: return "DTS-HD";
642 case 12: return "MAT (MLP)";
643 case 13: return "DST";
644 case 14: return "WMA Pro";
645 case 15: return "RESERVED";
646 }
647 return "BROKEN"; /* can't happen */
648}
649
650static void
651cea_audio_block(unsigned char *x)
652{
653 int i, format;
654 int length = x[0] & 0x1f;
655
656 if (length % 3) {
657 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
658 /* XXX non-conformant */
659 return;
660 }
661
662 for (i = 1; i < length; i += 3) {
663 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800664 printk(BIOS_SPEW, " %s, max channels %d\n",
665 audio_format(format), x[i] & 0x07);
666 printk(BIOS_SPEW,
667 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700668 (x[i+1] & 0x40) ? " 192" : "",
669 (x[i+1] & 0x20) ? " 176.4" : "",
670 (x[i+1] & 0x10) ? " 96" : "",
671 (x[i+1] & 0x08) ? " 88.2" : "",
672 (x[i+1] & 0x04) ? " 48" : "",
673 (x[i+1] & 0x02) ? " 44.1" : "",
674 (x[i+1] & 0x01) ? " 32" : "");
675 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800676 printk(BIOS_SPEW,
677 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700678 (x[2] & 0x04) ? " 24" : "",
679 (x[2] & 0x02) ? " 20" : "",
680 (x[2] & 0x01) ? " 16" : "");
681 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800682 printk(BIOS_SPEW,
683 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700684 }
685 }
686}
687
688static void
689cea_video_block(unsigned char *x)
690{
691 int i;
692 int length = x[0] & 0x1f;
693
694 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800695 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700696 x[i] & 0x80 ? "(native)" : "");
697}
698
699static void
700cea_hdmi_block(struct edid *out, unsigned char *x)
701{
702 int length = x[0] & 0x1f;
703
Yakir Yang85810cc2015-10-27 16:17:13 +0800704 out->hdmi_monitor_detected = 1;
705
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700706 printk(BIOS_SPEW, " (HDMI)\n");
707 printk(BIOS_SPEW,
708 " Source physical address %d.%d.%d.%d\n",
709 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
710
711 if (length > 5) {
712 if (x[6] & 0x80)
713 printk(BIOS_SPEW, " Supports_AI\n");
714 if (x[6] & 0x40)
715 printk(BIOS_SPEW, " DC_48bit\n");
716 if (x[6] & 0x20)
717 printk(BIOS_SPEW, " DC_36bit\n");
718 if (x[6] & 0x10)
719 printk(BIOS_SPEW, " DC_30bit\n");
720 if (x[6] & 0x08)
721 printk(BIOS_SPEW, " DC_Y444\n");
722 /* two reserved */
723 if (x[6] & 0x01)
724 printk(BIOS_SPEW, " DVI_Dual\n");
725 }
726
727 if (length > 6)
728 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
729
730 /* XXX the walk here is really ugly, and needs to be length-checked */
731 if (length > 7) {
732 int b = 0;
733
734 if (x[8] & 0x80) {
735 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
736 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
737 b += 2;
738 }
739
740 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800741 printk(BIOS_SPEW,
742 " Interlaced video latency: %d\n", x[9 + b]);
743 printk(BIOS_SPEW,
744 " Interlaced audio latency: %d\n",
745 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700746 b += 2;
747 }
748
749 if (x[8] & 0x20) {
750 int mask = 0, formats = 0;
751 int len_xx, len_3d;
752 printk(BIOS_SPEW, " Extended HDMI video details:\n");
753 if (x[9 + b] & 0x80)
754 printk(BIOS_SPEW, " 3D present\n");
755 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800756 printk(BIOS_SPEW,
757 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700758 formats = 1;
759 }
760 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800761 printk(BIOS_SPEW,
762 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700763 formats = 1;
764 mask = 1;
765 }
766 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800767 case 0x00:
768 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700769 case 0x08:
770 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
771 break;
772 case 0x10:
773 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
774 break;
775 case 0x18:
776 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
777 break;
778 }
779 len_xx = (x[10 + b] & 0xe0) >> 5;
780 len_3d = (x[10 + b] & 0x1f) >> 0;
781 b += 2;
782
783 if (len_xx) {
784 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
785 " document\n", len_xx);
786 b += len_xx;
787 }
788
789 if (len_3d) {
790 if (formats) {
791 if (x[9 + b] & 0x01)
792 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
793 if (x[10 + b] & 0x40)
794 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
795 if (x[10 + b] & 0x01)
796 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
797 b += 2;
798 }
799 if (mask) {
800 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800801 printk(BIOS_SPEW,
802 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700803 /* worst bit ordering ever */
804 for (i = 0; i < 8; i++)
805 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800806 printk(BIOS_SPEW,
807 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700808 for (i = 0; i < 8; i++)
809 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800810 printk(BIOS_SPEW,
811 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700812 printk(BIOS_SPEW, "\n");
813 b += 2;
814 }
815
816 /*
817 * XXX list of nibbles:
818 * 2D_VIC_Order_X
819 * 3D_Structure_X
820 * (optionally: 3D_Detail_X and reserved)
821 */
822 }
823
824 }
825 }
826}
827
828static void
829cea_block(struct edid *out, unsigned char *x)
830{
831 unsigned int oui;
832
833 switch ((x[0] & 0xe0) >> 5) {
834 case 0x01:
835 printk(BIOS_SPEW, " Audio data block\n");
836 cea_audio_block(x);
837 break;
838 case 0x02:
839 printk(BIOS_SPEW, " Video data block\n");
840 cea_video_block(x);
841 break;
842 case 0x03:
843 /* yes really, endianness lols */
844 oui = (x[3] << 16) + (x[2] << 8) + x[1];
Lee Leahy73402172017-03-10 15:23:24 -0800845 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
846 oui);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700847 if (oui == 0x000c03)
848 cea_hdmi_block(out, x);
849 else
850 printk(BIOS_SPEW, "\n");
851 break;
852 case 0x04:
853 printk(BIOS_SPEW, " Speaker allocation data block\n");
854 break;
855 case 0x05:
856 printk(BIOS_SPEW, " VESA DTC data block\n");
857 break;
858 case 0x07:
859 printk(BIOS_SPEW, " Extended tag: ");
860 switch (x[1]) {
861 case 0x00:
862 printk(BIOS_SPEW, "video capability data block\n");
863 break;
864 case 0x01:
865 printk(BIOS_SPEW, "vendor-specific video data block\n");
866 break;
867 case 0x02:
Lee Leahy73402172017-03-10 15:23:24 -0800868 printk(BIOS_SPEW,
869 "VESA video display device information data block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700870 break;
871 case 0x03:
872 printk(BIOS_SPEW, "VESA video data block\n");
873 break;
874 case 0x04:
875 printk(BIOS_SPEW, "HDMI video data block\n");
876 break;
877 case 0x05:
878 printk(BIOS_SPEW, "Colorimetry data block\n");
879 break;
880 case 0x10:
881 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
882 break;
883 case 0x11:
884 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
885 break;
886 case 0x12:
887 printk(BIOS_SPEW, "HDMI audio data block\n");
888 break;
889 default:
890 if (x[1] >= 6 && x[1] <= 15)
Lee Leahy73402172017-03-10 15:23:24 -0800891 printk(BIOS_SPEW,
892 "Reserved video block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700893 else if (x[1] >= 19 && x[1] <= 31)
Lee Leahy73402172017-03-10 15:23:24 -0800894 printk(BIOS_SPEW,
895 "Reserved audio block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700896 else
897 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
898 break;
899 }
900 break;
901 default:
902 {
903 int tag = (*x & 0xe0) >> 5;
904 int length = *x & 0x1f;
905 printk(BIOS_SPEW,
Lee Leahy73402172017-03-10 15:23:24 -0800906 " Unknown tag %d, length %d (raw %02x)\n",
907 tag, length, *x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700908 break;
909 }
910 }
911}
912
913static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800914parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700915{
916 int ret = 0;
917 int version = x[1];
918 int offset = x[2];
919 unsigned char *detailed;
920
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800921 if (version >= 1)
922 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700923 if (version == 1 && x[3] != 0)
924 ret = 1;
925
926 if (offset < 4)
927 break;
928
Lee Leahye20a3192017-03-09 16:21:34 -0800929 if (version < 3)
Lee Leahy73402172017-03-10 15:23:24 -0800930 printk(BIOS_SPEW,
931 "%d 8-byte timing descriptors\n",
932 (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800933 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700934 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800935 printk(BIOS_SPEW,
936 "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800937 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700938 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700939 }
940
941 if (version >= 2) {
942 if (x[3] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800943 printk(BIOS_SPEW,
944 "Underscans PC formats by default\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700945 if (x[3] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800946 printk(BIOS_SPEW,
947 "Basic audio support\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700948 if (x[3] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800949 printk(BIOS_SPEW,
950 "Supports YCbCr 4:4:4\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700951 if (x[3] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800952 printk(BIOS_SPEW,
953 "Supports YCbCr 4:2:2\n");
954 printk(BIOS_SPEW,
955 "%d native detailed modes\n",
956 x[3] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700957 }
958
Lee Leahy73402172017-03-10 15:23:24 -0800959 for (detailed = x + offset; detailed + 18 < x + 127;
960 detailed += 18)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700961 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800962 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700963 } while (0);
964
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800965 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700966 return ret;
967}
968
969/* generic extension code */
970
971static void
972extension_version(struct edid *out, unsigned char *x)
973{
974 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
975}
976
977static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800978parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700979{
980 int conformant_extension = 0;
981 printk(BIOS_SPEW, "\n");
982
Lee Leahy45fde702017-03-08 18:02:24 -0800983 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700984 case 0x02:
985 printk(BIOS_SPEW, "CEA extension block\n");
986 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800987 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700988 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800989 case 0x10:
990 printk(BIOS_SPEW, "VTB extension block\n");
991 break;
992 case 0x40:
993 printk(BIOS_SPEW, "DI extension block\n");
994 break;
995 case 0x50:
996 printk(BIOS_SPEW, "LS extension block\n");
997 break;
998 case 0x60:
999 printk(BIOS_SPEW, "DPVL extension block\n");
1000 break;
1001 case 0xF0:
1002 printk(BIOS_SPEW, "Block map\n");
1003 break;
1004 case 0xFF:
1005 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001006 default:
1007 printk(BIOS_SPEW, "Unknown extension block\n");
1008 break;
1009 }
1010
1011 printk(BIOS_SPEW, "\n");
1012
1013 return conformant_extension;
1014}
1015
1016static const struct {
1017 int x, y, refresh;
1018} established_timings[] = {
1019 /* 0x23 bit 7 - 0 */
1020 {720, 400, 70},
1021 {720, 400, 88},
1022 {640, 480, 60},
1023 {640, 480, 67},
1024 {640, 480, 72},
1025 {640, 480, 75},
1026 {800, 600, 56},
1027 {800, 600, 60},
1028 /* 0x24 bit 7 - 0 */
1029 {800, 600, 72},
1030 {800, 600, 75},
1031 {832, 624, 75},
1032 {1280, 768, 87},
1033 {1024, 768, 60},
1034 {1024, 768, 70},
1035 {1024, 768, 75},
1036 {1280, 1024, 75},
1037 /* 0x25 bit 7*/
1038 {1152, 870, 75},
1039};
1040
1041static void print_subsection(const char *name, unsigned char *edid, int start,
1042 int end)
1043{
1044 int i;
1045
1046 printk(BIOS_SPEW, "%s:", name);
1047 for (i = strlen(name); i < 15; i++)
1048 printk(BIOS_SPEW, " ");
1049 for (i = start; i <= end; i++)
1050 printk(BIOS_SPEW, " %02x", edid[i]);
1051 printk(BIOS_SPEW, "\n");
1052}
1053
1054static void dump_breakdown(unsigned char *edid)
1055{
1056 printk(BIOS_SPEW, "Extracted contents:\n");
1057 print_subsection("header", edid, 0, 7);
1058 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001059 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001060 print_subsection("basic params", edid, 20, 24);
1061 print_subsection("chroma info", edid, 25, 34);
1062 print_subsection("established", edid, 35, 37);
1063 print_subsection("standard", edid, 38, 53);
1064 print_subsection("descriptor 1", edid, 54, 71);
1065 print_subsection("descriptor 2", edid, 72, 89);
1066 print_subsection("descriptor 3", edid, 90, 107);
1067 print_subsection("descriptor 4", edid, 108, 125);
1068 print_subsection("extensions", edid, 126, 126);
1069 print_subsection("checksum", edid, 127, 127);
1070 printk(BIOS_SPEW, "\n");
1071}
1072
1073/*
David Hendrickse2054102015-08-07 18:41:37 -07001074 * Lookup table of some well-known modes that can be useful in case the
1075 * auto-detected mode is unsuitable.
1076 * ha = hdisplay; va = vdisplay;
1077 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1078 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1079 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1080 */
1081static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1082 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001083 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001084 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001085 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1086 .phsync = '-', .pvsync = '-' },
1087 [EDID_MODE_720x480_60Hz] = {
1088 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001089 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001090 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1091 .phsync = '-', .pvsync = '-' },
1092 [EDID_MODE_1280x720_60Hz] = {
1093 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001094 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001095 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1096 .phsync = '+', .pvsync = '+' },
1097 [EDID_MODE_1920x1080_60Hz] = {
1098 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001099 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001100 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1101 .phsync = '+', .pvsync = '+' },
1102};
1103
1104int set_display_mode(struct edid *edid, enum edid_modes mode)
1105{
1106 if (mode == EDID_MODE_AUTO)
1107 return 0;
1108
1109 if (edid->mode_is_supported[mode]) {
1110 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1111 edid->mode = known_modes[mode];
1112 return 0;
1113 }
1114
1115 printk(BIOS_ERR, "Requested display mode not supported.\n");
1116 return -1;
1117}
1118
1119/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001120 * Given a raw edid bloc, decode it into a form
1121 * that other parts of coreboot can use -- mainly
1122 * graphics bringup functions. The raw block is
1123 * required to be 128 bytes long, per the standard,
1124 * but we have no way of checking this minimum length.
1125 * We accept what we are given.
1126 */
1127int decode_edid(unsigned char *edid, int size, struct edid *out)
1128{
David Hendrickse2054102015-08-07 18:41:37 -07001129 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001130 struct edid_context c = {
1131 .has_valid_cvt = 1,
1132 .has_valid_dummy_block = 1,
1133 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001134 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001135 .has_valid_descriptor_pad = 1,
1136 .has_valid_range_descriptor = 1,
1137 .has_valid_max_dotclock = 1,
1138 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001139 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001140 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001141
1142 dump_breakdown(edid);
1143
David Hendricks40e89b42015-08-13 15:51:00 -07001144 memset(out, 0, sizeof(*out));
1145
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001146 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1147 printk(BIOS_SPEW, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001148 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001149 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001150
David Hendricksa3b898a2015-08-02 18:07:48 -07001151 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001152 c.manufacturer_name_well_formed = 1;
1153
David Hendricksa3b898a2015-08-02 18:07:48 -07001154 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1155 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001156 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1157
1158 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001159 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001160 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1161 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1162 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001163 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001164
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001165 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001166 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001167 if (edid[0x11] > 0x0f) {
1168 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001169 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001170 printk(BIOS_SPEW,
1171 "Made week %hhd of model year %hhd\n",
1172 edid[0x10], edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001173 extra_info.week = edid[0x10];
1174 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001175 } else {
Lee Leahy73402172017-03-10 15:23:24 -08001176 /* we know it's at least 2013, when this code
1177 * was written
1178 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001179 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001180 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001181 printk(BIOS_SPEW,
1182 "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001183 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001184 extra_info.week = edid[0x10];
1185 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001186 }
1187 }
1188 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001189 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001190
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001191 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001192 extra_info.version[0] = edid[0x12];
1193 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001194
1195 if (edid[0x12] == 1) {
1196 if (edid[0x13] > 4) {
Lee Leahy73402172017-03-10 15:23:24 -08001197 printk(BIOS_SPEW,
1198 "Claims > 1.4, assuming 1.4 conformance\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001199 edid[0x13] = 4;
1200 }
1201 switch (edid[0x13]) {
1202 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001203 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001204 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001205 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001206 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001207 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001208 default:
1209 break;
1210 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001211 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001212 }
1213
1214 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001215 if (edid[0x14] & 0x80) {
1216 int conformance_mask;
1217 analog = 0;
1218 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001219 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001220 conformance_mask = 0;
1221 if ((edid[0x14] & 0x70) == 0x00)
1222 printk(BIOS_SPEW, "Color depth is undefined\n");
1223 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001224 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001225 else
Lee Leahy73402172017-03-10 15:23:24 -08001226 printk(BIOS_SPEW,
1227 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001228 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001229 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1230 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001231 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001232
1233 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001234 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001235 printk(BIOS_SPEW,
1236 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001237 break;
1238 case 0x01:
1239 printk(BIOS_SPEW, "DVI interface\n");
1240 break;
1241 case 0x02:
1242 printk(BIOS_SPEW, "HDMI-a interface\n");
1243 break;
1244 case 0x03:
1245 printk(BIOS_SPEW, "HDMI-b interface\n");
1246 break;
1247 case 0x04:
1248 printk(BIOS_SPEW, "MDDI interface\n");
1249 break;
1250 case 0x05:
1251 printk(BIOS_SPEW, "DisplayPort interface\n");
1252 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001253 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001254 c.nonconformant_digital_display = 1;
1255 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001256 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001257 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001258 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001259 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001260 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001261 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001262 } else
1263 conformance_mask = 0x7F;
1264
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001265 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001266 c.nonconformant_digital_display = edid[0x14]
1267 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001268 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001269 } else {
1270 analog = 1;
1271 int voltage = (edid[0x14] & 0x60) >> 5;
1272 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001273 extra_info.voltage = voltage;
1274 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001275
1276 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1277 voltage == 3 ? "0.7/0.7" :
1278 voltage == 2 ? "1.0/0.4" :
1279 voltage == 1 ? "0.714/0.286" :
1280 "0.7/0.3");
1281
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001282 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001283 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001284 printk(BIOS_SPEW,
1285 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001286 else
Lee Leahy73402172017-03-10 15:23:24 -08001287 printk(BIOS_SPEW,
1288 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001289 } else if (edid[0x14] & 0x10) {
1290 /*
Lee Leahy73402172017-03-10 15:23:24 -08001291 * XXX this is just the X text. 1.3 says "if set,
1292 * display expects a blank-to-black setup or pedestal
1293 * per appropriate Signal Level Standard". Whatever
1294 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001295 */
1296 printk(BIOS_SPEW, "Configurable signal levels\n");
1297 }
1298
Lee Leahy73402172017-03-10 15:23:24 -08001299 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1300 sync & 0x08 ? "Separate " : "",
1301 sync & 0x04 ? "Composite " : "",
1302 sync & 0x02 ? "SyncOnGreen " : "",
1303 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001304 }
1305
1306
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001307 if (edid[0x15] && edid[0x16]) {
1308 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1309 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001310 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001311 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1312 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001313 printk(BIOS_SPEW,
1314 "Aspect ratio is %u.%03u (landscape)\n",
1315 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001316 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1317 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001318 printk(BIOS_SPEW,
1319 "Aspect ratio is %u.%03u (portrait)\n",
1320 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001321 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001322 } else {
1323 /* Either or both can be zero for 1.3 and before */
1324 printk(BIOS_SPEW, "Image size is variable\n");
1325 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001326
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001327 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001328 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001329 printk(BIOS_SPEW,
1330 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001331 else
1332 /* XXX Technically 1.3 doesn't say this... */
1333 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001334 } else
1335 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001336 printk(BIOS_SPEW, "Check DPMS levels\n");
1337 if (edid[0x18] & 0xE0) {
1338 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001339 if (edid[0x18] & 0x80)
1340 printk(BIOS_SPEW, " Standby");
1341 if (edid[0x18] & 0x40)
1342 printk(BIOS_SPEW, " Suspend");
1343 if (edid[0x18] & 0x20)
1344 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001345 printk(BIOS_SPEW, "\n");
1346 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001347
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001348 /* FIXME: this is from 1.4 spec, check earlier */
1349 if (analog) {
1350 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001351 case 0x00:
1352 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1353 break;
1354 case 0x08:
1355 printk(BIOS_SPEW, "RGB color display\n");
1356 break;
1357 case 0x10:
1358 printk(BIOS_SPEW, "Non-RGB color display\n");
1359 break;
1360 case 0x18:
1361 printk(BIOS_SPEW, "Undefined display color type\n");
1362 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001363 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001364 } else {
1365 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1366 if (edid[0x18] & 0x10)
1367 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1368 if (edid[0x18] & 0x08)
1369 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1370 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001371 }
1372
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001373 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001374 printk(BIOS_SPEW,
1375 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001376 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001377 printk(BIOS_SPEW,
1378 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001379 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001380 }
1381 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001382 printk(BIOS_SPEW,
1383 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384
1385 /* XXX color section */
1386
1387 printk(BIOS_SPEW, "Established timings supported:\n");
1388 /* it's not yet clear we want all this stuff in the edid struct.
1389 * Let's wait.
1390 */
1391 for (i = 0; i < 17; i++) {
1392 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001393 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1394 established_timings[i].x,
1395 established_timings[i].y,
1396 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001397
Douglas Anderson9fa07602015-10-28 10:19:52 -07001398 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001399 if (known_modes[j].ha ==
1400 established_timings[i].x
1401 && known_modes[j].va ==
1402 established_timings[i].y
1403 && known_modes[j].refresh ==
1404 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001405 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001406 }
David Hendrickse2054102015-08-07 18:41:37 -07001407 }
1408
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001409 }
1410
1411 printk(BIOS_SPEW, "Standard timings supported:\n");
1412 for (i = 0; i < 8; i++) {
1413 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1414 unsigned int x, y = 0, refresh;
1415
1416 if (b1 == 0x01 && b2 == 0x01)
1417 continue;
1418
1419 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001420 printk(BIOS_SPEW,
1421 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001422 continue;
1423 }
1424 x = (b1 + 31) * 8;
1425 switch ((b2 >> 6) & 0x3) {
1426 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001427 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001428 y = x * 10 / 16;
1429 else
1430 y = x;
1431 break;
1432 case 0x01:
1433 y = x * 3 / 4;
1434 break;
1435 case 0x02:
1436 y = x * 4 / 5;
1437 break;
1438 case 0x03:
1439 y = x * 9 / 16;
1440 break;
1441 }
1442 refresh = 60 + (b2 & 0x3f);
1443
1444 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001445 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1446 if (known_modes[j].ha == x && known_modes[j].va == y &&
1447 known_modes[j].refresh == refresh)
1448 out->mode_is_supported[j] = 1;
1449 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001450 }
1451
1452 /* detailed timings */
1453 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001454 for (i = 0; i < 4; i++) {
1455 c.has_valid_detailed_blocks &= detailed_block(
1456 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001457 if (i == 0 && c.has_preferred_timing
1458 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001459 /* not really accurate... */
1460 c.has_preferred_timing = 0;
1461 }
1462 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001463
1464 /* check this, 1.4 verification guide says otherwise */
1465 if (edid[0x7e]) {
1466 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1467 /* 2 is impossible because of the block map */
1468 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001469 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001470 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001471 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001472 }
1473
1474 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001475 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001476
1477 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1478 * the extension parsing loop below. Since v2.0 was quickly deprecated
1479 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1480 * that case now and can fix it when we need to use a real 2.0 panel.
1481 */
Lee Leahy45fde702017-03-08 18:02:24 -08001482 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001483 c.nonconformant_extension +=
1484 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001485
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001486 if (c.claims_one_point_four) {
1487 if (c.nonconformant_digital_display ||
1488 !c.has_valid_string_termination ||
1489 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001490 !c.has_preferred_timing) {
1491 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001492 printk(BIOS_ERR,
1493 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001494 }
1495
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001496 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001497 printk(BIOS_ERR,
1498 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001499 c.nonconformant_digital_display);
1500 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001501 printk(BIOS_ERR,
1502 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001503 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001504 printk(BIOS_ERR,
1505 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001506 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001507 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001508 } else if (c.claims_one_point_three) {
1509 if (c.nonconformant_digital_display ||
1510 !c.has_valid_string_termination ||
1511 !c.has_valid_descriptor_pad ||
1512 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001513 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001514 }
1515 /**
1516 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1517 * has_range_descriptor are both required. These fields are
1518 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1519 * don't have them. As a workaround, we only print warning
1520 * messages.
1521 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001522 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001523 printk(BIOS_ERR,
1524 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001525 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001526 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1527 "fully conform to EDID 1.3.\n");
1528
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001529 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001530 printk(BIOS_ERR,
1531 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001532 c.nonconformant_digital_display);
1533 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001534 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001535 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001536 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001537 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001538 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001539 /* Might be more than just 1.3 */
1540 if (!c.has_valid_descriptor_pad)
1541 printk(BIOS_ERR,
1542 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001543 if (!c.has_valid_string_termination) /* Likewise */
Lee Leahy73402172017-03-10 15:23:24 -08001544 printk(BIOS_ERR,
1545 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001546 } else if (c.claims_one_point_two) {
1547 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001548 !c.has_valid_string_termination) {
1549 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001550 printk(BIOS_ERR,
1551 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001552 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001553 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001554 printk(BIOS_ERR,
1555 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001556 c.nonconformant_digital_display);
1557 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001558 printk(BIOS_ERR,
1559 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001560 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001561 if (c.seen_non_detailed_descriptor) {
1562 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001563 printk(BIOS_ERR,
1564 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001565 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001566 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001567 printk(BIOS_ERR,
1568 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001569 }
1570
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001571 if (c.nonconformant_extension ||
1572 !c.has_valid_checksum ||
1573 !c.has_valid_cvt ||
1574 !c.has_valid_year ||
1575 !c.has_valid_week ||
1576 !c.has_valid_detailed_blocks ||
1577 !c.has_valid_dummy_block ||
1578 !c.has_valid_extension_count ||
1579 !c.has_valid_descriptor_ordering ||
1580 !c.has_valid_range_descriptor ||
1581 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001582 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001583 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001584 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001585 printk(BIOS_ERR,
1586 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001587 c.nonconformant_extension);
1588 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001589 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001590 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001591 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001592 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001593 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001594 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001595 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001596 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001597 printk(BIOS_ERR,
1598 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001599 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001600 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001601 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001602 printk(BIOS_ERR,
1603 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001604 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001605 printk(BIOS_ERR,
1606 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001607 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001608 printk(BIOS_ERR,
1609 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001610 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001611 printk(BIOS_ERR,
1612 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001613 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001614 printk(BIOS_ERR,
1615 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001616 }
1617
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001618 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001619 printk(BIOS_ERR,
1620 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001621 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001622 printk(BIOS_ERR,
1623 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001624 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001625}
1626
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001627/*
1628 * Notes on panel extensions: (TODO, implement me in the code)
1629 *
1630 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1631 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1632 * 0x6c: 00 00 00 0e 00
1633 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1634 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1635 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1636 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1637 * bit 4: DE polarity (0 high active 1 low active)
1638 * bit 3-0: interface (0000 LVDS TFT
1639 * 0001 mono STN 4/8bit
1640 * 0010 color STN 8/16 bit
1641 * 0011 18 bit tft
1642 * 0100 24 bit tft
1643 * 0101 tmds
1644 * else reserved)
1645 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1646 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1647 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1648 * else time in 10ms (10ms to 150ms))
1649 * bit 3-0: total poweron seq delay (as above)
1650 * 0x75: contrast power on/off seq delay, same as 0x74
1651 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1652 * bit 6: backlight enabled at boot (0 on 1 off)
1653 * bit 5-0: backlight brightness control steps (0..63)
1654 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1655 * 0x78 - 0x7c: reserved
1656 * 0x7d: bit 7-4: EPI descriptor major version (1)
1657 * bit 3-0: EPI descriptor minor version (0)
1658 *
1659 * ----
1660 *
1661 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1662 *
1663 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1664 *
1665 * detailed descriptor 3:
1666 * 0x5a - 0x5e: 00 00 00 fe 00
1667 * 0x5f - 0x63: PC maker part number
1668 * 0x64: LCD supplier revision #
1669 * 0x65 - 0x6b: manufacturer part number
1670 *
1671 * detailed descriptor 4:
1672 * 0x6c - 0x70: 00 00 00 fe 00
1673 * 0x71 - 0x78: smbus nits values (whut)
1674 * 0x79: number of lvds channels (1 or 2)
1675 * 0x7A: panel self test (1 if present)
1676 * and then dummy terminator
1677 *
1678 * SPWG also says something strange about the LSB of detailed descriptor 1:
1679 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1680 */
Julius Werner69112192016-03-14 17:29:55 -07001681
1682/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001683void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1684 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001685{
1686 /* Caller should pass a supported value, everything else is BUG(). */
1687 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Julius Werner2b6db972016-04-06 12:50:40 -07001688 row_byte_alignment = max(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001689
1690 edid->framebuffer_bits_per_pixel = fb_bpp;
1691 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Julius Werner2b6db972016-04-06 12:50:40 -07001692 div_round_up(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001693 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1694 edid->y_resolution = edid->mode.va;
1695}
1696
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001697/*
1698 * Take an edid, and create a framebuffer. Set vbe_valid to 1.
1699 */
1700
Nico Huber994a4a12016-06-16 05:57:49 +02001701void set_vbe_mode_info_valid(const struct edid *edid, uintptr_t fb_addr)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001702{
1703 edid_fb.physical_address = fb_addr;
Ronald G. Minnich4c5b1612013-06-28 14:33:30 -07001704 edid_fb.x_resolution = edid->x_resolution;
1705 edid_fb.y_resolution = edid->y_resolution;
1706 edid_fb.bytes_per_line = edid->bytes_per_line;
Lee Leahy73402172017-03-10 15:23:24 -08001707 /* In the case of (e.g.) 24 framebuffer bits per pixel, the convention
1708 * nowadays seems to be to round it up to the nearest reasonable
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001709 * boundary, because otherwise the byte-packing is hideous.
1710 * So, for example, in RGB with no alpha, the bytes are still
1711 * packed into 32-bit words, the so-called 32bpp-no-alpha mode.
1712 * Or, in 5:6:5 mode, the bytes are also packed into 32-bit words,
1713 * and in 4:4:4 mode, they are packed into 16-bit words.
1714 * Good call on the hardware guys part.
1715 * It's not clear we're covering all cases here, but
1716 * I'm not sure with grahpics you ever can.
1717 */
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001718 edid_fb.bits_per_pixel = edid->framebuffer_bits_per_pixel;
Patrick Georgi8b12a282014-12-06 17:35:25 +01001719 edid_fb.reserved_mask_pos = 0;
1720 edid_fb.reserved_mask_size = 0;
Lee Leahy35af5c42017-03-09 17:35:28 -08001721 switch (edid->framebuffer_bits_per_pixel) {
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001722 case 32:
1723 case 24:
1724 /* packed into 4-byte words */
Patrick Georgi8b12a282014-12-06 17:35:25 +01001725 edid_fb.reserved_mask_pos = 24;
1726 edid_fb.reserved_mask_size = 8;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001727 edid_fb.red_mask_pos = 16;
1728 edid_fb.red_mask_size = 8;
1729 edid_fb.green_mask_pos = 8;
1730 edid_fb.green_mask_size = 8;
1731 edid_fb.blue_mask_pos = 0;
1732 edid_fb.blue_mask_size = 8;
1733 break;
1734 case 16:
1735 /* packed into 2-byte words */
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001736 edid_fb.red_mask_pos = 11;
1737 edid_fb.red_mask_size = 5;
1738 edid_fb.green_mask_pos = 5;
1739 edid_fb.green_mask_size = 6;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001740 edid_fb.blue_mask_pos = 0;
Ronald G. Minnichc0d5eb22013-08-01 11:38:05 -07001741 edid_fb.blue_mask_size = 5;
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001742 break;
1743 default:
1744 printk(BIOS_SPEW, "%s: unsupported BPP %d\n", __func__,
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001745 edid->framebuffer_bits_per_pixel);
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001746 return;
1747 }
1748
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001749 vbe_valid = 1;
1750}
1751
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001752#if IS_ENABLED(CONFIG_NATIVE_VGA_INIT_USE_EDID)
Ronald G. Minnichb2893a012013-04-23 10:59:11 -07001753int vbe_mode_info_valid(void)
1754{
1755 return vbe_valid;
1756}
1757
1758void fill_lb_framebuffer(struct lb_framebuffer *framebuffer)
1759{
1760 *framebuffer = edid_fb;
1761}
Timothy Pearsonc522fc82015-02-02 18:25:34 -06001762#endif