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