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