edid.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. #ifndef __EDID_H_
  30. #define __EDID_H_
  31. #include <linux/types.h>
  32. #define GET_BIT(_x, _pos) \
  33. (((_x) >> (_pos)) & 1)
  34. #define GET_BITS(_x, _pos_msb, _pos_lsb) \
  35. (((_x) >> (_pos_lsb)) & ((1 << ((_pos_msb) - (_pos_lsb) + 1)) - 1))
  36. /* Aspect ratios used in EDID info. */
  37. enum edid_aspect {
  38. ASPECT_625 = 0,
  39. ASPECT_75,
  40. ASPECT_8,
  41. ASPECT_5625,
  42. };
  43. /* Detailed timing information used in EDID v1.x */
  44. struct edid_detailed_timing {
  45. unsigned char pixel_clock[2];
  46. #define EDID_DETAILED_TIMING_PIXEL_CLOCK(_x) \
  47. (((((uint32_t)(_x).pixel_clock[1]) << 8) + \
  48. (_x).pixel_clock[0]) * 10000)
  49. unsigned char horizontal_active;
  50. unsigned char horizontal_blanking;
  51. unsigned char horizontal_active_blanking_hi;
  52. #define EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(_x) \
  53. ((GET_BITS((_x).horizontal_active_blanking_hi, 7, 4) << 8) + \
  54. (_x).horizontal_active)
  55. #define EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(_x) \
  56. ((GET_BITS((_x).horizontal_active_blanking_hi, 3, 0) << 8) + \
  57. (_x).horizontal_blanking)
  58. unsigned char vertical_active;
  59. unsigned char vertical_blanking;
  60. unsigned char vertical_active_blanking_hi;
  61. #define EDID_DETAILED_TIMING_VERTICAL_ACTIVE(_x) \
  62. ((GET_BITS((_x).vertical_active_blanking_hi, 7, 4) << 8) + \
  63. (_x).vertical_active)
  64. #define EDID_DETAILED_TIMING_VERTICAL_BLANKING(_x) \
  65. ((GET_BITS((_x).vertical_active_blanking_hi, 3, 0) << 8) + \
  66. (_x).vertical_blanking)
  67. unsigned char hsync_offset;
  68. unsigned char hsync_pulse_width;
  69. unsigned char sync_offset_pulse_width;
  70. unsigned char hsync_vsync_offset_pulse_width_hi;
  71. #define EDID_DETAILED_TIMING_HSYNC_OFFSET(_x) \
  72. ((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 7, 6) << 8) + \
  73. (_x).hsync_offset)
  74. #define EDID_DETAILED_TIMING_HSYNC_PULSE_WIDTH(_x) \
  75. ((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 5, 4) << 8) + \
  76. (_x).hsync_pulse_width)
  77. #define EDID_DETAILED_TIMING_VSYNC_OFFSET(_x) \
  78. ((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 3, 2) << 4) + \
  79. GET_BITS((_x).vsync_offset_pulse_width, 7, 4))
  80. #define EDID_DETAILED_TIMING_VSYNC_PULSE_WIDTH(_x) \
  81. ((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 1, 0) << 4) + \
  82. GET_BITS((_x).vsync_offset_pulse_width, 3, 0))
  83. unsigned char himage_size;
  84. unsigned char vimage_size;
  85. unsigned char himage_vimage_size_hi;
  86. #define EDID_DETAILED_TIMING_HIMAGE_SIZE(_x) \
  87. ((GET_BITS((_x).himage_vimage_size_hi, 7, 4) << 8) + (_x).himage_size)
  88. #define EDID_DETAILED_TIMING_VIMAGE_SIZE(_x) \
  89. ((GET_BITS((_x).himage_vimage_size_hi, 3, 0) << 8) + (_x).vimage_size)
  90. unsigned char hborder;
  91. unsigned char vborder;
  92. unsigned char flags;
  93. #define EDID_DETAILED_TIMING_FLAG_INTERLACED(_x) \
  94. GET_BIT((_x).flags, 7)
  95. #define EDID_DETAILED_TIMING_FLAG_STEREO(_x) \
  96. GET_BITS((_x).flags, 6, 5)
  97. #define EDID_DETAILED_TIMING_FLAG_DIGITAL_COMPOSITE(_x) \
  98. GET_BITS((_x).flags, 4, 3)
  99. #define EDID_DETAILED_TIMING_FLAG_POLARITY(_x) \
  100. GET_BITS((_x).flags, 2, 1)
  101. #define EDID_DETAILED_TIMING_FLAG_INTERLEAVED(_x) \
  102. GET_BIT((_x).flags, 0)
  103. } __attribute__ ((__packed__));
  104. enum edid_monitor_descriptor_types {
  105. EDID_MONITOR_DESCRIPTOR_SERIAL = 0xff,
  106. EDID_MONITOR_DESCRIPTOR_ASCII = 0xfe,
  107. EDID_MONITOR_DESCRIPTOR_RANGE = 0xfd,
  108. EDID_MONITOR_DESCRIPTOR_NAME = 0xfc,
  109. };
  110. struct edid_monitor_descriptor {
  111. uint16_t zero_flag_1;
  112. unsigned char zero_flag_2;
  113. unsigned char type;
  114. unsigned char zero_flag_3;
  115. union {
  116. char string[13];
  117. struct {
  118. unsigned char vertical_min;
  119. unsigned char vertical_max;
  120. unsigned char horizontal_min;
  121. unsigned char horizontal_max;
  122. unsigned char pixel_clock_max;
  123. unsigned char gtf_data[8];
  124. } range_data;
  125. } data;
  126. } __attribute__ ((__packed__));
  127. struct edid1_info {
  128. unsigned char header[8];
  129. unsigned char manufacturer_name[2];
  130. #define EDID1_INFO_MANUFACTURER_NAME_ZERO(_x) \
  131. GET_BIT(((_x).manufacturer_name[0]), 7)
  132. #define EDID1_INFO_MANUFACTURER_NAME_CHAR1(_x) \
  133. GET_BITS(((_x).manufacturer_name[0]), 6, 2)
  134. #define EDID1_INFO_MANUFACTURER_NAME_CHAR2(_x) \
  135. ((GET_BITS(((_x).manufacturer_name[0]), 1, 0) << 3) + \
  136. GET_BITS(((_x).manufacturer_name[1]), 7, 5))
  137. #define EDID1_INFO_MANUFACTURER_NAME_CHAR3(_x) \
  138. GET_BITS(((_x).manufacturer_name[1]), 4, 0)
  139. unsigned char product_code[2];
  140. #define EDID1_INFO_PRODUCT_CODE(_x) \
  141. (((uint16_t)(_x).product_code[1] << 8) + (_x).product_code[0])
  142. unsigned char serial_number[4];
  143. #define EDID1_INFO_SERIAL_NUMBER(_x) \
  144. (((uint32_t)(_x).serial_number[3] << 24) + \
  145. ((_x).serial_number[2] << 16) + ((_x).serial_number[1] << 8) + \
  146. (_x).serial_number[0])
  147. unsigned char week;
  148. unsigned char year;
  149. unsigned char version;
  150. unsigned char revision;
  151. unsigned char video_input_definition;
  152. #define EDID1_INFO_VIDEO_INPUT_DIGITAL(_x) \
  153. GET_BIT(((_x).video_input_definition), 7)
  154. #define EDID1_INFO_VIDEO_INPUT_VOLTAGE_LEVEL(_x) \
  155. GET_BITS(((_x).video_input_definition), 6, 5)
  156. #define EDID1_INFO_VIDEO_INPUT_BLANK_TO_BLACK(_x) \
  157. GET_BIT(((_x).video_input_definition), 4)
  158. #define EDID1_INFO_VIDEO_INPUT_SEPARATE_SYNC(_x) \
  159. GET_BIT(((_x).video_input_definition), 3)
  160. #define EDID1_INFO_VIDEO_INPUT_COMPOSITE_SYNC(_x) \
  161. GET_BIT(((_x).video_input_definition), 2)
  162. #define EDID1_INFO_VIDEO_INPUT_SYNC_ON_GREEN(_x) \
  163. GET_BIT(((_x).video_input_definition), 1)
  164. #define EDID1_INFO_VIDEO_INPUT_SERRATION_V(_x) \
  165. GET_BIT(((_x).video_input_definition), 0)
  166. unsigned char max_size_horizontal;
  167. unsigned char max_size_vertical;
  168. unsigned char gamma;
  169. unsigned char feature_support;
  170. #define EDID1_INFO_FEATURE_STANDBY(_x) \
  171. GET_BIT(((_x).feature_support), 7)
  172. #define EDID1_INFO_FEATURE_SUSPEND(_x) \
  173. GET_BIT(((_x).feature_support), 6)
  174. #define EDID1_INFO_FEATURE_ACTIVE_OFF(_x) \
  175. GET_BIT(((_x).feature_support), 5)
  176. #define EDID1_INFO_FEATURE_DISPLAY_TYPE(_x) \
  177. GET_BITS(((_x).feature_support), 4, 3)
  178. #define EDID1_INFO_FEATURE_RGB(_x) \
  179. GET_BIT(((_x).feature_support), 2)
  180. #define EDID1_INFO_FEATURE_PREFERRED_TIMING_MODE(_x) \
  181. GET_BIT(((_x).feature_support), 1)
  182. #define EDID1_INFO_FEATURE_DEFAULT_GTF_SUPPORT(_x) \
  183. GET_BIT(((_x).feature_support), 0)
  184. unsigned char color_characteristics[10];
  185. unsigned char established_timings[3];
  186. #define EDID1_INFO_ESTABLISHED_TIMING_720X400_70(_x) \
  187. GET_BIT(((_x).established_timings[0]), 7)
  188. #define EDID1_INFO_ESTABLISHED_TIMING_720X400_88(_x) \
  189. GET_BIT(((_x).established_timings[0]), 6)
  190. #define EDID1_INFO_ESTABLISHED_TIMING_640X480_60(_x) \
  191. GET_BIT(((_x).established_timings[0]), 5)
  192. #define EDID1_INFO_ESTABLISHED_TIMING_640X480_67(_x) \
  193. GET_BIT(((_x).established_timings[0]), 4)
  194. #define EDID1_INFO_ESTABLISHED_TIMING_640X480_72(_x) \
  195. GET_BIT(((_x).established_timings[0]), 3)
  196. #define EDID1_INFO_ESTABLISHED_TIMING_640X480_75(_x) \
  197. GET_BIT(((_x).established_timings[0]), 2)
  198. #define EDID1_INFO_ESTABLISHED_TIMING_800X600_56(_x) \
  199. GET_BIT(((_x).established_timings[0]), 1)
  200. #define EDID1_INFO_ESTABLISHED_TIMING_800X600_60(_x) \
  201. GET_BIT(((_x).established_timings[0]), 0)
  202. #define EDID1_INFO_ESTABLISHED_TIMING_800X600_72(_x) \
  203. GET_BIT(((_x).established_timings[1]), 7)
  204. #define EDID1_INFO_ESTABLISHED_TIMING_800X600_75(_x) \
  205. GET_BIT(((_x).established_timings[1]), 6)
  206. #define EDID1_INFO_ESTABLISHED_TIMING_832X624_75(_x) \
  207. GET_BIT(((_x).established_timings[1]), 5)
  208. #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_87I(_x) \
  209. GET_BIT(((_x).established_timings[1]), 4)
  210. #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_60(_x) \
  211. GET_BIT(((_x).established_timings[1]), 3)
  212. #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_70(_x) \
  213. GET_BIT(((_x).established_timings[1]), 2)
  214. #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_75(_x) \
  215. GET_BIT(((_x).established_timings[1]), 1)
  216. #define EDID1_INFO_ESTABLISHED_TIMING_1280X1024_75(_x) \
  217. GET_BIT(((_x).established_timings[1]), 0)
  218. #define EDID1_INFO_ESTABLISHED_TIMING_1152X870_75(_x) \
  219. GET_BIT(((_x).established_timings[2]), 7)
  220. struct {
  221. unsigned char xresolution;
  222. unsigned char aspect_vfreq;
  223. } __attribute__((__packed__)) standard_timings[8];
  224. #define EDID1_INFO_STANDARD_TIMING_XRESOLUTION(_x, _i) \
  225. (((_x).standard_timings[_i]).xresolution)
  226. #define EDID1_INFO_STANDARD_TIMING_ASPECT(_x, _i) \
  227. GET_BITS(((_x).standard_timings[_i].aspect_vfreq), 7, 6)
  228. #define EDID1_INFO_STANDARD_TIMING_VFREQ(_x, _i) \
  229. GET_BITS(((_x).standard_timings[_i].aspect_vfreq), 5, 0)
  230. union {
  231. unsigned char timing[72];
  232. struct edid_monitor_descriptor descriptor[4];
  233. } monitor_details;
  234. unsigned char extension_flag;
  235. unsigned char checksum;
  236. } __attribute__ ((__packed__));
  237. /**
  238. * Print the EDID info.
  239. *
  240. * @param edid_info The EDID info to be printed
  241. */
  242. void edid_print_info(struct edid1_info *edid_info);
  243. /**
  244. * Check the EDID info.
  245. *
  246. * @param info The EDID info to be checked
  247. * @return 0 on valid, or -1 on invalid
  248. */
  249. int edid_check_info(struct edid1_info *info);
  250. /**
  251. * Get the horizontal and vertical rate ranges of the monitor.
  252. *
  253. * @param edid The EDID info
  254. * @param hmin Returns the minimum horizontal rate
  255. * @param hmax Returns the maxium horizontal rate
  256. * @param vmin Returns the minimum vertical rate
  257. * @param vmax Returns the maxium vertical rate
  258. * @return 0 on success, or -1 on error
  259. */
  260. int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
  261. unsigned int *hmax, unsigned int *vmin,
  262. unsigned int *vmax);
  263. #endif /* __EDID_H_ */