edid.c 9.8 KB

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