xref: /openbmc/linux/include/linux/hdmi.h (revision 4ec575b7)
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 int 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 
223 enum hdmi_spd_sdi {
224 	HDMI_SPD_SDI_UNKNOWN,
225 	HDMI_SPD_SDI_DSTB,
226 	HDMI_SPD_SDI_DVDP,
227 	HDMI_SPD_SDI_DVHS,
228 	HDMI_SPD_SDI_HDDVR,
229 	HDMI_SPD_SDI_DVC,
230 	HDMI_SPD_SDI_DSC,
231 	HDMI_SPD_SDI_VCD,
232 	HDMI_SPD_SDI_GAME,
233 	HDMI_SPD_SDI_PC,
234 	HDMI_SPD_SDI_BD,
235 	HDMI_SPD_SDI_SACD,
236 	HDMI_SPD_SDI_HDDVD,
237 	HDMI_SPD_SDI_PMP,
238 };
239 
240 struct hdmi_spd_infoframe {
241 	enum hdmi_infoframe_type type;
242 	unsigned char version;
243 	unsigned char length;
244 	char vendor[8];
245 	char product[16];
246 	enum hdmi_spd_sdi sdi;
247 };
248 
249 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
250 			    const char *vendor, const char *product);
251 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
252 				size_t size);
253 ssize_t hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe *frame,
254 				     void *buffer, size_t size);
255 int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe *frame);
256 
257 enum hdmi_audio_coding_type {
258 	HDMI_AUDIO_CODING_TYPE_STREAM,
259 	HDMI_AUDIO_CODING_TYPE_PCM,
260 	HDMI_AUDIO_CODING_TYPE_AC3,
261 	HDMI_AUDIO_CODING_TYPE_MPEG1,
262 	HDMI_AUDIO_CODING_TYPE_MP3,
263 	HDMI_AUDIO_CODING_TYPE_MPEG2,
264 	HDMI_AUDIO_CODING_TYPE_AAC_LC,
265 	HDMI_AUDIO_CODING_TYPE_DTS,
266 	HDMI_AUDIO_CODING_TYPE_ATRAC,
267 	HDMI_AUDIO_CODING_TYPE_DSD,
268 	HDMI_AUDIO_CODING_TYPE_EAC3,
269 	HDMI_AUDIO_CODING_TYPE_DTS_HD,
270 	HDMI_AUDIO_CODING_TYPE_MLP,
271 	HDMI_AUDIO_CODING_TYPE_DST,
272 	HDMI_AUDIO_CODING_TYPE_WMA_PRO,
273 	HDMI_AUDIO_CODING_TYPE_CXT,
274 };
275 
276 enum hdmi_audio_sample_size {
277 	HDMI_AUDIO_SAMPLE_SIZE_STREAM,
278 	HDMI_AUDIO_SAMPLE_SIZE_16,
279 	HDMI_AUDIO_SAMPLE_SIZE_20,
280 	HDMI_AUDIO_SAMPLE_SIZE_24,
281 };
282 
283 enum hdmi_audio_sample_frequency {
284 	HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
285 	HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
286 	HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
287 	HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
288 	HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
289 	HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
290 	HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
291 	HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
292 };
293 
294 enum hdmi_audio_coding_type_ext {
295 	/* Refer to Audio Coding Type (CT) field in Data Byte 1 */
296 	HDMI_AUDIO_CODING_TYPE_EXT_CT,
297 
298 	/*
299 	 * The next three CXT values are defined in CEA-861-E only.
300 	 * They do not exist in older versions, and in CEA-861-F they are
301 	 * defined as 'Not in use'.
302 	 */
303 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
304 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
305 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
306 
307 	/* The following CXT values are only defined in CEA-861-F. */
308 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC,
309 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2,
310 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC,
311 	HDMI_AUDIO_CODING_TYPE_EXT_DRA,
312 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND,
313 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND = 10,
314 };
315 
316 struct hdmi_audio_infoframe {
317 	enum hdmi_infoframe_type type;
318 	unsigned char version;
319 	unsigned char length;
320 	unsigned char channels;
321 	enum hdmi_audio_coding_type coding_type;
322 	enum hdmi_audio_sample_size sample_size;
323 	enum hdmi_audio_sample_frequency sample_frequency;
324 	enum hdmi_audio_coding_type_ext coding_type_ext;
325 	unsigned char channel_allocation;
326 	unsigned char level_shift_value;
327 	bool downmix_inhibit;
328 
329 };
330 
331 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
332 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
333 				  void *buffer, size_t size);
334 ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
335 				       void *buffer, size_t size);
336 int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame);
337 
338 enum hdmi_3d_structure {
339 	HDMI_3D_STRUCTURE_INVALID = -1,
340 	HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
341 	HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
342 	HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
343 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
344 	HDMI_3D_STRUCTURE_L_DEPTH,
345 	HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
346 	HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
347 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
348 };
349 
350 
351 struct hdmi_vendor_infoframe {
352 	enum hdmi_infoframe_type type;
353 	unsigned char version;
354 	unsigned char length;
355 	unsigned int oui;
356 	u8 vic;
357 	enum hdmi_3d_structure s3d_struct;
358 	unsigned int s3d_ext_data;
359 };
360 
361 /* HDR Metadata as per 861.G spec */
362 struct hdr_static_metadata {
363 	__u8 eotf;
364 	__u8 metadata_type;
365 	__u16 max_cll;
366 	__u16 max_fall;
367 	__u16 min_cll;
368 };
369 
370 /**
371  * struct hdr_sink_metadata - HDR sink metadata
372  *
373  * Metadata Information read from Sink's EDID
374  */
375 struct hdr_sink_metadata {
376 	/**
377 	 * @metadata_type: Static_Metadata_Descriptor_ID.
378 	 */
379 	__u32 metadata_type;
380 	/**
381 	 * @hdmi_type1: HDR Metadata Infoframe.
382 	 */
383 	union {
384 		struct hdr_static_metadata hdmi_type1;
385 	};
386 };
387 
388 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
389 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
390 				   void *buffer, size_t size);
391 ssize_t hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe *frame,
392 					void *buffer, size_t size);
393 int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe *frame);
394 
395 union hdmi_vendor_any_infoframe {
396 	struct {
397 		enum hdmi_infoframe_type type;
398 		unsigned char version;
399 		unsigned char length;
400 		unsigned int oui;
401 	} any;
402 	struct hdmi_vendor_infoframe hdmi;
403 };
404 
405 /**
406  * union hdmi_infoframe - overall union of all abstract infoframe representations
407  * @any: generic infoframe
408  * @avi: avi infoframe
409  * @spd: spd infoframe
410  * @vendor: union of all vendor infoframes
411  * @audio: audio infoframe
412  * @drm: Dynamic Range and Mastering infoframe
413  *
414  * This is used by the generic pack function. This works since all infoframes
415  * have the same header which also indicates which type of infoframe should be
416  * packed.
417  */
418 union hdmi_infoframe {
419 	struct hdmi_any_infoframe any;
420 	struct hdmi_avi_infoframe avi;
421 	struct hdmi_spd_infoframe spd;
422 	union hdmi_vendor_any_infoframe vendor;
423 	struct hdmi_audio_infoframe audio;
424 	struct hdmi_drm_infoframe drm;
425 };
426 
427 ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer,
428 			    size_t size);
429 ssize_t hdmi_infoframe_pack_only(const union hdmi_infoframe *frame,
430 				 void *buffer, size_t size);
431 int hdmi_infoframe_check(union hdmi_infoframe *frame);
432 int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
433 			  const void *buffer, size_t size);
434 void hdmi_infoframe_log(const char *level, struct device *dev,
435 			const union hdmi_infoframe *frame);
436 
437 #endif /* _DRM_HDMI_H */
438