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