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