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
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
|
#define LOG_TAG "ddp_manager"
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/bug.h>
#include <mach/mt_irq.h>
#include "disp_drv_platform.h"
#include "lcm_drv.h"
#include "ddp_reg.h"
#include "ddp_path.h"
#include "ddp_irq.h"
#include "ddp_drv.h"
#include "ddp_debug.h"
#include "ddp_manager.h"
#include "ddp_rdma.h"
#include "ddp_ovl.h"
#include "ddp_log.h"
#include "mtkfb_fence.h"
#include "primary_display.h"
#include <mach/mt_clkmgr.h>
//#pragma GCC optimize("O0")
extern DDP_MODULE_DRIVER * ddp_modules_driver[DISP_MODULE_NUM];
#ifdef MTKFB_FB_BYPASS_PQ
unsigned int gDDPError = 1;
#else
unsigned int gDDPError = 0;
#endif
static int ddp_manager_init = 0;
#define DDP_MAX_MANAGER_HANDLE (DISP_MUTEX_DDP_COUNT+DISP_MUTEX_DDP_FIRST)
extern int disp_get_session_number();
extern unsigned int WDMA0_FRAME_START_FLAG;
extern unsigned int ALL_LAYER_DISABLE_STEP;
unsigned int allLayerDisabled = 0;
typedef struct
{
volatile unsigned int init;
DISP_PATH_EVENT event;
wait_queue_head_t wq;
volatile unsigned long long data;
}DPMGR_WQ_HANDLE;
typedef struct
{
DDP_IRQ_BIT irq_bit;
}DDP_IRQ_EVENT_MAPPING;
typedef struct
{
cmdqRecHandle cmdqhandle;
int hwmutexid;
int power_sate;
DDP_MODE mode;
struct mutex mutex_lock;
DDP_IRQ_EVENT_MAPPING irq_event_map[DISP_PATH_EVENT_NUM];
DPMGR_WQ_HANDLE wq_list[DISP_PATH_EVENT_NUM];
DDP_SCENARIO_ENUM scenario;
DISP_MODULE_ENUM mem_module;
disp_ddp_path_config last_config;
}ddp_path_handle_t, *ddp_path_handle;
typedef struct
{
int handle_cnt;
int mutex_idx;
int power_sate;
struct mutex mutex_lock;
int module_usage_table[DISP_MODULE_NUM];
ddp_path_handle module_path_table[DISP_MODULE_NUM];
ddp_path_handle handle_pool[DDP_MAX_MANAGER_HANDLE];
}DDP_MANAGER_CONTEXT;
#define DEFAULT_IRQ_EVENT_SCENARIO (4)
static DDP_IRQ_EVENT_MAPPING ddp_irq_event_list[DEFAULT_IRQ_EVENT_SCENARIO][DISP_PATH_EVENT_NUM] =
{
{//ovl0 path
{DDP_IRQ_RDMA0_DONE }, /*FRAME_DONE*/
{DDP_IRQ_RDMA0_START }, /*FRAME_START*/
{DDP_IRQ_RDMA0_REG_UPDATE }, /*FRAME_REG_UPDATE*/
{DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_TARGET_LINE*/
{DDP_IRQ_WDMA0_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
{DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_STOP*/
{DDP_IRQ_RDMA0_REG_UPDATE }, /*IF_CMD_DONE*/
{DDP_IRQ_DSI0_EXT_TE }, /*IF_VSYNC*/
{DDP_IRQ_UNKNOW }, /*TRIGER*/
{DDP_IRQ_AAL_OUT_END_FRAME }, /*AAL_OUT_END_EVENT*/
},
{//ovl1 path
{DDP_IRQ_RDMA1_DONE }, /*FRAME_DONE*/
{DDP_IRQ_RDMA1_START }, /*FRAME_START*/
{DDP_IRQ_RDMA1_REG_UPDATE }, /*FRAME_REG_UPDATE*/
{DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_TARGET_LINE*/
{DDP_IRQ_WDMA1_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
{DDP_IRQ_RDMA1_TARGET_LINE }, /*FRAME_STOP*/
{DDP_IRQ_RDMA1_REG_UPDATE }, /*IF_CMD_DONE*/
{DDP_IRQ_RDMA1_TARGET_LINE }, /*IF_VSYNC*/
{DDP_IRQ_UNKNOW }, /*TRIGER*/
{DDP_IRQ_UNKNOW }, /*AAL_OUT_END_EVENT*/
},
{ // rdma path
{DDP_IRQ_RDMA2_DONE }, /*FRAME_DONE*/
{DDP_IRQ_RDMA2_START }, /*FRAME_START*/
{DDP_IRQ_RDMA2_REG_UPDATE }, /*FRAME_REG_UPDATE*/
{DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_TARGET_LINE*/
{DDP_IRQ_UNKNOW }, /*FRAME_COMPLETE*/
{DDP_IRQ_RDMA2_TARGET_LINE }, /*FRAME_STOP*/
{DDP_IRQ_RDMA2_REG_UPDATE }, /*IF_CMD_DONE*/
{DDP_IRQ_RDMA2_TARGET_LINE }, /*IF_VSYNC*/
{DDP_IRQ_UNKNOW }, /*TRIGER*/
{DDP_IRQ_UNKNOW }, /*AAL_OUT_END_EVENT*/
},
{//ovl0 path
{DDP_IRQ_RDMA0_DONE }, /*FRAME_DONE*/
{DDP_IRQ_MUTEX1_SOF}, /*FRAME_START*/
{DDP_IRQ_RDMA0_REG_UPDATE }, /*FRAME_REG_UPDATE*/
{DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_TARGET_LINE*/
{DDP_IRQ_WDMA0_FRAME_COMPLETE}, /*FRAME_COMPLETE*/
{DDP_IRQ_RDMA0_TARGET_LINE }, /*FRAME_STOP*/
{DDP_IRQ_RDMA0_REG_UPDATE }, /*IF_CMD_DONE*/
{DDP_IRQ_DSI0_EXT_TE }, /*IF_VSYNC*/
{DDP_IRQ_UNKNOW }, /*TRIGER*/
{DDP_IRQ_AAL_OUT_END_FRAME }, /*AAL_OUT_END_EVENT*/
}
};
static char * path_event_name(DISP_PATH_EVENT event)
{
switch(event)
{
case DISP_PATH_EVENT_FRAME_START:
return "FRAME_START";
case DISP_PATH_EVENT_FRAME_DONE:
return "FRAME_DONE";
case DISP_PATH_EVENT_FRAME_REG_UPDATE:
return "REG_UPDATE";
case DISP_PATH_EVENT_FRAME_TARGET_LINE:
return "TARGET_LINE";
case DISP_PATH_EVENT_FRAME_COMPLETE:
return "FRAME COMPLETE";
case DISP_PATH_EVENT_FRAME_STOP:
return "FRAME_STOP";
case DISP_PATH_EVENT_IF_CMD_DONE:
return "FRAME_STOP";
case DISP_PATH_EVENT_IF_VSYNC:
return "VSYNC";
case DISP_PATH_EVENT_TRIGGER:
return "TRIGGER";
default:
return "unknow event";
}
return "unknow event";
}
static DDP_MANAGER_CONTEXT* _get_context(void)
{
static int is_context_inited = 0;
static DDP_MANAGER_CONTEXT context;
if(!is_context_inited)
{
memset((void*)&context, 0, sizeof(DDP_MANAGER_CONTEXT));
context.mutex_idx = (1<<DISP_MUTEX_DDP_COUNT) - 1;
mutex_init(&context.mutex_lock);
is_context_inited = 1;
}
return &context;
}
static int path_top_clock_off(void)
{
int i =0;
DDP_MANAGER_CONTEXT * context = _get_context();
if(context->power_sate)
{
for(i=0; i< DDP_MAX_MANAGER_HANDLE; i++)
{
if(context->handle_pool[i] != NULL && context->handle_pool[i]->power_sate !=0)
{
return 0;
}
}
context->power_sate = 0;
ddp_path_top_clock_off();
}
return 0;
}
static int path_top_clock_on(void)
{
DDP_MANAGER_CONTEXT * context = _get_context();
if(!context->power_sate)
{
context->power_sate = 1;
ddp_path_top_clock_on();
}
return 0;
}
static int module_power_off(DISP_MODULE_ENUM module)
{
if(module == DISP_MODULE_DSI0)
{
return 0;
}
if(ddp_modules_driver[module] != 0)
{
if(ddp_modules_driver[module]->power_off!= 0)
{
DISP_LOG_V("%s power off\n",ddp_get_module_name(module));
ddp_modules_driver[module]->power_off(module, NULL); // now just 0;
}
}
return 0;
}
static int module_power_on(DISP_MODULE_ENUM module)
{
if(module == DISP_MODULE_DSI0)
{
/*bypass dsi*/
return 0;
}
if(ddp_modules_driver[module] != 0)
{
if(ddp_modules_driver[module]->power_on!= 0)
{
DISP_LOG_V("%s power on\n",ddp_get_module_name(module));
ddp_modules_driver[module]->power_on(module, NULL); // now just 0;
}
}
return 0;
}
static ddp_path_handle find_handle_by_module(DISP_MODULE_ENUM module)
{
return _get_context()->module_path_table[module];
}
int dpmgr_module_notify(DISP_MODULE_ENUM module, DISP_PATH_EVENT event)
{
ddp_path_handle handle = find_handle_by_module(module);
MMProfileLogEx(ddp_mmp_get_events()->primary_display_aalod_trigger, MMProfileFlagPulse, module, 0);
return dpmgr_signal_event(handle,event);
return 0;
}
static int assign_default_irqs_table(DDP_SCENARIO_ENUM scenario,DDP_IRQ_EVENT_MAPPING * irq_events)
{
int idx = 0;
switch(scenario)
{
case DDP_SCENARIO_PRIMARY_DISP:
case DDP_SCENARIO_PRIMARY_RDMA0_COLOR0_DISP:
case DDP_SCENARIO_PRIMARY_RDMA0_DISP:
case DDP_SCENARIO_PRIMARY_BYPASS_RDMA:
case DDP_SCENARIO_PRIMARY_DITHER_MEMOUT:
case DDP_SCENARIO_PRIMARY_UFOE_MEMOUT:
case DDP_SCENARIO_PRIMARY_ALL:
case DDP_SCENARIO_MULTIPLE_OVL:
idx = 0;
break;
case DDP_SCENARIO_SUB_DISP:
case DDP_SCENARIO_SUB_RDMA1_DISP:
case DDP_SCENARIO_SUB_OVL_MEMOUT:
case DDP_SCENARIO_SUB_ALL:
#ifdef CONFIG_SINGLE_PANEL_OUTPUT
idx = 0;
#else
idx = 1;
#endif
break;
case DDP_SCENARIO_PRIMARY_OVL_MEMOUT:
idx = 3;
break;
default:
DISP_LOG_E("unknow scenario %d\n",scenario);
}
DISP_LOG_I("assign default irqs table index %d\n",idx);
memcpy(irq_events,ddp_irq_event_list[idx],sizeof(ddp_irq_event_list[idx]));
return 0;
}
static int acquire_free_bit(unsigned int total)
{
int free_id =0 ;
while(total)
{
if(total & 0x1)
{
return free_id;
}
total>>=1;
++free_id;
}
return -1;
}
static int acquire_mutex(DDP_SCENARIO_ENUM scenario)
{
///: primay use mutex 0
int mutex_id =0 ;
DDP_MANAGER_CONTEXT * content = _get_context();
int mutex_idx_free = content->mutex_idx;
ASSERT(scenario >= 0 && scenario < DDP_SCENARIO_MAX);
while(mutex_idx_free)
{
if(mutex_idx_free & 0x1)
{
content->mutex_idx &= (~(0x1<<mutex_id));
mutex_id += DISP_MUTEX_DDP_FIRST;
break;
}
mutex_idx_free>>=1;
++mutex_id;
}
ASSERT(mutex_id < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
DISP_LOG_I("scenario %s acquire mutex %d , left mutex 0x%x!\n",
ddp_get_scenario_name(scenario), mutex_id, content->mutex_idx);
return mutex_id;
}
static int release_mutex(int mutex_idx)
{
DDP_MANAGER_CONTEXT * content = _get_context();
ASSERT(mutex_idx < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT));
content->mutex_idx |= 1<< (mutex_idx-DISP_MUTEX_DDP_FIRST);
DISP_LOG_I("release mutex %d , left mutex 0x%x!\n",
mutex_idx, content->mutex_idx);
return 0;
}
int dpmgr_path_set_video_mode(disp_path_handle dp_handle, int is_vdo_mode)
{
ddp_path_handle handle = NULL;
ASSERT(dp_handle != NULL);
handle = (ddp_path_handle)dp_handle;
handle->mode = is_vdo_mode ? DDP_VIDEO_MODE : DDP_CMD_MODE;
DISP_LOG_I("set scenario %s mode: %s\n",ddp_get_scenario_name(handle->scenario),
is_vdo_mode ? "Video_Mode":"Cmd_Mode");
return 0;
}
unsigned long hw_mutex_id_to_handle_map[128];
disp_path_handle dpmgr_create_path(DDP_SCENARIO_ENUM scenario, cmdqRecHandle cmdq_handle)
{
int i =0;
int module_name ;
ddp_path_handle path_handle = NULL;
int * modules = ddp_get_scenario_list(scenario);
int module_num = ddp_get_module_num(scenario);
DDP_MANAGER_CONTEXT * content = _get_context();
path_handle = kzalloc(sizeof(uint8_t*) * sizeof(ddp_path_handle_t), GFP_KERNEL);
if (NULL != path_handle)
{
path_handle->cmdqhandle = cmdq_handle;
path_handle->scenario = scenario;
path_handle->hwmutexid = acquire_mutex(scenario);
assign_default_irqs_table(scenario,path_handle->irq_event_map);
DISP_LOG_I("create handle %p on scenario %s\n",path_handle,ddp_get_scenario_name(scenario));
for( i=0; i< module_num;i++)
{
module_name = modules[i];
DISP_LOG_I(" scenario %s include module %s\n",ddp_get_scenario_name(scenario),ddp_get_module_name(module_name));
content->module_usage_table[module_name]++;
content->module_path_table[module_name] = path_handle;
}
hw_mutex_id_to_handle_map[path_handle->hwmutexid] = path_handle;
content->handle_cnt ++;
content->handle_pool[path_handle->hwmutexid] = path_handle;
}
else
{
DISP_LOG_E("Fail to create handle on scenario %s\n",ddp_get_scenario_name(scenario));
}
return path_handle;
}
// please ensure thread/irq safe by caller
int dpmgr_modify_path(disp_path_handle dp_handle, DDP_SCENARIO_ENUM new_scenario, cmdqRecHandle cmdq_handle, DDP_MODE isvdomode)
{
int i =0;
int module_name = 0;
DISP_MODULE_ENUM module[DISP_MODULE_NUM]={0};
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DDP_MANAGER_CONTEXT * content = _get_context();
DDP_SCENARIO_ENUM old_scenario = handle->scenario;
int *new_modules = ddp_get_scenario_list(new_scenario);
int new_module_num = ddp_get_module_num(new_scenario);
int *old_modules = ddp_get_scenario_list(old_scenario);
int old_module_num = ddp_get_module_num(old_scenario);
handle->cmdqhandle = cmdq_handle;
handle->scenario = new_scenario;
DISP_LOG_I("modify handle %p from %s to %s\n", handle, ddp_get_scenario_name(old_scenario), ddp_get_scenario_name(new_scenario));
for(i=0; i< new_module_num;i++)
{
module_name = new_modules[i];
module[module_name] ++;
if(content->module_usage_table[module_name] == 0)
{
content->module_usage_table[module_name]++;
DISP_LOG_D("add module %s\n", ddp_get_module_name(module_name));
content->module_path_table[module_name] = handle;
module_power_on(module_name);
}
}
for(i=0; i< old_module_num;i++)
{
module_name = old_modules[i];
if(module[module_name] == 0)
{
content->module_usage_table[module_name]--;
DISP_LOG_D("remove module %s\n", ddp_get_module_name(module_name));
content->module_path_table[module_name] = NULL;
module_power_off(module_name);
}
}
// mutex set will clear old settings
ddp_mutex_set(handle->hwmutexid, new_scenario, isvdomode, cmdq_handle);
ddp_mutex_Interrupt_enable(handle->hwmutexid, cmdq_handle);
// disconnect old path first
ddp_disconnect_path(old_scenario,cmdq_handle);
// connect new path
ddp_connect_path(new_scenario,cmdq_handle);
return 0;
}
int dpmgr_destroy_path(disp_path_handle dp_handle, cmdqRecHandle cmdq_handle)
{
int i =0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DDP_MANAGER_CONTEXT * content = _get_context();
DISP_LOG_I("destroy path handle %p on scenario %s\n",handle,ddp_get_scenario_name(handle->scenario));
if(handle != NULL)
{
release_mutex(handle->hwmutexid);
ddp_disconnect_path(handle->scenario,cmdq_handle);
for( i=0; i< module_num;i++)
{
module_name = modules[i];
content->module_usage_table[module_name]--;
content->module_path_table[module_name] = NULL;
}
content->handle_cnt --;
ASSERT(content->handle_cnt >=0);
content->handle_pool[handle->hwmutexid] = NULL;
kfree(handle);
}
return 0;
}
int dpmgr_path_memout_clock(disp_path_handle dp_handle, int clock_switch)
{
#if 0
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
handle->mem_module = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
if(handle->mem_module == DISP_MODULE_WDMA0 || handle->mem_module ==DISP_MODULE_WDMA1)
{
if(ddp_modules_driver[handle->mem_module] != 0)
{
if(clock_switch)
{
if(ddp_modules_driver[handle->mem_module]->power_on!= 0)
{
ddp_modules_driver[handle->mem_module]->power_on(handle->mem_module, NULL);
}
}
else
{
if(ddp_modules_driver[handle->mem_module]->power_off!= 0)
{
ddp_modules_driver[handle->mem_module]->power_off(handle->mem_module, NULL);
}
handle->mem_module = DISP_MODULE_UNKNOWN;
}
}
return 0;
}
return -1;
#endif
return 0;
}
int dpmgr_path_add_memout(disp_path_handle dp_handle, ENGINE_DUMP engine,void * cmdq_handle )
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_SUB_DISP
|| handle->scenario ==DDP_SCENARIO_PRIMARY_OVL_MEMOUT || handle->scenario ==DDP_SCENARIO_PRIMARY_ALL);
DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
if(ddp_is_module_in_scenario(handle->scenario, wdma)==1)
{
DDPERR("dpmgr_path_add_memout error, wdma is already in scenario=%s \n", ddp_get_scenario_name(handle->scenario));
// ASSERT(0);
return -1;
}
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[wdma]++;
context->module_path_table[wdma] = handle;
handle->scenario = DDP_SCENARIO_PRIMARY_ALL;
// update connected
ddp_connect_path(handle->scenario,cmdq_handle);
ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdq_handle);
//wdma just need start.
if(ddp_modules_driver[wdma] != 0)
{
if(ddp_modules_driver[wdma]->power_on!= 0)
{
ddp_modules_driver[wdma]->power_on(wdma, cmdq_handle);
}
if(ddp_modules_driver[wdma]->start!= 0)
{
ddp_modules_driver[wdma]->start(wdma, cmdq_handle);
}
}
return 0;
}
int dpmgr_path_remove_memout(disp_path_handle dp_handle, void * cmdq_handle)
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
ASSERT(handle->scenario ==DDP_SCENARIO_PRIMARY_DISP || handle->scenario ==DDP_SCENARIO_PRIMARY_ALL
|| handle->scenario ==DDP_SCENARIO_SUB_DISP || handle->scenario ==DDP_SCENARIO_SUB_ALL);
DISP_MODULE_ENUM wdma = ddp_is_scenario_on_primary(handle->scenario) ? DISP_MODULE_WDMA0: DISP_MODULE_WDMA1;
if(ddp_is_module_in_scenario(handle->scenario, wdma)==0)
{
DDPERR("dpmgr_path_remove_memout error, wdma is not in scenario=%s \n", ddp_get_scenario_name(handle->scenario));
// ASSERT(0);
return -1;
}
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[wdma]--;
context->module_path_table[wdma] = 0;
//wdma just need stop
if(ddp_modules_driver[wdma] != 0)
{
if(ddp_modules_driver[wdma]->stop!= 0)
{
ddp_modules_driver[wdma]->stop(wdma, cmdq_handle);
}
if(ddp_modules_driver[wdma]->deinit!= 0)
{
ddp_modules_driver[wdma]->deinit(wdma, cmdq_handle);
}
}
ddp_disconnect_path(DDP_SCENARIO_PRIMARY_OVL_MEMOUT,cmdq_handle);
handle->scenario = DDP_SCENARIO_PRIMARY_DISP;
// update connected
ddp_connect_path(handle->scenario,cmdq_handle);
ddp_mutex_set(handle->hwmutexid, handle->scenario, handle->mode, cmdq_handle);
return 0;
}
int dpmgr_insert_ovl1_sub(disp_path_handle dp_handle, void * cmdq_handle)
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
if((handle->scenario != DDP_SCENARIO_SUB_RDMA1_DISP) && (handle->scenario != DDP_SCENARIO_SUB_DISP))
{
DDPERR("dpmgr_insert_ovl1_sub error, handle->scenario=%s \n", ddp_get_scenario_name(handle->scenario));
return -1;
}
if(ddp_is_module_in_scenario(handle->scenario, DISP_MODULE_OVL1) == 1)
{
return -1;
}
DDPMSG("dpmgr_insert_ovl1_sub \n");
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[DISP_MODULE_OVL1]++;
context->module_path_table[DISP_MODULE_OVL1] = handle;
// update connected
ddp_connect_path(DDP_SCENARIO_SUB_DISP, cmdq_handle);
ddp_mutex_set(handle->hwmutexid, DDP_SCENARIO_SUB_DISP, handle->mode, cmdq_handle);
handle->scenario = DDP_SCENARIO_SUB_DISP;
//ovl1 just need start.
if(ddp_modules_driver[DISP_MODULE_OVL1] != 0)
{
if(ddp_modules_driver[DISP_MODULE_OVL1]->init!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->init(DISP_MODULE_OVL1, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->start!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->start(DISP_MODULE_OVL1, cmdq_handle);
}
}
ovl_set_status(DDP_OVL1_STATUS_SUB);
return 0;
}
int dpmgr_remove_ovl1_sub(disp_path_handle dp_handle, void * cmdq_handle)
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
if((handle->scenario != DDP_SCENARIO_SUB_RDMA1_DISP) && (handle->scenario != DDP_SCENARIO_SUB_DISP))
{
DDPERR("dpmgr_remove_ovl1_sub error, handle->scenario=%s \n", ddp_get_scenario_name(handle->scenario));
return -1;
}
if(ddp_is_module_in_scenario(handle->scenario, DISP_MODULE_OVL1) == 0)
{
return -1;
}
DDPMSG("dpmgr_remove_ovl1_sub \n");
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[DISP_MODULE_OVL1]--;
context->module_path_table[DISP_MODULE_OVL1] = 0;
ddp_disconnect_path(handle->scenario,cmdq_handle);
ddp_connect_path(DDP_SCENARIO_SUB_RDMA1_DISP,cmdq_handle);
ddp_mutex_set(handle->hwmutexid, DDP_SCENARIO_SUB_RDMA1_DISP, handle->mode, cmdq_handle);
handle->scenario = DDP_SCENARIO_SUB_RDMA1_DISP;
//ovl1 just need stop
if(ddp_modules_driver[DISP_MODULE_OVL1] != 0)
{
if(ddp_modules_driver[DISP_MODULE_OVL1]->stop!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->stop(DISP_MODULE_OVL1, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->deinit!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->deinit(DISP_MODULE_OVL1, cmdq_handle);
}
}
return 0;
}
disp_path_handle g_dp_handle;
void * g_cmdq_handle;
int dpmgr_path_get_handle(unsigned int* dp_handle, unsigned int* cmdq_handle)
{
*dp_handle = (unsigned long)g_dp_handle;
*cmdq_handle = (unsigned long)g_cmdq_handle;
}
int dpmgr_path_enable_cascade(disp_path_handle dp_handle, void * cmdq_handle )
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
// udpate handle
{
g_dp_handle = dp_handle;
g_cmdq_handle = cmdq_handle;
}
if((handle->scenario !=DDP_SCENARIO_PRIMARY_DISP) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_ALL) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_DITHER_MEMOUT) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_OVL_MEMOUT))
{
DDPERR("dpmgr_path_enable_cascade error, handle->scenario=%s \n", ddp_get_scenario_name(handle->scenario));
//ASSERT(0);
return -1;
}
if(ddp_is_module_in_scenario(handle->scenario, DISP_MODULE_OVL1)==1)
{
//DDPERR("dpmgr_path_enable_cascade error, OVL1 is already in scenario=%s \n", ddp_get_scenario_name(handle->scenario));
// ASSERT(0);
ovl_set_status(DDP_OVL1_STATUS_PRIMARY);
return -1;
}
DDPMSG("dpmgr_path_enable_cascade %s\n",ddp_get_scenario_name(handle->scenario));
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[DISP_MODULE_OVL1]++;
context->module_path_table[DISP_MODULE_OVL1] = handle;
// update connected
//ddp_insert_module(handle->scenario, DISP_MODULE_OVL0, DISP_MODULE_OVL1);
ddp_insert_module(DDP_SCENARIO_PRIMARY_DISP, DISP_MODULE_OVL0, DISP_MODULE_OVL1);
ddp_insert_module(DDP_SCENARIO_PRIMARY_ALL, DISP_MODULE_OVL0, DISP_MODULE_OVL1);
ddp_insert_module(DDP_SCENARIO_PRIMARY_OVL_MEMOUT, DISP_MODULE_OVL0, DISP_MODULE_OVL1);
ddp_insert_module(DDP_SCENARIO_PRIMARY_DITHER_MEMOUT, DISP_MODULE_OVL0, DISP_MODULE_OVL1);
ddp_connect_path(DDP_SCENARIO_MULTIPLE_OVL, cmdq_handle);
ddp_connect_path(handle->scenario, cmdq_handle);
ddp_mutex_add_module(handle->hwmutexid, DISP_MODULE_OVL1, cmdq_handle);
//ovl1 just need start.
if(ddp_modules_driver[DISP_MODULE_OVL1] != 0)
{
if(ddp_modules_driver[DISP_MODULE_OVL1]->cmd!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->cmd(DISP_MODULE_OVL1, DISP_IOCTL_OVL_ENABLE_CASCADE, 0, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->init!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->init(DISP_MODULE_OVL1, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->start!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->start(DISP_MODULE_OVL1, cmdq_handle);
}
}
if(ovl_get_status()!=DDP_OVL1_STATUS_PRIMARY && ovl_get_status()!=DDP_OVL1_STATUS_SUB_REQUESTING) // from primary-with-OVL1 to primary_all-with-OVL1 should not rebuild trigger loop cmdq
{
ovl_set_status(DDP_OVL1_STATUS_PRIMARY);
}
MMProfileLogEx(ddp_mmp_get_events()->cascade_enable, MMProfileFlagPulse, 0, 0);
return 0;
}
int dpmgr_path_disable_cascade(disp_path_handle dp_handle, void * cmdq_handle)
{
int ret = 0;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
if((handle->scenario !=DDP_SCENARIO_PRIMARY_DISP) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_ALL) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_DITHER_MEMOUT) &&
( handle->scenario !=DDP_SCENARIO_PRIMARY_OVL_MEMOUT))
{
DDPERR("dpmgr_path_disable_cascade error, handle->scenario=%s \n", ddp_get_scenario_name(handle->scenario));
// ASSERT(0);
return -1;
}
if(ddp_is_module_in_scenario(handle->scenario, DISP_MODULE_OVL1)==0)
{
//DDPERR("dpmgr_path_disable_cascade error, OVL1 is not in scenario=%s \n", ddp_get_scenario_name(handle->scenario));
// ASSERT(0);
return -1;
}
DDPMSG("dpmgr_path_disable_cascade %s\n",ddp_get_scenario_name(handle->scenario));
// update contxt
DDP_MANAGER_CONTEXT * context = _get_context();
context->module_usage_table[DISP_MODULE_OVL1]--;
context->module_path_table[DISP_MODULE_OVL1] = 0;
ddp_disconnect_path(DDP_SCENARIO_MULTIPLE_OVL, cmdq_handle);
//ddp_remove_module(handle->scenario, DISP_MODULE_OVL1);
ddp_remove_module(DDP_SCENARIO_PRIMARY_DISP, DISP_MODULE_OVL1);
ddp_remove_module(DDP_SCENARIO_PRIMARY_ALL, DISP_MODULE_OVL1);
ddp_remove_module(DDP_SCENARIO_PRIMARY_OVL_MEMOUT, DISP_MODULE_OVL1);
ddp_remove_module(DDP_SCENARIO_PRIMARY_DITHER_MEMOUT, DISP_MODULE_OVL1);
ddp_mutex_remove_module(handle->hwmutexid, DISP_MODULE_OVL1, cmdq_handle);
//ovl1 just need stop
if(ddp_modules_driver[DISP_MODULE_OVL1] != 0)
{
if(ddp_modules_driver[DISP_MODULE_OVL1]->cmd!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->cmd(DISP_MODULE_OVL1, DISP_IOCTL_OVL_DISABLE_CASCADE, 0, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->stop!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->stop(DISP_MODULE_OVL1, cmdq_handle);
}
if(ddp_modules_driver[DISP_MODULE_OVL1]->deinit!= 0)
{
ddp_modules_driver[DISP_MODULE_OVL1]->deinit(DISP_MODULE_OVL1, cmdq_handle);
}
}
MMProfileLogEx(ddp_mmp_get_events()->cascade_disable, MMProfileFlagPulse, 0, 0);
return 0;
}
int dpmgr_path_release_8_layer_fence()
{
unsigned int i=0;
for(i=OVL_LAYER_NUM_PER_OVL; i<OVL_LAYER_NUM; i++)
{
mtkfb_release_layer_fence(MAKE_DISP_SESSION(DISP_SESSION_PRIMARY,0), i);
}
}
int dpmgr_path_set_dst_module(disp_path_handle dp_handle,DISP_MODULE_ENUM dst_module)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
DISP_LOG_I("set dst module on scenario %s, module %s\n",
ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
return ddp_set_dst_module(handle->scenario, dst_module);
}
int dpmgr_path_get_mutex(disp_path_handle dp_handle)
{
ddp_path_handle handle = NULL;
ASSERT(dp_handle != NULL);
handle = (ddp_path_handle)dp_handle;
return handle->hwmutexid;
}
DISP_MODULE_ENUM dpmgr_path_get_dst_module(disp_path_handle dp_handle)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
ASSERT((handle->scenario >= 0 && handle->scenario < DDP_SCENARIO_MAX));
DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
DISP_LOG_V("get dst module on scenario %s, module %s\n",
ddp_get_scenario_name(handle->scenario),ddp_get_module_name(dst_module));
return dst_module;
}
int dpmgr_path_connect(disp_path_handle dp_handle, int encmdq)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("dpmgr_path_connect on scenario %s\n",ddp_get_scenario_name(handle->scenario));
ddp_connect_path(handle->scenario,cmdqHandle);
ddp_mutex_set(handle->hwmutexid,
handle->scenario,
handle->mode,
cmdqHandle);
ddp_mutex_Interrupt_enable(handle->hwmutexid,cmdqHandle);
return 0;
}
int dpmgr_path_disconnect(disp_path_handle dp_handle, int encmdq)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("dpmgr_path_disconnect on scenario %s\n",ddp_get_scenario_name(handle->scenario));
ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
ddp_mutex_Interrupt_disable(handle->hwmutexid,cmdqHandle);
ddp_disconnect_path(handle->scenario, cmdqHandle);
return 0;
}
int dpmgr_path_init(disp_path_handle dp_handle, int encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path init on scenario %s\n",ddp_get_scenario_name(handle->scenario));
//open top clock
path_top_clock_on();
//seting mutex
ddp_mutex_set(handle->hwmutexid,
handle->scenario,
handle->mode,
cmdqHandle);
ddp_mutex_Interrupt_enable(handle->hwmutexid,cmdqHandle);
//connect path;
ddp_connect_path(handle->scenario,cmdqHandle);
// each module init
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->init!= 0)
{
DISP_LOG_I("scenario %s init module %s\n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->init(module_name, cmdqHandle);
}
if(ddp_modules_driver[module_name]->set_listener!= 0)
{
ddp_modules_driver[module_name]->set_listener(module_name,dpmgr_module_notify);
}
}
}
//after init this path will power on;
handle->power_sate = 1;
return 0;
}
int dpmgr_path_deinit(disp_path_handle dp_handle, int encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path deinit on scenario %s\n",ddp_get_scenario_name(handle->scenario));
ddp_mutex_Interrupt_disable(handle->hwmutexid,cmdqHandle);
ddp_mutex_clear(handle->hwmutexid,cmdqHandle);
ddp_disconnect_path(handle->scenario, cmdqHandle);
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->deinit!= 0)
{
DISP_LOG_I("scenario %s deinit module %s\n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->deinit(module_name, cmdqHandle);
}
if(ddp_modules_driver[module_name]->set_listener!= 0)
{
ddp_modules_driver[module_name]->set_listener(module_name,NULL);
}
}
}
handle->power_sate = 0;
//close top clock when last path init
path_top_clock_off();
return 0;
}
int dpmgr_path_start(disp_path_handle dp_handle, int encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path start on scenario %s\n",ddp_get_scenario_name(handle->scenario));
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->start!= 0)
{
DISP_LOG_V("scenario %s start module %s\n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->start(module_name, cmdqHandle);
}
}
}
return 0;
}
int dpmgr_path_stop(disp_path_handle dp_handle, int encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path stop on scenario %s\n",ddp_get_scenario_name(handle->scenario));
for( i=module_num-1; i>=0;i--)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->stop!= 0)
{
DISP_LOG_V("scenario %s stop module %s \n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->stop(module_name, cmdqHandle);
}
}
}
return 0;
}
int dpmgr_path_ioctl(disp_path_handle dp_handle, void * cmdq_handle, DDP_IOCTL_NAME ioctl_cmd, unsigned long *params)
{
int i=0;
int ret = 0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("path IOCTL on scenario %s\n",ddp_get_scenario_name(handle->scenario));
for( i=module_num-1; i >= 0 ;i--)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->ioctl!= 0)
{
printk("scenario %s, module %s ioctl\n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ret += ddp_modules_driver[module_name]->ioctl(module_name, cmdq_handle, (unsigned int)ioctl_cmd, params);
}
}
}
return ret;
}
#ifdef CONFIG_SINGLE_PANEL_OUTPUT
int dpmgr_reset_module_handle(disp_path_handle dp_handle)
{
ddp_path_handle path_handle = NULL;
int module_name;
int i;
ASSERT(dp_handle != NULL);
path_handle=(ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(path_handle->scenario);
int module_num = ddp_get_module_num(path_handle->scenario);
DDP_MANAGER_CONTEXT * content = _get_context();
for( i=0; i< module_num; i++) {
module_name = modules[i];
DISP_LOG_I(" scenario %s reset module %s handle\n", ddp_get_scenario_name(path_handle->scenario),
ddp_get_module_name(module_name));
content->module_path_table[module_name] = path_handle;
}
return 0;
}
#endif
int dpmgr_path_reset(disp_path_handle dp_handle, int encmdq)
{
int i=0;
int ret = 0;
int error = 0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path reset on scenario %s\n",ddp_get_scenario_name(handle->scenario));
/* first reset mutex */
ddp_mutex_reset(handle->hwmutexid,cmdqHandle);
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->reset != 0)
{
DISP_LOG_I("scenario %s reset module %s \n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ret = ddp_modules_driver[module_name]->reset(module_name, cmdqHandle);
if(ret != 0)
{
error++;
}
}
}
}
return error > 0? -1: 0;
}
static int dpmgr_layer_num(disp_ddp_path_config * config)
{
int i=0;
int max_layer = 0;
for (i = 0; i < OVL_LAYER_NUM; i++)
{
if (config->ovl_config[i].layer_en != 0){
if(config->ovl_config[i].layer+1 > max_layer)
max_layer = config->ovl_config[i].layer+1;
}
}
return max_layer;
}
static unsigned int dpmgr_is_PQ(DISP_MODULE_ENUM module)
{
unsigned int isPQ = 0;
switch(module)
{
case DISP_MODULE_COLOR0:
case DISP_MODULE_CCORR :
case DISP_MODULE_AAL :
case DISP_MODULE_GAMMA :
case DISP_MODULE_DITHER:
//case DISP_MODULE_UFOE :
//case DISP_MODULE_PWM0 :
isPQ = 1;
break;
default:
isPQ = 0;
}
return isPQ;
}
extern int is_DAL_Enabled(void);
int dpmgr_path_config(disp_path_handle dp_handle, disp_ddp_path_config * config, void * cmdq_handle)
{
int i=0;
int ret = 0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
memcpy(&handle->last_config, config, sizeof(disp_ddp_path_config));
// switch between single and dual ovl mode
#ifdef OVL_CASCADE_SUPPORT
if((config->ovl_dirty==1) &&
(ovl_get_status()==DDP_OVL1_STATUS_IDLE)/* &&
dpmgr_layer_num(config)>=4*/)
{
//DDPMSG("cascade switch, call dpmgr_path_enable_cascade() in dpmgr_path_config()");
dpmgr_path_enable_cascade(dp_handle, cmdq_handle);
module_num = ddp_get_module_num(handle->scenario);
}
else if((config->ovl_dirty==1) && (ovl_get_status()==DDP_OVL1_STATUS_SUB_REQUESTING))
{
int enable_layers = dpmgr_layer_num(config);
if(enable_layers <= 4) {
DDPMSG("cascade switch, call dpmgr_path_disable_cascade() in dpmgr_path_config() %d\n", enable_layers);
dpmgr_path_disable_cascade(dp_handle, cmdq_handle);
module_num = ddp_get_module_num(handle->scenario);
ovl_set_status(DDP_OVL1_STATUS_PRIMARY_RELEASING);
} else {
DDPMSG("cascade: in path_config(), split ovl1 fail, enable_layers=%d\n", enable_layers);
}
}
#endif
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
#ifndef CONFIG_FPGA_EARLY_PORTING
#ifdef CONFIG_FOR_SOURCE_PQ
if (module_name == DISP_MODULE_COLOR0) {
extern void set_color_bypass(DISP_MODULE_ENUM module, int bypass, void* cmdq_handle);
set_color_bypass(DISP_MODULE_COLOR0, 1, cmdq_handle);
}
#endif
if(gDDPError==1 && dpmgr_is_PQ(module_name)==1)
#endif
{
if(ddp_modules_driver[module_name]->bypass!=NULL)
{
ddp_modules_driver[module_name]->bypass(module_name, 1);
//DDPMSG("-- bypass %s\n", ddp_get_module_name(module_name));
}
}
#ifndef CONFIG_FPGA_EARLY_PORTING
else if(ddp_modules_driver[module_name]->config!= 0)
#else
if(ddp_modules_driver[module_name]->config!= 0)
#endif
{
DISP_LOG_V("scenario %s config module %s \n",ddp_get_scenario_name(handle->scenario),
ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->config(module_name, config, cmdq_handle);
}
}
}
#ifdef OVL_CASCADE_SUPPORT
if(ovl_get_status()==DDP_OVL1_STATUS_PRIMARY_RELEASING)
{
ovl_set_status(DDP_OVL1_STATUS_PRIMARY_RELEASED);
}
if(config->ovl_dirty==1 && dpmgr_layer_num(config)==0 && disp_get_session_number()>1
&& ovl_get_status()!=DDP_OVL1_STATUS_SUB
&& ovl_get_status()!=DDP_OVL1_STATUS_IDLE) // all 8 layer disabled
{
DDPMSG("disable cascade if 8 layer all disabled! \n");
allLayerDisabled = 1;
ret = dpmgr_path_disable_cascade(dp_handle, cmdq_handle);
allLayerDisabled = 0;
ALL_LAYER_DISABLE_STEP = 1;
if(ret == 0 && ovl_get_status()==DDP_OVL1_STATUS_PRIMARY)
{
ovl_set_status(DDP_OVL1_STATUS_PRIMARY_DISABLE);
}
}
#endif
return 0;
}
disp_ddp_path_config *dpmgr_path_get_last_config(disp_path_handle dp_handle)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
handle->last_config.ovl_dirty =0;
handle->last_config.rdma_dirty =0;
handle->last_config.wdma_dirty =0;
handle->last_config.dst_dirty =0;
return &handle->last_config;
}
void dpmgr_get_input_address(disp_path_handle dp_handle, unsigned long * addr)
{
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
if (modules[0] == DISP_MODULE_OVL0 || modules[0] == DISP_MODULE_OVL1){
ovl_get_address(modules[0],addr);
}else if(modules[0] == DISP_MODULE_RDMA0 || modules[0] == DISP_MODULE_RDMA1
|| modules[0] == DISP_MODULE_RDMA2){
rdma_get_address(modules[0],addr);
}
return ;
}
int dpmgr_path_build_cmdq(disp_path_handle dp_handle, void *trigger_loop_handle, CMDQ_STATE state)
{
int ret = 0;
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DDP_SCENARIO_ENUM scenario = handle->scenario;
int * modules = ddp_get_scenario_list(scenario);
int module_num = ddp_get_module_num(scenario);
DISP_LOG_D("path build cmdq on scenario %s\n",ddp_get_scenario_name(scenario));
#if defined(MANUAL_MUTEX_HW_DCM)
if (state == CMDQ_BEFORE_STREAM_SOF)
{
ddp_mutex_hw_dcm_off(handle->hwmutexid,trigger_loop_handle);
}
if (state == CMDQ_AFTER_STREAM_EOF)
{
ddp_mutex_hw_dcm_on(handle->hwmutexid,trigger_loop_handle);
}
#endif
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->build_cmdq!= 0)
{
DISP_LOG_D("%s build cmdq, state=%d\n",ddp_get_module_name(module_name), state);
ret = ddp_modules_driver[module_name]->build_cmdq(module_name, trigger_loop_handle, state); // now just 0;
}
}
}
return ret;
}
int dpmgr_path_trigger(disp_path_handle dp_handle, void *trigger_loop_handle, int encmdq)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DISP_LOG_V("dpmgr_path_trigger on scenario %s\n",ddp_get_scenario_name(handle->scenario));
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
int i=0;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
int module_name ;
ddp_mutex_enable(handle->hwmutexid,handle->scenario,trigger_loop_handle);
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->trigger!= 0)
{
DISP_LOG_V("%s trigger\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->trigger(module_name, trigger_loop_handle);
}
}
}
return 0;
}
int dpmgr_path_flush(disp_path_handle dp_handle,int encmdq)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
cmdqRecHandle cmdqHandle = encmdq ? handle->cmdqhandle : NULL;
DISP_LOG_I("path flush on scenario %s\n",ddp_get_scenario_name(handle->scenario));
return ddp_mutex_enable(handle->hwmutexid,handle->scenario,cmdqHandle);
}
int dpmgr_wdma_path_force_power_off(void)
{
int i=0;
int module_name ;
#ifdef WDMA_PATH_CLOCK_DYNAMIC_SWITCH
#ifdef CONFIG_FOR_SOURCE_PQ
DDP_SCENARIO_ENUM scenario = DDP_SCENARIO_PRIMARY_DITHER_MEMOUT;
#else
DDP_SCENARIO_ENUM scenario = DDP_SCENARIO_PRIMARY_OVL_MEMOUT;
#endif
int * modules = ddp_get_scenario_list(scenario);
int module_num = ddp_get_module_num(scenario);
DISP_LOG_I("wdma path power off on scenario %s\n",ddp_get_scenario_name(scenario));
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_off!= 0)
{
DISP_LOG_V(" %s power off\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_off(module_name, NULL); // now just 0;
}
}
}
#endif
return 0;
}
int dpmgr_wdma_path_force_power_on(void)
{
int i=0;
int module_name ;
#ifdef WDMA_PATH_CLOCK_DYNAMIC_SWITCH
#ifdef CONFIG_FOR_SOURCE_PQ
DDP_SCENARIO_ENUM scenario = DDP_SCENARIO_PRIMARY_DITHER_MEMOUT;
#else
DDP_SCENARIO_ENUM scenario = DDP_SCENARIO_PRIMARY_OVL_MEMOUT;
#endif
int * modules = ddp_get_scenario_list(scenario);
int module_num = ddp_get_module_num(scenario);
DISP_LOG_I("wdma path power on scenario %s\n",ddp_get_scenario_name(scenario));
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_on!= 0)
{
DISP_LOG_V("%s power on\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_on(module_name, NULL); // now just 0;
}
}
}
#endif
return 0;
}
int dpmgr_path_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("path power off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_off!= 0)
{
DISP_LOG_V(" %s power off\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
}
}
}
handle->power_sate = 0;
path_top_clock_off();
return 0;
}
int dpmgr_path_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("path power on scenario %s\n",ddp_get_scenario_name(handle->scenario));
path_top_clock_on();
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_on!= 0)
{
DISP_LOG_V("%s power on\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
}
}
}
//modules on this path will resume power on;
handle->power_sate = 1;
return 0;
}
int dpmgr_path_dsi_power_off(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
module_name=dst_module;
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_off!= 0)
{
DISP_LOG_V(" %s power off\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_off(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
}
}
return 0;
}
int dpmgr_path_dsi_power_on(disp_path_handle dp_handle, CMDQ_SWITCH encmdq)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
module_name=dst_module;
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_on!= 0)
{
DISP_LOG_V("%s power on\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->power_on(module_name, encmdq?handle->cmdqhandle:NULL); // now just 0;
}
}
return 0;
}
int dpmgr_path_dsi_off(disp_path_handle dp_handle, void * cmdq_handle,unsigned int level)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
module_name=dst_module;
// printk("ddp_idle dsi_off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
if( module_name >= 0 && module_name < DISP_MODULE_UNKNOWN){
ddp_modules_driver[module_name]->ioctl(module_name, cmdq_handle, DDP_DSI_IDLE_CLK_CLOSED,&level);
}else{
DISP_LOG_E("dpmgr_path_dsi_off unknow module %d",module_name);
}
ddp_path_lp_top_clock_off();
}
int dpmgr_path_dsi_on(disp_path_handle dp_handle, void * cmdq_handle,unsigned int level)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_MODULE_ENUM dst_module = ddp_get_dst_module(handle->scenario);
module_name = dst_module;
// printk("ddp_idle dsi_on scenario %s\n",ddp_get_scenario_name(handle->scenario));
ddp_path_lp_top_clock_on();
if( module_name >= 0 && module_name < DISP_MODULE_UNKNOWN){
ddp_modules_driver[module_name]->ioctl(module_name, cmdq_handle, DDP_DSI_IDLE_CLK_OPEN, &level);
}else{
DISP_LOG_E("dpmgr_path_dsi_on unknow module %d",module_name);
}
return 0;
}
int dpmgr_path_idle_off(disp_path_handle dp_handle, void * cmdq_handle,unsigned int level)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("ddp_idle off on scenario %s\n",ddp_get_scenario_name(handle->scenario));
// For DSI CMD mode, do not clock pwm_26M, used to make sure MM clock off but MTCMOS on
if(primary_display_is_video_mode()==0)
{
enable_clock(MT_CG_PERI_DISP_PWM, "screen_idle");
}
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_off!= 0)
{
DISP_LOG_V(" %s power off\n",ddp_get_module_name(module_name));
if(!((module_name == DISP_MODULE_DSIDUAL) || (module_name == DISP_MODULE_DSI0) || (module_name == DISP_MODULE_DSI1)))
ddp_modules_driver[module_name]->power_off(module_name, cmdq_handle);
else
ddp_modules_driver[module_name]->ioctl(module_name, cmdq_handle, DDP_DSI_IDLE_CLK_CLOSED,&level);
}
}
}
//dpmgr_path_dsi_off(dp_handle,cmdq_handle,level);
handle->power_sate = 0;
path_top_clock_off();
}
int dpmgr_path_idle_on(disp_path_handle dp_handle, void * cmdq_handle,unsigned int level)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("ddp_idle on scenario %s\n",ddp_get_scenario_name(handle->scenario));
path_top_clock_on();
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->power_on!= 0)
{
DISP_LOG_V("%s power on\n",ddp_get_module_name(module_name));
if(!((module_name == DISP_MODULE_DSIDUAL) || (module_name == DISP_MODULE_DSI0) || (module_name == DISP_MODULE_DSI1)))
ddp_modules_driver[module_name]->power_on(module_name, cmdq_handle);
else
ddp_modules_driver[module_name]->ioctl(module_name, cmdq_handle, DDP_DSI_IDLE_CLK_OPEN, &level);
}
}
}
// clock on PEM_26M one more time when idle off, so need clock off it here
if(primary_display_is_video_mode()==0)
{
disable_clock(MT_CG_PERI_DISP_PWM, "screen_idle");
}
handle->power_sate = 1;
return 0;
}
static int is_module_in_path(DISP_MODULE_ENUM module,ddp_path_handle handle)
{
DDP_MANAGER_CONTEXT * context = _get_context();
ASSERT(module <DISP_MODULE_UNKNOWN);
if(context->module_path_table[module]==handle)
{
return 1;
}
return 0;
}
int dpmgr_path_user_cmd(disp_path_handle dp_handle, int msg, unsigned long arg, void *cmdqhandle)
{
int ret = -1;
DISP_MODULE_ENUM dst = DISP_MODULE_UNKNOWN;
ddp_path_handle handle = NULL;
ASSERT(dp_handle != NULL);
handle = (ddp_path_handle)dp_handle;
//DISP_LOG_W("dpmgr_path_user_cmd msg 0x%08x\n",msg);
switch(msg)
{
case DISP_IOCTL_AAL_EVENTCTL:
case DISP_IOCTL_AAL_GET_HIST:
case DISP_IOCTL_AAL_INIT_REG:
case DISP_IOCTL_AAL_SET_PARAM:
{
//TODO: just for verify rootcause, will be removed soon
#ifndef CONFIG_FOR_SOURCE_PQ
if(is_module_in_path(DISP_MODULE_AAL,handle))
{
if(ddp_modules_driver[DISP_MODULE_AAL]->cmd!=NULL)
{
ret = ddp_modules_driver[DISP_MODULE_AAL]->cmd(DISP_MODULE_AAL,msg,arg,
cmdqhandle);
}
}
#endif
break;
}
case DISP_IOCTL_SET_GAMMALUT:
if(ddp_modules_driver[DISP_MODULE_GAMMA]->cmd!=NULL)
{
ret = ddp_modules_driver[DISP_MODULE_GAMMA]->cmd(DISP_MODULE_GAMMA,msg,arg,
cmdqhandle);
}
break;
case DISP_IOCTL_SET_CCORR:
if(ddp_modules_driver[DISP_MODULE_CCORR]->cmd!=NULL)
{
ret = ddp_modules_driver[DISP_MODULE_CCORR]->cmd(DISP_MODULE_CCORR,msg,arg,
cmdqhandle);
}
break;
case DISP_IOCTL_SET_PQPARAM:
case DISP_IOCTL_GET_PQPARAM:
case DISP_IOCTL_SET_PQINDEX:
case DISP_IOCTL_GET_PQINDEX:
case DISP_IOCTL_SET_TDSHPINDEX:
case DISP_IOCTL_GET_TDSHPINDEX:
case DISP_IOCTL_SET_PQ_CAM_PARAM:
case DISP_IOCTL_GET_PQ_CAM_PARAM:
case DISP_IOCTL_SET_PQ_GAL_PARAM:
case DISP_IOCTL_GET_PQ_GAL_PARAM:
case DISP_IOCTL_PQ_SET_BYPASS_COLOR:
case DISP_IOCTL_PQ_SET_WINDOW:
case DISP_IOCTL_READ_REG:
case DISP_IOCTL_MUTEX_CONTROL:
case DISP_IOCTL_PQ_GET_TDSHP_FLAG:
case DISP_IOCTL_PQ_SET_TDSHP_FLAG:
case DISP_IOCTL_PQ_GET_DC_PARAM:
case DISP_IOCTL_PQ_SET_DC_PARAM:
case DISP_IOCTL_WRITE_SW_REG:
case DISP_IOCTL_READ_SW_REG:
{
if(is_module_in_path(DISP_MODULE_COLOR0,handle))
{
dst = DISP_MODULE_COLOR0;
}
else if(is_module_in_path(DISP_MODULE_COLOR1,handle))
{
dst = DISP_MODULE_COLOR1;
}
else
{
DISP_LOG_W("dpmgr_path_user_cmd color is not on this path\n");
}
if(dst != DISP_MODULE_UNKNOWN)
{
if(ddp_modules_driver[dst]->cmd!=NULL)
{
ret = ddp_modules_driver[dst]->cmd(dst,msg,arg,
cmdqhandle);
}
}
break;
}
/*
case DISP_IOCTL_OD_CTL:
{
if(is_module_in_path(DISP_MODULE_OD,handle))
{
if(ddp_modules_driver[DISP_MODULE_OD]->cmd!=NULL)
{
ret = ddp_modules_driver[DISP_MODULE_OD]->cmd(DISP_MODULE_OD,msg,arg,
cmdqhandle);
}
}
break;
}*/
default:
{
DISP_LOG_W("dpmgr_path_user_cmd io not supported\n");
break;
}
}
return ret;
}
int dpmgr_path_set_parameter(disp_path_handle dp_handle, int io_evnet, void * data)
{
return 0;
}
int dpmgr_path_get_parameter(disp_path_handle dp_handle,int io_evnet, void * data )
{
return 0;
}
int dpmgr_path_is_idle(disp_path_handle dp_handle)
{
ASSERT(dp_handle != NULL);
return !dpmgr_path_is_busy(dp_handle);
}
int dpmgr_path_is_busy(disp_path_handle dp_handle)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_V("path check busy on scenario %s\n",ddp_get_scenario_name(handle->scenario));
for( i=module_num-1; i>=0;i--)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->is_busy!= 0)
{
if(ddp_modules_driver[module_name]->is_busy(module_name))
{
DISP_LOG_V("%s is busy\n", ddp_get_module_name(module_name));
return 1;
}
}
}
}
return 0;
}
int dpmgr_set_lcm_utils(disp_path_handle dp_handle, void *lcm_drv)
{
int i=0;
int module_name ;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_V("path set lcm drv handle %p\n",handle);
for( i=0; i< module_num;i++)
{
module_name = modules[i];
if(ddp_modules_driver[module_name] != 0)
{
if((ddp_modules_driver[module_name]->set_lcm_utils!= 0)&&lcm_drv)
{
DISP_LOG_I("%s set lcm utils\n",ddp_get_module_name(module_name));
ddp_modules_driver[module_name]->set_lcm_utils(module_name, lcm_drv); // now just 0;
}
}
}
return 0;
}
int dpmgr_enable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
DISP_LOG_I("enable event %s on scenario %s, irtbit 0x%x\n",
path_event_name(event),
ddp_get_scenario_name(handle->scenario),
handle->irq_event_map[event].irq_bit);
if(!wq_handle->init)
{
init_waitqueue_head(&(wq_handle->wq));
wq_handle->init = 1;
wq_handle->data= 0;
wq_handle->event = event;
}
return 0;
}
int dpmgr_map_event_to_irq(disp_path_handle dp_handle, DISP_PATH_EVENT event, DDP_IRQ_BIT irq_bit)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DDP_IRQ_EVENT_MAPPING *irq_table = handle->irq_event_map;
if(event < DISP_PATH_EVENT_NUM)
{
DISP_LOG_I("map event %s to irq 0x%x on scenario %s\n",path_event_name(event),irq_bit,ddp_get_scenario_name(handle->scenario));
irq_table[event].irq_bit= irq_bit;
return 0;
}
DISP_LOG_E("fail to map event %s to irq 0x%x on scenario %s\n",path_event_name(event),irq_bit,ddp_get_scenario_name(handle->scenario));
return -1;
}
int dpmgr_disable_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DISP_LOG_I("disable event %s on scenario %s \n",path_event_name(event),ddp_get_scenario_name(handle->scenario));
DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
wq_handle->init = 0;
wq_handle->data= 0;
return 0;
}
int dpmgr_check_status(disp_path_handle dp_handle)
{
int i =0;
int module_name ;
if(dp_handle == NULL )
{
DISP_LOG_E("check status with NULL handle is invalid.\n");
return -1; // avoid kernel to access invalid address.
}
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
int * modules = ddp_get_scenario_list(handle->scenario);
int module_num = ddp_get_module_num(handle->scenario);
DISP_LOG_I("check status on scenario %s\n",
ddp_get_scenario_name(handle->scenario));
ddp_dump_analysis(DISP_MODULE_CONFIG);
ddp_check_path(handle->scenario);
ddp_check_mutex(handle->hwmutexid,handle->scenario,
handle->mode);
// dump path
{
DDPMSG("path:");
for(i=0;i<module_num;i++)
{
printk("%s-", ddp_get_module_name(modules[i]));
}
printk("\n");
}
ddp_dump_analysis(DISP_MODULE_MUTEX);
for( i=0; i< module_num;i++)
{
ddp_dump_analysis(modules[i]);
}
for( i=0; i< module_num;i++)
{
ddp_dump_reg(modules[i]);
}
ddp_dump_reg(DISP_MODULE_CONFIG);
ddp_dump_reg(DISP_MODULE_MUTEX);
dump_stack();
return 0;
}
void dpmgr_debug_path_status(int mutex_id)
{
int i=0;
DDP_MANAGER_CONTEXT * content = _get_context();
disp_path_handle handle=NULL;
if(mutex_id >=DISP_MUTEX_DDP_FIRST && mutex_id < (DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT))
{
handle = (disp_path_handle)content->handle_pool[mutex_id];
if(handle)
{
dpmgr_check_status(handle);
}
}
else
{
for(i=DISP_MUTEX_DDP_FIRST; i<(DISP_MUTEX_DDP_FIRST+DISP_MUTEX_DDP_COUNT);i++)
{
handle = (disp_path_handle)content->handle_pool[i];
if(handle)
{
dpmgr_check_status(handle);
}
}
}
return ;
}
int dpmgr_wait_event_timeout(disp_path_handle dp_handle, DISP_PATH_EVENT event, int timeout)
{
int ret = -1;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
if(wq_handle->init)
{
DISP_LOG_V("wait event %s on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
unsigned long long cur_time = sched_clock();
ret = wait_event_interruptible_timeout(wq_handle->wq, cur_time < wq_handle->data,timeout);
if(ret == 0)
{
DISP_LOG_E("wait %s timeout on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
MMProfileLogEx(ddp_mmp_get_events()->dpmgr_wait_event_timeout, MMProfileFlagPulse, ddp_get_scenario_name(handle->scenario), event);
dpmgr_check_status(dp_handle);
// dpmgr_path_reset(dp_handle, 0);
// gDDPError = 1;
}
else if(ret < 0)
{
DISP_LOG_E("wait %s interrupt by other timeleft %d on scenario %s\n", path_event_name(event),ret,ddp_get_scenario_name(handle->scenario));
}
else
{
DISP_LOG_V("received event %s timeleft %d on scenario %s\n", path_event_name(event), ret,ddp_get_scenario_name(handle->scenario));
}
return ret;
}
DISP_LOG_E("wait event %s not initialized on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
return ret;
}
int dpmgr_wait_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
{
int ret = -1;
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DPMGR_WQ_HANDLE *wq_handle = & handle->wq_list[event];
if(wq_handle->init)
{
DISP_LOG_V("wait event %s on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
unsigned long long cur_time = sched_clock();
ret = wait_event_interruptible(wq_handle->wq, cur_time < wq_handle->data);
if(ret < 0)
{
DISP_LOG_E("wait %s interrupt by other ret %d on scenario %s\n", path_event_name(event), ret,ddp_get_scenario_name(handle->scenario));
}
else
{
DISP_LOG_V("received event %s ret %d on scenario %s\n", path_event_name(event), ret,ddp_get_scenario_name(handle->scenario));
}
return ret;
}
DISP_LOG_E("wait event %s not initialized on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
return ret;
}
int dpmgr_signal_event(disp_path_handle dp_handle, DISP_PATH_EVENT event)
{
ASSERT(dp_handle != NULL);
ddp_path_handle handle = (ddp_path_handle)dp_handle;
DPMGR_WQ_HANDLE *wq_handle = &handle->wq_list[event];
if(handle->wq_list[event].init)
{
wq_handle->data = sched_clock();
DISP_LOG_V("wake up evnet %s on scenario %s\n", path_event_name(event),ddp_get_scenario_name(handle->scenario));
wake_up_interruptible(&(handle->wq_list[event].wq));
}
return 0;
}
static void dpmgr_irq_handler(DISP_MODULE_ENUM module,unsigned int regvalue)
{
int i = 0;
int j = 0;
int irq_bits_num =0;
int irq_bit = 0;
ddp_path_handle handle = NULL;
irq_bits_num = ddp_get_module_max_irq_bit(module);
for(i = 0; i<=irq_bits_num; i++)
{
if(regvalue & (0x1<<i))
{
if(module == DISP_MODULE_MUTEX)
{
if(i < irq_bits_num/2)
handle = hw_mutex_id_to_handle_map[i];
else
handle = hw_mutex_id_to_handle_map[i%(irq_bits_num/2)];
}
else
{
handle = find_handle_by_module(module);
}
if(handle == NULL)
{
continue;
}
irq_bit = MAKE_DDP_IRQ_BIT(module,i);
dprec_stub_irq(irq_bit);
for(j = 0; j < DISP_PATH_EVENT_NUM; j++)
{
if(handle->wq_list[j].init && irq_bit == handle->irq_event_map[j].irq_bit)
{
dprec_stub_event(j);
handle->wq_list[j].data =sched_clock();
DDPIRQ("irq signal event %s on cycle %llu on scenario %s\n", path_event_name(j), handle->wq_list[j].data ,ddp_get_scenario_name(handle->scenario));
wake_up_interruptible(&(handle->wq_list[j].wq));
//MMProfileLogEx(ddp_mmp_get_events()->primary_wakeup, MMProfileFlagPulse, j, irq_bit);
}
}
}
}
return ;
}
int dpmgr_init(void)
{
DISP_LOG_I("ddp manager init\n");
if (ddp_manager_init)
return 0;
ddp_manager_init = 1;
ddp_debug_init();
disp_init_irq();
disp_register_irq_callback(dpmgr_irq_handler);
memset((void*)hw_mutex_id_to_handle_map, 0, sizeof(hw_mutex_id_to_handle_map));
return 0;
}
int dpmgr_factory_mode_test(int module_name, void *cmdqhandle, void *config)
{
if(ddp_modules_driver[module_name] != 0)
{
if(ddp_modules_driver[module_name]->ioctl!= 0)
{
DISP_LOG_I(" %s factory_mode_test\n",ddp_get_module_name(DISP_MODULE_DPI));
ddp_modules_driver[DISP_MODULE_DPI]->ioctl(module_name, cmdqhandle, DDP_DPI_FACTORY_TEST, config);
}
}
return 0;
}
|