xref: /openbmc/u-boot/include/edid.h (revision 301e8038)
1 /*
2  * Copyright (c) 2012 The Chromium OS Authors.
3  *
4  * (C) Copyright 2010
5  * Petr Stetiar <ynezz@true.cz>
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  *
25  * Contains stolen code from ddcprobe project which is:
26  * Copyright (C) Nalin Dahyabhai <bigfun@pobox.com>
27  *
28  */
29 
30 #ifndef __EDID_H_
31 #define __EDID_H_
32 
33 #include <linux/types.h>
34 
35 #define GET_BIT(_x, _pos) \
36 	(((_x) >> (_pos)) & 1)
37 #define GET_BITS(_x, _pos_msb, _pos_lsb) \
38 	(((_x) >> (_pos_lsb)) & ((1 << ((_pos_msb) - (_pos_lsb) + 1)) - 1))
39 
40 /* Aspect ratios used in EDID info. */
41 enum edid_aspect {
42 	ASPECT_625 = 0,
43 	ASPECT_75,
44 	ASPECT_8,
45 	ASPECT_5625,
46 };
47 
48 /* Detailed timing information used in EDID v1.x */
49 struct edid_detailed_timing {
50 	unsigned char pixel_clock[2];
51 #define EDID_DETAILED_TIMING_PIXEL_CLOCK(_x) \
52 	(((((uint32_t)(_x).pixel_clock[1]) << 8) + \
53 	 (_x).pixel_clock[0]) * 10000)
54 	unsigned char horizontal_active;
55 	unsigned char horizontal_blanking;
56 	unsigned char horizontal_active_blanking_hi;
57 #define EDID_DETAILED_TIMING_HORIZONTAL_ACTIVE(_x) \
58 	((GET_BITS((_x).horizontal_active_blanking_hi, 7, 4) << 8) + \
59 	 (_x).horizontal_active)
60 #define EDID_DETAILED_TIMING_HORIZONTAL_BLANKING(_x) \
61 	((GET_BITS((_x).horizontal_active_blanking_hi, 3, 0) << 8) + \
62 	 (_x).horizontal_blanking)
63 	unsigned char vertical_active;
64 	unsigned char vertical_blanking;
65 	unsigned char vertical_active_blanking_hi;
66 #define EDID_DETAILED_TIMING_VERTICAL_ACTIVE(_x) \
67 	((GET_BITS((_x).vertical_active_blanking_hi, 7, 4) << 8) + \
68 	 (_x).vertical_active)
69 #define EDID_DETAILED_TIMING_VERTICAL_BLANKING(_x) \
70 	((GET_BITS((_x).vertical_active_blanking_hi, 3, 0) << 8) + \
71 	 (_x).vertical_blanking)
72 	unsigned char hsync_offset;
73 	unsigned char hsync_pulse_width;
74 	unsigned char sync_offset_pulse_width;
75 	unsigned char hsync_vsync_offset_pulse_width_hi;
76 #define EDID_DETAILED_TIMING_HSYNC_OFFSET(_x) \
77 	((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 7, 6) << 8) + \
78 	 (_x).hsync_offset)
79 #define EDID_DETAILED_TIMING_HSYNC_PULSE_WIDTH(_x) \
80 	((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 5, 4) << 8) + \
81 	 (_x).hsync_pulse_width)
82 #define EDID_DETAILED_TIMING_VSYNC_OFFSET(_x) \
83 	((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 3, 2) << 4) + \
84 	 GET_BITS((_x).vsync_offset_pulse_width, 7, 4))
85 #define EDID_DETAILED_TIMING_VSYNC_PULSE_WIDTH(_x) \
86 	((GET_BITS((_x).hsync_vsync_offset_pulse_width_hi, 1, 0) << 4) + \
87 	 GET_BITS((_x).vsync_offset_pulse_width, 3, 0))
88 	unsigned char himage_size;
89 	unsigned char vimage_size;
90 	unsigned char himage_vimage_size_hi;
91 #define EDID_DETAILED_TIMING_HIMAGE_SIZE(_x) \
92 	((GET_BITS((_x).himage_vimage_size_hi, 7, 4) << 8) + (_x).himage_size)
93 #define EDID_DETAILED_TIMING_VIMAGE_SIZE(_x) \
94 	((GET_BITS((_x).himage_vimage_size_hi, 3, 0) << 8) + (_x).vimage_size)
95 	unsigned char hborder;
96 	unsigned char vborder;
97 	unsigned char flags;
98 #define EDID_DETAILED_TIMING_FLAG_INTERLACED(_x) \
99 	GET_BIT((_x).flags, 7)
100 #define EDID_DETAILED_TIMING_FLAG_STEREO(_x) \
101 	GET_BITS((_x).flags, 6, 5)
102 #define EDID_DETAILED_TIMING_FLAG_DIGITAL_COMPOSITE(_x) \
103 	GET_BITS((_x).flags, 4, 3)
104 #define EDID_DETAILED_TIMING_FLAG_POLARITY(_x) \
105 	GET_BITS((_x).flags, 2, 1)
106 #define EDID_DETAILED_TIMING_FLAG_INTERLEAVED(_x) \
107 	GET_BIT((_x).flags, 0)
108 } __attribute__ ((__packed__));
109 
110 enum edid_monitor_descriptor_types {
111 	EDID_MONITOR_DESCRIPTOR_SERIAL = 0xff,
112 	EDID_MONITOR_DESCRIPTOR_ASCII = 0xfe,
113 	EDID_MONITOR_DESCRIPTOR_RANGE = 0xfd,
114 	EDID_MONITOR_DESCRIPTOR_NAME = 0xfc,
115 };
116 
117 struct edid_monitor_descriptor {
118 	uint16_t zero_flag_1;
119 	unsigned char zero_flag_2;
120 	unsigned char type;
121 	unsigned char zero_flag_3;
122 	union {
123 		char string[13];
124 		struct {
125 			unsigned char vertical_min;
126 			unsigned char vertical_max;
127 			unsigned char horizontal_min;
128 			unsigned char horizontal_max;
129 			unsigned char pixel_clock_max;
130 			unsigned char gtf_data[8];
131 		} range_data;
132 	} data;
133 } __attribute__ ((__packed__));
134 
135 struct edid1_info {
136 	unsigned char header[8];
137 	unsigned char manufacturer_name[2];
138 #define EDID1_INFO_MANUFACTURER_NAME_ZERO(_x) \
139 	GET_BIT(((_x).manufacturer_name[0]), 7)
140 #define EDID1_INFO_MANUFACTURER_NAME_CHAR1(_x) \
141 	GET_BITS(((_x).manufacturer_name[0]), 6, 2)
142 #define EDID1_INFO_MANUFACTURER_NAME_CHAR2(_x) \
143 	((GET_BITS(((_x).manufacturer_name[0]), 1, 0) << 3) + \
144 	 GET_BITS(((_x).manufacturer_name[1]), 7, 5))
145 #define EDID1_INFO_MANUFACTURER_NAME_CHAR3(_x) \
146 	GET_BITS(((_x).manufacturer_name[1]), 4, 0)
147 	unsigned char product_code[2];
148 #define EDID1_INFO_PRODUCT_CODE(_x) \
149 	(((uint16_t)(_x).product_code[1] << 8) + (_x).product_code[0])
150 	unsigned char serial_number[4];
151 #define EDID1_INFO_SERIAL_NUMBER(_x) \
152 	(((uint32_t)(_x).serial_number[3] << 24) + \
153 	 ((_x).serial_number[2] << 16) + ((_x).serial_number[1] << 8) + \
154 	 (_x).serial_number[0])
155 	unsigned char week;
156 	unsigned char year;
157 	unsigned char version;
158 	unsigned char revision;
159 	unsigned char video_input_definition;
160 #define EDID1_INFO_VIDEO_INPUT_DIGITAL(_x) \
161 	GET_BIT(((_x).video_input_definition), 7)
162 #define EDID1_INFO_VIDEO_INPUT_VOLTAGE_LEVEL(_x) \
163 	GET_BITS(((_x).video_input_definition), 6, 5)
164 #define EDID1_INFO_VIDEO_INPUT_BLANK_TO_BLACK(_x) \
165 	GET_BIT(((_x).video_input_definition), 4)
166 #define EDID1_INFO_VIDEO_INPUT_SEPARATE_SYNC(_x) \
167 	GET_BIT(((_x).video_input_definition), 3)
168 #define EDID1_INFO_VIDEO_INPUT_COMPOSITE_SYNC(_x) \
169 	GET_BIT(((_x).video_input_definition), 2)
170 #define EDID1_INFO_VIDEO_INPUT_SYNC_ON_GREEN(_x) \
171 	GET_BIT(((_x).video_input_definition), 1)
172 #define EDID1_INFO_VIDEO_INPUT_SERRATION_V(_x) \
173 	GET_BIT(((_x).video_input_definition), 0)
174 	unsigned char max_size_horizontal;
175 	unsigned char max_size_vertical;
176 	unsigned char gamma;
177 	unsigned char feature_support;
178 #define EDID1_INFO_FEATURE_STANDBY(_x) \
179 	GET_BIT(((_x).feature_support), 7)
180 #define EDID1_INFO_FEATURE_SUSPEND(_x) \
181 	GET_BIT(((_x).feature_support), 6)
182 #define EDID1_INFO_FEATURE_ACTIVE_OFF(_x) \
183 	GET_BIT(((_x).feature_support), 5)
184 #define EDID1_INFO_FEATURE_DISPLAY_TYPE(_x) \
185 	GET_BITS(((_x).feature_support), 4, 3)
186 #define EDID1_INFO_FEATURE_RGB(_x) \
187 	GET_BIT(((_x).feature_support), 2)
188 #define EDID1_INFO_FEATURE_PREFERRED_TIMING_MODE(_x) \
189 	GET_BIT(((_x).feature_support), 1)
190 #define EDID1_INFO_FEATURE_DEFAULT_GTF_SUPPORT(_x) \
191 	GET_BIT(((_x).feature_support), 0)
192 	unsigned char color_characteristics[10];
193 	unsigned char established_timings[3];
194 #define EDID1_INFO_ESTABLISHED_TIMING_720X400_70(_x) \
195 	GET_BIT(((_x).established_timings[0]), 7)
196 #define EDID1_INFO_ESTABLISHED_TIMING_720X400_88(_x) \
197 	GET_BIT(((_x).established_timings[0]), 6)
198 #define EDID1_INFO_ESTABLISHED_TIMING_640X480_60(_x) \
199 	GET_BIT(((_x).established_timings[0]), 5)
200 #define EDID1_INFO_ESTABLISHED_TIMING_640X480_67(_x) \
201 	GET_BIT(((_x).established_timings[0]), 4)
202 #define EDID1_INFO_ESTABLISHED_TIMING_640X480_72(_x) \
203 	GET_BIT(((_x).established_timings[0]), 3)
204 #define EDID1_INFO_ESTABLISHED_TIMING_640X480_75(_x) \
205 	GET_BIT(((_x).established_timings[0]), 2)
206 #define EDID1_INFO_ESTABLISHED_TIMING_800X600_56(_x) \
207 	GET_BIT(((_x).established_timings[0]), 1)
208 #define EDID1_INFO_ESTABLISHED_TIMING_800X600_60(_x) \
209 	GET_BIT(((_x).established_timings[0]), 0)
210 #define EDID1_INFO_ESTABLISHED_TIMING_800X600_72(_x) \
211 	GET_BIT(((_x).established_timings[1]), 7)
212 #define EDID1_INFO_ESTABLISHED_TIMING_800X600_75(_x) \
213 	GET_BIT(((_x).established_timings[1]), 6)
214 #define EDID1_INFO_ESTABLISHED_TIMING_832X624_75(_x) \
215 	GET_BIT(((_x).established_timings[1]), 5)
216 #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_87I(_x) \
217 	GET_BIT(((_x).established_timings[1]), 4)
218 #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_60(_x) \
219 	GET_BIT(((_x).established_timings[1]), 3)
220 #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_70(_x) \
221 	GET_BIT(((_x).established_timings[1]), 2)
222 #define EDID1_INFO_ESTABLISHED_TIMING_1024X768_75(_x) \
223 	GET_BIT(((_x).established_timings[1]), 1)
224 #define EDID1_INFO_ESTABLISHED_TIMING_1280X1024_75(_x) \
225 	GET_BIT(((_x).established_timings[1]), 0)
226 #define EDID1_INFO_ESTABLISHED_TIMING_1152X870_75(_x) \
227 	GET_BIT(((_x).established_timings[2]), 7)
228 	struct {
229 		unsigned char xresolution;
230 		unsigned char aspect_vfreq;
231 	} __attribute__((__packed__)) standard_timings[8];
232 #define EDID1_INFO_STANDARD_TIMING_XRESOLUTION(_x, _i) \
233 	(((_x).standard_timings[_i]).xresolution)
234 #define EDID1_INFO_STANDARD_TIMING_ASPECT(_x, _i) \
235 	GET_BITS(((_x).standard_timings[_i].aspect_vfreq), 7, 6)
236 #define EDID1_INFO_STANDARD_TIMING_VFREQ(_x, _i) \
237 	GET_BITS(((_x).standard_timings[_i].aspect_vfreq), 5, 0)
238 	union {
239 		unsigned char timing[72];
240 		struct edid_monitor_descriptor descriptor[4];
241 	} monitor_details;
242 	unsigned char extension_flag;
243 	unsigned char checksum;
244 } __attribute__ ((__packed__));
245 
246 /**
247  * Print the EDID info.
248  *
249  * @param edid_info	The EDID info to be printed
250  */
251 void edid_print_info(struct edid1_info *edid_info);
252 
253 /**
254  * Check the EDID info.
255  *
256  * @param info  The EDID info to be checked
257  * @return 0 on valid, or -1 on invalid
258  */
259 int edid_check_info(struct edid1_info *info);
260 
261 /**
262  * Get the horizontal and vertical rate ranges of the monitor.
263  *
264  * @param edid	The EDID info
265  * @param hmin	Returns the minimum horizontal rate
266  * @param hmax	Returns the maxium horizontal rate
267  * @param vmin	Returns the minimum vertical rate
268  * @param vmax	Returns the maxium vertical rate
269  * @return 0 on success, or -1 on error
270  */
271 int edid_get_ranges(struct edid1_info *edid, unsigned int *hmin,
272 		    unsigned int *hmax, unsigned int *vmin,
273 		    unsigned int *vmax);
274 
275 #endif /* __EDID_H_ */
276