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
|
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) Samsung Electronics Co., Ltd.
* Gwanghui Lee <gwanghui.lee@samsung.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/of_gpio.h>
#include <video/mipi_display.h>
#include <linux/lcd.h>
#include <linux/spi/spi.h>
//#include "../dpu/mipi_panel_drv.h"
#include "panel_drv.h"
#include "panel.h"
#include "panel_bl.h"
//#include "mdnie.h"
#ifdef CONFIG_EXYNOS_DECON_LCD_SPI
#include "spi.h"
#endif
#ifdef CONFIG_PANEL_AID_DIMMING
#include "dimming.h"
#include "panel_dimming.h"
#endif
const char *cmd_type_name[] = {
[CMD_TYPE_NONE] = "NONE",
[CMD_TYPE_DELAY] = "DELAY",
[CMD_TYPE_DELAY_NO_SLEEP] = "DELAY_NO_SLEEP",
[CMD_TYPE_PINCTL] = "PINCTL",
[CMD_PKT_TYPE_NONE] = "PKT_NONE",
[SPI_PKT_TYPE_WR] = "SPI_WR",
[DSI_PKT_TYPE_WR] = "DSI_WR",
[DSI_PKT_TYPE_COMP] = "DSI_DSC_WR",
[DSI_PKT_TYPE_WR_SR] = "DSI_WR_SR",
[DSI_PKT_TYPE_WR_MEM] = "DSI_WR_MEM",
[DSI_PKT_TYPE_PPS] = "DSI_WR_PPS",
[SPI_PKT_TYPE_RD] = "SPI_RD",
[DSI_PKT_TYPE_RD] = "DSI_RD",
#ifdef CONFIG_SUPPORT_DDI_FLASH
[DSI_PKT_TYPE_RD_POC] = "DSI_RD_POC",
#endif
[CMD_TYPE_RES] = "RES",
[CMD_TYPE_SEQ] = "SEQ",
[CMD_TYPE_KEY] = "KEY",
[CMD_TYPE_MAP] = "MAP",
[CMD_TYPE_DMP] = "DUMP",
};
void print_data(char *data, int size)
{
char buf[256];
int i, len = 0, sz_buf = ARRAY_SIZE(buf);
bool newline = true;
char *delim = "==============================================";
if (data == NULL || size <= 0 || size > 512) {
pr_warn("%s, invalid parameter (size %d)\n",
__func__, size);
return;
}
pr_info("%s\n", delim);
for (i = 0; i < size; i++) {
if (newline)
len += snprintf(buf + len, sz_buf - len,
"[%02Xh] ", i);
len += snprintf(buf + len, sz_buf - len,
"0x%02X", data[i]);
if (!((i + 1) % 8) || (i + 1 == size)) {
len += snprintf(buf + len, sz_buf - len, "\n");
newline = true;
} else {
len += snprintf(buf + len, sz_buf - len, " ");
newline = false;
}
if (newline) {
pr_info("%s", buf);
len = 0;
}
}
pr_info("%s\n", delim);
}
void print_maptbl(struct maptbl *tbl)
{
char strbuf[100];
char *space[3] = {"", "\t", "\t\t"};
int layer, row, col, len;
int depth = 0;
pr_info("MAPTBL %s (%d layer, %d row, %d col)\n",
tbl->name, tbl->nlayer, tbl->nrow, tbl->ncol);
for_each_layer(tbl, layer) {
for_each_row(tbl, row) {
depth++;
len = snprintf(strbuf, sizeof(strbuf),
"%s[%3d] : ", space[depth], row);
for_each_col(tbl, col) {
len += snprintf(strbuf + len,
max((int)sizeof(strbuf) - len, 0), "%02X ",
tbl->arr[sizeof_layer(tbl) * layer +
sizeof_row(tbl) * row + col]);
}
pr_info("%s\n", strbuf);
depth--;
}
pr_info("\n");
}
}
static int nr_panel;
static struct common_panel_info *panel_list[MAX_PANEL];
int register_common_panel(struct common_panel_info *info)
{
int i;
if (unlikely(!info)) {
pr_err("%s, invalid panel_info\n", __func__);
return -EINVAL;
}
if (unlikely(nr_panel >= MAX_PANEL)) {
pr_warn("%s, exceed max seqtbl\n", __func__);
return -EINVAL;
}
for (i = 0; i < nr_panel; i++) {
if (!strcmp(panel_list[i]->name, info->name) &&
panel_list[i]->id == info->id &&
panel_list[i]->rev == info->rev) {
pr_warn("%s, already exist panel (%s id-0x%06X rev-%d)\n",
__func__, info->name, info->id, info->rev);
return -EINVAL;
}
}
panel_list[nr_panel++] = info;
pr_info("%s, panel:%s id:0x%06X rev:%d) registered\n",
__func__, info->name, info->id, info->rev);
return 0;
}
static struct common_panel_info *find_common_panel_with_name(const char *name)
{
int i;
if (!name) {
panel_err("%s, invalid name\n", __func__);
return NULL;
}
for (i = 0; i < nr_panel; i++) {
if (!panel_list[i]->name)
continue;
if (!strncmp(panel_list[i]->name, name, 128)) {
pr_info("%s, found panel:%s id:0x%06X rev:%d\n",
__func__, panel_list[i]->name,
panel_list[i]->id, panel_list[i]->rev);
return panel_list[i];
}
}
return NULL;
}
void print_panel_lut(struct panel_lut_info *lut_info)
{
int i;
for (i = 0; i < lut_info->nr_panel; i++)
panel_dbg("PANEL:DBG:panel_lut names[%d] %s\n", i, lut_info->names[i]);
for (i = 0; i < lut_info->nr_lut; i++)
panel_dbg("PANEL:DBG:panel_lut[%d] id:0x%08X mask:0x%08X index:%d(%s)\n",
i, lut_info->lut[i].id, lut_info->lut[i].mask,
lut_info->lut[i].index, lut_info->names[lut_info->lut[i].index]);
}
int find_panel_lut(struct panel_device *panel, u32 id)
{
struct panel_lut_info *lut_info = &panel->panel_data.lut_info;
int i;
for (i = 0; i < lut_info->nr_lut; i++) {
if ((lut_info->lut[i].id & lut_info->lut[i].mask)
== (id & lut_info->lut[i].mask)) {
panel_info("%s, found %s (id:0x%08X lut[%d].id:0x%08X lut[%d].mask:0x%08X)\n",
__func__, lut_info->names[lut_info->lut[i].index],
id, i, lut_info->lut[i].id, i, lut_info->lut[i].mask);
return lut_info->lut[i].index;
}
pr_debug("%s, id:0x%08X lut[%d].id:0x%08X lut[%d].mask:0x%08X (0x%08X 0x%08X) - not same\n",
__func__, id, i, lut_info->lut[i].id, i, lut_info->lut[i].mask,
lut_info->lut[i].id & lut_info->lut[i].mask,
id & lut_info->lut[i].mask);
}
panel_err("%s, panel not found!! (id 0x%08X)\n", __func__, id);
return -ENODEV;
}
struct common_panel_info *find_panel(struct panel_device *panel, u32 id)
{
struct panel_lut_info *lut_info = &panel->panel_data.lut_info;
int index;
index = find_panel_lut(panel, id);
if (index < 0) {
panel_err("%s, failed to find panel lookup table\n", __func__);
return NULL;
}
if (index >= lut_info->nr_panel) {
panel_err("%s, index %d exceeded nr_panel of lut\n", __func__, index);
return NULL;
}
return find_common_panel_with_name(lut_info->names[index]);
}
int find_panel_ddi_lut(struct panel_device *panel, u32 id)
{
struct panel_lut_info *lut_info = &panel->panel_data.lut_info;
int i;
for (i = 0; i < lut_info->nr_lut; i++) {
if ((lut_info->lut[i].id & lut_info->lut[i].mask)
== (id & lut_info->lut[i].mask)) {
panel_info("%s, found %s (id:0x%08X lut[%d].id:0x%08X lut[%d].mask:0x%08X)\n",
__func__, lut_info->ddi_node[lut_info->lut[i].ddi_index]->name,
id, i, lut_info->lut[i].id, i, lut_info->lut[i].mask);
return lut_info->lut[i].ddi_index;
}
pr_debug("%s, id:0x%08X lut[%d].id:0x%08X lut[%d].mask:0x%08X (0x%08X 0x%08X) - not same\n",
__func__, id, i, lut_info->lut[i].id, i, lut_info->lut[i].mask,
lut_info->lut[i].id & lut_info->lut[i].mask,
id & lut_info->lut[i].mask);
}
panel_err("%s, panel not found!! (id 0x%08X)\n", __func__, id);
return -ENODEV;
}
struct device_node *find_panel_ddi_node(struct panel_device *panel, u32 id)
{
struct panel_lut_info *lut_info = &panel->panel_data.lut_info;
int index;
index = find_panel_ddi_lut(panel, id);
if (index < 0) {
panel_err("%s, failed to find panel lookup table\n", __func__);
return NULL;
}
if (index >= lut_info->nr_panel_ddi) {
panel_err("%s, index %d exceeded nr_panel_ddi of lut\n", __func__, index);
return NULL;
}
return lut_info->ddi_node[index];
}
struct seqinfo *find_panel_seqtbl(struct panel_info *panel_data, char *name)
{
int i;
if (unlikely(!panel_data->seqtbl)) {
panel_err("%s, seqtbl not exist\n", __func__);
return NULL;
}
for (i = 0; i < panel_data->nr_seqtbl; i++) {
if (unlikely(!panel_data->seqtbl[i].name))
continue;
if (!strcmp(panel_data->seqtbl[i].name, name)) {
panel_dbg("%s, found %s panel seqtbl\n", __func__, name);
return &panel_data->seqtbl[i];
}
}
return NULL;
}
struct seqinfo *find_index_seqtbl(struct panel_info *panel_data, u32 index)
{
struct seqinfo *tbl;
if (unlikely(!panel_data->seqtbl)) {
panel_err("%s, seqtbl not exist\n", __func__);
return NULL;
}
if (unlikely(index >= MAX_PANEL_SEQ)) {
panel_err("%s, invalid paramter (index %d)\n",
__func__, index);
return NULL;
}
tbl = &panel_data->seqtbl[index];
if (tbl != NULL)
pr_debug("%s, found %s panel seqtbl\n", __func__, tbl->name);
return tbl;
}
struct pktinfo *alloc_static_packet(char *name, u32 type, u8 *data, u32 dlen)
{
struct pktinfo *info = kzalloc(sizeof(struct pktinfo), GFP_KERNEL);
info->name = name;
info->type = type;
info->data = data;
info->dlen = dlen;
return info;
}
struct pktinfo *find_packet(struct seqinfo *seqtbl, char *name)
{
int i;
void **cmdtbl;
if (unlikely(!seqtbl || !name)) {
pr_err("%s, invalid paramter (seqtbl %p, name %p)\n",
__func__, seqtbl, name);
return NULL;
}
cmdtbl = seqtbl->cmdtbl;
if (unlikely(!cmdtbl)) {
pr_err("%s, invalid command table\n", __func__);
return NULL;
}
for (i = 0; i < seqtbl->size; i++) {
if (cmdtbl[i] == NULL) {
pr_debug("%s, end of cmdtbl %d\n", __func__, i);
break;
}
if (!strcmp(((struct cmdinfo *)cmdtbl[i])->name, name))
return cmdtbl[i];
}
return NULL;
}
struct pktinfo *find_packet_suffix(struct seqinfo *seqtbl, char *name)
{
int i, j, len;
void **cmdtbl;
if (unlikely(!seqtbl || !name)) {
pr_err("%s, invalid paramter (seqtbl %p, name %p)\n",
__func__, seqtbl, name);
return NULL;
}
cmdtbl = seqtbl->cmdtbl;
if (unlikely(!cmdtbl)) {
pr_err("%s, invalid command table\n", __func__);
return NULL;
}
for (i = 0; i < seqtbl->size; i++) {
if (cmdtbl[i] == NULL) {
pr_debug("%s, end of cmdtbl %d\n", __func__, i);
break;
}
len = strlen(((struct cmdinfo *)cmdtbl[i])->name);
for (j = 0; j < len; j++) {
if (!strcmp(&((struct cmdinfo *)cmdtbl[i])->name[j], name))
return cmdtbl[i];
}
}
return NULL;
}
struct maptbl *find_panel_maptbl_by_index(struct panel_info *panel, int index)
{
if (unlikely(!panel || !panel->maptbl)) {
pr_err("%s, maptbl not exist\n", __func__);
return NULL;
}
if (index < 0 || index >= panel->nr_maptbl) {
pr_err("%s, out of range (index %d)\n", __func__, index);
return NULL;
}
return &panel->maptbl[index];
}
struct maptbl *find_panel_maptbl_by_name(struct panel_info *panel_data, char *name)
{
int i = 0;
if (unlikely(!panel_data || !panel_data->maptbl)) {
pr_err("%s, maptbl not exist\n", __func__);
return NULL;
}
for (i = 0; i < panel_data->nr_maptbl; i++)
if (strstr(panel_data->maptbl[i].name, name))
return &panel_data->maptbl[i];
return NULL;
}
struct panel_dimming_info *
find_panel_dimming(struct panel_info *panel_data, char *name)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(panel_data->panel_dim_info); i++) {
if (!strcmp(panel_data->panel_dim_info[i]->name, name)) {
panel_dbg("%s, found %s panel dimming\n", __func__, name);
return panel_data->panel_dim_info[i];
}
}
return NULL;
}
u32 maptbl_index(struct maptbl *tbl, int layer, int row, int col)
{
return (tbl->nrow * tbl->ncol * layer) + (tbl->ncol * row) + col;
}
int maptbl_init(struct maptbl *tbl)
{
int ret;
if (!tbl || !tbl->ops.init)
return -EINVAL;
ret = tbl->ops.init(tbl);
if (ret < 0) {
pr_err("%s failed to init maptbl(%s)\n",
__func__, tbl->name);
return ret;
}
tbl->initialized = true;
return 0;
}
int maptbl_getidx(struct maptbl *tbl)
{
if (!tbl || !tbl->initialized ||
!tbl->ops.getidx)
return -EINVAL;
return tbl->ops.getidx(tbl);
}
u8 *maptbl_getptr(struct maptbl *tbl)
{
int index = maptbl_getidx(tbl);
if (unlikely(index < 0)) {
pr_err("%s, failed to get index\n", __func__);
return NULL;
}
if (unlikely(!tbl->arr)) {
pr_err("%s, failed to get pointer\n", __func__);
return NULL;
}
return &tbl->arr[index];
}
void maptbl_copy(struct maptbl *tbl, u8 *dst)
{
if (!tbl || !tbl->initialized ||
!dst || !tbl->ops.copy)
return;
tbl->ops.copy(tbl, dst);
}
void maptbl_memcpy(struct maptbl *dst, struct maptbl *src)
{
if (!dst || !src || dst->nlayer != src->nlayer ||
dst->nrow != src->nrow || dst->ncol != src->ncol) {
pr_err("%s failed to copy from:%s to:%s size:%d\n",
__func__, (!src || !src->name) ? "" : src->name,
(!dst || !dst->name) ? "" : dst->name,
(!dst) ? 0 : sizeof_maptbl(dst));
return;
}
memcpy(dst->arr, src->arr, sizeof_maptbl(dst));
}
struct maptbl *maptbl_find(struct panel_info *panel, char *name)
{
int i;
if (unlikely(!panel || !name)) {
pr_err("%s, invalid parameter\n", __func__);
return NULL;
}
if (unlikely(!panel->maptbl)) {
pr_err("%s, maptbl not exist\n", __func__);
return NULL;
}
for (i = 0; i < panel->nr_maptbl; i++)
if (!strcmp(name, panel->maptbl[i].name))
return &panel->maptbl[i];
return NULL;
}
int pktui_maptbl_getidx(struct pkt_update_info *pktui)
{
if (pktui && pktui->getidx)
return pktui->getidx(pktui);
return -EINVAL;
}
void panel_update_packet_data(struct panel_device *panel, struct pktinfo *info)
{
struct pkt_update_info *pktui;
struct maptbl *maptbl;
int i, idx, offset;
if (!info || !info->data || !info->pktui || !info->nr_pktui) {
pr_warn("%s, invalid pkt update info\n", __func__);
return;
}
pktui = info->pktui;
/*
* TODO : move out pktui->pdata initial code
* panel_pkt_update_info_init();
*/
for (i = 0; i < info->nr_pktui; i++) {
pktui[i].pdata = panel;
offset = pktui[i].offset;
if (pktui[i].nr_maptbl > 1 && pktui[i].getidx) {
idx = pktui_maptbl_getidx(&pktui[i]);
if (unlikely(idx < 0)) {
pr_err("%s, failed to pktui_maptbl_getidx %d\n", __func__, idx);
return;
}
maptbl = &pktui[i].maptbl[idx];
} else {
maptbl = pktui[i].maptbl;
}
if (unlikely(!maptbl)) {
pr_err("%s, invalid info (offset %d, maptbl %p)\n",
__func__, pktui[i].offset, pktui[i].maptbl);
return;
}
if (!maptbl->initialized) {
pr_info("%s init maptbl(%s) +\n", __func__, maptbl->name);
maptbl_init(maptbl);
pr_info("%s init maptbl(%s) -\n", __func__, maptbl->name);
}
if (unlikely(offset + maptbl->sz_copy > info->dlen)) {
pr_err("%s, out of range (offset %d, sz_copy %d, dlen %d)\n",
__func__, offset, maptbl->sz_copy, info->dlen);
return;
}
maptbl_copy(maptbl, &info->data[offset]);
#ifdef DEBUG_PANEL
pr_info("%s, copy %d bytes from %s to %s[%d]\n",
__func__, maptbl->sz_copy, maptbl->name, info->name, offset);
#endif
}
}
static int panel_do_delay(struct panel_device *panel, struct delayinfo *info, ktime_t s_time)
{
ktime_t e_time = ktime_get();
int remained_usec = 0;
if (unlikely(!panel || !info)) {
panel_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
if (ktime_after(e_time, ktime_add_us(s_time, info->usec))) {
pr_debug("%s skip delay (elapsed %lld usec >= requested %d usec)\n",
__func__, ktime_to_us(ktime_sub(e_time, s_time)), info->usec);
return 0;
}
if (info->usec >= (u32)ktime_to_us(ktime_sub(e_time, s_time)))
remained_usec = info->usec - (u32)ktime_to_us(ktime_sub(e_time, s_time));
if (remained_usec > 0)
usleep_range(remained_usec, remained_usec + 1);
return 0;
}
static int panel_do_delay_no_sleep(struct panel_device *panel, struct delayinfo *info, ktime_t s_time)
{
ktime_t e_time = ktime_get();
int remained_usec = 0;
if (unlikely(!panel || !info)) {
panel_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
if (ktime_after(e_time, ktime_add_us(s_time, info->usec))) {
pr_debug("%s skip delay (elapsed %lld usec >= requested %d usec)\n",
__func__, ktime_to_us(ktime_sub(e_time, s_time)), info->usec);
return 0;
}
if (info->usec >= (u32)ktime_to_us(ktime_sub(e_time, s_time)))
remained_usec = info->usec - (u32)ktime_to_us(ktime_sub(e_time, s_time));
if (remained_usec > 0)
udelay(remained_usec);
return 0;
}
static int panel_do_pinctl(struct panel_device *panel, struct pininfo *info)
{
if (unlikely(!panel || !info)) {
pr_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
if (info->pin) {
// TODO : control external pin
#ifdef DEBUG_PANEL
pr_info("%s, set %d pin %s\n",
__func__, info->pin, info->onoff ? "on" : "off");
#endif
}
return 0;
}
#ifdef CONFIG_SUPPORT_POC_SPI
static int panel_spi_read_data(struct panel_device *panel,
u8 cmd_id, u8 *buf, int size)
{
struct panel_spi_dev *spi_dev;
if (!panel)
return -EINVAL;
spi_dev = &panel->panel_spi_dev;
if (!spi_dev)
return -EINVAL;
return spi_dev->ops->read(spi_dev, cmd_id, buf, size);
}
#endif
static int panel_dsi_write_data(struct panel_device *panel,
u8 cmd_id, const u8 *buf, u8 ofs, int size, bool block)
{
u32 option = 0;
if (unlikely(!panel || !panel->mipi_drv.write))
return -EINVAL;
if ((panel->panel_data.ddi_props.gpara &
DDI_SUPPORT_POINT_GPARA))
option |= DSIM_OPTION_POINT_GPARA;
if (block)
option |= DSIM_OPTION_WAIT_TX_DONE;
return panel->mipi_drv.write(panel->dsi_id, cmd_id, buf, ofs, size, option, true);
}
static int panel_dsi_write_data_no_wakable(struct panel_device *panel,
u8 cmd_id, const u8 *buf, u8 ofs, int size, bool block)
{
u32 option = 0;
if (unlikely(!panel || !panel->mipi_drv.write))
return -EINVAL;
if ((panel->panel_data.ddi_props.gpara &
DDI_SUPPORT_POINT_GPARA))
option |= DSIM_OPTION_POINT_GPARA;
if (block)
option |= DSIM_OPTION_WAIT_TX_DONE;
return panel->mipi_drv.write(panel->dsi_id, cmd_id, buf, ofs, size, option, false);
}
/* Todo need to move dt file */
#define SRAM_BYTE_ALIGN 16
static int panel_dsi_write_mem(struct panel_device *panel,
u8 cmd_id, const u8 *buf, u8 ofs, int size)
{
u8 c_start = 0, c_next = 0;
/* TODO: 512 NEED TO CHANGE AS DSIM_FIFO_SIZE */
u8 cmdbuf[512];
int tx_size, ret, len = 0;
int remained = size;
if (unlikely(!panel || !panel->mipi_drv.write))
return -EINVAL;
if (cmd_id == MIPI_DSI_WR_GRAM_CMD) {
c_start = MIPI_DCS_WRITE_GRAM_START;
c_next = MIPI_DCS_WRITE_GRAM_CONTINUE;
} else if (cmd_id == MIPI_DSI_WR_SRAM_CMD) {
c_start = MIPI_DCS_WRITE_SIDE_RAM_START;
c_next = MIPI_DCS_WRITE_SIDE_RAM_CONTINUE;
} else {
panel_err("%s:invalid cmd_id %d\n",
__func__, cmd_id);
return -EINVAL;
}
do {
cmdbuf[0] = (size == remained) ? c_start : c_next;
tx_size = min(remained, 511);
tx_size -= (tx_size % SRAM_BYTE_ALIGN);
memcpy(cmdbuf + 1, buf + len, tx_size);
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
cmdbuf, 0, tx_size + 1, false);
if (ret != tx_size + 1) {
panel_err("%s:failed to write command\n", __func__);
return -EINVAL;
}
len += tx_size;
remained -= tx_size;
pr_debug("%s tx_size %d len %d, remained %d\n",
__func__, tx_size, len, remained);
} while (remained > 0);
return len;
}
static int panel_dsi_read_data(struct panel_device *panel,
u8 addr, u8 ofs, u8 *buf, int size)
{
u32 option = 0;
if (unlikely(!panel || !panel->mipi_drv.read))
return -EINVAL;
if ((panel->panel_data.ddi_props.gpara &
DDI_SUPPORT_POINT_GPARA))
option |= DSIM_OPTION_POINT_GPARA;
return panel->mipi_drv.read(panel->dsi_id, addr, ofs, buf, size, option);
}
static int panel_dsi_get_state(struct panel_device *panel)
{
if (unlikely(!panel || !panel->mipi_drv.get_state))
return -EINVAL;
return panel->mipi_drv.get_state(panel->dsi_id);
}
int panel_set_key(struct panel_device *panel, int level, bool on)
{
int ret = 0;
static const unsigned char SEQ_TEST_KEY_ON_9F[] = { 0x9F, 0xA5, 0xA5 };
static const unsigned char SEQ_TEST_KEY_ON_F0[] = { 0xF0, 0x5A, 0x5A };
static const unsigned char SEQ_TEST_KEY_ON_FC[] = { 0xFC, 0x5A, 0x5A };
static const unsigned char SEQ_TEST_KEY_OFF_9F[] = { 0x9F, 0x5A, 0x5A };
static const unsigned char SEQ_TEST_KEY_OFF_F0[] = { 0xF0, 0xA5, 0xA5 };
static const unsigned char SEQ_TEST_KEY_OFF_FC[] = { 0xFC, 0xA5, 0xA5 };
if (unlikely(!panel)) {
panel_err("ERR:PANEL:%s: panel is null\n", __func__);
return -EINVAL;
}
if (on) {
if (level >= 1) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_ON_9F, 0, ARRAY_SIZE(SEQ_TEST_KEY_ON_9F), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_9F)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_ON_9F\n", __func__);
return -EIO;
}
}
if (level >= 2) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_ON_F0, 0, ARRAY_SIZE(SEQ_TEST_KEY_ON_F0), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_ON_F0\n", __func__);
return -EIO;
}
}
if (level >= 3) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_ON_FC, 0, ARRAY_SIZE(SEQ_TEST_KEY_ON_FC), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_ON_FC\n", __func__);
return -EIO;
}
}
} else {
if (level >= 3) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_OFF_FC, 0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_FC), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_FC)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_OFF_FC\n", __func__);
return -EIO;
}
}
if (level >= 2) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_OFF_F0, 0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_F0), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_F0)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_OFF_F0\n", __func__);
return -EIO;
}
}
if (level >= 1) {
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD,
SEQ_TEST_KEY_OFF_9F, 0, ARRAY_SIZE(SEQ_TEST_KEY_OFF_9F), false);
if (ret != ARRAY_SIZE(SEQ_TEST_KEY_ON_9F)) {
pr_err("%s : fail to write CMD : SEQ_TEST_KEY_OFF_9F\n", __func__);
return -EIO;
}
}
}
return 0;
}
int panel_verify_tx_packet(struct panel_device *panel, u8 *src, u8 ofs, u8 len)
{
u8 *buf;
int i, ret = 0;
unsigned char addr = src[0];
unsigned char *data = src + 1;
if (unlikely(!panel)) {
panel_err("PANEL:ERR:%s:panel is null\n", __func__);
return -EINVAL;
}
if (!IS_PANEL_ACTIVE(panel))
return 0;
buf = kcalloc(len, sizeof(u8), GFP_KERNEL);
if (!buf) {
pr_err("%s, failed to alloc memory\n", __func__);
return -ENOMEM;
}
//mutex_lock(&panel->op_lock);
panel_rx_nbytes(panel, DSI_PKT_TYPE_RD, buf, addr, 0, len - 1);
for (i = 0; i < len - 1; i++) {
if (buf[i] != data[i]) {
pr_warn("%02Xh[%2d] - (tx 0x%02X, rx 0x%02X) not match\n",
addr, i, data[i], buf[i]);
ret = -EINVAL;
} else {
pr_info("%02Xh[%2d] - (tx 0x%02X, rx 0x%02X) match\n",
addr, i, data[i], buf[i]);
}
}
//mutex_unlock(&panel->op_lock);
kfree(buf);
return ret;
}
static int panel_do_tx_packet(struct panel_device *panel, struct pktinfo *info, bool block)
{
int ret;
u32 type;
u8 addr = 0, cmd_id = MIPI_DSI_WR_UNKNOWN;
if (unlikely(!panel || !info)) {
panel_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
if (info->pktui)
panel_update_packet_data(panel, info);
type = info->type;
#ifdef DEBUG_PANEL
panel_dbg("%s, send packet %s - start\n", __func__, info->name);
#endif
switch (type) {
case DSI_PKT_TYPE_COMP:
cmd_id = MIPI_DSI_WR_DSC_CMD;
break;
case DSI_PKT_TYPE_PPS:
cmd_id = MIPI_DSI_WR_PPS_CMD;
break;
case DSI_PKT_TYPE_WR:
cmd_id = MIPI_DSI_WR_GEN_CMD;
addr = info->data ? info->data[0] : 0;
break;
case DSI_PKT_TYPE_WR_NO_WAKE:
cmd_id = MIPI_DSI_WR_CMD_NO_WAKE;
addr = info->data ? info->data[0] : 0;
break;
case DSI_PKT_TYPE_WR_MEM:
cmd_id = MIPI_DSI_WR_GRAM_CMD;
addr = info->data ? info->data[0] : 0;
break;
case DSI_PKT_TYPE_WR_SR:
cmd_id = MIPI_DSI_WR_SRAM_CMD;
addr = info->data ? info->data[0] : 0;
break;
case CMD_PKT_TYPE_NONE:
case DSI_PKT_TYPE_RD:
default:
cmd_id = MIPI_DSI_WR_UNKNOWN;
break;
}
if (cmd_id == MIPI_DSI_WR_UNKNOWN) {
panel_err("%s, unknown type\n", __func__);
return -EINVAL;
}
#ifdef DEBUG_PANEL
panel_dbg("%s, %s start\n", __func__, info->name);
#endif
if (info->option & PKT_OPTION_CHECK_TX_DONE ||
(addr == MIPI_DCS_SOFT_RESET ||
addr == MIPI_DCS_SET_DISPLAY_ON ||
addr == MIPI_DCS_SET_DISPLAY_OFF ||
addr == MIPI_DCS_ENTER_SLEEP_MODE ||
addr == MIPI_DCS_EXIT_SLEEP_MODE ||
/* poc command */
addr == 0xC0 || addr == 0xC1))
block = true;
if (cmd_id == MIPI_DSI_WR_GRAM_CMD ||
cmd_id == MIPI_DSI_WR_SRAM_CMD)
ret = panel_dsi_write_mem(panel, cmd_id,
info->data, info->offset, info->dlen);
else if (cmd_id == MIPI_DSI_WR_CMD_NO_WAKE)
ret = panel_dsi_write_data_no_wakable(panel, cmd_id,
info->data, info->offset, info->dlen, block);
else
ret = panel_dsi_write_data(panel, cmd_id,
info->data, info->offset, info->dlen, block);
if (ret != info->dlen) {
panel_err("%s, failed to send packet %s (ret %d)\n",
__func__, info->name, ret);
return -EINVAL;
}
#ifdef DEBUG_PANEL
panel_dbg("%s, %s end\n", __func__, info->name);
print_data(info->data, info->dlen);
#endif
return 0;
}
#ifdef CONFIG_SUPPORT_POC_SPI
static int panel_spi_packet(struct panel_device *panel, struct pktinfo *info)
{
struct panel_spi_dev *spi_dev;
int ret = 0;
u32 type;
if (unlikely(!panel || !info)) {
panel_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
spi_dev = &panel->panel_spi_dev;
if (!spi_dev) {
panel_err("%s, spi_dev not found\n", __func__);
return -EINVAL;
}
if (!spi_dev->ops) {
panel_err("%s, spi_dev.ops not found\n", __func__);
return -EINVAL;
}
if (info->pktui)
panel_update_packet_data(panel, info);
type = info->type;
switch (type) {
case SPI_PKT_TYPE_WR:
if (!spi_dev->ops->cmd) {
ret = -ENOTSUPP;
break;
}
ret = spi_dev->ops->cmd(spi_dev, info->data, info->dlen, NULL, 0);
break;
case SPI_PKT_TYPE_SETPARAM:
if (!spi_dev->ops->setparam) {
ret = -ENOTSUPP;
break;
}
ret = spi_dev->ops->setparam(spi_dev, info->data, info->dlen);
break;
default:
break;
}
if (ret < 0) {
panel_err("%s, failed to send spi packet %s (ret %d type %d)\n", __func__, info->name, ret, type);
return -EINVAL;
}
return 0;
}
#endif
static int panel_do_setkey(struct panel_device *panel, struct keyinfo *info, bool block)
{
struct panel_info *panel_data;
bool send_packet = false;
int ret = 0;
if (unlikely(!panel || !info)) {
panel_err("%s, invalid paramter (panel %p, info %p)\n",
__func__, panel, info);
return -EINVAL;
}
if (info->level < 0 || info->level >= MAX_CMD_LEVEL) {
panel_err("%s, invalid level %d\n", __func__, info->level);
return -EINVAL;
}
if (info->en != KEY_ENABLE && info->en != KEY_DISABLE) {
panel_err("%s, invalid key type %d\n", __func__, info->en);
return -EINVAL;
}
panel_data = &panel->panel_data;
if (info->en == KEY_ENABLE) {
if (panel_data->props.key[info->level] == 0)
send_packet = true;
panel_data->props.key[info->level] += 1;
} else if (info->en == KEY_DISABLE) {
if (panel_data->props.key[info->level] < 1) {
panel_err("%s unbalanced key [%d]%s(%d)\n", __func__, info->level,
(panel_data->props.key[info->level] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[info->level]);
return -EINVAL;
}
if (panel_data->props.key[info->level] == 1)
send_packet = true;
panel_data->props.key[info->level] -= 1;
}
if (send_packet) {
ret = panel_do_tx_packet(panel, info->packet, block);
if (ret < 0) {
panel_err("%s failed %s\n", __func__,
info->packet->name);
}
} else {
pr_warn("%s ignore send key %d %s packet\n",
__func__, info->level, info->en ? "ENABLED" : "DISABLED");
}
#ifdef DEBUG_PANEL
panel_dbg("%s key [1]%s(%d) [2]%s(%d) [3]%s(%d)\n", __func__,
(panel_data->props.key[CMD_LEVEL_1] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_1],
(panel_data->props.key[CMD_LEVEL_2] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_2],
(panel_data->props.key[CMD_LEVEL_3] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_3]);
#endif
return 0;
}
int panel_do_init_maptbl(struct panel_device *panel, struct maptbl *maptbl)
{
int ret;
if (unlikely(!panel || !maptbl)) {
panel_err("%s, invalid paramter (panel %p, maptbl %p)\n",
__func__, panel, maptbl);
return -EINVAL;
}
ret = maptbl_init(maptbl);
if (ret < 0) {
panel_err("%s failed to init maptbl(%s) ret %d\n",
__func__, maptbl->name, ret);
return ret;
}
return 0;
}
int panel_do_seqtbl(struct panel_device *panel, struct seqinfo *seqtbl)
{
int i, ret = 0;
u32 type;
void **cmdtbl;
bool block = false;
ktime_t s_time = ktime_get();
if (unlikely(!panel || !seqtbl)) {
pr_err("%s, invalid paramter (panel %p, seqtbl %p)\n",
__func__, panel, seqtbl);
return -EINVAL;
}
cmdtbl = seqtbl->cmdtbl;
if (unlikely(!cmdtbl)) {
pr_err("%s, invalid command table\n", __func__);
return -EINVAL;
}
for (i = 0; i < seqtbl->size; i++) {
if (cmdtbl[i] == NULL) {
pr_debug("%s, end of cmdtbl %d\n", __func__, i);
break;
}
type = *((u32 *)cmdtbl[i]);
if (type >= MAX_CMD_TYPE) {
pr_warn("%s invalid cmd type %d\n", __func__, type);
break;
}
#ifdef DEBUG_PANEL
pr_info("SEQ: %s %s %s+\n", seqtbl->name, cmd_type_name[type],
(((struct cmdinfo *)cmdtbl[i])->name ?
((struct cmdinfo *)cmdtbl[i])->name : "none"));
#endif
switch (type) {
case CMD_TYPE_KEY:
if (i + 1 < seqtbl->size && cmdtbl[i + 1] &&
!IS_CMD_TYPE_TX_PKT(*((u32 *)cmdtbl[i + 1])))
block = true;
ret = panel_do_setkey(panel, (struct keyinfo *)cmdtbl[i], block);
break;
case CMD_TYPE_DELAY:
ret = panel_do_delay(panel, (struct delayinfo *)cmdtbl[i], s_time);
break;
case CMD_TYPE_DELAY_NO_SLEEP:
ret = panel_do_delay_no_sleep(panel, (struct delayinfo *)cmdtbl[i], s_time);
break;
case CMD_TYPE_PINCTL:
ret = panel_do_pinctl(panel, (struct pininfo *)cmdtbl[i]);
break;
case CMD_TYPE_TX_PKT_START ... CMD_TYPE_TX_PKT_END:
if (i + 1 < seqtbl->size && cmdtbl[i + 1] &&
!IS_CMD_TYPE_TX_PKT(*((u32 *)cmdtbl[i + 1])))
block = true;
ret = panel_do_tx_packet(panel, (struct pktinfo *)cmdtbl[i], block);
break;
case CMD_TYPE_RES:
ret = panel_resource_update(panel, (struct resinfo *)cmdtbl[i]);
break;
case CMD_TYPE_SEQ:
ret = panel_do_seqtbl(panel, (struct seqinfo *)cmdtbl[i]);
break;
case CMD_TYPE_MAP:
ret = panel_do_init_maptbl(panel, (struct maptbl *)cmdtbl[i]);
break;
case CMD_TYPE_DMP:
ret = panel_dumpinfo_update(panel, (struct dumpinfo *)cmdtbl[i]);
break;
#ifdef CONFIG_SUPPORT_POC_SPI
case SPI_PKT_TYPE_WR:
case SPI_PKT_TYPE_SETPARAM:
ret = panel_spi_packet(panel, (struct pktinfo *)cmdtbl[i]);
break;
#endif
case CMD_TYPE_NONE:
default:
pr_warn("%s, unknown pakcet type %d\n", __func__, type);
break;
}
if (ret < 0) {
pr_err("%s, failed to do(seq:%s type:%s cmd:%s)\n", __func__,
seqtbl->name, cmd_type_name[type],
(((struct cmdinfo *)cmdtbl[i])->name ?
((struct cmdinfo *)cmdtbl[i])->name : "none"));
/*
* CMD_TYP_DMP seq is intended for debugging only.
* So if it's failed, go through the dump seq.
*/
if (type != CMD_TYPE_DMP)
return ret;
}
s_time = ktime_get();
#ifdef DEBUG_PANEL
pr_info("SEQ: %s %s %s-\n", seqtbl->name, cmd_type_name[type],
(((struct cmdinfo *)cmdtbl[i])->name ?
((struct cmdinfo *)cmdtbl[i])->name : "none"));
#endif
}
return 0;
}
int excute_seqtbl_nolock(struct panel_device *panel, struct seqinfo *seqtbl, int index)
{
int ret;
struct seqinfo *tbl;
struct panel_info *panel_data;
struct timespec cur_ts, last_ts, delta_ts;
s64 elapsed_usec;
if (panel == NULL) {
panel_err("ERR:PANEL:%s:panel is null\n", __func__);
return -EINVAL;
}
if (seqtbl == NULL) {
panel_err("ERR:PANEL:%s:seqtbl is null\n", __func__);
return -EINVAL;
}
if (!IS_PANEL_ACTIVE(panel))
return -EIO;
panel_data = &panel->panel_data;
tbl = seqtbl;
ktime_get_ts(&cur_ts);
if (panel_data->props.key[CMD_LEVEL_1] != 0 ||
panel_data->props.key[CMD_LEVEL_2] != 0 ||
panel_data->props.key[CMD_LEVEL_3] != 0) {
panel_warn("%s before seq:%s unbalanced key [1]%s(%d) [2]%s(%d) [3]%s(%d)\n",
__func__, tbl[index].name,
(panel_data->props.key[CMD_LEVEL_1] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_1],
(panel_data->props.key[CMD_LEVEL_2] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_2],
(panel_data->props.key[CMD_LEVEL_3] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_3]);
panel_data->props.key[CMD_LEVEL_1] = 0;
panel_data->props.key[CMD_LEVEL_2] = 0;
panel_data->props.key[CMD_LEVEL_3] = 0;
}
ret = panel_do_seqtbl(panel, &tbl[index]);
if (unlikely(ret < 0)) {
pr_err("%s, failed to excute seqtbl %s\n",
__func__, tbl[index].name);
ret = -EIO;
goto do_exit;
}
do_exit:
if (panel_data->props.key[CMD_LEVEL_1] != 0 ||
panel_data->props.key[CMD_LEVEL_2] != 0 ||
panel_data->props.key[CMD_LEVEL_3] != 0) {
panel_warn("%s after seq:%s unbalanced key [1]%s(%d) [2]%s(%d) [3]%s(%d)\n",
__func__, tbl[index].name,
(panel_data->props.key[CMD_LEVEL_1] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_1],
(panel_data->props.key[CMD_LEVEL_2] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_2],
(panel_data->props.key[CMD_LEVEL_3] > 0 ? "ENABLED" : "DISABLED"),
panel_data->props.key[CMD_LEVEL_3]);
panel_data->props.key[CMD_LEVEL_1] = 0;
panel_data->props.key[CMD_LEVEL_2] = 0;
panel_data->props.key[CMD_LEVEL_3] = 0;
}
ktime_get_ts(&last_ts);
delta_ts = timespec_sub(last_ts, cur_ts);
elapsed_usec = timespec_to_ns(&delta_ts) / 1000;
pr_debug("seq:%s done (elapsed %2lld.%03lld msec)\n",
tbl[index].name, elapsed_usec / 1000, elapsed_usec % 1000);
return 0;
}
int panel_do_seqtbl_by_index_nolock(struct panel_device *panel, int index)
{
if (panel == NULL) {
panel_err("ERR:PANEL:%s:invalid panel\n", __func__);
return -EINVAL;
}
if (panel->panel_data.seqtbl == NULL) {
panel_err("ERR:PANEL:%s:invalid seqtbl\n", __func__);
return -EINVAL;
}
if (unlikely(index < 0 || index >= MAX_PANEL_SEQ)) {
panel_err("%s, invalid paramter (panel %p, index %d)\n",
__func__, panel, index);
return -EINVAL;
}
return excute_seqtbl_nolock(panel, panel->panel_data.seqtbl, index);
}
int panel_do_seqtbl_by_index(struct panel_device *panel, int index)
{
int ret;
mutex_lock(&panel->op_lock);
ret = panel_do_seqtbl_by_index_nolock(panel, index);
mutex_unlock(&panel->op_lock);
return ret;
}
struct resinfo *find_panel_resource(struct panel_info *panel_data, char *name)
{
int i = 0;
if (unlikely(!panel_data->restbl))
return NULL;
for (i = 0; i < panel_data->nr_restbl; i++)
if (!strcmp(name, panel_data->restbl[i].name))
return &panel_data->restbl[i];
return NULL;
}
bool panel_resource_initialized(struct panel_info *panel_data, char *name)
{
struct resinfo *res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
panel_err("%s, %s not found in resource\n",
__func__, name);
return false;
}
return res->state == RES_INITIALIZED;
}
int rescpy(u8 *dst, struct resinfo *res, u32 offset, u32 len)
{
if (unlikely(!dst || !res)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
if (unlikely(offset + len > res->dlen)) {
pr_err("%s, exceed range (offset %d, len %d, res->dlen %d\n",
__func__, offset, len, res->dlen);
return -EINVAL;
}
memcpy(dst, &res->data[offset], len);
return 0;
}
int rescpy_by_name(struct panel_info *panel_data, u8 *dst, char *name, u32 offset, u32 len)
{
struct resinfo *res;
if (unlikely(!panel_data || !dst || !name)) {
panel_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
panel_err("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
if (unlikely(offset + len > res->dlen)) {
panel_err("%s, exceed range (offset %d, len %d, res->dlen %d\n",
__func__, offset, len, res->dlen);
return -EINVAL;
}
memcpy(dst, &res->data[offset], len);
return 0;
}
int get_panel_resource_size(struct resinfo *res)
{
if (unlikely(!res)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
return res->dlen;
}
int resource_clear(struct resinfo *res)
{
if (!res)
return -EINVAL;
res->state = RES_UNINITIALIZED;
return 0;
}
int resource_clear_by_name(struct panel_info *panel_data, char *name)
{
struct resinfo *res;
if (unlikely(!panel_data || !name)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
pr_warn("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
return resource_clear(res);
}
int resource_copy(u8 *dst, struct resinfo *res)
{
if (unlikely(!dst || !res)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
if (res->state == RES_UNINITIALIZED) {
pr_warn("%s, %s not initialized\n",
__func__, res->name);
return -EINVAL;
}
return rescpy(dst, res, 0, res->dlen);
}
int resource_copy_by_name(struct panel_info *panel_data, u8 *dst, char *name)
{
struct resinfo *res;
if (unlikely(!panel_data || !dst || !name)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
pr_warn("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
if (res->state == RES_UNINITIALIZED) {
pr_warn("%s, %s not initialized\n",
__func__, res->name);
return -EINVAL;
}
return rescpy(dst, res, 0, res->dlen);
}
int resource_copy_n_clear_by_name(struct panel_info *panel_data, u8 *dst, char *name)
{
struct resinfo *res;
int ret;
if (unlikely(!panel_data || !dst || !name)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
pr_warn("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
if (res->state == RES_UNINITIALIZED) {
pr_warn("%s, %s not initialized\n",
__func__, res->name);
return -EINVAL;
}
ret = rescpy(dst, res, 0, res->dlen);
resource_clear(res);
return ret;
}
int get_resource_size_by_name(struct panel_info *panel_data, char *name)
{
struct resinfo *res;
if (unlikely(!panel_data || !name)) {
pr_warn("%s, invalid parameter\n", __func__);
return -EINVAL;
}
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
pr_warn("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
return get_panel_resource_size(res);
}
#define MAX_READ_BYTES (40)
int panel_rx_nbytes(struct panel_device *panel,
u32 type, u8 *buf, u8 addr, u8 pos, u32 len)
{
int ret, read_len, remained = len, index = 0;
static char gpara[] = {0xB0, 0x00};
if (panel == NULL) {
panel_err("PANEL:ERR:%s:panel is null\n", __func__);
return -EINVAL;
}
if (!IS_CMD_TYPE_RX_PKT(type)) {
pr_err("%s, invalid type %d\n", __func__, type);
return -EINVAL;
}
#ifdef CONFIG_SUPPORT_POC_SPI
if (type == SPI_PKT_TYPE_RD) {
ret = panel_spi_read_data(panel, addr, buf, len);
if (ret < 0)
return ret;
return len;
}
#endif
gpara[1] = pos;
while (remained > 0) {
read_len = remained < MAX_READ_BYTES ? remained : MAX_READ_BYTES;
ret = 0;
if (type == DSI_PKT_TYPE_RD) {
if ((panel->panel_data.ddi_props.gpara &
DDI_SUPPORT_READ_GPARA) == false) {
/*
* S6E3HA9 DDI NOT SUPPORTED GPARA FOR READ
* SO TEMPORARY DISABLE GPRAR FOR READ FUNCTION
*/
char *temp_buf = kmalloc(gpara[1] + read_len, GFP_KERNEL);
if (!temp_buf)
return -EINVAL;
ret = panel_dsi_read_data(panel,
addr, 0, temp_buf, gpara[1] + read_len);
ret -= gpara[1];
memcpy(&buf[index], temp_buf + gpara[1], read_len);
kfree(temp_buf);
} else {
ret = panel_dsi_read_data(panel,
addr, gpara[1], &buf[index], read_len);
}
#ifdef CONFIG_EXYNOS_DECON_LCD_SPI
} else if (type == SPI_PKT_TYPE_RD) {
if (gpara[1] != 0) {
ret = panel_dsi_write_data(panel,
MIPI_DSI_WR_GEN_CMD, gpara, 0, ARRAY_SIZE(gpara), true);
if (ret != ARRAY_SIZE(gpara))
panel_err("%s, failed to set gpara %d (ret %d)\n",
__func__, gpara[1], ret);
}
ret = panel_spi_read_data(panel->spi,
addr, &buf[index], read_len);
#endif
}
if (ret != read_len) {
panel_err("%s, failed to read addr:0x%02X, pos:%d, len:%u ret %d\n",
__func__, addr, pos, len, ret);
return -EINVAL;
}
index += read_len;
gpara[1] += read_len;
remained -= read_len;
}
#ifdef DEBUG_PANEL
panel_dbg("%s, addr:%2Xh, pos:%d, len:%u\n", __func__, addr, pos, len);
print_data(buf, len);
#endif
return len;
}
int panel_tx_nbytes(struct panel_device *panel,
u32 type, u8 *buf, u8 addr, u8 pos, u32 len)
{
int ret;
if (panel == NULL) {
panel_err("PANEL:ERR:%s:panel is null\n", __func__);
return -EINVAL;
}
if (!IS_CMD_TYPE_TX_PKT(type)) {
pr_err("%s, invalid type %d\n", __func__, type);
return -EINVAL;
}
ret = panel_dsi_write_data(panel, MIPI_DSI_WR_GEN_CMD, buf, pos, len, false);
if (ret != len) {
panel_err("%s, failed to write addr:0x%02X, pos:%d, len:%u ret %d\n",
__func__, addr, pos, len, ret);
return -EINVAL;
}
#ifdef DEBUG_PANEL
panel_dbg("%s, addr:%2Xh, pos:%d, len:%u\n", __func__, buf[0], pos, len);
print_data(buf, len);
#endif
return ret;
}
int read_panel_id(struct panel_device *panel, u8 *buf)
{
int len, ret = 0;
if (panel == NULL) {
panel_err("PANEL:ERR:%s:panel is null\n", __func__);
return -EINVAL;
}
if (!IS_PANEL_ACTIVE(panel))
return -ENODEV;
mutex_lock(&panel->op_lock);
panel_set_key(panel, 3, true);
len = panel_rx_nbytes(panel, DSI_PKT_TYPE_RD, buf, PANEL_ID_REG, 0, 3);
if (len != 3) {
pr_err("%s, failed to read id\n", __func__);
ret = -EINVAL;
goto read_err;
}
read_err:
panel_set_key(panel, 3, false);
mutex_unlock(&panel->op_lock);
return ret;
}
static struct rdinfo *find_panel_rdinfo(struct panel_info *panel_data, char *name)
{
int i;
for (i = 0; i < panel_data->nr_rditbl; i++)
if (!strcmp(name, panel_data->rditbl[i].name))
return &panel_data->rditbl[i];
return NULL;
}
int panel_rdinfo_update(struct panel_device *panel, struct rdinfo *rdi)
{
int ret;
if (unlikely(!panel || !rdi)) {
pr_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
kfree(rdi->data);
rdi->data = kcalloc(rdi->len, sizeof(u8), GFP_KERNEL);
#ifdef CONFIG_SUPPORT_DDI_FLASH
if (rdi->type == DSI_PKT_TYPE_RD_POC)
ret = copy_poc_partition(&panel->poc_dev, rdi->data, rdi->addr, rdi->offset, rdi->len);
else
ret = panel_rx_nbytes(panel, rdi->type, rdi->data, rdi->addr, rdi->offset, rdi->len);
#else
ret = panel_rx_nbytes(panel, rdi->type, rdi->data, rdi->addr, rdi->offset, rdi->len);
#endif
if (unlikely(ret != rdi->len)) {
pr_err("%s, read failed\n", __func__);
return -EIO;
}
return 0;
}
int panel_rdinfo_update_by_name(struct panel_device *panel, char *name)
{
int ret;
struct rdinfo *rdi;
struct panel_info *panel_data;
if (unlikely(!panel || !name)) {
pr_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
panel_data = &panel->panel_data;
rdi = find_panel_rdinfo(panel_data, name);
if (unlikely(!rdi)) {
pr_err("%s, read info %s not found\n", __func__, name);
return -ENODEV;
}
ret = panel_rdinfo_update(panel, rdi);
if (ret) {
pr_err("%s, failed to update read info\n", __func__);
return -EINVAL;
}
return 0;
}
void print_panel_resource(struct panel_device *panel)
{
struct panel_info *panel_data;
int i;
if (panel == NULL) {
panel_err("PANEL:ERR:%s:panel is null\n", __func__);
return;
}
panel_data = &panel->panel_data;
if (unlikely(!panel_data)) {
panel_err("PANEL:ERR:%s:panel_data is null\n", __func__);
return;
}
for (i = 0; i < panel_data->nr_restbl; i++) {
panel_info("[panel_resource : %12s %3d bytes] %s\n",
panel_data->restbl[i].name, panel_data->restbl[i].dlen,
(panel_data->restbl[i].state == RES_UNINITIALIZED ?
"UNINITIALIZED" : "INITIALIZED"));
#ifdef DEBUG_PANEL
if (panel_data->restbl[i].state == RES_INITIALIZED)
print_data(panel_data->restbl[i].data,
panel_data->restbl[i].dlen);
#endif
}
}
int panel_resource_update(struct panel_device *panel, struct resinfo *res)
{
int i, ret;
struct rdinfo *rdi;
if (unlikely(!panel || !res)) {
pr_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
for (i = 0; i < res->nr_resui; i++) {
rdi = res->resui[i].rditbl;
if (unlikely(!rdi)) {
panel_warn("%s read info not exist\n", __func__);
return -EINVAL;
}
ret = panel_rdinfo_update(panel, rdi);
if (ret) {
pr_err("%s, failed to update read info\n", __func__);
return -EINVAL;
}
if (!res->data) {
panel_warn("%s resource data not exist\n", __func__);
return -EINVAL;
}
memcpy(res->data + res->resui[i].offset, rdi->data, rdi->len);
res->state = RES_INITIALIZED;
}
#ifdef DEBUG_PANEL
panel_info("[panel_resource : %12s %3d bytes] %s\n",
res->name, res->dlen, (res->state == RES_UNINITIALIZED ?
"UNINITIALIZED" : "INITIALIZED"));
if (res->state == RES_INITIALIZED)
print_data(res->data, res->dlen);
#endif
return 0;
}
int panel_resource_update_by_name(struct panel_device *panel, char *name)
{
int ret;
struct resinfo *res;
struct panel_info *panel_data;
if (unlikely(!panel || !name)) {
pr_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
panel_data = &panel->panel_data;
res = find_panel_resource(panel_data, name);
if (unlikely(!res)) {
pr_warn("%s, %s not found in resource\n",
__func__, name);
return -EINVAL;
}
ret = panel_resource_update(panel, res);
if (unlikely(ret)) {
pr_err("%s, failed to update resource\n", __func__);
return ret;
}
return 0;
}
int panel_dumpinfo_update(struct panel_device *panel, struct dumpinfo *info)
{
int ret;
if (unlikely(!panel || !info || !info->res || !info->callback)) {
pr_err("%s, invalid parameter\n", __func__);
return -EINVAL;
}
ret = panel_resource_update(panel, info->res);
if (unlikely(ret < 0)) {
pr_err("%s, dump:%s failed to update resource\n",
__func__, info->name);
return ret;
}
info->callback(info);
return 0;
}
int check_panel_active(struct panel_device *panel, const char *caller)
{
struct panel_state *state;
int dsi_state;
if (unlikely(!panel)) {
panel_err("PANEL:ERR:%s:panel is null\n", caller);
return 0;
}
state = &panel->state;
if (state->connect_panel == PANEL_DISCONNECT) {
panel_warn("PANEL:WARN:%s:panel no use\n", caller);
return 0;
}
dsi_state = panel_dsi_get_state(panel);
if (dsi_state == DSIM_STATE_OFF ||
dsi_state == DSIM_STATE_DOZE_SUSPEND) {
panel_err("PANEL:WARN:%s:dsim %s\n",
caller, (dsi_state == DSIM_STATE_OFF) ?
"off" : "doze_suspend");
return 0;
}
#if defined(CONFIG_SUPPORT_PANEL_SWAP)
if (ub_con_disconnected(panel)) {
panel_warn("PANEL:WARN:%s:ub disconnected\n", __func__);
return 0;
}
#endif
return 1;
}
|