forked from torvalds/linux
/
hdmi_tx_main.c
5086 lines (4495 loc) · 135 KB
/
hdmi_tx_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* drivers/amlogic/media/vout/hdmitx/hdmi_tx_20/hdmi_tx_main.c
*
* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*/
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/mm.h>
#include <linux/major.h>
#include <linux/platform_device.h>
#include <linux/pinctrl/consumer.h>
#include <linux/mutex.h>
#include <linux/cdev.h>
#include <linux/ctype.h>
#include <linux/extcon.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
#include <linux/workqueue.h>
#include <linux/input.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_platform.h>
#include <linux/of_address.h>
#include <linux/reboot.h>
#include <linux/extcon.h>
#include <linux/i2c.h>
#include <linux/amlogic/cpu_version.h>
#include <linux/amlogic/media/vout/vinfo.h>
#include <linux/amlogic/media/vout/vout_notify.h>
#ifdef CONFIG_AMLOGIC_SND_SOC
#include <linux/amlogic/media/sound/aout_notify.h>
#endif
#include <linux/amlogic/media/vout/hdmi_tx/hdmi_info_global.h>
#include <linux/amlogic/media/vout/hdmi_tx/hdmi_tx_ddc.h>
#include <linux/amlogic/media/vout/hdmi_tx/hdmi_tx_module.h>
#include <linux/amlogic/media/vout/hdmi_tx/hdmi_config.h>
#include "hw/tvenc_conf.h"
#include "hw/hdmi_tx_reg.h"
#include "hw/mach_reg.h"
#include "hw/common.h"
#include "hw/hw_clk.h"
#include "hdmi_tx_hdcp.h"
#define DEVICE_NAME "amhdmitx"
#define HDMI_TX_COUNT 32
#define HDMI_TX_POOL_NUM 6
#define HDMI_TX_RESOURCE_NUM 4
#define HDMI_TX_PWR_CTRL_NUM 6
static struct class *hdmitx_class;
static int set_disp_mode_auto(void);
static void hdmitx_get_edid(struct hdmitx_dev *hdev);
static void hdmitx_set_drm_pkt(struct master_display_info_s *data);
static void hdmitx_set_vsif_pkt(enum eotf_type type, enum mode_type
tunnel_mode, struct dv_vsif_para *data);
static void hdmitx_set_hdr10plus_pkt(unsigned int flag,
struct hdr10plus_para *data);
static void hdmitx_set_emp_pkt(unsigned char *data,
unsigned int type, unsigned int size);
static int check_fbc_special(unsigned char *edid_dat);
static struct vinfo_s *hdmitx_get_current_vinfo(void);
static DEFINE_MUTEX(setclk_mutex);
static DEFINE_MUTEX(getedid_mutex);
static struct hdmitx_dev hdmitx_device = {
.frac_rate_policy = 1,
};
struct vout_device_s hdmitx_vdev = {
.dv_info = &(hdmitx_device.RXCap.dv_info),
.fresh_tx_hdr_pkt = hdmitx_set_drm_pkt,
.fresh_tx_vsif_pkt = hdmitx_set_vsif_pkt,
.fresh_tx_hdr10plus_pkt = hdmitx_set_hdr10plus_pkt,
.fresh_tx_emp_pkt = hdmitx_set_emp_pkt,
};
struct hdmi_config_platform_data *hdmi_pdata;
static const unsigned int hdmi_cable[] = {
EXTCON_DISP_HDMI,
EXTCON_NONE,
};
struct extcon_dev *hdmitx_extcon_hdmi;
struct extcon_dev *hdmitx_extcon_audio;
struct extcon_dev *hdmitx_extcon_power;
struct extcon_dev *hdmitx_extcon_hdr;
struct extcon_dev *hdmitx_extcon_rxsense;
struct extcon_dev *hdmitx_extcon_hdcp;
void control_hdmiphy(bool on)
{
if (on)
hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_TMDS_PHY_OP,
TMDS_PHY_ENABLE);
else
hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_TMDS_PHY_OP,
TMDS_PHY_DISABLE);
}
static struct hdmi_cea_timing custom_timing;
struct hdmi_cea_timing *get_custom_timing(void)
{
return &custom_timing;
}
EXPORT_SYMBOL(get_custom_timing);
static inline void hdmitx_notify_hpd(int hpd)
{
if (hpd)
hdmitx_event_notify(HDMITX_PLUG, NULL);
else
hdmitx_event_notify(HDMITX_UNPLUG, NULL);
}
#ifdef CONFIG_AMLOGIC_LEGACY_EARLY_SUSPEND
#include <linux/amlogic/pm.h>
static void hdmitx_early_suspend(struct early_suspend *h)
{
struct hdmitx_dev *phdmi = (struct hdmitx_dev *)h->param;
phdmi->ready = 0;
phdmi->hpd_lock = 1;
msleep(20);
phdmi->HWOp.CntlMisc(phdmi, MISC_AVMUTE_OP, SET_AVMUTE);
mdelay(100);
pr_info(SYS "HDMITX: early suspend\n");
phdmi->HWOp.Cntl((struct hdmitx_dev *)h->param,
HDMITX_EARLY_SUSPEND_RESUME_CNTL, HDMITX_EARLY_SUSPEND);
phdmi->cur_VIC = HDMI_Unknown;
phdmi->output_blank_flag = 0;
phdmi->HWOp.CntlDDC(phdmi, DDC_HDCP_MUX_INIT, 1);
phdmi->HWOp.CntlDDC(phdmi, DDC_HDCP_OP, HDCP14_OFF);
extcon_set_state_sync(hdmitx_extcon_power, EXTCON_DISP_HDMI, 0);
phdmi->HWOp.CntlConfig(&hdmitx_device, CONF_CLR_AVI_PACKET, 0);
phdmi->HWOp.CntlConfig(&hdmitx_device, CONF_CLR_VSDB_PACKET, 0);
/*close vpu clk*/
if (phdmi->hdmitx_clk_tree.hdmi_clk_vapb != NULL)
clk_disable_unprepare(phdmi->hdmitx_clk_tree.hdmi_clk_vapb);
if (phdmi->hdmitx_clk_tree.hdmi_clk_vpu != NULL)
clk_disable_unprepare(phdmi->hdmitx_clk_tree.hdmi_clk_vpu);
}
static int hdmitx_is_hdmi_vmode(char *mode_name)
{
enum hdmi_vic vic = hdmitx_edid_vic_tab_map_vic(mode_name);
if (vic == HDMI_Unknown)
return 0;
return 1;
}
static void hdmitx_late_resume(struct early_suspend *h)
{
const struct vinfo_s *info = hdmitx_get_current_vinfo();
struct hdmitx_dev *phdmi = (struct hdmitx_dev *)h->param;
/*open vpu clk*/
if (phdmi->hdmitx_clk_tree.hdmi_clk_vapb != NULL)
clk_prepare_enable(phdmi->hdmitx_clk_tree.hdmi_clk_vapb);
if (phdmi->hdmitx_clk_tree.hdmi_clk_vpu != NULL)
clk_prepare_enable(phdmi->hdmitx_clk_tree.hdmi_clk_vpu);
if (info && (hdmitx_is_hdmi_vmode(info->name) == 1))
phdmi->HWOp.CntlMisc(&hdmitx_device, MISC_HPLL_FAKE, 0);
phdmi->hpd_lock = 0;
/* update status for hpd and switch/state */
hdmitx_device.hpd_state = !!(hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_HPD_GPI_ST, 0));
pr_info("hdmitx hpd state: %d\n", hdmitx_device.hpd_state);
hdmitx_notify_hpd(hdmitx_device.hpd_state);
/*force to get EDID after resume for Amplifer Power case*/
if (hdmitx_device.hpd_state)
hdmitx_get_edid(phdmi);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_MUTE);
set_disp_mode_auto();
extcon_set_state_sync(hdmitx_extcon_hdmi, EXTCON_DISP_HDMI,
hdmitx_device.hpd_state);
extcon_set_state_sync(hdmitx_extcon_power, EXTCON_DISP_HDMI, 1);
extcon_set_state_sync(hdmitx_extcon_audio, EXTCON_DISP_HDMI,
hdmitx_device.hpd_state);
pr_info("amhdmitx: late resume module %d\n", __LINE__);
phdmi->HWOp.Cntl((struct hdmitx_dev *)h->param,
HDMITX_EARLY_SUSPEND_RESUME_CNTL, HDMITX_LATE_RESUME);
pr_info(SYS "late resume\n");
}
/* Set avmute_set signal to HDMIRX */
static int hdmitx_reboot_notifier(struct notifier_block *nb,
unsigned long action, void *data)
{
struct hdmitx_dev *hdev = container_of(nb, struct hdmitx_dev, nb);
hdev->ready = 0;
hdev->HWOp.CntlMisc(hdev, MISC_AVMUTE_OP, SET_AVMUTE);
mdelay(100);
hdev->HWOp.CntlMisc(hdev, MISC_TMDS_PHY_OP, TMDS_PHY_DISABLE);
hdev->HWOp.Cntl(hdev, HDMITX_EARLY_SUSPEND_RESUME_CNTL,
HDMITX_EARLY_SUSPEND);
return NOTIFY_OK;
}
static struct early_suspend hdmitx_early_suspend_handler = {
.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 10,
.suspend = hdmitx_early_suspend,
.resume = hdmitx_late_resume,
.param = &hdmitx_device,
};
#endif
#define INIT_FLAG_VDACOFF 0x1
/* unplug powerdown */
#define INIT_FLAG_POWERDOWN 0x2
#define INIT_FLAG_NOT_LOAD 0x80
static unsigned char init_flag;
#undef DISABLE_AUDIO
int get_cur_vout_index(void)
/*
* return value: 1, vout; 2, vout2;
*/
{
int vout_index = 1;
return vout_index;
}
static int set_disp_mode(const char *mode)
{
int ret = -1;
enum hdmi_vic vic;
vic = hdmitx_edid_get_VIC(&hdmitx_device, mode, 1);
if (strncmp(mode, "2160p30hz", strlen("2160p30hz")) == 0)
vic = HDMI_4k2k_30;
else if (strncmp(mode, "2160p25hz", strlen("2160p25hz")) == 0)
vic = HDMI_4k2k_25;
else if (strncmp(mode, "2160p24hz", strlen("2160p24hz")) == 0)
vic = HDMI_4k2k_24;
else if (strncmp(mode, "smpte24hz", strlen("smpte24hz")) == 0)
vic = HDMI_4k2k_smpte_24;
else
;/* nothing */
if (strncmp(mode, "1080p60hz", strlen("1080p60hz")) == 0)
vic = HDMI_1080p60;
if (strncmp(mode, "1080p50hz", strlen("1080p50hz")) == 0)
vic = HDMI_1080p50;
if (vic != HDMI_Unknown) {
hdmitx_device.mux_hpd_if_pin_high_flag = 1;
if (hdmitx_device.vic_count == 0) {
if (hdmitx_device.unplug_powerdown)
return 0;
}
}
hdmitx_device.cur_VIC = HDMI_Unknown;
ret = hdmitx_set_display(&hdmitx_device, vic);
if (ret >= 0) {
hdmitx_device.HWOp.Cntl(&hdmitx_device,
HDMITX_AVMUTE_CNTL, AVMUTE_CLEAR);
hdmitx_device.cur_VIC = vic;
hdmitx_device.audio_param_update_flag = 1;
hdmitx_device.auth_process_timer = AUTH_PROCESS_TIME;
}
if (hdmitx_device.cur_VIC == HDMI_Unknown) {
if (hdmitx_device.hpdmode == 2) {
/* edid will be read again when hpd is muxed and
* it is high
*/
hdmitx_edid_clear(&hdmitx_device);
hdmitx_device.mux_hpd_if_pin_high_flag = 0;
}
if (hdmitx_device.HWOp.Cntl) {
hdmitx_device.HWOp.Cntl(&hdmitx_device,
HDMITX_HWCMD_TURNOFF_HDMIHW,
(hdmitx_device.hpdmode == 2)?1:0);
}
}
return ret;
}
static void hdmitx_pre_display_init(void)
{
hdmitx_device.cur_VIC = HDMI_Unknown;
hdmitx_device.auth_process_timer = AUTH_PROCESS_TIME;
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_MUTE);
hdmitx_device.HWOp.CntlDDC(&hdmitx_device, DDC_HDCP_MUX_INIT, 1);
hdmitx_device.HWOp.CntlDDC(&hdmitx_device, DDC_HDCP_OP, HDCP14_OFF);
/* msleep(10); */
hdmitx_device.HWOp.CntlMisc(&hdmitx_device, MISC_TMDS_PHY_OP,
TMDS_PHY_DISABLE);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_CLR_AVI_PACKET, 0);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_CLR_VSDB_PACKET, 0);
}
/* fr_tab[]
* 1080p24hz, 24:1
* 1080p23.976hz, 2997:125
* 25/50/100/200hz, no change
*/
static struct frac_rate_table fr_tab[] = {
{"24hz", 24, 1, 2997, 125},
{"30hz", 30, 1, 2997, 100},
{"60hz", 60, 1, 2997, 50},
{"120hz", 120, 1, 2997, 25},
{"240hz", 120, 1, 5994, 25},
{NULL},
};
static void recalc_vinfo_sync_duration(struct vinfo_s *info, unsigned int frac)
{
struct frac_rate_table *fr = &fr_tab[0];
pr_info(SYS "recalc before %s %d %d\n", info->name,
info->sync_duration_num, info->sync_duration_den);
while (fr->hz) {
if (strstr(info->name, fr->hz)) {
if (frac) {
info->sync_duration_num = fr->sync_num_dec;
info->sync_duration_den = fr->sync_den_dec;
} else {
info->sync_duration_num = fr->sync_num_int;
info->sync_duration_den = fr->sync_den_int;
}
break;
}
fr++;
}
pr_info(SYS "recalc after %s %d %d\n", info->name,
info->sync_duration_num, info->sync_duration_den);
}
static void hdmi_physcial_size_update(struct hdmitx_dev *hdev)
{
unsigned int width, height;
struct vinfo_s *info = NULL;
info = hdmitx_get_current_vinfo();
if ((info == NULL) || (info->name == NULL)) {
pr_info(SYS "cann't get valid mode\n");
return;
}
if (info->mode == VMODE_HDMI) {
width = hdev->RXCap.physcial_weight;
height = hdev->RXCap.physcial_height;
if ((width == 0) || (height == 0)) {
info->screen_real_width = info->aspect_ratio_num;
info->screen_real_height = info->aspect_ratio_den;
} else {
/* transfer mm */
info->screen_real_width = width * 10;
info->screen_real_height = height * 10;
}
pr_info(SYS "update physcial size: %d %d\n",
info->screen_real_width, info->screen_real_height);
}
}
static void hdrinfo_to_vinfo(struct vinfo_s *info, struct hdmitx_dev *hdev)
{
unsigned int i, j;
/*static hdr*/
info->hdr_info.hdr_support = (hdev->RXCap.hdr_sup_eotf_sdr << 0)
| (hdev->RXCap.hdr_sup_eotf_hdr << 1)
| (hdev->RXCap.hdr_sup_eotf_smpte_st_2084 << 2)
| (hdev->RXCap.hdr_sup_eotf_hlg << 3);
/*dynamic hdr*/
for (i = 0; i < 4; i++) {
if (hdev->RXCap.hdr_dynamic_info[i].type == 0) {
memset(&info->hdr_info.dynamic_info[i],
0, sizeof(struct hdr_dynamic));
continue;
}
info->hdr_info.dynamic_info[i].type =
hdev->RXCap.hdr_dynamic_info[i].type;
info->hdr_info.dynamic_info[i].of_len =
hdev->RXCap.hdr_dynamic_info[i].hd_len - 3;
info->hdr_info.dynamic_info[i].support_flags =
hdev->RXCap.hdr_dynamic_info[i].support_flags;
for (j = 0; j < hdev->RXCap.hdr_dynamic_info[i].hd_len - 3; j++)
info->hdr_info.dynamic_info[i].optional_fields[j] =
hdev->RXCap.hdr_dynamic_info[i].optional_fields[j];
}
/*hdr 10+*/
memcpy(&(info->hdr_info.hdr10plus_info),
&(hdev->RXCap.hdr10plus_info), sizeof(struct hdr10_plus_info));
info->hdr_info.colorimetry_support =
hdev->RXCap.colorimetry_data;
info->hdr_info.lumi_max = hdev->RXCap.hdr_lum_max;
info->hdr_info.lumi_avg = hdev->RXCap.hdr_lum_avg;
info->hdr_info.lumi_min = hdev->RXCap.hdr_lum_min;
pr_info(SYS "update rx hdr info %x\n",
info->hdr_info.hdr_support);
}
static void rxlatency_to_vinfo(struct vinfo_s *info, struct rx_cap *rx)
{
if (!info || !rx)
return;
info->rx_latency.vLatency = rx->vLatency;
info->rx_latency.aLatency = rx->aLatency;
info->rx_latency.i_vLatency = rx->i_vLatency;
info->rx_latency.i_aLatency = rx->i_aLatency;
}
static int set_disp_mode_auto(void)
{
int ret = -1;
struct vinfo_s *info = NULL;
struct hdmitx_dev *hdev = &hdmitx_device;
struct hdmi_format_para *para = NULL;
unsigned char mode[32];
enum hdmi_vic vic = HDMI_Unknown;
enum hdmi_color_depth stream_cur_cd;
/* vic_ready got from IP */
enum hdmi_vic vic_ready = hdev->HWOp.GetState(
hdev, STAT_VIDEO_VIC, 0);
memset(mode, 0, sizeof(mode));
hdev->ready = 0;
/* get current vinfo */
info = hdmitx_get_current_vinfo();
if ((info == NULL) || (info->name == NULL))
return -1;
stream_cur_cd = hdev->para->cd;
if (hdev->cur_video_param != NULL){
pr_info("hdmitx: display colourdepth was %d in cur_param 0x%p (VIC: %d)\n",hdev->cur_video_param->color_depth * 2,
hdev->cur_video_param, hdev->cur_video_param->VIC);
}
pr_info(SYS "get current mode: %s\n", info->name);
if (!((strncmp(info->name, "480cvbs", 7) == 0) ||
(strncmp(info->name, "576cvbs", 7) == 0) ||
(strncmp(info->name, "null", 4) == 0))) {
hdrinfo_to_vinfo(info, hdev);
rxlatency_to_vinfo(info, &hdev->RXCap);
}
hdmi_physcial_size_update(hdev);
/* If info->name equals to cvbs, then set mode to I mode to hdmi
*/
if ((strncmp(info->name, "480cvbs", 7) == 0) ||
(strncmp(info->name, "576cvbs", 7) == 0) ||
(strncmp(info->name, "ntsc_m", 6) == 0) ||
(strncmp(info->name, "pal_m", 5) == 0) ||
(strncmp(info->name, "pal_n", 5) == 0) ||
#ifndef CONFIG_ARCH_MESON64_ODROIDN2
(strncmp(info->name, "panel", 5) == 0) ||
#endif
(strncmp(info->name, "null", 4) == 0)) {
pr_info(SYS "%s not valid hdmi mode\n", info->name);
hdev->HWOp.CntlConfig(hdev, CONF_CLR_AVI_PACKET, 0);
hdev->HWOp.CntlConfig(hdev, CONF_CLR_VSDB_PACKET, 0);
hdev->HWOp.CntlMisc(hdev, MISC_TMDS_PHY_OP, TMDS_PHY_DISABLE);
hdev->para = hdmi_get_fmt_name("invalid", hdev->fmt_attr);
para->cd = stream_cur_cd;
return -1;
}
strncpy(mode, info->name, sizeof(mode));
mode[31] = '\0';
if (strstr(mode, "fp")) {
int i = 0;
for (; mode[i]; i++) {
if ((mode[i] == 'f') && (mode[i + 1] == 'p')) {
/* skip "f", 1080fp60hz -> 1080p60hz */
do {
mode[i] = mode[i + 1];
i++;
} while (mode[i]);
break;
}
}
}
para = hdmi_get_fmt_name(mode, hdev->fmt_attr);
/* force 4k50/60Hz to 420 unless manually set */
if (strstr(hdmitx_device.fmt_attr,"422") == NULL){
switch ((para->vic) & 0xff) {
case HDMI_3840x2160p50_16x9:
case HDMI_3840x2160p60_16x9:
case HDMI_4096x2160p50_256x135:
case HDMI_4096x2160p60_256x135:
case HDMI_3840x2160p50_64x27:
case HDMI_3840x2160p60_64x27:
para->cs = COLORSPACE_YUV420;
break;
default:
break;
}
}
hdev->para = para;
if (hdev->cur_video_param != NULL){
if (strstr(hdmitx_device.fmt_attr,"bit") != NULL){
hdev->cur_video_param->color_depth = para->cd;
pr_info("hdmitx: display colourdepth set by attr to %d in cur_param 0x%p (VIC: %d)\n",hdev->cur_video_param->color_depth * 2,
hdev->cur_video_param, hdev->cur_video_param->VIC);
} else {
hdev->cur_video_param->color_depth = COLORDEPTH_30B;
pr_info("hdmitx: display colourdepth is %d in cur_param 0x%p (VIC: %d)\n",hdev->cur_video_param->color_depth * 2,
hdev->cur_video_param, hdev->cur_video_param->VIC);
}
if (hdev->cur_video_param->color_depth > COLORDEPTH_24B){
int dc_support = 0;
if (hdev->RXCap.ColorDeepSupport & 0x78 && hdev->para->cs != COLORSPACE_YUV420)
dc_support = 1;
else if ((hdev->RXCap.hf_ieeeoui) &&
((hdev->RXCap.dc_30bit_420 && hdev->cur_video_param->color_depth == COLORDEPTH_30B) ||
(hdev->RXCap.dc_36bit_420 && hdev->cur_video_param->color_depth == COLORDEPTH_36B) ||
(hdev->RXCap.dc_48bit_420 && hdev->cur_video_param->color_depth == COLORDEPTH_48B)))
dc_support = 1;
if (! dc_support){
pr_warn("Bitdepth is set to %d bits but display does not support deep colour",
hdev->cur_video_param->color_depth * 2);
/* drop to 8 bit unless forced */
if (strstr(hdmitx_device.fmt_attr,"bit") == NULL)
hdev->cur_video_param->color_depth = COLORDEPTH_24B;
}
}
}
/* and recover the original bitstream bitdepth */
para->cd = stream_cur_cd;
vic = hdmitx_edid_get_VIC(hdev, mode, 1);
if (strncmp(info->name, "2160p30hz", strlen("2160p30hz")) == 0) {
vic = HDMI_4k2k_30;
} else if (strncmp(info->name, "2160p25hz",
strlen("2160p25hz")) == 0) {
vic = HDMI_4k2k_25;
} else if (strncmp(info->name, "2160p24hz",
strlen("2160p24hz")) == 0) {
vic = HDMI_4k2k_24;
} else if (strncmp(info->name, "smpte24hz",
strlen("smpte24hz")) == 0)
vic = HDMI_4k2k_smpte_24;
else {
/* nothing */
}
if ((vic_ready != HDMI_Unknown) && (vic_ready == vic) && (strstr(hdmitx_device.fmt_attr,"now") == NULL)) {
pr_info(SYS "[%s] ALREADY init VIC = %d\n",
__func__, vic);
#if defined(CONFIG_ARCH_MESON64_ODROID_COMMON)
if (odroid_voutmode() == VOUTMODE_HDMI) {
hdev->HWOp.CntlConfig(hdev, CONF_HDMI_DVI_MODE,
HDMI_MODE);
pr_info(SYS "change to HDMI mode\n");
} else if (odroid_voutmode() == VOUTMODE_DVI) {
hdev->HWOp.CntlConfig(hdev, CONF_HDMI_DVI_MODE,
DVI_MODE);
pr_info(SYS "change to DVI mode\n");
} else if (hdev->RXCap.ieeeoui == 0) {
#else
if (hdev->RXCap.ieeeoui == 0) {
#endif
/* DVI case judgement. In uboot, directly output HDMI
* mode
*/
hdev->HWOp.CntlConfig(hdev, CONF_HDMI_DVI_MODE,
DVI_MODE);
pr_info(SYS "change to DVI mode\n");
} else if ((hdev->RXCap.ieeeoui == 0xc03) &&
(hdev->HWOp.CntlConfig(hdev, CONF_GET_HDMI_DVI_MODE, 0)
== DVI_MODE)) {
hdev->HWOp.CntlConfig(hdev, CONF_HDMI_DVI_MODE,
HDMI_MODE);
pr_info(SYS "change to HDMI mode\n");
}
hdev->cur_VIC = vic;
hdev->output_blank_flag = 1;
hdev->ready = 1;
return 1;
}
hdmitx_pre_display_init();
if (strstr(hdmitx_device.fmt_attr,"now") != NULL){
memcpy(strstr(hdmitx_device.fmt_attr,"now"), " ", 3);
}
hdev->cur_VIC = HDMI_Unknown;
/* if vic is HDMI_Unknown, hdmitx_set_display will disable HDMI */
ret = hdmitx_set_display(hdev, vic);
if (ret >= 0) {
hdev->HWOp.Cntl(hdev, HDMITX_AVMUTE_CNTL, AVMUTE_CLEAR);
hdev->cur_VIC = vic;
hdev->audio_param_update_flag = 1;
hdev->auth_process_timer = AUTH_PROCESS_TIME;
}
if (hdev->cur_VIC == HDMI_Unknown) {
if (hdev->hpdmode == 2) {
/* edid will be read again when hpd is muxed
* and it is high
*/
hdmitx_edid_clear(hdev);
hdev->mux_hpd_if_pin_high_flag = 0;
}
/* If current display is NOT panel, needn't TURNOFF_HDMIHW */
#ifndef CONFIG_ARCH_MESON64_ODROIDN2
if (strncmp(mode, "panel", 5) == 0) {
hdev->HWOp.Cntl(hdev, HDMITX_HWCMD_TURNOFF_HDMIHW,
(hdev->hpdmode == 2)?1:0);
}
#endif
}
hdmitx_set_audio(hdev, &(hdev->cur_audio_param));
hdev->output_blank_flag = 1;
hdev->ready = 1;
return ret;
}
/*disp_mode attr*/
static ssize_t show_disp_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
pos += snprintf(buf+pos, PAGE_SIZE, "VIC:%d\n",
hdmitx_device.cur_VIC);
return pos;
}
static ssize_t store_disp_mode(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
set_disp_mode(buf);
return count;
}
static ssize_t show_attr(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
pos += snprintf(buf+pos, PAGE_SIZE, "%s\n\r", hdmitx_device.fmt_attr);
return pos;
}
ssize_t store_attr(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
strncpy(hdmitx_device.fmt_attr, buf, sizeof(hdmitx_device.fmt_attr));
hdmitx_device.fmt_attr[15] = '\0';
if (strstr(hdmitx_device.fmt_attr,"now")){
set_disp_mode_auto();
}
return count;
return count;
}
/*aud_mode attr*/
void setup_attr(const char *buf)
{
char attr[16] = {0};
memcpy(attr, buf, sizeof(attr));
memcpy(hdmitx_device.fmt_attr, attr, sizeof(hdmitx_device.fmt_attr));
}
EXPORT_SYMBOL(setup_attr);
/* for android application data exchange / swap */
static char *tmp_swap;
static DEFINE_MUTEX(mutex_swap);
static ssize_t store_swap(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
pr_info("store_swap: %s\n", buf);
mutex_lock(&mutex_swap);
kfree(tmp_swap);
tmp_swap = kzalloc(count + 1, GFP_KERNEL);
if (!tmp_swap) {
mutex_unlock(&mutex_swap);
return count;
}
memcpy(tmp_swap, buf, count);
tmp_swap[count] = '\0'; /* padding end string */
mutex_unlock(&mutex_swap);
return count;
}
static ssize_t show_swap(struct device *dev,
struct device_attribute *attr, char *buf)
{
int i = 0;
int n = 0;
struct hdmitx_dev *hdev = &hdmitx_device;
struct rx_cap *pRXCap = &hdev->RXCap;
struct hdcprp14_topo *topo14 = &hdev->topo_info->topo.topo14;
mutex_lock(&mutex_swap);
if (!tmp_swap ||
(!hdev->edid_parsing && !strstr(tmp_swap, "hdcp.topo"))) {
mutex_unlock(&mutex_swap);
return n;
}
/* VSD: Video Short Descriptor */
if (strstr(tmp_swap, "edid.vsd"))
for (i = 0; i < pRXCap->vsd.len; i++)
n += snprintf(buf + n, PAGE_SIZE - n, "%02x",
pRXCap->vsd.raw[i]);
/* ASD: Audio Short Descriptor */
if (strstr(tmp_swap, "edid.asd"))
for (i = 0; i < pRXCap->asd.len; i++)
n += snprintf(buf + n, PAGE_SIZE - n, "%02x",
pRXCap->asd.raw[i]);
/* CEC: Physical Address */
if (strstr(tmp_swap, "edid.cec"))
n += snprintf(buf + n, PAGE_SIZE - n, "%x%x%x%x",
hdev->hdmi_info.vsdb_phy_addr.a,
hdev->hdmi_info.vsdb_phy_addr.b,
hdev->hdmi_info.vsdb_phy_addr.c,
hdev->hdmi_info.vsdb_phy_addr.d);
/* HDCP TOPO */
if (strstr(tmp_swap, "hdcp.topo")) {
char *tmp = (char *)topo14;
pr_info("max_cascade_exceeded %d\n",
topo14->max_cascade_exceeded);
pr_info("depth %d\n", topo14->depth);
pr_info("max_devs_exceeded %d\n", topo14->max_devs_exceeded);
pr_info("device_count %d\n", topo14->device_count);
for (i = 0; i < sizeof(struct hdcprp14_topo); i++)
n += snprintf(buf + n, PAGE_SIZE - n, "%02x", tmp[i]);
}
kfree(tmp_swap);
tmp_swap = NULL;
mutex_unlock(&mutex_swap);
return n;
}
static ssize_t show_aud_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
static ssize_t store_aud_mode(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
/* set_disp_mode(buf); */
struct hdmitx_audpara *audio_param =
&(hdmitx_device.cur_audio_param);
if (strncmp(buf, "32k", 3) == 0)
audio_param->sample_rate = FS_32K;
else if (strncmp(buf, "44.1k", 5) == 0)
audio_param->sample_rate = FS_44K1;
else if (strncmp(buf, "48k", 3) == 0)
audio_param->sample_rate = FS_48K;
else {
hdmitx_device.force_audio_flag = 0;
return count;
}
audio_param->type = CT_PCM;
audio_param->channel_num = CC_2CH;
audio_param->sample_size = SS_16BITS;
hdmitx_device.audio_param_update_flag = 1;
hdmitx_device.force_audio_flag = 1;
return count;
}
/*edid attr*/
static ssize_t show_edid(struct device *dev,
struct device_attribute *attr, char *buf)
{
return hdmitx_edid_dump(&hdmitx_device, buf, PAGE_SIZE);
}
static int dump_edid_data(unsigned int type, char *path)
{
struct file *filp = NULL;
loff_t pos = 0;
char line[128] = {0};
mm_segment_t old_fs = get_fs();
unsigned int i = 0, j = 0, k = 0, size = 0, block_cnt = 0;
set_fs(KERNEL_DS);
filp = filp_open(path, O_RDWR|O_CREAT, 0666);
if (IS_ERR(filp)) {
pr_info("[%s] failed to open/create file: |%s|\n",
__func__, path);
goto PROCESS_END;
}
block_cnt = hdmitx_device.EDID_buf[0x7e] + 1;
if (type == 1) {
/* dump as bin file*/
size = vfs_write(filp, hdmitx_device.EDID_buf,
block_cnt*128, &pos);
} else if (type == 2) {
/* dump as txt file*/
for (i = 0; i < block_cnt; i++) {
for (j = 0; j < 8; j++) {
for (k = 0; k < 16; k++) {
snprintf((char *)&line[k*6], 7,
"0x%02x, ",
hdmitx_device.EDID_buf[i*128+j*16+k]);
}
line[16*6-1] = '\n';
line[16*6] = 0x0;
pos = (i*8+j)*16*6;
size += vfs_write(filp, line, 16*6, &pos);
}
}
}
pr_info("[%s] write %d bytes to file %s\n", __func__, size, path);
vfs_fsync(filp, 0);
filp_close(filp, NULL);
PROCESS_END:
set_fs(old_fs);
return 0;
}
static int load_edid_data(unsigned int type, char *path)
{
struct file *filp = NULL;
loff_t pos = 0;
mm_segment_t old_fs = get_fs();
struct kstat stat;
unsigned int length = 0, max_len = EDID_MAX_BLOCK * 128;
char *buf = NULL;
set_fs(KERNEL_DS);
filp = filp_open(path, O_RDONLY, 0444);
if (IS_ERR(filp)) {
pr_info("[%s] failed to open file: |%s|\n", __func__, path);
goto PROCESS_END;
}
vfs_stat(path, &stat);
length = (stat.size > max_len)?max_len:stat.size;
buf = kmalloc(length, GFP_KERNEL);
if (buf == NULL)
goto PROCESS_END;
vfs_read(filp, buf, length, &pos);
memcpy(hdmitx_device.EDID_buf, buf, length);
kfree(buf);
filp_close(filp, NULL);
pr_info("[%s] %d bytes loaded from file %s\n", __func__, length, path);
hdmitx_edid_clear(&hdmitx_device);
hdmitx_edid_parse(&hdmitx_device);
pr_info("[%s] new edid loaded!\n", __func__);
PROCESS_END:
set_fs(old_fs);
return 0;
}
static ssize_t store_edid(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
unsigned int argn = 0;
char *p = NULL, *para = NULL, *argv[8] = {NULL};
unsigned int path_length = 0;
p = kstrdup(buf, GFP_KERNEL);
if (p == NULL)
return count;
do {
para = strsep(&p, " ");
if (para != NULL) {
argv[argn] = para;
argn++;
if (argn > 7)
break;
}
} while (para != NULL);
if (buf[0] == 'h') {
int i;
pr_info(EDID "EDID hash value:\n");
for (i = 0; i < 20; i++)
pr_info("%02x", hdmitx_device.EDID_hash[i]);
pr_info("\n");
}
if (buf[0] == 'd') {
int ii, jj;
unsigned long block_idx;
int ret;
ret = kstrtoul(buf+1, 16, &block_idx);
if (block_idx < EDID_MAX_BLOCK) {
for (ii = 0; ii < 8; ii++) {
for (jj = 0; jj < 16; jj++) {
pr_info(EDID "%02x ",
hdmitx_device.EDID_buf[block_idx*128+ii*16+jj]);
}
pr_info("\n");
}
pr_info("\n");
}
}
if (buf[0] == 'e') {
int ii, jj;
unsigned long block_idx;
int ret;
ret = kstrtoul(buf+1, 16, &block_idx);
if (block_idx < EDID_MAX_BLOCK) {
for (ii = 0; ii < 8; ii++) {
for (jj = 0; jj < 16; jj++) {
pr_info(EDID "%02x ",
hdmitx_device.EDID_buf1[block_idx*128+ii*16+jj]);
}
pr_info("\n");
}
pr_info("\n");
}
}
if (!strncmp(argv[0], "save", strlen("save"))) {
unsigned int type = 0;
if (argn != 3) {
pr_info("[%s] cmd format: save bin/txt edid_file_path\n",
__func__);
goto PROCESS_END;
}
if (!strncmp(argv[1], "bin", strlen("bin")))