xref: /openbmc/linux/include/linux/hdmi.h (revision 132db935)
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 __LINUX_HDMI_H_
25 #define __LINUX_HDMI_H_
26 
27 #include <linux/types.h>
28 #include <linux/device.h>
29 
30 enum hdmi_packet_type {
31 	HDMI_PACKET_TYPE_NULL = 0x00,
32 	HDMI_PACKET_TYPE_AUDIO_CLOCK_REGEN = 0x01,
33 	HDMI_PACKET_TYPE_AUDIO_SAMPLE = 0x02,
34 	HDMI_PACKET_TYPE_GENERAL_CONTROL = 0x03,
35 	HDMI_PACKET_TYPE_ACP = 0x04,
36 	HDMI_PACKET_TYPE_ISRC1 = 0x05,
37 	HDMI_PACKET_TYPE_ISRC2 = 0x06,
38 	HDMI_PACKET_TYPE_ONE_BIT_AUDIO_SAMPLE = 0x07,
39 	HDMI_PACKET_TYPE_DST_AUDIO = 0x08,
40 	HDMI_PACKET_TYPE_HBR_AUDIO_STREAM = 0x09,
41 	HDMI_PACKET_TYPE_GAMUT_METADATA = 0x0a,
42 	/* + enum hdmi_infoframe_type */
43 };
44 
45 enum hdmi_infoframe_type {
46 	HDMI_INFOFRAME_TYPE_VENDOR = 0x81,
47 	HDMI_INFOFRAME_TYPE_AVI = 0x82,
48 	HDMI_INFOFRAME_TYPE_SPD = 0x83,
49 	HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
50 	HDMI_INFOFRAME_TYPE_DRM = 0x87,
51 };
52 
53 #define HDMI_IEEE_OUI 0x000c03
54 #define HDMI_FORUM_IEEE_OUI 0xc45dd8
55 #define HDMI_INFOFRAME_HEADER_SIZE  4
56 #define HDMI_AVI_INFOFRAME_SIZE    13
57 #define HDMI_SPD_INFOFRAME_SIZE    25
58 #define HDMI_AUDIO_INFOFRAME_SIZE  10
59 #define HDMI_DRM_INFOFRAME_SIZE    26
60 
61 #define HDMI_INFOFRAME_SIZE(type)	\
62 	(HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
63 
64 struct hdmi_any_infoframe {
65 	enum hdmi_infoframe_type type;
66 	unsigned char version;
67 	unsigned char length;
68 };
69 
70 enum hdmi_colorspace {
71 	HDMI_COLORSPACE_RGB,
72 	HDMI_COLORSPACE_YUV422,
73 	HDMI_COLORSPACE_YUV444,
74 	HDMI_COLORSPACE_YUV420,
75 	HDMI_COLORSPACE_RESERVED4,
76 	HDMI_COLORSPACE_RESERVED5,
77 	HDMI_COLORSPACE_RESERVED6,
78 	HDMI_COLORSPACE_IDO_DEFINED,
79 };
80 
81 enum hdmi_scan_mode {
82 	HDMI_SCAN_MODE_NONE,
83 	HDMI_SCAN_MODE_OVERSCAN,
84 	HDMI_SCAN_MODE_UNDERSCAN,
85 	HDMI_SCAN_MODE_RESERVED,
86 };
87 
88 enum hdmi_colorimetry {
89 	HDMI_COLORIMETRY_NONE,
90 	HDMI_COLORIMETRY_ITU_601,
91 	HDMI_COLORIMETRY_ITU_709,
92 	HDMI_COLORIMETRY_EXTENDED,
93 };
94 
95 enum hdmi_picture_aspect {
96 	HDMI_PICTURE_ASPECT_NONE,
97 	HDMI_PICTURE_ASPECT_4_3,
98 	HDMI_PICTURE_ASPECT_16_9,
99 	HDMI_PICTURE_ASPECT_64_27,
100 	HDMI_PICTURE_ASPECT_256_135,
101 	HDMI_PICTURE_ASPECT_RESERVED,
102 };
103 
104 enum hdmi_active_aspect {
105 	HDMI_ACTIVE_ASPECT_16_9_TOP = 2,
106 	HDMI_ACTIVE_ASPECT_14_9_TOP = 3,
107 	HDMI_ACTIVE_ASPECT_16_9_CENTER = 4,
108 	HDMI_ACTIVE_ASPECT_PICTURE = 8,
109 	HDMI_ACTIVE_ASPECT_4_3 = 9,
110 	HDMI_ACTIVE_ASPECT_16_9 = 10,
111 	HDMI_ACTIVE_ASPECT_14_9 = 11,
112 	HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13,
113 	HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14,
114 	HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15,
115 };
116 
117 enum hdmi_extended_colorimetry {
118 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_601,
119 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_709,
120 	HDMI_EXTENDED_COLORIMETRY_S_YCC_601,
121 	HDMI_EXTENDED_COLORIMETRY_OPYCC_601,
122 	HDMI_EXTENDED_COLORIMETRY_OPRGB,
123 
124 	/* The following EC values are only defined in CEA-861-F. */
125 	HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM,
126 	HDMI_EXTENDED_COLORIMETRY_BT2020,
127 	HDMI_EXTENDED_COLORIMETRY_RESERVED,
128 };
129 
130 enum hdmi_quantization_range {
131 	HDMI_QUANTIZATION_RANGE_DEFAULT,
132 	HDMI_QUANTIZATION_RANGE_LIMITED,
133 	HDMI_QUANTIZATION_RANGE_FULL,
134 	HDMI_QUANTIZATION_RANGE_RESERVED,
135 };
136 
137 /* non-uniform picture scaling */
138 enum hdmi_nups {
139 	HDMI_NUPS_UNKNOWN,
140 	HDMI_NUPS_HORIZONTAL,
141 	HDMI_NUPS_VERTICAL,
142 	HDMI_NUPS_BOTH,
143 };
144 
145 enum hdmi_ycc_quantization_range {
146 	HDMI_YCC_QUANTIZATION_RANGE_LIMITED,
147 	HDMI_YCC_QUANTIZATION_RANGE_FULL,
148 };
149 
150 enum hdmi_content_type {
151 	HDMI_CONTENT_TYPE_GRAPHICS,
152 	HDMI_CONTENT_TYPE_PHOTO,
153 	HDMI_CONTENT_TYPE_CINEMA,
154 	HDMI_CONTENT_TYPE_GAME,
155 };
156 
157 enum hdmi_metadata_type {
158 	HDMI_STATIC_METADATA_TYPE1 = 1,
159 };
160 
161 enum hdmi_eotf {
162 	HDMI_EOTF_TRADITIONAL_GAMMA_SDR,
163 	HDMI_EOTF_TRADITIONAL_GAMMA_HDR,
164 	HDMI_EOTF_SMPTE_ST2084,
165 	HDMI_EOTF_BT_2100_HLG,
166 };
167 
168 struct hdmi_avi_infoframe {
169 	enum hdmi_infoframe_type type;
170 	unsigned char version;
171 	unsigned char length;
172 	enum hdmi_colorspace colorspace;
173 	enum hdmi_scan_mode scan_mode;
174 	enum hdmi_colorimetry colorimetry;
175 	enum hdmi_picture_aspect picture_aspect;
176 	enum hdmi_active_aspect active_aspect;
177 	bool itc;
178 	enum hdmi_extended_colorimetry extended_colorimetry;
179 	enum hdmi_quantization_range quantization_range;
180 	enum hdmi_nups nups;
181 	unsigned char video_code;
182 	enum hdmi_ycc_quantization_range ycc_quantization_range;
183 	enum hdmi_content_type content_type;
184 	unsigned char pixel_repeat;
185 	unsigned short top_bar;
186 	unsigned short bottom_bar;
187 	unsigned short left_bar;
188 	unsigned short right_bar;
189 };
190 
191 /* DRM Infoframe as per CTA 861.G spec */
192 struct hdmi_drm_infoframe {
193 	enum hdmi_infoframe_type type;
194 	unsigned char version;
195 	unsigned char length;
196 	enum hdmi_eotf eotf;
197 	enum hdmi_metadata_type metadata_type;
198 	struct {
199 		u16 x, y;
200 	} display_primaries[3];
201 	struct {
202 		u16 x, y;
203 	} white_point;
204 	u16 max_display_mastering_luminance;
205 	u16 min_display_mastering_luminance;
206 	u16 max_cll;
207 	u16 max_fall;
208 };
209 
210 void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
211 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
212 				size_t size);
213 ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
214 				     void *buffer, size_t size);
215 int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame);
216 int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame);
217 ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame, void *buffer,
218 				size_t size);
219 ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
220 				     void *buffer, size_t size);
221 int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame);
222 int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
223 				   const void *buffer, size_t size);
224 
225 enum hdmi_spd_sdi {
226 	HDMI_SPD_SDI_UNKNOWN,
227 	HDMI_SPD_SDI_DSTB,
228 	HDMI_SPD_SDI_DVDP,
229 	HDMI_SPD_SDI_DVHS,
230 	HDMI_SPD_SDI_HDDVR,
231 	HDMI_SPD_SDI_DVC,
232 	HDMI_SPD_SDI_DSC,
233 	HDMI_SPD_SDI_VCD,
234 	HDMI_SPD_SDI_GAME,
235 	HDMI_SPD_SDI_PC,
236 	HDMI_SPD_SDI_BD,
237 	HDMI_SPD_SDI_SACD,
238 	HDMI_SPD_SDI_HDDVD,
239 	HDMI_SPD_SDI_PMP,
240 };
241 
242 struct hdmi_spd_infoframe {
243 	enum hdmi_infoframe_type type;
244 	unsigned char version;
245 	unsigned char length;
246 	char vendor[8];
247 	char product[16];
248 	enum hdmi_spd_sdi sdi;
249 };
250 
251 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
252 			    const char *vendor, const char *product);
253 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
254 				size_t size);
255 ssize_t hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe *frame,
256 				     void *buffer, size_t size);
257 int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe *frame);
258 
259 enum hdmi_audio_coding_type {
260 	HDMI_AUDIO_CODING_TYPE_STREAM,
261 	HDMI_AUDIO_CODING_TYPE_PCM,
262 	HDMI_AUDIO_CODING_TYPE_AC3,
263 	HDMI_AUDIO_CODING_TYPE_MPEG1,
264 	HDMI_AUDIO_CODING_TYPE_MP3,
265 	HDMI_AUDIO_CODING_TYPE_MPEG2,
266 	HDMI_AUDIO_CODING_TYPE_AAC_LC,
267 	HDMI_AUDIO_CODING_TYPE_DTS,
268 	HDMI_AUDIO_CODING_TYPE_ATRAC,
269 	HDMI_AUDIO_CODING_TYPE_DSD,
270 	HDMI_AUDIO_CODING_TYPE_EAC3,
271 	HDMI_AUDIO_CODING_TYPE_DTS_HD,
272 	HDMI_AUDIO_CODING_TYPE_MLP,
273 	HDMI_AUDIO_CODING_TYPE_DST,
274 	HDMI_AUDIO_CODING_TYPE_WMA_PRO,
275 	HDMI_AUDIO_CODING_TYPE_CXT,
276 };
277 
278 enum hdmi_audio_sample_size {
279 	HDMI_AUDIO_SAMPLE_SIZE_STREAM,
280 	HDMI_AUDIO_SAMPLE_SIZE_16,
281 	HDMI_AUDIO_SAMPLE_SIZE_20,
282 	HDMI_AUDIO_SAMPLE_SIZE_24,
283 };
284 
285 enum hdmi_audio_sample_frequency {
286 	HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
287 	HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
288 	HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
289 	HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
290 	HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
291 	HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
292 	HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
293 	HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
294 };
295 
296 enum hdmi_audio_coding_type_ext {
297 	/* Refer to Audio Coding Type (CT) field in Data Byte 1 */
298 	HDMI_AUDIO_CODING_TYPE_EXT_CT,
299 
300 	/*
301 	 * The next three CXT values are defined in CEA-861-E only.
302 	 * They do not exist in older versions, and in CEA-861-F they are
303 	 * defined as 'Not in use'.
304 	 */
305 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
306 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
307 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
308 
309 	/* The following CXT values are only defined in CEA-861-F. */
310 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC,
311 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2,
312 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC,
313 	HDMI_AUDIO_CODING_TYPE_EXT_DRA,
314 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND,
315 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND = 10,
316 };
317 
318 struct hdmi_audio_infoframe {
319 	enum hdmi_infoframe_type type;
320 	unsigned char version;
321 	unsigned char length;
322 	unsigned char channels;
323 	enum hdmi_audio_coding_type coding_type;
324 	enum hdmi_audio_sample_size sample_size;
325 	enum hdmi_audio_sample_frequency sample_frequency;
326 	enum hdmi_audio_coding_type_ext coding_type_ext;
327 	unsigned char channel_allocation;
328 	unsigned char level_shift_value;
329 	bool downmix_inhibit;
330 
331 };
332 
333 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
334 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
335 				  void *buffer, size_t size);
336 ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
337 				       void *buffer, size_t size);
338 int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame);
339 
340 enum hdmi_3d_structure {
341 	HDMI_3D_STRUCTURE_INVALID = -1,
342 	HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
343 	HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
344 	HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
345 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
346 	HDMI_3D_STRUCTURE_L_DEPTH,
347 	HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
348 	HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
349 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
350 };
351 
352 
353 struct hdmi_vendor_infoframe {
354 	enum hdmi_infoframe_type type;
355 	unsigned char version;
356 	unsigned char length;
357 	unsigned int oui;
358 	u8 vic;
359 	enum hdmi_3d_structure s3d_struct;
360 	unsigned int s3d_ext_data;
361 };
362 
363 /* HDR Metadata as per 861.G spec */
364 struct hdr_static_metadata {
365 	__u8 eotf;
366 	__u8 metadata_type;
367 	__u16 max_cll;
368 	__u16 max_fall;
369 	__u16 min_cll;
370 };
371 
372 /**
373  * struct hdr_sink_metadata - HDR sink metadata
374  *
375  * Metadata Information read from Sink's EDID
376  */
377 struct hdr_sink_metadata {
378 	/**
379 	 * @metadata_type: Static_Metadata_Descriptor_ID.
380 	 */
381 	__u32 metadata_type;
382 	/**
383 	 * @hdmi_type1: HDR Metadata Infoframe.
384 	 */
385 	union {
386 		struct hdr_static_metadata hdmi_type1;
387 	};
388 };
389 
390 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
391 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
392 				   void *buffer, size_t size);
393 ssize_t hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe *frame,
394 					void *buffer, size_t size);
395 int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe *frame);
396 
397 union hdmi_vendor_any_infoframe {
398 	struct {
399 		enum hdmi_infoframe_type type;
400 		unsigned char version;
401 		unsigned char length;
402 		unsigned int oui;
403 	} any;
404 	struct hdmi_vendor_infoframe hdmi;
405 };
406 
407 /**
408  * union hdmi_infoframe - overall union of all abstract infoframe representations
409  * @any: generic infoframe
410  * @avi: avi infoframe
411  * @spd: spd infoframe
412  * @vendor: union of all vendor infoframes
413  * @audio: audio infoframe
414  * @drm: Dynamic Range and Mastering infoframe
415  *
416  * This is used by the generic pack function. This works since all infoframes
417  * have the same header which also indicates which type of infoframe should be
418  * packed.
419  */
420 union hdmi_infoframe {
421 	struct hdmi_any_infoframe any;
422 	struct hdmi_avi_infoframe avi;
423 	struct hdmi_spd_infoframe spd;
424 	union hdmi_vendor_any_infoframe vendor;
425 	struct hdmi_audio_infoframe audio;
426 	struct hdmi_drm_infoframe drm;
427 };
428 
429 ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer,
430 			    size_t size);
431 ssize_t hdmi_infoframe_pack_only(const union hdmi_infoframe *frame,
432 				 void *buffer, size_t size);
433 int hdmi_infoframe_check(union hdmi_infoframe *frame);
434 int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
435 			  const void *buffer, size_t size);
436 void hdmi_infoframe_log(const char *level, struct device *dev,
437 			const union hdmi_infoframe *frame);
438 
439 #endif /* _DRM_HDMI_H */
440