2
* Copyright 2007 Red Hat, Inc.
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* on the rights to use, copy, modify, merge, publish, distribute, sub
8
* license, and/or sell copies of the Software, and to permit persons to whom
9
* the Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
/* Author: Soren Sandmann <sandmann@redhat.com> */
32
get_bit (int in, int bit)
34
return (in & (1 << bit)) >> bit;
38
get_bits (int in, int begin, int end)
40
int mask = (1 << (end - begin + 1)) - 1;
42
return (in >> begin) & mask;
46
decode_header (const uchar *edid)
48
if (memcmp (edid, "\x00\xff\xff\xff\xff\xff\xff\x00", 8) == 0)
54
decode_vendor_and_product_identification (const uchar *edid, MonitorInfo *info)
58
/* Manufacturer Code */
59
info->manufacturer_code[0] = get_bits (edid[0x08], 2, 6);
60
info->manufacturer_code[1] = get_bits (edid[0x08], 0, 1) << 3;
61
info->manufacturer_code[1] |= get_bits (edid[0x09], 5, 7);
62
info->manufacturer_code[2] = get_bits (edid[0x09], 0, 4);
63
info->manufacturer_code[3] = '\0';
65
info->manufacturer_code[0] += 'A' - 1;
66
info->manufacturer_code[1] += 'A' - 1;
67
info->manufacturer_code[2] += 'A' - 1;
70
info->product_code = edid[0x0b] << 8 | edid[0x0a];
74
edid[0x0c] | edid[0x0d] << 8 | edid[0x0e] << 16 | edid[0x0f] << 24;
77
is_model_year = FALSE;
81
info->production_week = -1;
85
info->production_week = -1;
90
info->production_week = edid[0x10];
96
info->production_year = -1;
97
info->model_year = 1990 + edid[0x11];
101
info->production_year = 1990 + edid[0x11];
102
info->model_year = -1;
109
decode_edid_version (const uchar *edid, MonitorInfo *info)
111
info->major_version = edid[0x12];
112
info->minor_version = edid[0x13];
118
decode_display_parameters (const uchar *edid, MonitorInfo *info)
120
/* Digital vs Analog */
121
info->is_digital = get_bit (edid[0x14], 7);
123
if (info->is_digital)
127
static const int bit_depth[8] =
129
-1, 6, 8, 10, 12, 14, 16, -1
132
static const Interface interfaces[6] =
134
UNDEFINED, DVI, HDMI_A, HDMI_B, MDDI, DISPLAY_PORT
137
bits = get_bits (edid[0x14], 4, 6);
138
info->connector.digital.bits_per_primary = bit_depth[bits];
140
bits = get_bits (edid[0x14], 0, 3);
143
info->connector.digital.interface = interfaces[bits];
145
info->connector.digital.interface = UNDEFINED;
149
int bits = get_bits (edid[0x14], 5, 6);
151
static const double levels[][3] =
154
{ 0.714, 0.286, 1.0 },
159
info->connector.analog.video_signal_level = levels[bits][0];
160
info->connector.analog.sync_signal_level = levels[bits][1];
161
info->connector.analog.total_signal_level = levels[bits][2];
163
info->connector.analog.blank_to_black = get_bit (edid[0x14], 4);
165
info->connector.analog.separate_hv_sync = get_bit (edid[0x14], 3);
166
info->connector.analog.composite_sync_on_h = get_bit (edid[0x14], 2);
167
info->connector.analog.composite_sync_on_green = get_bit (edid[0x14], 1);
169
info->connector.analog.serration_on_vsync = get_bit (edid[0x14], 0);
172
/* Screen Size / Aspect Ratio */
173
if (edid[0x15] == 0 && edid[0x16] == 0)
176
info->height_mm = -1;
177
info->aspect_ratio = -1.0;
179
else if (edid[0x16] == 0)
182
info->height_mm = -1;
183
info->aspect_ratio = 100.0 / (edid[0x15] + 99);
185
else if (edid[0x15] == 0)
188
info->height_mm = -1;
189
info->aspect_ratio = 100.0 / (edid[0x16] + 99);
190
info->aspect_ratio = 1/info->aspect_ratio; /* portrait */
194
info->width_mm = 10 * edid[0x15];
195
info->height_mm = 10 * edid[0x16];
199
if (edid[0x17] == 0xFF)
202
info->gamma = (edid[0x17] + 100.0) / 100.0;
205
info->standby = get_bit (edid[0x18], 7);
206
info->suspend = get_bit (edid[0x18], 6);
207
info->active_off = get_bit (edid[0x18], 5);
209
if (info->is_digital)
211
info->connector.digital.rgb444 = TRUE;
212
if (get_bit (edid[0x18], 3))
213
info->connector.digital.ycrcb444 = 1;
214
if (get_bit (edid[0x18], 4))
215
info->connector.digital.ycrcb422 = 1;
219
int bits = get_bits (edid[0x18], 3, 4);
220
ColorType color_type[4] =
222
MONOCHROME, RGB, OTHER_COLOR, UNDEFINED_COLOR
225
info->connector.analog.color_type = color_type[bits];
228
info->srgb_is_standard = get_bit (edid[0x18], 2);
230
/* In 1.3 this is called "has preferred timing" */
231
info->preferred_timing_includes_native = get_bit (edid[0x18], 1);
233
/* FIXME: In 1.3 this indicates whether the monitor accepts GTF */
234
info->continuous_frequency = get_bit (edid[0x18], 0);
239
decode_fraction (int high, int low)
244
high = (high << 2) | low;
246
for (i = 0; i < 10; ++i)
247
result += get_bit (high, i) * pow (2, i - 10);
253
decode_color_characteristics (const uchar *edid, MonitorInfo *info)
255
info->red_x = decode_fraction (edid[0x1b], get_bits (edid[0x19], 6, 7));
256
info->red_y = decode_fraction (edid[0x1c], get_bits (edid[0x19], 5, 4));
257
info->green_x = decode_fraction (edid[0x1d], get_bits (edid[0x19], 2, 3));
258
info->green_y = decode_fraction (edid[0x1e], get_bits (edid[0x19], 0, 1));
259
info->blue_x = decode_fraction (edid[0x1f], get_bits (edid[0x1a], 6, 7));
260
info->blue_y = decode_fraction (edid[0x20], get_bits (edid[0x1a], 4, 5));
261
info->white_x = decode_fraction (edid[0x21], get_bits (edid[0x1a], 2, 3));
262
info->white_y = decode_fraction (edid[0x22], get_bits (edid[0x1a], 0, 1));
268
decode_established_timings (const uchar *edid, MonitorInfo *info)
270
static const Timing established[][8] =
307
for (i = 0; i < 3; ++i)
309
for (j = 0; j < 8; ++j)
311
int byte = edid[0x23 + i];
313
if (get_bit (byte, j) && established[i][j].frequency != 0)
314
info->established[idx++] = established[i][j];
321
decode_standard_timings (const uchar *edid, MonitorInfo *info)
325
for (i = 0; i < 8; i++)
327
int first = edid[0x26 + 2 * i];
328
int second = edid[0x27 + 2 * i];
330
if (first != 0x01 && second != 0x01)
332
int w = 8 * (first + 31);
335
switch (get_bits (second, 6, 7))
337
case 0x00: h = (w / 16) * 10; break;
338
case 0x01: h = (w / 4) * 3; break;
339
case 0x02: h = (w / 5) * 4; break;
340
case 0x03: h = (w / 16) * 9; break;
343
info->standard[i].width = w;
344
info->standard[i].height = h;
345
info->standard[i].frequency = get_bits (second, 0, 5) + 60;
353
decode_lf_string (const uchar *s, int n_chars, char *result)
356
for (i = 0; i < n_chars; ++i)
363
else if (s[i] == 0x00)
365
/* Convert embedded 0's to spaces */
376
decode_display_descriptor (const uchar *desc,
382
decode_lf_string (desc + 5, 13, info->dsc_product_name);
385
decode_lf_string (desc + 5, 13, info->dsc_serial_number);
388
decode_lf_string (desc + 5, 13, info->dsc_string);
397
/* Timing Identifications */
400
/* Color Management */
406
/* Established Timings */
414
decode_detailed_timing (const uchar *timing,
415
DetailedTiming *detailed)
418
StereoType stereo[] =
420
NO_STEREO, NO_STEREO, FIELD_RIGHT, FIELD_LEFT,
421
TWO_WAY_RIGHT_ON_EVEN, TWO_WAY_LEFT_ON_EVEN,
422
FOUR_WAY_INTERLEAVED, SIDE_BY_SIDE
425
detailed->pixel_clock = (timing[0x00] | timing[0x01] << 8) * 10000;
426
detailed->h_addr = timing[0x02] | ((timing[0x04] & 0xf0) << 4);
427
detailed->h_blank = timing[0x03] | ((timing[0x04] & 0x0f) << 8);
428
detailed->v_addr = timing[0x05] | ((timing[0x07] & 0xf0) << 4);
429
detailed->v_blank = timing[0x06] | ((timing[0x07] & 0x0f) << 8);
430
detailed->h_front_porch = timing[0x08] | get_bits (timing[0x0b], 6, 7) << 8;
431
detailed->h_sync = timing[0x09] | get_bits (timing[0x0b], 4, 5) << 8;
432
detailed->v_front_porch =
433
get_bits (timing[0x0a], 4, 7) | get_bits (timing[0x0b], 2, 3) << 4;
435
get_bits (timing[0x0a], 0, 3) | get_bits (timing[0x0b], 0, 1) << 4;
436
detailed->width_mm = timing[0x0c] | get_bits (timing[0x0e], 4, 7) << 8;
437
detailed->height_mm = timing[0x0d] | get_bits (timing[0x0e], 0, 3) << 8;
438
detailed->right_border = timing[0x0f];
439
detailed->top_border = timing[0x10];
441
detailed->interlaced = get_bit (timing[0x11], 7);
444
bits = get_bits (timing[0x11], 5, 6) << 1 | get_bit (timing[0x11], 0);
445
detailed->stereo = stereo[bits];
450
detailed->digital_sync = get_bit (bits, 4);
451
if (detailed->digital_sync)
453
detailed->connector.digital.composite = !get_bit (bits, 3);
455
if (detailed->connector.digital.composite)
457
detailed->connector.digital.serrations = get_bit (bits, 2);
458
detailed->connector.digital.negative_vsync = FALSE;
462
detailed->connector.digital.serrations = FALSE;
463
detailed->connector.digital.negative_vsync = !get_bit (bits, 2);
466
detailed->connector.digital.negative_hsync = !get_bit (bits, 0);
470
detailed->connector.analog.bipolar = get_bit (bits, 3);
471
detailed->connector.analog.serrations = get_bit (bits, 2);
472
detailed->connector.analog.sync_on_green = !get_bit (bits, 1);
477
decode_descriptors (const uchar *edid, MonitorInfo *info)
484
for (i = 0; i < 4; ++i)
486
int index = 0x36 + i * 18;
488
if (edid[index + 0] == 0x00 && edid[index + 1] == 0x00)
490
decode_display_descriptor (edid + index, info);
494
decode_detailed_timing (
495
edid + index, &(info->detailed_timings[timing_idx++]));
499
info->n_detailed_timings = timing_idx;
505
decode_check_sum (const uchar *edid,
511
for (i = 0; i < 128; ++i)
514
info->checksum = check;
518
decode_edid (const uchar *edid)
520
MonitorInfo *info = g_new0 (MonitorInfo, 1);
522
decode_check_sum (edid, info);
524
if (decode_header (edid)
525
&& decode_vendor_and_product_identification (edid, info)
526
&& decode_edid_version (edid, info)
527
&& decode_display_parameters (edid, info)
528
&& decode_color_characteristics (edid, info)
529
&& decode_established_timings (edid, info)
530
&& decode_standard_timings (edid, info)
531
&& decode_descriptors (edid, info))