blob: 7ad41368148e5fca69a5481f6f4cff4693df23ce [file] [log] [blame]
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001/*
2 * Copyright 2013 Google Inc.
3 * Copyright 2006-2012 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23/* Author: Adam Jackson <ajax@nwnk.net> */
24
25/* this is a pretty robust parser for EDID, and we're tasked with parsing
26 * an arbitrary panel. We will pass it a raw EDID block and a struct which
27 * it must fill in with values. The set of values we need is pretty limited
28 * at present.
29 */
30
Julius Werner69112192016-03-14 17:29:55 -070031#include <assert.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070032#include <stddef.h>
33#include <console/console.h>
34#include <arch/io.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070035#include <stdint.h>
36#include <string.h>
37#include <stdlib.h>
38#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070039#include <boot/coreboot_tables.h>
40#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070041
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080042struct edid_context {
43 int claims_one_point_oh;
44 int claims_one_point_two;
45 int claims_one_point_three;
46 int claims_one_point_four;
47 int nonconformant_digital_display;
48 int nonconformant_extension;
49 int did_detailed_timing;
50 int has_name_descriptor;
51 int has_range_descriptor;
52 int has_preferred_timing;
53 int has_valid_checksum;
54 int has_valid_cvt;
55 int has_valid_dummy_block;
56 int has_valid_week;
57 int has_valid_year;
58 int has_valid_detailed_blocks;
59 int has_valid_extension_count;
60 int has_valid_descriptor_ordering;
61 int has_valid_descriptor_pad;
62 int has_valid_range_descriptor;
63 int has_valid_max_dotclock;
64 int has_valid_string_termination;
65 int manufacturer_name_well_formed;
66 int seen_non_detailed_descriptor;
67 int warning_excessive_dotclock_correction;
68 int warning_zero_preferred_refresh;
Arthur Heymans8c5884e2017-04-30 08:28:05 +020069 enum edid_status conformant;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080070};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070071
David Hendricksa3b898a2015-08-02 18:07:48 -070072/* Stuff that isn't used anywhere but is nice to pretty-print while
73 we're decoding everything else. */
74static struct {
75 char manuf_name[4];
76 unsigned int model;
77 unsigned int serial;
78 unsigned int year;
79 unsigned int week;
80 unsigned int version[2];
81 unsigned int nonconformant;
82 unsigned int type;
83
84 unsigned int x_mm;
85 unsigned int y_mm;
86
87 unsigned int voltage;
88 unsigned int sync;
89
90 const char *syncmethod;
91 const char *range_class;
92 const char *stereo;
93} extra_info;
94
Douglas Andersonbca67fb2015-10-28 09:18:28 -070095static struct edid tmp_edid;
96
David Hendricksa3b898a2015-08-02 18:07:48 -070097static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070098{
David Hendricksa3b898a2015-08-02 18:07:48 -070099 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
Lee Leahy73402172017-03-10 15:23:24 -0800100 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5)
101 + '@';
David Hendricksa3b898a2015-08-02 18:07:48 -0700102 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
103 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700104
David Hendricksa3b898a2015-08-02 18:07:48 -0700105 if (isupper(extra_info.manuf_name[0]) &&
106 isupper(extra_info.manuf_name[1]) &&
107 isupper(extra_info.manuf_name[2]))
108 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700109
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800110 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700111}
112
113static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700114detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700115{
116 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -0800117 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700118 int width = 0, height = 0;
119 int valid = 1;
120 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
121
122 if (!first && !memcmp(x, empty, 3))
123 return valid;
124
125 height = x[0];
126 height |= (x[1] & 0xf0) << 4;
127 height++;
128 height *= 2;
129
130 switch (x[1] & 0x0c) {
131 case 0x00:
132 width = (height * 4) / 3; break;
133 case 0x04:
134 width = (height * 16) / 9; break;
135 case 0x08:
136 width = (height * 16) / 10; break;
137 case 0x0c:
138 width = (height * 15) / 9; break;
139 }
140
141 if (x[1] & 0x03)
142 valid = 0;
143 if (x[2] & 0x80)
144 valid = 0;
145 if (!(x[2] & 0x1f))
146 valid = 0;
147
148 fifty = (x[2] & 0x10);
149 sixty = (x[2] & 0x08);
150 seventyfive = (x[2] & 0x04);
151 eightyfive = (x[2] & 0x02);
152 reduced = (x[2] & 0x01);
153
154 if (!valid) {
155 printk(BIOS_SPEW, " (broken)\n");
156 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800157 printk(BIOS_SPEW,
158 " %dx%d @ ( %s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700159 width, height,
160 fifty ? "50 " : "",
161 sixty ? "60 " : "",
162 seventyfive ? "75 " : "",
163 eightyfive ? "85 " : "",
164 reduced ? "60RB " : "",
165 names[(x[2] & 0x60) >> 5],
166 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
167 }
168
169 return valid;
170}
171
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800172/* extract a CP437 string from a detailed subblock, checking for termination (if
173 * less than len of bytes) with LF and padded with SP.
174 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700175static char *
176extract_string(unsigned char *x, int *valid_termination, int len)
177{
178 static char ret[128];
179 int i, seen_newline = 0;
180
181 memset(ret, 0, sizeof(ret));
182
183 for (i = 0; i < len; i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800184 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700185 if (x[i] != 0x20) {
186 *valid_termination = 0;
187 return ret;
188 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800189 } else if (x[i] == 0x0a) {
190 seen_newline = 1;
191 } else {
192 /* normal characters */
193 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700194 }
195 }
196
197 return ret;
198}
199
200/* 1 means valid data */
201static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700202detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800203 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700204{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700205 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700206 int i;
207#if 1
208 printk(BIOS_SPEW, "Hex of detail: ");
209 for (i = 0; i < 18; i++)
210 printk(BIOS_SPEW, "%02x", x[i]);
211 printk(BIOS_SPEW, "\n");
212#endif
213
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700214 /* Result might already have some valid fields like mode_is_supported */
215 *out = *result_edid;
216
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700217 if (x[0] == 0 && x[1] == 0) {
218 /* Monitor descriptor block, not detailed timing descriptor. */
219 if (x[2] != 0) {
220 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800221 printk(BIOS_SPEW,
222 "Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700223 x[2]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800224 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700225 }
226 if (x[3] != 0xfd && x[4] != 0x00) {
227 /* 1.3, 3.10.3 */
Lee Leahy73402172017-03-10 15:23:24 -0800228 printk(BIOS_SPEW,
229 "Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700230 x[4]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800231 c->has_valid_descriptor_pad = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700232 }
233
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800234 c->seen_non_detailed_descriptor = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700235 if (x[3] <= 0xF) {
236 /*
Lee Leahy73402172017-03-10 15:23:24 -0800237 * in principle we can decode these, if we know what
238 * they are.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700239 * 0x0f seems to be common in laptop panels.
240 * 0x0e is used by EPI: http://www.epi-standard.org/
241 */
Lee Leahy73402172017-03-10 15:23:24 -0800242 printk(BIOS_SPEW,
243 "Manufacturer-specified data, tag %d\n", x[3]);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800244 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700245 }
246 switch (x[3]) {
247 case 0x10:
248 printk(BIOS_SPEW, "Dummy block\n");
249 for (i = 5; i < 18; i++)
250 if (x[i] != 0x00)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800251 c->has_valid_dummy_block = 0;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800252 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700253 case 0xF7:
254 /* TODO */
255 printk(BIOS_SPEW, "Established timings III\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800256 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700257 case 0xF8:
258 {
259 int valid_cvt = 1; /* just this block */
260 printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
261 if (x[5] != 0x01) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800262 c->has_valid_cvt = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700263 return 0;
264 }
265 for (i = 0; i < 4; i++)
Lee Leahy73402172017-03-10 15:23:24 -0800266 valid_cvt &= detailed_cvt_descriptor(x + 6
267 + (i * 3), (i == 0));
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800268 c->has_valid_cvt &= valid_cvt;
Hung-Te Linb2c10622014-04-03 19:59:37 +0800269 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700270 }
271 case 0xF9:
272 /* TODO */
273 printk(BIOS_SPEW, "Color management data\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800274 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700275 case 0xFA:
276 /* TODO */
277 printk(BIOS_SPEW, "More standard timings\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800278 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700279 case 0xFB:
280 /* TODO */
281 printk(BIOS_SPEW, "Color point\n");
Hung-Te Linb2c10622014-04-03 19:59:37 +0800282 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700283 case 0xFC:
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800284 printk(BIOS_SPEW, "Monitor name: %s\n",
285 extract_string(x + 5,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800286 &c->has_valid_string_termination,
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800287 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800288 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700289 case 0xFD:
290 {
291 int h_max_offset = 0, h_min_offset = 0;
292 int v_max_offset = 0, v_min_offset = 0;
293 int is_cvt = 0;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800294 c->has_range_descriptor = 1;
David Hendricksa3b898a2015-08-02 18:07:48 -0700295 extra_info.range_class = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700296 /*
297 * XXX todo: implement feature flags, vtd blocks
Lee Leahy73402172017-03-10 15:23:24 -0800298 * XXX check: ranges are well-formed; block termination
299 * if no vtd
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700300 */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800301 if (c->claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700302 if (x[4] & 0x02) {
303 v_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800304 if (x[4] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700305 v_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700306 }
307 if (x[4] & 0x04) {
308 h_max_offset = 255;
Lee Leahy2f919ec2017-03-08 17:37:06 -0800309 if (x[4] & 0x03)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700310 h_min_offset = 255;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700311 }
312 } else if (x[4]) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800313 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700314 }
315
316 /*
317 * despite the values, this is not a bitfield.
318 */
319 switch (x[10]) {
320 case 0x00: /* default gtf */
David Hendricksa3b898a2015-08-02 18:07:48 -0700321 extra_info.range_class = "GTF";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700322 break;
323 case 0x01: /* range limits only */
David Hendricksa3b898a2015-08-02 18:07:48 -0700324 extra_info.range_class = "bare limits";
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800325 if (!c->claims_one_point_four)
326 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700327 break;
328 case 0x02: /* secondary gtf curve */
David Hendricksa3b898a2015-08-02 18:07:48 -0700329 extra_info.range_class = "GTF with icing";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700330 break;
331 case 0x04: /* cvt */
David Hendricksa3b898a2015-08-02 18:07:48 -0700332 extra_info.range_class = "CVT";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700333 is_cvt = 1;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800334 if (!c->claims_one_point_four)
335 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700336 break;
337 default: /* invalid */
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800338 c->has_valid_range_descriptor = 0;
David Hendricksa3b898a2015-08-02 18:07:48 -0700339 extra_info.range_class = "invalid";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700340 break;
341 }
342
343 if (x[5] + v_min_offset > x[6] + v_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800344 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700345 if (x[7] + h_min_offset > x[8] + h_max_offset)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800346 c->has_valid_range_descriptor = 0;
Lee Leahy73402172017-03-10 15:23:24 -0800347 printk(BIOS_SPEW,
348 "Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
David Hendricksa3b898a2015-08-02 18:07:48 -0700349 extra_info.range_class,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700350 x[5] + v_min_offset, x[6] + v_max_offset,
351 x[7] + h_min_offset, x[8] + h_max_offset);
352 if (x[9])
Lee Leahy73402172017-03-10 15:23:24 -0800353 printk(BIOS_SPEW,
354 ", max dotclock %dMHz\n", x[9] * 10);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700355 else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800356 if (c->claims_one_point_four)
357 c->has_valid_max_dotclock = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700358 printk(BIOS_SPEW, "\n");
359 }
360
361 if (is_cvt) {
362 int max_h_pixels = 0;
363
Lee Leahy73402172017-03-10 15:23:24 -0800364 printk(BIOS_SPEW, "CVT version %d.%d\n",
365 x[11] & 0xf0 >> 4, x[11] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700366
367 if (x[12] & 0xfc) {
368 int raw_offset = (x[12] & 0xfc) >> 2;
Lee Leahy73402172017-03-10 15:23:24 -0800369 printk(BIOS_SPEW,
370 "Real max dotclock: %dKHz\n",
371 (x[9] * 10000)
372 - (raw_offset * 250));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700373 if (raw_offset >= 40)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800374 c->warning_excessive_dotclock_correction = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700375 }
376
377 max_h_pixels = x[12] & 0x03;
378 max_h_pixels <<= 8;
379 max_h_pixels |= x[13];
380 max_h_pixels *= 8;
381 if (max_h_pixels)
Lee Leahy73402172017-03-10 15:23:24 -0800382 printk(BIOS_SPEW,
383 "Max active pixels per line: %d\n",
384 max_h_pixels);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700385
Lee Leahy73402172017-03-10 15:23:24 -0800386 printk(BIOS_SPEW,
387 "Supported aspect ratios: %s %s %s %s %s\n",
388 x[14] & 0x80 ? "4:3" : "",
389 x[14] & 0x40 ? "16:9" : "",
390 x[14] & 0x20 ? "16:10" : "",
391 x[14] & 0x10 ? "5:4" : "",
392 x[14] & 0x08 ? "15:9" : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700393 if (x[14] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800394 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700395
396 printk(BIOS_SPEW, "Preferred aspect ratio: ");
Lee Leahy45fde702017-03-08 18:02:24 -0800397 switch ((x[15] & 0xe0) >> 5) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800398 case 0x00:
399 printk(BIOS_SPEW, "4:3");
400 break;
401 case 0x01:
402 printk(BIOS_SPEW, "16:9");
403 break;
404 case 0x02:
405 printk(BIOS_SPEW, "16:10");
406 break;
407 case 0x03:
408 printk(BIOS_SPEW, "5:4");
409 break;
410 case 0x04:
411 printk(BIOS_SPEW, "15:9");
412 break;
413 default:
414 printk(BIOS_SPEW, "(broken)");
415 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700416 }
417 printk(BIOS_SPEW, "\n");
418
419 if (x[15] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -0800420 printk(BIOS_SPEW,
421 "Supports CVT standard blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700422 if (x[15] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800423 printk(BIOS_SPEW,
424 "Supports CVT reduced blanking\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700425
426 if (x[15] & 0x07)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800427 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700428
429 if (x[16] & 0xf0) {
Lee Leahy73402172017-03-10 15:23:24 -0800430 printk(BIOS_SPEW,
431 "Supported display scaling:\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700432 if (x[16] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800433 printk(BIOS_SPEW,
434 " Horizontal shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700435 if (x[16] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800436 printk(BIOS_SPEW,
437 " Horizontal stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700438 if (x[16] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800439 printk(BIOS_SPEW,
440 " Vertical shrink\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700441 if (x[16] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800442 printk(BIOS_SPEW,
443 " Vertical stretch\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700444 }
445
446 if (x[16] & 0x0f)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800447 c->has_valid_range_descriptor = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700448
449 if (x[17])
Lee Leahy73402172017-03-10 15:23:24 -0800450 printk(BIOS_SPEW,
451 "Preferred vertical refresh: %d Hz\n",
452 x[17]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700453 else
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800454 c->warning_zero_preferred_refresh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700455 }
456
457 /*
Lee Leahy73402172017-03-10 15:23:24 -0800458 * Slightly weird to return a global, but I've never
459 * seen any EDID block wth two range descriptors, so
460 * it's harmless.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700461 */
Hung-Te Linb2c10622014-04-03 19:59:37 +0800462 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700463 }
464 case 0xFE:
465 /*
Lee Leahy73402172017-03-10 15:23:24 -0800466 * TODO: Two of these in a row, in the third and fourth
467 * slots, seems to be specified by SPWG:
468 * http://www.spwg.org/
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700469 */
Arthur Heymansdbe81612017-04-29 14:00:47 +0200470 strcpy(result_edid->ascii_string, extract_string(x + 5,
471 &c->has_valid_string_termination,
472 EDID_ASCII_STRING_LENGTH));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700473 printk(BIOS_SPEW, "ASCII string: %s\n",
Arthur Heymansdbe81612017-04-29 14:00:47 +0200474 result_edid->ascii_string);
Hung-Te Linb2c10622014-04-03 19:59:37 +0800475 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700476 case 0xFF:
477 printk(BIOS_SPEW, "Serial number: %s\n",
Lee Leahy73402172017-03-10 15:23:24 -0800478 extract_string(x + 5,
479 &c->has_valid_string_termination, 13));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800480 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700481 default:
Lee Leahy73402172017-03-10 15:23:24 -0800482 printk(BIOS_SPEW,
483 "Unknown monitor description type %d\n",
484 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700485 return 0;
486 }
487 }
488
Lee Leahy2f919ec2017-03-08 17:37:06 -0800489 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800490 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700491
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700492 /* Edid contains pixel clock in terms of 10KHz */
493 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
494 /*
495 LVDS supports following pixel clocks
496 25000...112000 kHz: single channel
497 80000...224000 kHz: dual channel
498 There is some overlap in theoretically supported
499 pixel clock between single-channel and dual-channel.
500 In practice with current panels all panels
501 <= 75200 kHz: single channel
502 >= 97750 kHz: dual channel
503 We have no samples between those values, so put a
504 threshold at 95000 kHz. If we get anything over
505 95000 kHz with single channel, we can make this
506 more sofisticated but it's currently not needed.
507 */
508 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
509 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
510 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
511 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
512 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
513 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
514 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
515 out->mode.hborder = x[15];
516 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
517 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
518 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
519 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
520 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700521
Julius Werner69112192016-03-14 17:29:55 -0700522 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700523 * Chipsets that want something else will need to override this with
524 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
525 * heuristic, assume that X86 systems require a 64-byte row alignment
526 * (since that seems to be true for most Intel chipsets). */
527 if (IS_ENABLED(CONFIG_ARCH_X86))
528 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
529 else
530 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700531
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700532 switch ((x[17] & 0x18) >> 3) {
533 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700534 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700535 break;
536 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700537 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700538 break;
539 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700540 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700541 break;
542 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700543 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700544 break;
545 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700546 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
547 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700548 switch (x[17] & 0x61) {
549 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700550 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700551 break;
552 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700553 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700554 break;
555 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700556 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700557 break;
558 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700559 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700560 break;
561 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700562 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700563 break;
564 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700565 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700566 break;
567 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700568 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700569 break;
570 }
571
Lee Leahy73402172017-03-10 15:23:24 -0800572 printk(BIOS_SPEW,
573 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700574 " %04x %04x %04x %04x hborder %x\n"
575 " %04x %04x %04x %04x vborder %x\n"
576 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700577 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700578 extra_info.x_mm,
579 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700580 out->mode.ha, out->mode.ha + out->mode.hso,
581 out->mode.ha + out->mode.hso + out->mode.hspw,
582 out->mode.ha + out->mode.hbl, out->mode.hborder,
583 out->mode.va, out->mode.va + out->mode.vso,
584 out->mode.va + out->mode.vso + out->mode.vspw,
585 out->mode.va + out->mode.vbl, out->mode.vborder,
586 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800587 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700588 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700589
Lee Leahy35af5c42017-03-09 17:35:28 -0800590 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700591 printk(BIOS_SPEW, "Did detailed timing\n");
592 c->did_detailed_timing = 1;
593 *result_edid = *out;
594 }
595
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700596 return 1;
597}
598
599static int
600do_checksum(unsigned char *x)
601{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800602 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600603 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700604 {
605 unsigned char sum = 0;
606 int i;
607 for (i = 0; i < 128; i++)
608 sum += x[i];
609 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800610 printk(BIOS_SPEW, " (should be 0x%hhx)",
611 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700612 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800613 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700614 printk(BIOS_SPEW, " (valid)");
615 }
616 }
617 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800618 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700619}
620
621/* CEA extension */
622
623static const char *
624audio_format(unsigned char x)
625{
626 switch (x) {
627 case 0: return "RESERVED";
628 case 1: return "Linear PCM";
629 case 2: return "AC-3";
630 case 3: return "MPEG 1 (Layers 1 & 2)";
631 case 4: return "MPEG 1 Layer 3 (MP3)";
632 case 5: return "MPEG2 (multichannel)";
633 case 6: return "AAC";
634 case 7: return "DTS";
635 case 8: return "ATRAC";
636 case 9: return "One Bit Audio";
637 case 10: return "Dolby Digital+";
638 case 11: return "DTS-HD";
639 case 12: return "MAT (MLP)";
640 case 13: return "DST";
641 case 14: return "WMA Pro";
642 case 15: return "RESERVED";
643 }
644 return "BROKEN"; /* can't happen */
645}
646
647static void
648cea_audio_block(unsigned char *x)
649{
650 int i, format;
651 int length = x[0] & 0x1f;
652
653 if (length % 3) {
654 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
655 /* XXX non-conformant */
656 return;
657 }
658
659 for (i = 1; i < length; i += 3) {
660 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800661 printk(BIOS_SPEW, " %s, max channels %d\n",
662 audio_format(format), x[i] & 0x07);
663 printk(BIOS_SPEW,
664 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700665 (x[i+1] & 0x40) ? " 192" : "",
666 (x[i+1] & 0x20) ? " 176.4" : "",
667 (x[i+1] & 0x10) ? " 96" : "",
668 (x[i+1] & 0x08) ? " 88.2" : "",
669 (x[i+1] & 0x04) ? " 48" : "",
670 (x[i+1] & 0x02) ? " 44.1" : "",
671 (x[i+1] & 0x01) ? " 32" : "");
672 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800673 printk(BIOS_SPEW,
674 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700675 (x[2] & 0x04) ? " 24" : "",
676 (x[2] & 0x02) ? " 20" : "",
677 (x[2] & 0x01) ? " 16" : "");
678 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800679 printk(BIOS_SPEW,
680 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700681 }
682 }
683}
684
685static void
686cea_video_block(unsigned char *x)
687{
688 int i;
689 int length = x[0] & 0x1f;
690
691 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800692 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700693 x[i] & 0x80 ? "(native)" : "");
694}
695
696static void
697cea_hdmi_block(struct edid *out, unsigned char *x)
698{
699 int length = x[0] & 0x1f;
700
Yakir Yang85810cc2015-10-27 16:17:13 +0800701 out->hdmi_monitor_detected = 1;
702
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700703 printk(BIOS_SPEW, " (HDMI)\n");
704 printk(BIOS_SPEW,
705 " Source physical address %d.%d.%d.%d\n",
706 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
707
708 if (length > 5) {
709 if (x[6] & 0x80)
710 printk(BIOS_SPEW, " Supports_AI\n");
711 if (x[6] & 0x40)
712 printk(BIOS_SPEW, " DC_48bit\n");
713 if (x[6] & 0x20)
714 printk(BIOS_SPEW, " DC_36bit\n");
715 if (x[6] & 0x10)
716 printk(BIOS_SPEW, " DC_30bit\n");
717 if (x[6] & 0x08)
718 printk(BIOS_SPEW, " DC_Y444\n");
719 /* two reserved */
720 if (x[6] & 0x01)
721 printk(BIOS_SPEW, " DVI_Dual\n");
722 }
723
724 if (length > 6)
725 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
726
727 /* XXX the walk here is really ugly, and needs to be length-checked */
728 if (length > 7) {
729 int b = 0;
730
731 if (x[8] & 0x80) {
732 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
733 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
734 b += 2;
735 }
736
737 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800738 printk(BIOS_SPEW,
739 " Interlaced video latency: %d\n", x[9 + b]);
740 printk(BIOS_SPEW,
741 " Interlaced audio latency: %d\n",
742 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700743 b += 2;
744 }
745
746 if (x[8] & 0x20) {
747 int mask = 0, formats = 0;
748 int len_xx, len_3d;
749 printk(BIOS_SPEW, " Extended HDMI video details:\n");
750 if (x[9 + b] & 0x80)
751 printk(BIOS_SPEW, " 3D present\n");
752 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800753 printk(BIOS_SPEW,
754 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700755 formats = 1;
756 }
757 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800758 printk(BIOS_SPEW,
759 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700760 formats = 1;
761 mask = 1;
762 }
763 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800764 case 0x00:
765 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700766 case 0x08:
767 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
768 break;
769 case 0x10:
770 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
771 break;
772 case 0x18:
773 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
774 break;
775 }
776 len_xx = (x[10 + b] & 0xe0) >> 5;
777 len_3d = (x[10 + b] & 0x1f) >> 0;
778 b += 2;
779
780 if (len_xx) {
781 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
782 " document\n", len_xx);
783 b += len_xx;
784 }
785
786 if (len_3d) {
787 if (formats) {
788 if (x[9 + b] & 0x01)
789 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
790 if (x[10 + b] & 0x40)
791 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
792 if (x[10 + b] & 0x01)
793 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
794 b += 2;
795 }
796 if (mask) {
797 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800798 printk(BIOS_SPEW,
799 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700800 /* worst bit ordering ever */
801 for (i = 0; i < 8; i++)
802 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800803 printk(BIOS_SPEW,
804 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700805 for (i = 0; i < 8; i++)
806 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800807 printk(BIOS_SPEW,
808 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700809 printk(BIOS_SPEW, "\n");
810 b += 2;
811 }
812
813 /*
814 * XXX list of nibbles:
815 * 2D_VIC_Order_X
816 * 3D_Structure_X
817 * (optionally: 3D_Detail_X and reserved)
818 */
819 }
820
821 }
822 }
823}
824
825static void
826cea_block(struct edid *out, unsigned char *x)
827{
828 unsigned int oui;
829
830 switch ((x[0] & 0xe0) >> 5) {
831 case 0x01:
832 printk(BIOS_SPEW, " Audio data block\n");
833 cea_audio_block(x);
834 break;
835 case 0x02:
836 printk(BIOS_SPEW, " Video data block\n");
837 cea_video_block(x);
838 break;
839 case 0x03:
840 /* yes really, endianness lols */
841 oui = (x[3] << 16) + (x[2] << 8) + x[1];
Lee Leahy73402172017-03-10 15:23:24 -0800842 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
843 oui);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700844 if (oui == 0x000c03)
845 cea_hdmi_block(out, x);
846 else
847 printk(BIOS_SPEW, "\n");
848 break;
849 case 0x04:
850 printk(BIOS_SPEW, " Speaker allocation data block\n");
851 break;
852 case 0x05:
853 printk(BIOS_SPEW, " VESA DTC data block\n");
854 break;
855 case 0x07:
856 printk(BIOS_SPEW, " Extended tag: ");
857 switch (x[1]) {
858 case 0x00:
859 printk(BIOS_SPEW, "video capability data block\n");
860 break;
861 case 0x01:
862 printk(BIOS_SPEW, "vendor-specific video data block\n");
863 break;
864 case 0x02:
Lee Leahy73402172017-03-10 15:23:24 -0800865 printk(BIOS_SPEW,
866 "VESA video display device information data block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700867 break;
868 case 0x03:
869 printk(BIOS_SPEW, "VESA video data block\n");
870 break;
871 case 0x04:
872 printk(BIOS_SPEW, "HDMI video data block\n");
873 break;
874 case 0x05:
875 printk(BIOS_SPEW, "Colorimetry data block\n");
876 break;
877 case 0x10:
878 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
879 break;
880 case 0x11:
881 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
882 break;
883 case 0x12:
884 printk(BIOS_SPEW, "HDMI audio data block\n");
885 break;
886 default:
887 if (x[1] >= 6 && x[1] <= 15)
Lee Leahy73402172017-03-10 15:23:24 -0800888 printk(BIOS_SPEW,
889 "Reserved video block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700890 else if (x[1] >= 19 && x[1] <= 31)
Lee Leahy73402172017-03-10 15:23:24 -0800891 printk(BIOS_SPEW,
892 "Reserved audio block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700893 else
894 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
895 break;
896 }
897 break;
898 default:
899 {
900 int tag = (*x & 0xe0) >> 5;
901 int length = *x & 0x1f;
902 printk(BIOS_SPEW,
Lee Leahy73402172017-03-10 15:23:24 -0800903 " Unknown tag %d, length %d (raw %02x)\n",
904 tag, length, *x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700905 break;
906 }
907 }
908}
909
910static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800911parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700912{
913 int ret = 0;
914 int version = x[1];
915 int offset = x[2];
916 unsigned char *detailed;
917
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800918 if (version >= 1)
919 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700920 if (version == 1 && x[3] != 0)
921 ret = 1;
922
923 if (offset < 4)
924 break;
925
Lee Leahye20a3192017-03-09 16:21:34 -0800926 if (version < 3)
Lee Leahy73402172017-03-10 15:23:24 -0800927 printk(BIOS_SPEW,
928 "%d 8-byte timing descriptors\n",
929 (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800930 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700931 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800932 printk(BIOS_SPEW,
933 "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800934 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700935 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700936 }
937
938 if (version >= 2) {
939 if (x[3] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800940 printk(BIOS_SPEW,
941 "Underscans PC formats by default\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700942 if (x[3] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800943 printk(BIOS_SPEW,
944 "Basic audio support\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700945 if (x[3] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800946 printk(BIOS_SPEW,
947 "Supports YCbCr 4:4:4\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700948 if (x[3] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800949 printk(BIOS_SPEW,
950 "Supports YCbCr 4:2:2\n");
951 printk(BIOS_SPEW,
952 "%d native detailed modes\n",
953 x[3] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700954 }
955
Lee Leahy73402172017-03-10 15:23:24 -0800956 for (detailed = x + offset; detailed + 18 < x + 127;
957 detailed += 18)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700958 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800959 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700960 } while (0);
961
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800962 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700963 return ret;
964}
965
966/* generic extension code */
967
968static void
969extension_version(struct edid *out, unsigned char *x)
970{
971 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
972}
973
974static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800975parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700976{
977 int conformant_extension = 0;
978 printk(BIOS_SPEW, "\n");
979
Lee Leahy45fde702017-03-08 18:02:24 -0800980 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700981 case 0x02:
982 printk(BIOS_SPEW, "CEA extension block\n");
983 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800984 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700985 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800986 case 0x10:
987 printk(BIOS_SPEW, "VTB extension block\n");
988 break;
989 case 0x40:
990 printk(BIOS_SPEW, "DI extension block\n");
991 break;
992 case 0x50:
993 printk(BIOS_SPEW, "LS extension block\n");
994 break;
995 case 0x60:
996 printk(BIOS_SPEW, "DPVL extension block\n");
997 break;
998 case 0xF0:
999 printk(BIOS_SPEW, "Block map\n");
1000 break;
1001 case 0xFF:
1002 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001003 default:
1004 printk(BIOS_SPEW, "Unknown extension block\n");
1005 break;
1006 }
1007
1008 printk(BIOS_SPEW, "\n");
1009
1010 return conformant_extension;
1011}
1012
1013static const struct {
1014 int x, y, refresh;
1015} established_timings[] = {
1016 /* 0x23 bit 7 - 0 */
1017 {720, 400, 70},
1018 {720, 400, 88},
1019 {640, 480, 60},
1020 {640, 480, 67},
1021 {640, 480, 72},
1022 {640, 480, 75},
1023 {800, 600, 56},
1024 {800, 600, 60},
1025 /* 0x24 bit 7 - 0 */
1026 {800, 600, 72},
1027 {800, 600, 75},
1028 {832, 624, 75},
1029 {1280, 768, 87},
1030 {1024, 768, 60},
1031 {1024, 768, 70},
1032 {1024, 768, 75},
1033 {1280, 1024, 75},
1034 /* 0x25 bit 7*/
1035 {1152, 870, 75},
1036};
1037
1038static void print_subsection(const char *name, unsigned char *edid, int start,
1039 int end)
1040{
1041 int i;
1042
1043 printk(BIOS_SPEW, "%s:", name);
1044 for (i = strlen(name); i < 15; i++)
1045 printk(BIOS_SPEW, " ");
1046 for (i = start; i <= end; i++)
1047 printk(BIOS_SPEW, " %02x", edid[i]);
1048 printk(BIOS_SPEW, "\n");
1049}
1050
1051static void dump_breakdown(unsigned char *edid)
1052{
1053 printk(BIOS_SPEW, "Extracted contents:\n");
1054 print_subsection("header", edid, 0, 7);
1055 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001056 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001057 print_subsection("basic params", edid, 20, 24);
1058 print_subsection("chroma info", edid, 25, 34);
1059 print_subsection("established", edid, 35, 37);
1060 print_subsection("standard", edid, 38, 53);
1061 print_subsection("descriptor 1", edid, 54, 71);
1062 print_subsection("descriptor 2", edid, 72, 89);
1063 print_subsection("descriptor 3", edid, 90, 107);
1064 print_subsection("descriptor 4", edid, 108, 125);
1065 print_subsection("extensions", edid, 126, 126);
1066 print_subsection("checksum", edid, 127, 127);
1067 printk(BIOS_SPEW, "\n");
1068}
1069
1070/*
David Hendrickse2054102015-08-07 18:41:37 -07001071 * Lookup table of some well-known modes that can be useful in case the
1072 * auto-detected mode is unsuitable.
1073 * ha = hdisplay; va = vdisplay;
1074 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1075 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1076 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1077 */
1078static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1079 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001080 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001081 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001082 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1083 .phsync = '-', .pvsync = '-' },
1084 [EDID_MODE_720x480_60Hz] = {
1085 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001086 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001087 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1088 .phsync = '-', .pvsync = '-' },
1089 [EDID_MODE_1280x720_60Hz] = {
1090 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001091 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001092 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1093 .phsync = '+', .pvsync = '+' },
1094 [EDID_MODE_1920x1080_60Hz] = {
1095 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001096 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001097 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1098 .phsync = '+', .pvsync = '+' },
1099};
1100
1101int set_display_mode(struct edid *edid, enum edid_modes mode)
1102{
1103 if (mode == EDID_MODE_AUTO)
1104 return 0;
1105
1106 if (edid->mode_is_supported[mode]) {
1107 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1108 edid->mode = known_modes[mode];
1109 return 0;
1110 }
1111
1112 printk(BIOS_ERR, "Requested display mode not supported.\n");
1113 return -1;
1114}
1115
1116/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001117 * Given a raw edid bloc, decode it into a form
1118 * that other parts of coreboot can use -- mainly
1119 * graphics bringup functions. The raw block is
1120 * required to be 128 bytes long, per the standard,
1121 * but we have no way of checking this minimum length.
1122 * We accept what we are given.
1123 */
1124int decode_edid(unsigned char *edid, int size, struct edid *out)
1125{
David Hendrickse2054102015-08-07 18:41:37 -07001126 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001127 struct edid_context c = {
1128 .has_valid_cvt = 1,
1129 .has_valid_dummy_block = 1,
1130 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001131 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001132 .has_valid_descriptor_pad = 1,
1133 .has_valid_range_descriptor = 1,
1134 .has_valid_max_dotclock = 1,
1135 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001136 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001137 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001138
1139 dump_breakdown(edid);
1140
David Hendricks40e89b42015-08-13 15:51:00 -07001141 memset(out, 0, sizeof(*out));
1142
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001143 if (!edid || memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
1144 printk(BIOS_SPEW, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001145 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001146 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001147
David Hendricksa3b898a2015-08-02 18:07:48 -07001148 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001149 c.manufacturer_name_well_formed = 1;
1150
David Hendricksa3b898a2015-08-02 18:07:48 -07001151 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1152 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001153 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1154
1155 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001156 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001157 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1158 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1159 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001160 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001161
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001162 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001163 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001164 if (edid[0x11] > 0x0f) {
1165 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001166 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001167 printk(BIOS_SPEW,
1168 "Made week %hhd of model year %hhd\n",
1169 edid[0x10], edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001170 extra_info.week = edid[0x10];
1171 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001172 } else {
Lee Leahy73402172017-03-10 15:23:24 -08001173 /* we know it's at least 2013, when this code
1174 * was written
1175 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001176 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001177 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001178 printk(BIOS_SPEW,
1179 "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001180 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001181 extra_info.week = edid[0x10];
1182 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001183 }
1184 }
1185 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001186 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001187
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001188 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001189 extra_info.version[0] = edid[0x12];
1190 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001191
1192 if (edid[0x12] == 1) {
1193 if (edid[0x13] > 4) {
Lee Leahy73402172017-03-10 15:23:24 -08001194 printk(BIOS_SPEW,
1195 "Claims > 1.4, assuming 1.4 conformance\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001196 edid[0x13] = 4;
1197 }
1198 switch (edid[0x13]) {
1199 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001200 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001201 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001202 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001203 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001204 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001205 default:
1206 break;
1207 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001208 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001209 }
1210
1211 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001212 if (edid[0x14] & 0x80) {
1213 int conformance_mask;
1214 analog = 0;
1215 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001216 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001217 conformance_mask = 0;
1218 if ((edid[0x14] & 0x70) == 0x00)
1219 printk(BIOS_SPEW, "Color depth is undefined\n");
1220 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001221 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001222 else
Lee Leahy73402172017-03-10 15:23:24 -08001223 printk(BIOS_SPEW,
1224 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001225 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001226 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1227 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001228 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001229
1230 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001231 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001232 printk(BIOS_SPEW,
1233 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001234 break;
1235 case 0x01:
1236 printk(BIOS_SPEW, "DVI interface\n");
1237 break;
1238 case 0x02:
1239 printk(BIOS_SPEW, "HDMI-a interface\n");
1240 break;
1241 case 0x03:
1242 printk(BIOS_SPEW, "HDMI-b interface\n");
1243 break;
1244 case 0x04:
1245 printk(BIOS_SPEW, "MDDI interface\n");
1246 break;
1247 case 0x05:
1248 printk(BIOS_SPEW, "DisplayPort interface\n");
1249 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001250 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001251 c.nonconformant_digital_display = 1;
1252 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001253 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001254 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001255 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001256 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001257 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001258 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001259 } else
1260 conformance_mask = 0x7F;
1261
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001262 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001263 c.nonconformant_digital_display = edid[0x14]
1264 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001265 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001266 } else {
1267 analog = 1;
1268 int voltage = (edid[0x14] & 0x60) >> 5;
1269 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001270 extra_info.voltage = voltage;
1271 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001272
1273 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1274 voltage == 3 ? "0.7/0.7" :
1275 voltage == 2 ? "1.0/0.4" :
1276 voltage == 1 ? "0.714/0.286" :
1277 "0.7/0.3");
1278
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001279 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001280 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001281 printk(BIOS_SPEW,
1282 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001283 else
Lee Leahy73402172017-03-10 15:23:24 -08001284 printk(BIOS_SPEW,
1285 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001286 } else if (edid[0x14] & 0x10) {
1287 /*
Lee Leahy73402172017-03-10 15:23:24 -08001288 * XXX this is just the X text. 1.3 says "if set,
1289 * display expects a blank-to-black setup or pedestal
1290 * per appropriate Signal Level Standard". Whatever
1291 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001292 */
1293 printk(BIOS_SPEW, "Configurable signal levels\n");
1294 }
1295
Lee Leahy73402172017-03-10 15:23:24 -08001296 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1297 sync & 0x08 ? "Separate " : "",
1298 sync & 0x04 ? "Composite " : "",
1299 sync & 0x02 ? "SyncOnGreen " : "",
1300 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001301 }
1302
1303
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001304 if (edid[0x15] && edid[0x16]) {
1305 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1306 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001307 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001308 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1309 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001310 printk(BIOS_SPEW,
1311 "Aspect ratio is %u.%03u (landscape)\n",
1312 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001313 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1314 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001315 printk(BIOS_SPEW,
1316 "Aspect ratio is %u.%03u (portrait)\n",
1317 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001318 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001319 } else {
1320 /* Either or both can be zero for 1.3 and before */
1321 printk(BIOS_SPEW, "Image size is variable\n");
1322 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001323
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001324 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001325 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001326 printk(BIOS_SPEW,
1327 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001328 else
1329 /* XXX Technically 1.3 doesn't say this... */
1330 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001331 } else
1332 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001333 printk(BIOS_SPEW, "Check DPMS levels\n");
1334 if (edid[0x18] & 0xE0) {
1335 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001336 if (edid[0x18] & 0x80)
1337 printk(BIOS_SPEW, " Standby");
1338 if (edid[0x18] & 0x40)
1339 printk(BIOS_SPEW, " Suspend");
1340 if (edid[0x18] & 0x20)
1341 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001342 printk(BIOS_SPEW, "\n");
1343 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001344
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001345 /* FIXME: this is from 1.4 spec, check earlier */
1346 if (analog) {
1347 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001348 case 0x00:
1349 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1350 break;
1351 case 0x08:
1352 printk(BIOS_SPEW, "RGB color display\n");
1353 break;
1354 case 0x10:
1355 printk(BIOS_SPEW, "Non-RGB color display\n");
1356 break;
1357 case 0x18:
1358 printk(BIOS_SPEW, "Undefined display color type\n");
1359 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001360 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001361 } else {
1362 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1363 if (edid[0x18] & 0x10)
1364 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1365 if (edid[0x18] & 0x08)
1366 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1367 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001368 }
1369
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001370 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001371 printk(BIOS_SPEW,
1372 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001373 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001374 printk(BIOS_SPEW,
1375 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001376 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001377 }
1378 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001379 printk(BIOS_SPEW,
1380 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001381
1382 /* XXX color section */
1383
1384 printk(BIOS_SPEW, "Established timings supported:\n");
1385 /* it's not yet clear we want all this stuff in the edid struct.
1386 * Let's wait.
1387 */
1388 for (i = 0; i < 17; i++) {
1389 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001390 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1391 established_timings[i].x,
1392 established_timings[i].y,
1393 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001394
Douglas Anderson9fa07602015-10-28 10:19:52 -07001395 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001396 if (known_modes[j].ha ==
1397 established_timings[i].x
1398 && known_modes[j].va ==
1399 established_timings[i].y
1400 && known_modes[j].refresh ==
1401 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001402 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001403 }
David Hendrickse2054102015-08-07 18:41:37 -07001404 }
1405
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001406 }
1407
1408 printk(BIOS_SPEW, "Standard timings supported:\n");
1409 for (i = 0; i < 8; i++) {
1410 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1411 unsigned int x, y = 0, refresh;
1412
1413 if (b1 == 0x01 && b2 == 0x01)
1414 continue;
1415
1416 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001417 printk(BIOS_SPEW,
1418 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001419 continue;
1420 }
1421 x = (b1 + 31) * 8;
1422 switch ((b2 >> 6) & 0x3) {
1423 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001424 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001425 y = x * 10 / 16;
1426 else
1427 y = x;
1428 break;
1429 case 0x01:
1430 y = x * 3 / 4;
1431 break;
1432 case 0x02:
1433 y = x * 4 / 5;
1434 break;
1435 case 0x03:
1436 y = x * 9 / 16;
1437 break;
1438 }
1439 refresh = 60 + (b2 & 0x3f);
1440
1441 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001442 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1443 if (known_modes[j].ha == x && known_modes[j].va == y &&
1444 known_modes[j].refresh == refresh)
1445 out->mode_is_supported[j] = 1;
1446 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001447 }
1448
1449 /* detailed timings */
1450 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001451 for (i = 0; i < 4; i++) {
1452 c.has_valid_detailed_blocks &= detailed_block(
1453 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001454 if (i == 0 && c.has_preferred_timing
1455 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001456 /* not really accurate... */
1457 c.has_preferred_timing = 0;
1458 }
1459 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001460
1461 /* check this, 1.4 verification guide says otherwise */
1462 if (edid[0x7e]) {
1463 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1464 /* 2 is impossible because of the block map */
1465 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001466 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001467 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001468 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001469 }
1470
1471 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001472 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001473
1474 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1475 * the extension parsing loop below. Since v2.0 was quickly deprecated
1476 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1477 * that case now and can fix it when we need to use a real 2.0 panel.
1478 */
Lee Leahy45fde702017-03-08 18:02:24 -08001479 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001480 c.nonconformant_extension +=
1481 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001482
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001483 if (c.claims_one_point_four) {
1484 if (c.nonconformant_digital_display ||
1485 !c.has_valid_string_termination ||
1486 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001487 !c.has_preferred_timing) {
1488 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001489 printk(BIOS_ERR,
1490 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001491 }
1492
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001493 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001494 printk(BIOS_ERR,
1495 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001496 c.nonconformant_digital_display);
1497 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001498 printk(BIOS_ERR,
1499 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001500 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001501 printk(BIOS_ERR,
1502 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001503 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001504 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001505 } else if (c.claims_one_point_three) {
1506 if (c.nonconformant_digital_display ||
1507 !c.has_valid_string_termination ||
1508 !c.has_valid_descriptor_pad ||
1509 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001510 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001511 }
1512 /**
1513 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1514 * has_range_descriptor are both required. These fields are
1515 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1516 * don't have them. As a workaround, we only print warning
1517 * messages.
1518 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001519 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001520 printk(BIOS_ERR,
1521 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001522 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001523 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1524 "fully conform to EDID 1.3.\n");
1525
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001526 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001527 printk(BIOS_ERR,
1528 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001529 c.nonconformant_digital_display);
1530 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001531 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001532 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001533 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001534 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001535 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001536 /* Might be more than just 1.3 */
1537 if (!c.has_valid_descriptor_pad)
1538 printk(BIOS_ERR,
1539 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001540 if (!c.has_valid_string_termination) /* Likewise */
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_two) {
1544 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001545 !c.has_valid_string_termination) {
1546 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001547 printk(BIOS_ERR,
1548 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001549 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001550 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001551 printk(BIOS_ERR,
1552 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001553 c.nonconformant_digital_display);
1554 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001555 printk(BIOS_ERR,
1556 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001557 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001558 if (c.seen_non_detailed_descriptor) {
1559 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001560 printk(BIOS_ERR,
1561 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001562 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001563 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001564 printk(BIOS_ERR,
1565 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001566 }
1567
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001568 if (c.nonconformant_extension ||
1569 !c.has_valid_checksum ||
1570 !c.has_valid_cvt ||
1571 !c.has_valid_year ||
1572 !c.has_valid_week ||
1573 !c.has_valid_detailed_blocks ||
1574 !c.has_valid_dummy_block ||
1575 !c.has_valid_extension_count ||
1576 !c.has_valid_descriptor_ordering ||
1577 !c.has_valid_range_descriptor ||
1578 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001579 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001580 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001581 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001582 printk(BIOS_ERR,
1583 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001584 c.nonconformant_extension);
1585 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001586 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001587 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001588 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001589 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001590 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001591 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001592 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001593 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001594 printk(BIOS_ERR,
1595 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001596 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001597 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001598 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001599 printk(BIOS_ERR,
1600 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001601 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001602 printk(BIOS_ERR,
1603 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001604 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001605 printk(BIOS_ERR,
1606 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001607 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001608 printk(BIOS_ERR,
1609 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001610 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001611 printk(BIOS_ERR,
1612 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001613 }
1614
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001615 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001616 printk(BIOS_ERR,
1617 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001618 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001619 printk(BIOS_ERR,
1620 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001621 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001622}
1623
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001624/*
1625 * Notes on panel extensions: (TODO, implement me in the code)
1626 *
1627 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1628 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1629 * 0x6c: 00 00 00 0e 00
1630 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1631 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1632 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1633 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1634 * bit 4: DE polarity (0 high active 1 low active)
1635 * bit 3-0: interface (0000 LVDS TFT
1636 * 0001 mono STN 4/8bit
1637 * 0010 color STN 8/16 bit
1638 * 0011 18 bit tft
1639 * 0100 24 bit tft
1640 * 0101 tmds
1641 * else reserved)
1642 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1643 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1644 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1645 * else time in 10ms (10ms to 150ms))
1646 * bit 3-0: total poweron seq delay (as above)
1647 * 0x75: contrast power on/off seq delay, same as 0x74
1648 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1649 * bit 6: backlight enabled at boot (0 on 1 off)
1650 * bit 5-0: backlight brightness control steps (0..63)
1651 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1652 * 0x78 - 0x7c: reserved
1653 * 0x7d: bit 7-4: EPI descriptor major version (1)
1654 * bit 3-0: EPI descriptor minor version (0)
1655 *
1656 * ----
1657 *
1658 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1659 *
1660 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1661 *
1662 * detailed descriptor 3:
1663 * 0x5a - 0x5e: 00 00 00 fe 00
1664 * 0x5f - 0x63: PC maker part number
1665 * 0x64: LCD supplier revision #
1666 * 0x65 - 0x6b: manufacturer part number
1667 *
1668 * detailed descriptor 4:
1669 * 0x6c - 0x70: 00 00 00 fe 00
1670 * 0x71 - 0x78: smbus nits values (whut)
1671 * 0x79: number of lvds channels (1 or 2)
1672 * 0x7A: panel self test (1 if present)
1673 * and then dummy terminator
1674 *
1675 * SPWG also says something strange about the LSB of detailed descriptor 1:
1676 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1677 */
Julius Werner69112192016-03-14 17:29:55 -07001678
1679/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001680void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1681 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001682{
1683 /* Caller should pass a supported value, everything else is BUG(). */
1684 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Julius Werner2b6db972016-04-06 12:50:40 -07001685 row_byte_alignment = max(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001686
1687 edid->framebuffer_bits_per_pixel = fb_bpp;
1688 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Julius Werner2b6db972016-04-06 12:50:40 -07001689 div_round_up(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001690 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1691 edid->y_resolution = edid->mode.va;
1692}