edid.h 12 KB

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