edid.h 11 KB

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