-
Notifications
You must be signed in to change notification settings - Fork 7
/
smi_mode.c
1250 lines (1020 loc) · 30.6 KB
/
smi_mode.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+
// Copyright (c) 2023, SiliconMotion Inc.
#include "smi_drv.h"
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
#include <drm/drm_fourcc.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
#include <drm/drm_pci.h>
#else
#include <linux/pci.h>
#endif
#include <drm/drm_vblank.h>
#else
#include <drm/drmP.h>
#endif
#include <drm/drm_atomic_helper.h>
#include <drm/drm_atomic_state_helper.h>
#include <drm/drm_gem.h>
#include <drm/drm_plane_helper.h>
#include <drm/drm_crtc_helper.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
#include <drm/drm_probe_helper.h>
#endif
#include "hw750.h"
#include "hw768.h"
#include "ddk768/ddk768_video.h"
#include "ddk768/ddk768_chip.h"
#include "smi_dbg.h"
int smi_calc_hdmi_ctrl(int m_connector)
{
int smi_ctrl = 0;
if(m_connector==USE_DVI_HDMI) // //vga is empty, dvi is occupied , HDMI use ctrl 1;
smi_ctrl = 1;
else
smi_ctrl = 0;
return smi_ctrl;
}
static int smi_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g,
u16 *b, uint32_t size,
struct drm_modeset_acquire_ctx *ctx)
{
struct smi_crtc *smi_crtc = to_smi_crtc(crtc);
int i , max_index = 2, ctrl_index, dst_ctrl;
struct smi_device *sdev = crtc->dev->dev_private;
ctrl_index = 0;
dst_ctrl = 0;
if(sdev->specId == SPC_SM768)
max_index = MAX_ENCODER;
for(i = 0;i < max_index; i++)
{
if(crtc == sdev->smi_enc_tab[i]->crtc)
{
ctrl_index = i;
break;
}
}
dst_ctrl = (ctrl_index == SMI1_CTRL)?SMI1_CTRL:SMI0_CTRL;
if(ctrl_index > SMI1_CTRL)
{
dst_ctrl= smi_calc_hdmi_ctrl(sdev->m_connector);
}
for (i = 0; i < crtc->gamma_size; i++)
{
smi_crtc->lut_r[i] = r[i] >> 8;
smi_crtc->lut_g[i] = g[i] >> 8;
smi_crtc->lut_b[i] = b[i] >> 8;
}
if (sdev->specId == SPC_SM768) {
hw768_setgamma(dst_ctrl, true , lvds_channel);
hw768_load_lut(dst_ctrl, crtc->gamma_size, smi_crtc->lut_r, smi_crtc->lut_g, smi_crtc->lut_b);
}else if(sdev->specId == SPC_SM750) {
hw750_setgamma(dst_ctrl, true);
hw750_load_lut(dst_ctrl, crtc->gamma_size, smi_crtc->lut_r, smi_crtc->lut_g, smi_crtc->lut_b);
}
return 0;
}
/*
* The DRM core requires DPMS functions, but they make little sense in our
* case and so are just stubs
*/
static void smi_crtc_mode_set_nofb(struct drm_crtc *crtc)
{
struct drm_display_mode *mode;
struct smi_device *sdev = crtc->dev->dev_private;
logicalMode_t logicalMode;
unsigned long refresh_rate;
unsigned int need_to_scale = 0;
YUV_BUF_ADDR SrcAddr;
BLIT_BLK src;
BLIT_BLK dest;
ENTER();
logicalMode.valid_edid = false;
if (WARN_ON(!crtc->state))
LEAVE();
mode = &crtc->state->adjusted_mode;
refresh_rate = drm_mode_vrefresh(mode);
dbg_msg("***crtc addr:%p\n", crtc);
dbg_msg("encode->crtc:[%p, %p, %p] \n", sdev->smi_enc_tab[0]->crtc, sdev->smi_enc_tab[1]->crtc,
sdev->smi_enc_tab[2] == NULL ? NULL : sdev->smi_enc_tab[2]->crtc);
dbg_msg("m_connector = %d, DVI [%d], VGA[%d], HDMI[%d] \n", sdev->m_connector,
sdev->m_connector & 0x1, sdev->m_connector & 0x2, sdev->m_connector & 0x4);
dbg_msg("wxh:%dx%d@%ldHz\n", mode->hdisplay, mode->vdisplay, refresh_rate);
if (sdev->specId == SPC_SM750) {
if(crtc == sdev->smi_enc_tab[0]->crtc)
{
logicalMode.baseAddress = 0;
logicalMode.x = mode->hdisplay;
logicalMode.y = mode->vdisplay;
logicalMode.bpp = smi_bpp;
logicalMode.dispCtrl = SMI0_CTRL;
logicalMode.hz = refresh_rate;
logicalMode.pitch = 0;
setMode(&logicalMode);
setDisplayControl(SMI0_CTRL, DISP_ON); /* Turn on Primary Control */
setPath(SMI0_PATH, SMI0_CTRL, DISP_ON); /* Turn on Panel Path and use Primary data */
}
if(crtc == sdev->smi_enc_tab[1]->crtc)
{
logicalMode.baseAddress = 0;
logicalMode.x = mode->hdisplay;
logicalMode.y = mode->vdisplay;
logicalMode.bpp = smi_bpp;
logicalMode.dispCtrl = SMI1_CTRL;
logicalMode.hz = refresh_rate;
logicalMode.pitch = 0;
setMode(&logicalMode);
setDisplayControl(SMI1_CTRL, DISP_ON); /* Turn on Secondary control */
setPath(SMI1_PATH, SMI1_CTRL, DISP_ON); /* Turn on CRT Path and use Secondary data */
}
swPanelPowerSequence(DISP_ON, 4); /* Turn on Panel */
setDAC(DISP_ON); /* Turn on DAC */
#ifdef USE_HDMICHIP
printk("HDMI set mode\n");
sii9022xSetMode(5);
#endif
}
else {
int i, ctrl_index, dst_ctrl;
ctrl_index = 0;
dst_ctrl = 0;
for(i = 0;i < MAX_ENCODER; i++)
{
if(crtc == sdev->smi_enc_tab[i]->crtc)
{
ctrl_index = i;
break;
}
}
dst_ctrl = (ctrl_index == SMI1_CTRL)?SMI1_CTRL:SMI0_CTRL;
if(ctrl_index > SMI1_CTRL)
{
dst_ctrl=smi_calc_hdmi_ctrl(sdev->m_connector);
dbg_msg("hdmi use channel %d\n",dst_ctrl);
}
logicalMode.baseAddress = 0;
logicalMode.x = mode->hdisplay;
logicalMode.y = mode->vdisplay;
logicalMode.bpp = smi_bpp;
logicalMode.hz = refresh_rate;
logicalMode.pitch = 0;
logicalMode.dispCtrl = dst_ctrl;
switch (ctrl_index)
{
case 0:
if (sdev->dvi_edid && drm_edid_header_is_valid((u8 *)sdev->dvi_edid) == 8)
logicalMode.valid_edid = true;
break;
case 1:
if (sdev->vga_edid && drm_edid_header_is_valid((u8 *)sdev->vga_edid) == 8)
logicalMode.valid_edid = true;
break;
case 2:
if (sdev->hdmi_edid && drm_edid_header_is_valid((u8 *)sdev->hdmi_edid) == 8)
logicalMode.valid_edid = true;
break;
default:
break;
}
if(edid_mode == 0){
printk("Use Driver build-in mode timing\n");
logicalMode.valid_edid = false;
}
if(lcd_scale && (dst_ctrl == 0) && (mode->hdisplay != fixed_width) && (mode->vdisplay != fixed_height) ){
need_to_scale = 1;
}
if(need_to_scale){
logicalMode.x = fixed_width;
logicalMode.y = fixed_height;
logicalMode.valid_edid = false;
}
hw768_setMode(&logicalMode, *mode);
DisableDoublePixel(0);
DisableDoublePixel(1);
if(need_to_scale)
{
file_format srcFormat;
if(logicalMode.bpp==16)
srcFormat = FFT_RGB565;
if(logicalMode.bpp==32)
srcFormat = FFT_RGBx888;
src.Width = mode->hdisplay;
src.Height = mode->vdisplay;
src.Pitch = logicalMode.pitch;
dest.Width = logicalMode.x;
dest.Height = logicalMode.y;
dest.Pitch = logicalMode.pitch;
dest.x = 0;
dest.y = 0;
SrcAddr.bufYAddr = logicalMode.baseAddress;
SrcAddr.bufCbAddr = 0;
SrcAddr.bufCrAddr = 0;
SM768_setOverlay(logicalMode.dispCtrl, &src, &SrcAddr, &dest, srcFormat);
}else{
stopVideo(dst_ctrl);
}
setSingleViewOn(dst_ctrl);
initDisplay();
if(need_to_scale)
ddk768_setDisplayPlaneDisableOnly(dst_ctrl);
#ifdef USE_EP952
hw768_SetPixelClockFormat(dst_ctrl,1);
#else
if (ddk768_getPixelType())
hw768_SetPixelClockFormat(dst_ctrl, 1);
else
hw768_SetPixelClockFormat(dst_ctrl,0);
#endif
if((sdev->m_connector & USE_HDMI)&&(ctrl_index > SMI1_CTRL))
{
int ret = 0;
printk("Starting init SM768 HDMI! Use Channel [%d]\n", dst_ctrl);
if(dst_ctrl == 0)
hw768_SetPixelClockFormat(dst_ctrl,0);
ret=hw768_set_hdmi_mode(&logicalMode, *mode, sdev->is_hdmi);
if (ret != 0)
{
printk("HDMI Mode not supported!\n");
}
}
if(lvds_channel == 1){
printk("Use Single Channel LVDS\n");
hw768_enable_lvds(1);
}
else if(lvds_channel == 2){
printk("Use Dual Channel LVDS\n");
hw768_enable_lvds(2);
EnableDoublePixel(0);
}
}
LEAVE();
}
/* Simple cleanup function */
static void smi_crtc_destroy(struct drm_crtc *crtc)
{
struct smi_crtc *smi_crtc = to_smi_crtc(crtc);
drm_crtc_cleanup(crtc);
kfree(smi_crtc);
}
static void smi_crtc_atomic_flush(struct drm_crtc *crtc,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
struct drm_atomic_state *state)
#else
struct drm_crtc_state *old_state)
#endif
{
unsigned long flags;
ENTER();
spin_lock_irqsave(&crtc->dev->event_lock, flags);
if (crtc->state->event)
drm_crtc_send_vblank_event(crtc, crtc->state->event);
crtc->state->event = NULL;
spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
LEAVE();
}
static void smi_crtc_atomic_enable(struct drm_crtc *crtc,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
struct drm_atomic_state *state)
#else
struct drm_crtc_state *old_state)
#endif
{
ENTER();
LEAVE();
}
static void smi_crtc_atomic_disable(struct drm_crtc *crtc,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 11, 0)
struct drm_atomic_state *state)
#else
struct drm_crtc_state *old_state)
#endif
{
ENTER();
LEAVE();
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
static int smi_enable_vblank(struct drm_crtc *crtc)
{
struct smi_device *sdev = crtc->dev->dev_private;
if (sdev->specId == SPC_SM750) {
hw750_en_dis_interrupt(1);
} else if (sdev->specId == SPC_SM768) {
hw768_en_dis_interrupt(1);
}
return 0;
}
static void smi_disable_vblank(struct drm_crtc *crtc)
{
struct smi_device *sdev = crtc->dev->dev_private;
if (sdev->specId == SPC_SM750) {
hw750_en_dis_interrupt(0);
} else if (sdev->specId == SPC_SM768) {
hw768_en_dis_interrupt(0);
}
}
#endif
/* These provide the minimum set of functions required to handle a CRTC */
static const struct drm_crtc_funcs smi_crtc_funcs = {
.page_flip = drm_atomic_helper_page_flip,
.reset = drm_atomic_helper_crtc_reset,
.atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
.atomic_destroy_state = drm_atomic_helper_crtc_destroy_state,
.set_config = drm_atomic_helper_set_config,
.destroy = smi_crtc_destroy,
.gamma_set = smi_crtc_gamma_set,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 5, 0)
.enable_vblank = smi_enable_vblank,
.disable_vblank = smi_disable_vblank,
#endif
};
static const struct drm_crtc_helper_funcs smi_crtc_helper_funcs = {
.mode_set_nofb = smi_crtc_mode_set_nofb,
.atomic_flush = smi_crtc_atomic_flush,
.atomic_enable = smi_crtc_atomic_enable,
.atomic_disable = smi_crtc_atomic_disable
};
/* CRTC setup */
static struct smi_crtc *smi_crtc_init(struct drm_device *dev, int crtc_id)
{
struct smi_device *cdev = dev->dev_private;
struct smi_crtc *smi_crtc;
struct drm_plane *primary = NULL, *cursor = NULL;
int r, i;
smi_crtc = kzalloc(sizeof(struct smi_crtc) + sizeof(struct drm_connector *), GFP_KERNEL);
if (smi_crtc == NULL)
return NULL;
primary = smi_plane_init(cdev, 1 << crtc_id, DRM_PLANE_TYPE_PRIMARY);
if (IS_ERR(primary)) {
r = -ENOMEM;
goto free_mem;
}
if(swcur_en)
cursor = NULL;
else{
cursor = smi_plane_init(cdev, 1 << crtc_id, DRM_PLANE_TYPE_CURSOR);
if (IS_ERR(cursor)) {
r = -ENOMEM;
goto clean_primary;
}
}
smi_crtc->CursorOffset = 0;
r = drm_crtc_init_with_planes(dev, &smi_crtc->base, primary, cursor, &smi_crtc_funcs, NULL);
if (r) {
goto clean_cursor;
}
drm_mode_crtc_set_gamma_size(&smi_crtc->base, 256);
for (i = 0; i < smi_crtc->base.gamma_size; i++)
{
smi_crtc->lut_r[i] = smi_crtc->lut_g[i] = smi_crtc->lut_b[i] = i;
}
drm_crtc_helper_add(&smi_crtc->base, &smi_crtc_helper_funcs);
return smi_crtc;
clean_cursor:
if (cursor) {
drm_plane_cleanup(cursor);
kfree(cursor);
}
clean_primary:
drm_plane_cleanup(primary);
kfree(primary);
free_mem:
kfree(smi_crtc);
return NULL;
}
static void smi_encoder_mode_set(struct drm_encoder *encoder,
struct drm_display_mode *mode,
struct drm_display_mode *adjusted_mode)
{
}
static void smi_encoder_dpms(struct drm_encoder *encoder, int mode)
{
int index =0;
struct smi_device *sdev = encoder->dev->dev_private;
ENTER();
if (encoder->encoder_type == DRM_MODE_ENCODER_LVDS)
index = 0;
else if (encoder->encoder_type == DRM_MODE_ENCODER_DAC)
index = 1;
else if (encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
index = 2;
dbg_msg("The current connect group = [%d], we deal with con=[%d], mode=[%s]\n", sdev->m_connector,index, (mode == DRM_MODE_DPMS_OFF)?"Off":"ON");
if(sdev->specId == SPC_SM750)
{
if (mode == DRM_MODE_DPMS_OFF) {
dbg_msg("disable dpms, index=%d\n",index);
setDisplayControl(index, DISP_OFF);
}else
{
setDisplayControl(index, DISP_ON);
swPanelPowerSequence(DISP_ON, 4);
dbg_msg("enable dpms ,index=%d\n",index);
}
}else if(sdev->specId == SPC_SM768)
{
if(encoder->encoder_type == DRM_MODE_ENCODER_LVDS)
{
if(sdev->m_connector == USE_VGA_HDMI||sdev->m_connector==USE_HDMI)
{
dbg_msg("DVI connector off\n");
LEAVE();
}
dbg_msg("DVI connector: index=%d\n",index);
}
else if(encoder->encoder_type == DRM_MODE_ENCODER_DAC)
{
if(sdev->m_connector == USE_DVI_HDMI)
{
dbg_msg("VGA connector off\n");
LEAVE();
}
dbg_msg("VGA connector: index=%d\n",index);
}
else if(encoder->encoder_type == DRM_MODE_ENCODER_TMDS)
{
if (mode == DRM_MODE_DPMS_OFF)
hw768_HDMI_Disable_Output();
else
hw768_HDMI_Enable_Output();
if(sdev->m_connector == USE_DVI_HDMI){
index = SMI1_CTRL;
dbg_msg("HDMI connector: index=%d\n",index);
}
else if(sdev->m_connector == USE_VGA_HDMI || sdev->m_connector == USE_HDMI){
index = SMI0_CTRL;
dbg_msg("HDMI connector: index=%d\n",index);
}else{
dbg_msg("HDMI connector not set dpms\n");
LEAVE();
}
}
if (mode == DRM_MODE_DPMS_OFF){
setDisplayDPMS(index, DISP_DPMS_OFF);
ddk768_swPanelPowerSequence(index, 0, 4);
}else{
setDisplayDPMS(index, DISP_DPMS_ON);
ddk768_swPanelPowerSequence(index, 1, 4);
}
if(lvds_channel == 2)
EnableDoublePixel(0);
}
LEAVE();
}
static void smi_encoder_prepare(struct drm_encoder *encoder)
{
smi_encoder_dpms(encoder, DRM_MODE_DPMS_OFF);
}
static void smi_encoder_commit(struct drm_encoder *encoder)
{
smi_encoder_dpms(encoder, DRM_MODE_DPMS_ON);
}
void smi_encoder_destroy(struct drm_encoder *encoder)
{
struct smi_encoder *smi_encoder = to_smi_encoder(encoder);
drm_encoder_cleanup(encoder);
kfree(smi_encoder);
}
static const struct drm_encoder_helper_funcs smi_encoder_helper_funcs = {
.dpms = smi_encoder_dpms,
.mode_set = smi_encoder_mode_set,
.prepare = smi_encoder_prepare,
.commit = smi_encoder_commit,
};
static const struct drm_encoder_funcs smi_encoder_encoder_funcs = {
.destroy = smi_encoder_destroy,
};
static struct drm_encoder *smi_encoder_init(struct drm_device *dev, int index)
{
struct drm_encoder *encoder;
struct smi_encoder *smi_encoder;
smi_encoder = kzalloc(sizeof(struct smi_encoder), GFP_KERNEL);
if (!smi_encoder)
return NULL;
encoder = &smi_encoder->base;
encoder->possible_crtcs = (1 << index);
switch (index)
{
case 0:
//DVI,LVDS
drm_encoder_init(dev, encoder, &smi_encoder_encoder_funcs, DRM_MODE_ENCODER_LVDS, NULL);
break;
case 1:
//VGA
drm_encoder_init(dev, encoder, &smi_encoder_encoder_funcs, DRM_MODE_ENCODER_DAC, NULL);
break;
case 2:
//HDMI
encoder->possible_crtcs = 0x3;
drm_encoder_init(dev, encoder, &smi_encoder_encoder_funcs, DRM_MODE_ENCODER_TMDS, NULL);
break;
default:
printk(KERN_ERR "Wrong connector index\n");
}
drm_encoder_helper_add(encoder, &smi_encoder_helper_funcs);
return encoder;
}
int smi_connector_get_modes(struct drm_connector *connector)
{
#ifdef USE_HDMICHIP
int ret = 0;
#endif
int count = 0;
void *edid_buf = NULL;
struct smi_device *sdev = connector->dev->dev_private;
struct smi_connector *smi_connector = to_smi_connector(connector);
ENTER();
dbg_msg("print connector type: [%d], DVI=%d, VGA=%d, HDMI=%d\n",
connector->connector_type, DRM_MODE_CONNECTOR_DVII, DRM_MODE_CONNECTOR_VGA, DRM_MODE_CONNECTOR_HDMIA);
if(!fixed_width || !fixed_height){
fixed_width = 1024;
fixed_height = 768;
}
if(sdev->specId == SPC_SM750)
{
if(connector->connector_type == DRM_MODE_CONNECTOR_DVII)
{
#ifdef USE_HDMICHIP
edid_buf = sdev->si9022_edid;
if(ddk750_GetDDC_9022Access())
ret = ddk750_edidReadMonitorEx(SMI0_CTRL, edid_buf, 256, 0, 30, 31);
ddk750_Release9022DDC();
if(ret){
drm_connector_update_edid_property(connector, sdev->si9022_edid);
count = drm_add_edid_modes(connector, sdev->si9022_edid);
}
if (ret == 0 || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}
#else
edid_buf = drm_get_edid(connector, &smi_connector->adapter);
if(edid_buf)
{
dbg_msg("DVI get edid success.\n");
sdev->dvi_edid = edid_buf;
drm_connector_update_edid_property(connector, sdev->dvi_edid);
count = drm_add_edid_modes(connector, sdev->dvi_edid);
}
if (edid_buf == NULL || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}
#endif
}
if(connector->connector_type == DRM_MODE_CONNECTOR_VGA)
{
edid_buf = drm_get_edid(connector, &smi_connector->adapter);
if(edid_buf){
dbg_msg("VGA get edid success.\n");
sdev->vga_edid = edid_buf;
drm_connector_update_edid_property(connector, sdev->vga_edid);
count = drm_add_edid_modes(connector, sdev->vga_edid);
}
if (edid_buf == NULL || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}
}
}
else
{ //SM768 Part
if(connector->connector_type == DRM_MODE_CONNECTOR_DVII)
{
if(lvds_channel){
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, fixed_width, fixed_height);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}else{
edid_buf = drm_get_edid(connector, &smi_connector->adapter);
if(edid_buf){
dbg_msg("DVI get edid success.\n");
sdev->dvi_edid = edid_buf;
drm_connector_update_edid_property(connector, sdev->dvi_edid);
count = drm_add_edid_modes(connector, sdev->dvi_edid);
}
if (edid_buf == NULL || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}
}
}
if(connector->connector_type == DRM_MODE_CONNECTOR_VGA)
{
edid_buf = drm_get_edid(connector, &smi_connector->adapter);
if (edid_buf)
{
dbg_msg("VGA get edid success.\n");
sdev->vga_edid = edid_buf;
drm_connector_update_edid_property(connector, sdev->vga_edid);
count = drm_add_edid_modes(connector, sdev->vga_edid);
}
if (edid_buf == NULL || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
}
}
if(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA)
{
edid_buf = drm_get_edid(connector, &smi_connector->adapter);
//hw768_get_hdmi_edid(tmpedid); // Too Slow..
if (edid_buf)
{
dbg_msg("HDMIA get edid success.\n");
sdev->hdmi_edid = edid_buf;
drm_connector_update_edid_property(connector, sdev->hdmi_edid);
count = drm_add_edid_modes(connector, sdev->hdmi_edid);
sdev->is_hdmi = drm_detect_hdmi_monitor(sdev->hdmi_edid);
dbg_msg("HDMI connector is %s\n",(sdev->is_hdmi ? "HDMI monitor" : "DVI monitor"));
}
if (edid_buf == NULL || count == 0)
{
drm_connector_update_edid_property(connector, NULL);
count = drm_add_modes_noedid(connector, 1920, 1080);
drm_set_preferred_mode(connector, fixed_width, fixed_height);
sdev->is_hdmi = true;
}
}
}
LEAVE(count);
}
static enum drm_mode_status smi_connector_mode_valid(struct drm_connector *connector,
struct drm_display_mode *mode)
{
struct smi_device *sdev = connector->dev->dev_private;
u32 vrefresh = drm_mode_vrefresh(mode);
if ((vrefresh < 29) || (vrefresh > 61) || (vrefresh > 31 && vrefresh < 59)){
if(!edid_mode)
return MODE_NOCLOCK;
}
if ((mode->hdisplay > 3840) || (mode->vdisplay > 2160) || (mode->clock > 297000))
return MODE_NOMODE;
if(mode->hdisplay > 1920) {
if ((sdev->m_connector == USE_DVI_HDMI) || (sdev->m_connector == USE_VGA_HDMI)||(sdev->specId == SPC_SM750))
return MODE_NOMODE;
}
if(lvds_channel && (!lcd_scale)){
if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) {
if ((mode->hdisplay == fixed_width) && (mode->vdisplay == fixed_height))
return MODE_OK;
else
return MODE_NOMODE;
}
}
return MODE_OK;
}
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 5, 0)
struct drm_encoder *smi_connector_best_encoder(struct drm_connector *connector)
{
int enc_id = connector->encoder_ids[0];
if (enc_id)
return drm_encoder_find(connector->dev, NULL, enc_id);
return NULL;
}
#endif
static enum drm_connector_status smi_connector_detect(struct drm_connector
*connector,
bool force)
{
struct smi_connector *smi_connector = to_smi_connector(connector);
struct smi_device *sdev = connector->dev->dev_private;
#ifdef USE_HDMICHIP
int ret = 0;
void *edid_buf;
#endif
if (sdev->specId == SPC_SM750)
{
if (connector->connector_type == DRM_MODE_CONNECTOR_DVII)
{
if (force_connect & USE_DVI){
sdev->m_connector = sdev->m_connector | USE_DVI;
return connector_status_connected;
}else if(force_connect){
sdev->m_connector = sdev->m_connector & (~USE_DVI);
return connector_status_disconnected;
}
#ifdef USE_HDMICHIP
if (ddk750_GetDDC_9022Access())
ret = ddk750_edidReadMonitorEx(SMI0_CTRL, edid_buf, 128, 0, 30, 31);
ddk750_Release9022DDC();
if (ret)
{
dbg_msg("detect sii9022 HDMI connected.\n");
return connector_status_connected;
}
else
{
dbg_msg("detect sii9022 HDMI disconnected.\n");
return connector_status_disconnected;
}
#endif
if (!drm_probe_ddc(&smi_connector->adapter))
{
dbg_msg("detect DVI/Panel DO NOT connected.\n");
return connector_status_disconnected;
}
else
{
dbg_msg("detect DVI/Panel connected.\n");
return connector_status_connected;
}
}
else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
{
if (force_connect & USE_VGA){
sdev->m_connector = sdev->m_connector | USE_VGA;
return connector_status_connected;
}else if(force_connect){
sdev->m_connector = sdev->m_connector & (~USE_VGA);
return connector_status_disconnected;
}
#if 0
if(ddk750_detectCRTMonitor(0, 0, 0) == 0)
{
dbg_msg("detect CRT connected.\n");
return connector_status_connected;
}
else
{
dbg_msg("detect CRT DO NOT connected.\n");
return connector_status_disconnected;
}
#else
if(!drm_probe_ddc(&smi_connector->adapter))
{
dbg_msg("detect CRT DO NOT connected.\n");
return connector_status_disconnected;
}
else
{
dbg_msg("detect CRT connected.\n");
return connector_status_connected;
}
#endif
}
else
return connector_status_unknown;
}
else //SM768 Part
{
if(connector->connector_type == DRM_MODE_CONNECTOR_DVII)
{
if ((force_connect & USE_DVI) || (lvds_channel)){
sdev->m_connector = sdev->m_connector | USE_DVI;
return connector_status_connected;
}else if(force_connect){
sdev->m_connector = sdev->m_connector & (~USE_DVI);
return connector_status_disconnected;
}
if (!drm_probe_ddc(&smi_connector->adapter))
{
dbg_msg("detect DVI DO NOT connected. \n");
sdev->m_connector = sdev->m_connector & (~USE_DVI);
return connector_status_disconnected;
}
else
{
dbg_msg("detect DVI connected(GPIO30,31)\n");
sdev->m_connector =sdev->m_connector |USE_DVI;
return connector_status_connected;
}
}
else if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
{
if (force_connect & USE_VGA){
sdev->m_connector = sdev->m_connector | USE_VGA;
return connector_status_connected;
}else if(force_connect){
sdev->m_connector = sdev->m_connector & (~USE_VGA);
return connector_status_disconnected;
}
if (!drm_probe_ddc(&smi_connector->adapter))
{
dbg_msg("detect CRT DO NOT connected. \n");
sdev->m_connector =sdev->m_connector&(~USE_VGA);
return connector_status_disconnected;
}
else
{
dbg_msg("detect CRT connected(GPIO 6, 7)\n");
sdev->m_connector = sdev->m_connector|USE_VGA;
return connector_status_connected;
}
}
else if (connector->connector_type == DRM_MODE_CONNECTOR_HDMIA)