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/string.h>
30 #include <linux/device.h>
32 #define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
34 static u8
hdmi_infoframe_checksum(const 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 void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe
*frame
)
59 memset(frame
, 0, sizeof(*frame
));
61 frame
->type
= HDMI_INFOFRAME_TYPE_AVI
;
63 frame
->length
= HDMI_AVI_INFOFRAME_SIZE
;
65 EXPORT_SYMBOL(hdmi_avi_infoframe_init
);
67 static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe
*frame
)
69 if (frame
->type
!= HDMI_INFOFRAME_TYPE_AVI
||
70 frame
->version
!= 2 ||
71 frame
->length
!= HDMI_AVI_INFOFRAME_SIZE
)
74 if (frame
->picture_aspect
> HDMI_PICTURE_ASPECT_16_9
)
81 * hdmi_avi_infoframe_check() - check a HDMI AVI infoframe
82 * @frame: HDMI AVI infoframe
84 * Validates that the infoframe is consistent and updates derived fields
85 * (eg. length) based on other fields.
87 * Returns 0 on success or a negative error code on failure.
89 int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe
*frame
)
91 return hdmi_avi_infoframe_check_only(frame
);
93 EXPORT_SYMBOL(hdmi_avi_infoframe_check
);
96 * hdmi_avi_infoframe_pack_only() - write HDMI AVI infoframe to binary buffer
97 * @frame: HDMI AVI infoframe
98 * @buffer: destination buffer
99 * @size: size of buffer
101 * Packs the information contained in the @frame structure into a binary
102 * representation that can be written into the corresponding controller
103 * registers. Also computes the checksum as required by section 5.3.5 of
104 * the HDMI 1.4 specification.
106 * Returns the number of bytes packed into the binary buffer or a negative
107 * error code on failure.
109 ssize_t
hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe
*frame
,
110 void *buffer
, size_t size
)
116 ret
= hdmi_avi_infoframe_check_only(frame
);
120 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
125 memset(buffer
, 0, size
);
127 ptr
[0] = frame
->type
;
128 ptr
[1] = frame
->version
;
129 ptr
[2] = frame
->length
;
130 ptr
[3] = 0; /* checksum */
132 /* start infoframe payload */
133 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
135 ptr
[0] = ((frame
->colorspace
& 0x3) << 5) | (frame
->scan_mode
& 0x3);
138 * Data byte 1, bit 4 has to be set if we provide the active format
141 if (frame
->active_aspect
& 0xf)
144 /* Bit 3 and 2 indicate if we transmit horizontal/vertical bar data */
145 if (frame
->top_bar
|| frame
->bottom_bar
)
148 if (frame
->left_bar
|| frame
->right_bar
)
151 ptr
[1] = ((frame
->colorimetry
& 0x3) << 6) |
152 ((frame
->picture_aspect
& 0x3) << 4) |
153 (frame
->active_aspect
& 0xf);
155 ptr
[2] = ((frame
->extended_colorimetry
& 0x7) << 4) |
156 ((frame
->quantization_range
& 0x3) << 2) |
162 ptr
[3] = frame
->video_code
& 0x7f;
164 ptr
[4] = ((frame
->ycc_quantization_range
& 0x3) << 6) |
165 ((frame
->content_type
& 0x3) << 4) |
166 (frame
->pixel_repeat
& 0xf);
168 ptr
[5] = frame
->top_bar
& 0xff;
169 ptr
[6] = (frame
->top_bar
>> 8) & 0xff;
170 ptr
[7] = frame
->bottom_bar
& 0xff;
171 ptr
[8] = (frame
->bottom_bar
>> 8) & 0xff;
172 ptr
[9] = frame
->left_bar
& 0xff;
173 ptr
[10] = (frame
->left_bar
>> 8) & 0xff;
174 ptr
[11] = frame
->right_bar
& 0xff;
175 ptr
[12] = (frame
->right_bar
>> 8) & 0xff;
177 hdmi_infoframe_set_checksum(buffer
, length
);
181 EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only
);
184 * hdmi_avi_infoframe_pack() - check a HDMI AVI infoframe,
185 * and write it to binary buffer
186 * @frame: HDMI AVI infoframe
187 * @buffer: destination buffer
188 * @size: size of buffer
190 * Validates that the infoframe is consistent and updates derived fields
191 * (eg. length) based on other fields, after which it packs the information
192 * contained in the @frame structure into a binary representation that
193 * can be written into the corresponding controller registers. This function
194 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
197 * Returns the number of bytes packed into the binary buffer or a negative
198 * error code on failure.
200 ssize_t
hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe
*frame
,
201 void *buffer
, size_t size
)
205 ret
= hdmi_avi_infoframe_check(frame
);
209 return hdmi_avi_infoframe_pack_only(frame
, buffer
, size
);
211 EXPORT_SYMBOL(hdmi_avi_infoframe_pack
);
214 * hdmi_spd_infoframe_init() - initialize an HDMI SPD infoframe
215 * @frame: HDMI SPD infoframe
216 * @vendor: vendor string
217 * @product: product string
219 * Returns 0 on success or a negative error code on failure.
221 int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe
*frame
,
222 const char *vendor
, const char *product
)
224 memset(frame
, 0, sizeof(*frame
));
226 frame
->type
= HDMI_INFOFRAME_TYPE_SPD
;
228 frame
->length
= HDMI_SPD_INFOFRAME_SIZE
;
230 strncpy(frame
->vendor
, vendor
, sizeof(frame
->vendor
));
231 strncpy(frame
->product
, product
, sizeof(frame
->product
));
235 EXPORT_SYMBOL(hdmi_spd_infoframe_init
);
237 static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe
*frame
)
239 if (frame
->type
!= HDMI_INFOFRAME_TYPE_SPD
||
240 frame
->version
!= 1 ||
241 frame
->length
!= HDMI_SPD_INFOFRAME_SIZE
)
248 * hdmi_spd_infoframe_check() - check a HDMI SPD infoframe
249 * @frame: HDMI SPD infoframe
251 * Validates that the infoframe is consistent and updates derived fields
252 * (eg. length) based on other fields.
254 * Returns 0 on success or a negative error code on failure.
256 int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe
*frame
)
258 return hdmi_spd_infoframe_check_only(frame
);
260 EXPORT_SYMBOL(hdmi_spd_infoframe_check
);
263 * hdmi_spd_infoframe_pack_only() - write HDMI SPD infoframe to binary buffer
264 * @frame: HDMI SPD infoframe
265 * @buffer: destination buffer
266 * @size: size of buffer
268 * Packs the information contained in the @frame structure into a binary
269 * representation that can be written into the corresponding controller
270 * registers. Also computes the checksum as required by section 5.3.5 of
271 * the HDMI 1.4 specification.
273 * Returns the number of bytes packed into the binary buffer or a negative
274 * error code on failure.
276 ssize_t
hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe
*frame
,
277 void *buffer
, size_t size
)
283 ret
= hdmi_spd_infoframe_check_only(frame
);
287 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
292 memset(buffer
, 0, size
);
294 ptr
[0] = frame
->type
;
295 ptr
[1] = frame
->version
;
296 ptr
[2] = frame
->length
;
297 ptr
[3] = 0; /* checksum */
299 /* start infoframe payload */
300 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
302 memcpy(ptr
, frame
->vendor
, sizeof(frame
->vendor
));
303 memcpy(ptr
+ 8, frame
->product
, sizeof(frame
->product
));
305 ptr
[24] = frame
->sdi
;
307 hdmi_infoframe_set_checksum(buffer
, length
);
311 EXPORT_SYMBOL(hdmi_spd_infoframe_pack_only
);
314 * hdmi_spd_infoframe_pack() - check a HDMI SPD infoframe,
315 * and write it to binary buffer
316 * @frame: HDMI SPD infoframe
317 * @buffer: destination buffer
318 * @size: size of buffer
320 * Validates that the infoframe is consistent and updates derived fields
321 * (eg. length) based on other fields, after which it packs the information
322 * contained in the @frame structure into a binary representation that
323 * can be written into the corresponding controller registers. This function
324 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
327 * Returns the number of bytes packed into the binary buffer or a negative
328 * error code on failure.
330 ssize_t
hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe
*frame
,
331 void *buffer
, size_t size
)
335 ret
= hdmi_spd_infoframe_check(frame
);
339 return hdmi_spd_infoframe_pack_only(frame
, buffer
, size
);
341 EXPORT_SYMBOL(hdmi_spd_infoframe_pack
);
344 * hdmi_audio_infoframe_init() - initialize an HDMI audio infoframe
345 * @frame: HDMI audio infoframe
347 * Returns 0 on success or a negative error code on failure.
349 int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe
*frame
)
351 memset(frame
, 0, sizeof(*frame
));
353 frame
->type
= HDMI_INFOFRAME_TYPE_AUDIO
;
355 frame
->length
= HDMI_AUDIO_INFOFRAME_SIZE
;
359 EXPORT_SYMBOL(hdmi_audio_infoframe_init
);
361 static int hdmi_audio_infoframe_check_only(const struct hdmi_audio_infoframe
*frame
)
363 if (frame
->type
!= HDMI_INFOFRAME_TYPE_AUDIO
||
364 frame
->version
!= 1 ||
365 frame
->length
!= HDMI_AUDIO_INFOFRAME_SIZE
)
372 * hdmi_audio_infoframe_check() - check a HDMI audio infoframe
373 * @frame: HDMI audio infoframe
375 * Validates that the infoframe is consistent and updates derived fields
376 * (eg. length) based on other fields.
378 * Returns 0 on success or a negative error code on failure.
380 int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe
*frame
)
382 return hdmi_audio_infoframe_check_only(frame
);
384 EXPORT_SYMBOL(hdmi_audio_infoframe_check
);
387 * hdmi_audio_infoframe_pack_only() - write HDMI audio infoframe to binary buffer
388 * @frame: HDMI audio infoframe
389 * @buffer: destination buffer
390 * @size: size of buffer
392 * Packs the information contained in the @frame structure into a binary
393 * representation that can be written into the corresponding controller
394 * registers. Also computes the checksum as required by section 5.3.5 of
395 * the HDMI 1.4 specification.
397 * Returns the number of bytes packed into the binary buffer or a negative
398 * error code on failure.
400 ssize_t
hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe
*frame
,
401 void *buffer
, size_t size
)
403 unsigned char channels
;
408 ret
= hdmi_audio_infoframe_check_only(frame
);
412 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
417 memset(buffer
, 0, size
);
419 if (frame
->channels
>= 2)
420 channels
= frame
->channels
- 1;
424 ptr
[0] = frame
->type
;
425 ptr
[1] = frame
->version
;
426 ptr
[2] = frame
->length
;
427 ptr
[3] = 0; /* checksum */
429 /* start infoframe payload */
430 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
432 ptr
[0] = ((frame
->coding_type
& 0xf) << 4) | (channels
& 0x7);
433 ptr
[1] = ((frame
->sample_frequency
& 0x7) << 2) |
434 (frame
->sample_size
& 0x3);
435 ptr
[2] = frame
->coding_type_ext
& 0x1f;
436 ptr
[3] = frame
->channel_allocation
;
437 ptr
[4] = (frame
->level_shift_value
& 0xf) << 3;
439 if (frame
->downmix_inhibit
)
442 hdmi_infoframe_set_checksum(buffer
, length
);
446 EXPORT_SYMBOL(hdmi_audio_infoframe_pack_only
);
449 * hdmi_audio_infoframe_pack() - check a HDMI Audio infoframe,
450 * and write it to binary buffer
451 * @frame: HDMI Audio infoframe
452 * @buffer: destination buffer
453 * @size: size of buffer
455 * Validates that the infoframe is consistent and updates derived fields
456 * (eg. length) based on other fields, after which it packs the information
457 * contained in the @frame structure into a binary representation that
458 * can be written into the corresponding controller registers. This function
459 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
462 * Returns the number of bytes packed into the binary buffer or a negative
463 * error code on failure.
465 ssize_t
hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe
*frame
,
466 void *buffer
, size_t size
)
470 ret
= hdmi_audio_infoframe_check(frame
);
474 return hdmi_audio_infoframe_pack_only(frame
, buffer
, size
);
476 EXPORT_SYMBOL(hdmi_audio_infoframe_pack
);
479 * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
480 * @frame: HDMI vendor infoframe
482 * Returns 0 on success or a negative error code on failure.
484 int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe
*frame
)
486 memset(frame
, 0, sizeof(*frame
));
488 frame
->type
= HDMI_INFOFRAME_TYPE_VENDOR
;
491 frame
->oui
= HDMI_IEEE_OUI
;
494 * 0 is a valid value for s3d_struct, so we use a special "not set"
497 frame
->s3d_struct
= HDMI_3D_STRUCTURE_INVALID
;
502 EXPORT_SYMBOL(hdmi_vendor_infoframe_init
);
504 static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe
*frame
)
506 /* for side by side (half) we also need to provide 3D_Ext_Data */
507 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
509 else if (frame
->vic
!= 0 || frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
)
515 static int hdmi_vendor_infoframe_check_only(const struct hdmi_vendor_infoframe
*frame
)
517 if (frame
->type
!= HDMI_INFOFRAME_TYPE_VENDOR
||
518 frame
->version
!= 1 ||
519 frame
->oui
!= HDMI_IEEE_OUI
)
522 /* only one of those can be supplied */
523 if (frame
->vic
!= 0 && frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
)
526 if (frame
->length
!= hdmi_vendor_infoframe_length(frame
))
533 * hdmi_vendor_infoframe_check() - check a HDMI vendor infoframe
534 * @frame: HDMI infoframe
536 * Validates that the infoframe is consistent and updates derived fields
537 * (eg. length) based on other fields.
539 * Returns 0 on success or a negative error code on failure.
541 int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe
*frame
)
543 frame
->length
= hdmi_vendor_infoframe_length(frame
);
545 return hdmi_vendor_infoframe_check_only(frame
);
547 EXPORT_SYMBOL(hdmi_vendor_infoframe_check
);
550 * hdmi_vendor_infoframe_pack_only() - write a HDMI vendor infoframe to binary buffer
551 * @frame: HDMI infoframe
552 * @buffer: destination buffer
553 * @size: size of buffer
555 * Packs the information contained in the @frame structure into a binary
556 * representation that can be written into the corresponding controller
557 * registers. Also computes the checksum as required by section 5.3.5 of
558 * the HDMI 1.4 specification.
560 * Returns the number of bytes packed into the binary buffer or a negative
561 * error code on failure.
563 ssize_t
hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe
*frame
,
564 void *buffer
, size_t size
)
570 ret
= hdmi_vendor_infoframe_check_only(frame
);
574 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
579 memset(buffer
, 0, size
);
581 ptr
[0] = frame
->type
;
582 ptr
[1] = frame
->version
;
583 ptr
[2] = frame
->length
;
584 ptr
[3] = 0; /* checksum */
591 if (frame
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
) {
592 ptr
[7] = 0x2 << 5; /* video format */
593 ptr
[8] = (frame
->s3d_struct
& 0xf) << 4;
594 if (frame
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
595 ptr
[9] = (frame
->s3d_ext_data
& 0xf) << 4;
596 } else if (frame
->vic
) {
597 ptr
[7] = 0x1 << 5; /* video format */
600 ptr
[7] = 0x0 << 5; /* video format */
603 hdmi_infoframe_set_checksum(buffer
, length
);
607 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack_only
);
610 * hdmi_vendor_infoframe_pack() - check a HDMI Vendor infoframe,
611 * and write it to binary buffer
612 * @frame: HDMI Vendor infoframe
613 * @buffer: destination buffer
614 * @size: size of buffer
616 * Validates that the infoframe is consistent and updates derived fields
617 * (eg. length) based on other fields, after which it packs the information
618 * contained in the @frame structure into a binary representation that
619 * can be written into the corresponding controller registers. This function
620 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
623 * Returns the number of bytes packed into the binary buffer or a negative
624 * error code on failure.
626 ssize_t
hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe
*frame
,
627 void *buffer
, size_t size
)
631 ret
= hdmi_vendor_infoframe_check(frame
);
635 return hdmi_vendor_infoframe_pack_only(frame
, buffer
, size
);
637 EXPORT_SYMBOL(hdmi_vendor_infoframe_pack
);
640 hdmi_vendor_any_infoframe_check_only(const union hdmi_vendor_any_infoframe
*frame
)
642 if (frame
->any
.type
!= HDMI_INFOFRAME_TYPE_VENDOR
||
643 frame
->any
.version
!= 1)
650 * hdmi_drm_infoframe_init() - initialize an HDMI Dynaminc Range and
651 * mastering infoframe
652 * @frame: HDMI DRM infoframe
654 * Returns 0 on success or a negative error code on failure.
656 int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe
*frame
)
658 memset(frame
, 0, sizeof(*frame
));
660 frame
->type
= HDMI_INFOFRAME_TYPE_DRM
;
662 frame
->length
= HDMI_DRM_INFOFRAME_SIZE
;
666 EXPORT_SYMBOL(hdmi_drm_infoframe_init
);
668 static int hdmi_drm_infoframe_check_only(const struct hdmi_drm_infoframe
*frame
)
670 if (frame
->type
!= HDMI_INFOFRAME_TYPE_DRM
||
674 if (frame
->length
!= HDMI_DRM_INFOFRAME_SIZE
)
681 * hdmi_drm_infoframe_check() - check a HDMI DRM infoframe
682 * @frame: HDMI DRM infoframe
684 * Validates that the infoframe is consistent.
685 * Returns 0 on success or a negative error code on failure.
687 int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe
*frame
)
689 return hdmi_drm_infoframe_check_only(frame
);
691 EXPORT_SYMBOL(hdmi_drm_infoframe_check
);
694 * hdmi_drm_infoframe_pack_only() - write HDMI DRM infoframe to binary buffer
695 * @frame: HDMI DRM infoframe
696 * @buffer: destination buffer
697 * @size: size of buffer
699 * Packs the information contained in the @frame structure into a binary
700 * representation that can be written into the corresponding controller
701 * registers. Also computes the checksum as required by section 5.3.5 of
702 * the HDMI 1.4 specification.
704 * Returns the number of bytes packed into the binary buffer or a negative
705 * error code on failure.
707 ssize_t
hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe
*frame
,
708 void *buffer
, size_t size
)
714 length
= HDMI_INFOFRAME_HEADER_SIZE
+ frame
->length
;
719 memset(buffer
, 0, size
);
721 ptr
[0] = frame
->type
;
722 ptr
[1] = frame
->version
;
723 ptr
[2] = frame
->length
;
724 ptr
[3] = 0; /* checksum */
726 /* start infoframe payload */
727 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
729 *ptr
++ = frame
->eotf
;
730 *ptr
++ = frame
->metadata_type
;
732 for (i
= 0; i
< 3; i
++) {
733 *ptr
++ = frame
->display_primaries
[i
].x
;
734 *ptr
++ = frame
->display_primaries
[i
].x
>> 8;
735 *ptr
++ = frame
->display_primaries
[i
].y
;
736 *ptr
++ = frame
->display_primaries
[i
].y
>> 8;
739 *ptr
++ = frame
->white_point
.x
;
740 *ptr
++ = frame
->white_point
.x
>> 8;
742 *ptr
++ = frame
->white_point
.y
;
743 *ptr
++ = frame
->white_point
.y
>> 8;
745 *ptr
++ = frame
->max_display_mastering_luminance
;
746 *ptr
++ = frame
->max_display_mastering_luminance
>> 8;
748 *ptr
++ = frame
->min_display_mastering_luminance
;
749 *ptr
++ = frame
->min_display_mastering_luminance
>> 8;
751 *ptr
++ = frame
->max_cll
;
752 *ptr
++ = frame
->max_cll
>> 8;
754 *ptr
++ = frame
->max_fall
;
755 *ptr
++ = frame
->max_fall
>> 8;
757 hdmi_infoframe_set_checksum(buffer
, length
);
761 EXPORT_SYMBOL(hdmi_drm_infoframe_pack_only
);
764 * hdmi_drm_infoframe_pack() - check a HDMI DRM infoframe,
765 * and write it to binary buffer
766 * @frame: HDMI DRM infoframe
767 * @buffer: destination buffer
768 * @size: size of buffer
770 * Validates that the infoframe is consistent and updates derived fields
771 * (eg. length) based on other fields, after which it packs the information
772 * contained in the @frame structure into a binary representation that
773 * can be written into the corresponding controller registers. This function
774 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
777 * Returns the number of bytes packed into the binary buffer or a negative
778 * error code on failure.
780 ssize_t
hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe
*frame
,
781 void *buffer
, size_t size
)
785 ret
= hdmi_drm_infoframe_check(frame
);
789 return hdmi_drm_infoframe_pack_only(frame
, buffer
, size
);
791 EXPORT_SYMBOL(hdmi_drm_infoframe_pack
);
794 * hdmi_vendor_any_infoframe_check() - check a vendor infoframe
797 hdmi_vendor_any_infoframe_check(union hdmi_vendor_any_infoframe
*frame
)
801 ret
= hdmi_vendor_any_infoframe_check_only(frame
);
805 /* we only know about HDMI vendor infoframes */
806 if (frame
->any
.oui
!= HDMI_IEEE_OUI
)
809 return hdmi_vendor_infoframe_check(&frame
->hdmi
);
813 * hdmi_vendor_any_infoframe_pack_only() - write a vendor infoframe to binary buffer
816 hdmi_vendor_any_infoframe_pack_only(const union hdmi_vendor_any_infoframe
*frame
,
817 void *buffer
, size_t size
)
821 ret
= hdmi_vendor_any_infoframe_check_only(frame
);
825 /* we only know about HDMI vendor infoframes */
826 if (frame
->any
.oui
!= HDMI_IEEE_OUI
)
829 return hdmi_vendor_infoframe_pack_only(&frame
->hdmi
, buffer
, size
);
833 * hdmi_vendor_any_infoframe_pack() - check a vendor infoframe,
834 * and write it to binary buffer
837 hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe
*frame
,
838 void *buffer
, size_t size
)
842 ret
= hdmi_vendor_any_infoframe_check(frame
);
846 return hdmi_vendor_any_infoframe_pack_only(frame
, buffer
, size
);
850 * hdmi_infoframe_check() - check a HDMI infoframe
851 * @frame: HDMI infoframe
853 * Validates that the infoframe is consistent and updates derived fields
854 * (eg. length) based on other fields.
856 * Returns 0 on success or a negative error code on failure.
859 hdmi_infoframe_check(union hdmi_infoframe
*frame
)
861 switch (frame
->any
.type
) {
862 case HDMI_INFOFRAME_TYPE_AVI
:
863 return hdmi_avi_infoframe_check(&frame
->avi
);
864 case HDMI_INFOFRAME_TYPE_SPD
:
865 return hdmi_spd_infoframe_check(&frame
->spd
);
866 case HDMI_INFOFRAME_TYPE_AUDIO
:
867 return hdmi_audio_infoframe_check(&frame
->audio
);
868 case HDMI_INFOFRAME_TYPE_VENDOR
:
869 return hdmi_vendor_any_infoframe_check(&frame
->vendor
);
871 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
875 EXPORT_SYMBOL(hdmi_infoframe_check
);
878 * hdmi_infoframe_pack_only() - write a HDMI infoframe to binary buffer
879 * @frame: HDMI infoframe
880 * @buffer: destination buffer
881 * @size: size of buffer
883 * Packs the information contained in the @frame structure into a binary
884 * representation that can be written into the corresponding controller
885 * registers. Also computes the checksum as required by section 5.3.5 of
886 * the HDMI 1.4 specification.
888 * Returns the number of bytes packed into the binary buffer or a negative
889 * error code on failure.
892 hdmi_infoframe_pack_only(const union hdmi_infoframe
*frame
, void *buffer
, size_t size
)
896 switch (frame
->any
.type
) {
897 case HDMI_INFOFRAME_TYPE_AVI
:
898 length
= hdmi_avi_infoframe_pack_only(&frame
->avi
,
901 case HDMI_INFOFRAME_TYPE_DRM
:
902 length
= hdmi_drm_infoframe_pack_only(&frame
->drm
,
905 case HDMI_INFOFRAME_TYPE_SPD
:
906 length
= hdmi_spd_infoframe_pack_only(&frame
->spd
,
909 case HDMI_INFOFRAME_TYPE_AUDIO
:
910 length
= hdmi_audio_infoframe_pack_only(&frame
->audio
,
913 case HDMI_INFOFRAME_TYPE_VENDOR
:
914 length
= hdmi_vendor_any_infoframe_pack_only(&frame
->vendor
,
918 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
924 EXPORT_SYMBOL(hdmi_infoframe_pack_only
);
927 * hdmi_infoframe_pack() - check a HDMI infoframe,
928 * and write it to binary buffer
929 * @frame: HDMI infoframe
930 * @buffer: destination buffer
931 * @size: size of buffer
933 * Validates that the infoframe is consistent and updates derived fields
934 * (eg. length) based on other fields, after which it packs the information
935 * contained in the @frame structure into a binary representation that
936 * can be written into the corresponding controller registers. This function
937 * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
940 * Returns the number of bytes packed into the binary buffer or a negative
941 * error code on failure.
944 hdmi_infoframe_pack(union hdmi_infoframe
*frame
,
945 void *buffer
, size_t size
)
949 switch (frame
->any
.type
) {
950 case HDMI_INFOFRAME_TYPE_AVI
:
951 length
= hdmi_avi_infoframe_pack(&frame
->avi
, buffer
, size
);
953 case HDMI_INFOFRAME_TYPE_DRM
:
954 length
= hdmi_drm_infoframe_pack(&frame
->drm
, buffer
, size
);
956 case HDMI_INFOFRAME_TYPE_SPD
:
957 length
= hdmi_spd_infoframe_pack(&frame
->spd
, buffer
, size
);
959 case HDMI_INFOFRAME_TYPE_AUDIO
:
960 length
= hdmi_audio_infoframe_pack(&frame
->audio
, buffer
, size
);
962 case HDMI_INFOFRAME_TYPE_VENDOR
:
963 length
= hdmi_vendor_any_infoframe_pack(&frame
->vendor
,
967 WARN(1, "Bad infoframe type %d\n", frame
->any
.type
);
973 EXPORT_SYMBOL(hdmi_infoframe_pack
);
975 static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type
)
977 if (type
< 0x80 || type
> 0x9f)
980 case HDMI_INFOFRAME_TYPE_VENDOR
:
982 case HDMI_INFOFRAME_TYPE_AVI
:
983 return "Auxiliary Video Information (AVI)";
984 case HDMI_INFOFRAME_TYPE_SPD
:
985 return "Source Product Description (SPD)";
986 case HDMI_INFOFRAME_TYPE_AUDIO
:
988 case HDMI_INFOFRAME_TYPE_DRM
:
989 return "Dynamic Range and Mastering";
994 static void hdmi_infoframe_log_header(const char *level
,
996 const struct hdmi_any_infoframe
*frame
)
998 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
999 hdmi_infoframe_type_get_name(frame
->type
),
1000 frame
->version
, frame
->length
);
1003 static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace
)
1005 switch (colorspace
) {
1006 case HDMI_COLORSPACE_RGB
:
1008 case HDMI_COLORSPACE_YUV422
:
1009 return "YCbCr 4:2:2";
1010 case HDMI_COLORSPACE_YUV444
:
1011 return "YCbCr 4:4:4";
1012 case HDMI_COLORSPACE_YUV420
:
1013 return "YCbCr 4:2:0";
1014 case HDMI_COLORSPACE_RESERVED4
:
1015 return "Reserved (4)";
1016 case HDMI_COLORSPACE_RESERVED5
:
1017 return "Reserved (5)";
1018 case HDMI_COLORSPACE_RESERVED6
:
1019 return "Reserved (6)";
1020 case HDMI_COLORSPACE_IDO_DEFINED
:
1021 return "IDO Defined";
1026 static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode
)
1028 switch (scan_mode
) {
1029 case HDMI_SCAN_MODE_NONE
:
1031 case HDMI_SCAN_MODE_OVERSCAN
:
1033 case HDMI_SCAN_MODE_UNDERSCAN
:
1035 case HDMI_SCAN_MODE_RESERVED
:
1041 static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry
)
1043 switch (colorimetry
) {
1044 case HDMI_COLORIMETRY_NONE
:
1046 case HDMI_COLORIMETRY_ITU_601
:
1048 case HDMI_COLORIMETRY_ITU_709
:
1050 case HDMI_COLORIMETRY_EXTENDED
:
1057 hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect
)
1059 switch (picture_aspect
) {
1060 case HDMI_PICTURE_ASPECT_NONE
:
1062 case HDMI_PICTURE_ASPECT_4_3
:
1064 case HDMI_PICTURE_ASPECT_16_9
:
1066 case HDMI_PICTURE_ASPECT_64_27
:
1068 case HDMI_PICTURE_ASPECT_256_135
:
1070 case HDMI_PICTURE_ASPECT_RESERVED
:
1077 hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect
)
1079 if (active_aspect
< 0 || active_aspect
> 0xf)
1082 switch (active_aspect
) {
1083 case HDMI_ACTIVE_ASPECT_16_9_TOP
:
1085 case HDMI_ACTIVE_ASPECT_14_9_TOP
:
1087 case HDMI_ACTIVE_ASPECT_16_9_CENTER
:
1088 return "16:9 Center";
1089 case HDMI_ACTIVE_ASPECT_PICTURE
:
1090 return "Same as Picture";
1091 case HDMI_ACTIVE_ASPECT_4_3
:
1093 case HDMI_ACTIVE_ASPECT_16_9
:
1095 case HDMI_ACTIVE_ASPECT_14_9
:
1097 case HDMI_ACTIVE_ASPECT_4_3_SP_14_9
:
1098 return "4:3 SP 14:9";
1099 case HDMI_ACTIVE_ASPECT_16_9_SP_14_9
:
1100 return "16:9 SP 14:9";
1101 case HDMI_ACTIVE_ASPECT_16_9_SP_4_3
:
1102 return "16:9 SP 4:3";
1108 hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col
)
1111 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601
:
1113 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709
:
1115 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601
:
1117 case HDMI_EXTENDED_COLORIMETRY_OPYCC_601
:
1119 case HDMI_EXTENDED_COLORIMETRY_OPRGB
:
1121 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM
:
1122 return "BT.2020 Constant Luminance";
1123 case HDMI_EXTENDED_COLORIMETRY_BT2020
:
1125 case HDMI_EXTENDED_COLORIMETRY_RESERVED
:
1132 hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange
)
1135 case HDMI_QUANTIZATION_RANGE_DEFAULT
:
1137 case HDMI_QUANTIZATION_RANGE_LIMITED
:
1139 case HDMI_QUANTIZATION_RANGE_FULL
:
1141 case HDMI_QUANTIZATION_RANGE_RESERVED
:
1147 static const char *hdmi_nups_get_name(enum hdmi_nups nups
)
1150 case HDMI_NUPS_UNKNOWN
:
1151 return "Unknown Non-uniform Scaling";
1152 case HDMI_NUPS_HORIZONTAL
:
1153 return "Horizontally Scaled";
1154 case HDMI_NUPS_VERTICAL
:
1155 return "Vertically Scaled";
1156 case HDMI_NUPS_BOTH
:
1157 return "Horizontally and Vertically Scaled";
1163 hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange
)
1166 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED
:
1168 case HDMI_YCC_QUANTIZATION_RANGE_FULL
:
1175 hdmi_content_type_get_name(enum hdmi_content_type content_type
)
1177 switch (content_type
) {
1178 case HDMI_CONTENT_TYPE_GRAPHICS
:
1180 case HDMI_CONTENT_TYPE_PHOTO
:
1182 case HDMI_CONTENT_TYPE_CINEMA
:
1184 case HDMI_CONTENT_TYPE_GAME
:
1190 static void hdmi_avi_infoframe_log(const char *level
,
1192 const struct hdmi_avi_infoframe
*frame
)
1194 hdmi_infoframe_log_header(level
, dev
,
1195 (const struct hdmi_any_infoframe
*)frame
);
1197 hdmi_log(" colorspace: %s\n",
1198 hdmi_colorspace_get_name(frame
->colorspace
));
1199 hdmi_log(" scan mode: %s\n",
1200 hdmi_scan_mode_get_name(frame
->scan_mode
));
1201 hdmi_log(" colorimetry: %s\n",
1202 hdmi_colorimetry_get_name(frame
->colorimetry
));
1203 hdmi_log(" picture aspect: %s\n",
1204 hdmi_picture_aspect_get_name(frame
->picture_aspect
));
1205 hdmi_log(" active aspect: %s\n",
1206 hdmi_active_aspect_get_name(frame
->active_aspect
));
1207 hdmi_log(" itc: %s\n", frame
->itc
? "IT Content" : "No Data");
1208 hdmi_log(" extended colorimetry: %s\n",
1209 hdmi_extended_colorimetry_get_name(frame
->extended_colorimetry
));
1210 hdmi_log(" quantization range: %s\n",
1211 hdmi_quantization_range_get_name(frame
->quantization_range
));
1212 hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame
->nups
));
1213 hdmi_log(" video code: %u\n", frame
->video_code
);
1214 hdmi_log(" ycc quantization range: %s\n",
1215 hdmi_ycc_quantization_range_get_name(frame
->ycc_quantization_range
));
1216 hdmi_log(" hdmi content type: %s\n",
1217 hdmi_content_type_get_name(frame
->content_type
));
1218 hdmi_log(" pixel repeat: %u\n", frame
->pixel_repeat
);
1219 hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
1220 frame
->top_bar
, frame
->bottom_bar
,
1221 frame
->left_bar
, frame
->right_bar
);
1224 static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi
)
1226 if (sdi
< 0 || sdi
> 0xff)
1229 case HDMI_SPD_SDI_UNKNOWN
:
1231 case HDMI_SPD_SDI_DSTB
:
1232 return "Digital STB";
1233 case HDMI_SPD_SDI_DVDP
:
1234 return "DVD Player";
1235 case HDMI_SPD_SDI_DVHS
:
1237 case HDMI_SPD_SDI_HDDVR
:
1238 return "HDD Videorecorder";
1239 case HDMI_SPD_SDI_DVC
:
1241 case HDMI_SPD_SDI_DSC
:
1243 case HDMI_SPD_SDI_VCD
:
1245 case HDMI_SPD_SDI_GAME
:
1247 case HDMI_SPD_SDI_PC
:
1248 return "PC General";
1249 case HDMI_SPD_SDI_BD
:
1250 return "Blu-Ray Disc (BD)";
1251 case HDMI_SPD_SDI_SACD
:
1252 return "Super Audio CD";
1253 case HDMI_SPD_SDI_HDDVD
:
1255 case HDMI_SPD_SDI_PMP
:
1261 static void hdmi_spd_infoframe_log(const char *level
,
1263 const struct hdmi_spd_infoframe
*frame
)
1267 hdmi_infoframe_log_header(level
, dev
,
1268 (const struct hdmi_any_infoframe
*)frame
);
1270 memset(buf
, 0, sizeof(buf
));
1272 strncpy(buf
, frame
->vendor
, 8);
1273 hdmi_log(" vendor: %s\n", buf
);
1274 strncpy(buf
, frame
->product
, 16);
1275 hdmi_log(" product: %s\n", buf
);
1276 hdmi_log(" source device information: %s (0x%x)\n",
1277 hdmi_spd_sdi_get_name(frame
->sdi
), frame
->sdi
);
1281 hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type
)
1283 switch (coding_type
) {
1284 case HDMI_AUDIO_CODING_TYPE_STREAM
:
1285 return "Refer to Stream Header";
1286 case HDMI_AUDIO_CODING_TYPE_PCM
:
1288 case HDMI_AUDIO_CODING_TYPE_AC3
:
1290 case HDMI_AUDIO_CODING_TYPE_MPEG1
:
1292 case HDMI_AUDIO_CODING_TYPE_MP3
:
1294 case HDMI_AUDIO_CODING_TYPE_MPEG2
:
1296 case HDMI_AUDIO_CODING_TYPE_AAC_LC
:
1298 case HDMI_AUDIO_CODING_TYPE_DTS
:
1300 case HDMI_AUDIO_CODING_TYPE_ATRAC
:
1302 case HDMI_AUDIO_CODING_TYPE_DSD
:
1303 return "One Bit Audio";
1304 case HDMI_AUDIO_CODING_TYPE_EAC3
:
1305 return "Dolby Digital +";
1306 case HDMI_AUDIO_CODING_TYPE_DTS_HD
:
1308 case HDMI_AUDIO_CODING_TYPE_MLP
:
1310 case HDMI_AUDIO_CODING_TYPE_DST
:
1312 case HDMI_AUDIO_CODING_TYPE_WMA_PRO
:
1314 case HDMI_AUDIO_CODING_TYPE_CXT
:
1315 return "Refer to CXT";
1321 hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size
)
1323 switch (sample_size
) {
1324 case HDMI_AUDIO_SAMPLE_SIZE_STREAM
:
1325 return "Refer to Stream Header";
1326 case HDMI_AUDIO_SAMPLE_SIZE_16
:
1328 case HDMI_AUDIO_SAMPLE_SIZE_20
:
1330 case HDMI_AUDIO_SAMPLE_SIZE_24
:
1337 hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq
)
1340 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM
:
1341 return "Refer to Stream Header";
1342 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000
:
1344 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100
:
1345 return "44.1 kHz (CD)";
1346 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000
:
1348 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200
:
1350 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000
:
1352 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400
:
1354 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000
:
1361 hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx
)
1363 if (ctx
< 0 || ctx
> 0x1f)
1367 case HDMI_AUDIO_CODING_TYPE_EXT_CT
:
1368 return "Refer to CT";
1369 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC
:
1371 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2
:
1373 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND
:
1374 return "MPEG SURROUND";
1375 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC
:
1376 return "MPEG-4 HE AAC";
1377 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2
:
1378 return "MPEG-4 HE AAC v2";
1379 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC
:
1380 return "MPEG-4 AAC LC";
1381 case HDMI_AUDIO_CODING_TYPE_EXT_DRA
:
1383 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND
:
1384 return "MPEG-4 HE AAC + MPEG Surround";
1385 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND
:
1386 return "MPEG-4 AAC LC + MPEG Surround";
1391 static void hdmi_audio_infoframe_log(const char *level
,
1393 const struct hdmi_audio_infoframe
*frame
)
1395 hdmi_infoframe_log_header(level
, dev
,
1396 (const struct hdmi_any_infoframe
*)frame
);
1398 if (frame
->channels
)
1399 hdmi_log(" channels: %u\n", frame
->channels
- 1);
1401 hdmi_log(" channels: Refer to stream header\n");
1402 hdmi_log(" coding type: %s\n",
1403 hdmi_audio_coding_type_get_name(frame
->coding_type
));
1404 hdmi_log(" sample size: %s\n",
1405 hdmi_audio_sample_size_get_name(frame
->sample_size
));
1406 hdmi_log(" sample frequency: %s\n",
1407 hdmi_audio_sample_frequency_get_name(frame
->sample_frequency
));
1408 hdmi_log(" coding type ext: %s\n",
1409 hdmi_audio_coding_type_ext_get_name(frame
->coding_type_ext
));
1410 hdmi_log(" channel allocation: 0x%x\n",
1411 frame
->channel_allocation
);
1412 hdmi_log(" level shift value: %u dB\n",
1413 frame
->level_shift_value
);
1414 hdmi_log(" downmix inhibit: %s\n",
1415 frame
->downmix_inhibit
? "Yes" : "No");
1418 static void hdmi_drm_infoframe_log(const char *level
,
1420 const struct hdmi_drm_infoframe
*frame
)
1424 hdmi_infoframe_log_header(level
, dev
,
1425 (struct hdmi_any_infoframe
*)frame
);
1426 hdmi_log("length: %d\n", frame
->length
);
1427 hdmi_log("metadata type: %d\n", frame
->metadata_type
);
1428 hdmi_log("eotf: %d\n", frame
->eotf
);
1429 for (i
= 0; i
< 3; i
++) {
1430 hdmi_log("x[%d]: %d\n", i
, frame
->display_primaries
[i
].x
);
1431 hdmi_log("y[%d]: %d\n", i
, frame
->display_primaries
[i
].y
);
1434 hdmi_log("white point x: %d\n", frame
->white_point
.x
);
1435 hdmi_log("white point y: %d\n", frame
->white_point
.y
);
1437 hdmi_log("max_display_mastering_luminance: %d\n",
1438 frame
->max_display_mastering_luminance
);
1439 hdmi_log("min_display_mastering_luminance: %d\n",
1440 frame
->min_display_mastering_luminance
);
1442 hdmi_log("max_cll: %d\n", frame
->max_cll
);
1443 hdmi_log("max_fall: %d\n", frame
->max_fall
);
1447 hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct
)
1449 if (s3d_struct
< 0 || s3d_struct
> 0xf)
1452 switch (s3d_struct
) {
1453 case HDMI_3D_STRUCTURE_FRAME_PACKING
:
1454 return "Frame Packing";
1455 case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE
:
1456 return "Field Alternative";
1457 case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE
:
1458 return "Line Alternative";
1459 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL
:
1460 return "Side-by-side (Full)";
1461 case HDMI_3D_STRUCTURE_L_DEPTH
:
1463 case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH
:
1464 return "L + Depth + Graphics + Graphics-depth";
1465 case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM
:
1466 return "Top-and-Bottom";
1467 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
:
1468 return "Side-by-side (Half)";
1476 hdmi_vendor_any_infoframe_log(const char *level
,
1478 const union hdmi_vendor_any_infoframe
*frame
)
1480 const struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
1482 hdmi_infoframe_log_header(level
, dev
,
1483 (const struct hdmi_any_infoframe
*)frame
);
1485 if (frame
->any
.oui
!= HDMI_IEEE_OUI
) {
1486 hdmi_log(" not a HDMI vendor infoframe\n");
1489 if (hvf
->vic
== 0 && hvf
->s3d_struct
== HDMI_3D_STRUCTURE_INVALID
) {
1490 hdmi_log(" empty frame\n");
1495 hdmi_log(" HDMI VIC: %u\n", hvf
->vic
);
1496 if (hvf
->s3d_struct
!= HDMI_3D_STRUCTURE_INVALID
) {
1497 hdmi_log(" 3D structure: %s\n",
1498 hdmi_3d_structure_get_name(hvf
->s3d_struct
));
1499 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
)
1500 hdmi_log(" 3D extension data: %d\n",
1506 * hdmi_infoframe_log() - log info of HDMI infoframe
1507 * @level: logging level
1509 * @frame: HDMI infoframe
1511 void hdmi_infoframe_log(const char *level
,
1513 const union hdmi_infoframe
*frame
)
1515 switch (frame
->any
.type
) {
1516 case HDMI_INFOFRAME_TYPE_AVI
:
1517 hdmi_avi_infoframe_log(level
, dev
, &frame
->avi
);
1519 case HDMI_INFOFRAME_TYPE_SPD
:
1520 hdmi_spd_infoframe_log(level
, dev
, &frame
->spd
);
1522 case HDMI_INFOFRAME_TYPE_AUDIO
:
1523 hdmi_audio_infoframe_log(level
, dev
, &frame
->audio
);
1525 case HDMI_INFOFRAME_TYPE_VENDOR
:
1526 hdmi_vendor_any_infoframe_log(level
, dev
, &frame
->vendor
);
1528 case HDMI_INFOFRAME_TYPE_DRM
:
1529 hdmi_drm_infoframe_log(level
, dev
, &frame
->drm
);
1533 EXPORT_SYMBOL(hdmi_infoframe_log
);
1536 * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
1537 * @frame: HDMI AVI infoframe
1538 * @buffer: source buffer
1539 * @size: size of buffer
1541 * Unpacks the information contained in binary @buffer into a structured
1542 * @frame of the HDMI Auxiliary Video (AVI) information frame.
1543 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1546 * Returns 0 on success or a negative error code on failure.
1548 static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe
*frame
,
1549 const void *buffer
, size_t size
)
1551 const u8
*ptr
= buffer
;
1553 if (size
< HDMI_INFOFRAME_SIZE(AVI
))
1556 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AVI
||
1558 ptr
[2] != HDMI_AVI_INFOFRAME_SIZE
)
1561 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AVI
)) != 0)
1564 hdmi_avi_infoframe_init(frame
);
1566 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1568 frame
->colorspace
= (ptr
[0] >> 5) & 0x3;
1570 frame
->active_aspect
= ptr
[1] & 0xf;
1572 frame
->top_bar
= (ptr
[6] << 8) | ptr
[5];
1573 frame
->bottom_bar
= (ptr
[8] << 8) | ptr
[7];
1576 frame
->left_bar
= (ptr
[10] << 8) | ptr
[9];
1577 frame
->right_bar
= (ptr
[12] << 8) | ptr
[11];
1579 frame
->scan_mode
= ptr
[0] & 0x3;
1581 frame
->colorimetry
= (ptr
[1] >> 6) & 0x3;
1582 frame
->picture_aspect
= (ptr
[1] >> 4) & 0x3;
1583 frame
->active_aspect
= ptr
[1] & 0xf;
1585 frame
->itc
= ptr
[2] & 0x80 ? true : false;
1586 frame
->extended_colorimetry
= (ptr
[2] >> 4) & 0x7;
1587 frame
->quantization_range
= (ptr
[2] >> 2) & 0x3;
1588 frame
->nups
= ptr
[2] & 0x3;
1590 frame
->video_code
= ptr
[3] & 0x7f;
1591 frame
->ycc_quantization_range
= (ptr
[4] >> 6) & 0x3;
1592 frame
->content_type
= (ptr
[4] >> 4) & 0x3;
1594 frame
->pixel_repeat
= ptr
[4] & 0xf;
1600 * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
1601 * @frame: HDMI SPD infoframe
1602 * @buffer: source buffer
1603 * @size: size of buffer
1605 * Unpacks the information contained in binary @buffer into a structured
1606 * @frame of the HDMI Source Product Description (SPD) information frame.
1607 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1610 * Returns 0 on success or a negative error code on failure.
1612 static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe
*frame
,
1613 const void *buffer
, size_t size
)
1615 const u8
*ptr
= buffer
;
1618 if (size
< HDMI_INFOFRAME_SIZE(SPD
))
1621 if (ptr
[0] != HDMI_INFOFRAME_TYPE_SPD
||
1623 ptr
[2] != HDMI_SPD_INFOFRAME_SIZE
) {
1627 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(SPD
)) != 0)
1630 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1632 ret
= hdmi_spd_infoframe_init(frame
, ptr
, ptr
+ 8);
1636 frame
->sdi
= ptr
[24];
1642 * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
1643 * @frame: HDMI Audio 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 Audio 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_audio_infoframe_unpack(struct hdmi_audio_infoframe
*frame
,
1655 const void *buffer
, size_t size
)
1657 const u8
*ptr
= buffer
;
1660 if (size
< HDMI_INFOFRAME_SIZE(AUDIO
))
1663 if (ptr
[0] != HDMI_INFOFRAME_TYPE_AUDIO
||
1665 ptr
[2] != HDMI_AUDIO_INFOFRAME_SIZE
) {
1669 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(AUDIO
)) != 0)
1672 ret
= hdmi_audio_infoframe_init(frame
);
1676 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1678 frame
->channels
= ptr
[0] & 0x7;
1679 frame
->coding_type
= (ptr
[0] >> 4) & 0xf;
1680 frame
->sample_size
= ptr
[1] & 0x3;
1681 frame
->sample_frequency
= (ptr
[1] >> 2) & 0x7;
1682 frame
->coding_type_ext
= ptr
[2] & 0x1f;
1683 frame
->channel_allocation
= ptr
[3];
1684 frame
->level_shift_value
= (ptr
[4] >> 3) & 0xf;
1685 frame
->downmix_inhibit
= ptr
[4] & 0x80 ? true : false;
1691 * hdmi_vendor_infoframe_unpack() - unpack binary buffer to a HDMI vendor infoframe
1692 * @frame: HDMI Vendor infoframe
1693 * @buffer: source buffer
1694 * @size: size of buffer
1696 * Unpacks the information contained in binary @buffer into a structured
1697 * @frame of the HDMI Vendor information frame.
1698 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1701 * Returns 0 on success or a negative error code on failure.
1704 hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe
*frame
,
1705 const void *buffer
, size_t size
)
1707 const u8
*ptr
= buffer
;
1710 u8 hdmi_video_format
;
1711 struct hdmi_vendor_infoframe
*hvf
= &frame
->hdmi
;
1713 if (size
< HDMI_INFOFRAME_HEADER_SIZE
)
1716 if (ptr
[0] != HDMI_INFOFRAME_TYPE_VENDOR
||
1718 (ptr
[2] != 4 && ptr
[2] != 5 && ptr
[2] != 6))
1723 if (size
< HDMI_INFOFRAME_HEADER_SIZE
+ length
)
1726 if (hdmi_infoframe_checksum(buffer
,
1727 HDMI_INFOFRAME_HEADER_SIZE
+ length
) != 0)
1730 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1733 if ((ptr
[0] != 0x03) ||
1738 hdmi_video_format
= ptr
[3] >> 5;
1740 if (hdmi_video_format
> 0x2)
1743 ret
= hdmi_vendor_infoframe_init(hvf
);
1747 hvf
->length
= length
;
1749 if (hdmi_video_format
== 0x2) {
1750 if (length
!= 5 && length
!= 6)
1752 hvf
->s3d_struct
= ptr
[4] >> 4;
1753 if (hvf
->s3d_struct
>= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF
) {
1756 hvf
->s3d_ext_data
= ptr
[5] >> 4;
1758 } else if (hdmi_video_format
== 0x1) {
1771 * hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
1772 * @frame: HDMI DRM infoframe
1773 * @buffer: source buffer
1774 * @size: size of buffer
1776 * Unpacks the information contained in binary @buffer into a structured
1777 * @frame of the HDMI Dynamic Range and Mastering (DRM) information frame.
1778 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1781 * Returns 0 on success or a negative error code on failure.
1783 static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe
*frame
,
1784 const void *buffer
, size_t size
)
1786 const u8
*ptr
= buffer
;
1793 if (size
< HDMI_INFOFRAME_SIZE(DRM
))
1796 if (ptr
[0] != HDMI_INFOFRAME_TYPE_DRM
||
1798 ptr
[2] != HDMI_DRM_INFOFRAME_SIZE
)
1801 if (hdmi_infoframe_checksum(buffer
, HDMI_INFOFRAME_SIZE(DRM
)) != 0)
1804 ret
= hdmi_drm_infoframe_init(frame
);
1808 ptr
+= HDMI_INFOFRAME_HEADER_SIZE
;
1810 frame
->eotf
= ptr
[0] & 0x7;
1811 frame
->metadata_type
= ptr
[1] & 0x7;
1814 for (i
= 0; i
< 3; i
++) {
1817 frame
->display_primaries
[i
].x
= (x_msb
<< 8) | x_lsb
;
1820 frame
->display_primaries
[i
].y
= (y_msb
<< 8) | y_lsb
;
1823 frame
->white_point
.x
= (ptr
[15] << 8) | ptr
[14];
1824 frame
->white_point
.y
= (ptr
[17] << 8) | ptr
[16];
1826 frame
->max_display_mastering_luminance
= (ptr
[19] << 8) | ptr
[18];
1827 frame
->min_display_mastering_luminance
= (ptr
[21] << 8) | ptr
[20];
1828 frame
->max_cll
= (ptr
[23] << 8) | ptr
[22];
1829 frame
->max_fall
= (ptr
[25] << 8) | ptr
[24];
1835 * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
1836 * @frame: HDMI infoframe
1837 * @buffer: source buffer
1838 * @size: size of buffer
1840 * Unpacks the information contained in binary buffer @buffer into a structured
1841 * @frame of a HDMI infoframe.
1842 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1845 * Returns 0 on success or a negative error code on failure.
1847 int hdmi_infoframe_unpack(union hdmi_infoframe
*frame
,
1848 const void *buffer
, size_t size
)
1851 const u8
*ptr
= buffer
;
1853 if (size
< HDMI_INFOFRAME_HEADER_SIZE
)
1857 case HDMI_INFOFRAME_TYPE_AVI
:
1858 ret
= hdmi_avi_infoframe_unpack(&frame
->avi
, buffer
, size
);
1860 case HDMI_INFOFRAME_TYPE_DRM
:
1861 ret
= hdmi_drm_infoframe_unpack(&frame
->drm
, buffer
, size
);
1863 case HDMI_INFOFRAME_TYPE_SPD
:
1864 ret
= hdmi_spd_infoframe_unpack(&frame
->spd
, buffer
, size
);
1866 case HDMI_INFOFRAME_TYPE_AUDIO
:
1867 ret
= hdmi_audio_infoframe_unpack(&frame
->audio
, buffer
, size
);
1869 case HDMI_INFOFRAME_TYPE_VENDOR
:
1870 ret
= hdmi_vendor_any_infoframe_unpack(&frame
->vendor
, buffer
, size
);
1879 EXPORT_SYMBOL(hdmi_infoframe_unpack
);