1 // SPDX-License-Identifier: MIT
3 * Copyright 2006-2012 Red Hat, Inc.
4 * Copyright 2018-2020 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
6 * Author: Adam Jackson <ajax@nwnk.net>
7 * Maintainer: Hans Verkuil <hverkuil-cisco@xs4all.nl>
10 #ifndef __EDID_DECODE_H_
11 #define __EDID_DECODE_H_
17 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
18 #define min(a, b) ((a) < (b) ? (a) : (b))
19 #define max(a, b) ((a) > (b) ? (a) : (b))
21 #define EDID_PAGE_SIZE 128U
22 #define EDID_MAX_BLOCKS 256U
25 // If interlaced is true, then the vertical blanking
26 // for each field is (vfp + vsync + vbp + 0.5), except for
27 // the VIC 39 timings that doesn't have the 0.5 constant.
29 // Active horizontal and vertical frame height, including any
30 // borders, if present.
31 // Note: for interlaced formats the active field height is vact / 2
33 unsigned hratio
, vratio
;
35 unsigned rb
; // 1 if CVT with reduced blanking, 2 if CVT with reduced blanking v2
37 // The horizontal frontporch may be negative in GTF calculations,
38 // so use int instead of unsigned for hfp. Example: 292x176@76.
41 // The backporch may be negative in buggy detailed timings.
42 // So use int instead of unsigned for hbp and vbp.
45 // For interlaced formats the vertical front porch of the Even Field
46 // is actually a half-line longer.
48 // For interlaced formats the vertical back porch of the Odd Field
49 // is actually a half-line longer.
52 unsigned hborder
, vborder
;
53 bool even_vtotal
; // special for VIC 39
54 bool no_pol_vsync
; // digital composite signals have no vsync polarity
55 unsigned hsize_mm
, vsize_mm
;
56 bool ycbcr420
; // YCbCr 4:2:0 encoding
62 memset(&t
, 0, sizeof(t
));
64 timings_ext(unsigned svr
, const std::string
&_type
)
66 memset(&t
, 0, sizeof(t
));
70 timings_ext(const timings
&_t
, const std::string
&_type
, const std::string
&_flags
)
77 bool is_valid() const { return t
.hact
; }
78 bool has_svr() const { return t
.hact
&& !t
.vact
; }
79 unsigned svr() const { return t
.hact
; }
85 typedef std::vector
<timings_ext
> vec_timings_ext
;
91 edid_size
= num_blocks
= block_nr
= 0;
92 max_hor_freq_hz
= max_vert_freq_hz
= max_pixclk_khz
= 0;
93 min_hor_freq_hz
= 0xffffff;
94 min_vert_freq_hz
= 0xffffffff;
95 warnings
= failures
= 0;
96 has_cta
= has_dispid
= false;
100 base
.has_name_descriptor
= base
.has_display_range_descriptor
=
101 base
.has_serial_number
= base
.has_serial_string
=
102 base
.supports_continuous_freq
= base
.supports_gtf
=
103 base
.supports_cvt
= base
.uses_gtf
= base
.uses_cvt
=
104 base
.has_640x480p60_est_timing
= base
.has_spwg
=
105 base
.seen_non_detailed_descriptor
=
106 base
.preferred_is_also_native
= false;
107 base
.detailed_block_cnt
= base
.dtd_cnt
= 0;
109 base
.min_display_hor_freq_hz
= base
.max_display_hor_freq_hz
=
110 base
.min_display_vert_freq_hz
= base
.max_display_vert_freq_hz
=
111 base
.max_display_pixclk_khz
= base
.max_display_width_mm
=
112 base
.max_display_height_mm
= 0;
114 // CTA-861 block state
115 cta
.has_vic_1
= cta
.first_svd_might_be_preferred
=
116 cta
.has_hdmi
= cta
.has_vcdb
= cta
.has_vfpdb
= false;
117 cta
.last_block_was_hdmi_vsdb
= cta
.have_hf_vsdb
= cta
.have_hf_scdb
= false;
118 cta
.first_block
= cta
.first_svd
= true;
119 cta
.supported_hdmi_vic_codes
= cta
.supported_hdmi_vic_vsb_codes
= 0;
120 memset(cta
.vics
, 0, sizeof(cta
.vics
));
121 memset(cta
.preparsed_has_vic
, 0, sizeof(cta
.preparsed_has_vic
));
122 cta
.preparsed_phys_addr
= 0xffff;
123 cta
.preparse_total_dtds
= 0;
125 // DisplayID block state
127 dispid
.preparse_color_ids
= dispid
.preparse_xfer_ids
= 0;
128 dispid
.preparse_displayid_blocks
= 0;
129 dispid
.is_base_block
= true;
130 dispid
.is_display
= dispid
.has_product_identification
=
131 dispid
.has_display_parameters
= dispid
.has_type_1_7
=
132 dispid
.has_display_interface_features
= false;
134 // Block Map block state
135 block_map
.saw_block_1
= false;
143 std::string data_block
;
147 unsigned min_hor_freq_hz
;
148 unsigned max_hor_freq_hz
;
149 double min_vert_freq_hz
;
150 double max_vert_freq_hz
;
151 unsigned max_pixclk_khz
;
159 bool has_name_descriptor
;
160 bool has_display_range_descriptor
;
161 bool has_serial_number
;
162 bool has_serial_string
;
163 bool supports_continuous_freq
;
169 unsigned detailed_block_cnt
;
171 bool seen_non_detailed_descriptor
;
172 bool has_640x480p60_est_timing
;
173 bool preferred_is_also_native
;
174 timings_ext preferred_timing
;
176 unsigned min_display_hor_freq_hz
;
177 unsigned max_display_hor_freq_hz
;
178 unsigned min_display_vert_freq_hz
;
179 unsigned max_display_vert_freq_hz
;
180 unsigned max_display_pixclk_khz
;
181 unsigned max_display_width_mm
;
182 unsigned max_display_height_mm
;
185 // CTA-861 block state
187 unsigned preparse_total_dtds
;
188 vec_timings_ext vec_dtds
;
189 vec_timings_ext preferred_timings
;
190 vec_timings_ext native_timings
;
192 bool first_svd_might_be_preferred
;
197 unsigned short preparsed_phys_addr
;
198 bool last_block_was_hdmi_vsdb
;
199 bool have_hf_vsdb
, have_hf_scdb
;
202 unsigned supported_hdmi_vic_codes
;
203 unsigned supported_hdmi_vic_vsb_codes
;
204 unsigned short vics
[256][2];
205 bool preparsed_has_vic
[2][256];
206 std::vector
<unsigned char> preparsed_svds
[2];
209 // DisplayID block state
211 unsigned char version
;
212 unsigned short preparse_color_ids
;
213 unsigned short preparse_xfer_ids
;
214 unsigned preparse_displayid_blocks
;
217 bool has_product_identification
;
218 bool has_display_parameters
;
220 bool has_display_interface_features
;
221 vec_timings_ext preferred_timings
;
224 // Block Map block state
229 std::string
dtd_type(unsigned dtd
);
230 std::string
dtd_type() { return dtd_type(base
.dtd_cnt
); }
231 bool print_timings(const char *prefix
, const struct timings
*t
,
232 const char *type
, const char *flags
= "",
233 bool detailed
= false);
234 bool print_timings(const char *prefix
, const struct timings_ext
&t
,
235 bool detailed
= false)
237 return print_timings(prefix
, &t
.t
, t
.type
.c_str(), t
.flags
.c_str(), detailed
);
239 void edid_gtf_mode(unsigned refresh
, struct timings
&t
);
240 void edid_cvt_mode(unsigned refresh
, struct timings
&t
);
241 void detailed_cvt_descriptor(const char *prefix
, const unsigned char *x
, bool first
);
242 void print_standard_timing(const char *prefix
, unsigned char b1
, unsigned char b2
,
243 bool gtf_only
= false, unsigned vrefresh_offset
= 60);
244 void detailed_display_range_limits(const unsigned char *x
);
245 void detailed_epi(const unsigned char *x
);
246 void detailed_timings(const char *prefix
, const unsigned char *x
,
247 bool base_or_cta
= true);
248 void detailed_block(const unsigned char *x
);
249 void parse_base_block(const unsigned char *x
);
250 void check_base_block();
252 void print_vic_index(const char *prefix
, unsigned idx
, const char *suffix
, bool ycbcr420
= false);
253 void cta_vcdb(const unsigned char *x
, unsigned length
);
254 void cta_svd(const unsigned char *x
, unsigned n
, bool for_ycbcr420
);
255 void cta_y420cmdb(const unsigned char *x
, unsigned length
);
256 void cta_vfpdb(const unsigned char *x
, unsigned length
);
257 void cta_hdmi_block(const unsigned char *x
, unsigned length
);
258 void cta_ext_block(const unsigned char *x
, unsigned length
);
259 void cta_block(const unsigned char *x
);
260 void preparse_cta_block(const unsigned char *x
);
261 void parse_cta_block(const unsigned char *x
);
262 void cta_resolve_svr(vec_timings_ext::iterator iter
);
263 void cta_resolve_svrs();
264 void check_cta_blocks();
266 void parse_digital_interface(const unsigned char *x
);
267 void parse_display_device(const unsigned char *x
);
268 void parse_display_caps(const unsigned char *x
);
269 void parse_display_xfer(const unsigned char *x
);
270 void parse_di_ext_block(const unsigned char *x
);
272 void parse_displayid_product_id(const unsigned char *x
);
273 std::string
product_type(unsigned char x
, bool heading
);
274 void parse_displayid_interface_features(const unsigned char *x
);
275 void parse_displayid_parameters(const unsigned char *x
);
276 void parse_displayid_parameters_v2(const unsigned char *x
);
277 void parse_displayid_display_intf(const unsigned char *x
);
278 void parse_displayid_color_characteristics(const unsigned char *x
);
279 void parse_displayid_transfer_characteristics(const unsigned char *x
);
280 void parse_displayid_stereo_display_intf(const unsigned char *x
);
281 void parse_displayid_type_1_7_timing(const unsigned char *x
, bool type7
);
282 void parse_displayid_type_2_timing(const unsigned char *x
);
283 void parse_displayid_type_3_timing(const unsigned char *x
);
284 void parse_displayid_type_4_8_timing(unsigned char type
, unsigned short id
);
285 void parse_displayid_type_5_timing(const unsigned char *x
);
286 void parse_displayid_type_6_timing(const unsigned char *x
);
287 void parse_displayid_type_9_timing(const unsigned char *x
);
288 void preparse_displayid_block(const unsigned char *x
);
289 void parse_displayid_block(const unsigned char *x
);
290 void parse_displayid_cta_data_block(const unsigned char *x
);
291 void check_displayid_blocks();
293 void parse_vtb_ext_block(const unsigned char *x
);
295 void parse_ls_ext_block(const unsigned char *x
);
297 void parse_block_map(const unsigned char *x
);
299 void preparse_extension(const unsigned char *x
);
300 void parse_extension(const unsigned char *x
);
304 static inline void add_str(std::string
&s
, const std::string
&add
)
308 else if (!add
.empty())
312 void msg(bool is_warn
, const char *fmt
, ...);
316 #define warn(fmt, ...) msg(true, fmt, __VA_ARGS__)
317 #define warn_once(fmt, ...) \
319 static bool shown_warn; \
322 msg(true, fmt, __VA_ARGS__); \
325 #define fail(fmt, ...) msg(false, fmt, __VA_ARGS__)
329 #define warn(fmt, args...) msg(true, fmt, ##args)
330 #define warn_once(fmt, args...) \
332 static bool shown_warn; \
335 msg(true, fmt, ##args); \
338 #define fail(fmt, args...) msg(false, fmt, ##args)
342 void do_checksum(const char *prefix
, const unsigned char *x
, size_t len
);
343 std::string
utohex(unsigned char x
);
344 std::string
ouitohex(unsigned oui
);
345 bool memchk(const unsigned char *x
, unsigned len
, unsigned char v
= 0);
346 void hex_block(const char *prefix
, const unsigned char *x
, unsigned length
,
347 bool show_ascii
= true, unsigned step
= 16);
348 std::string
block_name(unsigned char block
);
349 void calc_ratio(struct timings
*t
);
350 const char *oui_name(unsigned oui
, bool reverse
= false);
352 const struct timings
*find_dmt_id(unsigned char dmt_id
);
353 const struct timings
*find_vic_id(unsigned char vic
);
354 const struct timings
*find_hdmi_vic_id(unsigned char hdmi_vic
);
355 unsigned char hdmi_vic_to_vic(unsigned char hdmi_vic
);
356 char *extract_string(const unsigned char *x
, unsigned len
);