-
Notifications
You must be signed in to change notification settings - Fork 1
/
edid.c
1810 lines (1675 loc) · 56.7 KB
/
edid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: MIT */
/* this is a pretty robust parser for EDID, and we're tasked with parsing
* an arbitrary panel. We will pass it a raw EDID block and a struct which
* it must fill in with values. The set of values we need is pretty limited
* at present.
*/
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "edid.h"
// #include <ctype.h>
// #include <commonlib/helpers.h>
// #include <console/console.h>
// #include <vbe.h>
struct edid_context
{
int claims_one_point_oh;
int claims_one_point_two;
int claims_one_point_three;
int claims_one_point_four;
int nonconformant_digital_display;
int nonconformant_extension;
int did_detailed_timing;
int has_name_descriptor;
int has_range_descriptor;
int has_preferred_timing;
int has_valid_checksum;
int has_valid_cvt;
int has_valid_dummy_block;
int has_valid_week;
int has_valid_year;
int has_valid_detailed_blocks;
int has_valid_extension_count;
int has_valid_descriptor_ordering;
int has_valid_descriptor_pad;
int has_valid_range_descriptor;
int has_valid_max_dotclock;
int has_valid_string_termination;
int manufacturer_name_well_formed;
int seen_non_detailed_descriptor;
int warning_excessive_dotclock_correction;
int warning_zero_preferred_refresh;
enum edid_status conformant;
};
/* Stuff that isn't used anywhere but is nice to pretty-print while
we're decoding everything else. */
static struct
{
unsigned int model;
unsigned int serial;
unsigned int year;
unsigned int week;
unsigned int version[2];
unsigned int nonconformant;
unsigned int type;
unsigned int x_mm;
unsigned int y_mm;
unsigned int voltage;
unsigned int sync;
const char *syncmethod;
const char *range_class;
const char *stereo;
} extra_info;
static struct edid tmp_edid;
static int manufacturer_name(unsigned char *x, char *output)
{
output[0] = ((x[0] & 0x7C) >> 2) + '@';
output[1] = ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@';
output[2] = (x[1] & 0x1F) + '@';
output[3] = 0;
if (isupper(output[0]) &&
isupper(output[1]) &&
isupper(output[2]))
return 1;
memset(output, 0, 4);
return 0;
}
static int
detailed_cvt_descriptor(unsigned char *x, int first)
{
const unsigned char empty[3] = {0, 0, 0};
static const char *names[] = {"50", "60", "75", "85"};
int width = 0, height = 0;
int valid = 1;
int fifty = 0, sixty = 0, seventyfive = 0, eightyfive = 0, reduced = 0;
if (!first && !memcmp(x, empty, 3))
return valid;
height = x[0];
height |= (x[1] & 0xf0) << 4;
height++;
height *= 2;
switch (x[1] & 0x0c)
{
case 0x00:
width = (height * 4) / 3;
break;
case 0x04:
width = (height * 16) / 9;
break;
case 0x08:
width = (height * 16) / 10;
break;
case 0x0c:
width = (height * 15) / 9;
break;
}
if (x[1] & 0x03)
valid = 0;
if (x[2] & 0x80)
valid = 0;
if (!(x[2] & 0x1f))
valid = 0;
fifty = (x[2] & 0x10);
sixty = (x[2] & 0x08);
seventyfive = (x[2] & 0x04);
eightyfive = (x[2] & 0x02);
reduced = (x[2] & 0x01);
if (!valid)
{
printk(BIOS_SPEW, " (broken)\n");
}
else
{
printk(BIOS_SPEW,
" %dx%d @ (%s%s%s%s%s) Hz (%s%s preferred)\n",
width, height,
fifty ? "50 " : "",
sixty ? "60 " : "",
seventyfive ? "75 " : "",
eightyfive ? "85 " : "",
reduced ? "60RB " : "",
names[(x[2] & 0x60) >> 5],
(((x[2] & 0x60) == 0x20) && reduced) ? "RB" : "");
}
return valid;
}
/* extract a CP437 string from a detailed subblock, checking for termination (if
* less than len of bytes) with LF and padded with SP.
*/
static char *
extract_string(unsigned char *x, int *valid_termination, int len)
{
static char ret[EDID_ASCII_STRING_LENGTH + 1];
int i, seen_newline = 0;
memset(ret, 0, sizeof(ret));
for (i = 0; i < MIN(len, EDID_ASCII_STRING_LENGTH); i++)
{
if (seen_newline)
{
if (x[i] != 0x20)
{
*valid_termination = 0;
return ret;
}
}
else if (x[i] == 0x0a)
{
seen_newline = 1;
}
else
{
/* normal characters */
ret[i] = x[i];
}
}
return ret;
}
/* 1 means valid data */
static int
detailed_block(struct edid *result_edid, unsigned char *x, int in_extension,
struct edid_context *c)
{
struct edid *out = &tmp_edid;
int i;
if (console_log_level(BIOS_SPEW))
{
printk(BIOS_SPEW, "Hex of detail: ");
for (i = 0; i < 18; i++)
printk(BIOS_SPEW, "%02x", x[i]);
printk(BIOS_SPEW, "\n");
}
/* Result might already have some valid fields like mode_is_supported */
*out = *result_edid;
if (x[0] == 0 && x[1] == 0)
{
/* Monitor descriptor block, not detailed timing descriptor. */
if (x[2] != 0)
{
/* 1.3, 3.10.3 */
printk(BIOS_SPEW,
"Monitor descriptor block has byte 2 nonzero (0x%02x)\n",
x[2]);
c->has_valid_descriptor_pad = 0;
}
if (x[3] != 0xfd && x[4] != 0x00)
{
/* 1.3, 3.10.3 */
printk(BIOS_SPEW,
"Monitor descriptor block has byte 4 nonzero (0x%02x)\n",
x[4]);
c->has_valid_descriptor_pad = 0;
}
c->seen_non_detailed_descriptor = 1;
if (x[3] <= 0xF)
{
/*
* in principle we can decode these, if we know what
* they are.
* 0x0f seems to be common in laptop panels.
* 0x0e is used by EPI: http://www.epi-standard.org/
*/
printk(BIOS_SPEW,
"Manufacturer-specified data, tag %d\n", x[3]);
return 1;
}
switch (x[3])
{
case 0x10:
printk(BIOS_SPEW, "Dummy block\n");
for (i = 5; i < 18; i++)
if (x[i] != 0x00)
c->has_valid_dummy_block = 0;
return 1;
case 0xF7:
/* TODO */
printk(BIOS_SPEW, "Established timings III\n");
return 1;
case 0xF8:
{
int valid_cvt = 1; /* just this block */
printk(BIOS_SPEW, "CVT 3-byte code descriptor:\n");
if (x[5] != 0x01)
{
c->has_valid_cvt = 0;
return 0;
}
for (i = 0; i < 4; i++)
valid_cvt &= detailed_cvt_descriptor(x + 6 + (i * 3), (i == 0));
c->has_valid_cvt &= valid_cvt;
return 1;
}
case 0xF9:
/* TODO */
printk(BIOS_SPEW, "Color management data\n");
return 1;
case 0xFA:
/* TODO */
printk(BIOS_SPEW, "More standard timings\n");
return 1;
case 0xFB:
/* TODO */
printk(BIOS_SPEW, "Color point\n");
return 1;
case 0xFC:
printk(BIOS_SPEW, "Monitor name: %s\n",
extract_string(x + 5,
&c->has_valid_string_termination,
EDID_ASCII_STRING_LENGTH));
return 1;
case 0xFD:
{
int h_max_offset = 0, h_min_offset = 0;
int v_max_offset = 0, v_min_offset = 0;
int is_cvt = 0;
c->has_range_descriptor = 1;
extra_info.range_class = "";
/*
* XXX todo: implement feature flags, vtd blocks
* XXX check: ranges are well-formed; block termination
* if no vtd
*/
if (c->claims_one_point_four)
{
if (x[4] & 0x02)
{
v_max_offset = 255;
if (x[4] & 0x01)
v_min_offset = 255;
}
if (x[4] & 0x04)
{
h_max_offset = 255;
if (x[4] & 0x03)
h_min_offset = 255;
}
}
else if (x[4])
{
c->has_valid_range_descriptor = 0;
}
/*
* despite the values, this is not a bitfield.
*/
switch (x[10])
{
case 0x00: /* default gtf */
extra_info.range_class = "GTF";
break;
case 0x01: /* range limits only */
extra_info.range_class = "bare limits";
if (!c->claims_one_point_four)
c->has_valid_range_descriptor = 0;
break;
case 0x02: /* secondary gtf curve */
extra_info.range_class = "GTF with icing";
break;
case 0x04: /* cvt */
extra_info.range_class = "CVT";
is_cvt = 1;
if (!c->claims_one_point_four)
c->has_valid_range_descriptor = 0;
break;
default: /* invalid */
c->has_valid_range_descriptor = 0;
extra_info.range_class = "invalid";
break;
}
if (x[5] + v_min_offset > x[6] + v_max_offset)
c->has_valid_range_descriptor = 0;
if (x[7] + h_min_offset > x[8] + h_max_offset)
c->has_valid_range_descriptor = 0;
printk(BIOS_SPEW,
"Monitor ranges (%s): %d-%dHz V, %d-%dkHz H",
extra_info.range_class,
x[5] + v_min_offset, x[6] + v_max_offset,
x[7] + h_min_offset, x[8] + h_max_offset);
if (x[9])
printk(BIOS_SPEW,
", max dotclock %dMHz\n", x[9] * 10);
else
{
if (c->claims_one_point_four)
c->has_valid_max_dotclock = 0;
printk(BIOS_SPEW, "\n");
}
if (is_cvt)
{
int max_h_pixels = 0;
printk(BIOS_SPEW, "CVT version %d.%d\n",
x[11] & 0xf0 >> 4, x[11] & 0x0f);
if (x[12] & 0xfc)
{
int raw_offset = (x[12] & 0xfc) >> 2;
printk(BIOS_SPEW,
"Real max dotclock: %dKHz\n",
(x[9] * 10000) - (raw_offset * 250));
if (raw_offset >= 40)
c->warning_excessive_dotclock_correction = 1;
}
max_h_pixels = x[12] & 0x03;
max_h_pixels <<= 8;
max_h_pixels |= x[13];
max_h_pixels *= 8;
if (max_h_pixels)
printk(BIOS_SPEW,
"Max active pixels per line: %d\n",
max_h_pixels);
printk(BIOS_SPEW,
"Supported aspect ratios: %s %s %s %s %s\n",
x[14] & 0x80 ? "4:3" : "",
x[14] & 0x40 ? "16:9" : "",
x[14] & 0x20 ? "16:10" : "",
x[14] & 0x10 ? "5:4" : "",
x[14] & 0x08 ? "15:9" : "");
if (x[14] & 0x07)
c->has_valid_range_descriptor = 0;
printk(BIOS_SPEW, "Preferred aspect ratio: ");
switch ((x[15] & 0xe0) >> 5)
{
case 0x00:
printk(BIOS_SPEW, "4:3");
break;
case 0x01:
printk(BIOS_SPEW, "16:9");
break;
case 0x02:
printk(BIOS_SPEW, "16:10");
break;
case 0x03:
printk(BIOS_SPEW, "5:4");
break;
case 0x04:
printk(BIOS_SPEW, "15:9");
break;
default:
printk(BIOS_SPEW, "(broken)");
break;
}
printk(BIOS_SPEW, "\n");
if (x[15] & 0x04)
printk(BIOS_SPEW,
"Supports CVT standard blanking\n");
if (x[15] & 0x10)
printk(BIOS_SPEW,
"Supports CVT reduced blanking\n");
if (x[15] & 0x07)
c->has_valid_range_descriptor = 0;
if (x[16] & 0xf0)
{
printk(BIOS_SPEW,
"Supported display scaling:\n");
if (x[16] & 0x80)
printk(BIOS_SPEW,
" Horizontal shrink\n");
if (x[16] & 0x40)
printk(BIOS_SPEW,
" Horizontal stretch\n");
if (x[16] & 0x20)
printk(BIOS_SPEW,
" Vertical shrink\n");
if (x[16] & 0x10)
printk(BIOS_SPEW,
" Vertical stretch\n");
}
if (x[16] & 0x0f)
c->has_valid_range_descriptor = 0;
if (x[17])
printk(BIOS_SPEW,
"Preferred vertical refresh: %d Hz\n",
x[17]);
else
c->warning_zero_preferred_refresh = 1;
}
/*
* Slightly weird to return a global, but I've never
* seen any EDID block wth two range descriptors, so
* it's harmless.
*/
return 1;
}
case 0xFE:
/*
* TODO: Two of these in a row, in the third and fourth
* slots, seems to be specified by SPWG:
* http://www.spwg.org/
*/
strcpy(result_edid->ascii_string, extract_string(x + 5,
&c->has_valid_string_termination,
EDID_ASCII_STRING_LENGTH));
printk(BIOS_SPEW, "ASCII string: %s\n",
result_edid->ascii_string);
return 1;
case 0xFF:
printk(BIOS_SPEW, "Serial number: %s\n",
extract_string(x + 5,
&c->has_valid_string_termination,
EDID_ASCII_STRING_LENGTH));
return 1;
default:
printk(BIOS_SPEW,
"Unknown monitor description type %d\n",
x[3]);
return 0;
}
}
if (c->seen_non_detailed_descriptor && !in_extension)
c->has_valid_descriptor_ordering = 0;
bool supported = true;
if ((x[0] + (x[1] << 8)) * 10 > 62500)
{
supported = false;
printk(BIOS_SPEW,
"Not supported on stm32\n");
}
/* Edid contains pixel clock in terms of 10KHz */
out->mode.pixel_clock = (x[0] + (x[1] << 8)) * 10;
/*
LVDS supports following pixel clocks
25000...112000 kHz: single channel
80000...224000 kHz: dual channel
There is some overlap in theoretically supported
pixel clock between single-channel and dual-channel.
In practice with current panels all panels
<= 75200 kHz: single channel
>= 97750 kHz: dual channel
We have no samples between those values, so put a
threshold at 95000 kHz. If we get anything over
95000 kHz with single channel, we can make this
more sofisticated but it's currently not needed.
*/
out->mode.lvds_dual_channel = (out->mode.pixel_clock >= 95000);
extra_info.x_mm = (x[12] + ((x[14] & 0xF0) << 4));
extra_info.y_mm = (x[13] + ((x[14] & 0x0F) << 8));
out->mode.ha = (x[2] + ((x[4] & 0xF0) << 4));
out->mode.hbl = (x[3] + ((x[4] & 0x0F) << 8));
out->mode.hso = (x[8] + ((x[11] & 0xC0) << 2));
out->mode.hspw = (x[9] + ((x[11] & 0x30) << 4));
out->mode.hborder = x[15];
out->mode.va = (x[5] + ((x[7] & 0xF0) << 4));
out->mode.vbl = (x[6] + ((x[7] & 0x0F) << 8));
out->mode.vso = ((x[10] >> 4) + ((x[11] & 0x0C) << 2));
out->mode.vspw = ((x[10] & 0x0F) + ((x[11] & 0x03) << 4));
out->mode.vborder = x[16];
/* We assume rgb888 (32 bits per pixel) framebuffers by default.
* Chipsets that want something else will need to override this with
* another call to edid_set_framebuffer_bits_per_pixel(). As a cheap
* heuristic, assume that X86 systems require a 64-byte row alignment
* (since that seems to be true for most Intel chipsets). */
if (CONFIG(ARCH_X86))
edid_set_framebuffer_bits_per_pixel(out, 32, 64);
else
edid_set_framebuffer_bits_per_pixel(out, 16, 0);
switch ((x[17] & 0x18) >> 3)
{
case 0x00:
extra_info.syncmethod = " analog composite";
break;
case 0x01:
extra_info.syncmethod = " bipolar analog composite";
break;
case 0x02:
extra_info.syncmethod = " digital composite";
break;
case 0x03:
extra_info.syncmethod = "";
break;
}
out->mode.pvsync = (x[17] & (1 << 2)) ? '+' : '-';
out->mode.phsync = (x[17] & (1 << 1)) ? '+' : '-';
switch (x[17] & 0x61)
{
case 0x20:
extra_info.stereo = "field sequential L/R";
break;
case 0x40:
extra_info.stereo = "field sequential R/L";
break;
case 0x21:
extra_info.stereo = "interleaved right even";
break;
case 0x41:
extra_info.stereo = "interleaved left even";
break;
case 0x60:
extra_info.stereo = "four way interleaved";
break;
case 0x61:
extra_info.stereo = "side by side interleaved";
break;
default:
extra_info.stereo = "";
break;
}
printk(BIOS_SPEW,
"Detailed mode (IN HEX): Clock %d KHz, %x mm x %x mm\n"
" %04x %04x %04x %04x hborder %x\n"
" %04x %04x %04x %04x vborder %x\n"
" %chsync %cvsync%s%s %s\n",
out->mode.pixel_clock,
extra_info.x_mm,
extra_info.y_mm,
out->mode.ha, out->mode.ha + out->mode.hso,
out->mode.ha + out->mode.hso + out->mode.hspw,
out->mode.ha + out->mode.hbl, out->mode.hborder,
out->mode.va, out->mode.va + out->mode.vso,
out->mode.va + out->mode.vso + out->mode.vspw,
out->mode.va + out->mode.vbl, out->mode.vborder,
out->mode.phsync, out->mode.pvsync,
extra_info.syncmethod, x[17] & 0x80 ? " interlaced" : "",
extra_info.stereo);
if (!c->did_detailed_timing && supported)
{
printk(BIOS_SPEW, "Did detailed timing\n");
c->did_detailed_timing = 1;
*result_edid = *out;
}
return 1;
}
static int
do_checksum(unsigned char *x)
{
int valid = 0;
printk(BIOS_SPEW, "Checksum: 0x%hhx", x[0x7f]);
{
unsigned char sum = 0;
int i;
for (i = 0; i < 128; i++)
sum += x[i];
if (sum)
{
printk(BIOS_SPEW, " (should be 0x%hhx)",
(unsigned char)(x[0x7f] - sum));
}
else
{
valid = 1;
printk(BIOS_SPEW, " (valid)");
}
}
printk(BIOS_SPEW, "\n");
return valid;
}
/* CEA extension */
static const char *
audio_format(unsigned char x)
{
switch (x)
{
case 0:
return "RESERVED";
case 1:
return "Linear PCM";
case 2:
return "AC-3";
case 3:
return "MPEG 1 (Layers 1 & 2)";
case 4:
return "MPEG 1 Layer 3 (MP3)";
case 5:
return "MPEG2 (multichannel)";
case 6:
return "AAC";
case 7:
return "DTS";
case 8:
return "ATRAC";
case 9:
return "One Bit Audio";
case 10:
return "Dolby Digital+";
case 11:
return "DTS-HD";
case 12:
return "MAT (MLP)";
case 13:
return "DST";
case 14:
return "WMA Pro";
case 15:
return "RESERVED";
}
return "BROKEN"; /* can't happen */
}
static void
cea_audio_block(unsigned char *x)
{
int i, format;
int length = x[0] & 0x1f;
if (length % 3)
{
printk(BIOS_SPEW, "Broken CEA audio block length %d\n", length);
/* XXX non-conformant */
return;
}
for (i = 1; i < length; i += 3)
{
format = (x[i] & 0x78) >> 3;
printk(BIOS_SPEW, " %s, max channels %d\n",
audio_format(format), x[i] & 0x07);
printk(BIOS_SPEW,
" Supported sample rates (kHz):%s%s%s%s%s%s%s\n",
(x[i + 1] & 0x40) ? " 192" : "",
(x[i + 1] & 0x20) ? " 176.4" : "",
(x[i + 1] & 0x10) ? " 96" : "",
(x[i + 1] & 0x08) ? " 88.2" : "",
(x[i + 1] & 0x04) ? " 48" : "",
(x[i + 1] & 0x02) ? " 44.1" : "",
(x[i + 1] & 0x01) ? " 32" : "");
if (format == 1)
{
printk(BIOS_SPEW,
" Supported sample sizes (bits):%s%s%s\n",
(x[2] & 0x04) ? " 24" : "",
(x[2] & 0x02) ? " 20" : "",
(x[2] & 0x01) ? " 16" : "");
}
else if (format <= 8)
{
printk(BIOS_SPEW,
" Maximum bit rate: %d kHz\n", x[2] * 8);
}
}
}
static void
cea_video_block(unsigned char *x)
{
int i;
int length = x[0] & 0x1f;
for (i = 1; i < length; i++)
printk(BIOS_SPEW, " VIC %02d %s\n", x[i] & 0x7f,
x[i] & 0x80 ? "(native)" : "");
}
static void
cea_hdmi_block(struct edid *out, unsigned char *x)
{
int length = x[0] & 0x1f;
out->hdmi_monitor_detected = 1;
printk(BIOS_SPEW, " (HDMI)\n");
printk(BIOS_SPEW,
" Source physical address %d.%d.%d.%d\n",
x[4] >> 4, x[4] & 0x0f, x[5] >> 4, x[5] & 0x0f);
if (length > 5)
{
if (x[6] & 0x80)
printk(BIOS_SPEW, " Supports_AI\n");
if (x[6] & 0x40)
printk(BIOS_SPEW, " DC_48bit\n");
if (x[6] & 0x20)
printk(BIOS_SPEW, " DC_36bit\n");
if (x[6] & 0x10)
printk(BIOS_SPEW, " DC_30bit\n");
if (x[6] & 0x08)
printk(BIOS_SPEW, " DC_Y444\n");
/* two reserved */
if (x[6] & 0x01)
printk(BIOS_SPEW, " DVI_Dual\n");
}
if (length > 6)
printk(BIOS_SPEW, " Maximum TMDS clock: %dMHz\n", x[7] * 5);
/* XXX the walk here is really ugly, and needs to be length-checked */
if (length > 7)
{
int b = 0;
if (x[8] & 0x80)
{
printk(BIOS_SPEW, " Video latency: %d\n", x[9 + b]);
printk(BIOS_SPEW, " Audio latency: %d\n", x[10 + b]);
b += 2;
}
if (x[8] & 0x40)
{
printk(BIOS_SPEW,
" Interlaced video latency: %d\n", x[9 + b]);
printk(BIOS_SPEW,
" Interlaced audio latency: %d\n",
x[10 + b]);
b += 2;
}
if (x[8] & 0x20)
{
int mask = 0, formats = 0;
int len_xx, len_3d;
printk(BIOS_SPEW, " Extended HDMI video details:\n");
if (x[9 + b] & 0x80)
printk(BIOS_SPEW, " 3D present\n");
if ((x[9 + b] & 0x60) == 0x20)
{
printk(BIOS_SPEW,
" All advertised VICs are 3D-capable\n");
formats = 1;
}
if ((x[9 + b] & 0x60) == 0x40)
{
printk(BIOS_SPEW,
" 3D-capable-VIC mask present\n");
formats = 1;
mask = 1;
}
switch (x[9 + b] & 0x18)
{
case 0x00:
break;
case 0x08:
printk(BIOS_SPEW, " Base EDID image size is aspect ratio\n");
break;
case 0x10:
printk(BIOS_SPEW, " Base EDID image size is in units of 1cm\n");
break;
case 0x18:
printk(BIOS_SPEW, " Base EDID image size is in units of 5cm\n");
break;
}
len_xx = (x[10 + b] & 0xe0) >> 5;
len_3d = (x[10 + b] & 0x1f) >> 0;
b += 2;
if (len_xx)
{
printk(BIOS_SPEW, " Skipping %d bytes that HDMI refuses to publicly"
" document\n",
len_xx);
b += len_xx;
}
if (len_3d)
{
if (formats)
{
if (x[9 + b] & 0x01)
printk(BIOS_SPEW, " Side-by-side 3D supported\n");
if (x[10 + b] & 0x40)
printk(BIOS_SPEW, " Top-and-bottom 3D supported\n");
if (x[10 + b] & 0x01)
printk(BIOS_SPEW, " Frame-packing 3D supported\n");
b += 2;
}
if (mask)
{
int i;
printk(BIOS_SPEW,
" 3D VIC indices:");
/* worst bit ordering ever */
for (i = 0; i < 8; i++)
if (x[10 + b] & (1 << i))
printk(BIOS_SPEW,
" %d", i);
for (i = 0; i < 8; i++)
if (x[9 + b] & (1 << i))
printk(BIOS_SPEW,
" %d", i + 8);
printk(BIOS_SPEW, "\n");
b += 2;
}
/*
* XXX list of nibbles:
* 2D_VIC_Order_X
* 3D_Structure_X
* (optionally: 3D_Detail_X and reserved)
*/
}
}
/* Tell static analysis we know index b is left unused. */
(void)b;
}
}
static void
cea_block(struct edid *out, unsigned char *x)
{
unsigned int oui;
switch ((x[0] & 0xe0) >> 5)
{
case 0x01:
printk(BIOS_SPEW, " Audio data block\n");
cea_audio_block(x);
break;
case 0x02:
printk(BIOS_SPEW, " Video data block\n");
cea_video_block(x);
break;
case 0x03:
/* yes really, endianness lols */
oui = (x[3] << 16) + (x[2] << 8) + x[1];
printk(BIOS_SPEW, " Vendor-specific data block, OUI %06x",
oui);
if (oui == 0x000c03)
cea_hdmi_block(out, x);
else
printk(BIOS_SPEW, "\n");
break;
case 0x04:
printk(BIOS_SPEW, " Speaker allocation data block\n");
break;
case 0x05:
printk(BIOS_SPEW, " VESA DTC data block\n");
break;
case 0x07:
printk(BIOS_SPEW, " Extended tag: ");
switch (x[1])
{
case 0x00:
printk(BIOS_SPEW, "video capability data block\n");
break;
case 0x01:
printk(BIOS_SPEW, "vendor-specific video data block\n");
break;
case 0x02:
printk(BIOS_SPEW,
"VESA video display device information data block\n");
break;
case 0x03:
printk(BIOS_SPEW, "VESA video data block\n");
break;
case 0x04:
printk(BIOS_SPEW, "HDMI video data block\n");
break;
case 0x05:
printk(BIOS_SPEW, "Colorimetry data block\n");
break;
case 0x10:
printk(BIOS_SPEW, "CEA miscellaneous audio fields\n");
break;
case 0x11:
printk(BIOS_SPEW, "Vendor-specific audio data block\n");
break;
case 0x12:
printk(BIOS_SPEW, "HDMI audio data block\n");
break;
default:
if (x[1] >= 6 && x[1] <= 15)
printk(BIOS_SPEW,
"Reserved video block (%02x)\n", x[1]);
else if (x[1] >= 19 && x[1] <= 31)
printk(BIOS_SPEW,
"Reserved audio block (%02x)\n", x[1]);
else
printk(BIOS_SPEW, "Unknown (%02x)\n", x[1]);
break;
}
break;
default:
{
int tag = (*x & 0xe0) >> 5;
int length = *x & 0x1f;
printk(BIOS_SPEW,
" Unknown tag %d, length %d (raw %02x)\n",
tag, length, *x);
break;
}
}
}
static int
parse_cea(struct edid *out, unsigned char *x, struct edid_context *c)
{
int ret = 0;
int version = x[1];
int offset = x[2];
unsigned char *detailed;
if (version >= 1)
do
{
if (version == 1 && x[3] != 0)
ret = 1;
if (offset < 4)
break;
if (version < 3)
printk(BIOS_SPEW,
"%d 8-byte timing descriptors\n",
(offset - 4) / 8);
else if (version == 3)
{
int i;
printk(BIOS_SPEW,
"%d bytes of CEA data\n", offset - 4);
for (i = 4; i < offset; i += (x[i] & 0x1f) + 1)