blob: 748f3d63fdf7aa112f91fda836eb5a604bec594b [file] [log] [blame]
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07002 * Permission is hereby granted, free of charge, to any person obtaining a
3 * copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation
5 * on the rights to use, copy, modify, merge, publish, distribute, sub
6 * license, and/or sell copies of the Software, and to permit persons to whom
7 * the Software is furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice (including the next
10 * paragraph) shall be included in all copies or substantial portions of the
11 * Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070020
21/* this is a pretty robust parser for EDID, and we're tasked with parsing
22 * an arbitrary panel. We will pass it a raw EDID block and a struct which
23 * it must fill in with values. The set of values we need is pretty limited
24 * at present.
25 */
26
Julius Werner69112192016-03-14 17:29:55 -070027#include <assert.h>
Elyes HAOUASba9b5042019-12-19 07:47:52 +010028#include <commonlib/helpers.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070029#include <stddef.h>
30#include <console/console.h>
Joel Kitching393c71c2019-06-16 16:09:42 +080031#include <ctype.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070032#include <stdint.h>
33#include <string.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070034#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070035#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070036
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080037struct edid_context {
38 int claims_one_point_oh;
39 int claims_one_point_two;
40 int claims_one_point_three;
41 int claims_one_point_four;
42 int nonconformant_digital_display;
43 int nonconformant_extension;
44 int did_detailed_timing;
45 int has_name_descriptor;
46 int has_range_descriptor;
47 int has_preferred_timing;
48 int has_valid_checksum;
49 int has_valid_cvt;
50 int has_valid_dummy_block;
51 int has_valid_week;
52 int has_valid_year;
53 int has_valid_detailed_blocks;
54 int has_valid_extension_count;
55 int has_valid_descriptor_ordering;
56 int has_valid_descriptor_pad;
57 int has_valid_range_descriptor;
58 int has_valid_max_dotclock;
59 int has_valid_string_termination;
60 int manufacturer_name_well_formed;
61 int seen_non_detailed_descriptor;
62 int warning_excessive_dotclock_correction;
63 int warning_zero_preferred_refresh;
Arthur Heymans8c5884e2017-04-30 08:28:05 +020064 enum edid_status conformant;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080065};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070066
David Hendricksa3b898a2015-08-02 18:07:48 -070067/* Stuff that isn't used anywhere but is nice to pretty-print while
68 we're decoding everything else. */
69static struct {
David Hendricksa3b898a2015-08-02 18:07:48 -070070 unsigned int model;
71 unsigned int serial;
72 unsigned int year;
73 unsigned int week;
74 unsigned int version[2];
75 unsigned int nonconformant;
76 unsigned int type;
77
78 unsigned int x_mm;
79 unsigned int y_mm;
80
81 unsigned int voltage;
82 unsigned int sync;
83
84 const char *syncmethod;
85 const char *range_class;
86 const char *stereo;
87} extra_info;
88
Douglas Andersonbca67fb2015-10-28 09:18:28 -070089static struct edid tmp_edid;
90
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080091static int manufacturer_name(unsigned char *x, char *output)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070092{
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080093 output[0] = ((x[0] & 0x7C) >> 2) + '@';
94 output[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
95 output[2] = (x[1] & 0x1F) + '@';
96 output[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070097
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080098 if (isupper(output[0]) &&
99 isupper(output[1]) &&
100 isupper(output[2]))
101 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700102
Hung-Te Lin6673e8e2019-08-13 12:06:27 +0800103 memset(output, 0, 4);
104 return 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700105}
106
107static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700108detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700109{
110 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -0800111 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700112 int width = 0, height = 0;
113 int valid = 1;
114 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
115
116 if (!first && !memcmp(x, empty, 3))
117 return valid;
118
119 height = x[0];
120 height |= (x[1] & 0xf0) << 4;
121 height++;
122 height *= 2;
123
124 switch (x[1] & 0x0c) {
125 case 0x00:
126 width = (height * 4) / 3; break;
127 case 0x04:
128 width = (height * 16) / 9; break;
129 case 0x08:
130 width = (height * 16) / 10; break;
131 case 0x0c:
132 width = (height * 15) / 9; break;
133 }
134
135 if (x[1] & 0x03)
136 valid = 0;
137 if (x[2] & 0x80)
138 valid = 0;
139 if (!(x[2] & 0x1f))
140 valid = 0;
141
142 fifty = (x[2] & 0x10);
143 sixty = (x[2] & 0x08);
144 seventyfive = (x[2] & 0x04);
145 eightyfive = (x[2] & 0x02);
146 reduced = (x[2] & 0x01);
147
148 if (!valid) {
149 printk(BIOS_SPEW, " (broken)\n");
150 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800151 printk(BIOS_SPEW,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200152 " %dx%d @ (%s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700153 width, height,
154 fifty ? "50 " : "",
155 sixty ? "60 " : "",
156 seventyfive ? "75 " : "",
157 eightyfive ? "85 " : "",
158 reduced ? "60RB " : "",
159 names[(x[2] & 0x60) >> 5],
160 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
161 }
162
163 return valid;
164}
165
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800166/* extract a CP437 string from a detailed subblock, checking for termination (if
167 * less than len of bytes) with LF and padded with SP.
168 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700169static char *
170extract_string(unsigned char *x, int *valid_termination, int len)
171{
Patrick Georgid840e2b2018-09-18 18:01:02 +0200172 static char ret[EDID_ASCII_STRING_LENGTH + 1];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700173 int i, seen_newline = 0;
174
175 memset(ret, 0, sizeof(ret));
176
Elyes HAOUASba9b5042019-12-19 07:47:52 +0100177 for (i = 0; i < MIN(len, EDID_ASCII_STRING_LENGTH); i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800178 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700179 if (x[i] != 0x20) {
180 *valid_termination = 0;
181 return ret;
182 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800183 } else if (x[i] == 0x0a) {
184 seen_newline = 1;
185 } else {
186 /* normal characters */
187 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700188 }
189 }
190
191 return ret;
192}
193
194/* 1 means valid data */
195static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700196detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800197 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700198{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700199 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700200 int i;
Angel Ponscc335c72018-10-02 11:58:28 +0200201
202 if (console_log_level(BIOS_SPEW)) {
203 printk(BIOS_SPEW, "Hex of detail: ");
204 for (i = 0; i < 18; i++)
205 printk(BIOS_SPEW, "%02x", x[i]);
206 printk(BIOS_SPEW, "\n");
207 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700208
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700209 /* Result might already have some valid fields like mode_is_supported */
210 *out = *result_edid;
211
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700212 if (x[0] == 0 && x[1] == 0) {
213 /* Monitor descriptor block, not detailed timing descriptor. */
214 if (x[2] != 0) {
215 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800216 printk(BIOS_SPEW,
217 "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700218 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800219 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700220 }
221 if (x[3] != 0xfd && x[4] != 0x00) {
222 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800223 printk(BIOS_SPEW,
224 "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700225 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800226 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700227 }
228
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800229 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700230 if (x[3] <= 0xF) {
231 /*
Lee Leahy73402172017-03-10 15:23:24 -0800232 * in principle we can decode these, if we know what
233 * they are.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700234 * 0x0f seems to be common in laptop panels.
235 * 0x0e is used by EPI: http://www.epi-standard.org/
236 */
Lee Leahy73402172017-03-10 15:23:24 -0800237 printk(BIOS_SPEW,
238 "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800239 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700240 }
241 switch (x[3]) {
242 case 0x10:
243 printk(BIOS_SPEW, "Dummy block\n");
244 for (i = 5; i < 18; i++)
245 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800246 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800247 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700248 case 0xF7:
249 /* TODO */
250 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800251 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700252 case 0xF8:
253 {
254 int valid_cvt = 1; /* just this block */
255 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
256 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800257 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700258 return 0;
259 }
260 for (i = 0; i < 4; i++)
Lee Leahy73402172017-03-10 15:23:24 -0800261 valid_cvt &= detailed_cvt_descriptor(x + 6
262 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800263 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800264 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700265 }
266 case 0xF9:
267 /* TODO */
268 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800269 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700270 case 0xFA:
271 /* TODO */
272 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800273 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700274 case 0xFB:
275 /* TODO */
276 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800277 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700278 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800279 printk(BIOS_SPEW, "Monitor name: %s\n",
280 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800281 &c->has_valid_string_termination,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200282 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800283 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700284 case 0xFD:
285 {
286 int h_max_offset = 0, h_min_offset = 0;
287 int v_max_offset = 0, v_min_offset = 0;
288 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800289 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700290 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700291 /*
292 * XXX todo: implement feature flags, vtd blocks
Lee Leahy73402172017-03-10 15:23:24 -0800293 * XXX check: ranges are well-formed; block termination
294 * if no vtd
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700295 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800296 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700297 if (x[4] & 0x02) {
298 v_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800299 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700300 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700301 }
302 if (x[4] & 0x04) {
303 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800304 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700305 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700306 }
307 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800308 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700309 }
310
311 /*
312 * despite the values, this is not a bitfield.
313 */
314 switch (x[10]) {
315 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700316 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700317 break;
318 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700319 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800320 if (!c->claims_one_point_four)
321 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700322 break;
323 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700324 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700325 break;
326 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700327 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700328 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800329 if (!c->claims_one_point_four)
330 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700331 break;
332 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800333 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700334 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700335 break;
336 }
337
338 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800339 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700340 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800341 c->has_valid_range_descriptor = 0;
Lee Leahy73402172017-03-10 15:23:24 -0800342 printk(BIOS_SPEW,
343 "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700344 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700345 x[5] + v_min_offset, x[6] + v_max_offset,
346 x[7] + h_min_offset, x[8] + h_max_offset);
347 if (x[9])
Lee Leahy73402172017-03-10 15:23:24 -0800348 printk(BIOS_SPEW,
349 ", max dotclock %dMHz\n", x[9] * 10);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700350 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800351 if (c->claims_one_point_four)
352 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700353 printk(BIOS_SPEW, "\n");
354 }
355
356 if (is_cvt) {
357 int max_h_pixels = 0;
358
Lee Leahy73402172017-03-10 15:23:24 -0800359 printk(BIOS_SPEW, "CVT version %d.%d\n",
360 x[11] & 0xf0 >> 4, x[11] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700361
362 if (x[12] & 0xfc) {
363 int raw_offset = (x[12] & 0xfc) >> 2;
Lee Leahy73402172017-03-10 15:23:24 -0800364 printk(BIOS_SPEW,
365 "Real max dotclock: %dKHz\n",
366 (x[9] * 10000)
367 - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700368 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800369 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700370 }
371
372 max_h_pixels = x[12] & 0x03;
373 max_h_pixels <<= 8;
374 max_h_pixels |= x[13];
375 max_h_pixels *= 8;
376 if (max_h_pixels)
Lee Leahy73402172017-03-10 15:23:24 -0800377 printk(BIOS_SPEW,
378 "Max active pixels per line: %d\n",
379 max_h_pixels);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700380
Lee Leahy73402172017-03-10 15:23:24 -0800381 printk(BIOS_SPEW,
382 "Supported aspect ratios: %s %s %s %s %s\n",
383 x[14] & 0x80 ? "4:3" : "",
384 x[14] & 0x40 ? "16:9" : "",
385 x[14] & 0x20 ? "16:10" : "",
386 x[14] & 0x10 ? "5:4" : "",
387 x[14] & 0x08 ? "15:9" : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700388 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800389 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700390
391 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800392 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800393 case 0x00:
394 printk(BIOS_SPEW, "4:3");
395 break;
396 case 0x01:
397 printk(BIOS_SPEW, "16:9");
398 break;
399 case 0x02:
400 printk(BIOS_SPEW, "16:10");
401 break;
402 case 0x03:
403 printk(BIOS_SPEW, "5:4");
404 break;
405 case 0x04:
406 printk(BIOS_SPEW, "15:9");
407 break;
408 default:
409 printk(BIOS_SPEW, "(broken)");
410 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700411 }
412 printk(BIOS_SPEW, "\n");
413
414 if (x[15] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -0800415 printk(BIOS_SPEW,
416 "Supports CVT standard blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700417 if (x[15] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800418 printk(BIOS_SPEW,
419 "Supports CVT reduced blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700420
421 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800422 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700423
424 if (x[16] & 0xf0) {
Lee Leahy73402172017-03-10 15:23:24 -0800425 printk(BIOS_SPEW,
426 "Supported display scaling:\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700427 if (x[16] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800428 printk(BIOS_SPEW,
429 " Horizontal shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700430 if (x[16] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800431 printk(BIOS_SPEW,
432 " Horizontal stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700433 if (x[16] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800434 printk(BIOS_SPEW,
435 " Vertical shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700436 if (x[16] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800437 printk(BIOS_SPEW,
438 " Vertical stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700439 }
440
441 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800442 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700443
444 if (x[17])
Lee Leahy73402172017-03-10 15:23:24 -0800445 printk(BIOS_SPEW,
446 "Preferred vertical refresh: %d Hz\n",
447 x[17]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700448 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800449 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700450 }
451
452 /*
Lee Leahy73402172017-03-10 15:23:24 -0800453 * Slightly weird to return a global, but I've never
454 * seen any EDID block wth two range descriptors, so
455 * it's harmless.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700456 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800457 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700458 }
459 case 0xFE:
460 /*
Lee Leahy73402172017-03-10 15:23:24 -0800461 * TODO: Two of these in a row, in the third and fourth
462 * slots, seems to be specified by SPWG:
463 * http://www.spwg.org/
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700464 */
Arthur Heymansdbe81612017-04-29 14:00:47 +0200465 strcpy(result_edid->ascii_string, extract_string(x + 5,
466 &c->has_valid_string_termination,
467 EDID_ASCII_STRING_LENGTH));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700468 printk(BIOS_SPEW, "ASCII string: %s\n",
Arthur Heymansdbe81612017-04-29 14:00:47 +0200469 result_edid->ascii_string);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800470 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700471 case 0xFF:
472 printk(BIOS_SPEW, "Serial number: %s\n",
Lee Leahy73402172017-03-10 15:23:24 -0800473 extract_string(x + 5,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200474 &c->has_valid_string_termination,
475 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800476 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700477 default:
Lee Leahy73402172017-03-10 15:23:24 -0800478 printk(BIOS_SPEW,
479 "Unknown monitor description type %d\n",
480 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700481 return 0;
482 }
483 }
484
Lee Leahy2f919ec2017-03-08 17:37:06 -0800485 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800486 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700487
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700488 /* Edid contains pixel clock in terms of 10KHz */
489 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
490 /*
491 LVDS supports following pixel clocks
492 25000...112000 kHz: single channel
493 80000...224000 kHz: dual channel
494 There is some overlap in theoretically supported
495 pixel clock between single-channel and dual-channel.
496 In practice with current panels all panels
497 <= 75200 kHz: single channel
498 >= 97750 kHz: dual channel
499 We have no samples between those values, so put a
500 threshold at 95000 kHz. If we get anything over
501 95000 kHz with single channel, we can make this
502 more sofisticated but it's currently not needed.
503 */
504 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
505 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
506 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
507 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
508 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
509 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
510 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
511 out->mode.hborder = x[15];
512 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
513 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
514 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
515 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
516 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700517
Julius Werner69112192016-03-14 17:29:55 -0700518 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700519 * Chipsets that want something else will need to override this with
520 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
521 * heuristic, assume that X86 systems require a 64-byte row alignment
522 * (since that seems to be true for most Intel chipsets). */
Julius Wernercd49cce2019-03-05 16:53:33 -0800523 if (CONFIG(ARCH_X86))
Julius Werner2b6db972016-04-06 12:50:40 -0700524 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
525 else
526 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700527
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700528 switch ((x[17] & 0x18) >> 3) {
529 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700530 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700531 break;
532 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700533 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700534 break;
535 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700536 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700537 break;
538 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700539 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700540 break;
541 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700542 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
543 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700544 switch (x[17] & 0x61) {
545 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700546 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700547 break;
548 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700549 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700550 break;
551 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700552 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700553 break;
554 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700555 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700556 break;
557 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700558 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700559 break;
560 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700561 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700562 break;
563 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700564 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700565 break;
566 }
567
Lee Leahy73402172017-03-10 15:23:24 -0800568 printk(BIOS_SPEW,
569 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700570 " %04x %04x %04x %04x hborder %x\n"
571 " %04x %04x %04x %04x vborder %x\n"
Paul Menzel433bf772016-11-29 21:02:04 +0100572 " %chsync %cvsync%s%s%s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700573 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700574 extra_info.x_mm,
575 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700576 out->mode.ha, out->mode.ha + out->mode.hso,
577 out->mode.ha + out->mode.hso + out->mode.hspw,
578 out->mode.ha + out->mode.hbl, out->mode.hborder,
579 out->mode.va, out->mode.va + out->mode.vso,
580 out->mode.va + out->mode.vso + out->mode.vspw,
581 out->mode.va + out->mode.vbl, out->mode.vborder,
582 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800583 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700584 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700585
Lee Leahy35af5c42017-03-09 17:35:28 -0800586 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700587 printk(BIOS_SPEW, "Did detailed timing\n");
588 c->did_detailed_timing = 1;
589 *result_edid = *out;
590 }
591
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700592 return 1;
593}
594
595static int
596do_checksum(unsigned char *x)
597{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800598 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600599 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700600 {
601 unsigned char sum = 0;
602 int i;
603 for (i = 0; i < 128; i++)
604 sum += x[i];
605 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800606 printk(BIOS_SPEW, " (should be 0x%hhx)",
607 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700608 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800609 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700610 printk(BIOS_SPEW, " (valid)");
611 }
612 }
613 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800614 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700615}
616
617/* CEA extension */
618
619static const char *
620audio_format(unsigned char x)
621{
622 switch (x) {
623 case 0: return "RESERVED";
624 case 1: return "Linear PCM";
625 case 2: return "AC-3";
626 case 3: return "MPEG 1 (Layers 1 & 2)";
627 case 4: return "MPEG 1 Layer 3 (MP3)";
628 case 5: return "MPEG2 (multichannel)";
629 case 6: return "AAC";
630 case 7: return "DTS";
631 case 8: return "ATRAC";
632 case 9: return "One Bit Audio";
633 case 10: return "Dolby Digital+";
634 case 11: return "DTS-HD";
635 case 12: return "MAT (MLP)";
636 case 13: return "DST";
637 case 14: return "WMA Pro";
638 case 15: return "RESERVED";
639 }
640 return "BROKEN"; /* can't happen */
641}
642
643static void
644cea_audio_block(unsigned char *x)
645{
646 int i, format;
647 int length = x[0] & 0x1f;
648
649 if (length % 3) {
650 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
651 /* XXX non-conformant */
652 return;
653 }
654
655 for (i = 1; i < length; i += 3) {
656 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800657 printk(BIOS_SPEW, " %s, max channels %d\n",
658 audio_format(format), x[i] & 0x07);
659 printk(BIOS_SPEW,
660 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700661 (x[i+1] & 0x40) ? " 192" : "",
662 (x[i+1] & 0x20) ? " 176.4" : "",
663 (x[i+1] & 0x10) ? " 96" : "",
664 (x[i+1] & 0x08) ? " 88.2" : "",
665 (x[i+1] & 0x04) ? " 48" : "",
666 (x[i+1] & 0x02) ? " 44.1" : "",
667 (x[i+1] & 0x01) ? " 32" : "");
668 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800669 printk(BIOS_SPEW,
670 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700671 (x[2] & 0x04) ? " 24" : "",
672 (x[2] & 0x02) ? " 20" : "",
673 (x[2] & 0x01) ? " 16" : "");
674 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800675 printk(BIOS_SPEW,
676 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700677 }
678 }
679}
680
681static void
682cea_video_block(unsigned char *x)
683{
684 int i;
685 int length = x[0] & 0x1f;
686
687 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800688 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700689 x[i] & 0x80 ? "(native)" : "");
690}
691
692static void
693cea_hdmi_block(struct edid *out, unsigned char *x)
694{
695 int length = x[0] & 0x1f;
696
Yakir Yang85810cc2015-10-27 16:17:13 +0800697 out->hdmi_monitor_detected = 1;
698
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700699 printk(BIOS_SPEW, " (HDMI)\n");
700 printk(BIOS_SPEW,
701 " Source physical address %d.%d.%d.%d\n",
702 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
703
704 if (length > 5) {
705 if (x[6] & 0x80)
706 printk(BIOS_SPEW, " Supports_AI\n");
707 if (x[6] & 0x40)
708 printk(BIOS_SPEW, " DC_48bit\n");
709 if (x[6] & 0x20)
710 printk(BIOS_SPEW, " DC_36bit\n");
711 if (x[6] & 0x10)
712 printk(BIOS_SPEW, " DC_30bit\n");
713 if (x[6] & 0x08)
714 printk(BIOS_SPEW, " DC_Y444\n");
715 /* two reserved */
716 if (x[6] & 0x01)
717 printk(BIOS_SPEW, " DVI_Dual\n");
718 }
719
720 if (length > 6)
721 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
722
723 /* XXX the walk here is really ugly, and needs to be length-checked */
724 if (length > 7) {
725 int b = 0;
726
727 if (x[8] & 0x80) {
728 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
729 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
730 b += 2;
731 }
732
733 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800734 printk(BIOS_SPEW,
735 " Interlaced video latency: %d\n", x[9 + b]);
736 printk(BIOS_SPEW,
737 " Interlaced audio latency: %d\n",
738 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700739 b += 2;
740 }
741
742 if (x[8] & 0x20) {
743 int mask = 0, formats = 0;
744 int len_xx, len_3d;
745 printk(BIOS_SPEW, " Extended HDMI video details:\n");
746 if (x[9 + b] & 0x80)
747 printk(BIOS_SPEW, " 3D present\n");
748 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800749 printk(BIOS_SPEW,
750 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700751 formats = 1;
752 }
753 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800754 printk(BIOS_SPEW,
755 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700756 formats = 1;
757 mask = 1;
758 }
759 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800760 case 0x00:
761 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700762 case 0x08:
763 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
764 break;
765 case 0x10:
766 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
767 break;
768 case 0x18:
769 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
770 break;
771 }
772 len_xx = (x[10 + b] & 0xe0) >> 5;
773 len_3d = (x[10 + b] & 0x1f) >> 0;
774 b += 2;
775
776 if (len_xx) {
777 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
778 " document\n", len_xx);
779 b += len_xx;
780 }
781
782 if (len_3d) {
783 if (formats) {
784 if (x[9 + b] & 0x01)
785 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
786 if (x[10 + b] & 0x40)
787 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
788 if (x[10 + b] & 0x01)
789 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
790 b += 2;
791 }
792 if (mask) {
793 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800794 printk(BIOS_SPEW,
795 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700796 /* worst bit ordering ever */
797 for (i = 0; i < 8; i++)
798 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800799 printk(BIOS_SPEW,
800 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700801 for (i = 0; i < 8; i++)
802 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800803 printk(BIOS_SPEW,
804 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700805 printk(BIOS_SPEW, "\n");
806 b += 2;
807 }
808
809 /*
810 * XXX list of nibbles:
811 * 2D_VIC_Order_X
812 * 3D_Structure_X
813 * (optionally: 3D_Detail_X and reserved)
814 */
815 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700816 }
Richard Spiegel2fdbe0c2018-08-07 08:43:22 -0700817 /* Tell static analysis we know index b is left unused. */
818 (void)b;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700819 }
820}
821
822static void
823cea_block(struct edid *out, unsigned char *x)
824{
825 unsigned int oui;
826
827 switch ((x[0] & 0xe0) >> 5) {
828 case 0x01:
829 printk(BIOS_SPEW, " Audio data block\n");
830 cea_audio_block(x);
831 break;
832 case 0x02:
833 printk(BIOS_SPEW, " Video data block\n");
834 cea_video_block(x);
835 break;
836 case 0x03:
837 /* yes really, endianness lols */
838 oui = (x[3] << 16) + (x[2] << 8) + x[1];
Lee Leahy73402172017-03-10 15:23:24 -0800839 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
840 oui);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700841 if (oui == 0x000c03)
842 cea_hdmi_block(out, x);
843 else
844 printk(BIOS_SPEW, "\n");
845 break;
846 case 0x04:
847 printk(BIOS_SPEW, " Speaker allocation data block\n");
848 break;
849 case 0x05:
850 printk(BIOS_SPEW, " VESA DTC data block\n");
851 break;
852 case 0x07:
853 printk(BIOS_SPEW, " Extended tag: ");
854 switch (x[1]) {
855 case 0x00:
856 printk(BIOS_SPEW, "video capability data block\n");
857 break;
858 case 0x01:
859 printk(BIOS_SPEW, "vendor-specific video data block\n");
860 break;
861 case 0x02:
Lee Leahy73402172017-03-10 15:23:24 -0800862 printk(BIOS_SPEW,
863 "VESA video display device information data block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700864 break;
865 case 0x03:
866 printk(BIOS_SPEW, "VESA video data block\n");
867 break;
868 case 0x04:
869 printk(BIOS_SPEW, "HDMI video data block\n");
870 break;
871 case 0x05:
872 printk(BIOS_SPEW, "Colorimetry data block\n");
873 break;
874 case 0x10:
875 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
876 break;
877 case 0x11:
878 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
879 break;
880 case 0x12:
881 printk(BIOS_SPEW, "HDMI audio data block\n");
882 break;
883 default:
884 if (x[1] >= 6 && x[1] <= 15)
Lee Leahy73402172017-03-10 15:23:24 -0800885 printk(BIOS_SPEW,
886 "Reserved video block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700887 else if (x[1] >= 19 && x[1] <= 31)
Lee Leahy73402172017-03-10 15:23:24 -0800888 printk(BIOS_SPEW,
889 "Reserved audio block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700890 else
891 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
892 break;
893 }
894 break;
895 default:
896 {
897 int tag = (*x & 0xe0) >> 5;
898 int length = *x & 0x1f;
899 printk(BIOS_SPEW,
Lee Leahy73402172017-03-10 15:23:24 -0800900 " Unknown tag %d, length %d (raw %02x)\n",
901 tag, length, *x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700902 break;
903 }
904 }
905}
906
907static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800908parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700909{
910 int ret = 0;
911 int version = x[1];
912 int offset = x[2];
913 unsigned char *detailed;
914
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800915 if (version >= 1)
916 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700917 if (version == 1 && x[3] != 0)
918 ret = 1;
919
920 if (offset < 4)
921 break;
922
Lee Leahye20a3192017-03-09 16:21:34 -0800923 if (version < 3)
Lee Leahy73402172017-03-10 15:23:24 -0800924 printk(BIOS_SPEW,
925 "%d 8-byte timing descriptors\n",
926 (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800927 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700928 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800929 printk(BIOS_SPEW,
930 "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800931 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700932 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700933 }
934
935 if (version >= 2) {
936 if (x[3] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800937 printk(BIOS_SPEW,
938 "Underscans PC formats by default\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700939 if (x[3] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800940 printk(BIOS_SPEW,
941 "Basic audio support\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700942 if (x[3] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800943 printk(BIOS_SPEW,
944 "Supports YCbCr 4:4:4\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700945 if (x[3] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800946 printk(BIOS_SPEW,
947 "Supports YCbCr 4:2:2\n");
948 printk(BIOS_SPEW,
949 "%d native detailed modes\n",
950 x[3] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700951 }
952
Lee Leahy73402172017-03-10 15:23:24 -0800953 for (detailed = x + offset; detailed + 18 < x + 127;
954 detailed += 18)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700955 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800956 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700957 } while (0);
958
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800959 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700960 return ret;
961}
962
963/* generic extension code */
964
965static void
966extension_version(struct edid *out, unsigned char *x)
967{
968 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
969}
970
971static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800972parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700973{
974 int conformant_extension = 0;
975 printk(BIOS_SPEW, "\n");
976
Lee Leahy45fde702017-03-08 18:02:24 -0800977 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700978 case 0x02:
979 printk(BIOS_SPEW, "CEA extension block\n");
980 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800981 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700982 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800983 case 0x10:
984 printk(BIOS_SPEW, "VTB extension block\n");
985 break;
986 case 0x40:
987 printk(BIOS_SPEW, "DI extension block\n");
988 break;
989 case 0x50:
990 printk(BIOS_SPEW, "LS extension block\n");
991 break;
992 case 0x60:
993 printk(BIOS_SPEW, "DPVL extension block\n");
994 break;
995 case 0xF0:
996 printk(BIOS_SPEW, "Block map\n");
997 break;
998 case 0xFF:
999 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Jacob Garbere447aec2019-03-27 17:23:42 -06001000 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001001 default:
1002 printk(BIOS_SPEW, "Unknown extension block\n");
1003 break;
1004 }
1005
1006 printk(BIOS_SPEW, "\n");
1007
1008 return conformant_extension;
1009}
1010
1011static const struct {
1012 int x, y, refresh;
1013} established_timings[] = {
1014 /* 0x23 bit 7 - 0 */
1015 {720, 400, 70},
1016 {720, 400, 88},
1017 {640, 480, 60},
1018 {640, 480, 67},
1019 {640, 480, 72},
1020 {640, 480, 75},
1021 {800, 600, 56},
1022 {800, 600, 60},
1023 /* 0x24 bit 7 - 0 */
1024 {800, 600, 72},
1025 {800, 600, 75},
1026 {832, 624, 75},
1027 {1280, 768, 87},
1028 {1024, 768, 60},
1029 {1024, 768, 70},
1030 {1024, 768, 75},
1031 {1280, 1024, 75},
1032 /* 0x25 bit 7*/
1033 {1152, 870, 75},
1034};
1035
1036static void print_subsection(const char *name, unsigned char *edid, int start,
1037 int end)
1038{
1039 int i;
1040
1041 printk(BIOS_SPEW, "%s:", name);
1042 for (i = strlen(name); i < 15; i++)
1043 printk(BIOS_SPEW, " ");
1044 for (i = start; i <= end; i++)
1045 printk(BIOS_SPEW, " %02x", edid[i]);
1046 printk(BIOS_SPEW, "\n");
1047}
1048
1049static void dump_breakdown(unsigned char *edid)
1050{
1051 printk(BIOS_SPEW, "Extracted contents:\n");
1052 print_subsection("header", edid, 0, 7);
1053 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001054 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001055 print_subsection("basic params", edid, 20, 24);
1056 print_subsection("chroma info", edid, 25, 34);
1057 print_subsection("established", edid, 35, 37);
1058 print_subsection("standard", edid, 38, 53);
1059 print_subsection("descriptor 1", edid, 54, 71);
1060 print_subsection("descriptor 2", edid, 72, 89);
1061 print_subsection("descriptor 3", edid, 90, 107);
1062 print_subsection("descriptor 4", edid, 108, 125);
1063 print_subsection("extensions", edid, 126, 126);
1064 print_subsection("checksum", edid, 127, 127);
1065 printk(BIOS_SPEW, "\n");
1066}
1067
1068/*
David Hendrickse2054102015-08-07 18:41:37 -07001069 * Lookup table of some well-known modes that can be useful in case the
1070 * auto-detected mode is unsuitable.
1071 * ha = hdisplay; va = vdisplay;
1072 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1073 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1074 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1075 */
1076static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1077 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001078 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001079 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001080 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1081 .phsync = '-', .pvsync = '-' },
1082 [EDID_MODE_720x480_60Hz] = {
1083 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001084 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001085 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1086 .phsync = '-', .pvsync = '-' },
1087 [EDID_MODE_1280x720_60Hz] = {
1088 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001089 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001090 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1091 .phsync = '+', .pvsync = '+' },
1092 [EDID_MODE_1920x1080_60Hz] = {
1093 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001094 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001095 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1096 .phsync = '+', .pvsync = '+' },
1097};
1098
1099int set_display_mode(struct edid *edid, enum edid_modes mode)
1100{
1101 if (mode == EDID_MODE_AUTO)
1102 return 0;
1103
1104 if (edid->mode_is_supported[mode]) {
1105 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1106 edid->mode = known_modes[mode];
1107 return 0;
1108 }
1109
1110 printk(BIOS_ERR, "Requested display mode not supported.\n");
1111 return -1;
1112}
1113
1114/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001115 * Given a raw edid bloc, decode it into a form
1116 * that other parts of coreboot can use -- mainly
1117 * graphics bringup functions. The raw block is
1118 * required to be 128 bytes long, per the standard,
1119 * but we have no way of checking this minimum length.
1120 * We accept what we are given.
1121 */
1122int decode_edid(unsigned char *edid, int size, struct edid *out)
1123{
David Hendrickse2054102015-08-07 18:41:37 -07001124 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001125 struct edid_context c = {
1126 .has_valid_cvt = 1,
1127 .has_valid_dummy_block = 1,
1128 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001129 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001130 .has_valid_descriptor_pad = 1,
1131 .has_valid_range_descriptor = 1,
1132 .has_valid_max_dotclock = 1,
1133 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001134 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001135 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001136
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001137 if (!edid) {
Jacob Garber18553292019-03-27 12:02:38 -06001138 printk(BIOS_ERR, "No EDID found\n");
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001139 return EDID_ABSENT;
1140 }
1141
1142 dump_breakdown(edid);
1143
1144 if (memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
Jacob Garber18553292019-03-27 12:02:38 -06001145 printk(BIOS_ERR, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001146 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001147 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001148
Paul Menzel1ced4e62020-02-15 13:12:04 +01001149 memset(out, 0, sizeof(*out));
1150
Hung-Te Lin6673e8e2019-08-13 12:06:27 +08001151 if (manufacturer_name(edid + 0x08, out->manufacturer_name))
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",
Hung-Te Lin6673e8e2019-08-13 12:06:27 +08001159 out->manufacturer_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;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001204 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001205 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001206 c.claims_one_point_three = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001207 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001208 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001209 c.claims_one_point_two = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001210 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001211 default:
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001212 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001213 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001214 }
1215
1216 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001217 if (edid[0x14] & 0x80) {
1218 int conformance_mask;
1219 analog = 0;
1220 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001221 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001222 conformance_mask = 0;
1223 if ((edid[0x14] & 0x70) == 0x00)
1224 printk(BIOS_SPEW, "Color depth is undefined\n");
1225 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001226 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001227 else
Lee Leahy73402172017-03-10 15:23:24 -08001228 printk(BIOS_SPEW,
1229 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001230 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001231 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1232 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001233 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001234
1235 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001236 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001237 printk(BIOS_SPEW,
1238 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001239 break;
1240 case 0x01:
1241 printk(BIOS_SPEW, "DVI interface\n");
1242 break;
1243 case 0x02:
1244 printk(BIOS_SPEW, "HDMI-a interface\n");
1245 break;
1246 case 0x03:
1247 printk(BIOS_SPEW, "HDMI-b interface\n");
1248 break;
1249 case 0x04:
1250 printk(BIOS_SPEW, "MDDI interface\n");
1251 break;
1252 case 0x05:
1253 printk(BIOS_SPEW, "DisplayPort interface\n");
1254 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001255 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001256 c.nonconformant_digital_display = 1;
1257 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001258 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001259 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001260 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001261 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001262 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001263 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001264 } else
1265 conformance_mask = 0x7F;
1266
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001267 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001268 c.nonconformant_digital_display = edid[0x14]
1269 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001270 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001271 } else {
1272 analog = 1;
1273 int voltage = (edid[0x14] & 0x60) >> 5;
1274 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001275 extra_info.voltage = voltage;
1276 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001277
1278 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1279 voltage == 3 ? "0.7/0.7" :
1280 voltage == 2 ? "1.0/0.4" :
1281 voltage == 1 ? "0.714/0.286" :
1282 "0.7/0.3");
1283
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001284 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001285 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001286 printk(BIOS_SPEW,
1287 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001288 else
Lee Leahy73402172017-03-10 15:23:24 -08001289 printk(BIOS_SPEW,
1290 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001291 } else if (edid[0x14] & 0x10) {
1292 /*
Lee Leahy73402172017-03-10 15:23:24 -08001293 * XXX this is just the X text. 1.3 says "if set,
1294 * display expects a blank-to-black setup or pedestal
1295 * per appropriate Signal Level Standard". Whatever
1296 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001297 */
1298 printk(BIOS_SPEW, "Configurable signal levels\n");
1299 }
1300
Lee Leahy73402172017-03-10 15:23:24 -08001301 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1302 sync & 0x08 ? "Separate " : "",
1303 sync & 0x04 ? "Composite " : "",
1304 sync & 0x02 ? "SyncOnGreen " : "",
1305 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001306 }
1307
1308
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001309 if (edid[0x15] && edid[0x16]) {
1310 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1311 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001312 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001313 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1314 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001315 printk(BIOS_SPEW,
1316 "Aspect ratio is %u.%03u (landscape)\n",
1317 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001318 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1319 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001320 printk(BIOS_SPEW,
1321 "Aspect ratio is %u.%03u (portrait)\n",
1322 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001323 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001324 } else {
1325 /* Either or both can be zero for 1.3 and before */
1326 printk(BIOS_SPEW, "Image size is variable\n");
1327 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001328
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001329 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001330 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001331 printk(BIOS_SPEW,
1332 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001333 else
1334 /* XXX Technically 1.3 doesn't say this... */
1335 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001336 } else
1337 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001338 printk(BIOS_SPEW, "Check DPMS levels\n");
1339 if (edid[0x18] & 0xE0) {
1340 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001341 if (edid[0x18] & 0x80)
1342 printk(BIOS_SPEW, " Standby");
1343 if (edid[0x18] & 0x40)
1344 printk(BIOS_SPEW, " Suspend");
1345 if (edid[0x18] & 0x20)
1346 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001347 printk(BIOS_SPEW, "\n");
1348 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001349
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001350 /* FIXME: this is from 1.4 spec, check earlier */
1351 if (analog) {
1352 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001353 case 0x00:
1354 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1355 break;
1356 case 0x08:
1357 printk(BIOS_SPEW, "RGB color display\n");
1358 break;
1359 case 0x10:
1360 printk(BIOS_SPEW, "Non-RGB color display\n");
1361 break;
1362 case 0x18:
1363 printk(BIOS_SPEW, "Undefined display color type\n");
1364 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001365 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001366 } else {
1367 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1368 if (edid[0x18] & 0x10)
1369 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1370 if (edid[0x18] & 0x08)
1371 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1372 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001373 }
1374
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001375 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001376 printk(BIOS_SPEW,
1377 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001378 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001379 printk(BIOS_SPEW,
1380 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001381 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001382 }
1383 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001384 printk(BIOS_SPEW,
1385 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001386
1387 /* XXX color section */
1388
1389 printk(BIOS_SPEW, "Established timings supported:\n");
1390 /* it's not yet clear we want all this stuff in the edid struct.
1391 * Let's wait.
1392 */
1393 for (i = 0; i < 17; i++) {
1394 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001395 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1396 established_timings[i].x,
1397 established_timings[i].y,
1398 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001399
Douglas Anderson9fa07602015-10-28 10:19:52 -07001400 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001401 if (known_modes[j].ha ==
1402 established_timings[i].x
1403 && known_modes[j].va ==
1404 established_timings[i].y
1405 && known_modes[j].refresh ==
1406 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001407 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001408 }
David Hendrickse2054102015-08-07 18:41:37 -07001409 }
1410
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001411 }
1412
1413 printk(BIOS_SPEW, "Standard timings supported:\n");
1414 for (i = 0; i < 8; i++) {
1415 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1416 unsigned int x, y = 0, refresh;
1417
1418 if (b1 == 0x01 && b2 == 0x01)
1419 continue;
1420
1421 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001422 printk(BIOS_SPEW,
1423 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001424 continue;
1425 }
1426 x = (b1 + 31) * 8;
1427 switch ((b2 >> 6) & 0x3) {
1428 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001429 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001430 y = x * 10 / 16;
1431 else
1432 y = x;
1433 break;
1434 case 0x01:
1435 y = x * 3 / 4;
1436 break;
1437 case 0x02:
1438 y = x * 4 / 5;
1439 break;
1440 case 0x03:
1441 y = x * 9 / 16;
1442 break;
1443 }
1444 refresh = 60 + (b2 & 0x3f);
1445
1446 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001447 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1448 if (known_modes[j].ha == x && known_modes[j].va == y &&
1449 known_modes[j].refresh == refresh)
1450 out->mode_is_supported[j] = 1;
1451 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001452 }
1453
1454 /* detailed timings */
1455 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 for (i = 0; i < 4; i++) {
1457 c.has_valid_detailed_blocks &= detailed_block(
1458 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001459 if (i == 0 && c.has_preferred_timing
1460 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001461 /* not really accurate... */
1462 c.has_preferred_timing = 0;
1463 }
1464 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001465
1466 /* check this, 1.4 verification guide says otherwise */
1467 if (edid[0x7e]) {
1468 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1469 /* 2 is impossible because of the block map */
1470 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001471 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001472 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001473 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001474 }
1475
1476 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001477 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001478
1479 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1480 * the extension parsing loop below. Since v2.0 was quickly deprecated
1481 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1482 * that case now and can fix it when we need to use a real 2.0 panel.
1483 */
Lee Leahy45fde702017-03-08 18:02:24 -08001484 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001485 c.nonconformant_extension +=
1486 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001487
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001488 if (c.claims_one_point_four) {
1489 if (c.nonconformant_digital_display ||
1490 !c.has_valid_string_termination ||
1491 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001492 !c.has_preferred_timing) {
1493 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001494 printk(BIOS_ERR,
1495 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001496 }
1497
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001498 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001499 printk(BIOS_ERR,
1500 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001501 c.nonconformant_digital_display);
1502 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001503 printk(BIOS_ERR,
1504 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001505 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001506 printk(BIOS_ERR,
1507 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001508 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001509 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001510 } else if (c.claims_one_point_three) {
1511 if (c.nonconformant_digital_display ||
1512 !c.has_valid_string_termination ||
1513 !c.has_valid_descriptor_pad ||
1514 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001515 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001516 }
1517 /**
1518 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1519 * has_range_descriptor are both required. These fields are
1520 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1521 * don't have them. As a workaround, we only print warning
1522 * messages.
1523 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001524 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001525 printk(BIOS_ERR,
1526 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001527 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001528 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1529 "fully conform to EDID 1.3.\n");
1530
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001531 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001532 printk(BIOS_ERR,
1533 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001534 c.nonconformant_digital_display);
1535 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001536 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001537 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001538 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001539 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001540 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001541 /* Might be more than just 1.3 */
1542 if (!c.has_valid_descriptor_pad)
1543 printk(BIOS_ERR,
1544 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001545 if (!c.has_valid_string_termination) /* Likewise */
Lee Leahy73402172017-03-10 15:23:24 -08001546 printk(BIOS_ERR,
1547 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001548 } else if (c.claims_one_point_two) {
1549 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001550 !c.has_valid_string_termination) {
1551 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001552 printk(BIOS_ERR,
1553 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001554 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001555 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001556 printk(BIOS_ERR,
1557 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001558 c.nonconformant_digital_display);
1559 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001560 printk(BIOS_ERR,
1561 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001562 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001563 if (c.seen_non_detailed_descriptor) {
1564 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001565 printk(BIOS_ERR,
1566 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001567 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001568 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001569 printk(BIOS_ERR,
1570 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001571 }
1572
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001573 if (c.nonconformant_extension ||
1574 !c.has_valid_checksum ||
1575 !c.has_valid_cvt ||
1576 !c.has_valid_year ||
1577 !c.has_valid_week ||
1578 !c.has_valid_detailed_blocks ||
1579 !c.has_valid_dummy_block ||
1580 !c.has_valid_extension_count ||
1581 !c.has_valid_descriptor_ordering ||
1582 !c.has_valid_range_descriptor ||
1583 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001584 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001585 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001586 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001587 printk(BIOS_ERR,
1588 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001589 c.nonconformant_extension);
1590 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001591 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001592 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001593 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001594 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001595 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001596 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001597 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001598 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001599 printk(BIOS_ERR,
1600 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001601 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001602 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001603 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001604 printk(BIOS_ERR,
1605 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001606 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001607 printk(BIOS_ERR,
1608 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001609 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001610 printk(BIOS_ERR,
1611 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001612 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001613 printk(BIOS_ERR,
1614 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001615 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001616 printk(BIOS_ERR,
1617 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001618 }
1619
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001620 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001621 printk(BIOS_ERR,
1622 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001623 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001624 printk(BIOS_ERR,
1625 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001626 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001627}
1628
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001629/*
1630 * Notes on panel extensions: (TODO, implement me in the code)
1631 *
1632 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1633 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1634 * 0x6c: 00 00 00 0e 00
1635 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1636 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1637 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1638 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1639 * bit 4: DE polarity (0 high active 1 low active)
1640 * bit 3-0: interface (0000 LVDS TFT
1641 * 0001 mono STN 4/8bit
1642 * 0010 color STN 8/16 bit
1643 * 0011 18 bit tft
1644 * 0100 24 bit tft
1645 * 0101 tmds
1646 * else reserved)
1647 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1648 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1649 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1650 * else time in 10ms (10ms to 150ms))
1651 * bit 3-0: total poweron seq delay (as above)
1652 * 0x75: contrast power on/off seq delay, same as 0x74
1653 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1654 * bit 6: backlight enabled at boot (0 on 1 off)
1655 * bit 5-0: backlight brightness control steps (0..63)
1656 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1657 * 0x78 - 0x7c: reserved
1658 * 0x7d: bit 7-4: EPI descriptor major version (1)
1659 * bit 3-0: EPI descriptor minor version (0)
1660 *
1661 * ----
1662 *
1663 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1664 *
1665 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1666 *
1667 * detailed descriptor 3:
1668 * 0x5a - 0x5e: 00 00 00 fe 00
1669 * 0x5f - 0x63: PC maker part number
1670 * 0x64: LCD supplier revision #
1671 * 0x65 - 0x6b: manufacturer part number
1672 *
1673 * detailed descriptor 4:
1674 * 0x6c - 0x70: 00 00 00 fe 00
1675 * 0x71 - 0x78: smbus nits values (whut)
1676 * 0x79: number of lvds channels (1 or 2)
1677 * 0x7A: panel self test (1 if present)
1678 * and then dummy terminator
1679 *
1680 * SPWG also says something strange about the LSB of detailed descriptor 1:
1681 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1682 */
Julius Werner69112192016-03-14 17:29:55 -07001683
1684/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001685void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1686 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001687{
1688 /* Caller should pass a supported value, everything else is BUG(). */
1689 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Elyes HAOUASba9b5042019-12-19 07:47:52 +01001690 row_byte_alignment = MAX(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001691
1692 edid->framebuffer_bits_per_pixel = fb_bpp;
1693 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Elyes HAOUAS6df3b642018-11-26 22:53:49 +01001694 DIV_ROUND_UP(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001695 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1696 edid->y_resolution = edid->mode.va;
1697}