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