Tom Wai-Hong Tam | baebbf5 | 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 | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Tom Wai-Hong Tam | baebbf5 | 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 | baebbf5 | 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 | 86842e3 | 2013-08-07 09:22:33 +0200 | [diff] [blame] | 57 | unsigned char vsync_offset_pulse_width; |
Tom Wai-Hong Tam | baebbf5 | 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) |
| 89 | #define EDID_DETAILED_TIMING_FLAG_INTERLEAVED(_x) \ |
| 90 | GET_BIT((_x).flags, 0) |
| 91 | } __attribute__ ((__packed__)); |
| 92 | |
| 93 | enum edid_monitor_descriptor_types { |
| 94 | EDID_MONITOR_DESCRIPTOR_SERIAL = 0xff, |
| 95 | EDID_MONITOR_DESCRIPTOR_ASCII = 0xfe, |
| 96 | EDID_MONITOR_DESCRIPTOR_RANGE = 0xfd, |
| 97 | EDID_MONITOR_DESCRIPTOR_NAME = 0xfc, |
| 98 | }; |
| 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 | |
| 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 | |
| 229 | /** |
| 230 | * Print the EDID info. |
| 231 | * |
| 232 | * @param edid_info The EDID info to be printed |
| 233 | */ |
| 234 | void edid_print_info(struct edid1_info *edid_info); |
| 235 | |
| 236 | /** |
| 237 | * Check the EDID info. |
| 238 | * |
| 239 | * @param info The EDID info to be checked |
| 240 | * @return 0 on valid, or -1 on invalid |
| 241 | */ |
| 242 | int edid_check_info(struct edid1_info *info); |
| 243 | |
| 244 | /** |
| 245 | * Get the horizontal and vertical rate ranges of the monitor. |
| 246 | * |
| 247 | * @param edid The EDID info |
| 248 | * @param hmin Returns the minimum horizontal rate |
| 249 | * @param hmax Returns the maxium horizontal rate |
| 250 | * @param vmin Returns the minimum vertical rate |
| 251 | * @param vmax Returns the maxium vertical rate |
| 252 | * @return 0 on success, or -1 on error |
| 253 | */ |
| 254 | int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin, |
| 255 | unsigned int *hmax, unsigned int *vmin, |
| 256 | unsigned int *vmax); |
| 257 | |
| 258 | #endif /* __EDID_H_ */ |