分类: LINUX
2012-10-24 15:13:45
一.EDID数据格式:
EDID 1.3 data format
Byte sequence
00-19 Header information
00–07 Header information "00h FFh FFh FFh FFh FFh FFh 00h"
08–09
Manufacturer ID. These IDs are assigned by Microsoft. "00001=A”;
“00010=B”; ... “11010=Z”. Bit 7 (at address 08h) is 0, the first
character (letter) is located at bits 6 → 2 (at address 08h), the second
character (letter) is located at bits 1 & 0 (at address 08h) and
bits 7 → 5 (at address 09h), and the third character (letter) is located
at bits 4 → 0 (at address 09h).
10–11 Product ID Code (stored as LSB first). Assigned by manufacturer.
12–15
32-bit Serial Number. No requirement for the format. Usually stored as
LSB first. In order to maintain compatibility with previous
requirements the field should set at least one byte of the field to be
non-zero if an ASCII serial number descriptor is provided in the
detailed timing section.
16 Week of Manufacture. This varies by
manufacturer. One way is to count January 1–7 as week 1, January 8–15
as week 2 and so on. Some count based on the week number
(Sunday-Saturday). Valid range is 1-54.
17 Year of Manufacture. Add 1990 to the value for actual year.
18 EDID Version Number "01h"
19 EDID Revision Number "03h"
20-24 Basic display parameters
20 Video input definition
7 0=analog 1=digital
6 video level
00=0.7, 0.3; 01=0.714, 0.286; 10=1, 0.4; 11=0.7, 0
5
4 blank-to-black setup
3 separate syncs
2 composite sync
1 sync on green
0 serration vsync 1=DFP 1.x compatible
21 Maximum Horizontal Image Size (in centimeters).
22 Maximum Vertical Image Size (in centimetres).
23 Display Gamma. Divide by 100, then add 1 for actual value.
24 Power Management and Supported Feature(s):
7 standby
6 suspend
5 active-off/low power
4 Display type:
00=monochrome, 01=RGB colour, 10=non RGB multicolour, 11=undefined
3
2 standard colour space
1 preferred timing mode
0 default GTF supported
25-34 Chromaticity coordinates
25 low significant bits for Red X (bit 7-6), Red Y (bit 5-4), Green X (bit 3-2), Green Y (bit 1-0).
26 low significant bits for Blue X (bit 7-6), Blue Y (bit 5-4), White X (bit 3-2), White Y (bit 1-0).
27–34
high significant bits for Red X, Red Y, Green X, Green Y, Blue X, Blue
Y, White X, White Y. To decode actual value, rearrange bits as
follows: High significant bits 7-0 for (channel), low significant bits
for (channel). Actual value is between 0.000 and 0.999, but encoded
value is between 000h and 3FFh. Normalize by *999/1023.
35 Established timing I:
720×400@70 Hz, 720×400@88 Hz, 640×480@60 Hz, 640×480@67 Hz, 640×480@72 Hz, 640×480@75 Hz, 800×600@56 Hz, 800×600@60 Hz
36 Established timing II:
800×600@72 Hz, 800×600@75 Hz, 832×624@75 Hz, 1024×768@87 Hz (Interlaced), 1024×768@60 Hz, 1024×768@70 Hz, 1024×768@75 Hz, 1280×1024@75 Hz
37 Manufacturer's reserved timing:
00h for none
bit 7: 1152x870 @ 75 Hz (Mac II, Apple)
38–53 Standard timing identification
First byte: Horizontal resolution. Multiply by 8, then add 248 for actual value.
Second byte:
bit 7-6
Aspect ratio. Actual vertical resolution depends on horizontal resolution.
00=16:10, 01=4:3, 10=5:4, 11=16:9 (00=1:1 prior to v1.3)
bit 5-0
Vertical frequency. Add 60 to get actual value.
54–71 Descriptor Block 1
54–55 Pixel Clock (in 10 kHz) or 0 (55 MSB 54 LSB)
If Pixel Clock is non null:
56: Horizontal Active (in pixels)
57: Horizontal Blanking (in pixels)
58: Horizontal Active high (4 upper bits)
Horizontal Blanking high (4 lower bits)
59: Vertical Active (in lines)
60: Vertical Blanking (in lines)
61: high significant bits for Vertical Active (4 upper bits)
high significant bits for Vertical Blanking (4 lower bits)
62: Horizontal Sync Offset (in pixels)
63: Horizontal Sync Pulse Width (in pixels)
64: Vertical Sync Offset (in lines) (4 upper bits)
Vertical Sync Pulse Width (in lines) (4 lower bits)
65: high significant bits for Horizontal Sync Offset (bit 7-6)
high significant bits for Horizontal Sync Pulse Width (bit 5-4)
high significant bits for Vertical Sync Offset (bit 3-2)
high significant bits for Vertical Sync Pulse Width (bit 1-0)
66: Horizontal Image Size (in mm)
67: Vertical Image Size (in mm)
68: high significant bits for Horizontal Image Size (4 upper bits)
high significant bits for Vertical Image Size (4 lower bits)
69: Horizontal Border (in pixels representing only one side)
70: Vertical Border (in lines representing only one side)
71: Interlaced or not (bit 7)
Stereo or not (bit 6-5) ("00" means not)
Separate Sync or not (bit 4-3)
Vertical Sync positive or not (bit 2)
Horizontal Sync positive or not (bit 1)
Stereo Mode (bit 0) (unused if 6-5 are 00)
If Pixel Clock is null:
56: 0
57: Block type
FFh=Monitor Serial Number, FEh=ASCII string, FDh=Monitor Range Limits, FCh=Monitor name,
FBh=Colour Point Data, FAh, Standard Timing Data, F9h=Currently undefined,
0Fh=defined by manufacturer
58: 0
59–71: Descriptor block contents.
If block type is FFh, FEh, or FCh, the entire area is a text string.
If block type is FDh:
59–63:
Min Vertical frequency, Max Vertical frequency,
Min Horizontal frequency (in kHz), Max Horizontal frequency (in kHz), pixel clock
(in MHz (multiply by 10 for actual value))
64–65: Secondary GTF toggle
If encoded value is 000A, bytes 59-63 are used. If encoded value is 0200,
bytes 67–71 are used.
66: Start horizontal frequency (in kHz). Multiply by 2 for actual value.
67: C. Divide by 2 for actual value.
68-69: M (stored as LSB first).
70: K
71: J. Divide by 2 for actual value.
If block type is FBh:
59: W Index 0. If set to 0, bytes 60-63 are not used. If set to 1, 60–63 are
assigned to white point index #1
64: W Index 1. If set to 0, bytes 65-68 are not used. If set to 2, 65–68 are
assigned to white point index #2
White point index structure:
First byte
bit 3-2: low significant bits for White X (bit 3-2), White Y (bit 1-0)
Second to third byte: high significant bits for White X, White Y.
Fourth byte: Gamma. Divide by 100, then add 1 for actual value.
To decode White X and White Y, see bytes 25-34.
If block type is FAh:
59–70: Standard Timing Identification. 2 bytes for each record.
For structure details, see bytes 38-53.
72–89 Descriptor Block 2
90–107 Descriptor Block 3
108–125 Descriptor Block 4
126
Extension Flag.
This is the number of extension blocks which follow this block. Prior to EDID 1.3, it is ignored, and should be set to 0.
127 Checksum.
This byte should be programmed such that the sum of all 128 bytes equals 00h.
CEA EDID Timing Extension Version 3 data format:
Byte sequence
00: Extension tag (which kind of extension block this is); 02h for CEA EDID
01: Revision number (Version number); 03h for Version 3
02: Byte number "d" within this block where the 18-byte DTDs begin. If no non-DTD data is present
in this extension block, the value should be set to 04h (the byte after next). If set to 00h,
there are no DTDs present in this block and no non-DTD data.
03: Number of DTDs present, other Version 2+ information
bit 7: 1 if display supports underscan, 0 if not
bit 6: 1 if display supports basic audio, 0 if not
bit 5: 1 if display supports YCbCr 4:4:4, 0 if not
bit 4: 1 if display supports YCbCr 4:2:2, 0 if not
bit 3..0: total number of native formats in the DTDs included in this block
04: Start of Data Block Collection. If byte 02 is set to 04h, this is where the DTD collection
begins. If byte 02 is set to another value, byte 04 is where the Data Block Collection begins,
and the DTD collection follows immediately thereafter.
The Data Block Collection contains one or more data blocks detailing video, audio, and speaker
placement information about the display. The blocks can be placed in any order, and the initial
byte of each block defines both its type and its length:
bit 7..5: Block Type Tag (1 is audio, 2 is video, 3 is vendor specific, 4 is speaker
allocation, all other values Reserved)
bit 4..0: Total number of bytes in this block following this byte
Once one data block has ended, the next byte is assumed to be the beginning of the next data
block. This is the case until the byte (designated in Byte 02, above) where the DTDs are known
to begin.
Any Audio Data Block contains one or more 3-byte Short Audio Descriptors (SADs). Each SAD
details audio format, channel number, and bitrate/resolution capabilities of the display as
follows:
SAD Byte 1 (format and number of channels):
bit 7: Reserved (0)
bit 6..3: Audio format code
1 = Linear Pulse Code Modulation (LPCM)
2 = AC-3
3 = MPEG1 (Layers 1 and 2)
4 = MP3
5 = MPEG2
6 = AAC
7 = DTS
8 = ATRAC
0, 15: Reserved
9 = One-bit audio aka SACD
10 = DD+
11 = DTS-HD
12 = MLP/Dolby TrueHD
13 = DST Audio
14 = Microsoft WMA Pro
bit 2..0: number of channels minus 1 (i.e. 000 = 1 channel; 001 = 2 channels; 111 =
8 channels)
SAD Byte 2 (sampling frequencies supported):
bit 7: Reserved (0)
bit 6: 192kHz
bit 5: 176kHz
bit 4: 96kHz
bit 3: 88kHz
bit 2: 48kHz
bit 1: 44kHz
bit 0: 32kHz
SAD Byte 3 (bitrate):
For LPCM, bits 7:3 are reserved and the remaining bits define bit depth
bit 2: 24 bit
bit 1: 20 bit
bit 0: 16 bit
For all other sound formats, bits 7..0 designate the maximum supported bitrate divided by
8kbps.
Any Video Data Block will contain one or more 1-byte Short Video Descriptors (SVDs). They are
decoded as follows:
bit 7: 1 to designate that this should be considered a "native" resolution, 0 for non-native
bit 6..0: index value to a table of standard resolutions/timings from CEA/EIA-861E:
Code
Short Aspect
Name Ratio HxV @ F
1 DMT0659 4:3 640x480p @ 59.94/60Hz
2 480p 4:3 720x480p @ 59.94/60Hz
3 480pH 16:9 720x480p @ 59.94/60Hz
4 720p 16:9 1280x720p @ 59.94/60Hz
5 1080i 16:9 1920x1080i @ 59.94/60Hz
6 480i 4:3 720(1440)x480i @ 59.94/60Hz
7 480iH 16:9 720(1440)x480i @ 59.94/60Hz
8 240p 4:3 720(1440)x240p @ 59.94/60Hz
9 240pH 16:9 720(1440)x240p @ 59.94/60Hz
10 480i4x 4:3 (2880)x480i @ 59.94/60Hz
11 480i4xH 16:9 (2880)x480i @ 59.94/60Hz
12 240p4x 4:3 (2880)x240p @ 59.94/60Hz
13 240p4xH 16:9 (2880)x240p @ 59.94/60Hz
14 480p2x 4:3 1440x480p @ 59.94/60Hz
15 480p2xH 16:9 1440x480p @ 59.94/60Hz
16 1080p 16:9 1920x1080p @ 59.94/60Hz
17 576p 4:3 720x576p @ 50Hz
18 576pH 16:9 720x576p @ 50Hz
19 720p50 16:9 1280x720p @ 50Hz
20 1080i25 16:9 1920x1080i @ 50Hz*
21 576i 4:3 720(1440)x576i @ 50Hz
22 576iH 16:9 720(1440)x576i @ 50Hz
23 288p 4:3 720(1440)x288p @ 50Hz
24 288pH 16:9 720(1440)x288p @ 50Hz
25 576i4x 4:3 (2880)x576i @ 50Hz
26 576i4xH 16:9 (2880)x576i @ 50Hz
27 288p4x 4:3 (2880)x288p @ 50Hz
28 288p4xH 16:9 (2880)x288p @ 50Hz
29 576p2x 4:3 1440x576p @ 50Hz
30 576p2xH 16:9 1440x576p @ 50Hz
31 1080p50 16:9 1920x1080p @ 50Hz
32 1080p24 16:9 1920x1080p @ 23.98/24Hz
33 1080p25 16:9 1920x1080p @ 25Hz
34 1080p30 16:9 1920x1080p @ 29.97/30Hz
35 480p4x 4:3 (2880)x480p @ 59.94/60Hz
36 480p4xH 16:9 (2880)x480p @ 59.94/60Hz
37 576p4x 4:3 (2880)x576p @ 50Hz
38 576p4xH 16:9 (2880)x576p @ 50Hz
39 1080i25 16:9 1920x1080i(1250 Total) @ 50Hz*
40 1080i50 16:9 1920x1080i @ 100Hz
41 720p100 16:9 1280x720p @ 100Hz
42 576p100 4:3 720x576p @ 100Hz
43 576p100H 16:9 720x576p @ 100Hz
44 576i50 4:3 720(1440)x576i @ 100Hz
45 576i50H 16:9 720(1440)x576i @ 100Hz
46 1080i60 16:9 1920x1080i @ 119.88/120Hz
47 720p120 16:9 1280x720p @ 119.88/120Hz
48 480p119 4:3 720x480p @ 119.88/120Hz
49 480p119H 16:9 720x480p @ 119.88/120Hz
50 480i59 4:3 720(1440)x480i @ 119.88/120Hz
51 480i59H 16:9 720(1440)x480i @ 119.88/120Hz
52 576p200 4:3 720x576p @ 200Hz
53 576p200H 16:9 720x576p @ 200Hz
54 576i100 4:3 720(1440)x576i @ 200Hz
55 576i100H 16:9 720(1440)x576i @ 200Hz
56 480p239 4:3 720x480p @ 239.76/240Hz
57 480p239H 16:9 720x480p @ 239.76/240Hz
58 480i119 4:3 720(1440)x480i @ 239.76/240Hz
59 480i119H 16:9 720(1440)x480i @ 239.76/240Hz
60 720p24 16:9 1280x720p @ 23.98/24Hz
61 720p25 16:9 1280x720p @ 25Hz
62 720p30 16:9 1280x720p @ 29.97/30Hz
63 1080p120 16:9 1920x1080p @ 119.88/120Hz
二.hdmi ddc bus是通过 i2c总线来通信的,因此要在kernel注册i2c驱动:
i2c驱动的设备节点是/dev/hdmi_ddc_misc,这个驱动非常的简单,只做了将35 byte的edid数据从kernel空间传到用户空间。
然后就可以在用户空间读到这35 byte的数据:
fh = open("/dev/hdmi_ddc_misc",O_RDWR);
if (fh == -1) {
printf("open hdmi_ddc device error! ");
return 0;
}
if(ioctl(fh,HDMI_DDC_I2C_READ,hdmi_edid_data)<0){
perror("ioctl error");
exit(1);
}
三.在用户空间对edid数据的解析:
//printf("Established timing monitor support:\n");
if(hdmi_edid_data[0] & ESTABLISHED_TIMING2)videoType |= (1 << VideoStd_640x480);
if(hdmi_edid_data[0] & ESTABLISHED_TIMING3)videoType |= (1 << VideoStd_640x480);
if(hdmi_edid_data[0] & ESTABLISHED_TIMING4)videoType |= (1 << VideoStd_640x480);
if(hdmi_edid_data[0] & ESTABLISHED_TIMING5)videoType |= (1 << VideoStd_640x480);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING14)videoType |= (1 << VideoStd_800x600);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING15)videoType |= (1 << VideoStd_800x600);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING9)videoType |= (1 << VideoStd_1024x768);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING10)videoType |= (1 << VideoStd_1024x768);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING11)videoType |= (1 << VideoStd_1024x768);
if(hdmi_edid_data[1] & ESTABLISHED_TIMING8)videoType |= (1 << VideoStd_1280x1024);
//printf("Standard timing monitor support:\n");
for(i=0;i<8;i++){
if(0x01 == hdmi_edid_data[i*2+2])goto st_end;
hsize = hdmi_edid_data[i*2+2]*8+248;
if(0x00 == (hdmi_edid_data[i*2+3] & 0xc0))vsize=hsize/16*10;
if(0x40 == (hdmi_edid_data[i*2+3] & 0xc0))vsize=hsize/4*3;
if(0x80 == (hdmi_edid_data[i*2+3] & 0xc0))vsize=hsize/5*4;
if(0xc0 == (hdmi_edid_data[i*2+3] & 0xc0))vsize=hsize/16*9;
rate = (hdmi_edid_data[i*2+3] & 0x3f)+60;
//printf("monitor support %dx%d@%d Hz\n",hsize,vsize,rate);
if((640 == hsize) && (480 == vsize))videoType |= (1 << VideoStd_640x480);
if((720 == hsize) && (480 == vsize))videoType |= (1 << VideoStd_720x480);
if((800 == hsize) && (480 == vsize))videoType |= (1 << VideoStd_800x480);
if((800 == hsize) && (600 == vsize))videoType |= (1 << VideoStd_800x600);
if((1024 == hsize) && (768 == vsize))videoType |= (1 << VideoStd_1024x768);
if((1280 == hsize) && (720 == vsize))videoType |= (1 << VideoStd_1280x720);
if((1280 == hsize) && (1024 == vsize))videoType |= (1 << VideoStd_1280x1024);
if((1600 == hsize) && (900 == vsize))videoType |= (1 << VideoStd_1600x900);
if((1920 == hsize) && (1080 == vsize))videoType |= (1 << VideoStd_1920x1080);
}
st_end:
//printf("CEA EDID Timing monitor support:\n");
if(0x01 != hdmi_edid_data[18])goto cet_end;
for(i=20;i<35;i++){
if(1 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_640x480);
if(2 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(3 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(48 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(49 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(56 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(57 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_720x480);
if(4 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(19 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(41 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(47 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(60 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(61 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(62 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1280x720);
if(16 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
if(31 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
if(32 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
if(33 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
if(34 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
if(63 == (hdmi_edid_data[i] & 0x7f))videoType |= (1 << VideoStd_1920x1080);
}
cet_end:
四.数据协商,设置一种最佳的分辨率:
if(videoType & (1 << VideoStd_1280x720)) {
current_videotype = VideoStd_1280x720;
goto display_set_end;
}
if(videoType & (1 << VideoStd_1600x900)) {
current_videotype = VideoStd_1600x900;
SysFs_change(Display_Output_DVI, VideoStd_1600x900);
goto display_set_end;
}
if(videoType & (1 << VideoStd_1280x1024)){
current_videotype = VideoStd_1280x1024;
SysFs_change(Display_Output_DVI, VideoStd_1280x1024);
goto display_set_end;
}
if(videoType & (1 << VideoStd_1024x768)) {
current_videotype = VideoStd_1024x768;
SysFs_change(Display_Output_DVI, VideoStd_1024x768);
goto display_set_end;
}
if(videoType & (1 << VideoStd_800x480)) {
current_videotype = VideoStd_800x480;
SysFs_change(Display_Output_DVI, VideoStd_800x480);
goto display_set_end;
}
if(videoType & (1 << VideoStd_800x600)) {
current_videotype = VideoStd_800x600;
SysFs_change(Display_Output_DVI, VideoStd_800x600);
goto display_set_end;
}
if(videoType & (1 << VideoStd_640x480)) {
current_videotype = VideoStd_640x480;
SysFs_change(Display_Output_DVI, VideoStd_640x480);
goto display_set_end;
}
if(videoType & (1 << VideoStd_720x480)) {
current_videotype = VideoStd_720x480;
SysFs_change(Display_Output_DVI, VideoStd_720x480);
goto display_set_end;
}
if(videoType & (1 << VideoStd_1920x1080)){
current_videotype = VideoStd_1920x1080;
SysFs_change(Display_Output_DVI, VideoStd_1920x1080);
goto display_set_end;
}
display_set_end:
五.提供给用户的API:
1.得到显示器支持的分辨率:
int get_monitor_support_video_type(void)
{
return videoType;
}
2.得到设备当前的分辨率:
int get_current_video_type(void)
{
return current_videotype;
}
3.设置分辨率:
int set_video_type(int videoType)