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 <drm/display/drm_dp.h>
25 #include <linux/bitops.h>
26 #include <linux/bug.h>
27 #include <linux/errno.h>
28 #include <linux/export.h>
29 #include <linux/hdmi.h>
30 #include <linux/string.h>
31 #include <linux/device.h>
33 #define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
35 static u8
hdmi_infoframe_checksum(const u8
*ptr
, size_t size
)
40 /* compute checksum */
41 for (i
= 0; i
< size
; i
++)
47 static void hdmi_infoframe_set_checksum(void *buffer
, size_t size
)
51 ptr
[3] = hdmi_infoframe_checksum(buffer
, size
);
55 * hdmi_avi_infoframe_init() - initialize an HDMI AVI infoframe
56 * @frame: HDMI AVI infoframe
58 void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe
*frame
)
60 memset(frame
, 0, sizeof(*frame
));
62 frame
->type
= HDMI_INFOFRAME_TYPE_AVI
;
64 frame
->length
= HDMI_AVI_INFOFRAME_SIZE
;
66 EXPORT_SYMBOL(hdmi_avi_infoframe_init
);
68 static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe
*frame
)
70 if (frame
->type
!= HDMI_INFOFRAME_TYPE_AVI
||
71 frame
->version
!= 2 ||
72 frame
->length
!= HDMI_AVI_INFOFRAME_SIZE
)
75 if (frame
->picture_aspect
> HDMI_PICTURE_ASPECT_16_9
)
82 * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
83 * @frame: HDMI AVI infoframe
85 * Validates that the infoframe is consistent and updates derived fields
86 * (eg. length) based on other fields.
88 * Returns 0 on success or a negative error code on failure.
90 int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe
*frame
)
92 return hdmi_avi_infoframe_check_only(frame
);
94 EXPORT_SYMBOL(hdmi_avi_infoframe_check
);
97 * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary buffer
98 * @frame: HDMI AVI infoframe
99 * @buffer: destination buffer
100 * @size: size of buffer
102 * Packs the information contained in the @frame structure into a binary
103 * representation that can be written into the corresponding controller
104 * registers. Also computes the checksum as required by section 5.3.5 of
105 * the HDMI 1.4 specification.
107 * Returns the number of bytes packed into the binary buffer or a negative
108 * error code on failure.
110 ssize_t
hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe
*frame
,
111 void *buffer
, size_t size
)
117 ret
= hdmi_avi_infoframe_check_only(frame
);
121 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
126 memset(buffer
, 0, size
);
128 ptr
[0] = frame
->type
;
129 ptr
[1] = frame
->version
;
130 ptr
[2] = frame
->length
;
131 ptr
[3] = 0; /* checksum */
133 /* start infoframe payload */
134 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
136 ptr
[0] = ((frame
->colorspace
& 0x3) << 5) | (frame
->scan_mode
& 0x3);
139 * Data byte 1, bit 4 has to be set if we provide the active format
142 if (frame
->active_aspect
& 0xf)
145 /* Bit 3 and 2 indicate if we transmit horizontal/vertical bar data */
146 if (frame
->top_bar
|| frame
->bottom_bar
)
149 if (frame
->left_bar
|| frame
->right_bar
)
152 ptr
[1] = ((frame
->colorimetry
& 0x3) << 6) |
153 ((frame
->picture_aspect
& 0x3) << 4) |
154 (frame
->active_aspect
& 0xf);
156 ptr
[2] = ((frame
->extended_colorimetry
& 0x7) << 4) |
157 ((frame
->quantization_range
& 0x3) << 2) |
163 ptr
[3] = frame
->video_code
& 0x7f;
165 ptr
[4] = ((frame
->ycc_quantization_range
& 0x3) << 6) |
166 ((frame
->content_type
& 0x3) << 4) |
167 (frame
->pixel_repeat
& 0xf);
169 ptr
[5] = frame
->top_bar
& 0xff;
170 ptr
[6] = (frame
->top_bar
>> 8) & 0xff;
171 ptr
[7] = frame
->bottom_bar
& 0xff;
172 ptr
[8] = (frame
->bottom_bar
>> 8) & 0xff;
173 ptr
[9] = frame
->left_bar
& 0xff;
174 ptr
[10] = (frame
->left_bar
>> 8) & 0xff;
175 ptr
[11] = frame
->right_bar
& 0xff;
176 ptr
[12] = (frame
->right_bar
>> 8) & 0xff;
178 hdmi_infoframe_set_checksum(buffer
, length
);
182 EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only
);
185 * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
186 * and write it to binary buffer
187 * @frame: HDMI AVI infoframe
188 * @buffer: destination buffer
189 * @size: size of buffer
191 * Validates that the infoframe is consistent and updates derived fields
192 * (eg. length) based on other fields, after which it packs the information
193 * contained in the @frame structure into a binary representation that
194 * can be written into the corresponding controller registers. This function
195 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
198 * Returns the number of bytes packed into the binary buffer or a negative
199 * error code on failure.
201 ssize_t
hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe
*frame
,
202 void *buffer
, size_t size
)
206 ret
= hdmi_avi_infoframe_check(frame
);
210 return hdmi_avi_infoframe_pack_only(frame
, buffer
, size
);
212 EXPORT_SYMBOL(hdmi_avi_infoframe_pack
);
215 * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
216 * @frame: HDMI SPD infoframe
217 * @vendor: vendor string
218 * @product: product string
220 * Returns 0 on success or a negative error code on failure.
222 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe
*frame
,
223 const char *vendor
, const char *product
)
227 memset(frame
, 0, sizeof(*frame
));
229 frame
->type
= HDMI_INFOFRAME_TYPE_SPD
;
231 frame
->length
= HDMI_SPD_INFOFRAME_SIZE
;
233 len
= strlen(vendor
);
234 memcpy(frame
->vendor
, vendor
, min(len
, sizeof(frame
->vendor
)));
235 len
= strlen(product
);
236 memcpy(frame
->product
, product
, min(len
, sizeof(frame
->product
)));
240 EXPORT_SYMBOL(hdmi_spd_infoframe_init
);
242 static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe
*frame
)
244 if (frame
->type
!= HDMI_INFOFRAME_TYPE_SPD
||
245 frame
->version
!= 1 ||
246 frame
->length
!= HDMI_SPD_INFOFRAME_SIZE
)
253 * hdmi_spd_infoframe_check() - check a HDMI SPD infoframe
254 * @frame: HDMI SPD infoframe
256 * Validates that the infoframe is consistent and updates derived fields
257 * (eg. length) based on other fields.
259 * Returns 0 on success or a negative error code on failure.
261 int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe
*frame
)
263 return hdmi_spd_infoframe_check_only(frame
);
265 EXPORT_SYMBOL(hdmi_spd_infoframe_check
);
268 * hdmi_spd_infoframe_pack_only() - write HDMI SPD infoframe to binary buffer
269 * @frame: HDMI SPD infoframe
270 * @buffer: destination buffer
271 * @size: size of buffer
273 * Packs the information contained in the @frame structure into a binary
274 * representation that can be written into the corresponding controller
275 * registers. Also computes the checksum as required by section 5.3.5 of
276 * the HDMI 1.4 specification.
278 * Returns the number of bytes packed into the binary buffer or a negative
279 * error code on failure.
281 ssize_t
hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe
*frame
,
282 void *buffer
, size_t size
)
288 ret
= hdmi_spd_infoframe_check_only(frame
);
292 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
297 memset(buffer
, 0, size
);
299 ptr
[0] = frame
->type
;
300 ptr
[1] = frame
->version
;
301 ptr
[2] = frame
->length
;
302 ptr
[3] = 0; /* checksum */
304 /* start infoframe payload */
305 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
307 memcpy(ptr
, frame
->vendor
, sizeof(frame
->vendor
));
308 memcpy(ptr
+ 8, frame
->product
, sizeof(frame
->product
));
310 ptr
[24] = frame
->sdi
;
312 hdmi_infoframe_set_checksum(buffer
, length
);
316 EXPORT_SYMBOL(hdmi_spd_infoframe_pack_only
);
319 * hdmi_spd_infoframe_pack() - check a HDMI SPD infoframe,
320 * and write it to binary buffer
321 * @frame: HDMI SPD infoframe
322 * @buffer: destination buffer
323 * @size: size of buffer
325 * Validates that the infoframe is consistent and updates derived fields
326 * (eg. length) based on other fields, after which it packs the information
327 * contained in the @frame structure into a binary representation that
328 * can be written into the corresponding controller registers. This function
329 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
332 * Returns the number of bytes packed into the binary buffer or a negative
333 * error code on failure.
335 ssize_t
hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe
*frame
,
336 void *buffer
, size_t size
)
340 ret
= hdmi_spd_infoframe_check(frame
);
344 return hdmi_spd_infoframe_pack_only(frame
, buffer
, size
);
346 EXPORT_SYMBOL(hdmi_spd_infoframe_pack
);
349 * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
350 * @frame: HDMI audio infoframe
352 * Returns 0 on success or a negative error code on failure.
354 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe
*frame
)
356 memset(frame
, 0, sizeof(*frame
));
358 frame
->type
= HDMI_INFOFRAME_TYPE_AUDIO
;
360 frame
->length
= HDMI_AUDIO_INFOFRAME_SIZE
;
364 EXPORT_SYMBOL(hdmi_audio_infoframe_init
);
366 static int hdmi_audio_infoframe_check_only(const struct hdmi_audio_infoframe
*frame
)
368 if (frame
->type
!= HDMI_INFOFRAME_TYPE_AUDIO
||
369 frame
->version
!= 1 ||
370 frame
->length
!= HDMI_AUDIO_INFOFRAME_SIZE
)
377 * hdmi_audio_infoframe_check() - check a HDMI audio infoframe
378 * @frame: HDMI audio infoframe
380 * Validates that the infoframe is consistent and updates derived fields
381 * (eg. length) based on other fields.
383 * Returns 0 on success or a negative error code on failure.
385 int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe
*frame
)
387 return hdmi_audio_infoframe_check_only(frame
);
389 EXPORT_SYMBOL(hdmi_audio_infoframe_check
);
392 hdmi_audio_infoframe_pack_payload(const struct hdmi_audio_infoframe
*frame
,
397 if (frame
->channels
>= 2)
398 channels
= frame
->channels
- 1;
402 buffer
[0] = ((frame
->coding_type
& 0xf) << 4) | (channels
& 0x7);
403 buffer
[1] = ((frame
->sample_frequency
& 0x7) << 2) |
404 (frame
->sample_size
& 0x3);
405 buffer
[2] = frame
->coding_type_ext
& 0x1f;
406 buffer
[3] = frame
->channel_allocation
;
407 buffer
[4] = (frame
->level_shift_value
& 0xf) << 3;
409 if (frame
->downmix_inhibit
)
414 * hdmi_audio_infoframe_pack_only() - write HDMI audio infoframe to binary buffer
415 * @frame: HDMI audio infoframe
416 * @buffer: destination buffer
417 * @size: size of buffer
419 * Packs the information contained in the @frame structure into a binary
420 * representation that can be written into the corresponding controller
421 * registers. Also computes the checksum as required by section 5.3.5 of
422 * the HDMI 1.4 specification.
424 * Returns the number of bytes packed into the binary buffer or a negative
425 * error code on failure.
427 ssize_t
hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe
*frame
,
428 void *buffer
, size_t size
)
434 ret
= hdmi_audio_infoframe_check_only(frame
);
438 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
443 memset(buffer
, 0, size
);
445 ptr
[0] = frame
->type
;
446 ptr
[1] = frame
->version
;
447 ptr
[2] = frame
->length
;
448 ptr
[3] = 0; /* checksum */
450 hdmi_audio_infoframe_pack_payload(frame
,
451 ptr
+ HDMI_INFOFRAME_HEADER_SIZE
);
453 hdmi_infoframe_set_checksum(buffer
, length
);
457 EXPORT_SYMBOL(hdmi_audio_infoframe_pack_only
);
460 * hdmi_audio_infoframe_pack() - check a HDMI Audio infoframe,
461 * and write it to binary buffer
462 * @frame: HDMI Audio infoframe
463 * @buffer: destination buffer
464 * @size: size of buffer
466 * Validates that the infoframe is consistent and updates derived fields
467 * (eg. length) based on other fields, after which it packs the information
468 * contained in the @frame structure into a binary representation that
469 * can be written into the corresponding controller registers. This function
470 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
473 * Returns the number of bytes packed into the binary buffer or a negative
474 * error code on failure.
476 ssize_t
hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe
*frame
,
477 void *buffer
, size_t size
)
481 ret
= hdmi_audio_infoframe_check(frame
);
485 return hdmi_audio_infoframe_pack_only(frame
, buffer
, size
);
487 EXPORT_SYMBOL(hdmi_audio_infoframe_pack
);
490 * hdmi_audio_infoframe_pack_for_dp - Pack a HDMI Audio infoframe for DisplayPort
492 * @frame: HDMI Audio infoframe
493 * @sdp: Secondary data packet for DisplayPort.
494 * @dp_version: DisplayPort version to be encoded in the header
496 * Packs a HDMI Audio Infoframe to be sent over DisplayPort. This function
497 * fills the secondary data packet to be used for DisplayPort.
499 * Return: Number of total written bytes or a negative errno on failure.
502 hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe
*frame
,
503 struct dp_sdp
*sdp
, u8 dp_version
)
507 ret
= hdmi_audio_infoframe_check(frame
);
511 memset(sdp
->db
, 0, sizeof(sdp
->db
));
513 /* Secondary-data packet header */
514 sdp
->sdp_header
.HB0
= 0;
515 sdp
->sdp_header
.HB1
= frame
->type
;
516 sdp
->sdp_header
.HB2
= DP_SDP_AUDIO_INFOFRAME_HB2
;
517 sdp
->sdp_header
.HB3
= (dp_version
& 0x3f) << 2;
519 hdmi_audio_infoframe_pack_payload(frame
, sdp
->db
);
521 /* Return size = frame length + four HB for sdp_header */
522 return frame
->length
+ 4;
524 EXPORT_SYMBOL(hdmi_audio_infoframe_pack_for_dp
);
527 * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
528 * @frame: HDMI vendor infoframe
530 * Returns 0 on success or a negative error code on failure.
532 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe
*frame
)
534 memset(frame
, 0, sizeof(*frame
));
536 frame
->type
= HDMI_INFOFRAME_TYPE_VENDOR
;
539 frame
->oui
= HDMI_IEEE_OUI
;
542 * 0 is a valid value for s3d_struct, so we use a special "not set"
545 frame
->s3d_struct
= HDMI_3D_STRUCTURE_INVALID
;
546 frame
->length
= HDMI_VENDOR_INFOFRAME_SIZE
;
550 EXPORT_SYMBOL(hdmi_vendor_infoframe_init
);
552 static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe
*frame
)
554 /* for side by side (half) we also need to provide 3D_Ext_Data */
555 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
557 else if (frame
->vic
!= 0 || frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
)
563 static int hdmi_vendor_infoframe_check_only(const struct hdmi_vendor_infoframe
*frame
)
565 if (frame
->type
!= HDMI_INFOFRAME_TYPE_VENDOR
||
566 frame
->version
!= 1 ||
567 frame
->oui
!= HDMI_IEEE_OUI
)
570 /* only one of those can be supplied */
571 if (frame
->vic
!= 0 && frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
)
574 if (frame
->length
!= hdmi_vendor_infoframe_length(frame
))
581 * hdmi_vendor_infoframe_check() - check a HDMI vendor infoframe
582 * @frame: HDMI infoframe
584 * Validates that the infoframe is consistent and updates derived fields
585 * (eg. length) based on other fields.
587 * Returns 0 on success or a negative error code on failure.
589 int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe
*frame
)
591 frame
->length
= hdmi_vendor_infoframe_length(frame
);
593 return hdmi_vendor_infoframe_check_only(frame
);
595 EXPORT_SYMBOL(hdmi_vendor_infoframe_check
);
598 * hdmi_vendor_infoframe_pack_only() - write a HDMI vendor infoframe to binary buffer
599 * @frame: HDMI infoframe
600 * @buffer: destination buffer
601 * @size: size of buffer
603 * Packs the information contained in the @frame structure into a binary
604 * representation that can be written into the corresponding controller
605 * registers. Also computes the checksum as required by section 5.3.5 of
606 * the HDMI 1.4 specification.
608 * Returns the number of bytes packed into the binary buffer or a negative
609 * error code on failure.
611 ssize_t
hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe
*frame
,
612 void *buffer
, size_t size
)
618 ret
= hdmi_vendor_infoframe_check_only(frame
);
622 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
627 memset(buffer
, 0, size
);
629 ptr
[0] = frame
->type
;
630 ptr
[1] = frame
->version
;
631 ptr
[2] = frame
->length
;
632 ptr
[3] = 0; /* checksum */
639 if (frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
) {
640 ptr
[7] = 0x2 << 5; /* video format */
641 ptr
[8] = (frame
->s3d_struct
& 0xf) << 4;
642 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
643 ptr
[9] = (frame
->s3d_ext_data
& 0xf) << 4;
644 } else if (frame
->vic
) {
645 ptr
[7] = 0x1 << 5; /* video format */
648 ptr
[7] = 0x0 << 5; /* video format */
651 hdmi_infoframe_set_checksum(buffer
, length
);
655 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack_only
);
658 * hdmi_vendor_infoframe_pack() - check a HDMI Vendor infoframe,
659 * and write it to binary buffer
660 * @frame: HDMI Vendor infoframe
661 * @buffer: destination buffer
662 * @size: size of buffer
664 * Validates that the infoframe is consistent and updates derived fields
665 * (eg. length) based on other fields, after which it packs the information
666 * contained in the @frame structure into a binary representation that
667 * can be written into the corresponding controller registers. This function
668 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
671 * Returns the number of bytes packed into the binary buffer or a negative
672 * error code on failure.
674 ssize_t
hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe
*frame
,
675 void *buffer
, size_t size
)
679 ret
= hdmi_vendor_infoframe_check(frame
);
683 return hdmi_vendor_infoframe_pack_only(frame
, buffer
, size
);
685 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack
);
688 hdmi_vendor_any_infoframe_check_only(const union hdmi_vendor_any_infoframe
*frame
)
690 if (frame
->any
.type
!= HDMI_INFOFRAME_TYPE_VENDOR
||
691 frame
->any
.version
!= 1)
698 * hdmi_drm_infoframe_init() - initialize an HDMI Dynaminc Range and
699 * mastering infoframe
700 * @frame: HDMI DRM infoframe
702 * Returns 0 on success or a negative error code on failure.
704 int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe
*frame
)
706 memset(frame
, 0, sizeof(*frame
));
708 frame
->type
= HDMI_INFOFRAME_TYPE_DRM
;
710 frame
->length
= HDMI_DRM_INFOFRAME_SIZE
;
714 EXPORT_SYMBOL(hdmi_drm_infoframe_init
);
716 static int hdmi_drm_infoframe_check_only(const struct hdmi_drm_infoframe
*frame
)
718 if (frame
->type
!= HDMI_INFOFRAME_TYPE_DRM
||
722 if (frame
->length
!= HDMI_DRM_INFOFRAME_SIZE
)
729 * hdmi_drm_infoframe_check() - check a HDMI DRM infoframe
730 * @frame: HDMI DRM infoframe
732 * Validates that the infoframe is consistent.
733 * Returns 0 on success or a negative error code on failure.
735 int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe
*frame
)
737 return hdmi_drm_infoframe_check_only(frame
);
739 EXPORT_SYMBOL(hdmi_drm_infoframe_check
);
742 * hdmi_drm_infoframe_pack_only() - write HDMI DRM infoframe to binary buffer
743 * @frame: HDMI DRM infoframe
744 * @buffer: destination buffer
745 * @size: size of buffer
747 * Packs the information contained in the @frame structure into a binary
748 * representation that can be written into the corresponding controller
749 * registers. Also computes the checksum as required by section 5.3.5 of
750 * the HDMI 1.4 specification.
752 * Returns the number of bytes packed into the binary buffer or a negative
753 * error code on failure.
755 ssize_t
hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe
*frame
,
756 void *buffer
, size_t size
)
762 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
767 memset(buffer
, 0, size
);
769 ptr
[0] = frame
->type
;
770 ptr
[1] = frame
->version
;
771 ptr
[2] = frame
->length
;
772 ptr
[3] = 0; /* checksum */
774 /* start infoframe payload */
775 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
777 *ptr
++ = frame
->eotf
;
778 *ptr
++ = frame
->metadata_type
;
780 for (i
= 0; i
< 3; i
++) {
781 *ptr
++ = frame
->display_primaries
[i
].x
;
782 *ptr
++ = frame
->display_primaries
[i
].x
>> 8;
783 *ptr
++ = frame
->display_primaries
[i
].y
;
784 *ptr
++ = frame
->display_primaries
[i
].y
>> 8;
787 *ptr
++ = frame
->white_point
.x
;
788 *ptr
++ = frame
->white_point
.x
>> 8;
790 *ptr
++ = frame
->white_point
.y
;
791 *ptr
++ = frame
->white_point
.y
>> 8;
793 *ptr
++ = frame
->max_display_mastering_luminance
;
794 *ptr
++ = frame
->max_display_mastering_luminance
>> 8;
796 *ptr
++ = frame
->min_display_mastering_luminance
;
797 *ptr
++ = frame
->min_display_mastering_luminance
>> 8;
799 *ptr
++ = frame
->max_cll
;
800 *ptr
++ = frame
->max_cll
>> 8;
802 *ptr
++ = frame
->max_fall
;
803 *ptr
++ = frame
->max_fall
>> 8;
805 hdmi_infoframe_set_checksum(buffer
, length
);
809 EXPORT_SYMBOL(hdmi_drm_infoframe_pack_only
);
812 * hdmi_drm_infoframe_pack() - check a HDMI DRM infoframe,
813 * and write it to binary buffer
814 * @frame: HDMI DRM infoframe
815 * @buffer: destination buffer
816 * @size: size of buffer
818 * Validates that the infoframe is consistent and updates derived fields
819 * (eg. length) based on other fields, after which it packs the information
820 * contained in the @frame structure into a binary representation that
821 * can be written into the corresponding controller registers. This function
822 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
825 * Returns the number of bytes packed into the binary buffer or a negative
826 * error code on failure.
828 ssize_t
hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe
*frame
,
829 void *buffer
, size_t size
)
833 ret
= hdmi_drm_infoframe_check(frame
);
837 return hdmi_drm_infoframe_pack_only(frame
, buffer
, size
);
839 EXPORT_SYMBOL(hdmi_drm_infoframe_pack
);
842 * hdmi_vendor_any_infoframe_check() - check a vendor infoframe
845 hdmi_vendor_any_infoframe_check(union hdmi_vendor_any_infoframe
*frame
)
849 ret
= hdmi_vendor_any_infoframe_check_only(frame
);
853 /* we only know about HDMI vendor infoframes */
854 if (frame
->any
.oui
!= HDMI_IEEE_OUI
)
857 return hdmi_vendor_infoframe_check(&frame
->hdmi
);
861 * hdmi_vendor_any_infoframe_pack_only() - write a vendor infoframe to binary buffer
864 hdmi_vendor_any_infoframe_pack_only(const union hdmi_vendor_any_infoframe
*frame
,
865 void *buffer
, size_t size
)
869 ret
= hdmi_vendor_any_infoframe_check_only(frame
);
873 /* we only know about HDMI vendor infoframes */
874 if (frame
->any
.oui
!= HDMI_IEEE_OUI
)
877 return hdmi_vendor_infoframe_pack_only(&frame
->hdmi
, buffer
, size
);
881 * hdmi_vendor_any_infoframe_pack() - check a vendor infoframe,
882 * and write it to binary buffer
885 hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe
*frame
,
886 void *buffer
, size_t size
)
890 ret
= hdmi_vendor_any_infoframe_check(frame
);
894 return hdmi_vendor_any_infoframe_pack_only(frame
, buffer
, size
);
898 * hdmi_infoframe_check() - check a HDMI infoframe
899 * @frame: HDMI infoframe
901 * Validates that the infoframe is consistent and updates derived fields
902 * (eg. length) based on other fields.
904 * Returns 0 on success or a negative error code on failure.
907 hdmi_infoframe_check(union hdmi_infoframe
*frame
)
909 switch (frame
->any
.type
) {
910 case HDMI_INFOFRAME_TYPE_AVI
:
911 return hdmi_avi_infoframe_check(&frame
->avi
);
912 case HDMI_INFOFRAME_TYPE_SPD
:
913 return hdmi_spd_infoframe_check(&frame
->spd
);
914 case HDMI_INFOFRAME_TYPE_AUDIO
:
915 return hdmi_audio_infoframe_check(&frame
->audio
);
916 case HDMI_INFOFRAME_TYPE_VENDOR
:
917 return hdmi_vendor_any_infoframe_check(&frame
->vendor
);
919 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
923 EXPORT_SYMBOL(hdmi_infoframe_check
);
926 * hdmi_infoframe_pack_only() - write a HDMI infoframe to binary buffer
927 * @frame: HDMI infoframe
928 * @buffer: destination buffer
929 * @size: size of buffer
931 * Packs the information contained in the @frame structure into a binary
932 * representation that can be written into the corresponding controller
933 * registers. Also computes the checksum as required by section 5.3.5 of
934 * the HDMI 1.4 specification.
936 * Returns the number of bytes packed into the binary buffer or a negative
937 * error code on failure.
940 hdmi_infoframe_pack_only(const union hdmi_infoframe
*frame
, void *buffer
, size_t size
)
944 switch (frame
->any
.type
) {
945 case HDMI_INFOFRAME_TYPE_AVI
:
946 length
= hdmi_avi_infoframe_pack_only(&frame
->avi
,
949 case HDMI_INFOFRAME_TYPE_DRM
:
950 length
= hdmi_drm_infoframe_pack_only(&frame
->drm
,
953 case HDMI_INFOFRAME_TYPE_SPD
:
954 length
= hdmi_spd_infoframe_pack_only(&frame
->spd
,
957 case HDMI_INFOFRAME_TYPE_AUDIO
:
958 length
= hdmi_audio_infoframe_pack_only(&frame
->audio
,
961 case HDMI_INFOFRAME_TYPE_VENDOR
:
962 length
= hdmi_vendor_any_infoframe_pack_only(&frame
->vendor
,
966 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
972 EXPORT_SYMBOL(hdmi_infoframe_pack_only
);
975 * hdmi_infoframe_pack() - check a HDMI infoframe,
976 * and write it to binary buffer
977 * @frame: HDMI infoframe
978 * @buffer: destination buffer
979 * @size: size of buffer
981 * Validates that the infoframe is consistent and updates derived fields
982 * (eg. length) based on other fields, after which it packs the information
983 * contained in the @frame structure into a binary representation that
984 * can be written into the corresponding controller registers. This function
985 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
988 * Returns the number of bytes packed into the binary buffer or a negative
989 * error code on failure.
992 hdmi_infoframe_pack(union hdmi_infoframe
*frame
,
993 void *buffer
, size_t size
)
997 switch (frame
->any
.type
) {
998 case HDMI_INFOFRAME_TYPE_AVI
:
999 length
= hdmi_avi_infoframe_pack(&frame
->avi
, buffer
, size
);
1001 case HDMI_INFOFRAME_TYPE_DRM
:
1002 length
= hdmi_drm_infoframe_pack(&frame
->drm
, buffer
, size
);
1004 case HDMI_INFOFRAME_TYPE_SPD
:
1005 length
= hdmi_spd_infoframe_pack(&frame
->spd
, buffer
, size
);
1007 case HDMI_INFOFRAME_TYPE_AUDIO
:
1008 length
= hdmi_audio_infoframe_pack(&frame
->audio
, buffer
, size
);
1010 case HDMI_INFOFRAME_TYPE_VENDOR
:
1011 length
= hdmi_vendor_any_infoframe_pack(&frame
->vendor
,
1015 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
1021 EXPORT_SYMBOL(hdmi_infoframe_pack
);
1023 static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type
)
1025 if (type
< 0x80 || type
> 0x9f)
1028 case HDMI_INFOFRAME_TYPE_VENDOR
:
1030 case HDMI_INFOFRAME_TYPE_AVI
:
1031 return "Auxiliary Video Information (AVI)";
1032 case HDMI_INFOFRAME_TYPE_SPD
:
1033 return "Source Product Description (SPD)";
1034 case HDMI_INFOFRAME_TYPE_AUDIO
:
1036 case HDMI_INFOFRAME_TYPE_DRM
:
1037 return "Dynamic Range and Mastering";
1042 static void hdmi_infoframe_log_header(const char *level
,
1044 const struct hdmi_any_infoframe
*frame
)
1046 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
1047 hdmi_infoframe_type_get_name(frame
->type
),
1048 frame
->version
, frame
->length
);
1051 static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace
)
1053 switch (colorspace
) {
1054 case HDMI_COLORSPACE_RGB
:
1056 case HDMI_COLORSPACE_YUV422
:
1057 return "YCbCr 4:2:2";
1058 case HDMI_COLORSPACE_YUV444
:
1059 return "YCbCr 4:4:4";
1060 case HDMI_COLORSPACE_YUV420
:
1061 return "YCbCr 4:2:0";
1062 case HDMI_COLORSPACE_RESERVED4
:
1063 return "Reserved (4)";
1064 case HDMI_COLORSPACE_RESERVED5
:
1065 return "Reserved (5)";
1066 case HDMI_COLORSPACE_RESERVED6
:
1067 return "Reserved (6)";
1068 case HDMI_COLORSPACE_IDO_DEFINED
:
1069 return "IDO Defined";
1074 static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode
)
1076 switch (scan_mode
) {
1077 case HDMI_SCAN_MODE_NONE
:
1079 case HDMI_SCAN_MODE_OVERSCAN
:
1081 case HDMI_SCAN_MODE_UNDERSCAN
:
1083 case HDMI_SCAN_MODE_RESERVED
:
1089 static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry
)
1091 switch (colorimetry
) {
1092 case HDMI_COLORIMETRY_NONE
:
1094 case HDMI_COLORIMETRY_ITU_601
:
1096 case HDMI_COLORIMETRY_ITU_709
:
1098 case HDMI_COLORIMETRY_EXTENDED
:
1105 hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect
)
1107 switch (picture_aspect
) {
1108 case HDMI_PICTURE_ASPECT_NONE
:
1110 case HDMI_PICTURE_ASPECT_4_3
:
1112 case HDMI_PICTURE_ASPECT_16_9
:
1114 case HDMI_PICTURE_ASPECT_64_27
:
1116 case HDMI_PICTURE_ASPECT_256_135
:
1118 case HDMI_PICTURE_ASPECT_RESERVED
:
1125 hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect
)
1127 if (active_aspect
< 0 || active_aspect
> 0xf)
1130 switch (active_aspect
) {
1131 case HDMI_ACTIVE_ASPECT_16_9_TOP
:
1133 case HDMI_ACTIVE_ASPECT_14_9_TOP
:
1135 case HDMI_ACTIVE_ASPECT_16_9_CENTER
:
1136 return "16:9 Center";
1137 case HDMI_ACTIVE_ASPECT_PICTURE
:
1138 return "Same as Picture";
1139 case HDMI_ACTIVE_ASPECT_4_3
:
1141 case HDMI_ACTIVE_ASPECT_16_9
:
1143 case HDMI_ACTIVE_ASPECT_14_9
:
1145 case HDMI_ACTIVE_ASPECT_4_3_SP_14_9
:
1146 return "4:3 SP 14:9";
1147 case HDMI_ACTIVE_ASPECT_16_9_SP_14_9
:
1148 return "16:9 SP 14:9";
1149 case HDMI_ACTIVE_ASPECT_16_9_SP_4_3
:
1150 return "16:9 SP 4:3";
1156 hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col
)
1159 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601
:
1161 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709
:
1163 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601
:
1165 case HDMI_EXTENDED_COLORIMETRY_OPYCC_601
:
1167 case HDMI_EXTENDED_COLORIMETRY_OPRGB
:
1169 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM
:
1170 return "BT.2020 Constant Luminance";
1171 case HDMI_EXTENDED_COLORIMETRY_BT2020
:
1173 case HDMI_EXTENDED_COLORIMETRY_RESERVED
:
1180 hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange
)
1183 case HDMI_QUANTIZATION_RANGE_DEFAULT
:
1185 case HDMI_QUANTIZATION_RANGE_LIMITED
:
1187 case HDMI_QUANTIZATION_RANGE_FULL
:
1189 case HDMI_QUANTIZATION_RANGE_RESERVED
:
1195 static const char *hdmi_nups_get_name(enum hdmi_nups nups
)
1198 case HDMI_NUPS_UNKNOWN
:
1199 return "Unknown Non-uniform Scaling";
1200 case HDMI_NUPS_HORIZONTAL
:
1201 return "Horizontally Scaled";
1202 case HDMI_NUPS_VERTICAL
:
1203 return "Vertically Scaled";
1204 case HDMI_NUPS_BOTH
:
1205 return "Horizontally and Vertically Scaled";
1211 hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange
)
1214 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED
:
1216 case HDMI_YCC_QUANTIZATION_RANGE_FULL
:
1223 hdmi_content_type_get_name(enum hdmi_content_type content_type
)
1225 switch (content_type
) {
1226 case HDMI_CONTENT_TYPE_GRAPHICS
:
1228 case HDMI_CONTENT_TYPE_PHOTO
:
1230 case HDMI_CONTENT_TYPE_CINEMA
:
1232 case HDMI_CONTENT_TYPE_GAME
:
1238 static void hdmi_avi_infoframe_log(const char *level
,
1240 const struct hdmi_avi_infoframe
*frame
)
1242 hdmi_infoframe_log_header(level
, dev
,
1243 (const struct hdmi_any_infoframe
*)frame
);
1245 hdmi_log(" colorspace: %s\n",
1246 hdmi_colorspace_get_name(frame
->colorspace
));
1247 hdmi_log(" scan mode: %s\n",
1248 hdmi_scan_mode_get_name(frame
->scan_mode
));
1249 hdmi_log(" colorimetry: %s\n",
1250 hdmi_colorimetry_get_name(frame
->colorimetry
));
1251 hdmi_log(" picture aspect: %s\n",
1252 hdmi_picture_aspect_get_name(frame
->picture_aspect
));
1253 hdmi_log(" active aspect: %s\n",
1254 hdmi_active_aspect_get_name(frame
->active_aspect
));
1255 hdmi_log(" itc: %s\n", frame
->itc
? "IT Content" : "No Data");
1256 hdmi_log(" extended colorimetry: %s\n",
1257 hdmi_extended_colorimetry_get_name(frame
->extended_colorimetry
));
1258 hdmi_log(" quantization range: %s\n",
1259 hdmi_quantization_range_get_name(frame
->quantization_range
));
1260 hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame
->nups
));
1261 hdmi_log(" video code: %u\n", frame
->video_code
);
1262 hdmi_log(" ycc quantization range: %s\n",
1263 hdmi_ycc_quantization_range_get_name(frame
->ycc_quantization_range
));
1264 hdmi_log(" hdmi content type: %s\n",
1265 hdmi_content_type_get_name(frame
->content_type
));
1266 hdmi_log(" pixel repeat: %u\n", frame
->pixel_repeat
);
1267 hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
1268 frame
->top_bar
, frame
->bottom_bar
,
1269 frame
->left_bar
, frame
->right_bar
);
1272 static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi
)
1274 if (sdi
< 0 || sdi
> 0xff)
1277 case HDMI_SPD_SDI_UNKNOWN
:
1279 case HDMI_SPD_SDI_DSTB
:
1280 return "Digital STB";
1281 case HDMI_SPD_SDI_DVDP
:
1282 return "DVD Player";
1283 case HDMI_SPD_SDI_DVHS
:
1285 case HDMI_SPD_SDI_HDDVR
:
1286 return "HDD Videorecorder";
1287 case HDMI_SPD_SDI_DVC
:
1289 case HDMI_SPD_SDI_DSC
:
1291 case HDMI_SPD_SDI_VCD
:
1293 case HDMI_SPD_SDI_GAME
:
1295 case HDMI_SPD_SDI_PC
:
1296 return "PC General";
1297 case HDMI_SPD_SDI_BD
:
1298 return "Blu-Ray Disc (BD)";
1299 case HDMI_SPD_SDI_SACD
:
1300 return "Super Audio CD";
1301 case HDMI_SPD_SDI_HDDVD
:
1303 case HDMI_SPD_SDI_PMP
:
1309 static void hdmi_spd_infoframe_log(const char *level
,
1311 const struct hdmi_spd_infoframe
*frame
)
1313 hdmi_infoframe_log_header(level
, dev
,
1314 (const struct hdmi_any_infoframe
*)frame
);
1316 hdmi_log(" vendor: %.8s\n", frame
->vendor
);
1317 hdmi_log(" product: %.16s\n", frame
->product
);
1318 hdmi_log(" source device information: %s (0x%x)\n",
1319 hdmi_spd_sdi_get_name(frame
->sdi
), frame
->sdi
);
1323 hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type
)
1325 switch (coding_type
) {
1326 case HDMI_AUDIO_CODING_TYPE_STREAM
:
1327 return "Refer to Stream Header";
1328 case HDMI_AUDIO_CODING_TYPE_PCM
:
1330 case HDMI_AUDIO_CODING_TYPE_AC3
:
1332 case HDMI_AUDIO_CODING_TYPE_MPEG1
:
1334 case HDMI_AUDIO_CODING_TYPE_MP3
:
1336 case HDMI_AUDIO_CODING_TYPE_MPEG2
:
1338 case HDMI_AUDIO_CODING_TYPE_AAC_LC
:
1340 case HDMI_AUDIO_CODING_TYPE_DTS
:
1342 case HDMI_AUDIO_CODING_TYPE_ATRAC
:
1344 case HDMI_AUDIO_CODING_TYPE_DSD
:
1345 return "One Bit Audio";
1346 case HDMI_AUDIO_CODING_TYPE_EAC3
:
1347 return "Dolby Digital +";
1348 case HDMI_AUDIO_CODING_TYPE_DTS_HD
:
1350 case HDMI_AUDIO_CODING_TYPE_MLP
:
1352 case HDMI_AUDIO_CODING_TYPE_DST
:
1354 case HDMI_AUDIO_CODING_TYPE_WMA_PRO
:
1356 case HDMI_AUDIO_CODING_TYPE_CXT
:
1357 return "Refer to CXT";
1363 hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size
)
1365 switch (sample_size
) {
1366 case HDMI_AUDIO_SAMPLE_SIZE_STREAM
:
1367 return "Refer to Stream Header";
1368 case HDMI_AUDIO_SAMPLE_SIZE_16
:
1370 case HDMI_AUDIO_SAMPLE_SIZE_20
:
1372 case HDMI_AUDIO_SAMPLE_SIZE_24
:
1379 hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq
)
1382 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM
:
1383 return "Refer to Stream Header";
1384 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000
:
1386 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100
:
1387 return "44.1 kHz (CD)";
1388 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000
:
1390 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200
:
1392 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000
:
1394 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400
:
1396 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000
:
1403 hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx
)
1405 if (ctx
< 0 || ctx
> 0x1f)
1409 case HDMI_AUDIO_CODING_TYPE_EXT_CT
:
1410 return "Refer to CT";
1411 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC
:
1413 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2
:
1415 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND
:
1416 return "MPEG SURROUND";
1417 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC
:
1418 return "MPEG-4 HE AAC";
1419 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2
:
1420 return "MPEG-4 HE AAC v2";
1421 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC
:
1422 return "MPEG-4 AAC LC";
1423 case HDMI_AUDIO_CODING_TYPE_EXT_DRA
:
1425 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND
:
1426 return "MPEG-4 HE AAC + MPEG Surround";
1427 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND
:
1428 return "MPEG-4 AAC LC + MPEG Surround";
1433 static void hdmi_audio_infoframe_log(const char *level
,
1435 const struct hdmi_audio_infoframe
*frame
)
1437 hdmi_infoframe_log_header(level
, dev
,
1438 (const struct hdmi_any_infoframe
*)frame
);
1440 if (frame
->channels
)
1441 hdmi_log(" channels: %u\n", frame
->channels
- 1);
1443 hdmi_log(" channels: Refer to stream header\n");
1444 hdmi_log(" coding type: %s\n",
1445 hdmi_audio_coding_type_get_name(frame
->coding_type
));
1446 hdmi_log(" sample size: %s\n",
1447 hdmi_audio_sample_size_get_name(frame
->sample_size
));
1448 hdmi_log(" sample frequency: %s\n",
1449 hdmi_audio_sample_frequency_get_name(frame
->sample_frequency
));
1450 hdmi_log(" coding type ext: %s\n",
1451 hdmi_audio_coding_type_ext_get_name(frame
->coding_type_ext
));
1452 hdmi_log(" channel allocation: 0x%x\n",
1453 frame
->channel_allocation
);
1454 hdmi_log(" level shift value: %u dB\n",
1455 frame
->level_shift_value
);
1456 hdmi_log(" downmix inhibit: %s\n",
1457 frame
->downmix_inhibit
? "Yes" : "No");
1460 static void hdmi_drm_infoframe_log(const char *level
,
1462 const struct hdmi_drm_infoframe
*frame
)
1466 hdmi_infoframe_log_header(level
, dev
,
1467 (struct hdmi_any_infoframe
*)frame
);
1468 hdmi_log("length: %d\n", frame
->length
);
1469 hdmi_log("metadata type: %d\n", frame
->metadata_type
);
1470 hdmi_log("eotf: %d\n", frame
->eotf
);
1471 for (i
= 0; i
< 3; i
++) {
1472 hdmi_log("x[%d]: %d\n", i
, frame
->display_primaries
[i
].x
);
1473 hdmi_log("y[%d]: %d\n", i
, frame
->display_primaries
[i
].y
);
1476 hdmi_log("white point x: %d\n", frame
->white_point
.x
);
1477 hdmi_log("white point y: %d\n", frame
->white_point
.y
);
1479 hdmi_log("max_display_mastering_luminance: %d\n",
1480 frame
->max_display_mastering_luminance
);
1481 hdmi_log("min_display_mastering_luminance: %d\n",
1482 frame
->min_display_mastering_luminance
);
1484 hdmi_log("max_cll: %d\n", frame
->max_cll
);
1485 hdmi_log("max_fall: %d\n", frame
->max_fall
);
1489 hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct
)
1491 if (s3d_struct
< 0 || s3d_struct
> 0xf)
1494 switch (s3d_struct
) {
1495 case HDMI_3D_STRUCTURE_FRAME_PACKING
:
1496 return "Frame Packing";
1497 case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE
:
1498 return "Field Alternative";
1499 case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE
:
1500 return "Line Alternative";
1501 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL
:
1502 return "Side-by-side (Full)";
1503 case HDMI_3D_STRUCTURE_L_DEPTH
:
1505 case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH
:
1506 return "L + Depth + Graphics + Graphics-depth";
1507 case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM
:
1508 return "Top-and-Bottom";
1509 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
:
1510 return "Side-by-side (Half)";
1518 hdmi_vendor_any_infoframe_log(const char *level
,
1520 const union hdmi_vendor_any_infoframe
*frame
)
1522 const struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
1524 hdmi_infoframe_log_header(level
, dev
,
1525 (const struct hdmi_any_infoframe
*)frame
);
1527 if (frame
->any
.oui
!= HDMI_IEEE_OUI
) {
1528 hdmi_log(" not a HDMI vendor infoframe\n");
1531 if (hvf
->vic
== 0 && hvf
->s3d_struct
== HDMI_3D_STRUCTURE_INVALID
) {
1532 hdmi_log(" empty frame\n");
1537 hdmi_log(" HDMI VIC: %u\n", hvf
->vic
);
1538 if (hvf
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
) {
1539 hdmi_log(" 3D structure: %s\n",
1540 hdmi_3d_structure_get_name(hvf
->s3d_struct
));
1541 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
1542 hdmi_log(" 3D extension data: %d\n",
1548 * hdmi_infoframe_log() - log info of HDMI infoframe
1549 * @level: logging level
1551 * @frame: HDMI infoframe
1553 void hdmi_infoframe_log(const char *level
,
1555 const union hdmi_infoframe
*frame
)
1557 switch (frame
->any
.type
) {
1558 case HDMI_INFOFRAME_TYPE_AVI
:
1559 hdmi_avi_infoframe_log(level
, dev
, &frame
->avi
);
1561 case HDMI_INFOFRAME_TYPE_SPD
:
1562 hdmi_spd_infoframe_log(level
, dev
, &frame
->spd
);
1564 case HDMI_INFOFRAME_TYPE_AUDIO
:
1565 hdmi_audio_infoframe_log(level
, dev
, &frame
->audio
);
1567 case HDMI_INFOFRAME_TYPE_VENDOR
:
1568 hdmi_vendor_any_infoframe_log(level
, dev
, &frame
->vendor
);
1570 case HDMI_INFOFRAME_TYPE_DRM
:
1571 hdmi_drm_infoframe_log(level
, dev
, &frame
->drm
);
1575 EXPORT_SYMBOL(hdmi_infoframe_log
);
1578 * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
1579 * @frame: HDMI AVI infoframe
1580 * @buffer: source buffer
1581 * @size: size of buffer
1583 * Unpacks the information contained in binary @buffer into a structured
1584 * @frame of the HDMI Auxiliary Video (AVI) information frame.
1585 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1588 * Returns 0 on success or a negative error code on failure.
1590 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe
*frame
,
1591 const void *buffer
, size_t size
)
1593 const u8
*ptr
= buffer
;
1595 if (size
< HDMI_INFOFRAME_SIZE(AVI
))
1598 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AVI
||
1600 ptr
[2] != HDMI_AVI_INFOFRAME_SIZE
)
1603 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AVI
)) != 0)
1606 hdmi_avi_infoframe_init(frame
);
1608 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1610 frame
->colorspace
= (ptr
[0] >> 5) & 0x3;
1612 frame
->active_aspect
= ptr
[1] & 0xf;
1614 frame
->top_bar
= (ptr
[6] << 8) | ptr
[5];
1615 frame
->bottom_bar
= (ptr
[8] << 8) | ptr
[7];
1618 frame
->left_bar
= (ptr
[10] << 8) | ptr
[9];
1619 frame
->right_bar
= (ptr
[12] << 8) | ptr
[11];
1621 frame
->scan_mode
= ptr
[0] & 0x3;
1623 frame
->colorimetry
= (ptr
[1] >> 6) & 0x3;
1624 frame
->picture_aspect
= (ptr
[1] >> 4) & 0x3;
1625 frame
->active_aspect
= ptr
[1] & 0xf;
1627 frame
->itc
= ptr
[2] & 0x80 ? true : false;
1628 frame
->extended_colorimetry
= (ptr
[2] >> 4) & 0x7;
1629 frame
->quantization_range
= (ptr
[2] >> 2) & 0x3;
1630 frame
->nups
= ptr
[2] & 0x3;
1632 frame
->video_code
= ptr
[3] & 0x7f;
1633 frame
->ycc_quantization_range
= (ptr
[4] >> 6) & 0x3;
1634 frame
->content_type
= (ptr
[4] >> 4) & 0x3;
1636 frame
->pixel_repeat
= ptr
[4] & 0xf;
1642 * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
1643 * @frame: HDMI SPD infoframe
1644 * @buffer: source buffer
1645 * @size: size of buffer
1647 * Unpacks the information contained in binary @buffer into a structured
1648 * @frame of the HDMI Source Product Description (SPD) information frame.
1649 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1652 * Returns 0 on success or a negative error code on failure.
1654 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe
*frame
,
1655 const void *buffer
, size_t size
)
1657 const u8
*ptr
= buffer
;
1660 if (size
< HDMI_INFOFRAME_SIZE(SPD
))
1663 if (ptr
[0] != HDMI_INFOFRAME_TYPE_SPD
||
1665 ptr
[2] != HDMI_SPD_INFOFRAME_SIZE
) {
1669 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(SPD
)) != 0)
1672 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1674 ret
= hdmi_spd_infoframe_init(frame
, ptr
, ptr
+ 8);
1678 frame
->sdi
= ptr
[24];
1684 * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
1685 * @frame: HDMI Audio infoframe
1686 * @buffer: source buffer
1687 * @size: size of buffer
1689 * Unpacks the information contained in binary @buffer into a structured
1690 * @frame of the HDMI Audio information frame.
1691 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1694 * Returns 0 on success or a negative error code on failure.
1696 static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe
*frame
,
1697 const void *buffer
, size_t size
)
1699 const u8
*ptr
= buffer
;
1702 if (size
< HDMI_INFOFRAME_SIZE(AUDIO
))
1705 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AUDIO
||
1707 ptr
[2] != HDMI_AUDIO_INFOFRAME_SIZE
) {
1711 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AUDIO
)) != 0)
1714 ret
= hdmi_audio_infoframe_init(frame
);
1718 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1720 frame
->channels
= ptr
[0] & 0x7;
1721 frame
->coding_type
= (ptr
[0] >> 4) & 0xf;
1722 frame
->sample_size
= ptr
[1] & 0x3;
1723 frame
->sample_frequency
= (ptr
[1] >> 2) & 0x7;
1724 frame
->coding_type_ext
= ptr
[2] & 0x1f;
1725 frame
->channel_allocation
= ptr
[3];
1726 frame
->level_shift_value
= (ptr
[4] >> 3) & 0xf;
1727 frame
->downmix_inhibit
= ptr
[4] & 0x80 ? true : false;
1733 * hdmi_vendor_any_infoframe_unpack() - unpack binary buffer to a HDMI
1735 * @frame: HDMI Vendor infoframe
1736 * @buffer: source buffer
1737 * @size: size of buffer
1739 * Unpacks the information contained in binary @buffer into a structured
1740 * @frame of the HDMI Vendor information frame.
1741 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1744 * Returns 0 on success or a negative error code on failure.
1747 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe
*frame
,
1748 const void *buffer
, size_t size
)
1750 const u8
*ptr
= buffer
;
1753 u8 hdmi_video_format
;
1754 struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
1756 if (size
< HDMI_INFOFRAME_HEADER_SIZE
)
1759 if (ptr
[0] != HDMI_INFOFRAME_TYPE_VENDOR
||
1761 (ptr
[2] != 4 && ptr
[2] != 5 && ptr
[2] != 6))
1766 if (size
< HDMI_INFOFRAME_HEADER_SIZE
+ length
)
1769 if (hdmi_infoframe_checksum(buffer
,
1770 HDMI_INFOFRAME_HEADER_SIZE
+ length
) != 0)
1773 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1776 if ((ptr
[0] != 0x03) ||
1781 hdmi_video_format
= ptr
[3] >> 5;
1783 if (hdmi_video_format
> 0x2)
1786 ret
= hdmi_vendor_infoframe_init(hvf
);
1790 hvf
->length
= length
;
1792 if (hdmi_video_format
== 0x2) {
1793 if (length
!= 5 && length
!= 6)
1795 hvf
->s3d_struct
= ptr
[4] >> 4;
1796 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
) {
1799 hvf
->s3d_ext_data
= ptr
[5] >> 4;
1801 } else if (hdmi_video_format
== 0x1) {
1814 * hdmi_drm_infoframe_unpack_only() - unpack binary buffer of CTA-861-G DRM
1815 * infoframe DataBytes to a HDMI DRM
1817 * @frame: HDMI DRM infoframe
1818 * @buffer: source buffer
1819 * @size: size of buffer
1821 * Unpacks CTA-861-G DRM infoframe DataBytes contained in the binary @buffer
1822 * into a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
1825 * Returns 0 on success or a negative error code on failure.
1827 int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe
*frame
,
1828 const void *buffer
, size_t size
)
1830 const u8
*ptr
= buffer
;
1837 if (size
< HDMI_DRM_INFOFRAME_SIZE
)
1840 ret
= hdmi_drm_infoframe_init(frame
);
1844 frame
->eotf
= ptr
[0] & 0x7;
1845 frame
->metadata_type
= ptr
[1] & 0x7;
1848 for (i
= 0; i
< 3; i
++) {
1851 frame
->display_primaries
[i
].x
= (x_msb
<< 8) | x_lsb
;
1854 frame
->display_primaries
[i
].y
= (y_msb
<< 8) | y_lsb
;
1857 frame
->white_point
.x
= (ptr
[15] << 8) | ptr
[14];
1858 frame
->white_point
.y
= (ptr
[17] << 8) | ptr
[16];
1860 frame
->max_display_mastering_luminance
= (ptr
[19] << 8) | ptr
[18];
1861 frame
->min_display_mastering_luminance
= (ptr
[21] << 8) | ptr
[20];
1862 frame
->max_cll
= (ptr
[23] << 8) | ptr
[22];
1863 frame
->max_fall
= (ptr
[25] << 8) | ptr
[24];
1867 EXPORT_SYMBOL(hdmi_drm_infoframe_unpack_only
);
1870 * hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
1871 * @frame: HDMI DRM infoframe
1872 * @buffer: source buffer
1873 * @size: size of buffer
1875 * Unpacks the CTA-861-G DRM infoframe contained in the binary @buffer into
1876 * a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
1877 * infoframe. It also verifies the checksum as required by section 5.3.5 of
1878 * the HDMI 1.4 specification.
1880 * Returns 0 on success or a negative error code on failure.
1882 static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe
*frame
,
1883 const void *buffer
, size_t size
)
1885 const u8
*ptr
= buffer
;
1888 if (size
< HDMI_INFOFRAME_SIZE(DRM
))
1891 if (ptr
[0] != HDMI_INFOFRAME_TYPE_DRM
||
1893 ptr
[2] != HDMI_DRM_INFOFRAME_SIZE
)
1896 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(DRM
)) != 0)
1899 ret
= hdmi_drm_infoframe_unpack_only(frame
, ptr
+ HDMI_INFOFRAME_HEADER_SIZE
,
1900 size
- HDMI_INFOFRAME_HEADER_SIZE
);
1905 * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
1906 * @frame: HDMI infoframe
1907 * @buffer: source buffer
1908 * @size: size of buffer
1910 * Unpacks the information contained in binary buffer @buffer into a structured
1911 * @frame of a HDMI infoframe.
1912 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1915 * Returns 0 on success or a negative error code on failure.
1917 int hdmi_infoframe_unpack(union hdmi_infoframe
*frame
,
1918 const void *buffer
, size_t size
)
1921 const u8
*ptr
= buffer
;
1923 if (size
< HDMI_INFOFRAME_HEADER_SIZE
)
1927 case HDMI_INFOFRAME_TYPE_AVI
:
1928 ret
= hdmi_avi_infoframe_unpack(&frame
->avi
, buffer
, size
);
1930 case HDMI_INFOFRAME_TYPE_DRM
:
1931 ret
= hdmi_drm_infoframe_unpack(&frame
->drm
, buffer
, size
);
1933 case HDMI_INFOFRAME_TYPE_SPD
:
1934 ret
= hdmi_spd_infoframe_unpack(&frame
->spd
, buffer
, size
);
1936 case HDMI_INFOFRAME_TYPE_AUDIO
:
1937 ret
= hdmi_audio_infoframe_unpack(&frame
->audio
, buffer
, size
);
1939 case HDMI_INFOFRAME_TYPE_VENDOR
:
1940 ret
= hdmi_vendor_any_infoframe_unpack(&frame
->vendor
, buffer
, size
);
1949 EXPORT_SYMBOL(hdmi_infoframe_unpack
);