edid.h 9.2 KB

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