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
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
|
/*
* Copyright@ Samsung Electronics Co. LTD
*
* This software is proprietary of Samsung Electronics.
* No part of this software, either material or conceptual may be copied or distributed, transmitted,
* transcribed, stored in a retrieval system or translated into any human or computer language in any form by any means,
* electronic, mechanical, manual or otherwise, or disclosed
* to third parties without the express written permission of Samsung Electronics.
* Alternatively, this program is free software in case of open source projec;
* you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/fb.h>
#include <linux/ctype.h>
#include <linux/platform_device.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/memory.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/kthread.h>
#include <linux/regulator/consumer.h>
#include <linux/notifier.h>
#include <linux/pm_runtime.h>
#include <linux/lcd.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <video/mipi_display.h>
#include <plat/cpu.h>
#include <mach/map.h>
#include <mach/exynos5-mipiphy.h>
#include "regs-dsim.h"
#include "dsim.h"
#include "decon.h"
#include "panels/dsim_panel.h"
static DEFINE_MUTEX(dsim_rd_wr_mutex);
static DECLARE_COMPLETION(dsim_ph_wr_comp);
static DECLARE_COMPLETION(dsim_wr_comp);
static DECLARE_COMPLETION(dsim_rd_comp);
static int dsim_runtime_suspend(struct device *dev);
static int dsim_runtime_resume(struct device *dev);
static int dsim_set_ulps_by_ddi(struct dsim_device *dsim, u32 en);
#define MIPI_WR_TIMEOUT msecs_to_jiffies(50)
#define MIPI_RD_TIMEOUT msecs_to_jiffies(50)
#ifdef CONFIG_LCD_ALPM
#define ALPM_TIMEOUT 3
#endif
#ifdef CONFIG_OF
static const struct of_device_id exynos5_dsim[] = {
{ .compatible = "samsung,exynos5-dsim" },
{},
};
MODULE_DEVICE_TABLE(of, exynos5_dsim);
#endif
struct dsim_device *dsim0_for_decon;
EXPORT_SYMBOL(dsim0_for_decon);
struct dsim_device *dsim1_for_decon;
EXPORT_SYMBOL(dsim1_for_decon);
static void dsim_dump(struct dsim_device *dsim, int dump_panel)
{
dsim_info("=== DSIM SFR DUMP ===\n");
print_hex_dump(KERN_ERR, "", DUMP_PREFIX_ADDRESS, 32, 4,
dsim->reg_base, 0xBC, false);
if (dump_panel) {
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim_pkt_go_enable(dsim, false);
#endif
dsim_info("=== Panel Status DUMP ===\n");
call_panel_ops(dsim, dump, dsim);
}
}
static void dsim_long_data_wr(struct dsim_device *dsim, unsigned long data0, unsigned int data1)
{
unsigned int data_cnt = 0, payload = 0;
/* in case that data count is more then 4 */
for (data_cnt = 0; data_cnt < data1; data_cnt += 4) {
/*
* after sending 4bytes per one time,
* send remainder data less then 4.
*/
if ((data1 - data_cnt) < 4) {
if ((data1 - data_cnt) == 3) {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8 |
(*(u8 *)(data0 + (data_cnt + 2))) << 16;
dev_dbg(dsim->dev, "count = 3 payload = %x, %x %x %x\n",
payload, *(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)),
*(u8 *)(data0 + (data_cnt + 2)));
} else if ((data1 - data_cnt) == 2) {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8;
dev_dbg(dsim->dev,
"count = 2 payload = %x, %x %x\n", payload,
*(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)));
} else if ((data1 - data_cnt) == 1) {
payload = *(u8 *)(data0 + data_cnt);
}
dsim_reg_wr_tx_payload(dsim->id, payload);
/* send 4bytes per one time. */
} else {
payload = *(u8 *)(data0 + data_cnt) |
(*(u8 *)(data0 + (data_cnt + 1))) << 8 |
(*(u8 *)(data0 + (data_cnt + 2))) << 16 |
(*(u8 *)(data0 + (data_cnt + 3))) << 24;
dev_dbg(dsim->dev,
"count = 4 payload = %x, %x %x %x %x\n",
payload, *(u8 *)(data0 + data_cnt),
*(u8 *)(data0 + (data_cnt + 1)),
*(u8 *)(data0 + (data_cnt + 2)),
*(u8 *)(data0 + (data_cnt + 3)));
dsim_reg_wr_tx_payload(dsim->id, payload);
}
}
}
static int dsim_wait_for_cmd_fifo_empty(struct dsim_device *dsim, int id)
{
unsigned long wr_timeout = MIPI_WR_TIMEOUT;
#ifdef CONFIG_LCD_ALPM
if(dsim->alpm)
wr_timeout *= ALPM_TIMEOUT;
#endif
switch (id) {
case 0: /* SFR_PH_FIFO */
if (!wait_for_completion_timeout(&dsim_ph_wr_comp, wr_timeout)) {
if (dsim_read_mask(dsim->id, DSIM_INTSRC, DSIM_INTSRC_SFR_PH_FIFO_EMPTY)) {
INIT_COMPLETION(dsim_ph_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PH_FIFO_EMPTY);
return 0;
}
return -ETIMEDOUT;
}
break;
case 1: /* SFR_PL_FIFO */
if (!wait_for_completion_timeout(&dsim_wr_comp, wr_timeout)) {
if (dsim_read_mask(dsim->id, DSIM_INTSRC, DSIM_INTSRC_SFR_PL_FIFO_EMPTY)) {
INIT_COMPLETION(dsim_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PL_FIFO_EMPTY);
return 0;
}
return -ETIMEDOUT;
}
break;
default:
break;
}
return 0;
}
int dsim_write_data(struct dsim_device *dsim, unsigned int data_id,
unsigned long data0, unsigned int data1)
{
int ret = 0;
#ifdef CONFIG_FB_DSU
struct decon_device *decon = decon_int_drvdata;
if( decon!=NULL && decon->need_DSU_update ) {
char pBuffer[1024];
u8* pData;
int i;
sprintf( pBuffer, "%s(dsu): ", __func__ );
switch (data_id) {
/* short packet types of packet types for command. */
case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
case MIPI_DSI_DCS_SHORT_WRITE:
case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
case MIPI_DSI_DCS_READ:
case MIPI_DSI_COLOR_MODE_OFF:
case MIPI_DSI_COLOR_MODE_ON:
case MIPI_DSI_SHUTDOWN_PERIPHERAL:
case MIPI_DSI_TURN_ON_PERIPHERAL:
sprintf( pBuffer +strlen(pBuffer), "cmd:%02x, data=%02x %02x ", data_id, (unsigned int) data0, data1 );
break;
/* long packet types of packet types for command. */
case MIPI_DSI_GENERIC_LONG_WRITE:
case MIPI_DSI_DCS_LONG_WRITE:
pData = (u8 *)(data0);
sprintf( pBuffer +strlen(pBuffer), "cmd:%02x, (%d)data=", data_id, decon->need_DSU_update );
for( i = 0; i < data1; i++ )
sprintf( pBuffer +strlen(pBuffer), "%02x ", pData[i] );
break;
default:
break;
}
pr_info( "%s\n", pBuffer );
}
#endif
if (decon_int_drvdata) {
/* LPD related: Decon must be enabled for PACKET_GO mode */
decon_lpd_block_exit(decon_int_drvdata);
}
mutex_lock(&dsim_rd_wr_mutex);
if (dsim->state != DSIM_STATE_HSCLKEN) {
dev_err(dsim->dev, "DSIM is not ready. state(%d)\n", dsim->state);
ret = -EINVAL;
goto err_exit;
}
DISP_SS_EVENT_LOG_CMD(&dsim->sd, data_id, data0);
switch (data_id) {
/* short packet types of packet types for command. */
case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
case MIPI_DSI_DCS_SHORT_WRITE:
case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
INIT_COMPLETION(dsim_ph_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PH_FIFO_EMPTY);
dsim_reg_wr_tx_header(dsim->id, data_id, data0, data1);
if (dsim_wait_for_cmd_fifo_empty(dsim, 0)) {
dev_err(dsim->dev, "ID:%d : MIPI DSIM short packet write Timeout! 0x%lx\n",
data_id, data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* general command */
case MIPI_DSI_COLOR_MODE_OFF:
case MIPI_DSI_COLOR_MODE_ON:
case MIPI_DSI_SHUTDOWN_PERIPHERAL:
case MIPI_DSI_TURN_ON_PERIPHERAL:
INIT_COMPLETION(dsim_ph_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PH_FIFO_EMPTY);
dsim_reg_wr_tx_header(dsim->id, data_id, data0, data1);
if (dsim_wait_for_cmd_fifo_empty(dsim, 0)) {
dev_err(dsim->dev, "ID: %d : MIPI DSIM short packet write Timeout! 0x%lx\n",
data_id, data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* packet types for video data */
case MIPI_DSI_V_SYNC_START:
case MIPI_DSI_V_SYNC_END:
case MIPI_DSI_H_SYNC_START:
case MIPI_DSI_H_SYNC_END:
case MIPI_DSI_END_OF_TRANSMISSION:
break;
/* short and response packet types for command */
case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
case MIPI_DSI_DCS_READ:
INIT_COMPLETION(dsim_ph_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PH_FIFO_EMPTY);
dsim_reg_wr_tx_header(dsim->id, data_id, data0, data1);
if (dsim_wait_for_cmd_fifo_empty(dsim, 0)) {
dev_err(dsim->dev, "ID: %d : MIPI DSIM short packet write Timeout! 0x%lx\n",
data_id, data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
/* long packet type and null packet */
case MIPI_DSI_NULL_PACKET:
case MIPI_DSI_BLANKING_PACKET:
break;
case MIPI_DSI_GENERIC_LONG_WRITE:
case MIPI_DSI_DCS_LONG_WRITE:
{
unsigned int size;
size = data1 * 4;
INIT_COMPLETION(dsim_wr_comp);
INIT_COMPLETION(dsim_ph_wr_comp);
dsim_reg_clear_int(dsim->id, DSIM_INTSRC_SFR_PL_FIFO_EMPTY |
DSIM_INTSRC_SFR_PH_FIFO_EMPTY);
/* if data count is less then 4, then send 3bytes data. */
if (data1 < 4) {
unsigned int payload = 0;
payload = *(u8 *)(data0) |
*(u8 *)(data0 + 1) << 8 |
*(u8 *)(data0 + 2) << 16;
dsim_reg_wr_tx_payload(dsim->id, payload);
dev_dbg(dsim->dev, "count = %d payload = %x,%x %x %x\n",
data1, payload,
*(u8 *)(data0),
*(u8 *)(data0 + 1),
*(u8 *)(data0 + 2));
/* in case that data count is more then 4 */
} else
dsim_long_data_wr(dsim, data0, data1);
/* put data into header fifo */
dsim_reg_wr_tx_header(dsim->id, data_id, data1 & 0xff, (data1 & 0xff00) >> 8);
if (dsim_wait_for_cmd_fifo_empty(dsim, 1)) {
dev_err(dsim->dev, "ID: %d : MIPI DSIM write Timeout! 0x%0lx\n",
data_id, data0);
ret = -ETIMEDOUT;
goto exit;
}
if (dsim_wait_for_cmd_fifo_empty(dsim, 0)) {
dev_err(dsim->dev, "ID: %d : MIPI DSIM short packet write Timeout! 0x%lx\n",
data_id, data0);
ret = -ETIMEDOUT;
goto exit;
}
break;
}
/* packet typo for video data */
case MIPI_DSI_PACKED_PIXEL_STREAM_16:
case MIPI_DSI_PACKED_PIXEL_STREAM_18:
case MIPI_DSI_PIXEL_STREAM_3BYTE_18:
case MIPI_DSI_PACKED_PIXEL_STREAM_24:
break;
default:
dev_warn(dsim->dev, "data id %x is not supported current DSI spec.\n", data_id);
ret = -EINVAL;
goto exit;
}
exit:
if ((dsim->state == DSIM_STATE_HSCLKEN) && (ret == -ETIMEDOUT)) {
dev_err(dsim->dev, "0x%08X, 0x%08X, 0x%08X, 0x%08X\n",
readl(dsim->reg_base + DSIM_STATUS),
readl(dsim->reg_base + DSIM_INTSRC),
readl(dsim->reg_base + DSIM_FIFOCTRL),
readl(dsim->reg_base + DSIM_MULTI_PKT));
dsim_reg_set_fifo_ctrl(dsim->id, DSIM_FIFOCTRL_INIT_SFR);
}
err_exit:
mutex_unlock(&dsim_rd_wr_mutex);
if (decon_int_drvdata)
decon_lpd_unblock(decon_int_drvdata);
return ret;
}
int dsim_write_hl_data(struct dsim_device *dsim, const u8 *cmd, u32 cmdSize)
{
int ret;
int retry;
struct panel_private *panel = &dsim->priv;
if (panel->lcdConnected == PANEL_DISCONNEDTED)
return cmdSize;
//mutex_lock(&dsim->rdwr_lock);
retry = 5;
try_write:
if (cmdSize == 1)
ret = dsim_write_data(dsim, MIPI_DSI_DCS_SHORT_WRITE, cmd[0], 0);
else if (cmdSize == 2)
ret = dsim_write_data(dsim, MIPI_DSI_DCS_SHORT_WRITE_PARAM, cmd[0], cmd[1]);
else
ret = dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE, (unsigned long)cmd, cmdSize);
if (ret != 0) {
if (--retry)
goto try_write;
else
dsim_err("dsim write failed, cmd : %x\n", cmd[0]);
}
//mutex_unlock(&dsim->rdwr_lock);
return ret;
}
int dsim_read_hl_data(struct dsim_device *dsim, u8 addr, u32 size, u8 *buf)
{
int ret;
int retry = 5;
struct panel_private *panel = &dsim->priv;
if (panel->lcdConnected == PANEL_DISCONNEDTED)
return size;
try_read:
ret = dsim_read_data(dsim, MIPI_DSI_DCS_READ, (u32)addr, size, buf);
dsim_info("%s read ret : %d\n", __func__, ret);
if (ret != size) {
if (--retry)
goto try_read;
else
dsim_err("dsim read failed, addr : %x\n", addr);
}
return ret;
}
#ifdef CONFIG_FB_WINDOW_UPDATE
static int dsim_partial_area_command(struct dsim_device *dsim, void *arg)
{
struct panel_private *panel = &dsim->priv;
struct decon_win_rect *win_rect = (struct decon_win_rect *)arg;
char data_2a[5];
char data_2b[5];
int retry;
if (panel->lcdConnected == PANEL_DISCONNEDTED)
return 0;
/* w is right & h is bottom */
data_2a[0] = MIPI_DCS_SET_COLUMN_ADDRESS;
data_2a[1] = ((win_rect->x +dsim->glide_display_size) >> 8) & 0xff;
data_2a[2] = (win_rect->x +dsim->glide_display_size) & 0xff;
data_2a[3] = ((win_rect->w +dsim->glide_display_size) >> 8) & 0xff;
data_2a[4] = (win_rect->w +dsim->glide_display_size) & 0xff;
data_2b[0] = MIPI_DCS_SET_PAGE_ADDRESS;
data_2b[1] = (win_rect->y >> 8) & 0xff;
data_2b[2] = win_rect->y & 0xff;
data_2b[3] = (win_rect->h >> 8) & 0xff;
data_2b[4] = win_rect->h & 0xff;
retry = 2;
while (dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
(unsigned long)data_2a, ARRAY_SIZE(data_2a)) != 0) {
pr_info("%s:fail to write window update size a.\n", __func__);
if (--retry <= 0) {
pr_err("%s: size-a:failed: exceed retry count\n", __func__);
return -1;
}
}
retry = 2;
while (dsim_write_data(dsim, MIPI_DSI_DCS_LONG_WRITE,
(unsigned long)data_2b, ARRAY_SIZE(data_2b)) != 0) {
printk(KERN_ERR "fail to write window update size b.\n");
if (--retry <= 0) {
pr_err("%s: size-b:failed: exceed retry count\n", __func__);
return -1;
}
}
return 0;
}
static void dsim_set_lcd_full_screen(struct dsim_device *dsim)
{
struct decon_win_rect win_rect;
win_rect.x = 0;
win_rect.y = 0;
win_rect.w = dsim->lcd_info.xres - 1;
win_rect.h = dsim->lcd_info.yres - 1;
dsim_partial_area_command(dsim, (void *)(&win_rect));
return;
}
#else
static void dsim_set_lcd_full_screen(struct dsim_device *dsim)
{
return;
}
#endif
#ifdef CONFIG_FB_DSU
static int dsim_dsu_command(struct dsim_device *dsim, struct decon_device *decon)
{
pr_info( "%s : DSU_mode=%d, (%d,%d)\n", __func__, decon->DSU_mode, dsim->dsu_xres, dsim->dsu_yres );
call_panel_ops(dsim, dsu_cmd, dsim);
return 0;
}
#endif
static void dsim_rx_err_handler(struct dsim_device *dsim,
u32 rx_fifo)
{
/* Parse error report bit*/
if (rx_fifo & (1 << 8))
dev_err(dsim->dev, "SoT error!\n");
if (rx_fifo & (1 << 9))
dev_err(dsim->dev, "SoT sync error!\n");
if (rx_fifo & (1 << 10))
dev_err(dsim->dev, "EoT error!\n");
if (rx_fifo & (1 << 11))
dev_err(dsim->dev, "Escape mode entry command error!\n");
if (rx_fifo & (1 << 12))
dev_err(dsim->dev, "Low-power transmit sync error!\n");
if (rx_fifo & (1 << 13))
dev_err(dsim->dev, "HS receive timeout error!\n");
if (rx_fifo & (1 << 14))
dev_err(dsim->dev, "False control error!\n");
/* Bit 15 is reserved*/
if (rx_fifo & (1 << 16))
dev_err(dsim->dev, "ECC error, single-bit(detected and corrected)!\n");
if (rx_fifo & (1 << 17))
dev_err(dsim->dev, "ECC error, multi-bit(detected, not corrected)!\n");
if (rx_fifo & (1 << 18))
dev_err(dsim->dev, "Checksum error(long packet only)!\n");
if (rx_fifo & (1 << 19))
dev_err(dsim->dev, "DSI data type not recognized!\n");
if (rx_fifo & (1 << 20))
dev_err(dsim->dev, "DSI VC ID invalid!\n");
if (rx_fifo & (1 << 21))
dev_err(dsim->dev, "Invalid transmission length!\n");
/* Bit 22 is reserved */
if (rx_fifo & (1 << 23))
dev_err(dsim->dev, "DSI protocol violation!\n");
}
int dsim_read_data(struct dsim_device *dsim, u32 data_id,
u32 addr, u32 count, u8 *buf)
{
u32 rx_fifo, rx_size = 0;
int i, j, ret = 0;
unsigned long rd_timeout = MIPI_RD_TIMEOUT;
#ifdef CONFIG_LCD_ALPM
if(dsim->alpm)
rd_timeout *= ALPM_TIMEOUT;
#endif
if (decon_int_drvdata) {
/* LPD related: Decon must be enabled for PACKET_GO mode */
decon_lpd_block_exit(decon_int_drvdata);
}
if (dsim->state != DSIM_STATE_HSCLKEN) {
dev_err(dsim->dev, "DSIM is not ready. state(%d)\n", dsim->state);
if (decon_int_drvdata)
decon_lpd_unblock(decon_int_drvdata);
return -EINVAL;
}
INIT_COMPLETION(dsim_rd_comp);
/* Set the maximum packet size returned */
dsim_write_data(dsim,
MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, count, 0);
/* Read request */
dsim_write_data(dsim, data_id, addr, 0);
if (!wait_for_completion_timeout(&dsim_rd_comp, rd_timeout)) {
dev_err(dsim->dev, "MIPI DSIM read Timeout!\n");
return -ETIMEDOUT;
}
mutex_lock(&dsim_rd_wr_mutex);
DISP_SS_EVENT_LOG_CMD(&dsim->sd, data_id, (char)addr);
rx_fifo = readl(dsim->reg_base + DSIM_RXFIFO);
/* Parse the RX packet data types */
switch (rx_fifo & 0xff) {
case MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT:
dsim_rx_err_handler(dsim, rx_fifo);
goto rx_error;
case MIPI_DSI_RX_END_OF_TRANSMISSION:
dev_dbg(dsim->dev, "EoTp was received from LCD module.\n");
break;
case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE:
case MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE:
case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE:
case MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE:
dev_dbg(dsim->dev, "Short Packet was received from LCD module.\n");
for (i = 0; i < count; i++)
buf[i] = (rx_fifo >> (8 + i * 8)) & 0xff;
rx_size = count;
break;
case MIPI_DSI_RX_DCS_LONG_READ_RESPONSE:
case MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE:
dev_dbg(dsim->dev, "Long Packet was received from LCD module.\n");
rx_size = (rx_fifo & 0x00ffff00) >> 8;
dev_info(dsim->dev, "rx fifo : %8x, response : %x, rx_size : %d\n",
rx_fifo, rx_fifo & 0xff, rx_size);
/* Read data from RX packet payload */
for (i = 0; i < rx_size >> 2; i++) {
rx_fifo = readl(dsim->reg_base + DSIM_RXFIFO);
for (j = 0; j < 4; j++)
buf[(i*4)+j] = (u8)(rx_fifo >> (j * 8)) & 0xff;
}
if (rx_size % 4) {
rx_fifo = readl(dsim->reg_base + DSIM_RXFIFO);
for (j = 0; j < rx_size % 4; j++)
buf[4 * i + j] =
(u8)(rx_fifo >> (j * 8)) & 0xff;
}
break;
default:
dev_err(dsim->dev, "Packet format is invaild.\n");
goto rx_error;
}
rx_fifo = readl(dsim->reg_base + DSIM_RXFIFO);
if (rx_fifo != DSIM_RX_FIFO_READ_DONE) {
dev_info(dsim->dev, "%s Can't find RX FIFO READ DONE FLAG : %x\n",
__func__, rx_fifo);
goto clear_rx_fifo;
}
ret = rx_size;
goto exit;
clear_rx_fifo:
i = 0;
while (1) {
rx_fifo = readl(dsim->reg_base + DSIM_RXFIFO);
if ((rx_fifo == DSIM_RX_FIFO_READ_DONE) ||
(i > DSIM_MAX_RX_FIFO))
break;
dev_info(dsim->dev, "%s clear rx fifo : %08x\n", __func__, rx_fifo);
i++;
}
ret = 0;
goto exit;
rx_error:
dsim_reg_force_dphy_stop_state(dsim->id, 1);
usleep_range(3000, 4000);
dsim_reg_force_dphy_stop_state(dsim->id, 0);
ret = -EPERM;
goto exit;
exit:
mutex_unlock(&dsim_rd_wr_mutex);
if (decon_int_drvdata)
decon_lpd_unblock(decon_int_drvdata);
return ret;
}
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
void dsim_pkt_go_ready(struct dsim_device *dsim)
{
if (dsim->pktgo != DSIM_PKTGO_ENABLED) {
return;
}
dsim_reg_set_pkt_go_ready(dsim->id);
}
void dsim_pkt_go_enable(struct dsim_device *dsim, bool enable)
{
struct decon_device *decon = decon_int_drvdata;
if (decon)
decon_lpd_block(decon);
if (dsim->state != DSIM_STATE_HSCLKEN)
goto end;
if (enable) {
if (likely(dsim->pktgo == DSIM_PKTGO_ENABLED))
goto end;
dsim_reg_set_pkt_go_cnt(dsim->id, 0xff);
dsim_reg_set_pkt_go_enable(dsim->id, true);
dsim->pktgo = DSIM_PKTGO_ENABLED;
dev_dbg(dsim->dev, "%s: DSIM_PKTGO_ENABLED", __func__);
} else {
if (unlikely(dsim->pktgo != DSIM_PKTGO_ENABLED))
goto end;
dsim_reg_set_pkt_go_cnt(dsim->id, 0x1); /* Do not use 0x0 */
dsim_reg_set_pkt_go_enable(dsim->id, false);
dsim->pktgo = DSIM_PKTGO_DISABLED;
dev_dbg(dsim->dev, "%s: DSIM_PKTGO_DISABLED", __func__);
}
end:
if (decon)
decon_lpd_unblock(decon);
}
#endif
static void dsim_write_test(struct dsim_device *dsim)
{
int ret = 0, re_try = 4, i = 0;
u32 test_data[2] = {0xaa, 0xaa};
for (i = 0; i < re_try; i++) {
ret = dsim_write_data(dsim, MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM,
test_data[0], test_data[1]);
if(ret < 0)
dsim_dbg("%s: Failed to write test data!\n",
(dsim->pktgo == DSIM_PKTGO_ENABLED) ? "PKT-GO mode" : "Non PKT-GO mode");
else
dsim_dbg("%s: Succeeded to write test data!\n",
(dsim->pktgo == DSIM_PKTGO_ENABLED) ? "PKT-GO mode" : "Non PKT-GO mode");
}
}
static void dsim_read_test(struct dsim_device *dsim)
{
int ret = 0;
int count = 3;
u8 buf[4];
u32 rd_addr = 0x04;
ret = dsim_read_data(dsim, MIPI_DSI_DCS_READ, rd_addr, count, buf);
if (ret < 0)
dsim_dbg("%s: Failed to read test data!\n",
(dsim->pktgo == DSIM_PKTGO_ENABLED) ? "PKT-GO mode" : "Non PKT-GO mode");
else
dsim_dbg("%s: Succeeded to read test data! test data[0] = %#x, test data[1] = %#x, test data[2] = %#x\n",
((dsim->pktgo == DSIM_PKTGO_ENABLED) ? "PKT-GO mode" : "Non PKT-GO mode"), buf[0], buf[1], buf[3]);
}
static void dsim_d_phy_onoff(struct dsim_device *dsim,
unsigned int enable)
{
exynos5_dism_phy_enable(0, enable);
#if !defined(CONFIG_SOC_EXYNOS7580)
exynos5_dism_phy_enable(1, enable);
#endif
}
static irqreturn_t dsim_interrupt_handler(int irq, void *dev_id)
{
unsigned int int_src;
struct dsim_device *dsim = dev_id;
int active;
spin_lock(&dsim->slock);
active = pm_runtime_active(dsim->dev);
if (!active) {
dev_warn(dsim->dev, "dsim power is off(%d), state(%d)\n", active, dsim->state);
spin_unlock(&dsim->slock);
return IRQ_HANDLED;
}
int_src = readl(dsim->reg_base + DSIM_INTSRC);
/* Test bit */
if (int_src & DSIM_INTSRC_SFR_PL_FIFO_EMPTY)
complete(&dsim_wr_comp);
if (int_src & DSIM_INTSRC_SFR_PH_FIFO_EMPTY)
complete(&dsim_ph_wr_comp);
if (int_src & DSIM_INTSRC_RX_DAT_DONE)
complete(&dsim_rd_comp);
if (int_src & DSIM_INTSRC_FRAME_DONE) {
DISP_SS_EVENT_LOG(DISP_EVT_DSIM_FRAMEDONE, &dsim->sd, ktime_set(0, 0));
if (decon_int_drvdata)
decon_lpd_trig_reset(decon_int_drvdata);
}
if (int_src & DSIM_INTSRC_ERR_RX_ECC)
dev_err(dsim->dev, "RX ECC Multibit error was detected!\n");
dsim_reg_clear_int(dsim->id, int_src);
spin_unlock(&dsim->slock);
return IRQ_HANDLED;
}
static void dsim_clocks_info(struct dsim_device *dsim)
{
dsim_info("%s: %ld Mhz\n", __clk_get_name(dsim->res.pclk),
clk_get_rate(dsim->res.pclk) / MHZ);
dsim_info("%s: %ld Mhz\n", __clk_get_name(dsim->res.dphy_esc),
clk_get_rate(dsim->res.dphy_esc) / MHZ);
dsim_info("%s: %ld Mhz\n", __clk_get_name(dsim->res.dphy_byte),
clk_get_rate(dsim->res.dphy_byte) / MHZ);
dsim_info("%s: %ld Mhz\n", __clk_get_name(dsim->res.rgb_vclk0),
clk_get_rate(dsim->res.rgb_vclk0) / MHZ);
dsim_info("%s: %ld Mhz\n", __clk_get_name(dsim->res.pclk_disp),
clk_get_rate(dsim->res.pclk_disp) / MHZ);
}
static int dsim_get_clocks(struct dsim_device *dsim)
{
struct device *dev = dsim->dev;
if (!dsim->id) {
dsim->res.pclk = clk_get(dev, "pclk_dsim0");
if (IS_ERR_OR_NULL(dsim->res.pclk)) {
dsim_err("failed to get pclk_dsim0\n");
return -ENODEV;
}
dsim->res.dphy_esc = clk_get(dev, "mipi0_rx");
if (IS_ERR_OR_NULL(dsim->res.dphy_esc)) {
dsim_err("failed to get mipi0_rx\n");
return -ENODEV;
}
dsim->res.dphy_byte = clk_get(dev, "mipi0_bit");
if (IS_ERR_OR_NULL(dsim->res.dphy_byte)) {
dsim_err("failed to get mipi0_bit\n");
return -ENODEV;
}
/* This clock is used for transferring RGB data from decon-int to dsim0
* So, It must be enabled before starting decon-int and disabled after
* stopping decon-int */
dsim->res.rgb_vclk0 = clk_get(dev, "rgb_vclk0");
if (IS_ERR_OR_NULL(dsim->res.rgb_vclk0)) {
dsim_err("failed to get rgb_vclk0\n");
return -ENODEV;
}
dsim->res.pclk_disp = clk_get(dev, "pclk_disp");
if (IS_ERR_OR_NULL(dsim->res.pclk_disp)) {
decon_err("failed to get pclk_disp\n");
return -ENODEV;
}
} else {
dsim->res.pclk = clk_get(dev, "pclk_dsim1");
if (IS_ERR_OR_NULL(dsim->res.pclk)) {
dsim_err("failed to get pclk_dsim1\n");
return -ENODEV;
}
dsim->res.dphy_esc = clk_get(dev, "mipi1_rx");
if (IS_ERR_OR_NULL(dsim->res.dphy_esc)) {
dsim_err("failed to get mipi1_rx\n");
return -ENODEV;
}
dsim->res.dphy_byte = clk_get(dev, "mipi1_bit");
if (IS_ERR_OR_NULL(dsim->res.dphy_byte)) {
dsim_err("failed to get mipi1_bit\n");
return -ENODEV;
}
/* This clock is used for transferring RGB data from decon-int to dsim1
* So, It must be enabled before starting decon-int and disabled after
* stopping decon-int */
dsim->res.rgb_vclk0 = clk_get(dev, "rgb_vclk1");
if (IS_ERR_OR_NULL(dsim->res.rgb_vclk0)) {
dsim_err("failed to get rgb_vclk1\n");
return -ENODEV;
}
dsim->res.pclk_disp = clk_get(dev, "pclk_disp");
if (IS_ERR_OR_NULL(dsim->res.pclk_disp)) {
decon_err("failed to get pclk_disp\n");
return -ENODEV;
}
}
return 0;
}
static void dsim_put_clocks(struct dsim_device *dsim)
{
clk_put(dsim->res.pclk);
clk_put(dsim->res.dphy_esc);
clk_put(dsim->res.dphy_byte);
clk_put(dsim->res.rgb_vclk0);
clk_put(dsim->res.pclk_disp);
}
static int dsim_get_gpios(struct dsim_device *dsim)
{
struct device *dev = dsim->dev;
struct dsim_resources *res = &dsim->res;
dsim_info("%s +\n", __func__);
if (of_get_property(dev->of_node, "gpios", NULL) != NULL) {
/* panel reset */
res->lcd_reset = of_get_gpio(dev->of_node, 0);
if (res->lcd_reset < 0) {
dsim_err("failed to get lcd reset GPIO");
return -ENODEV;
}
res->lcd_power[0] = of_get_gpio(dev->of_node, 1);
if (res->lcd_power[0] < 0) {
res->lcd_power[0] = -1;
dsim_info("This board doesn't support LCD power GPIO");
}
res->lcd_power[1] = of_get_gpio(dev->of_node, 2);
if (res->lcd_power[1] < 0) {
res->lcd_power[1] = -1;
dsim_info("This board doesn't support 2nd LCD power GPIO");
}
}
dsim_info("%s -\n", __func__);
return 0;
}
static int dsim_get_regulator(struct dsim_device *dsim)
{
int ret = 0;
char *str_reg_V30 = NULL;
char *str_reg_V18 = NULL;
char *str_reg_V16 = NULL;
struct device *dev = dsim->dev;
struct dsim_resources *res = &dsim->res;
dsim_info("%s +\n", __func__);
res->regulator_30V = NULL;
of_property_read_string(dev->of_node, "regulator_30V", (const char **)&str_reg_V30);
if (str_reg_V30) {
dsim_info("getting string : %s\n",str_reg_V30);
res->regulator_30V = regulator_get(NULL, str_reg_V30);
if (IS_ERR(res->regulator_30V)) {
dsim_err("%s : dsim regulator 3.0V get failed\n", __func__);
res->regulator_30V = NULL;
}
}
res->regulator_18V = NULL;
of_property_read_string(dev->of_node, "regulator_18V", (const char **)&str_reg_V18);
if (str_reg_V18) {
dsim_info("getting string : %s\n",str_reg_V18);
res->regulator_18V = regulator_get(NULL, str_reg_V18);
if (IS_ERR(res->regulator_18V)) {
dsim_err("%s : dsim regulator 1.8V get failed\n", __func__);
res->regulator_18V = NULL;
}
}
res->regulator_16V = NULL;
of_property_read_string(dev->of_node, "regulator_16V", (const char **)&str_reg_V16);
if (str_reg_V16) {
dsim_info("getting string : %s\n",str_reg_V16);
res->regulator_16V = regulator_get(NULL, str_reg_V16);
if (IS_ERR(res->regulator_16V)) {
dsim_err("%s : dsim regulator 1.6V get failed\n", __func__);
res->regulator_16V = NULL;
}
}
if (res->regulator_16V) {
ret = regulator_enable(res->regulator_16V);
if (ret) {
dsim_err("%s : dsim regulator 1.6V enable failed\n", __func__);
}
}
if (res->regulator_30V) {
ret = regulator_enable(res->regulator_30V);
if (ret) {
dsim_err("%s : dsim regulator 3.0V enable failed\n", __func__);
}
}
if (res->regulator_18V) {
ret = regulator_enable(res->regulator_18V);
if (ret) {
dsim_err("%s : dsim regulator 3.0V enable failed\n", __func__);
}
}
dsim_info("%s -\n", __func__);
return 0;
}
static int dsim_reset_panel(struct dsim_device *dsim)
{
struct dsim_resources *res = &dsim->res;
int ret;
#ifdef CONFIG_LCD_ALPM
if (dsim->alpm)
return 0;
#endif
#ifdef CONFIG_DSIM_ESD_RECOVERY_NOPOWER
if( decon_int_drvdata->esd.queuework_pending ) {
dsim_info( "%s : esd type is %d.\n", __func__, decon_int_drvdata->esd.irq_type );
if( decon_int_drvdata->esd.irq_type == irq_err_fg ) {
dsim_info( "%s : return by esd_recovery.\n", __func__ );
return 0;
}
}
#endif
dsim_dbg("%s +\n", __func__);
ret = gpio_request_one(res->lcd_reset, GPIOF_OUT_INIT_HIGH, "lcd_reset");
if (ret < 0) {
dsim_err("failed to get LCD reset GPIO\n");
return -EINVAL;
}
usleep_range(5000, 6000);
gpio_set_value(res->lcd_reset, 0);
usleep_range(5000, 6000);
gpio_set_value(res->lcd_reset, 1);
gpio_free(res->lcd_reset);
usleep_range(10000, 11000);
dsim_dbg("%s -\n", __func__);
return 0;
}
static int dsim_set_panel_power(struct dsim_device *dsim, bool on)
{
struct dsim_resources *res = &dsim->res;
struct panel_private *panel = &dsim->priv;
int ret;
dsim_dbg("%s(%d) +\n", __func__, on);
#ifdef CONFIG_LCD_ALPM
if (dsim->alpm)
return 0;
#endif
if (panel->lcdConnected == PANEL_DISCONNEDTED) {
dsim_err("%s: panel is not connected. panel power off.\n", __func__);
on = false;
}
#ifdef CONFIG_DSIM_ESD_RECOVERY_NOPOWER
if( decon_int_drvdata->esd.queuework_pending
&& (decon_int_drvdata->esd.irq_type == irq_err_fg)) {
dsim_info( "%s : return by esd_recovery.\n", __func__ );
return 0;
}
#endif
if (on) {
if (res->lcd_power[0] > 0) {
ret = gpio_request_one(res->lcd_power[0], GPIOF_OUT_INIT_HIGH, "lcd_power0");
if (ret < 0) {
dsim_err("failed LCD power on\n");
return -EINVAL;
}
gpio_free(res->lcd_power[0]);
usleep_range(10000, 11000);
}
if (res->regulator_18V) {
if (!regulator_is_enabled(res->regulator_18V)) {
ret = regulator_enable(res->regulator_18V);
if (ret) {
dsim_err("%s : dsim regulator 1.8V enable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(10000, 11000);
}
if (res->regulator_16V) {
if (!regulator_is_enabled(res->regulator_16V)) {
ret = regulator_enable(res->regulator_16V);
if (ret) {
dsim_err("%s : dsim regulator 1.6V enable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(10000, 11000);
}
if (res->lcd_power[1] > 0) {
ret = gpio_request_one(res->lcd_power[1], GPIOF_OUT_INIT_HIGH, "lcd_power1");
if (ret < 0) {
dsim_err("failed 2nd LCD power on\n");
return -EINVAL;
}
gpio_free(res->lcd_power[1]);
usleep_range(10000, 11000);
}
if (res->regulator_30V) {
if (!regulator_is_enabled(res->regulator_30V)) {
ret = regulator_enable(res->regulator_30V);
if (ret) {
dsim_err("%s : dsim regulator 3.0V enable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(10000, 11000);
}
if (dsim->lcd_info.mode != DECON_VIDEO_MODE) {
/* TODO: only in case of command mode */
ret = pinctrl_select_state(dsim->pinctrl, dsim->turnon_tes);
if (ret) {
dsim_err("failed to turn on TE\n");
return -EINVAL;
}
}
} else {
ret = gpio_request_one(res->lcd_reset, GPIOF_OUT_INIT_LOW, "lcd_reset");
if (ret < 0) {
dsim_err("failed LCD reset off\n");
return -EINVAL;
}
gpio_free(res->lcd_reset);
if (res->lcd_power[0] > 0) {
ret = gpio_request_one(res->lcd_power[0], GPIOF_OUT_INIT_LOW, "lcd_power0");
if (ret < 0) {
dsim_err("failed LCD power off\n");
return -EINVAL;
}
gpio_free(res->lcd_power[0]);
usleep_range(5000, 6000);
}
if (res->regulator_30V) {
if (regulator_is_enabled(res->regulator_30V)) {
ret = regulator_disable(res->regulator_30V);
if (ret) {
dsim_err("%s : dsim regulator 3.0V disable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(5000, 6000);
}
if (res->regulator_16V) {
if (regulator_is_enabled(res->regulator_16V)) {
ret = regulator_disable(res->regulator_16V);
if (ret) {
dsim_err("%s : dsim regulator 1.6V disable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(5000, 6000);
}
if (res->lcd_power[1] > 0) {
ret = gpio_request_one(res->lcd_power[1], GPIOF_OUT_INIT_LOW, "lcd_power1");
if (ret < 0) {
dsim_err("failed 2nd LCD power off\n");
return -EINVAL;
}
gpio_free(res->lcd_power[1]);
usleep_range(5000, 6000);
}
if (res->regulator_18V) {
if (regulator_is_enabled(res->regulator_18V)) {
ret = regulator_disable(res->regulator_18V);
if (ret) {
dsim_err("%s : dsim regulator 1.8V disable failed\n", __func__);
return -EINVAL;
}
}
usleep_range(5000, 6000);
}
if (dsim->lcd_info.mode != DECON_VIDEO_MODE) {
/* TODO: only in case of command mode */
ret = pinctrl_select_state(dsim->pinctrl, dsim->turnoff_tes);
if (ret) {
dsim_err("failed to turn off TE\n");
return -EINVAL;
}
}
}
dsim_dbg("%s(%d) -\n", __func__, on);
return 0;
}
static int dsim_enable(struct dsim_device *dsim)
{
pr_info("%s ++\n", __func__);
if (dsim->state == DSIM_STATE_HSCLKEN) {
#ifdef CONFIG_LCD_DOZE_MODE
if ((dsim->dsim_doze == DSIM_DOZE_STATE_DOZE) ||
(dsim->dsim_doze == DSIM_DOZE_STATE_DOZE_SUSPEND)) {
call_panel_ops(dsim, exitalpm, dsim);
}
#endif
goto exit_dsim_enable;
}
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_get_sync(dsim->dev);
#else
dsim_runtime_resume(dsim->dev);
#endif
dsim_set_panel_power(dsim, 1);
call_panel_ops(dsim, resume, dsim);
/* DPHY power on */
dsim_d_phy_onoff(dsim, 1);
dsim_reg_init(dsim->id, &dsim->lcd_info, dsim->data_lane_cnt);
clk_prepare_enable(dsim->res.dphy_esc);
clk_prepare_enable(dsim->res.dphy_byte);
dsim_reg_enable_clocks(dsim->id, &dsim->clks_param,
DSIM_LANE_CLOCK | dsim->data_lane);
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 1);
#ifdef CONFIG_LCD_ALPM
if(dsim->alpm)
dsim_set_ulps_by_ddi(dsim, 0);
#endif
#ifdef CONFIG_LCD_DOZE_MODE
if ((dsim->dsim_doze == DSIM_DOZE_STATE_DOZE) ||
(dsim->dsim_doze == DSIM_DOZE_STATE_DOZE_SUSPEND)) {
dsim_info("%s : exit doze\n", __func__);
} else {
dsim_reset_panel(dsim);
}
#else
dsim_reset_panel(dsim);
#endif
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 1);
/* enable interrupts */
dsim_reg_set_int(dsim->id, 1);
dsim->state = DSIM_STATE_HSCLKEN;
#ifdef CONFIG_LCD_DOZE_MODE
if ((dsim->dsim_doze == DSIM_DOZE_STATE_DOZE) ||
(dsim->dsim_doze == DSIM_DOZE_STATE_DOZE_SUSPEND)) {
call_panel_ops(dsim, exitalpm, dsim);
} else {
call_panel_ops(dsim, displayon, dsim);
}
#else
call_panel_ops(dsim, displayon, dsim);
#endif
dsim_clocks_info(dsim);
exit_dsim_enable:
#ifdef CONFIG_LCD_DOZE_MODE
dsim->dsim_doze = DSIM_DOZE_STATE_NORMAL;
dsim->priv.curr_alpm_mode = 0;
#endif
pr_info("%s --\n", __func__);
return 0;
}
static int dsim_disable(struct dsim_device *dsim)
{
pr_info("%s ++\n", __func__);
if (dsim->state == DSIM_STATE_SUSPEND) {
goto exit_dsim_disable;
}
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim_pkt_go_enable(dsim, false);
#endif
dsim_set_lcd_full_screen(dsim);
call_panel_ops(dsim, suspend, dsim);
#ifdef CONFIG_LCD_DOZE_MODE
dsim->dsim_doze = DSIM_DOZE_STATE_SUSPEND;
#endif
//fixme ignore mutex?
dsim->state = DSIM_STATE_SUSPEND;
/* Wait for current read & write CMDs. */
mutex_lock(&dsim_rd_wr_mutex);
dsim->state = DSIM_STATE_SUSPEND;
mutex_unlock(&dsim_rd_wr_mutex);
/* disable interrupts */
dsim_reg_set_int(dsim->id, 0);
/* disable HS clock */
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 0);
#ifdef CONFIG_LCD_ALPM
if(dsim->alpm)
dsim_set_ulps_by_ddi(dsim, 1);
#endif
/* make CLK/DATA Lane as LP00 */
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 0);
dsim_reg_set_clocks(dsim->id, NULL, DSIM_LANE_CLOCK | dsim->data_lane, 0);
dsim_reg_sw_reset(dsim->id);
clk_disable_unprepare(dsim->res.dphy_esc);
clk_disable_unprepare(dsim->res.dphy_byte);
dsim_d_phy_onoff(dsim, 0);
dsim_set_panel_power(dsim, 0);
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_put_sync(dsim->dev);
#else
dsim_runtime_suspend(dsim->dev);
#endif
exit_dsim_disable:
pr_info("%s --\n", __func__);
return 0;
}
#ifdef CONFIG_LCD_DOZE_MODE
static int dsim_doze_enable(struct dsim_device *dsim)
{
struct panel_private *panel = &dsim->priv;
dsim_info("++ %s\n", __func__);
if (panel->alpm_support == 0) {
dsim_info("%s:this panel does not support alpm mode\n", __func__);
return -ENODEV;
}
if (dsim->state == DSIM_STATE_HSCLKEN) {
if (dsim->dsim_doze != DSIM_DOZE_STATE_DOZE) {
call_panel_ops(dsim, enteralpm, dsim);
dsim->dsim_doze = DSIM_DOZE_STATE_DOZE;
}
goto set_state_doze;
}
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_get_sync(dsim->dev);
#else
dsim_runtime_resume(dsim->dev);
#endif
if (dsim->dsim_doze == DSIM_DOZE_STATE_SUSPEND) {
dsim_set_panel_power(dsim, 1);
}
/* DPHY power on */
dsim_d_phy_onoff(dsim, 1);
dsim_reg_init(dsim->id, &dsim->lcd_info, dsim->data_lane_cnt);
clk_prepare_enable(dsim->res.dphy_esc);
clk_prepare_enable(dsim->res.dphy_byte);
dsim_reg_enable_clocks(dsim->id, &dsim->clks_param,
DSIM_LANE_CLOCK | dsim->data_lane);
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 1);
#ifdef CONFIG_LCD_ALPM
if(dsim->alpm)
dsim_set_ulps_by_ddi(dsim, 0);
#endif
if (dsim->dsim_doze == DSIM_DOZE_STATE_SUSPEND) {
dsim_reset_panel(dsim);
}
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 1);
/* enable interrupts */
dsim_reg_set_int(dsim->id, 1);
dsim->state = DSIM_STATE_HSCLKEN;
if (dsim->dsim_doze == DSIM_DOZE_STATE_SUSPEND) {
call_panel_ops(dsim, enteralpm, dsim);
}
if (dsim->dsim_doze == DSIM_DOZE_STATE_DOZE_SUSPEND) {
if (panel->curr_alpm_mode != panel->alpm_mode) {
call_panel_ops(dsim, enteralpm, dsim);
}
}
set_state_doze:
dsim->dsim_doze = DSIM_DOZE_STATE_DOZE;
dsim_info("-- %s\n", __func__);
return 0;
}
static int dsim_doze_suspend(struct dsim_device *dsim)
{
struct panel_private *panel = &dsim->priv;
dsim_info("++ %s\n", __func__);
if (panel->alpm_support == 0) {
dsim_info("%s:this panel does not support alpm mode\n", __func__);
return -ENODEV;
}
if (dsim->state == DSIM_STATE_SUSPEND) {
goto exit_doze_disable;
}
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim_pkt_go_enable(dsim, false);
#endif
dsim_set_lcd_full_screen(dsim);
#if 0
if (dsim->dsim_doze != DSIM_DOZE_STATE_DOZE)
call_panel_ops(dsim, suspend, dsim);
#endif
if (dsim->dsim_doze == DSIM_DOZE_STATE_NORMAL)
call_panel_ops(dsim, enteralpm, dsim);
dsim->dsim_doze = DSIM_DOZE_STATE_DOZE_SUSPEND;
/* Wait for current read & write CMDs. */
mutex_lock(&dsim_rd_wr_mutex);
dsim->state = DSIM_STATE_SUSPEND;
mutex_unlock(&dsim_rd_wr_mutex);
dsim_reg_set_int(dsim->id, 0);
dsim_reg_set_standby(dsim->id, &dsim->lcd_info, 0);
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 0);
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 0);
dsim_reg_set_esc_clk_on_lane(dsim->id, 0, dsim->data_lane);
dsim_reg_enable_byte_clock(dsim->id, 0);
dsim_reg_set_clocks(dsim->id, NULL, dsim->data_lane, 0);
dsim_reg_sw_reset(dsim->id);
dsim_d_phy_onoff(dsim, 0);
#if 0
if (dsim->dsim_doze != DSIM_DOZE_STATE_DOZE)
dsim_set_panel_power(dsim, 0);
#endif
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_put_sync(dsim->dev);
#else
dsim_runtime_suspend(dsim->dev);
#endif
exit_doze_disable:
dsim_info("-- %s\n", __func__);
return 0;
}
#endif
static int dsim_set_ulps_by_ddi(struct dsim_device *dsim, u32 en)
{
int ret;
switch (dsim->lcd_info.ddi_type) {
case TYPE_OF_SM_DDI:
ret = dsim_reg_set_smddi_ulps(dsim->id, en, dsim->data_lane);
break;
case TYPE_OF_MAGNA_DDI:
dsim_err("This ddi(%d) doesn't support ULPS\n", dsim->lcd_info.ddi_type);
ret = -EINVAL;
break;
case TYPE_OF_NORMAL_DDI:
default:
ret = dsim_reg_set_ulps(dsim->id, en, dsim->data_lane);
break;
}
return ret;
}
static int dsim_enter_ulps(struct dsim_device *dsim)
{
int ret = 0;
DISP_SS_EVENT_START();
dsim_dbg("%s +\n", __func__);
exynos_ss_printk("%s:state %d: active %d:+\n", __func__,
dsim->state, pm_runtime_active(dsim->dev));
if (dsim->state != DSIM_STATE_HSCLKEN) {
ret = -EBUSY;
goto err;
}
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
dsim_pkt_go_enable(dsim, false);
#endif
/* Wait for current read & write CMDs. */
mutex_lock(&dsim_rd_wr_mutex);
dsim->state = DSIM_STATE_ULPS;
mutex_unlock(&dsim_rd_wr_mutex);
/* disable interrupts */
dsim_reg_set_int(dsim->id, 0);
disable_irq(dsim->irq);
/* disable HS clock */
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 0);
/* try to enter ULPS mode. The sequence is depends on DDI type */
ret = dsim_set_ulps_by_ddi(dsim, 1);
if (ret < 0) {
dsim_info("%s: failed to enter ULPS: %d", __func__, ret);
dsim_dump(dsim, 0);
ret = 0;
}
/* make CLK/DATA Lane as LP00 */
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 0);
dsim_reg_set_clocks(dsim->id, NULL, DSIM_LANE_CLOCK | dsim->data_lane, 0);
dsim_reg_sw_reset(dsim->id);
clk_disable_unprepare(dsim->res.dphy_esc);
clk_disable_unprepare(dsim->res.dphy_byte);
dsim_d_phy_onoff(dsim, 0);
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_put_sync(dsim->dev);
#else
dsim_runtime_suspend(dsim->dev);
#endif
DISP_SS_EVENT_LOG(DISP_EVT_ENTER_ULPS, &dsim->sd, start);
err:
dsim_dbg("%s -\n", __func__);
exynos_ss_printk("%s:state %d: active %d:-\n", __func__,
dsim->state, pm_runtime_active(dsim->dev));
return ret;
}
static int dsim_exit_ulps(struct dsim_device *dsim)
{
int ret = 0;
DISP_SS_EVENT_START();
dsim_dbg("%s +\n", __func__);
exynos_ss_printk("%s:state %d: active %d:+\n", __func__,
dsim->state, pm_runtime_active(dsim->dev));
if (dsim->state != DSIM_STATE_ULPS) {
ret = -EBUSY;
goto err;
}
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_get_sync(dsim->dev);
#else
dsim_runtime_resume(dsim->dev);
#endif
/* DPHY power on */
dsim_d_phy_onoff(dsim, 1);
dsim_reg_init(dsim->id, &dsim->lcd_info, dsim->data_lane_cnt);
clk_prepare_enable(dsim->res.dphy_esc);
clk_prepare_enable(dsim->res.dphy_byte);
dsim_reg_enable_clocks(dsim->id, &dsim->clks_param,
DSIM_LANE_CLOCK | dsim->data_lane);
dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 1);
/* try to exit ULPS mode. The sequence is depends on DDI type */
ret = dsim_set_ulps_by_ddi(dsim, 0);
if (ret < 0) {
dsim_info("%s: failed to exit ULPS: %d", __func__, ret);
dsim_dump(dsim, 0);
}
dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 1);
enable_irq(dsim->irq);
/* enable interrupts */
dsim_reg_set_int(dsim->id, 1);
dsim->state = DSIM_STATE_HSCLKEN;
DISP_SS_EVENT_LOG(DISP_EVT_EXIT_ULPS, &dsim->sd, start);
err:
dsim_dbg("%s -\n", __func__);
exynos_ss_printk("%s:state %d: active %d:-\n", __func__,
dsim->state, pm_runtime_active(dsim->dev));
return 0;
}
static struct dsim_device *sd_to_dsim(struct v4l2_subdev *sd)
{
return container_of(sd, struct dsim_device, sd);
}
static int dsim_s_stream(struct v4l2_subdev *sd, int enable)
{
int ret = 0;
struct dsim_device *dsim = sd_to_dsim(sd);
switch (enable) {
case DSIM_REQ_POWER_OFF:
ret = dsim_disable(dsim);
break;
case DSIM_REQ_POWER_ON:
ret = dsim_enable(dsim);
break;
#ifdef CONFIG_LCD_DOZE_MODE
case DSIM_REQ_DOZE_MODE:
dsim_info("decon : dsim doze mode\n");
ret = dsim_doze_enable(dsim);
break;
case DSIM_REQ_DOZE_SUSPEND:
dsim_info("decon : dsim doze suspend\n");
ret = dsim_doze_suspend(dsim);
break;
#endif
}
return ret;
}
#ifdef CONFIG_FB_DSU
void dsim_reg_set_num_of_slice(u32 id, u32 num_of_slice);
void dsim_reg_set_multi_slice(u32 id, struct decon_lcd *lcd_info);
void dsim_reg_set_size_of_slice(u32 id, struct decon_lcd *lcd_info);
#endif
static long dsim_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
{
struct dsim_device *dsim = sd_to_dsim(sd);
int ret = 0;
#ifdef CONFIG_FB_DSU
static const unsigned char LCD_SEQ_TE_ON[] = {0x35,};
static const unsigned char LCD_SEQ_TE_OFF[] = { 0x34,};
static const unsigned char LCD_SEQ_DISPLAY_ON[] = { 0x29, };
static const unsigned char LCD_SEQ_DISPLAY_OFF[] = { 0x28 };
#endif
switch (cmd) {
case DSIM_IOC_GET_LCD_INFO:
v4l2_set_subdev_hostdata(sd, &dsim->lcd_info);
break;
case DSIM_IOC_ENTER_ULPS:
if ((unsigned long)arg)
ret = dsim_enter_ulps(dsim);
else
ret = dsim_exit_ulps(dsim);
break;
case DSIM_IOC_LCD_OFF:
ret = dsim_set_panel_power(dsim, 0);
break;
#ifdef CONFIG_DECON_MIPI_DSI_PKTGO
case DSIM_IOC_PKT_GO_ENABLE:
dsim_pkt_go_enable(dsim, true);
break;
case DSIM_IOC_PKT_GO_DISABLE:
dsim_pkt_go_enable(dsim, false);
break;
case DSIM_IOC_PKT_GO_READY:
dsim_pkt_go_ready(dsim);
break;
#endif
#ifdef CONFIG_FB_WINDOW_UPDATE
case DSIM_IOC_PARTIAL_CMD:
ret = dsim_partial_area_command(dsim, arg);
break;
case DSIM_IOC_SET_PORCH:
dsim_reg_set_porch(dsim->id, (struct decon_lcd *)v4l2_get_subdev_hostdata(sd));
break;
#endif
case DSIM_IOC_DUMP:
dsim_dump(dsim, 1);
break;
#ifdef CONFIG_FB_DSU
case DSIM_IOC_DSU_CMD:
ret = dsim_dsu_command(dsim, (struct decon_device *) arg );
break;
case DSIM_IOC_TE_ONOFF:
if( (bool) arg ) { // TE_ON
pr_info( "%s (DSU) send LCD_SEQ_TE_ON(%d)\n", __func__, (int)((unsigned long)arg) );
dsim_write_hl_data(dsim, LCD_SEQ_TE_ON, ARRAY_SIZE(LCD_SEQ_TE_ON));
} else { // TE_OFF
msleep(1); // this delay is requared by noise in LCD-bottom (HD->FHD)
pr_info( "%s (DSU) LCD_SEQ_TE_OFF(%d)\n", __func__, (int)((unsigned long)arg) );
dsim_write_hl_data(dsim, LCD_SEQ_TE_OFF, ARRAY_SIZE(LCD_SEQ_TE_OFF));
}
break;
case DSIM_IOC_DISPLAY_ONOFF:
if( (bool) arg ) { // TE_ON
pr_info( "%s (DSU) send LCD_SEQ_DISPLAY_ON(%d)\n", __func__, (int)((unsigned long)arg) );
dsim_write_hl_data(dsim, LCD_SEQ_DISPLAY_ON, ARRAY_SIZE(LCD_SEQ_DISPLAY_ON));
} else { // TE_OFF
pr_info( "%s (DSU) LCD_SEQ_DISPLAY_OFF(%d)\n", __func__, (int)((unsigned long)arg) );
dsim_write_hl_data(dsim, LCD_SEQ_DISPLAY_OFF, ARRAY_SIZE(LCD_SEQ_DISPLAY_OFF));
}
break;
case DSIM_IOC_DSU_RECONFIG:
pr_info("%s: DSIM_IOC_DSU_RECONFIG ++\n", __func__ );
// src code from : dsim_reg_init()
ret = 0;
break;
#endif
default:
dev_err(dsim->dev, "unsupported ioctl");
ret = -EINVAL;
break;
}
return ret;
}
static const struct v4l2_subdev_core_ops dsim_sd_core_ops = {
.ioctl = dsim_ioctl,
};
static const struct v4l2_subdev_video_ops dsim_sd_video_ops = {
.s_stream = dsim_s_stream,
};
static const struct v4l2_subdev_ops dsim_subdev_ops = {
.core = &dsim_sd_core_ops,
.video = &dsim_sd_video_ops,
};
static int dsim_link_setup(struct media_entity *entity,
const struct media_pad *local,
const struct media_pad *remote, u32 flags)
{
if (flags & MEDIA_LNK_FL_ENABLED)
dev_info(NULL, "Link is enabled\n");
else
dev_info(NULL, "Link is disabled\n");
return 0;
}
static const struct media_entity_operations dsim_entity_ops = {
.link_setup = dsim_link_setup,
};
static int dsim_register_entity(struct dsim_device *dsim)
{
struct v4l2_subdev *sd = &dsim->sd;
struct v4l2_device *v4l2_dev;
struct device *dev = dsim->dev;
struct media_pad *pads = &dsim->pad;
struct media_entity *me = &sd->entity;
struct exynos_md *md;
int ret;
v4l2_subdev_init(sd, &dsim_subdev_ops);
sd->owner = THIS_MODULE;
snprintf(sd->name, sizeof(sd->name), "exynos-mipi-dsi%d-subdev", dsim->id);
dev_set_drvdata(dev, sd);
pads[DSIM_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
me->ops = &dsim_entity_ops;
ret = media_entity_init(me, DSIM_PADS_NUM, pads, 0);
if (ret) {
dev_err(dev, "failed to initialize media entity\n");
return ret;
}
md = (struct exynos_md *)module_name_to_driver_data(MDEV_MODULE_NAME);
if (!md) {
dev_err(dev, "failed to get output media device\n");
return -ENODEV;
}
v4l2_dev = &md->v4l2_dev;
ret = v4l2_device_register_subdev(v4l2_dev, sd);
if (ret) {
dev_err(dev, "failed to register HDMI subdev\n");
return ret;
}
/* 0: DSIM_0, 1: DSIM_1 */
md->dsim_sd[dsim->id] = &dsim->sd;
return 0;
}
static ssize_t dsim_rw_test_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
static ssize_t decon_rw_test_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int ret;
unsigned long cmd;
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct dsim_device *dsim = sd_to_dsim(sd);
ret = kstrtoul(buf, 0, &cmd);
if (ret)
return ret;
ret = -ENXIO;
if (cmd == 0x1) {
dsim_info("Dsim is trying to do write test\n");
dsim_write_test(dsim);
}
else {
dsim_info("Dsim is trying to do read test\n");
dsim_read_test(dsim);
}
return ret;
}
static DEVICE_ATTR(rw_test, 0644, dsim_rw_test_show, decon_rw_test_store);
int dsim_create_rw_test_sysfs(struct dsim_device *dsim)
{
int ret = 0;
ret = device_create_file(dsim->dev, &dev_attr_rw_test);
if (ret) {
dsim_err("failed to create read & write test sysfs\n");
}
return ret;
}
static int dsim_parse_lcd_info(struct dsim_device *dsim)
{
u32 res[3];
struct device_node *node;
node = of_parse_phandle(dsim->dev->of_node, "lcd_info", 0);
dsim_info("%s is founded\n", of_node_full_name(node));
of_property_read_u32(node, "mode", &dsim->lcd_info.mode);
dsim_dbg("%s mode\n", dsim->lcd_info.mode ? "command" : "video");
of_property_read_u32_array(node, "resolution", res, 2);
dsim->lcd_info.xres = res[0];
dsim->lcd_info.yres = res[1];
dsim_info("LCD resolution: xres(%d), yres(%d)\n", res[0], res[1]);
of_property_read_u32_array(node, "size", res, 2);
dsim->lcd_info.width = res[0];
dsim->lcd_info.height = res[1];
dsim_info("LCD size: width(%d), height(%d)\n", dsim->lcd_info.width, dsim->lcd_info.height);
of_property_read_u32(node, "timing,refresh", &dsim->lcd_info.fps);
dsim_info("LCD refresh rate(%d)\n", dsim->lcd_info.fps);
of_property_read_u32_array(node, "timing,h-porch", res, 3);
dsim->lcd_info.hbp = res[0];
dsim->lcd_info.hfp = res[1];
dsim->lcd_info.hsa = res[2];
dsim_info("hbp(%d), hfp(%d), hsa(%d)\n", res[0], res[1], res[2]);
of_property_read_u32_array(node, "timing,v-porch", res, 3);
dsim->lcd_info.vbp = res[0];
dsim->lcd_info.vfp = res[1];
dsim->lcd_info.vsa = res[2];
dsim_info("vbp(%d), vfp(%d), vsa(%d)\n", res[0], res[1], res[2]);
of_property_read_u32(node, "timing,dsi-hs-clk", &dsim->lcd_info.hs_clk);
dsim->clks_param.clks.hs_clk = dsim->lcd_info.hs_clk;
dsim_dbg("requested hs clock(%d)\n", dsim->lcd_info.hs_clk);
of_property_read_u32(node, "timing,dsi-escape-clk", &dsim->lcd_info.esc_clk);
dsim->clks_param.clks.esc_clk = dsim->lcd_info.esc_clk;
dsim_dbg("requested escape clock(%d)\n", dsim->lcd_info.esc_clk);
of_property_read_u32(node, "mic", &dsim->lcd_info.mic_enabled);
dsim_info("mic is %s\n", dsim->lcd_info.mic_enabled ? "enabled" : "disabled");
of_property_read_u32(node, "mic_ver", &dsim->lcd_info.mic_ver);
dsim_dbg("mic version(%d)\n", dsim->lcd_info.mic_ver);
of_property_read_u32(node, "type_of_ddi", &dsim->lcd_info.ddi_type);
dsim_info("ddi type(%d)\n", dsim->lcd_info.ddi_type);
return 0;
}
static int dsim_probe(struct platform_device *pdev)
{
int ret = 0;
struct resource *res;
struct device *dev = &pdev->dev;
struct dsim_device *dsim = NULL;
dsim = devm_kzalloc(dev, sizeof(struct dsim_device), GFP_KERNEL);
if (!dsim) {
dev_err(dev, "failed to allocate dsim device.\n");
return -ENOMEM;
}
dsim->id = of_alias_get_id(dev->of_node, "dsim");
dsim_info("dsim(%d) probe start..\n", dsim->id);
if (!dsim->id)
dsim0_for_decon = dsim;
else
dsim1_for_decon = dsim;
dsim->dev = &pdev->dev;
ret = dsim_panel_ops_init(dsim);
if (ret) {
dsim_err("%s : failed to set panel ops\n", __func__);
goto fail_free;
}
call_panel_ops(dsim, early_probe, dsim);
dsim_get_gpios(dsim);
dsim_get_regulator(dsim);
dsim_get_clocks(dsim);
spin_lock_init(&dsim->slock);
of_property_read_u32(dev->of_node, "data_lane_cnt", &dsim->data_lane_cnt);
dev_info(dev, "using data lane count(%d)\n", dsim->data_lane_cnt);
dsim_parse_lcd_info(dsim);
/* added */
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(dev, "failed to get resource");
ret = -ENOENT;
goto fail_clock;
}
dsim_info("res: start(0x%x), end(0x%x)\n", (u32)res->start, (u32)res->end);
dsim->reg_base = devm_request_and_ioremap(dev, res);
if (!dsim->reg_base) {
dev_err(&pdev->dev, "mipi-dsi: failed to remap io region\n");
ret = -EINVAL;
goto fail_clock;
}
res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
if (!res) {
dev_err(dev, "failed to get resource");
ret = -EINVAL;
goto fail_clock;
}
dsim->irq = res->start;
ret = devm_request_irq(dev, res->start,
dsim_interrupt_handler, 0, pdev->name, dsim);
if (ret) {
dev_err(dev, "failed to install irq\n");
goto fail_clock;
}
dsim->pinctrl = devm_pinctrl_get(dev);
if (IS_ERR(dsim->pinctrl)) {
dev_err(dev, "failed to get lcd pinctrl\n");
goto fail_irq;
} else {
dsim->turnon_tes = pinctrl_lookup_state(dsim->pinctrl, "turnon_tes");
if (IS_ERR(dsim->turnon_tes)) {
dev_err(dev, "failed to get turnon_test pin state\n");
goto fail_irq;
}
dsim->turnoff_tes = pinctrl_lookup_state(dsim->pinctrl, "turnoff_tes");
if (IS_ERR(dsim->turnoff_tes)) {
dev_err(dev, "failed to get turnoff_test pin state\n");
goto fail_irq;
}
}
ret = dsim_register_entity(dsim);
if (ret)
goto fail_irq;
dsim->timing.bps = 0;
mutex_init(&dsim_rd_wr_mutex);
pm_runtime_enable(dev);
/* set using lanes */
switch (dsim->data_lane_cnt) {
case 1:
dsim->data_lane = DSIM_LANE_DATA0;
break;
case 2:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1;
break;
case 3:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1 |
DSIM_LANE_DATA2;
break;
case 4:
dsim->data_lane = DSIM_LANE_DATA0 | DSIM_LANE_DATA1 |
DSIM_LANE_DATA2 | DSIM_LANE_DATA3;
break;
default:
dev_info(dsim->dev, "data lane is invalid.\n");
ret = -EINVAL;
goto fail_mutex;
};
dsim->state = DSIM_STATE_SUSPEND;
#if defined(CONFIG_PM_RUNTIME)
pm_runtime_get_sync(dsim->dev);
#else
dsim_runtime_resume(dsim->dev);
#endif
dsim_reg_prepare_clocks(&dsim->clks_param);
/* DSIM does not need to start, if DSIM is already
* becomes HS status (enabled on LCD_ON_UBOOT) */
if (dsim_reg_is_hs_clk_ready(dsim->id)) {
/* DPHY power on: it is required to maintain ref_count */
dsim_d_phy_onoff(dsim, 1);
dsim_reg_init_probe(dsim->id, &dsim->lcd_info, dsim->data_lane_cnt);
clk_prepare_enable(dsim->res.dphy_esc);
clk_prepare_enable(dsim->res.dphy_byte);
ret = dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 1);
if (ret) {
dsim_err("%s : failed to set lanes\n" , __func__);
goto fail_mutex;
}
ret = dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 1);
if (ret) {
dsim_err("%s : failed to set hs clock\n", __func__);
goto fail_mutex;
}
dsim_reg_set_int(dsim->id, 1);
goto dsim_init_done;
}
ret = dsim_set_panel_power(dsim, 1);
if (ret) {
dsim_err("%s : failed to panel power\n", __func__);
goto fail_mutex;
}
/* DPHY power on */
dsim_d_phy_onoff(dsim, 1);
dsim_reg_init(dsim->id, &dsim->lcd_info, dsim->data_lane_cnt);
dsim_reg_enable_clocks(dsim->id, &dsim->clks_param,
DSIM_LANE_CLOCK | dsim->data_lane);
clk_prepare_enable(dsim->res.dphy_esc);
clk_prepare_enable(dsim->res.dphy_byte);
ret = dsim_reg_set_lanes(dsim->id, DSIM_LANE_CLOCK | dsim->data_lane, 1);
if (ret) {
dsim_err("%s : failed dsim set lane\n", __func__);
goto fail_mutex;
}
ret = dsim_reset_panel(dsim);
if (ret) {
dsim_err("%s : failed dsim reset panel\n", __func__);
goto fail_mutex;
}
ret = dsim_reg_set_hs_clock(dsim->id, &dsim->lcd_info, 1);
if (ret) {
dsim_err("%s : failed dsim hs clock\n", __func__);
goto fail_mutex;
}
/* enable interrupts */
dsim_reg_set_int(dsim->id, 1);
dsim_init_done:
dsim->state = DSIM_STATE_HSCLKEN;
#ifdef CONFIG_LCD_DOZE_MODE
dsim->dsim_doze = DSIM_DOZE_STATE_NORMAL;
#endif
call_panel_ops(dsim, probe, dsim);
/* TODO: displayon is moved to decon probe only in case of lcd on probe */
/* dsim->panel_ops->displayon(dsim); */
dsim_clocks_info(dsim);
dsim_create_rw_test_sysfs(dsim);
dev_info(dev, "mipi-dsi driver(%s mode) has been probed.\n",
dsim->lcd_info.mode == DECON_MIPI_COMMAND_MODE ? "CMD" : "VIDEO");
#ifdef CONFIG_LCD_ALPM
dsim->alpm = 0;
#endif
return 0;
fail_mutex:
mutex_destroy(&dsim_rd_wr_mutex);
fail_irq:
release_resource(res);
fail_clock:
dsim_put_clocks(dsim);
fail_free:
kfree(dsim);
dsim_err("%s : dsim prove failed\n", __func__);
return ret;
}
static int dsim_remove(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct dsim_device *dsim = sd_to_dsim(sd);
pm_runtime_disable(dev);
dsim_put_clocks(dsim);
mutex_destroy(&dsim_rd_wr_mutex);
dev_info(dev, "mipi-dsi driver removed\n");
return 0;
}
static void dsim_shutdown(struct platform_device *pdev)
{
int ret;
struct device *dev = &pdev->dev;
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct dsim_device *dsim = sd_to_dsim(sd);
dev_info(dev, "%s +\n", __func__);
dsim_info("dsim->state : %d\n", dsim->state);
if (dsim->state != DSIM_STATE_SUSPEND) {
ret = dsim_disable(dsim);
if (ret) {
dsim_info("%s : failed to disable\n", __func__);
goto shutdown_exit;
}
}
dev_info(dev, "mipi-dsi driver shutdown\n");
shutdown_exit:
dev_info(dev, "%s -\n", __func__);
return;
}
static const struct of_device_id dsim_match[] = {
{ .compatible = "samsung,exynos5-mipi-dsi" },
{},
};
MODULE_DEVICE_TABLE(of, dsim_match);
static struct platform_device_id dsim_ids[] = {
{
.name = "exynos-mipi-dsi"
},
{},
};
MODULE_DEVICE_TABLE(platform, dsim_ids);
static int dsim_runtime_suspend(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct dsim_device *dsim = sd_to_dsim(sd);
DISP_SS_EVENT_LOG(DISP_EVT_DSIM_SUSPEND, sd, ktime_set(0, 0));
dsim_dbg("%s +\n", __func__);
clk_disable_unprepare(dsim->res.pclk);
clk_disable_unprepare(dsim->res.rgb_vclk0);
clk_disable_unprepare(dsim->res.pclk_disp);
dsim_dbg("%s -\n", __func__);
return 0;
}
static int dsim_runtime_resume(struct device *dev)
{
struct v4l2_subdev *sd = dev_get_drvdata(dev);
struct dsim_device *dsim = sd_to_dsim(sd);
DISP_SS_EVENT_LOG(DISP_EVT_DSIM_RESUME, sd, ktime_set(0, 0));
dsim_dbg("%s: +\n", __func__);
clk_prepare_enable(dsim->res.pclk);
clk_prepare_enable(dsim->res.rgb_vclk0);
clk_prepare_enable(dsim->res.pclk_disp);
dsim_dbg("%s -\n", __func__);
return 0;
}
static const struct dev_pm_ops dsim_pm_ops = {
.runtime_suspend = dsim_runtime_suspend,
.runtime_resume = dsim_runtime_resume,
};
static struct platform_driver dsim_driver __refdata = {
.probe = dsim_probe,
.remove = dsim_remove,
.shutdown = dsim_shutdown,
.id_table = dsim_ids,
.driver = {
.name = "exynos-mipi-dsi",
.owner = THIS_MODULE,
.pm = &dsim_pm_ops,
.of_match_table = of_match_ptr(dsim_match),
.suppress_bind_attrs = true,
}
};
static int __init dsim_init(void)
{
int ret = platform_driver_register(&dsim_driver);
if (ret)
printk(KERN_ERR "mipi_dsi driver register failed\n");
return ret;
}
late_initcall(dsim_init);
static void __exit dsim_exit(void)
{
platform_driver_unregister(&dsim_driver);
}
module_exit(dsim_exit);
MODULE_AUTHOR("Jiun Yu <jiun.yu@samsung.com>");
MODULE_DESCRIPTION("Samusung MIPI-DSI driver");
|