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 <sys/cdefs.h>
25 __FBSDID("$FreeBSD$");
27 #include <sys/param.h>
28 #include <sys/systm.h>
30 #include <arm/nvidia/drm2/hdmi.h>
32 #define EXPORT_SYMBOL(x)
34 #define BIT(x) (1U << (x))
36 #define hdmi_log(fmt, ...) printf(fmt, ##__VA_ARGS__)
38 static uint8_t hdmi_infoframe_checksum(uint8_t *ptr, size_t size)
43 /* compute checksum */
44 for (i = 0; i < size; i++)
50 static void hdmi_infoframe_set_checksum(void *buffer, size_t size)
52 uint8_t *ptr = buffer;
54 ptr[3] = hdmi_infoframe_checksum(buffer, size);
58 * hdmi_avi_infoframe_init() - initialize an HDMI AVI infoframe
59 * @frame: HDMI AVI infoframe
61 * Returns 0 on success or a negative error code on failure.
63 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame)
65 memset(frame, 0, sizeof(*frame));
67 frame->type = HDMI_INFOFRAME_TYPE_AVI;
69 frame->length = HDMI_AVI_INFOFRAME_SIZE;
73 EXPORT_SYMBOL(hdmi_avi_infoframe_init);
76 * hdmi_avi_infoframe_pack() - write HDMI AVI infoframe to binary buffer
77 * @frame: HDMI AVI infoframe
78 * @buffer: destination buffer
79 * @size: size of buffer
81 * Packs the information contained in the @frame structure into a binary
82 * representation that can be written into the corresponding controller
83 * registers. Also computes the checksum as required by section 5.3.5 of
84 * the HDMI 1.4 specification.
86 * Returns the number of bytes packed into the binary buffer or a negative
87 * error code on failure.
89 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
92 uint8_t *ptr = buffer;
95 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
100 memset(buffer, 0, size);
102 ptr[0] = frame->type;
103 ptr[1] = frame->version;
104 ptr[2] = frame->length;
105 ptr[3] = 0; /* checksum */
107 /* start infoframe payload */
108 ptr += HDMI_INFOFRAME_HEADER_SIZE;
110 ptr[0] = ((frame->colorspace & 0x3) << 5) | (frame->scan_mode & 0x3);
113 * Data byte 1, bit 4 has to be set if we provide the active format
116 if (frame->active_aspect & 0xf)
119 /* Bit 3 and 2 indicate if we transmit horizontal/vertical bar data */
120 if (frame->top_bar || frame->bottom_bar)
123 if (frame->left_bar || frame->right_bar)
126 ptr[1] = ((frame->colorimetry & 0x3) << 6) |
127 ((frame->picture_aspect & 0x3) << 4) |
128 (frame->active_aspect & 0xf);
130 ptr[2] = ((frame->extended_colorimetry & 0x7) << 4) |
131 ((frame->quantization_range & 0x3) << 2) |
137 ptr[3] = frame->video_code & 0x7f;
139 ptr[4] = ((frame->ycc_quantization_range & 0x3) << 6) |
140 ((frame->content_type & 0x3) << 4) |
141 (frame->pixel_repeat & 0xf);
143 ptr[5] = frame->top_bar & 0xff;
144 ptr[6] = (frame->top_bar >> 8) & 0xff;
145 ptr[7] = frame->bottom_bar & 0xff;
146 ptr[8] = (frame->bottom_bar >> 8) & 0xff;
147 ptr[9] = frame->left_bar & 0xff;
148 ptr[10] = (frame->left_bar >> 8) & 0xff;
149 ptr[11] = frame->right_bar & 0xff;
150 ptr[12] = (frame->right_bar >> 8) & 0xff;
152 hdmi_infoframe_set_checksum(buffer, length);
156 EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
159 * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
160 * @frame: HDMI SPD infoframe
161 * @vendor: vendor string
162 * @product: product string
164 * Returns 0 on success or a negative error code on failure.
166 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
167 const char *vendor, const char *product)
169 memset(frame, 0, sizeof(*frame));
171 frame->type = HDMI_INFOFRAME_TYPE_SPD;
173 frame->length = HDMI_SPD_INFOFRAME_SIZE;
175 strncpy(frame->vendor, vendor, sizeof(frame->vendor));
176 strncpy(frame->product, product, sizeof(frame->product));
180 EXPORT_SYMBOL(hdmi_spd_infoframe_init);
183 * hdmi_spd_infoframe_pack() - write HDMI SPD infoframe to binary buffer
184 * @frame: HDMI SPD infoframe
185 * @buffer: destination buffer
186 * @size: size of buffer
188 * Packs the information contained in the @frame structure into a binary
189 * representation that can be written into the corresponding controller
190 * registers. Also computes the checksum as required by section 5.3.5 of
191 * the HDMI 1.4 specification.
193 * Returns the number of bytes packed into the binary buffer or a negative
194 * error code on failure.
196 ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
199 uint8_t *ptr = buffer;
202 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
207 memset(buffer, 0, size);
209 ptr[0] = frame->type;
210 ptr[1] = frame->version;
211 ptr[2] = frame->length;
212 ptr[3] = 0; /* checksum */
214 /* start infoframe payload */
215 ptr += HDMI_INFOFRAME_HEADER_SIZE;
217 memcpy(ptr, frame->vendor, sizeof(frame->vendor));
218 memcpy(ptr + 8, frame->product, sizeof(frame->product));
220 ptr[24] = frame->sdi;
222 hdmi_infoframe_set_checksum(buffer, length);
226 EXPORT_SYMBOL(hdmi_spd_infoframe_pack);
229 * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
230 * @frame: HDMI audio infoframe
232 * Returns 0 on success or a negative error code on failure.
234 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame)
236 memset(frame, 0, sizeof(*frame));
238 frame->type = HDMI_INFOFRAME_TYPE_AUDIO;
240 frame->length = HDMI_AUDIO_INFOFRAME_SIZE;
244 EXPORT_SYMBOL(hdmi_audio_infoframe_init);
247 * hdmi_audio_infoframe_pack() - write HDMI audio infoframe to binary buffer
248 * @frame: HDMI audio infoframe
249 * @buffer: destination buffer
250 * @size: size of buffer
252 * Packs the information contained in the @frame structure into a binary
253 * representation that can be written into the corresponding controller
254 * registers. Also computes the checksum as required by section 5.3.5 of
255 * the HDMI 1.4 specification.
257 * Returns the number of bytes packed into the binary buffer or a negative
258 * error code on failure.
260 ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
261 void *buffer, size_t size)
263 unsigned char channels;
264 uint8_t *ptr = buffer;
267 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
272 memset(buffer, 0, size);
274 if (frame->channels >= 2)
275 channels = frame->channels - 1;
279 ptr[0] = frame->type;
280 ptr[1] = frame->version;
281 ptr[2] = frame->length;
282 ptr[3] = 0; /* checksum */
284 /* start infoframe payload */
285 ptr += HDMI_INFOFRAME_HEADER_SIZE;
287 ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7);
288 ptr[1] = ((frame->sample_frequency & 0x7) << 2) |
289 (frame->sample_size & 0x3);
290 ptr[2] = frame->coding_type_ext & 0x1f;
291 ptr[3] = frame->channel_allocation;
292 ptr[4] = (frame->level_shift_value & 0xf) << 3;
294 if (frame->downmix_inhibit)
297 hdmi_infoframe_set_checksum(buffer, length);
301 EXPORT_SYMBOL(hdmi_audio_infoframe_pack);
304 * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
305 * @frame: HDMI vendor infoframe
307 * Returns 0 on success or a negative error code on failure.
309 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
311 memset(frame, 0, sizeof(*frame));
313 frame->type = HDMI_INFOFRAME_TYPE_VENDOR;
316 frame->oui = HDMI_IEEE_OUI;
319 * 0 is a valid value for s3d_struct, so we use a special "not set"
322 frame->s3d_struct = HDMI_3D_STRUCTURE_INVALID;
326 EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
329 * hdmi_vendor_infoframe_pack() - write a HDMI vendor infoframe to binary buffer
330 * @frame: HDMI infoframe
331 * @buffer: destination buffer
332 * @size: size of buffer
334 * Packs the information contained in the @frame structure into a binary
335 * representation that can be written into the corresponding controller
336 * registers. Also computes the checksum as required by section 5.3.5 of
337 * the HDMI 1.4 specification.
339 * Returns the number of bytes packed into the binary buffer or a negative
340 * error code on failure.
342 ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
343 void *buffer, size_t size)
345 uint8_t *ptr = buffer;
348 /* empty info frame */
349 if (frame->vic == 0 && frame->s3d_struct == HDMI_3D_STRUCTURE_INVALID)
352 /* only one of those can be supplied */
353 if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
356 /* for side by side (half) we also need to provide 3D_Ext_Data */
357 if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
362 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
367 memset(buffer, 0, size);
369 ptr[0] = frame->type;
370 ptr[1] = frame->version;
371 ptr[2] = frame->length;
372 ptr[3] = 0; /* checksum */
380 ptr[7] = 0x1 << 5; /* video format */
383 ptr[7] = 0x2 << 5; /* video format */
384 ptr[8] = (frame->s3d_struct & 0xf) << 4;
385 if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
386 ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
389 hdmi_infoframe_set_checksum(buffer, length);
393 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack);
396 * hdmi_vendor_any_infoframe_pack() - write a vendor infoframe to binary buffer
399 hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe *frame,
400 void *buffer, size_t size)
402 /* we only know about HDMI vendor infoframes */
403 if (frame->any.oui != HDMI_IEEE_OUI)
406 return hdmi_vendor_infoframe_pack(&frame->hdmi, buffer, size);
410 * hdmi_infoframe_pack() - write a HDMI infoframe to binary buffer
411 * @frame: HDMI infoframe
412 * @buffer: destination buffer
413 * @size: size of buffer
415 * Packs the information contained in the @frame structure into a binary
416 * representation that can be written into the corresponding controller
417 * registers. Also computes the checksum as required by section 5.3.5 of
418 * the HDMI 1.4 specification.
420 * Returns the number of bytes packed into the binary buffer or a negative
421 * error code on failure.
424 hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size)
428 switch (frame->any.type) {
429 case HDMI_INFOFRAME_TYPE_AVI:
430 length = hdmi_avi_infoframe_pack(&frame->avi, buffer, size);
432 case HDMI_INFOFRAME_TYPE_SPD:
433 length = hdmi_spd_infoframe_pack(&frame->spd, buffer, size);
435 case HDMI_INFOFRAME_TYPE_AUDIO:
436 length = hdmi_audio_infoframe_pack(&frame->audio, buffer, size);
438 case HDMI_INFOFRAME_TYPE_VENDOR:
439 length = hdmi_vendor_any_infoframe_pack(&frame->vendor,
443 printf("Bad infoframe type %d\n", frame->any.type);
449 EXPORT_SYMBOL(hdmi_infoframe_pack);
451 static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type)
453 if (type < 0x80 || type > 0x9f)
456 case HDMI_INFOFRAME_TYPE_VENDOR:
458 case HDMI_INFOFRAME_TYPE_AVI:
459 return "Auxiliary Video Information (AVI)";
460 case HDMI_INFOFRAME_TYPE_SPD:
461 return "Source Product Description (SPD)";
462 case HDMI_INFOFRAME_TYPE_AUDIO:
468 static void hdmi_infoframe_log_header(struct hdmi_any_infoframe *frame)
470 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
471 hdmi_infoframe_type_get_name(frame->type),
472 frame->version, frame->length);
475 static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace)
477 switch (colorspace) {
478 case HDMI_COLORSPACE_RGB:
480 case HDMI_COLORSPACE_YUV422:
481 return "YCbCr 4:2:2";
482 case HDMI_COLORSPACE_YUV444:
483 return "YCbCr 4:4:4";
484 case HDMI_COLORSPACE_YUV420:
485 return "YCbCr 4:2:0";
486 case HDMI_COLORSPACE_RESERVED4:
487 return "Reserved (4)";
488 case HDMI_COLORSPACE_RESERVED5:
489 return "Reserved (5)";
490 case HDMI_COLORSPACE_RESERVED6:
491 return "Reserved (6)";
492 case HDMI_COLORSPACE_IDO_DEFINED:
493 return "IDO Defined";
498 static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode)
501 case HDMI_SCAN_MODE_NONE:
503 case HDMI_SCAN_MODE_OVERSCAN:
505 case HDMI_SCAN_MODE_UNDERSCAN:
507 case HDMI_SCAN_MODE_RESERVED:
513 static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry)
515 switch (colorimetry) {
516 case HDMI_COLORIMETRY_NONE:
518 case HDMI_COLORIMETRY_ITU_601:
520 case HDMI_COLORIMETRY_ITU_709:
522 case HDMI_COLORIMETRY_EXTENDED:
529 hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect)
531 switch (picture_aspect) {
532 case HDMI_PICTURE_ASPECT_NONE:
534 case HDMI_PICTURE_ASPECT_4_3:
536 case HDMI_PICTURE_ASPECT_16_9:
538 case HDMI_PICTURE_ASPECT_RESERVED:
545 hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect)
547 if (active_aspect > 0xf)
550 switch (active_aspect) {
551 case HDMI_ACTIVE_ASPECT_16_9_TOP:
553 case HDMI_ACTIVE_ASPECT_14_9_TOP:
555 case HDMI_ACTIVE_ASPECT_16_9_CENTER:
556 return "16:9 Center";
557 case HDMI_ACTIVE_ASPECT_PICTURE:
558 return "Same as Picture";
559 case HDMI_ACTIVE_ASPECT_4_3:
561 case HDMI_ACTIVE_ASPECT_16_9:
563 case HDMI_ACTIVE_ASPECT_14_9:
565 case HDMI_ACTIVE_ASPECT_4_3_SP_14_9:
566 return "4:3 SP 14:9";
567 case HDMI_ACTIVE_ASPECT_16_9_SP_14_9:
568 return "16:9 SP 14:9";
569 case HDMI_ACTIVE_ASPECT_16_9_SP_4_3:
570 return "16:9 SP 4:3";
576 hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col)
579 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601:
581 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709:
583 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601:
585 case HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601:
586 return "Adobe YCC 601";
587 case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB:
589 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM:
590 return "BT.2020 Constant Luminance";
591 case HDMI_EXTENDED_COLORIMETRY_BT2020:
593 case HDMI_EXTENDED_COLORIMETRY_RESERVED:
600 hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange)
603 case HDMI_QUANTIZATION_RANGE_DEFAULT:
605 case HDMI_QUANTIZATION_RANGE_LIMITED:
607 case HDMI_QUANTIZATION_RANGE_FULL:
609 case HDMI_QUANTIZATION_RANGE_RESERVED:
615 static const char *hdmi_nups_get_name(enum hdmi_nups nups)
618 case HDMI_NUPS_UNKNOWN:
619 return "Unknown Non-uniform Scaling";
620 case HDMI_NUPS_HORIZONTAL:
621 return "Horizontally Scaled";
622 case HDMI_NUPS_VERTICAL:
623 return "Vertically Scaled";
625 return "Horizontally and Vertically Scaled";
631 hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange)
634 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED:
636 case HDMI_YCC_QUANTIZATION_RANGE_FULL:
643 hdmi_content_type_get_name(enum hdmi_content_type content_type)
645 switch (content_type) {
646 case HDMI_CONTENT_TYPE_GRAPHICS:
648 case HDMI_CONTENT_TYPE_PHOTO:
650 case HDMI_CONTENT_TYPE_CINEMA:
652 case HDMI_CONTENT_TYPE_GAME:
659 * hdmi_avi_infoframe_log() - log info of HDMI AVI infoframe
660 * @level: logging level
662 * @frame: HDMI AVI infoframe
664 static void hdmi_avi_infoframe_log(struct hdmi_avi_infoframe *frame)
666 hdmi_infoframe_log_header((struct hdmi_any_infoframe *)frame);
668 hdmi_log(" colorspace: %s\n",
669 hdmi_colorspace_get_name(frame->colorspace));
670 hdmi_log(" scan mode: %s\n",
671 hdmi_scan_mode_get_name(frame->scan_mode));
672 hdmi_log(" colorimetry: %s\n",
673 hdmi_colorimetry_get_name(frame->colorimetry));
674 hdmi_log(" picture aspect: %s\n",
675 hdmi_picture_aspect_get_name(frame->picture_aspect));
676 hdmi_log(" active aspect: %s\n",
677 hdmi_active_aspect_get_name(frame->active_aspect));
678 hdmi_log(" itc: %s\n", frame->itc ? "IT Content" : "No Data");
679 hdmi_log(" extended colorimetry: %s\n",
680 hdmi_extended_colorimetry_get_name(frame->extended_colorimetry));
681 hdmi_log(" quantization range: %s\n",
682 hdmi_quantization_range_get_name(frame->quantization_range));
683 hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame->nups));
684 hdmi_log(" video code: %u\n", frame->video_code);
685 hdmi_log(" ycc quantization range: %s\n",
686 hdmi_ycc_quantization_range_get_name(frame->ycc_quantization_range));
687 hdmi_log(" hdmi content type: %s\n",
688 hdmi_content_type_get_name(frame->content_type));
689 hdmi_log(" pixel repeat: %u\n", frame->pixel_repeat);
690 hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
691 frame->top_bar, frame->bottom_bar,
692 frame->left_bar, frame->right_bar);
695 static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi)
699 case HDMI_SPD_SDI_UNKNOWN:
701 case HDMI_SPD_SDI_DSTB:
702 return "Digital STB";
703 case HDMI_SPD_SDI_DVDP:
705 case HDMI_SPD_SDI_DVHS:
707 case HDMI_SPD_SDI_HDDVR:
708 return "HDD Videorecorder";
709 case HDMI_SPD_SDI_DVC:
711 case HDMI_SPD_SDI_DSC:
713 case HDMI_SPD_SDI_VCD:
715 case HDMI_SPD_SDI_GAME:
717 case HDMI_SPD_SDI_PC:
719 case HDMI_SPD_SDI_BD:
720 return "Blu-Ray Disc (BD)";
721 case HDMI_SPD_SDI_SACD:
722 return "Super Audio CD";
723 case HDMI_SPD_SDI_HDDVD:
725 case HDMI_SPD_SDI_PMP:
732 * hdmi_spd_infoframe_log() - log info of HDMI SPD infoframe
733 * @level: logging level
735 * @frame: HDMI SPD infoframe
737 static void hdmi_spd_infoframe_log(struct hdmi_spd_infoframe *frame)
741 hdmi_infoframe_log_header((struct hdmi_any_infoframe *)frame);
743 memset(buf, 0, sizeof(buf));
745 strncpy(buf, frame->vendor, 8);
746 hdmi_log(" vendor: %s\n", buf);
747 strncpy(buf, frame->product, 16);
748 hdmi_log(" product: %s\n", buf);
749 hdmi_log(" source device information: %s (0x%x)\n",
750 hdmi_spd_sdi_get_name(frame->sdi), frame->sdi);
754 hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type)
756 switch (coding_type) {
757 case HDMI_AUDIO_CODING_TYPE_STREAM:
758 return "Refer to Stream Header";
759 case HDMI_AUDIO_CODING_TYPE_PCM:
761 case HDMI_AUDIO_CODING_TYPE_AC3:
763 case HDMI_AUDIO_CODING_TYPE_MPEG1:
765 case HDMI_AUDIO_CODING_TYPE_MP3:
767 case HDMI_AUDIO_CODING_TYPE_MPEG2:
769 case HDMI_AUDIO_CODING_TYPE_AAC_LC:
771 case HDMI_AUDIO_CODING_TYPE_DTS:
773 case HDMI_AUDIO_CODING_TYPE_ATRAC:
775 case HDMI_AUDIO_CODING_TYPE_DSD:
776 return "One Bit Audio";
777 case HDMI_AUDIO_CODING_TYPE_EAC3:
778 return "Dolby Digital +";
779 case HDMI_AUDIO_CODING_TYPE_DTS_HD:
781 case HDMI_AUDIO_CODING_TYPE_MLP:
783 case HDMI_AUDIO_CODING_TYPE_DST:
785 case HDMI_AUDIO_CODING_TYPE_WMA_PRO:
787 case HDMI_AUDIO_CODING_TYPE_CXT:
788 return "Refer to CXT";
794 hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size)
796 switch (sample_size) {
797 case HDMI_AUDIO_SAMPLE_SIZE_STREAM:
798 return "Refer to Stream Header";
799 case HDMI_AUDIO_SAMPLE_SIZE_16:
801 case HDMI_AUDIO_SAMPLE_SIZE_20:
803 case HDMI_AUDIO_SAMPLE_SIZE_24:
810 hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq)
813 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM:
814 return "Refer to Stream Header";
815 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000:
817 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100:
818 return "44.1 kHz (CD)";
819 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000:
821 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200:
823 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000:
825 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400:
827 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000:
834 hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx)
838 case HDMI_AUDIO_CODING_TYPE_EXT_CT:
839 return "Refer to CT";
840 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC:
842 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2:
844 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND:
845 return "MPEG SURROUND";
846 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC:
847 return "MPEG-4 HE AAC";
848 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2:
849 return "MPEG-4 HE AAC v2";
850 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC:
851 return "MPEG-4 AAC LC";
852 case HDMI_AUDIO_CODING_TYPE_EXT_DRA:
854 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND:
855 return "MPEG-4 HE AAC + MPEG Surround";
856 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND:
857 return "MPEG-4 AAC LC + MPEG Surround";
863 * hdmi_audio_infoframe_log() - log info of HDMI AUDIO infoframe
864 * @level: logging level
866 * @frame: HDMI AUDIO infoframe
868 static void hdmi_audio_infoframe_log(struct hdmi_audio_infoframe *frame)
870 hdmi_infoframe_log_header((struct hdmi_any_infoframe *)frame);
873 hdmi_log(" channels: %u\n", frame->channels - 1);
875 hdmi_log(" channels: Refer to stream header\n");
876 hdmi_log(" coding type: %s\n",
877 hdmi_audio_coding_type_get_name(frame->coding_type));
878 hdmi_log(" sample size: %s\n",
879 hdmi_audio_sample_size_get_name(frame->sample_size));
880 hdmi_log(" sample frequency: %s\n",
881 hdmi_audio_sample_frequency_get_name(frame->sample_frequency));
882 hdmi_log(" coding type ext: %s\n",
883 hdmi_audio_coding_type_ext_get_name(frame->coding_type_ext));
884 hdmi_log(" channel allocation: 0x%x\n",
885 frame->channel_allocation);
886 hdmi_log(" level shift value: %u dB\n",
887 frame->level_shift_value);
888 hdmi_log(" downmix inhibit: %s\n",
889 frame->downmix_inhibit ? "Yes" : "No");
893 hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct)
895 if (s3d_struct < 0 || s3d_struct > 0xf)
898 switch (s3d_struct) {
899 case HDMI_3D_STRUCTURE_FRAME_PACKING:
900 return "Frame Packing";
901 case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE:
902 return "Field Alternative";
903 case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE:
904 return "Line Alternative";
905 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL:
906 return "Side-by-side (Full)";
907 case HDMI_3D_STRUCTURE_L_DEPTH:
909 case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH:
910 return "L + Depth + Graphics + Graphics-depth";
911 case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM:
912 return "Top-and-Bottom";
913 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF:
914 return "Side-by-side (Half)";
922 * hdmi_vendor_infoframe_log() - log info of HDMI VENDOR infoframe
923 * @level: logging level
925 * @frame: HDMI VENDOR infoframe
928 hdmi_vendor_any_infoframe_log(union hdmi_vendor_any_infoframe *frame)
930 struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
932 hdmi_infoframe_log_header((struct hdmi_any_infoframe *)frame);
934 if (frame->any.oui != HDMI_IEEE_OUI) {
935 hdmi_log(" not a HDMI vendor infoframe\n");
938 if (hvf->vic == 0 && hvf->s3d_struct == HDMI_3D_STRUCTURE_INVALID) {
939 hdmi_log(" empty frame\n");
944 hdmi_log(" HDMI VIC: %u\n", hvf->vic);
945 if (hvf->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
946 hdmi_log(" 3D structure: %s\n",
947 hdmi_3d_structure_get_name(hvf->s3d_struct));
948 if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
949 hdmi_log(" 3D extension data: %d\n",
955 * hdmi_infoframe_log() - log info of HDMI infoframe
956 * @level: logging level
958 * @frame: HDMI infoframe
960 void hdmi_infoframe_log(union hdmi_infoframe *frame)
962 switch (frame->any.type) {
963 case HDMI_INFOFRAME_TYPE_AVI:
964 hdmi_avi_infoframe_log(&frame->avi);
966 case HDMI_INFOFRAME_TYPE_SPD:
967 hdmi_spd_infoframe_log(&frame->spd);
969 case HDMI_INFOFRAME_TYPE_AUDIO:
970 hdmi_audio_infoframe_log(&frame->audio);
972 case HDMI_INFOFRAME_TYPE_VENDOR:
973 hdmi_vendor_any_infoframe_log(&frame->vendor);
977 EXPORT_SYMBOL(hdmi_infoframe_log);
980 * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
981 * @buffer: source buffer
982 * @frame: HDMI AVI infoframe
984 * Unpacks the information contained in binary @buffer into a structured
985 * @frame of the HDMI Auxiliary Video (AVI) information frame.
986 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
989 * Returns 0 on success or a negative error code on failure.
991 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
994 uint8_t *ptr = buffer;
997 if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
999 ptr[2] != HDMI_AVI_INFOFRAME_SIZE)
1002 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AVI)) != 0)
1005 ret = hdmi_avi_infoframe_init(frame);
1009 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1011 frame->colorspace = (ptr[0] >> 5) & 0x3;
1013 frame->active_aspect = ptr[1] & 0xf;
1015 frame->top_bar = (ptr[5] << 8) + ptr[6];
1016 frame->bottom_bar = (ptr[7] << 8) + ptr[8];
1019 frame->left_bar = (ptr[9] << 8) + ptr[10];
1020 frame->right_bar = (ptr[11] << 8) + ptr[12];
1022 frame->scan_mode = ptr[0] & 0x3;
1024 frame->colorimetry = (ptr[1] >> 6) & 0x3;
1025 frame->picture_aspect = (ptr[1] >> 4) & 0x3;
1026 frame->active_aspect = ptr[1] & 0xf;
1028 frame->itc = ptr[2] & 0x80 ? true : false;
1029 frame->extended_colorimetry = (ptr[2] >> 4) & 0x7;
1030 frame->quantization_range = (ptr[2] >> 2) & 0x3;
1031 frame->nups = ptr[2] & 0x3;
1033 frame->video_code = ptr[3] & 0x7f;
1034 frame->ycc_quantization_range = (ptr[4] >> 6) & 0x3;
1035 frame->content_type = (ptr[4] >> 4) & 0x3;
1037 frame->pixel_repeat = ptr[4] & 0xf;
1043 * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
1044 * @buffer: source buffer
1045 * @frame: HDMI SPD infoframe
1047 * Unpacks the information contained in binary @buffer into a structured
1048 * @frame of the HDMI Source Product Description (SPD) information frame.
1049 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1052 * Returns 0 on success or a negative error code on failure.
1054 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
1057 uint8_t *ptr = buffer;
1060 if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
1062 ptr[2] != HDMI_SPD_INFOFRAME_SIZE) {
1066 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(SPD)) != 0)
1069 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1071 ret = hdmi_spd_infoframe_init(frame, ptr, ptr + 8);
1075 frame->sdi = ptr[24];
1081 * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
1082 * @buffer: source buffer
1083 * @frame: HDMI Audio infoframe
1085 * Unpacks the information contained in binary @buffer into a structured
1086 * @frame of the HDMI Audio information frame.
1087 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1090 * Returns 0 on success or a negative error code on failure.
1092 static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
1095 uint8_t *ptr = buffer;
1098 if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
1100 ptr[2] != HDMI_AUDIO_INFOFRAME_SIZE) {
1104 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AUDIO)) != 0)
1107 ret = hdmi_audio_infoframe_init(frame);
1111 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1113 frame->channels = ptr[0] & 0x7;
1114 frame->coding_type = (ptr[0] >> 4) & 0xf;
1115 frame->sample_size = ptr[1] & 0x3;
1116 frame->sample_frequency = (ptr[1] >> 2) & 0x7;
1117 frame->coding_type_ext = ptr[2] & 0x1f;
1118 frame->channel_allocation = ptr[3];
1119 frame->level_shift_value = (ptr[4] >> 3) & 0xf;
1120 frame->downmix_inhibit = ptr[4] & 0x80 ? true : false;
1126 * hdmi_vendor_infoframe_unpack() - unpack binary buffer to a HDMI vendor infoframe
1127 * @buffer: source buffer
1128 * @frame: HDMI Vendor infoframe
1130 * Unpacks the information contained in binary @buffer into a structured
1131 * @frame of the HDMI Vendor information frame.
1132 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1135 * Returns 0 on success or a negative error code on failure.
1138 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
1141 uint8_t *ptr = buffer;
1144 uint8_t hdmi_video_format;
1145 struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
1147 if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
1149 (ptr[2] != 5 && ptr[2] != 6))
1154 if (hdmi_infoframe_checksum(buffer,
1155 HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
1158 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1161 if ((ptr[0] != 0x03) ||
1166 hdmi_video_format = ptr[3] >> 5;
1168 if (hdmi_video_format > 0x2)
1171 ret = hdmi_vendor_infoframe_init(hvf);
1175 hvf->length = length;
1177 if (hdmi_video_format == 0x1) {
1179 } else if (hdmi_video_format == 0x2) {
1180 hvf->s3d_struct = ptr[4] >> 4;
1181 if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
1183 hvf->s3d_ext_data = ptr[5] >> 4;
1193 * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
1194 * @buffer: source buffer
1195 * @frame: HDMI infoframe
1197 * Unpacks the information contained in binary buffer @buffer into a structured
1198 * @frame of a HDMI infoframe.
1199 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1202 * Returns 0 on success or a negative error code on failure.
1204 int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer)
1207 uint8_t *ptr = buffer;
1210 case HDMI_INFOFRAME_TYPE_AVI:
1211 ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer);
1213 case HDMI_INFOFRAME_TYPE_SPD:
1214 ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer);
1216 case HDMI_INFOFRAME_TYPE_AUDIO:
1217 ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer);
1219 case HDMI_INFOFRAME_TYPE_VENDOR:
1220 ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer);
1229 EXPORT_SYMBOL(hdmi_infoframe_unpack);