1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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>
31
32#define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
33
34static u8 hdmi_infoframe_checksum(const u8 *ptr, size_t size)
35{
36 u8 csum = 0;
37 size_t i;
38
39
40 for (i = 0; i < size; i++)
41 csum += ptr[i];
42
43 return 256 - csum;
44}
45
46static void hdmi_infoframe_set_checksum(void *buffer, size_t size)
47{
48 u8 *ptr = buffer;
49
50 ptr[3] = hdmi_infoframe_checksum(buffer, size);
51}
52
53
54
55
56
57void hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame)
58{
59 memset(frame, 0, sizeof(*frame));
60
61 frame->type = HDMI_INFOFRAME_TYPE_AVI;
62 frame->version = 2;
63 frame->length = HDMI_AVI_INFOFRAME_SIZE;
64}
65EXPORT_SYMBOL(hdmi_avi_infoframe_init);
66
67static int hdmi_avi_infoframe_check_only(const struct hdmi_avi_infoframe *frame)
68{
69 if (frame->type != HDMI_INFOFRAME_TYPE_AVI ||
70 frame->version != 2 ||
71 frame->length != HDMI_AVI_INFOFRAME_SIZE)
72 return -EINVAL;
73
74 if (frame->picture_aspect > HDMI_PICTURE_ASPECT_16_9)
75 return -EINVAL;
76
77 return 0;
78}
79
80
81
82
83
84
85
86
87
88
89int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame)
90{
91 return hdmi_avi_infoframe_check_only(frame);
92}
93EXPORT_SYMBOL(hdmi_avi_infoframe_check);
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
110 void *buffer, size_t size)
111{
112 u8 *ptr = buffer;
113 size_t length;
114 int ret;
115
116 ret = hdmi_avi_infoframe_check_only(frame);
117 if (ret)
118 return ret;
119
120 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
121
122 if (size < length)
123 return -ENOSPC;
124
125 memset(buffer, 0, size);
126
127 ptr[0] = frame->type;
128 ptr[1] = frame->version;
129 ptr[2] = frame->length;
130 ptr[3] = 0;
131
132
133 ptr += HDMI_INFOFRAME_HEADER_SIZE;
134
135 ptr[0] = ((frame->colorspace & 0x3) << 5) | (frame->scan_mode & 0x3);
136
137
138
139
140
141 if (frame->active_aspect & 0xf)
142 ptr[0] |= BIT(4);
143
144
145 if (frame->top_bar || frame->bottom_bar)
146 ptr[0] |= BIT(3);
147
148 if (frame->left_bar || frame->right_bar)
149 ptr[0] |= BIT(2);
150
151 ptr[1] = ((frame->colorimetry & 0x3) << 6) |
152 ((frame->picture_aspect & 0x3) << 4) |
153 (frame->active_aspect & 0xf);
154
155 ptr[2] = ((frame->extended_colorimetry & 0x7) << 4) |
156 ((frame->quantization_range & 0x3) << 2) |
157 (frame->nups & 0x3);
158
159 if (frame->itc)
160 ptr[2] |= BIT(7);
161
162 ptr[3] = frame->video_code & 0x7f;
163
164 ptr[4] = ((frame->ycc_quantization_range & 0x3) << 6) |
165 ((frame->content_type & 0x3) << 4) |
166 (frame->pixel_repeat & 0xf);
167
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;
176
177 hdmi_infoframe_set_checksum(buffer, length);
178
179 return length;
180}
181EXPORT_SYMBOL(hdmi_avi_infoframe_pack_only);
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame,
201 void *buffer, size_t size)
202{
203 int ret;
204
205 ret = hdmi_avi_infoframe_check(frame);
206 if (ret)
207 return ret;
208
209 return hdmi_avi_infoframe_pack_only(frame, buffer, size);
210}
211EXPORT_SYMBOL(hdmi_avi_infoframe_pack);
212
213
214
215
216
217
218
219
220
221int hdmi_spd_infoframe_init(struct hdmi_spd_infoframe *frame,
222 const char *vendor, const char *product)
223{
224 memset(frame, 0, sizeof(*frame));
225
226 frame->type = HDMI_INFOFRAME_TYPE_SPD;
227 frame->version = 1;
228 frame->length = HDMI_SPD_INFOFRAME_SIZE;
229
230 strncpy(frame->vendor, vendor, sizeof(frame->vendor));
231 strncpy(frame->product, product, sizeof(frame->product));
232
233 return 0;
234}
235EXPORT_SYMBOL(hdmi_spd_infoframe_init);
236
237static int hdmi_spd_infoframe_check_only(const struct hdmi_spd_infoframe *frame)
238{
239 if (frame->type != HDMI_INFOFRAME_TYPE_SPD ||
240 frame->version != 1 ||
241 frame->length != HDMI_SPD_INFOFRAME_SIZE)
242 return -EINVAL;
243
244 return 0;
245}
246
247
248
249
250
251
252
253
254
255
256int hdmi_spd_infoframe_check(struct hdmi_spd_infoframe *frame)
257{
258 return hdmi_spd_infoframe_check_only(frame);
259}
260EXPORT_SYMBOL(hdmi_spd_infoframe_check);
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276ssize_t hdmi_spd_infoframe_pack_only(const struct hdmi_spd_infoframe *frame,
277 void *buffer, size_t size)
278{
279 u8 *ptr = buffer;
280 size_t length;
281 int ret;
282
283 ret = hdmi_spd_infoframe_check_only(frame);
284 if (ret)
285 return ret;
286
287 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
288
289 if (size < length)
290 return -ENOSPC;
291
292 memset(buffer, 0, size);
293
294 ptr[0] = frame->type;
295 ptr[1] = frame->version;
296 ptr[2] = frame->length;
297 ptr[3] = 0;
298
299
300 ptr += HDMI_INFOFRAME_HEADER_SIZE;
301
302 memcpy(ptr, frame->vendor, sizeof(frame->vendor));
303 memcpy(ptr + 8, frame->product, sizeof(frame->product));
304
305 ptr[24] = frame->sdi;
306
307 hdmi_infoframe_set_checksum(buffer, length);
308
309 return length;
310}
311EXPORT_SYMBOL(hdmi_spd_infoframe_pack_only);
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame,
331 void *buffer, size_t size)
332{
333 int ret;
334
335 ret = hdmi_spd_infoframe_check(frame);
336 if (ret)
337 return ret;
338
339 return hdmi_spd_infoframe_pack_only(frame, buffer, size);
340}
341EXPORT_SYMBOL(hdmi_spd_infoframe_pack);
342
343
344
345
346
347
348
349int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame)
350{
351 memset(frame, 0, sizeof(*frame));
352
353 frame->type = HDMI_INFOFRAME_TYPE_AUDIO;
354 frame->version = 1;
355 frame->length = HDMI_AUDIO_INFOFRAME_SIZE;
356
357 return 0;
358}
359EXPORT_SYMBOL(hdmi_audio_infoframe_init);
360
361static int hdmi_audio_infoframe_check_only(const struct hdmi_audio_infoframe *frame)
362{
363 if (frame->type != HDMI_INFOFRAME_TYPE_AUDIO ||
364 frame->version != 1 ||
365 frame->length != HDMI_AUDIO_INFOFRAME_SIZE)
366 return -EINVAL;
367
368 return 0;
369}
370
371
372
373
374
375
376
377
378
379
380int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame)
381{
382 return hdmi_audio_infoframe_check_only(frame);
383}
384EXPORT_SYMBOL(hdmi_audio_infoframe_check);
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame,
401 void *buffer, size_t size)
402{
403 unsigned char channels;
404 u8 *ptr = buffer;
405 size_t length;
406 int ret;
407
408 ret = hdmi_audio_infoframe_check_only(frame);
409 if (ret)
410 return ret;
411
412 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
413
414 if (size < length)
415 return -ENOSPC;
416
417 memset(buffer, 0, size);
418
419 if (frame->channels >= 2)
420 channels = frame->channels - 1;
421 else
422 channels = 0;
423
424 ptr[0] = frame->type;
425 ptr[1] = frame->version;
426 ptr[2] = frame->length;
427 ptr[3] = 0;
428
429
430 ptr += HDMI_INFOFRAME_HEADER_SIZE;
431
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;
438
439 if (frame->downmix_inhibit)
440 ptr[4] |= BIT(7);
441
442 hdmi_infoframe_set_checksum(buffer, length);
443
444 return length;
445}
446EXPORT_SYMBOL(hdmi_audio_infoframe_pack_only);
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
466 void *buffer, size_t size)
467{
468 int ret;
469
470 ret = hdmi_audio_infoframe_check(frame);
471 if (ret)
472 return ret;
473
474 return hdmi_audio_infoframe_pack_only(frame, buffer, size);
475}
476EXPORT_SYMBOL(hdmi_audio_infoframe_pack);
477
478
479
480
481
482
483
484int hdmi_vendor_infoframe_init(struct hdmi_vendor_infoframe *frame)
485{
486 memset(frame, 0, sizeof(*frame));
487
488 frame->type = HDMI_INFOFRAME_TYPE_VENDOR;
489 frame->version = 1;
490
491 frame->oui = HDMI_IEEE_OUI;
492
493
494
495
496
497 frame->s3d_struct = HDMI_3D_STRUCTURE_INVALID;
498 frame->length = 4;
499
500 return 0;
501}
502EXPORT_SYMBOL(hdmi_vendor_infoframe_init);
503
504static int hdmi_vendor_infoframe_length(const struct hdmi_vendor_infoframe *frame)
505{
506
507 if (frame->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
508 return 6;
509 else if (frame->vic != 0 || frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
510 return 5;
511 else
512 return 4;
513}
514
515static int hdmi_vendor_infoframe_check_only(const struct hdmi_vendor_infoframe *frame)
516{
517 if (frame->type != HDMI_INFOFRAME_TYPE_VENDOR ||
518 frame->version != 1 ||
519 frame->oui != HDMI_IEEE_OUI)
520 return -EINVAL;
521
522
523 if (frame->vic != 0 && frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID)
524 return -EINVAL;
525
526 if (frame->length != hdmi_vendor_infoframe_length(frame))
527 return -EINVAL;
528
529 return 0;
530}
531
532
533
534
535
536
537
538
539
540
541int hdmi_vendor_infoframe_check(struct hdmi_vendor_infoframe *frame)
542{
543 frame->length = hdmi_vendor_infoframe_length(frame);
544
545 return hdmi_vendor_infoframe_check_only(frame);
546}
547EXPORT_SYMBOL(hdmi_vendor_infoframe_check);
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563ssize_t hdmi_vendor_infoframe_pack_only(const struct hdmi_vendor_infoframe *frame,
564 void *buffer, size_t size)
565{
566 u8 *ptr = buffer;
567 size_t length;
568 int ret;
569
570 ret = hdmi_vendor_infoframe_check_only(frame);
571 if (ret)
572 return ret;
573
574 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
575
576 if (size < length)
577 return -ENOSPC;
578
579 memset(buffer, 0, size);
580
581 ptr[0] = frame->type;
582 ptr[1] = frame->version;
583 ptr[2] = frame->length;
584 ptr[3] = 0;
585
586
587 ptr[4] = 0x03;
588 ptr[5] = 0x0c;
589 ptr[6] = 0x00;
590
591 if (frame->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
592 ptr[7] = 0x2 << 5;
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;
598 ptr[8] = frame->vic;
599 } else {
600 ptr[7] = 0x0 << 5;
601 }
602
603 hdmi_infoframe_set_checksum(buffer, length);
604
605 return length;
606}
607EXPORT_SYMBOL(hdmi_vendor_infoframe_pack_only);
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
627 void *buffer, size_t size)
628{
629 int ret;
630
631 ret = hdmi_vendor_infoframe_check(frame);
632 if (ret)
633 return ret;
634
635 return hdmi_vendor_infoframe_pack_only(frame, buffer, size);
636}
637EXPORT_SYMBOL(hdmi_vendor_infoframe_pack);
638
639static int
640hdmi_vendor_any_infoframe_check_only(const union hdmi_vendor_any_infoframe *frame)
641{
642 if (frame->any.type != HDMI_INFOFRAME_TYPE_VENDOR ||
643 frame->any.version != 1)
644 return -EINVAL;
645
646 return 0;
647}
648
649
650
651
652
653
654
655
656int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame)
657{
658 memset(frame, 0, sizeof(*frame));
659
660 frame->type = HDMI_INFOFRAME_TYPE_DRM;
661 frame->version = 1;
662 frame->length = HDMI_DRM_INFOFRAME_SIZE;
663
664 return 0;
665}
666EXPORT_SYMBOL(hdmi_drm_infoframe_init);
667
668static int hdmi_drm_infoframe_check_only(const struct hdmi_drm_infoframe *frame)
669{
670 if (frame->type != HDMI_INFOFRAME_TYPE_DRM ||
671 frame->version != 1)
672 return -EINVAL;
673
674 if (frame->length != HDMI_DRM_INFOFRAME_SIZE)
675 return -EINVAL;
676
677 return 0;
678}
679
680
681
682
683
684
685
686
687int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame)
688{
689 return hdmi_drm_infoframe_check_only(frame);
690}
691EXPORT_SYMBOL(hdmi_drm_infoframe_check);
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
708 void *buffer, size_t size)
709{
710 u8 *ptr = buffer;
711 size_t length;
712 int i;
713
714 length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
715
716 if (size < length)
717 return -ENOSPC;
718
719 memset(buffer, 0, size);
720
721 ptr[0] = frame->type;
722 ptr[1] = frame->version;
723 ptr[2] = frame->length;
724 ptr[3] = 0;
725
726
727 ptr += HDMI_INFOFRAME_HEADER_SIZE;
728
729 *ptr++ = frame->eotf;
730 *ptr++ = frame->metadata_type;
731
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;
737 }
738
739 *ptr++ = frame->white_point.x;
740 *ptr++ = frame->white_point.x >> 8;
741
742 *ptr++ = frame->white_point.y;
743 *ptr++ = frame->white_point.y >> 8;
744
745 *ptr++ = frame->max_display_mastering_luminance;
746 *ptr++ = frame->max_display_mastering_luminance >> 8;
747
748 *ptr++ = frame->min_display_mastering_luminance;
749 *ptr++ = frame->min_display_mastering_luminance >> 8;
750
751 *ptr++ = frame->max_cll;
752 *ptr++ = frame->max_cll >> 8;
753
754 *ptr++ = frame->max_fall;
755 *ptr++ = frame->max_fall >> 8;
756
757 hdmi_infoframe_set_checksum(buffer, length);
758
759 return length;
760}
761EXPORT_SYMBOL(hdmi_drm_infoframe_pack_only);
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame,
781 void *buffer, size_t size)
782{
783 int ret;
784
785 ret = hdmi_drm_infoframe_check(frame);
786 if (ret)
787 return ret;
788
789 return hdmi_drm_infoframe_pack_only(frame, buffer, size);
790}
791EXPORT_SYMBOL(hdmi_drm_infoframe_pack);
792
793
794
795
796static int
797hdmi_vendor_any_infoframe_check(union hdmi_vendor_any_infoframe *frame)
798{
799 int ret;
800
801 ret = hdmi_vendor_any_infoframe_check_only(frame);
802 if (ret)
803 return ret;
804
805
806 if (frame->any.oui != HDMI_IEEE_OUI)
807 return -EINVAL;
808
809 return hdmi_vendor_infoframe_check(&frame->hdmi);
810}
811
812
813
814
815static ssize_t
816hdmi_vendor_any_infoframe_pack_only(const union hdmi_vendor_any_infoframe *frame,
817 void *buffer, size_t size)
818{
819 int ret;
820
821 ret = hdmi_vendor_any_infoframe_check_only(frame);
822 if (ret)
823 return ret;
824
825
826 if (frame->any.oui != HDMI_IEEE_OUI)
827 return -EINVAL;
828
829 return hdmi_vendor_infoframe_pack_only(&frame->hdmi, buffer, size);
830}
831
832
833
834
835
836static ssize_t
837hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe *frame,
838 void *buffer, size_t size)
839{
840 int ret;
841
842 ret = hdmi_vendor_any_infoframe_check(frame);
843 if (ret)
844 return ret;
845
846 return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size);
847}
848
849
850
851
852
853
854
855
856
857
858int
859hdmi_infoframe_check(union hdmi_infoframe *frame)
860{
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);
870 default:
871 WARN(1, "Bad infoframe type %d\n", frame->any.type);
872 return -EINVAL;
873 }
874}
875EXPORT_SYMBOL(hdmi_infoframe_check);
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891ssize_t
892hdmi_infoframe_pack_only(const union hdmi_infoframe *frame, void *buffer, size_t size)
893{
894 ssize_t length;
895
896 switch (frame->any.type) {
897 case HDMI_INFOFRAME_TYPE_AVI:
898 length = hdmi_avi_infoframe_pack_only(&frame->avi,
899 buffer, size);
900 break;
901 case HDMI_INFOFRAME_TYPE_DRM:
902 length = hdmi_drm_infoframe_pack_only(&frame->drm,
903 buffer, size);
904 break;
905 case HDMI_INFOFRAME_TYPE_SPD:
906 length = hdmi_spd_infoframe_pack_only(&frame->spd,
907 buffer, size);
908 break;
909 case HDMI_INFOFRAME_TYPE_AUDIO:
910 length = hdmi_audio_infoframe_pack_only(&frame->audio,
911 buffer, size);
912 break;
913 case HDMI_INFOFRAME_TYPE_VENDOR:
914 length = hdmi_vendor_any_infoframe_pack_only(&frame->vendor,
915 buffer, size);
916 break;
917 default:
918 WARN(1, "Bad infoframe type %d\n", frame->any.type);
919 length = -EINVAL;
920 }
921
922 return length;
923}
924EXPORT_SYMBOL(hdmi_infoframe_pack_only);
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943ssize_t
944hdmi_infoframe_pack(union hdmi_infoframe *frame,
945 void *buffer, size_t size)
946{
947 ssize_t length;
948
949 switch (frame->any.type) {
950 case HDMI_INFOFRAME_TYPE_AVI:
951 length = hdmi_avi_infoframe_pack(&frame->avi, buffer, size);
952 break;
953 case HDMI_INFOFRAME_TYPE_DRM:
954 length = hdmi_drm_infoframe_pack(&frame->drm, buffer, size);
955 break;
956 case HDMI_INFOFRAME_TYPE_SPD:
957 length = hdmi_spd_infoframe_pack(&frame->spd, buffer, size);
958 break;
959 case HDMI_INFOFRAME_TYPE_AUDIO:
960 length = hdmi_audio_infoframe_pack(&frame->audio, buffer, size);
961 break;
962 case HDMI_INFOFRAME_TYPE_VENDOR:
963 length = hdmi_vendor_any_infoframe_pack(&frame->vendor,
964 buffer, size);
965 break;
966 default:
967 WARN(1, "Bad infoframe type %d\n", frame->any.type);
968 length = -EINVAL;
969 }
970
971 return length;
972}
973EXPORT_SYMBOL(hdmi_infoframe_pack);
974
975static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type)
976{
977 if (type < 0x80 || type > 0x9f)
978 return "Invalid";
979 switch (type) {
980 case HDMI_INFOFRAME_TYPE_VENDOR:
981 return "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:
987 return "Audio";
988 case HDMI_INFOFRAME_TYPE_DRM:
989 return "Dynamic Range and Mastering";
990 }
991 return "Reserved";
992}
993
994static void hdmi_infoframe_log_header(const char *level,
995 struct device *dev,
996 const struct hdmi_any_infoframe *frame)
997{
998 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
999 hdmi_infoframe_type_get_name(frame->type),
1000 frame->version, frame->length);
1001}
1002
1003static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace)
1004{
1005 switch (colorspace) {
1006 case HDMI_COLORSPACE_RGB:
1007 return "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";
1022 }
1023 return "Invalid";
1024}
1025
1026static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode)
1027{
1028 switch (scan_mode) {
1029 case HDMI_SCAN_MODE_NONE:
1030 return "No Data";
1031 case HDMI_SCAN_MODE_OVERSCAN:
1032 return "Overscan";
1033 case HDMI_SCAN_MODE_UNDERSCAN:
1034 return "Underscan";
1035 case HDMI_SCAN_MODE_RESERVED:
1036 return "Reserved";
1037 }
1038 return "Invalid";
1039}
1040
1041static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry)
1042{
1043 switch (colorimetry) {
1044 case HDMI_COLORIMETRY_NONE:
1045 return "No Data";
1046 case HDMI_COLORIMETRY_ITU_601:
1047 return "ITU601";
1048 case HDMI_COLORIMETRY_ITU_709:
1049 return "ITU709";
1050 case HDMI_COLORIMETRY_EXTENDED:
1051 return "Extended";
1052 }
1053 return "Invalid";
1054}
1055
1056static const char *
1057hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect)
1058{
1059 switch (picture_aspect) {
1060 case HDMI_PICTURE_ASPECT_NONE:
1061 return "No Data";
1062 case HDMI_PICTURE_ASPECT_4_3:
1063 return "4:3";
1064 case HDMI_PICTURE_ASPECT_16_9:
1065 return "16:9";
1066 case HDMI_PICTURE_ASPECT_64_27:
1067 return "64:27";
1068 case HDMI_PICTURE_ASPECT_256_135:
1069 return "256:135";
1070 case HDMI_PICTURE_ASPECT_RESERVED:
1071 return "Reserved";
1072 }
1073 return "Invalid";
1074}
1075
1076static const char *
1077hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect)
1078{
1079 if (active_aspect < 0 || active_aspect > 0xf)
1080 return "Invalid";
1081
1082 switch (active_aspect) {
1083 case HDMI_ACTIVE_ASPECT_16_9_TOP:
1084 return "16:9 Top";
1085 case HDMI_ACTIVE_ASPECT_14_9_TOP:
1086 return "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:
1092 return "4:3";
1093 case HDMI_ACTIVE_ASPECT_16_9:
1094 return "16:9";
1095 case HDMI_ACTIVE_ASPECT_14_9:
1096 return "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";
1103 }
1104 return "Reserved";
1105}
1106
1107static const char *
1108hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col)
1109{
1110 switch (ext_col) {
1111 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601:
1112 return "xvYCC 601";
1113 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709:
1114 return "xvYCC 709";
1115 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601:
1116 return "sYCC 601";
1117 case HDMI_EXTENDED_COLORIMETRY_OPYCC_601:
1118 return "opYCC 601";
1119 case HDMI_EXTENDED_COLORIMETRY_OPRGB:
1120 return "opRGB";
1121 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM:
1122 return "BT.2020 Constant Luminance";
1123 case HDMI_EXTENDED_COLORIMETRY_BT2020:
1124 return "BT.2020";
1125 case HDMI_EXTENDED_COLORIMETRY_RESERVED:
1126 return "Reserved";
1127 }
1128 return "Invalid";
1129}
1130
1131static const char *
1132hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange)
1133{
1134 switch (qrange) {
1135 case HDMI_QUANTIZATION_RANGE_DEFAULT:
1136 return "Default";
1137 case HDMI_QUANTIZATION_RANGE_LIMITED:
1138 return "Limited";
1139 case HDMI_QUANTIZATION_RANGE_FULL:
1140 return "Full";
1141 case HDMI_QUANTIZATION_RANGE_RESERVED:
1142 return "Reserved";
1143 }
1144 return "Invalid";
1145}
1146
1147static const char *hdmi_nups_get_name(enum hdmi_nups nups)
1148{
1149 switch (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";
1158 }
1159 return "Invalid";
1160}
1161
1162static const char *
1163hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange)
1164{
1165 switch (qrange) {
1166 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED:
1167 return "Limited";
1168 case HDMI_YCC_QUANTIZATION_RANGE_FULL:
1169 return "Full";
1170 }
1171 return "Invalid";
1172}
1173
1174static const char *
1175hdmi_content_type_get_name(enum hdmi_content_type content_type)
1176{
1177 switch (content_type) {
1178 case HDMI_CONTENT_TYPE_GRAPHICS:
1179 return "Graphics";
1180 case HDMI_CONTENT_TYPE_PHOTO:
1181 return "Photo";
1182 case HDMI_CONTENT_TYPE_CINEMA:
1183 return "Cinema";
1184 case HDMI_CONTENT_TYPE_GAME:
1185 return "Game";
1186 }
1187 return "Invalid";
1188}
1189
1190static void hdmi_avi_infoframe_log(const char *level,
1191 struct device *dev,
1192 const struct hdmi_avi_infoframe *frame)
1193{
1194 hdmi_infoframe_log_header(level, dev,
1195 (const struct hdmi_any_infoframe *)frame);
1196
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);
1222}
1223
1224static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi)
1225{
1226 if (sdi < 0 || sdi > 0xff)
1227 return "Invalid";
1228 switch (sdi) {
1229 case HDMI_SPD_SDI_UNKNOWN:
1230 return "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:
1236 return "D-VHS";
1237 case HDMI_SPD_SDI_HDDVR:
1238 return "HDD Videorecorder";
1239 case HDMI_SPD_SDI_DVC:
1240 return "DVC";
1241 case HDMI_SPD_SDI_DSC:
1242 return "DSC";
1243 case HDMI_SPD_SDI_VCD:
1244 return "Video CD";
1245 case HDMI_SPD_SDI_GAME:
1246 return "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:
1254 return "HD DVD";
1255 case HDMI_SPD_SDI_PMP:
1256 return "PMP";
1257 }
1258 return "Reserved";
1259}
1260
1261static void hdmi_spd_infoframe_log(const char *level,
1262 struct device *dev,
1263 const struct hdmi_spd_infoframe *frame)
1264{
1265 u8 buf[17];
1266
1267 hdmi_infoframe_log_header(level, dev,
1268 (const struct hdmi_any_infoframe *)frame);
1269
1270 memset(buf, 0, sizeof(buf));
1271
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);
1278}
1279
1280static const char *
1281hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type)
1282{
1283 switch (coding_type) {
1284 case HDMI_AUDIO_CODING_TYPE_STREAM:
1285 return "Refer to Stream Header";
1286 case HDMI_AUDIO_CODING_TYPE_PCM:
1287 return "PCM";
1288 case HDMI_AUDIO_CODING_TYPE_AC3:
1289 return "AC-3";
1290 case HDMI_AUDIO_CODING_TYPE_MPEG1:
1291 return "MPEG1";
1292 case HDMI_AUDIO_CODING_TYPE_MP3:
1293 return "MP3";
1294 case HDMI_AUDIO_CODING_TYPE_MPEG2:
1295 return "MPEG2";
1296 case HDMI_AUDIO_CODING_TYPE_AAC_LC:
1297 return "AAC";
1298 case HDMI_AUDIO_CODING_TYPE_DTS:
1299 return "DTS";
1300 case HDMI_AUDIO_CODING_TYPE_ATRAC:
1301 return "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:
1307 return "DTS-HD";
1308 case HDMI_AUDIO_CODING_TYPE_MLP:
1309 return "MAT (MLP)";
1310 case HDMI_AUDIO_CODING_TYPE_DST:
1311 return "DST";
1312 case HDMI_AUDIO_CODING_TYPE_WMA_PRO:
1313 return "WMA PRO";
1314 case HDMI_AUDIO_CODING_TYPE_CXT:
1315 return "Refer to CXT";
1316 }
1317 return "Invalid";
1318}
1319
1320static const char *
1321hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size)
1322{
1323 switch (sample_size) {
1324 case HDMI_AUDIO_SAMPLE_SIZE_STREAM:
1325 return "Refer to Stream Header";
1326 case HDMI_AUDIO_SAMPLE_SIZE_16:
1327 return "16 bit";
1328 case HDMI_AUDIO_SAMPLE_SIZE_20:
1329 return "20 bit";
1330 case HDMI_AUDIO_SAMPLE_SIZE_24:
1331 return "24 bit";
1332 }
1333 return "Invalid";
1334}
1335
1336static const char *
1337hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq)
1338{
1339 switch (freq) {
1340 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM:
1341 return "Refer to Stream Header";
1342 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000:
1343 return "32 kHz";
1344 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100:
1345 return "44.1 kHz (CD)";
1346 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000:
1347 return "48 kHz";
1348 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200:
1349 return "88.2 kHz";
1350 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000:
1351 return "96 kHz";
1352 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400:
1353 return "176.4 kHz";
1354 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000:
1355 return "192 kHz";
1356 }
1357 return "Invalid";
1358}
1359
1360static const char *
1361hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx)
1362{
1363 if (ctx < 0 || ctx > 0x1f)
1364 return "Invalid";
1365
1366 switch (ctx) {
1367 case HDMI_AUDIO_CODING_TYPE_EXT_CT:
1368 return "Refer to CT";
1369 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC:
1370 return "HE AAC";
1371 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2:
1372 return "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:
1382 return "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";
1387 }
1388 return "Reserved";
1389}
1390
1391static void hdmi_audio_infoframe_log(const char *level,
1392 struct device *dev,
1393 const struct hdmi_audio_infoframe *frame)
1394{
1395 hdmi_infoframe_log_header(level, dev,
1396 (const struct hdmi_any_infoframe *)frame);
1397
1398 if (frame->channels)
1399 hdmi_log(" channels: %u\n", frame->channels - 1);
1400 else
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");
1416}
1417
1418static void hdmi_drm_infoframe_log(const char *level,
1419 struct device *dev,
1420 const struct hdmi_drm_infoframe *frame)
1421{
1422 int i;
1423
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);
1432 }
1433
1434 hdmi_log("white point x: %d\n", frame->white_point.x);
1435 hdmi_log("white point y: %d\n", frame->white_point.y);
1436
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);
1441
1442 hdmi_log("max_cll: %d\n", frame->max_cll);
1443 hdmi_log("max_fall: %d\n", frame->max_fall);
1444}
1445
1446static const char *
1447hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct)
1448{
1449 if (s3d_struct < 0 || s3d_struct > 0xf)
1450 return "Invalid";
1451
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:
1462 return "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)";
1469 default:
1470 break;
1471 }
1472 return "Reserved";
1473}
1474
1475static void
1476hdmi_vendor_any_infoframe_log(const char *level,
1477 struct device *dev,
1478 const union hdmi_vendor_any_infoframe *frame)
1479{
1480 const struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
1481
1482 hdmi_infoframe_log_header(level, dev,
1483 (const struct hdmi_any_infoframe *)frame);
1484
1485 if (frame->any.oui != HDMI_IEEE_OUI) {
1486 hdmi_log(" not a HDMI vendor infoframe\n");
1487 return;
1488 }
1489 if (hvf->vic == 0 && hvf->s3d_struct == HDMI_3D_STRUCTURE_INVALID) {
1490 hdmi_log(" empty frame\n");
1491 return;
1492 }
1493
1494 if (hvf->vic)
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",
1501 hvf->s3d_ext_data);
1502 }
1503}
1504
1505
1506
1507
1508
1509
1510
1511void hdmi_infoframe_log(const char *level,
1512 struct device *dev,
1513 const union hdmi_infoframe *frame)
1514{
1515 switch (frame->any.type) {
1516 case HDMI_INFOFRAME_TYPE_AVI:
1517 hdmi_avi_infoframe_log(level, dev, &frame->avi);
1518 break;
1519 case HDMI_INFOFRAME_TYPE_SPD:
1520 hdmi_spd_infoframe_log(level, dev, &frame->spd);
1521 break;
1522 case HDMI_INFOFRAME_TYPE_AUDIO:
1523 hdmi_audio_infoframe_log(level, dev, &frame->audio);
1524 break;
1525 case HDMI_INFOFRAME_TYPE_VENDOR:
1526 hdmi_vendor_any_infoframe_log(level, dev, &frame->vendor);
1527 break;
1528 case HDMI_INFOFRAME_TYPE_DRM:
1529 hdmi_drm_infoframe_log(level, dev, &frame->drm);
1530 break;
1531 }
1532}
1533EXPORT_SYMBOL(hdmi_infoframe_log);
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
1549 const void *buffer, size_t size)
1550{
1551 const u8 *ptr = buffer;
1552
1553 if (size < HDMI_INFOFRAME_SIZE(AVI))
1554 return -EINVAL;
1555
1556 if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
1557 ptr[1] != 2 ||
1558 ptr[2] != HDMI_AVI_INFOFRAME_SIZE)
1559 return -EINVAL;
1560
1561 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AVI)) != 0)
1562 return -EINVAL;
1563
1564 hdmi_avi_infoframe_init(frame);
1565
1566 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1567
1568 frame->colorspace = (ptr[0] >> 5) & 0x3;
1569 if (ptr[0] & 0x10)
1570 frame->active_aspect = ptr[1] & 0xf;
1571 if (ptr[0] & 0x8) {
1572 frame->top_bar = (ptr[6] << 8) | ptr[5];
1573 frame->bottom_bar = (ptr[8] << 8) | ptr[7];
1574 }
1575 if (ptr[0] & 0x4) {
1576 frame->left_bar = (ptr[10] << 8) | ptr[9];
1577 frame->right_bar = (ptr[12] << 8) | ptr[11];
1578 }
1579 frame->scan_mode = ptr[0] & 0x3;
1580
1581 frame->colorimetry = (ptr[1] >> 6) & 0x3;
1582 frame->picture_aspect = (ptr[1] >> 4) & 0x3;
1583 frame->active_aspect = ptr[1] & 0xf;
1584
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;
1589
1590 frame->video_code = ptr[3] & 0x7f;
1591 frame->ycc_quantization_range = (ptr[4] >> 6) & 0x3;
1592 frame->content_type = (ptr[4] >> 4) & 0x3;
1593
1594 frame->pixel_repeat = ptr[4] & 0xf;
1595
1596 return 0;
1597}
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
1613 const void *buffer, size_t size)
1614{
1615 const u8 *ptr = buffer;
1616 int ret;
1617
1618 if (size < HDMI_INFOFRAME_SIZE(SPD))
1619 return -EINVAL;
1620
1621 if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
1622 ptr[1] != 1 ||
1623 ptr[2] != HDMI_SPD_INFOFRAME_SIZE) {
1624 return -EINVAL;
1625 }
1626
1627 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(SPD)) != 0)
1628 return -EINVAL;
1629
1630 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1631
1632 ret = hdmi_spd_infoframe_init(frame, ptr, ptr + 8);
1633 if (ret)
1634 return ret;
1635
1636 frame->sdi = ptr[24];
1637
1638 return 0;
1639}
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
1655 const void *buffer, size_t size)
1656{
1657 const u8 *ptr = buffer;
1658 int ret;
1659
1660 if (size < HDMI_INFOFRAME_SIZE(AUDIO))
1661 return -EINVAL;
1662
1663 if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
1664 ptr[1] != 1 ||
1665 ptr[2] != HDMI_AUDIO_INFOFRAME_SIZE) {
1666 return -EINVAL;
1667 }
1668
1669 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AUDIO)) != 0)
1670 return -EINVAL;
1671
1672 ret = hdmi_audio_infoframe_init(frame);
1673 if (ret)
1674 return ret;
1675
1676 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1677
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;
1686
1687 return 0;
1688}
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703static int
1704hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
1705 const void *buffer, size_t size)
1706{
1707 const u8 *ptr = buffer;
1708 size_t length;
1709 int ret;
1710 u8 hdmi_video_format;
1711 struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
1712
1713 if (size < HDMI_INFOFRAME_HEADER_SIZE)
1714 return -EINVAL;
1715
1716 if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
1717 ptr[1] != 1 ||
1718 (ptr[2] != 4 && ptr[2] != 5 && ptr[2] != 6))
1719 return -EINVAL;
1720
1721 length = ptr[2];
1722
1723 if (size < HDMI_INFOFRAME_HEADER_SIZE + length)
1724 return -EINVAL;
1725
1726 if (hdmi_infoframe_checksum(buffer,
1727 HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
1728 return -EINVAL;
1729
1730 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1731
1732
1733 if ((ptr[0] != 0x03) ||
1734 (ptr[1] != 0x0c) ||
1735 (ptr[2] != 0x00))
1736 return -EINVAL;
1737
1738 hdmi_video_format = ptr[3] >> 5;
1739
1740 if (hdmi_video_format > 0x2)
1741 return -EINVAL;
1742
1743 ret = hdmi_vendor_infoframe_init(hvf);
1744 if (ret)
1745 return ret;
1746
1747 hvf->length = length;
1748
1749 if (hdmi_video_format == 0x2) {
1750 if (length != 5 && length != 6)
1751 return -EINVAL;
1752 hvf->s3d_struct = ptr[4] >> 4;
1753 if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
1754 if (length != 6)
1755 return -EINVAL;
1756 hvf->s3d_ext_data = ptr[5] >> 4;
1757 }
1758 } else if (hdmi_video_format == 0x1) {
1759 if (length != 5)
1760 return -EINVAL;
1761 hvf->vic = ptr[4];
1762 } else {
1763 if (length != 4)
1764 return -EINVAL;
1765 }
1766
1767 return 0;
1768}
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
1784 const void *buffer, size_t size)
1785{
1786 const u8 *ptr = buffer;
1787 const u8 *temp;
1788 u8 x_lsb, x_msb;
1789 u8 y_lsb, y_msb;
1790 int ret;
1791 int i;
1792
1793 if (size < HDMI_INFOFRAME_SIZE(DRM))
1794 return -EINVAL;
1795
1796 if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
1797 ptr[1] != 1 ||
1798 ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
1799 return -EINVAL;
1800
1801 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
1802 return -EINVAL;
1803
1804 ret = hdmi_drm_infoframe_init(frame);
1805 if (ret)
1806 return ret;
1807
1808 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1809
1810 frame->eotf = ptr[0] & 0x7;
1811 frame->metadata_type = ptr[1] & 0x7;
1812
1813 temp = ptr + 2;
1814 for (i = 0; i < 3; i++) {
1815 x_lsb = *temp++;
1816 x_msb = *temp++;
1817 frame->display_primaries[i].x = (x_msb << 8) | x_lsb;
1818 y_lsb = *temp++;
1819 y_msb = *temp++;
1820 frame->display_primaries[i].y = (y_msb << 8) | y_lsb;
1821 }
1822
1823 frame->white_point.x = (ptr[15] << 8) | ptr[14];
1824 frame->white_point.y = (ptr[17] << 8) | ptr[16];
1825
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];
1830
1831 return 0;
1832}
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847int hdmi_infoframe_unpack(union hdmi_infoframe *frame,
1848 const void *buffer, size_t size)
1849{
1850 int ret;
1851 const u8 *ptr = buffer;
1852
1853 if (size < HDMI_INFOFRAME_HEADER_SIZE)
1854 return -EINVAL;
1855
1856 switch (ptr[0]) {
1857 case HDMI_INFOFRAME_TYPE_AVI:
1858 ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer, size);
1859 break;
1860 case HDMI_INFOFRAME_TYPE_DRM:
1861 ret = hdmi_drm_infoframe_unpack(&frame->drm, buffer, size);
1862 break;
1863 case HDMI_INFOFRAME_TYPE_SPD:
1864 ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer, size);
1865 break;
1866 case HDMI_INFOFRAME_TYPE_AUDIO:
1867 ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer, size);
1868 break;
1869 case HDMI_INFOFRAME_TYPE_VENDOR:
1870 ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer, size);
1871 break;
1872 default:
1873 ret = -EINVAL;
1874 break;
1875 }
1876
1877 return ret;
1878}
1879EXPORT_SYMBOL(hdmi_infoframe_unpack);
1880