xref: /openbmc/linux/include/linux/hdmi.h (revision e8f6f3b4)
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 
29 enum hdmi_infoframe_type {
30 	HDMI_INFOFRAME_TYPE_VENDOR = 0x81,
31 	HDMI_INFOFRAME_TYPE_AVI = 0x82,
32 	HDMI_INFOFRAME_TYPE_SPD = 0x83,
33 	HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
34 };
35 
36 #define HDMI_IEEE_OUI 0x000c03
37 #define HDMI_INFOFRAME_HEADER_SIZE  4
38 #define HDMI_AVI_INFOFRAME_SIZE    13
39 #define HDMI_SPD_INFOFRAME_SIZE    25
40 #define HDMI_AUDIO_INFOFRAME_SIZE  10
41 
42 #define HDMI_INFOFRAME_SIZE(type)	\
43 	(HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
44 
45 struct hdmi_any_infoframe {
46 	enum hdmi_infoframe_type type;
47 	unsigned char version;
48 	unsigned char length;
49 };
50 
51 enum hdmi_colorspace {
52 	HDMI_COLORSPACE_RGB,
53 	HDMI_COLORSPACE_YUV422,
54 	HDMI_COLORSPACE_YUV444,
55 };
56 
57 enum hdmi_scan_mode {
58 	HDMI_SCAN_MODE_NONE,
59 	HDMI_SCAN_MODE_OVERSCAN,
60 	HDMI_SCAN_MODE_UNDERSCAN,
61 };
62 
63 enum hdmi_colorimetry {
64 	HDMI_COLORIMETRY_NONE,
65 	HDMI_COLORIMETRY_ITU_601,
66 	HDMI_COLORIMETRY_ITU_709,
67 	HDMI_COLORIMETRY_EXTENDED,
68 };
69 
70 enum hdmi_picture_aspect {
71 	HDMI_PICTURE_ASPECT_NONE,
72 	HDMI_PICTURE_ASPECT_4_3,
73 	HDMI_PICTURE_ASPECT_16_9,
74 };
75 
76 enum hdmi_active_aspect {
77 	HDMI_ACTIVE_ASPECT_16_9_TOP = 2,
78 	HDMI_ACTIVE_ASPECT_14_9_TOP = 3,
79 	HDMI_ACTIVE_ASPECT_16_9_CENTER = 4,
80 	HDMI_ACTIVE_ASPECT_PICTURE = 8,
81 	HDMI_ACTIVE_ASPECT_4_3 = 9,
82 	HDMI_ACTIVE_ASPECT_16_9 = 10,
83 	HDMI_ACTIVE_ASPECT_14_9 = 11,
84 	HDMI_ACTIVE_ASPECT_4_3_SP_14_9 = 13,
85 	HDMI_ACTIVE_ASPECT_16_9_SP_14_9 = 14,
86 	HDMI_ACTIVE_ASPECT_16_9_SP_4_3 = 15,
87 };
88 
89 enum hdmi_extended_colorimetry {
90 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_601,
91 	HDMI_EXTENDED_COLORIMETRY_XV_YCC_709,
92 	HDMI_EXTENDED_COLORIMETRY_S_YCC_601,
93 	HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601,
94 	HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB,
95 };
96 
97 enum hdmi_quantization_range {
98 	HDMI_QUANTIZATION_RANGE_DEFAULT,
99 	HDMI_QUANTIZATION_RANGE_LIMITED,
100 	HDMI_QUANTIZATION_RANGE_FULL,
101 };
102 
103 /* non-uniform picture scaling */
104 enum hdmi_nups {
105 	HDMI_NUPS_UNKNOWN,
106 	HDMI_NUPS_HORIZONTAL,
107 	HDMI_NUPS_VERTICAL,
108 	HDMI_NUPS_BOTH,
109 };
110 
111 enum hdmi_ycc_quantization_range {
112 	HDMI_YCC_QUANTIZATION_RANGE_LIMITED,
113 	HDMI_YCC_QUANTIZATION_RANGE_FULL,
114 };
115 
116 enum hdmi_content_type {
117 	HDMI_CONTENT_TYPE_NONE,
118 	HDMI_CONTENT_TYPE_PHOTO,
119 	HDMI_CONTENT_TYPE_CINEMA,
120 	HDMI_CONTENT_TYPE_GAME,
121 };
122 
123 struct hdmi_avi_infoframe {
124 	enum hdmi_infoframe_type type;
125 	unsigned char version;
126 	unsigned char length;
127 	enum hdmi_colorspace colorspace;
128 	enum hdmi_scan_mode scan_mode;
129 	enum hdmi_colorimetry colorimetry;
130 	enum hdmi_picture_aspect picture_aspect;
131 	enum hdmi_active_aspect active_aspect;
132 	bool itc;
133 	enum hdmi_extended_colorimetry extended_colorimetry;
134 	enum hdmi_quantization_range quantization_range;
135 	enum hdmi_nups nups;
136 	unsigned char video_code;
137 	enum hdmi_ycc_quantization_range ycc_quantization_range;
138 	enum hdmi_content_type content_type;
139 	unsigned char pixel_repeat;
140 	unsigned short top_bar;
141 	unsigned short bottom_bar;
142 	unsigned short left_bar;
143 	unsigned short right_bar;
144 };
145 
146 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
147 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
148 				size_t size);
149 
150 enum hdmi_spd_sdi {
151 	HDMI_SPD_SDI_UNKNOWN,
152 	HDMI_SPD_SDI_DSTB,
153 	HDMI_SPD_SDI_DVDP,
154 	HDMI_SPD_SDI_DVHS,
155 	HDMI_SPD_SDI_HDDVR,
156 	HDMI_SPD_SDI_DVC,
157 	HDMI_SPD_SDI_DSC,
158 	HDMI_SPD_SDI_VCD,
159 	HDMI_SPD_SDI_GAME,
160 	HDMI_SPD_SDI_PC,
161 	HDMI_SPD_SDI_BD,
162 	HDMI_SPD_SDI_SACD,
163 	HDMI_SPD_SDI_HDDVD,
164 	HDMI_SPD_SDI_PMP,
165 };
166 
167 struct hdmi_spd_infoframe {
168 	enum hdmi_infoframe_type type;
169 	unsigned char version;
170 	unsigned char length;
171 	char vendor[8];
172 	char product[16];
173 	enum hdmi_spd_sdi sdi;
174 };
175 
176 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
177 			    const char *vendor, const char *product);
178 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
179 				size_t size);
180 
181 enum hdmi_audio_coding_type {
182 	HDMI_AUDIO_CODING_TYPE_STREAM,
183 	HDMI_AUDIO_CODING_TYPE_PCM,
184 	HDMI_AUDIO_CODING_TYPE_AC3,
185 	HDMI_AUDIO_CODING_TYPE_MPEG1,
186 	HDMI_AUDIO_CODING_TYPE_MP3,
187 	HDMI_AUDIO_CODING_TYPE_MPEG2,
188 	HDMI_AUDIO_CODING_TYPE_AAC_LC,
189 	HDMI_AUDIO_CODING_TYPE_DTS,
190 	HDMI_AUDIO_CODING_TYPE_ATRAC,
191 	HDMI_AUDIO_CODING_TYPE_DSD,
192 	HDMI_AUDIO_CODING_TYPE_EAC3,
193 	HDMI_AUDIO_CODING_TYPE_DTS_HD,
194 	HDMI_AUDIO_CODING_TYPE_MLP,
195 	HDMI_AUDIO_CODING_TYPE_DST,
196 	HDMI_AUDIO_CODING_TYPE_WMA_PRO,
197 };
198 
199 enum hdmi_audio_sample_size {
200 	HDMI_AUDIO_SAMPLE_SIZE_STREAM,
201 	HDMI_AUDIO_SAMPLE_SIZE_16,
202 	HDMI_AUDIO_SAMPLE_SIZE_20,
203 	HDMI_AUDIO_SAMPLE_SIZE_24,
204 };
205 
206 enum hdmi_audio_sample_frequency {
207 	HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM,
208 	HDMI_AUDIO_SAMPLE_FREQUENCY_32000,
209 	HDMI_AUDIO_SAMPLE_FREQUENCY_44100,
210 	HDMI_AUDIO_SAMPLE_FREQUENCY_48000,
211 	HDMI_AUDIO_SAMPLE_FREQUENCY_88200,
212 	HDMI_AUDIO_SAMPLE_FREQUENCY_96000,
213 	HDMI_AUDIO_SAMPLE_FREQUENCY_176400,
214 	HDMI_AUDIO_SAMPLE_FREQUENCY_192000,
215 };
216 
217 enum hdmi_audio_coding_type_ext {
218 	HDMI_AUDIO_CODING_TYPE_EXT_STREAM,
219 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC,
220 	HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2,
221 	HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND,
222 };
223 
224 struct hdmi_audio_infoframe {
225 	enum hdmi_infoframe_type type;
226 	unsigned char version;
227 	unsigned char length;
228 	unsigned char channels;
229 	enum hdmi_audio_coding_type coding_type;
230 	enum hdmi_audio_sample_size sample_size;
231 	enum hdmi_audio_sample_frequency sample_frequency;
232 	enum hdmi_audio_coding_type_ext coding_type_ext;
233 	unsigned char channel_allocation;
234 	unsigned char level_shift_value;
235 	bool downmix_inhibit;
236 
237 };
238 
239 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame);
240 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
241 				  void *buffer, size_t size);
242 
243 enum hdmi_3d_structure {
244 	HDMI_3D_STRUCTURE_INVALID = -1,
245 	HDMI_3D_STRUCTURE_FRAME_PACKING = 0,
246 	HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE,
247 	HDMI_3D_STRUCTURE_LINE_ALTERNATIVE,
248 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL,
249 	HDMI_3D_STRUCTURE_L_DEPTH,
250 	HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH,
251 	HDMI_3D_STRUCTURE_TOP_AND_BOTTOM,
252 	HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF = 8,
253 };
254 
255 
256 struct hdmi_vendor_infoframe {
257 	enum hdmi_infoframe_type type;
258 	unsigned char version;
259 	unsigned char length;
260 	unsigned int oui;
261 	u8 vic;
262 	enum hdmi_3d_structure s3d_struct;
263 	unsigned int s3d_ext_data;
264 };
265 
266 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame);
267 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
268 				   void *buffer, size_t size);
269 
270 union hdmi_vendor_any_infoframe {
271 	struct {
272 		enum hdmi_infoframe_type type;
273 		unsigned char version;
274 		unsigned char length;
275 		unsigned int oui;
276 	} any;
277 	struct hdmi_vendor_infoframe hdmi;
278 };
279 
280 /**
281  * union hdmi_infoframe - overall union of all abstract infoframe representations
282  * @any: generic infoframe
283  * @avi: avi infoframe
284  * @spd: spd infoframe
285  * @vendor: union of all vendor infoframes
286  * @audio: audio infoframe
287  *
288  * This is used by the generic pack function. This works since all infoframes
289  * have the same header which also indicates which type of infoframe should be
290  * packed.
291  */
292 union hdmi_infoframe {
293 	struct hdmi_any_infoframe any;
294 	struct hdmi_avi_infoframe avi;
295 	struct hdmi_spd_infoframe spd;
296 	union hdmi_vendor_any_infoframe vendor;
297 	struct hdmi_audio_infoframe audio;
298 };
299 
300 ssize_t
301 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size);
302 
303 #endif /* _DRM_HDMI_H */
304