summaryrefstree
path: root/kernel/drivers/video/fbdev/exynos/dpu20/event_log.c
blob: ffe5cb80d14e1a56e03573ff3a5acc421b26e203 (plain)
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
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
/*
 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
 *		http://www.samsung.com
 *
 * DPU Event log file for Samsung EXYNOS DPU driver
 *
 * 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/ktime.h>
#include <linux/debugfs.h>
#include <media/v4l2-subdev.h>
#include <video/mipi_display.h>
#ifdef CONFIG_SUPPORT_RDX_DUMP
#include <linux/bootmem.h>
#include <linux/slab.h>
#ifdef CONFIG_NO_BOOTMEM
#include <linux/memblock.h>
#endif
#endif

#include "decon.h"
#include "dsim.h"
#include "dpp.h"

#if defined(CONFIG_EXYNOS_COMMON_PANEL)
const char dpu_event_dtype_name[MAX_DPU_EVT_DTYPE][MAX_EVENT_NAME_SIZE] = {
	[DPU_EVT_DTYPE_NONE] = "NONE",
	[DPU_EVT_DTYPE_DPP] = "DPP",
	[DPU_EVT_DTYPE_UPDATE_REG] = "UPDATE_REG",
	[DPU_EVT_DTYPE_WIN_REG] = "WIN_REG",
	[DPU_EVT_DTYPE_WIN_CONFIG] = "WIN_CONFIG",
	[DPU_EVT_DTYPE_WIN] = "WIN",
	[DPU_EVT_DTYPE_CMD_BUF] = "CMD_BUF",
	[DPU_EVT_DTYPE_PM] = "PM",
	[DPU_EVT_DTYPE_FENCE] = "FENCE",
	[DPU_EVT_DTYPE_CURSOR] = "CURSOR",
	[DPU_EVT_DTYPE_WINUP] = "WINUP",
};

const char dpu_event_name[DPU_EVT_MAX][MAX_EVENT_NAME_SIZE] = {
	/* Related with FB interface */
	[DPU_EVT_BLANK] = "BLANK",
	[DPU_EVT_UNBLANK] = "UNBLANK",
	[DPU_EVT_ACT_VSYNC] = "ACT_VSYNC",
	[DPU_EVT_DEACT_VSYNC] = "DEACT_VSYNC",
	[DPU_EVT_WIN_CONFIG] = "WIN_CONFIG",
	[DPU_EVT_DISP_INFO] = "DISP_INFO",

	/* Related with interrupt */
	[DPU_EVT_TE_INTERRUPT] = "TE_INTERRUPT",
	[DPU_EVT_UNDERRUN] = "UNDERRUN",
	[DPU_EVT_DECON_FRAMEDONE] = "DECON_FRAMEDONE",
	[DPU_EVT_DSIM_FRAMEDONE] = "DSIM_FRAMEDONE",
	[DPU_EVT_RSC_CONFLICT] = "RSC_CONFLICT",

	/* Related with async event */
	[DPU_EVT_UPDATE_HANDLER] = "UPDATE_HANDLER",

	[DPU_EVT_UPDATE_HANDLER_WIN_REG_0] = "WIN_REG_0",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_1] = "WIN_REG_1",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_2] = "WIN_REG_2",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_3] = "WIN_REG_3",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_4] = "WIN_REG_4",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_5] = "WIN_REG_5",
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_6] = "WIN_REG_6",

	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_0] = "WIN_CONFIG_0",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_1] = "WIN_CONFIG_1",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_2] = "WIN_CONFIG_2",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_3] = "WIN_CONFIG_3",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_4] = "WIN_CONFIG_4",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_5] = "WIN_CONFIG_5",
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_6] = "WIN_CONFIG_6",

	[DPU_EVT_UPDATE_HANDLER_WIN] = "WIN",

	[DPU_EVT_DSIM_COMMAND] = "DSIM_COMMAND",
	[DPU_EVT_TRIG_MASK] = "TRIG_MASK",
	[DPU_EVT_TRIG_UNMASK] = "TRIG_UNMASK",
	[DPU_EVT_FENCE_RELEASE] = "FENCE_RELEASE",
	[DPU_EVT_DECON_FRAMEDONE_WAIT] = "DECON_FRAMEDONE_WAIT",
	[DPU_EVT_DECON_SHUTDOWN] = "DECON_SHUTDOWN",
	[DPU_EVT_DSIM_SHUTDOWN] = "DSIM_SHUTDOWN",
	[DPU_EVT_DECON_FRAMESTART] = "DECON_FRAMESTART",

	/* Related with DPP */
	[DPU_EVT_DPP_WINCON] = "DPP_WINCON",
	[DPU_EVT_DPP_FRAMEDONE] = "DPP_FRAMEDONE",
	[DPU_EVT_DPP_STOP] = "DPP_STOP",
	[DPU_EVT_DPP_UPDATE_DONE] = "DPP_UPDATE_DONE",
	[DPU_EVT_DPP_SHADOW_UPDATE] = "DPP_SHADOW_UPDATE",
	[DPU_EVT_DPP_SUSPEND] = "DPP_SUSPEND",
	[DPU_EVT_DPP_RESUME] = "DPP_RESUME",

	/* Related with PM */
	[DPU_EVT_DECON_SUSPEND] = "DECON_SUSPEND",
	[DPU_EVT_DECON_RESUME] = "DECON_RESUME",
	[DPU_EVT_ENTER_HIBER] = "ENTER_HIBER",
	[DPU_EVT_EXIT_HIBER] = "EXIT_HIBER",
	[DPU_EVT_DSIM_SUSPEND] = "DSIM_SUSPEND",
	[DPU_EVT_DSIM_RESUME] = "DSIM_RESUME",
	[DPU_EVT_ENTER_ULPS] = "ENTER_ULPS",
	[DPU_EVT_EXIT_ULPS] = "EXIT_ULPS",

	[DPU_EVT_LINECNT_ZERO] = "LINECNT_ZERO",

	/* write-back events */
	[DPU_EVT_WB_SET_BUFFER] = "WB_SET_BUFFER",
	[DPU_EVT_WB_SW_TRIGGER] = "WB_SW_TRIGGER",

	[DPU_EVT_DMA_FRAMEDONE] = "DMA_FRAMEDONE",
	[DPU_EVT_DMA_RECOVERY] = "DMA_RECOVERY",

	[DPU_EVT_DECON_SET_BUFFER] = "DECON_SET_BUFFER",
	/* cursor async */
	[DPU_EVT_CURSOR_POS] = "CURSOR_POS",
	[DPU_EVT_CURSOR_UPDATE] = "CURSOR_UPDATE",

	/* window update */
	[DPU_EVT_WINUP_UPDATE_REGION] = "WINUP_UPDATE_REGION",
	[DPU_EVT_WINUP_FLAGS] = "WINUP_FLAGS",
	[DPU_EVT_WINUP_APPLY_REGION] = "WINUP_APPLY_REGION",

	[DPU_EVT_DOZE] = "DOZE",
	[DPU_EVT_DOZE_SUSPEND] = "DOZE_SUSPEND",
};

dpu_event_t dpu_event_dtype[DPU_EVT_MAX] = {
	/* Related with FB interface */
	[DPU_EVT_BLANK] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_UNBLANK] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_ACT_VSYNC] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_DEACT_VSYNC] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_WIN_CONFIG] = DPU_EVT_DTYPE_FENCE,
	[DPU_EVT_DISP_INFO] = DPU_EVT_DTYPE_NONE,

	/* Related with interrupt */
	[DPU_EVT_TE_INTERRUPT] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_UNDERRUN] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_DECON_FRAMEDONE] = DPU_EVT_DTYPE_FENCE,
	[DPU_EVT_DSIM_FRAMEDONE] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_RSC_CONFLICT] = DPU_EVT_DTYPE_NONE,

	/* Related with async event */
	[DPU_EVT_UPDATE_HANDLER] = DPU_EVT_DTYPE_UPDATE_REG,

	[DPU_EVT_UPDATE_HANDLER_WIN_REG_0] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_1] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_2] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_3] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_4] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_5] = DPU_EVT_DTYPE_WIN_REG,
	[DPU_EVT_UPDATE_HANDLER_WIN_REG_6] = DPU_EVT_DTYPE_WIN_REG,

	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_0] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_1] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_2] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_3] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_4] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_5] = DPU_EVT_DTYPE_WIN_CONFIG,
	[DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_6] = DPU_EVT_DTYPE_WIN_CONFIG,

	[DPU_EVT_UPDATE_HANDLER_WIN] = DPU_EVT_DTYPE_WIN,

	[DPU_EVT_DSIM_COMMAND] = DPU_EVT_DTYPE_CMD_BUF,
	[DPU_EVT_TRIG_MASK] = DPU_EVT_DTYPE_FENCE,
	[DPU_EVT_TRIG_UNMASK] = DPU_EVT_DTYPE_FENCE,
	[DPU_EVT_FENCE_RELEASE] = DPU_EVT_DTYPE_FENCE,
	[DPU_EVT_DECON_FRAMEDONE_WAIT] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_DECON_SHUTDOWN] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_DSIM_SHUTDOWN] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_DECON_FRAMESTART] = DPU_EVT_DTYPE_NONE,

	/* Related with DPP */
	[DPU_EVT_DPP_WINCON] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DPP_FRAMEDONE] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DPP_STOP] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DPP_UPDATE_DONE] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DPP_SHADOW_UPDATE] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DPP_SUSPEND] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_DPP_RESUME] = DPU_EVT_DTYPE_PM,

	/* Related with PM */
	[DPU_EVT_DECON_SUSPEND] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_DECON_RESUME] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_ENTER_HIBER] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_EXIT_HIBER] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_DSIM_SUSPEND] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_DSIM_RESUME] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_ENTER_ULPS] = DPU_EVT_DTYPE_PM,
	[DPU_EVT_EXIT_ULPS] = DPU_EVT_DTYPE_PM,

	[DPU_EVT_LINECNT_ZERO] = DPU_EVT_DTYPE_NONE,

	/* write-back events */
	[DPU_EVT_WB_SET_BUFFER] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_WB_SW_TRIGGER] = DPU_EVT_DTYPE_NONE,

	[DPU_EVT_DMA_FRAMEDONE] = DPU_EVT_DTYPE_DPP,
	[DPU_EVT_DMA_RECOVERY] = DPU_EVT_DTYPE_DPP,

	[DPU_EVT_DECON_SET_BUFFER] = DPU_EVT_DTYPE_NONE,
	/* cursor async */
	[DPU_EVT_CURSOR_POS] = DPU_EVT_DTYPE_CURSOR,
	[DPU_EVT_CURSOR_UPDATE] = DPU_EVT_DTYPE_UPDATE_REG,

	/* window update */
	[DPU_EVT_WINUP_UPDATE_REGION] = DPU_EVT_DTYPE_WINUP,
	[DPU_EVT_WINUP_FLAGS] = DPU_EVT_DTYPE_WINUP,
	[DPU_EVT_WINUP_APPLY_REGION] = DPU_EVT_DTYPE_WINUP,

	[DPU_EVT_DOZE] = DPU_EVT_DTYPE_NONE,
	[DPU_EVT_DOZE_SUSPEND] = DPU_EVT_DTYPE_NONE,
};

static inline void dpu_event_log_header(struct decon_device *decon, u32 log_cnt)
{
	struct dpu_log_header *header;

	if (IS_ERR_OR_NULL(decon->d.event_log_header))
		return;

	header = decon->d.event_log_header;
	header->magic = DPU_LOG_VALID_MARK;
	header->header_size = (u32)sizeof(struct dpu_log_header);
	header->log_size = (u32)sizeof(struct dpu_log) * log_cnt;
	header->log_cnt = log_cnt;
	header->name_len = MAX_EVENT_NAME_SIZE;

	header->event_name_size = (u32)sizeof(dpu_event_name);
	header->event_dtype_name_size = (u32)sizeof(dpu_event_dtype_name);
	header->event_dtype_size = (u32)sizeof(dpu_event_dtype);

	memcpy(header->event_name, dpu_event_name, sizeof(dpu_event_name));
	memcpy(header->event_dtype_name, dpu_event_dtype_name, sizeof(dpu_event_dtype_name));
	memcpy(header->event_dtype, dpu_event_dtype, sizeof(dpu_event_dtype));
}
#endif /* CONFIG_EXYNOS_COMMON_PANEL */

/* DPU fence event logger function */
void DPU_F_EVT_LOG(dpu_f_evt_t type, struct v4l2_subdev *sd,
		struct dpu_fence_info *fence_info)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_fence_log *log;
	int idx;

	if (!decon || IS_ERR_OR_NULL(decon->d.f_evt_log))
		return;

	idx = atomic_inc_return(&decon->d.f_evt_log_idx) % decon->d.f_evt_log_cnt;
	log = &decon->d.f_evt_log[idx];

	log->time = ktime_get();
	log->type = type;
	memcpy(&log->fence_info, fence_info, sizeof(struct dpu_fence_info));
}

/* logging a event related with DECON */
static inline void dpu_event_log_decon
	(dpu_event_t type, struct v4l2_subdev *sd, ktime_t time)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

#if defined(CONFIG_SUPPORT_KERNEL_4_9)
	if (time.tv64)
#else
	if (time)
#endif
		log->time = time;
	else
		log->time = ktime_get();
	log->type = type;

	switch (type) {
	case DPU_EVT_DECON_SUSPEND:
	case DPU_EVT_DECON_RESUME:
	case DPU_EVT_ENTER_HIBER:
	case DPU_EVT_EXIT_HIBER:
		log->data.pm.pm_status = pm_runtime_active(decon->dev);
		log->data.pm.elapsed = ktime_sub(ktime_get(), log->time);
		break;
	case DPU_EVT_WIN_CONFIG:
	case DPU_EVT_TRIG_UNMASK:
	case DPU_EVT_TRIG_MASK:
	case DPU_EVT_FENCE_RELEASE:
	case DPU_EVT_DECON_FRAMEDONE:
#if defined(CONFIG_SUPPORT_LEGACY_FENCE)
		log->data.fence.timeline_value = decon->timeline->value;
		log->data.fence.timeline_max = decon->timeline_max;
#else
		log->data.fence.timeline_value = atomic_read(&decon->fence.timeline);
		log->data.fence.timeline_max = atomic_read(&decon->fence.timeline);
#endif
		break;
	case DPU_EVT_WB_SW_TRIGGER:
		break;
	case DPU_EVT_TE_INTERRUPT:
	case DPU_EVT_UNDERRUN:
	case DPU_EVT_LINECNT_ZERO:
		break;
	case DPU_EVT_CURSOR_POS:	/* cursor async */
		log->data.cursor.xpos = decon->cursor.xpos;
		log->data.cursor.ypos = decon->cursor.ypos;
		log->data.cursor.elapsed = ktime_sub(ktime_get(), log->time);
		break;
	default:
		/* Any remaining types will be log just time and type */
		break;
	}
}

/* logging a event related with DSIM */
static inline void dpu_event_log_dsim
	(dpu_event_t type, struct v4l2_subdev *sd, ktime_t time)
{
	struct dsim_device *dsim = container_of(sd, struct dsim_device, sd);
	struct decon_device *decon = get_decon_drvdata(dsim->id);
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

#if defined(CONFIG_SUPPORT_KERNEL_4_9)
	if (time.tv64)
#else
	if (time)
#endif
		log->time = time;
	else
		log->time = ktime_get();
	log->type = type;

	switch (type) {
	case DPU_EVT_DSIM_SUSPEND:
	case DPU_EVT_DSIM_RESUME:
	case DPU_EVT_ENTER_ULPS:
	case DPU_EVT_EXIT_ULPS:
		log->data.pm.pm_status = pm_runtime_active(dsim->dev);
		log->data.pm.elapsed = ktime_sub(ktime_get(), log->time);
		break;
	default:
		/* Any remaining types will be log just time and type */
		break;
	}
}

/* get decon's id used by dpp */
static int __get_decon_id_for_dpp(struct v4l2_subdev *sd)
{
	struct decon_device *decon;
	struct dpp_device *dpp = v4l2_get_subdevdata(sd);
	int idx;
	int ret = 0;
	int decon_cnt;

	decon_cnt = get_decon_drvdata(0)->dt.decon_cnt;

	for (idx = 0; idx < decon_cnt; idx++) {
		decon = get_decon_drvdata(idx);
		if (!decon || IS_ERR_OR_NULL(decon->d.debug_event))
			continue;
		if (test_bit(dpp->id, &decon->prev_used_dpp))
			ret = decon->id;
	}

	return ret;
}

/* logging a event related with DPP */
static inline void dpu_event_log_dpp
	(dpu_event_t type, struct v4l2_subdev *sd, ktime_t time)
{
	struct decon_device *decon = get_decon_drvdata(__get_decon_id_for_dpp(sd));
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpp_device *dpp = v4l2_get_subdevdata(sd);
	struct dpu_log *log;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

#if defined(CONFIG_SUPPORT_KERNEL_4_9)
	if (time.tv64)
#else
	if (time)
#endif
		log->time = time;
	else
		log->time = ktime_get();
	log->type = type;

	switch (type) {
	case DPU_EVT_DPP_SUSPEND:
	case DPU_EVT_DPP_RESUME:
		log->data.pm.pm_status = pm_runtime_active(dpp->dev);
		log->data.pm.elapsed = ktime_sub(ktime_get(), log->time);
		break;
	case DPU_EVT_DPP_FRAMEDONE:
	case DPU_EVT_DPP_STOP:
	case DPU_EVT_DMA_FRAMEDONE:
	case DPU_EVT_DMA_RECOVERY:
		log->data.dpp.id = dpp->id;
		log->data.dpp.done_cnt = dpp->d.done_count;
		break;
	case DPU_EVT_DPP_WINCON:
		log->data.dpp.id = dpp->id;
		log->data.dpp.comp = dpp->dpp_config->config.compression;
		log->data.dpp.rot = dpp->dpp_config->config.dpp_parm.rot;
		log->data.dpp.hdr_std = dpp->dpp_config->config.dpp_parm.hdr_std;
		memcpy(&log->data.dpp.src, &dpp->dpp_config->config.src, sizeof(struct decon_frame));
		memcpy(&log->data.dpp.dst, &dpp->dpp_config->config.dst, sizeof(struct decon_frame));
		break;
	default:
		log->data.dpp.id = dpp->id;
		break;
	}

	return;
}

/* If event are happend continuously, then ignore */
static bool dpu_event_ignore
	(dpu_event_t type, struct decon_device *decon)
{
	int latest = atomic_read(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;
	int idx;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return true;

	/* Seek a oldest from current index */
	idx = (latest + decon->d.event_log_cnt - DPU_EVENT_KEEP_CNT) % decon->d.event_log_cnt;
	do {
		if (++idx >= decon->d.event_log_cnt)
			idx = 0;

		log = &decon->d.event_log[idx];
		if (log->type != type)
			return false;
	} while (latest != idx);

	return true;
}

/* ===== EXTERN APIs ===== */
/* Common API to log a event related with DECON/DSIM/DPP */
void DPU_EVENT_LOG(dpu_event_t type, struct v4l2_subdev *sd, ktime_t time)
{
	struct decon_device *decon = get_decon_drvdata(0);

	if (!decon || IS_ERR_OR_NULL(decon->d.debug_event) ||
			IS_ERR_OR_NULL(decon->d.event_log))
		return;

	/* log a eventy softly */
	switch (type) {
	case DPU_EVT_TE_INTERRUPT:
	case DPU_EVT_UNDERRUN:
		/* If occurs continuously, skipped. It is a burden */
		if (dpu_event_ignore(type, decon))
			break;
	case DPU_EVT_BLANK:
	case DPU_EVT_UNBLANK:
	case DPU_EVT_ENTER_HIBER:
	case DPU_EVT_EXIT_HIBER:
	case DPU_EVT_DECON_SUSPEND:
	case DPU_EVT_DECON_RESUME:
	case DPU_EVT_LINECNT_ZERO:
	case DPU_EVT_TRIG_MASK:
	case DPU_EVT_TRIG_UNMASK:
	case DPU_EVT_FENCE_RELEASE:
	case DPU_EVT_DECON_FRAMEDONE:
	case DPU_EVT_DECON_FRAMEDONE_WAIT:
	case DPU_EVT_WIN_CONFIG:
	case DPU_EVT_WB_SW_TRIGGER:
	case DPU_EVT_DECON_SHUTDOWN:
	case DPU_EVT_RSC_CONFLICT:
	case DPU_EVT_DECON_FRAMESTART:
	case DPU_EVT_CURSOR_POS:	/* cursor async */
		dpu_event_log_decon(type, sd, time);
		break;
	case DPU_EVT_DSIM_FRAMEDONE:
	case DPU_EVT_ENTER_ULPS:
	case DPU_EVT_EXIT_ULPS:
	case DPU_EVT_DSIM_SHUTDOWN:
		dpu_event_log_dsim(type, sd, time);
		break;
	case DPU_EVT_DPP_FRAMEDONE:
	case DPU_EVT_DPP_STOP:
	case DPU_EVT_DPP_WINCON:
	case DPU_EVT_DMA_FRAMEDONE:
	case DPU_EVT_DMA_RECOVERY:
		dpu_event_log_dpp(type, sd, time);
		break;
	default:
		break;
	}

	if (decon->d.event_log_level == DPU_EVENT_LEVEL_LOW)
		return;

	/* additionally logging hardly */
	switch (type) {
	case DPU_EVT_ACT_VSYNC:
	case DPU_EVT_DEACT_VSYNC:
	case DPU_EVT_WB_SET_BUFFER:
	case DPU_EVT_DECON_SET_BUFFER:
		dpu_event_log_decon(type, sd, time);
		break;
	case DPU_EVT_DSIM_SUSPEND:
	case DPU_EVT_DSIM_RESUME:
		dpu_event_log_dsim(type, sd, time);
		break;
	case DPU_EVT_DPP_SUSPEND:
	case DPU_EVT_DPP_RESUME:
	case DPU_EVT_DPP_UPDATE_DONE:
	case DPU_EVT_DPP_SHADOW_UPDATE:
		dpu_event_log_dpp(type, sd, time);
	default:
		break;
	}
}

void DPU_EVENT_LOG_WINCON(struct v4l2_subdev *sd, struct decon_reg_data *regs)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_log *log;
	int idx;
	int win = 0;
	bool window_updated = false;
	ktime_t time = ktime_get();

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	for (win = 0; win < decon->dt.max_win; win++) {
		if (!(regs->win_regs[win].wincon & WIN_EN_F(win)))
			continue;

		idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
		log = &decon->d.event_log[idx];
		log->magic = DPU_LOG_VALID_MARK;
		log->time = time;
		log->type = DPU_EVT_UPDATE_HANDLER_WIN_REG_0 + win;
		memcpy(&log->data.win_regs, &regs->win_regs[win],
				sizeof(struct decon_window_regs));
	}

	for (win = 0; win < decon->dt.max_win; win++) {
		if (!(regs->win_regs[win].wincon & WIN_EN_F(win)))
			continue;

		idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
		log = &decon->d.event_log[idx];
		log->magic = DPU_LOG_VALID_MARK;
		log->time = time;
		log->type = DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_0 + win;
		memcpy(&log->data.win_config, &regs->dpp_config[win],
				sizeof(struct decon_win_config));
	}

	win  = DECON_WIN_UPDATE_IDX;

	if ((regs->dpp_config[win].state == DECON_WIN_STATE_UPDATE) ||
		(regs->dpp_config[win].state == DECON_WIN_STATE_MRESOL) ||
		(decon->dt.out_type == DECON_OUT_WB)) {
		/* window update case : last window
			OR
	       write-back case : last window
		*/
		idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
		log = &decon->d.event_log[idx];
		log->magic = DPU_LOG_VALID_MARK;
		log->time = time;
		log->type = DPU_EVT_UPDATE_HANDLER_WIN_CONFIG_0 + win;

		window_updated = true;
		memcpy(&log->data.win_config, &regs->dpp_config[win],
				sizeof(struct decon_win_config));
	}

	idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;
	log->time = time;
	log->type = DPU_EVT_UPDATE_HANDLER_WIN;

	if (window_updated) {
		log->data.win.x = regs->dpp_config[win].dst.x;
		log->data.win.y = regs->dpp_config[win].dst.y;
		log->data.win.w = regs->dpp_config[win].dst.w;
		log->data.win.h = regs->dpp_config[win].dst.h;
	} else {
		log->data.win.x = 0;
		log->data.win.y = 0;
		log->data.win.w = decon->lcd_info->xres;
		log->data.win.h = decon->lcd_info->yres;
	}
}

#if 0
void DPU_EVENT_LOG_WINCON(struct v4l2_subdev *sd, struct decon_reg_data *regs)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_log *log;
	//int idx = atomic_inc_return(&decon->d.event_log_idx) % DPU_EVENT_LOG_MAX;
	int idx;
	//int idx = atomic_add_return(MAX_DECON_WIN * 2 + 2, &decon->d.event_log_idx);
	int win = 0;
	bool window_updated = false;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	for (i = 0; i < MAX_DECON_WIN * 2 + 2; i++) {
		log = &decon->d.event_log[idx];
		log->magic = DPU_LOG_VALID_MARK;
		log->time = ktime_get();
		log->type = DPU_EVT_UPDATE_HANDLER_WIN_REG_0 + i;
	}

	for (win = 0; win < decon->dt.max_win; win++) {

	}
	/*
	for (win = 0; win < decon->dt.max_win; win++) {
		if (regs->win_regs[win].wincon & WIN_EN_F(win)) {
			memcpy(&log->data.reg.win_regs[win], &regs->win_regs[win],
				sizeof(struct decon_window_regs));
			memcpy(&log->data.reg.win_config[win], &regs->dpp_config[win],
				sizeof(struct decon_win_config));
		} else {
			log->data.reg.win_config[win].state =
						DECON_WIN_STATE_DISABLED;
		}
	}
	*/

	/* window update case : last window */
	win  = DECON_WIN_UPDATE_IDX;
	if (regs->dpp_config[win].state == DECON_WIN_STATE_UPDATE) {
		window_updated = true;
		memcpy(&log->data.reg.win_config[win], &regs->dpp_config[win],
				sizeof(struct decon_win_config));
	}

	/* write-back case : last window */
	if (decon->dt.out_type == DECON_OUT_WB)
		memcpy(&log->data.reg.win_config[win], &regs->dpp_config[win],
				sizeof(struct decon_win_config));

	if (window_updated) {
		log->data.reg.win.x = regs->dpp_config[win].dst.x;
		log->data.reg.win.y = regs->dpp_config[win].dst.y;
		log->data.reg.win.w = regs->dpp_config[win].dst.w;
		log->data.reg.win.h = regs->dpp_config[win].dst.h;
	} else {
		log->data.reg.win.x = 0;
		log->data.reg.win.y = 0;
		log->data.reg.win.w = decon->lcd_info->xres;
		log->data.reg.win.h = decon->lcd_info->yres;
	}
}
#endif

extern void *return_address(int);

/* Common API to log a event related with DSIM COMMAND */
void DPU_EVENT_LOG_CMD(struct v4l2_subdev *sd, u32 cmd_id, unsigned long data)
{
	struct dsim_device *dsim = container_of(sd, struct dsim_device, sd);
	struct decon_device *decon = get_decon_drvdata(dsim->id);
	int idx, i;
	struct dpu_log *log;

	if (!decon || IS_ERR_OR_NULL(decon->d.debug_event) ||
			IS_ERR_OR_NULL(decon->d.event_log))
		return;

	idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

	log->time = ktime_get();
	log->type = DPU_EVT_DSIM_COMMAND;
	log->data.cmd_buf.id = cmd_id;
	if (cmd_id == MIPI_DSI_DCS_LONG_WRITE)
		log->data.cmd_buf.buf = *(u8 *)(data);
	else
		log->data.cmd_buf.buf = (u8)data;

	for (i = 0; i < DPU_CALLSTACK_MAX; i++)
		log->data.cmd_buf.caller[i] = (void *)((size_t)return_address(i + 1));
}

/* cursor async */
#if 0
void DPU_EVENT_LOG_CURSOR(struct v4l2_subdev *sd, struct decon_reg_data *regs)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_log *log;
	int idx = atomic_inc_return(&decon->d.event_log_idx) % DPU_EVENT_LOG_MAX;
	int win = 0;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;
	log->time = ktime_get();
	log->type = DPU_EVT_CURSOR_UPDATE;

	for (win = 0; win < decon->dt.max_win; win++) {
		if (regs->is_cursor_win[win] && regs->win_regs[win].wincon & WIN_EN_F(win)) {
			memcpy(&log->data.reg.win_regs[win], &regs->win_regs[win],
				sizeof(struct decon_window_regs));
			memcpy(&log->data.reg.win_config[win], &regs->dpp_config[win],
				sizeof(struct decon_win_config));
		} else {
			log->data.reg.win_config[win].state =
						DECON_WIN_STATE_DISABLED;
		}
	}
	win  = DECON_WIN_UPDATE_IDX;
	log->data.reg.win_config[win].state = DECON_WIN_STATE_DISABLED;
}
#else
void DPU_EVENT_LOG_CURSOR(struct v4l2_subdev *sd, struct decon_reg_data *regs)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_log *log;
	int idx;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;
	idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;
	log->time = ktime_get();
	log->type = DPU_EVT_CURSOR_UPDATE;

	if (regs->is_cursor_win[regs->cursor_win]) {
		memcpy(&log->data.win_regs, &regs->win_regs[regs->cursor_win],
			sizeof(struct decon_window_regs));
		memcpy(&log->data.win_config, &regs->dpp_config[regs->cursor_win],
			sizeof(struct decon_win_config));
	} else {
		log->data.win_config.state = DECON_WIN_STATE_DISABLED;
	}
}
#endif

void DPU_EVENT_LOG_UPDATE_REGION(struct v4l2_subdev *sd,
		struct decon_frame *req_region, struct decon_frame *adj_region)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;

	if (!decon || IS_ERR_OR_NULL(decon->d.debug_event) ||
			IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;
	log->time = ktime_get();
	log->type = DPU_EVT_WINUP_UPDATE_REGION;

	memcpy(&log->data.winup.req_region, req_region, sizeof(struct decon_frame));
	memcpy(&log->data.winup.adj_region, adj_region, sizeof(struct decon_frame));
}

void DPU_EVENT_LOG_WINUP_FLAGS(struct v4l2_subdev *sd, bool need_update,
		bool reconfigure)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	struct dpu_log *log;
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;

	if (!decon || IS_ERR_OR_NULL(decon->d.debug_event) ||
			IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

	log->time = ktime_get();
	log->type = DPU_EVT_WINUP_FLAGS;

	log->data.winup.need_update = need_update;
	log->data.winup.reconfigure = reconfigure;
}

void DPU_EVENT_LOG_APPLY_REGION(struct v4l2_subdev *sd,
		struct decon_rect *apl_rect)
{
	struct decon_device *decon = container_of(sd, struct decon_device, sd);
	int idx = atomic_inc_return(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;

	if (!decon || IS_ERR_OR_NULL(decon->d.debug_event) ||
			IS_ERR_OR_NULL(decon->d.event_log))
		return;

	log = &decon->d.event_log[idx];
	log->magic = DPU_LOG_VALID_MARK;

	log->time = ktime_get();
	log->type = DPU_EVT_WINUP_APPLY_REGION;

	log->data.winup.apl_region.x = apl_rect->left;
	log->data.winup.apl_region.y = apl_rect->top;
	log->data.winup.apl_region.w = apl_rect->right - apl_rect->left + 1;
	log->data.winup.apl_region.h = apl_rect->bottom - apl_rect->top + 1;
}

/* display logged events related with DECON */
void DPU_EVENT_SHOW(struct seq_file *s, struct decon_device *decon)
{
	int idx = atomic_read(&decon->d.event_log_idx) % decon->d.event_log_cnt;
	struct dpu_log *log;
	int latest = idx;
	struct timeval tv;
	ktime_t prev_ktime;
	struct dsim_device *dsim;

	if (IS_ERR_OR_NULL(decon->d.event_log))
		return;

	if (!decon->id)
		dsim = get_dsim_drvdata(decon->id);

	/* TITLE */
	seq_printf(s, "-------------------DECON%d EVENT LOGGER ----------------------\n",
			decon->id);
	seq_printf(s, "-- STATUS: Hibernation(%s) ",
			IS_ENABLED(CONFIG_EXYNOS_HIBERNATION) ? "on" : "off");
	seq_printf(s, "BlockMode(%s) ",
			IS_ENABLED(CONFIG_EXYNOS_BLOCK_MODE) ? "on" : "off");
	seq_printf(s, "Window_Update(%s)\n",
			decon->win_up.enabled ? "on" : "off");
	if (!decon->id)
		seq_printf(s, "-- Total underrun count(%d)\n",
				dsim->total_underrun_cnt);
	seq_printf(s, "-- Hibernation enter/exit count(%d %d)\n",
			decon->hiber.enter_cnt, decon->hiber.exit_cnt);
	seq_puts(s, "-------------------------------------------------------------\n");
	seq_printf(s, "%14s  %20s  %20s\n",
		"Time", "Event ID", "Remarks");
	seq_puts(s, "-------------------------------------------------------------\n");

	/* Seek a oldest from current index */
	idx = (idx + decon->d.event_log_cnt / 2) % decon->d.event_log_cnt;
	prev_ktime = ktime_set(0, 0);
	do {
		if (++idx >= decon->d.event_log_cnt)
			idx = 0;

		/* Seek a index */
		log = &decon->d.event_log[idx];

		/* TIME */
		tv = ktime_to_timeval(log->time);
		seq_printf(s, "[%6ld.%06ld] ", tv.tv_sec, tv.tv_usec);

		/* If there is no timestamp, then exit directly */
		if (!tv.tv_sec)
			break;

		/* EVETN ID + Information */
		switch (log->type) {
		case DPU_EVT_BLANK:
			seq_printf(s, "%20s  %20s", "FB_BLANK", "-\n");
			break;
		case DPU_EVT_UNBLANK:
			seq_printf(s, "%20s  %20s", "FB_UNBLANK", "-\n");
			break;
		case DPU_EVT_ACT_VSYNC:
			seq_printf(s, "%20s  %20s", "ACT_VSYNC", "-\n");
			break;
		case DPU_EVT_DEACT_VSYNC:
			seq_printf(s, "%20s  %20s", "DEACT_VSYNC", "-\n");
			break;
		case DPU_EVT_WIN_CONFIG:
			seq_printf(s, "%20s  %20s", "WIN_CONFIG", "-\n");
			break;
		case DPU_EVT_TE_INTERRUPT:
			prev_ktime = ktime_sub(log->time, prev_ktime);
			seq_printf(s, "%20s  ", "TE_INTERRUPT");
			seq_printf(s, "time_diff=[%ld.%04lds]\n",
					ktime_to_timeval(prev_ktime).tv_sec,
					ktime_to_timeval(prev_ktime).tv_usec/100);
			/* Update for latest DPU_EVT_TE time */
			prev_ktime = log->time;
			break;
		case DPU_EVT_UNDERRUN:
			seq_printf(s, "%20s  %20s", "UNDER_RUN", "-\n");
			break;
		case DPU_EVT_DECON_FRAMEDONE:
			seq_printf(s, "%20s  %20s", "DECON_FRAME_DONE", "-\n");
			break;
		case DPU_EVT_DSIM_FRAMEDONE:
			seq_printf(s, "%20s  %20s", "DSIM_FRAME_DONE", "-\n");
			break;
		case DPU_EVT_RSC_CONFLICT:
			seq_printf(s, "%20s  %20s", "RSC_CONFLICT", "-\n");
			break;
		case DPU_EVT_UPDATE_HANDLER:
			seq_printf(s, "%20s  ", "UPDATE_HANDLER");
			/*
			seq_printf(s, "Partial Size (%d,%d,%d,%d)\n",
					log->data.reg.win.x,
					log->data.reg.win.y,
					log->data.reg.win.w,
					log->data.reg.win.h);
			*/
			break;
		case DPU_EVT_DSIM_COMMAND:
			seq_printf(s, "%20s  ", "DSIM_COMMAND");
			seq_printf(s, "id=0x%x, command=0x%x\n",
					log->data.cmd_buf.id,
					log->data.cmd_buf.buf);
			break;
		case DPU_EVT_TRIG_MASK:
			seq_printf(s, "%20s  %20s", "TRIG_MASK", "-\n");
			break;
		case DPU_EVT_TRIG_UNMASK:
			seq_printf(s, "%20s  %20s", "TRIG_UNMASK", "-\n");
			break;
		case DPU_EVT_FENCE_RELEASE:
			seq_printf(s, "%20s  %20s", "FENCE_RELEASE", "-\n");
			break;
		case DPU_EVT_DECON_SHUTDOWN:
			seq_printf(s, "%20s  %20s", "DECON_SHUTDOWN", "-\n");
			break;
		case DPU_EVT_DSIM_SHUTDOWN:
			seq_printf(s, "%20s  %20s", "DSIM_SHUTDOWN", "-\n");
			break;
		case DPU_EVT_DECON_FRAMESTART:
			seq_printf(s, "%20s  %20s", "DECON_FRAMESTART", "-\n");
			break;
		case DPU_EVT_DPP_WINCON:
			seq_printf(s, "%20s  ", "DPP_WINCON");
			seq_printf(s, "ID:%d, comp= %d, rot= %d, hdr= %d\n",
					log->data.dpp.id,
					log->data.dpp.comp,
					log->data.dpp.rot,
					log->data.dpp.hdr_std);
			break;
		case DPU_EVT_DPP_FRAMEDONE:
			seq_printf(s, "%20s  ", "DPP_FRAMEDONE");
			seq_printf(s, "ID:%d, start=%d, done=%d\n",
					log->data.dpp.id,
					log->data.dpp.start_cnt,
					log->data.dpp.done_cnt);
			break;
		case DPU_EVT_DPP_STOP:
			seq_printf(s, "%20s  ", "DPP_STOP");
			seq_printf(s, "(id:%d)\n", log->data.dpp.id);
			break;
		case DPU_EVT_DPP_SUSPEND:
			seq_printf(s, "%20s  %20s", "DPP_SUSPEND", "-\n");
			break;
		case DPU_EVT_DPP_RESUME:
			seq_printf(s, "%20s  %20s", "DPP_RESUME", "-\n");
			break;
		case DPU_EVT_DECON_SUSPEND:
			seq_printf(s, "%20s  %20s", "DECON_SUSPEND", "-\n");
			break;
		case DPU_EVT_DECON_RESUME:
			seq_printf(s, "%20s  %20s", "DECON_RESUME", "-\n");
			break;
		case DPU_EVT_ENTER_HIBER:
			seq_printf(s, "%20s  ", "ENTER_HIBER");
			tv = ktime_to_timeval(log->data.pm.elapsed);
			seq_printf(s, "pm=%s, elapsed=[%ld.%03lds]\n",
					log->data.pm.pm_status ? "active " : "suspend",
					tv.tv_sec, tv.tv_usec/1000);
			break;
		case DPU_EVT_EXIT_HIBER:
			seq_printf(s, "%20s  ", "EXIT_HIBER");
			tv = ktime_to_timeval(log->data.pm.elapsed);
			seq_printf(s, "pm=%s, elapsed=[%ld.%03lds]\n",
					log->data.pm.pm_status ? "active " : "suspend",
					tv.tv_sec, tv.tv_usec/1000);
			break;
		case DPU_EVT_DSIM_SUSPEND:
			seq_printf(s, "%20s  %20s", "DSIM_SUSPEND", "-\n");
			break;
		case DPU_EVT_DSIM_RESUME:
			seq_printf(s, "%20s  %20s", "DSIM_RESUME", "-\n");
			break;
		case DPU_EVT_ENTER_ULPS:
			seq_printf(s, "%20s  ", "ENTER_ULPS");
			tv = ktime_to_timeval(log->data.pm.elapsed);
			seq_printf(s, "pm=%s, elapsed=[%ld.%03lds]\n",
					log->data.pm.pm_status ? "active " : "suspend",
					tv.tv_sec, tv.tv_usec/1000);
			break;
		case DPU_EVT_EXIT_ULPS:
			seq_printf(s, "%20s  ", "EXIT_ULPS");
			tv = ktime_to_timeval(log->data.pm.elapsed);
			seq_printf(s, "pm=%s, elapsed=[%ld.%03lds]\n",
					log->data.pm.pm_status ? "active " : "suspend",
					tv.tv_sec, tv.tv_usec/1000);
			break;
		case DPU_EVT_DMA_FRAMEDONE:
			seq_printf(s, "%20s  ", "DPP_FRAMEDONE");
			seq_printf(s, "ID:%d\n", log->data.dpp.id);
			break;
		case DPU_EVT_DMA_RECOVERY:
			seq_printf(s, "%20s  %20s", "DMA_FRAMEDONE", "-\n");
			break;
		default:
			seq_printf(s, "%20s  (%2d)\n", "NO_DEFINED", log->type);
			break;
		}
	} while (latest != idx);

	seq_puts(s, "-------------------------------------------------------------\n");

	return;
}

static int decon_debug_event_show(struct seq_file *s, void *unused)
{
	struct decon_device *decon = s->private;
	DPU_EVENT_SHOW(s, decon);
	return 0;
}

static int decon_debug_event_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_event_show, inode->i_private);
}

static const struct file_operations decon_event_fops = {
	.open = decon_debug_event_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_dump_show(struct seq_file *s, void *unused)
{
	struct decon_device *decon = s->private;

	if (!IS_DECON_ON_STATE(decon)) {
		decon_info("%s: decon is not ON(%d)\n", __func__, decon->state);
		return 0;
	}
	decon_dump(decon, IGN_DSI_DUMP);
	return 0;
}

static int decon_debug_dump_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_dump_show, inode->i_private);
}

static const struct file_operations decon_dump_fops = {
	.open = decon_debug_dump_open,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_bts_show(struct seq_file *s, void *unused)
{
	seq_printf(s, "%u\n", dpu_bts_log_level);

	return 0;
}

static int decon_debug_bts_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_bts_show, inode->i_private);
}

static ssize_t decon_debug_bts_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &dpu_bts_log_level);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_bts_fops = {
	.open = decon_debug_bts_open,
	.write = decon_debug_bts_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_win_show(struct seq_file *s, void *unused)
{
	seq_printf(s, "%u\n", win_update_log_level);

	return 0;
}

static int decon_debug_win_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_win_show, inode->i_private);
}

static ssize_t decon_debug_win_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &win_update_log_level);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_win_fops = {
	.open = decon_debug_win_open,
	.write = decon_debug_win_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_mres_show(struct seq_file *s, void *unused)
{
	seq_printf(s, "%u\n", dpu_mres_log_level);

	return 0;
}

static int decon_debug_mres_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_mres_show, inode->i_private);
}

static ssize_t decon_debug_mres_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &dpu_mres_log_level);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_mres_fops = {
	.open = decon_debug_mres_open,
	.write = decon_debug_mres_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_systrace_show(struct seq_file *s, void *unused)
{
	seq_printf(s, "%u\n", decon_systrace_enable);
	return 0;
}

static int decon_systrace_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_systrace_show, inode->i_private);
}

static ssize_t decon_systrace_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &decon_systrace_enable);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_systrace_fops = {
	.open = decon_systrace_open,
	.write = decon_systrace_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

#if defined(CONFIG_DSIM_CMD_TEST)
static int decon_debug_cmd_show(struct seq_file *s, void *unused)
{
	return 0;
}

static int decon_debug_cmd_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_cmd_show, inode->i_private);
}

static ssize_t decon_debug_cmd_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;
	unsigned int cmd;
	struct dsim_device *dsim;
	u32 id, d1;
	unsigned long d0;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &cmd);
	if (ret < 0)
		goto out;

	dsim = get_dsim_drvdata(0);

	switch (cmd) {
	case 1:
		id = MIPI_DSI_DCS_SHORT_WRITE;
		d0 = (unsigned long)SEQ_DISPLAY_ON[0];
		d1 = 0;
		break;
	case 2:
		id = MIPI_DSI_DCS_SHORT_WRITE;
		d0 = (unsigned long)SEQ_DISPLAY_OFF[0];
		d1 = 0;
		break;
	case 3:
		id = MIPI_DSI_DCS_SHORT_WRITE;
		d0 = (unsigned long)SEQ_ALLPOFF[0];
		d1 = 0;
		break;
	case 4:
		id = MIPI_DSI_DCS_SHORT_WRITE;
		d0 = (unsigned long)SEQ_ALLPON[0];
		d1 = 0;
		break;
	case 5:
		id = MIPI_DSI_DCS_LONG_WRITE;
		d0 = (unsigned long)SEQ_ESD_FG;
		d1 = ARRAY_SIZE(SEQ_ESD_FG);
		break;
	case 6:
		id = MIPI_DSI_DCS_LONG_WRITE;
		d0 = (unsigned long)SEQ_TEST_KEY_OFF_F0;
		d1 = ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0);
		break;
	case 7:
		id = MIPI_DSI_DCS_LONG_WRITE;
		d0 = (unsigned long)SEQ_TEST_KEY_OFF_F1;
		d1 = ARRAY_SIZE(SEQ_TEST_KEY_OFF_F1);
		break;
	default:
		dsim_info("unsupported command(%d)\n", cmd);
		goto out;
	}

	ret = dsim_write_data(dsim, id, d0, d1);
	if (ret < 0) {
		decon_err("failed to write DSIM command(0x%lx)\n",
				(id == MIPI_DSI_DCS_LONG_WRITE) ?
				*(u8 *)(d0) : d0);
		goto out;
	}

	decon_info("success to write DSIM command(0x%lx, %d)\n",
			(id == MIPI_DSI_DCS_LONG_WRITE) ?
			*(u8 *)(d0) : d0, d1);
out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_cmd_fops = {
	.open = decon_debug_cmd_open,
	.write = decon_debug_cmd_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};
#endif

static int decon_debug_cmd_lp_ref_show(struct seq_file *s, void *unused)
{
	struct dsim_device *dsim = get_dsim_drvdata(0);
	int i;

	/* DSU_MODE_1 is used in stead of 1 in MCD */
	seq_printf(s, "%u\n", dsim->lcd_info.mres_mode);

	for (i = 0; i < dsim->lcd_info.dt_lcd_mres.mres_number; i++)
		seq_printf(s, "%u\n", dsim->lcd_info.cmd_underrun_lp_ref[i]);

	return 0;
}

static int decon_debug_cmd_lp_ref_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_cmd_lp_ref_show, inode->i_private);
}

static ssize_t decon_debug_cmd_lp_ref_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;
	unsigned int cmd_lp_ref = 0;
	struct dsim_device *dsim;
	int idx;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &cmd_lp_ref);
	if (ret != 1)
		goto out;

	dsim = get_dsim_drvdata(0);

	idx = dsim->lcd_info.mres_mode;
	dsim->lcd_info.cmd_underrun_lp_ref[idx] = cmd_lp_ref;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_cmd_lp_ref_fops = {
	.open = decon_debug_cmd_lp_ref_open,
	.write = decon_debug_cmd_lp_ref_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_rec_show(struct seq_file *s, void *unused)
{
#if 0 /* TODO: This will be implemented */
	seq_printf(s, "VGF0[%u] VGF1[%u]\n",
			get_dpp_drvdata(DPU_DMA2CH(IDMA_VGF0))->d.recovery_cnt,
			get_dpp_drvdata(DPU_DMA2CH(IDMA_VGF1))->d.recovery_cnt);
#endif
	return 0;
}

static int decon_debug_rec_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_rec_show, inode->i_private);
}

static ssize_t decon_debug_rec_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	return count;
}

static const struct file_operations decon_rec_fops = {
	.open = decon_debug_rec_open,
	.write = decon_debug_rec_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

static int decon_debug_low_persistence_show(struct seq_file *s, void *unused)
{
	struct decon_device *decon = get_decon_drvdata(0);
	seq_printf(s, "%u\n", decon->low_persistence);

	return 0;
}

static int decon_debug_low_persistence_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_low_persistence_show, inode->i_private);
}

static ssize_t decon_debug_low_persistence_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	struct decon_device *decon;
	char *buf_data;
	int ret;
	unsigned int low_persistence;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &low_persistence);
	if (ret < 0)
		goto out;

	decon = get_decon_drvdata(0);
	decon->low_persistence = low_persistence;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_low_persistence_fops = {
	.open = decon_debug_low_persistence_open,
	.write = decon_debug_low_persistence_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

void dpu_memmap_inc(struct decon_device *decon, dma_addr_t target)
{
#if defined(CONFIG_EXYNOS_MEMMAP_DEBUG)
	int i;
	if (decon->d.addr_n >= MAX_BUF_MEMMAP) {
		decon_info("%s:%d not enough room for the memmap\n",
				__func__, __LINE__);
		return;
	}
	for (i = 0; i < decon->d.addr_n; i++) {
		if (target == decon->d.mmap_info[i].addr_q) {
			decon->d.mmap_info[i].map_cnt++;
			return;
		}
	}
	decon->d.mmap_info[decon->d.addr_n].map_cnt = 1;
	decon->d.mmap_info[decon->d.addr_n].unmap_cnt = 0;
	decon->d.mmap_info[decon->d.addr_n].addr_q = target;
	decon->d.addr_n++;
#endif
}

void dpu_memmap_dec(struct decon_device *decon, dma_addr_t target)
{
#if defined(CONFIG_EXYNOS_MEMMAP_DEBUG)
	int i;
	for (i = 0; i < decon->d.addr_n; i++) {
		if (target == decon->d.mmap_info[i].addr_q) {
			decon->d.mmap_info[i].unmap_cnt++;
			return;
		}
	}
	decon_err("%s:%d address(0x%x) not found in the memmap list\n",
				__func__, __LINE__, target);
#endif
}

#if defined(CONFIG_EXYNOS_MEMMAP_DEBUG)
static int decon_n;
static int decon_debug_memmap_ref_cnt_show(struct seq_file *s, void *unused)
{
	int ret = 0;
	struct decon_device *decon;
	int i;

	decon = get_decon_drvdata(decon_n);
	if (!decon) {
		seq_printf(s, "decon%d not probed yet\n", decon_n);
		goto out;
	}

	seq_printf(s, "< Memory map count info : decon%d >\n", decon_n);
	for (i = 0; i < decon->d.addr_n; i++) {
		seq_printf(s, "0x%x : mapcnt(%u) unmapcnt(%u)\n",
				decon->d.mmap_info[i].addr_q,
				decon->d.mmap_info[i].map_cnt,
				decon->d.mmap_info[i].unmap_cnt);
	}
	if (!decon->d.addr_n)
		seq_printf(s, " - List empty\n");
	seq_printf(s, "--------------------------------\n");
out:
	return ret;
}

static int decon_debug_memmap_ref_cnt_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_memmap_ref_cnt_show, inode->i_private);
}

static ssize_t decon_debug_memmap_ref_cnt_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	int ret;
	char *buf_data;
	unsigned int d_n;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		goto out_buf;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &d_n);
	if (ret < 0)
		goto out;

	if (d_n > 2)
		d_n = 0;
	decon_info("decon%u selected for memmap ref cnt check\n", d_n);
	decon_n = d_n;
out:
	kfree(buf_data);
out_buf:
	return count;
}

static const struct file_operations decon_memmap_ref_cnt_fops = {
	.open = decon_debug_memmap_ref_cnt_open,
	.write = decon_debug_memmap_ref_cnt_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};
#endif

static int decon_debug_fence_show(struct seq_file *s, void *unused)
{
	seq_printf(s, "%u\n", dpu_fence_log_level);

	return 0;
}

static int decon_debug_fence_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_fence_show, inode->i_private);
}

static ssize_t decon_debug_fence_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &dpu_fence_log_level);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_fence_fops = {
	.open = decon_debug_fence_open,
	.write = decon_debug_fence_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

void decon_hiber_start(struct decon_device *decon)
{
	if (!decon->hiber.profile_started)
		return;

	decon->hiber.hiber_entry_time = ktime_get();
	decon->hiber.profile_enter_cnt++;
}

void decon_hiber_finish(struct decon_device *decon)
{
	if (!decon->hiber.profile_started)
		return;

	decon->hiber.hiber_time += ktime_to_us(ktime_sub(ktime_get(),
				decon->hiber.hiber_entry_time));
	decon->hiber.profile_exit_cnt++;
}

static int decon_get_hiber_ratio(struct decon_device *decon)
{
	s64 residency = decon->hiber.hiber_time;

	if (!residency)
		return 0;

	residency *= 100;
	do_div(residency, decon->hiber.profile_time);

	return residency;
}

static void _decon_profile_hiber_show(struct decon_device *decon)
{
	if (decon->hiber.profile_started) {
		decon_info("%s: hibernation profiling is ongoing\n", __func__);
		return;
	}

	decon_info("#########################################\n");
	decon_info("Profiling Time: %llu us\n", decon->hiber.profile_time);
	decon_info("Hibernation Entry Time: %llu us\n", decon->hiber.hiber_time);
	decon_info("Hibernation Entry Ratio: %d %%\n", decon_get_hiber_ratio(decon));
	decon_info("Entry count: %d, Exit count: %d\n", decon->hiber.profile_enter_cnt,
			decon->hiber.profile_exit_cnt);
	decon_info("Framedone count: %d, FPS: %lld\n", decon->hiber.frame_cnt,
			(decon->hiber.frame_cnt * 1000000) / decon->hiber.profile_time);
	decon_info("#########################################\n");
}


static int decon_profile_hiber_show(struct seq_file *s, void *unused)
{
	int ret = 0;
	struct decon_device *decon = get_decon_drvdata(0);

	if (!decon) {
		seq_printf(s, "decon0 is not probed yet\n");
		goto out;
	}

	_decon_profile_hiber_show(decon);

out:
	return ret;
}

static int decon_profile_hiber_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_profile_hiber_show, inode->i_private);
}

static void decon_profile_hiber_start(struct decon_device *decon)
{
	if (decon->hiber.profile_started) {
		decon_err("%s: hibernation profiling is ongoing\n", __func__);
		return;
	}

	/* reset profiling variables */
	decon->hiber.hiber_entry_time = 0;
	decon->hiber.hiber_time = 0;
	decon->hiber.profile_time = 0;
	decon->hiber.profile_enter_cnt = 0;
	decon->hiber.profile_exit_cnt = 0;
	decon->hiber.frame_cnt = 0;
	decon->hiber.fps = 0;

	/* profiling is just started */
	decon->hiber.profile_start_time = ktime_get();
	decon->hiber.profile_started = true;

	/* hibernation status when profiling is started */
	if (IS_DECON_HIBER_STATE(decon))
		decon_hiber_start(decon);

	decon_info("display hibernation profiling is started\n");
}

static void decon_profile_hiber_finish(struct decon_device *decon)
{
	if (!decon->hiber.profile_started) {
		decon_err("%s: hibernation profiling is not started\n", __func__);
		return;
	}

	decon->hiber.profile_time = ktime_to_us(ktime_sub(ktime_get(),
				decon->hiber.profile_start_time));

	/* hibernation status when profiling is finished */
	if (IS_DECON_HIBER_STATE(decon))
		decon_hiber_finish(decon);

	decon->hiber.profile_started = false;

	_decon_profile_hiber_show(decon);

	decon_info("display hibernation profiling is finished\n");
}

static ssize_t decon_profile_hiber_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	char *buf_data;
	int ret;
	int input;
	struct decon_device *decon = get_decon_drvdata(0);

	if (!decon) {
		decon_err("decon0 is not probed yet\n");
		goto out_cnt;
	}

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		goto out_cnt;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &input);
	if (ret < 0)
		goto out;

	if (input)
		decon_profile_hiber_start(decon);
	else
		decon_profile_hiber_finish(decon);

out:
	kfree(buf_data);
out_cnt:
	return count;
}

static const struct file_operations decon_profile_hiber_fops = {
	.open = decon_profile_hiber_open,
	.write = decon_profile_hiber_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

#if defined(CONFIG_EXYNOS_CHANGE_HIBER_CNT)
static int decon_hiber_cnt_show(struct seq_file *s, void *unused)
{
	struct decon_device *decon = get_decon_drvdata(0);
	seq_printf(s, "%u\n", decon->hiber.hiber_enter_cnt);

	return 0;
}

static int decon_hiber_cnt_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_hiber_cnt_show, inode->i_private);
}

static ssize_t decon_hiber_cnt_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	struct decon_device *decon = get_decon_drvdata(0);
	char *buf_data;
	int ret;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	ret = sscanf(buf_data, "%u", &decon->hiber.hiber_enter_cnt);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_hiber_cnt_fops = {
	.open = decon_hiber_cnt_open,
	.write = decon_hiber_cnt_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};
#endif

static int decon_debug_freq_hop_show(struct seq_file *s, void *unused)
{
	struct decon_device *decon = get_decon_drvdata(0);

	seq_printf(s, "m(%u) k(%u)\n", decon->freq_hop.request_m,
			decon->freq_hop.request_k);

	return 0;
}

static int decon_debug_freq_hop_open(struct inode *inode, struct file *file)
{
	return single_open(file, decon_debug_freq_hop_show, inode->i_private);
}

static ssize_t decon_debug_freq_hop_write(struct file *file, const char __user *buf,
		size_t count, loff_t *f_ops)
{
	struct decon_device *decon = get_decon_drvdata(0);
	char *buf_data;
	int ret;

	if (!decon->freq_hop.enabled)
		return count;

	if (count <= 0)
		return count;

	buf_data = kmalloc(count, GFP_KERNEL);
	if (buf_data == NULL)
		return count;

	memset(buf_data, 0, count);

	ret = copy_from_user(buf_data, buf, count);
	if (ret < 0)
		goto out;

	/*
	 * The synchronization is required when request_m value is updated
	 * between writing sysfs node of "request_m" and calling
	 * S3CFB_WIN_CONFIG ioctl.
	 */
	mutex_lock(&decon->lock);
	ret = sscanf(buf_data, "%u %u", &decon->freq_hop.request_m,
			&decon->freq_hop.request_k);
	mutex_unlock(&decon->lock);
	if (ret < 0)
		goto out;

out:
	kfree(buf_data);
	return count;
}

static const struct file_operations decon_freq_hop_fops = {
	.open = decon_debug_freq_hop_open,
	.write = decon_debug_freq_hop_write,
	.read = seq_read,
	.llseek = seq_lseek,
	.release = seq_release,
};

#ifdef CONFIG_SUPPORT_RDX_DUMP
static unsigned int *rdx_mem_ptr;
static void *rdx_mem_buf;
static size_t rdx_mem_pos;
static size_t rdx_mem_size;

void *rdx_mem_alloc(size_t s)
{
	void *ret;

	if (s > rdx_mem_size)
		return NULL;

	ret = rdx_mem_buf + rdx_mem_pos;
	rdx_mem_pos += s;

	return ret;
}

static int __init decon_event_log_setup(char *str)
{
	size_t size = memparse(str, &str);
	unsigned long base = 0;
	unsigned int *rdx_mem_magic;

	pr_info("%s :%s\n", __func__, str);

	if (!size || size != roundup_pow_of_two(size) ||
	    *str != '@' || kstrtoul(str + 1, 0, &base))
		goto setup_exit;

#ifdef CONFIG_NO_BOOTMEM
	if (memblock_is_region_reserved(base - 8, size + 8) ||
	    memblock_reserve(base - 8, size + 8)) {
#else
	if (reserve_bootmem(base - 8, size + 8, BOOTMEM_EXCLUSIVE)) {
#endif
		pr_err("%s: failed reserving size %d at base 0x%lx\n",
		       __func__, size, base);
		goto setup_exit;
	}
	rdx_mem_magic = phys_to_virt(base) - 8;
	rdx_mem_ptr = phys_to_virt(base) - 4;
	rdx_mem_buf = phys_to_virt(base);
	rdx_mem_size = size;

	pr_info("%s: *disp_rdx_log_ptr:%x\n", __func__, *rdx_mem_ptr);
	pr_info("%s: disp_rdx_log_buf:%p disp_rdx_log_size:0x%llx\n",
		__func__, rdx_mem_buf, rdx_mem_size);

	return 1;

setup_exit:
	return 0;
}
__setup("sec_disp_log=", decon_event_log_setup);
#endif

int decon_create_debugfs(struct decon_device *decon)
{
	char name[MAX_NAME_SIZE];
	int ret = 0;
	int i;
	u32 event_cnt;
	size_t real_size = 0;

	decon->d.event_log = NULL;
	event_cnt = DPU_EVENT_LOG_MAX;
	for (i = 0; i < DPU_EVENT_LOG_RETRY; ++i) {
		event_cnt = event_cnt >> i;
#ifdef CONFIG_SUPPORT_RDX_DUMP
		if (decon->id == 0) {
			decon->d.event_log_header = rdx_mem_alloc(sizeof(struct dpu_log_header));
			if (IS_ERR_OR_NULL(decon->d.event_log_header)) {
				decon_warn("failed to alloc event log header buf[%d]. retry\n",
						sizeof(struct dpu_log_header));
				continue;
			}
			real_size = sizeof(struct dpu_log_header) + sizeof(struct dpu_log) * event_cnt;
			pr_info("%s alloc total size %llx\n", __func__, real_size);
			if (real_size >= rdx_mem_size) {
				decon_warn("failed to alloc because over size[%d]. retry\n",
						real_size);
				continue;
			}
			dpu_event_log_header(decon, event_cnt);
			decon->d.event_log = rdx_mem_alloc(sizeof(struct dpu_log) * event_cnt);
		} else {
			decon->d.event_log = kzalloc(sizeof(struct dpu_log) * event_cnt,
					GFP_KERNEL);
		}
#else
		decon->d.event_log = kzalloc(sizeof(struct dpu_log) * event_cnt,
				GFP_KERNEL);
#endif
		if (IS_ERR_OR_NULL(decon->d.event_log)) {
			decon_warn("failed to alloc event log buf[%d]. retry\n",
					event_cnt);
			continue;
		}

		decon_info("#%d event log buffers are allocated\n", event_cnt);
		break;
	}
	decon->d.event_log_cnt = event_cnt;
	atomic_set(&decon->d.event_log_idx, -1);

	decon->d.f_evt_log = NULL;
	event_cnt = DPU_FENCE_EVENT_LOG_MAX;
	for (i = 0; i < DPU_FENCE_EVENT_LOG_RETRY; ++i) {
		event_cnt = event_cnt >> i;
		decon->d.f_evt_log = kzalloc(sizeof(struct dpu_fence_log) * event_cnt,
				GFP_KERNEL);
		if (IS_ERR_OR_NULL(decon->d.f_evt_log)) {
			decon_warn("failed to alloc fence event log buf[%d]. retry\n",
					event_cnt);
			continue;
		}

		decon_info("#%d fence event log buffers are allocated\n", event_cnt);
		break;
	}
	decon->d.f_evt_log_cnt = event_cnt;
	atomic_set(&decon->d.f_evt_log_idx, -1);

	if (!decon->id) {
		decon->d.debug_root = debugfs_create_dir("decon", NULL);
		if (!decon->d.debug_root) {
			decon_err("failed to create debugfs root directory.\n");
			ret = -ENOENT;
			goto err_event_log;
		}
	}

	if (decon->id == 1 || decon->id == 2)
		decon->d.debug_root = decon_drvdata[0]->d.debug_root;

	snprintf(name, MAX_NAME_SIZE, "event%d", decon->id);
	decon->d.debug_event = debugfs_create_file(name, 0444,
			decon->d.debug_root, decon, &decon_event_fops);
	if (!decon->d.debug_event) {
		decon_err("failed to create debugfs file(%d)\n", decon->id);
		ret = -ENOENT;
		goto err_debugfs;
	}

	snprintf(name, MAX_NAME_SIZE, "dump%d", decon->id);
	decon->d.debug_dump = debugfs_create_file(name, 0444,
			decon->d.debug_root, decon, &decon_dump_fops);
	if (!decon->d.debug_dump) {
		decon_err("failed to create SFR dump debugfs file(%d)\n",
				decon->id);
		ret = -ENOENT;
		goto err_debugfs;
	}

	if (decon->id == 0) {
		decon->d.debug_bts = debugfs_create_file("bts_log", 0444,
				decon->d.debug_root, NULL, &decon_bts_fops);
		if (!decon->d.debug_bts) {
			decon_err("failed to create BTS log level file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
		decon->d.debug_win = debugfs_create_file("win_update_log", 0444,
				decon->d.debug_root, NULL, &decon_win_fops);
		if (!decon->d.debug_win) {
			decon_err("failed to create win update log level file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
		decon->d.debug_mres = debugfs_create_file("mres_log", 0444,
				decon->d.debug_root, NULL, &decon_mres_fops);
		if (!decon->d.debug_mres) {
			decon_err("failed to create mres log level file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
		decon->d.debug_systrace = debugfs_create_file("decon_systrace", 0444,
				decon->d.debug_root, NULL, &decon_systrace_fops);
		if (!decon->d.debug_systrace) {
			decon_err("failed to create decon_systrace file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
#if defined(CONFIG_DSIM_CMD_TEST)
		decon->d.debug_cmd = debugfs_create_file("cmd", 0444,
				decon->d.debug_root, NULL, &decon_cmd_fops);
		if (!decon->d.debug_cmd) {
			decon_err("failed to create cmd_rw file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
#endif
		decon->d.debug_recovery_cnt = debugfs_create_file("recovery_cnt",
				0444, decon->d.debug_root, NULL, &decon_rec_fops);
		if (!decon->d.debug_recovery_cnt) {
			decon_err("failed to create recovery_cnt file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
		decon->d.debug_cmd_lp_ref = debugfs_create_file("cmd_lp_ref",
				0444, decon->d.debug_root, NULL, &decon_cmd_lp_ref_fops);
		if (!decon->d.debug_cmd_lp_ref) {
			decon_err("failed to create cmd_lp_ref file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
		decon->d.debug_low_persistence = debugfs_create_file("low_persistence",
				0444, decon->d.debug_root, NULL, &decon_low_persistence_fops);
		if (!decon->d.debug_low_persistence) {
			decon_err("failed to create low persistence file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}

#if defined(CONFIG_EXYNOS_MEMMAP_DEBUG)
		decon->d.debug_memmap_ref_cnt = debugfs_create_file("memmap_ref_cnt",
				0444, decon->d.debug_root, NULL, &decon_memmap_ref_cnt_fops);
		if (!decon->d.debug_memmap_ref_cnt) {
			decon_err("failed to create memory map ref cnt file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
#endif

		decon->hiber.profile = debugfs_create_file("profile_hiber",
				0444, decon->d.debug_root, NULL,
				&decon_profile_hiber_fops);
		if (!decon->hiber.profile) {
			decon_err("failed to create hibernation profiling\n");
			ret = -ENOENT;
			goto err_debugfs;
		}

#if defined(CONFIG_EXYNOS_CHANGE_HIBER_CNT)
		decon->hiber.hiber_cnt = debugfs_create_file("hiber_enter_cnt",
				0444, decon->d.debug_root, NULL,
				&decon_hiber_cnt_fops);
		if (!decon->hiber.hiber_cnt) {
			decon_err("failed to create hibernation entry count\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
#endif
		decon->d.debug_freq_hop = debugfs_create_file("request_mk",
				0444, decon->d.debug_root, NULL, &decon_freq_hop_fops);
		if (!decon->d.debug_freq_hop) {
			decon_err("failed to create request m value file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}

		decon->d.debug_fence = debugfs_create_file("fence_log", 0444,
				decon->d.debug_root, NULL, &decon_fence_fops);
		if (!decon->d.debug_fence) {
			decon_err("failed to create fence log level file\n");
			ret = -ENOENT;
			goto err_debugfs;
		}
	}

	return 0;

err_debugfs:
	debugfs_remove_recursive(decon->d.debug_root);
err_event_log:
#ifdef CONFIG_SUPPORT_RDX_DUMP
	if (decon->id != 0)
		kfree(decon->d.event_log);
#else
	kfree(decon->d.event_log);
#endif
	kfree(decon->d.f_evt_log);
	decon->d.event_log = NULL;
	decon->d.f_evt_log = NULL;
	return ret;
}

void decon_destroy_debugfs(struct decon_device *decon)
{
	if (decon->d.debug_root)
		debugfs_remove(decon->d.debug_root);
	if (decon->d.debug_event)
		debugfs_remove(decon->d.debug_event);
}