edid.c
9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Copyright (c) 2012 The Chromium OS Authors.
*
* (C) Copyright 2010
* Petr Stetiar <ynezz@true.cz>
*
* SPDX-License-Identifier: GPL-2.0+
*
* Contains stolen code from ddcprobe project which is:
* Copyright (C) Nalin Dahyabhai <bigfun@pobox.com>
*/
#include <common.h>
#include <edid.h>
#include <errno.h>
#include <linux/ctype.h>
#include <linux/string.h>
int edid_check_info(struct edid1_info *edid_info)
{
if ((edid_info == NULL) || (edid_info->version == 0))
return -1;
if (memcmp(edid_info->header, "\x0\xff\xff\xff\xff\xff\xff\x0", 8))
return -1;
if (edid_info->version == 0xff && edid_info->revision == 0xff)
return -1;
return 0;
}
int edid_check_checksum(u8 *edid_block)
{
u8 checksum = 0;
int i;
for (i = 0; i < 128; i++)
checksum += edid_block[i];
return (checksum == 0) ? 0 : -EINVAL;
}
int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
unsigned int *hmax, unsigned int *vmin,
unsigned int *vmax)
{
int i;
struct edid_monitor_descriptor *monitor;
*hmin = *hmax = *vmin = *vmax = 0;
if (edid_check_info(edid))
return -1;
for (i = 0; i < ARRAY_SIZE(edid->monitor_details.descriptor); i++) {
monitor = &edid->monitor_details.descriptor[i];
if (monitor->type == EDID_MONITOR_DESCRIPTOR_RANGE) {
*hmin = monitor->data.range_data.horizontal_min;
*hmax = monitor->data.range_data.horizontal_max;
*vmin = monitor->data.range_data.vertical_min;
*vmax = monitor->data.range_data.vertical_max;
return 0;
}
}
return -1;
}
/**
* Snip the tailing whitespace/return of a string.
*
* @param string The string to be snipped
* @return the snipped string
*/
static char *snip(char *string)
{
char *s;
/*
* This is always a 13 character buffer
* and it's not always terminated.
*/
string[12] = '\0';
s = &string[strlen(string) - 1];
while (s >= string && (isspace(*s) || *s == '\n' || *s == '\r' ||
*s == '\0'))
*(s--) = '\0';
return string;
}
/**
* Print an EDID monitor descriptor block
*
* @param monitor The EDID monitor descriptor block
* @have_timing Modifies to 1 if the desciptor contains timing info
*/
static void edid_print_dtd(struct edid_monitor_descriptor *monitor,
unsigned int *have_timing)
{
unsigned char *bytes = (unsigned char *)monitor;
struct edid_detailed_timing *timing =
(struct edid_detailed_timing *)monitor;
if (bytes[0] == 0 && bytes[1] == 0) {
if (monitor->type == EDID_MONITOR_DESCRIPTOR_SERIAL)
printf("Monitor serial number: %s\n",
snip(monitor->data.string));
else if (monitor->type == EDID_MONITOR_DESCRIPTOR_ASCII)
printf("Monitor ID: %s\n",
snip(monitor->data.string));
else if (monitor->type == EDID_MONITOR_DESCRIPTOR_NAME)
printf("Monitor name: %s\n",
snip(monitor->data.string));
else if (monitor->type == EDID_MONITOR_DESCRIPTOR_RANGE)
printf("Monitor range limits, horizontal sync: "
"%d-%d kHz, vertical refresh: "
"%d-%d Hz, max pixel clock: "
"%d MHz\n",
monitor->data.range_data.horizontal_min,
monitor->data.range_data.horizontal_max,
monitor->data.range_data.vertical_min,
monitor->data.range_data.vertical_max,
monitor->data.range_data.pixel_clock_max * 10);
} else {
uint32_t pixclock, h_active, h_blanking, v_active, v_blanking;
uint32_t h_total, v_total, vfreq;
pixclock = EDID_DETAILED_TIMING_PIXEL_CLOCK(*timing);
h_active = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*timing);
h_blanking = EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*timing);
v_active = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*timing);
v_blanking = EDID_DETAILED_TIMING_VERTICAL_BLANKING(*timing);
h_total = h_active + h_blanking;
v_total = v_active + v_blanking;
if (v_total * h_total)
vfreq = pixclock / (v_total * h_total);
else
vfreq = 1; /* Error case */
printf("\t%dx%d\%c\t%d Hz (detailed)\n", h_active,
v_active, h_active > 1000 ? ' ' : '\t', vfreq);
*have_timing = 1;
}
}
/**
* Get the manufacturer name from an EDID info.
*
* @param edid_info The EDID info to be printed
* @param name Returns the string of the manufacturer name
*/
static void edid_get_manufacturer_name(struct edid1_info *edid, char *name)
{
name[0] = EDID1_INFO_MANUFACTURER_NAME_CHAR1(*edid) + 'A' - 1;
name[1] = EDID1_INFO_MANUFACTURER_NAME_CHAR2(*edid) + 'A' - 1;
name[2] = EDID1_INFO_MANUFACTURER_NAME_CHAR3(*edid) + 'A' - 1;
name[3] = '\0';
}
void edid_print_info(struct edid1_info *edid_info)
{
int i;
char manufacturer[4];
unsigned int have_timing = 0;
uint32_t serial_number;
if (edid_check_info(edid_info)) {
printf("Not a valid EDID\n");
return;
}
printf("EDID version: %d.%d\n",
edid_info->version, edid_info->revision);
printf("Product ID code: %04x\n", EDID1_INFO_PRODUCT_CODE(*edid_info));
edid_get_manufacturer_name(edid_info, manufacturer);
printf("Manufacturer: %s\n", manufacturer);
serial_number = EDID1_INFO_SERIAL_NUMBER(*edid_info);
if (serial_number != 0xffffffff) {
if (strcmp(manufacturer, "MAG") == 0)
serial_number -= 0x7000000;
if (strcmp(manufacturer, "OQI") == 0)
serial_number -= 456150000;
if (strcmp(manufacturer, "VSC") == 0)
serial_number -= 640000000;
}
printf("Serial number: %08x\n", serial_number);
printf("Manufactured in week: %d year: %d\n",
edid_info->week, edid_info->year + 1990);
printf("Video input definition: %svoltage level %d%s%s%s%s%s\n",
EDID1_INFO_VIDEO_INPUT_DIGITAL(*edid_info) ?
"digital signal, " : "analog signal, ",
EDID1_INFO_VIDEO_INPUT_VOLTAGE_LEVEL(*edid_info),
EDID1_INFO_VIDEO_INPUT_BLANK_TO_BLACK(*edid_info) ?
", blank to black" : "",
EDID1_INFO_VIDEO_INPUT_SEPARATE_SYNC(*edid_info) ?
", separate sync" : "",
EDID1_INFO_VIDEO_INPUT_COMPOSITE_SYNC(*edid_info) ?
", composite sync" : "",
EDID1_INFO_VIDEO_INPUT_SYNC_ON_GREEN(*edid_info) ?
", sync on green" : "",
EDID1_INFO_VIDEO_INPUT_SERRATION_V(*edid_info) ?
", serration v" : "");
printf("Monitor is %s\n",
EDID1_INFO_FEATURE_RGB(*edid_info) ? "RGB" : "non-RGB");
printf("Maximum visible display size: %d cm x %d cm\n",
edid_info->max_size_horizontal,
edid_info->max_size_vertical);
printf("Power management features: %s%s, %s%s, %s%s\n",
EDID1_INFO_FEATURE_ACTIVE_OFF(*edid_info) ?
"" : "no ", "active off",
EDID1_INFO_FEATURE_SUSPEND(*edid_info) ? "" : "no ", "suspend",
EDID1_INFO_FEATURE_STANDBY(*edid_info) ? "" : "no ", "standby");
printf("Estabilished timings:\n");
if (EDID1_INFO_ESTABLISHED_TIMING_720X400_70(*edid_info))
printf("\t720x400\t\t70 Hz (VGA 640x400, IBM)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_720X400_88(*edid_info))
printf("\t720x400\t\t88 Hz (XGA2)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_640X480_60(*edid_info))
printf("\t640x480\t\t60 Hz (VGA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_640X480_67(*edid_info))
printf("\t640x480\t\t67 Hz (Mac II, Apple)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_640X480_72(*edid_info))
printf("\t640x480\t\t72 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_640X480_75(*edid_info))
printf("\t640x480\t\t75 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_800X600_56(*edid_info))
printf("\t800x600\t\t56 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_800X600_60(*edid_info))
printf("\t800x600\t\t60 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_800X600_72(*edid_info))
printf("\t800x600\t\t72 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_800X600_75(*edid_info))
printf("\t800x600\t\t75 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_832X624_75(*edid_info))
printf("\t832x624\t\t75 Hz (Mac II)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_87I(*edid_info))
printf("\t1024x768\t87 Hz Interlaced (8514A)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_60(*edid_info))
printf("\t1024x768\t60 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_70(*edid_info))
printf("\t1024x768\t70 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_75(*edid_info))
printf("\t1024x768\t75 Hz (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1280X1024_75(*edid_info))
printf("\t1280x1024\t75 (VESA)\n");
if (EDID1_INFO_ESTABLISHED_TIMING_1152X870_75(*edid_info))
printf("\t1152x870\t75 (Mac II)\n");
/* Standard timings. */
printf("Standard timings:\n");
for (i = 0; i < ARRAY_SIZE(edid_info->standard_timings); i++) {
unsigned int aspect = 10000;
unsigned int x, y;
unsigned char xres, vfreq;
xres = EDID1_INFO_STANDARD_TIMING_XRESOLUTION(*edid_info, i);
vfreq = EDID1_INFO_STANDARD_TIMING_VFREQ(*edid_info, i);
if ((xres != vfreq) ||
((xres != 0) && (xres != 1)) ||
((vfreq != 0) && (vfreq != 1))) {
switch (EDID1_INFO_STANDARD_TIMING_ASPECT(*edid_info,
i)) {
case ASPECT_625:
aspect = 6250;
break;
case ASPECT_75:
aspect = 7500;
break;
case ASPECT_8:
aspect = 8000;
break;
case ASPECT_5625:
aspect = 5625;
break;
}
x = (xres + 31) * 8;
y = x * aspect / 10000;
printf("\t%dx%d%c\t%d Hz\n", x, y,
x > 1000 ? ' ' : '\t', (vfreq & 0x3f) + 60);
have_timing = 1;
}
}
/* Detailed timing information. */
for (i = 0; i < ARRAY_SIZE(edid_info->monitor_details.descriptor);
i++) {
edid_print_dtd(&edid_info->monitor_details.descriptor[i],
&have_timing);
}
if (!have_timing)
printf("\tNone\n");
}