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