Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

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