blob: f20d23959ed498361232ad87d89b0ec20fbf0406 [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: MIT */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07002
3/* this is a pretty robust parser for EDID, and we're tasked with parsing
4 * an arbitrary panel. We will pass it a raw EDID block and a struct which
5 * it must fill in with values. The set of values we need is pretty limited
6 * at present.
7 */
8
Julius Werner69112192016-03-14 17:29:55 -07009#include <assert.h>
Elyes HAOUASba9b5042019-12-19 07:47:52 +010010#include <commonlib/helpers.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070011#include <console/console.h>
Joel Kitching393c71c2019-06-16 16:09:42 +080012#include <ctype.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070013#include <stdint.h>
14#include <string.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070015#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070016#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070017
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080018struct edid_context {
19 int claims_one_point_oh;
20 int claims_one_point_two;
21 int claims_one_point_three;
22 int claims_one_point_four;
23 int nonconformant_digital_display;
24 int nonconformant_extension;
25 int did_detailed_timing;
26 int has_name_descriptor;
27 int has_range_descriptor;
28 int has_preferred_timing;
29 int has_valid_checksum;
30 int has_valid_cvt;
31 int has_valid_dummy_block;
32 int has_valid_week;
33 int has_valid_year;
34 int has_valid_detailed_blocks;
35 int has_valid_extension_count;
36 int has_valid_descriptor_ordering;
37 int has_valid_descriptor_pad;
38 int has_valid_range_descriptor;
39 int has_valid_max_dotclock;
40 int has_valid_string_termination;
41 int manufacturer_name_well_formed;
42 int seen_non_detailed_descriptor;
43 int warning_excessive_dotclock_correction;
44 int warning_zero_preferred_refresh;
Arthur Heymans8c5884e2017-04-30 08:28:05 +020045 enum edid_status conformant;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080046};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070047
David Hendricksa3b898a2015-08-02 18:07:48 -070048/* Stuff that isn't used anywhere but is nice to pretty-print while
49 we're decoding everything else. */
50static struct {
David Hendricksa3b898a2015-08-02 18:07:48 -070051 unsigned int model;
52 unsigned int serial;
53 unsigned int year;
54 unsigned int week;
55 unsigned int version[2];
56 unsigned int nonconformant;
57 unsigned int type;
58
59 unsigned int x_mm;
60 unsigned int y_mm;
61
62 unsigned int voltage;
63 unsigned int sync;
64
65 const char *syncmethod;
66 const char *range_class;
67 const char *stereo;
68} extra_info;
69
Douglas Andersonbca67fb2015-10-28 09:18:28 -070070static struct edid tmp_edid;
71
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080072static int manufacturer_name(unsigned char *x, char *output)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070073{
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080074 output[0] = ((x[0] & 0x7C) >> 2) + '@';
75 output[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
76 output[2] = (x[1] & 0x1F) + '@';
77 output[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070078
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080079 if (isupper(output[0]) &&
80 isupper(output[1]) &&
81 isupper(output[2]))
82 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070083
Hung-Te Lin6673e8e2019-08-13 12:06:27 +080084 memset(output, 0, 4);
85 return 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070086}
87
88static int
Douglas Anderson14dd3702015-10-28 11:19:57 -070089detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070090{
91 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -080092 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070093 int width = 0, height = 0;
94 int valid = 1;
95 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
96
97 if (!first && !memcmp(x, empty, 3))
98 return valid;
99
100 height = x[0];
101 height |= (x[1] & 0xf0) << 4;
102 height++;
103 height *= 2;
104
105 switch (x[1] & 0x0c) {
106 case 0x00:
107 width = (height * 4) / 3; break;
108 case 0x04:
109 width = (height * 16) / 9; break;
110 case 0x08:
111 width = (height * 16) / 10; break;
112 case 0x0c:
113 width = (height * 15) / 9; break;
114 }
115
116 if (x[1] & 0x03)
117 valid = 0;
118 if (x[2] & 0x80)
119 valid = 0;
120 if (!(x[2] & 0x1f))
121 valid = 0;
122
123 fifty = (x[2] & 0x10);
124 sixty = (x[2] & 0x08);
125 seventyfive = (x[2] & 0x04);
126 eightyfive = (x[2] & 0x02);
127 reduced = (x[2] & 0x01);
128
129 if (!valid) {
130 printk(BIOS_SPEW, " (broken)\n");
131 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800132 printk(BIOS_SPEW,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200133 " %dx%d @ (%s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700134 width, height,
135 fifty ? "50 " : "",
136 sixty ? "60 " : "",
137 seventyfive ? "75 " : "",
138 eightyfive ? "85 " : "",
139 reduced ? "60RB " : "",
140 names[(x[2] & 0x60) >> 5],
141 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
142 }
143
144 return valid;
145}
146
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800147/* extract a CP437 string from a detailed subblock, checking for termination (if
148 * less than len of bytes) with LF and padded with SP.
149 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700150static char *
151extract_string(unsigned char *x, int *valid_termination, int len)
152{
Patrick Georgid840e2b2018-09-18 18:01:02 +0200153 static char ret[EDID_ASCII_STRING_LENGTH + 1];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700154 int i, seen_newline = 0;
155
156 memset(ret, 0, sizeof(ret));
157
Elyes HAOUASba9b5042019-12-19 07:47:52 +0100158 for (i = 0; i < MIN(len, EDID_ASCII_STRING_LENGTH); i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800159 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700160 if (x[i] != 0x20) {
161 *valid_termination = 0;
162 return ret;
163 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800164 } else if (x[i] == 0x0a) {
165 seen_newline = 1;
166 } else {
167 /* normal characters */
168 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700169 }
170 }
171
172 return ret;
173}
174
175/* 1 means valid data */
176static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700177detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800178 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700179{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700180 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700181 int i;
Angel Ponscc335c72018-10-02 11:58:28 +0200182
183 if (console_log_level(BIOS_SPEW)) {
184 printk(BIOS_SPEW, "Hex of detail: ");
185 for (i = 0; i < 18; i++)
186 printk(BIOS_SPEW, "%02x", x[i]);
187 printk(BIOS_SPEW, "\n");
188 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700189
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700190 /* Result might already have some valid fields like mode_is_supported */
191 *out = *result_edid;
192
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700193 if (x[0] == 0 && x[1] == 0) {
194 /* Monitor descriptor block, not detailed timing descriptor. */
195 if (x[2] != 0) {
196 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800197 printk(BIOS_SPEW,
198 "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700199 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800200 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700201 }
202 if (x[3] != 0xfd && x[4] != 0x00) {
203 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800204 printk(BIOS_SPEW,
205 "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700206 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800207 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700208 }
209
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800210 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700211 if (x[3] <= 0xF) {
212 /*
Lee Leahy73402172017-03-10 15:23:24 -0800213 * in principle we can decode these, if we know what
214 * they are.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700215 * 0x0f seems to be common in laptop panels.
216 * 0x0e is used by EPI: http://www.epi-standard.org/
217 */
Lee Leahy73402172017-03-10 15:23:24 -0800218 printk(BIOS_SPEW,
219 "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800220 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700221 }
222 switch (x[3]) {
223 case 0x10:
224 printk(BIOS_SPEW, "Dummy block\n");
225 for (i = 5; i < 18; i++)
226 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800227 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800228 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700229 case 0xF7:
230 /* TODO */
231 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800232 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700233 case 0xF8:
234 {
235 int valid_cvt = 1; /* just this block */
236 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
237 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800238 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700239 return 0;
240 }
241 for (i = 0; i < 4; i++)
Lee Leahy73402172017-03-10 15:23:24 -0800242 valid_cvt &= detailed_cvt_descriptor(x + 6
243 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800244 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800245 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700246 }
247 case 0xF9:
248 /* TODO */
249 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800250 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700251 case 0xFA:
252 /* TODO */
253 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800254 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700255 case 0xFB:
256 /* TODO */
257 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800258 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700259 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800260 printk(BIOS_SPEW, "Monitor name: %s\n",
261 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800262 &c->has_valid_string_termination,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200263 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800264 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700265 case 0xFD:
266 {
267 int h_max_offset = 0, h_min_offset = 0;
268 int v_max_offset = 0, v_min_offset = 0;
269 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800270 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700271 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700272 /*
273 * XXX todo: implement feature flags, vtd blocks
Lee Leahy73402172017-03-10 15:23:24 -0800274 * XXX check: ranges are well-formed; block termination
275 * if no vtd
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700276 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800277 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700278 if (x[4] & 0x02) {
279 v_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800280 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700281 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700282 }
283 if (x[4] & 0x04) {
284 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800285 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700286 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700287 }
288 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800289 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700290 }
291
292 /*
293 * despite the values, this is not a bitfield.
294 */
295 switch (x[10]) {
296 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700297 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700298 break;
299 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700300 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800301 if (!c->claims_one_point_four)
302 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700303 break;
304 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700305 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700306 break;
307 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700308 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700309 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800310 if (!c->claims_one_point_four)
311 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700312 break;
313 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800314 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700315 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700316 break;
317 }
318
319 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800320 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700321 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800322 c->has_valid_range_descriptor = 0;
Lee Leahy73402172017-03-10 15:23:24 -0800323 printk(BIOS_SPEW,
324 "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700325 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700326 x[5] + v_min_offset, x[6] + v_max_offset,
327 x[7] + h_min_offset, x[8] + h_max_offset);
328 if (x[9])
Lee Leahy73402172017-03-10 15:23:24 -0800329 printk(BIOS_SPEW,
330 ", max dotclock %dMHz\n", x[9] * 10);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700331 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800332 if (c->claims_one_point_four)
333 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700334 printk(BIOS_SPEW, "\n");
335 }
336
337 if (is_cvt) {
338 int max_h_pixels = 0;
339
Lee Leahy73402172017-03-10 15:23:24 -0800340 printk(BIOS_SPEW, "CVT version %d.%d\n",
341 x[11] & 0xf0 >> 4, x[11] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700342
343 if (x[12] & 0xfc) {
344 int raw_offset = (x[12] & 0xfc) >> 2;
Lee Leahy73402172017-03-10 15:23:24 -0800345 printk(BIOS_SPEW,
346 "Real max dotclock: %dKHz\n",
347 (x[9] * 10000)
348 - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700349 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800350 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700351 }
352
353 max_h_pixels = x[12] & 0x03;
354 max_h_pixels <<= 8;
355 max_h_pixels |= x[13];
356 max_h_pixels *= 8;
357 if (max_h_pixels)
Lee Leahy73402172017-03-10 15:23:24 -0800358 printk(BIOS_SPEW,
359 "Max active pixels per line: %d\n",
360 max_h_pixels);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700361
Lee Leahy73402172017-03-10 15:23:24 -0800362 printk(BIOS_SPEW,
363 "Supported aspect ratios: %s %s %s %s %s\n",
364 x[14] & 0x80 ? "4:3" : "",
365 x[14] & 0x40 ? "16:9" : "",
366 x[14] & 0x20 ? "16:10" : "",
367 x[14] & 0x10 ? "5:4" : "",
368 x[14] & 0x08 ? "15:9" : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700369 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800370 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700371
372 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800373 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800374 case 0x00:
375 printk(BIOS_SPEW, "4:3");
376 break;
377 case 0x01:
378 printk(BIOS_SPEW, "16:9");
379 break;
380 case 0x02:
381 printk(BIOS_SPEW, "16:10");
382 break;
383 case 0x03:
384 printk(BIOS_SPEW, "5:4");
385 break;
386 case 0x04:
387 printk(BIOS_SPEW, "15:9");
388 break;
389 default:
390 printk(BIOS_SPEW, "(broken)");
391 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700392 }
393 printk(BIOS_SPEW, "\n");
394
395 if (x[15] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -0800396 printk(BIOS_SPEW,
397 "Supports CVT standard blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700398 if (x[15] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800399 printk(BIOS_SPEW,
400 "Supports CVT reduced blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700401
402 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800403 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700404
405 if (x[16] & 0xf0) {
Lee Leahy73402172017-03-10 15:23:24 -0800406 printk(BIOS_SPEW,
407 "Supported display scaling:\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700408 if (x[16] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800409 printk(BIOS_SPEW,
410 " Horizontal shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700411 if (x[16] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800412 printk(BIOS_SPEW,
413 " Horizontal stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700414 if (x[16] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800415 printk(BIOS_SPEW,
416 " Vertical shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700417 if (x[16] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800418 printk(BIOS_SPEW,
419 " Vertical stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700420 }
421
422 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800423 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700424
425 if (x[17])
Lee Leahy73402172017-03-10 15:23:24 -0800426 printk(BIOS_SPEW,
427 "Preferred vertical refresh: %d Hz\n",
428 x[17]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700429 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800430 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700431 }
432
433 /*
Lee Leahy73402172017-03-10 15:23:24 -0800434 * Slightly weird to return a global, but I've never
435 * seen any EDID block wth two range descriptors, so
436 * it's harmless.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700437 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800438 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700439 }
440 case 0xFE:
441 /*
Lee Leahy73402172017-03-10 15:23:24 -0800442 * TODO: Two of these in a row, in the third and fourth
443 * slots, seems to be specified by SPWG:
444 * http://www.spwg.org/
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700445 */
Arthur Heymansdbe81612017-04-29 14:00:47 +0200446 strcpy(result_edid->ascii_string, extract_string(x + 5,
447 &c->has_valid_string_termination,
448 EDID_ASCII_STRING_LENGTH));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700449 printk(BIOS_SPEW, "ASCII string: %s\n",
Arthur Heymansdbe81612017-04-29 14:00:47 +0200450 result_edid->ascii_string);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800451 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700452 case 0xFF:
453 printk(BIOS_SPEW, "Serial number: %s\n",
Lee Leahy73402172017-03-10 15:23:24 -0800454 extract_string(x + 5,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200455 &c->has_valid_string_termination,
456 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800457 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700458 default:
Lee Leahy73402172017-03-10 15:23:24 -0800459 printk(BIOS_SPEW,
460 "Unknown monitor description type %d\n",
461 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700462 return 0;
463 }
464 }
465
Lee Leahy2f919ec2017-03-08 17:37:06 -0800466 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800467 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700468
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700469 /* Edid contains pixel clock in terms of 10KHz */
470 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
471 /*
472 LVDS supports following pixel clocks
473 25000...112000 kHz: single channel
474 80000...224000 kHz: dual channel
475 There is some overlap in theoretically supported
476 pixel clock between single-channel and dual-channel.
477 In practice with current panels all panels
478 <= 75200 kHz: single channel
479 >= 97750 kHz: dual channel
480 We have no samples between those values, so put a
481 threshold at 95000 kHz. If we get anything over
482 95000 kHz with single channel, we can make this
483 more sofisticated but it's currently not needed.
484 */
485 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
486 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
487 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
488 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
489 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
490 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
491 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
492 out->mode.hborder = x[15];
493 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
494 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
495 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
496 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
497 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700498
Julius Werner69112192016-03-14 17:29:55 -0700499 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700500 * Chipsets that want something else will need to override this with
501 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
502 * heuristic, assume that X86 systems require a 64-byte row alignment
503 * (since that seems to be true for most Intel chipsets). */
Kyösti Mälkki7336f972020-06-08 06:05:03 +0300504 if (ENV_X86)
Julius Werner2b6db972016-04-06 12:50:40 -0700505 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
506 else
507 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700508
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700509 switch ((x[17] & 0x18) >> 3) {
510 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700511 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700512 break;
513 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700514 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700515 break;
516 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700517 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700518 break;
519 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700520 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700521 break;
522 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700523 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
524 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700525 switch (x[17] & 0x61) {
526 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700527 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700528 break;
529 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700530 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700531 break;
532 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700533 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700534 break;
535 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700536 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700537 break;
538 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700539 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700540 break;
541 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700542 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700543 break;
544 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700545 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700546 break;
547 }
548
Lee Leahy73402172017-03-10 15:23:24 -0800549 printk(BIOS_SPEW,
550 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700551 " %04x %04x %04x %04x hborder %x\n"
552 " %04x %04x %04x %04x vborder %x\n"
Paul Menzel433bf772016-11-29 21:02:04 +0100553 " %chsync %cvsync%s%s%s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700554 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700555 extra_info.x_mm,
556 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700557 out->mode.ha, out->mode.ha + out->mode.hso,
558 out->mode.ha + out->mode.hso + out->mode.hspw,
559 out->mode.ha + out->mode.hbl, out->mode.hborder,
560 out->mode.va, out->mode.va + out->mode.vso,
561 out->mode.va + out->mode.vso + out->mode.vspw,
562 out->mode.va + out->mode.vbl, out->mode.vborder,
563 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800564 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700565 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700566
Lee Leahy35af5c42017-03-09 17:35:28 -0800567 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700568 printk(BIOS_SPEW, "Did detailed timing\n");
569 c->did_detailed_timing = 1;
570 *result_edid = *out;
571 }
572
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700573 return 1;
574}
575
576static int
577do_checksum(unsigned char *x)
578{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800579 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600580 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700581 {
582 unsigned char sum = 0;
583 int i;
584 for (i = 0; i < 128; i++)
585 sum += x[i];
586 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800587 printk(BIOS_SPEW, " (should be 0x%hhx)",
588 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700589 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800590 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700591 printk(BIOS_SPEW, " (valid)");
592 }
593 }
594 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800595 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700596}
597
598/* CEA extension */
599
600static const char *
601audio_format(unsigned char x)
602{
603 switch (x) {
604 case 0: return "RESERVED";
605 case 1: return "Linear PCM";
606 case 2: return "AC-3";
607 case 3: return "MPEG 1 (Layers 1 & 2)";
608 case 4: return "MPEG 1 Layer 3 (MP3)";
609 case 5: return "MPEG2 (multichannel)";
610 case 6: return "AAC";
611 case 7: return "DTS";
612 case 8: return "ATRAC";
613 case 9: return "One Bit Audio";
614 case 10: return "Dolby Digital+";
615 case 11: return "DTS-HD";
616 case 12: return "MAT (MLP)";
617 case 13: return "DST";
618 case 14: return "WMA Pro";
619 case 15: return "RESERVED";
620 }
621 return "BROKEN"; /* can't happen */
622}
623
624static void
625cea_audio_block(unsigned char *x)
626{
627 int i, format;
628 int length = x[0] & 0x1f;
629
630 if (length % 3) {
631 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
632 /* XXX non-conformant */
633 return;
634 }
635
636 for (i = 1; i < length; i += 3) {
637 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800638 printk(BIOS_SPEW, " %s, max channels %d\n",
639 audio_format(format), x[i] & 0x07);
640 printk(BIOS_SPEW,
641 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700642 (x[i+1] & 0x40) ? " 192" : "",
643 (x[i+1] & 0x20) ? " 176.4" : "",
644 (x[i+1] & 0x10) ? " 96" : "",
645 (x[i+1] & 0x08) ? " 88.2" : "",
646 (x[i+1] & 0x04) ? " 48" : "",
647 (x[i+1] & 0x02) ? " 44.1" : "",
648 (x[i+1] & 0x01) ? " 32" : "");
649 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800650 printk(BIOS_SPEW,
651 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700652 (x[2] & 0x04) ? " 24" : "",
653 (x[2] & 0x02) ? " 20" : "",
654 (x[2] & 0x01) ? " 16" : "");
655 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800656 printk(BIOS_SPEW,
657 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700658 }
659 }
660}
661
662static void
663cea_video_block(unsigned char *x)
664{
665 int i;
666 int length = x[0] & 0x1f;
667
668 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800669 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700670 x[i] & 0x80 ? "(native)" : "");
671}
672
673static void
674cea_hdmi_block(struct edid *out, unsigned char *x)
675{
676 int length = x[0] & 0x1f;
677
Yakir Yang85810cc2015-10-27 16:17:13 +0800678 out->hdmi_monitor_detected = 1;
679
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700680 printk(BIOS_SPEW, " (HDMI)\n");
681 printk(BIOS_SPEW,
682 " Source physical address %d.%d.%d.%d\n",
683 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
684
685 if (length > 5) {
686 if (x[6] & 0x80)
687 printk(BIOS_SPEW, " Supports_AI\n");
688 if (x[6] & 0x40)
689 printk(BIOS_SPEW, " DC_48bit\n");
690 if (x[6] & 0x20)
691 printk(BIOS_SPEW, " DC_36bit\n");
692 if (x[6] & 0x10)
693 printk(BIOS_SPEW, " DC_30bit\n");
694 if (x[6] & 0x08)
695 printk(BIOS_SPEW, " DC_Y444\n");
696 /* two reserved */
697 if (x[6] & 0x01)
698 printk(BIOS_SPEW, " DVI_Dual\n");
699 }
700
701 if (length > 6)
702 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
703
704 /* XXX the walk here is really ugly, and needs to be length-checked */
705 if (length > 7) {
706 int b = 0;
707
708 if (x[8] & 0x80) {
709 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
710 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
711 b += 2;
712 }
713
714 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800715 printk(BIOS_SPEW,
716 " Interlaced video latency: %d\n", x[9 + b]);
717 printk(BIOS_SPEW,
718 " Interlaced audio latency: %d\n",
719 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700720 b += 2;
721 }
722
723 if (x[8] & 0x20) {
724 int mask = 0, formats = 0;
725 int len_xx, len_3d;
726 printk(BIOS_SPEW, " Extended HDMI video details:\n");
727 if (x[9 + b] & 0x80)
728 printk(BIOS_SPEW, " 3D present\n");
729 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800730 printk(BIOS_SPEW,
731 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700732 formats = 1;
733 }
734 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800735 printk(BIOS_SPEW,
736 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700737 formats = 1;
738 mask = 1;
739 }
740 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800741 case 0x00:
742 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700743 case 0x08:
744 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
745 break;
746 case 0x10:
747 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
748 break;
749 case 0x18:
750 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
751 break;
752 }
753 len_xx = (x[10 + b] & 0xe0) >> 5;
754 len_3d = (x[10 + b] & 0x1f) >> 0;
755 b += 2;
756
757 if (len_xx) {
758 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
759 " document\n", len_xx);
760 b += len_xx;
761 }
762
763 if (len_3d) {
764 if (formats) {
765 if (x[9 + b] & 0x01)
766 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
767 if (x[10 + b] & 0x40)
768 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
769 if (x[10 + b] & 0x01)
770 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
771 b += 2;
772 }
773 if (mask) {
774 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800775 printk(BIOS_SPEW,
776 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700777 /* worst bit ordering ever */
778 for (i = 0; i < 8; i++)
779 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800780 printk(BIOS_SPEW,
781 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700782 for (i = 0; i < 8; i++)
783 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800784 printk(BIOS_SPEW,
785 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700786 printk(BIOS_SPEW, "\n");
787 b += 2;
788 }
789
790 /*
791 * XXX list of nibbles:
792 * 2D_VIC_Order_X
793 * 3D_Structure_X
794 * (optionally: 3D_Detail_X and reserved)
795 */
796 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700797 }
Richard Spiegel2fdbe0c2018-08-07 08:43:22 -0700798 /* Tell static analysis we know index b is left unused. */
799 (void)b;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700800 }
801}
802
803static void
804cea_block(struct edid *out, unsigned char *x)
805{
806 unsigned int oui;
807
808 switch ((x[0] & 0xe0) >> 5) {
809 case 0x01:
810 printk(BIOS_SPEW, " Audio data block\n");
811 cea_audio_block(x);
812 break;
813 case 0x02:
814 printk(BIOS_SPEW, " Video data block\n");
815 cea_video_block(x);
816 break;
817 case 0x03:
818 /* yes really, endianness lols */
819 oui = (x[3] << 16) + (x[2] << 8) + x[1];
Lee Leahy73402172017-03-10 15:23:24 -0800820 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
821 oui);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700822 if (oui == 0x000c03)
823 cea_hdmi_block(out, x);
824 else
825 printk(BIOS_SPEW, "\n");
826 break;
827 case 0x04:
828 printk(BIOS_SPEW, " Speaker allocation data block\n");
829 break;
830 case 0x05:
831 printk(BIOS_SPEW, " VESA DTC data block\n");
832 break;
833 case 0x07:
834 printk(BIOS_SPEW, " Extended tag: ");
835 switch (x[1]) {
836 case 0x00:
837 printk(BIOS_SPEW, "video capability data block\n");
838 break;
839 case 0x01:
840 printk(BIOS_SPEW, "vendor-specific video data block\n");
841 break;
842 case 0x02:
Lee Leahy73402172017-03-10 15:23:24 -0800843 printk(BIOS_SPEW,
844 "VESA video display device information data block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700845 break;
846 case 0x03:
847 printk(BIOS_SPEW, "VESA video data block\n");
848 break;
849 case 0x04:
850 printk(BIOS_SPEW, "HDMI video data block\n");
851 break;
852 case 0x05:
853 printk(BIOS_SPEW, "Colorimetry data block\n");
854 break;
855 case 0x10:
856 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
857 break;
858 case 0x11:
859 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
860 break;
861 case 0x12:
862 printk(BIOS_SPEW, "HDMI audio data block\n");
863 break;
864 default:
865 if (x[1] >= 6 && x[1] <= 15)
Lee Leahy73402172017-03-10 15:23:24 -0800866 printk(BIOS_SPEW,
867 "Reserved video block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700868 else if (x[1] >= 19 && x[1] <= 31)
Lee Leahy73402172017-03-10 15:23:24 -0800869 printk(BIOS_SPEW,
870 "Reserved audio block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700871 else
872 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
873 break;
874 }
875 break;
876 default:
877 {
878 int tag = (*x & 0xe0) >> 5;
879 int length = *x & 0x1f;
880 printk(BIOS_SPEW,
Lee Leahy73402172017-03-10 15:23:24 -0800881 " Unknown tag %d, length %d (raw %02x)\n",
882 tag, length, *x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700883 break;
884 }
885 }
886}
887
888static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800889parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700890{
891 int ret = 0;
892 int version = x[1];
893 int offset = x[2];
894 unsigned char *detailed;
895
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800896 if (version >= 1)
897 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700898 if (version == 1 && x[3] != 0)
899 ret = 1;
900
901 if (offset < 4)
902 break;
903
Lee Leahye20a3192017-03-09 16:21:34 -0800904 if (version < 3)
Lee Leahy73402172017-03-10 15:23:24 -0800905 printk(BIOS_SPEW,
906 "%d 8-byte timing descriptors\n",
907 (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800908 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700909 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800910 printk(BIOS_SPEW,
911 "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800912 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700913 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700914 }
915
916 if (version >= 2) {
917 if (x[3] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800918 printk(BIOS_SPEW,
919 "Underscans PC formats by default\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700920 if (x[3] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800921 printk(BIOS_SPEW,
922 "Basic audio support\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700923 if (x[3] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800924 printk(BIOS_SPEW,
925 "Supports YCbCr 4:4:4\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700926 if (x[3] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800927 printk(BIOS_SPEW,
928 "Supports YCbCr 4:2:2\n");
929 printk(BIOS_SPEW,
930 "%d native detailed modes\n",
931 x[3] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700932 }
933
Lee Leahy73402172017-03-10 15:23:24 -0800934 for (detailed = x + offset; detailed + 18 < x + 127;
935 detailed += 18)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700936 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800937 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700938 } while (0);
939
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800940 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700941 return ret;
942}
943
944/* generic extension code */
945
946static void
947extension_version(struct edid *out, unsigned char *x)
948{
949 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
950}
951
952static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800953parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700954{
955 int conformant_extension = 0;
956 printk(BIOS_SPEW, "\n");
957
Lee Leahy45fde702017-03-08 18:02:24 -0800958 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700959 case 0x02:
960 printk(BIOS_SPEW, "CEA extension block\n");
961 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800962 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700963 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800964 case 0x10:
965 printk(BIOS_SPEW, "VTB extension block\n");
966 break;
967 case 0x40:
968 printk(BIOS_SPEW, "DI extension block\n");
969 break;
970 case 0x50:
971 printk(BIOS_SPEW, "LS extension block\n");
972 break;
973 case 0x60:
974 printk(BIOS_SPEW, "DPVL extension block\n");
975 break;
976 case 0xF0:
977 printk(BIOS_SPEW, "Block map\n");
978 break;
979 case 0xFF:
980 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Jacob Garbere447aec2019-03-27 17:23:42 -0600981 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700982 default:
983 printk(BIOS_SPEW, "Unknown extension block\n");
984 break;
985 }
986
987 printk(BIOS_SPEW, "\n");
988
989 return conformant_extension;
990}
991
992static const struct {
993 int x, y, refresh;
994} established_timings[] = {
995 /* 0x23 bit 7 - 0 */
996 {720, 400, 70},
997 {720, 400, 88},
998 {640, 480, 60},
999 {640, 480, 67},
1000 {640, 480, 72},
1001 {640, 480, 75},
1002 {800, 600, 56},
1003 {800, 600, 60},
1004 /* 0x24 bit 7 - 0 */
1005 {800, 600, 72},
1006 {800, 600, 75},
1007 {832, 624, 75},
1008 {1280, 768, 87},
1009 {1024, 768, 60},
1010 {1024, 768, 70},
1011 {1024, 768, 75},
1012 {1280, 1024, 75},
1013 /* 0x25 bit 7*/
1014 {1152, 870, 75},
1015};
1016
1017static void print_subsection(const char *name, unsigned char *edid, int start,
1018 int end)
1019{
1020 int i;
1021
1022 printk(BIOS_SPEW, "%s:", name);
1023 for (i = strlen(name); i < 15; i++)
1024 printk(BIOS_SPEW, " ");
1025 for (i = start; i <= end; i++)
1026 printk(BIOS_SPEW, " %02x", edid[i]);
1027 printk(BIOS_SPEW, "\n");
1028}
1029
1030static void dump_breakdown(unsigned char *edid)
1031{
1032 printk(BIOS_SPEW, "Extracted contents:\n");
1033 print_subsection("header", edid, 0, 7);
1034 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001035 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001036 print_subsection("basic params", edid, 20, 24);
1037 print_subsection("chroma info", edid, 25, 34);
1038 print_subsection("established", edid, 35, 37);
1039 print_subsection("standard", edid, 38, 53);
1040 print_subsection("descriptor 1", edid, 54, 71);
1041 print_subsection("descriptor 2", edid, 72, 89);
1042 print_subsection("descriptor 3", edid, 90, 107);
1043 print_subsection("descriptor 4", edid, 108, 125);
1044 print_subsection("extensions", edid, 126, 126);
1045 print_subsection("checksum", edid, 127, 127);
1046 printk(BIOS_SPEW, "\n");
1047}
1048
1049/*
David Hendrickse2054102015-08-07 18:41:37 -07001050 * Lookup table of some well-known modes that can be useful in case the
1051 * auto-detected mode is unsuitable.
1052 * ha = hdisplay; va = vdisplay;
1053 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1054 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1055 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1056 */
1057static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1058 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001059 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001060 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001061 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1062 .phsync = '-', .pvsync = '-' },
1063 [EDID_MODE_720x480_60Hz] = {
1064 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001065 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001066 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1067 .phsync = '-', .pvsync = '-' },
1068 [EDID_MODE_1280x720_60Hz] = {
1069 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001070 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001071 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1072 .phsync = '+', .pvsync = '+' },
1073 [EDID_MODE_1920x1080_60Hz] = {
1074 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001075 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001076 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1077 .phsync = '+', .pvsync = '+' },
1078};
1079
1080int set_display_mode(struct edid *edid, enum edid_modes mode)
1081{
1082 if (mode == EDID_MODE_AUTO)
1083 return 0;
1084
1085 if (edid->mode_is_supported[mode]) {
1086 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1087 edid->mode = known_modes[mode];
1088 return 0;
1089 }
1090
1091 printk(BIOS_ERR, "Requested display mode not supported.\n");
1092 return -1;
1093}
1094
1095/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001096 * Given a raw edid bloc, decode it into a form
1097 * that other parts of coreboot can use -- mainly
1098 * graphics bringup functions. The raw block is
1099 * required to be 128 bytes long, per the standard,
1100 * but we have no way of checking this minimum length.
1101 * We accept what we are given.
1102 */
1103int decode_edid(unsigned char *edid, int size, struct edid *out)
1104{
David Hendrickse2054102015-08-07 18:41:37 -07001105 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001106 struct edid_context c = {
1107 .has_valid_cvt = 1,
1108 .has_valid_dummy_block = 1,
1109 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001110 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001111 .has_valid_descriptor_pad = 1,
1112 .has_valid_range_descriptor = 1,
1113 .has_valid_max_dotclock = 1,
1114 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001115 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001116 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001117
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001118 if (!edid) {
Jacob Garber18553292019-03-27 12:02:38 -06001119 printk(BIOS_ERR, "No EDID found\n");
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001120 return EDID_ABSENT;
1121 }
1122
1123 dump_breakdown(edid);
1124
1125 if (memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
Jacob Garber18553292019-03-27 12:02:38 -06001126 printk(BIOS_ERR, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001127 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001128 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001129
Paul Menzel1ced4e62020-02-15 13:12:04 +01001130 memset(out, 0, sizeof(*out));
1131
Hung-Te Lin6673e8e2019-08-13 12:06:27 +08001132 if (manufacturer_name(edid + 0x08, out->manufacturer_name))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001133 c.manufacturer_name_well_formed = 1;
1134
David Hendricksa3b898a2015-08-02 18:07:48 -07001135 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1136 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001137 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1138
1139 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
Hung-Te Lin6673e8e2019-08-13 12:06:27 +08001140 out->manufacturer_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001141 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1142 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1143 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001144 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001145
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001146 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001147 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001148 if (edid[0x11] > 0x0f) {
1149 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001150 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001151 printk(BIOS_SPEW,
1152 "Made week %hhd of model year %hhd\n",
1153 edid[0x10], edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001154 extra_info.week = edid[0x10];
1155 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001156 } else {
Lee Leahy73402172017-03-10 15:23:24 -08001157 /* we know it's at least 2013, when this code
1158 * was written
1159 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001160 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001161 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001162 printk(BIOS_SPEW,
1163 "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001164 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001165 extra_info.week = edid[0x10];
1166 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001167 }
1168 }
1169 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001170 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001171
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001172 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001173 extra_info.version[0] = edid[0x12];
1174 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001175
1176 if (edid[0x12] == 1) {
1177 if (edid[0x13] > 4) {
Lee Leahy73402172017-03-10 15:23:24 -08001178 printk(BIOS_SPEW,
1179 "Claims > 1.4, assuming 1.4 conformance\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001180 edid[0x13] = 4;
1181 }
1182 switch (edid[0x13]) {
1183 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001184 c.claims_one_point_four = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001185 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001186 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001187 c.claims_one_point_three = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001188 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001189 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001190 c.claims_one_point_two = 1;
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001191 /* fall through */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001192 default:
Jacob Garber4c33a3a2019-07-12 10:34:06 -06001193 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001194 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001195 }
1196
1197 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001198 if (edid[0x14] & 0x80) {
1199 int conformance_mask;
1200 analog = 0;
1201 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001202 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001203 conformance_mask = 0;
1204 if ((edid[0x14] & 0x70) == 0x00)
1205 printk(BIOS_SPEW, "Color depth is undefined\n");
1206 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001207 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001208 else
Lee Leahy73402172017-03-10 15:23:24 -08001209 printk(BIOS_SPEW,
1210 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001211 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001212 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1213 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001214 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001215
1216 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001217 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001218 printk(BIOS_SPEW,
1219 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001220 break;
1221 case 0x01:
1222 printk(BIOS_SPEW, "DVI interface\n");
1223 break;
1224 case 0x02:
1225 printk(BIOS_SPEW, "HDMI-a interface\n");
1226 break;
1227 case 0x03:
1228 printk(BIOS_SPEW, "HDMI-b interface\n");
1229 break;
1230 case 0x04:
1231 printk(BIOS_SPEW, "MDDI interface\n");
1232 break;
1233 case 0x05:
1234 printk(BIOS_SPEW, "DisplayPort interface\n");
1235 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001236 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001237 c.nonconformant_digital_display = 1;
1238 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001239 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001240 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001241 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001242 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001243 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001244 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001245 } else
1246 conformance_mask = 0x7F;
1247
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001248 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001249 c.nonconformant_digital_display = edid[0x14]
1250 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001251 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001252 } else {
1253 analog = 1;
1254 int voltage = (edid[0x14] & 0x60) >> 5;
1255 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001256 extra_info.voltage = voltage;
1257 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001258
1259 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1260 voltage == 3 ? "0.7/0.7" :
1261 voltage == 2 ? "1.0/0.4" :
1262 voltage == 1 ? "0.714/0.286" :
1263 "0.7/0.3");
1264
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001265 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001266 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001267 printk(BIOS_SPEW,
1268 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001269 else
Lee Leahy73402172017-03-10 15:23:24 -08001270 printk(BIOS_SPEW,
1271 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001272 } else if (edid[0x14] & 0x10) {
1273 /*
Lee Leahy73402172017-03-10 15:23:24 -08001274 * XXX this is just the X text. 1.3 says "if set,
1275 * display expects a blank-to-black setup or pedestal
1276 * per appropriate Signal Level Standard". Whatever
1277 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001278 */
1279 printk(BIOS_SPEW, "Configurable signal levels\n");
1280 }
1281
Lee Leahy73402172017-03-10 15:23:24 -08001282 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1283 sync & 0x08 ? "Separate " : "",
1284 sync & 0x04 ? "Composite " : "",
1285 sync & 0x02 ? "SyncOnGreen " : "",
1286 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001287 }
1288
1289
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001290 if (edid[0x15] && edid[0x16]) {
1291 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1292 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001293 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001294 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1295 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001296 printk(BIOS_SPEW,
1297 "Aspect ratio is %u.%03u (landscape)\n",
1298 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001299 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1300 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001301 printk(BIOS_SPEW,
1302 "Aspect ratio is %u.%03u (portrait)\n",
1303 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001304 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001305 } else {
1306 /* Either or both can be zero for 1.3 and before */
1307 printk(BIOS_SPEW, "Image size is variable\n");
1308 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001309
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001310 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001311 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001312 printk(BIOS_SPEW,
1313 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001314 else
1315 /* XXX Technically 1.3 doesn't say this... */
1316 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001317 } else
1318 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001319 printk(BIOS_SPEW, "Check DPMS levels\n");
1320 if (edid[0x18] & 0xE0) {
1321 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001322 if (edid[0x18] & 0x80)
1323 printk(BIOS_SPEW, " Standby");
1324 if (edid[0x18] & 0x40)
1325 printk(BIOS_SPEW, " Suspend");
1326 if (edid[0x18] & 0x20)
1327 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001328 printk(BIOS_SPEW, "\n");
1329 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001330
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001331 /* FIXME: this is from 1.4 spec, check earlier */
1332 if (analog) {
1333 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001334 case 0x00:
1335 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1336 break;
1337 case 0x08:
1338 printk(BIOS_SPEW, "RGB color display\n");
1339 break;
1340 case 0x10:
1341 printk(BIOS_SPEW, "Non-RGB color display\n");
1342 break;
1343 case 0x18:
1344 printk(BIOS_SPEW, "Undefined display color type\n");
1345 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001346 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001347 } else {
1348 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1349 if (edid[0x18] & 0x10)
1350 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1351 if (edid[0x18] & 0x08)
1352 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1353 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001354 }
1355
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001356 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001357 printk(BIOS_SPEW,
1358 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001359 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001360 printk(BIOS_SPEW,
1361 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001362 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001363 }
1364 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001365 printk(BIOS_SPEW,
1366 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001367
1368 /* XXX color section */
1369
1370 printk(BIOS_SPEW, "Established timings supported:\n");
1371 /* it's not yet clear we want all this stuff in the edid struct.
1372 * Let's wait.
1373 */
1374 for (i = 0; i < 17; i++) {
1375 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001376 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1377 established_timings[i].x,
1378 established_timings[i].y,
1379 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001380
Douglas Anderson9fa07602015-10-28 10:19:52 -07001381 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001382 if (known_modes[j].ha ==
1383 established_timings[i].x
1384 && known_modes[j].va ==
1385 established_timings[i].y
1386 && known_modes[j].refresh ==
1387 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001388 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001389 }
David Hendrickse2054102015-08-07 18:41:37 -07001390 }
1391
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001392 }
1393
1394 printk(BIOS_SPEW, "Standard timings supported:\n");
1395 for (i = 0; i < 8; i++) {
1396 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1397 unsigned int x, y = 0, refresh;
1398
1399 if (b1 == 0x01 && b2 == 0x01)
1400 continue;
1401
1402 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001403 printk(BIOS_SPEW,
1404 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001405 continue;
1406 }
1407 x = (b1 + 31) * 8;
1408 switch ((b2 >> 6) & 0x3) {
1409 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001410 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001411 y = x * 10 / 16;
1412 else
1413 y = x;
1414 break;
1415 case 0x01:
1416 y = x * 3 / 4;
1417 break;
1418 case 0x02:
1419 y = x * 4 / 5;
1420 break;
1421 case 0x03:
1422 y = x * 9 / 16;
1423 break;
1424 }
1425 refresh = 60 + (b2 & 0x3f);
1426
1427 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001428 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1429 if (known_modes[j].ha == x && known_modes[j].va == y &&
1430 known_modes[j].refresh == refresh)
1431 out->mode_is_supported[j] = 1;
1432 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001433 }
1434
1435 /* detailed timings */
1436 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001437 for (i = 0; i < 4; i++) {
1438 c.has_valid_detailed_blocks &= detailed_block(
1439 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001440 if (i == 0 && c.has_preferred_timing
1441 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001442 /* not really accurate... */
1443 c.has_preferred_timing = 0;
1444 }
1445 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001446
1447 /* check this, 1.4 verification guide says otherwise */
1448 if (edid[0x7e]) {
1449 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1450 /* 2 is impossible because of the block map */
1451 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001452 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001453 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001454 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001455 }
1456
1457 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001458 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001459
1460 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1461 * the extension parsing loop below. Since v2.0 was quickly deprecated
1462 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1463 * that case now and can fix it when we need to use a real 2.0 panel.
1464 */
Lee Leahy45fde702017-03-08 18:02:24 -08001465 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001466 c.nonconformant_extension +=
1467 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001468
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001469 if (c.claims_one_point_four) {
1470 if (c.nonconformant_digital_display ||
1471 !c.has_valid_string_termination ||
1472 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001473 !c.has_preferred_timing) {
1474 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001475 printk(BIOS_ERR,
1476 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001477 }
1478
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001479 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001480 printk(BIOS_ERR,
1481 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001482 c.nonconformant_digital_display);
1483 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001484 printk(BIOS_ERR,
1485 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001486 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001487 printk(BIOS_ERR,
1488 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001489 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001490 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001491 } else if (c.claims_one_point_three) {
1492 if (c.nonconformant_digital_display ||
1493 !c.has_valid_string_termination ||
1494 !c.has_valid_descriptor_pad ||
1495 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001496 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001497 }
1498 /**
1499 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1500 * has_range_descriptor are both required. These fields are
1501 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1502 * don't have them. As a workaround, we only print warning
1503 * messages.
1504 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001505 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001506 printk(BIOS_ERR,
1507 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001508 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001509 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1510 "fully conform to EDID 1.3.\n");
1511
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001512 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001513 printk(BIOS_ERR,
1514 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001515 c.nonconformant_digital_display);
1516 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001517 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001518 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001519 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001520 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001521 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001522 /* Might be more than just 1.3 */
1523 if (!c.has_valid_descriptor_pad)
1524 printk(BIOS_ERR,
1525 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001526 if (!c.has_valid_string_termination) /* Likewise */
Lee Leahy73402172017-03-10 15:23:24 -08001527 printk(BIOS_ERR,
1528 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001529 } else if (c.claims_one_point_two) {
1530 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001531 !c.has_valid_string_termination) {
1532 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001533 printk(BIOS_ERR,
1534 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001535 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001536 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001537 printk(BIOS_ERR,
1538 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001539 c.nonconformant_digital_display);
1540 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001541 printk(BIOS_ERR,
1542 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001543 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001544 if (c.seen_non_detailed_descriptor) {
1545 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001546 printk(BIOS_ERR,
1547 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001548 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001549 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001550 printk(BIOS_ERR,
1551 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001552 }
1553
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001554 if (c.nonconformant_extension ||
1555 !c.has_valid_checksum ||
1556 !c.has_valid_cvt ||
1557 !c.has_valid_year ||
1558 !c.has_valid_week ||
1559 !c.has_valid_detailed_blocks ||
1560 !c.has_valid_dummy_block ||
1561 !c.has_valid_extension_count ||
1562 !c.has_valid_descriptor_ordering ||
1563 !c.has_valid_range_descriptor ||
1564 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001565 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001566 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001567 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001568 printk(BIOS_ERR,
1569 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001570 c.nonconformant_extension);
1571 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001572 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001573 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001574 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001575 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001576 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001577 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001578 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001579 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001580 printk(BIOS_ERR,
1581 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001582 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001583 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001584 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001585 printk(BIOS_ERR,
1586 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001587 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001588 printk(BIOS_ERR,
1589 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001590 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001591 printk(BIOS_ERR,
1592 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001593 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001594 printk(BIOS_ERR,
1595 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001596 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001597 printk(BIOS_ERR,
1598 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001599 }
1600
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001601 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001602 printk(BIOS_ERR,
1603 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001604 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001605 printk(BIOS_ERR,
1606 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001607 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001608}
1609
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001610/*
1611 * Notes on panel extensions: (TODO, implement me in the code)
1612 *
1613 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1614 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1615 * 0x6c: 00 00 00 0e 00
1616 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1617 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1618 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1619 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1620 * bit 4: DE polarity (0 high active 1 low active)
1621 * bit 3-0: interface (0000 LVDS TFT
1622 * 0001 mono STN 4/8bit
1623 * 0010 color STN 8/16 bit
1624 * 0011 18 bit tft
1625 * 0100 24 bit tft
1626 * 0101 tmds
1627 * else reserved)
1628 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1629 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1630 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1631 * else time in 10ms (10ms to 150ms))
1632 * bit 3-0: total poweron seq delay (as above)
1633 * 0x75: contrast power on/off seq delay, same as 0x74
1634 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1635 * bit 6: backlight enabled at boot (0 on 1 off)
1636 * bit 5-0: backlight brightness control steps (0..63)
1637 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1638 * 0x78 - 0x7c: reserved
1639 * 0x7d: bit 7-4: EPI descriptor major version (1)
1640 * bit 3-0: EPI descriptor minor version (0)
1641 *
1642 * ----
1643 *
1644 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1645 *
1646 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1647 *
1648 * detailed descriptor 3:
1649 * 0x5a - 0x5e: 00 00 00 fe 00
1650 * 0x5f - 0x63: PC maker part number
1651 * 0x64: LCD supplier revision #
1652 * 0x65 - 0x6b: manufacturer part number
1653 *
1654 * detailed descriptor 4:
1655 * 0x6c - 0x70: 00 00 00 fe 00
1656 * 0x71 - 0x78: smbus nits values (whut)
1657 * 0x79: number of lvds channels (1 or 2)
1658 * 0x7A: panel self test (1 if present)
1659 * and then dummy terminator
1660 *
1661 * SPWG also says something strange about the LSB of detailed descriptor 1:
1662 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1663 */
Julius Werner69112192016-03-14 17:29:55 -07001664
1665/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001666void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1667 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001668{
1669 /* Caller should pass a supported value, everything else is BUG(). */
1670 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Elyes HAOUASba9b5042019-12-19 07:47:52 +01001671 row_byte_alignment = MAX(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001672
1673 edid->framebuffer_bits_per_pixel = fb_bpp;
1674 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Elyes HAOUAS6df3b642018-11-26 22:53:49 +01001675 DIV_ROUND_UP(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001676 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1677 edid->y_resolution = edid->mode.va;
1678}