edid.h revision 05b261ec
1 2/* edid.h: defines to parse an EDID block 3 * 4 * This file contains all information to interpret a standard EDIC block 5 * transmitted by a display device via DDC (Display Data Channel). So far 6 * there is no information to deal with optional EDID blocks. 7 * DDC is a Trademark of VESA (Video Electronics Standard Association). 8 * 9 * Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE> 10 */ 11 12#ifndef _EDID_H_ 13#define _EDID_H_ 14 15/* read complete EDID record */ 16#define EDID1_LEN 128 17#define BITS_PER_BYTE 9 18#define NUM BITS_PER_BYTE*EDID1_LEN 19#define HEADER 6 20 21#define STD_TIMINGS 8 22#define DET_TIMINGS 4 23 24#ifdef _PARSE_EDID_ 25 26/* header: 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00 */ 27#define HEADER_SECTION 0 28#define HEADER_LENGTH 8 29 30/* vendor section */ 31#define VENDOR_SECTION (HEADER_SECTION + HEADER_LENGTH) 32#define V_MANUFACTURER 0 33#define V_PROD_ID (V_MANUFACTURER + 2) 34#define V_SERIAL (V_PROD_ID + 2) 35#define V_WEEK (V_SERIAL + 4) 36#define V_YEAR (V_WEEK + 1) 37#define VENDOR_LENGTH (V_YEAR + 1) 38 39/* EDID version */ 40#define VERSION_SECTION (VENDOR_SECTION + VENDOR_LENGTH) 41#define V_VERSION 0 42#define V_REVISION (V_VERSION + 1) 43#define VERSION_LENGTH (V_REVISION + 1) 44 45/* display information */ 46#define DISPLAY_SECTION (VERSION_SECTION + VERSION_LENGTH) 47#define D_INPUT 0 48#define D_HSIZE (D_INPUT + 1) 49#define D_VSIZE (D_HSIZE + 1) 50#define D_GAMMA (D_VSIZE + 1) 51#define FEAT_S (D_GAMMA + 1) 52#define D_RG_LOW (FEAT_S + 1) 53#define D_BW_LOW (D_RG_LOW + 1) 54#define D_REDX (D_BW_LOW + 1) 55#define D_REDY (D_REDX + 1) 56#define D_GREENX (D_REDY + 1) 57#define D_GREENY (D_GREENX + 1) 58#define D_BLUEX (D_GREENY + 1) 59#define D_BLUEY (D_BLUEX + 1) 60#define D_WHITEX (D_BLUEY + 1) 61#define D_WHITEY (D_WHITEX + 1) 62#define DISPLAY_LENGTH (D_WHITEY + 1) 63 64/* supported VESA and other standard timings */ 65#define ESTABLISHED_TIMING_SECTION (DISPLAY_SECTION + DISPLAY_LENGTH) 66#define E_T1 0 67#define E_T2 (E_T1 + 1) 68#define E_TMANU (E_T2 + 1) 69#define E_TIMING_LENGTH (E_TMANU + 1) 70 71/* non predefined standard timings supported by display */ 72#define STD_TIMING_SECTION (ESTABLISHED_TIMING_SECTION + E_TIMING_LENGTH) 73#define STD_TIMING_INFO_LEN 2 74#define STD_TIMING_INFO_NUM STD_TIMINGS 75#define STD_TIMING_LENGTH (STD_TIMING_INFO_LEN * STD_TIMING_INFO_NUM) 76 77/* detailed timing info of non standard timings */ 78#define DET_TIMING_SECTION (STD_TIMING_SECTION + STD_TIMING_LENGTH) 79#define DET_TIMING_INFO_LEN 18 80#define MONITOR_DESC_LEN DET_TIMING_INFO_LEN 81#define DET_TIMING_INFO_NUM DET_TIMINGS 82#define DET_TIMING_LENGTH (DET_TIMING_INFO_LEN * DET_TIMING_INFO_NUM) 83 84/* number of EDID sections to follow */ 85#define NO_EDID (DET_TIMING_SECTION + DET_TIMING_LENGTH) 86/* one byte checksum */ 87#define CHECKSUM (NO_EDID + 1) 88 89#if (CHECKSUM != (EDID1_LEN - 1)) 90# error "EDID1 length != 128!" 91#endif 92 93 94#define SECTION(x,y) (Uchar *)(x + y) 95#define GET_ARRAY(y) ((Uchar *)(c + y)) 96#define GET(y) *(Uchar *)(c + y) 97 98/* extract information from vendor section */ 99#define _PROD_ID(x) x[0] + (x[1] << 8); 100#define PROD_ID _PROD_ID(GET_ARRAY(V_PROD_ID)) 101#define _SERIAL_NO(x) x[0] + (x[1] << 8) + (x[2] << 16) + (x[3] << 24) 102#define SERIAL_NO _SERIAL_NO(GET_ARRAY(V_SERIAL)) 103#define _YEAR(x) (x & 0xFF) + 1990 104#define YEAR _YEAR(GET(V_YEAR)) 105#define WEEK GET(V_WEEK) & 0xFF 106#define _L1(x) ((x[0] & 0x7C) >> 2) + '@' 107#define _L2(x) ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@' 108#define _L3(x) (x[1] & 0x1F) + '@'; 109#define L1 _L1(GET_ARRAY(V_MANUFACTURER)) 110#define L2 _L2(GET_ARRAY(V_MANUFACTURER)) 111#define L3 _L3(GET_ARRAY(V_MANUFACTURER)) 112 113/* extract information from version section */ 114#define VERSION GET(V_VERSION) 115#define REVISION GET(V_REVISION) 116 117/* extract information from display section */ 118#define _INPUT_TYPE(x) ((x & 0x80) >> 7) 119#define INPUT_TYPE _INPUT_TYPE(GET(D_INPUT)) 120#define _INPUT_VOLTAGE(x) ((x & 0x60) >> 5) 121#define INPUT_VOLTAGE _INPUT_VOLTAGE(GET(D_INPUT)) 122#define _SETUP(x) ((x & 0x10) >> 4) 123#define SETUP _SETUP(GET(D_INPUT)) 124#define _SYNC(x) (x & 0x0F) 125#define SYNC _SYNC(GET(D_INPUT)) 126#define _DFP(x) (x & 0x01) 127#define DFP _DFP(GET(D_INPUT)) 128#define _GAMMA(x) (x == 0xff ? 1.0 : ((x + 100.0)/100.0)) 129#define GAMMA _GAMMA(GET(D_GAMMA)) 130#define HSIZE_MAX GET(D_HSIZE) 131#define VSIZE_MAX GET(D_VSIZE) 132#define _DPMS(x) ((x & 0xE0) >> 5) 133#define DPMS _DPMS(GET(FEAT_S)) 134#define _DISPLAY_TYPE(x) ((x & 0x18) >> 3) 135#define DISPLAY_TYPE _DISPLAY_TYPE(GET(FEAT_S)) 136#define _MSC(x) (x & 0x7) 137#define MSC _MSC(GET(FEAT_S)) 138 139 140/* color characteristics */ 141#define CC_L(x,y) ((x & (0x03 << y)) >> y) 142#define CC_H(x) (x << 2) 143#define I_CC(x,y,z) CC_H(y) | CC_L(x,z) 144#define F_CC(x) ((x)/1024.0) 145#define REDX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDX)),6)) 146#define REDY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDY)),4)) 147#define GREENX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENX)),2)) 148#define GREENY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENY)),0)) 149#define BLUEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEX)),6)) 150#define BLUEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEY)),4)) 151#define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2)) 152#define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0)) 153 154/* extract information from standard timing section */ 155#define T1 GET(E_T1) 156#define T2 GET(E_T2) 157#define T_MANU GET(E_TMANU) 158 159/* extract information from estabished timing section */ 160#define _VALID_TIMING(x) !(((x[0] == 0x01) && (x[1] == 0x01)) \ 161 || ((x[0] == 0x00) && (x[1] == 0x00)) \ 162 || ((x[0] == 0x20) && (x[1] == 0x20)) ) 163#define VALID_TIMING _VALID_TIMING(c) 164#define _HSIZE1(x) ((x[0] + 31) * 8) 165#define HSIZE1 _HSIZE1(c) 166#define RATIO(x) ((x[1] & 0xC0) >> 6) 167#define RATIO1_1 0 168/* EDID Ver. 1.3 redefined this */ 169#define RATIO16_10 RATIO1_1 170#define RATIO4_3 1 171#define RATIO5_4 2 172#define RATIO16_9 3 173#define _VSIZE1(x,y,r) switch(RATIO(x)){ \ 174 case RATIO1_1: y = ((v->version > 1 || v->revision > 2) \ 175 ? (_HSIZE1(x) * 10) / 16 : _HSIZE1(x)); break; \ 176 case RATIO4_3: y = _HSIZE1(x) * 3 / 4; break; \ 177 case RATIO5_4: y = _HSIZE1(x) * 4 / 5; break; \ 178 case RATIO16_9: y = _HSIZE1(x) * 9 / 16; break; \ 179 } 180#define VSIZE1(x) _VSIZE1(c,x,v) 181#define _REFRESH_R(x) (x[1] & 0x3F) + 60 182#define REFRESH_R _REFRESH_R(c) 183#define _ID_LOW(x) x[0] 184#define ID_LOW _ID_LOW(c) 185#define _ID_HIGH(x) (x[1] << 8) 186#define ID_HIGH _ID_HIGH(c) 187#define STD_TIMING_ID (ID_LOW | ID_HIGH) 188#define _NEXT_STD_TIMING(x) (x = (x + STD_TIMING_INFO_LEN)) 189#define NEXT_STD_TIMING _NEXT_STD_TIMING(c) 190 191 192/* EDID Ver. >= 1.2 */ 193#define _IS_MONITOR_DESC(x) (x[0] == 0 && x[1] == 0 && x[2] == 0 && x[4] == 0) 194#define IS_MONITOR_DESC _IS_MONITOR_DESC(c) 195#define _PIXEL_CLOCK(x) (x[0] + (x[1] << 8)) * 10000 196#define PIXEL_CLOCK _PIXEL_CLOCK(c) 197#define _H_ACTIVE(x) (x[2] + ((x[4] & 0xF0) << 4)) 198#define H_ACTIVE _H_ACTIVE(c) 199#define _H_BLANK(x) (x[3] + ((x[4] & 0x0F) << 8)) 200#define H_BLANK _H_BLANK(c) 201#define _V_ACTIVE(x) (x[5] + ((x[7] & 0xF0) << 4)) 202#define V_ACTIVE _V_ACTIVE(c) 203#define _V_BLANK(x) (x[6] + ((x[7] & 0x0F) << 8)) 204#define V_BLANK _V_BLANK(c) 205#define _H_SYNC_OFF(x) (x[8] + ((x[11] & 0xC0) << 2)) 206#define H_SYNC_OFF _H_SYNC_OFF(c) 207#define _H_SYNC_WIDTH(x) (x[9] + ((x[11] & 0x30) << 4)) 208#define H_SYNC_WIDTH _H_SYNC_WIDTH(c) 209#define _V_SYNC_OFF(x) ((x[10] >> 4) + ((x[11] & 0x0C) << 2)) 210#define V_SYNC_OFF _V_SYNC_OFF(c) 211#define _V_SYNC_WIDTH(x) ((x[10] & 0x0F) + ((x[11] & 0x03) << 4)) 212#define V_SYNC_WIDTH _V_SYNC_WIDTH(c) 213#define _H_SIZE(x) (x[12] + ((x[14] & 0xF0) << 4)) 214#define H_SIZE _H_SIZE(c) 215#define _V_SIZE(x) (x[13] + ((x[14] & 0x0F) << 8)) 216#define V_SIZE _V_SIZE(c) 217#define _H_BORDER(x) (x[15]) 218#define H_BORDER _H_BORDER(c) 219#define _V_BORDER(x) (x[16]) 220#define V_BORDER _V_BORDER(c) 221#define _INTERLACED(x) ((x[17] & 0x80) >> 7) 222#define INTERLACED _INTERLACED(c) 223#define _STEREO(x) ((x[17] & 0x60) >> 5) 224#define STEREO _STEREO(c) 225#define _STEREO1(x) (x[17] & 0x1) 226#define STEREO1 _STEREO(c) 227#define _SYNC_T(x) ((x[17] & 0x18) >> 3) 228#define SYNC_T _SYNC_T(c) 229#define _MISC(x) ((x[17] & 0x06) >> 1) 230#define MISC _MISC(c) 231 232#define _MONITOR_DESC_TYPE(x) x[3] 233#define MONITOR_DESC_TYPE _MONITOR_DESC_TYPE(c) 234#define SERIAL_NUMBER 0xFF 235#define ASCII_STR 0xFE 236#define MONITOR_RANGES 0xFD 237#define _MIN_V(x) x[5] 238#define MIN_V _MIN_V(c) 239#define _MAX_V(x) x[6] 240#define MAX_V _MAX_V(c) 241#define _MIN_H(x) x[7] 242#define MIN_H _MIN_H(c) 243#define _MAX_H(x) x[8] 244#define MAX_H _MAX_H(c) 245#define _MAX_CLOCK(x) x[9] 246#define MAX_CLOCK _MAX_CLOCK(c) 247#define _HAVE_2ND_GTF(x) (x[10] == 0x02) 248#define HAVE_2ND_GTF _HAVE_2ND_GTF(c) 249#define _F_2ND_GTF(x) (x[12] * 2) 250#define F_2ND_GTF _F_2ND_GTF(c) 251#define _C_2ND_GTF(x) (x[13] / 2) 252#define C_2ND_GTF _C_2ND_GTF(c) 253#define _M_2ND_GTF(x) (x[14] + (x[15] << 8)) 254#define M_2ND_GTF _M_2ND_GTF(c) 255#define _K_2ND_GTF(x) (x[16]) 256#define K_2ND_GTF _K_2ND_GTF(c) 257#define _J_2ND_GTF(x) (x[17] / 2) 258#define J_2ND_GTF _J_2ND_GTF(c) 259#define MONITOR_NAME 0xFC 260#define ADD_COLOR_POINT 0xFB 261#define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2)) 262#define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0)) 263#define _WHITEX_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 1)),2)) 264#define _WHITEY_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 2)),0)) 265#define _WHITE_INDEX1(x) x[5] 266#define WHITE_INDEX1 _WHITE_INDEX1(c) 267#define _WHITE_INDEX2(x) x[10] 268#define WHITE_INDEX2 _WHITE_INDEX2(c) 269#define WHITEX1 _WHITEX_ADD(c,6) 270#define WHITEY1 _WHITEY_ADD(c,6) 271#define WHITEX2 _WHITEX_ADD(c,12) 272#define WHITEY2 _WHITEY_ADD(c,12) 273#define _WHITE_GAMMA1(x) _GAMMA(x[9]) 274#define WHITE_GAMMA1 _WHITE_GAMMA1(c) 275#define _WHITE_GAMMA2(x) _GAMMA(x[14]) 276#define WHITE_GAMMA2 _WHITE_GAMMA2(c) 277#define ADD_STD_TIMINGS 0xFA 278#define ADD_DUMMY 0x10 279 280#define _NEXT_DT_MD_SECTION(x) (x = (x + DET_TIMING_INFO_LEN)) 281#define NEXT_DT_MD_SECTION _NEXT_DT_MD_SECTION(c) 282 283#endif /* _PARSE_EDID_ */ 284 285/* input type */ 286#define DIGITAL(x) x 287 288/* DFP */ 289#define DFP1(x) x 290 291/* input voltage level */ 292#define V070 0 /* 0.700V/0.300V */ 293#define V071 1 /* 0.714V/0.286V */ 294#define V100 2 /* 1.000V/0.400V */ 295#define V007 3 /* 0.700V/0.000V */ 296 297/* Signal level setup */ 298#define SIG_SETUP(x) (x) 299 300/* sync characteristics */ 301#define SEP_SYNC(x) (x & 0x08) 302#define COMP_SYNC(x) (x & 0x04) 303#define SYNC_O_GREEN(x) (x & 0x02) 304#define SYNC_SERR(x) (x & 0x01) 305 306/* DPMS features */ 307#define DPMS_STANDBY(x) (x & 0x04) 308#define DPMS_SUSPEND(x) (x & 0x02) 309#define DPMS_OFF(x) (x & 0x01) 310 311/* display type */ 312#define DISP_MONO 0 313#define DISP_RGB 1 314#define DISP_MULTCOLOR 2 315 316/* Msc stuff EDID Ver > 1.1 */ 317#define STD_COLOR_SPACE(x) (x & 0x4) 318#define PREFERRED_TIMING_MODE(x) (x & 0x2) 319#define GFT_SUPPORTED(x) (x & 0x1) 320 321/* detailed timing misc */ 322#define IS_INTERLACED(x) (x) 323#define IS_STEREO(x) (x) 324#define IS_RIGHT_STEREO(x) (x & 0x01) 325#define IS_LEFT_STEREO(x) (x & 0x02) 326#define IS_4WAY_STEREO(x) (x & 0x03) 327#define IS_RIGHT_ON_SYNC(x) IS_RIGHT_STEREO(x) 328#define IS_LEFT_ON_SYNC(x) IS_LEFT_STEREO(x) 329 330 331typedef unsigned int Uint; 332typedef unsigned char Uchar; 333 334struct vendor { 335 char name[4]; 336 int prod_id; 337 Uint serial; 338 int week; 339 int year; 340}; 341 342struct edid_version { 343 int version; 344 int revision; 345}; 346 347struct disp_features { 348 unsigned int input_type:1; 349 unsigned int input_voltage:2; 350 unsigned int input_setup:1; 351 unsigned int input_sync:5; 352 unsigned int input_dfp:1; 353 int hsize; 354 int vsize; 355 float gamma; 356 unsigned int dpms:3; 357 unsigned int display_type:2; 358 unsigned int msc:3; 359 float redx; 360 float redy; 361 float greenx; 362 float greeny; 363 float bluex; 364 float bluey; 365 float whitex; 366 float whitey; 367}; 368 369struct established_timings { 370 Uchar t1; 371 Uchar t2; 372 Uchar t_manu; 373}; 374 375struct std_timings { 376 int hsize; 377 int vsize; 378 int refresh; 379 CARD16 id; 380}; 381 382struct detailed_timings { 383 int clock; 384 int h_active; 385 int h_blanking; 386 int v_active; 387 int v_blanking; 388 int h_sync_off; 389 int h_sync_width; 390 int v_sync_off; 391 int v_sync_width; 392 int h_size; 393 int v_size; 394 int h_border; 395 int v_border; 396 unsigned int interlaced:1; 397 unsigned int stereo:2; 398 unsigned int sync:2; 399 unsigned int misc:2; 400 unsigned int stereo_1:1; 401}; 402 403#define DT 0 404#define DS_SERIAL 0xFF 405#define DS_ASCII_STR 0xFE 406#define DS_NAME 0xFC 407#define DS_RANGES 0xFD 408#define DS_WHITE_P 0xFB 409#define DS_STD_TIMINGS 0xFA 410#define DS_DUMMY 0x10 411#define DS_UNKOWN 0x100 /* type is an int */ 412 413struct monitor_ranges { 414 int min_v; 415 int max_v; 416 int min_h; 417 int max_h; 418 int max_clock; 419 int gtf_2nd_f; 420 int gtf_2nd_c; 421 int gtf_2nd_m; 422 int gtf_2nd_k; 423 int gtf_2nd_j; 424}; 425 426struct whitePoints{ 427 int index; 428 float white_x; 429 float white_y; 430 float white_gamma; 431}; 432 433struct detailed_monitor_section { 434 int type; 435 union { 436 struct detailed_timings d_timings; 437 Uchar serial[13]; 438 Uchar ascii_data[13]; 439 Uchar name[13]; 440 struct monitor_ranges ranges; 441 struct std_timings std_t[5]; 442 struct whitePoints wp[2]; 443 } section; 444}; 445 446typedef struct { 447 int scrnIndex; 448 struct vendor vendor; 449 struct edid_version ver; 450 struct disp_features features; 451 struct established_timings timings1; 452 struct std_timings timings2[8]; 453 struct detailed_monitor_section det_mon[4]; 454 void *vdif; /* unused */ 455 int no_sections; 456 Uchar *rawData; 457} xf86Monitor, *xf86MonPtr; 458 459extern xf86MonPtr ConfiguredMonitor; 460 461#endif /* _EDID_H_ */ 462