blob: 5925759a4c9b589cce4014402360803685df3bcf [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>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070034#include <stdint.h>
35#include <string.h>
36#include <stdlib.h>
37#include <edid.h>
Ronald G. Minnichb2893a012013-04-23 10:59:11 -070038#include <boot/coreboot_tables.h>
39#include <vbe.h>
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070040
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080041struct edid_context {
42 int claims_one_point_oh;
43 int claims_one_point_two;
44 int claims_one_point_three;
45 int claims_one_point_four;
46 int nonconformant_digital_display;
47 int nonconformant_extension;
48 int did_detailed_timing;
49 int has_name_descriptor;
50 int has_range_descriptor;
51 int has_preferred_timing;
52 int has_valid_checksum;
53 int has_valid_cvt;
54 int has_valid_dummy_block;
55 int has_valid_week;
56 int has_valid_year;
57 int has_valid_detailed_blocks;
58 int has_valid_extension_count;
59 int has_valid_descriptor_ordering;
60 int has_valid_descriptor_pad;
61 int has_valid_range_descriptor;
62 int has_valid_max_dotclock;
63 int has_valid_string_termination;
64 int manufacturer_name_well_formed;
65 int seen_non_detailed_descriptor;
66 int warning_excessive_dotclock_correction;
67 int warning_zero_preferred_refresh;
Arthur Heymans8c5884e2017-04-30 08:28:05 +020068 enum edid_status conformant;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +080069};
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070070
David Hendricksa3b898a2015-08-02 18:07:48 -070071/* Stuff that isn't used anywhere but is nice to pretty-print while
72 we're decoding everything else. */
73static struct {
74 char manuf_name[4];
75 unsigned int model;
76 unsigned int serial;
77 unsigned int year;
78 unsigned int week;
79 unsigned int version[2];
80 unsigned int nonconformant;
81 unsigned int type;
82
83 unsigned int x_mm;
84 unsigned int y_mm;
85
86 unsigned int voltage;
87 unsigned int sync;
88
89 const char *syncmethod;
90 const char *range_class;
91 const char *stereo;
92} extra_info;
93
Douglas Andersonbca67fb2015-10-28 09:18:28 -070094static struct edid tmp_edid;
95
David Hendricksa3b898a2015-08-02 18:07:48 -070096static char *manufacturer_name(unsigned char *x)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -070097{
David Hendricksa3b898a2015-08-02 18:07:48 -070098 extra_info.manuf_name[0] = ((x[0] & 0x7C) >> 2) + '@';
Lee Leahy73402172017-03-10 15:23:24 -080099 extra_info.manuf_name[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5)
100 + '@';
David Hendricksa3b898a2015-08-02 18:07:48 -0700101 extra_info.manuf_name[2] = (x[1] & 0x1F) + '@';
102 extra_info.manuf_name[3] = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700103
David Hendricksa3b898a2015-08-02 18:07:48 -0700104 if (isupper(extra_info.manuf_name[0]) &&
105 isupper(extra_info.manuf_name[1]) &&
106 isupper(extra_info.manuf_name[2]))
107 return extra_info.manuf_name;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700108
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800109 return NULL;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700110}
111
112static int
Douglas Anderson14dd3702015-10-28 11:19:57 -0700113detailed_cvt_descriptor(unsigned char *x, int first)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700114{
115 const unsigned char empty[3] = { 0, 0, 0 };
Lee Leahy36984d82017-03-10 17:56:44 -0800116 static const char *names[] = { "50", "60", "75", "85" };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700117 int width = 0, height = 0;
118 int valid = 1;
119 int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
120
121 if (!first && !memcmp(x, empty, 3))
122 return valid;
123
124 height = x[0];
125 height |= (x[1] & 0xf0) << 4;
126 height++;
127 height *= 2;
128
129 switch (x[1] & 0x0c) {
130 case 0x00:
131 width = (height * 4) / 3; break;
132 case 0x04:
133 width = (height * 16) / 9; break;
134 case 0x08:
135 width = (height * 16) / 10; break;
136 case 0x0c:
137 width = (height * 15) / 9; break;
138 }
139
140 if (x[1] & 0x03)
141 valid = 0;
142 if (x[2] & 0x80)
143 valid = 0;
144 if (!(x[2] & 0x1f))
145 valid = 0;
146
147 fifty = (x[2] & 0x10);
148 sixty = (x[2] & 0x08);
149 seventyfive = (x[2] & 0x04);
150 eightyfive = (x[2] & 0x02);
151 reduced = (x[2] & 0x01);
152
153 if (!valid) {
154 printk(BIOS_SPEW, " (broken)\n");
155 } else {
Lee Leahy73402172017-03-10 15:23:24 -0800156 printk(BIOS_SPEW,
Elyes HAOUASa342f392018-10-17 10:56:26 +0200157 " %dx%d @ (%s%s%s%s%s) Hz (%s%s preferred)\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700158 width, height,
159 fifty ? "50 " : "",
160 sixty ? "60 " : "",
161 seventyfive ? "75 " : "",
162 eightyfive ? "85 " : "",
163 reduced ? "60RB " : "",
164 names[(x[2] & 0x60) >> 5],
165 (((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
166 }
167
168 return valid;
169}
170
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800171/* extract a CP437 string from a detailed subblock, checking for termination (if
172 * less than len of bytes) with LF and padded with SP.
173 */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700174static char *
175extract_string(unsigned char *x, int *valid_termination, int len)
176{
Patrick Georgid840e2b2018-09-18 18:01:02 +0200177 static char ret[EDID_ASCII_STRING_LENGTH + 1];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700178 int i, seen_newline = 0;
179
180 memset(ret, 0, sizeof(ret));
181
Patrick Georgid840e2b2018-09-18 18:01:02 +0200182 for (i = 0; i < min(len, EDID_ASCII_STRING_LENGTH); i++) {
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800183 if (seen_newline) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700184 if (x[i] != 0x20) {
185 *valid_termination = 0;
186 return ret;
187 }
Hung-Te Lin2536c1a2014-04-03 19:21:03 +0800188 } else if (x[i] == 0x0a) {
189 seen_newline = 1;
190 } else {
191 /* normal characters */
192 ret[i] = x[i];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700193 }
194 }
195
196 return ret;
197}
198
199/* 1 means valid data */
200static int
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700201detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800202 struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700203{
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700204 struct edid *out = &tmp_edid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700205 int i;
Angel Ponscc335c72018-10-02 11:58:28 +0200206
207 if (console_log_level(BIOS_SPEW)) {
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 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700213
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,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200287 EDID_ASCII_STRING_LENGTH));
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,
Patrick Georgid840e2b2018-09-18 18:01:02 +0200479 &c->has_valid_string_termination,
480 EDID_ASCII_STRING_LENGTH));
Hung-Te Linb2c10622014-04-03 19:59:37 +0800481 return 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700482 default:
Lee Leahy73402172017-03-10 15:23:24 -0800483 printk(BIOS_SPEW,
484 "Unknown monitor description type %d\n",
485 x[3]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700486 return 0;
487 }
488 }
489
Lee Leahy2f919ec2017-03-08 17:37:06 -0800490 if (c->seen_non_detailed_descriptor && !in_extension)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800491 c->has_valid_descriptor_ordering = 0;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700492
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700493 /* Edid contains pixel clock in terms of 10KHz */
494 out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
495 /*
496 LVDS supports following pixel clocks
497 25000...112000 kHz: single channel
498 80000...224000 kHz: dual channel
499 There is some overlap in theoretically supported
500 pixel clock between single-channel and dual-channel.
501 In practice with current panels all panels
502 <= 75200 kHz: single channel
503 >= 97750 kHz: dual channel
504 We have no samples between those values, so put a
505 threshold at 95000 kHz. If we get anything over
506 95000 kHz with single channel, we can make this
507 more sofisticated but it's currently not needed.
508 */
509 out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
510 extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
511 extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
512 out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
513 out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
514 out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
515 out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
516 out->mode.hborder = x[15];
517 out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
518 out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
519 out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
520 out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
521 out->mode.vborder = x[16];
Furquan Shaikhd0a81f72013-07-30 12:41:08 -0700522
Julius Werner69112192016-03-14 17:29:55 -0700523 /* We assume rgb888 (32 bits per pixel) framebuffers by default.
Julius Werner2b6db972016-04-06 12:50:40 -0700524 * Chipsets that want something else will need to override this with
525 * another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
526 * heuristic, assume that X86 systems require a 64-byte row alignment
527 * (since that seems to be true for most Intel chipsets). */
Julius Wernercd49cce2019-03-05 16:53:33 -0800528 if (CONFIG(ARCH_X86))
Julius Werner2b6db972016-04-06 12:50:40 -0700529 edid_set_framebuffer_bits_per_pixel(out, 32, 64);
530 else
531 edid_set_framebuffer_bits_per_pixel(out, 32, 0);
Julius Werner69112192016-03-14 17:29:55 -0700532
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700533 switch ((x[17] & 0x18) >> 3) {
534 case 0x00:
David Hendricksa3b898a2015-08-02 18:07:48 -0700535 extra_info.syncmethod = " analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700536 break;
537 case 0x01:
David Hendricksa3b898a2015-08-02 18:07:48 -0700538 extra_info.syncmethod = " bipolar analog composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700539 break;
540 case 0x02:
David Hendricksa3b898a2015-08-02 18:07:48 -0700541 extra_info.syncmethod = " digital composite";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700542 break;
543 case 0x03:
David Hendricksa3b898a2015-08-02 18:07:48 -0700544 extra_info.syncmethod = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700545 break;
546 }
David Hendricks7dbf9c62015-07-30 18:49:48 -0700547 out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
548 out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700549 switch (x[17] & 0x61) {
550 case 0x20:
David Hendricksa3b898a2015-08-02 18:07:48 -0700551 extra_info.stereo = "field sequential L/R";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700552 break;
553 case 0x40:
David Hendricksa3b898a2015-08-02 18:07:48 -0700554 extra_info.stereo = "field sequential R/L";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700555 break;
556 case 0x21:
David Hendricksa3b898a2015-08-02 18:07:48 -0700557 extra_info.stereo = "interleaved right even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700558 break;
559 case 0x41:
David Hendricksa3b898a2015-08-02 18:07:48 -0700560 extra_info.stereo = "interleaved left even";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700561 break;
562 case 0x60:
David Hendricksa3b898a2015-08-02 18:07:48 -0700563 extra_info.stereo = "four way interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700564 break;
565 case 0x61:
David Hendricksa3b898a2015-08-02 18:07:48 -0700566 extra_info.stereo = "side by side interleaved";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700567 break;
568 default:
David Hendricksa3b898a2015-08-02 18:07:48 -0700569 extra_info.stereo = "";
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700570 break;
571 }
572
Lee Leahy73402172017-03-10 15:23:24 -0800573 printk(BIOS_SPEW,
574 "Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700575 " %04x %04x %04x %04x hborder %x\n"
576 " %04x %04x %04x %04x vborder %x\n"
577 " %chsync %cvsync%s%s %s\n",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700578 out->mode.pixel_clock,
David Hendricksa3b898a2015-08-02 18:07:48 -0700579 extra_info.x_mm,
580 extra_info.y_mm,
David Hendricks7dbf9c62015-07-30 18:49:48 -0700581 out->mode.ha, out->mode.ha + out->mode.hso,
582 out->mode.ha + out->mode.hso + out->mode.hspw,
583 out->mode.ha + out->mode.hbl, out->mode.hborder,
584 out->mode.va, out->mode.va + out->mode.vso,
585 out->mode.va + out->mode.vso + out->mode.vspw,
586 out->mode.va + out->mode.vbl, out->mode.vborder,
587 out->mode.phsync, out->mode.pvsync,
Lee Leahy35af5c42017-03-09 17:35:28 -0800588 extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
David Hendricks7dbf9c62015-07-30 18:49:48 -0700589 extra_info.stereo);
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700590
Lee Leahy35af5c42017-03-09 17:35:28 -0800591 if (!c->did_detailed_timing) {
Douglas Andersonbca67fb2015-10-28 09:18:28 -0700592 printk(BIOS_SPEW, "Did detailed timing\n");
593 c->did_detailed_timing = 1;
594 *result_edid = *out;
595 }
596
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700597 return 1;
598}
599
600static int
601do_checksum(unsigned char *x)
602{
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800603 int valid = 0;
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -0600604 printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700605 {
606 unsigned char sum = 0;
607 int i;
608 for (i = 0; i < 128; i++)
609 sum += x[i];
610 if (sum) {
Lee Leahy73402172017-03-10 15:23:24 -0800611 printk(BIOS_SPEW, " (should be 0x%hhx)",
612 (unsigned char)(x[0x7f] - sum));
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700613 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800614 valid = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700615 printk(BIOS_SPEW, " (valid)");
616 }
617 }
618 printk(BIOS_SPEW, "\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800619 return valid;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700620}
621
622/* CEA extension */
623
624static const char *
625audio_format(unsigned char x)
626{
627 switch (x) {
628 case 0: return "RESERVED";
629 case 1: return "Linear PCM";
630 case 2: return "AC-3";
631 case 3: return "MPEG 1 (Layers 1 & 2)";
632 case 4: return "MPEG 1 Layer 3 (MP3)";
633 case 5: return "MPEG2 (multichannel)";
634 case 6: return "AAC";
635 case 7: return "DTS";
636 case 8: return "ATRAC";
637 case 9: return "One Bit Audio";
638 case 10: return "Dolby Digital+";
639 case 11: return "DTS-HD";
640 case 12: return "MAT (MLP)";
641 case 13: return "DST";
642 case 14: return "WMA Pro";
643 case 15: return "RESERVED";
644 }
645 return "BROKEN"; /* can't happen */
646}
647
648static void
649cea_audio_block(unsigned char *x)
650{
651 int i, format;
652 int length = x[0] & 0x1f;
653
654 if (length % 3) {
655 printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
656 /* XXX non-conformant */
657 return;
658 }
659
660 for (i = 1; i < length; i += 3) {
661 format = (x[i] & 0x78) >> 3;
Lee Leahy73402172017-03-10 15:23:24 -0800662 printk(BIOS_SPEW, " %s, max channels %d\n",
663 audio_format(format), x[i] & 0x07);
664 printk(BIOS_SPEW,
665 " Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700666 (x[i+1] & 0x40) ? " 192" : "",
667 (x[i+1] & 0x20) ? " 176.4" : "",
668 (x[i+1] & 0x10) ? " 96" : "",
669 (x[i+1] & 0x08) ? " 88.2" : "",
670 (x[i+1] & 0x04) ? " 48" : "",
671 (x[i+1] & 0x02) ? " 44.1" : "",
672 (x[i+1] & 0x01) ? " 32" : "");
673 if (format == 1) {
Lee Leahy73402172017-03-10 15:23:24 -0800674 printk(BIOS_SPEW,
675 " Supported sample sizes (bits):%s%s%s\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700676 (x[2] & 0x04) ? " 24" : "",
677 (x[2] & 0x02) ? " 20" : "",
678 (x[2] & 0x01) ? " 16" : "");
679 } else if (format <= 8) {
Lee Leahy73402172017-03-10 15:23:24 -0800680 printk(BIOS_SPEW,
681 " Maximum bit rate: %d kHz\n", x[2] * 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700682 }
683 }
684}
685
686static void
687cea_video_block(unsigned char *x)
688{
689 int i;
690 int length = x[0] & 0x1f;
691
692 for (i = 1; i < length; i++)
Lee Leahy35af5c42017-03-09 17:35:28 -0800693 printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700694 x[i] & 0x80 ? "(native)" : "");
695}
696
697static void
698cea_hdmi_block(struct edid *out, unsigned char *x)
699{
700 int length = x[0] & 0x1f;
701
Yakir Yang85810cc2015-10-27 16:17:13 +0800702 out->hdmi_monitor_detected = 1;
703
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700704 printk(BIOS_SPEW, " (HDMI)\n");
705 printk(BIOS_SPEW,
706 " Source physical address %d.%d.%d.%d\n",
707 x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
708
709 if (length > 5) {
710 if (x[6] & 0x80)
711 printk(BIOS_SPEW, " Supports_AI\n");
712 if (x[6] & 0x40)
713 printk(BIOS_SPEW, " DC_48bit\n");
714 if (x[6] & 0x20)
715 printk(BIOS_SPEW, " DC_36bit\n");
716 if (x[6] & 0x10)
717 printk(BIOS_SPEW, " DC_30bit\n");
718 if (x[6] & 0x08)
719 printk(BIOS_SPEW, " DC_Y444\n");
720 /* two reserved */
721 if (x[6] & 0x01)
722 printk(BIOS_SPEW, " DVI_Dual\n");
723 }
724
725 if (length > 6)
726 printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
727
728 /* XXX the walk here is really ugly, and needs to be length-checked */
729 if (length > 7) {
730 int b = 0;
731
732 if (x[8] & 0x80) {
733 printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
734 printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
735 b += 2;
736 }
737
738 if (x[8] & 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800739 printk(BIOS_SPEW,
740 " Interlaced video latency: %d\n", x[9 + b]);
741 printk(BIOS_SPEW,
742 " Interlaced audio latency: %d\n",
743 x[10 + b]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700744 b += 2;
745 }
746
747 if (x[8] & 0x20) {
748 int mask = 0, formats = 0;
749 int len_xx, len_3d;
750 printk(BIOS_SPEW, " Extended HDMI video details:\n");
751 if (x[9 + b] & 0x80)
752 printk(BIOS_SPEW, " 3D present\n");
753 if ((x[9 + b] & 0x60) == 0x20) {
Lee Leahy73402172017-03-10 15:23:24 -0800754 printk(BIOS_SPEW,
755 " All advertised VICs are 3D-capable\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700756 formats = 1;
757 }
758 if ((x[9 + b] & 0x60) == 0x40) {
Lee Leahy73402172017-03-10 15:23:24 -0800759 printk(BIOS_SPEW,
760 " 3D-capable-VIC mask present\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700761 formats = 1;
762 mask = 1;
763 }
764 switch (x[9 + b] & 0x18) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800765 case 0x00:
766 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700767 case 0x08:
768 printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
769 break;
770 case 0x10:
771 printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
772 break;
773 case 0x18:
774 printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
775 break;
776 }
777 len_xx = (x[10 + b] & 0xe0) >> 5;
778 len_3d = (x[10 + b] & 0x1f) >> 0;
779 b += 2;
780
781 if (len_xx) {
782 printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
783 " document\n", len_xx);
784 b += len_xx;
785 }
786
787 if (len_3d) {
788 if (formats) {
789 if (x[9 + b] & 0x01)
790 printk(BIOS_SPEW, " Side-by-side 3D supported\n");
791 if (x[10 + b] & 0x40)
792 printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
793 if (x[10 + b] & 0x01)
794 printk(BIOS_SPEW, " Frame-packing 3D supported\n");
795 b += 2;
796 }
797 if (mask) {
798 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800799 printk(BIOS_SPEW,
800 " 3D VIC indices:");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700801 /* worst bit ordering ever */
802 for (i = 0; i < 8; i++)
803 if (x[10 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800804 printk(BIOS_SPEW,
805 " %d", i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700806 for (i = 0; i < 8; i++)
807 if (x[9 + b] & (1 << i))
Lee Leahy73402172017-03-10 15:23:24 -0800808 printk(BIOS_SPEW,
809 " %d", i + 8);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700810 printk(BIOS_SPEW, "\n");
811 b += 2;
812 }
813
814 /*
815 * XXX list of nibbles:
816 * 2D_VIC_Order_X
817 * 3D_Structure_X
818 * (optionally: 3D_Detail_X and reserved)
819 */
820 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700821 }
Richard Spiegel2fdbe0c2018-08-07 08:43:22 -0700822 /* Tell static analysis we know index b is left unused. */
823 (void)b;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700824 }
825}
826
827static void
828cea_block(struct edid *out, unsigned char *x)
829{
830 unsigned int oui;
831
832 switch ((x[0] & 0xe0) >> 5) {
833 case 0x01:
834 printk(BIOS_SPEW, " Audio data block\n");
835 cea_audio_block(x);
836 break;
837 case 0x02:
838 printk(BIOS_SPEW, " Video data block\n");
839 cea_video_block(x);
840 break;
841 case 0x03:
842 /* yes really, endianness lols */
843 oui = (x[3] << 16) + (x[2] << 8) + x[1];
Lee Leahy73402172017-03-10 15:23:24 -0800844 printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
845 oui);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700846 if (oui == 0x000c03)
847 cea_hdmi_block(out, x);
848 else
849 printk(BIOS_SPEW, "\n");
850 break;
851 case 0x04:
852 printk(BIOS_SPEW, " Speaker allocation data block\n");
853 break;
854 case 0x05:
855 printk(BIOS_SPEW, " VESA DTC data block\n");
856 break;
857 case 0x07:
858 printk(BIOS_SPEW, " Extended tag: ");
859 switch (x[1]) {
860 case 0x00:
861 printk(BIOS_SPEW, "video capability data block\n");
862 break;
863 case 0x01:
864 printk(BIOS_SPEW, "vendor-specific video data block\n");
865 break;
866 case 0x02:
Lee Leahy73402172017-03-10 15:23:24 -0800867 printk(BIOS_SPEW,
868 "VESA video display device information data block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700869 break;
870 case 0x03:
871 printk(BIOS_SPEW, "VESA video data block\n");
872 break;
873 case 0x04:
874 printk(BIOS_SPEW, "HDMI video data block\n");
875 break;
876 case 0x05:
877 printk(BIOS_SPEW, "Colorimetry data block\n");
878 break;
879 case 0x10:
880 printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
881 break;
882 case 0x11:
883 printk(BIOS_SPEW, "Vendor-specific audio data block\n");
884 break;
885 case 0x12:
886 printk(BIOS_SPEW, "HDMI audio data block\n");
887 break;
888 default:
889 if (x[1] >= 6 && x[1] <= 15)
Lee Leahy73402172017-03-10 15:23:24 -0800890 printk(BIOS_SPEW,
891 "Reserved video block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700892 else if (x[1] >= 19 && x[1] <= 31)
Lee Leahy73402172017-03-10 15:23:24 -0800893 printk(BIOS_SPEW,
894 "Reserved audio block (%02x)\n", x[1]);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700895 else
896 printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
897 break;
898 }
899 break;
900 default:
901 {
902 int tag = (*x & 0xe0) >> 5;
903 int length = *x & 0x1f;
904 printk(BIOS_SPEW,
Lee Leahy73402172017-03-10 15:23:24 -0800905 " Unknown tag %d, length %d (raw %02x)\n",
906 tag, length, *x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700907 break;
908 }
909 }
910}
911
912static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800913parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700914{
915 int ret = 0;
916 int version = x[1];
917 int offset = x[2];
918 unsigned char *detailed;
919
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800920 if (version >= 1)
921 do {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700922 if (version == 1 && x[3] != 0)
923 ret = 1;
924
925 if (offset < 4)
926 break;
927
Lee Leahye20a3192017-03-09 16:21:34 -0800928 if (version < 3)
Lee Leahy73402172017-03-10 15:23:24 -0800929 printk(BIOS_SPEW,
930 "%d 8-byte timing descriptors\n",
931 (offset - 4) / 8);
Lee Leahye20a3192017-03-09 16:21:34 -0800932 else if (version == 3) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700933 int i;
Lee Leahy73402172017-03-10 15:23:24 -0800934 printk(BIOS_SPEW,
935 "%d bytes of CEA data\n", offset - 4);
Lee Leahy2f919ec2017-03-08 17:37:06 -0800936 for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700937 cea_block(out, x + i);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700938 }
939
940 if (version >= 2) {
941 if (x[3] & 0x80)
Lee Leahy73402172017-03-10 15:23:24 -0800942 printk(BIOS_SPEW,
943 "Underscans PC formats by default\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700944 if (x[3] & 0x40)
Lee Leahy73402172017-03-10 15:23:24 -0800945 printk(BIOS_SPEW,
946 "Basic audio support\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700947 if (x[3] & 0x20)
Lee Leahy73402172017-03-10 15:23:24 -0800948 printk(BIOS_SPEW,
949 "Supports YCbCr 4:4:4\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700950 if (x[3] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -0800951 printk(BIOS_SPEW,
952 "Supports YCbCr 4:2:2\n");
953 printk(BIOS_SPEW,
954 "%d native detailed modes\n",
955 x[3] & 0x0f);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700956 }
957
Lee Leahy73402172017-03-10 15:23:24 -0800958 for (detailed = x + offset; detailed + 18 < x + 127;
959 detailed += 18)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700960 if (detailed[0])
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800961 detailed_block(out, detailed, 1, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700962 } while (0);
963
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800964 c->has_valid_checksum &= do_checksum(x);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700965 return ret;
966}
967
968/* generic extension code */
969
970static void
971extension_version(struct edid *out, unsigned char *x)
972{
973 printk(BIOS_SPEW, "Extension version: %d\n", x[1]);
974}
975
976static int
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800977parse_extension(struct edid *out, unsigned char *x, struct edid_context *c)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700978{
979 int conformant_extension = 0;
980 printk(BIOS_SPEW, "\n");
981
Lee Leahy45fde702017-03-08 18:02:24 -0800982 switch (x[0]) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700983 case 0x02:
984 printk(BIOS_SPEW, "CEA extension block\n");
985 extension_version(out, x);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +0800986 conformant_extension = parse_cea(out, x, c);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -0700987 break;
Lee Leahyb6ee0f92017-03-09 13:35:26 -0800988 case 0x10:
989 printk(BIOS_SPEW, "VTB extension block\n");
990 break;
991 case 0x40:
992 printk(BIOS_SPEW, "DI extension block\n");
993 break;
994 case 0x50:
995 printk(BIOS_SPEW, "LS extension block\n");
996 break;
997 case 0x60:
998 printk(BIOS_SPEW, "DPVL extension block\n");
999 break;
1000 case 0xF0:
1001 printk(BIOS_SPEW, "Block map\n");
1002 break;
1003 case 0xFF:
1004 printk(BIOS_SPEW, "Manufacturer-specific extension block\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001005 default:
1006 printk(BIOS_SPEW, "Unknown extension block\n");
1007 break;
1008 }
1009
1010 printk(BIOS_SPEW, "\n");
1011
1012 return conformant_extension;
1013}
1014
1015static const struct {
1016 int x, y, refresh;
1017} established_timings[] = {
1018 /* 0x23 bit 7 - 0 */
1019 {720, 400, 70},
1020 {720, 400, 88},
1021 {640, 480, 60},
1022 {640, 480, 67},
1023 {640, 480, 72},
1024 {640, 480, 75},
1025 {800, 600, 56},
1026 {800, 600, 60},
1027 /* 0x24 bit 7 - 0 */
1028 {800, 600, 72},
1029 {800, 600, 75},
1030 {832, 624, 75},
1031 {1280, 768, 87},
1032 {1024, 768, 60},
1033 {1024, 768, 70},
1034 {1024, 768, 75},
1035 {1280, 1024, 75},
1036 /* 0x25 bit 7*/
1037 {1152, 870, 75},
1038};
1039
1040static void print_subsection(const char *name, unsigned char *edid, int start,
1041 int end)
1042{
1043 int i;
1044
1045 printk(BIOS_SPEW, "%s:", name);
1046 for (i = strlen(name); i < 15; i++)
1047 printk(BIOS_SPEW, " ");
1048 for (i = start; i <= end; i++)
1049 printk(BIOS_SPEW, " %02x", edid[i]);
1050 printk(BIOS_SPEW, "\n");
1051}
1052
1053static void dump_breakdown(unsigned char *edid)
1054{
1055 printk(BIOS_SPEW, "Extracted contents:\n");
1056 print_subsection("header", edid, 0, 7);
1057 print_subsection("serial number", edid, 8, 17);
Lee Leahy35af5c42017-03-09 17:35:28 -08001058 print_subsection("version", edid, 18, 19);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001059 print_subsection("basic params", edid, 20, 24);
1060 print_subsection("chroma info", edid, 25, 34);
1061 print_subsection("established", edid, 35, 37);
1062 print_subsection("standard", edid, 38, 53);
1063 print_subsection("descriptor 1", edid, 54, 71);
1064 print_subsection("descriptor 2", edid, 72, 89);
1065 print_subsection("descriptor 3", edid, 90, 107);
1066 print_subsection("descriptor 4", edid, 108, 125);
1067 print_subsection("extensions", edid, 126, 126);
1068 print_subsection("checksum", edid, 127, 127);
1069 printk(BIOS_SPEW, "\n");
1070}
1071
1072/*
David Hendrickse2054102015-08-07 18:41:37 -07001073 * Lookup table of some well-known modes that can be useful in case the
1074 * auto-detected mode is unsuitable.
1075 * ha = hdisplay; va = vdisplay;
1076 * hbl = htotal - hdisplay; vbl = vtotal - vdisplay;
1077 * hso = hsync_start - hdsiplay; vso = vsync_start - vdisplay;
1078 * hspw = hsync_end - hsync_start; vspw = vsync_end - vsync_start;
1079 */
1080static struct edid_mode known_modes[NUM_KNOWN_MODES] = {
1081 [EDID_MODE_640x480_60Hz] = {
Douglas Anderson78e226cf2015-10-28 09:52:22 -07001082 .name = "640x480@60Hz", .pixel_clock = 25200, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001083 .ha = 640, .hbl = 160, .hso = 16, .hspw = 96,
David Hendrickse2054102015-08-07 18:41:37 -07001084 .va = 480, .vbl = 45, .vso = 10, .vspw = 2,
1085 .phsync = '-', .pvsync = '-' },
1086 [EDID_MODE_720x480_60Hz] = {
1087 .name = "720x480@60Hz", .pixel_clock = 27000, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001088 .ha = 720, .hbl = 138, .hso = 16, .hspw = 62,
David Hendrickse2054102015-08-07 18:41:37 -07001089 .va = 480, .vbl = 45, .vso = 9, .vspw = 6,
1090 .phsync = '-', .pvsync = '-' },
1091 [EDID_MODE_1280x720_60Hz] = {
1092 .name = "1280x720@60Hz", .pixel_clock = 74250, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001093 .ha = 1280, .hbl = 370, .hso = 110, .hspw = 40,
David Hendrickse2054102015-08-07 18:41:37 -07001094 .va = 720, .vbl = 30, .vso = 5, .vspw = 20,
1095 .phsync = '+', .pvsync = '+' },
1096 [EDID_MODE_1920x1080_60Hz] = {
1097 .name = "1920x1080@60Hz", .pixel_clock = 148500, .refresh = 60,
Yakir Yangbedbdc42015-08-18 04:18:09 -05001098 .ha = 1920, .hbl = 280, .hso = 88, .hspw = 44,
David Hendrickse2054102015-08-07 18:41:37 -07001099 .va = 1080, .vbl = 45, .vso = 4, .vspw = 5,
1100 .phsync = '+', .pvsync = '+' },
1101};
1102
1103int set_display_mode(struct edid *edid, enum edid_modes mode)
1104{
1105 if (mode == EDID_MODE_AUTO)
1106 return 0;
1107
1108 if (edid->mode_is_supported[mode]) {
1109 printk(BIOS_DEBUG, "Forcing mode %s\n", known_modes[mode].name);
1110 edid->mode = known_modes[mode];
1111 return 0;
1112 }
1113
1114 printk(BIOS_ERR, "Requested display mode not supported.\n");
1115 return -1;
1116}
1117
1118/*
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001119 * Given a raw edid bloc, decode it into a form
1120 * that other parts of coreboot can use -- mainly
1121 * graphics bringup functions. The raw block is
1122 * required to be 128 bytes long, per the standard,
1123 * but we have no way of checking this minimum length.
1124 * We accept what we are given.
1125 */
1126int decode_edid(unsigned char *edid, int size, struct edid *out)
1127{
David Hendrickse2054102015-08-07 18:41:37 -07001128 int analog, i, j;
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001129 struct edid_context c = {
1130 .has_valid_cvt = 1,
1131 .has_valid_dummy_block = 1,
1132 .has_valid_descriptor_ordering = 1,
Vince Hsu4213b972014-04-21 17:07:57 +08001133 .has_valid_detailed_blocks = 1,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001134 .has_valid_descriptor_pad = 1,
1135 .has_valid_range_descriptor = 1,
1136 .has_valid_max_dotclock = 1,
1137 .has_valid_string_termination = 1,
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001138 .conformant = EDID_CONFORMANT,
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001139 };
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001140
David Hendricks40e89b42015-08-13 15:51:00 -07001141 memset(out, 0, sizeof(*out));
1142
Jacob Garbercd23f7f2019-03-25 19:53:45 -06001143 if (!edid) {
1144 printk(BIOS_SPEW, "No EDID found\n");
1145 return EDID_ABSENT;
1146 }
1147
1148 dump_breakdown(edid);
1149
1150 if (memcmp(edid, "\x00\xFF\xFF\xFF\xFF\xFF\xFF\x00", 8)) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001151 printk(BIOS_SPEW, "No header found\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001152 return EDID_ABSENT;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001153 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001154
David Hendricksa3b898a2015-08-02 18:07:48 -07001155 if (manufacturer_name(edid + 0x08))
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001156 c.manufacturer_name_well_formed = 1;
1157
David Hendricksa3b898a2015-08-02 18:07:48 -07001158 extra_info.model = (unsigned short)(edid[0x0A] + (edid[0x0B] << 8));
1159 extra_info.serial = (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001160 + (edid[0x0E] << 16) + (edid[0x0F] << 24));
1161
1162 printk(BIOS_SPEW, "Manufacturer: %s Model %x Serial Number %u\n",
David Hendricksa3b898a2015-08-02 18:07:48 -07001163 extra_info.manuf_name,
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001164 (unsigned short)(edid[0x0A] + (edid[0x0B] << 8)),
1165 (unsigned int)(edid[0x0C] + (edid[0x0D] << 8)
1166 + (edid[0x0E] << 16) + (edid[0x0F] << 24)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001167 /* XXX need manufacturer ID table */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001168
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001169 if (edid[0x10] < 55 || edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001170 c.has_valid_week = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001171 if (edid[0x11] > 0x0f) {
1172 if (edid[0x10] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001173 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001174 printk(BIOS_SPEW,
1175 "Made week %hhd of model year %hhd\n",
1176 edid[0x10], edid[0x11]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001177 extra_info.week = edid[0x10];
1178 extra_info.year = edid[0x11];
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001179 } else {
Lee Leahy73402172017-03-10 15:23:24 -08001180 /* we know it's at least 2013, when this code
1181 * was written
1182 */
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001183 if (edid[0x11] + 90 <= 2013) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001184 c.has_valid_year = 1;
Lee Leahy73402172017-03-10 15:23:24 -08001185 printk(BIOS_SPEW,
1186 "Made week %hhd of %d\n",
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001187 edid[0x10], edid[0x11] + 1990);
David Hendricksa3b898a2015-08-02 18:07:48 -07001188 extra_info.week = edid[0x10];
1189 extra_info.year = edid[0x11] + 1990;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001190 }
1191 }
1192 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001193 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001194
Alexandru Gagniuc9d0ae592014-12-10 16:44:44 -06001195 printk(BIOS_SPEW, "EDID version: %hhd.%hhd\n", edid[0x12], edid[0x13]);
David Hendricksa3b898a2015-08-02 18:07:48 -07001196 extra_info.version[0] = edid[0x12];
1197 extra_info.version[1] = edid[0x13];
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001198
1199 if (edid[0x12] == 1) {
1200 if (edid[0x13] > 4) {
Lee Leahy73402172017-03-10 15:23:24 -08001201 printk(BIOS_SPEW,
1202 "Claims > 1.4, assuming 1.4 conformance\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001203 edid[0x13] = 4;
1204 }
1205 switch (edid[0x13]) {
1206 case 4:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001207 c.claims_one_point_four = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001208 case 3:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001209 c.claims_one_point_three = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001210 case 2:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001211 c.claims_one_point_two = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001212 default:
1213 break;
1214 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001215 c.claims_one_point_oh = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001216 }
1217
1218 /* display section */
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001219 if (edid[0x14] & 0x80) {
1220 int conformance_mask;
1221 analog = 0;
1222 printk(BIOS_SPEW, "Digital display\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001223 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001224 conformance_mask = 0;
1225 if ((edid[0x14] & 0x70) == 0x00)
1226 printk(BIOS_SPEW, "Color depth is undefined\n");
1227 else if ((edid[0x14] & 0x70) == 0x70)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001228 c.nonconformant_digital_display = 1;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001229 else
Lee Leahy73402172017-03-10 15:23:24 -08001230 printk(BIOS_SPEW,
1231 "%d bits per primary color channel\n",
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001232 ((edid[0x14] & 0x70) >> 3) + 4);
Lee Leahy73402172017-03-10 15:23:24 -08001233 out->panel_bits_per_color = ((edid[0x14] & 0x70) >> 3)
1234 + 4;
Ronald G. Minnich9518b562013-09-19 16:45:22 -07001235 out->panel_bits_per_pixel = 3*out->panel_bits_per_color;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001236
1237 switch (edid[0x14] & 0x0f) {
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001238 case 0x00:
Lee Leahy73402172017-03-10 15:23:24 -08001239 printk(BIOS_SPEW,
1240 "Digital interface is not defined\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001241 break;
1242 case 0x01:
1243 printk(BIOS_SPEW, "DVI interface\n");
1244 break;
1245 case 0x02:
1246 printk(BIOS_SPEW, "HDMI-a interface\n");
1247 break;
1248 case 0x03:
1249 printk(BIOS_SPEW, "HDMI-b interface\n");
1250 break;
1251 case 0x04:
1252 printk(BIOS_SPEW, "MDDI interface\n");
1253 break;
1254 case 0x05:
1255 printk(BIOS_SPEW, "DisplayPort interface\n");
1256 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001257 default:
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001258 c.nonconformant_digital_display = 1;
1259 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001260 }
David Hendricksa3b898a2015-08-02 18:07:48 -07001261 extra_info.type = edid[0x14] & 0x0f;
Lee Leahye20a3192017-03-09 16:21:34 -08001262 } else if (c.claims_one_point_two) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001263 conformance_mask = 0x7E;
Lee Leahy2f919ec2017-03-08 17:37:06 -08001264 if (edid[0x14] & 0x01)
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001265 printk(BIOS_SPEW, "DFP 1.x compatible TMDS\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001266 } else
1267 conformance_mask = 0x7F;
1268
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001269 if (!c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001270 c.nonconformant_digital_display = edid[0x14]
1271 & conformance_mask;
David Hendricksa3b898a2015-08-02 18:07:48 -07001272 extra_info.nonconformant = c.nonconformant_digital_display;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001273 } else {
1274 analog = 1;
1275 int voltage = (edid[0x14] & 0x60) >> 5;
1276 int sync = (edid[0x14] & 0x0F);
David Hendricksa3b898a2015-08-02 18:07:48 -07001277 extra_info.voltage = voltage;
1278 extra_info.sync = sync;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001279
1280 printk(BIOS_SPEW, "Analog display, Input voltage level: %s V\n",
1281 voltage == 3 ? "0.7/0.7" :
1282 voltage == 2 ? "1.0/0.4" :
1283 voltage == 1 ? "0.714/0.286" :
1284 "0.7/0.3");
1285
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001286 if (c.claims_one_point_four) {
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001287 if (edid[0x14] & 0x10)
Lee Leahy73402172017-03-10 15:23:24 -08001288 printk(BIOS_SPEW,
1289 "Blank-to-black setup/pedestal\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001290 else
Lee Leahy73402172017-03-10 15:23:24 -08001291 printk(BIOS_SPEW,
1292 "Blank level equals black level\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001293 } else if (edid[0x14] & 0x10) {
1294 /*
Lee Leahy73402172017-03-10 15:23:24 -08001295 * XXX this is just the X text. 1.3 says "if set,
1296 * display expects a blank-to-black setup or pedestal
1297 * per appropriate Signal Level Standard". Whatever
1298 * _that_ means.
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001299 */
1300 printk(BIOS_SPEW, "Configurable signal levels\n");
1301 }
1302
Lee Leahy73402172017-03-10 15:23:24 -08001303 printk(BIOS_SPEW, "Sync: %s%s%s%s\n",
1304 sync & 0x08 ? "Separate " : "",
1305 sync & 0x04 ? "Composite " : "",
1306 sync & 0x02 ? "SyncOnGreen " : "",
1307 sync & 0x01 ? "Serration " : "");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001308 }
1309
1310
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001311 if (edid[0x15] && edid[0x16]) {
1312 printk(BIOS_SPEW, "Maximum image size: %d cm x %d cm\n",
1313 edid[0x15], edid[0x16]);
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001314 } else if (c.claims_one_point_four && (edid[0x15] || edid[0x16])) {
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001315 if (edid[0x15]) { /* edid[0x15] != 0 && edid[0x16] == 0 */
1316 unsigned int ratio = 100000/(edid[0x15] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001317 printk(BIOS_SPEW,
1318 "Aspect ratio is %u.%03u (landscape)\n",
1319 ratio / 1000, ratio % 1000);
Patrick Georgibe71ee5d2014-12-15 22:52:14 +01001320 } else { /* edid[0x15] == 0 && edid[0x16] != 0 */
1321 unsigned int ratio = 100000/(edid[0x16] + 99);
Lee Leahy73402172017-03-10 15:23:24 -08001322 printk(BIOS_SPEW,
1323 "Aspect ratio is %u.%03u (portrait)\n",
1324 ratio / 1000, ratio % 1000);
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001325 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001326 } else {
1327 /* Either or both can be zero for 1.3 and before */
1328 printk(BIOS_SPEW, "Image size is variable\n");
1329 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001330
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001331 if (edid[0x17] == 0xff) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001332 if (c.claims_one_point_four)
Lee Leahy73402172017-03-10 15:23:24 -08001333 printk(BIOS_SPEW,
1334 "Gamma is defined in an extension block\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001335 else
1336 /* XXX Technically 1.3 doesn't say this... */
1337 printk(BIOS_SPEW, "Gamma: 1.0\n");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001338 } else
1339 printk(BIOS_SPEW, "Gamma: %d%%\n", ((edid[0x17] + 100)));
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001340 printk(BIOS_SPEW, "Check DPMS levels\n");
1341 if (edid[0x18] & 0xE0) {
1342 printk(BIOS_SPEW, "DPMS levels:");
Lee Leahyb6ee0f92017-03-09 13:35:26 -08001343 if (edid[0x18] & 0x80)
1344 printk(BIOS_SPEW, " Standby");
1345 if (edid[0x18] & 0x40)
1346 printk(BIOS_SPEW, " Suspend");
1347 if (edid[0x18] & 0x20)
1348 printk(BIOS_SPEW, " Off");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001349 printk(BIOS_SPEW, "\n");
1350 }
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001351
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001352 /* FIXME: this is from 1.4 spec, check earlier */
1353 if (analog) {
1354 switch (edid[0x18] & 0x18) {
Lee Leahye20a3192017-03-09 16:21:34 -08001355 case 0x00:
1356 printk(BIOS_SPEW, "Monochrome or grayscale display\n");
1357 break;
1358 case 0x08:
1359 printk(BIOS_SPEW, "RGB color display\n");
1360 break;
1361 case 0x10:
1362 printk(BIOS_SPEW, "Non-RGB color display\n");
1363 break;
1364 case 0x18:
1365 printk(BIOS_SPEW, "Undefined display color type\n");
1366 break;
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001367 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001368 } else {
1369 printk(BIOS_SPEW, "Supported color formats: RGB 4:4:4");
1370 if (edid[0x18] & 0x10)
1371 printk(BIOS_SPEW, ", YCrCb 4:4:4");
1372 if (edid[0x18] & 0x08)
1373 printk(BIOS_SPEW, ", YCrCb 4:2:2");
1374 printk(BIOS_SPEW, "\n");
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001375 }
1376
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001377 if (edid[0x18] & 0x04)
Lee Leahy73402172017-03-10 15:23:24 -08001378 printk(BIOS_SPEW,
1379 "Default (sRGB) color space is primary color space\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001380 if (edid[0x18] & 0x02) {
Lee Leahy73402172017-03-10 15:23:24 -08001381 printk(BIOS_SPEW,
1382 "First detailed timing is preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001383 c.has_preferred_timing = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001384 }
1385 if (edid[0x18] & 0x01)
Lee Leahy73402172017-03-10 15:23:24 -08001386 printk(BIOS_SPEW,
1387 "Supports GTF timings within operating range\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001388
1389 /* XXX color section */
1390
1391 printk(BIOS_SPEW, "Established timings supported:\n");
1392 /* it's not yet clear we want all this stuff in the edid struct.
1393 * Let's wait.
1394 */
1395 for (i = 0; i < 17; i++) {
1396 if (edid[0x23 + i / 8] & (1 << (7 - i % 8))) {
Lee Leahy73402172017-03-10 15:23:24 -08001397 printk(BIOS_SPEW, " %dx%d@%dHz\n",
1398 established_timings[i].x,
1399 established_timings[i].y,
1400 established_timings[i].refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001401
Douglas Anderson9fa07602015-10-28 10:19:52 -07001402 for (j = 0; j < NUM_KNOWN_MODES; j++) {
Lee Leahy73402172017-03-10 15:23:24 -08001403 if (known_modes[j].ha ==
1404 established_timings[i].x
1405 && known_modes[j].va ==
1406 established_timings[i].y
1407 && known_modes[j].refresh ==
1408 established_timings[i].refresh)
David Hendrickse2054102015-08-07 18:41:37 -07001409 out->mode_is_supported[j] = 1;
Douglas Anderson9fa07602015-10-28 10:19:52 -07001410 }
David Hendrickse2054102015-08-07 18:41:37 -07001411 }
1412
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001413 }
1414
1415 printk(BIOS_SPEW, "Standard timings supported:\n");
1416 for (i = 0; i < 8; i++) {
1417 uint8_t b1 = edid[0x26 + i * 2], b2 = edid[0x26 + i * 2 + 1];
1418 unsigned int x, y = 0, refresh;
1419
1420 if (b1 == 0x01 && b2 == 0x01)
1421 continue;
1422
1423 if (b1 == 0) {
Lee Leahy73402172017-03-10 15:23:24 -08001424 printk(BIOS_SPEW,
1425 "non-conformant standard timing (0 horiz)\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001426 continue;
1427 }
1428 x = (b1 + 31) * 8;
1429 switch ((b2 >> 6) & 0x3) {
1430 case 0x00:
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001431 if (c.claims_one_point_three)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001432 y = x * 10 / 16;
1433 else
1434 y = x;
1435 break;
1436 case 0x01:
1437 y = x * 3 / 4;
1438 break;
1439 case 0x02:
1440 y = x * 4 / 5;
1441 break;
1442 case 0x03:
1443 y = x * 9 / 16;
1444 break;
1445 }
1446 refresh = 60 + (b2 & 0x3f);
1447
1448 printk(BIOS_SPEW, " %dx%d@%dHz\n", x, y, refresh);
David Hendrickse2054102015-08-07 18:41:37 -07001449 for (j = 0; j < NUM_KNOWN_MODES; j++) {
1450 if (known_modes[j].ha == x && known_modes[j].va == y &&
1451 known_modes[j].refresh == refresh)
1452 out->mode_is_supported[j] = 1;
1453 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001454 }
1455
1456 /* detailed timings */
1457 printk(BIOS_SPEW, "Detailed timings\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001458 for (i = 0; i < 4; i++) {
1459 c.has_valid_detailed_blocks &= detailed_block(
1460 out, edid + 0x36 + i * 18, 0, &c);
Lee Leahy342f8d62017-03-10 15:31:56 -08001461 if (i == 0 && c.has_preferred_timing
1462 && !c.did_detailed_timing) {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001463 /* not really accurate... */
1464 c.has_preferred_timing = 0;
1465 }
1466 }
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001467
1468 /* check this, 1.4 verification guide says otherwise */
1469 if (edid[0x7e]) {
1470 printk(BIOS_SPEW, "Has %d extension blocks\n", edid[0x7e]);
1471 /* 2 is impossible because of the block map */
1472 if (edid[0x7e] != 2)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001473 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001474 } else {
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001475 c.has_valid_extension_count = 1;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001476 }
1477
1478 printk(BIOS_SPEW, "Checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001479 c.has_valid_checksum = do_checksum(edid);
Hung-Te Lin79445812014-04-03 18:35:58 +08001480
1481 /* EDID v2.0 has a larger blob (256 bytes) and may have some problem in
1482 * the extension parsing loop below. Since v2.0 was quickly deprecated
1483 * by v1.3 and we are unlikely to use any EDID 2.0 panels, we ignore
1484 * that case now and can fix it when we need to use a real 2.0 panel.
1485 */
Lee Leahy45fde702017-03-08 18:02:24 -08001486 for (i = 128; i < size; i += 128)
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001487 c.nonconformant_extension +=
1488 parse_extension(out, &edid[i], &c);
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001489
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001490 if (c.claims_one_point_four) {
1491 if (c.nonconformant_digital_display ||
1492 !c.has_valid_string_termination ||
1493 !c.has_valid_descriptor_pad ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001494 !c.has_preferred_timing) {
1495 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001496 printk(BIOS_ERR,
1497 "EDID block does NOT conform to EDID 1.4!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001498 }
1499
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001500 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001501 printk(BIOS_ERR,
1502 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001503 c.nonconformant_digital_display);
1504 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001505 printk(BIOS_ERR,
1506 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001507 if (!c.has_valid_descriptor_pad)
Lee Leahy73402172017-03-10 15:23:24 -08001508 printk(BIOS_ERR,
1509 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001510 if (!c.has_preferred_timing)
Hung-Te Lin08f6c802014-04-03 21:13:11 +08001511 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001512 } else if (c.claims_one_point_three) {
1513 if (c.nonconformant_digital_display ||
1514 !c.has_valid_string_termination ||
1515 !c.has_valid_descriptor_pad ||
1516 !c.has_preferred_timing) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001517 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Lin076c3172014-04-03 21:13:11 +08001518 }
1519 /**
1520 * According to E-EDID (EDIDv1.3), has_name_descriptor and
1521 * has_range_descriptor are both required. These fields are
1522 * optional in v1.4. However some v1.3 panels (Ex, B133XTN01.3)
1523 * don't have them. As a workaround, we only print warning
1524 * messages.
1525 */
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001526 if (c.conformant == EDID_NOT_CONFORMANT)
Lee Leahy73402172017-03-10 15:23:24 -08001527 printk(BIOS_ERR,
1528 "EDID block does NOT conform to EDID 1.3!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001529 else if (!c.has_name_descriptor || !c.has_range_descriptor)
Hung-Te Lin076c3172014-04-03 21:13:11 +08001530 printk(BIOS_WARNING, "WARNING: EDID block does NOT "
1531 "fully conform to EDID 1.3.\n");
1532
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001533 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001534 printk(BIOS_ERR,
1535 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001536 c.nonconformant_digital_display);
1537 if (!c.has_name_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001538 printk(BIOS_ERR, "\tMissing name descriptor\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001539 if (!c.has_preferred_timing)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001540 printk(BIOS_ERR, "\tMissing preferred timing\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001541 if (!c.has_range_descriptor)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001542 printk(BIOS_ERR, "\tMissing monitor ranges\n");
Lee Leahy73402172017-03-10 15:23:24 -08001543 /* Might be more than just 1.3 */
1544 if (!c.has_valid_descriptor_pad)
1545 printk(BIOS_ERR,
1546 "\tInvalid descriptor block padding\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001547 if (!c.has_valid_string_termination) /* Likewise */
Lee Leahy73402172017-03-10 15:23:24 -08001548 printk(BIOS_ERR,
1549 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001550 } else if (c.claims_one_point_two) {
1551 if (c.nonconformant_digital_display ||
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001552 !c.has_valid_string_termination) {
1553 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001554 printk(BIOS_ERR,
1555 "EDID block does NOT conform to EDID 1.2!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001556 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001557 if (c.nonconformant_digital_display)
Lee Leahy73402172017-03-10 15:23:24 -08001558 printk(BIOS_ERR,
1559 "\tDigital display field contains garbage: %x\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001560 c.nonconformant_digital_display);
1561 if (!c.has_valid_string_termination)
Lee Leahy73402172017-03-10 15:23:24 -08001562 printk(BIOS_ERR,
1563 "\tDetailed block string not properly terminated\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001564 } else if (c.claims_one_point_oh) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001565 if (c.seen_non_detailed_descriptor) {
1566 c.conformant = EDID_NOT_CONFORMANT;
Lee Leahy73402172017-03-10 15:23:24 -08001567 printk(BIOS_ERR,
1568 "EDID block does NOT conform to EDID 1.0!\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001569 }
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001570 if (c.seen_non_detailed_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001571 printk(BIOS_ERR,
1572 "\tHas descriptor blocks other than detailed timings\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001573 }
1574
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001575 if (c.nonconformant_extension ||
1576 !c.has_valid_checksum ||
1577 !c.has_valid_cvt ||
1578 !c.has_valid_year ||
1579 !c.has_valid_week ||
1580 !c.has_valid_detailed_blocks ||
1581 !c.has_valid_dummy_block ||
1582 !c.has_valid_extension_count ||
1583 !c.has_valid_descriptor_ordering ||
1584 !c.has_valid_range_descriptor ||
1585 !c.manufacturer_name_well_formed) {
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001586 c.conformant = EDID_NOT_CONFORMANT;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001587 printk(BIOS_ERR, "EDID block does not conform at all!\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001588 if (c.nonconformant_extension)
Lee Leahy73402172017-03-10 15:23:24 -08001589 printk(BIOS_ERR,
1590 "\tHas %d nonconformant extension block(s)\n",
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001591 c.nonconformant_extension);
1592 if (!c.has_valid_checksum)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001593 printk(BIOS_ERR, "\tBlock has broken checksum\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001594 if (!c.has_valid_cvt)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001595 printk(BIOS_ERR, "\tBroken 3-byte CVT blocks\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001596 if (!c.has_valid_year)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001597 printk(BIOS_ERR, "\tBad year of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001598 if (!c.has_valid_week)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001599 printk(BIOS_ERR, "\tBad week of manufacture\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001600 if (!c.has_valid_detailed_blocks)
Lee Leahy73402172017-03-10 15:23:24 -08001601 printk(BIOS_ERR,
1602 "\tDetailed blocks filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001603 if (!c.has_valid_dummy_block)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001604 printk(BIOS_ERR, "\tDummy block filled with garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001605 if (!c.has_valid_extension_count)
Lee Leahy73402172017-03-10 15:23:24 -08001606 printk(BIOS_ERR,
1607 "\tImpossible extension block count\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001608 if (!c.manufacturer_name_well_formed)
Lee Leahy73402172017-03-10 15:23:24 -08001609 printk(BIOS_ERR,
1610 "\tManufacturer name field contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001611 if (!c.has_valid_descriptor_ordering)
Lee Leahy73402172017-03-10 15:23:24 -08001612 printk(BIOS_ERR,
1613 "\tInvalid detailed timing descriptor ordering\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001614 if (!c.has_valid_range_descriptor)
Lee Leahy73402172017-03-10 15:23:24 -08001615 printk(BIOS_ERR,
1616 "\tRange descriptor contains garbage\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001617 if (!c.has_valid_max_dotclock)
Lee Leahy73402172017-03-10 15:23:24 -08001618 printk(BIOS_ERR,
1619 "\tEDID 1.4 block does not set max dotclock\n");
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001620 }
1621
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001622 if (c.warning_excessive_dotclock_correction)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001623 printk(BIOS_ERR,
1624 "Warning: CVT block corrects dotclock by more than 9.75MHz\n");
Hung-Te Lin1c8ee212014-04-17 15:21:37 +08001625 if (c.warning_zero_preferred_refresh)
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001626 printk(BIOS_ERR,
1627 "Warning: CVT block does not set preferred refresh rate\n");
Arthur Heymans8c5884e2017-04-30 08:28:05 +02001628 return c.conformant;
Hung-Te Linfc0d2442014-04-03 18:33:01 +08001629}
1630
Ronald G. Minnichb3b72f32013-03-13 14:35:01 -07001631/*
1632 * Notes on panel extensions: (TODO, implement me in the code)
1633 *
1634 * EPI: http://www.epi-standard.org/fileadmin/spec/EPI_Specification1.0.pdf
1635 * at offset 0x6c (fourth detailed block): (all other bits reserved)
1636 * 0x6c: 00 00 00 0e 00
1637 * 0x71: bit 6-5: data color mapping (00 conventional/fpdi/vesa, 01 openldi)
1638 * bit 4-3: pixels per clock (00 1, 01 2, 10 4, 11 reserved)
1639 * bit 2-0: bits per pixel (000 18, 001 24, 010 30, else reserved)
1640 * 0x72: bit 5: FPSCLK polarity (0 normal 1 inverted)
1641 * bit 4: DE polarity (0 high active 1 low active)
1642 * bit 3-0: interface (0000 LVDS TFT
1643 * 0001 mono STN 4/8bit
1644 * 0010 color STN 8/16 bit
1645 * 0011 18 bit tft
1646 * 0100 24 bit tft
1647 * 0101 tmds
1648 * else reserved)
1649 * 0x73: bit 1: horizontal display mode (0 normal 1 right/left reverse)
1650 * bit 0: vertical display mode (0 normal 1 up/down reverse)
1651 * 0x74: bit 7-4: total poweroff seq delay (0000 vga controller default
1652 * else time in 10ms (10ms to 150ms))
1653 * bit 3-0: total poweron seq delay (as above)
1654 * 0x75: contrast power on/off seq delay, same as 0x74
1655 * 0x76: bit 7: backlight control enable (1 means this field is valid)
1656 * bit 6: backlight enabled at boot (0 on 1 off)
1657 * bit 5-0: backlight brightness control steps (0..63)
1658 * 0x77: bit 7: contrast control, same bit pattern as 0x76 except bit 6 resvd
1659 * 0x78 - 0x7c: reserved
1660 * 0x7d: bit 7-4: EPI descriptor major version (1)
1661 * bit 3-0: EPI descriptor minor version (0)
1662 *
1663 * ----
1664 *
1665 * SPWG: http://www.spwg.org/spwg_spec_version3.8_3-14-2007.pdf
1666 *
1667 * Since these are "dummy" blocks, terminate with 0a 20 20 20 ... as usual
1668 *
1669 * detailed descriptor 3:
1670 * 0x5a - 0x5e: 00 00 00 fe 00
1671 * 0x5f - 0x63: PC maker part number
1672 * 0x64: LCD supplier revision #
1673 * 0x65 - 0x6b: manufacturer part number
1674 *
1675 * detailed descriptor 4:
1676 * 0x6c - 0x70: 00 00 00 fe 00
1677 * 0x71 - 0x78: smbus nits values (whut)
1678 * 0x79: number of lvds channels (1 or 2)
1679 * 0x7A: panel self test (1 if present)
1680 * and then dummy terminator
1681 *
1682 * SPWG also says something strange about the LSB of detailed descriptor 1:
1683 * "LSB is set to "1" if panel is DE-timing only. H/V can be ignored."
1684 */
Julius Werner69112192016-03-14 17:29:55 -07001685
1686/* Set the framebuffer bits-per-pixel, recalculating all dependent values. */
Julius Werner2b6db972016-04-06 12:50:40 -07001687void edid_set_framebuffer_bits_per_pixel(struct edid *edid, int fb_bpp,
1688 int row_byte_alignment)
Julius Werner69112192016-03-14 17:29:55 -07001689{
1690 /* Caller should pass a supported value, everything else is BUG(). */
1691 assert(fb_bpp == 32 || fb_bpp == 24 || fb_bpp == 16);
Julius Werner2b6db972016-04-06 12:50:40 -07001692 row_byte_alignment = max(row_byte_alignment, 1);
Julius Werner69112192016-03-14 17:29:55 -07001693
1694 edid->framebuffer_bits_per_pixel = fb_bpp;
1695 edid->bytes_per_line = ALIGN_UP(edid->mode.ha *
Elyes HAOUAS6df3b642018-11-26 22:53:49 +01001696 DIV_ROUND_UP(fb_bpp, 8), row_byte_alignment);
Julius Werner69112192016-03-14 17:29:55 -07001697 edid->x_resolution = edid->bytes_per_line / (fb_bpp / 8);
1698 edid->y_resolution = edid->mode.va;
1699}