xref: /freebsd/sys/arm/nvidia/drm2/hdmi.h (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
1 /*
2  * Copyright (C) 2012 Avionic Design GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #ifndef _HDMI_H_
25 #define _HDMI_H_
26 
27 enum hdmi_infoframe_type {
28 	HDMI_INFOFRAME_TYPE_VENDOR = 0x81,
29 	HDMI_INFOFRAME_TYPE_AVI = 0x82,
30 	HDMI_INFOFRAME_TYPE_SPD = 0x83,
31 	HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
32 };
33 
34 #define HDMI_IEEE_OUI 0x000c03
35 #define HDMI_INFOFRAME_HEADER_SIZE  4
36 #define HDMI_AVI_INFOFRAME_SIZE    13
37 #define HDMI_SPD_INFOFRAME_SIZE    25
38 #define HDMI_AUDIO_INFOFRAME_SIZE  10
39 
40 #define HDMI_INFOFRAME_SIZE(type)	\
41 	(HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
42 
43 struct hdmi_any_infoframe {
44 	enum hdmi_infoframe_type type;
45 	unsigned char version;
46 	unsigned char length;
47 };
48 
49 enum hdmi_colorspace {
50 	HDMI_COLORSPACE_RGB,
51 	HDMI_COLORSPACE_YUV422,
52 	HDMI_COLORSPACE_YUV444,
53 	HDMI_COLORSPACE_YUV420,
54 	HDMI_COLORSPACE_RESERVED4,
55 	HDMI_COLORSPACE_RESERVED5,
56 	HDMI_COLORSPACE_RESERVED6,
57 	HDMI_COLORSPACE_IDO_DEFINED,
58 };
59 
60 enum hdmi_scan_mode {
61 	HDMI_SCAN_MODE_NONE,
62 	HDMI_SCAN_MODE_OVERSCAN,
63 	HDMI_SCAN_MODE_UNDERSCAN,
64 	HDMI_SCAN_MODE_RESERVED,
65 };
66 
67 enum hdmi_colorimetry {
68 	HDMI_COLORIMETRY_NONE,
69 	HDMI_COLORIMETRY_ITU_601,
70 	HDMI_COLORIMETRY_ITU_709,
71 	HDMI_COLORIMETRY_EXTENDED,
72 };
73 
74 enum hdmi_picture_aspect {
75 	HDMI_PICTURE_ASPECT_NONE,
76 	HDMI_PICTURE_ASPECT_4_3,
77 	HDMI_PICTURE_ASPECT_16_9,
78 	HDMI_PICTURE_ASPECT_RESERVED,
79 };
80 
81 enum hdmi_active_aspect {
82 	HDMI_ACTIVE_ASPECT_16_9_TOP = 2,
83 	HDMI_ACTIVE_ASPECT_14_9_TOP = 3,
84 	HDMI_ACTIVE_ASPECT_16_9_CENTER = 4,
85 	HDMI_ACTIVE_ASPECT_PICTURE = 8,
86 	HDMI_ACTIVE_ASPECT_4_3 = 9,
87 	HDMI_ACTIVE_ASPECT_16_9 = 10,
88 	HDMI_ACTIVE_ASPECT_14_9 = 11,
89 	HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13,
90 	HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14,
91 	HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15,
92 };
93 
94 enum hdmi_extended_colorimetry {
95 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_601,
96 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_709,
97 	HDMI_EXTENDED_COLORIMETRY_S_YCC_601,
98 	HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601,
99 	HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB,
100 
101 	/* The following EC values are only defined in CEA-861-F. */
102 	HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM,
103 	HDMI_EXTENDED_COLORIMETRY_BT2020,
104 	HDMI_EXTENDED_COLORIMETRY_RESERVED,
105 };
106 
107 enum hdmi_quantization_range {
108 	HDMI_QUANTIZATION_RANGE_DEFAULT,
109 	HDMI_QUANTIZATION_RANGE_LIMITED,
110 	HDMI_QUANTIZATION_RANGE_FULL,
111 	HDMI_QUANTIZATION_RANGE_RESERVED,
112 };
113 
114 /* non-uniform picture scaling */
115 enum hdmi_nups {
116 	HDMI_NUPS_UNKNOWN,
117 	HDMI_NUPS_HORIZONTAL,
118 	HDMI_NUPS_VERTICAL,
119 	HDMI_NUPS_BOTH,
120 };
121 
122 enum hdmi_ycc_quantization_range {
123 	HDMI_YCC_QUANTIZATION_RANGE_LIMITED,
124 	HDMI_YCC_QUANTIZATION_RANGE_FULL,
125 };
126 
127 enum hdmi_content_type {
128 	HDMI_CONTENT_TYPE_GRAPHICS,
129 	HDMI_CONTENT_TYPE_PHOTO,
130 	HDMI_CONTENT_TYPE_CINEMA,
131 	HDMI_CONTENT_TYPE_GAME,
132 };
133 
134 struct hdmi_avi_infoframe {
135 	enum hdmi_infoframe_type type;
136 	unsigned char version;
137 	unsigned char length;
138 	enum hdmi_colorspace colorspace;
139 	enum hdmi_scan_mode scan_mode;
140 	enum hdmi_colorimetry colorimetry;
141 	enum hdmi_picture_aspect picture_aspect;
142 	enum hdmi_active_aspect active_aspect;
143 	bool itc;
144 	enum hdmi_extended_colorimetry extended_colorimetry;
145 	enum hdmi_quantization_range quantization_range;
146 	enum hdmi_nups nups;
147 	unsigned char video_code;
148 	enum hdmi_ycc_quantization_range ycc_quantization_range;
149 	enum hdmi_content_type content_type;
150 	unsigned char pixel_repeat;
151 	unsigned short top_bar;
152 	unsigned short bottom_bar;
153 	unsigned short left_bar;
154 	unsigned short right_bar;
155 };
156 
157 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
158 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
159 				size_t size);
160 
161 enum hdmi_spd_sdi {
162 	HDMI_SPD_SDI_UNKNOWN,
163 	HDMI_SPD_SDI_DSTB,
164 	HDMI_SPD_SDI_DVDP,
165 	HDMI_SPD_SDI_DVHS,
166 	HDMI_SPD_SDI_HDDVR,
167 	HDMI_SPD_SDI_DVC,
168 	HDMI_SPD_SDI_DSC,
169 	HDMI_SPD_SDI_VCD,
170 	HDMI_SPD_SDI_GAME,
171 	HDMI_SPD_SDI_PC,
172 	HDMI_SPD_SDI_BD,
173 	HDMI_SPD_SDI_SACD,
174 	HDMI_SPD_SDI_HDDVD,
175 	HDMI_SPD_SDI_PMP,
176 };
177 
178 struct hdmi_spd_infoframe {
179 	enum hdmi_infoframe_type type;
180 	unsigned char version;
181 	unsigned char length;
182 	char vendor[8];
183 	char product[16];
184 	enum hdmi_spd_sdi sdi;
185 };
186 
187 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
188 			    const char *vendor, const char *product);
189 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
190 				size_t size);
191 
192 enum hdmi_audio_coding_type {
193 	HDMI_AUDIO_CODING_TYPE_STREAM,
194 	HDMI_AUDIO_CODING_TYPE_PCM,
195 	HDMI_AUDIO_CODING_TYPE_AC3,
196 	HDMI_AUDIO_CODING_TYPE_MPEG1,
197 	HDMI_AUDIO_CODING_TYPE_MP3,
198 	HDMI_AUDIO_CODING_TYPE_MPEG2,
199 	HDMI_AUDIO_CODING_TYPE_AAC_LC,
200 	HDMI_AUDIO_CODING_TYPE_DTS,
201 	HDMI_AUDIO_CODING_TYPE_ATRAC,
202 	HDMI_AUDIO_CODING_TYPE_DSD,
203 	HDMI_AUDIO_CODING_TYPE_EAC3,
204 	HDMI_AUDIO_CODING_TYPE_DTS_HD,
205 	HDMI_AUDIO_CODING_TYPE_MLP,
206 	HDMI_AUDIO_CODING_TYPE_DST,
207 	HDMI_AUDIO_CODING_TYPE_WMA_PRO,
208 	HDMI_AUDIO_CODING_TYPE_CXT,
209 };
210 
211 enum hdmi_audio_sample_size {
212 	HDMI_AUDIO_SAMPLE_SIZE_STREAM,
213 	HDMI_AUDIO_SAMPLE_SIZE_16,
214 	HDMI_AUDIO_SAMPLE_SIZE_20,
215 	HDMI_AUDIO_SAMPLE_SIZE_24,
216 };
217 
218 enum hdmi_audio_sample_frequency {
219 	HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
220 	HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
221 	HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
222 	HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
223 	HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
224 	HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
225 	HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
226 	HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
227 };
228 
229 enum hdmi_audio_coding_type_ext {
230 	/* Refer to Audio Coding Type (CT) field in Data Byte 1 */
231 	HDMI_AUDIO_CODING_TYPE_EXT_CT,
232 
233 	/*
234 	 * The next three CXT values are defined in CEA-861-E only.
235 	 * They do not exist in older versions, and in CEA-861-F they are
236 	 * defined as 'Not in use'.
237 	 */
238 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
239 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
240 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
241 
242 	/* The following CXT values are only defined in CEA-861-F. */
243 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC,
244 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2,
245 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC,
246 	HDMI_AUDIO_CODING_TYPE_EXT_DRA,
247 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND,
248 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND = 10,
249 };
250 
251 struct hdmi_audio_infoframe {
252 	enum hdmi_infoframe_type type;
253 	unsigned char version;
254 	unsigned char length;
255 	unsigned char channels;
256 	enum hdmi_audio_coding_type coding_type;
257 	enum hdmi_audio_sample_size sample_size;
258 	enum hdmi_audio_sample_frequency sample_frequency;
259 	enum hdmi_audio_coding_type_ext coding_type_ext;
260 	unsigned char channel_allocation;
261 	unsigned char level_shift_value;
262 	bool downmix_inhibit;
263 
264 };
265 
266 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
267 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
268 				  void *buffer, size_t size);
269 
270 enum hdmi_3d_structure {
271 	HDMI_3D_STRUCTURE_INVALID = -1,
272 	HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
273 	HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
274 	HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
275 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
276 	HDMI_3D_STRUCTURE_L_DEPTH,
277 	HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
278 	HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
279 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
280 };
281 
282 struct hdmi_vendor_infoframe {
283 	enum hdmi_infoframe_type type;
284 	unsigned char version;
285 	unsigned char length;
286 	unsigned int oui;
287 	uint8_t vic;
288 	enum hdmi_3d_structure s3d_struct;
289 	unsigned int s3d_ext_data;
290 };
291 
292 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
293 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
294 				   void *buffer, size_t size);
295 
296 union hdmi_vendor_any_infoframe {
297 	struct {
298 		enum hdmi_infoframe_type type;
299 		unsigned char version;
300 		unsigned char length;
301 		unsigned int oui;
302 	} any;
303 	struct hdmi_vendor_infoframe hdmi;
304 };
305 
306 /**
307  * union hdmi_infoframe - overall union of all abstract infoframe representations
308  * @any: generic infoframe
309  * @avi: avi infoframe
310  * @spd: spd infoframe
311  * @vendor: union of all vendor infoframes
312  * @audio: audio infoframe
313  *
314  * This is used by the generic pack function. This works since all infoframes
315  * have the same header which also indicates which type of infoframe should be
316  * packed.
317  */
318 union hdmi_infoframe {
319 	struct hdmi_any_infoframe any;
320 	struct hdmi_avi_infoframe avi;
321 	struct hdmi_spd_infoframe spd;
322 	union hdmi_vendor_any_infoframe vendor;
323 	struct hdmi_audio_infoframe audio;
324 };
325 
326 ssize_t
327 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
328 int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer);
329 void hdmi_infoframe_log(union hdmi_infoframe *frame);
330 
331 #endif /* _HDMI_H */
332