blob: 3b81b5c30ab4fb5f5be1ad86be2037e7916b347c [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>
Joel Kitching393c71c2019-06-16 16:09:42 +080034#include <ctype.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
David Hendricksa3b898a2015-08-02 18:07:48 -070097static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070098{
David Hendricksa3b898a2015-08-02 18:07:48 -070099 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
Lee Leahy73402172017-03-10 15:23:24 -0800100 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5)
101 + '@';
David Hendricksa3b898a2015-08-02 18:07:48 -0700102 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
103 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700104
David Hendricksa3b898a2015-08-02 18:07:48 -0700105 if (isupper(extra_info.manuf_name[0]) &&
106 isupper(extra_info.manuf_name[1]) &&
107 isupper(extra_info.manuf_name[2]))
108 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700109
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800110 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700111}
112
113static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700114detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700115{
116 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -0800117 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700118 int width = 0, height = 0;
119 int valid = 1;
120 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
121
122 if (!first && !memcmp(x, empty, 3))
123 return valid;
124
125 height = x[0];
126 height |= (x[1] & 0xf0) << 4;
127 height++;
128 height *= 2;
129
130 switch (x[1] & 0x0c) {
131 case 0x00:
132 width = (height * 4) / 3; break;
133 case 0x04:
134 width = (height * 16) / 9; break;
135 case 0x08:
136 width = (height * 16) / 10; break;
137 case 0x0c:
138 width = (height * 15) / 9; break;
139 }
140
141 if (x[1] & 0x03)
142 valid = 0;
143 if (x[2] & 0x80)
144 valid = 0;
145 if (!(x[2] & 0x1f))
146 valid = 0;
147
148 fifty = (x[2] & 0x10);
149 sixty = (x[2] & 0x08);
150 seventyfive = (x[2] & 0x04);
151 eightyfive = (x[2] & 0x02);
152 reduced = (x[2] & 0x01);
153
154 if (!valid) {
155 printk(BIOS_SPEW, " (broken)\n");
156 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800157 printk(BIOS_SPEW,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200158 " %dx%d @ (%s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700159 width, height,
160 fifty ? "50 " : "",
161 sixty ? "60 " : "",
162 seventyfive ? "75 " : "",
163 eightyfive ? "85 " : "",
164 reduced ? "60RB " : "",
165 names[(x[2] & 0x60) >> 5],
166 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
167 }
168
169 return valid;
170}
171
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800172/* extract a CP437 string from a detailed subblock, checking for termination (if
173 * less than len of bytes) with LF and padded with SP.
174 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700175static char *
176extract_string(unsigned char *x, int *valid_termination, int len)
177{
Patrick Georgid840e2b2018-09-18 18:01:02 +0200178 static char ret[EDID_ASCII_STRING_LENGTH + 1];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700179 int i, seen_newline = 0;
180
181 memset(ret, 0, sizeof(ret));
182
Patrick Georgid840e2b2018-09-18 18:01:02 +0200183 for (i = 0; i < min(len, EDID_ASCII_STRING_LENGTH); i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800184 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700185 if (x[i] != 0x20) {
186 *valid_termination = 0;
187 return ret;
188 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800189 } else if (x[i] == 0x0a) {
190 seen_newline = 1;
191 } else {
192 /* normal characters */
193 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700194 }
195 }
196
197 return ret;
198}
199
200/* 1 means valid data */
201static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700202detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800203 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700204{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700205 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700206 int i;
Angel Ponscc335c72018-10-02 11:58:28 +0200207
208 if (console_log_level(BIOS_SPEW)) {
209 printk(BIOS_SPEW, "Hex of detail: ");
210 for (i = 0; i < 18; i++)
211 printk(BIOS_SPEW, "%02x", x[i]);
212 printk(BIOS_SPEW, "\n");
213 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700214
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700215 /* Result might already have some valid fields like mode_is_supported */
216 *out = *result_edid;
217
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700218 if (x[0] == 0 && x[1] == 0) {
219 /* Monitor descriptor block, not detailed timing descriptor. */
220 if (x[2] != 0) {
221 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800222 printk(BIOS_SPEW,
223 "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700224 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800225 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700226 }
227 if (x[3] != 0xfd && x[4] != 0x00) {
228 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800229 printk(BIOS_SPEW,
230 "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700231 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800232 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700233 }
234
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800235 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700236 if (x[3] <= 0xF) {
237 /*
Lee Leahy73402172017-03-10 15:23:24 -0800238 * in principle we can decode these, if we know what
239 * they are.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700240 * 0x0f seems to be common in laptop panels.
241 * 0x0e is used by EPI: http://www.epi-standard.org/
242 */
Lee Leahy73402172017-03-10 15:23:24 -0800243 printk(BIOS_SPEW,
244 "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800245 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700246 }
247 switch (x[3]) {
248 case 0x10:
249 printk(BIOS_SPEW, "Dummy block\n");
250 for (i = 5; i < 18; i++)
251 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800252 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800253 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700254 case 0xF7:
255 /* TODO */
256 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800257 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700258 case 0xF8:
259 {
260 int valid_cvt = 1; /* just this block */
261 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
262 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800263 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700264 return 0;
265 }
266 for (i = 0; i < 4; i++)
Lee Leahy73402172017-03-10 15:23:24 -0800267 valid_cvt &= detailed_cvt_descriptor(x + 6
268 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800269 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800270 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700271 }
272 case 0xF9:
273 /* TODO */
274 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800275 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700276 case 0xFA:
277 /* TODO */
278 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800279 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700280 case 0xFB:
281 /* TODO */
282 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800283 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700284 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800285 printk(BIOS_SPEW, "Monitor name: %s\n",
286 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800287 &c->has_valid_string_termination,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200288 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800289 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700290 case 0xFD:
291 {
292 int h_max_offset = 0, h_min_offset = 0;
293 int v_max_offset = 0, v_min_offset = 0;
294 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800295 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700296 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700297 /*
298 * XXX todo: implement feature flags, vtd blocks
Lee Leahy73402172017-03-10 15:23:24 -0800299 * XXX check: ranges are well-formed; block termination
300 * if no vtd
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700301 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800302 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700303 if (x[4] & 0x02) {
304 v_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800305 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700306 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700307 }
308 if (x[4] & 0x04) {
309 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800310 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700311 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700312 }
313 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800314 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700315 }
316
317 /*
318 * despite the values, this is not a bitfield.
319 */
320 switch (x[10]) {
321 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700322 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700323 break;
324 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700325 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800326 if (!c->claims_one_point_four)
327 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700328 break;
329 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700330 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700331 break;
332 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700333 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700334 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800335 if (!c->claims_one_point_four)
336 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700337 break;
338 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800339 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700340 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700341 break;
342 }
343
344 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800345 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700346 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800347 c->has_valid_range_descriptor = 0;
Lee Leahy73402172017-03-10 15:23:24 -0800348 printk(BIOS_SPEW,
349 "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700350 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700351 x[5] + v_min_offset, x[6] + v_max_offset,
352 x[7] + h_min_offset, x[8] + h_max_offset);
353 if (x[9])
Lee Leahy73402172017-03-10 15:23:24 -0800354 printk(BIOS_SPEW,
355 ", max dotclock %dMHz\n", x[9] * 10);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700356 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800357 if (c->claims_one_point_four)
358 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700359 printk(BIOS_SPEW, "\n");
360 }
361
362 if (is_cvt) {
363 int max_h_pixels = 0;
364
Lee Leahy73402172017-03-10 15:23:24 -0800365 printk(BIOS_SPEW, "CVT version %d.%d\n",
366 x[11] & 0xf0 >> 4, x[11] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700367
368 if (x[12] & 0xfc) {
369 int raw_offset = (x[12] & 0xfc) >> 2;
Lee Leahy73402172017-03-10 15:23:24 -0800370 printk(BIOS_SPEW,
371 "Real max dotclock: %dKHz\n",
372 (x[9] * 10000)
373 - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700374 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800375 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700376 }
377
378 max_h_pixels = x[12] & 0x03;
379 max_h_pixels <<= 8;
380 max_h_pixels |= x[13];
381 max_h_pixels *= 8;
382 if (max_h_pixels)
Lee Leahy73402172017-03-10 15:23:24 -0800383 printk(BIOS_SPEW,
384 "Max active pixels per line: %d\n",
385 max_h_pixels);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700386
Lee Leahy73402172017-03-10 15:23:24 -0800387 printk(BIOS_SPEW,
388 "Supported aspect ratios: %s %s %s %s %s\n",
389 x[14] & 0x80 ? "4:3" : "",
390 x[14] & 0x40 ? "16:9" : "",
391 x[14] & 0x20 ? "16:10" : "",
392 x[14] & 0x10 ? "5:4" : "",
393 x[14] & 0x08 ? "15:9" : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700394 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800395 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700396
397 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800398 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800399 case 0x00:
400 printk(BIOS_SPEW, "4:3");
401 break;
402 case 0x01:
403 printk(BIOS_SPEW, "16:9");
404 break;
405 case 0x02:
406 printk(BIOS_SPEW, "16:10");
407 break;
408 case 0x03:
409 printk(BIOS_SPEW, "5:4");
410 break;
411 case 0x04:
412 printk(BIOS_SPEW, "15:9");
413 break;
414 default:
415 printk(BIOS_SPEW, "(broken)");
416 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700417 }
418 printk(BIOS_SPEW, "\n");
419
420 if (x[15] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -0800421 printk(BIOS_SPEW,
422 "Supports CVT standard blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700423 if (x[15] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800424 printk(BIOS_SPEW,
425 "Supports CVT reduced blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700426
427 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800428 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700429
430 if (x[16] & 0xf0) {
Lee Leahy73402172017-03-10 15:23:24 -0800431 printk(BIOS_SPEW,
432 "Supported display scaling:\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700433 if (x[16] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800434 printk(BIOS_SPEW,
435 " Horizontal shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700436 if (x[16] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800437 printk(BIOS_SPEW,
438 " Horizontal stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700439 if (x[16] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800440 printk(BIOS_SPEW,
441 " Vertical shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700442 if (x[16] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800443 printk(BIOS_SPEW,
444 " Vertical stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700445 }
446
447 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800448 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700449
450 if (x[17])
Lee Leahy73402172017-03-10 15:23:24 -0800451 printk(BIOS_SPEW,
452 "Preferred vertical refresh: %d Hz\n",
453 x[17]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700454 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800455 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700456 }
457
458 /*
Lee Leahy73402172017-03-10 15:23:24 -0800459 * Slightly weird to return a global, but I've never
460 * seen any EDID block wth two range descriptors, so
461 * it's harmless.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700462 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800463 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700464 }
465 case 0xFE:
466 /*
Lee Leahy73402172017-03-10 15:23:24 -0800467 * TODO: Two of these in a row, in the third and fourth
468 * slots, seems to be specified by SPWG:
469 * http://www.spwg.org/
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700470 */
Arthur Heymansdbe81612017-04-29 14:00:47 +0200471 strcpy(result_edid->ascii_string, extract_string(x + 5,
472 &c->has_valid_string_termination,
473 EDID_ASCII_STRING_LENGTH));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700474 printk(BIOS_SPEW, "ASCII string: %s\n",
Arthur Heymansdbe81612017-04-29 14:00:47 +0200475 result_edid->ascii_string);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800476 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700477 case 0xFF:
478 printk(BIOS_SPEW, "Serial number: %s\n",
Lee Leahy73402172017-03-10 15:23:24 -0800479 extract_string(x + 5,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200480 &c->has_valid_string_termination,
481 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800482 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700483 default:
Lee Leahy73402172017-03-10 15:23:24 -0800484 printk(BIOS_SPEW,
485 "Unknown monitor description type %d\n",
486 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700487 return 0;
488 }
489 }
490
Lee Leahy2f919ec2017-03-08 17:37:06 -0800491 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800492 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700493
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700494 /* Edid contains pixel clock in terms of 10KHz */
495 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
496 /*
497 LVDS supports following pixel clocks
498 25000...112000 kHz: single channel
499 80000...224000 kHz: dual channel
500 There is some overlap in theoretically supported
501 pixel clock between single-channel and dual-channel.
502 In practice with current panels all panels
503 <= 75200 kHz: single channel
504 >= 97750 kHz: dual channel
505 We have no samples between those values, so put a
506 threshold at 95000 kHz. If we get anything over
507 95000 kHz with single channel, we can make this
508 more sofisticated but it's currently not needed.
509 */
510 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
511 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
512 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
513 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
514 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
515 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
516 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
517 out->mode.hborder = x[15];
518 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
519 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
520 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
521 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
522 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700523
Julius Werner69112192016-03-14 17:29:55 -0700524 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700525 * Chipsets that want something else will need to override this with
526 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
527 * heuristic, assume that X86 systems require a 64-byte row alignment
528 * (since that seems to be true for most Intel chipsets). */
Julius Wernercd49cce2019-03-05 16:53:33 -0800529 if (CONFIG(ARCH_X86))
Julius Werner2b6db972016-04-06 12:50:40 -0700530 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
531 else
532 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700533
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700534 switch ((x[17] & 0x18) >> 3) {
535 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700536 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700537 break;
538 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700539 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700540 break;
541 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700542 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700543 break;
544 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700545 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700546 break;
547 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700548 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
549 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700550 switch (x[17] & 0x61) {
551 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700552 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700553 break;
554 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700555 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700556 break;
557 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700558 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700559 break;
560 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700561 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700562 break;
563 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700564 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700565 break;
566 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700567 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700568 break;
569 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700570 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700571 break;
572 }
573
Lee Leahy73402172017-03-10 15:23:24 -0800574 printk(BIOS_SPEW,
575 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700576 " %04x %04x %04x %04x hborder %x\n"
577 " %04x %04x %04x %04x vborder %x\n"
578 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700579 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700580 extra_info.x_mm,
581 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700582 out->mode.ha, out->mode.ha + out->mode.hso,
583 out->mode.ha + out->mode.hso + out->mode.hspw,
584 out->mode.ha + out->mode.hbl, out->mode.hborder,
585 out->mode.va, out->mode.va + out->mode.vso,
586 out->mode.va + out->mode.vso + out->mode.vspw,
587 out->mode.va + out->mode.vbl, out->mode.vborder,
588 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800589 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700590 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700591
Lee Leahy35af5c42017-03-09 17:35:28 -0800592 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700593 printk(BIOS_SPEW, "Did detailed timing\n");
594 c->did_detailed_timing = 1;
595 *result_edid = *out;
596 }
597
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700598 return 1;
599}
600
601static int
602do_checksum(unsigned char *x)
603{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800604 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600605 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700606 {
607 unsigned char sum = 0;
608 int i;
609 for (i = 0; i < 128; i++)
610 sum += x[i];
611 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800612 printk(BIOS_SPEW, " (should be 0x%hhx)",
613 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700614 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800615 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700616 printk(BIOS_SPEW, " (valid)");
617 }
618 }
619 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800620 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700621}
622
623/* CEA extension */
624
625static const char *
626audio_format(unsigned char x)
627{
628 switch (x) {
629 case 0: return "RESERVED";
630 case 1: return "Linear PCM";
631 case 2: return "AC-3";
632 case 3: return "MPEG 1 (Layers 1 & 2)";
633 case 4: return "MPEG 1 Layer 3 (MP3)";
634 case 5: return "MPEG2 (multichannel)";
635 case 6: return "AAC";
636 case 7: return "DTS";
637 case 8: return "ATRAC";
638 case 9: return "One Bit Audio";
639 case 10: return "Dolby Digital+";
640 case 11: return "DTS-HD";
641 case 12: return "MAT (MLP)";
642 case 13: return "DST";
643 case 14: return "WMA Pro";
644 case 15: return "RESERVED";
645 }
646 return "BROKEN"; /* can't happen */
647}
648
649static void
650cea_audio_block(unsigned char *x)
651{
652 int i, format;
653 int length = x[0] & 0x1f;
654
655 if (length % 3) {
656 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
657 /* XXX non-conformant */
658 return;
659 }
660
661 for (i = 1; i < length; i += 3) {
662 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800663 printk(BIOS_SPEW, " %s, max channels %d\n",
664 audio_format(format), x[i] & 0x07);
665 printk(BIOS_SPEW,
666 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700667 (x[i+1] & 0x40) ? " 192" : "",
668 (x[i+1] & 0x20) ? " 176.4" : "",
669 (x[i+1] & 0x10) ? " 96" : "",
670 (x[i+1] & 0x08) ? " 88.2" : "",
671 (x[i+1] & 0x04) ? " 48" : "",
672 (x[i+1] & 0x02) ? " 44.1" : "",
673 (x[i+1] & 0x01) ? " 32" : "");
674 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800675 printk(BIOS_SPEW,
676 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700677 (x[2] & 0x04) ? " 24" : "",
678 (x[2] & 0x02) ? " 20" : "",
679 (x[2] & 0x01) ? " 16" : "");
680 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800681 printk(BIOS_SPEW,
682 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700683 }
684 }
685}
686
687static void
688cea_video_block(unsigned char *x)
689{
690 int i;
691 int length = x[0] & 0x1f;
692
693 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800694 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700695 x[i] & 0x80 ? "(native)" : "");
696}
697
698static void
699cea_hdmi_block(struct edid *out, unsigned char *x)
700{
701 int length = x[0] & 0x1f;
702
Yakir Yang85810cc2015-10-27 16:17:13 +0800703 out->hdmi_monitor_detected = 1;
704
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700705 printk(BIOS_SPEW, " (HDMI)\n");
706 printk(BIOS_SPEW,
707 " Source physical address %d.%d.%d.%d\n",
708 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
709
710 if (length > 5) {
711 if (x[6] & 0x80)
712 printk(BIOS_SPEW, " Supports_AI\n");
713 if (x[6] & 0x40)
714 printk(BIOS_SPEW, " DC_48bit\n");
715 if (x[6] & 0x20)
716 printk(BIOS_SPEW, " DC_36bit\n");
717 if (x[6] & 0x10)
718 printk(BIOS_SPEW, " DC_30bit\n");
719 if (x[6] & 0x08)
720 printk(BIOS_SPEW, " DC_Y444\n");
721 /* two reserved */
722 if (x[6] & 0x01)
723 printk(BIOS_SPEW, " DVI_Dual\n");
724 }
725
726 if (length > 6)
727 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
728
729 /* XXX the walk here is really ugly, and needs to be length-checked */
730 if (length > 7) {
731 int b = 0;
732
733 if (x[8] & 0x80) {
734 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
735 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
736 b += 2;
737 }
738
739 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800740 printk(BIOS_SPEW,
741 " Interlaced video latency: %d\n", x[9 + b]);
742 printk(BIOS_SPEW,
743 " Interlaced audio latency: %d\n",
744 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700745 b += 2;
746 }
747
748 if (x[8] & 0x20) {
749 int mask = 0, formats = 0;
750 int len_xx, len_3d;
751 printk(BIOS_SPEW, " Extended HDMI video details:\n");
752 if (x[9 + b] & 0x80)
753 printk(BIOS_SPEW, " 3D present\n");
754 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800755 printk(BIOS_SPEW,
756 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700757 formats = 1;
758 }
759 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800760 printk(BIOS_SPEW,
761 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700762 formats = 1;
763 mask = 1;
764 }
765 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800766 case 0x00:
767 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700768 case 0x08:
769 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
770 break;
771 case 0x10:
772 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
773 break;
774 case 0x18:
775 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
776 break;
777 }
778 len_xx = (x[10 + b] & 0xe0) >> 5;
779 len_3d = (x[10 + b] & 0x1f) >> 0;
780 b += 2;
781
782 if (len_xx) {
783 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
784 " document\n", len_xx);
785 b += len_xx;
786 }
787
788 if (len_3d) {
789 if (formats) {
790 if (x[9 + b] & 0x01)
791 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
792 if (x[10 + b] & 0x40)
793 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
794 if (x[10 + b] & 0x01)
795 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
796 b += 2;
797 }
798 if (mask) {
799 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800800 printk(BIOS_SPEW,
801 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700802 /* worst bit ordering ever */
803 for (i = 0; i < 8; i++)
804 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800805 printk(BIOS_SPEW,
806 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700807 for (i = 0; i < 8; i++)
808 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800809 printk(BIOS_SPEW,
810 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700811 printk(BIOS_SPEW, "\n");
812 b += 2;
813 }
814
815 /*
816 * XXX list of nibbles:
817 * 2D_VIC_Order_X
818 * 3D_Structure_X
819 * (optionally: 3D_Detail_X and reserved)
820 */
821 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700822 }
Richard Spiegel2fdbe0c2018-08-07 08:43:22 -0700823 /* Tell static analysis we know index b is left unused. */
824 (void)b;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700825 }
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");
Jacob Garbere447aec2019-03-27 17:23:42 -06001006 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001007 default:
1008 printk(BIOS_SPEW, "Unknown extension block\n");
1009 break;
1010 }
1011
1012 printk(BIOS_SPEW, "\n");
1013
1014 return conformant_extension;
1015}
1016
1017static const struct {
1018 int x, y, refresh;
1019} established_timings[] = {
1020 /* 0x23 bit 7 - 0 */
1021 {720, 400, 70},
1022 {720, 400, 88},
1023 {640, 480, 60},
1024 {640, 480, 67},
1025 {640, 480, 72},
1026 {640, 480, 75},
1027 {800, 600, 56},
1028 {800, 600, 60},
1029 /* 0x24 bit 7 - 0 */
1030 {800, 600, 72},
1031 {800, 600, 75},
1032 {832, 624, 75},
1033 {1280, 768, 87},
1034 {1024, 768, 60},
1035 {1024, 768, 70},
1036 {1024, 768, 75},
1037 {1280, 1024, 75},
1038 /* 0x25 bit 7*/
1039 {1152, 870, 75},
1040};
1041
1042static void print_subsection(const char *name, unsigned char *edid, int start,
1043 int end)
1044{
1045 int i;
1046
1047 printk(BIOS_SPEW, "%s:", name);
1048 for (i = strlen(name); i < 15; i++)
1049 printk(BIOS_SPEW, " ");
1050 for (i = start; i <= end; i++)
1051 printk(BIOS_SPEW, " %02x", edid[i]);
1052 printk(BIOS_SPEW, "\n");
1053}
1054
1055static void dump_breakdown(unsigned char *edid)
1056{
1057 printk(BIOS_SPEW, "Extracted contents:\n");
1058 print_subsection("header", edid, 0, 7);
1059 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001060 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001061 print_subsection("basic params", edid, 20, 24);
1062 print_subsection("chroma info", edid, 25, 34);
1063 print_subsection("established", edid, 35, 37);
1064 print_subsection("standard", edid, 38, 53);
1065 print_subsection("descriptor 1", edid, 54, 71);
1066 print_subsection("descriptor 2", edid, 72, 89);
1067 print_subsection("descriptor 3", edid, 90, 107);
1068 print_subsection("descriptor 4", edid, 108, 125);
1069 print_subsection("extensions", edid, 126, 126);
1070 print_subsection("checksum", edid, 127, 127);
1071 printk(BIOS_SPEW, "\n");
1072}
1073
1074/*
David Hendrickse2054102015-08-07 18:41:37 -07001075 * Lookup table of some well-known modes that can be useful in case the
1076 * auto-detected mode is unsuitable.
1077 * ha = hdisplay; va = vdisplay;
1078 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1079 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1080 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1081 */
1082static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1083 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001084 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001085 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001086 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1087 .phsync = '-', .pvsync = '-' },
1088 [EDID_MODE_720x480_60Hz] = {
1089 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001090 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001091 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1092 .phsync = '-', .pvsync = '-' },
1093 [EDID_MODE_1280x720_60Hz] = {
1094 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001095 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001096 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1097 .phsync = '+', .pvsync = '+' },
1098 [EDID_MODE_1920x1080_60Hz] = {
1099 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001100 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001101 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1102 .phsync = '+', .pvsync = '+' },
1103};
1104
1105int set_display_mode(struct edid *edid, enum edid_modes mode)
1106{
1107 if (mode == EDID_MODE_AUTO)
1108 return 0;
1109
1110 if (edid->mode_is_supported[mode]) {
1111 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1112 edid->mode = known_modes[mode];
1113 return 0;
1114 }
1115
1116 printk(BIOS_ERR, "Requested display mode not supported.\n");
1117 return -1;
1118}
1119
1120/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001121 * Given a raw edid bloc, decode it into a form
1122 * that other parts of coreboot can use -- mainly
1123 * graphics bringup functions. The raw block is
1124 * required to be 128 bytes long, per the standard,
1125 * but we have no way of checking this minimum length.
1126 * We accept what we are given.
1127 */
1128int decode_edid(unsigned char *edid, int size, struct edid *out)
1129{
David Hendrickse2054102015-08-07 18:41:37 -07001130 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001131 struct edid_context c = {
1132 .has_valid_cvt = 1,
1133 .has_valid_dummy_block = 1,
1134 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001135 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001136 .has_valid_descriptor_pad = 1,
1137 .has_valid_range_descriptor = 1,
1138 .has_valid_max_dotclock = 1,
1139 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001140 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001141 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001142
David Hendricks40e89b42015-08-13 15:51:00 -07001143 memset(out, 0, sizeof(*out));
1144
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001145 if (!edid) {
Jacob Garber18553292019-03-27 12:02:38 -06001146 printk(BIOS_ERR, "No EDID found\n");
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001147 return EDID_ABSENT;
1148 }
1149
1150 dump_breakdown(edid);
1151
1152 if (memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
Jacob Garber18553292019-03-27 12:02:38 -06001153 printk(BIOS_ERR, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001154 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001155 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001156
David Hendricksa3b898a2015-08-02 18:07:48 -07001157 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001158 c.manufacturer_name_well_formed = 1;
1159
David Hendricksa3b898a2015-08-02 18:07:48 -07001160 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1161 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001162 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1163
1164 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001165 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001166 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1167 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1168 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001169 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001170
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001171 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001172 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001173 if (edid[0x11] > 0x0f) {
1174 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001175 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001176 printk(BIOS_SPEW,
1177 "Made week %hhd of model year %hhd\n",
1178 edid[0x10], edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001179 extra_info.week = edid[0x10];
1180 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001181 } else {
Lee Leahy73402172017-03-10 15:23:24 -08001182 /* we know it's at least 2013, when this code
1183 * was written
1184 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001185 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001186 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001187 printk(BIOS_SPEW,
1188 "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001189 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001190 extra_info.week = edid[0x10];
1191 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001192 }
1193 }
1194 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001195 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001196
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001197 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001198 extra_info.version[0] = edid[0x12];
1199 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001200
1201 if (edid[0x12] == 1) {
1202 if (edid[0x13] > 4) {
Lee Leahy73402172017-03-10 15:23:24 -08001203 printk(BIOS_SPEW,
1204 "Claims > 1.4, assuming 1.4 conformance\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001205 edid[0x13] = 4;
1206 }
1207 switch (edid[0x13]) {
1208 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001209 c.claims_one_point_four = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001210 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001211 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001212 c.claims_one_point_three = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001213 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001214 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001215 c.claims_one_point_two = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001216 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001217 default:
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001218 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001219 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001220 }
1221
1222 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001223 if (edid[0x14] & 0x80) {
1224 int conformance_mask;
1225 analog = 0;
1226 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001227 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001228 conformance_mask = 0;
1229 if ((edid[0x14] & 0x70) == 0x00)
1230 printk(BIOS_SPEW, "Color depth is undefined\n");
1231 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001232 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001233 else
Lee Leahy73402172017-03-10 15:23:24 -08001234 printk(BIOS_SPEW,
1235 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001236 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001237 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1238 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001239 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001240
1241 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001242 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001243 printk(BIOS_SPEW,
1244 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001245 break;
1246 case 0x01:
1247 printk(BIOS_SPEW, "DVI interface\n");
1248 break;
1249 case 0x02:
1250 printk(BIOS_SPEW, "HDMI-a interface\n");
1251 break;
1252 case 0x03:
1253 printk(BIOS_SPEW, "HDMI-b interface\n");
1254 break;
1255 case 0x04:
1256 printk(BIOS_SPEW, "MDDI interface\n");
1257 break;
1258 case 0x05:
1259 printk(BIOS_SPEW, "DisplayPort interface\n");
1260 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001261 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001262 c.nonconformant_digital_display = 1;
1263 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001264 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001265 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001266 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001267 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001268 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001269 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001270 } else
1271 conformance_mask = 0x7F;
1272
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001273 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001274 c.nonconformant_digital_display = edid[0x14]
1275 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001276 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001277 } else {
1278 analog = 1;
1279 int voltage = (edid[0x14] & 0x60) >> 5;
1280 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001281 extra_info.voltage = voltage;
1282 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001283
1284 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1285 voltage == 3 ? "0.7/0.7" :
1286 voltage == 2 ? "1.0/0.4" :
1287 voltage == 1 ? "0.714/0.286" :
1288 "0.7/0.3");
1289
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001290 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001291 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001292 printk(BIOS_SPEW,
1293 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001294 else
Lee Leahy73402172017-03-10 15:23:24 -08001295 printk(BIOS_SPEW,
1296 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001297 } else if (edid[0x14] & 0x10) {
1298 /*
Lee Leahy73402172017-03-10 15:23:24 -08001299 * XXX this is just the X text. 1.3 says "if set,
1300 * display expects a blank-to-black setup or pedestal
1301 * per appropriate Signal Level Standard". Whatever
1302 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001303 */
1304 printk(BIOS_SPEW, "Configurable signal levels\n");
1305 }
1306
Lee Leahy73402172017-03-10 15:23:24 -08001307 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1308 sync & 0x08 ? "Separate " : "",
1309 sync & 0x04 ? "Composite " : "",
1310 sync & 0x02 ? "SyncOnGreen " : "",
1311 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001312 }
1313
1314
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001315 if (edid[0x15] && edid[0x16]) {
1316 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1317 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001318 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001319 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1320 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001321 printk(BIOS_SPEW,
1322 "Aspect ratio is %u.%03u (landscape)\n",
1323 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001324 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1325 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001326 printk(BIOS_SPEW,
1327 "Aspect ratio is %u.%03u (portrait)\n",
1328 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001329 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001330 } else {
1331 /* Either or both can be zero for 1.3 and before */
1332 printk(BIOS_SPEW, "Image size is variable\n");
1333 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001334
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001335 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001336 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001337 printk(BIOS_SPEW,
1338 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001339 else
1340 /* XXX Technically 1.3 doesn't say this... */
1341 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001342 } else
1343 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001344 printk(BIOS_SPEW, "Check DPMS levels\n");
1345 if (edid[0x18] & 0xE0) {
1346 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001347 if (edid[0x18] & 0x80)
1348 printk(BIOS_SPEW, " Standby");
1349 if (edid[0x18] & 0x40)
1350 printk(BIOS_SPEW, " Suspend");
1351 if (edid[0x18] & 0x20)
1352 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001353 printk(BIOS_SPEW, "\n");
1354 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001355
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001356 /* FIXME: this is from 1.4 spec, check earlier */
1357 if (analog) {
1358 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001359 case 0x00:
1360 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1361 break;
1362 case 0x08:
1363 printk(BIOS_SPEW, "RGB color display\n");
1364 break;
1365 case 0x10:
1366 printk(BIOS_SPEW, "Non-RGB color display\n");
1367 break;
1368 case 0x18:
1369 printk(BIOS_SPEW, "Undefined display color type\n");
1370 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001371 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001372 } else {
1373 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1374 if (edid[0x18] & 0x10)
1375 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1376 if (edid[0x18] & 0x08)
1377 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1378 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001379 }
1380
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001381 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001382 printk(BIOS_SPEW,
1383 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001385 printk(BIOS_SPEW,
1386 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001387 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001388 }
1389 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001390 printk(BIOS_SPEW,
1391 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001392
1393 /* XXX color section */
1394
1395 printk(BIOS_SPEW, "Established timings supported:\n");
1396 /* it's not yet clear we want all this stuff in the edid struct.
1397 * Let's wait.
1398 */
1399 for (i = 0; i < 17; i++) {
1400 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001401 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1402 established_timings[i].x,
1403 established_timings[i].y,
1404 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001405
Douglas Anderson9fa07602015-10-28 10:19:52 -07001406 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001407 if (known_modes[j].ha ==
1408 established_timings[i].x
1409 && known_modes[j].va ==
1410 established_timings[i].y
1411 && known_modes[j].refresh ==
1412 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001413 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001414 }
David Hendrickse2054102015-08-07 18:41:37 -07001415 }
1416
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001417 }
1418
1419 printk(BIOS_SPEW, "Standard timings supported:\n");
1420 for (i = 0; i < 8; i++) {
1421 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1422 unsigned int x, y = 0, refresh;
1423
1424 if (b1 == 0x01 && b2 == 0x01)
1425 continue;
1426
1427 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001428 printk(BIOS_SPEW,
1429 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001430 continue;
1431 }
1432 x = (b1 + 31) * 8;
1433 switch ((b2 >> 6) & 0x3) {
1434 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001435 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001436 y = x * 10 / 16;
1437 else
1438 y = x;
1439 break;
1440 case 0x01:
1441 y = x * 3 / 4;
1442 break;
1443 case 0x02:
1444 y = x * 4 / 5;
1445 break;
1446 case 0x03:
1447 y = x * 9 / 16;
1448 break;
1449 }
1450 refresh = 60 + (b2 & 0x3f);
1451
1452 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001453 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1454 if (known_modes[j].ha == x && known_modes[j].va == y &&
1455 known_modes[j].refresh == refresh)
1456 out->mode_is_supported[j] = 1;
1457 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001458 }
1459
1460 /* detailed timings */
1461 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001462 for (i = 0; i < 4; i++) {
1463 c.has_valid_detailed_blocks &= detailed_block(
1464 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001465 if (i == 0 && c.has_preferred_timing
1466 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001467 /* not really accurate... */
1468 c.has_preferred_timing = 0;
1469 }
1470 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001471
1472 /* check this, 1.4 verification guide says otherwise */
1473 if (edid[0x7e]) {
1474 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1475 /* 2 is impossible because of the block map */
1476 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001477 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001478 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001479 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001480 }
1481
1482 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001483 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001484
1485 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1486 * the extension parsing loop below. Since v2.0 was quickly deprecated
1487 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1488 * that case now and can fix it when we need to use a real 2.0 panel.
1489 */
Lee Leahy45fde702017-03-08 18:02:24 -08001490 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001491 c.nonconformant_extension +=
1492 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001493
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001494 if (c.claims_one_point_four) {
1495 if (c.nonconformant_digital_display ||
1496 !c.has_valid_string_termination ||
1497 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001498 !c.has_preferred_timing) {
1499 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001500 printk(BIOS_ERR,
1501 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001502 }
1503
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001504 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001505 printk(BIOS_ERR,
1506 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001507 c.nonconformant_digital_display);
1508 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001509 printk(BIOS_ERR,
1510 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001511 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001512 printk(BIOS_ERR,
1513 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001514 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001515 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001516 } else if (c.claims_one_point_three) {
1517 if (c.nonconformant_digital_display ||
1518 !c.has_valid_string_termination ||
1519 !c.has_valid_descriptor_pad ||
1520 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001521 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001522 }
1523 /**
1524 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1525 * has_range_descriptor are both required. These fields are
1526 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1527 * don't have them. As a workaround, we only print warning
1528 * messages.
1529 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001530 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001531 printk(BIOS_ERR,
1532 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001533 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001534 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1535 "fully conform to EDID 1.3.\n");
1536
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001537 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001538 printk(BIOS_ERR,
1539 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001540 c.nonconformant_digital_display);
1541 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001542 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001543 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001544 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001545 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001546 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001547 /* Might be more than just 1.3 */
1548 if (!c.has_valid_descriptor_pad)
1549 printk(BIOS_ERR,
1550 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001551 if (!c.has_valid_string_termination) /* Likewise */
Lee Leahy73402172017-03-10 15:23:24 -08001552 printk(BIOS_ERR,
1553 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001554 } else if (c.claims_one_point_two) {
1555 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001556 !c.has_valid_string_termination) {
1557 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001558 printk(BIOS_ERR,
1559 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001560 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001561 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001562 printk(BIOS_ERR,
1563 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001564 c.nonconformant_digital_display);
1565 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001566 printk(BIOS_ERR,
1567 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001568 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001569 if (c.seen_non_detailed_descriptor) {
1570 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001571 printk(BIOS_ERR,
1572 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001573 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001574 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001575 printk(BIOS_ERR,
1576 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001577 }
1578
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001579 if (c.nonconformant_extension ||
1580 !c.has_valid_checksum ||
1581 !c.has_valid_cvt ||
1582 !c.has_valid_year ||
1583 !c.has_valid_week ||
1584 !c.has_valid_detailed_blocks ||
1585 !c.has_valid_dummy_block ||
1586 !c.has_valid_extension_count ||
1587 !c.has_valid_descriptor_ordering ||
1588 !c.has_valid_range_descriptor ||
1589 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001590 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001591 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001592 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001593 printk(BIOS_ERR,
1594 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001595 c.nonconformant_extension);
1596 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001597 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001598 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001599 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001600 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001601 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001602 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001603 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001604 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001605 printk(BIOS_ERR,
1606 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001607 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001608 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001609 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001610 printk(BIOS_ERR,
1611 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001612 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001613 printk(BIOS_ERR,
1614 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001615 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001616 printk(BIOS_ERR,
1617 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001618 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001619 printk(BIOS_ERR,
1620 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001621 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001622 printk(BIOS_ERR,
1623 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001624 }
1625
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001626 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001627 printk(BIOS_ERR,
1628 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001629 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001630 printk(BIOS_ERR,
1631 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001632 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001633}
1634
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001635/*
1636 * Notes on panel extensions: (TODO, implement me in the code)
1637 *
1638 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1639 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1640 * 0x6c: 00 00 00 0e 00
1641 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1642 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1643 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1644 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1645 * bit 4: DE polarity (0 high active 1 low active)
1646 * bit 3-0: interface (0000 LVDS TFT
1647 * 0001 mono STN 4/8bit
1648 * 0010 color STN 8/16 bit
1649 * 0011 18 bit tft
1650 * 0100 24 bit tft
1651 * 0101 tmds
1652 * else reserved)
1653 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1654 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1655 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1656 * else time in 10ms (10ms to 150ms))
1657 * bit 3-0: total poweron seq delay (as above)
1658 * 0x75: contrast power on/off seq delay, same as 0x74
1659 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1660 * bit 6: backlight enabled at boot (0 on 1 off)
1661 * bit 5-0: backlight brightness control steps (0..63)
1662 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1663 * 0x78 - 0x7c: reserved
1664 * 0x7d: bit 7-4: EPI descriptor major version (1)
1665 * bit 3-0: EPI descriptor minor version (0)
1666 *
1667 * ----
1668 *
1669 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1670 *
1671 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1672 *
1673 * detailed descriptor 3:
1674 * 0x5a - 0x5e: 00 00 00 fe 00
1675 * 0x5f - 0x63: PC maker part number
1676 * 0x64: LCD supplier revision #
1677 * 0x65 - 0x6b: manufacturer part number
1678 *
1679 * detailed descriptor 4:
1680 * 0x6c - 0x70: 00 00 00 fe 00
1681 * 0x71 - 0x78: smbus nits values (whut)
1682 * 0x79: number of lvds channels (1 or 2)
1683 * 0x7A: panel self test (1 if present)
1684 * and then dummy terminator
1685 *
1686 * SPWG also says something strange about the LSB of detailed descriptor 1:
1687 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1688 */
Julius Werner69112192016-03-14 17:29:55 -07001689
1690/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001691void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1692 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001693{
1694 /* Caller should pass a supported value, everything else is BUG(). */
1695 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Julius Werner2b6db972016-04-06 12:50:40 -07001696 row_byte_alignment = max(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001697
1698 edid->framebuffer_bits_per_pixel = fb_bpp;
1699 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Elyes HAOUAS6df3b642018-11-26 22:53:49 +01001700 DIV_ROUND_UP(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001701 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1702 edid->y_resolution = edid->mode.va;
1703}