2 * Copyright (c) 2012 The Chromium OS Authors.
5 * Petr Stetiar <ynezz@true.cz>
7 * SPDX-License-Identifier: GPL-2.0+
9 * Contains stolen code from ddcprobe project which is:
10 * Copyright (C) Nalin Dahyabhai <bigfun@pobox.com>
16 #include <linux/ctype.h>
17 #include <linux/string.h>
19 int edid_check_info(struct edid1_info *edid_info)
21 if ((edid_info == NULL) || (edid_info->version == 0))
24 if (memcmp(edid_info->header, "\x0\xff\xff\xff\xff\xff\xff\x0", 8))
27 if (edid_info->version == 0xff && edid_info->revision == 0xff)
33 int edid_check_checksum(u8 *edid_block)
38 for (i = 0; i < 128; i++)
39 checksum += edid_block[i];
41 return (checksum == 0) ? 0 : -EINVAL;
44 int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
45 unsigned int *hmax, unsigned int *vmin,
49 struct edid_monitor_descriptor *monitor;
51 *hmin = *hmax = *vmin = *vmax = 0;
52 if (edid_check_info(edid))
55 for (i = 0; i < ARRAY_SIZE(edid->monitor_details.descriptor); i++) {
56 monitor = &edid->monitor_details.descriptor[i];
57 if (monitor->type == EDID_MONITOR_DESCRIPTOR_RANGE) {
58 *hmin = monitor->data.range_data.horizontal_min;
59 *hmax = monitor->data.range_data.horizontal_max;
60 *vmin = monitor->data.range_data.vertical_min;
61 *vmax = monitor->data.range_data.vertical_max;
69 * Snip the tailing whitespace/return of a string.
71 * @param string The string to be snipped
72 * @return the snipped string
74 static char *snip(char *string)
79 * This is always a 13 character buffer
80 * and it's not always terminated.
83 s = &string[strlen(string) - 1];
85 while (s >= string && (isspace(*s) || *s == '\n' || *s == '\r' ||
93 * Print an EDID monitor descriptor block
95 * @param monitor The EDID monitor descriptor block
96 * @have_timing Modifies to 1 if the desciptor contains timing info
98 static void edid_print_dtd(struct edid_monitor_descriptor *monitor,
99 unsigned int *have_timing)
101 unsigned char *bytes = (unsigned char *)monitor;
102 struct edid_detailed_timing *timing =
103 (struct edid_detailed_timing *)monitor;
105 if (bytes[0] == 0 && bytes[1] == 0) {
106 if (monitor->type == EDID_MONITOR_DESCRIPTOR_SERIAL)
107 printf("Monitor serial number: %s\n",
108 snip(monitor->data.string));
109 else if (monitor->type == EDID_MONITOR_DESCRIPTOR_ASCII)
110 printf("Monitor ID: %s\n",
111 snip(monitor->data.string));
112 else if (monitor->type == EDID_MONITOR_DESCRIPTOR_NAME)
113 printf("Monitor name: %s\n",
114 snip(monitor->data.string));
115 else if (monitor->type == EDID_MONITOR_DESCRIPTOR_RANGE)
116 printf("Monitor range limits, horizontal sync: "
117 "%d-%d kHz, vertical refresh: "
118 "%d-%d Hz, max pixel clock: "
120 monitor->data.range_data.horizontal_min,
121 monitor->data.range_data.horizontal_max,
122 monitor->data.range_data.vertical_min,
123 monitor->data.range_data.vertical_max,
124 monitor->data.range_data.pixel_clock_max * 10);
126 uint32_t pixclock, h_active, h_blanking, v_active, v_blanking;
127 uint32_t h_total, v_total, vfreq;
129 pixclock = EDID_DETAILED_TIMING_PIXEL_CLOCK(*timing);
130 h_active = EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(*timing);
131 h_blanking = EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(*timing);
132 v_active = EDID_DETAILED_TIMING_VERTICAL_ACTIVE(*timing);
133 v_blanking = EDID_DETAILED_TIMING_VERTICAL_BLANKING(*timing);
135 h_total = h_active + h_blanking;
136 v_total = v_active + v_blanking;
137 if (v_total * h_total)
138 vfreq = pixclock / (v_total * h_total);
140 vfreq = 1; /* Error case */
141 printf("\t%dx%d\%c\t%d Hz (detailed)\n", h_active,
142 v_active, h_active > 1000 ? ' ' : '\t', vfreq);
148 * Get the manufacturer name from an EDID info.
150 * @param edid_info The EDID info to be printed
151 * @param name Returns the string of the manufacturer name
153 static void edid_get_manufacturer_name(struct edid1_info *edid, char *name)
155 name[0] = EDID1_INFO_MANUFACTURER_NAME_CHAR1(*edid) + 'A' - 1;
156 name[1] = EDID1_INFO_MANUFACTURER_NAME_CHAR2(*edid) + 'A' - 1;
157 name[2] = EDID1_INFO_MANUFACTURER_NAME_CHAR3(*edid) + 'A' - 1;
161 void edid_print_info(struct edid1_info *edid_info)
164 char manufacturer[4];
165 unsigned int have_timing = 0;
166 uint32_t serial_number;
168 if (edid_check_info(edid_info)) {
169 printf("Not a valid EDID\n");
173 printf("EDID version: %d.%d\n",
174 edid_info->version, edid_info->revision);
176 printf("Product ID code: %04x\n", EDID1_INFO_PRODUCT_CODE(*edid_info));
178 edid_get_manufacturer_name(edid_info, manufacturer);
179 printf("Manufacturer: %s\n", manufacturer);
181 serial_number = EDID1_INFO_SERIAL_NUMBER(*edid_info);
182 if (serial_number != 0xffffffff) {
183 if (strcmp(manufacturer, "MAG") == 0)
184 serial_number -= 0x7000000;
185 if (strcmp(manufacturer, "OQI") == 0)
186 serial_number -= 456150000;
187 if (strcmp(manufacturer, "VSC") == 0)
188 serial_number -= 640000000;
190 printf("Serial number: %08x\n", serial_number);
191 printf("Manufactured in week: %d year: %d\n",
192 edid_info->week, edid_info->year + 1990);
194 printf("Video input definition: %svoltage level %d%s%s%s%s%s\n",
195 EDID1_INFO_VIDEO_INPUT_DIGITAL(*edid_info) ?
196 "digital signal, " : "analog signal, ",
197 EDID1_INFO_VIDEO_INPUT_VOLTAGE_LEVEL(*edid_info),
198 EDID1_INFO_VIDEO_INPUT_BLANK_TO_BLACK(*edid_info) ?
199 ", blank to black" : "",
200 EDID1_INFO_VIDEO_INPUT_SEPARATE_SYNC(*edid_info) ?
201 ", separate sync" : "",
202 EDID1_INFO_VIDEO_INPUT_COMPOSITE_SYNC(*edid_info) ?
203 ", composite sync" : "",
204 EDID1_INFO_VIDEO_INPUT_SYNC_ON_GREEN(*edid_info) ?
205 ", sync on green" : "",
206 EDID1_INFO_VIDEO_INPUT_SERRATION_V(*edid_info) ?
207 ", serration v" : "");
209 printf("Monitor is %s\n",
210 EDID1_INFO_FEATURE_RGB(*edid_info) ? "RGB" : "non-RGB");
212 printf("Maximum visible display size: %d cm x %d cm\n",
213 edid_info->max_size_horizontal,
214 edid_info->max_size_vertical);
216 printf("Power management features: %s%s, %s%s, %s%s\n",
217 EDID1_INFO_FEATURE_ACTIVE_OFF(*edid_info) ?
218 "" : "no ", "active off",
219 EDID1_INFO_FEATURE_SUSPEND(*edid_info) ? "" : "no ", "suspend",
220 EDID1_INFO_FEATURE_STANDBY(*edid_info) ? "" : "no ", "standby");
222 printf("Estabilished timings:\n");
223 if (EDID1_INFO_ESTABLISHED_TIMING_720X400_70(*edid_info))
224 printf("\t720x400\t\t70 Hz (VGA 640x400, IBM)\n");
225 if (EDID1_INFO_ESTABLISHED_TIMING_720X400_88(*edid_info))
226 printf("\t720x400\t\t88 Hz (XGA2)\n");
227 if (EDID1_INFO_ESTABLISHED_TIMING_640X480_60(*edid_info))
228 printf("\t640x480\t\t60 Hz (VGA)\n");
229 if (EDID1_INFO_ESTABLISHED_TIMING_640X480_67(*edid_info))
230 printf("\t640x480\t\t67 Hz (Mac II, Apple)\n");
231 if (EDID1_INFO_ESTABLISHED_TIMING_640X480_72(*edid_info))
232 printf("\t640x480\t\t72 Hz (VESA)\n");
233 if (EDID1_INFO_ESTABLISHED_TIMING_640X480_75(*edid_info))
234 printf("\t640x480\t\t75 Hz (VESA)\n");
235 if (EDID1_INFO_ESTABLISHED_TIMING_800X600_56(*edid_info))
236 printf("\t800x600\t\t56 Hz (VESA)\n");
237 if (EDID1_INFO_ESTABLISHED_TIMING_800X600_60(*edid_info))
238 printf("\t800x600\t\t60 Hz (VESA)\n");
239 if (EDID1_INFO_ESTABLISHED_TIMING_800X600_72(*edid_info))
240 printf("\t800x600\t\t72 Hz (VESA)\n");
241 if (EDID1_INFO_ESTABLISHED_TIMING_800X600_75(*edid_info))
242 printf("\t800x600\t\t75 Hz (VESA)\n");
243 if (EDID1_INFO_ESTABLISHED_TIMING_832X624_75(*edid_info))
244 printf("\t832x624\t\t75 Hz (Mac II)\n");
245 if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_87I(*edid_info))
246 printf("\t1024x768\t87 Hz Interlaced (8514A)\n");
247 if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_60(*edid_info))
248 printf("\t1024x768\t60 Hz (VESA)\n");
249 if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_70(*edid_info))
250 printf("\t1024x768\t70 Hz (VESA)\n");
251 if (EDID1_INFO_ESTABLISHED_TIMING_1024X768_75(*edid_info))
252 printf("\t1024x768\t75 Hz (VESA)\n");
253 if (EDID1_INFO_ESTABLISHED_TIMING_1280X1024_75(*edid_info))
254 printf("\t1280x1024\t75 (VESA)\n");
255 if (EDID1_INFO_ESTABLISHED_TIMING_1152X870_75(*edid_info))
256 printf("\t1152x870\t75 (Mac II)\n");
258 /* Standard timings. */
259 printf("Standard timings:\n");
260 for (i = 0; i < ARRAY_SIZE(edid_info->standard_timings); i++) {
261 unsigned int aspect = 10000;
263 unsigned char xres, vfreq;
265 xres = EDID1_INFO_STANDARD_TIMING_XRESOLUTION(*edid_info, i);
266 vfreq = EDID1_INFO_STANDARD_TIMING_VFREQ(*edid_info, i);
267 if ((xres != vfreq) ||
268 ((xres != 0) && (xres != 1)) ||
269 ((vfreq != 0) && (vfreq != 1))) {
270 switch (EDID1_INFO_STANDARD_TIMING_ASPECT(*edid_info,
286 y = x * aspect / 10000;
287 printf("\t%dx%d%c\t%d Hz\n", x, y,
288 x > 1000 ? ' ' : '\t', (vfreq & 0x3f) + 60);
293 /* Detailed timing information. */
294 for (i = 0; i < ARRAY_SIZE(edid_info->monitor_details.descriptor);
296 edid_print_dtd(&edid_info->monitor_details.descriptor[i],