-
Notifications
You must be signed in to change notification settings - Fork 10
/
disp_lcd.c
executable file
·2005 lines (1685 loc) · 52.9 KB
/
disp_lcd.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
#include "disp_lcd.h"
#include "../dev_disp.h"
#include <linux/backlight.h>
struct disp_lcd_private_data
{
disp_lcd_flow open_flow;
disp_lcd_flow close_flow;
disp_panel_para panel_info;
panel_extend_para panel_extend_info;
disp_lcd_cfg lcd_cfg;
disp_lcd_panel_fun lcd_panel_fun;
bool enabling;
bool disabling;
u32 irq_no;
u32 irq_no_dsi;
u32 irq_no_edp;
u32 enabled;
u32 power_enabled;
u32 bl_need_enabled;
struct {
uintptr_t dev;
u32 channel;
u32 polarity;
u32 period_ns;
u32 duty_ns;
u32 enabled;
}pwm_info;
struct backlight_device *backlight;
struct clk *clk;
struct clk *lvds_clk;
struct clk *dsi_clk0;
struct clk *dsi_clk1;
struct clk *edp_clk;
struct clk *clk_parent;
};
#if defined(__LINUX_PLAT__)
static spinlock_t lcd_data_lock;
#else
static int lcd_data_lock;
#endif
static struct disp_device *lcds = NULL;
static struct disp_lcd_private_data *lcd_private;
s32 disp_lcd_set_bright(struct disp_device *lcd, u32 bright);
s32 disp_lcd_get_bright(struct disp_device *lcd);
struct disp_device* disp_get_lcd(u32 disp)
{
u32 num_screens;
num_screens = bsp_disp_feat_get_num_screens();
if (disp >= num_screens || !bsp_disp_feat_is_supported_output_types(disp, DISP_OUTPUT_TYPE_LCD)) {
DE_INF("disp %d not support lcd output\n", disp);
return NULL;
}
return &lcds[disp];
}
static struct disp_lcd_private_data *disp_lcd_get_priv(struct disp_device *lcd)
{
if (NULL == lcd) {
DE_WRN("param is NULL!\n");
return NULL;
}
if (!bsp_disp_feat_is_supported_output_types(lcd->disp, DISP_OUTPUT_TYPE_LCD)) {
DE_INF("disp %d not support lcd output\n", lcd->disp);
return NULL;
}
return &lcd_private[lcd->disp];
}
static s32 disp_lcd_is_used(struct disp_device* lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
s32 ret = 0;
if ((NULL == lcd) || (NULL == lcdp)) {
ret = 0;
} else {
if (bsp_disp_feat_is_supported_output_types(lcd->disp, DISP_OUTPUT_TYPE_LCD))
ret = (s32)lcdp->lcd_cfg.lcd_used;
}
return ret;
}
static s32 lcd_parse_panel_para(u32 disp, disp_panel_para * info)
{
s32 ret = 0;
char primary_key[25];
s32 value = 0;
sprintf(primary_key, "lcd%d", disp);
memset(info, 0, sizeof(disp_panel_para));
ret = disp_sys_script_get_item(primary_key, "lcd_x", &value, 1);
if (ret == 1)
{
info->lcd_x = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_y", &value, 1);
if (ret == 1)
{
info->lcd_y = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_width", &value, 1);
if (ret == 1)
{
info->lcd_width = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_height", &value, 1);
if (ret == 1)
{
info->lcd_height = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dclk_freq", &value, 1);
if (ret == 1)
{
info->lcd_dclk_freq = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_pwm_used", &value, 1);
if (ret == 1)
{
info->lcd_pwm_used = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_pwm_ch", &value, 1);
if (ret == 1)
{
info->lcd_pwm_ch = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_pwm_freq", &value, 1);
if (ret == 1)
{
info->lcd_pwm_freq = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_pwm_pol", &value, 1);
if (ret == 1)
{
info->lcd_pwm_pol = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_if", &value, 1);
if (ret == 1)
{
info->lcd_if = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hbp", &value, 1);
if (ret == 1)
{
info->lcd_hbp = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_ht", &value, 1);
if (ret == 1)
{
info->lcd_ht = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_vbp", &value, 1);
if (ret == 1)
{
info->lcd_vbp = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_vt", &value, 1);
if (ret == 1)
{
info->lcd_vt = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_if", &value, 1);
if (ret == 1)
{
info->lcd_hv_if = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_vspw", &value, 1);
if (ret == 1)
{
info->lcd_vspw = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hspw", &value, 1);
if (ret == 1)
{
info->lcd_hspw = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_lvds_if", &value, 1);
if (ret == 1)
{
info->lcd_lvds_if = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_lvds_mode", &value, 1);
if (ret == 1)
{
info->lcd_lvds_mode = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_lvds_colordepth", &value, 1);
if (ret == 1)
{
info->lcd_lvds_colordepth= value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_lvds_io_polarity", &value, 1);
if (ret == 1)
{
info->lcd_lvds_io_polarity = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_cpu_if", &value, 1);
if (ret == 1)
{
info->lcd_cpu_if = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_cpu_te", &value, 1);
if (ret == 1)
{
info->lcd_cpu_te = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_frm", &value, 1);
if (ret == 1)
{
info->lcd_frm = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dsi_if", &value, 1);
if (ret == 1)
{
info->lcd_dsi_if = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dsi_lane", &value, 1);
if (ret == 1)
{
info->lcd_dsi_lane = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dsi_format", &value, 1);
if (ret == 1)
{
info->lcd_dsi_format = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dsi_eotp", &value, 1);
if (ret == 1)
{
info->lcd_dsi_eotp = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_dsi_te", &value, 1);
if (ret == 1)
{
info->lcd_dsi_te = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_edp_rate", &value, 1);
if (ret == 1)
{
info->lcd_edp_rate = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_edp_lane", &value, 1);
if (ret == 1)
{
info->lcd_edp_lane= value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_edp_colordepth", &value, 1);
if (ret == 1)
{
info->lcd_edp_colordepth = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_edp_fps", &value, 1);
if (ret == 1)
{
info->lcd_edp_fps = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_clk_phase", &value, 1);
if (ret == 1)
{
info->lcd_hv_clk_phase = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_sync_polarity", &value, 1);
if (ret == 1)
{
info->lcd_hv_sync_polarity = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_srgb_seq", &value, 1);
if (ret == 1)
{
info->lcd_hv_srgb_seq = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_rb_swap", &value, 1);
if (ret == 1)
{
info->lcd_rb_swap = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_syuv_seq", &value, 1);
if (ret == 1)
{
info->lcd_hv_syuv_seq = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_hv_syuv_fdly", &value, 1);
if (ret == 1)
{
info->lcd_hv_syuv_fdly = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_gamma_en", &value, 1);
if (ret == 1)
{
info->lcd_gamma_en = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_cmap_en", &value, 1);
if (ret == 1)
{
info->lcd_cmap_en = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_xtal_freq", &value, 1);
if (ret == 1)
{
info->lcd_xtal_freq = value;
}
ret = disp_sys_script_get_item(primary_key, "lcd_size", (int*)info->lcd_size, 2);
ret = disp_sys_script_get_item(primary_key, "lcd_model_name", (int*)info->lcd_model_name, 2);
return 0;
}
#if 0
static void lcd_panel_parameter_check(u32 disp, struct disp_device* lcd)
{
disp_panel_para* info;
u32 cycle_num = 1;
u32 Lcd_Panel_Err_Flag = 0;
u32 Lcd_Panel_Wrn_Flag = 0;
u32 Disp_Driver_Bug_Flag = 0;
u32 lcd_fclk_frq;
u32 lcd_clk_div;
s32 ret = 0;
char primary_key[20];
s32 value = 0;
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return ;
}
if (!disp_al_query_lcd_mod(lcd->disp))
return;
sprintf(primary_key, "lcd%d", lcd->disp);
ret = disp_sys_script_get_item(primary_key, "lcd_used", &value, 1);
if (ret != 0 ) {
DE_WRN("get lcd%dpara lcd_used fail\n", lcd->disp);
return;
} else {
if (value != 1) {
DE_WRN("lcd%dpara is not used\n", lcd->disp);
return;
}
}
info = &(lcdp->panel_info);
if (NULL == info) {
DE_WRN("NULL hdl!\n");
return;
}
if (info->lcd_if == 0 && info->lcd_hv_if == 8)
cycle_num = 3;
else if (info->lcd_if == 0 && info->lcd_hv_if == 10)
cycle_num = 3;
else if (info->lcd_if == 0 && info->lcd_hv_if == 11)
cycle_num = 4;
else if (info->lcd_if == 0 && info->lcd_hv_if == 12)
cycle_num = 4;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 2)
cycle_num = 3;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 4)
cycle_num = 2;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 6)
cycle_num = 2;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 10)
cycle_num = 2;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 12)
cycle_num = 3;
else if (info->lcd_if == 1 && info->lcd_cpu_if == 14)
cycle_num = 2;
else
cycle_num = 1;
if (info->lcd_hbp > info->lcd_hspw)
{
;
}
else
{
Lcd_Panel_Err_Flag |= BIT0;
}
if (info->lcd_vbp > info->lcd_vspw)
{
;
}
else
{
Lcd_Panel_Err_Flag |= BIT1;
}
if (info->lcd_ht >= (info->lcd_hbp+info->lcd_x*cycle_num+4))
{
;
}
else
{
Lcd_Panel_Err_Flag |= BIT2;
}
if ((info->lcd_vt) >= (info->lcd_vbp+info->lcd_y + 2))
{
;
}
else
{
Lcd_Panel_Err_Flag |= BIT3;
}
lcd_clk_div = disp_al_lcd_get_clk_div(disp);
if (lcd_clk_div >= 6)
{
;
}
else if (lcd_clk_div >=2)
{
if ((info->lcd_hv_clk_phase == 1) && (info->lcd_hv_clk_phase == 3))
{
Lcd_Panel_Err_Flag |= BIT10;
}
}
else
{
Disp_Driver_Bug_Flag |= 1;
}
if ((info->lcd_if == 1 && info->lcd_cpu_if == 0) || (info->lcd_if == 1 && info->lcd_cpu_if == 10)
|| (info->lcd_if == 1 && info->lcd_cpu_if == 12) ||(info->lcd_if == 3 && info->lcd_lvds_colordepth == 1))
{
if (info->lcd_frm != 1)
Lcd_Panel_Wrn_Flag |= BIT0;
}
else if (info->lcd_if == 1 && ((info->lcd_cpu_if == 2) || (info->lcd_cpu_if == 4) || (info->lcd_cpu_if == 6)
|| (info->lcd_cpu_if == 8) || (info->lcd_cpu_if == 14)))
{
if (info->lcd_frm != 2)
Lcd_Panel_Wrn_Flag |= BIT1;
}
lcd_fclk_frq = (info->lcd_dclk_freq * 1000 * 1000) / ((info->lcd_vt) * info->lcd_ht);
if (lcd_fclk_frq < 50 || lcd_fclk_frq > 70)
{
Lcd_Panel_Wrn_Flag |= BIT2;
}
if (Lcd_Panel_Err_Flag != 0 || Lcd_Panel_Wrn_Flag != 0)
{
if (Lcd_Panel_Err_Flag != 0)
{
u32 i;
for (i = 0; i < 200; i++)
{
//OSAL_PRINTF("*** Lcd in danger...\n");
}
}
OSAL_PRINTF("*****************************************************************\n");
OSAL_PRINTF("***\n");
OSAL_PRINTF("*** LCD Panel Parameter Check\n");
OSAL_PRINTF("***\n");
OSAL_PRINTF("*** by guozhenjie\n");
OSAL_PRINTF("***\n");
OSAL_PRINTF("*****************************************************************\n");
OSAL_PRINTF("*** \n");
OSAL_PRINTF("*** Interface:");
if (info->lcd_if == 0 && info->lcd_hv_if == 0)
{OSAL_PRINTF("*** Parallel HV Panel\n");}
else if (info->lcd_if == 0 && info->lcd_hv_if == 8)
{OSAL_PRINTF("*** Serial HV Panel\n");}
else if (info->lcd_if == 0 && info->lcd_hv_if == 10)
{OSAL_PRINTF("*** Dummy RGB HV Panel\n");}
else if (info->lcd_if == 0 && info->lcd_hv_if == 11)
{OSAL_PRINTF("*** RGB Dummy HV Panel\n");}
else if (info->lcd_if == 0 && info->lcd_hv_if == 12)
{OSAL_PRINTF("*** Serial YUV Panel\n");}
else if (info->lcd_if == 3 && info->lcd_lvds_colordepth== 0)
{OSAL_PRINTF("*** 24Bit LVDS Panel\n");}
else if (info->lcd_if == 3 && info->lcd_lvds_colordepth== 1)
{OSAL_PRINTF("*** 18Bit LVDS Panel\n");}
else if ((info->lcd_if == 1) && (info->lcd_cpu_if == 0 || info->lcd_cpu_if == 10 || info->lcd_cpu_if == 12))
{OSAL_PRINTF("*** 18Bit CPU Panel\n");}
else if ((info->lcd_if == 1) && (info->lcd_cpu_if == 2 || info->lcd_cpu_if == 4 ||
info->lcd_cpu_if == 6 || info->lcd_cpu_if == 8 || info->lcd_cpu_if == 14))
{OSAL_PRINTF("*** 16Bit CPU Panel\n");}
else
{
OSAL_PRINTF("\n");
OSAL_PRINTF("*** lcd_if: %d\n",info->lcd_if);
OSAL_PRINTF("*** lcd_hv_if: %d\n",info->lcd_hv_if);
OSAL_PRINTF("*** lcd_cpu_if: %d\n",info->lcd_cpu_if);
}
if (info->lcd_frm == 0)
{OSAL_PRINTF("*** Lcd Frm Disable\n");}
else if (info->lcd_frm == 1)
{OSAL_PRINTF("*** Lcd Frm to RGB666\n");}
else if (info->lcd_frm == 2)
{OSAL_PRINTF("*** Lcd Frm to RGB565\n");}
OSAL_PRINTF("*** \n");
OSAL_PRINTF("*** Timing:\n");
OSAL_PRINTF("*** lcd_x: %d\n", info->lcd_x);
OSAL_PRINTF("*** lcd_y: %d\n", info->lcd_y);
OSAL_PRINTF("*** lcd_ht: %d\n", info->lcd_ht);
OSAL_PRINTF("*** lcd_hbp: %d\n", info->lcd_hbp);
OSAL_PRINTF("*** lcd_vt: %d\n", info->lcd_vt);
OSAL_PRINTF("*** lcd_vbp: %d\n", info->lcd_vbp);
OSAL_PRINTF("*** lcd_hspw: %d\n", info->lcd_hspw);
OSAL_PRINTF("*** lcd_vspw: %d\n", info->lcd_vspw);
OSAL_PRINTF("*** lcd_frame_frq: %dHz\n", lcd_fclk_frq);
OSAL_PRINTF("*** \n");
if (Lcd_Panel_Err_Flag & BIT0)
{OSAL_PRINTF("*** Err01: Violate \"lcd_hbp > lcd_hspw\"\n");}
if (Lcd_Panel_Err_Flag & BIT1)
{OSAL_PRINTF("*** Err02: Violate \"lcd_vbp > lcd_vspw\"\n");}
if (Lcd_Panel_Err_Flag & BIT2)
{OSAL_PRINTF("*** Err03: Violate \"lcd_ht >= (lcd_hbp+lcd_x*%d+4)\"\n", cycle_num);}
if (Lcd_Panel_Err_Flag & BIT3)
{OSAL_PRINTF("*** Err04: Violate \"(lcd_vt) >= (lcd_vbp+lcd_y+2)\"\n");}
if (Lcd_Panel_Err_Flag & BIT10)
{OSAL_PRINTF("*** Err10: Violate \"lcd_hv_clk_phase\",use \"0\" or \"2\"");}
if (Lcd_Panel_Wrn_Flag & BIT0)
{OSAL_PRINTF("*** WRN01: Recommend \"lcd_frm = 1\"\n");}
if (Lcd_Panel_Wrn_Flag & BIT1)
{OSAL_PRINTF("*** WRN02: Recommend \"lcd_frm = 2\"\n");}
if (Lcd_Panel_Wrn_Flag & BIT2)
{OSAL_PRINTF("*** WRN03: Recommend \"lcd_dclk_frq = %d\"\n",
((info->lcd_vt) * info->lcd_ht) * 60 / (1000 * 1000));}
OSAL_PRINTF("*** \n");
if (Lcd_Panel_Err_Flag != 0)
{
u32 image_base_addr;
u32 reg_value = 0;
image_base_addr = DE_Get_Reg_Base(disp);
sys_put_wvalue(image_base_addr+0x804, 0xffff00ff);//set background color
reg_value = sys_get_wvalue(image_base_addr + 0x800);
sys_put_wvalue(image_base_addr+0x800, reg_value & 0xfffff0ff);//close all layer
mdelay(2000);
sys_put_wvalue(image_base_addr + 0x804, 0x00000000);//set background color
sys_put_wvalue(image_base_addr + 0x800, reg_value);//open layer
OSAL_PRINTF("*** Try new parameters,you can make it pass!\n");
}
OSAL_PRINTF("*** LCD Panel Parameter Check End\n");
OSAL_PRINTF("*****************************************************************\n");
}
}
#endif
static void lcd_get_sys_config(u32 disp, disp_lcd_cfg *lcd_cfg)
{
disp_gpio_set_t *gpio_info;
int value = 1;
char primary_key[20], sub_name[25];
int i = 0;
int ret;
sprintf(primary_key, "lcd%d", disp);
//lcd_used
ret = disp_sys_script_get_item(primary_key, "lcd_used", &value, 1);
if (ret == 1)
{
lcd_cfg->lcd_used = value;
}
if (lcd_cfg->lcd_used == 0) //no need to get lcd config if lcd_used eq 0
return ;
//lcd_bl_en
lcd_cfg->lcd_bl_en_used = 0;
gpio_info = &(lcd_cfg->lcd_bl_en);
ret = disp_sys_script_get_item(primary_key,"lcd_bl_en", (int *)gpio_info, 3);
if (ret == 3)
{
lcd_cfg->lcd_bl_en_used = 1;
}
sprintf(sub_name, "lcd_bl_en_power");
ret = disp_sys_script_get_item(primary_key, sub_name, (int *)lcd_cfg->lcd_bl_en_power, 2);
//lcd fix power
for (i=0; i<LCD_POWER_NUM; i++)
{
if (i==0)
sprintf(sub_name, "lcd_fix_power");
else
sprintf(sub_name, "lcd_fix_power%d", i);
lcd_cfg->lcd_power_used[i] = 0;
ret = disp_sys_script_get_item(primary_key,sub_name, (int *)(lcd_cfg->lcd_fix_power[i]), 2);
if (ret == 2) {
/* str */
lcd_cfg->lcd_fix_power_used[i] = 1;
}
}
//lcd_power
for (i=0; i<LCD_POWER_NUM; i++)
{
if (i==0)
sprintf(sub_name, "lcd_power");
else
sprintf(sub_name, "lcd_power%d", i);
lcd_cfg->lcd_power_used[i] = 0;
ret = disp_sys_script_get_item(primary_key,sub_name, (int *)(lcd_cfg->lcd_power[i]), 2);
if (ret == 2) {
/* str */
lcd_cfg->lcd_power_used[i] = 1;
}
}
//lcd_gpio
for (i=0; i<4; i++)
{
sprintf(sub_name, "lcd_gpio_%d", i);
gpio_info = &(lcd_cfg->lcd_gpio[i]);
ret = disp_sys_script_get_item(primary_key,sub_name, (int *)gpio_info, 3);
if (ret == 3)
{
lcd_cfg->lcd_gpio_used[i]= 1;
}
}
//lcd_gpio_scl,lcd_gpio_sda
gpio_info = &(lcd_cfg->lcd_gpio[LCD_GPIO_SCL]);
ret = disp_sys_script_get_item(primary_key,"lcd_gpio_scl", (int *)gpio_info, 3);
if (ret == 3)
{
lcd_cfg->lcd_gpio_used[LCD_GPIO_SCL]= 1;
}
gpio_info = &(lcd_cfg->lcd_gpio[LCD_GPIO_SDA]);
ret = disp_sys_script_get_item(primary_key,"lcd_gpio_sda", (int *)gpio_info, 3);
if (ret == 3)
{
lcd_cfg->lcd_gpio_used[LCD_GPIO_SDA]= 1;
}
for (i = 0; i < LCD_GPIO_REGU_NUM; i++)
{
sprintf(sub_name, "lcd_gpio_power%d", i);
ret = disp_sys_script_get_item(primary_key, sub_name, (int *)lcd_cfg->lcd_gpio_power[i], 2);
}
for (i=0; i<LCD_GPIO_REGU_NUM; i++) {
if (0==i)
sprintf(sub_name, "lcd_pin_power");
else
sprintf(sub_name, "lcd_pin_power%d", i);
ret = disp_sys_script_get_item(primary_key, sub_name, (int *)lcd_cfg->lcd_pin_power[i], 2);
}
//backlight adjust
for (i = 0; i < 101; i++) {
sprintf(sub_name, "lcd_bl_%d_percent", i);
lcd_cfg->backlight_curve_adjust[i] = 0;
if (i == 100)
lcd_cfg->backlight_curve_adjust[i] = 255;
ret = disp_sys_script_get_item(primary_key, sub_name, &value, 1);
if (ret == 1) {
value = (value > 100)? 100:value;
value = value * 255 / 100;
lcd_cfg->backlight_curve_adjust[i] = value;
}
}
sprintf(sub_name, "lcd_backlight");
ret = disp_sys_script_get_item(primary_key, sub_name, &value, 1);
if (ret == 1) {
value = (value > 256)? 256:value;
lcd_cfg->backlight_bright = value;
} else {
lcd_cfg->backlight_bright = 197;
}
}
#include <linux/clk-provider.h>
static s32 lcd_clk_init(struct disp_device* lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
DE_INF("lcd %d clk init\n", lcd->disp);
lcdp->clk_parent = clk_get_parent(lcdp->clk);
return DIS_SUCCESS;
}
static s32 lcd_clk_exit(struct disp_device* lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
if (lcdp->clk_parent)
clk_put(lcdp->clk_parent);
return DIS_SUCCESS;
}
static s32 lcd_clk_config(struct disp_device* lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
struct lcd_clk_info clk_info;
unsigned long pll_rate, lcd_rate, dclk_rate, dsi_rate = 0;//hz
unsigned long pll_rate_set, lcd_rate_set, dclk_rate_set, dsi_rate_set = 0;//hz
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
memset(&clk_info, 0, sizeof(struct lcd_clk_info));
disp_al_lcd_get_clk_info(lcd->disp, &clk_info, &lcdp->panel_info);
dclk_rate = lcdp->panel_info.lcd_dclk_freq * 1000000;//Mhz -> hz
if (LCD_IF_DSI == lcdp->panel_info.lcd_if) {
lcd_rate = dclk_rate * clk_info.dsi_div;
pll_rate = lcd_rate * clk_info.lcd_div;
} else {
lcd_rate = dclk_rate * clk_info.tcon_div;
pll_rate = lcd_rate * clk_info.lcd_div;
}
dsi_rate = pll_rate / clk_info.dsi_div;
if (lcdp->clk_parent) {
clk_set_rate(lcdp->clk_parent, pll_rate);
pll_rate_set = clk_get_rate(lcdp->clk_parent);
}
if (clk_info.lcd_div)
lcd_rate_set = pll_rate_set / clk_info.lcd_div;
clk_set_rate(lcdp->clk, lcd_rate_set);
lcd_rate_set = clk_get_rate(lcdp->clk);
if (LCD_IF_DSI == lcdp->panel_info.lcd_if) {
dsi_rate_set = pll_rate_set / clk_info.dsi_div;
dsi_rate_set = (0 == clk_info.dsi_rate)? dsi_rate_set:clk_info.dsi_rate;
clk_set_rate(lcdp->dsi_clk0, dsi_rate_set);
//disp_sys_clk_set_rate(lcdp->dsi_clk1, dsi_rate_set);//FIXME, dsi clk0 = dsi clk1(rate)
}
dclk_rate_set = lcd_rate_set / clk_info.tcon_div;
if ((pll_rate_set != pll_rate) || (lcd_rate_set != lcd_rate)
|| (dclk_rate_set != dclk_rate)) {
DE_WRN("disp %d, clk: pll(%ld),clk(%ld),dclk(%ld) dsi_rate(%ld)\n clk real:pll(%ld),clk(%ld),dclk(%ld) dsi_rate(%ld)\n",
lcd->disp, pll_rate, lcd_rate, dclk_rate, dsi_rate, pll_rate_set, lcd_rate_set, dclk_rate_set, dsi_rate_set);
}
return 0;
}
static s32 lcd_clk_enable(struct disp_device* lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
int ret;
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
lcd_clk_config(lcd);
ret = clk_prepare_enable(lcdp->clk);
if (0 != ret) {
DE_WRN("fail enable lcd's clock!\n");
goto exit;
}
if (LCD_IF_LVDS == lcdp->panel_info.lcd_if) {
ret = clk_prepare_enable(lcdp->lvds_clk);
if (0 != ret) {
DE_WRN("fail enable lvds's clock!\n");
goto exit;
}
} else if (LCD_IF_DSI == lcdp->panel_info.lcd_if) {
ret = clk_prepare_enable(lcdp->dsi_clk0);
if (0 != ret) {
DE_WRN("fail enable dsi's clock0!\n");
goto exit;
}
ret = clk_prepare_enable(lcdp->dsi_clk1);
if (0 != ret) {
DE_WRN("fail enable dsi's clock1!\n");
goto exit;
}
} else if (LCD_IF_EDP == lcdp->panel_info.lcd_if) {
ret = clk_prepare_enable(lcdp->edp_clk);
if (0 != ret) {
DE_WRN("fail enable edp's clock!\n");
goto exit;
}
}
exit:
return ret;
}
static s32 lcd_clk_disable(struct disp_device* lcd)
{ struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
if (LCD_IF_LVDS == lcdp->panel_info.lcd_if) {
clk_disable(lcdp->lvds_clk);
} else if (LCD_IF_DSI == lcdp->panel_info.lcd_if) {
clk_disable(lcdp->dsi_clk1);
clk_disable(lcdp->dsi_clk0);
} else if (LCD_IF_EDP == lcdp->panel_info.lcd_if) {
clk_disable(lcdp->edp_clk);
}
clk_disable(lcdp->clk);
return DIS_SUCCESS;
}
static s32 disp_lcd_tcon_enable(struct disp_device *lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
return disp_al_lcd_enable(lcd->disp, &lcdp->panel_info);
}
static s32 disp_lcd_tcon_disable(struct disp_device *lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return -1;
}
return disp_al_lcd_disable(lcd->disp, &lcdp->panel_info);
}
static s32 disp_lcd_pin_cfg(struct disp_device *lcd, u32 bon)
{
int i;
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
char dev_name[25];
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return DIS_FAIL;
}
DE_INF("lcd %d pin config, state %s, %d\n", lcd->disp, (bon)? "on":"off", bon);
//io-pad
if (bon == 1) {
for (i=0; i<LCD_GPIO_REGU_NUM; i++) {
if (!((!strcmp(lcdp->lcd_cfg.lcd_pin_power[i], "")) || (!strcmp(lcdp->lcd_cfg.lcd_pin_power[i], "none"))))
disp_sys_power_enable(lcdp->lcd_cfg.lcd_pin_power[i]);
}
}
sprintf(dev_name, "lcd%d", lcd->disp);
disp_sys_pin_set_state(dev_name, (1==bon)? DISP_PIN_STATE_ACTIVE:DISP_PIN_STATE_SLEEP);
disp_al_lcd_io_cfg(lcd->disp, bon, &lcdp->panel_info);
if (bon == 0) {
for (i=LCD_GPIO_REGU_NUM-1; i>=0; i--) {
if (!((!strcmp(lcdp->lcd_cfg.lcd_pin_power[i], "")) || (!strcmp(lcdp->lcd_cfg.lcd_pin_power[i], "none"))))
disp_sys_power_disable(lcdp->lcd_cfg.lcd_pin_power[i]);
}
}
return DIS_SUCCESS;
}
static s32 disp_lcd_pwm_enable(struct disp_device *lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return DIS_FAIL;
}
if (disp_lcd_is_used(lcd) && lcdp->pwm_info.dev) {
disp_sys_pwm_set_polarity(lcdp->pwm_info.dev, lcdp->pwm_info.polarity);
return disp_sys_pwm_enable(lcdp->pwm_info.dev);
}
DE_WRN("pwm device hdl is NULL\n");
return DIS_FAIL;
}
static s32 disp_lcd_pwm_disable(struct disp_device *lcd)
{
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return DIS_FAIL;
}
if (disp_lcd_is_used(lcd) && lcdp->pwm_info.dev) {
return disp_sys_pwm_disable(lcdp->pwm_info.dev);
}
DE_WRN("pwm device hdl is NULL\n");
return DIS_FAIL;
}
static s32 disp_lcd_backlight_enable(struct disp_device *lcd)
{
disp_gpio_set_t gpio_info[1];
int hdl;
struct disp_lcd_private_data *lcdp = disp_lcd_get_priv(lcd);
unsigned long flags;
if ((NULL == lcd) || (NULL == lcdp)) {
DE_WRN("NULL hdl!\n");
return DIS_FAIL;
}
spin_lock_irqsave(&lcd_data_lock, flags);
if (lcdp->backlight) {
lcdp->backlight->props.power = FB_BLANK_UNBLANK;
}
lcdp->bl_need_enabled = 1;
spin_unlock_irqrestore(&lcd_data_lock, flags);
if (disp_lcd_is_used(lcd)) {
unsigned bl;