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
|
/* Source for:
* Cypress TrueTouch(TM) Standard Product touchscreen driver.
* drivers/input/touchscreen/cyttsp_core.c
*
* Copyright (C) 2009-2011 Cypress Semiconductor, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2, and only version 2, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Cypress reserves the right to make changes without further notice
* to the materials described herein. Cypress does not assume any
* liability arising out of the application described herein.
*
* Contact Cypress Semiconductor at www.cypress.com
*
*/
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/input.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/byteorder/generic.h>
#include <linux/bitops.h>
#include <linux/earlysuspend.h>
#include <linux/cyttsp.h>
#include <linux/ctype.h>
#include <linux/regulator/consumer.h>
#include "cyttsp_core.h"
#define DBG(x)
#define DBG2(x)
#define DBG3(x)
/* rely on kernel input.h to define Multi-Touch capability */
#ifndef ABS_MT_TRACKING_ID
/* define only if not defined already by system; */
/* value based on linux kernel 2.6.30.10 */
#define ABS_MT_TRACKING_ID (ABS_MT_BLOB_ID + 1)
#endif /* ABS_MT_TRACKING_ID */
#define TOUCHSCREEN_TIMEOUT (msecs_to_jiffies(28))
/* Bootloader File 0 offset */
#define CY_BL_FILE0 0x00
/* Bootloader command directive */
#define CY_BL_CMD 0xFF
/* Bootloader Enter Loader mode */
#define CY_BL_ENTER 0x38
/* Bootloader Write a Block */
#define CY_BL_WRITE_BLK 0x39
/* Bootloader Terminate Loader mode */
#define CY_BL_TERMINATE 0x3B
/* Bootloader Exit and Verify Checksum command */
#define CY_BL_EXIT 0xA5
/* Bootloader default keys */
#define CY_BL_KEY0 0
#define CY_BL_KEY1 1
#define CY_BL_KEY2 2
#define CY_BL_KEY3 3
#define CY_BL_KEY4 4
#define CY_BL_KEY5 5
#define CY_BL_KEY6 6
#define CY_BL_KEY7 7
#define CY_DIFF(m, n) ((m) != (n))
#define GET_NUM_TOUCHES(x) ((x) & 0x0F)
#define GET_TOUCH1_ID(x) (((x) & 0xF0) >> 4)
#define GET_TOUCH2_ID(x) ((x) & 0x0F)
#define GET_TOUCH3_ID(x) (((x) & 0xF0) >> 4)
#define GET_TOUCH4_ID(x) ((x) & 0x0F)
#define IS_LARGE_AREA(x) (((x) & 0x10) >> 4)
#define IS_BAD_PKT(x) ((x) & 0x20)
#define FLIP_DATA_FLAG 0x01
#define REVERSE_X_FLAG 0x02
#define REVERSE_Y_FLAG 0x04
#define FLIP_DATA(flags) ((flags) & FLIP_DATA_FLAG)
#define REVERSE_X(flags) ((flags) & REVERSE_X_FLAG)
#define REVERSE_Y(flags) ((flags) & REVERSE_Y_FLAG)
#define FLIP_XY(x, y) {typeof(x) tmp; tmp = (x); (x) = (y); (y) = tmp; }
#define INVERT_X(x, xmax) ((xmax) - (x))
#define INVERT_Y(y, ymax) ((ymax) - (y))
#define SET_HSTMODE(reg, mode) ((reg) & (mode))
#define GET_HSTMODE(reg) ((reg & 0x70) >> 4)
#define GET_BOOTLOADERMODE(reg) ((reg & 0x10) >> 4)
/* Watchdog timeout to check if device is reset and no interrupts running */
#define CY_WDG_TIMEOUT msecs_to_jiffies(3000)
#define CY_MODE_ERROR(ps, hst_mode, tt_mode) \
((ps == CY_ACTIVE_STATE && GET_HSTMODE(hst_mode) != CY_OPERATE_MODE) ||\
GET_BOOTLOADERMODE(tt_mode))
/* maximum number of concurrent ST track IDs */
#define CY_NUM_ST_TCH_ID 2
/* maximum number of concurrent MT track IDs */
#define CY_NUM_MT_TCH_ID 4
/* maximum number of track IDs */
#define CY_NUM_TRK_ID 16
/*
* maximum number of concurrent touches
* (only CY_NUM_MT_TCH_ID have coord data)
*/
#define CY_MAX_TCH 10
/*
* maximum number of touch reports with
* current touches=0 before performing Driver reset
*/
#define CY_MAX_NTCH 10
#define CY_NTCH 0 /* lift off */
#define CY_TCH 1 /* touch down */
#define CY_ST_FNGR1_IDX 0
#define CY_ST_FNGR2_IDX 1
#define CY_MT_TCH1_IDX 0
#define CY_MT_TCH2_IDX 1
#define CY_MT_TCH3_IDX 2
#define CY_MT_TCH4_IDX 3
#define CY_XPOS 0
#define CY_YPOS 1
#define CY_IGNR_TCH (-1)
#define CY_SMALL_TOOL_WIDTH 10
#define CY_LARGE_TOOL_WIDTH 255
#define CY_REG_BASE 0x00
#define CY_REG_GEST_SET 0x1E
#define CY_REG_SCN_TYP 0x1C
#define CY_REG_ACT_INTRVL 0x1D
#define CY_REG_TCH_TMOUT (CY_REG_ACT_INTRVL+1)
#define CY_REG_LP_INTRVL (CY_REG_TCH_TMOUT+1)
#define CY_SOFT_RESET (1 << 0)
#define CY_DEEP_SLEEP (1 << 1)
#define CY_LOW_POWER (1 << 2)
#define CY_MAXZ 255
#define CY_OK 0
#define CY_INIT 1
#define CY_DELAY_DFLT 20 /* ms */
#define CY_DELAY_MAX (500/CY_DELAY_DFLT) /* half second */
#define CY_DELAY_SYSINFO 20 /* ms */
#define CY_DELAY_BL 300
#define CY_DELAY_DNLOAD 100 /* ms */
#define CY_HNDSHK_BIT 0x80
/* device mode bits */
#define CY_OPERATE_MODE 0x00
#define CY_SYSINFO_MODE 0x10
/* power mode select bits */
#define CY_SOFT_RESET_MODE 0x01 /* return to Bootloader mode */
#define CY_DEEP_SLEEP_MODE 0x02
#define CY_LOW_POWER_MODE 0x04
#define CY_NUM_KEY 8
/* TrueTouch Standard Product Gen3 (Txx3xx) interface definition */
struct cyttsp_xydata {
u8 hst_mode;
u8 tt_mode;
u8 tt_stat;
u16 x1 __attribute__ ((packed));
u16 y1 __attribute__ ((packed));
u8 z1;
u8 touch12_id;
u16 x2 __attribute__ ((packed));
u16 y2 __attribute__ ((packed));
u8 z2;
u8 gest_cnt;
u8 gest_id;
u16 x3 __attribute__ ((packed));
u16 y3 __attribute__ ((packed));
u8 z3;
u8 touch34_id;
u16 x4 __attribute__ ((packed));
u16 y4 __attribute__ ((packed));
u8 z4;
u8 tt_undef[3];
u8 gest_set;
u8 tt_reserved;
};
struct cyttsp_xydata_gen2 {
u8 hst_mode;
u8 tt_mode;
u8 tt_stat;
u16 x1 __attribute__ ((packed));
u16 y1 __attribute__ ((packed));
u8 z1;
u8 evnt_idx;
u16 x2 __attribute__ ((packed));
u16 y2 __attribute__ ((packed));
u8 tt_undef1;
u8 gest_cnt;
u8 gest_id;
u8 tt_undef[14];
u8 gest_set;
u8 tt_reserved;
};
/* TrueTouch Standard Product Gen2 (Txx2xx) interface definition */
enum cyttsp_gen2_std {
CY_GEN2_NOTOUCH = 0x03, /* Both touches removed */
CY_GEN2_GHOST = 0x02, /* ghost */
CY_GEN2_2TOUCH = 0x03, /* 2 touch; no ghost */
CY_GEN2_1TOUCH = 0x01, /* 1 touch only */
CY_GEN2_TOUCH2 = 0x01, /* 1st touch removed; 2nd touch remains */
};
/* TTSP System Information interface definition */
struct cyttsp_sysinfo_data {
u8 hst_mode;
u8 mfg_stat;
u8 mfg_cmd;
u8 cid[3];
u8 tt_undef1;
u8 uid[8];
u8 bl_verh;
u8 bl_verl;
u8 tts_verh;
u8 tts_verl;
u8 app_idh;
u8 app_idl;
u8 app_verh;
u8 app_verl;
u8 tt_undef[5];
u8 scn_typ; /* Gen3 only: scan type [0:Mutual, 1:Self] */
u8 act_intrvl;
u8 tch_tmout;
u8 lp_intrvl;
};
/* TTSP Bootloader Register Map interface definition */
#define CY_BL_CHKSUM_OK 0x01
struct cyttsp_bootloader_data {
u8 bl_file;
u8 bl_status;
u8 bl_error;
u8 blver_hi;
u8 blver_lo;
u8 bld_blver_hi;
u8 bld_blver_lo;
u8 ttspver_hi;
u8 ttspver_lo;
u8 appid_hi;
u8 appid_lo;
u8 appver_hi;
u8 appver_lo;
u8 cid_0;
u8 cid_1;
u8 cid_2;
};
#define cyttsp_wake_data cyttsp_xydata
struct cyttsp {
struct device *pdev;
int irq;
struct input_dev *input;
struct work_struct work;
struct timer_list timer;
struct mutex mutex;
struct early_suspend early_suspend;
char phys[32];
struct cyttsp_platform_data *platform_data;
struct cyttsp_bootloader_data bl_data;
struct cyttsp_sysinfo_data sysinfo_data;
u8 num_prv_st_tch;
u16 act_trk[CY_NUM_TRK_ID];
u16 prv_mt_tch[CY_NUM_MT_TCH_ID];
u16 prv_st_tch[CY_NUM_ST_TCH_ID];
u16 prv_mt_pos[CY_NUM_TRK_ID][2];
struct cyttsp_bus_ops *bus_ops;
struct regulator *regulator;
unsigned fw_loader_mode:1;
unsigned suspended:1;
struct timer_list to_timer;
bool to_timeout;
struct completion int_running;
bool bl_ready;
u8 reg_id;
u8 ntch_count;
};
struct cyttsp_track_data {
u8 prv_tch;
u8 cur_tch;
u16 tmp_trk[CY_NUM_MT_TCH_ID];
u16 snd_trk[CY_NUM_MT_TCH_ID];
u16 cur_trk[CY_NUM_TRK_ID];
u16 cur_st_tch[CY_NUM_ST_TCH_ID];
u16 cur_mt_tch[CY_NUM_MT_TCH_ID];
/* if NOT CY_USE_TRACKING_ID then only */
/* uses CY_NUM_MT_TCH_ID positions */
u16 cur_mt_pos[CY_NUM_TRK_ID][2];
/* if NOT CY_USE_TRACKING_ID then only */
/* uses CY_NUM_MT_TCH_ID positions */
u8 cur_mt_z[CY_NUM_TRK_ID];
u8 tool_width;
u16 st_x1;
u16 st_y1;
u8 st_z1;
u16 st_x2;
u16 st_y2;
u8 st_z2;
};
static const u8 bl_cmd[] = {
CY_BL_FILE0, CY_BL_CMD, CY_BL_EXIT,
CY_BL_KEY0, CY_BL_KEY1, CY_BL_KEY2,
CY_BL_KEY3, CY_BL_KEY4, CY_BL_KEY5,
CY_BL_KEY6, CY_BL_KEY7
};
#define LOCK(m) do { \
DBG(printk(KERN_INFO "%s: lock\n", __func__);) \
mutex_lock(&(m)); \
} while (0);
#define UNLOCK(m) do { \
DBG(printk(KERN_INFO "%s: unlock\n", __func__);) \
mutex_unlock(&(m)); \
} while (0);
DBG(
static void print_data_block(const char *func, u8 command,
u8 length, void *data)
{
char buf[1024];
unsigned buf_len = sizeof(buf);
char *p = buf;
int i;
int l;
l = snprintf(p, buf_len, "cmd 0x%x: ", command);
buf_len -= l;
p += l;
for (i = 0; i < length && buf_len; i++, p += l, buf_len -= l)
l = snprintf(p, buf_len, "%02x ", *((char *)data + i));
printk(KERN_DEBUG "%s: %s\n", func, buf);
})
static int cyttsp_soft_reset(struct cyttsp *ts);
static int cyttsp_set_operational_mode(struct cyttsp *ts);
static int cyttsp_exit_bl_mode(struct cyttsp *ts);
static int cyttsp_power_on(struct cyttsp *ts);
static void cyttsp_init_tch(struct cyttsp *ts)
{
/* init the touch structures */
ts->num_prv_st_tch = CY_NTCH;
memset(ts->act_trk, CY_NTCH, sizeof(ts->act_trk));
memset(ts->prv_mt_pos, CY_NTCH, sizeof(ts->prv_mt_pos));
memset(ts->prv_mt_tch, CY_IGNR_TCH, sizeof(ts->prv_mt_tch));
memset(ts->prv_st_tch, CY_IGNR_TCH, sizeof(ts->prv_st_tch));
ts->ntch_count = 0;
}
static u8 ttsp_convert_gen2(u8 cur_tch, struct cyttsp_xydata *pxy_data)
{
struct cyttsp_xydata_gen2 *pxy_data_gen2;
pxy_data_gen2 = (struct cyttsp_xydata_gen2 *)(pxy_data);
if (pxy_data_gen2->evnt_idx == CY_GEN2_NOTOUCH) {
cur_tch = 0;
} else if (cur_tch == CY_GEN2_GHOST) {
cur_tch = 0;
} else if (cur_tch == CY_GEN2_2TOUCH) {
/* stuff artificial track ID1 and ID2 */
pxy_data->touch12_id = 0x12;
pxy_data->z1 = CY_MAXZ;
pxy_data->z2 = CY_MAXZ;
cur_tch--; /* 2 touches */
} else if (cur_tch == CY_GEN2_1TOUCH) {
/* stuff artificial track ID1 and ID2 */
pxy_data->touch12_id = 0x12;
pxy_data->z1 = CY_MAXZ;
pxy_data->z2 = CY_NTCH;
if (pxy_data_gen2->evnt_idx == CY_GEN2_TOUCH2) {
/* push touch 2 data into touch1
* (first finger up; second finger down) */
/* stuff artificial track ID1 for touch2 info */
pxy_data->touch12_id = 0x20;
/* stuff touch 1 with touch 2 coordinate data */
pxy_data->x1 = pxy_data->x2;
pxy_data->y1 = pxy_data->y2;
}
} else {
cur_tch = 0;
}
return cur_tch;
}
static int ttsp_read_block_data(struct cyttsp *ts, u8 command,
u8 length, void *buf)
{
int rc;
int tries;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
if (!buf || !length) {
printk(KERN_ERR "%s: Error, buf:%s len:%u\n",
__func__, !buf ? "NULL" : "OK", length);
return -EIO;
}
for (tries = 0, rc = -1; tries < CY_NUM_RETRY && (rc < 0); tries++) {
rc = ts->bus_ops->read(ts->bus_ops, command, length, buf);
if (rc)
msleep(CY_DELAY_DFLT);
}
if (rc < 0)
printk(KERN_ERR "%s: error %d\n", __func__, rc);
DBG(print_data_block(__func__, command, length, buf);)
return rc;
}
static int ttsp_write_block_data(struct cyttsp *ts, u8 command,
u8 length, void *buf)
{
int rc;
int tries;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
if (!buf || !length) {
printk(KERN_ERR "%s: Error, buf:%s len:%u\n",
__func__, !buf ? "NULL" : "OK", length);
return -EIO;
}
for (tries = 0, rc = -1; tries < CY_NUM_RETRY && (rc < 0); tries++) {
rc = ts->bus_ops->write(ts->bus_ops, command, length, buf);
if (rc)
msleep(CY_DELAY_DFLT);
}
if (rc < 0)
printk(KERN_ERR "%s: error %d\n", __func__, rc);
DBG(print_data_block(__func__, command, length, buf);)
return rc;
}
static int ttsp_tch_ext(struct cyttsp *ts, void *buf)
{
int rc;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
if (!buf) {
printk(KERN_ERR "%s: Error, buf:%s\n",
__func__, !buf ? "NULL" : "OK");
return -EIO;
}
rc = ts->bus_ops->ext(ts->bus_ops, buf);
if (rc < 0)
printk(KERN_ERR "%s: error %d\n", __func__, rc);
return rc;
}
/* ************************************************************************
* The cyttsp_xy_worker function reads the XY coordinates and sends them to
* the input layer. It is called from the Touch Interrupt.
* *************************************************************************/
static int cyttsp_inlist(u16 prev_track[], u8 cur_trk_id, u8 *prev_loc,
u8 num_touches)
{
u8 id = 0;
DBG(printk(KERN_INFO"%s: IN p[%d]=%d c=%d n=%d loc=%d\n",
__func__, id, prev_track[id], cur_trk_id,
num_touches, *prev_loc);)
for (*prev_loc = CY_IGNR_TCH; id < num_touches; id++) {
DBG(printk(KERN_INFO"%s: p[%d]=%d c=%d n=%d loc=%d\n",
__func__, id, prev_track[id], cur_trk_id,
num_touches, *prev_loc);)
if (prev_track[id] == cur_trk_id) {
*prev_loc = id;
break;
}
}
DBG(printk(KERN_INFO"%s: OUT p[%d]=%d c=%d n=%d loc=%d\n", __func__,
id, prev_track[id], cur_trk_id, num_touches, *prev_loc);)
return *prev_loc < CY_NUM_TRK_ID;
}
static int cyttsp_next_avail_inlist(u16 cur_trk[], u8 *new_loc,
u8 num_touches)
{
u8 id = 0;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
for (*new_loc = CY_IGNR_TCH; id < num_touches; id++) {
if (cur_trk[id] > CY_NUM_TRK_ID) {
*new_loc = id;
break;
}
}
return *new_loc < CY_NUM_TRK_ID;
}
static void handle_single_touch(struct cyttsp_xydata *xy,
struct cyttsp_track_data *t, struct cyttsp *ts)
{
u8 id;
u8 use_trk_id = ts->platform_data->use_trk_id;
DBG(printk(KERN_INFO"%s: ST STEP 0 - ST1 ID=%d ST2 ID=%d\n",
__func__, t->cur_st_tch[CY_ST_FNGR1_IDX],
t->cur_st_tch[CY_ST_FNGR2_IDX]);)
if (t->cur_st_tch[CY_ST_FNGR1_IDX] > CY_NUM_TRK_ID) {
/* reassign finger 1 and 2 positions to new tracks */
if (t->cur_tch > 0) {
/* reassign st finger1 */
if (use_trk_id) {
id = CY_MT_TCH1_IDX;
t->cur_st_tch[CY_ST_FNGR1_IDX] =
t->cur_mt_tch[id];
} else {
id = GET_TOUCH1_ID(xy->touch12_id);
t->cur_st_tch[CY_ST_FNGR1_IDX] = id;
}
t->st_x1 = t->cur_mt_pos[id][CY_XPOS];
t->st_y1 = t->cur_mt_pos[id][CY_YPOS];
t->st_z1 = t->cur_mt_z[id];
DBG(printk(KERN_INFO"%s: ST STEP 1 - ST1 ID=%3d\n",
__func__, t->cur_st_tch[CY_ST_FNGR1_IDX]);)
if ((t->cur_tch > 1) &&
(t->cur_st_tch[CY_ST_FNGR2_IDX] >
CY_NUM_TRK_ID)) {
/* reassign st finger2 */
if (use_trk_id) {
id = CY_MT_TCH2_IDX;
t->cur_st_tch[CY_ST_FNGR2_IDX] =
t->cur_mt_tch[id];
} else {
id = GET_TOUCH2_ID(xy->touch12_id);
t->cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
t->st_x2 = t->cur_mt_pos[id][CY_XPOS];
t->st_y2 = t->cur_mt_pos[id][CY_YPOS];
t->st_z2 = t->cur_mt_z[id];
DBG(
printk(KERN_INFO"%s: ST STEP 2 - ST2 ID=%3d\n",
__func__, t->cur_st_tch[CY_ST_FNGR2_IDX]);)
}
}
} else if (t->cur_st_tch[CY_ST_FNGR2_IDX] > CY_NUM_TRK_ID) {
if (t->cur_tch > 1) {
/* reassign st finger2 */
if (use_trk_id) {
/* reassign st finger2 */
id = CY_MT_TCH2_IDX;
t->cur_st_tch[CY_ST_FNGR2_IDX] =
t->cur_mt_tch[id];
} else {
/* reassign st finger2 */
id = GET_TOUCH2_ID(xy->touch12_id);
t->cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
t->st_x2 = t->cur_mt_pos[id][CY_XPOS];
t->st_y2 = t->cur_mt_pos[id][CY_YPOS];
t->st_z2 = t->cur_mt_z[id];
DBG(printk(KERN_INFO"%s: ST STEP 3 - ST2 ID=%3d\n",
__func__, t->cur_st_tch[CY_ST_FNGR2_IDX]);)
}
}
/* if the 1st touch is missing and there is a 2nd touch,
* then set the 1st touch to 2nd touch and terminate 2nd touch
*/
if ((t->cur_st_tch[CY_ST_FNGR1_IDX] > CY_NUM_TRK_ID) &&
(t->cur_st_tch[CY_ST_FNGR2_IDX] < CY_NUM_TRK_ID)) {
t->st_x1 = t->st_x2;
t->st_y1 = t->st_y2;
t->st_z1 = t->st_z2;
t->cur_st_tch[CY_ST_FNGR1_IDX] = t->cur_st_tch[CY_ST_FNGR2_IDX];
t->cur_st_tch[CY_ST_FNGR2_IDX] = CY_IGNR_TCH;
}
/* if the 2nd touch ends up equal to the 1st touch,
* then just report a single touch */
if (t->cur_st_tch[CY_ST_FNGR1_IDX] == t->cur_st_tch[CY_ST_FNGR2_IDX])
t->cur_st_tch[CY_ST_FNGR2_IDX] = CY_IGNR_TCH;
/* set Single Touch current event signals */
if (t->cur_st_tch[CY_ST_FNGR1_IDX] < CY_NUM_TRK_ID) {
input_report_abs(ts->input, ABS_X, t->st_x1);
input_report_abs(ts->input, ABS_Y, t->st_y1);
input_report_abs(ts->input, ABS_PRESSURE, t->st_z1);
input_report_key(ts->input, BTN_TOUCH, CY_TCH);
input_report_abs(ts->input, ABS_TOOL_WIDTH, t->tool_width);
DBG2(printk(KERN_INFO"%s:ST->F1:%3d X:%3d Y:%3d Z:%3d\n",
__func__, t->cur_st_tch[CY_ST_FNGR1_IDX],
t->st_x1, t->st_y1, t->st_z1);)
if (t->cur_st_tch[CY_ST_FNGR2_IDX] < CY_NUM_TRK_ID) {
input_report_key(ts->input, BTN_2, CY_TCH);
input_report_abs(ts->input, ABS_HAT0X, t->st_x2);
input_report_abs(ts->input, ABS_HAT0Y, t->st_y2);
DBG2(printk(KERN_INFO
"%s:ST->F2:%3d X:%3d Y:%3d Z:%3d\n",
__func__, t->cur_st_tch[CY_ST_FNGR2_IDX],
t->st_x2, t->st_y2, t->st_z2);)
} else {
input_report_key(ts->input, BTN_2, CY_NTCH);
}
} else {
input_report_abs(ts->input, ABS_PRESSURE, CY_NTCH);
input_report_key(ts->input, BTN_TOUCH, CY_NTCH);
input_report_key(ts->input, BTN_2, CY_NTCH);
}
/* update platform data for the current single touch info */
ts->prv_st_tch[CY_ST_FNGR1_IDX] = t->cur_st_tch[CY_ST_FNGR1_IDX];
ts->prv_st_tch[CY_ST_FNGR2_IDX] = t->cur_st_tch[CY_ST_FNGR2_IDX];
}
static void handle_multi_touch(struct cyttsp_track_data *t, struct cyttsp *ts)
{
u8 id;
u8 i, loc;
void (*mt_sync_func)(struct input_dev *) = ts->platform_data->mt_sync;
if (!ts->platform_data->use_trk_id)
goto no_track_id;
/* terminate any previous touch where the track
* is missing from the current event */
for (id = 0; id < CY_NUM_TRK_ID; id++) {
if ((ts->act_trk[id] == CY_NTCH) || (t->cur_trk[id] != CY_NTCH))
continue;
input_report_abs(ts->input, ABS_MT_TRACKING_ID, id);
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, CY_NTCH);
input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, t->tool_width);
input_report_abs(ts->input, ABS_MT_POSITION_X,
ts->prv_mt_pos[id][CY_XPOS]);
input_report_abs(ts->input, ABS_MT_POSITION_Y,
ts->prv_mt_pos[id][CY_YPOS]);
if (mt_sync_func)
mt_sync_func(ts->input);
ts->act_trk[id] = CY_NTCH;
ts->prv_mt_pos[id][CY_XPOS] = 0;
ts->prv_mt_pos[id][CY_YPOS] = 0;
}
/* set Multi-Touch current event signals */
for (id = 0; id < CY_NUM_MT_TCH_ID; id++) {
if (t->cur_mt_tch[id] >= CY_NUM_TRK_ID)
continue;
input_report_abs(ts->input, ABS_MT_TRACKING_ID,
t->cur_mt_tch[id]);
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
t->cur_mt_z[id]);
input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR,
t->tool_width);
input_report_abs(ts->input, ABS_MT_POSITION_X,
t->cur_mt_pos[id][CY_XPOS]);
input_report_abs(ts->input, ABS_MT_POSITION_Y,
t->cur_mt_pos[id][CY_YPOS]);
if (mt_sync_func)
mt_sync_func(ts->input);
ts->act_trk[id] = CY_TCH;
ts->prv_mt_pos[id][CY_XPOS] = t->cur_mt_pos[id][CY_XPOS];
ts->prv_mt_pos[id][CY_YPOS] = t->cur_mt_pos[id][CY_YPOS];
}
return;
no_track_id:
/* set temporary track array elements to voids */
memset(t->tmp_trk, CY_IGNR_TCH, sizeof(t->tmp_trk));
memset(t->snd_trk, CY_IGNR_TCH, sizeof(t->snd_trk));
/* get what is currently active */
for (i = id = 0; id < CY_NUM_TRK_ID && i < CY_NUM_MT_TCH_ID; id++) {
if (t->cur_trk[id] == CY_TCH) {
/* only incr counter if track found */
t->tmp_trk[i] = id;
i++;
}
}
DBG(printk(KERN_INFO"%s: T1: t0=%d, t1=%d, t2=%d, t3=%d\n", __func__,
t->tmp_trk[0], t->tmp_trk[1],
t->tmp_trk[2], t->tmp_trk[3]);)
DBG(printk(KERN_INFO"%s: T1: p0=%d, p1=%d, p2=%d, p3=%d\n", __func__,
ts->prv_mt_tch[0], ts->prv_mt_tch[1],
ts->prv_mt_tch[2], ts->prv_mt_tch[3]);)
/* pack in still active previous touches */
for (id = t->prv_tch = 0; id < CY_NUM_MT_TCH_ID; id++) {
if (t->tmp_trk[id] >= CY_NUM_TRK_ID)
continue;
if (cyttsp_inlist(ts->prv_mt_tch, t->tmp_trk[id], &loc,
CY_NUM_MT_TCH_ID)) {
loc &= CY_NUM_MT_TCH_ID - 1;
t->snd_trk[loc] = t->tmp_trk[id];
t->prv_tch++;
DBG(printk(KERN_INFO"%s: in list s[%d]=%d "
"t[%d]=%d, loc=%d p=%d\n", __func__,
loc, t->snd_trk[loc],
id, t->tmp_trk[id],
loc, t->prv_tch);)
} else {
DBG(printk(KERN_INFO"%s: is not in list s[%d]=%d"
" t[%d]=%d loc=%d\n", __func__,
id, t->snd_trk[id],
id, t->tmp_trk[id],
loc);)
}
}
DBG(printk(KERN_INFO"%s: S1: s0=%d, s1=%d, s2=%d, s3=%d p=%d\n",
__func__,
t->snd_trk[0], t->snd_trk[1], t->snd_trk[2],
t->snd_trk[3], t->prv_tch);)
/* pack in new touches */
for (id = 0; id < CY_NUM_MT_TCH_ID; id++) {
if (t->tmp_trk[id] >= CY_NUM_TRK_ID)
continue;
if (!cyttsp_inlist(t->snd_trk, t->tmp_trk[id], &loc,
CY_NUM_MT_TCH_ID)) {
DBG(
printk(KERN_INFO"%s: not in list t[%d]=%d, loc=%d\n",
__func__,
id, t->tmp_trk[id], loc);)
if (cyttsp_next_avail_inlist(t->snd_trk, &loc,
CY_NUM_MT_TCH_ID)) {
loc &= CY_NUM_MT_TCH_ID - 1;
t->snd_trk[loc] = t->tmp_trk[id];
DBG(printk(KERN_INFO "%s: put in list s[%d]=%d"
" t[%d]=%d\n", __func__,
loc,
t->snd_trk[loc], id, t->tmp_trk[id]);
)
}
} else {
DBG(printk(KERN_INFO"%s: is in list s[%d]=%d "
"t[%d]=%d loc=%d\n", __func__,
id, t->snd_trk[id], id, t->tmp_trk[id], loc);)
}
}
DBG(printk(KERN_INFO"%s: S2: s0=%d, s1=%d, s2=%d, s3=%d\n", __func__,
t->snd_trk[0], t->snd_trk[1],
t->snd_trk[2], t->snd_trk[3]);)
/* sync motion event signals for each current touch */
for (id = 0; id < CY_NUM_MT_TCH_ID; id++) {
/* z will either be 0 (NOTOUCH) or
* some pressure (TOUCH)
*/
DBG(printk(KERN_INFO "%s: MT0 prev[%d]=%d "
"temp[%d]=%d send[%d]=%d\n",
__func__, id, ts->prv_mt_tch[id],
id, t->tmp_trk[id], id, t->snd_trk[id]);)
if (ts->platform_data->invert) {
t->cur_mt_pos[t->snd_trk[id]][CY_XPOS] =
INVERT_X(t->cur_mt_pos[t->snd_trk[id]]
[CY_XPOS], ts->platform_data->maxx);
t->cur_mt_pos[t->snd_trk[id]][CY_YPOS] =
INVERT_X(t->cur_mt_pos[t->snd_trk[id]]
[CY_YPOS], ts->platform_data->maxy);
}
if (t->snd_trk[id] < CY_NUM_TRK_ID) {
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
t->cur_mt_z[t->snd_trk[id]]);
input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR,
t->tool_width);
input_report_abs(ts->input, ABS_MT_POSITION_X,
t->cur_mt_pos[t->snd_trk[id]][CY_XPOS]);
input_report_abs(ts->input, ABS_MT_POSITION_Y,
t->cur_mt_pos[t->snd_trk[id]][CY_YPOS]);
if (mt_sync_func)
mt_sync_func(ts->input);
DBG2(printk(KERN_INFO"%s: MT1 -> TID:"
"%3d X:%3d Y:%3d Z:%3d\n", __func__,
t->snd_trk[id],
t->cur_mt_pos[t->snd_trk[id]][CY_XPOS],
t->cur_mt_pos[t->snd_trk[id]][CY_YPOS],
t->cur_mt_z[t->snd_trk[id]]);)
} else if (ts->prv_mt_tch[id] < CY_NUM_TRK_ID) {
/* void out this touch */
input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR,
CY_NTCH);
input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR,
t->tool_width);
input_report_abs(ts->input, ABS_MT_POSITION_X,
ts->prv_mt_pos[ts->prv_mt_tch[id]][CY_XPOS]);
input_report_abs(ts->input, ABS_MT_POSITION_Y,
ts->prv_mt_pos[ts->prv_mt_tch[id]][CY_YPOS]);
if (mt_sync_func)
mt_sync_func(ts->input);
DBG2(printk(KERN_INFO"%s: "
"MT2->TID:%2d X:%3d Y:%3d Z:%3d liftoff-sent\n",
__func__, ts->prv_mt_tch[id],
ts->prv_mt_pos[ts->prv_mt_tch[id]][CY_XPOS],
ts->prv_mt_pos[ts->prv_mt_tch[id]][CY_YPOS],
CY_NTCH);)
} else {
/* do not stuff any signals for this
* previously and currently void touches
*/
DBG(printk(KERN_INFO"%s: "
"MT3->send[%d]=%d - No touch - NOT sent\n",
__func__, id, t->snd_trk[id]);)
}
}
/* save current posted tracks to
* previous track memory */
for (id = 0; id < CY_NUM_MT_TCH_ID; id++) {
ts->prv_mt_tch[id] = t->snd_trk[id];
if (t->snd_trk[id] < CY_NUM_TRK_ID) {
ts->prv_mt_pos[t->snd_trk[id]][CY_XPOS] =
t->cur_mt_pos[t->snd_trk[id]][CY_XPOS];
ts->prv_mt_pos[t->snd_trk[id]][CY_YPOS] =
t->cur_mt_pos[t->snd_trk[id]][CY_YPOS];
DBG(printk(KERN_INFO"%s: "
"MT4->TID:%2d X:%3d Y:%3d Z:%3d save for prv\n",
__func__, t->snd_trk[id],
ts->prv_mt_pos[t->snd_trk[id]][CY_XPOS],
ts->prv_mt_pos[t->snd_trk[id]][CY_YPOS],
CY_NTCH);)
}
}
memset(ts->act_trk, CY_NTCH, sizeof(ts->act_trk));
for (id = 0; id < CY_NUM_MT_TCH_ID; id++) {
if (t->snd_trk[id] < CY_NUM_TRK_ID)
ts->act_trk[t->snd_trk[id]] = CY_TCH;
}
}
static void cyttsp_xy_worker(struct cyttsp *ts)
{
struct cyttsp_xydata xy_data;
u8 id, tilt, rev_x, rev_y;
struct cyttsp_track_data trc;
s32 retval;
DBG(printk(KERN_INFO "%s: Enter\n", __func__);)
/* get event data from CYTTSP device */
retval = ttsp_read_block_data(ts, CY_REG_BASE,
sizeof(xy_data), &xy_data);
if (retval < 0) {
printk(KERN_ERR "%s: Error, fail to read device on host interface bus\n",
__func__);
goto exit_xy_worker;
}
if (CY_MODE_ERROR(ts->platform_data->power_state,
xy_data.hst_mode, xy_data.tt_mode)) {
/* TTSP device has switched to non-operational mode */
printk(KERN_ERR "%s: Error, bad mode ps=%d hm=%02X tm=%02X\n",
__func__, ts->platform_data->power_state,
xy_data.hst_mode, xy_data.tt_mode);
retval = cyttsp_power_on(ts);
if (retval < 0)
printk(KERN_ERR "%s: Error, power on fail\n", __func__);
goto exit_xy_worker;
}
/* touch extension handling */
retval = ttsp_tch_ext(ts, &xy_data);
if (retval < 0) {
printk(KERN_ERR "%s: Error, touch extension handling\n",
__func__);
goto exit_xy_worker;
} else if (retval > 0) {
DBG(printk(KERN_INFO "%s: Touch extension handled\n",
__func__);)
goto exit_xy_worker;
}
/* provide flow control handshake */
if (ts->irq) {
if (ts->platform_data->use_hndshk) {
u8 cmd;
cmd = xy_data.hst_mode & CY_HNDSHK_BIT ?
xy_data.hst_mode & ~CY_HNDSHK_BIT :
xy_data.hst_mode | CY_HNDSHK_BIT;
retval = ttsp_write_block_data(ts, CY_REG_BASE,
sizeof(cmd), (u8 *)&cmd);
}
}
trc.cur_tch = GET_NUM_TOUCHES(xy_data.tt_stat);
if (IS_LARGE_AREA(xy_data.tt_stat) == 1) {
/* terminate all active tracks */
trc.cur_tch = CY_NTCH;
DBG(printk(KERN_INFO "%s: Large area detected\n",
__func__);)
} else if (trc.cur_tch > CY_MAX_TCH) {
/* terminate all active tracks */
trc.cur_tch = CY_NTCH;
DBG(printk(KERN_INFO "%s: Num touch error detected\n",
__func__);)
} else if (IS_BAD_PKT(xy_data.tt_mode)) {
/* terminate all active tracks */
trc.cur_tch = CY_NTCH;
DBG(printk(KERN_INFO "%s: Invalid buffer detected\n",
__func__);)
}
/* set tool size */
trc.tool_width = CY_SMALL_TOOL_WIDTH;
if (ts->platform_data->gen == CY_GEN2) {
/* translate Gen2 interface data into comparable Gen3 data */
trc.cur_tch = ttsp_convert_gen2(trc.cur_tch, &xy_data);
}
/* clear current active track ID array and count previous touches */
for (id = 0, trc.prv_tch = CY_NTCH; id < CY_NUM_TRK_ID; id++) {
trc.cur_trk[id] = CY_NTCH;
trc.prv_tch += ts->act_trk[id];
}
/*
* send no events if there were no
* previous touches and no new touches
*/
if ((trc.prv_tch == CY_NTCH) && ((trc.cur_tch == CY_NTCH) ||
(trc.cur_tch > CY_MAX_TCH))) {
if (++ts->ntch_count > CY_MAX_NTCH) {
/* TTSP device has a stuck operational mode */
printk(KERN_ERR "%s: Error, stuck no-touch ct=%d\n",
__func__, trc.cur_tch);
retval = cyttsp_power_on(ts);
if (retval < 0)
printk(KERN_ERR "%s: Error, power on fail\n",
__func__);
goto exit_xy_worker;
}
} else
ts->ntch_count = 0;
DBG(printk(KERN_INFO "%s: prev=%d curr=%d\n", __func__,
trc.prv_tch, trc.cur_tch);)
/* clear current single-touch array */
memset(trc.cur_st_tch, CY_IGNR_TCH, sizeof(trc.cur_st_tch));
/* clear single touch positions */
trc.st_x1 = trc.st_y1 = trc.st_z1 =
trc.st_x2 = trc.st_y2 = trc.st_z2 = CY_NTCH;
/* clear current multi-touch arrays */
memset(trc.cur_mt_tch, CY_IGNR_TCH, sizeof(trc.cur_mt_tch));
memset(trc.cur_mt_pos, CY_NTCH, sizeof(trc.cur_mt_pos));
memset(trc.cur_mt_z, CY_NTCH, sizeof(trc.cur_mt_z));
DBG(
if (trc.cur_tch) {
unsigned i;
u8 *pdata = (u8 *)&xy_data;
printk(KERN_INFO "%s: TTSP data_pack: ", __func__);
for (i = 0; i < sizeof(struct cyttsp_xydata); i++)
printk(KERN_INFO "[%d]=0x%x ", i, pdata[i]);
printk(KERN_INFO "\n");
})
/* Determine if display is tilted */
tilt = !!FLIP_DATA(ts->platform_data->flags);
/* Check for switch in origin */
rev_x = !!REVERSE_X(ts->platform_data->flags);
rev_y = !!REVERSE_Y(ts->platform_data->flags);
/* process the touches */
switch (trc.cur_tch) {
case 4:
xy_data.x4 = be16_to_cpu(xy_data.x4);
xy_data.y4 = be16_to_cpu(xy_data.y4);
if (tilt)
FLIP_XY(xy_data.x4, xy_data.y4);
if (rev_x)
xy_data.x4 = INVERT_X(xy_data.x4,
ts->platform_data->maxx);
if (rev_y)
xy_data.y4 = INVERT_X(xy_data.y4,
ts->platform_data->maxy);
id = GET_TOUCH4_ID(xy_data.touch34_id);
if (ts->platform_data->use_trk_id) {
trc.cur_mt_pos[CY_MT_TCH4_IDX][CY_XPOS] = xy_data.x4;
trc.cur_mt_pos[CY_MT_TCH4_IDX][CY_YPOS] = xy_data.y4;
trc.cur_mt_z[CY_MT_TCH4_IDX] = xy_data.z4;
} else {
trc.cur_mt_pos[id][CY_XPOS] = xy_data.x4;
trc.cur_mt_pos[id][CY_YPOS] = xy_data.y4;
trc.cur_mt_z[id] = xy_data.z4;
}
trc.cur_mt_tch[CY_MT_TCH4_IDX] = id;
trc.cur_trk[id] = CY_TCH;
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] < CY_NUM_TRK_ID) {
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] == id) {
trc.st_x1 = xy_data.x4;
trc.st_y1 = xy_data.y4;
trc.st_z1 = xy_data.z4;
trc.cur_st_tch[CY_ST_FNGR1_IDX] = id;
} else if (ts->prv_st_tch[CY_ST_FNGR2_IDX] == id) {
trc.st_x2 = xy_data.x4;
trc.st_y2 = xy_data.y4;
trc.st_z2 = xy_data.z4;
trc.cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
}
DBG(printk(KERN_INFO"%s: 4th XYZ:% 3d,% 3d,% 3d ID:% 2d\n\n",
__func__, xy_data.x4, xy_data.y4, xy_data.z4,
(xy_data.touch34_id & 0x0F));)
/* do not break */
case 3:
xy_data.x3 = be16_to_cpu(xy_data.x3);
xy_data.y3 = be16_to_cpu(xy_data.y3);
if (tilt)
FLIP_XY(xy_data.x3, xy_data.y3);
if (rev_x)
xy_data.x3 = INVERT_X(xy_data.x3,
ts->platform_data->maxx);
if (rev_y)
xy_data.y3 = INVERT_X(xy_data.y3,
ts->platform_data->maxy);
id = GET_TOUCH3_ID(xy_data.touch34_id);
if (ts->platform_data->use_trk_id) {
trc.cur_mt_pos[CY_MT_TCH3_IDX][CY_XPOS] = xy_data.x3;
trc.cur_mt_pos[CY_MT_TCH3_IDX][CY_YPOS] = xy_data.y3;
trc.cur_mt_z[CY_MT_TCH3_IDX] = xy_data.z3;
} else {
trc.cur_mt_pos[id][CY_XPOS] = xy_data.x3;
trc.cur_mt_pos[id][CY_YPOS] = xy_data.y3;
trc.cur_mt_z[id] = xy_data.z3;
}
trc.cur_mt_tch[CY_MT_TCH3_IDX] = id;
trc.cur_trk[id] = CY_TCH;
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] < CY_NUM_TRK_ID) {
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] == id) {
trc.st_x1 = xy_data.x3;
trc.st_y1 = xy_data.y3;
trc.st_z1 = xy_data.z3;
trc.cur_st_tch[CY_ST_FNGR1_IDX] = id;
} else if (ts->prv_st_tch[CY_ST_FNGR2_IDX] == id) {
trc.st_x2 = xy_data.x3;
trc.st_y2 = xy_data.y3;
trc.st_z2 = xy_data.z3;
trc.cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
}
DBG(printk(KERN_INFO"%s: 3rd XYZ:% 3d,% 3d,% 3d ID:% 2d\n",
__func__, xy_data.x3, xy_data.y3, xy_data.z3,
((xy_data.touch34_id >> 4) & 0x0F));)
/* do not break */
case 2:
xy_data.x2 = be16_to_cpu(xy_data.x2);
xy_data.y2 = be16_to_cpu(xy_data.y2);
if (tilt)
FLIP_XY(xy_data.x2, xy_data.y2);
if (rev_x)
xy_data.x2 = INVERT_X(xy_data.x2,
ts->platform_data->maxx);
if (rev_y)
xy_data.y2 = INVERT_X(xy_data.y2,
ts->platform_data->maxy);
id = GET_TOUCH2_ID(xy_data.touch12_id);
if (ts->platform_data->use_trk_id) {
trc.cur_mt_pos[CY_MT_TCH2_IDX][CY_XPOS] = xy_data.x2;
trc.cur_mt_pos[CY_MT_TCH2_IDX][CY_YPOS] = xy_data.y2;
trc.cur_mt_z[CY_MT_TCH2_IDX] = xy_data.z2;
} else {
trc.cur_mt_pos[id][CY_XPOS] = xy_data.x2;
trc.cur_mt_pos[id][CY_YPOS] = xy_data.y2;
trc.cur_mt_z[id] = xy_data.z2;
}
trc.cur_mt_tch[CY_MT_TCH2_IDX] = id;
trc.cur_trk[id] = CY_TCH;
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] < CY_NUM_TRK_ID) {
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] == id) {
trc.st_x1 = xy_data.x2;
trc.st_y1 = xy_data.y2;
trc.st_z1 = xy_data.z2;
trc.cur_st_tch[CY_ST_FNGR1_IDX] = id;
} else if (ts->prv_st_tch[CY_ST_FNGR2_IDX] == id) {
trc.st_x2 = xy_data.x2;
trc.st_y2 = xy_data.y2;
trc.st_z2 = xy_data.z2;
trc.cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
}
DBG(printk(KERN_INFO"%s: 2nd XYZ:% 3d,% 3d,% 3d ID:% 2d\n",
__func__, xy_data.x2, xy_data.y2, xy_data.z2,
(xy_data.touch12_id & 0x0F));)
/* do not break */
case 1:
xy_data.x1 = be16_to_cpu(xy_data.x1);
xy_data.y1 = be16_to_cpu(xy_data.y1);
if (tilt)
FLIP_XY(xy_data.x1, xy_data.y1);
if (rev_x)
xy_data.x1 = INVERT_X(xy_data.x1,
ts->platform_data->maxx);
if (rev_y)
xy_data.y1 = INVERT_X(xy_data.y1,
ts->platform_data->maxy);
id = GET_TOUCH1_ID(xy_data.touch12_id);
if (ts->platform_data->use_trk_id) {
trc.cur_mt_pos[CY_MT_TCH1_IDX][CY_XPOS] = xy_data.x1;
trc.cur_mt_pos[CY_MT_TCH1_IDX][CY_YPOS] = xy_data.y1;
trc.cur_mt_z[CY_MT_TCH1_IDX] = xy_data.z1;
} else {
trc.cur_mt_pos[id][CY_XPOS] = xy_data.x1;
trc.cur_mt_pos[id][CY_YPOS] = xy_data.y1;
trc.cur_mt_z[id] = xy_data.z1;
}
trc.cur_mt_tch[CY_MT_TCH1_IDX] = id;
trc.cur_trk[id] = CY_TCH;
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] < CY_NUM_TRK_ID) {
if (ts->prv_st_tch[CY_ST_FNGR1_IDX] == id) {
trc.st_x1 = xy_data.x1;
trc.st_y1 = xy_data.y1;
trc.st_z1 = xy_data.z1;
trc.cur_st_tch[CY_ST_FNGR1_IDX] = id;
} else if (ts->prv_st_tch[CY_ST_FNGR2_IDX] == id) {
trc.st_x2 = xy_data.x1;
trc.st_y2 = xy_data.y1;
trc.st_z2 = xy_data.z1;
trc.cur_st_tch[CY_ST_FNGR2_IDX] = id;
}
}
DBG(printk(KERN_INFO"%s: S1st XYZ:% 3d,% 3d,% 3d ID:% 2d\n",
__func__, xy_data.x1, xy_data.y1, xy_data.z1,
((xy_data.touch12_id >> 4) & 0x0F));)
break;
case 0:
default:
break;
}
if (ts->platform_data->use_st)
handle_single_touch(&xy_data, &trc, ts);
if (ts->platform_data->use_mt)
handle_multi_touch(&trc, ts);
/* handle gestures */
if (ts->platform_data->use_gestures && xy_data.gest_id) {
input_report_key(ts->input, BTN_3, CY_TCH);
input_report_abs(ts->input, ABS_HAT1X, xy_data.gest_id);
input_report_abs(ts->input, ABS_HAT1Y, xy_data.gest_cnt);
}
/* signal the view motion event */
input_sync(ts->input);
/* update platform data for the current multi-touch information */
memcpy(ts->act_trk, trc.cur_trk, CY_NUM_TRK_ID);
exit_xy_worker:
/* reset the watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
DBG(printk(KERN_INFO"%s: finished.\n", __func__);)
return;
}
static irqreturn_t cyttsp_irq(int irq, void *handle)
{
struct cyttsp *ts = (struct cyttsp *)handle;
DBG(printk(KERN_INFO"%s: Got IRQ!\n", __func__);)
switch (ts->platform_data->power_state) {
case CY_BL_STATE:
case CY_SYSINFO_STATE:
complete(&ts->int_running);
break;
case CY_LDR_STATE:
ts->bl_ready = true;
break;
case CY_ACTIVE_STATE:
cyttsp_xy_worker(ts);
break;
case CY_READY_STATE:
default:
break;
}
return IRQ_HANDLED;
}
/* Timer function used as watchdog */
static void cyttsp_timer(unsigned long handle)
{
struct cyttsp *ts = (struct cyttsp *)handle;
DBG(printk(KERN_INFO"%s: Watchdog timer event\n", __func__);)
if (!work_pending(&ts->work))
schedule_work(&ts->work);
return;
}
/*
************************************************************************
* Probe initialization functions
************************************************************************
*/
static int cyttsp_load_bl_regs(struct cyttsp *ts)
{
int retval;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
memset(&ts->bl_data, 0, sizeof(ts->bl_data));
retval = ttsp_read_block_data(ts, CY_REG_BASE,
sizeof(ts->bl_data), &(ts->bl_data));
if (retval < 0) {
DBG2(printk(KERN_INFO "%s: Failed reading block data, err:%d\n",
__func__, retval);)
goto fail;
}
DBG({
int i;
u8 *bl_data = (u8 *)&(ts->bl_data);
for (i = 0; i < sizeof(struct cyttsp_bootloader_data); i++)
printk(KERN_INFO "%s bl_data[%d]=0x%x\n",
__func__, i, bl_data[i]);
})
DBG2(printk(KERN_INFO "%s: bl f=%02X s=%02X e=%02X\n",
__func__,
ts->bl_data.bl_file,
ts->bl_data.bl_status,
ts->bl_data.bl_error);)
return 0;
fail:
return retval;
}
static bool cyttsp_bl_app_valid(struct cyttsp *ts)
{
int retval;
ts->bl_data.bl_status = 0x00;
retval = cyttsp_load_bl_regs(ts);
if (retval < 0)
return false;
if (ts->bl_data.bl_status == 0x11) {
printk(KERN_INFO "%s: App found; normal boot\n", __func__);
return true;
} else if (ts->bl_data.bl_status == 0x10) {
printk(KERN_INFO "%s: NO APP; load firmware!!\n", __func__);
return false;
} else {
if (ts->bl_data.bl_file == CY_OPERATE_MODE) {
int invalid_op_mode_status;
invalid_op_mode_status = ts->bl_data.bl_status & 0x3f;
if (invalid_op_mode_status)
return false;
else {
if (ts->platform_data->power_state ==
CY_ACTIVE_STATE)
printk(KERN_INFO "%s: Operational\n",
__func__);
else
printk(KERN_INFO "%s: No bootloader\n",
__func__);
}
}
return true;
}
}
static int cyttsp_exit_bl_mode(struct cyttsp *ts)
{
int retval;
int tries = 0;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
/* check if in bootloader mode;
* if in operational mode then just return without fail
*/
cyttsp_load_bl_regs(ts);
if (!GET_BOOTLOADERMODE(ts->bl_data.bl_status))
return 0;
retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(bl_cmd),
(void *)bl_cmd);
if (retval < 0) {
printk(KERN_ERR "%s: Failed writing block data, err:%d\n",
__func__, retval);
goto fail;
}
do {
msleep(20);
cyttsp_load_bl_regs(ts);
} while (GET_BOOTLOADERMODE(ts->bl_data.bl_status) && tries++ < 10);
DBG2(printk(KERN_INFO "%s: read tries=%d\n", __func__, tries);)
DBG(printk(KERN_INFO"%s: Exit "
"f=%02X s=%02X e=%02X\n",
__func__,
ts->bl_data.bl_file, ts->bl_data.bl_status,
ts->bl_data.bl_error);)
return 0;
fail:
return retval;
}
static int cyttsp_set_sysinfo_mode(struct cyttsp *ts)
{
int retval;
u8 cmd = CY_SYSINFO_MODE;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
memset(&(ts->sysinfo_data), 0, sizeof(struct cyttsp_sysinfo_data));
/* switch to sysinfo mode */
retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd);
if (retval < 0) {
printk(KERN_ERR "%s: Failed writing block data, err:%d\n",
__func__, retval);
goto exit_sysinfo_mode;
}
if (!(retval < 0)) {
/* wait for interrupt to set ready completion */
ts->platform_data->power_state = CY_SYSINFO_STATE;
INIT_COMPLETION(ts->int_running);
retval = wait_for_completion_interruptible_timeout(
&ts->int_running,
msecs_to_jiffies(CY_DELAY_DFLT * CY_DELAY_MAX));
ts->platform_data->power_state = CY_READY_STATE;
}
if (retval < 0) {
ts->platform_data->power_state = CY_IDLE_STATE;
printk(KERN_ERR "%s: reset timeout fail (ret=%d)\n",
__func__, retval);
}
exit_sysinfo_mode:
/* read sysinfo registers */
retval = ttsp_read_block_data(ts, CY_REG_BASE,
sizeof(ts->sysinfo_data), &(ts->sysinfo_data));
DBG(printk(KERN_INFO"%s:SI2: hst_mode=0x%02X mfg_cmd=0x%02X "
"mfg_stat=0x%02X\n", __func__, ts->sysinfo_data.hst_mode,
ts->sysinfo_data.mfg_cmd,
ts->sysinfo_data.mfg_stat);)
DBG(printk(KERN_INFO"%s:SI2: bl_ver=0x%02X%02X\n",
__func__, ts->sysinfo_data.bl_verh, ts->sysinfo_data.bl_verl);)
DBG(printk(KERN_INFO"%s:SI2: sysinfo act_intrvl=0x%02X "
"tch_tmout=0x%02X lp_intrvl=0x%02X\n",
__func__, ts->sysinfo_data.act_intrvl,
ts->sysinfo_data.tch_tmout,
ts->sysinfo_data.lp_intrvl);)
printk(KERN_INFO"%s:SI2:tts_ver=%02X%02X app_id=%02X%02X "
"app_ver=%02X%02X c_id=%02X%02X%02X "
"u_id=%02X%02X%02X%02X%02X%02X%02X%02X\n",
__func__,
ts->sysinfo_data.tts_verh, ts->sysinfo_data.tts_verl,
ts->sysinfo_data.app_idh, ts->sysinfo_data.app_idl,
ts->sysinfo_data.app_verh, ts->sysinfo_data.app_verl,
ts->sysinfo_data.cid[0], ts->sysinfo_data.cid[1],
ts->sysinfo_data.cid[2],
ts->sysinfo_data.uid[0], ts->sysinfo_data.uid[1],
ts->sysinfo_data.uid[2], ts->sysinfo_data.uid[3],
ts->sysinfo_data.uid[4], ts->sysinfo_data.uid[5],
ts->sysinfo_data.uid[6], ts->sysinfo_data.uid[7]);
return retval;
}
static int cyttsp_set_sysinfo_regs(struct cyttsp *ts)
{
int retval = 0;
if (ts->platform_data->scn_typ != CY_SCN_TYP_DFLT) {
u8 scn_typ = ts->platform_data->scn_typ;
retval = ttsp_write_block_data(ts,
CY_REG_SCN_TYP,
sizeof(scn_typ), &scn_typ);
}
if (retval < 0)
return retval;
if ((ts->platform_data->act_intrvl != CY_ACT_INTRVL_DFLT) ||
(ts->platform_data->tch_tmout != CY_TCH_TMOUT_DFLT) ||
(ts->platform_data->lp_intrvl != CY_LP_INTRVL_DFLT)) {
u8 intrvl_ray[3];
intrvl_ray[0] = ts->platform_data->act_intrvl;
intrvl_ray[1] = ts->platform_data->tch_tmout;
intrvl_ray[2] = ts->platform_data->lp_intrvl;
/* set intrvl registers */
retval = ttsp_write_block_data(ts,
CY_REG_ACT_INTRVL,
sizeof(intrvl_ray), intrvl_ray);
msleep(CY_DELAY_SYSINFO);
}
return retval;
}
static int cyttsp_set_operational_mode(struct cyttsp *ts)
{
int retval;
int tries;
u8 cmd = CY_OPERATE_MODE;
u8 gest_default;
struct cyttsp_xydata xy_data;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd);
if (retval < 0) {
printk(KERN_ERR "%s: Failed writing block data, err:%d\n",
__func__, retval);
goto write_block_data_fail;
}
/* wait for TTSP Device to complete switch to Operational mode */
msleep(20);
tries = 0;
gest_default =
CY_GEST_GRP1 + CY_GEST_GRP2 +
CY_GEST_GRP3 + CY_GEST_GRP4 +
CY_ACT_DIST_DFLT;
tries = 0;
do {
msleep(CY_DELAY_DFLT);
memset(&xy_data, 0, sizeof(xy_data));
retval = ttsp_read_block_data(ts, CY_REG_BASE,
sizeof(struct cyttsp_xydata), &xy_data);
} while (!((retval == 0) &&
((xy_data.gest_set & CY_ACT_DIST_BITS) ==
(CY_ACT_DIST_DFLT & CY_ACT_DIST_BITS))) &&
(tries++ < CY_DELAY_MAX));
DBG2(printk(KERN_INFO "%s: read tries=%d\n", __func__, tries);)
return 0;
write_block_data_fail:
return retval;
}
static int cyttsp_soft_reset(struct cyttsp *ts)
{
int retval;
u8 cmd = CY_SOFT_RESET_MODE;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
/* reset TTSP Device back to bootloader mode */
ts->platform_data->power_state = CY_BL_STATE;
retval = ttsp_write_block_data(ts, CY_REG_BASE, sizeof(cmd), &cmd);
if (!(retval < 0)) {
/* wait for interrupt to set ready completion */
INIT_COMPLETION(ts->int_running);
retval = wait_for_completion_interruptible_timeout(
&ts->int_running,
msecs_to_jiffies(CY_DELAY_DFLT * CY_DELAY_MAX));
}
if (retval < 0) {
ts->platform_data->power_state = CY_IDLE_STATE;
printk(KERN_ERR "%s: reset timeout fail (ret=%d)\n",
__func__, retval);
}
if (retval > 0)
retval = 0;
return retval;
}
static int cyttsp_gesture_setup(struct cyttsp *ts)
{
int retval;
u8 gesture_setup;
DBG(printk(KERN_INFO"%s: Init gesture; active distance setup\n",
__func__);)
gesture_setup = ts->platform_data->gest_set;
retval = ttsp_write_block_data(ts, CY_REG_GEST_SET,
sizeof(gesture_setup), &gesture_setup);
return retval;
}
#ifdef CY_INCLUDE_LOAD_RECS
#include "cyttsp_ldr.h"
#else
static bool cyttsp_bl_status(struct cyttsp *ts)
{
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
return ((ts->bl_data.bl_status == 0x10) ||
(ts->bl_data.bl_status == 0x11));
}
static int cyttsp_loader(struct cyttsp *ts)
{
void *fptr = cyttsp_bl_status; /* kill warning */
if (ts) {
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
DBG(printk(KERN_INFO"%s: Exit\n", __func__);)
}
if (!fptr)
return -EIO;
else
return 0;
}
#endif
static int cyttsp_power_on(struct cyttsp *ts)
{
int retval = 0;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
/* (re-)start watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
cyttsp_init_tch(ts);
retval = cyttsp_soft_reset(ts);
DBG2(printk(KERN_INFO"%s: after softreset r=%d\n", __func__, retval);)
if (retval < 0)
goto bypass;
if (ts->platform_data->use_load_file)
retval = cyttsp_loader(ts);
if (!cyttsp_bl_app_valid(ts)) {
retval = 1;
goto bypass;
}
retval = cyttsp_exit_bl_mode(ts);
DBG2(printk(KERN_INFO"%s: after exit bl r=%d\n", __func__, retval);)
if (retval < 0)
goto bypass;
/* switch to System Information mode to read */
/* versions and set interval registers */
ts->platform_data->power_state = CY_READY_STATE;
retval = cyttsp_set_sysinfo_mode(ts);
if (retval < 0)
goto bypass;
retval = cyttsp_set_sysinfo_regs(ts);
if (retval < 0)
goto bypass;
/* switch back to Operational mode */
DBG2(printk(KERN_INFO"%s: switch back to operational mode\n",
__func__);)
retval = cyttsp_set_operational_mode(ts);
if (retval < 0)
goto bypass;
/* init gesture setup; required for active distance */
cyttsp_gesture_setup(ts);
bypass:
if (retval)
ts->platform_data->power_state = CY_IDLE_STATE;
else
ts->platform_data->power_state = CY_ACTIVE_STATE;
printk(KERN_INFO"%s: Power state is %s\n",
__func__, (ts->platform_data->power_state == CY_ACTIVE_STATE) ?
"ACTIVE" : "IDLE");
return retval;
}
static void cyttsp_check_bl(struct work_struct *work)
{
struct cyttsp *ts = container_of(work, struct cyttsp, work);
s32 retval;
struct cyttsp_xydata xy_data;
retval = ttsp_read_block_data(ts, CY_REG_BASE, 2, &xy_data);
if (retval < 0) {
printk(KERN_ERR "%s: Error, fail to read device\n", __func__);
goto reserve_next;
}
if (CY_MODE_ERROR(ts->platform_data->power_state,
xy_data.hst_mode, xy_data.tt_mode)) {
printk(KERN_ERR "%s: Error, mode error detected "
"on watchdog timeout ps=%d mode=%02X bl_mode=%02X\n",
__func__, ts->platform_data->power_state,
xy_data.hst_mode, xy_data.tt_mode);
retval = cyttsp_power_on(ts);
if (retval < 0)
printk(KERN_ERR "%s: Error, power on fail\n", __func__);
}
reserve_next:
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
}
static int cyttsp_resume(struct cyttsp *ts)
{
int retval = 0;
struct cyttsp_xydata xydata;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
if (ts->platform_data->use_sleep && (ts->platform_data->power_state !=
CY_ACTIVE_STATE)) {
if (ts->platform_data->wakeup) {
retval = ts->platform_data->wakeup();
if (retval < 0)
printk(KERN_ERR "%s: Error, wakeup failed!\n",
__func__);
} else {
printk(KERN_ERR "%s: Error, wakeup not implemented "
"(check board file).\n", __func__);
retval = -ENOSYS;
}
if (!(retval < 0)) {
retval = ttsp_read_block_data(ts, CY_REG_BASE,
sizeof(xydata), &xydata);
if (!(retval < 0) && !GET_HSTMODE(xydata.hst_mode))
ts->platform_data->power_state =
CY_ACTIVE_STATE;
}
}
DBG(printk(KERN_INFO"%s: Wake Up %s\n", __func__,
(retval < 0) ? "FAIL" : "PASS");)
return retval;
}
static int cyttsp_suspend(struct cyttsp *ts)
{
u8 sleep_mode = 0;
int retval = 0;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
if (ts->platform_data->use_sleep &&
(ts->platform_data->power_state == CY_ACTIVE_STATE)) {
sleep_mode = CY_DEEP_SLEEP_MODE;
retval = ttsp_write_block_data(ts,
CY_REG_BASE, sizeof(sleep_mode), &sleep_mode);
if (!(retval < 0))
ts->platform_data->power_state = CY_SLEEP_STATE;
}
DBG(printk(KERN_INFO"%s: Sleep Power state is %s\n", __func__,
(ts->platform_data->power_state == CY_ACTIVE_STATE) ?
"ACTIVE" :
((ts->platform_data->power_state == CY_SLEEP_STATE) ?
"SLEEP" : "LOW POWER"));)
return retval;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void cyttsp_ts_early_suspend(struct early_suspend *h)
{
struct cyttsp *ts = container_of(h, struct cyttsp, early_suspend);
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
LOCK(ts->mutex);
if (!ts->fw_loader_mode) {
disable_irq_nosync(ts->irq);
ts->suspended = 1;
/* kill watchdog */
del_timer(&ts->timer);
cancel_work_sync(&ts->work);
cyttsp_suspend(ts);
}
regulator_disable(ts->regulator);
UNLOCK(ts->mutex);
}
static void cyttsp_ts_late_resume(struct early_suspend *h)
{
struct cyttsp *ts = container_of(h, struct cyttsp, early_suspend);
regulator_enable(ts->regulator);
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
LOCK(ts->mutex);
if (!ts->fw_loader_mode && ts->suspended) {
ts->suspended = 0;
if (cyttsp_resume(ts) < 0)
printk(KERN_ERR "%s: Error, cyttsp_resume.\n",
__func__);
enable_irq(ts->irq);
/* resume watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
}
UNLOCK(ts->mutex);
}
#endif
static int cyttsp_wr_reg(struct cyttsp *ts, u8 reg_id, u8 reg_data)
{
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
return ttsp_write_block_data(ts,
CY_REG_BASE + reg_id, sizeof(u8), ®_data);
}
static int cyttsp_rd_reg(struct cyttsp *ts, u8 reg_id, u8 *reg_data)
{
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
return ttsp_read_block_data(ts,
CY_REG_BASE + reg_id, sizeof(u8), reg_data);
}
static ssize_t firmware_write(struct file *filp, struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct cyttsp *ts = dev_get_drvdata(dev);
LOCK(ts->mutex);
if (!ts->fw_loader_mode) {
unsigned short val = *(unsigned short *)buf;
u8 reg_data = val & 0xff;
ts->reg_id = (val & 0xff00) >> 8;
if (!(ts->reg_id & 0x80)) {
/* write user specified operational register */
if (ts->reg_id == 0x00) {
switch (GET_HSTMODE(reg_data)) {
case GET_HSTMODE(CY_OPERATE_MODE):
cyttsp_wr_reg(ts, ts->reg_id, reg_data);
ts->platform_data->power_state =
CY_ACTIVE_STATE;
enable_irq(ts->irq);
mod_timer(&ts->timer, CY_WDG_TIMEOUT);
printk(KERN_INFO "%s: "
"Switch to Operational Mode "
"ps=%d\n", __func__,
ts->platform_data->power_state);
break;
case GET_HSTMODE(CY_SYSINFO_MODE):
ts->platform_data->power_state =
CY_READY_STATE;
disable_irq_nosync(ts->irq);
/* kill watchdog */
del_timer(&ts->timer);
cancel_work_sync(&ts->work);
cyttsp_wr_reg(ts, ts->reg_id, reg_data);
printk(KERN_INFO "%s: "
"Switch to SysInfo Mode "
"ps=%d\n", __func__,
ts->platform_data->power_state);
break;
default:
cyttsp_wr_reg(ts, ts->reg_id, reg_data);
break;
}
} else
cyttsp_wr_reg(ts, ts->reg_id, reg_data);
printk(KERN_INFO "%s: "
"write(reg=%02X(%d) dat=0x%02X(%d))\n",
__func__,
ts->reg_id & ~0x80, ts->reg_id & ~0x80,
reg_data, reg_data);
} else {
/* save user specified operational read register */
DBG2(printk(KERN_INFO "%s: read(r=0x%02X)\n",
__func__, ts->reg_id);)
}
} else {
int retval = 0;
int tries = 0;
DBG({
char str[128];
char *p = str;
int i;
for (i = 0; i < size; i++, p += 2)
sprintf(p, "%02x", (unsigned char)buf[i]);
printk(KERN_DEBUG "%s: size %d, pos %ld payload %s\n",
__func__, size, (long)pos, str);
})
do {
retval = ttsp_write_block_data(ts,
CY_REG_BASE, size, buf);
if (retval < 0)
msleep(500);
} while ((retval < 0) && (tries++ < 10));
}
UNLOCK(ts->mutex);
return size;
}
static ssize_t firmware_read(struct file *filp, struct kobject *kobj,
struct bin_attribute *ba,
char *buf, loff_t pos, size_t size)
{
int count = 0;
u8 reg_data;
struct device *dev = container_of(kobj, struct device, kobj);
struct cyttsp *ts = dev_get_drvdata(dev);
DBG2(printk(KERN_INFO"%s: Enter (mode=%d)\n",
__func__, ts->fw_loader_mode);)
LOCK(ts->mutex);
if (!ts->fw_loader_mode) {
/* read user specified operational register */
cyttsp_rd_reg(ts, ts->reg_id & ~0x80, ®_data);
*(unsigned short *)buf = reg_data << 8;
count = sizeof(unsigned short);
printk(KERN_INFO "%s: read(reg=%02X(%d) dat=0x%02X(%d))\n",
__func__, ts->reg_id & ~0x80, ts->reg_id & ~0x80,
reg_data, reg_data);
} else {
int retval = 0;
int tries = 0;
do {
retval = cyttsp_load_bl_regs(ts);
if (retval < 0)
msleep(500);
} while ((retval < 0) && (tries++ < 10));
if (retval < 0) {
printk(KERN_ERR "%s: error reading status\n", __func__);
count = 0;
} else {
*(unsigned short *)buf = ts->bl_data.bl_status << 8 |
ts->bl_data.bl_error;
count = sizeof(unsigned short);
}
DBG2(printk(KERN_INFO
"%s:bl_f=0x%02X bl_s=0x%02X bl_e=0x%02X\n",
__func__,
ts->bl_data.bl_file,
ts->bl_data.bl_status,
ts->bl_data.bl_error);)
}
UNLOCK(ts->mutex);
return count;
}
static struct bin_attribute cyttsp_firmware = {
.attr = {
.name = "firmware",
.mode = 0644,
},
.size = 128,
.read = firmware_read,
.write = firmware_write,
};
static ssize_t attr_fwloader_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct cyttsp *ts = dev_get_drvdata(dev);
return sprintf(buf, "0x%02X%02X 0x%02X%02X 0x%02X%02X 0x%02X%02X%02X\n",
ts->sysinfo_data.tts_verh, ts->sysinfo_data.tts_verl,
ts->sysinfo_data.app_idh, ts->sysinfo_data.app_idl,
ts->sysinfo_data.app_verh, ts->sysinfo_data.app_verl,
ts->sysinfo_data.cid[0], ts->sysinfo_data.cid[1],
ts->sysinfo_data.cid[2]);
}
static ssize_t attr_fwloader_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t size)
{
char *p;
int ret;
struct cyttsp *ts = dev_get_drvdata(dev);
unsigned val = simple_strtoul(buf, &p, 10);
ret = p - buf;
if (*p && isspace(*p))
ret++;
DBG2(printk(KERN_DEBUG "%s: %u\n", __func__, val);)
LOCK(ts->mutex)
if (val == 3) {
sysfs_remove_bin_file(&dev->kobj, &cyttsp_firmware);
DBG2(printk(KERN_INFO "%s: FW loader closed for reg r/w\n",
__func__);)
} else if (val == 2) {
if (sysfs_create_bin_file(&dev->kobj, &cyttsp_firmware))
printk(KERN_ERR "%s: unable to create file\n",
__func__);
DBG2(printk(KERN_INFO "%s: FW loader opened for reg r/w\n",
__func__);)
if (ts->suspended) {
cyttsp_resume(ts);
ts->suspended = 0;
enable_irq(ts->irq);
/* resume watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
}
} else if ((val == 1) && !ts->fw_loader_mode) {
ts->fw_loader_mode = 1;
if (ts->suspended) {
cyttsp_resume(ts);
ts->suspended = 0;
enable_irq(ts->irq);
/* resume watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
}
disable_irq_nosync(ts->irq);
/* kill watchdog */
del_timer(&ts->timer);
cancel_work_sync(&ts->work);
if (sysfs_create_bin_file(&dev->kobj, &cyttsp_firmware))
printk(KERN_ERR "%s: unable to create file\n",
__func__);
DBG2(printk(KERN_INFO
"%s: FW loader opened for start load: ps=%d mode=%d\n",
__func__,
ts->platform_data->power_state, ts->fw_loader_mode);)
cyttsp_soft_reset(ts);
printk(KERN_INFO "%s: FW loader started.\n", __func__);
ts->platform_data->power_state = CY_LDR_STATE;
} else if (!val && ts->fw_loader_mode) {
sysfs_remove_bin_file(&dev->kobj, &cyttsp_firmware);
ts->fw_loader_mode = 0;
printk(KERN_INFO "%s: FW loader finished.\n", __func__);
enable_irq(ts->irq);
ret = cyttsp_power_on(ts);
if (ret < 0)
printk(KERN_ERR "%s: Error, power on fail\n", __func__);
/* resume watchdog */
mod_timer(&ts->timer, jiffies + CY_WDG_TIMEOUT);
}
UNLOCK(ts->mutex);
return ret == size ? ret : -EINVAL;
}
int cyttsp_reset_controller(struct cyttsp *ts)
{
int ret;
ret = gpio_request(ts->platform_data->rst_gpio, "reset_pin");
if (ret) {
printk(KERN_ERR "touch gpio failed\n");
return ret;
}
ret = gpio_direction_output(ts->platform_data->rst_gpio, 1);
if (ret < 0) {
printk(KERN_ERR "reset gpio direction failed\n");
goto out;
}
/*
* The start up procedure
* Set the RESET pin to low
* Wait for a period of 1 milisecond
* Set the RESET pin to high
* Wait for a period of 5 milisecond
* Start the initial Sequence
*/
gpio_set_value(ts->platform_data->rst_gpio, 0);
mdelay(1);
gpio_set_value(ts->platform_data->rst_gpio, 1);
mdelay(5);
out:
gpio_free(ts->platform_data->rst_gpio);
return 0;
}
static struct device_attribute fwloader =
__ATTR(fwloader, 0644, attr_fwloader_show, attr_fwloader_store);
void *cyttsp_core_init(struct cyttsp_bus_ops *bus_ops, struct device *pdev)
{
struct input_dev *input_device;
struct cyttsp *ts;
int retval = 0, ret = 0;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
ts = kzalloc(sizeof(*ts), GFP_KERNEL);
if (ts == NULL) {
printk(KERN_ERR "%s: Error, kzalloc\n", __func__);
goto error_alloc_data_failed;
}
mutex_init(&ts->mutex);
ts->pdev = pdev;
ts->platform_data = pdev->platform_data;
ts->bus_ops = bus_ops;
init_completion(&ts->int_running);
if (ts->platform_data->init)
retval = ts->platform_data->init(1);
if (retval) {
printk(KERN_ERR "%s: platform init failed!\n", __func__);
goto error_init;
}
ret = cyttsp_reset_controller(ts);
if (ret < 0) {
printk(KERN_ERR "controller reset failed\n");
goto error_reset;
}
/* Create the input device and register it. */
input_device = input_allocate_device();
if (!input_device) {
retval = -ENOMEM;
printk(KERN_ERR "%s: Error, failed to allocate input device\n",
__func__);
goto error_input_allocate_device;
}
ts->input = input_device;
input_device->name = ts->platform_data->name;
input_device->phys = ts->phys;
input_device->dev.parent = ts->pdev;
/* enable interrupts */
ts->irq = gpio_to_irq(ts->platform_data->irq_gpio);
retval = request_threaded_irq(ts->irq, NULL, cyttsp_irq,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
ts->input->name, ts);
if (retval < 0) {
printk(KERN_ERR "%s: IRQ request failed r=%d\n",
__func__, retval);
ts->platform_data->power_state = CY_INVALID_STATE;
goto error_set_irq;
}
/* setup watchdog */
INIT_WORK(&ts->work, cyttsp_check_bl);
setup_timer(&ts->timer, cyttsp_timer, (unsigned long) ts);
DBG(printk(KERN_INFO "%s: call power_on\n", __func__);)
retval = cyttsp_power_on(ts);
if (retval < 0) {
printk(KERN_ERR "%s: Error, power on failed!\n", __func__);
goto error_power_on;
}
set_bit(EV_SYN, input_device->evbit);
set_bit(EV_KEY, input_device->evbit);
set_bit(EV_ABS, input_device->evbit);
set_bit(BTN_TOUCH, input_device->keybit);
set_bit(BTN_2, input_device->keybit);
if (ts->platform_data->use_gestures)
set_bit(BTN_3, input_device->keybit);
input_set_abs_params(input_device, ABS_X, 0, ts->platform_data->maxx,
0, 0);
input_set_abs_params(input_device, ABS_Y, 0, ts->platform_data->maxy,
0, 0);
input_set_abs_params(input_device, ABS_TOOL_WIDTH, 0,
CY_LARGE_TOOL_WIDTH, 0, 0);
input_set_abs_params(input_device, ABS_PRESSURE, 0, CY_MAXZ, 0, 0);
input_set_abs_params(input_device, ABS_HAT0X, 0,
ts->platform_data->maxx, 0, 0);
input_set_abs_params(input_device, ABS_HAT0Y, 0,
ts->platform_data->maxy, 0, 0);
if (ts->platform_data->use_gestures) {
input_set_abs_params(input_device, ABS_HAT1X, 0, CY_MAXZ,
0, 0);
input_set_abs_params(input_device, ABS_HAT1Y, 0, CY_MAXZ,
0, 0);
}
if (ts->platform_data->use_mt) {
input_set_abs_params(input_device, ABS_MT_POSITION_X, 0,
ts->platform_data->maxx, 0, 0);
input_set_abs_params(input_device, ABS_MT_POSITION_Y, 0,
ts->platform_data->maxy, 0, 0);
input_set_abs_params(input_device, ABS_MT_TOUCH_MAJOR, 0,
CY_MAXZ, 0, 0);
input_set_abs_params(input_device, ABS_MT_WIDTH_MAJOR, 0,
CY_LARGE_TOOL_WIDTH, 0, 0);
if (ts->platform_data->use_trk_id)
input_set_abs_params(input_device, ABS_MT_TRACKING_ID,
0, CY_NUM_TRK_ID, 0, 0);
}
if (ts->platform_data->use_virtual_keys)
input_set_capability(input_device, EV_KEY, KEY_PROG1);
retval = input_register_device(input_device);
if (retval) {
printk(KERN_ERR "%s: Error, failed to register input device\n",
__func__);
goto error_input_register_device;
}
DBG(printk(KERN_INFO "%s: Registered input device %s\n",
__func__, input_device->name);)
ts->regulator = regulator_get(ts->pdev, "vcpin");
if (IS_ERR(ts->regulator)) {
printk(KERN_ERR "%s: Error, regulator_get failed\n", __func__);
ts->regulator = NULL;
goto error_input_register_device;
} else {
ret = regulator_enable(ts->regulator);
if (ret < 0) {
printk(KERN_ERR "%s: regulator enable failed\n",
__func__);
goto out_regulator_error;
}
}
#ifdef CONFIG_HAS_EARLYSUSPEND
ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
ts->early_suspend.suspend = cyttsp_ts_early_suspend;
ts->early_suspend.resume = cyttsp_ts_late_resume;
register_early_suspend(&ts->early_suspend);
#endif
retval = device_create_file(pdev, &fwloader);
if (retval) {
printk(KERN_ERR "%s: Error, could not create attribute\n",
__func__);
goto device_create_error;
}
dev_set_drvdata(pdev, ts);
return ts;
device_create_error:
regulator_disable(ts->regulator);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&ts->early_suspend);
#endif
out_regulator_error:
regulator_put(ts->regulator);
error_input_register_device:
input_unregister_device(input_device);
error_power_on:
cancel_work_sync(&ts->work);
del_timer_sync(&ts->timer);
if (ts->irq >= 0)
free_irq(ts->irq, ts);
error_set_irq:
input_free_device(input_device);
error_reset:
error_input_allocate_device:
if (ts->platform_data->init)
ts->platform_data->init(0);
error_init:
kfree(ts);
error_alloc_data_failed:
return NULL;
}
/* registered in driver struct */
void cyttsp_core_release(void *handle)
{
struct cyttsp *ts = handle;
DBG(printk(KERN_INFO"%s: Enter\n", __func__);)
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&ts->early_suspend);
#endif
del_timer_sync(&ts->timer);
cancel_work_sync(&ts->work);
free_irq(ts->irq, ts);
input_unregister_device(ts->input);
input_free_device(ts->input);
if (ts->platform_data->init)
ts->platform_data->init(0);
kfree(ts);
}
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver core");
MODULE_AUTHOR("Cypress");
|