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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
|
/* linux/drivers/video/decon_display/decon_mipi_dsi.c
*
* Samsung SoC MIPI-DSIM driver.
*
* Copyright (c) 2013 Samsung Electronics
*
* Haowei Li <haowei.li@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/clk.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/fb.h>
#include <linux/ctype.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/memory.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include <linux/regulator/consumer.h>
#include <linux/notifier.h>
#include <linux/pm_runtime.h>
#include <linux/lcd.h>
#include <linux/gpio.h>
#include <video/mipi_display.h>
#include <plat/cpu.h>
#include <mach/map.h>
#include <mach/exynos5-mipiphy.h>
#include "decon_display_driver.h"
#include "decon_mipi_dsi_lowlevel.h"
#include "decon_mipi_dsi.h"
#include "regs-mipidsim.h"
#include "decon_dt.h"
#include "decon_pm.h"
#if defined(CONFIG_SOC_EXYNOS5430) || defined(CONFIG_SOC_EXYNOS5433)
#include "decon_fb.h"
#else
#include <mach/regs-pmu.h>
#include "fimd_fb.h"
#endif
static DEFINE_MUTEX(dsim_rd_wr_mutex);
static DECLARE_COMPLETION(dsim_ph_wr_comp);
static DECLARE_COMPLETION(dsim_wr_comp);
static DECLARE_COMPLETION(dsim_rd_comp);
#define MIPI_WR_TIMEOUT msecs_to_jiffies(50)
#define MIPI_RD_TIMEOUT msecs_to_jiffies(50)
static unsigned int dpll_table[15] = {
100, 120, 170, 220, 270,
320, 390, 450, 510, 560,
640, 690, 770, 870, 950 };
unsigned int dphy_timing[][10] = {
/* bps, clk_prepare, clk_zero, clk_post, clk_trail, hs_prepare, hs_zero, hs_trail, lpx */
{1500, 13, 65, 17, 13, 16, 24, 16, 11, 18},
{1490, 13, 65, 17, 13, 16, 24, 16, 11, 18},
{1480, 13, 64, 17, 13, 16, 24, 16, 11, 18},
{1470, 13, 64, 17, 13, 16, 24, 16, 11, 18},
{1460, 13, 63, 17, 13, 16, 24, 16, 10, 18},
{1450, 13, 63, 17, 13, 16, 23, 16, 10, 18},
{1440, 13, 63, 17, 13, 15, 23, 16, 10, 18},
{1430, 12, 62, 17, 13, 15, 23, 16, 10, 17},
{1420, 12, 62, 17, 13, 15, 23, 16, 10, 17},
{1410, 12, 61, 16, 13, 15, 23, 16, 10, 17},
{1400, 12, 61, 16, 13, 15, 23, 16, 10, 17},
{1390, 12, 60, 16, 12, 15, 22, 15, 10, 17},
{1380, 12, 60, 16, 12, 15, 22, 15, 10, 17},
{1370, 12, 59, 16, 12, 15, 22, 15, 10, 17},
{1360, 12, 59, 16, 12, 15, 22, 15, 10, 17},
{1350, 12, 59, 16, 12, 14, 22, 15, 10, 16},
{1340, 12, 58, 16, 12, 14, 21, 15, 10, 16},
{1330, 11, 58, 16, 12, 14, 21, 15, 9, 16},
{1320, 11, 57, 16, 12, 14, 21, 15, 9, 16},
{1310, 11, 57, 16, 12, 14, 21, 15, 9, 16},
{1300, 11, 56, 16, 12, 14, 21, 15, 9, 16},
{1290, 11, 56, 16, 12, 14, 21, 15, 9, 16},
{1280, 11, 56, 15, 11, 14, 20, 14, 9, 16},
{1270, 11, 55, 15, 11, 14, 20, 14, 9, 15},
{1260, 11, 55, 15, 11, 13, 20, 14, 9, 15},
{1250, 11, 54, 15, 11, 13, 20, 14, 9, 15},
{1240, 11, 54, 15, 11, 13, 20, 14, 9, 15},
{1230, 11, 53, 15, 11, 13, 19, 14, 9, 15},
{1220, 10, 53, 15, 11, 13, 19, 14, 9, 15},
{1210, 10, 52, 15, 11, 13, 19, 14, 9, 15},
{1200, 10, 52, 15, 11, 13, 19, 14, 9, 15},
{1190, 10, 52, 15, 11, 13, 19, 14, 8, 14},
{1180, 10, 51, 15, 11, 13, 19, 13, 8, 14},
{1170, 10, 51, 15, 10, 12, 18, 13, 8, 14},
{1160, 10, 50, 15, 10, 12, 18, 13, 8, 14},
{1150, 10, 50, 15, 10, 12, 18, 13, 8, 14},
{1140, 10, 49, 14, 10, 12, 18, 13, 8, 14},
{1130, 10, 49, 14, 10, 12, 18, 13, 8, 14},
{1120, 10, 49, 14, 10, 12, 17, 13, 8, 14},
{1110, 9, 48, 14, 10, 12, 17, 13, 8, 13},
{1100, 9, 48, 14, 10, 12, 17, 13, 8, 13},
{1090, 9, 47, 14, 10, 12, 17, 13, 8, 13},
{1080, 9, 47, 14, 10, 11, 17, 13, 8, 13},
{1070, 9, 46, 14, 10, 11, 17, 12, 8, 13},
{1060, 9, 46, 14, 10, 11, 16, 12, 7, 13},
{1050, 9, 45, 14, 9, 11, 16, 12, 7, 13},
{1040, 9, 45, 14, 9, 11, 16, 12, 7, 13},
{1030, 9, 45, 14, 9, 11, 16, 12, 7, 12},
{1020, 9, 44, 14, 9, 11, 16, 12, 7, 12},
{1010, 8, 44, 13, 9, 11, 15, 12, 7, 12},
{1000, 8, 43, 13, 9, 11, 15, 12, 7, 12},
{990, 8, 43, 13, 9, 10, 15, 12, 7, 12},
{980, 8, 42, 13, 9, 10, 15, 12, 7, 12},
{970, 8, 42, 13, 9, 10, 15, 12, 7, 12},
{960, 8, 42, 13, 9, 10, 15, 11, 7, 12},
{950, 8, 41, 13, 9, 10, 14, 11, 7, 11},
{940, 8, 41, 13, 8, 10, 14, 11, 7, 11},
{930, 8, 40, 13, 8, 10, 14, 11, 6, 11},
{920, 8, 40, 13, 8, 10, 14, 11, 6, 11},
{910, 8, 39, 13, 8, 9, 14, 11, 6, 11},
{900, 7, 39, 13, 8, 9, 13, 11, 6, 11},
{890, 7, 38, 13, 8, 9, 13, 11, 6, 11},
{880, 7, 38, 12, 8, 9, 13, 11, 6, 11},
{870, 7, 38, 12, 8, 9, 13, 11, 6, 10},
{860, 7, 37, 12, 8, 9, 13, 11, 6, 10},
{850, 7, 37, 12, 8, 9, 13, 10, 6, 10},
{840, 7, 36, 12, 8, 9, 12, 10, 6, 10},
{830, 7, 36, 12, 8, 9, 12, 10, 6, 10},
{820, 7, 35, 12, 7, 8, 12, 10, 6, 10},
{810, 7, 35, 12, 7, 8, 12, 10, 6, 10},
{800, 7, 35, 12, 7, 8, 12, 10, 6, 10},
{790, 6, 34, 12, 7, 8, 11, 10, 5, 9},
{780, 6, 34, 12, 7, 8, 11, 10, 5, 9},
{770, 6, 33, 12, 7, 8, 11, 10, 5, 9},
{760, 6, 33, 12, 7, 8, 11, 10, 5, 9},
{750, 6, 32, 12, 7, 8, 11, 9, 5, 9},
{740, 6, 32, 11, 7, 8, 11, 9, 5, 9},
{730, 6, 31, 11, 7, 7, 10, 9, 5, 9},
{720, 6, 31, 11, 7, 7, 10, 9, 5, 9},
{710, 6, 31, 11, 6, 7, 10, 9, 5, 8},
{700, 6, 30, 11, 6, 7, 10, 9, 5, 8},
{690, 5, 30, 11, 6, 7, 10, 9, 5, 8},
{680, 5, 29, 11, 6, 7, 9, 9, 5, 8},
{670, 5, 29, 11, 6, 7, 9, 9, 5, 8},
{660, 5, 28, 11, 6, 7, 9, 9, 4, 8},
{650, 5, 28, 11, 6, 7, 9, 9, 4, 8},
{640, 5, 28, 11, 6, 6, 9, 8, 4, 8},
{630, 5, 27, 11, 6, 6, 9, 8, 4, 7},
{620, 5, 27, 11, 6, 6, 8, 8, 4, 7},
{610, 5, 26, 10, 6, 6, 8, 8, 4, 7},
{600, 5, 26, 10, 6, 6, 8, 8, 4, 7},
{590, 5, 25, 10, 5, 6, 8, 8, 4, 7},
{580, 4, 25, 10, 5, 6, 8, 8, 4, 7},
{570, 4, 24, 10, 5, 6, 7, 8, 4, 7},
{560, 4, 24, 10, 5, 6, 7, 8, 4, 7},
{550, 4, 24, 10, 5, 5, 7, 8, 4, 6},
{540, 4, 23, 10, 5, 5, 7, 8, 4, 6},
{530, 4, 23, 10, 5, 5, 7, 7, 3, 6},
{520, 4, 22, 10, 5, 5, 7, 7, 3, 6},
{510, 4, 22, 10, 5, 5, 6, 7, 3, 6},
{500, 4, 21, 10, 5, 5, 6, 7, 3, 6},
{490, 4, 21, 10, 5, 5, 6, 7, 3, 6},
{480, 4, 21, 9, 4, 5, 6, 7, 3, 6},
};
#ifdef CONFIG_OF
static const struct of_device_id exynos5_dsim[] = {
{ .compatible = "samsung,exynos5-dsim" },
{},
};
MODULE_DEVICE_TABLE(of, exynos5_dsim);
#endif
struct mipi_dsim_device *dsim_for_decon;
EXPORT_SYMBOL(dsim_for_decon);
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
int s5p_mipi_dsi_hibernation_power_on(struct display_driver *dispdrv);
int s5p_mipi_dsi_hibernation_power_off(struct display_driver *dispdrv);
#endif
int s5p_dsim_init_d_phy(struct mipi_dsim_device *dsim, unsigned int enable)
{
#if defined(CONFIG_SOC_EXYNOS5430) || defined(CONFIG_SOC_EXYNOS5433)
exynos5_dism_phy_enable(0, enable);
#else
unsigned int reg;
reg = readl(S5P_MIPI_DPHY_CONTROL(1)) & ~(1 << 0);
reg |= (enable << 0);
writel(reg, S5P_MIPI_DPHY_CONTROL(1));
reg = readl(S5P_MIPI_DPHY_CONTROL(1)) & ~(1 << 2);
reg |= (enable << 2);
writel(reg, S5P_MIPI_DPHY_CONTROL(1));
#endif
return 0;
}
#ifdef CONFIG_DECON_MIC
static void decon_mipi_dsi_config_mic(struct mipi_dsim_device *dsim)
{
#if defined(CONFIG_SOC_EXYNOS5422)
return;
#endif
if (!dsim->lcd_info->mic)
return;
s5p_mipi_dsi_enable_mic(dsim, true);
s5p_mipi_dsi_set_3d_off_mic_on_h_size(dsim);
}
#endif
static void s5p_mipi_dsi_set_packet_ctrl(struct mipi_dsim_device *dsim)
{
writel(0xffff, dsim->reg_base + S5P_DSIM_MULTI_PKT);
}
static void s5p_mipi_dsi_long_data_wr(struct mipi_dsim_device *dsim, unsigned int data0, unsigned int data1)
{
unsigned int data_cnt = 0, payload = 0;
/* in case that data count is more then 4 */
for (data_cnt = 0; data_cnt < data1; data_cnt += 4) {
/*
* after sending 4bytes per one time,
* send remainder data less then 4.
*/
if ((data1 - data_cnt) < 4) {
if ((data1 - data_cnt) == 3) {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8 |
(*(u8 *)(data0 + (data_cnt + 2))) << 16;
dev_dbg(dsim->dev, "count = 3 payload = %x, %x %x %x\n",
payload, *(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)),
*(u8 *)(data0 + (data_cnt + 2)));
} else if ((data1 - data_cnt) == 2) {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8;
dev_dbg(dsim->dev,
"count = 2 payload = %x, %x %x\n", payload,
*(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)));
} else if ((data1 - data_cnt) == 1) {
payload = *(u8 *)(data0 + data_cnt);
}
s5p_mipi_dsi_wr_tx_data(dsim, payload);
/* send 4bytes per one time. */
} else {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8 |
(*(u8 *)(data0 + (data_cnt + 2))) << 16 |
(*(u8 *)(data0 + (data_cnt + 3))) << 24;
dev_dbg(dsim->dev,
"count = 4 payload = %x, %x %x %x %x\n",
payload, *(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)),
*(u8 *)(data0 + (data_cnt + 2)),
*(u8 *)(data0 + (data_cnt + 3)));
s5p_mipi_dsi_wr_tx_data(dsim, payload);
}
}
}
int s5p_mipi_dsi_wr_data(struct mipi_dsim_device *dsim, unsigned int data_id,
unsigned int data0, unsigned int data1)
{
int ret = 0;
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
struct display_driver *dispdrv = get_display_driver();
disp_pm_gate_lock(dispdrv, true);
disp_pm_add_refcount(dispdrv);
#endif
if (dsim->enabled == false || dsim->state != DSIM_STATE_HSCLKEN) {
dev_info(dsim->dev, "MIPI DSIM is not ready. enabled %d state %d\n",
dsim->enabled, dsim->state);
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
disp_pm_gate_lock(dispdrv, false);
#endif
return -EINVAL;
}
mutex_lock(&dsim_rd_wr_mutex);
switch (data_id) {
/* short packet types of packet types for command. */
case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
case MIPI_DSI_DCS_SHORT_WRITE:
case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
INIT_COMPLETION(dsim_ph_wr_comp);
s5p_mipi_dsi_clear_interrupt(dsim, INTSRC_SFR_PH_FIFO_EMPTY);
s5p_mipi_dsi_wr_tx_header(dsim, data_id, data0, data1);
if (!wait_for_completion_interruptible_timeout(&dsim_ph_wr_comp,
MIPI_WR_TIMEOUT)) {
dev_err(dsim->dev, "MIPI DSIM short packet write Timeout! %02X\n", data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* general command */
case MIPI_DSI_COLOR_MODE_OFF:
case MIPI_DSI_COLOR_MODE_ON:
case MIPI_DSI_SHUTDOWN_PERIPHERAL:
case MIPI_DSI_TURN_ON_PERIPHERAL:
INIT_COMPLETION(dsim_ph_wr_comp);
s5p_mipi_dsi_clear_interrupt(dsim, INTSRC_SFR_PH_FIFO_EMPTY);
s5p_mipi_dsi_wr_tx_header(dsim, data_id, data0, data1);
if (!wait_for_completion_interruptible_timeout(&dsim_ph_wr_comp,
MIPI_WR_TIMEOUT)) {
dev_err(dsim->dev, "MIPI DSIM short packet write Timeout! %02X\n", data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* packet types for video data */
case MIPI_DSI_V_SYNC_START:
case MIPI_DSI_V_SYNC_END:
case MIPI_DSI_H_SYNC_START:
case MIPI_DSI_H_SYNC_END:
case MIPI_DSI_END_OF_TRANSMISSION:
break;
/* short and response packet types for command */
case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
case MIPI_DSI_DCS_READ:
INIT_COMPLETION(dsim_ph_wr_comp);
s5p_mipi_dsi_clear_all_interrupt(dsim);
s5p_mipi_dsi_wr_tx_header(dsim, data_id, data0, data1);
if (!wait_for_completion_interruptible_timeout(&dsim_ph_wr_comp,
MIPI_WR_TIMEOUT)) {
dev_err(dsim->dev, "MIPI DSIM short packet write Timeout! %02X\n", data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* long packet type and null packet */
case MIPI_DSI_NULL_PACKET:
case MIPI_DSI_BLANKING_PACKET:
break;
case MIPI_DSI_GENERIC_LONG_WRITE:
case MIPI_DSI_DCS_LONG_WRITE:
{
unsigned int size;
size = data1 * 4;
INIT_COMPLETION(dsim_wr_comp);
s5p_mipi_dsi_clear_interrupt(dsim, INTSRC_SFR_FIFO_EMPTY);
/* if data count is less then 4, then send 3bytes data. */
if (data1 < 4) {
unsigned int payload = 0;
payload = *(u8 *)(data0) |
*(u8 *)(data0 + 1) << 8 |
*(u8 *)(data0 + 2) << 16;
s5p_mipi_dsi_wr_tx_data(dsim, payload);
dev_dbg(dsim->dev, "count = %d payload = %x,%x %x %x\n",
data1, payload,
*(u8 *)(data0),
*(u8 *)(data0 + 1),
*(u8 *)(data0 + 2));
/* in case that data count is more then 4 */
} else
s5p_mipi_dsi_long_data_wr(dsim, data0, data1);
/* put data into header fifo */
s5p_mipi_dsi_wr_tx_header(dsim, data_id, data1 & 0xff,
(data1 & 0xff00) >> 8);
if (!wait_for_completion_interruptible_timeout(&dsim_wr_comp,
MIPI_WR_TIMEOUT)) {
dev_err(dsim->dev, "MIPI DSIM write Timeout! %02X\n", *(u8 *)(data0));
ret = -ETIMEDOUT;
goto exit;
}
break;
}
/* packet typo for video data */
case MIPI_DSI_PACKED_PIXEL_STREAM_16:
case MIPI_DSI_PACKED_PIXEL_STREAM_18:
case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
case MIPI_DSI_PACKED_PIXEL_STREAM_24:
break;
default:
dev_warn(dsim->dev, "data id %x is not supported current DSI spec.\n", data_id);
ret = -EINVAL;
goto exit;
}
exit:
if (dsim->enabled && (ret == -ETIMEDOUT)) {
dev_info(dsim->dev, "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
readl(dsim->reg_base + S5P_DSIM_STATUS),
readl(dsim->reg_base + S5P_DSIM_INTSRC),
readl(dsim->reg_base + S5P_DSIM_FIFOCTRL),
readl(dsim->reg_base + S5P_DSIM_MULTI_PKT));
s5p_mipi_dsi_init_fifo_pointer(dsim, DSIM_INIT_SFR);
}
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
disp_pm_gate_lock(dispdrv, false);
#endif
mutex_unlock(&dsim_rd_wr_mutex);
return ret;
}
static void s5p_mipi_dsi_rx_err_handler(struct mipi_dsim_device *dsim,
u32 rx_fifo)
{
/* Parse error report bit*/
if (rx_fifo & (1 << 8))
dev_err(dsim->dev, "SoT error!\n");
if (rx_fifo & (1 << 9))
dev_err(dsim->dev, "SoT sync error!\n");
if (rx_fifo & (1 << 10))
dev_err(dsim->dev, "EoT error!\n");
if (rx_fifo & (1 << 11))
dev_err(dsim->dev, "Escape mode entry command error!\n");
if (rx_fifo & (1 << 12))
dev_err(dsim->dev, "Low-power transmit sync error!\n");
if (rx_fifo & (1 << 13))
dev_err(dsim->dev, "HS receive timeout error!\n");
if (rx_fifo & (1 << 14))
dev_err(dsim->dev, "False control error!\n");
/* Bit 15 is reserved*/
if (rx_fifo & (1 << 16))
dev_err(dsim->dev, "ECC error, single-bit(detected and corrected)!\n");
if (rx_fifo & (1 << 17))
dev_err(dsim->dev, "ECC error, multi-bit(detected, not corrected)!\n");
if (rx_fifo & (1 << 18))
dev_err(dsim->dev, "Checksum error(long packet only)!\n");
if (rx_fifo & (1 << 19))
dev_err(dsim->dev, "DSI data type not recognized!\n");
if (rx_fifo & (1 << 20))
dev_err(dsim->dev, "DSI VC ID invalid!\n");
if (rx_fifo & (1 << 21))
dev_err(dsim->dev, "Invalid transmission length!\n");
/* Bit 22 is reserved */
if (rx_fifo & (1 << 23))
dev_err(dsim->dev, "DSI protocol violation!\n");
}
int s5p_mipi_dsi_rd_data(struct mipi_dsim_device *dsim, u32 data_id,
u32 addr, u32 count, u8 *buf, u8 rxfifo_done)
{
u32 rx_fifo, rx_size = 0;
int i, j, ret = 0;
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
struct display_driver *dispdrv = get_display_driver();
#endif
if (dsim->enabled == false || dsim->state != DSIM_STATE_HSCLKEN) {
dev_dbg(dsim->dev, "MIPI DSIM is not ready.\n");
return -EINVAL;
}
INIT_COMPLETION(dsim_rd_comp);
/* Set the maximum packet size returned */
s5p_mipi_dsi_wr_data(dsim,
MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, count, 0);
/* Read request */
s5p_mipi_dsi_wr_data(dsim, data_id, addr, 0);
if (!wait_for_completion_interruptible_timeout(&dsim_rd_comp,
MIPI_RD_TIMEOUT)) {
dev_err(dsim->dev, "MIPI DSIM read Timeout!\n");
return -ETIMEDOUT;
}
mutex_lock(&dsim_rd_wr_mutex);
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
disp_pm_gate_lock(dispdrv, true);
disp_pm_add_refcount(dispdrv);
#endif
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
/* Parse the RX packet data types */
switch (rx_fifo & 0xff) {
case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
s5p_mipi_dsi_rx_err_handler(dsim, rx_fifo);
goto rx_error;
case MIPI_DSI_RX_END_OF_TRANSMISSION:
dev_dbg(dsim->dev, "EoTp was received from LCD module.\n");
break;
case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
dev_dbg(dsim->dev, "Short Packet was received from LCD module.\n");
for (i = 0; i <= count; i++)
buf[i] = (rx_fifo >> (8 + i * 8)) & 0xff;
break;
case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
dev_dbg(dsim->dev, "Long Packet was received from LCD module.\n");
rx_size = (rx_fifo & 0x00ffff00) >> 8;
dev_info(dsim->dev, "rx fifo : %8x, response : %x, rx_size : %d\n",
rx_fifo, rx_fifo & 0xff, rx_size);
/* Read data from RX packet payload */
for (i = 0; i < rx_size >> 2; i++) {
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
for (j = 0; j < 4; j++)
buf[(i*4)+j] = (u8)(rx_fifo >> (j * 8)) & 0xff;
}
if (rx_size % 4) {
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
for (j = 0; j < rx_size % 4; j++)
buf[4 * i + j] =
(u8)(rx_fifo >> (j * 8)) & 0xff;
}
break;
default:
dev_err(dsim->dev, "Packet format is invaild.\n");
goto rx_error;
}
if (!rxfifo_done) {
ret = rx_size;
goto exit;
}
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
if (rx_fifo != DSIM_RX_FIFO_READ_DONE) {
dev_info(dsim->dev, "%s Can't find RX FIFO READ DONE FLAG : %x\n",
__func__, rx_fifo);
goto clear_rx_fifo;
}
ret = rx_size;
goto exit;
clear_rx_fifo:
i = 0;
while (1) {
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
if ((rx_fifo == DSIM_RX_FIFO_READ_DONE) ||
(i > DSIM_MAX_RX_FIFO))
break;
dev_info(dsim->dev, "%s clear rx fifo : %08x\n", __func__, rx_fifo);
i++;
}
ret = 0;
goto exit;
rx_error:
s5p_mipi_dsi_force_dphy_stop_state(dsim, 1);
usleep_range(3000, 4000);
s5p_mipi_dsi_force_dphy_stop_state(dsim, 0);
ret = -EPERM;
goto exit;
exit:
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
disp_pm_gate_lock(dispdrv, false);
#endif
mutex_unlock(&dsim_rd_wr_mutex);
return ret;
}
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
void s5p_mipi_dsi_te_triggered(void)
{
struct display_driver *dispdrv = get_display_driver();
struct mipi_dsim_device *dsim = dispdrv->dsi_driver.dsim;
if (!dsim->enabled)
return;
s5p_mipi_dsi_pkt_go_ready(dsim);
}
void s5p_mipi_dsi_trigger_unmask(void)
{
struct display_driver *dispdrv = get_display_driver();
struct mipi_dsim_device *dsim = dispdrv->dsi_driver.dsim;
if (likely(dsim->pktgo != DSIM_PKTGO_STANDBY))
return;
s5p_mipi_dsi_pkt_go_cnt(dsim, 0xff);
s5p_mipi_dsi_pkt_go_enable(dsim, true);
dsim->pktgo = DSIM_PKTGO_ENABLED;
dev_info(dsim->dev, "%s: DSIM_PKTGO_ENABLED", __func__);
}
#endif
int s5p_mipi_dsi_pll_on(struct mipi_dsim_device *dsim, unsigned int enable)
{
int sw_timeout;
if (enable) {
sw_timeout = 1000;
s5p_mipi_dsi_clear_interrupt(dsim, INTSRC_PLL_STABLE);
s5p_mipi_dsi_enable_pll(dsim, 1);
while (1) {
sw_timeout--;
if (s5p_mipi_dsi_is_pll_stable(dsim))
return 0;
if (sw_timeout == 0)
return -EINVAL;
}
} else
s5p_mipi_dsi_enable_pll(dsim, 0);
return 0;
}
static unsigned long s5p_mipi_dsi_change_pll(struct mipi_dsim_device *dsim,
unsigned int pre_divider, unsigned int main_divider,
unsigned int scaler)
{
unsigned long dfin_pll, dfvco, dpll_out;
unsigned int i, freq_band = 0xf;
dfin_pll = (FIN_HZ / pre_divider);
if (soc_is_exynos5250()) {
if (dfin_pll < DFIN_PLL_MIN_HZ || dfin_pll > DFIN_PLL_MAX_HZ) {
dev_warn(dsim->dev, "fin_pll range should be 6MHz ~ 12MHz\n");
s5p_mipi_dsi_enable_afc(dsim, 0, 0);
} else {
if (dfin_pll < 7 * MHZ)
s5p_mipi_dsi_enable_afc(dsim, 1, 0x1);
else if (dfin_pll < 8 * MHZ)
s5p_mipi_dsi_enable_afc(dsim, 1, 0x0);
else if (dfin_pll < 9 * MHZ)
s5p_mipi_dsi_enable_afc(dsim, 1, 0x3);
else if (dfin_pll < 10 * MHZ)
s5p_mipi_dsi_enable_afc(dsim, 1, 0x2);
else if (dfin_pll < 11 * MHZ)
s5p_mipi_dsi_enable_afc(dsim, 1, 0x5);
else
s5p_mipi_dsi_enable_afc(dsim, 1, 0x4);
}
}
dfvco = dfin_pll * main_divider;
dev_dbg(dsim->dev, "dfvco: %lu, dfin_pll: %lu, main_divider: %d\n", dfvco, dfin_pll, main_divider);
if (soc_is_exynos5250()) {
if (dfvco < DFVCO_MIN_HZ || dfvco > DFVCO_MAX_HZ)
dev_warn(dsim->dev, "fvco range should be 500MHz ~ 1000MHz\n");
}
dpll_out = dfvco / (1 << scaler);
/* condition with DPHY support upto 1.5 */
if (!soc_is_exynos4210() && !soc_is_exynos4212() && !soc_is_exynos4212())
dpll_out *= 2;
dev_info(dsim->dev, "dpll_out: %lu, dfvco: %lu, scaler: %d\n", dpll_out, dfvco, scaler);
if (soc_is_exynos5250()) {
for (i = 0; i < ARRAY_SIZE(dpll_table); i++) {
if (dpll_out < dpll_table[i] * MHZ) {
freq_band = i;
break;
}
}
dev_dbg(dsim->dev, "freq_band = %d\n", freq_band);
}
s5p_mipi_dsi_pll_freq(dsim, pre_divider, main_divider, scaler);
s5p_mipi_dsi_hs_zero_ctrl(dsim, 0);
s5p_mipi_dsi_prep_ctrl(dsim, 0);
if (soc_is_exynos5250()) {
/* Freq Band */
s5p_mipi_dsi_pll_freq_band(dsim, freq_band);
}
/* Stable time */
s5p_mipi_dsi_pll_stable_time(dsim, dsim->dsim_config->pll_stable_time);
/* Enable PLL */
dev_dbg(dsim->dev, "FOUT of mipi dphy pll is %luMHz\n", (dpll_out / MHZ));
return dpll_out;
}
static u32 decon_mipi_dsi_calc_pms(struct mipi_dsim_device *dsim)
{
u32 p_div, m_div, s_div;
u32 target_freq, fin_pll, voc_out, fout_cal;
u32 fin = 24;
/*
* One clk lane consists of 2 lines.
* HS clk freq = line rate X 2
* Here, we calculate the freq of ONE line(fout_cal is the freq of ONE line).
* Thus, target_freq = dsim->lcd_info->hs_clk/2.
*/
target_freq = dsim->lcd_info->hs_clk / 2;
for (p_div = 1; p_div <= 33; p_div++)
for (m_div = 25; m_div <= 125; m_div++)
for (s_div = 0; s_div <= 3; s_div++) {
fin_pll = fin / p_div;
voc_out = (m_div * fin) / p_div;
fout_cal = (m_div * fin) / (p_div * (1 << s_div));
if ((fin_pll < 6) || (fin_pll > 12))
continue;
if ((voc_out < 300) || (voc_out > 750))
continue;
if (fout_cal < target_freq)
continue;
if ((target_freq == fout_cal) && (fout_cal <= 750))
goto calculation_success;
}
for (p_div = 1; p_div <= 33; p_div++)
for (m_div = 25; m_div <= 125; m_div++)
for (s_div = 0; s_div <= 3; s_div++) {
fin_pll = fin / p_div;
voc_out = (m_div * fin) / p_div;
fout_cal = (m_div * fin) / (p_div * (1 << s_div));
if ((fin_pll < 6) || (fin_pll > 12))
continue;
if ((voc_out < 300) || (voc_out > 750))
continue;
if (fout_cal < target_freq)
continue;
/* target_freq < fout_cal, here is different from the above */
if ((target_freq < fout_cal) && (fout_cal <= 750))
goto calculation_success;
}
dev_err(dsim->dev, "Failed to calculate PMS values\n");
return -EINVAL;
calculation_success:
dsim->dsim_config->p = p_div;
dsim->dsim_config->m = m_div;
dsim->dsim_config->s = s_div;
dev_dbg(dsim->dev, "High Speed Clock rate = %dMhz, P = %d, M = %d, S = %d\n",
fout_cal * 2, p_div, m_div, s_div);
return fout_cal * 2;
}
static int decon_mipi_dsi_get_dphy_timing(struct mipi_dsim_device *dsim)
{
bool loop = true;
/* The index of the last element in array */
int i = sizeof(dphy_timing) / sizeof(dphy_timing[0]) - 1;
/* In case of resume, don't run the following code */
if (dsim->timing.bps)
return 1;
while (loop) {
if (dphy_timing[i][0] < dsim->hs_clk) {
i--;
continue;
} else {
dsim->timing.bps = dsim->hs_clk;
dsim->timing.clk_prepare = dphy_timing[i][1];
dsim->timing.clk_zero = dphy_timing[i][2];
dsim->timing.clk_post = dphy_timing[i][3];
dsim->timing.clk_trail = dphy_timing[i][4];
dsim->timing.hs_prepare = dphy_timing[i][5];
dsim->timing.hs_zero = dphy_timing[i][6];
dsim->timing.hs_trail = dphy_timing[i][7];
dsim->timing.lpx = dphy_timing[i][8];
dsim->timing.hs_exit = dphy_timing[i][9];
loop = false;
}
}
switch (dsim->dsim_config->esc_clk) {
/* Mhz */
case 20:
dsim->timing.b_dphyctl = 0x1f4;
break;
case 19:
dsim->timing.b_dphyctl = 0x1db;
break;
case 18:
dsim->timing.b_dphyctl = 0x1c2;
break;
case 17:
dsim->timing.b_dphyctl = 0x1a9;
break;
case 16:
dsim->timing.b_dphyctl = 0x190;
break;
case 15:
dsim->timing.b_dphyctl = 0x177;
break;
case 14:
dsim->timing.b_dphyctl = 0x15e;
break;
case 13:
dsim->timing.b_dphyctl = 0x145;
break;
case 12:
dsim->timing.b_dphyctl = 0x12c;
break;
case 11:
dsim->timing.b_dphyctl = 0x113;
break;
case 10:
dsim->timing.b_dphyctl = 0xfa;
break;
case 9:
dsim->timing.b_dphyctl = 0xe1;
break;
case 8:
dsim->timing.b_dphyctl = 0xc8;
break;
case 7:
dsim->timing.b_dphyctl = 0xaf;
break;
default:
dev_err(dsim->dev, "Escape clock is set too low\n");
break;
}
return 1;
}
static int decon_mipi_dsi_set_dphy_timing_value(struct mipi_dsim_device *dsim)
{
s5p_mipi_dsi_set_timing_register0(dsim, dsim->timing.lpx,
dsim->timing.hs_exit);
s5p_mipi_dsi_set_timing_register1(dsim, dsim->timing.clk_prepare,
dsim->timing.clk_zero, dsim->timing.clk_post,
dsim->timing.clk_trail);
s5p_mipi_dsi_set_timing_register2(dsim, dsim->timing.hs_prepare,
dsim->timing.hs_zero, dsim->timing.hs_trail);
s5p_mipi_dsi_set_b_dphyctrl(dsim, dsim->timing.b_dphyctl);
return 1;
}
int s5p_mipi_dsi_set_clock(struct mipi_dsim_device *dsim,
unsigned int byte_clk_sel, unsigned int enable)
{
unsigned int esc_div;
unsigned long esc_clk_error_rate;
struct decon_lcd *lcd_info = dsim->lcd_info;
if (enable) {
dsim->e_clk_src = byte_clk_sel;
dsim->dsim_config->esc_clk = lcd_info->esc_clk;
/* Escape mode clock and byte clock source */
s5p_mipi_dsi_set_byte_clock_src(dsim, byte_clk_sel);
/* DPHY, DSIM Link : D-PHY clock out */
if (byte_clk_sel == DSIM_PLL_OUT_DIV8) {
dsim->hs_clk = decon_mipi_dsi_calc_pms(dsim);
if (dsim->hs_clk == -EINVAL) {
dev_err(dsim->dev,
"failed to get hs clock.\n");
return -EINVAL;
}
decon_mipi_dsi_get_dphy_timing(dsim);
s5p_mipi_dsi_change_pll(dsim,
dsim->dsim_config->p, dsim->dsim_config->m,
dsim->dsim_config->s);
if (!soc_is_exynos5250())
decon_mipi_dsi_set_dphy_timing_value(dsim);
dsim->byte_clk = dsim->hs_clk / 8;
s5p_mipi_dsi_enable_pll_bypass(dsim, 0);
s5p_mipi_dsi_pll_on(dsim, 1);
/* DPHY : D-PHY clock out, DSIM link : external clock out */
} else if (byte_clk_sel == DSIM_EXT_CLK_DIV8)
dev_warn(dsim->dev,
"this project is not support \
external clock source for MIPI DSIM\n");
else if (byte_clk_sel == DSIM_EXT_CLK_BYPASS)
dev_warn(dsim->dev,
"this project is not support \
external clock source for MIPI DSIM\n");
/* escape clock divider */
esc_div = dsim->byte_clk / (dsim->dsim_config->esc_clk);
dev_dbg(dsim->dev,
"esc_div = %d, byte_clk = %lu, esc_clk = %lu\n",
esc_div, dsim->byte_clk, dsim->dsim_config->esc_clk);
if ((dsim->byte_clk / esc_div) >= (20 * MHZ) ||
(dsim->byte_clk / esc_div) >
dsim->dsim_config->esc_clk)
esc_div += 1;
dsim->escape_clk = dsim->byte_clk / esc_div;
dev_dbg(dsim->dev,
"escape_clk = %lu, byte_clk = %lu, esc_div = %d\n",
dsim->escape_clk, dsim->byte_clk, esc_div);
/* enable byte clock. */
s5p_mipi_dsi_enable_byte_clock(dsim, DSIM_ESCCLK_ON);
/* enable escape clock */
s5p_mipi_dsi_set_esc_clk_prs(dsim, 1, esc_div);
/* escape clock on lane */
s5p_mipi_dsi_enable_esc_clk_on_lane(dsim,
(DSIM_LANE_CLOCK | dsim->data_lane), 1);
dev_dbg(dsim->dev, "byte clock is %luMHz\n",
dsim->byte_clk);
dev_dbg(dsim->dev, "escape clock that user's need is %lu\n",
dsim->dsim_config->esc_clk);
dev_dbg(dsim->dev, "escape clock divider is %x\n", esc_div);
dev_dbg(dsim->dev, "escape clock is %luMHz\n",
(dsim->byte_clk / esc_div));
if ((dsim->byte_clk / esc_div) > dsim->escape_clk) {
esc_clk_error_rate = dsim->escape_clk /
(dsim->byte_clk / esc_div);
dev_warn(dsim->dev, "error rate is %lu over.\n",
(esc_clk_error_rate / 100));
} else if ((dsim->byte_clk / esc_div) < (dsim->escape_clk)) {
esc_clk_error_rate = (dsim->byte_clk / esc_div) /
dsim->escape_clk;
dev_warn(dsim->dev, "error rate is %lu under.\n",
(esc_clk_error_rate / 100));
}
} else {
s5p_mipi_dsi_enable_esc_clk_on_lane(dsim,
(DSIM_LANE_CLOCK | dsim->data_lane), 0);
s5p_mipi_dsi_set_esc_clk_prs(dsim, 0, 0);
/* disable escape clock. */
s5p_mipi_dsi_enable_byte_clock(dsim, DSIM_ESCCLK_OFF);
if (byte_clk_sel == DSIM_PLL_OUT_DIV8)
s5p_mipi_dsi_pll_on(dsim, 0);
}
return 0;
}
void s5p_mipi_dsi_d_phy_onoff(struct mipi_dsim_device *dsim,
unsigned int enable)
{
/*
if (dsim->pd->init_d_phy)
dsim->pd->init_d_phy(dsim, enable);
*/
s5p_dsim_init_d_phy(dsim, enable);
}
int s5p_mipi_dsi_init_dsim(struct mipi_dsim_device *dsim)
{
s5p_mipi_dsi_d_phy_onoff(dsim, 1);
dsim->state = DSIM_STATE_INIT;
switch (dsim->dsim_config->e_no_data_lane) {
case DSIM_DATA_LANE_1:
dsim->data_lane = DSIM_LANE_DATA0;
break;
case DSIM_DATA_LANE_2:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1;
break;
case DSIM_DATA_LANE_3:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1 |
DSIM_LANE_DATA2;
break;
case DSIM_DATA_LANE_4:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1 |
DSIM_LANE_DATA2 | DSIM_LANE_DATA3;
break;
default:
dev_info(dsim->dev, "data lane is invalid.\n");
return -EINVAL;
};
s5p_mipi_dsi_sw_reset(dsim);
s5p_mipi_dsi_dp_dn_swap(dsim, 0);
return 0;
}
int s5p_mipi_dsi_enable_frame_done_int(struct mipi_dsim_device *dsim,
unsigned int enable)
{
/* enable only frame done interrupt */
s5p_mipi_dsi_set_interrupt_mask(dsim, INTMSK_FRAME_DONE, enable);
return 0;
}
int s5p_mipi_dsi_set_display_mode(struct mipi_dsim_device *dsim,
struct mipi_dsim_config *dsim_config)
{
unsigned int width = 0, height = 0;
u32 vbp, vfp, hbp, hfp, vsync_len, hsync_len;
width = dsim->lcd_info->xres;
height = dsim->lcd_info->yres;
vbp = dsim->lcd_info->vbp;
vfp = dsim->lcd_info->vfp;
hbp = dsim->lcd_info->hbp;
hfp = dsim->lcd_info->hfp;
vsync_len = dsim->lcd_info->vsa;
hsync_len = dsim->lcd_info->hsa;
/* in case of VIDEO MODE (RGB INTERFACE) */
if (dsim->dsim_config->e_interface == DSIM_VIDEO) {
s5p_mipi_dsi_set_main_disp_vporch(dsim,
6, /* cmd allow */
2, /* stable vfp */
vbp);
s5p_mipi_dsi_set_main_disp_hporch(dsim, hfp, hbp);
s5p_mipi_dsi_set_main_disp_sync_area(dsim, vsync_len, hsync_len);
}
#ifdef CONFIG_DECON_MIC
if (dsim->lcd_info->mic)
width = s5p_mipi_dsi_calc_bs_size(dsim);
#endif
s5p_mipi_dsi_set_main_disp_resol(dsim, height, width);
s5p_mipi_dsi_display_config(dsim);
return 0;
}
int s5p_mipi_dsi_init_link(struct mipi_dsim_device *dsim)
{
unsigned int time_out = 100;
unsigned int id;
id = dsim->id;
switch (dsim->state) {
case DSIM_STATE_INIT:
/* dsi configuration */
s5p_mipi_dsi_init_config(dsim);
s5p_mipi_dsi_enable_lane(dsim, DSIM_LANE_CLOCK, 1);
s5p_mipi_dsi_enable_lane(dsim, dsim->data_lane, 1);
/* set clock configuration */
s5p_mipi_dsi_set_clock(dsim, dsim->dsim_config->e_byte_clk, 1);
/* check clock and data lane state are stop state */
while (!(s5p_mipi_dsi_is_lane_state(dsim))) {
time_out--;
if (time_out == 0) {
dev_err(dsim->dev,
"DSI Master is not stop state.\n");
dev_err(dsim->dev,
"Check initialization process\n");
return -EINVAL;
}
}
if (time_out != 0) {
dev_dbg(dsim->dev,
"DSI Master driver has been completed.\n");
dev_dbg(dsim->dev, "DSI Master state is stop state\n");
}
dsim->state = DSIM_STATE_STOP;
/* BTA sequence counters */
s5p_mipi_dsi_set_stop_state_counter(dsim,
dsim->dsim_config->stop_holding_cnt);
s5p_mipi_dsi_set_bta_timeout(dsim,
dsim->dsim_config->bta_timeout);
s5p_mipi_dsi_set_lpdr_timeout(dsim,
dsim->dsim_config->rx_timeout);
s5p_mipi_dsi_set_packet_ctrl(dsim);
return 0;
default:
dev_info(dsim->dev, "DSI Master is already init.\n");
return 0;
}
return 0;
}
int s5p_mipi_dsi_set_hs_enable(struct mipi_dsim_device *dsim)
{
unsigned int time_out = 1000;
if (dsim->state == DSIM_STATE_STOP) {
if (dsim->e_clk_src != DSIM_EXT_CLK_BYPASS) {
dsim->state = DSIM_STATE_HSCLKEN;
/* set LCDC and CPU transfer mode to HS. */
s5p_mipi_dsi_set_lcdc_transfer_mode(dsim, 0);
s5p_mipi_dsi_set_cpu_transfer_mode(dsim, 0);
s5p_mipi_dsi_enable_hs_clock(dsim, 1);
while (!(s5p_mipi_dsi_is_hs_state(dsim))) {
time_out--;
if (time_out == 0) {
dev_err(dsim->dev,
"DSI Master is not HS state.\n");
return -EBUSY;
}
usleep_range(10, 10);
}
return 0;
} else
dev_warn(dsim->dev,
"clock source is external bypass.\n");
} else
dev_warn(dsim->dev, "DSIM is not stop state.\n");
return 0;
}
int s5p_mipi_dsi_set_data_transfer_mode(struct mipi_dsim_device *dsim,
unsigned int mode)
{
if (mode) {
if (dsim->state != DSIM_STATE_HSCLKEN) {
dev_err(dsim->dev, "HS Clock lane is not enabled.\n");
return -EINVAL;
}
s5p_mipi_dsi_set_lcdc_transfer_mode(dsim, 0);
} else {
if (dsim->state == DSIM_STATE_INIT || dsim->state ==
DSIM_STATE_ULPS) {
dev_err(dsim->dev,
"DSI Master is not STOP or HSDT state.\n");
return -EINVAL;
}
s5p_mipi_dsi_set_cpu_transfer_mode(dsim, 0);
}
return 0;
}
int s5p_mipi_dsi_get_frame_done_status(struct mipi_dsim_device *dsim)
{
return _s5p_mipi_dsi_get_frame_done_status(dsim);
}
int s5p_mipi_dsi_clear_frame_done(struct mipi_dsim_device *dsim)
{
_s5p_mipi_dsi_clear_frame_done(dsim);
return 0;
}
int s5p_mipi_dsi_clear_rx_fifo(struct mipi_dsim_device *dsim)
{
int i;
unsigned int rx_fifo;
for (i = 0; i < DSIM_MAX_RX_FIFO; i++)
rx_fifo = readl(dsim->reg_base + S5P_DSIM_RXFIFO);
dev_info(dsim->dev, "%s : rx_fifo 0x%08X\n", __func__, rx_fifo);
return 0;
}
static int s5p_mipi_dsi_set_interrupt(struct mipi_dsim_device *dsim, bool enable)
{
unsigned int int_msk;
int_msk = SFR_PL_FIFO_EMPTY | SFR_PH_FIFO_EMPTY | RX_DAT_DONE | MIPI_FRAME_DONE | ERR_RX_ECC;
if (enable) {
/* clear interrupt */
s5p_mipi_dsi_clear_all_interrupt(dsim);
s5p_mipi_dsi_set_interrupt_mask(dsim, int_msk, 0);
} else {
s5p_mipi_dsi_set_interrupt_mask(dsim, int_msk, 1);
}
return 0;
}
static irqreturn_t s5p_mipi_dsi_interrupt_handler(int irq, void *dev_id)
{
unsigned int int_msk = 0;
unsigned int int_src = 0;
struct mipi_dsim_device *dsim = dev_id;
int framedone = 0;
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
struct display_driver *dispdrv;
dispdrv = get_display_driver();
#endif
spin_lock(&dsim->slock);
#ifdef CONFIG_FB_HIBERNATION_DISPLAY_CLOCK_GATING
if (dispdrv->platform_status > DISP_STATUS_PM0 &&
!dispdrv->pm_status.clock_enabled) {
dev_err(dsim->dev, "IRQ occured during clock-gating!\n");
spin_unlock(&dsim->slock);
return IRQ_HANDLED;
}
#endif
int_src = readl(dsim->reg_base + S5P_DSIM_INTSRC);
int_msk = readl(dsim->reg_base + S5P_DSIM_INTMSK);
int_src = ~(int_msk) & int_src;
/* Test bit */
if (int_src & SFR_PL_FIFO_EMPTY)
complete(&dsim_wr_comp);
if (int_src & SFR_PH_FIFO_EMPTY)
complete(&dsim_ph_wr_comp);
if (int_src & RX_DAT_DONE)
complete(&dsim_rd_comp);
if (int_src & MIPI_FRAME_DONE)
framedone = 1;
if (int_src & ERR_RX_ECC)
dev_err(dsim->dev, "RX ECC Multibit error was detected!\n");
s5p_mipi_dsi_clear_interrupt(dsim, int_src);
spin_unlock(&dsim->slock);
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
/* tiggering power event for PM */
if (framedone)
disp_pm_dec_refcount(dispdrv);
#endif
return IRQ_HANDLED;
}
int s5p_mipi_dsi_enable(struct mipi_dsim_device *dsim)
{
struct display_driver *dispdrv;
dev_info(dsim->dev, "+%s\n", __func__);
/* get a reference of the display driver */
dispdrv = get_display_driver();
if (dsim->enabled == true)
return 0;
GET_DISPDRV_OPS(dispdrv).init_display_dsi_clocks(dsim->dev);
GET_DISPDRV_OPS(dispdrv).enable_display_driver_power(dsim->dev);
if (dsim->dsim_lcd_drv->resume)
dsim->dsim_lcd_drv->resume(dsim);
s5p_mipi_dsi_init_dsim(dsim);
s5p_mipi_dsi_init_link(dsim);
GET_DISPDRV_OPS(dispdrv).reset_display_driver_panel(dsim->dev);
#ifdef CONFIG_DECON_MIC
decon_mipi_dsi_config_mic(dsim);
#endif
s5p_mipi_dsi_set_data_transfer_mode(dsim, 0);
s5p_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
s5p_mipi_dsi_set_hs_enable(dsim);
/* enable interrupts */
s5p_mipi_dsi_set_interrupt(dsim, true);
/* usleep_range(1000, 1500); */
dsim->enabled = true;
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim->pktgo = DSIM_PKTGO_STANDBY;
#endif
dsim->dsim_lcd_drv->displayon(dsim);
dev_info(dsim->dev, "-%s\n", __func__);
return 0;
}
int s5p_mipi_dsi_disable(struct mipi_dsim_device *dsim)
{
struct display_driver *dispdrv;
dev_info(dsim->dev, "+%s\n", __func__);
/* get a reference of the display driver */
dispdrv = get_display_driver();
if (dsim->enabled == false)
return 0;
dsim->dsim_lcd_drv->suspend(dsim);
dsim->enabled = false;
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim->pktgo = DSIM_PKTGO_DISABLED;
#endif
/* disable interrupts */
s5p_mipi_dsi_set_interrupt(dsim, false);
/* disable HS clock */
s5p_mipi_dsi_enable_hs_clock(dsim, 0);
/* make CLK/DATA Lane as LP00 */
s5p_mipi_dsi_enable_lane(dsim, DSIM_LANE_CLOCK, 0);
s5p_mipi_dsi_enable_lane(dsim, dsim->data_lane, 0);
s5p_mipi_dsi_set_clock(dsim, dsim->dsim_config->e_byte_clk, 0);
s5p_mipi_dsi_sw_reset(dsim);
dsim->state = DSIM_STATE_SUSPEND;
s5p_mipi_dsi_d_phy_onoff(dsim, 0);
GET_DISPDRV_OPS(dispdrv).disable_display_driver_power(dsim->dev);
dev_info(dsim->dev, "-%s\n", __func__);
return 0;
}
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
int s5p_mipi_dsi_lcd_off(struct mipi_dsim_device *dsim)
{
struct display_driver *dispdrv;
/* get a reference of the display driver */
dispdrv = get_display_driver();
/* disable interrupts */
s5p_mipi_dsi_set_interrupt(dsim, false);
dsim->enabled = false;
dsim->dsim_lcd_drv->suspend(dsim);
dsim->state = DSIM_STATE_SUSPEND;
GET_DISPDRV_OPS(dispdrv).disable_display_driver_power(dsim->dev);
return 0;
}
#endif
int s5p_mipi_dsi_ulps_enable(struct mipi_dsim_device *dsim,
unsigned int mode)
{
int ret = 0;
unsigned int time_out = 1000;
if (mode == false) {
if (dsim->state == DSIM_STATE_STOP)
return ret;
/* Exit ULPS clock and data lane */
s5p_mipi_dsi_enable_ulps_exit_clk_data(dsim, 1);
/* Check ULPS Exit request for data lane */
while (!(s5p_mipi_dsi_is_ulps_lane_state(dsim, 0))) {
time_out--;
if (time_out == 0) {
dev_err(dsim->dev,
"%s: DSI Master is not stop state.\n", __func__);
return -EBUSY;
}
usleep_range(10, 10);
}
/* Clear ULPS enter & exit state */
s5p_mipi_dsi_enable_ulps_exit_clk_data(dsim, 0);
dsim->state = DSIM_STATE_STOP;
} else {
if (dsim->state == DSIM_STATE_ULPS)
return ret;
/* Disable TxRequestHsClk */
s5p_mipi_dsi_enable_hs_clock(dsim, 0);
/* Enable ULPS clock and data lane */
s5p_mipi_dsi_enable_ulps_clk_data(dsim, 1);
/* Check ULPS request for data lane */
while (!(s5p_mipi_dsi_is_ulps_lane_state(dsim, 1))) {
time_out--;
if (time_out == 0) {
dev_err(dsim->dev,
"%s: DSI Master is not ULPS state.\n", __func__);
/* Enable ULPS clock and data lane */
s5p_mipi_dsi_enable_ulps_clk_data(dsim, 1);
/* Disable TxRequestHsClk */
s5p_mipi_dsi_enable_hs_clock(dsim, 0);
return -EBUSY;
}
usleep_range(10, 10);
}
/* Clear ULPS enter & exit state */
s5p_mipi_dsi_enable_ulps_clk_data(dsim, 0);
dsim->state = DSIM_STATE_ULPS;
}
return ret;
}
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
int s5p_mipi_dsi_hibernation_power_on(struct display_driver *dispdrv)
{
struct mipi_dsim_device *dsim = dispdrv->dsi_driver.dsim;
if (dsim->enabled == true)
return 0;
GET_DISPDRV_OPS(dispdrv).init_display_dsi_clocks(dsim->dev);
/* PPI signal disable + D-PHY reset */
s5p_mipi_dsi_d_phy_onoff(dsim, 1);
/* Stable time */
s5p_mipi_dsi_pll_stable_time(dsim, dsim->dsim_config->pll_stable_time);
/* Enable PHY PLL */
s5p_mipi_dsi_pll_on(dsim, 1);
/* Exit ULPS mode clk & data */
s5p_mipi_dsi_ulps_enable(dsim, false);
s5p_mipi_dsi_init_dsim(dsim);
s5p_mipi_dsi_init_link(dsim);
dsim->enabled = true;
#ifdef CONFIG_DECON_MIC
decon_mipi_dsi_config_mic(dsim);
#endif
s5p_mipi_dsi_set_data_transfer_mode(dsim, 0);
s5p_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
s5p_mipi_dsi_set_hs_enable(dsim);
s5p_mipi_dsi_set_interrupt(dsim, true);
return 0;
}
int s5p_mipi_dsi_hibernation_power_off(struct display_driver *dispdrv)
{
struct mipi_dsim_device *dsim = dispdrv->dsi_driver.dsim;
if (dsim->enabled == false)
return 0;
s5p_mipi_dsi_set_interrupt(dsim, false);
/* Enter ULPS mode clk & data */
s5p_mipi_dsi_ulps_enable(dsim, true);
/* DSIM STOP SEQUENCE */
/* Set main stand-by off */
s5p_mipi_dsi_enable_main_standby(dsim, 0);
/* CLK and LANE disable */
s5p_mipi_dsi_enable_lane(dsim, DSIM_LANE_CLOCK, 0);
s5p_mipi_dsi_enable_lane(dsim, dsim->data_lane, 0);
/* escape clock on lane */
s5p_mipi_dsi_enable_esc_clk_on_lane(dsim,
(DSIM_LANE_CLOCK | dsim->data_lane), 0);
/* Disable byte clock */
s5p_mipi_dsi_enable_byte_clock(dsim, 0);
/* Disable PHY PLL */
s5p_mipi_dsi_pll_on(dsim, 0);
/* S/W reset */
s5p_mipi_dsi_sw_reset(dsim);
/* PPI signal disable + D-PHY reset */
s5p_mipi_dsi_d_phy_onoff(dsim, 0);
dsim->enabled = false;
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim->pktgo = DSIM_PKTGO_STANDBY;
#endif
return 0;
}
#endif
int create_mipi_dsi_controller(struct platform_device *pdev)
{
struct mipi_dsim_device *dsim = NULL;
struct display_driver *dispdrv;
int ret = -1;
/* get a reference of the display driver */
dispdrv = get_display_driver();
if (!dsim)
dsim = kzalloc(sizeof(struct mipi_dsim_device),
GFP_KERNEL);
if (!dsim) {
dev_err(&pdev->dev, "failed to allocate dsim object.\n");
return -EFAULT;
}
dispdrv->dsi_driver.dsim = dsim;
dsim->dev = &pdev->dev;
dsim->id = pdev->id;
spin_lock_init(&dsim->slock);
dsim->dsim_config = dispdrv->dt_ops.get_display_dsi_drvdata();
dsim->lcd_info = decon_get_lcd_info();
dsim->reg_base = devm_request_and_ioremap(&pdev->dev, dispdrv->dsi_driver.regs);
if (!dsim->reg_base) {
dev_err(&pdev->dev, "mipi-dsi: failed to remap io region\n");
ret = -EINVAL;
goto err_mem_region;
}
/*
* it uses frame done interrupt handler
* only in case of MIPI Video mode.
*/
dsim->irq = dispdrv->dsi_driver.dsi_irq_no;
if (request_irq(dsim->irq, s5p_mipi_dsi_interrupt_handler,
IRQF_DISABLED, "mipi-dsi", dsim)) {
dev_err(&pdev->dev, "request_irq failed.\n");
goto err_irq;
}
dsim->dsim_lcd_drv = dsim->dsim_config->dsim_ddi_pd;
dsim->timing.bps = 0;
mutex_init(&dsim_rd_wr_mutex);
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim->pktgo = DSIM_PKTGO_STANDBY;
#endif
#ifdef CONFIG_S5P_LCD_INIT
s5p_mipi_dsi_init_dsim(dsim);
s5p_mipi_dsi_init_link(dsim);
GET_DISPDRV_OPS(dispdrv).enable_display_driver_power(&pdev->dev);
GET_DISPDRV_OPS(dispdrv).reset_display_driver_panel(dsim->dev);
dsim->enabled = true;
#ifdef CONFIG_DECON_MIC
decon_mipi_dsi_config_mic(dsim);
#endif
s5p_mipi_dsi_set_data_transfer_mode(dsim, 0);
s5p_mipi_dsi_set_display_mode(dsim, dsim->dsim_config);
s5p_mipi_dsi_set_hs_enable(dsim);
/*
* dsim sfr access function must be called after s5p_mipi_dsi_init_dsim
* function. Because dsim sw reset function in s5p_mipi_dsi_init_dsim
* initializes all dsim sfr
*/
s5p_mipi_dsi_set_interrupt(dsim, true);
dsim->dsim_lcd_drv->probe(dsim);
dsim->dsim_lcd_drv->displayon(dsim);
#else
GET_DISPDRV_OPS(dispdrv).enable_display_driver_power(&pdev->dev);
/* Clear RX FIFO to prevent obnormal read opeation */
s5p_mipi_dsi_clear_rx_fifo(dsim);
dsim->enabled = true;
dsim->state = DSIM_STATE_HSCLKEN;
dsim->dsim_lcd_drv->probe(dsim);
#endif
dsim_for_decon = dsim;
dev_info(&pdev->dev, "mipi-dsi driver(%s mode) has been probed.\n",
(dsim->dsim_config->e_interface == DSIM_COMMAND) ?
"CPU" : "RGB");
dispdrv->dsi_driver.dsim = dsim;
#ifdef CONFIG_FB_HIBERNATION_DISPLAY
if (dispdrv->dsi_driver.ops) {
dispdrv->dsi_driver.ops->pwr_on = s5p_mipi_dsi_hibernation_power_on;
dispdrv->dsi_driver.ops->pwr_off = s5p_mipi_dsi_hibernation_power_off;
}
#endif
return 0;
err_irq:
release_resource(dispdrv->dsi_driver.regs);
kfree(dispdrv->dsi_driver.regs);
iounmap((void __iomem *) dsim->reg_base);
err_mem_region:
clk_disable(dsim->clock);
clk_put(dsim->clock);
kfree(dsim);
return ret;
}
MODULE_AUTHOR("Haowei li <haowei.li@samsung.com>");
MODULE_DESCRIPTION("Samusung MIPI-DSI driver");
MODULE_LICENSE("GPL");
|