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 #include <X11/Xmd.h>
16 
17 #ifndef _X_EXPORT
18 #include <X11/Xfuncproto.h>
19 #endif
20 
21 /* read complete EDID record */
22 #define EDID1_LEN 128
23 #define BITS_PER_BYTE 9
24 #define NUM BITS_PER_BYTE*EDID1_LEN
25 #define HEADER 6
26 
27 #define STD_TIMINGS 8
28 #define DET_TIMINGS 4
29 
30 #ifdef _PARSE_EDID_
31 
32 /* header: 0x00 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0x00  */
33 #define HEADER_SECTION 0
34 #define HEADER_LENGTH 8
35 
36 /* vendor section */
37 #define VENDOR_SECTION (HEADER_SECTION + HEADER_LENGTH)
38 #define V_MANUFACTURER 0
39 #define V_PROD_ID (V_MANUFACTURER + 2)
40 #define V_SERIAL (V_PROD_ID + 2)
41 #define V_WEEK (V_SERIAL + 4)
42 #define V_YEAR (V_WEEK + 1)
43 #define VENDOR_LENGTH (V_YEAR + 1)
44 
45 /* EDID version */
46 #define VERSION_SECTION (VENDOR_SECTION + VENDOR_LENGTH)
47 #define V_VERSION 0
48 #define V_REVISION (V_VERSION + 1)
49 #define VERSION_LENGTH (V_REVISION + 1)
50 
51 /* display information */
52 #define DISPLAY_SECTION (VERSION_SECTION + VERSION_LENGTH)
53 #define D_INPUT 0
54 #define D_HSIZE (D_INPUT + 1)
55 #define D_VSIZE (D_HSIZE + 1)
56 #define D_GAMMA (D_VSIZE + 1)
57 #define FEAT_S (D_GAMMA + 1)
58 #define D_RG_LOW (FEAT_S + 1)
59 #define D_BW_LOW (D_RG_LOW + 1)
60 #define D_REDX (D_BW_LOW + 1)
61 #define D_REDY (D_REDX + 1)
62 #define D_GREENX (D_REDY + 1)
63 #define D_GREENY (D_GREENX + 1)
64 #define D_BLUEX (D_GREENY + 1)
65 #define D_BLUEY (D_BLUEX + 1)
66 #define D_WHITEX (D_BLUEY + 1)
67 #define D_WHITEY (D_WHITEX + 1)
68 #define DISPLAY_LENGTH (D_WHITEY + 1)
69 
70 /* supported VESA and other standard timings */
71 #define ESTABLISHED_TIMING_SECTION (DISPLAY_SECTION + DISPLAY_LENGTH)
72 #define E_T1 0
73 #define E_T2 (E_T1 + 1)
74 #define E_TMANU (E_T2 + 1)
75 #define E_TIMING_LENGTH (E_TMANU + 1)
76 
77 /* non predefined standard timings supported by display */
78 #define STD_TIMING_SECTION (ESTABLISHED_TIMING_SECTION + E_TIMING_LENGTH)
79 #define STD_TIMING_INFO_LEN 2
80 #define STD_TIMING_INFO_NUM STD_TIMINGS
81 #define STD_TIMING_LENGTH (STD_TIMING_INFO_LEN * STD_TIMING_INFO_NUM)
82 
83 /* detailed timing info of non standard timings */
84 #define DET_TIMING_SECTION (STD_TIMING_SECTION + STD_TIMING_LENGTH)
85 #define DET_TIMING_INFO_LEN 18
86 #define MONITOR_DESC_LEN DET_TIMING_INFO_LEN
87 #define DET_TIMING_INFO_NUM DET_TIMINGS
88 #define DET_TIMING_LENGTH (DET_TIMING_INFO_LEN * DET_TIMING_INFO_NUM)
89 
90 /* number of EDID sections to follow */
91 #define NO_EDID (DET_TIMING_SECTION + DET_TIMING_LENGTH)
92 /* one byte checksum */
93 #define CHECKSUM (NO_EDID + 1)
94 
95 #if (CHECKSUM != (EDID1_LEN - 1))
96 #error "EDID1 length != 128!"
97 #endif
98 
99 #define SECTION(x,y) (Uchar *)(x + y)
100 #define GET_ARRAY(y) ((Uchar *)(c + y))
101 #define GET(y) *(Uchar *)(c + y)
102 
103 /* extract information from vendor section */
104 #define _PROD_ID(x) x[0] + (x[1] << 8);
105 #define PROD_ID _PROD_ID(GET_ARRAY(V_PROD_ID))
106 #define _SERIAL_NO(x) x[0] + (x[1] << 8) + (x[2] << 16) + (x[3] << 24)
107 #define SERIAL_NO _SERIAL_NO(GET_ARRAY(V_SERIAL))
108 #define _YEAR(x) (x & 0xFF) + 1990
109 #define YEAR _YEAR(GET(V_YEAR))
110 #define WEEK GET(V_WEEK) & 0xFF
111 #define _L1(x) ((x[0] & 0x7C) >> 2) + '@'
112 #define _L2(x) ((x[0] & 0x03) << 3) + ((x[1] & 0xE0) >> 5) + '@'
113 #define _L3(x) (x[1] & 0x1F) + '@';
114 #define L1 _L1(GET_ARRAY(V_MANUFACTURER))
115 #define L2 _L2(GET_ARRAY(V_MANUFACTURER))
116 #define L3 _L3(GET_ARRAY(V_MANUFACTURER))
117 
118 /* extract information from version section */
119 #define VERSION GET(V_VERSION)
120 #define REVISION GET(V_REVISION)
121 
122 /* extract information from display section */
123 #define _INPUT_TYPE(x) ((x & 0x80) >> 7)
124 #define INPUT_TYPE _INPUT_TYPE(GET(D_INPUT))
125 #define _INPUT_VOLTAGE(x) ((x & 0x60) >> 5)
126 #define INPUT_VOLTAGE _INPUT_VOLTAGE(GET(D_INPUT))
127 #define _SETUP(x) ((x & 0x10) >> 4)
128 #define SETUP _SETUP(GET(D_INPUT))
129 #define _SYNC(x) (x  & 0x0F)
130 #define SYNC _SYNC(GET(D_INPUT))
131 #define _DFP(x) (x & 0x01)
132 #define DFP _DFP(GET(D_INPUT))
133 #define _BPC(x) ((x & 0x70) >> 4)
134 #define BPC _BPC(GET(D_INPUT))
135 #define _DIGITAL_INTERFACE(x) (x & 0x0F)
136 #define DIGITAL_INTERFACE _DIGITAL_INTERFACE(GET(D_INPUT))
137 #define _GAMMA(x) (x == 0xff ? 0.0 : ((x + 100.0)/100.0))
138 #define GAMMA _GAMMA(GET(D_GAMMA))
139 #define HSIZE_MAX GET(D_HSIZE)
140 #define VSIZE_MAX GET(D_VSIZE)
141 #define _DPMS(x) ((x & 0xE0) >> 5)
142 #define DPMS _DPMS(GET(FEAT_S))
143 #define _DISPLAY_TYPE(x) ((x & 0x18) >> 3)
144 #define DISPLAY_TYPE _DISPLAY_TYPE(GET(FEAT_S))
145 #define _MSC(x) (x & 0x7)
146 #define MSC _MSC(GET(FEAT_S))
147 
148 /* color characteristics */
149 #define CC_L(x,y) ((x & (0x03 << y)) >> y)
150 #define CC_H(x) (x << 2)
151 #define I_CC(x,y,z) CC_H(y) | CC_L(x,z)
152 #define F_CC(x) ((x)/1024.0)
153 #define REDX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDX)),6))
154 #define REDY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_REDY)),4))
155 #define GREENX F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENX)),2))
156 #define GREENY F_CC(I_CC((GET(D_RG_LOW)),(GET(D_GREENY)),0))
157 #define BLUEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEX)),6))
158 #define BLUEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_BLUEY)),4))
159 #define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2))
160 #define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0))
161 
162 /* extract information from standard timing section */
163 #define T1 GET(E_T1)
164 #define T2 GET(E_T2)
165 #define T_MANU GET(E_TMANU)
166 
167 /* extract information from established timing section */
168 #define _VALID_TIMING(x) !(((x[0] == 0x01) && (x[1] == 0x01)) \
169                         || ((x[0] == 0x00) && (x[1] == 0x00)) \
170                         || ((x[0] == 0x20) && (x[1] == 0x20)) )
171 #define VALID_TIMING _VALID_TIMING(c)
172 #define _HSIZE1(x) ((x[0] + 31) * 8)
173 #define HSIZE1 _HSIZE1(c)
174 #define RATIO(x) ((x[1] & 0xC0) >> 6)
175 #define RATIO1_1 0
176 /* EDID Ver. 1.3 redefined this */
177 #define RATIO16_10 RATIO1_1
178 #define RATIO4_3 1
179 #define RATIO5_4 2
180 #define RATIO16_9 3
181 #define _VSIZE1(x,y,r) switch(RATIO(x)){ \
182   case RATIO1_1: y =  ((v->version > 1 || v->revision > 2) \
183 		       ? (_HSIZE1(x) * 10) / 16 : _HSIZE1(x)); break; \
184   case RATIO4_3: y = _HSIZE1(x) * 3 / 4; break; \
185   case RATIO5_4: y = _HSIZE1(x) * 4 / 5; break; \
186   case RATIO16_9: y = _HSIZE1(x) * 9 / 16; break; \
187   }
188 #define VSIZE1(x) _VSIZE1(c,x,v)
189 #define _REFRESH_R(x) (x[1] & 0x3F) + 60
190 #define REFRESH_R  _REFRESH_R(c)
191 #define _ID_LOW(x) x[0]
192 #define ID_LOW _ID_LOW(c)
193 #define _ID_HIGH(x) (x[1] << 8)
194 #define ID_HIGH _ID_HIGH(c)
195 #define STD_TIMING_ID (ID_LOW | ID_HIGH)
196 #define _NEXT_STD_TIMING(x)  (x = (x + STD_TIMING_INFO_LEN))
197 #define NEXT_STD_TIMING _NEXT_STD_TIMING(c)
198 
199 /* EDID Ver. >= 1.2 */
200 /**
201  * Returns true if the pointer is the start of a monitor descriptor block
202  * instead of a detailed timing descriptor.
203  *
204  * Checking the reserved pad fields for zeroes fails on some monitors with
205  * broken empty ASCII strings.  Only the first two bytes are reliable.
206  */
207 #define _IS_MONITOR_DESC(x) (x[0] == 0 && x[1] == 0)
208 #define IS_MONITOR_DESC _IS_MONITOR_DESC(c)
209 #define _PIXEL_CLOCK(x) (x[0] + (x[1] << 8)) * 10000
210 #define PIXEL_CLOCK _PIXEL_CLOCK(c)
211 #define _H_ACTIVE(x) (x[2] + ((x[4] & 0xF0) << 4))
212 #define H_ACTIVE _H_ACTIVE(c)
213 #define _H_BLANK(x) (x[3] + ((x[4] & 0x0F) << 8))
214 #define H_BLANK _H_BLANK(c)
215 #define _V_ACTIVE(x) (x[5] + ((x[7] & 0xF0) << 4))
216 #define V_ACTIVE _V_ACTIVE(c)
217 #define _V_BLANK(x) (x[6] + ((x[7] & 0x0F) << 8))
218 #define V_BLANK _V_BLANK(c)
219 #define _H_SYNC_OFF(x) (x[8] + ((x[11] & 0xC0) << 2))
220 #define H_SYNC_OFF _H_SYNC_OFF(c)
221 #define _H_SYNC_WIDTH(x) (x[9] + ((x[11] & 0x30) << 4))
222 #define H_SYNC_WIDTH _H_SYNC_WIDTH(c)
223 #define _V_SYNC_OFF(x) ((x[10] >> 4) + ((x[11] & 0x0C) << 2))
224 #define V_SYNC_OFF _V_SYNC_OFF(c)
225 #define _V_SYNC_WIDTH(x) ((x[10] & 0x0F) + ((x[11] & 0x03) << 4))
226 #define V_SYNC_WIDTH _V_SYNC_WIDTH(c)
227 #define _H_SIZE(x) (x[12] + ((x[14] & 0xF0) << 4))
228 #define H_SIZE _H_SIZE(c)
229 #define _V_SIZE(x) (x[13] + ((x[14] & 0x0F) << 8))
230 #define V_SIZE _V_SIZE(c)
231 #define _H_BORDER(x) (x[15])
232 #define H_BORDER _H_BORDER(c)
233 #define _V_BORDER(x) (x[16])
234 #define V_BORDER _V_BORDER(c)
235 #define _INTERLACED(x) ((x[17] & 0x80) >> 7)
236 #define INTERLACED _INTERLACED(c)
237 #define _STEREO(x) ((x[17] & 0x60) >> 5)
238 #define STEREO _STEREO(c)
239 #define _STEREO1(x) (x[17] & 0x1)
240 #define STEREO1 _STEREO(c)
241 #define _SYNC_T(x) ((x[17] & 0x18) >> 3)
242 #define SYNC_T _SYNC_T(c)
243 #define _MISC(x) ((x[17] & 0x06) >> 1)
244 #define MISC _MISC(c)
245 
246 #define _MONITOR_DESC_TYPE(x) x[3]
247 #define MONITOR_DESC_TYPE _MONITOR_DESC_TYPE(c)
248 #define SERIAL_NUMBER 0xFF
249 #define ASCII_STR 0xFE
250 #define MONITOR_RANGES 0xFD
251 #define _MIN_V_OFFSET(x) ((!!(x[4] & 0x01)) * 255)
252 #define _MAX_V_OFFSET(x) ((!!(x[4] & 0x02)) * 255)
253 #define _MIN_H_OFFSET(x) ((!!(x[4] & 0x04)) * 255)
254 #define _MAX_H_OFFSET(x) ((!!(x[4] & 0x08)) * 255)
255 #define _MIN_V(x) x[5]
256 #define MIN_V (_MIN_V(c) + _MIN_V_OFFSET(c))
257 #define _MAX_V(x) x[6]
258 #define MAX_V (_MAX_V(c) + _MAX_V_OFFSET(c))
259 #define _MIN_H(x) x[7]
260 #define MIN_H (_MIN_H(c) + _MIN_H_OFFSET(c))
261 #define _MAX_H(x) x[8]
262 #define MAX_H (_MAX_H(c) + _MAX_H_OFFSET(c))
263 #define _MAX_CLOCK(x) x[9]
264 #define MAX_CLOCK _MAX_CLOCK(c)
265 #define _DEFAULT_GTF(x) (x[10] == 0x00)
266 #define DEFAULT_GTF _DEFAULT_GTF(c)
267 #define _RANGE_LIMITS_ONLY(x) (x[10] == 0x01)
268 #define RANGE_LIMITS_ONLY _RANGE_LIMITS_ONLY(c)
269 #define _HAVE_2ND_GTF(x) (x[10] == 0x02)
270 #define HAVE_2ND_GTF _HAVE_2ND_GTF(c)
271 #define _F_2ND_GTF(x) (x[12] * 2)
272 #define F_2ND_GTF _F_2ND_GTF(c)
273 #define _C_2ND_GTF(x) (x[13] / 2)
274 #define C_2ND_GTF _C_2ND_GTF(c)
275 #define _M_2ND_GTF(x) (x[14] + (x[15] << 8))
276 #define M_2ND_GTF _M_2ND_GTF(c)
277 #define _K_2ND_GTF(x) (x[16])
278 #define K_2ND_GTF _K_2ND_GTF(c)
279 #define _J_2ND_GTF(x) (x[17] / 2)
280 #define J_2ND_GTF _J_2ND_GTF(c)
281 #define _HAVE_CVT(x) (x[10] == 0x04)
282 #define HAVE_CVT _HAVE_CVT(c)
283 #define _MAX_CLOCK_KHZ(x) (x[12] >> 2)
284 #define MAX_CLOCK_KHZ (MAX_CLOCK * 10000) - (_MAX_CLOCK_KHZ(c) * 250)
285 #define _MAXWIDTH(x) ((x[13] == 0 ? 0 : x[13] + ((x[12] & 0x03) << 8)) * 8)
286 #define MAXWIDTH _MAXWIDTH(c)
287 #define _SUPPORTED_ASPECT(x) x[14]
288 #define SUPPORTED_ASPECT _SUPPORTED_ASPECT(c)
289 #define  SUPPORTED_ASPECT_4_3   0x80
290 #define  SUPPORTED_ASPECT_16_9  0x40
291 #define  SUPPORTED_ASPECT_16_10 0x20
292 #define  SUPPORTED_ASPECT_5_4   0x10
293 #define  SUPPORTED_ASPECT_15_9  0x08
294 #define _PREFERRED_ASPECT(x) ((x[15] & 0xe0) >> 5)
295 #define PREFERRED_ASPECT _PREFERRED_ASPECT(c)
296 #define  PREFERRED_ASPECT_4_3   0
297 #define  PREFERRED_ASPECT_16_9  1
298 #define  PREFERRED_ASPECT_16_10 2
299 #define  PREFERRED_ASPECT_5_4   3
300 #define  PREFERRED_ASPECT_15_9  4
301 #define _SUPPORTED_BLANKING(x) ((x[15] & 0x18) >> 3)
302 #define SUPPORTED_BLANKING _SUPPORTED_BLANKING(c)
303 #define  CVT_STANDARD 0x01
304 #define  CVT_REDUCED  0x02
305 #define _SUPPORTED_SCALING(x) ((x[16] & 0xf0) >> 4)
306 #define SUPPORTED_SCALING _SUPPORTED_SCALING(c)
307 #define  SCALING_HSHRINK  0x08
308 #define  SCALING_HSTRETCH 0x04
309 #define  SCALING_VSHRINK  0x02
310 #define  SCALING_VSTRETCH 0x01
311 #define _PREFERRED_REFRESH(x) x[17]
312 #define PREFERRED_REFRESH _PREFERRED_REFRESH(c)
313 
314 #define MONITOR_NAME 0xFC
315 #define ADD_COLOR_POINT 0xFB
316 #define WHITEX F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEX)),2))
317 #define WHITEY F_CC(I_CC((GET(D_BW_LOW)),(GET(D_WHITEY)),0))
318 #define _WHITEX_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 1)),2))
319 #define _WHITEY_ADD(x,y) F_CC(I_CC(((*(x + y))),(*(x + y + 2)),0))
320 #define _WHITE_INDEX1(x) x[5]
321 #define WHITE_INDEX1 _WHITE_INDEX1(c)
322 #define _WHITE_INDEX2(x) x[10]
323 #define WHITE_INDEX2 _WHITE_INDEX2(c)
324 #define WHITEX1 _WHITEX_ADD(c,6)
325 #define WHITEY1 _WHITEY_ADD(c,6)
326 #define WHITEX2 _WHITEX_ADD(c,12)
327 #define WHITEY2 _WHITEY_ADD(c,12)
328 #define _WHITE_GAMMA1(x) _GAMMA(x[9])
329 #define WHITE_GAMMA1 _WHITE_GAMMA1(c)
330 #define _WHITE_GAMMA2(x) _GAMMA(x[14])
331 #define WHITE_GAMMA2 _WHITE_GAMMA2(c)
332 #define ADD_STD_TIMINGS 0xFA
333 #define COLOR_MANAGEMENT_DATA 0xF9
334 #define CVT_3BYTE_DATA 0xF8
335 #define ADD_EST_TIMINGS 0xF7
336 #define ADD_DUMMY 0x10
337 
338 #define _NEXT_DT_MD_SECTION(x) (x = (x + DET_TIMING_INFO_LEN))
339 #define NEXT_DT_MD_SECTION _NEXT_DT_MD_SECTION(c)
340 
341 #endif                          /* _PARSE_EDID_ */
342 
343 /* input type */
344 #define DIGITAL(x) x
345 
346 /* DFP */
347 #define DFP1(x) x
348 
349 /* input voltage level */
350 #define V070 0                  /* 0.700V/0.300V */
351 #define V071 1                  /* 0.714V/0.286V */
352 #define V100 2                  /* 1.000V/0.400V */
353 #define V007 3                  /* 0.700V/0.000V */
354 
355 /* Signal level setup */
356 #define SIG_SETUP(x) (x)
357 
358 /* sync characteristics */
359 #define SEP_SYNC(x) (x & 0x08)
360 #define COMP_SYNC(x) (x & 0x04)
361 #define SYNC_O_GREEN(x) (x & 0x02)
362 #define SYNC_SERR(x) (x & 0x01)
363 
364 /* DPMS features */
365 #define DPMS_STANDBY(x) (x & 0x04)
366 #define DPMS_SUSPEND(x) (x & 0x02)
367 #define DPMS_OFF(x) (x & 0x01)
368 
369 /* display type, analog */
370 #define DISP_MONO 0
371 #define DISP_RGB 1
372 #define DISP_MULTCOLOR 2
373 
374 /* display color encodings, digital */
375 #define DISP_YCRCB444 0x01
376 #define DISP_YCRCB422 0x02
377 
378 /* Msc stuff EDID Ver > 1.1 */
379 #define STD_COLOR_SPACE(x) (x & 0x4)
380 #define PREFERRED_TIMING_MODE(x) (x & 0x2)
381 #define GFT_SUPPORTED(x) (x & 0x1)
382 #define GTF_SUPPORTED(x) (x & 0x1)
383 #define CVT_SUPPORTED(x) (x & 0x1)
384 
385 /* detailed timing misc */
386 #define IS_INTERLACED(x)  (x)
387 #define IS_STEREO(x)  (x)
388 #define IS_RIGHT_STEREO(x) (x & 0x01)
389 #define IS_LEFT_STEREO(x) (x & 0x02)
390 #define IS_4WAY_STEREO(x) (x & 0x03)
391 #define IS_RIGHT_ON_SYNC(x) IS_RIGHT_STEREO(x)
392 #define IS_LEFT_ON_SYNC(x) IS_LEFT_STEREO(x)
393 
394 typedef unsigned int Uint;
395 typedef unsigned char Uchar;
396 
397 struct vendor {
398     char name[4];
399     int prod_id;
400     Uint serial;
401     int week;
402     int year;
403 };
404 
405 struct edid_version {
406     int version;
407     int revision;
408 };
409 
410 struct disp_features {
411     unsigned int input_type:1;
412     unsigned int input_voltage:2;
413     unsigned int input_setup:1;
414     unsigned int input_sync:5;
415     unsigned int input_dfp:1;
416     unsigned int input_bpc:3;
417     unsigned int input_interface:4;
418     /* 15 bit hole */
419     int hsize;
420     int vsize;
421     float gamma;
422     unsigned int dpms:3;
423     unsigned int display_type:2;
424     unsigned int msc:3;
425     float redx;
426     float redy;
427     float greenx;
428     float greeny;
429     float bluex;
430     float bluey;
431     float whitex;
432     float whitey;
433 };
434 
435 struct established_timings {
436     Uchar t1;
437     Uchar t2;
438     Uchar t_manu;
439 };
440 
441 struct std_timings {
442     int hsize;
443     int vsize;
444     int refresh;
445     CARD16 id;
446 };
447 
448 struct detailed_timings {
449     int clock;
450     int h_active;
451     int h_blanking;
452     int v_active;
453     int v_blanking;
454     int h_sync_off;
455     int h_sync_width;
456     int v_sync_off;
457     int v_sync_width;
458     int h_size;
459     int v_size;
460     int h_border;
461     int v_border;
462     unsigned int interlaced:1;
463     unsigned int stereo:2;
464     unsigned int sync:2;
465     unsigned int misc:2;
466     unsigned int stereo_1:1;
467 };
468 
469 #define DT 0
470 #define DS_SERIAL 0xFF
471 #define DS_ASCII_STR 0xFE
472 #define DS_NAME 0xFC
473 #define DS_RANGES 0xFD
474 #define DS_WHITE_P 0xFB
475 #define DS_STD_TIMINGS 0xFA
476 #define DS_CMD 0xF9
477 #define DS_CVT 0xF8
478 #define DS_EST_III 0xF7
479 #define DS_DUMMY 0x10
480 #define DS_UNKOWN 0x100         /* type is an int */
481 #define DS_VENDOR 0x101
482 #define DS_VENDOR_MAX 0x110
483 
484 /*
485  * Display range limit Descriptor of EDID version1, reversion 4
486  */
487 typedef enum {
488 	DR_DEFAULT_GTF,
489 	DR_LIMITS_ONLY,
490 	DR_SECONDARY_GTF,
491 	DR_CVT_SUPPORTED = 4,
492 } DR_timing_flags;
493 
494 struct monitor_ranges {
495     int min_v;
496     int max_v;
497     int min_h;
498     int max_h;
499     int max_clock;              /* in mhz */
500     int gtf_2nd_f;
501     int gtf_2nd_c;
502     int gtf_2nd_m;
503     int gtf_2nd_k;
504     int gtf_2nd_j;
505     int max_clock_khz;
506     int maxwidth;               /* in pixels */
507     char supported_aspect;
508     char preferred_aspect;
509     char supported_blanking;
510     char supported_scaling;
511     int preferred_refresh;      /* in hz */
512     DR_timing_flags display_range_timing_flags;
513 };
514 
515 struct whitePoints {
516     int index;
517     float white_x;
518     float white_y;
519     float white_gamma;
520 };
521 
522 struct cvt_timings {
523     int width;
524     int height;
525     int rate;
526     int rates;
527 };
528 
529 /*
530  * Be careful when adding new sections; this structure can't grow, it's
531  * embedded in the middle of xf86Monitor which is ABI.  Sizes below are
532  * in bytes, for ILP32 systems.  If all else fails just copy the section
533  * literally like serial and friends.
534  */
535 struct detailed_monitor_section {
536     int type;
537     union {
538         struct detailed_timings d_timings;      /* 56 */
539         Uchar serial[13];
540         Uchar ascii_data[13];
541         Uchar name[13];
542         struct monitor_ranges ranges;   /* 60 */
543         struct std_timings std_t[5];    /* 80 */
544         struct whitePoints wp[2];       /* 32 */
545         /* color management data */
546         struct cvt_timings cvt[4];      /* 64 */
547         Uchar est_iii[6];       /* 6 */
548     } section;                  /* max: 80 */
549 };
550 
551 /* flags */
552 #define MONITOR_EDID_COMPLETE_RAWDATA	0x01
553 /* old, don't use */
554 #define EDID_COMPLETE_RAWDATA		0x01
555 
556 /*
557  * For DisplayID devices, only the scrnIndex, flags, and rawData fields
558  * are meaningful.  For EDID, they all are.
559  */
560 typedef struct {
561     int scrnIndex;
562     struct vendor vendor;
563     struct edid_version ver;
564     struct disp_features features;
565     struct established_timings timings1;
566     struct std_timings timings2[8];
567     struct detailed_monitor_section det_mon[4];
568     unsigned long flags;
569     int no_sections;
570     Uchar *rawData;
571 } xf86Monitor, *xf86MonPtr;
572 
573 extern _X_EXPORT xf86MonPtr ConfiguredMonitor;
574 
575 #define EXT_TAG 0
576 #define EXT_REV 1
577 #define CEA_EXT   0x02
578 #define VTB_EXT   0x10
579 #define DI_EXT    0x40
580 #define LS_EXT    0x50
581 #define MI_EXT    0x60
582 
583 #define CEA_EXT_MIN_DATA_OFFSET 4
584 #define CEA_EXT_MAX_DATA_OFFSET 127
585 #define CEA_EXT_DET_TIMING_NUM 6
586 
587 #define IEEE_ID_HDMI    0x000C03
588 #define CEA_AUDIO_BLK   1
589 #define CEA_VIDEO_BLK   2
590 #define CEA_VENDOR_BLK  3
591 #define CEA_SPEAKER_ALLOC_BLK 4
592 #define CEA_VESA_DTC_BLK 5
593 #define VENDOR_SUPPORT_AI(x) ((x) >> 7)
594 #define VENDOR_SUPPORT_DC_48bit(x)  ( ( (x) >> 6) & 0x01)
595 #define VENDOR_SUPPORT_DC_36bit(x)  ( ( (x) >> 5) & 0x01)
596 #define VENDOR_SUPPORT_DC_30bit(x)  ( ( (x) >> 4) & 0x01)
597 #define VENDOR_SUPPORT_DC_Y444(x)   ( ( (x) >> 3) & 0x01)
598 #define VENDOR_LATENCY_PRESENT(x)     ( (x) >> 7)
599 #define VENDOR_LATENCY_PRESENT_I(x) ( ( (x) >> 6) & 0x01)
600 #define HDMI_MAX_TMDS_UNIT   (5000)
601 
602 struct cea_video_block {
603     Uchar video_code;
604 };
605 
606 struct cea_audio_block_descriptor {
607     Uchar audio_code[3];
608 };
609 
610 struct cea_audio_block {
611     struct cea_audio_block_descriptor descriptor[10];
612 };
613 
614 struct cea_vendor_block_hdmi {
615     Uchar portB:4;
616     Uchar portA:4;
617     Uchar portD:4;
618     Uchar portC:4;
619     Uchar support_flags;
620     Uchar max_tmds_clock;
621     Uchar latency_present;
622     Uchar video_latency;
623     Uchar audio_latency;
624     Uchar interlaced_video_latency;
625     Uchar interlaced_audio_latency;
626 };
627 
628 struct cea_vendor_block {
629     unsigned char ieee_id[3];
630     union {
631         struct cea_vendor_block_hdmi hdmi;
632         /* any other vendor blocks we know about */
633     };
634 };
635 
636 struct cea_speaker_block {
637     Uchar FLR:1;
638     Uchar LFE:1;
639     Uchar FC:1;
640     Uchar RLR:1;
641     Uchar RC:1;
642     Uchar FLRC:1;
643     Uchar RLRC:1;
644     Uchar FLRW:1;
645     Uchar FLRH:1;
646     Uchar TC:1;
647     Uchar FCH:1;
648     Uchar Resv:5;
649     Uchar ResvByte;
650 };
651 
652 struct cea_data_block {
653     Uchar len:5;
654     Uchar tag:3;
655     union {
656         struct cea_video_block video;
657         struct cea_audio_block audio;
658         struct cea_vendor_block vendor;
659         struct cea_speaker_block speaker;
660     } u;
661 };
662 
663 struct cea_ext_body {
664     Uchar tag;
665     Uchar rev;
666     Uchar dt_offset;
667     Uchar flags;
668     struct cea_data_block data_collection;
669 };
670 
671 #endif                          /* _EDID_H_ */
672