forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathhdmi_tx_main.c
More file actions
2522 lines (2267 loc) · 64.7 KB
/
hdmi_tx_main.c
File metadata and controls
2522 lines (2267 loc) · 64.7 KB
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/hdmi/hdmi_tx_20/hdmi_tx_main.c
*
* Copyright (C) 2015 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/mutex.h>
#include <linux/cdev.h>
#include <linux/switch.h>
#include <linux/proc_fs.h>
#include <linux/uaccess.h>
/* #include <mach/am_regs.h> */
/* #include <linux/amlogic/osd/osd_dev.h> */
#include <linux/amlogic/aml_gpio_consumer.h>
#include <linux/amlogic/vout/vout_notify.h>
#include "hdmi_tx_hdcp.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/amlogic/vout/vinfo.h>
#include <linux/amlogic/vout/vout_notify.h>
#include <linux/amlogic/sound/aout_notify.h>
#include <linux/amlogic/hdmi_tx/hdmi_info_global.h>
#include <linux/amlogic/hdmi_tx/hdmi_tx_ddc.h>
#include <linux/amlogic/hdmi_tx/hdmi_tx_module.h>
#include <linux/amlogic/hdmi_tx/hdmi_tx_cec.h>
#include <linux/amlogic/hdmi_tx/hdmi_config.h>
#include <linux/i2c.h>
#include "hw/tvenc_conf.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 dev_t hdmitx_id;
static struct class *hdmitx_class;
static int set_disp_mode_auto(void);
const struct vinfo_s *hdmi_get_current_vinfo(void);
static int edid_rx_data(unsigned char regaddr, unsigned char *rx_data,
int length);
static void gpio_read_edid(unsigned char *rx_edid);
#ifndef CONFIG_AM_TV_OUTPUT
/* Fake vinfo */
const struct vinfo_s vinfo_1080p60hz = {
.name = "1080p60hz",
.mode = VMODE_1080P,
.width = 1920,
.height = 1080,
.field_height = 1080,
.aspect_ratio_num = 16,
.aspect_ratio_den = 9,
.sync_duration_num = 60,
.sync_duration_den = 1,
.video_clk = 148500000,
};
const struct vinfo_s *get_current_vinfo(void)
{
return &vinfo_1080p60hz;
}
#endif
struct hdmi_config_platform_data *hdmi_pdata;
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
static int suspend_flag;
#endif
static struct hdmitx_dev hdmitx_device;
static struct switch_dev sdev = { /* android ics switch device */
.name = "hdmi",
};
static struct hdmi_cea_timing custom_timing;
struct hdmi_cea_timing *get_custom_timing(void)
{
return &custom_timing;
}
EXPORT_SYMBOL(get_custom_timing);
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
static void hdmitx_early_suspend(struct early_suspend *h)
{
const struct vinfo_s *info = hdmi_get_current_vinfo();
struct hdmitx_dev *phdmi = (struct hdmitx_dev *)h->param;
if (info && (strncmp(info->name, "panel", 5) == 0
|| strncmp(info->name, "null", 4) == 0))
return;
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
suspend_flag = 1;
#endif
phdmi->hpd_lock = 1;
phdmi->HWOp.Cntl((struct hdmitx_dev *)h->param,
HDMITX_EARLY_SUSPEND_RESUME_CNTL, HDMITX_EARLY_SUSPEND);
phdmi->cur_VIC = HDMI_Unkown;
phdmi->output_blank_flag = 0;
phdmi->HWOp.CntlDDC(phdmi, DDC_HDCP_OP, HDCP_OFF);
phdmi->HWOp.CntlDDC(phdmi, DDC_HDCP_OP, DDC_RESET_HDCP);
if (phdmi->gpio_i2c_enable) {
if (phdmi->hdcpop.hdcp14_en) {
hdmi_print(INF, SYS "unmux DDC for gpio read edid\n");
phdmi->HWOp.CntlDDC(phdmi, DDC_PIN_MUX_OP, PIN_UNMUX);
}
}
phdmi->HWOp.CntlConfig(&hdmitx_device, CONF_CLR_AVI_PACKET, 0);
phdmi->HWOp.CntlConfig(&hdmitx_device, CONF_CLR_VSDB_PACKET, 0);
hdmi_print(IMP, SYS "HDMITX: early suspend\n");
phdmi->HWOp.CntlMisc(&hdmitx_device, MISC_HPLL_FAKE, 0);
}
static void hdmitx_late_resume(struct early_suspend *h)
{
const struct vinfo_s *info = hdmi_get_current_vinfo();
struct hdmitx_dev *phdmi = (struct hdmitx_dev *)h->param;
if (info && (strncmp(info->name, "panel", 5) == 0 ||
strncmp(info->name, "null", 4) == 0)) {
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_VIDEO_BLANK_OP, VIDEO_UNBLANK);
return;
} else {
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_VIDEO_BLANK_OP, VIDEO_BLANK);
}
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));
switch_set_state(&sdev, hdmitx_device.hpd_state);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_MUTE);
hdmitx_device.HWOp.CntlDDC(&hdmitx_device, DDC_HDCP_OP,
HDCP_OFF);
hdmitx_device.internal_mode_change = 0;
set_disp_mode_auto();
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
suspend_flag = 0;
#endif
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);
hdmi_print(INF, 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->HWOp.CntlMisc(hdev, MISC_AVMUTE_OP, SET_AVMUTE);
mdelay(25);
hdev->HWOp.CntlMisc(hdev, MISC_TMDS_PHY_OP, TMDS_PHY_DISABLE);
hdev->HWOp.CntlMisc(hdev, MISC_HPLL_OP, HPLL_DISABLE);
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
/* static struct hdmitx_info hdmi_info; */
#define INIT_FLAG_VDACOFF 0x1
/* unplug powerdown */
#define INIT_FLAG_POWERDOWN 0x2
#define INIT_FLAG_NOT_LOAD 0x80
int hdmi_ch = 1; /* 1: 2ch */
static unsigned char init_flag;
#undef DISABLE_AUDIO
/* if set to 1, then HDMI will output no audio */
/* In KTV case, HDMI output Picture only, and Audio is driven by other
* sources.
*/
unsigned char hdmi_audio_off_flag = 0;
static int hpdmode = 1; /*
0, do not unmux hpd when off or unplug ;
1, unmux hpd when unplug;
2, unmux hpd when unplug or off;
*/
#ifdef CONFIG_AM_TV_OUTPUT2
static int force_vout_index;
#endif
/* 0xffff=disable; 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 31*/
static int hdmi_prbs_mode = 0xffff;
static int hdmi_480p_force_clk; /* 200, 225, 250, 270 */
static int hdmi_detect_when_booting = 1;
/* 1: error 2: important 3: normal 4: detailed */
static int debug_level = IMP;
void control_hdmiphy(int 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);
}
/*****************************
* hdmitx attr management :
* enable
* mode
* reg
******************************/
static void set_test_mode(void)
{
#ifdef ENABLE_TEST_MODE
/* when it is used as test source (PRBS and 20,22.5,25MHz) */
if ((hdmi_480p_force_clk) &&
((hdmitx_device.cur_VIC == HDMI_480p60) ||
(hdmitx_device.cur_VIC == HDMI_480p60_16x9) ||
(hdmitx_device.cur_VIC == HDMI_480i60) ||
(hdmitx_device.cur_VIC == HDMI_480i60_16x9) ||
(hdmitx_device.cur_VIC == HDMI_576p50) ||
(hdmitx_device.cur_VIC == HDMI_576p50_16x9) ||
(hdmitx_device.cur_VIC == HDMI_576i50) ||
(hdmitx_device.cur_VIC == HDMI_576i50_16x9))
) {
if (hdmitx_device.HWOp.Cntl)
hdmitx_device.HWOp.Cntl(&hdmitx_device,
HDMITX_FORCE_480P_CLK,
hdmi_480p_force_clk);
}
if (hdmi_prbs_mode != 0xffff)
if (hdmitx_device.HWOp.Cntl)
hdmitx_device.HWOp.Cntl(&hdmitx_device,
HDMITX_HWCMD_TURN_ON_PRBS,
hdmi_prbs_mode);
}
#endif
}
int get_cur_vout_index(void)
/*
return value: 1, vout; 2, vout2;
*/
{
int vout_index = 1;
#ifdef CONFIG_AM_TV_OUTPUT2
if (force_vout_index)
vout_index = force_vout_index;
else {
/* VPU_VIU_VENC_MUX_CTRL
* [ 3: 2] cntl_viu2_sel_venc. Select which one of the
* encI/P/T that VIU2 connects to:
* 0=No connection, 1=ENCI, 2=ENCP, 3=ENCT.
* [ 1: 0] cntl_viu1_sel_venc. Select which one of the
* encI/P/T that VIU1 connects to:
* 0=No connection, 1=ENCI, 2=ENCP, 3=ENCT.
*/
int viu2_sel = (aml_read_reg32
(P_VPU_VIU_VENC_MUX_CTRL)>>2)&0x3;
int viu1_sel = aml_read_reg32
(P_VPU_VIU_VENC_MUX_CTRL)&0x3;
if (((viu2_sel == 1) || (viu2_sel == 2)) &&
(viu1_sel != 1) && (viu1_sel != 2))
vout_index = 2;
}
#endif
return vout_index;
}
const struct vinfo_s *hdmi_get_current_vinfo(void)
{
const struct vinfo_s *info;
#ifdef CONFIG_AM_TV_OUTPUT2
if (get_cur_vout_index() == 2) {
info = get_current_vinfo2();
/* add to fix problem when dual display is not enabled in UI */
if (info == NULL)
info = get_current_vinfo();
} else
info = get_current_vinfo();
#else
info = get_current_vinfo();
#endif
return info;
}
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;
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
else if (strncmp(mode, "4k2k29hz", strlen("4k2k29hz")) == 0)
vic = HDMI_4k2k_30;
else if (strncmp(mode, "4k2k23hz", strlen("4k2k23hz")) == 0)
vic = HDMI_4k2k_24;
#endif
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_Unkown) {
hdmitx_device.mux_hpd_if_pin_high_flag = 1;
if (hdmitx_device.vic_count == 0) {
if (hdmitx_device.unplug_powerdown)
return 0;
}
}
#if 0
set_vmode_enc_hw(vic);
#endif
hdmitx_device.cur_VIC = HDMI_Unkown;
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;
hdmitx_device.internal_mode_change = 0;
set_test_mode();
}
if (hdmitx_device.cur_VIC == HDMI_Unkown) {
if (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,
(hpdmode == 2)?1:0);
}
}
return ret;
}
static void hdmitx_pre_display_init(void)
{
hdmitx_device.cur_VIC = HDMI_Unkown;
hdmitx_device.auth_process_timer = AUTH_PROCESS_TIME;
hdmitx_device.internal_mode_change = 1;
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_VIDEO_BLANK_OP, VIDEO_BLANK);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_MUTE);
hdmitx_device.HWOp.CntlDDC(&hdmitx_device, DDC_HDCP_OP,
HDCP_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);
hdmitx_device.internal_mode_change = 0;
}
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
/* */
/* input para: name of vmode, such as "1080p50hz" */
/* return values: */
/* 0: not supported in edid */
/* 1: supported in edid */
/* 2: no edid */
/* */
int hdmitx_is_vmode_supported(char *mode_name)
{
enum hdmi_vic vic;
if (hdmitx_device.tv_no_edid)
return 2;
vic = hdmitx_edid_get_VIC(&hdmitx_device, mode_name, 0);
if (vic != HDMI_Unkown)
return 1;
else
return 0;
return 0;
}
EXPORT_SYMBOL(hdmitx_is_vmode_supported);
#endif
static int set_disp_mode_auto(void)
{
int ret = -1;
const struct vinfo_s *info = NULL;
unsigned char mode[16];
enum hdmi_vic vic = HDMI_Unkown;
/* vic_ready got from IP */
enum hdmi_vic vic_ready = hdmitx_device.HWOp.GetState(
&hdmitx_device, STAT_VIDEO_VIC, 0);
memset(mode, 0, 16);
/* if HDMI plug-out, directly return */
if (!(hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_HPD_GPI_ST, 0))) {
hdmi_print(ERR, HPD "HPD deassert!\n");
hdmitx_device.HWOp.CntlMisc(&hdmitx_device, MISC_TMDS_PHY_OP,
TMDS_PHY_DISABLE);
return -1;
}
/* get current vinfo */
info = hdmi_get_current_vinfo();
hdmi_print(IMP, VID "get current mode: %s\n",
info ? info->name : "null");
if (info == NULL)
return -1;
/* 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, "panel", 5) == 0) ||
(strncmp(info->name, "null", 4) == 0)) {
hdmi_print(ERR, VID "%s not valid hdmi mode\n", info->name);
/*if (hdmitx_device.hdcpop.hdcp14_en)
hdmitx_device.HWOp.CntlDDC(&hdmitx_device,
DDC_HDCP_OP, HDCP_ON);*/
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_CLR_AVI_PACKET, 0);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_CLR_VSDB_PACKET, 0);
hdmitx_device.HWOp.CntlMisc(&hdmitx_device, MISC_TMDS_PHY_OP,
TMDS_PHY_DISABLE);
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_VIDEO_BLANK_OP, VIDEO_UNBLANK);
return -1;
} else
memcpy(mode, info->name, strlen(info->name));
hdmitx_device.mode420 = 0; /* default NOT mode420 */
/* msleep(500); */
vic = hdmitx_edid_get_VIC(&hdmitx_device, 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 (strstr(mode, "hz420") != NULL)
hdmitx_device.mode420 = 1;
#ifdef CONFIG_AML_VOUT_FRAMERATE_AUTOMATION
if (suspend_flag == 1)
vic_ready = HDMI_Unkown;
#endif
if ((vic_ready != HDMI_Unkown) && (vic_ready == vic)) {
hdmi_print(IMP, SYS "[%s] ALREADY init VIC = %d\n",
__func__, vic);
#if defined(CONFIG_ARCH_MESON64_ODROIDC2)
if (hdmitx_device.RXCap.IEEEOUI == 0 || odroidc_voutmode()) {
#else
if (hdmitx_device.RXCap.IEEEOUI == 0) {
#endif
/* DVI case judgement. In uboot, directly output HDMI
* mode
*/
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_HDMI_DVI_MODE, DVI_MODE);
hdmi_print(IMP, SYS "change to DVI mode\n");
}
hdmitx_device.cur_VIC = vic;
hdmitx_device.output_blank_flag = 1;
if (hdmitx_device.hdcpop.hdcp14_en)
hdmitx_device.HWOp.CntlDDC(&hdmitx_device,
DDC_HDCP_OP, HDCP_ON);
return 1;
} else
hdmitx_pre_display_init();
hdmitx_device.cur_VIC = HDMI_Unkown;
/* if vic is HDMI_Unkown, hdmitx_set_display will disable HDMI */
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;
hdmitx_device.internal_mode_change = 0;
set_test_mode();
}
if (hdmitx_device.cur_VIC == HDMI_Unkown) {
if (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 current display is NOT panel, needn't TURNOFF_HDMIHW */
if (strncmp(mode, "panel", 5) == 0) {
hdmitx_device.HWOp.Cntl(&hdmitx_device,
HDMITX_HWCMD_TURNOFF_HDMIHW,
(hpdmode == 2)?1:0);
}
}
if (hdmitx_device.mode420) {
switch (hdmitx_device.cur_VIC) {
/* Currently, only below formats support 420 mode */
case HDMI_3840x2160p60_16x9:
case HDMI_3840x2160p50_16x9:
case HDMI_3840x2160p50_16x9_Y420:
case HDMI_3840x2160p60_16x9_Y420:
pr_info("configure mode420, VIC = %d\n",
hdmitx_device.cur_VIC);
hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_CONF_MODE420, hdmitx_device.mode420);
break;
default:
hdmitx_device.mode420 = 0;
pr_info("mode420 is not supported at VIC: %d for now.\n",
hdmitx_device.cur_VIC);
}
}
hdmitx_device.HWOp.CntlMisc(&hdmitx_device, MISC_TMDS_CLK_DIV40,
hdmitx_device.cur_VIC);
hdmitx_set_audio(&hdmitx_device,
&(hdmitx_device.cur_audio_param), hdmi_ch);
hdmitx_device.output_blank_flag = 1;
if (hdmitx_device.hdcpop.hdcp14_en)
hdmitx_device.HWOp.CntlDDC(&hdmitx_device,
DDC_HDCP_OP, HDCP_ON);
return ret;
}
static unsigned char is_dispmode_valid_for_hdmi(void)
{
enum hdmi_vic vic;
const struct vinfo_s *info = hdmi_get_current_vinfo();
vic = hdmitx_edid_get_VIC(&hdmitx_device, info->name, 1);
return vic != HDMI_Unkown;
}
/*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 16;
}
/*aud_mode attr*/
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;
}
unsigned int use_loaded_edid = 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) {
pr_info("[%s] kmalloc failed!\n", __func__);
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;
hdmi_print(INF, 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++) {
hdmi_print(INF, "%02x ",
hdmitx_device.EDID_buf[block_idx*128+ii*16+jj]);
}
hdmi_print(INF, "\n");
}
hdmi_print(INF, "\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++) {
hdmi_print(INF, "%02x ",
hdmitx_device.EDID_buf1[block_idx*128+ii*16+jj]);
}
hdmi_print(INF, "\n");
}
hdmi_print(INF, "\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")))
type = 1;
else if (!strncmp(argv[1], "txt", strlen("txt")))
type = 2;
if ((type == 1) || (type == 2)) {
/* clean '\n' from file path*/
path_length = strlen(argv[2]);
if (argv[2][path_length-1] == '\n')
argv[2][path_length-1] = 0x0;
dump_edid_data(type, argv[2]);
}
} else if (!strncmp(argv[0], "load", strlen("load"))) {
if (argn != 2) {
pr_info("[%s] cmd format: load edid_file_path\n",
__func__);
goto PROCESS_END;
}
/* clean '\n' from file path*/
path_length = strlen(argv[1]);
if (argv[1][path_length-1] == '\n')
argv[1][path_length-1] = 0x0;
load_edid_data(0, argv[1]);
}
PROCESS_END:
kfree(p);
return 16;
}
/*config attr*/
static ssize_t show_config(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
unsigned char *aud_conf;
switch (hdmitx_device.tx_aud_cfg) {
case 0:
aud_conf = "off";
break;
case 1:
aud_conf = "on";
break;
case 2:
aud_conf = "auto";
break;
default:
aud_conf = "none";
}
pos += snprintf(buf+pos, PAGE_SIZE,
"disp switch (force or edid): %s\n",
(hdmitx_device.disp_switch_config ==
DISP_SWITCH_FORCE)?"force":"edid");
pos += snprintf(buf+pos, PAGE_SIZE, "audio config: %s\n",
aud_conf);
return pos;
}
void hdmitx_audio_mute_op(unsigned int flag)
{
hdmitx_device.tx_aud_cfg = flag;
if (flag == 0)
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_MUTE);
else
hdmitx_device.HWOp.CntlConfig(&hdmitx_device,
CONF_AUDIO_MUTE_OP, AUDIO_UNMUTE);
}
EXPORT_SYMBOL(hdmitx_audio_mute_op);
static ssize_t store_config(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int ret = 0;
if (strncmp(buf, "force", 5) == 0)
hdmitx_device.disp_switch_config = DISP_SWITCH_FORCE;
else if (strncmp(buf, "edid", 4) == 0)
hdmitx_device.disp_switch_config = DISP_SWITCH_EDID;
else if (strncmp(buf, "unplug_powerdown", 16) == 0) {
if (buf[16] == '0')
hdmitx_device.unplug_powerdown = 0;
else
hdmitx_device.unplug_powerdown = 1;
} else if (strncmp(buf, "3d", 2) == 0) {
/* First, disable HDMI TMDS */
hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_TMDS_PHY_OP, TMDS_PHY_DISABLE);
if (hdmitx_device.hdcpop.hdcp14_en)
hdmitx_device.HWOp.CntlDDC(&hdmitx_device,
DDC_HDCP_OP, HDCP_OFF);
/* Second, set 3D parameters */
if (strncmp(buf+2, "tb", 2) == 0)
hdmi_set_3d(&hdmitx_device, 6, 0);
else if (strncmp(buf+2, "lr", 2) == 0) {
unsigned long sub_sample_mode = 0;
if (buf[2])
ret = kstrtoul(buf+2, 10,
&sub_sample_mode);
/* side by side */
hdmi_set_3d(&hdmitx_device, 8, sub_sample_mode);
} else if (strncmp(buf+2, "off", 3) == 0)
hdmi_set_3d(&hdmitx_device, 0xf, 0);
/* Last, delay sometime and enable HDMI TMDS */
msleep(20);
hdmitx_device.HWOp.CntlMisc(&hdmitx_device,
MISC_TMDS_PHY_OP, TMDS_PHY_ENABLE);
if (hdmitx_device.hdcpop.hdcp14_en)
hdmitx_device.HWOp.CntlDDC(&hdmitx_device,
DDC_HDCP_OP, HDCP_ON);
} else if (strncmp(buf, "audio_", 6) == 0) {
if (strncmp(buf+6, "off", 3) == 0) {
hdmitx_audio_mute_op(0);
hdmi_print(IMP, AUD "configure off\n");
} else if (strncmp(buf+6, "on", 2) == 0) {
hdmitx_audio_mute_op(1);
hdmi_print(IMP, AUD "configure on\n");
} else if (strncmp(buf+6, "auto", 4) == 0) {
/* auto mode. if sink doesn't support current
* audio format, then no audio output
*/
hdmitx_device.tx_aud_cfg = 2;
hdmi_print(IMP, AUD "configure auto\n");
} else
hdmi_print(ERR, AUD "configure error\n");
}
return 16;
}
static ssize_t store_debug(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
hdmitx_device.HWOp.DebugFun(&hdmitx_device, buf);
return 16;
}
/* support format lists */
const char *disp_mode_t[] = {
"480i60hz",
"480i_rpt",
"480p60hz",
"480p_rpt",
"576i50hz",
"576i_rpt",
"576p50hz",
"576p_rpt",
"720p60hz",
"1080i60hz",
"1080p60hz",
"720p50hz",
"1080i50hz",
"1080p50hz",
"1080p24hz",
"2160p30hz",
"2160p25hz",
"2160p24hz",
"smpte24hz",
"2160p50hz",
"2160p60hz",
"2160p50hz420",
"2160p60hz420",
/* VESA modes */
"640x480p60hz",
"800x480p60hz",
"800x600p60hz",
"1024x600p60hz",
"1024x768p60hz",
"1280x800p60hz",
"1280x1024p60hz",
"1360x768p60hz",
"1366x768p60hz",
"1440x900p60hz",
"1600x900p60hz",
"1600x1200p60hz",