-
Notifications
You must be signed in to change notification settings - Fork 50
/
hdmi_tx_main.c
8405 lines (7435 loc) · 225 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
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
/*
* Copyright (c) 2019 Amlogic, Inc. All rights reserved.
*/
#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/devinfo.h>
#include <linux/pinctrl/consumer.h>
#include <linux/mutex.h>
#include <linux/cdev.h>
#include <linux/ctype.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/i2c.h>
#include <linux/miscdevice.h>
#include <linux/of_gpio.h>
#include <linux/rtc.h>
#include <linux/timekeeping.h>
//#include <linux/amlogic/cpu_version.h>
#include <linux/amlogic/media/vout/vinfo.h>
#include <linux/amlogic/media/vout/vout_notify.h>
#if IS_ENABLED(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 <linux/amlogic/media/vout/hdmi_tx_ext.h>
#include <linux/amlogic/media/registers/cpu_version.h>
#include "hw/tvenc_conf.h"
#include "hw/hdmi_tx_reg.h"
#include "hw/mach_reg.h"
#include "hw/reg_sc2.h"
#include "hw/common.h"
#include "hw/hw_clk.h"
#include "hw/reg_ops.h"
#include "hdmi_tx_hdcp.h"
#include "meson_drm_hdmitx.h"
#include "meson_hdcp.h"
#include <linux/component.h>
#include <uapi/drm/drm_mode.h>
#include <linux/amlogic/gki_module.h>
#include <drm/amlogic/meson_drm_bind.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, bool signal_sdr);
static void hdmitx_set_hdr10plus_pkt(unsigned int flag,
struct hdr10plus_para *data);
static void hdmitx_set_cuva_hdr_vsif(struct cuva_hdr_vsif_para *data);
static void hdmitx_set_cuva_hdr_vs_emds(struct cuva_hdr_vs_emds_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 void hdmitx_fmt_attr(struct hdmitx_dev *hdev);
static void clear_rx_vinfo(struct hdmitx_dev *hdev);
static void edidinfo_attach_to_vinfo(struct hdmitx_dev *hdev);
static void edidinfo_detach_to_vinfo(struct hdmitx_dev *hdev);
static void update_current_para(struct hdmitx_dev *hdev);
static bool is_cur_tmds_div40(struct hdmitx_dev *hdev);
static void hdmitx_resend_div40(struct hdmitx_dev *hdev);
static unsigned int hdmitx_get_frame_duration(void);
static int meson_hdmitx_bind(struct device *dev,
struct device *master, void *data);
static void meson_hdmitx_unbind(struct device *dev,
struct device *master, void *data);
/*
* Normally, after the HPD in or late resume, there will reading EDID, and
* notify application to select a hdmi mode output. But during the mode
* setting moment, there may be HPD out. It will clear the edid data, ..., etc.
* To avoid such case, here adds the hdmimode_mutex to let the HPD in, HPD out
* handler and mode setting sequentially.
*/
static DEFINE_MUTEX(hdmimode_mutex);
#ifdef CONFIG_AMLOGIC_VOUT_SERVE
static struct vinfo_s *hdmitx_get_current_vinfo(void *data);
#else
static struct vinfo_s *hdmitx_get_current_vinfo(void *data)
{
return NULL;
}
#endif
#ifdef CONFIG_OF
static struct amhdmitx_data_s amhdmitx_data_g12a = {
.chip_type = MESON_CPU_ID_G12A,
.chip_name = "g12a",
};
static struct amhdmitx_data_s amhdmitx_data_g12b = {
.chip_type = MESON_CPU_ID_G12B,
.chip_name = "g12b",
};
static struct amhdmitx_data_s amhdmitx_data_sm1 = {
.chip_type = MESON_CPU_ID_SM1,
.chip_name = "sm1",
};
static struct amhdmitx_data_s amhdmitx_data_sc2 = {
.chip_type = MESON_CPU_ID_SC2,
.chip_name = "sc2",
};
static struct amhdmitx_data_s amhdmitx_data_tm2 = {
.chip_type = MESON_CPU_ID_TM2,
.chip_name = "tm2",
};
static const struct of_device_id meson_amhdmitx_of_match[] = {
{
.compatible = "amlogic, amhdmitx-g12a",
.data = &amhdmitx_data_g12a,
},
{
.compatible = "amlogic, amhdmitx-g12b",
.data = &amhdmitx_data_g12b,
},
{
.compatible = "amlogic, amhdmitx-sm1",
.data = &amhdmitx_data_sm1,
},
{
.compatible = "amlogic, amhdmitx-sc2",
.data = &amhdmitx_data_sc2,
},
{
.compatible = "amlogic, amhdmitx-tm2",
.data = &amhdmitx_data_tm2,
},
{},
};
#else
#define meson_amhdmitx_dt_match NULL
#endif
static DEFINE_MUTEX(setclk_mutex);
static DEFINE_MUTEX(getedid_mutex);
static struct hdmitx_dev hdmitx_device = {
.frac_rate_policy = 1,
.cec_func_config = 0x7f
};
static const struct dv_info dv_dummy;
static int log_level;
static bool hdmitx_edid_done;
/* for SONY-KD-55A8F TV, need to mute more frames
* when switch DV(LL)->HLG
*/
static int hdr_mute_frame = 20;
static unsigned int res_1080p;
static char suspend_fmt_attr[16];
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_cuva_hdr_vsif = hdmitx_set_cuva_hdr_vsif,
.fresh_tx_cuva_hdr_vs_emds = hdmitx_set_cuva_hdr_vs_emds,
.fresh_tx_emp_pkt = hdmitx_set_emp_pkt,
.get_attr = get20_attr,
.setup_attr = setup20_attr,
.video_mute = hdmitx20_video_mute_op,
};
struct hdmi_config_platform_data *hdmi_pdata;
static struct hdmitx_uevent hdmi_events[] = {
{
.type = HDMITX_HPD_EVENT,
.env = "hdmitx_hpd=",
},
{
.type = HDMITX_HDCP_EVENT,
.env = "hdmitx_hdcp=",
},
{
.type = HDMITX_AUDIO_EVENT,
.env = "hdmitx_audio=",
},
{
.type = HDMITX_HDCPPWR_EVENT,
.env = "hdmitx_hdcppwr=",
},
{
.type = HDMITX_HDR_EVENT,
.env = "hdmitx_hdr=",
},
{
.type = HDMITX_RXSENSE_EVENT,
.env = "hdmitx_rxsense=",
},
{
.type = HDMITX_CEDST_EVENT,
.env = "hdmitx_cedst=",
},
{ /* end of hdmi_events[] */
.type = HDMITX_NONE_EVENT,
},
};
/* indicate plugout before systemcontrol boot */
static bool plugout_mute_flg;
static char hdmichecksum[11] = {
'i', 'n', 'v', 'a', 'l', 'i', 'd', 'c', 'r', 'c', '\0'
};
static char invalidchecksum[11] = {
'i', 'n', 'v', 'a', 'l', 'i', 'd', 'c', 'r', 'c', '\0'
};
static char emptychecksum[11] = {0};
static int hdmitx_set_uevent(enum hdmitx_event type, int val)
{
char env[MAX_UEVENT_LEN];
struct hdmitx_uevent *event = hdmi_events;
struct hdmitx_dev *hdev = &hdmitx_device;
char *envp[2];
int ret = -1;
for (event = hdmi_events; event->type != HDMITX_NONE_EVENT; event++) {
if (type == event->type)
break;
}
if (event->type == HDMITX_NONE_EVENT)
return ret;
if (event->state == val)
return ret;
event->state = val;
memset(env, 0, sizeof(env));
envp[0] = env;
envp[1] = NULL;
snprintf(env, MAX_UEVENT_LEN, "%s%d", event->env, val);
ret = kobject_uevent_env(&hdev->hdtx_dev->kobj, KOBJ_CHANGE, envp);
/* pr_info("%s[%d] %s %d\n", __func__, __LINE__, env, ret); */
return ret;
}
/* There are 3 callback functions for front HDR/DV/HDR10+ modules to notify
* hdmi drivers to send out related HDMI infoframe
* hdmitx_set_drm_pkt() is for HDR 2084 SMPTE, HLG, etc.
* hdmitx_set_vsif_pkt() is for DV
* hdmitx_set_hdr10plus_pkt is for HDR10+
* Front modules may call the 2nd, and next call the 1st, and the realted flags
* are remained the same. So, add hdr_status_pos and place it in the above 3
* functions to record the position.
*/
int hdr_status_pos;
static inline void hdmitx_notify_hpd(int hpd, void *p)
{
if (hpd)
hdmitx_event_notify(HDMITX_PLUG, p);
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 *hdev = (struct hdmitx_dev *)h->param;
bool need_rst_ratio = hdmitx_find_vendor_ratio(hdev);
unsigned int mute_us =
hdev->debug_param.avmute_frame * hdmitx_get_frame_duration();
/* Here remove the hpd_lock. Suppose at beginning, the hdmi cable is
* unconnected, and system goes to suspend, during this time, cable
* plugin. In this time, there will be no CEC physical address update
* and must wait the resume.
*/
mutex_lock(&hdmimode_mutex);
hdev->ready = 0;
hdev->hwop.cntlmisc(hdev, MISC_SUSFLAG, 1);
usleep_range(10000, 10010);
hdev->hwop.cntlmisc(hdev, MISC_AVMUTE_OP, SET_AVMUTE);
/* delay 100ms after avmute is a empirical value,
* mute_us is for debug, at least 16ms for 60fps
*/
if (hdev->debug_param.avmute_frame > 0)
msleep(mute_us / 1000);
else
msleep(100);
pr_info(SYS "HDMITX: Early Suspend\n");
/* if (hdev->hdcp_ctl_lvl > 0 && */
/* hdev->hwop.am_hdmitx_hdcp_disable) */
/* hdev->hwop.am_hdmitx_hdcp_disable(); */
hdev->hwop.cntl(hdev, HDMITX_EARLY_SUSPEND_RESUME_CNTL,
HDMITX_EARLY_SUSPEND);
hdev->cur_VIC = HDMI_UNKNOWN;
hdev->output_blank_flag = 0;
hdev->hwop.cntlddc(hdev, DDC_HDCP_MUX_INIT, 1);
hdev->hwop.cntlddc(hdev, DDC_HDCP_OP, HDCP14_OFF);
hdmitx_set_drm_pkt(NULL);
hdmitx_set_vsif_pkt(0, 0, NULL, true);
hdmitx_set_hdr10plus_pkt(0, NULL);
clear_rx_vinfo(hdev);
hdmitx_edid_clear(hdev);
hdmitx_edid_ram_buffer_clear(hdev);
edidinfo_detach_to_vinfo(hdev);
hdmitx_set_uevent(HDMITX_HDCPPWR_EVENT, HDMI_SUSPEND);
hdmitx_set_uevent(HDMITX_AUDIO_EVENT, 0);
hdev->hwop.cntlconfig(hdev, CONF_CLR_AVI_PACKET, 0);
hdev->hwop.cntlconfig(hdev, CONF_CLR_VSDB_PACKET, 0);
/* for huawei TV, it will display green screen pattern under
* 4k50/60hz y420 deep color when receive amvute. After disable
* phy of box, TV will continue mute and stay in still frame
* mode for a few frames, if it receives scdc clk rate change
* during this period, it may recognize it as signal unstable
* instead of no signal, and keep mute pattern for several
* seconds. Here keep hdmi output disabled for a few frames
* so let TV exit its still frame mode and not show pattern
*/
if (need_rst_ratio) {
usleep_range(120000, 120010);
hdev->hwop.cntlddc(hdev, DDC_SCDC_DIV40_SCRAMB, 0);
}
memcpy(suspend_fmt_attr, hdev->fmt_attr, sizeof(hdev->fmt_attr));
mutex_unlock(&hdmimode_mutex);
}
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(NULL);
struct hdmitx_dev *hdev = (struct hdmitx_dev *)h->param;
u8 hpd_state = 0;
mutex_lock(&hdmimode_mutex);
if (info && (hdmitx_is_hdmi_vmode(info->name) == 1))
hdev->hwop.cntlmisc(&hdmitx_device, MISC_HPLL_FAKE, 0);
hdev->hpd_lock = 0;
/* update status for hpd and switch/state */
hpd_state = !!(hdev->hwop.cntlmisc(hdev, MISC_HPD_GPI_ST, 0));
/* for RDK userspace, after receive plug change uevent,
* it will check connector state before enable encoder.
* so should not change hpd_state other than in plug handler
*/
if (hdev->hdcp_ctl_lvl != 0x1)
hdev->hpd_state = hpd_state;
if (hdev->hpd_state)
hdev->already_used = 1;
pr_info("hdmitx hpd state: %d\n", hdev->hpd_state);
/*force to get EDID after resume */
if (hpd_state) {
/*add i2c soft reset before read EDID */
hdev->hwop.cntlddc(hdev, DDC_GLITCH_FILTER_RESET, 0);
if (hdev->data->chip_type >= MESON_CPU_ID_G12A)
hdev->hwop.cntlmisc(hdev, MISC_I2C_RESET, 0);
hdmitx_get_edid(hdev);
hdmitx_edid_done = true;
}
hdmitx_notify_hpd(hpd_state,
hdev->edid_parsing ?
hdev->edid_ptr : NULL);
/* recover attr (especially for HDR case) */
if (info && drm_hdmitx_chk_mode_attr_sup(info->name,
suspend_fmt_attr))
setup_attr(suspend_fmt_attr);
hdmitx_set_uevent(HDMITX_HPD_EVENT, hdev->hpd_state);
hdmitx_set_uevent(HDMITX_HDCPPWR_EVENT, HDMI_WAKEUP);
hdmitx_set_uevent(HDMITX_AUDIO_EVENT, hdev->hpd_state);
pr_info("amhdmitx: late resume module %d\n", __LINE__);
hdev->hwop.cntl(hdev, HDMITX_EARLY_SUSPEND_RESUME_CNTL,
HDMITX_LATE_RESUME);
hdev->hwop.cntlmisc(hdev, MISC_SUSFLAG, 0);
pr_info(SYS "HDMITX: Late Resume\n");
mutex_unlock(&hdmimode_mutex);
/* hpd plug uevent may not be handled by rdk userspace
* during suspend/resume (such as no plugout uevent is
* triggered, and subsequent plugin event will be ignored)
* as a result, hdmi/hdcp may not set correctly.
* in such case, force restart hdmi/hdcp when resume.
*/
if (hdev->hpd_state) {
if (hdev->hdcp_ctl_lvl == 0x1)
hdev->hwop.am_hdmitx_set_out_mode();
}
}
/* 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);
unsigned int mute_us =
hdev->debug_param.avmute_frame * hdmitx_get_frame_duration();
hdev->ready = 0;
hdev->hwop.cntlmisc(hdev, MISC_AVMUTE_OP, SET_AVMUTE);
if (hdev->debug_param.avmute_frame > 0)
msleep(mute_us / 1000);
else
msleep(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.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);
}
static void hdmi_physical_size_update(struct hdmitx_dev *hdev)
{
unsigned int width, height;
struct vinfo_s *info = NULL;
info = hdmitx_get_current_vinfo(NULL);
if (!info || !info->name) {
pr_info(SYS "cann't get valid mode\n");
return;
}
if (info->mode == VMODE_HDMI) {
width = hdev->rxcap.physical_width;
height = hdev->rxcap.physical_height;
if (width == 0 || height == 0) {
info->screen_real_width = info->aspect_ratio_num;
info->screen_real_height = info->aspect_ratio_den;
} else {
info->screen_real_width = width;
info->screen_real_height = height;
}
pr_info(SYS "update physical size: %d %d\n",
info->screen_real_width, info->screen_real_height);
}
}
static void hdrinfo_to_vinfo(struct hdr_info *hdrinfo, struct hdmitx_dev *hdev)
{
memcpy(hdrinfo, &hdev->rxcap.hdr_info, sizeof(struct hdr_info));
hdrinfo->colorimetry_support = hdev->rxcap.colorimetry_data;
}
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 void edidinfo_attach_to_vinfo(struct hdmitx_dev *hdev)
{
struct vinfo_s *info = NULL;
/* get current vinfo */
info = hdmitx_get_current_vinfo(NULL);
if (!info || !info->name)
return;
if (strncmp(info->name, "480cvbs", 7) == 0 ||
strncmp(info->name, "576cvbs", 7) == 0 ||
strncmp(info->name, "null", 4) == 0)
return;
mutex_lock(&getedid_mutex);
hdrinfo_to_vinfo(&info->hdr_info, hdev);
rxlatency_to_vinfo(info, &hdev->rxcap);
hdmitx_vdev.dv_info = &hdmitx_device.rxcap.dv_info;
mutex_unlock(&getedid_mutex);
}
static void edidinfo_detach_to_vinfo(struct hdmitx_dev *hdev)
{
struct vinfo_s *info = NULL;
/* get current vinfo */
info = hdmitx_get_current_vinfo(NULL);
if (!info || !info->name)
return;
edidinfo_attach_to_vinfo(hdev);
hdmitx_vdev.dv_info = &dv_dummy;
}
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;
int colour_depths[] = { 8, 10, 12, 16 };
char* colour_sampling[] = {"RGB","YUV422","YUV444","YUV420"};
memset(mode, 0, sizeof(mode));
hdev->ready = 0;
/* get current vinfo */
info = hdmitx_get_current_vinfo(NULL);
if (!info || !info->name) {
return -1;
}
pr_info(SYS "get current mode: %s\n", info->name);
/*update hdmi checksum to vout*/
memcpy(info->hdmichecksum, hdev->rxcap.chksum, 10);
hdmi_physical_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) ||
(strncmp(info->name, "panel", 5) == 0) ||
(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);
if (hdev->cedst_policy)
cancel_delayed_work(&hdev->work_cedst);
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;
}
}
}
/* In the file hdmi_common/hdmi_parameters.c,
* the data array all_fmt_paras[] treat 2160p60hz and 2160p60hz420
* as two different modes, such Scrambler
* So if node "attr" contains 420, need append 420 to mode.
*/
if (strstr(hdev->fmt_attr, "420")) {
if (!strstr(mode, "420"))
strcat(mode, "420");
}
para = hdmi_get_fmt_name(mode, hdev->fmt_attr);
hdev->para = para;
if (!hdmitx_edid_check_valid_mode(hdev, para)) {
pr_err("check failed vic: %d\n", para->vic);
return -1;
}
vic = hdmitx_edid_get_VIC(hdev, mode, 1);
// force colour subsampling when DV mode
switch (hdev->hdmi_current_eotf_type) {
case EOTF_T_DOLBYVISION:
case EOTF_T_LL_MODE:
case EOTF_T_DV_AHEAD:
{
int cs = para->cs;
switch (hdev->hdmi_current_tunnel_mode) {
case RGB_8BIT:
case RGB_10_12BIT:
para->cs = COLORSPACE_YUV444;
break;
case YUV422_BIT12:
para->cs = COLORSPACE_YUV422;
break;
case YUV444_10_12BIT:
para->cs = COLORSPACE_YUV444;
break;
default:
break;
}
if (cs != para->cs)
pr_info("hdmitx: display colour subsampling is forced to %s by Dolby Vision tunneling\n",
colour_sampling[para->cs]);
}
break;
default:
break;
}
// parse and set maximum colourdepth given by edid
// check for colour subsampling limit
switch (hdev->hdmi_current_eotf_type) {
case EOTF_T_DOLBYVISION:
case EOTF_T_LL_MODE:
case EOTF_T_DV_AHEAD:
{
const struct dv_info *dv_info = &hdev->rxcap.dv_info;
int cd = para->cd;
switch (hdev->hdmi_current_tunnel_mode) {
case RGB_8BIT:
para->cd = COLORDEPTH_24B;
break;
case RGB_10_12BIT:
case YUV444_10_12BIT:
if (dv_info->ver == 2) {
switch (dv_info->sup_10b_12b_444) {
case 1:
para->cd = COLORDEPTH_30B;
break;
case 2:
para->cd = COLORDEPTH_36B;
break;
default:
break;
}
}
break;
case YUV422_BIT12:
para->cd = COLORDEPTH_36B;
break;
default:
break;
}
if (cd != para->cd)
pr_info("hdmitx: display colourdepth is forced to %d bits because of Dolby Vision sink capability\n",
colour_depths[para->cd - COLORDEPTH_24B]);
}
break;
default:
// auto detect colourdepth
if (strstr(hdev->fmt_attr,"bit") != NULL) {
pr_info("hdmitx: display colourdepth is forced by attr to %d bits (VIC: %d)\n",
colour_depths[para->cd - COLORDEPTH_24B], vic);
} else {
if (hdev->rxcap.ColorDeepSupport & 0x78 && hdev->para->cs != COLORSPACE_YUV420) {
enum hdmi_color_depth cd;
for (cd = COLORDEPTH_36B; cd >= COLORDEPTH_24B; cd--) {
if (hdev->rxcap.ColorDeepSupport & (1 << (cd - 1))) {
para->cd = cd;
break;
}
}
} else if (hdev->rxcap.hf_ieeeoui == HF_IEEEOUI) {
if (hdev->rxcap.dc_36bit_420)
para->cd = COLORDEPTH_36B;
else if (hdev->rxcap.dc_30bit_420)
para->cd = COLORDEPTH_30B;
else
para->cd = COLORDEPTH_24B;
}
switch (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:
if (para->cs == COLORSPACE_RGB444 || para->cs == COLORSPACE_YUV444)
{
para->cd = COLORDEPTH_24B;
pr_info("hdmitx: display colourdepth is forced to %d bits because of current colour sampling\n",
colour_depths[para->cd - COLORDEPTH_24B]);
}
break;
default:
break;
}
pr_info("hdmitx: display colourdepth is auto set to %d bits (VIC: %d)\n",
colour_depths[para->cd - COLORDEPTH_24B], vic);
}
break;
}
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 */
}
hdmitx_pre_display_init();
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 */
if (strncmp(mode, "panel", 5) == 0) {
hdev->hwop.cntl(hdev, HDMITX_HWCMD_TURNOFF_HDMIHW,
(hdev->hpdmode == 2) ? 1 : 0);
}
}
hdmitx_set_audio(hdev, &hdev->cur_audio_param);
if (hdev->cedst_policy) {
cancel_delayed_work(&hdev->work_cedst);
queue_delayed_work(hdev->cedst_wq, &hdev->work_cedst, 0);
}
hdev->output_blank_flag = 1;
hdev->ready = 1;
edidinfo_attach_to_vinfo(hdev);
/* backup values need to be updated to latest values */
memcpy(hdev->backup_fmt_attr, hdev->fmt_attr, 16);
hdev->backup_frac_rate_policy = hdev->frac_rate_policy;
return ret;
}
/*disp_mode attr*/
static ssize_t disp_mode_show(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 disp_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
set_disp_mode(buf);
return count;
}
static ssize_t attr_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
if (!memcmp(hdmitx_device.fmt_attr, "default,", 7)) {
memset(hdmitx_device.fmt_attr, 0,
sizeof(hdmitx_device.fmt_attr));
hdmitx_fmt_attr(&hdmitx_device);
}
pos += snprintf(buf + pos, PAGE_SIZE, "%s\n\r", hdmitx_device.fmt_attr);
return pos;
}
ssize_t attr_store(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 (!memcmp(hdmitx_device.fmt_attr, "rgb", 3))
hdmitx_device.para->cs = COLORSPACE_RGB444;
else if (!memcmp(hdmitx_device.fmt_attr, "422", 3))
hdmitx_device.para->cs = COLORSPACE_YUV422;
else if (!memcmp(hdmitx_device.fmt_attr, "420", 3))
hdmitx_device.para->cs = COLORSPACE_YUV420;
else
hdmitx_device.para->cs = COLORSPACE_YUV444;
if (strstr(hdmitx_device.fmt_attr, "now")) {
mutex_lock(&hdmimode_mutex);
set_disp_mode_auto();
mutex_unlock(&hdmimode_mutex);
memcpy(strstr(hdmitx_device.fmt_attr, "now"), " ", 3);
}
return count;
}
static ssize_t cs_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
int cs = hdmitx_rd_reg(HDMITX_DWC_FC_AVICONF0) & 0x3;
pos +=
snprintf(buf + pos, PAGE_SIZE, "%d\n", cs);
return pos;
}
static ssize_t cd_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int pos = 0;
int cs = hdmitx_rd_reg(HDMITX_DWC_FC_AVICONF0) & 0x3;
int cd = (hdmitx_rd_reg(HDMITX_DWC_TX_INVID0) & 0x6) >> 1;
// YUV422
if (cs == COLORSPACE_YUV422)
cd = (~cd & 0x3);
pos +=
snprintf(buf + pos, PAGE_SIZE, "%d\n", cd);
return pos;
}
void setup20_attr(const char *buf)
{
char attr[16] = {0};
memcpy(attr, buf, sizeof(attr));
memcpy(hdmitx_device.fmt_attr, attr, sizeof(hdmitx_device.fmt_attr));
}
void get20_attr(char attr[16])
{
memcpy(attr, hdmitx_device.fmt_attr, sizeof(hdmitx_device.fmt_attr));
}
/* for android application data exchange / swap */
static char *tmp_swap;
static DEFINE_MUTEX(mutex_swap);
static ssize_t swap_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
pr_info("%s: %s\n", __func__, buf);
mutex_lock(&mutex_swap);
kfree(tmp_swap);
tmp_swap = kzalloc(count + 1, GFP_KERNEL);
if (!tmp_swap) {
mutex_unlock(&mutex_swap);
return count;