2 * Parse VESA Extended Display Identification Data
4 * (c) 2011 Martin Mares <mj@ucw.cz>
13 typedef unsigned int uns;
14 typedef unsigned char byte;
16 static byte edid[128];
21 __attribute__((format(printf,1,2)))
22 __attribute__((noreturn))
28 fprintf(stderr, "edid: ");
29 vfprintf(stderr, msg, args);
38 return p[0] | (p[1] << 8);
44 return u16_le(p) | (u16_le(p+2) << 16);
56 printf("Model: %c%c%c %04x #%u\n",
57 ('A' - 1 + ((p[0] >> 2) & 0x1f)),
58 ('A' - 1 + ((p[0] & 3) << 3) | ((p[1] & 0xe0) >> 5)),
59 ('A' - 1 + (p[1] & 0x1f)),
62 printf("Manufactured: %d week %d\n", p[9] + 1990, p[8]);
70 printf("Input: Digital DFP%c\n", B(input & 1));
72 printf("Input: Analog SigLev=%d Setup%c SepSync%c CompSync%c GreenSync%c SerrSync%c\n",
80 printf("Image size: %dx%dcm\n", p[1], p[2]);
82 printf("Gamma: not given\n");
84 printf("Gamma: %d.%02d\n", (p[3] / 100) + 1, p[3] % 100);
87 static const char * const types[4] = { "Mono/Gray", "RGB", "NonRGB", "Unknown" };
88 printf("Flags: Suspend%c Standby%c ActiveOff%c Colors=%s HasSRGB%c PrefTiming%c GTF%c\n",
92 types[(flags >> 3) & 3],
101 uns rx = 4*p[2] | ((p[0] >> 6) & 3);
102 uns ry = 4*p[3] | ((p[0] >> 4) & 3);
103 uns gx = 4*p[4] | ((p[0] >> 2) & 3);
104 uns gy = 4*p[5] | ((p[0] ) & 3);
105 uns bx = 4*p[5] | ((p[1] >> 6) & 3);
106 uns by = 4*p[7] | ((p[1] >> 4) & 3);
107 uns wx = 4*p[8] | ((p[1] >> 2) & 3);
108 uns wy = 4*p[9] | ((p[1] ) & 3);
109 #define C(c) ((double)c / 1024)
110 printf("Chromaticity: R=(%.3f,%.3f) G=(%.3f,%.3f) B=(%.3f,%.3f) W=(%.3f,%.3f)\n",
111 C(rx), C(ry), C(gx), C(gy), C(bx), C(by), C(wx), C(wy));
116 show_timings(byte *p)
118 static const char * const estab_timings[24] = {
144 printf("Basic timings:");
145 for (int i=0; i<24; i++)
146 if (p[i/8] & (0x80 >> (i%8)))
147 printf(" %s", estab_timings[i]);
150 printf("Extended timings:");
151 for (int i=0; i<8; i++)
153 byte *q = p + 3 + 2*i;
154 if (q[0] == 1 && q[1] == 1)
156 uns h = (31 + q[0]) * 8;
161 if (version < 0x0103)
176 printf(" %dx%d@%d", h, v, 60 + (q[1] & 0x3f));
182 show_detailed_timing(byte *p)
184 uns hactive = p[2] | ((p[4] << 4) & 0xf00);
185 uns hblank = p[3] | ((p[4] << 8) & 0xf00);
186 uns vactive = p[5] | ((p[7] << 4) & 0xf00);
187 uns vblank = p[6] | ((p[7] << 8) & 0xf00);
188 uns hs_offset = p[8] | ((p[11] << 2) & 0x300);
189 uns hs_width = p[9] | ((p[11] << 4) & 0x300);
190 uns vs_offset = (p[10] >> 4) | ((p[11] << 2) & 0x30);
191 uns vs_width = (p[10] & 0xf) | ((p[11] << 4) & 0x30);
192 uns hsize = p[12] | ((p[14] << 4) & 0xf00);
193 uns vsize = p[13] | ((p[14] << 8) & 0xf00);
197 printf("Detailed timing: %dx%d (%.1f Hz)\n",
199 u16_le(p) * 10000. / (hactive+hblank) / (vactive+vblank));
200 printf("\tPixClk: %.2fMHz\n", u16_le(p) / 100.);
201 printf("\tH: Active=%d Blank=%d SyncOffset=%d SyncWidth=%d Border=%d\n",
202 hactive, hblank, hs_offset, hs_width, hborder);
203 printf("\tV: Active=%d Blank=%d SyncOffset=%d SyncWidth=%d Border=%d\n",
204 vactive, vblank, vs_offset, vs_width, vborder);
205 printf("\tSize: %dx%dmm\n", hsize, vsize);
208 uns stereo = ((flags >> 4) & 6) | (flags & 1);
209 uns input = (flags >> 3) & 3;
211 printf("\tStereo mode: #%d\n", stereo);
213 static const char * const input_types[4] = { "AnalogComposite", "BipolarAnalogComposite", "DigitalComposite", "DigitalSeparate" };
214 printf("\tInput: %s", input_types[input]);
216 printf(" Serrate%c", B(flags & 4));
218 printf(" VPolarity%c", B(flags & 4));
220 printf(" OnRGB%c", B(flags & 2));
222 printf(" CompPolarity%c", B(flags & 2));
224 printf(" HPolarity%c", B(flags & 2));
228 printf("\tCalculated DPI: %dx%d\n",
229 (int)(hactive / (hsize / 25.4)),
230 (int)(vactive / (vsize / 25.4)));
234 show_ascii(char *field, byte *p, uns len)
236 printf("%s: ", field);
241 else if (*p >= 0x20 && *p <= 0x7e)
244 printf("<%02x>", *p);
251 show_descriptor(byte *p)
255 case 0xff: // Serial number
256 show_ascii("Serial", p+5, 13);
258 case 0xfe: // ASCII data
259 show_ascii("Comment", p+5, 13);
261 case 0xfd: // Range limits
262 printf("Limits: Vert=%d-%dHz Horiz=%d-%dkHz PixClk=%dMHz\n",
263 p[5], p[6], p[7], p[8], p[9]*10);
266 case 0: // No secondary timing formula
268 case 2: // Secondary GTF
269 printf("Secondary GTF parameters: fStart=%dkHz C=%.1f M=%d K=%d J=%.1f\n",
270 p[12]*2, p[13]/2., u16_le(p+14), p[16], p[17]/2.);
273 printf("Unidentified secondary timing formula #%02x\n", p[10]);
276 case 0xfc: // Monitor name
277 show_ascii("Monitor name", p+5, 13);
279 case 0xfb: // Color point
280 printf("Color point: [...]\n");
282 case 0xfa: // More standard timings
283 printf("More standard timings: [...]\n");
285 case 0x10: // Dummy descriptor -- entry unused
288 printf("Unknown descriptor type %02x\n", p[3]);
295 if (memcmp(edid, "\000\377\377\377\377\377\377\000", 8))
296 die("Invalid EDID signature, giving up");
297 int ver = edid[0x12];
298 int rev = edid[0x13];
299 printf("EDID %d.%d\n", ver, rev);
300 version = (ver << 8) | rev;
303 for (int i=0; i<128; i++)
306 printf("Invalid checksum: off by %02x\n", sum);
308 show_model(edid + 8);
309 show_basic(edid + 0x14);
310 show_color(edid + 0x19);
311 show_timings(edid + 0x23);
312 for (int i=0; i<4; i++)
314 byte *p = edid + 0x36 + 18*i;
316 show_detailed_timing(p);
322 printf("### %d extension blocks follow, but they are not supported yet ###\n", edid[0x7e]);
325 static void read_binary(void)
327 int c = read(0, edid, 128);
329 die("Read error: %m");
331 die("Read only %d bytes, need 128", c);
341 while (fgets(line, sizeof(line), stdin))
345 if (strstr(line, "EDID (in hex):"))
350 char *c = strchr(line, '\n');
354 for (int i=0; i<32; i++)
359 if (x >= '0' && x <= '9')
361 else if (x >= 'A' && x <= 'F')
363 else if (x >= 'a' && x <= 'f')
370 edid[cnt-1-i/2] |= x << 4;
372 if (c > line && c[-1] != ' ' && c[-1] != '\t')
379 die("No EDID log found");
381 die("EDID log found, but it is too short (only %d bytes)", cnt);
384 die("EDID log parse error at: %s", line);
391 for (int i=0; i<128; i+=16)
394 for (int j=0; j<16; j++)
395 printf(" %02x", edid[i+j]);
403 fprintf(stderr, "Usage: edid <options>\n\n\
405 -l\t\tParse input as Xorg log file and try to find EDID dump there\n\
406 -x\t\tShow hexdump of the whole EDID block\n\
411 int main(int argc, char **argv)
417 while ((opt = getopt(argc, argv, "xl")) >= 0)