2 * Copyright (C) 2012 Avionic Design GmbH
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
24 #include <linux/bitops.h>
25 #include <linux/bug.h>
26 #include <linux/errno.h>
27 #include <linux/export.h>
28 #include <linux/hdmi.h>
29 #include <linux/device.h>
30 #include <linux/kernel.h>
32 #define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
34 static u8
hdmi_infoframe_checksum(u8
*ptr
, size_t size
)
39 /* compute checksum */
40 for (i
= 0; i
< size
; i
++)
46 static void hdmi_infoframe_set_checksum(void *buffer
, size_t size
)
50 ptr
[3] = hdmi_infoframe_checksum(buffer
, size
);
54 * hdmi_avi_infoframe_init() - initialize an HDMI AVI infoframe
55 * @frame: HDMI AVI infoframe
57 * Returns 0 on success or a negative error code on failure.
59 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe
*frame
)
61 memset(frame
, 0, sizeof(*frame
));
63 frame
->type
= HDMI_INFOFRAME_TYPE_AVI
;
65 frame
->length
= HDMI_AVI_INFOFRAME_SIZE
;
69 EXPORT_SYMBOL(hdmi_avi_infoframe_init
);
72 * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
73 * @frame: HDMI AVI infoframe
74 * @buffer: destination buffer
75 * @size: size of buffer
77 * Packs the information contained in the @frame structure into a binary
78 * representation that can be written into the corresponding controller
79 * registers. Also computes the checksum as required by section 5.3.5 of
80 * the HDMI 1.4 specification.
82 * Returns the number of bytes packed into the binary buffer or a negative
83 * error code on failure.
85 ssize_t
hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe
*frame
, void *buffer
,
91 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
96 memset(buffer
, 0, size
);
99 ptr
[1] = frame
->version
;
100 ptr
[2] = frame
->length
;
101 ptr
[3] = 0; /* checksum */
103 /* start infoframe payload */
104 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
106 ptr
[0] = ((frame
->colorspace
& 0x3) << 5) | (frame
->scan_mode
& 0x3);
109 * Data byte 1, bit 4 has to be set if we provide the active format
112 if (frame
->active_aspect
& 0xf)
115 /* Bit 3 and 2 indicate if we transmit horizontal/vertical bar data */
116 if (frame
->top_bar
|| frame
->bottom_bar
)
119 if (frame
->left_bar
|| frame
->right_bar
)
122 ptr
[1] = ((frame
->colorimetry
& 0x3) << 6) |
123 ((frame
->picture_aspect
& 0x3) << 4) |
124 (frame
->active_aspect
& 0xf);
126 ptr
[2] = ((frame
->extended_colorimetry
& 0x7) << 4) |
127 ((frame
->quantization_range
& 0x3) << 2) |
133 ptr
[3] = frame
->video_code
& 0x7f;
135 ptr
[4] = ((frame
->ycc_quantization_range
& 0x3) << 6) |
136 ((frame
->content_type
& 0x3) << 4) |
137 (frame
->pixel_repeat
& 0xf);
139 ptr
[5] = frame
->top_bar
& 0xff;
140 ptr
[6] = (frame
->top_bar
>> 8) & 0xff;
141 ptr
[7] = frame
->bottom_bar
& 0xff;
142 ptr
[8] = (frame
->bottom_bar
>> 8) & 0xff;
143 ptr
[9] = frame
->left_bar
& 0xff;
144 ptr
[10] = (frame
->left_bar
>> 8) & 0xff;
145 ptr
[11] = frame
->right_bar
& 0xff;
146 ptr
[12] = (frame
->right_bar
>> 8) & 0xff;
148 hdmi_infoframe_set_checksum(buffer
, length
);
152 EXPORT_SYMBOL(hdmi_avi_infoframe_pack
);
155 * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
156 * @frame: HDMI SPD infoframe
157 * @vendor: vendor string
158 * @product: product string
160 * Returns 0 on success or a negative error code on failure.
162 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe
*frame
,
163 const char *vendor
, const char *product
)
165 memset(frame
, 0, sizeof(*frame
));
167 frame
->type
= HDMI_INFOFRAME_TYPE_SPD
;
169 frame
->length
= HDMI_SPD_INFOFRAME_SIZE
;
171 strncpy(frame
->vendor
, vendor
, sizeof(frame
->vendor
));
172 strncpy(frame
->product
, product
, sizeof(frame
->product
));
176 EXPORT_SYMBOL(hdmi_spd_infoframe_init
);
179 * hdmi_spd_infoframe_pack() - write HDMI SPD infoframe to binary buffer
180 * @frame: HDMI SPD infoframe
181 * @buffer: destination buffer
182 * @size: size of buffer
184 * Packs the information contained in the @frame structure into a binary
185 * representation that can be written into the corresponding controller
186 * registers. Also computes the checksum as required by section 5.3.5 of
187 * the HDMI 1.4 specification.
189 * Returns the number of bytes packed into the binary buffer or a negative
190 * error code on failure.
192 ssize_t
hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe
*frame
, void *buffer
,
198 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
203 memset(buffer
, 0, size
);
205 ptr
[0] = frame
->type
;
206 ptr
[1] = frame
->version
;
207 ptr
[2] = frame
->length
;
208 ptr
[3] = 0; /* checksum */
210 /* start infoframe payload */
211 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
213 memcpy(ptr
, frame
->vendor
, sizeof(frame
->vendor
));
214 memcpy(ptr
+ 8, frame
->product
, sizeof(frame
->product
));
216 ptr
[24] = frame
->sdi
;
218 hdmi_infoframe_set_checksum(buffer
, length
);
222 EXPORT_SYMBOL(hdmi_spd_infoframe_pack
);
225 * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
226 * @frame: HDMI audio infoframe
228 * Returns 0 on success or a negative error code on failure.
230 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe
*frame
)
232 memset(frame
, 0, sizeof(*frame
));
234 frame
->type
= HDMI_INFOFRAME_TYPE_AUDIO
;
236 frame
->length
= HDMI_AUDIO_INFOFRAME_SIZE
;
240 EXPORT_SYMBOL(hdmi_audio_infoframe_init
);
243 * hdmi_audio_infoframe_pack() - write HDMI audio infoframe to binary buffer
244 * @frame: HDMI audio infoframe
245 * @buffer: destination buffer
246 * @size: size of buffer
248 * Packs the information contained in the @frame structure into a binary
249 * representation that can be written into the corresponding controller
250 * registers. Also computes the checksum as required by section 5.3.5 of
251 * the HDMI 1.4 specification.
253 * Returns the number of bytes packed into the binary buffer or a negative
254 * error code on failure.
256 ssize_t
hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe
*frame
,
257 void *buffer
, size_t size
)
259 unsigned char channels
;
263 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
268 memset(buffer
, 0, size
);
270 if (frame
->channels
>= 2)
271 channels
= frame
->channels
- 1;
275 ptr
[0] = frame
->type
;
276 ptr
[1] = frame
->version
;
277 ptr
[2] = frame
->length
;
278 ptr
[3] = 0; /* checksum */
280 /* start infoframe payload */
281 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
283 ptr
[0] = ((frame
->coding_type
& 0xf) << 4) | (channels
& 0x7);
284 ptr
[1] = ((frame
->sample_frequency
& 0x7) << 2) |
285 (frame
->sample_size
& 0x3);
286 ptr
[2] = frame
->coding_type_ext
& 0x1f;
287 ptr
[3] = frame
->channel_allocation
;
288 ptr
[4] = (frame
->level_shift_value
& 0xf) << 3;
290 if (frame
->downmix_inhibit
)
293 hdmi_infoframe_set_checksum(buffer
, length
);
297 EXPORT_SYMBOL(hdmi_audio_infoframe_pack
);
300 * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
301 * @frame: HDMI vendor infoframe
303 * Returns 0 on success or a negative error code on failure.
305 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe
*frame
)
307 memset(frame
, 0, sizeof(*frame
));
309 frame
->type
= HDMI_INFOFRAME_TYPE_VENDOR
;
312 frame
->oui
= HDMI_IEEE_OUI
;
315 * 0 is a valid value for s3d_struct, so we use a special "not set"
318 frame
->s3d_struct
= HDMI_3D_STRUCTURE_INVALID
;
322 EXPORT_SYMBOL(hdmi_vendor_infoframe_init
);
325 * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
326 * @frame: HDMI infoframe
327 * @buffer: destination buffer
328 * @size: size of buffer
330 * Packs the information contained in the @frame structure into a binary
331 * representation that can be written into the corresponding controller
332 * registers. Also computes the checksum as required by section 5.3.5 of
333 * the HDMI 1.4 specification.
335 * Returns the number of bytes packed into the binary buffer or a negative
336 * error code on failure.
338 ssize_t
hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe
*frame
,
339 void *buffer
, size_t size
)
344 /* empty info frame */
345 if (frame
->vic
== 0 && frame
->s3d_struct
== HDMI_3D_STRUCTURE_INVALID
)
348 /* only one of those can be supplied */
349 if (frame
->vic
!= 0 && frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
)
352 /* for side by side (half) we also need to provide 3D_Ext_Data */
353 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
358 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
363 memset(buffer
, 0, size
);
365 ptr
[0] = frame
->type
;
366 ptr
[1] = frame
->version
;
367 ptr
[2] = frame
->length
;
368 ptr
[3] = 0; /* checksum */
376 ptr
[7] = 0x1 << 5; /* video format */
379 ptr
[7] = 0x2 << 5; /* video format */
380 ptr
[8] = (frame
->s3d_struct
& 0xf) << 4;
381 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
382 ptr
[9] = (frame
->s3d_ext_data
& 0xf) << 4;
385 hdmi_infoframe_set_checksum(buffer
, length
);
389 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack
);
392 * hdmi_vendor_any_infoframe_pack() - write a vendor infoframe to binary buffer
395 hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe
*frame
,
396 void *buffer
, size_t size
)
398 /* we only know about HDMI vendor infoframes */
399 if (frame
->any
.oui
!= HDMI_IEEE_OUI
)
402 return hdmi_vendor_infoframe_pack(&frame
->hdmi
, buffer
, size
);
406 * hdmi_infoframe_pack() - write a HDMI infoframe to binary buffer
407 * @frame: HDMI infoframe
408 * @buffer: destination buffer
409 * @size: size of buffer
411 * Packs the information contained in the @frame structure into a binary
412 * representation that can be written into the corresponding controller
413 * registers. Also computes the checksum as required by section 5.3.5 of
414 * the HDMI 1.4 specification.
416 * Returns the number of bytes packed into the binary buffer or a negative
417 * error code on failure.
420 hdmi_infoframe_pack(union hdmi_infoframe
*frame
, void *buffer
, size_t size
)
424 switch (frame
->any
.type
) {
425 case HDMI_INFOFRAME_TYPE_AVI
:
426 length
= hdmi_avi_infoframe_pack(&frame
->avi
, buffer
, size
);
428 case HDMI_INFOFRAME_TYPE_SPD
:
429 length
= hdmi_spd_infoframe_pack(&frame
->spd
, buffer
, size
);
431 case HDMI_INFOFRAME_TYPE_AUDIO
:
432 length
= hdmi_audio_infoframe_pack(&frame
->audio
, buffer
, size
);
434 case HDMI_INFOFRAME_TYPE_VENDOR
:
435 length
= hdmi_vendor_any_infoframe_pack(&frame
->vendor
,
439 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
445 EXPORT_SYMBOL(hdmi_infoframe_pack
);
447 static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type
)
449 if (type
< 0x80 || type
> 0x9f)
452 case HDMI_INFOFRAME_TYPE_VENDOR
:
454 case HDMI_INFOFRAME_TYPE_AVI
:
455 return "Auxiliary Video Information (AVI)";
456 case HDMI_INFOFRAME_TYPE_SPD
:
457 return "Source Product Description (SPD)";
458 case HDMI_INFOFRAME_TYPE_AUDIO
:
464 static void hdmi_infoframe_log_header(const char *level
,
466 struct hdmi_any_infoframe
*frame
)
468 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
469 hdmi_infoframe_type_get_name(frame
->type
),
470 frame
->version
, frame
->length
);
473 static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace
)
475 switch (colorspace
) {
476 case HDMI_COLORSPACE_RGB
:
478 case HDMI_COLORSPACE_YUV422
:
479 return "YCbCr 4:2:2";
480 case HDMI_COLORSPACE_YUV444
:
481 return "YCbCr 4:4:4";
482 case HDMI_COLORSPACE_YUV420
:
483 return "YCbCr 4:2:0";
484 case HDMI_COLORSPACE_RESERVED4
:
485 return "Reserved (4)";
486 case HDMI_COLORSPACE_RESERVED5
:
487 return "Reserved (5)";
488 case HDMI_COLORSPACE_RESERVED6
:
489 return "Reserved (6)";
490 case HDMI_COLORSPACE_IDO_DEFINED
:
491 return "IDO Defined";
496 static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode
)
499 case HDMI_SCAN_MODE_NONE
:
501 case HDMI_SCAN_MODE_OVERSCAN
:
503 case HDMI_SCAN_MODE_UNDERSCAN
:
505 case HDMI_SCAN_MODE_RESERVED
:
511 static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry
)
513 switch (colorimetry
) {
514 case HDMI_COLORIMETRY_NONE
:
516 case HDMI_COLORIMETRY_ITU_601
:
518 case HDMI_COLORIMETRY_ITU_709
:
520 case HDMI_COLORIMETRY_EXTENDED
:
527 hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect
)
529 switch (picture_aspect
) {
530 case HDMI_PICTURE_ASPECT_NONE
:
532 case HDMI_PICTURE_ASPECT_4_3
:
534 case HDMI_PICTURE_ASPECT_16_9
:
536 case HDMI_PICTURE_ASPECT_RESERVED
:
543 hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect
)
545 if (active_aspect
< 0 || active_aspect
> 0xf)
548 switch (active_aspect
) {
549 case HDMI_ACTIVE_ASPECT_16_9_TOP
:
551 case HDMI_ACTIVE_ASPECT_14_9_TOP
:
553 case HDMI_ACTIVE_ASPECT_16_9_CENTER
:
554 return "16:9 Center";
555 case HDMI_ACTIVE_ASPECT_PICTURE
:
556 return "Same as Picture";
557 case HDMI_ACTIVE_ASPECT_4_3
:
559 case HDMI_ACTIVE_ASPECT_16_9
:
561 case HDMI_ACTIVE_ASPECT_14_9
:
563 case HDMI_ACTIVE_ASPECT_4_3_SP_14_9
:
564 return "4:3 SP 14:9";
565 case HDMI_ACTIVE_ASPECT_16_9_SP_14_9
:
566 return "16:9 SP 14:9";
567 case HDMI_ACTIVE_ASPECT_16_9_SP_4_3
:
568 return "16:9 SP 4:3";
574 hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col
)
577 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601
:
579 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709
:
581 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601
:
583 case HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601
:
584 return "Adobe YCC 601";
585 case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB
:
587 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM
:
588 return "BT.2020 Constant Luminance";
589 case HDMI_EXTENDED_COLORIMETRY_BT2020
:
591 case HDMI_EXTENDED_COLORIMETRY_RESERVED
:
598 hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange
)
601 case HDMI_QUANTIZATION_RANGE_DEFAULT
:
603 case HDMI_QUANTIZATION_RANGE_LIMITED
:
605 case HDMI_QUANTIZATION_RANGE_FULL
:
607 case HDMI_QUANTIZATION_RANGE_RESERVED
:
613 static const char *hdmi_nups_get_name(enum hdmi_nups nups
)
616 case HDMI_NUPS_UNKNOWN
:
617 return "Unknown Non-uniform Scaling";
618 case HDMI_NUPS_HORIZONTAL
:
619 return "Horizontally Scaled";
620 case HDMI_NUPS_VERTICAL
:
621 return "Vertically Scaled";
623 return "Horizontally and Vertically Scaled";
629 hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange
)
632 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED
:
634 case HDMI_YCC_QUANTIZATION_RANGE_FULL
:
641 hdmi_content_type_get_name(enum hdmi_content_type content_type
)
643 switch (content_type
) {
644 case HDMI_CONTENT_TYPE_GRAPHICS
:
646 case HDMI_CONTENT_TYPE_PHOTO
:
648 case HDMI_CONTENT_TYPE_CINEMA
:
650 case HDMI_CONTENT_TYPE_GAME
:
657 * hdmi_avi_infoframe_log() - log info of HDMI AVI infoframe
658 * @level: logging level
660 * @frame: HDMI AVI infoframe
662 static void hdmi_avi_infoframe_log(const char *level
,
664 struct hdmi_avi_infoframe
*frame
)
666 hdmi_infoframe_log_header(level
, dev
,
667 (struct hdmi_any_infoframe
*)frame
);
669 hdmi_log(" colorspace: %s\n",
670 hdmi_colorspace_get_name(frame
->colorspace
));
671 hdmi_log(" scan mode: %s\n",
672 hdmi_scan_mode_get_name(frame
->scan_mode
));
673 hdmi_log(" colorimetry: %s\n",
674 hdmi_colorimetry_get_name(frame
->colorimetry
));
675 hdmi_log(" picture aspect: %s\n",
676 hdmi_picture_aspect_get_name(frame
->picture_aspect
));
677 hdmi_log(" active aspect: %s\n",
678 hdmi_active_aspect_get_name(frame
->active_aspect
));
679 hdmi_log(" itc: %s\n", frame
->itc
? "IT Content" : "No Data");
680 hdmi_log(" extended colorimetry: %s\n",
681 hdmi_extended_colorimetry_get_name(frame
->extended_colorimetry
));
682 hdmi_log(" quantization range: %s\n",
683 hdmi_quantization_range_get_name(frame
->quantization_range
));
684 hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame
->nups
));
685 hdmi_log(" video code: %u\n", frame
->video_code
);
686 hdmi_log(" ycc quantization range: %s\n",
687 hdmi_ycc_quantization_range_get_name(frame
->ycc_quantization_range
));
688 hdmi_log(" hdmi content type: %s\n",
689 hdmi_content_type_get_name(frame
->content_type
));
690 hdmi_log(" pixel repeat: %u\n", frame
->pixel_repeat
);
691 hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
692 frame
->top_bar
, frame
->bottom_bar
,
693 frame
->left_bar
, frame
->right_bar
);
696 static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi
)
698 if (sdi
< 0 || sdi
> 0xff)
701 case HDMI_SPD_SDI_UNKNOWN
:
703 case HDMI_SPD_SDI_DSTB
:
704 return "Digital STB";
705 case HDMI_SPD_SDI_DVDP
:
707 case HDMI_SPD_SDI_DVHS
:
709 case HDMI_SPD_SDI_HDDVR
:
710 return "HDD Videorecorder";
711 case HDMI_SPD_SDI_DVC
:
713 case HDMI_SPD_SDI_DSC
:
715 case HDMI_SPD_SDI_VCD
:
717 case HDMI_SPD_SDI_GAME
:
719 case HDMI_SPD_SDI_PC
:
721 case HDMI_SPD_SDI_BD
:
722 return "Blu-Ray Disc (BD)";
723 case HDMI_SPD_SDI_SACD
:
724 return "Super Audio CD";
725 case HDMI_SPD_SDI_HDDVD
:
727 case HDMI_SPD_SDI_PMP
:
734 * hdmi_spd_infoframe_log() - log info of HDMI SPD infoframe
735 * @level: logging level
737 * @frame: HDMI SPD infoframe
739 static void hdmi_spd_infoframe_log(const char *level
,
741 struct hdmi_spd_infoframe
*frame
)
745 hdmi_infoframe_log_header(level
, dev
,
746 (struct hdmi_any_infoframe
*)frame
);
748 memset(buf
, 0, sizeof(buf
));
750 strncpy(buf
, frame
->vendor
, 8);
751 hdmi_log(" vendor: %s\n", buf
);
752 strncpy(buf
, frame
->product
, 16);
753 hdmi_log(" product: %s\n", buf
);
754 hdmi_log(" source device information: %s (0x%x)\n",
755 hdmi_spd_sdi_get_name(frame
->sdi
), frame
->sdi
);
759 hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type
)
761 switch (coding_type
) {
762 case HDMI_AUDIO_CODING_TYPE_STREAM
:
763 return "Refer to Stream Header";
764 case HDMI_AUDIO_CODING_TYPE_PCM
:
766 case HDMI_AUDIO_CODING_TYPE_AC3
:
768 case HDMI_AUDIO_CODING_TYPE_MPEG1
:
770 case HDMI_AUDIO_CODING_TYPE_MP3
:
772 case HDMI_AUDIO_CODING_TYPE_MPEG2
:
774 case HDMI_AUDIO_CODING_TYPE_AAC_LC
:
776 case HDMI_AUDIO_CODING_TYPE_DTS
:
778 case HDMI_AUDIO_CODING_TYPE_ATRAC
:
780 case HDMI_AUDIO_CODING_TYPE_DSD
:
781 return "One Bit Audio";
782 case HDMI_AUDIO_CODING_TYPE_EAC3
:
783 return "Dolby Digital +";
784 case HDMI_AUDIO_CODING_TYPE_DTS_HD
:
786 case HDMI_AUDIO_CODING_TYPE_MLP
:
788 case HDMI_AUDIO_CODING_TYPE_DST
:
790 case HDMI_AUDIO_CODING_TYPE_WMA_PRO
:
792 case HDMI_AUDIO_CODING_TYPE_CXT
:
793 return "Refer to CXT";
799 hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size
)
801 switch (sample_size
) {
802 case HDMI_AUDIO_SAMPLE_SIZE_STREAM
:
803 return "Refer to Stream Header";
804 case HDMI_AUDIO_SAMPLE_SIZE_16
:
806 case HDMI_AUDIO_SAMPLE_SIZE_20
:
808 case HDMI_AUDIO_SAMPLE_SIZE_24
:
815 hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq
)
818 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM
:
819 return "Refer to Stream Header";
820 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000
:
822 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100
:
823 return "44.1 kHz (CD)";
824 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000
:
826 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200
:
828 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000
:
830 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400
:
832 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000
:
839 hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx
)
841 if (ctx
< 0 || ctx
> 0x1f)
845 case HDMI_AUDIO_CODING_TYPE_EXT_CT
:
846 return "Refer to CT";
847 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC
:
849 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2
:
851 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND
:
852 return "MPEG SURROUND";
853 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC
:
854 return "MPEG-4 HE AAC";
855 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2
:
856 return "MPEG-4 HE AAC v2";
857 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC
:
858 return "MPEG-4 AAC LC";
859 case HDMI_AUDIO_CODING_TYPE_EXT_DRA
:
861 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND
:
862 return "MPEG-4 HE AAC + MPEG Surround";
863 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND
:
864 return "MPEG-4 AAC LC + MPEG Surround";
870 * hdmi_audio_infoframe_log() - log info of HDMI AUDIO infoframe
871 * @level: logging level
873 * @frame: HDMI AUDIO infoframe
875 static void hdmi_audio_infoframe_log(const char *level
,
877 struct hdmi_audio_infoframe
*frame
)
879 hdmi_infoframe_log_header(level
, dev
,
880 (struct hdmi_any_infoframe
*)frame
);
883 hdmi_log(" channels: %u\n", frame
->channels
- 1);
885 hdmi_log(" channels: Refer to stream header\n");
886 hdmi_log(" coding type: %s\n",
887 hdmi_audio_coding_type_get_name(frame
->coding_type
));
888 hdmi_log(" sample size: %s\n",
889 hdmi_audio_sample_size_get_name(frame
->sample_size
));
890 hdmi_log(" sample frequency: %s\n",
891 hdmi_audio_sample_frequency_get_name(frame
->sample_frequency
));
892 hdmi_log(" coding type ext: %s\n",
893 hdmi_audio_coding_type_ext_get_name(frame
->coding_type_ext
));
894 hdmi_log(" channel allocation: 0x%x\n",
895 frame
->channel_allocation
);
896 hdmi_log(" level shift value: %u dB\n",
897 frame
->level_shift_value
);
898 hdmi_log(" downmix inhibit: %s\n",
899 frame
->downmix_inhibit
? "Yes" : "No");
903 hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct
)
905 if (s3d_struct
< 0 || s3d_struct
> 0xf)
908 switch (s3d_struct
) {
909 case HDMI_3D_STRUCTURE_FRAME_PACKING
:
910 return "Frame Packing";
911 case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE
:
912 return "Field Alternative";
913 case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE
:
914 return "Line Alternative";
915 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL
:
916 return "Side-by-side (Full)";
917 case HDMI_3D_STRUCTURE_L_DEPTH
:
919 case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH
:
920 return "L + Depth + Graphics + Graphics-depth";
921 case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM
:
922 return "Top-and-Bottom";
923 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
:
924 return "Side-by-side (Half)";
932 * hdmi_vendor_infoframe_log() - log info of HDMI VENDOR infoframe
933 * @level: logging level
935 * @frame: HDMI VENDOR infoframe
938 hdmi_vendor_any_infoframe_log(const char *level
,
940 union hdmi_vendor_any_infoframe
*frame
)
942 struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
944 hdmi_infoframe_log_header(level
, dev
,
945 (struct hdmi_any_infoframe
*)frame
);
947 if (frame
->any
.oui
!= HDMI_IEEE_OUI
) {
948 hdmi_log(" not a HDMI vendor infoframe\n");
951 if (hvf
->vic
== 0 && hvf
->s3d_struct
== HDMI_3D_STRUCTURE_INVALID
) {
952 hdmi_log(" empty frame\n");
957 hdmi_log(" HDMI VIC: %u\n", hvf
->vic
);
958 if (hvf
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
) {
959 hdmi_log(" 3D structure: %s\n",
960 hdmi_3d_structure_get_name(hvf
->s3d_struct
));
961 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
962 hdmi_log(" 3D extension data: %d\n",
968 * hdmi_infoframe_log() - log info of HDMI infoframe
969 * @level: logging level
971 * @frame: HDMI infoframe
973 void hdmi_infoframe_log(const char *level
,
975 union hdmi_infoframe
*frame
)
977 switch (frame
->any
.type
) {
978 case HDMI_INFOFRAME_TYPE_AVI
:
979 hdmi_avi_infoframe_log(level
, dev
, &frame
->avi
);
981 case HDMI_INFOFRAME_TYPE_SPD
:
982 hdmi_spd_infoframe_log(level
, dev
, &frame
->spd
);
984 case HDMI_INFOFRAME_TYPE_AUDIO
:
985 hdmi_audio_infoframe_log(level
, dev
, &frame
->audio
);
987 case HDMI_INFOFRAME_TYPE_VENDOR
:
988 hdmi_vendor_any_infoframe_log(level
, dev
, &frame
->vendor
);
992 EXPORT_SYMBOL(hdmi_infoframe_log
);
995 * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
996 * @buffer: source buffer
997 * @frame: HDMI AVI infoframe
999 * Unpacks the information contained in binary @buffer into a structured
1000 * @frame of the HDMI Auxiliary Video (AVI) information frame.
1001 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1004 * Returns 0 on success or a negative error code on failure.
1006 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe
*frame
,
1012 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AVI
||
1014 ptr
[2] != HDMI_AVI_INFOFRAME_SIZE
)
1017 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AVI
)) != 0)
1020 ret
= hdmi_avi_infoframe_init(frame
);
1024 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1026 frame
->colorspace
= (ptr
[0] >> 5) & 0x3;
1028 frame
->active_aspect
= ptr
[1] & 0xf;
1030 frame
->top_bar
= (ptr
[5] << 8) + ptr
[6];
1031 frame
->bottom_bar
= (ptr
[7] << 8) + ptr
[8];
1034 frame
->left_bar
= (ptr
[9] << 8) + ptr
[10];
1035 frame
->right_bar
= (ptr
[11] << 8) + ptr
[12];
1037 frame
->scan_mode
= ptr
[0] & 0x3;
1039 frame
->colorimetry
= (ptr
[1] >> 6) & 0x3;
1040 frame
->picture_aspect
= (ptr
[1] >> 4) & 0x3;
1041 frame
->active_aspect
= ptr
[1] & 0xf;
1043 frame
->itc
= ptr
[2] & 0x80 ? true : false;
1044 frame
->extended_colorimetry
= (ptr
[2] >> 4) & 0x7;
1045 frame
->quantization_range
= (ptr
[2] >> 2) & 0x3;
1046 frame
->nups
= ptr
[2] & 0x3;
1048 frame
->video_code
= ptr
[3] & 0x7f;
1049 frame
->ycc_quantization_range
= (ptr
[4] >> 6) & 0x3;
1050 frame
->content_type
= (ptr
[4] >> 4) & 0x3;
1052 frame
->pixel_repeat
= ptr
[4] & 0xf;
1058 * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
1059 * @buffer: source buffer
1060 * @frame: HDMI SPD infoframe
1062 * Unpacks the information contained in binary @buffer into a structured
1063 * @frame of the HDMI Source Product Description (SPD) information frame.
1064 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1067 * Returns 0 on success or a negative error code on failure.
1069 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe
*frame
,
1075 if (ptr
[0] != HDMI_INFOFRAME_TYPE_SPD
||
1077 ptr
[2] != HDMI_SPD_INFOFRAME_SIZE
) {
1081 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(SPD
)) != 0)
1084 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1086 ret
= hdmi_spd_infoframe_init(frame
, ptr
, ptr
+ 8);
1090 frame
->sdi
= ptr
[24];
1096 * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
1097 * @buffer: source buffer
1098 * @frame: HDMI Audio infoframe
1100 * Unpacks the information contained in binary @buffer into a structured
1101 * @frame of the HDMI Audio information frame.
1102 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1105 * Returns 0 on success or a negative error code on failure.
1107 static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe
*frame
,
1113 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AUDIO
||
1115 ptr
[2] != HDMI_AUDIO_INFOFRAME_SIZE
) {
1119 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AUDIO
)) != 0)
1122 ret
= hdmi_audio_infoframe_init(frame
);
1126 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1128 frame
->channels
= ptr
[0] & 0x7;
1129 frame
->coding_type
= (ptr
[0] >> 4) & 0xf;
1130 frame
->sample_size
= ptr
[1] & 0x3;
1131 frame
->sample_frequency
= (ptr
[1] >> 2) & 0x7;
1132 frame
->coding_type_ext
= ptr
[2] & 0x1f;
1133 frame
->channel_allocation
= ptr
[3];
1134 frame
->level_shift_value
= (ptr
[4] >> 3) & 0xf;
1135 frame
->downmix_inhibit
= ptr
[4] & 0x80 ? true : false;
1141 * hdmi_vendor_infoframe_unpack() - unpack binary buffer to a HDMI vendor infoframe
1142 * @buffer: source buffer
1143 * @frame: HDMI Vendor infoframe
1145 * Unpacks the information contained in binary @buffer into a structured
1146 * @frame of the HDMI Vendor information frame.
1147 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1150 * Returns 0 on success or a negative error code on failure.
1153 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe
*frame
,
1159 u8 hdmi_video_format
;
1160 struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
1162 if (ptr
[0] != HDMI_INFOFRAME_TYPE_VENDOR
||
1164 (ptr
[2] != 5 && ptr
[2] != 6))
1169 if (hdmi_infoframe_checksum(buffer
,
1170 HDMI_INFOFRAME_HEADER_SIZE
+ length
) != 0)
1173 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1176 if ((ptr
[0] != 0x03) ||
1181 hdmi_video_format
= ptr
[3] >> 5;
1183 if (hdmi_video_format
> 0x2)
1186 ret
= hdmi_vendor_infoframe_init(hvf
);
1190 hvf
->length
= length
;
1192 if (hdmi_video_format
== 0x1) {
1194 } else if (hdmi_video_format
== 0x2) {
1195 hvf
->s3d_struct
= ptr
[4] >> 4;
1196 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
) {
1198 hvf
->s3d_ext_data
= ptr
[5] >> 4;
1208 * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
1209 * @buffer: source buffer
1210 * @frame: HDMI infoframe
1212 * Unpacks the information contained in binary buffer @buffer into a structured
1213 * @frame of a HDMI infoframe.
1214 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1217 * Returns 0 on success or a negative error code on failure.
1219 int hdmi_infoframe_unpack(union hdmi_infoframe
*frame
, void *buffer
)
1225 case HDMI_INFOFRAME_TYPE_AVI
:
1226 ret
= hdmi_avi_infoframe_unpack(&frame
->avi
, buffer
);
1228 case HDMI_INFOFRAME_TYPE_SPD
:
1229 ret
= hdmi_spd_infoframe_unpack(&frame
->spd
, buffer
);
1231 case HDMI_INFOFRAME_TYPE_AUDIO
:
1232 ret
= hdmi_audio_infoframe_unpack(&frame
->audio
, buffer
);
1234 case HDMI_INFOFRAME_TYPE_VENDOR
:
1235 ret
= hdmi_vendor_any_infoframe_unpack(&frame
->vendor
, buffer
);
1244 EXPORT_SYMBOL(hdmi_infoframe_unpack
);