1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
|
/*
*
* Zinitix bt541 touchscreen driver
*
* Copyright (C) 2013 Samsung Electronics Co.Ltd
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*/
#define TSP_VERBOSE_DEBUG
#define SEC_FACTORY_TEST
#define SUPPORTED_TOUCH_KEY
#include <linux/module.h>
#include <linux/input.h>
#include <linux/i2c.h>
#include <linux/miscdevice.h>
#include <linux/interrupt.h>
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/earlysuspend.h>
#endif
#if defined(CONFIG_PM_RUNTIME)
#include <linux/pm_runtime.h>
#endif
#include <linux/semaphore.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/uaccess.h>
#include <linux/regulator/consumer.h>
#include <linux/input/zinitix_bt541_ts.h>
#include <linux/input/mt.h>
#include <linux/of_gpio.h>
#include <soc/sprd/i2c-sprd.h>
#include <linux/power_supply.h>
/* added header file */
/* #define SUPPORTED_USE_DUAL_FW */
#ifdef SUPPORTED_USE_DUAL_FW
#include "zinitix_bt541_firmware_00.h"
#include "zinitix_bt541_firmware_01.h"
u8 *m_firmware_data;
#else
#include "zinitix_bt541_firmware.h"
#endif
extern void (*tsp_charger_status_cb)(int);
#ifdef SUPPORTED_USE_DUAL_FW
#define TSP_TYPE_COUNT 2
u8 *m_pFirmware[TSP_TYPE_COUNT] = {(u8 *)m_firmware_data_00, (u8 *)m_firmware_data_01,};
u8 m_FirmwareIdx = 0;
#define CHECK_HWID 1
static void bt541_firmware_check(void);
#else
#define CHECK_HWID 0
#endif
static bool ta_connected =0;
#define ZINITIX_DEBUG 1
#define ZINITIX_I2C_CHECKSUM 1
#define TOUCH_BOOSTER 0
#define NOT_SUPPORTED_TOUCH_DUMMY_KEY
#if TOUCH_BOOSTER
#include <linux/cpufreq.h>
#include <linux/cpufreq_limit.h>
extern int _store_cpu_num_min_limit(unsigned int input);
struct cpufreq_limit_handle *min_handle = NULL;
static const unsigned long touch_cpufreq_lock = 1200000;
#endif
#ifdef SUPPORTED_PALM_TOUCH
#define TOUCH_POINT_MODE 2
#else
#define TOUCH_POINT_MODE 0
#endif
#define MAX_SUPPORTED_FINGER_NUM 2 /* max 10 */
#ifdef SUPPORTED_TOUCH_KEY
#ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
#define MAX_SUPPORTED_BUTTON_NUM 2 /* max 8 */
#define SUPPORTED_BUTTON_NUM 2
#else
#define MAX_SUPPORTED_BUTTON_NUM 2 /* max 8 */
#define SUPPORTED_BUTTON_NUM 2
#endif
#endif
/* Upgrade Method*/
#define TOUCH_ONESHOT_UPGRADE 1
/* if you use isp mode, you must add i2c device :
name = "zinitix_isp" , addr 0x50*/
/* resolution offset */
#define ABS_PT_OFFSET (0)
#define TOUCH_FORCE_UPGRADE 1
#define USE_CHECKSUM 1
#define CHIP_OFF_DELAY 50 /*ms*/
#define CHIP_ON_DELAY 20 /*15*/ /*ms*/
#define FIRMWARE_ON_DELAY 60 /*40*/ /*ms*/
#define DELAY_FOR_SIGNAL_DELAY 30 /*us*/
#define DELAY_FOR_TRANSCATION 50
#define DELAY_FOR_POST_TRANSCATION 10
/* PMIC Regulator based supply to TSP */
#define TSP_REGULATOR_SUPPLY 1
/* gpio controlled LDO based supply to TSP */
#define TSP_LDO_SUPPLY 0
enum power_control {
POWER_OFF,
POWER_ON,
POWER_ON_SEQUENCE,
};
/* Key Enum */
enum key_event {
ICON_BUTTON_UNCHANGE,
ICON_BUTTON_DOWN,
ICON_BUTTON_UP,
};
/* ESD Protection */
/*second : if 0, no use. if you have to use, 3 is recommended*/
#define ESD_TIMER_INTERVAL 1
#define SCAN_RATE_HZ 100
#define CHECK_ESD_TIMER 3
/*Test Mode (Monitoring Raw Data) */
#define MAX_RAW_DATA_SZ 576 /* 32x18 */
#define MAX_TRAW_DATA_SZ \
(MAX_RAW_DATA_SZ + 4*MAX_SUPPORTED_FINGER_NUM + 2)
/* preriod raw data interval */
#define RAWDATA_DELAY_FOR_HOST 100
struct raw_ioctl {
u32 sz;
u32 buf;
};
struct reg_ioctl {
u32 addr;
u32 val;
};
#define TOUCH_SEC_MODE 48
#define TOUCH_REF_MODE 10
#define TOUCH_NORMAL_MODE 5
#define TOUCH_DELTA_MODE 3
#define TOUCH_SDND_MODE 6
#define TOUCH_DND_MODE 11
/* Other Things */
#define INIT_RETRY_CNT 1
#define I2C_SUCCESS 0
#define I2C_FAIL 1
/*---------------------------------------------------------------------*/
/* Register Map*/
#define BT541_SWRESET_CMD 0x0000
#define BT541_WAKEUP_CMD 0x0001
#define BT541_IDLE_CMD 0x0004
#define BT541_SLEEP_CMD 0x0005
#define BT541_CLEAR_INT_STATUS_CMD 0x0003
#define BT541_CALIBRATE_CMD 0x0006
#define BT541_SAVE_STATUS_CMD 0x0007
#define BT541_SAVE_CALIBRATION_CMD 0x0008
#define BT541_RECALL_FACTORY_CMD 0x000f
#define BT541_THRESHOLD 0x0020
#define BT541_DEBUG_REG 0x0115 /* 0~7 */
#define BT541_TOUCH_MODE 0x0010
#define BT541_CHIP_REVISION 0x0011
#define BT541_FIRMWARE_VERSION 0x0012
#define BT541_MINOR_FW_VERSION 0x0121
#define BT541_VENDOR_ID 0x001C
#define BT541_MODULE_ID 0x001E
#define BT541_HW_ID 0x0014
#define BT541_DATA_VERSION_REG 0x0013
#define BT541_SUPPORTED_FINGER_NUM 0x0015
#define BT541_EEPROM_INFO 0x0018
#define BT541_INITIAL_TOUCH_MODE 0x0019
#define BT541_TOTAL_NUMBER_OF_X 0x0060
#define BT541_TOTAL_NUMBER_OF_Y 0x0061
#define BT541_DELAY_RAW_FOR_HOST 0x007f
#define BT541_BUTTON_SUPPORTED_NUM 0x00B0
#define BT541_BUTTON_SENSITIVITY 0x00B2
#define BT541_DUMMY_BUTTON_SENSITIVITY 0X00C8
#define BT541_BTN_WIDTH 0x016d
#define BT541_X_RESOLUTION 0x00C0
#define BT541_Y_RESOLUTION 0x00C1
#define BT541_POINT_STATUS_REG 0x0080
#define BT541_ICON_STATUS_REG 0x00AA
#define BT541_AFE_FREQUENCY 0x0100
#define BT541_DND_N_COUNT 0x0122
#define BT541_DND_U_COUNT 0x0135
#define BT541_SHIFT_VALUE 0x012B
#define BT541_RAWDATA_REG 0x0200
#define BT541_EEPROM_INFO_REG 0x0018
#define BT541_INT_ENABLE_FLAG 0x00f0
#define BT541_PERIODICAL_INTERRUPT_INTERVAL 0x00f1
#define BT541_CHECKSUM_RESULT 0x012c
#define BT541_INIT_FLASH 0x01d0
#define BT541_WRITE_FLASH 0x01d1
#define BT541_READ_FLASH 0x01d2
#define ZINITIX_INTERNAL_FLAG_02 0x011e
#define BT541_OPTIONAL_SETTING 0x0116
/* Interrupt & status register flag bit
-------------------------------------------------
*/
#define BIT_PT_CNT_CHANGE 0
#define BIT_DOWN 1
#define BIT_MOVE 2
#define BIT_UP 3
#define BIT_PALM 4
#define BIT_PALM_REJECT 5
#define RESERVED_0 6
#define RESERVED_1 7
#define BIT_WEIGHT_CHANGE 8
#define BIT_PT_NO_CHANGE 9
#define BIT_REJECT 10
#define BIT_PT_EXIST 11
#define RESERVED_2 12
#define BIT_MUST_ZERO 13
#define BIT_DEBUG 14
#define BIT_ICON_EVENT 15
/* button */
#define BIT_O_ICON0_DOWN 0
#define BIT_O_ICON1_DOWN 1
#define BIT_O_ICON2_DOWN 2
#define BIT_O_ICON3_DOWN 3
#define BIT_O_ICON4_DOWN 4
#define BIT_O_ICON5_DOWN 5
#define BIT_O_ICON6_DOWN 6
#define BIT_O_ICON7_DOWN 7
#define BIT_O_ICON0_UP 8
#define BIT_O_ICON1_UP 9
#define BIT_O_ICON2_UP 10
#define BIT_O_ICON3_UP 11
#define BIT_O_ICON4_UP 12
#define BIT_O_ICON5_UP 13
#define BIT_O_ICON6_UP 14
#define BIT_O_ICON7_UP 15
#define SUB_BIT_EXIST 0
#define SUB_BIT_DOWN 1
#define SUB_BIT_MOVE 2
#define SUB_BIT_UP 3
#define SUB_BIT_UPDATE 4
#define SUB_BIT_WAIT 5
#define zinitix_bit_set(val, n) ((val) &= ~(1<<(n)), (val) |= (1<<(n)))
#define zinitix_bit_clr(val, n) ((val) &= ~(1<<(n)))
#define zinitix_bit_test(val, n) ((val) & (1<<(n)))
#define zinitix_swap_v(a, b, t) ((t) = (a), (a) = (b), (b) = (t))
#define zinitix_swap_16(s) (((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)))
/* end header file */
#ifdef SEC_FACTORY_TEST
/* Touch Screen */
#define TSP_CMD_STR_LEN 32
#define TSP_CMD_RESULT_STR_LEN 512
#define TSP_CMD_PARAM_NUM 8
#define TSP_CMD_Y_NUM 18
#define TSP_CMD_X_NUM 30
#define TSP_CMD_NODE_NUM (TSP_CMD_Y_NUM * TSP_CMD_X_NUM)
struct tsp_factory_info {
struct list_head cmd_list_head;
char cmd[TSP_CMD_STR_LEN];
char cmd_param[TSP_CMD_PARAM_NUM];
char cmd_result[TSP_CMD_RESULT_STR_LEN];
char cmd_buff[TSP_CMD_RESULT_STR_LEN];
struct mutex cmd_lock;
bool cmd_is_running;
u8 cmd_state;
};
struct tsp_raw_data {
u16 ref_data[TSP_CMD_NODE_NUM];
u16 pref_data[TSP_CMD_NODE_NUM];
/*s16 scantime_data[TSP_CMD_NODE_NUM]; */
s16 delta_data[TSP_CMD_NODE_NUM];
};
enum {
WAITING = 0,
RUNNING,
OK,
FAIL,
NOT_APPLICABLE,
};
struct tsp_cmd {
struct list_head list;
const char *cmd_name;
void (*cmd_func)(void *device_data);
};
static void fw_update(void *device_data);
static void get_fw_ver_bin(void *device_data);
static void get_fw_ver_ic(void *device_data);
static void module_off_master(void *device_data);
static void module_on_master(void *device_data);
static void module_off_slave(void *device_data);
static void module_on_slave(void *device_data);
static void get_chip_vendor(void *device_data);
static void get_chip_name(void *device_data);
static void get_threshold(void *device_data);
static void get_x_num(void *device_data);
static void get_y_num(void *device_data);
static void not_support_cmd(void *device_data);
/* Vendor dependant command */
#ifdef SUPPORTED_USE_DUAL_FW
static void get_module_vendor(void *device_data);
#endif
static void get_reference_DND(void *device_data);
/*static void get_reference_RxDND(void *device_data);*/
static void get_reference_HFDND(void *device_data);
/*static void get_reference_RxHFDND(void *device_data);*/
/*static void get_tkey_delta(void *device_data);*/
static void get_reference_V_Diff(void *device_data);
/*static void get_reference_max_V_Diff(void *device_data);*/
static void get_reference_H_Diff(void * device_data);
/*static void get_reference_max_H_Diff(void * device_data);*/
/*static void get_max_dnd(void *device_data);*/
/*static void get_min_dnd(void *device_data);*/
/*static void get_max_hfdnd(void *device_data);*/
/*static void get_min_hfdnd(void *device_data);*/
/*static void get_max_hdiff(void *device_data);*/
/*static void get_min_hdiff(void *device_data);*/
/*static void get_max_vdiff(void *device_data);*/
/*static void get_min_vdiff(void *device_data);*/
/*static void get_reference(void *device_data);*/
/*static void get_preference(void *device_data);*/
/*static void run_preference_read(void *device_data);*/
static void run_reference_DND(void *device_data);
static void run_reference_HFDND(void *device_data);
static void run_reference_V_Diff(void *device_data);
static void run_reference_H_Diff(void *device_data);
/*static void run_reference_read(void *device_data);*/
static void hfdnd_spec_adjust(void *device_data);
static void clear_reference_data(void *device_data);
static void run_ref_calibration(void *device_data);
#define TSP_CMD(name, func) .cmd_name = name, .cmd_func = func
static struct tsp_cmd tsp_cmds[] = {
{TSP_CMD("fw_update", fw_update),},
{TSP_CMD("get_fw_ver_bin", get_fw_ver_bin),},
{TSP_CMD("get_fw_ver_ic", get_fw_ver_ic),},
{TSP_CMD("get_threshold", get_threshold),},
{TSP_CMD("module_off_master", module_off_master),},
{TSP_CMD("module_on_master", module_on_master),},
{TSP_CMD("module_off_slave", module_off_slave),},
{TSP_CMD("module_on_slave", module_on_slave),},
{TSP_CMD("get_chip_vendor", get_chip_vendor),},
{TSP_CMD("get_chip_name", get_chip_name),},
{TSP_CMD("get_x_num", get_x_num),},
{TSP_CMD("get_y_num", get_y_num),},
{TSP_CMD("not_support_cmd", not_support_cmd),},
/* vendor dependant command */
#ifdef SUPPORTED_USE_DUAL_FW
{TSP_CMD("get_module_vendor", get_module_vendor),},
#endif
{TSP_CMD("run_reference_read", run_reference_DND),},
{TSP_CMD("get_reference", get_reference_DND),},
{TSP_CMD("run_vdiff_read", run_reference_V_Diff),},
{TSP_CMD("get_vdiff", get_reference_V_Diff),},
{TSP_CMD("run_hdiff_read", run_reference_H_Diff),},
{TSP_CMD("get_hdiff", get_reference_H_Diff),},
{TSP_CMD("run_highfreq_read", run_reference_HFDND),},
{TSP_CMD("get_highfreq", get_reference_HFDND),},
{TSP_CMD("hfdnd_spec_adjust", hfdnd_spec_adjust),},
{TSP_CMD("clear_reference_data", clear_reference_data),},
{TSP_CMD("run_ref_calibration", run_ref_calibration),},
/*
{TSP_CMD("get_reference_DND", get_reference_DND),},
{TSP_CMD("get_reference_RxDND", get_reference_RxDND),},
{TSP_CMD("get_reference_HFDND", get_reference_HFDND),},
{TSP_CMD("get_reference_RxHFDND", get_reference_RxHFDND),},
{TSP_CMD("get_reference_V_DIFF", get_reference_V_Diff),},
{TSP_CMD("get_reference_max_V_DIFF", get_reference_max_V_Diff),},
{TSP_CMD("get_reference_H_DIFF", get_reference_H_Diff),},
{TSP_CMD("get_reference_max_H_DIFF", get_reference_max_H_Diff),},
{TSP_CMD("run_reference_HFDND", run_reference_HFDND),},
{TSP_CMD("run_reference_DND", run_reference_DND),},
{TSP_CMD("run_reference_diff", run_reference_PDiff),},
{TSP_CMD("get_max_dnd", get_max_dnd),},
{TSP_CMD("get_min_dnd", get_min_dnd),},
{TSP_CMD("get_max_hfdnd", get_max_hfdnd),},
{TSP_CMD("get_min_hfdnd", get_min_hfdnd),},
{TSP_CMD("get_max_hdiff", get_max_hdiff),},
{TSP_CMD("get_min_hdiff", get_min_hdiff),},
{TSP_CMD("get_max_vdiff", get_max_vdiff),},
{TSP_CMD("get_min_vdiff", get_min_vdiff),},
{TSP_CMD("get_tkey_delta", get_tkey_delta),},
{TSP_CMD("run_reference_read", run_reference_read),},
{TSP_CMD("get_reference", get_reference),},
{TSP_CMD("run_dnd_read", run_preference_read),},
{TSP_CMD("get_dnd", get_preference),},
*/
};
#if 0
#ifdef SUPPORTED_TOUCH_KEY
/* Touch Key */
static ssize_t touchkey_threshold(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touch_sensitivity(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touchkey_back(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touchkey_recent(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t autocal_stat(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touchkey_raw_back(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touchkey_raw_menu(struct device *dev,
struct device_attribute *attr, char *buf);
/*static ssize_t touchkey_idac_back(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t touchkey_idac_menu(struct device *dev,
struct device_attribute *attr, char *buf);
*/
#endif
#endif
#endif
#define TSP_NORMAL_EVENT_MSG 1
static int m_ts_debug_mode = ZINITIX_DEBUG;
#if ESD_TIMER_INTERVAL
static struct workqueue_struct *esd_tmr_workqueue;
#endif
struct coord {
u16 x;
u16 y;
u8 width;
u8 sub_status;
#if (TOUCH_POINT_MODE == 2)
u8 minor_width;
u8 angle;
#endif
};
struct point_info {
u16 status;
#if (TOUCH_POINT_MODE == 1)
u16 event_flag;
#else
u8 finger_cnt;
u8 time_stamp;
#endif
struct coord coord[MAX_SUPPORTED_FINGER_NUM];
};
#define TOUCH_V_FLIP 0x01
#define TOUCH_H_FLIP 0x02
#define TOUCH_XY_SWAP 0x04
/*Test Mode (Monitoring Raw Data) */
/*---------------------------------------------------------------------*/
/* GF1 */
/*---------------------------------------------------------------------*/
#define PDIFF_DEBUG 1
#define TSP_INIT_TEST_RATIO 100
#define SEC_DND_N_COUNT 16
#define SEC_DND_U_COUNT 20
#define SEC_DND_FREQUENCY 138 /*300khz*/
#define SEC_HFDND_N_COUNT 16
#define SEC_HFDND_U_COUNT 20
#define SEC_HFDND_FREQUENCY 27 /*300khz*/
/*---------------------------------------------------------------------*/
struct capa_info {
u16 vendor_id;
u16 ic_revision;
u16 fw_version;
u16 fw_minor_version;
u16 reg_data_version;
u16 threshold;
u16 key_threshold;
u16 dummy_threshold;
u32 ic_fw_size;
u32 MaxX;
u32 MaxY;
u32 MinX;
u32 MinY;
u8 gesture_support;
u16 multi_fingers;
u16 button_num;
u16 ic_int_mask;
u16 x_node_num;
u16 y_node_num;
u16 total_node_num;
u16 hw_id;
u16 module_id;
u16 afe_frequency;
u16 shift_value;
u16 N_cnt;
u16 U_cnt;
u16 i2s_checksum;
};
enum work_state {
NOTHING = 0,
NORMAL,
ESD_TIMER,
EALRY_SUSPEND,
SUSPEND,
RESUME,
LATE_RESUME,
UPGRADE,
REMOVE,
SET_MODE,
HW_CALIBRAION,
RAW_DATA,
PROBE,
};
enum {
BUILT_IN = 0,
UMS,
REQ_FW,
};
struct bt541_ts_info;
struct bt541_ts_platform_data {
u32 gpio_int;
u32 gpio_ldo_en;
int (*tsp_power)(struct bt541_ts_info *info, int on);
u32 x_resolution;
u32 y_resolution;
u32 page_size;
u32 orientation;
u32 tsp_supply_type;
};
struct bt541_ts_info {
struct i2c_client *client;
struct input_dev *input_dev;
struct bt541_ts_platform_data *pdata;
char phys[32];
/*struct task_struct *task;*/
/*wait_queue_head_t wait;*/
/*struct semaphore update_lock;*/
/*u32 i2c_dev_addr;*/
struct capa_info cap_info;
struct point_info touch_info;
struct point_info reported_touch_info;
u16 icon_event_reg;
u16 prev_icon_event;
/*u16 event_type;*/
int irq;
u8 button[MAX_SUPPORTED_BUTTON_NUM];
u8 work_state;
struct semaphore work_lock;
/*u16 debug_reg[8];*/ /* for debug */
#if ESD_TIMER_INTERVAL
struct work_struct tmr_work;
struct timer_list esd_timeout_tmr;
struct timer_list *p_esd_timeout_tmr;
spinlock_t lock;
#endif
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
#endif
struct semaphore raw_data_lock;
u16 touch_mode;
s16 cur_data[MAX_TRAW_DATA_SZ];
u8 update;
#ifdef SEC_FACTORY_TEST
struct tsp_factory_info *factory_info;
struct tsp_raw_data *raw_data;
s16 ref_data[MAX_RAW_DATA_SZ];
s16 normal_data[MAX_RAW_DATA_SZ];
s16 delta_data[MAX_RAW_DATA_SZ];
u16 pdnd_data[MAX_RAW_DATA_SZ];
u16 hfdnd_data[MAX_RAW_DATA_SZ];
u16 PDND2_N_cnt;
u16 PDND2_u_cnt;
u16 PDND2_freq;
s16 ref_btn_option;
s16 dnd_max_x;
s16 dnd_max_y;
s16 dnd_max_val;
s16 dnd_real_max_x;
s16 dnd_real_max_y;
s16 dnd_real_max_val;
s16 dnd_min_x;
s16 dnd_min_y;
s16 dnd_min_val;
s16 dnd_real_min_x;
s16 dnd_real_min_y;
s16 dnd_real_min_val;
s16 dnd_node_num;
s16 hfdnd_max_x;
s16 hfdnd_max_y;
s16 hfdnd_max_val;
s16 hfdnd_real_max_x;
s16 hfdnd_real_max_y;
s16 hfdnd_real_max_val;
s16 hfdnd_min_x;
s16 hfdnd_min_y;
s16 hfdnd_min_val;
s16 hfdnd_real_min_x;
s16 hfdnd_real_min_y;
s16 hfdnd_real_min_val;
s16 hfdnd_node_num;
s16 hdiff_max_x;
s16 hdiff_max_y;
s16 hdiff_max_val;
s16 hdiff_min_x;
s16 hdiff_min_y;
s16 hdiff_min_val;
s16 hdiff_diff_val;
s16 hdiff_node_num;
s16 vdiff_max_x;
s16 vdiff_max_y;
s16 vdiff_max_val;
s16 vdiff_min_x;
s16 vdiff_min_y;
s16 vdiff_min_val;
s16 vdiff_diff_val;
s16 vdiff_node_num;
bool dnd_done;
bool hfdnd_done;
#endif
#if TOUCH_BOOSTER
u8 finger_cnt;
#endif
};
/* Dummy touchkey code */
#define KEY_DUMMY_HOME1 249
#define KEY_DUMMY_HOME2 250
#define KEY_DUMMY_MENU 251
#define KEY_DUMMY_HOME 252
#define KEY_DUMMY_BACK 253
/*<= you must set key button mapping*/
#ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
u32 BUTTON_MAPPING_KEY[MAX_SUPPORTED_BUTTON_NUM] = {
KEY_APPSELECT, KEY_BACK};
#else
u32 BUTTON_MAPPING_KEY[MAX_SUPPORTED_BUTTON_NUM] = {
KEY_DUMMY_MENU, KEY_RECENT,// KEY_DUMMY_HOME1,
/*KEY_DUMMY_HOME2,*/ KEY_BACK, KEY_DUMMY_BACK};
#endif
static int cal_mode;
static int get_boot_mode(char *str)
{
get_option(&str, &cal_mode);
printk("get_boot_mode, uart_mode : %d\n", cal_mode);
return 1;
}
__setup("calmode=",get_boot_mode);
/* define i2c sub functions*/
static inline s32 read_data(struct i2c_client *client,
u16 reg, u8 *values, u16 length)
{
s32 ret;
int count = 0;
retry:
/* select register*/
ret = i2c_master_send(client , (u8 *)® , 2);
if (ret < 0) {
mdelay(1);
if (++count < 8)
goto retry;
return ret;
}
/* for setup tx transaction. */
udelay(DELAY_FOR_TRANSCATION);
ret = i2c_master_recv(client , values , length);
if (ret < 0)
return ret;
udelay(DELAY_FOR_POST_TRANSCATION);
return length;
}
static inline s32 write_data(struct i2c_client *client,
u16 reg, u8 *values, u16 length)
{
s32 ret;
int count = 0;
u8 pkt[10]; /* max packet */
pkt[0] = (reg) & 0xff; /* reg addr */
pkt[1] = (reg >> 8)&0xff;
memcpy((u8 *)&pkt[2], values, length);
retry:
ret = i2c_master_send(client , pkt , length + 2);
if (ret < 0) {
mdelay(1);
if (++count < 8)
goto retry;
printk(KERN_INFO "%s, count = %d\n", __func__, count);
return ret;
}
udelay(DELAY_FOR_POST_TRANSCATION);
return length;
}
static inline s32 write_reg(struct i2c_client *client, u16 reg, u16 value)
{
if (write_data(client, reg, (u8 *)&value, 2) < 0)
return I2C_FAIL;
return I2C_SUCCESS;
}
static inline s32 write_cmd(struct i2c_client *client, u16 reg)
{
s32 ret;
int count = 0;
retry:
ret = i2c_master_send(client , (u8 *)® , 2);
if (ret < 0) {
mdelay(1);
if (++count < 8)
goto retry;
return ret;
}
udelay(DELAY_FOR_POST_TRANSCATION);
return I2C_SUCCESS;
}
static inline s32 read_raw_data(struct i2c_client *client,
u16 reg, u8 *values, u16 length)
{
s32 ret;
int count = 0;
retry:
/* select register */
ret = i2c_master_send(client , (u8 *)® , 2);
if (ret < 0) {
mdelay(1);
if (++count < 8)
goto retry;
return ret;
}
/* for setup tx transaction. */
udelay(200);
ret = i2c_master_recv(client , values , length);
if (ret < 0)
return ret;
udelay(DELAY_FOR_POST_TRANSCATION);
return length;
}
static inline s32 read_firmware_data(struct i2c_client *client,
u16 addr, u8 *values, u16 length)
{
s32 ret;
/* select register*/
ret = i2c_master_send(client , (u8 *)&addr , 2);
if (ret < 0)
return ret;
/* for setup tx transaction. */
mdelay(1);
ret = i2c_master_recv(client , values , length);
if (ret < 0)
return ret;
udelay(DELAY_FOR_POST_TRANSCATION);
return length;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void bt541_ts_early_suspend(struct early_suspend *h);
static void bt541_ts_late_resume(struct early_suspend *h);
#endif
static bool bt541_power_control(struct bt541_ts_info *info, u8 ctl);
static int bt541_power(struct bt541_ts_info *info, int on);
static bool init_touch(struct bt541_ts_info *info, bool fw_oneshot_upgrade);
static bool mini_init_touch(struct bt541_ts_info *info);
static void clear_report_data(struct bt541_ts_info *info);
#if ESD_TIMER_INTERVAL
static void esd_timer_start(u16 sec, struct bt541_ts_info *info);
static void esd_timer_stop(struct bt541_ts_info *info);
static void esd_timer_init(struct bt541_ts_info *info);
static void esd_timeout_handler(unsigned long data);
#endif
static long ts_misc_fops_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg);
static int ts_misc_fops_open(struct inode *inode, struct file *filp);
static int ts_misc_fops_close(struct inode *inode, struct file *filp);
static const struct file_operations ts_misc_fops = {
.owner = THIS_MODULE,
.open = ts_misc_fops_open,
.release = ts_misc_fops_close,
.unlocked_ioctl = ts_misc_fops_ioctl,
.compat_ioctl = ts_misc_fops_ioctl,
};
static struct miscdevice touch_misc_device = {
.minor = MISC_DYNAMIC_MINOR,
.name = "zinitix_touch_misc",
.fops = &ts_misc_fops,
};
#define TOUCH_IOCTL_BASE 0xbc
#define TOUCH_IOCTL_GET_DEBUGMSG_STATE _IOW(TOUCH_IOCTL_BASE, 0, int)
#define TOUCH_IOCTL_SET_DEBUGMSG_STATE _IOW(TOUCH_IOCTL_BASE, 1, int)
#define TOUCH_IOCTL_GET_CHIP_REVISION _IOW(TOUCH_IOCTL_BASE, 2, int)
#define TOUCH_IOCTL_GET_FW_VERSION _IOW(TOUCH_IOCTL_BASE, 3, int)
#define TOUCH_IOCTL_GET_REG_DATA_VERSION _IOW(TOUCH_IOCTL_BASE, 4, int)
#define TOUCH_IOCTL_VARIFY_UPGRADE_SIZE _IOW(TOUCH_IOCTL_BASE, 5, int)
#define TOUCH_IOCTL_VARIFY_UPGRADE_DATA _IOW(TOUCH_IOCTL_BASE, 6, int)
#define TOUCH_IOCTL_START_UPGRADE _IOW(TOUCH_IOCTL_BASE, 7, int)
#define TOUCH_IOCTL_GET_X_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 8, int)
#define TOUCH_IOCTL_GET_Y_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 9, int)
#define TOUCH_IOCTL_GET_TOTAL_NODE_NUM _IOW(TOUCH_IOCTL_BASE, 10, int)
#define TOUCH_IOCTL_SET_RAW_DATA_MODE _IOW(TOUCH_IOCTL_BASE, 11, int)
#define TOUCH_IOCTL_GET_RAW_DATA _IOW(TOUCH_IOCTL_BASE, 12, int)
#define TOUCH_IOCTL_GET_X_RESOLUTION _IOW(TOUCH_IOCTL_BASE, 13, int)
#define TOUCH_IOCTL_GET_Y_RESOLUTION _IOW(TOUCH_IOCTL_BASE, 14, int)
#define TOUCH_IOCTL_HW_CALIBRAION _IOW(TOUCH_IOCTL_BASE, 15, int)
#define TOUCH_IOCTL_GET_REG _IOW(TOUCH_IOCTL_BASE, 16, int)
#define TOUCH_IOCTL_SET_REG _IOW(TOUCH_IOCTL_BASE, 17, int)
#define TOUCH_IOCTL_SEND_SAVE_STATUS _IOW(TOUCH_IOCTL_BASE, 18, int)
#define TOUCH_IOCTL_DONOT_TOUCH_EVENT _IOW(TOUCH_IOCTL_BASE, 19, int)
struct bt541_ts_info *misc_info;
#ifdef SUPPORTED_USE_DUAL_FW
static void bt541_firmware_check(void)
{
int i;
u16 newHWID;
for (i = 0; i < TSP_TYPE_COUNT; i++) {
newHWID = (u16) (m_pFirmware[i][0x57d2] | (m_pFirmware[i][0x57d3]<<8));
if (misc_info->cap_info.hw_id == newHWID) {
m_FirmwareIdx = i;
break;
}
}
if (i == TSP_TYPE_COUNT)
m_FirmwareIdx = 0;
m_firmware_data = m_pFirmware[m_FirmwareIdx];
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&misc_info->client->dev, "touch tsp type = %d, hw_id = %d\n", m_FirmwareIdx, misc_info->cap_info.hw_id);
#endif
}
#endif
static u16 m_optional_mode = 0;
static u16 m_prev_optional_mode = 0;
static void bt541_set_optional_mode(struct bt541_ts_info *info, bool force)
{
if (m_prev_optional_mode == m_optional_mode && !force)
return;
if (write_reg(info->client, BT541_OPTIONAL_SETTING, m_optional_mode) == I2C_SUCCESS) {
m_prev_optional_mode = m_optional_mode;
dev_info(&misc_info->client->dev, "TA setting changed to %d\n",
m_optional_mode&0x1);
}
}
static void bt541_set_ta_status(struct bt541_ts_info *info)
{
if (ta_connected)
zinitix_bit_set(m_optional_mode, 0);
else
zinitix_bit_clr(m_optional_mode, 0);
}
void tsp_charger_enable(int status)
{
if (status == POWER_SUPPLY_TYPE_BATTERY ||
status == POWER_SUPPLY_TYPE_UNKNOWN)
status = 0;
else
status = 1;
if (status)
ta_connected = true;
else
ta_connected = false;
bt541_set_ta_status(misc_info);
dev_info(&misc_info->client->dev, "TA %s\n",
status ? "connected" : "disconnected");
}
EXPORT_SYMBOL(tsp_charger_enable);
static bool get_raw_data(struct bt541_ts_info *info, u8 *buff, int skip_cnt)
{
struct i2c_client *client = info->client;
struct bt541_ts_platform_data *pdata = info->pdata;
u32 total_node = info->cap_info.total_node_num;
u32 sz;
int i;
disable_irq(info->irq);
down(&info->work_lock);
if (info->work_state != NOTHING) {
printk(KERN_INFO "other process occupied.. (%d)\n", info->work_state);
enable_irq(info->irq);
up(&info->work_lock);
return false;
}
info->work_state = RAW_DATA;
for (i = 0; i < skip_cnt; i++) {
while (gpio_get_value(pdata->gpio_int))
msleep(1);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
msleep(1);
}
zinitix_debug_msg("read raw data\r\n");
sz = total_node * 2;
while (gpio_get_value(pdata->gpio_int))
msleep(1);
if (read_raw_data(client, BT541_RAWDATA_REG, (char *)buff, sz) < 0) {
zinitix_printk("error : read zinitix tc raw data\n");
info->work_state = NOTHING;
enable_irq(info->irq);
up(&info->work_lock);
return false;
}
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
info->work_state = NOTHING;
enable_irq(info->irq);
up(&info->work_lock);
return true;
}
static bool ts_get_raw_data(struct bt541_ts_info *info)
{
struct i2c_client *client = info->client;
u32 total_node = info->cap_info.total_node_num;
u32 sz;
if (down_trylock(&info->raw_data_lock)) {
dev_err(&client->dev, "Failed to occupy sema\n");
info->touch_info.status = 0;
return true;
}
sz = total_node * 2 + sizeof(struct point_info);
if (read_raw_data(info->client, BT541_RAWDATA_REG,
(char *)info->cur_data, sz) < 0) {
dev_err(&client->dev, "Failed to read raw data\n");
up(&info->raw_data_lock);
return false;
}
info->update = 1;
memcpy((u8 *)(&info->touch_info),
(u8 *)&info->cur_data[total_node],
sizeof(struct point_info));
up(&info->raw_data_lock);
return true;
}
#if ZINITIX_I2C_CHECKSUM
#define ZINITIX_I2C_CHECKSUM_WCNT 0x016a
#define ZINITIX_I2C_CHECKSUM_RESULT 0x016c
static bool i2c_checksum(struct bt541_ts_info *info, s16 *pChecksum, u16 wlength)
{
s16 checksum_result;
s16 checksum_cur;
int i;
checksum_cur = 0;
for (i = 0; i < wlength; i++) {
checksum_cur += (s16)pChecksum[i];
}
if (read_data(info->client,
ZINITIX_I2C_CHECKSUM_RESULT,
(u8 *)(&checksum_result), 2) < 0) {
printk(KERN_INFO "error read i2c checksum rsult.-\n");
return false;
}
if (checksum_cur != checksum_result) {
printk(KERN_INFO "checksum error : %d, %d\n", checksum_cur, checksum_result);
return false;
}
return true;
}
#endif
static bool ts_read_coord(struct bt541_ts_info *info)
{
struct i2c_client *client = info->client;
#if (TOUCH_POINT_MODE == 1)
int i;
#endif
/* zinitix_debug_msg("ts_read_coord+\r\n"); */
/* for Debugging Tool */
if (info->touch_mode != TOUCH_POINT_MODE) {
if (info->update == 0) {
if (ts_get_raw_data(info) == false)
return false;
} else {
info->touch_info.status = 0;
}
dev_err(&client->dev, "status = 0x%04X\n", info->touch_info.status);
goto out;
}
#if (TOUCH_POINT_MODE == 1)
memset(&info->touch_info,
0x0, sizeof(struct point_info));
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if ((write_reg(info->client, ZINITIX_I2C_CHECKSUM_WCNT, 2)) != I2C_SUCCESS)
return false;
#endif
if (read_data(info->client, BT541_POINT_STATUS_REG, (u8 *)(&info->touch_info), 4) < 0) {
dev_err(&client->dev, "%s: Failed to read point info\n", __func__);
return false;
}
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if (i2c_checksum(info, (s16 *)(&info->touch_info), 2) == false)
return false;
#endif
dev_info(&client->dev, "status reg = 0x%x , event_flag = 0x%04x\n",
info->touch_info.status, info->touch_info.event_flag);
bt541_set_optional_mode(info, false);
if (info->touch_info.event_flag == 0)
goto out;
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if ((write_reg(info->client, ZINITIX_I2C_CHECKSUM_WCNT, sizeof(struct point_info)/2)) != I2C_SUCCESS)
return false;
#endif
for (i = 0; i < info->cap_info.multi_fingers; i++) {
if (zinitix_bit_test(info->touch_info.event_flag, i)) {
udelay(20);
if (read_data(info->client, BT541_POINT_STATUS_REG + 2 + ( i * 4),
(u8 *)(&info->touch_info.coord[i]),
sizeof(struct coord)) < 0) {
dev_err(&client->dev, "Failed to read point info\n");
return false;
}
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if (i2c_checksum(info, (s16 *)(&info->touch_info.coord[i]), sizeof(struct point_info)/2) == false)
return false;
#endif
}
}
#else
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if (write_reg(info->client,
ZINITIX_I2C_CHECKSUM_WCNT,
(sizeof(struct point_info)/2)) != I2C_SUCCESS) {
dev_err(&client->dev, "error write checksum wcnt.-\n");
return false;
}
#endif
if (read_data(info->client, BT541_POINT_STATUS_REG,
(u8 *)(&info->touch_info), sizeof(struct point_info)) < 0) {
dev_err(&client->dev, "Failed to read point info\n");
return false;
}
#if ZINITIX_I2C_CHECKSUM
if (info->cap_info.i2s_checksum)
if (i2c_checksum(info, (s16 *)(&info->touch_info), sizeof(struct point_info)/2) == false)
return false;
#endif
bt541_set_optional_mode(info, false);
#endif
out:
/* error */
if (zinitix_bit_test(info->touch_info.status, BIT_MUST_ZERO)) {
dev_err(&client->dev, "Invalid must zero bit(%04x)\n",
info->touch_info.status);
return false;
}
write_cmd(info->client, BT541_CLEAR_INT_STATUS_CMD);
return true;
}
#if ESD_TIMER_INTERVAL
static void esd_timeout_handler(unsigned long data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)data;
info->p_esd_timeout_tmr = NULL;
queue_work(esd_tmr_workqueue, &info->tmr_work);
}
static void esd_timer_start(u16 sec, struct bt541_ts_info *info)
{
unsigned long flags;
spin_lock_irqsave(&info->lock,flags);
if (info->p_esd_timeout_tmr != NULL)
#ifdef CONFIG_SMP
del_singleshot_timer_sync(info->p_esd_timeout_tmr);
#else
del_timer(info->p_esd_timeout_tmr);
#endif
info->p_esd_timeout_tmr = NULL;
init_timer(&(info->esd_timeout_tmr));
info->esd_timeout_tmr.data = (unsigned long)(info);
info->esd_timeout_tmr.function = esd_timeout_handler;
info->esd_timeout_tmr.expires = jiffies + (HZ * sec);
info->p_esd_timeout_tmr = &info->esd_timeout_tmr;
add_timer(&info->esd_timeout_tmr);
spin_unlock_irqrestore(&info->lock, flags);
}
static void esd_timer_stop(struct bt541_ts_info *info)
{
unsigned long flags;
spin_lock_irqsave(&info->lock,flags);
if (info->p_esd_timeout_tmr)
#ifdef CONFIG_SMP
del_singleshot_timer_sync(info->p_esd_timeout_tmr);
#else
del_timer(info->p_esd_timeout_tmr);
#endif
info->p_esd_timeout_tmr = NULL;
spin_unlock_irqrestore(&info->lock, flags);
}
static void esd_timer_init(struct bt541_ts_info *info)
{
unsigned long flags;
spin_lock_irqsave(&info->lock,flags);
init_timer(&(info->esd_timeout_tmr));
info->esd_timeout_tmr.data = (unsigned long)(info);
info->esd_timeout_tmr.function = esd_timeout_handler;
info->p_esd_timeout_tmr = NULL;
spin_unlock_irqrestore(&info->lock, flags);
}
static void ts_tmr_work(struct work_struct *work)
{
struct bt541_ts_info *info =
container_of(work, struct bt541_ts_info, tmr_work);
struct i2c_client *client = info->client;
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "tmr queue work ++\n");
#endif
if (down_trylock(&info->work_lock)) {
dev_err(&client->dev, "%s: Failed to occupy work lock\n", __func__);
esd_timer_start(CHECK_ESD_TIMER, info);
return;
}
if (info->work_state != NOTHING) {
dev_info(&client->dev, "%s: Other process occupied (%d)\n",
__func__, info->work_state);
up(&info->work_lock);
return;
}
info->work_state = ESD_TIMER;
disable_irq(info->irq);
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
clear_report_data(info);
if (mini_init_touch(info) == false)
goto fail_time_out_init;
info->work_state = NOTHING;
enable_irq(info->irq);
up(&info->work_lock);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "tmr queue work--\n");
#endif
return;
fail_time_out_init:
dev_err(&client->dev, "%s: Failed to restart\n", __func__);
esd_timer_start(CHECK_ESD_TIMER, info);
info->work_state = NOTHING;
enable_irq(info->irq);
up(&info->work_lock);
return;
}
#endif
static bool bt541_power_sequence(struct bt541_ts_info *info)
{
struct i2c_client *client = info->client;
int retry = 0;
u16 chip_code;
retry_power_sequence:
if (write_reg(client, 0xc000, 0x0001) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to send power sequence(vendor cmd enable)\n");
goto fail_power_sequence;
}
udelay(10);
if (read_data(client, 0xcc00, (u8 *)&chip_code, 2) < 0) {
dev_err(&client->dev, "Failed to read chip code\n");
goto fail_power_sequence;
}
dev_info(&client->dev, "%s: chip code = 0x%x\n", __func__, chip_code);
udelay(10);
if (write_cmd(client, 0xc004) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to send power sequence(intn clear)\n");
goto fail_power_sequence;
}
udelay(10);
if (write_reg(client, 0xc002, 0x0001) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to send power sequence(nvm init)\n");
goto fail_power_sequence;
}
mdelay(2);
if (write_reg(client, 0xc001, 0x0001) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to send power sequence(program start)\n");
goto fail_power_sequence;
}
msleep(FIRMWARE_ON_DELAY); /* wait for checksum cal */
return true;
fail_power_sequence:
if (retry++ < 3) {
msleep(CHIP_ON_DELAY);
dev_info(&client->dev, "retry = %d\n", retry);
goto retry_power_sequence;
}
dev_err(&client->dev, "Failed to send power sequence\n");
return false;
}
static struct regulator *touch_regulator;
static int bt541_power(struct bt541_ts_info *info, int on)
{
int ret = 0;
static u8 is_power_on;
if (touch_regulator == NULL) {
touch_regulator = regulator_get(&info->client->dev, "vddsim2");
if (IS_ERR(touch_regulator)) {
touch_regulator = NULL;
pr_info("[TSP]: %s: get touch_regulator error\n",
__func__);
return -EIO;
}
}
if (on == 0) {
if (is_power_on) {
is_power_on = 0;
ret = regulator_disable(touch_regulator);
if (ret) {
is_power_on = 1;
pr_err("[TSP]: %s: touch_regulator disable " \
"failed (%d)\n", __func__, ret);
return -EIO;
}
mdelay(CHIP_OFF_DELAY);
}
} else {
if (!is_power_on) {
is_power_on = 1;
regulator_set_voltage(touch_regulator, 3000000, 3000000);
ret = regulator_enable(touch_regulator);
if (ret) {
is_power_on = 0;
pr_err("[TSP]: %s: touch_regulator enable "\
"failed (%d)\n", __func__, ret);
return -EIO;
}
}
}
pr_info("[TSP]: %s, expected power[%d], actural power[%d]\n",
__func__, on, is_power_on);
return 0;
}
static bool bt541_power_control(struct bt541_ts_info *info, u8 ctl)
{
int ret=0;
pr_info("[TSP] %s, %d\n", __func__, ctl);
if (info->pdata->tsp_supply_type == TSP_REGULATOR_SUPPLY) {
ret = info->pdata->tsp_power(info, ctl);
if (ret)
return false;
if (ctl == POWER_ON_SEQUENCE) {
msleep(CHIP_ON_DELAY);
return bt541_power_sequence(info);
}
}
else
{
if (ctl == POWER_OFF) {
gpio_direction_output(info->pdata->gpio_ldo_en, 0);
msleep(CHIP_OFF_DELAY);
} else {
gpio_direction_output(info->pdata->gpio_ldo_en, 1);
/* zxt power on sequence */
if (ctl == POWER_ON_SEQUENCE) {
msleep(CHIP_ON_DELAY);
return bt541_power_sequence(info);
}
}
}
return true;
}
#if TOUCH_ONESHOT_UPGRADE
static bool ts_check_need_upgrade(struct bt541_ts_info *info,
u16 cur_version, u16 cur_minor_version, u16 cur_reg_version, u16 cur_hw_id)
{
u16 new_version;
u16 new_minor_version;
u16 new_reg_version;
/* u16 new_chip_code;*/
#if CHECK_HWID
u16 new_hw_id;
#endif
new_version = (u16) (m_firmware_data[52] | (m_firmware_data[53]<<8));
new_minor_version = (u16) (m_firmware_data[56] | (m_firmware_data[57]<<8));
new_reg_version = (u16) (m_firmware_data[60] | (m_firmware_data[61]<<8));
/* new_chip_code = (u16) (m_firmware_data[64] | (m_firmware_data[65]<<8));*/
#if CHECK_HWID
new_hw_id = (u16)(m_firmware_data[0x7528] | (m_firmware_data[0x7529]<<8));
dev_info(&info->client->dev, "cur HW_ID = 0x%x, new HW_ID = 0x%x\n",
cur_hw_id, new_hw_id);
#endif
dev_info(&info->client->dev, "cur version = 0x%x, new version = 0x%x\n",
cur_version, new_version);
dev_info(&info->client->dev, "cur minor version = 0x%x, new minor version = 0x%x\n",
cur_minor_version, new_minor_version);
dev_info(&info->client->dev, "cur reg data version = 0x%x, new reg data version = 0x%x\n",
cur_reg_version, new_reg_version);
if (cal_mode) {
dev_info(&info->client->dev, "didn't update TSP F/W!! in CAL MODE\n");
return false;
}
if (cur_version > 0xFF)
return true;
if (cur_version < new_version)
return true;
else if (cur_version > new_version)
return false;
#if CHECK_HWID
if (cur_hw_id != new_hw_id)
return true;
#endif
if (cur_minor_version < new_minor_version)
return true;
else if (cur_minor_version > new_minor_version)
return false;
if (cur_reg_version < new_reg_version)
return true;
return false;
}
#endif
#define TC_SECTOR_SZ 8
#ifdef SUPPORTED_USE_DUAL_FW
static void ts_check_hwid_in_fatal_state(struct bt541_ts_info *info)
{
/*u16 flash_addr;*/
u8 check_data[80];
int i;
u16 hw_id0, hw_id1_1, hw_id1_2;
int retry = 0;
retry_fatal:
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON);
mdelay(10);
if (write_reg(info->client, 0xc000, 0x0001) != I2C_SUCCESS) {
dev_err(&info->client->dev, "power sequence error (vendor cmd enable)\n");
goto fail_check_hwid;
}
udelay(10);
if (write_cmd(info->client, 0xc004) != I2C_SUCCESS) {
dev_err(&info->client->dev, "power sequence error (intn clear)\n");
goto fail_check_hwid;
}
udelay(10);
if (write_reg(info->client, 0xc002, 0x0001) != I2C_SUCCESS) {
dev_err(&info->client->dev, "power sequence error (nvm init)\n");
goto fail_check_hwid;
}
/*dev_err(&info->client->dev, "init flash\n");*/
mdelay(5);
if (write_reg(info->client, 0xc003, 0x0000) != I2C_SUCCESS) {
dev_err(&info->client->dev, "fail to write nvm vpp on\n");
goto fail_check_hwid;
}
if (write_reg(info->client, 0xc104, 0x0000) != I2C_SUCCESS) {
dev_err(&info->client->dev, "fail to write nvm wp disable\n");
goto fail_check_hwid;
}
/*dev_err(&info->client->dev, "init flash\n");*/
if (write_cmd(info->client, BT541_INIT_FLASH) != I2C_SUCCESS) {
dev_err(&info->client->dev, "failed to init flash\n");
goto fail_check_hwid;
}
/*dev_err(&info->client->dev, "read firmware data\n");*/
for (i = 0; i < 80; i += TC_SECTOR_SZ) {
if (read_firmware_data(info->client,
BT541_READ_FLASH,
(u8 *)&check_data[i], TC_SECTOR_SZ) < 0) {
dev_err(&info->client->dev, "error : read zinitix tc firmare\n");
goto fail_check_hwid;
}
}
hw_id0 = check_data[48] + check_data[49]*256;
hw_id1_1 = check_data[70];
hw_id1_2 = check_data[71];
/*dev_err(&info->client->dev, "eeprom hw id = %d, %d, %d\n", hw_id0, hw_id1_1, hw_id1_2);*/
if (hw_id1_1 == hw_id1_2 && hw_id0 != hw_id1_1)
info->cap_info.hw_id = hw_id1_1;
else
info->cap_info.hw_id = hw_id0;
dev_err(&info->client->dev, "hw id = %d\n", info->cap_info.hw_id);
mdelay(5);
return;
fail_check_hwid:
if (retry++ < 3)
goto retry_fatal;
dev_err(&info->client->dev, "fail to check hw id\n");
mdelay(5);
}
#endif
static u8 ts_upgrade_firmware(struct bt541_ts_info *info,
const u8 *firmware_data, u32 size)
{
struct i2c_client *client = info->client;
u16 flash_addr;
u16 reg_val;
u8 *verify_data;
int retry_cnt = 0;
int i;
int page_sz = 0;
u16 chip_code;
verify_data = kzalloc(size, GFP_KERNEL);
if (verify_data == NULL) {
zinitix_printk(KERN_ERR "cannot alloc verify buffer\n");
return false;
}
#ifdef SUPPORTED_USE_DUAL_FW
if (read_data(client, BT541_MODULE_ID, (u8 *)&cap->module_id, 2) < 0)
dev_err(&client->dev, "Failed to read Modul ID\n");
#endif
retry_upgrade:
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON);
mdelay(10);
if (write_reg(client, 0xc000, 0x0001) != I2C_SUCCESS) {
zinitix_printk("power sequence error (vendor cmd enable)\n");
goto fail_upgrade;
}
udelay(10);
if (read_data(client, 0xcc00, (u8 *)&chip_code, 2) < 0) {
zinitix_printk("failed to read chip code\n");
goto fail_upgrade;
}
zinitix_printk("chip code = 0x%x\n", chip_code);
page_sz = 128;
udelay(10);
if (write_cmd(client, 0xc004) != I2C_SUCCESS) {
zinitix_printk("power sequence error (intn clear)\n");
goto fail_upgrade;
}
udelay(10);
if (write_reg(client, 0xc002, 0x0001) != I2C_SUCCESS) {
zinitix_printk("power sequence error (nvm init)\n");
goto fail_upgrade;
}
mdelay(5);
zinitix_printk(KERN_INFO "init flash\n");
if (write_reg(client, 0xc003, 0x0001) != I2C_SUCCESS) {
zinitix_printk("failed to write nvm vpp on\n");
goto fail_upgrade;
}
if (write_reg(client, 0xc104, 0x0001) != I2C_SUCCESS) {
zinitix_printk("failed to write nvm wp disable\n");
goto fail_upgrade;
}
if (write_cmd(client, BT541_INIT_FLASH) != I2C_SUCCESS) {
zinitix_printk(KERN_INFO "failed to init flash\n");
goto fail_upgrade;
}
zinitix_printk(KERN_INFO "writing firmware data\n");
for (flash_addr = 0; flash_addr < size; ) {
for (i = 0; i < page_sz / TC_SECTOR_SZ; i++) {
/*zinitix_debug_msg("write :addr=%04x, len=%d\n", flash_addr, TC_SECTOR_SZ);*/
/*zinitix_printk(KERN_INFO "writing :addr = %04x, len=%d \n", flash_addr, TC_SECTOR_SZ);*/
if (write_data(client,
BT541_WRITE_FLASH,
(u8 *)&firmware_data[flash_addr], TC_SECTOR_SZ) < 0) {
zinitix_printk(KERN_INFO"error : write zinitix tc firmare\n");
goto fail_upgrade;
}
flash_addr += TC_SECTOR_SZ;
udelay(100);
}
mdelay(30); /*for fuzing delay*/
}
if (write_reg(client, 0xc003, 0x0000) != I2C_SUCCESS) {
zinitix_printk("nvm write vpp off\n");
goto fail_upgrade;
}
if (write_reg(client, 0xc104, 0x0000) != I2C_SUCCESS) {
zinitix_printk("nvm wp enable\n");
goto fail_upgrade;
}
zinitix_printk(KERN_INFO "init flash\n");
if (write_cmd(client, BT541_INIT_FLASH) != I2C_SUCCESS) {
zinitix_printk(KERN_INFO "failed to init flash\n");
goto fail_upgrade;
}
zinitix_printk(KERN_INFO "read firmware data\n");
for (flash_addr = 0; flash_addr < size; ) {
for (i = 0; i < page_sz / TC_SECTOR_SZ; i++) {
/*zinitix_debug_msg("read :addr=%04x, len=%d\n",flash_addr, TC_SECTOR_SZ);*/
if (read_firmware_data(client,
BT541_READ_FLASH,
(u8 *)&verify_data[flash_addr], TC_SECTOR_SZ) < 0) {
dev_err(&client->dev, "Failed to read firmare\n");
goto fail_upgrade;
}
flash_addr += TC_SECTOR_SZ;
}
}
/* verify */
dev_info(&client->dev, "verify firmware data\n");
if (memcmp((u8 *)&firmware_data[0], (u8 *)&verify_data[0], size) == 0) {
dev_info(&client->dev, "upgrade finished\n");
kfree(verify_data);
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
for (i = 0; i < 5; i++) {
if (read_data(client, BT541_CHECKSUM_RESULT,
(u8 *)®_val, 2) < 0) {
mdelay(10);
continue;
}
}
if (reg_val != 0x55aa) {
dev_err(&client->dev, "upgrade done, but firmware checksum fail. reg_val = %x\n", reg_val);
goto fail_upgrade;
}
#ifdef SUPPORTED_USE_DUAL_FW
if (read_data(client, BT541_MODULE_ID, (u8 *)®_val, 2) < 0)
dev_err(&client->dev, "Failed to read Modul ID\n");
else {
if (cap->module_id != reg_val) {
write_reg(client, BT541_MODULE_ID, cap->module_id);
write_reg(client, 0xc003, 0x0001);
write_reg(client, 0xc104, 0x0001);
udelay(100);
if (write_cmd(client, BT541_SAVE_STATUS_CMD) != I2C_SUCCESS)
goto fail_upgrade;
mdelay(1000);
write_reg(client, 0xc003, 0x0000);
write_reg(client, 0xc104, 0x0000);
}
}
#endif
return true;
}
fail_upgrade:
bt541_power_control(info, POWER_OFF);
if (retry_cnt++ < INIT_RETRY_CNT) {
dev_err(&client->dev, "upgrade failed : so retry... (%d)\n", retry_cnt);
goto retry_upgrade;
}
if (verify_data != NULL)
kfree(verify_data);
dev_info(&client->dev, "Failed to upgrade\n");
return false;
}
static bool ts_hw_calibration(struct bt541_ts_info *info)
{
struct i2c_client *client = info->client;
u16 chip_eeprom_info;
int time_out = 0;
if (write_reg(client,
BT541_TOUCH_MODE, 0x07) != I2C_SUCCESS)
return false;
mdelay(10);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
mdelay(10);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
mdelay(50);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
mdelay(10);
if (write_cmd(client,
BT541_CALIBRATE_CMD) != I2C_SUCCESS)
return false;
if (write_cmd(client,
BT541_CLEAR_INT_STATUS_CMD) != I2C_SUCCESS)
return false;
mdelay(10);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
/* wait for h/w calibration*/
do {
mdelay(500);
write_cmd(client,
BT541_CLEAR_INT_STATUS_CMD);
if (read_data(client,
BT541_EEPROM_INFO_REG,
(u8 *)&chip_eeprom_info, 2) < 0)
return false;
zinitix_debug_msg("touch eeprom info = 0x%04X\r\n",
chip_eeprom_info);
if (!zinitix_bit_test(chip_eeprom_info, 0))
break;
if (time_out++ == 4) {
write_cmd(client, BT541_CALIBRATE_CMD);
mdelay(10);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
dev_err(&client->dev, "h/w calibration retry timeout.\n");
}
if (time_out++ > 10) {
dev_err(&client->dev, "h/w calibration timeout.\n");
break;
}
} while (1);
if (write_reg(client,
BT541_TOUCH_MODE, TOUCH_POINT_MODE) != I2C_SUCCESS)
return false;
if (info->cap_info.ic_int_mask != 0) {
if (write_reg(client,
BT541_INT_ENABLE_FLAG,
info->cap_info.ic_int_mask)
!= I2C_SUCCESS)
return false;
}
write_reg(client, 0xc003, 0x0001);
write_reg(client, 0xc104, 0x0001);
udelay(100);
if (write_cmd(client,
BT541_SAVE_CALIBRATION_CMD) != I2C_SUCCESS)
return false;
mdelay(1000);
write_reg(client, 0xc003, 0x0000);
write_reg(client, 0xc104, 0x0000);
return true;
}
static bool init_touch(struct bt541_ts_info *info, bool fw_oneshot_upgrade)
{
struct bt541_ts_platform_data *pdata = info->pdata;
struct i2c_client *client = info->client;
struct capa_info *cap = &(info->cap_info);
u16 reg_val;
int i;
u16 chip_eeprom_info;
#if USE_CHECKSUM
u16 chip_check_sum;
u8 checksum_err;
#endif
int retry_cnt = 0;
retry_init:
for (i = 0; i < INIT_RETRY_CNT; i++) {
if (read_data(client, BT541_EEPROM_INFO_REG,
(u8 *)&chip_eeprom_info, 2) < 0) {
dev_err(&client->dev, "Failed to read eeprom info(%d)\n", i);
mdelay(10);
continue;
} else
break;
}
if (i == INIT_RETRY_CNT)
goto fail_init;
#if USE_CHECKSUM
dev_info(&client->dev, "%s: Check checksum\n", __func__);
checksum_err = 0;
for (i = 0; i < INIT_RETRY_CNT; i++) {
if (read_data(client, BT541_CHECKSUM_RESULT,
(u8 *)&chip_check_sum, 2) < 0) {
mdelay(10);
continue;
}
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "0x%04X\n", chip_check_sum);
#endif
if (chip_check_sum == 0x55aa)
break;
else {
checksum_err = 1;
break;
}
}
if (i == INIT_RETRY_CNT || checksum_err) {
dev_err(&client->dev, "Failed to check firmware data\n");
if (checksum_err == 1 && retry_cnt < INIT_RETRY_CNT)
retry_cnt = INIT_RETRY_CNT;
goto fail_init;
}
#endif
if (write_cmd(client, BT541_SWRESET_CMD) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to write reset command\n");
goto fail_init;
}
cap->button_num = SUPPORTED_BUTTON_NUM;
reg_val = 0;
zinitix_bit_set(reg_val, BIT_PT_CNT_CHANGE);
zinitix_bit_set(reg_val, BIT_DOWN);
zinitix_bit_set(reg_val, BIT_MOVE);
zinitix_bit_set(reg_val, BIT_UP);
#if (TOUCH_POINT_MODE == 2)
zinitix_bit_set(reg_val, BIT_PALM);
zinitix_bit_set(reg_val, BIT_PALM_REJECT);
#endif
if (cap->button_num > 0)
zinitix_bit_set(reg_val, BIT_ICON_EVENT);
cap->ic_int_mask = reg_val;
if (write_reg(client, BT541_INT_ENABLE_FLAG, 0x0) != I2C_SUCCESS)
goto fail_init;
dev_info(&client->dev, "%s: Send reset command\n", __func__);
if (write_cmd(client, BT541_SWRESET_CMD) != I2C_SUCCESS)
goto fail_init;
/* get chip information */
if (read_data(client, BT541_VENDOR_ID,
(u8 *)&cap->vendor_id, 2) < 0) {
zinitix_printk("failed to read chip revision\n");
goto fail_init;
}
if (read_data(client, BT541_CHIP_REVISION,
(u8 *)&cap->ic_revision, 2) < 0) {
zinitix_printk("failed to read chip revision\n");
goto fail_init;
}
cap->ic_fw_size = 32*1024;
if (read_data(client, BT541_HW_ID, (u8 *)&cap->hw_id, 2) < 0) {
dev_err(&client->dev, "Failed to read hw id\n");
goto fail_init;
}
#ifdef SUPPORTED_USE_DUAL_FW
bt541_firmware_check();
#endif
if (read_data(client, BT541_THRESHOLD, (u8 *)&cap->threshold, 2) < 0)
goto fail_init;
if (read_data(client, BT541_BUTTON_SENSITIVITY,
(u8 *)&cap->key_threshold, 2) < 0)
goto fail_init;
/* if (read_data(client, BT541_DUMMY_BUTTON_SENSITIVITY,
(u8 *)&cap->dummy_threshold, 2) < 0)
goto fail_init;*/
if (read_data(client, BT541_TOTAL_NUMBER_OF_X,
(u8 *)&cap->x_node_num, 2) < 0)
goto fail_init;
if (read_data(client, BT541_TOTAL_NUMBER_OF_Y,
(u8 *)&cap->y_node_num, 2) < 0)
goto fail_init;
cap->total_node_num = cap->x_node_num * cap->y_node_num;
if (read_data(client, BT541_SHIFT_VALUE,
(u8 *)&cap->shift_value, 2) < 0)
goto fail_init;
zinitix_debug_msg("Shift value = %d\n", cap->shift_value);
if (read_data(client, BT541_DND_N_COUNT,
(u8 *)&cap->N_cnt, 2) < 0)
goto fail_init;
zinitix_debug_msg("N count = %d\n", cap->N_cnt);
if (read_data(client, BT541_DND_U_COUNT,
(u8 *)&cap->U_cnt, 2) < 0)
goto fail_init;
zinitix_debug_msg("u count = %d\n", cap->U_cnt);
if (read_data(client, BT541_AFE_FREQUENCY,
(u8 *)&cap->afe_frequency, 2) < 0)
goto fail_init;
zinitix_debug_msg("afe frequency = %d\n", cap->afe_frequency);
/* get chip firmware version */
if (read_data(client, BT541_FIRMWARE_VERSION,
(u8 *)&cap->fw_version, 2) < 0)
goto fail_init;
if (read_data(client, BT541_MINOR_FW_VERSION,
(u8 *)&cap->fw_minor_version, 2) < 0)
goto fail_init;
if (read_data(client, BT541_DATA_VERSION_REG,
(u8 *)&cap->reg_data_version, 2) < 0)
goto fail_init;
#if TOUCH_ONESHOT_UPGRADE
if (fw_oneshot_upgrade && (ts_check_need_upgrade(info, cap->fw_version,
cap->fw_minor_version, cap->reg_data_version,
cap->hw_id) == true)) {
zinitix_printk("start upgrade firmware\n");
if (ts_upgrade_firmware(info, m_firmware_data,
cap->ic_fw_size) == false)
goto fail_init;
if (ts_hw_calibration(info) == false)
goto fail_init;
/* disable chip interrupt */
if (write_reg(client, BT541_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
goto fail_init;
/* get chip firmware version */
if (read_data(client, BT541_FIRMWARE_VERSION,
(u8 *)&cap->fw_version, 2) < 0)
goto fail_init;
if (read_data(client, BT541_MINOR_FW_VERSION,
(u8 *)&cap->fw_minor_version, 2) < 0)
goto fail_init;
if (read_data(client, BT541_DATA_VERSION_REG,
(u8 *)&cap->reg_data_version, 2) < 0)
goto fail_init;
#ifdef SUPPORTED_USE_DUAL_FW
if (read_data(client, BT541_HW_ID,
(u8 *)&cap->hw_id, 2) < 0)
goto fail_init;
bt541_firmware_check();
if (read_data(client, BT541_VENDOR_ID,
(u8 *)&cap->vendor_id, 2) < 0)
goto fail_init;
#endif
}
#endif
if (read_data(client, BT541_EEPROM_INFO_REG,
(u8 *)&chip_eeprom_info, 2) < 0)
goto fail_init;
if (zinitix_bit_test(chip_eeprom_info, 0)) { /* hw calibration bit*/
if (ts_hw_calibration(info) == false)
goto fail_init;
/* disable chip interrupt */
if (write_reg(client, BT541_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
goto fail_init;
}
/* initialize */
if (write_reg(client, BT541_X_RESOLUTION,
(u16)pdata->x_resolution) != I2C_SUCCESS)
goto fail_init;
if (write_reg(client, BT541_Y_RESOLUTION,
(u16)pdata->y_resolution) != I2C_SUCCESS)
goto fail_init;
cap->MinX = (u32)0;
cap->MinY = (u32)0;
cap->MaxX = (u32)pdata->x_resolution;
cap->MaxY = (u32)pdata->y_resolution;
if (write_reg(client, BT541_BUTTON_SUPPORTED_NUM,
(u16)cap->button_num) != I2C_SUCCESS)
goto fail_init;
if (write_reg(client, BT541_SUPPORTED_FINGER_NUM,
(u16)MAX_SUPPORTED_FINGER_NUM) != I2C_SUCCESS)
goto fail_init;
cap->multi_fingers = MAX_SUPPORTED_FINGER_NUM;
zinitix_debug_msg("max supported finger num = %d\r\n",
cap->multi_fingers);
cap->gesture_support = 0;
zinitix_debug_msg("set other configuration\r\n");
if (write_reg(client, BT541_INITIAL_TOUCH_MODE,
TOUCH_POINT_MODE) != I2C_SUCCESS)
goto fail_init;
if (write_reg(client, BT541_TOUCH_MODE, info->touch_mode) != I2C_SUCCESS)
goto fail_init;
#if ZINITIX_I2C_CHECKSUM
if (read_data(client, ZINITIX_INTERNAL_FLAG_02,
(u8 *)®_val, 2) < 0)
goto fail_init;
cap->i2s_checksum = !(!zinitix_bit_test(reg_val, 15));
printk("use i2s checksum = %d\r\n",
cap->i2s_checksum);
#endif
bt541_set_ta_status(info);
bt541_set_optional_mode(info, true);
/* soft calibration */
/* if (write_cmd(client, BT541_CALIBRATE_CMD) != I2C_SUCCESS)
goto fail_init;*/
if (write_reg(client, BT541_INT_ENABLE_FLAG,
cap->ic_int_mask) != I2C_SUCCESS)
goto fail_init;
/* read garbage data */
for (i = 0; i < 10; i++) {
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
udelay(10);
}
if (info->touch_mode != TOUCH_POINT_MODE) { /* Test Mode */
if (write_reg(client, BT541_DELAY_RAW_FOR_HOST,
RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS) {
dev_err(&client->dev, "%s: Failed to set DELAY_RAW_FOR_HOST\n",
__func__);
goto fail_init;
}
}
#if ESD_TIMER_INTERVAL
if (write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL,
SCAN_RATE_HZ * ESD_TIMER_INTERVAL) != I2C_SUCCESS)
goto fail_init;
read_data(client, BT541_PERIODICAL_INTERRUPT_INTERVAL, (u8 *)®_val, 2);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Esd timer register = %d\n", reg_val);
#endif
#endif
tsp_charger_status_cb = tsp_charger_enable;
zinitix_debug_msg("successfully initialized\r\n");
return true;
fail_init:
if (cal_mode) {
dev_err(&client->dev,"didn't update TSP F/W!! in CAL MODE\n");
return false;
}
if (++retry_cnt <= INIT_RETRY_CNT) {
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
zinitix_debug_msg("retry to initiallize(retry cnt = %d)\r\n",
retry_cnt);
goto retry_init;
} else if (retry_cnt == INIT_RETRY_CNT+1) {
cap->ic_fw_size = 32*1024;
zinitix_debug_msg("retry to initiallize(retry cnt = %d)\r\n", retry_cnt);
#if TOUCH_FORCE_UPGRADE
#ifdef SUPPORTED_USE_DUAL_FW
ts_check_hwid_in_fatal_state(info);
bt541_firmware_check();
#endif
if (ts_upgrade_firmware(info, m_firmware_data,
cap->ic_fw_size) == false) {
zinitix_printk("upgrade failed\n");
return false;
}
mdelay(100);
/* hw calibration and make checksum */
if (ts_hw_calibration(info) == false) {
zinitix_printk("failed to initiallize\r\n");
return false;
}
goto retry_init;
#endif
}
dev_err(&client->dev, "Failed to initiallize\n");
return false;
}
static bool mini_init_touch(struct bt541_ts_info *info)
{
struct bt541_ts_platform_data *pdata = info->pdata;
struct i2c_client *client = info->client;
int i;
#if USE_CHECKSUM
u16 chip_check_sum;
/*dev_info(&client->dev, "check checksum\n");*/
if (read_data(client, BT541_CHECKSUM_RESULT,
(u8 *)&chip_check_sum, 2) < 0)
goto fail_mini_init;
if (chip_check_sum != 0x55aa) {
dev_err(&client->dev, "Failed to check firmware"
" checksum(0x%04x)\n", chip_check_sum);
goto fail_mini_init;
}
#endif
if (write_cmd(client, BT541_SWRESET_CMD) != I2C_SUCCESS) {
dev_info(&client->dev, "Failed to write reset command\n");
goto fail_mini_init;
}
/* initialize */
if (write_reg(client, BT541_X_RESOLUTION,
(u16)(pdata->x_resolution)) != I2C_SUCCESS)
goto fail_mini_init;
if (write_reg(client,BT541_Y_RESOLUTION,
(u16)(pdata->y_resolution)) != I2C_SUCCESS)
goto fail_mini_init;
/*dev_info(&client->dev, "touch max x = %d\r\n", pdata->x_resolution);
dev_info(&client->dev, "touch max y = %d\r\n", pdata->y_resolution);*/
if (write_reg(client, BT541_BUTTON_SUPPORTED_NUM,
(u16)info->cap_info.button_num) != I2C_SUCCESS)
goto fail_mini_init;
if (write_reg(client, BT541_SUPPORTED_FINGER_NUM,
(u16)MAX_SUPPORTED_FINGER_NUM) != I2C_SUCCESS)
goto fail_mini_init;
if (write_reg(client, BT541_INITIAL_TOUCH_MODE,
TOUCH_POINT_MODE) != I2C_SUCCESS)
goto fail_mini_init;
if (write_reg(client, BT541_TOUCH_MODE,
info->touch_mode) != I2C_SUCCESS)
goto fail_mini_init;
bt541_set_ta_status(info);
bt541_set_optional_mode(info, true);
/* soft calibration */
if (write_cmd(client, BT541_CALIBRATE_CMD) != I2C_SUCCESS)
goto fail_mini_init;
if (write_reg(client, BT541_INT_ENABLE_FLAG,
info->cap_info.ic_int_mask) != I2C_SUCCESS)
goto fail_mini_init;
/* read garbage data */
for (i = 0; i < 10; i++) {
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
udelay(10);
}
if (info->touch_mode != TOUCH_POINT_MODE) {
if (write_reg(client, BT541_DELAY_RAW_FOR_HOST,
RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS) {
dev_err(&client->dev, "Failed to set BT541_DELAY_RAW_FOR_HOST\n");
goto fail_mini_init;
}
}
#if ESD_TIMER_INTERVAL
if (write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL,
SCAN_RATE_HZ * ESD_TIMER_INTERVAL) != I2C_SUCCESS)
goto fail_mini_init;
esd_timer_start(CHECK_ESD_TIMER, info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Started esd timer\n");
#endif
#endif
dev_info(&client->dev, "Successfully mini initialized\r\n");
return true;
fail_mini_init:
dev_err(&client->dev, "Failed to initialize mini init\n");
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
if (init_touch(info, true) == false) {
dev_err(&client->dev, "Failed to initialize\n");
return false;
}
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Started esd timer\n");
#endif
#endif
return true;
}
static void clear_report_data(struct bt541_ts_info *info)
{
int i;
u8 reported = 0;
u8 sub_status;
for (i = 0; i < info->cap_info.button_num; i++) {
if (info->button[i] == ICON_BUTTON_DOWN) {
info->button[i] = ICON_BUTTON_UP;
input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 0);
reported = true;
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
printk(KERN_INFO "Button up = %d\n", i);
#else
printk(KERN_INFO "Button up\n");
#endif
}
}
for (i = 0; i < info->cap_info.multi_fingers; i++) {
sub_status = info->reported_touch_info.coord[i].sub_status;
if (zinitix_bit_test(sub_status, SUB_BIT_EXIST)) {
input_mt_slot(info->input_dev, i);
input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 0);
reported = true;
if (!m_ts_debug_mode && TSP_NORMAL_EVENT_MSG)
printk(KERN_INFO "[TSP] R %02d\r\n", i);
}
info->reported_touch_info.coord[i].sub_status = 0;
}
if (reported)
input_sync(info->input_dev);
}
#define PALM_REPORT_WIDTH 200
#define PALM_REJECT_WIDTH 255
static irqreturn_t bt541_touch_work(int irq, void *data)
{
struct bt541_ts_info* info = (struct bt541_ts_info*)data;
struct bt541_ts_platform_data *pdata = info->pdata;
struct i2c_client *client = info->client;
int i;
u8 sub_status;
u8 prev_sub_status;
u32 x, y, maxX, maxY;
u32 w;
u32 tmp;
u8 palm = 0;
if (gpio_get_value(info->pdata->gpio_int)) {
dev_err(&client->dev, "Invalid interrupt\n");
return IRQ_HANDLED;
}
if (down_trylock(&info->work_lock)) {
dev_err(&client->dev, "%s: Failed to occupy work lock\n", __func__);
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
return IRQ_HANDLED;
}
#if ESD_TIMER_INTERVAL
esd_timer_stop(info);
#endif
if (info->work_state != NOTHING) {
dev_err(&client->dev, "%s: Other process occupied\n", __func__);
udelay(DELAY_FOR_SIGNAL_DELAY);
if (!gpio_get_value(info->pdata->gpio_int)) {
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
udelay(DELAY_FOR_SIGNAL_DELAY);
}
goto out;
}
info->work_state = NORMAL;
#if ZINITIX_I2C_CHECKSUM
i = 0;
if (ts_read_coord(info) == false || info->touch_info.status == 0xffff
|| info->touch_info.status == 0x1) {
/* more retry*/
for (i = 1; i < 50; i++) { /* about 10ms*/
if (!(ts_read_coord(info) == false || info->touch_info.status == 0xffff
|| info->touch_info.status == 0x1))
break;
}
}
if (i == 50) {
dev_err(&client->dev, "Failed to read info coord\n");
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
clear_report_data(info);
mini_init_touch(info);
goto out;
}
#else
if (ts_read_coord(info) == false || info->touch_info.status == 0xffff
|| info->touch_info.status == 0x1) { /* maybe desirable reset */
dev_err(&client->dev, "Failed to read info coord\n");
bt541_power_control(info, POWER_OFF);
bt541_power_control(info, POWER_ON_SEQUENCE);
clear_report_data(info);
mini_init_touch(info);
goto out;
}
#endif
/* invalid : maybe periodical repeated int. */
if (info->touch_info.status == 0x0)
goto out;
if (zinitix_bit_test(info->touch_info.status, BIT_ICON_EVENT)) {
if (read_data(info->client, BT541_ICON_STATUS_REG,
(u8 *)(&info->icon_event_reg), 2) < 0) {
dev_err(&client->dev, "Failed to read button info\n");
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
goto out;
}
for (i = 0; i < info->cap_info.button_num; i++) {
if (zinitix_bit_test(info->icon_event_reg,
(BIT_O_ICON0_DOWN + i))) {
info->button[i] = ICON_BUTTON_DOWN;
input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 1);
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Button down = %d\n", i);
#else
dev_info(&client->dev, "Button down\n");
#endif
}
}
for (i = 0; i < info->cap_info.button_num; i++) {
if (zinitix_bit_test(info->icon_event_reg,
(BIT_O_ICON0_UP + i))) {
info->button[i] = ICON_BUTTON_UP;
input_report_key(info->input_dev, BUTTON_MAPPING_KEY[i], 0);
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Button up = %d\n", i);
#else
dev_info(&client->dev, "Button up\n");
#endif
}
}
}
#ifdef SUPPORTED_PALM_TOUCH
if (zinitix_bit_test(info->touch_info.status, BIT_PALM)) {
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Palm report\n");
#endif
palm = 1;
}
if (zinitix_bit_test(info->touch_info.status, BIT_PALM_REJECT)) {
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Palm reject\n");
#endif
palm = 2;
}
#endif
for (i = 0; i < info->cap_info.multi_fingers; i++) {
sub_status = info->touch_info.coord[i].sub_status;
prev_sub_status = info->reported_touch_info.coord[i].sub_status;
if (zinitix_bit_test(sub_status, SUB_BIT_EXIST)) {
x = info->touch_info.coord[i].x;
y = info->touch_info.coord[i].y;
w = info->touch_info.coord[i].width;
/* transformation from touch to screen orientation */
if (pdata->orientation & TOUCH_V_FLIP)
y = info->cap_info.MaxY
+ info->cap_info.MinY - y;
if (pdata->orientation & TOUCH_H_FLIP)
x = info->cap_info.MaxX
+ info->cap_info.MinX - x;
maxX = info->cap_info.MaxX;
maxY = info->cap_info.MaxY;
if (pdata->orientation & TOUCH_XY_SWAP) {
zinitix_swap_v(x, y, tmp);
zinitix_swap_v(maxX, maxY, tmp);
}
if (x > maxX || y > maxY) {
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_err(&client->dev,
"Invalid coord %d : x=%d, y=%d\n", i, x, y);
#endif
continue;
}
info->touch_info.coord[i].x = x;
info->touch_info.coord[i].y = y;
if (zinitix_bit_test(sub_status, SUB_BIT_DOWN))
{
#if TOUCH_BOOSTER
if (!min_handle)
{
min_handle = cpufreq_limit_min_freq(touch_cpufreq_lock, "TSP");
if (IS_ERR(min_handle)) {
printk(KERN_ERR "[TSP] cannot get cpufreq_min lock %lu(%ld)\n",
touch_cpufreq_lock, PTR_ERR(min_handle));
min_handle = NULL;
}
_store_cpu_num_min_limit(2);
dev_info(&client->dev, "cpu freq on\n");
}
info->finger_cnt++;
#endif
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Finger [%02d] x = %d, y = %d,"
" w = %d\n", i, x, y, w);
#else
dev_info(&client->dev, "Finger down\n");
#endif
}
if (w == 0)
w = 1;
input_mt_slot(info->input_dev, i);
input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 1);
#if (TOUCH_POINT_MODE == 2)
if (palm == 0) {
if (w >= PALM_REPORT_WIDTH)
w = PALM_REPORT_WIDTH - 10;
} else if (palm == 1) { /*palm report*/
w = PALM_REPORT_WIDTH;
/* info->touch_info.coord[i].minor_width = PALM_REPORT_WIDTH;*/
} else if (palm == 2) { /* palm reject*/
/* x = y = 0;*/
w = PALM_REJECT_WIDTH;
/* info->touch_info.coord[i].minor_width = PALM_REJECT_WIDTH;*/
}
#endif
input_report_abs(info->input_dev, ABS_MT_TOUCH_MAJOR, (u32)w);
input_report_abs(info->input_dev, ABS_MT_PRESSURE, (u32)w);
input_report_abs(info->input_dev, ABS_MT_WIDTH_MAJOR,
(u32)((palm == 1) ? w-40 : w));
#if (TOUCH_POINT_MODE == 2)
input_report_abs(info->input_dev,
ABS_MT_TOUCH_MINOR, (u32)info->touch_info.coord[i].minor_width);
/* input_report_abs(info->input_dev,
ABS_MT_WIDTH_MINOR, (u32)info->touch_info.coord[i].minor_width);*/
#ifdef SUPPORTED_PALM_TOUCH
/*input_report_abs(info->input_dev, ABS_MT_ANGLE,
(palm > 1)?70:info->touch_info.coord[i].angle - 90);*/
/*dev_info(&client->dev, "finger [%02d] angle = %03d\n", i,
info->touch_info.coord[i].angle);*/
input_report_abs(info->input_dev, ABS_MT_PALM, (palm > 0)?1:0);
#endif
/* input_report_abs(info->input_dev, ABS_MT_PALM, 1);*/
#endif
input_report_abs(info->input_dev, ABS_MT_POSITION_X, x);
input_report_abs(info->input_dev, ABS_MT_POSITION_Y, y);
} else if (zinitix_bit_test(sub_status, SUB_BIT_UP)||
zinitix_bit_test(prev_sub_status, SUB_BIT_EXIST)) {
#if TOUCH_BOOSTER
info->finger_cnt--;
if (!info->finger_cnt)
{
cpufreq_limit_put(min_handle);
min_handle = NULL;
_store_cpu_num_min_limit(1);
dev_info(&client->dev, "cpu freq off\n");
}
#endif
#if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
dev_info(&client->dev, "Finger [%02d] up\n", i);
#else
dev_info(&client->dev, "Finger up\n");
#endif
memset(&info->touch_info.coord[i], 0x0, sizeof(struct coord));
input_mt_slot(info->input_dev, i);
input_mt_report_slot_state(info->input_dev, MT_TOOL_FINGER, 0);
} else {
memset(&info->touch_info.coord[i], 0x0, sizeof(struct coord));
}
}
memcpy((char *)&info->reported_touch_info, (char *)&info->touch_info,
sizeof(struct point_info));
input_sync(info->input_dev);
out:
if (info->work_state == NORMAL) {
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, info);
#endif
info->work_state = NOTHING;
}
up(&info->work_lock);
return IRQ_HANDLED;
}
#ifdef CONFIG_HAS_EARLYSUSPEND
static void bt541_ts_late_resume(struct early_suspend *h)
{
struct bt541_ts_info *info = misc_info;
//info = container_of(h, struct bt541_ts_info, early_suspend);
struct capa_info *cap = &(info->cap_info);
if (info == NULL)
return;
zinitix_printk("late resume++\r\n");
down(&info->work_lock);
if (info->work_state != RESUME
&& info->work_state != EALRY_SUSPEND) {
zinitix_printk("invalid work proceedure (%d)\r\n",
info->work_state);
up(&info->work_lock);
return;
}
#if 0
write_cmd(info->client, BT541_WAKEUP_CMD);
mdelay(1);
#else
bt541_power_control(info, POWER_ON_SEQUENCE);
#endif
info->work_state = RESUME;
if (mini_init_touch(info) == false)
goto fail_late_resume;
if (read_data(info->client, BT541_FIRMWARE_VERSION, (u8 *)&cap->fw_version, 2))
;
if (read_data(info->client, BT541_MINOR_FW_VERSION, (u8 *)&cap->fw_minor_version, 2))
;
if (read_data(info->client, BT541_DATA_VERSION_REG, (u8 *)&cap->reg_data_version, 2))
;
if (read_data(info->client, BT541_HW_ID, (u8 *)&cap->hw_id, 2))
;
if (read_data(info->client, BT541_VENDOR_ID, (u8 *)&cap->vendor_id, 2))
;
#ifdef SUPPORTED_USE_DUAL_FW
bt541_firmware_check();
#endif
enable_irq(info->irq);
info->work_state = NOTHING;
up(&info->work_lock);
zinitix_printk("late resume--\n");
return;
fail_late_resume:
zinitix_printk("failed to late resume\n");
enable_irq(info->irq);
info->work_state = NOTHING;
up(&info->work_lock);
return;
}
static void bt541_ts_early_suspend(struct early_suspend *h)
{
struct bt541_ts_info *info = misc_info;
/*info = container_of(h, struct bt541_ts_info, early_suspend);*/
if (info == NULL)
return;
zinitix_printk("early suspend++\n");
disable_irq(info->irq);
#if ESD_TIMER_INTERVAL
flush_work(&info->tmr_work);
#endif
down(&info->work_lock);
if (info->work_state != NOTHING) {
zinitix_printk("invalid work proceedure (%d)\r\n",
info->work_state);
up(&info->work_lock);
enable_irq(info->irq);
return;
}
info->work_state = EALRY_SUSPEND;
zinitix_debug_msg("clear all reported points\r\n");
clear_report_data(info);
#if ESD_TIMER_INTERVAL
/*write_reg(info->client, BT541_PERIODICAL_INTERRUPT_INTERVAL, 0);*/
esd_timer_stop(info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&info->client->dev, "Stopped esd timer\n");
#endif
#endif
#if 0
write_reg(info->client, BT541_INT_ENABLE_FLAG, 0x0);
udelay(100);
if (write_cmd(info->client, BT541_SLEEP_CMD) != I2C_SUCCESS) {
zinitix_printk("failed to enter into sleep mode\n");
up(&info->work_lock);
return;
}
#else
bt541_power_control(info, POWER_OFF);
#endif
#if TOUCH_BOOSTER
if (min_handle)
{
dev_err(&info->client->dev,"[TSP] %s %d:: OOPs, Cpu was not in Normal Freq..\n", __func__, __LINE__);
if (cpufreq_limit_put(min_handle) < 0) {
dev_err(&info->client->dev, "[TSP] Error in scaling down cpu frequency\n");
}
min_handle = NULL;
info->finger_cnt = 0;
dev_info(&info->client->dev, "cpu freq off\n");
}
#endif
zinitix_printk("early suspend--\n");
up(&info->work_lock);
return;
}
#endif /* CONFIG_HAS_EARLYSUSPEND */
#if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND)
static int bt541_ts_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct bt541_ts_info *info = i2c_get_clientdata(client);
struct capa_info *cap = &(info->cap_info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "resume++\n");
#endif
down(&info->work_lock);
if (info->work_state != SUSPEND) {
dev_err(&client->dev, "%s: Invalid work proceedure (%d)\n",
__func__, info->work_state);
up(&info->work_lock);
return 0;
}
bt541_power_control(info, POWER_ON_SEQUENCE);
#ifdef CONFIG_HAS_EARLYSUSPEND
info->work_state = RESUME;
#else
info->work_state = NOTHING;
if (mini_init_touch(info) == false)
dev_err(&client->dev, "Failed to resume\n");
if (read_data(client, BT541_FIRMWARE_VERSION, (u8 *)&cap->fw_version, 2))
;
if (read_data(client, BT541_MINOR_FW_VERSION, (u8 *)&cap->fw_minor_version, 2))
;
if (read_data(client, BT541_DATA_VERSION_REG, (u8 *)&cap->reg_data_version, 2))
;
if (read_data(client, BT541_HW_ID, (u8 *)&cap->hw_id, 2))
;
if (read_data(client, BT541_VENDOR_ID, (u8 *)&cap->vendor_id, 2))
;
#ifdef SUPPORTED_USE_DUAL_FW
bt541_firmware_check();
#endif
if (!gpio_get_value(info->pdata->gpio_int))
{
write_cmd(info->client, BT541_CLEAR_INT_STATUS_CMD);
udelay(50);
write_cmd(info->client, BT541_CLEAR_INT_STATUS_CMD);
udelay(50);
write_cmd(info->client, BT541_CLEAR_INT_STATUS_CMD);
}
info->work_state = NOTHING;
#endif
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "resume--\n");
#endif
up(&info->work_lock);
enable_irq(info->irq);
return 0;
}
static int bt541_ts_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct bt541_ts_info *info = i2c_get_clientdata(client);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "suspend++\n");
#endif
#ifndef CONFIG_HAS_EARLYSUSPEND
disable_irq(info->irq);
#endif
#if ESD_TIMER_INTERVAL
flush_work(&info->tmr_work);
#endif
down(&info->work_lock);
if (info->work_state != NOTHING
&& info->work_state != SUSPEND) {
dev_err(&client->dev,"%s: Invalid work proceedure (%d)\n",
__func__, info->work_state);
up(&info->work_lock);
#ifndef CONFIG_HAS_EARLYSUSPEND
enable_irq(info->irq);
#endif
return 0;
}
#ifndef CONFIG_HAS_EARLYSUSPEND
clear_report_data(info);
#if ESD_TIMER_INTERVAL
esd_timer_stop(info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Stopped esd timer\n");
#endif
#endif
#endif
write_cmd(info->client, BT541_SLEEP_CMD);
bt541_power_control(info, POWER_OFF);
info->work_state = SUSPEND;
#if defined(TSP_VERBOSE_DEBUG)
zinitix_printk("suspend--\n");
#endif
up(&info->work_lock);
return 0;
}
#endif
static bool ts_set_touchmode(u16 value)
{
int i;
disable_irq(misc_info->irq);
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
printk(KERN_INFO "other process occupied.. (%d)\n",
misc_info->work_state);
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
if (value == TOUCH_DND_MODE) {
if (write_reg(misc_info->client, BT541_DND_N_COUNT,
SEC_DND_N_COUNT) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set DND_N_COUNT\n");
if (write_reg(misc_info->client, BT541_DND_U_COUNT,
SEC_DND_U_COUNT) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set DND_U_COUNT\n");
if (write_reg(misc_info->client, BT541_AFE_FREQUENCY,
SEC_DND_FREQUENCY) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set AFE_FREQUENCY\n");
} else if (misc_info->touch_mode == TOUCH_DND_MODE) {
if (write_reg(misc_info->client, BT541_AFE_FREQUENCY,
misc_info->cap_info.afe_frequency) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set AFE_FREQUENCY\n");
if (write_reg(misc_info->client, BT541_DND_U_COUNT,
misc_info->cap_info.U_cnt) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set U_COUNT\n");
if (write_reg(misc_info->client, BT541_SHIFT_VALUE,
misc_info->cap_info.shift_value) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set Shift\n");
}
if (value == TOUCH_SEC_MODE)
misc_info->touch_mode = TOUCH_POINT_MODE;
else
misc_info->touch_mode = value;
printk(KERN_INFO "[zinitix_touch] tsp_set_testmode, "
"touchkey_testmode = %d\r\n", misc_info->touch_mode);
if (misc_info->touch_mode != TOUCH_POINT_MODE) {
if (write_reg(misc_info->client, BT541_DELAY_RAW_FOR_HOST,
RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS)
zinitix_printk("Fail to set BT541_DELAY_RAW_FOR_HOST.\r\n");
}
if (write_reg(misc_info->client, BT541_TOUCH_MODE,
misc_info->touch_mode) != I2C_SUCCESS)
printk(KERN_INFO "[zinitix_touch] TEST Mode : "
"Fail to set ZINITX_TOUCH_MODE %d.\r\n", misc_info->touch_mode);
/* clear garbage data */
for (i = 0; i < 10; i++) {
mdelay(20);
write_cmd(misc_info->client, BT541_CLEAR_INT_STATUS_CMD);
}
misc_info->work_state = NOTHING;
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
return 1;
}
static bool ts_set_touchmode2(u16 value)
{
int i;
disable_irq(misc_info->irq);
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
printk(KERN_INFO "other process occupied.. (%d)\n",
misc_info->work_state);
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
if (value == TOUCH_DND_MODE) {
if (write_reg(misc_info->client, BT541_DND_N_COUNT,
SEC_HFDND_N_COUNT) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set DND_N_COUNT\n");
if (write_reg(misc_info->client, BT541_DND_U_COUNT,
SEC_HFDND_U_COUNT) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set DND_U_COUNT\n");
if (write_reg(misc_info->client, BT541_AFE_FREQUENCY,
SEC_HFDND_FREQUENCY) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set AFE_FREQUENCY\n");
} else {
if (write_reg(misc_info->client, BT541_AFE_FREQUENCY,
misc_info->cap_info.afe_frequency) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set AFE_FREQUENCY\n");
if (write_reg(misc_info->client, BT541_DND_U_COUNT,
misc_info->cap_info.U_cnt) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set U_COUNT\n");
if (write_reg(misc_info->client, BT541_SHIFT_VALUE,
misc_info->cap_info.shift_value) != I2C_SUCCESS)
dev_err(&misc_info->client->dev, "Failed to set Shift\n");
}
if (value == TOUCH_SEC_MODE)
misc_info->touch_mode = TOUCH_POINT_MODE;
else
misc_info->touch_mode = value;
printk(KERN_INFO "[zinitix_touch] tsp_set_testmode, "
"touchkey_testmode = %d\r\n", misc_info->touch_mode);
if (misc_info->touch_mode != TOUCH_POINT_MODE) {
if (write_reg(misc_info->client, BT541_DELAY_RAW_FOR_HOST,
RAWDATA_DELAY_FOR_HOST) != I2C_SUCCESS)
zinitix_printk("Fail to set BT541_DELAY_RAW_FOR_HOST.\r\n");
}
if (write_reg(misc_info->client, BT541_TOUCH_MODE,
misc_info->touch_mode) != I2C_SUCCESS)
printk(KERN_INFO "[zinitix_touch] TEST Mode : "
"Fail to set ZINITX_TOUCH_MODE %d.\r\n", misc_info->touch_mode);
/* clear garbage data */
for (i = 0; i < 10; i++) {
mdelay(20);
write_cmd(misc_info->client, BT541_CLEAR_INT_STATUS_CMD);
}
misc_info->work_state = NOTHING;
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
return 1;
}
static int ts_upgrade_sequence(const u8 *firmware_data)
{
disable_irq(misc_info->irq);
down(&misc_info->work_lock);
misc_info->work_state = UPGRADE;
#if ESD_TIMER_INTERVAL
esd_timer_stop(misc_info);
#endif
zinitix_debug_msg("clear all reported points\r\n");
clear_report_data(misc_info);
printk(KERN_INFO "start upgrade firmware\n");
if (ts_upgrade_firmware(misc_info,
firmware_data,
misc_info->cap_info.ic_fw_size) == false) {
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return -1;
}
if (init_touch(misc_info, false) == false) {
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return -1;
}
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, misc_info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&misc_info->client->dev, "Started esd timer\n");
#endif
#endif
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return 0;
}
#ifdef SEC_FACTORY_TEST
static inline void set_cmd_result(struct bt541_ts_info *info, char *buff, int len)
{
strncat(info->factory_info->cmd_result, buff, len);
}
static inline void set_default_result(struct bt541_ts_info *info)
{
char delim = ':';
memset(info->factory_info->cmd_result, 0x00, ARRAY_SIZE(info->factory_info->cmd_result));
memcpy(info->factory_info->cmd_result, info->factory_info->cmd, strlen(info->factory_info->cmd));
strncat(info->factory_info->cmd_result, &delim, 1);
}
#define MAX_FW_PATH 255
#define TSP_FW_FILENAME "zinitix_fw.bin"
static void fw_update(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
int ret = 0;
const u8 *buff = 0;
mm_segment_t old_fs = {0};
struct file *fp = NULL;
long fsize = 0, nread = 0;
char fw_path[MAX_FW_PATH+1];
char result[16] = {0};
set_default_result(info);
switch (info->factory_info->cmd_param[0]) {
case BUILT_IN:
ret = ts_upgrade_sequence((u8 *)m_firmware_data);
if (ret < 0) {
info->factory_info->cmd_state = 3;
return;
}
break;
case UMS:
old_fs = get_fs();
set_fs(get_ds());
snprintf(fw_path, MAX_FW_PATH, "/sdcard/%s", TSP_FW_FILENAME);
fp = filp_open(fw_path, O_RDONLY, 0);
if (IS_ERR(fp)) {
dev_err(&client->dev,
"file %s open error:%lu\n", fw_path, (unsigned long)fp);
info->factory_info->cmd_state = 3;
goto err_open;
}
fsize = fp->f_path.dentry->d_inode->i_size;
if (fsize != info->cap_info.ic_fw_size) {
dev_err(&client->dev, "invalid fw size!!\n");
info->factory_info->cmd_state = 3;
goto err_open;
}
buff = kzalloc((size_t)fsize, GFP_KERNEL);
if (!buff) {
dev_err(&client->dev, "failed to alloc buffer for fw\n");
info->factory_info->cmd_state = 3;
goto err_alloc;
}
nread = vfs_read(fp, (char __user *)buff, fsize, &fp->f_pos);
if (nread != fsize) {
info->factory_info->cmd_state = 3;
goto err_fw_size;
}
filp_close(fp, current->files);
set_fs(old_fs);
dev_info(&client->dev, "ums fw is loaded!!\n");
ret = ts_upgrade_sequence((u8 *)buff);
if (ret < 0) {
kfree(buff);
info->factory_info->cmd_state = 3;
goto update_fail;
}
break;
default:
dev_err(&client->dev, "invalid fw file type!!\n");
goto update_fail;
}
info->factory_info->cmd_state = 2;
snprintf(result, sizeof(result) , "%s", "OK");
set_cmd_result(info, result,
strnlen(result, sizeof(result)));
kfree(buff);
return;
if (fp != NULL) {
err_fw_size:
kfree(buff);
err_alloc:
filp_close(fp, NULL);
err_open:
set_fs(old_fs);
}
update_fail:
snprintf(result, sizeof(result) , "%s", "NG");
set_cmd_result(info, result, strnlen(result, sizeof(result)));
}
static void get_fw_ver_bin(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
u16 fw_version, fw_minor_version, reg_version, hw_id, vendor_id;
u32 version, length;
set_default_result(info);
/* To Do */
/* modify m_firmware_data */
fw_version = (u16)(m_firmware_data[52] | (m_firmware_data[53] << 8));
fw_minor_version = (u16)(m_firmware_data[56] | (m_firmware_data[57] << 8));
reg_version = (u16)(m_firmware_data[60] | (m_firmware_data[61] << 8));
hw_id = (u16)(m_firmware_data[0x7528] | (m_firmware_data[0x7529]<<8));
/* vendor_id = ntohs(*(u16 *)&m_firmware_data[0x57e2]);*/
version = (u32)((u32)(hw_id & 0xff) << 16) | ((fw_version & 0xf ) << 12)
| ((fw_minor_version & 0xf) << 8) | (reg_version & 0xff);
/* length = sizeof(vendor_id);
snprintf(finfo->cmd_buff, length + 1, "%s", (u8 *)&vendor_id);
snprintf(finfo->cmd_buff + length, sizeof(finfo->cmd_buff) - length,
"%06X", version);*/
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void get_fw_ver_ic(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
u16 fw_version, fw_minor_version, reg_version, hw_id, vendor_id;
u32 version, length;
set_default_result(info);
fw_version = info->cap_info.fw_version;
fw_minor_version = info->cap_info.fw_minor_version;
reg_version = info->cap_info.reg_data_version;
hw_id = info->cap_info.hw_id;
/* vendor_id = ntohs(info->cap_info.vendor_id);*/
version = (u32)((u32)(hw_id & 0xff) << 16) | ((fw_version & 0xf) << 12)
| ((fw_minor_version & 0xf) << 8) | (reg_version & 0xff);
/* length = sizeof(vendor_id);
snprintf(finfo->cmd_buff, length + 1, "%s", (u8 *)&vendor_id);
snprintf(finfo->cmd_buff + length, sizeof(finfo->cmd_buff) - length,
"%06X", version);*/
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void get_threshold(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
"%d", info->cap_info.threshold);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
/*
static void get_key_threshold(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
int ret = 0;
u16 threshold;
set_default_result(info);
ret = read_data(misc_info->client, BT541_BUTTON_SENSITIVITY, (u8 *)&threshold, 2);
if (ret < 0) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "fail");
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
return;
}
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", threshold);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
*/
static void module_off_master(void *device_data)
{
return;
}
static void module_on_master(void *device_data)
{
return;
}
static void module_off_slave(void *device_data)
{
return;
}
static void module_on_slave(void *device_data)
{
return;
}
#define BT541_VENDOR_NAME "ZINITIX"
static void get_chip_vendor(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
"%s", BT541_VENDOR_NAME);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
#define BT541_CHIP_NAME "BT541"
static void get_chip_name(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", BT541_CHIP_NAME);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
#ifdef SUPPORTED_USE_DUAL_FW
static void get_module_vendor(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
int module_vendor =0;
set_default_result(info);
switch (info->cap_info.hw_id) {
case 0:
module_vendor = 0;
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s,%d", "OK", module_vendor);
break;
case 1:
module_vendor = 1;
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s,%d", "OK", module_vendor);
break;
default:
break;
}
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
#endif
static void get_x_num(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
"%u", info->cap_info.x_node_num);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void get_y_num(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff),
"%u", info->cap_info.y_node_num);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void not_support_cmd(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
sprintf(finfo->cmd_buff, "%s", "NA");
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
info->factory_info->cmd_state = NOT_APPLICABLE;
dev_info(&client->dev, "%s: \"%s(%d)\"\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
#if 0
static void run_reference_read(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
u16 min, max;
s32 i,j;
#if ESD_TIMER_INTERVAL
esd_timer_stop(misc_info);
#endif
set_default_result(info);
ts_set_touchmode(TOUCH_DND_MODE);
get_raw_data(info, (u8 *)raw_data->ref_data, 10);
ts_set_touchmode(TOUCH_POINT_MODE);
min = 0xFFFF;
max = 0x0000;
for (i = 0; i < info->cap_info.x_node_num; i++)
{
for (j = 0; j < info->cap_info.y_node_num; j++)
{
/*pr_info("ref_data : %d ",
raw_data->ref_data[i * info->cap_info.y_node_num + j]);*/
if (raw_data->ref_data[i * info->cap_info.y_node_num + j] < min &&
raw_data->ref_data[i * info->cap_info.y_node_num + j] != 0)
min = raw_data->ref_data[i * info->cap_info.y_node_num + j];
if (raw_data->ref_data[i * info->cap_info.y_node_num + j] > max)
max = raw_data->ref_data[i * info->cap_info.y_node_num + j];
}
/*pr_info("\n");*/
}
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
(int)strlen(finfo->cmd_buff));
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, misc_info);
#endif
return;
}
#endif
static bool run_reference_DND_read(void *device_data, int button0, int button1) //DND
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
int i, j, nButton;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
int buttons[2] = {button0,button1};
bool result = true, item_result= true;
#if ESD_TIMER_INTERVAL
esd_timer_stop(misc_info);
#endif
set_default_result(info);
ts_set_touchmode(TOUCH_DND_MODE);
get_raw_data(info, (u8 *)info->pdnd_data, 5);
ts_set_touchmode(TOUCH_POINT_MODE);
printk("DND_data =\n");
for (i = 0; i < x_num; i++) {
for (j = 0; j < y_num; j++) {
printk("%d ", info->pdnd_data[j+i*y_num]);
}
printk("\n");
}
info->dnd_max_x = info->dnd_max_y = info->dnd_min_x = info->dnd_min_y = 0;
info->dnd_max_val = -32768;
info->dnd_min_val = 32767;
info->dnd_real_max_val = -32768;
info->dnd_real_min_val = 32767;
info->dnd_node_num = -1;
for (i = 0; i < x_num-1; i++) {
for (j = 0; j < y_num; j++) {
if (info->dnd_real_min_val > info->pdnd_data[j+i*y_num]) {
info->dnd_real_min_x = i;
info->dnd_real_min_y = j;
info->dnd_real_min_val = info->pdnd_data[j+i*y_num];
}
if (info->dnd_real_max_val < info->pdnd_data[j+i*y_num]) {
info->dnd_real_max_x = i;
info->dnd_real_max_y = j;
info->dnd_real_max_val = info->pdnd_data[j+i*y_num];
}
if ((info->pdnd_data[j+i*y_num] < pdnd_min[i][j]) && (info->pdnd_data[j+i*y_num] != 0)) {
printk(" DND View Min fail : NODE = %u, Raw data = %d, SPEC = %u\n", j+i*y_num, info->pdnd_data[j+i*y_num], pdnd_min[i][j]);
item_result = false;
result = false;
if (info->dnd_node_num == -1)
info->dnd_node_num = j + (i * y_num);
}
if (info->dnd_min_val > info->pdnd_data[j+i*y_num] - pdnd_min[i][j]) {
info->dnd_min_x = i;
info->dnd_min_y = j;
info->dnd_min_val = info->pdnd_data[j+i*y_num] - pdnd_min[i][j];
}
if (info->pdnd_data[j+i*y_num] > pdnd_max[i][j]) {
printk(" DND View Max fail : NODE = %u, Raw data = %d, SPEC = %u\n", j+i*y_num, info->pdnd_data[j+i*y_num], pdnd_max[i][j]);
item_result = false;
result = false;
if (info->dnd_node_num == -1)
info->dnd_node_num = j + (i * y_num);
}
if (info->dnd_max_val < info->pdnd_data[j+i*y_num] - pdnd_max[i][j]) {
info->dnd_max_x = i;
info->dnd_max_y = j;
info->dnd_max_val = info->pdnd_data[j+i*y_num] - pdnd_max[i][j];
}
}
}
if (item_result)
printk("DND View pass\n");
else
printk("DND View fail\n");
/*button*/
item_result = true;
if (info->cap_info.button_num) {
for (i = 0; i < 2; i++) {
nButton = buttons[i];
if (nButton < 0)
continue;
if (info->dnd_real_min_val > info->pdnd_data[(x_num-1)*y_num+nButton]) {
info->dnd_real_min_x = x_num-1;
info->dnd_real_min_y = nButton;
info->dnd_real_min_val = info->pdnd_data[(x_num-1)*y_num+nButton];
}
if (info->dnd_real_max_val < info->pdnd_data[(x_num-1)*y_num+nButton]) {
info->dnd_real_max_x = x_num-1;
info->dnd_real_max_y = nButton;
info->dnd_real_max_val = info->pdnd_data[(x_num-1)*y_num+nButton];
}
if (info->pdnd_data[(x_num-1)*y_num+nButton] < pdnd_min[x_num-1][nButton]) {
printk(" DND Button Min fail : NODE = %u, Raw data = %d, SPEC = %u\n", nButton, info->pdnd_data[(x_num-1)*y_num+nButton], pdnd_min[x_num-1][nButton]);
item_result = false;
result = false;
if (info->dnd_node_num == -1)
info->dnd_node_num = ((x_num - 1) * y_num) + nButton;
}
if (info->dnd_min_val > info->pdnd_data[(x_num-1)*y_num+nButton] - pdnd_min[x_num-1][nButton]) {
info->dnd_min_x = x_num-1;
info->dnd_min_y = nButton;
info->dnd_min_val = info->pdnd_data[(x_num-1)*y_num+nButton] - pdnd_min[x_num-1][nButton];
}
if (info->pdnd_data[(x_num-1)*y_num+nButton] > pdnd_max[x_num-1][nButton]) {
printk(" DND Button Max fail : NODE = %u, Raw data = %d, SPEC = %u\n", nButton, info->pdnd_data[(x_num-1)*y_num+nButton], pdnd_max[x_num-1][nButton]);
item_result = false;
result = false;
if (info->dnd_node_num == -1)
info->dnd_node_num = ((x_num - 1) * y_num) + nButton;
}
if (info->dnd_max_val < info->pdnd_data[(x_num-1)*y_num+nButton] - pdnd_max[x_num-1][nButton]) {
info->dnd_max_x = x_num-1;
info->dnd_max_y = nButton;
info->dnd_max_val = info->pdnd_data[(x_num-1)*y_num+nButton] - pdnd_max[x_num-1][nButton];
}
}
}
if (item_result) {
info->dnd_done = true;
printk("DND Button pass\n");
} else {
info->dnd_done = false;
printk("DND Butoon fail\n");
}
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, misc_info);
#endif
return result;
}
static void run_reference_DND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
bool temp;
set_default_result(info);
temp = run_reference_DND_read(device_data, 4, 7);
if (temp) {
pr_info("DND pass\n");
sprintf(finfo->cmd_buff, "OK\n");
} else {
int x, y, node_num;
node_num = info->dnd_node_num;
x = node_num / info->cap_info.y_node_num;
y = node_num % info->cap_info.y_node_num;
pr_info("DND Fail\n");
sprintf(finfo->cmd_buff, "%d,%d,%d,%d\n",
node_num,
pdnd_min[x][y],
pdnd_max[x][y],
info->pdnd_data[node_num]);
}
finfo->cmd_state = OK;
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
static bool run_reference_HFDND_read(void *device_data, int button0, int button1) //DND
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
int i, j, nButton;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
int buttons[2] = {button0,button1};
bool result = true, item_result= true;
#if ESD_TIMER_INTERVAL
esd_timer_stop(misc_info);
#endif
set_default_result(info);
ts_set_touchmode2(TOUCH_DND_MODE);
get_raw_data(info, (u8 *)info->hfdnd_data, 5);
ts_set_touchmode(TOUCH_POINT_MODE);
printk("HFDND_data =\n");
for (i = 0; i < x_num; i++) {
for (j = 0; j < y_num; j++) {
printk("%d ", info->hfdnd_data[j+i*y_num]);
}
printk("\n");
}
info->hfdnd_max_x = info->hfdnd_max_y = info->hfdnd_min_x = info->hfdnd_min_y = 0;
info->hfdnd_max_val = -32768;
info->hfdnd_min_val = 32767;
info->hfdnd_real_max_val = -32768;
info->hfdnd_real_min_val = 32767;
info->hfdnd_node_num = -1;
//MAX
for (i = 0; i < x_num-1; i++) {
for (j = 0; j < y_num; j++) {
if (info->hfdnd_real_min_val > info->hfdnd_data[j+i*y_num]) {
info->hfdnd_real_min_x = i;
info->hfdnd_real_min_y = j;
info->hfdnd_real_min_val = info->hfdnd_data[j+i*y_num];
}
if (info->hfdnd_real_max_val < info->hfdnd_data[j+i*y_num]) {
info->hfdnd_real_max_x = i;
info->hfdnd_real_max_y = j;
info->hfdnd_real_max_val = info->hfdnd_data[j+i*y_num];
}
if ((info->hfdnd_data[j+i*y_num] < hfdnd_min[i][j]) && (info->hfdnd_data[j+i*y_num] != 0)) {
printk(" HFDND View Min fail : NODE = %u,Raw data = %d, SPEC = %u\n", j+i*y_num, info->hfdnd_data[j+i*y_num], hfdnd_min[i][j]);
item_result = false;
result = false;
if (info->hfdnd_node_num == -1)
info->hfdnd_node_num = j + (i * y_num);
}
if (info->hfdnd_min_val > info->hfdnd_data[j+i*y_num] - hfdnd_min[i][j]) {
info->hfdnd_min_x = i;
info->hfdnd_min_y = j;
info->hfdnd_min_val = info->hfdnd_data[j+i*y_num] - hfdnd_min[i][j];
}
if (info->hfdnd_data[j+i*y_num] > hfdnd_max[i][j]) {
printk(" HFDND View Max fail : NODE = %u, Raw data = %d, SPEC = %u\n", j+i*y_num, info->hfdnd_data[j+i*y_num], hfdnd_max[i][j]);
item_result = false;
result = false;
if (info->hfdnd_node_num == -1)
info->hfdnd_node_num = j + (i * y_num);
}
if (info->hfdnd_max_val < info->hfdnd_data[j+i*y_num] - hfdnd_max[i][j]) {
info->hfdnd_max_x = i;
info->hfdnd_max_y = j;
info->hfdnd_max_val = info->hfdnd_data[j+i*y_num] - hfdnd_max[i][j];
}
}
}
if (item_result)
printk("HFDND View pass\n");
else
printk("HFDND View Fail\n");
//button
item_result = true;
if (info->cap_info.button_num) {
for (i = 0; i < 2; i++) {
nButton = buttons[i];
if (nButton < 0)
continue;
if (info->hfdnd_real_min_val > info->hfdnd_data[(x_num-1)*y_num+nButton]) {
info->hfdnd_real_min_x = x_num-1;
info->hfdnd_real_min_y = nButton;
info->hfdnd_real_min_val = info->hfdnd_data[(x_num-1)*y_num+nButton];
}
if (info->hfdnd_real_max_val < info->hfdnd_data[(x_num-1)*y_num+nButton]) {
info->hfdnd_real_max_x = x_num-1;
info->hfdnd_real_max_y = nButton;
info->hfdnd_real_max_val = info->hfdnd_data[(x_num-1)*y_num+nButton];
}
if (info->hfdnd_data[(x_num-1)*y_num+nButton] < hfdnd_min[x_num-1][nButton]) {
printk(" HFDND Button Min fail : NODE = %u, Raw data = %d, SPEC = %u\n", nButton, info->hfdnd_data[(x_num-1)*y_num+nButton], hfdnd_min[x_num-1][nButton]);
item_result = false;
result = false;
if (info->hfdnd_node_num == -1)
info->hfdnd_node_num = ((x_num - 1) * y_num) + nButton;
}
if (info->hfdnd_min_val > info->hfdnd_data[(x_num-1)*y_num+nButton] - hfdnd_min[x_num-1][nButton]) {
info->hfdnd_min_x = x_num-1;
info->hfdnd_min_y = nButton;
info->hfdnd_min_val = info->hfdnd_data[(x_num-1)*y_num+nButton] - hfdnd_min[x_num-1][nButton];
}
if (info->hfdnd_data[(x_num-1)*y_num+nButton] > hfdnd_max[x_num-1][nButton]) {
printk(" HFDND Button Max fail : NODE = %u, Raw data = %d, SPEC = %u\n", nButton, info->hfdnd_data[(x_num-1)*y_num+nButton], hfdnd_min[x_num-1][nButton]);
item_result = false;
result = false;
if (info->hfdnd_node_num == -1)
info->hfdnd_node_num = ((x_num - 1) * y_num) + nButton;
}
if (info->hfdnd_max_val < info->hfdnd_data[(x_num-1)*y_num+nButton] - hfdnd_min[x_num-1][nButton]) {
info->hfdnd_max_x = x_num-1;
info->hfdnd_max_y = nButton;
info->hfdnd_max_val = info->hfdnd_data[(x_num-1)*y_num+nButton] - hfdnd_min[x_num-1][nButton];
}
}
}
if (item_result) {
info->hfdnd_done = true;
printk("HFDND Button pass\n");
} else {
info->hfdnd_done = false;
printk("HFDND Button fail\n");
}
#if ESD_TIMER_INTERVAL
esd_timer_start(CHECK_ESD_TIMER, misc_info);
#endif
return result;
}
static void run_reference_HFDND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
bool temp;
set_default_result(info);
temp = run_reference_HFDND_read(device_data, 4, 7);
if (temp) {
pr_info("HF DND pass\n");
sprintf(finfo->cmd_buff, "OK\n");
} else {
int x, y, node_num;
node_num = info->hfdnd_node_num;
x = node_num / info->cap_info.y_node_num;
y = node_num % info->cap_info.y_node_num;
pr_info("HF DND Fail\n");
sprintf(finfo->cmd_buff, "%d,%d,%d,%d\n",
node_num,
hfdnd_min[x][y],
hfdnd_max[x][y],
info->hfdnd_data[node_num]);
}
finfo->cmd_state = OK;
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
static bool run_reference_V_Diff_read(void *device_data, int button0, int button1) //DND
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
int print_diff[19*10]={0,};
int buttons[2] = {button0,button1};
int i, j, diff_val, pre_val, next_val, nButton;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
bool result = true, item_result = true;
printk("TSP Diff test scale factor = %d\n",TSP_INIT_TEST_RATIO);
printk("V Diff start\n");
info->vdiff_max_x = info->vdiff_max_y = info->vdiff_min_x = info->vdiff_min_y = 0;
info->vdiff_max_val = -32768;
info->vdiff_min_val = 32767;
info->vdiff_node_num = -1;
item_result = true;
for (i = 0; i < x_num-2; i++) {
for (j = 0; j < y_num; j++) {
//printk("%d ", info->pdnd_data[i*y_num+j]);
next_val = info->pdnd_data[(i*y_num)+j];
pre_val = info->pdnd_data[(i*y_num)+j+y_num];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk(" %d ", diff_val);
pre_val = (TSP_INIT_TEST_RATIO == 100)?((s16)dnd_v_diff[i][j]):((s16)(((s32)dnd_v_diff[i][j] * TSP_INIT_TEST_RATIO) /100));
if (diff_val > pre_val) {
result = false;
item_result = false;
if (info->vdiff_node_num == -1) {
info->vdiff_node_num = j + (i * y_num);
info->vdiff_diff_val = diff_val;
}
}
#if PDIFF_DEBUG
print_diff[i*y_num+j] = diff_val;
#endif
if (info->vdiff_max_val < diff_val) {
info->vdiff_max_val = diff_val;
info->vdiff_max_x = i;
info->vdiff_max_y= j;
}
if (info->vdiff_min_val > diff_val) {
info->vdiff_min_val = diff_val;
info->vdiff_min_x = i;
info->vdiff_min_y= j;
}
}
printk("\n");
}
if (item_result)
printk("V Diff view pass\n");
else
printk("V Diff view fail\n");
item_result = true;
if ( info->cap_info.button_num) {
printk("TSP Button scale = %d\n", TSP_INIT_TEST_RATIO);
printk("TSP Button Diff Spec. = %d %d\n",
dnd_v_diff[x_num-2][buttons[0]], dnd_v_diff[x_num-2][buttons[1]]);
for (i = 0; i < 2; i++) {
nButton = buttons[i];
if (nButton < 0)
continue;
next_val = info->pdnd_data[(x_num-1)*y_num+nButton];
pre_val = info->pdnd_data[(x_num-2)*y_num+nButton];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
pre_val = (TSP_INIT_TEST_RATIO == 100)?( (s16)dnd_v_diff[x_num-2][nButton]+info->ref_btn_option): \
((s16)(((s32)dnd_v_diff[x_num-2][nButton]*TSP_INIT_TEST_RATIO)/100)+info->ref_btn_option);
if (diff_val > pre_val) {
item_result = false;
result = false;
if (info->vdiff_node_num == -1) {
info->vdiff_node_num = ((x_num - 2) * y_num) + nButton;
info->vdiff_diff_val = diff_val;
}
}
if (info->vdiff_max_val < diff_val) {
info->vdiff_max_val = diff_val;
info->vdiff_max_x = x_num - 1;
info->vdiff_max_y= nButton;
}
if (info->vdiff_min_val >diff_val) {
info->vdiff_min_val = diff_val;
info->vdiff_min_x = x_num - 1;
info->vdiff_min_y= nButton;
}
#if PDIFF_DEBUG
printk("buttons[%d]'s diff_val is %d\n", i, diff_val);
#endif
}
}
if (item_result)
printk("Button V Diff pass\n");
else
printk("Button V Diff fail\n");
return result;
}
static void run_reference_V_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
bool temp;
set_default_result(info);
temp = run_reference_V_Diff_read(device_data, 4, 7);
if (temp) {
pr_info("V Diff pass\n");
sprintf(finfo->cmd_buff, "OK\n");
} else {
int x, y, node_num;
node_num = info->dnd_node_num;
x = node_num / info->cap_info.y_node_num;
y = node_num % info->cap_info.y_node_num;
pr_info("V Diff Fail\n");
sprintf(finfo->cmd_buff, "%d,%d,%d,%d\n",
node_num,
0,
dnd_v_diff[x][y],
info->vdiff_diff_val);
}
finfo->cmd_state = OK;
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
static bool run_reference_H_Diff_read(void *device_data, int button0, int button1) //DND
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
int print_diff[19*10]={0,};
int buttons[2] = {button0,button1};
int i, j, diff_val, pre_val, next_val;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
bool result = true, item_result = true;
printk("TSP Diff test scale factor = %d\n",TSP_INIT_TEST_RATIO);
printk("Diff start\n");
//H DIff
info->hdiff_max_x = info->hdiff_max_y = info->hdiff_min_x = info->hdiff_min_y = 0;
info->hdiff_max_val = -32768;
info->hdiff_min_val = 32767;
info->hdiff_node_num = -1;
for (i = 0; i < x_num - 1; i++) {
for (j = 0; j < y_num-1; j++) {
//printk("%d ", info->dnd_data[i*y_num+j]);
next_val = info->pdnd_data[(i*y_num)+(j+1)];
pre_val = info->pdnd_data[(i*y_num)+j];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk("%d ", diff_val);
pre_val = (TSP_INIT_TEST_RATIO== 100)?((s16)dnd_h_diff[i][j]):((s16)(((s32)dnd_h_diff[i][j] * TSP_INIT_TEST_RATIO) /100));
if (diff_val > pre_val) {
result = false;
item_result = false;
if (info->hdiff_node_num == -1) {
info->hdiff_node_num = j + (i * y_num);
info->hdiff_diff_val = diff_val;
}
}
#if PDIFF_DEBUG
print_diff[i*y_num+j] = diff_val;
#endif
if (info->hdiff_max_val < diff_val) {
info->hdiff_max_val = diff_val;
info->hdiff_max_x = i;
info->hdiff_max_y= j;
}
if (info->hdiff_min_val > diff_val) {
info->hdiff_min_val = diff_val;
info->hdiff_min_x = i;
info->hdiff_min_y= j;
}
}
printk("\n");
}
if (item_result)
printk("H Diff pass\n");
else
printk("H Diff fail\n");
item_result = true;
if (info->cap_info.button_num) {
printk("TSP Button scale = %d\n", TSP_INIT_TEST_RATIO);
printk("TSP Button Diff Spec. = %d %d\n",
dnd_v_diff[x_num-2][buttons[0]], dnd_v_diff[x_num-2][buttons[1]]);
pre_val = info->pdnd_data[(x_num-1)*y_num+button0];
next_val = info->pdnd_data[(x_num-1)*y_num+button1];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
pre_val = (TSP_INIT_TEST_RATIO == 100)?( (s16)dnd_h_diff[x_num-1][button1]+info->ref_btn_option): \
((s16)(((s32)dnd_h_diff[x_num-1][button1]*TSP_INIT_TEST_RATIO)/100)+info->ref_btn_option);
if (diff_val > pre_val) {
item_result = false;
result = false;
if (info->hdiff_node_num == -1) {
info->hdiff_node_num = ((x_num - 1) * y_num) + button1;
info->hdiff_diff_val = diff_val;
}
}
if (info->hdiff_max_val < diff_val) {
info->hdiff_max_val = diff_val;
info->hdiff_max_x = x_num - 1;
info->hdiff_max_y= button1;
}
if (info->hdiff_min_val >diff_val) {
info->hdiff_min_val = diff_val;
info->hdiff_min_x = x_num - 1;
info->hdiff_min_y= button1;
}
}
if (item_result)
printk("Button H Diff pass\n");
else
printk("Button H Diff fail\n");
return result;
}
static void run_reference_H_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
bool temp;
u8 *ret_string;
set_default_result(info);
temp = run_reference_H_Diff_read(device_data, 4, 7);
if (temp)
ret_string = "H Diff pass";
else
ret_string = "H Diff Fail";
if (temp) {
pr_info("H Diff pass\n");
sprintf(finfo->cmd_buff, "OK\n");
} else {
int x, y, node_num;
node_num = info->hfdnd_node_num;
x = node_num / info->cap_info.y_node_num;
y = node_num % info->cap_info.y_node_num;
pr_info("H Diff Fail\n");
sprintf(finfo->cmd_buff, "%d,%d,%d,%d\n",
node_num,
0,
dnd_h_diff[x][y],
info->hdiff_diff_val);
}
finfo->cmd_state = OK;
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
static void get_reference_DND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
char buff[19*7] = {0};
// char tmp[16] = {0};
int x_node, y_node;
int node_num;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= x_num || y_node < 0 || y_node >= y_num) {
snprintf(buff, sizeof(buff), "%s", "NG");
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = FAIL;
return;
}
/*
for (i = 0; i < x_num-1; i++) {
node_num = i*y_num + y_node;
sprintf(tmp, "%d", info->pdnd_data[node_num]);
strcat(buff, tmp);
if (i < x_num-2)
strcat(buff, " ");
}
*/
node_num = (x_node * y_num) + y_node;
sprintf(finfo->cmd_buff, "%d", info->pdnd_data[node_num]);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
buff, (int)strnlen(buff, sizeof(buff)));
return;
}
/*
static void get_reference_max_H_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
int H_diff[19*9] = {0};
int i, j, diff_val, pre_val, next_val;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
int max_hdiff = 0;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
printk("H Diff start\n");
//H DIff
for (i = 0; i < x_num - 1; i++) {
for (j = 0; j <y_num-1; j++) {
next_val = info->pdnd_data[(i*y_num)+(j+1)];
pre_val = info->pdnd_data[(i*y_num)+j];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk("%4d ", diff_val);
H_diff[i*(y_num-1)+j] = diff_val;
if ((i == 0) && (j == 0))
max_hdiff = diff_val;
else {
if (max_hdiff < diff_val)
max_hdiff = diff_val;
}
}
printk("\n");
}
sprintf(finfo->cmd_buff, "%d", max_hdiff);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
*/
static void get_reference_H_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
int H_diff[19*9] = {0};
//char tmp[10] = {0};
int x_node, y_node;
int node_num;
int i, j, diff_val, pre_val, next_val;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
printk("H Diff start\n");
//H DIff
for (i = 0; i < x_num - 1; i++) {
for (j = 0; j < y_num-1; j++) {
next_val = info->pdnd_data[(i*y_num)+(j+1)];
pre_val = info->pdnd_data[(i*y_num)+j];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk("%4d ", diff_val);
H_diff[i*(y_num-1)+j] = diff_val;
}
printk("\n");
}
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= x_num || y_node < 0 || y_node >= y_num) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "NG");
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
return;
}
/*
for (i = 0; i < x_num-1; i++) {
node_num = i*(y_num-1) + y_node;
sprintf(tmp, "%d", H_diff[node_num]);
strcat(finfo->cmd_buff, tmp);
if (i < x_num-2)
strcat(finfo->cmd_buff, " ");
}
*/
node_num = (x_node * y_num) + y_node;
sprintf(finfo->cmd_buff, "%d", H_diff[node_num]);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
/*
static void get_reference_max_V_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
int V_Diff[19*10] = {0};
int buttons[2] = {4,7};
int i, j, pre_val, next_val, nButton;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
int diff_val = 0, max_vdiff = 0;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
for (i = 0; i < x_num-2; i++) {
for (j=0; j < y_num; j++) {
next_val = info->pdnd_data[(i*y_num)+j];
pre_val = info->pdnd_data[(i*y_num)+j+y_num];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk(" %4d ", diff_val);
V_Diff[i*y_num+j] = diff_val;
if ((i == 0) && (j == 0))
max_vdiff = diff_val;
else {
if (max_vdiff < diff_val)
max_vdiff = diff_val;
}
}
printk("\n");
}
//V DIff button
if ( info->cap_info.button_num) {
for (i = 0; i < 2; i++) {
nButton = buttons[i];
if (nButton < 0)
continue;
next_val = info->pdnd_data[(x_num-1)*y_num+nButton];
pre_val = info->pdnd_data[(x_num-2)*y_num+nButton];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
V_Diff[(x_num-1)*y_num + nButton] = diff_val;
if (max_vdiff < diff_val)
max_vdiff = diff_val;
}
}
sprintf(finfo->cmd_buff, "%d", diff_val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
*/
static void get_reference_V_Diff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
/*char tmp[10] = {0};*/
int V_Diff[19*10] = {0};
int x_node, y_node;
int node_num;
int buttons[2] = {4,7};
int i, j, diff_val, pre_val, next_val, nButton;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
for (i = 0; i < x_num-2; i++) {
for (j = 0; j < y_num; j++) {
next_val = info->pdnd_data[(i*y_num)+j];
pre_val = info->pdnd_data[(i*y_num)+j+y_num];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
printk(" %d ", diff_val);
V_Diff[i*y_num+j] = diff_val;
}
printk("\n");
}
//V DIff button
if ( info->cap_info.button_num) {
for (i = 0; i < 2; i++) {
nButton = buttons[i];
if (nButton < 0)
continue;
next_val = info->pdnd_data[(x_num-1)*y_num+nButton];
pre_val = info->pdnd_data[(x_num-2)*y_num+nButton];
diff_val = (next_val > pre_val)?(next_val - pre_val):(pre_val - next_val);
V_Diff[(x_num-1)*y_num + nButton] = diff_val;
}
}
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= x_num || y_node < 0 || y_node >= y_num) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "NG");
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
return;
}
/*
for (i = 0; i < x_num-2; i++) {
node_num = i*y_num + y_node;
sprintf(tmp, "%d", V_Diff[node_num]);
strcat(finfo->cmd_buff, tmp);
if (i < x_num-3)
strcat(finfo->cmd_buff, " ");
}
*/
node_num = (x_node * y_num) + y_node;
sprintf(finfo->cmd_buff, "%d", V_Diff[node_num]);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
}
static void get_reference_HFDND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
char buff[512] = {0};
// char tmp[16] = {0};
int x_node, y_node;
int node_num;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
set_default_result(info);
if (!info->hfdnd_done)
run_reference_HFDND_read(device_data, 4, 7);
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= x_num || y_node < 0 || y_node >= y_num) {
snprintf(buff, sizeof(buff), "%s", "NG");
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = FAIL;
return;
}
/*
for (i = 0; i < x_num-1; i++) {
node_num = i*y_num + y_node;
sprintf(tmp, "%d", info->hfdnd_data[node_num]);
strcat(buff, tmp);
if (i < x_num-2)
strcat(buff, " ");
}
*/
node_num = (x_node * y_num) + y_node;
sprintf(finfo->cmd_buff, "%d", info->hfdnd_data[node_num]);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
buff, (int)strnlen(buff, sizeof(buff)));
return;
}
/*
static void get_max_dnd(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
sprintf(finfo->cmd_buff, "%d", info->dnd_real_max_val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_min_dnd(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
if (!info->dnd_done)
run_reference_DND_read(device_data, 4, 7);
sprintf(finfo->cmd_buff, "%d", info->dnd_real_min_val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_max_hfdnd(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->hfdnd_max_x;
val[1] = info->hfdnd_max_y;
val[2] = info->hfdnd_max_val;
memcpy(finfo->cmd_buff, (char*)val, sizeof(finfo->cmd_buff));
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_min_hfdnd(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->hfdnd_min_x;
val[1] = info->hfdnd_min_y;
val[2] = info->hfdnd_min_val;
memcpy(finfo->cmd_buff, (char*)val, sizeof(finfo->cmd_buff));
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_max_hdiff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->hdiff_max_x;
val[1] = info->hdiff_max_y;
val[2] = info->hdiff_max_val;
sprintf(finfo->cmd_buff, "%d", info->hdiff_max_val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_min_hdiff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->hdiff_min_x;
val[1] = info->hdiff_min_y;
val[2] = info->hdiff_min_val;
sprintf(finfo->cmd_buff, "%d", info->hdiff_min_val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_max_vdiff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->vdiff_max_x;
val[1] = info->vdiff_max_y;
val[2] = info->vdiff_max_val;
memcpy(finfo->cmd_buff, (char*)val, sizeof(finfo->cmd_buff));
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_min_vdiff(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
s16 val[3] = {0};
set_default_result(info);
val[0] = info->vdiff_min_x;
val[1] = info->vdiff_min_y;
val[2] = info->vdiff_min_val;
memcpy(finfo->cmd_buff, (char*)val, sizeof(finfo->cmd_buff));
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
}
*/
/*
static void get_reference(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
unsigned int val;
int x_node, y_node;
int node_num;
set_default_result(info);
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
y_node < 0 || y_node >= info->cap_info.y_node_num) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
return;
}
node_num = x_node * info->cap_info.y_node_num + y_node;
val = raw_data->ref_data[node_num];
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
*/
#if 0
static void run_preference_read(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
u16 min, max;
s32 i,j;
set_default_result(info);
ts_set_touchmode(TOUCH_PDND_MODE);
get_raw_data(info, (u8 *)raw_data->pref_data, 10);
ts_set_touchmode(TOUCH_POINT_MODE);
min = 0xFFFF;
max = 0x0000;
for (i = 0; i < info->cap_info.x_node_num; i++)
{
for (j = 0; j < info->cap_info.y_node_num; j++)
{
/*pr_info("pref_data : %d ",
raw_data->pref_data[i * info->cap_info.y_node_num + j]);*/
if (raw_data->pref_data[i * info->cap_info.y_node_num + j] < min &&
raw_data->pref_data[i * info->cap_info.y_node_num + j] != 0)
min = raw_data->pref_data[i * info->cap_info.y_node_num + j];
if (raw_data->pref_data[i * info->cap_info.y_node_num + j] > max)
max = raw_data->pref_data[i * info->cap_info.y_node_num + j];
}
/*pr_info("\n");*/
}
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
strlen(finfo->cmd_buff));
return;
}
static void get_preference(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
unsigned int val;
int x_node, y_node;
int node_num;
set_default_result(info);
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
y_node < 0 || y_node >= info->cap_info.y_node_num) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
info->factory_info->cmd_state = FAIL;
return;
}
node_num = x_node * info->cap_info.y_node_num + y_node;
val = raw_data->pref_data[node_num];
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
/*
static void run_scantime_read(void *device_data)
{
return;
}
static void get_scantime(void *device_data)
{
return;
}
*/
static void run_normal_read(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
ts_set_touchmode(TOUCH_NORMAL_MODE);
get_raw_data(info, (u8 *)info->normal_data, 5);
ts_set_touchmode(TOUCH_POINT_MODE);
finfo->cmd_state = OK;
}
#endif
#if 0
static void run_delta_read(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
s16 min, max;
s32 i,j;
set_default_result(info);
ts_set_touchmode(TOUCH_DELTA_MODE);
get_raw_data(info, (u8 *)(u8 *)raw_data->delta_data, 5);
ts_set_touchmode(TOUCH_POINT_MODE);
finfo->cmd_state = OK;
min = (s16)0x7FFF;
max = (s16)0x8000;
for (i = 0; i < info->cap_info.x_node_num; i++)
{
for (j = 0; j < info->cap_info.y_node_num; j++)
{
/*printk("delta_data : %d\n", raw_data->delta_data[j+i]);*/
if (raw_data->delta_data[i * info->cap_info.y_node_num + j] < min &&
raw_data->delta_data[i * info->cap_info.y_node_num + j] != 0)
min = raw_data->delta_data[i * info->cap_info.y_node_num + j];
if (raw_data->delta_data[i * info->cap_info.y_node_num + j] > max)
max = raw_data->delta_data[i * info->cap_info.y_node_num + j];
}
/*printk("\n");*/
}
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%d,%d\n", min, max);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: \"%s\"(%d)\n", __func__, finfo->cmd_buff,
(int)strlen(finfo->cmd_buff));
return;
}
#endif
/*
static void get_reference_RxDND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
int y_node, i;
int node_num;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
s16 val[20] = {0};
char buff[40] = {0};
set_default_result(info);
y_node = finfo->cmd_param[0];
if (y_node < 0 || y_node > y_num) {
snprintf(buff, sizeof(buff), "%s", "abnormal");
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = FAIL;
return;
}
for (i = 0; i < x_num; i++) {
node_num = i*y_num + y_node;
val[i] = info->pdnd_data[node_num];
}
memcpy(buff, (char*)val, sizeof(buff));
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
buff, (int)strnlen(buff, sizeof(buff)));
}
*/
/*
static void get_reference_RxHFDND(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
char buff[40] = {0};
s16 val[20] = {0};
int y_node, i;
int node_num;
int x_num = info->cap_info.x_node_num, y_num = info->cap_info.y_node_num;
set_default_result(info);
y_node = finfo->cmd_param[0];
if (y_node < 0 || y_node > y_num) {
snprintf(buff, sizeof(buff), "%s", "NG");
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = FAIL;
return;
}
for (i = 0; i < x_num; i++) {
node_num = i*y_num + y_node;
val[i] = info->hfdnd_data[node_num];
}
memcpy(buff, (char*)val, sizeof(buff));
set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
buff, (int)strnlen(buff, sizeof(buff)));
}
*/
/*
static void get_delta(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
struct tsp_raw_data *raw_data = info->raw_data;
unsigned int val;
int x_node, y_node;
int node_num;
set_default_result(info);
x_node = finfo->cmd_param[0];
y_node = finfo->cmd_param[1];
if (x_node < 0 || x_node >= info->cap_info.x_node_num ||
y_node < 0 || y_node >= info->cap_info.y_node_num) {
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "abnormal");
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
return;
}
node_num = x_node * info->cap_info.y_node_num + y_node;
val = raw_data->delta_data[node_num];
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
set_cmd_result(info, finfo->cmd_buff,
strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__, finfo->cmd_buff,
(int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
*/
/*
static void get_tkey_delta(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct tsp_factory_info *finfo = info->factory_info;
u16 val;
int btn_node;
int ret;
set_default_result(info);
btn_node = finfo->cmd_param[0];
if (btn_node < 0 || btn_node > MAX_SUPPORTED_BUTTON_NUM)
goto err_out;
disable_irq(misc_info->irq);
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
printk(KERN_INFO "other process occupied.. (%d)\n",
misc_info->work_state);
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
goto err_out;
}
misc_info->work_state = SET_MODE;
ret = read_data(misc_info->client, BT541_BTN_WIDTH + btn_node, (u8 *)&val, 2);
if (ret < 0) {
printk(KERN_INFO "read error..\n");
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
goto err_out;
}
misc_info->work_state = NOTHING;
enable_irq(misc_info->irq);
up(&misc_info->work_lock);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%u", val);
set_cmd_result(info, finfo->cmd_buff, strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&info->client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
err_out:
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "NG");
set_cmd_result(info, finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = FAIL;
}
*/
static void hfdnd_spec_adjust(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
int test;
set_default_result(info);
test = finfo->cmd_param[0];
if (test) {
dnd_v_diff = assy_dnd_v_diff;
dnd_h_diff = assy_dnd_h_diff;
pdnd_max = assy_pdnd_max;
pdnd_min = assy_pdnd_min;
hfdnd_max = assy_hfdnd_max;
hfdnd_min = assy_hfdnd_min;
} else {
dnd_v_diff = tsp_dnd_v_diff;
dnd_h_diff = tsp_dnd_h_diff;
pdnd_max = tsp_pdnd_max;
pdnd_min = tsp_pdnd_min;
hfdnd_max = tsp_hfdnd_max;
hfdnd_min = tsp_hfdnd_min;
}
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "OK");
set_cmd_result(info, finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void clear_reference_data(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
set_default_result(info);
#if ESD_TIMER_INTERVAL
esd_timer_stop(info);
write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL, 0);
#endif
write_reg(client, BT541_EEPROM_INFO_REG, 0xffff);
write_reg(client, 0xc003, 0x0001);
write_reg(client, 0xc104, 0x0001);
udelay(100);
if (write_cmd(client, BT541_SAVE_STATUS_CMD) != I2C_SUCCESS)
return;
mdelay(500);
write_reg(client, 0xc003, 0x0000);
write_reg(client, 0xc104, 0x0000);
udelay(100);
#if ESD_TIMER_INTERVAL
write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL,
SCAN_RATE_HZ * ESD_TIMER_INTERVAL);
esd_timer_start(CHECK_ESD_TIMER, info);
#endif
dev_info(&client->dev, "%s: TSP clear calibration bit\n", __func__);
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "OK");
set_cmd_result(info, finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static void run_ref_calibration(void *device_data)
{
struct bt541_ts_info *info = (struct bt541_ts_info *)device_data;
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
int i;
set_default_result(info);
#if ESD_TIMER_INTERVAL
esd_timer_stop(info);
write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL, 0);
#endif
write_reg(client, 0x01CA, 1300);
if (ts_hw_calibration(info) == true)
dev_info(&client->dev, "%s: TSP calibration Pass\n", __func__);
else
dev_info(&client->dev, "%s: TSP calibration Fail\n", __func__);
write_reg(client, 0x01CA, 0);
write_reg(client, 0x0149, 0);
for (i = 0; i < 5; i++) {
write_cmd(client, BT541_CLEAR_INT_STATUS_CMD);
udelay(10);
}
#if ESD_TIMER_INTERVAL
write_reg(client, BT541_PERIODICAL_INTERRUPT_INTERVAL,
SCAN_RATE_HZ * ESD_TIMER_INTERVAL);
esd_timer_start(CHECK_ESD_TIMER, info);
#endif
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "%s", "OK");
set_cmd_result(info, finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
finfo->cmd_state = OK;
dev_info(&client->dev, "%s: %s(%d)\n", __func__,
finfo->cmd_buff, (int)strnlen(finfo->cmd_buff, sizeof(finfo->cmd_buff)));
return;
}
static ssize_t store_cmd(struct device *dev, struct device_attribute
*devattr, const char *buf, size_t count)
{
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
char *cur, *start, *end;
char buff[TSP_CMD_STR_LEN] = {0};
int len, i;
struct tsp_cmd *tsp_cmd_ptr = NULL;
char delim = ',';
bool cmd_found = false;
int param_cnt = 0;
if (finfo->cmd_is_running == true) {
dev_err(&client->dev, "%s: other cmd is running\n", __func__);
goto err_out;
}
/* check lock */
mutex_lock(&finfo->cmd_lock);
finfo->cmd_is_running = true;
mutex_unlock(&finfo->cmd_lock);
finfo->cmd_state = RUNNING;
for (i = 0; i < ARRAY_SIZE(finfo->cmd_param); i++)
finfo->cmd_param[i] = 0;
len = (int)count;
if (*(buf + len - 1) == '\n')
len--;
memset(finfo->cmd, 0x00, ARRAY_SIZE(finfo->cmd));
memcpy(finfo->cmd, buf, len);
cur = strchr(buf, (int)delim);
if (cur)
memcpy(buff, buf, cur - buf);
else
memcpy(buff, buf, len);
/* find command */
list_for_each_entry(tsp_cmd_ptr, &finfo->cmd_list_head, list) {
if (!strcmp(buff, tsp_cmd_ptr->cmd_name)) {
cmd_found = true;
break;
}
}
/* set not_support_cmd */
if (!cmd_found) {
list_for_each_entry(tsp_cmd_ptr, &finfo->cmd_list_head, list) {
if (!strcmp("not_support_cmd", tsp_cmd_ptr->cmd_name))
break;
}
}
/* parsing parameters */
if (cur && cmd_found) {
cur++;
start = cur;
memset(buff, 0x00, ARRAY_SIZE(buff));
do {
if (*cur == delim || cur - buf == len) {
end = cur;
memcpy(buff, start, end - start);
*(buff + strlen(buff)) = '\0';
finfo->cmd_param[param_cnt] =
(int)simple_strtol(buff, NULL, 10);
start = cur + 1;
memset(buff, 0x00, ARRAY_SIZE(buff));
param_cnt++;
}
cur++;
} while (cur - buf <= len);
}
dev_info(&client->dev, "cmd = %s\n", tsp_cmd_ptr->cmd_name);
/* for (i = 0; i < param_cnt; i++)
dev_info(&client->dev, "cmd param %d= %d\n", i, finfo->cmd_param[i]);*/
tsp_cmd_ptr->cmd_func(info);
mutex_lock(&finfo->cmd_lock);
finfo->cmd_is_running = false;
mutex_unlock(&finfo->cmd_lock);
err_out:
return count;
}
static ssize_t show_cmd_status(struct device *dev,
struct device_attribute *devattr, char *buf)
{
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
dev_info(&client->dev, "tsp cmd: status:%d\n", finfo->cmd_state);
if (finfo->cmd_state == WAITING)
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "WAITING");
else if (finfo->cmd_state == RUNNING)
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "RUNNING");
else if (finfo->cmd_state == OK)
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "OK");
else if (finfo->cmd_state == FAIL)
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "FAIL");
else if (finfo->cmd_state == NOT_APPLICABLE)
snprintf(finfo->cmd_buff, sizeof(finfo->cmd_buff), "NOT_APPLICABLE");
return snprintf(buf, sizeof(finfo->cmd_buff),
"%s\n", finfo->cmd_buff);
}
static ssize_t show_cmd_result(struct device *dev, struct device_attribute
*devattr, char *buf)
{
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
struct tsp_factory_info *finfo = info->factory_info;
dev_info(&client->dev, "tsp cmd: result: %s\n", finfo->cmd_result);
finfo->cmd_state = WAITING;
return snprintf(buf, sizeof(finfo->cmd_result),
"%s\n", finfo->cmd_result);
}
static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, store_cmd);
static DEVICE_ATTR(cmd_status, S_IRUGO, show_cmd_status, NULL);
static DEVICE_ATTR(cmd_result, S_IRUGO, show_cmd_result, NULL);
static struct attribute *touchscreen_attributes[] = {
&dev_attr_cmd.attr,
&dev_attr_cmd_status.attr,
&dev_attr_cmd_result.attr,
NULL,
};
static struct attribute_group touchscreen_attr_group = {
.attrs = touchscreen_attributes,
};
#ifdef SUPPORTED_TOUCH_KEY
static ssize_t show_touchkey_threshold(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
struct capa_info *cap = &(info->cap_info);
#ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
dev_info(&client->dev, "%s: key threshold = %d\n", __func__,
cap->key_threshold);
return snprintf(buf, 41, "%d", cap->key_threshold);
#else
dev_info(&client->dev, "%s: key threshold = %d %d %d %d\n", __func__,
cap->dummy_threshold, cap->key_threshold, cap->key_threshold, cap->dummy_threshold);
return snprintf(buf, 41, "%d %d %d %d", cap->dummy_threshold,
cap->key_threshold, cap->key_threshold,
cap->dummy_threshold);
#endif
}
#if 0
static ssize_t enable_dummy_key(struct device *dev,
struct device_attribute *attr, char *buf, size_t count)
{
static char enable = '0';
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
if (!strcmp(buf, ""))
count = sprintf(buf, "%c", enable);
else {
if ((buf[0] - '0' <= 1) && count == 2)
enable = *buf;
else {
dev_err(&client->dev, "%s: Invalid parameter\n", __func__);
goto err_out;
}
}
dev_info(&client->dev, "%s: Extra button event %c\n", __func__, enable);
return count;
err_out:
return sprintf(buf, "NG");
return 0;
}
#endif
static ssize_t show_touchkey_sensitivity(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct bt541_ts_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
u16 val = 0;
int ret;
int i;
#ifdef NOT_SUPPORTED_TOUCH_DUMMY_KEY
if (!strcmp(attr->attr.name, "touchkey_recent"))
i = 0;
else if (!strcmp(attr->attr.name, "touchkey_back"))
i = 1;
else {
dev_err(&client->dev, "%s: Invalid attribute\n", __func__);
goto err_out;
}
#else
if (!strcmp(attr->attr.name, "touchkey_dummy_btn1"))
i = 0;
else if (!strcmp(attr->attr.name, "touchkey_recent"))
i = 1;
else if (!strcmp(attr->attr.name, "touchkey_back"))
i = 2;
else if (!strcmp(attr->attr.name, "touchkey_dummy_btn4"))
i = 3;
else if (!strcmp(attr->attr.name, "touchkey_dummy_btn5"))
i = 4;
else if (!strcmp(attr->attr.name, "touchkey_dummy_btn6"))
i = 5;
else {
dev_err(&client->dev, "%s: Invalid attribute\n", __func__);
goto err_out;
}
#endif
ret = read_data(client, BT541_BTN_WIDTH + i, (u8 *)&val, 2);
if (ret < 0) {
dev_err(&client->dev, "%s: Failed to read %d's key sensitivity\n",
__func__, i);
goto err_out;
}
dev_info(&client->dev, "%s: %d's key sensitivity = %d\n",
__func__, i, val);
return snprintf(buf, 6, "%d", val);
err_out:
return sprintf(buf, "NG");
}
static ssize_t show_back_key_raw_data(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
static ssize_t show_menu_key_raw_data(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
/*
static ssize_t show_back_key_idac_data(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
static ssize_t show_menu_key_idac_data(struct device *dev,
struct device_attribute *attr, char *buf)
{
return 0;
}
*/
static DEVICE_ATTR(touchkey_threshold, S_IRUGO, show_touchkey_threshold, NULL);
/*static DEVICE_ATTR(touch_sensitivity, S_IRUGO, back_key_state_show, NULL);*/
//static DEVICE_ATTR(extra_button_event, S_IWUSR | S_IWGRP | S_IRUGO, NULL, enable_dummy_key);
static DEVICE_ATTR(touchkey_recent, S_IRUGO, show_touchkey_sensitivity, NULL);
static DEVICE_ATTR(touchkey_back, S_IRUGO, show_touchkey_sensitivity, NULL);
#ifndef NOT_SUPPORTED_TOUCH_DUMMY_KEY
static DEVICE_ATTR(touchkey_dummy_btn1, S_IRUGO,
show_touchkey_sensitivity, NULL);
static DEVICE_ATTR(touchkey_dummy_btn3, S_IRUGO,
show_touchkey_sensitivity, NULL);
static DEVICE_ATTR(touchkey_dummy_btn4, S_IRUGO,
show_touchkey_sensitivity, NULL);
static DEVICE_ATTR(touchkey_dummy_btn6, S_IRUGO,
show_touchkey_sensitivity, NULL);
#endif
/*static DEVICE_ATTR(autocal_stat, S_IRUGO, show_autocal_status, NULL);*/
static DEVICE_ATTR(touchkey_raw_back, S_IRUGO, show_back_key_raw_data, NULL);
static DEVICE_ATTR(touchkey_raw_menu, S_IRUGO, show_menu_key_raw_data, NULL);
/*static DEVICE_ATTR(touchkey_idac_back, S_IRUGO, show_back_key_idac_data, NULL);
static DEVICE_ATTR(touchkey_idac_menu, S_IRUGO, show_menu_key_idac_data, NULL);*/
static struct attribute *touchkey_attributes[] = {
&dev_attr_touchkey_threshold.attr,
/*&dev_attr_touch_sensitivity.attr,*/
&dev_attr_touchkey_back.attr,
&dev_attr_touchkey_recent.attr,
//&dev_attr_autocal_stat.attr,
//&dev_attr_extra_button_event.attr,
&dev_attr_touchkey_raw_menu.attr,
&dev_attr_touchkey_raw_back.attr,
#ifndef NOT_SUPPORTED_TOUCH_DUMMY_KEY
&dev_attr_touchkey_dummy_btn1.attr,
&dev_attr_touchkey_dummy_btn3.attr,
&dev_attr_touchkey_dummy_btn4.attr,
&dev_attr_touchkey_dummy_btn6.attr,
#endif
//&dev_attr_touchkey_idac_back.attr,
//&dev_attr_touchkey_idac_menu.attr,
NULL,
};
static struct attribute_group touchkey_attr_group = {
.attrs = touchkey_attributes,
};
#endif
static int init_sec_factory(struct bt541_ts_info *info)
{
struct device *factory_ts_dev;
#ifdef SUPPORTED_TOUCH_KEY
struct device *factory_tk_dev;
#endif
struct tsp_factory_info *factory_info;
struct tsp_raw_data *raw_data;
int ret;
int i;
factory_info = kzalloc(sizeof(struct tsp_factory_info), GFP_KERNEL);
if (unlikely(!factory_info)) {
dev_err(&info->client->dev, "%s: Failed to allocate memory\n",
__func__);
ret = -ENOMEM;
goto err_alloc1;
}
raw_data = kzalloc(sizeof(struct tsp_raw_data), GFP_KERNEL);
if (unlikely(!raw_data)) {
dev_err(&info->client->dev, "%s: Failed to allocate memory\n",
__func__);
ret = -ENOMEM;
goto err_alloc2;
}
INIT_LIST_HEAD(&factory_info->cmd_list_head);
for (i = 0; i < ARRAY_SIZE(tsp_cmds); i++)
list_add_tail(&tsp_cmds[i].list, &factory_info->cmd_list_head);
factory_ts_dev = device_create(sec_class, NULL, 0, info, "tsp");
if (unlikely(!factory_ts_dev)) {
dev_err(&info->client->dev, "Failed to create factory dev\n");
ret = -ENODEV;
goto err_create_device;
}
#ifdef SUPPORTED_TOUCH_KEY
factory_tk_dev = device_create(sec_class, NULL, 0, info, "sec_touchkey");
if (IS_ERR(factory_tk_dev)) {
dev_err(&info->client->dev, "Failed to create factory dev\n");
ret = -ENODEV;
goto err_create_device;
}
#endif
ret = sysfs_create_group(&factory_ts_dev->kobj, &touchscreen_attr_group);
if (unlikely(ret)) {
dev_err(&info->client->dev, "Failed to create touchscreen sysfs group\n");
goto err_create_sysfs;
}
#ifdef SUPPORTED_TOUCH_KEY
ret = sysfs_create_group(&factory_tk_dev->kobj, &touchkey_attr_group);
if (unlikely(ret)) {
dev_err(&info->client->dev, "Failed to create touchkey sysfs group\n");
goto err_create_sysfs;
}
#endif
mutex_init(&factory_info->cmd_lock);
factory_info->cmd_is_running = false;
info->factory_info = factory_info;
info->raw_data = raw_data;
dnd_v_diff = assy_dnd_v_diff;
dnd_h_diff = assy_dnd_h_diff;
pdnd_max = assy_pdnd_max;
pdnd_min = assy_pdnd_min;
hfdnd_max = assy_hfdnd_max;
hfdnd_min = assy_hfdnd_min;
return ret;
err_create_sysfs:
err_create_device:
kfree(raw_data);
err_alloc2:
kfree(factory_info);
err_alloc1:
return ret;
}
#endif
static int ts_misc_fops_open(struct inode *inode, struct file *filp)
{
return 0;
}
static int ts_misc_fops_close(struct inode *inode, struct file *filp)
{
return 0;
}
static long ts_misc_fops_ioctl(struct file *filp,
unsigned int cmd, unsigned long arg)
{
void __user *argp = (void __user *)arg;
struct raw_ioctl raw_ioctl;
u8 *u8Data;
int ret = 0;
size_t sz = 0;
u16 version;
u16 mode;
struct reg_ioctl reg_ioctl;
u16 val;
int nval = 0;
if (misc_info == NULL)
{
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
switch (cmd) {
case TOUCH_IOCTL_GET_DEBUGMSG_STATE:
ret = m_ts_debug_mode;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_SET_DEBUGMSG_STATE:
if (copy_from_user(&nval, argp, 4)) {
pr_info("[zinitix_touch] error : copy_from_user\n");
return -1;
}
if (nval)
pr_info("[zinitix_touch] on debug mode (%d)\n",
nval);
else
pr_info("[zinitix_touch] off debug mode (%d)\n",
nval);
m_ts_debug_mode = nval;
break;
case TOUCH_IOCTL_GET_CHIP_REVISION:
ret = misc_info->cap_info.ic_revision;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_FW_VERSION:
ret = misc_info->cap_info.fw_version;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_REG_DATA_VERSION:
ret = misc_info->cap_info.reg_data_version;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_VARIFY_UPGRADE_SIZE:
if (copy_from_user(&sz, argp, sizeof(size_t)))
return -1;
printk(KERN_INFO "[zinitix_touch]: firmware size = %d\r\n", (int)sz);
if (misc_info->cap_info.ic_fw_size != sz) {
pr_info("[zinitix_touch]: firmware size error\r\n");
return -1;
}
break;
case TOUCH_IOCTL_VARIFY_UPGRADE_DATA:
if (copy_from_user(m_firmware_data,
argp, misc_info->cap_info.ic_fw_size))
return -1;
version = (u16) (m_firmware_data[52] | (m_firmware_data[53]<<8));
pr_info("[zinitix_touch]: firmware version = %x\r\n", version);
if (copy_to_user(argp, &version, sizeof(version)))
return -1;
break;
case TOUCH_IOCTL_START_UPGRADE:
return ts_upgrade_sequence((u8 *)m_firmware_data);
case TOUCH_IOCTL_GET_X_RESOLUTION:
ret = misc_info->pdata->x_resolution;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_Y_RESOLUTION:
ret = misc_info->pdata->y_resolution;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_X_NODE_NUM:
ret = misc_info->cap_info.x_node_num;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_Y_NODE_NUM:
ret = misc_info->cap_info.y_node_num;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_GET_TOTAL_NODE_NUM:
ret = misc_info->cap_info.total_node_num;
if (copy_to_user(argp, &ret, sizeof(ret)))
return -1;
break;
case TOUCH_IOCTL_HW_CALIBRAION:
ret = -1;
disable_irq(misc_info->irq);
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
pr_info("[zinitix_touch]: other process occupied.. (%d)\r\n",
misc_info->work_state);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = HW_CALIBRAION;
mdelay(100);
/* h/w calibration */
if (ts_hw_calibration(misc_info) == true)
ret = 0;
mode = misc_info->touch_mode;
if (write_reg(misc_info->client,
BT541_TOUCH_MODE, mode) != I2C_SUCCESS) {
pr_err("[zinitix_touch]: failed to set touch mode %d.\n",
mode);
goto fail_hw_cal;
}
if (write_cmd(misc_info->client,
BT541_SWRESET_CMD) != I2C_SUCCESS)
goto fail_hw_cal;
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return ret;
fail_hw_cal:
enable_irq(misc_info->irq);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return -1;
case TOUCH_IOCTL_SET_RAW_DATA_MODE:
if (misc_info == NULL) {
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
if (copy_from_user(&nval, argp, 4)) {
pr_info("[zinitix_touch] error : copy_from_user\r\n");
misc_info->work_state = NOTHING;
return -1;
}
ts_set_touchmode((u16)nval);
return 0;
case TOUCH_IOCTL_GET_REG:
if (misc_info == NULL) {
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
pr_info("[zinitix_touch]:other process occupied.. (%d)\n",
misc_info->work_state);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
if (copy_from_user(®_ioctl,
argp, sizeof(struct reg_ioctl))) {
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
pr_info("[zinitix_touch] error : copy_from_user\n");
return -1;
}
if (read_data(misc_info->client,
(u16)reg_ioctl.addr, (u8 *)&val, 2) < 0)
ret = -1;
nval = (int)val;
if (copy_to_user((void *)(unsigned long)reg_ioctl.val, (u8 *)&nval, 4)) {
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
pr_info("[zinitix_touch] error : copy_to_user\n");
return -1;
}
zinitix_debug_msg("read : reg addr = 0x%x, val = 0x%x\n",
reg_ioctl.addr, nval);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return ret;
case TOUCH_IOCTL_SET_REG:
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
pr_info("[zinitix_touch]: other process occupied.. (%d)\n",
misc_info->work_state);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
if (copy_from_user(®_ioctl,
argp, sizeof(struct reg_ioctl))) {
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
pr_info("[zinitix_touch] error : copy_from_user(1)\n");
return -1;
}
if (copy_from_user(&val, (void *)(unsigned long)reg_ioctl.val, 4)) {
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
pr_info("[zinitix_touch] error : copy_from_user(2)\n");
return -1;
}
if (write_reg(misc_info->client,
(u16)reg_ioctl.addr, val) != I2C_SUCCESS)
ret = -1;
zinitix_debug_msg("write : reg addr = 0x%x, val = 0x%x\r\n",
reg_ioctl.addr, val);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return ret;
case TOUCH_IOCTL_DONOT_TOUCH_EVENT:
if (misc_info == NULL) {
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
pr_info("[zinitix_touch]: other process occupied.. (%d)\r\n",
misc_info->work_state);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
if (write_reg(misc_info->client,
BT541_INT_ENABLE_FLAG, 0) != I2C_SUCCESS)
ret = -1;
zinitix_debug_msg("write : reg addr = 0x%x, val = 0x0\r\n",
BT541_INT_ENABLE_FLAG);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return ret;
case TOUCH_IOCTL_SEND_SAVE_STATUS:
if (misc_info == NULL) {
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
down(&misc_info->work_lock);
if (misc_info->work_state != NOTHING) {
pr_info("[zinitix_touch]: other process occupied.." \
"(%d)\r\n", misc_info->work_state);
up(&misc_info->work_lock);
return -1;
}
misc_info->work_state = SET_MODE;
ret = 0;
write_reg(misc_info->client, 0xc003, 0x0001);
write_reg(misc_info->client, 0xc104, 0x0001);
if (write_cmd(misc_info->client,
BT541_SAVE_STATUS_CMD) != I2C_SUCCESS)
ret = -1;
mdelay(1000); /* for fusing eeprom */
write_reg(misc_info->client, 0xc003, 0x0000);
write_reg(misc_info->client, 0xc104, 0x0000);
misc_info->work_state = NOTHING;
up(&misc_info->work_lock);
return ret;
case TOUCH_IOCTL_GET_RAW_DATA:
if (misc_info == NULL) {
zinitix_debug_msg("misc device NULL?\n");
return -1;
}
if (misc_info->touch_mode == TOUCH_POINT_MODE)
return -1;
down(&misc_info->raw_data_lock);
if (misc_info->update == 0) {
up(&misc_info->raw_data_lock);
return -2;
}
if (copy_from_user(&raw_ioctl,
argp, sizeof(struct raw_ioctl))) {
up(&misc_info->raw_data_lock);
pr_info("[zinitix_touch] error : copy_from_user\r\n");
return -1;
}
misc_info->update = 0;
u8Data = (u8 *)&misc_info->cur_data[0];
if (raw_ioctl.sz > MAX_TRAW_DATA_SZ*2)
raw_ioctl.sz = MAX_TRAW_DATA_SZ*2;
if (copy_to_user((void *)(unsigned long)raw_ioctl.buf, (u8 *)u8Data,
raw_ioctl.sz)) {
up(&misc_info->raw_data_lock);
return -1;
}
up(&misc_info->raw_data_lock);
return 0;
default:
break;
}
return 0;
}
#ifdef CONFIG_OF
static const struct of_device_id tsp_dt_ids[] = {
{ .compatible = "Zinitix,bt541_ts", },
{},
};
MODULE_DEVICE_TABLE(of, tsp_dt_ids);
#endif
static int bt541_ts_probe_dt(struct device_node *np,
struct device *dev,
struct bt541_ts_platform_data *pdata)
{
int ret;
if (!np)
return -EINVAL;
pdata->gpio_int = of_get_named_gpio(np,"gpios", 0);
if (pdata->gpio_int < 0) {
pr_err("%s: of_get_named_gpio failed: %d\n", __func__,
pdata->gpio_int);
return -EINVAL;
}
ret = of_property_read_u32(np, "bt541,x_resolution",
&pdata->x_resolution);
if (ret < 0)
return ret;
ret = of_property_read_u32(np, "bt541,y_resolution",
&pdata->y_resolution);
if (ret < 0)
return ret;
ret = of_property_read_u32(np, "bt541,orientation",
&pdata->orientation);
if (ret < 0)
return ret;
ret = of_property_read_u32(np, "bt541,page_size", &pdata->page_size);
if (ret < 0)
return ret;
ret = of_property_read_u32(np, "tsp_vdd_supply_type",
&pdata->tsp_supply_type);
if (ret < 0) {
pr_err("%s: failed to read property tsp_vdd_supply_type\n",
__func__);
return ret;
}
if (pdata->tsp_supply_type == TSP_LDO_SUPPLY) {
pdata->gpio_ldo_en = of_get_named_gpio(np, "gpio_ldo_en", 0);
if (pdata->gpio_ldo_en < 0) {
pr_err("%s: of_get_named_gpio failed: %d\n", __func__,
pdata->gpio_ldo_en);
return -EINVAL;
}
}
pdata->tsp_power = bt541_power;
return 0;
}
static int bt541_ts_probe(struct i2c_client *client,
const struct i2c_device_id *i2c_id)
{
struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
struct bt541_ts_platform_data *pdata = client->dev.platform_data;
struct bt541_ts_info *info;
struct input_dev *input_dev;
int ret = 0;
int i;
struct device_node *np = client->dev.of_node;
if (IS_ENABLED(CONFIG_OF)) {
if (!pdata) {
pdata = devm_kzalloc(&client->dev,
sizeof(*pdata), GFP_KERNEL);
if (!pdata)
return -ENOMEM;
}
ret = bt541_ts_probe_dt(np, &client->dev, pdata);
if (ret)
goto err_no_platform_data;
} else if (!pdata) {
dev_err(&client->dev, "Not exist platform data\n");
return -EINVAL;
}
if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev, "Not compatible i2c function\n");
ret = -EIO;
goto err_no_platform_data;
}
info = kzalloc(sizeof(struct bt541_ts_info), GFP_KERNEL);
if (!info) {
dev_err(&client->dev, "Failed to allocate memory\n");
ret = -ENOMEM;
goto err_no_platform_data;
}
ret = gpio_request(pdata->gpio_int, "bt541_int");
if (ret < 0) {
pr_err("%s: Request GPIO failed, gpio %d (%d)\n", BT541_TS_DEVICE,
pdata->gpio_int, ret);
goto err_gpio_alloc;
}
gpio_direction_input(pdata->gpio_int);
i2c_set_clientdata(client, info);
info->client = client;
info->pdata = pdata;
input_dev = input_allocate_device();
if (!input_dev) {
dev_err(&client->dev, "Failed to allocate input device\n");
ret = -EPERM;
goto err_alloc;
}
info->input_dev = input_dev;
info->work_state = PROBE;
/* power on */
if (bt541_power_control(info, POWER_ON_SEQUENCE) == false) {
ret = -EPERM;
goto err_power_sequence;
}
/* To Do */
/* FW version read from tsp */
memset(&info->reported_touch_info,
0x0, sizeof(struct point_info));
/* init touch mode */
info->touch_mode = TOUCH_POINT_MODE;
misc_info = info;
if (init_touch(info, true) == false) {
ret = -EPERM;
goto err_input_unregister_device;
}
for (i = 0; i < MAX_SUPPORTED_BUTTON_NUM; i++)
info->button[i] = ICON_BUTTON_UNCHANGE;
snprintf(info->phys, sizeof(info->phys),
"%s/input0", dev_name(&client->dev));
input_dev->name = "sec_touchscreen";
input_dev->id.bustype = BUS_I2C;
/* input_dev->id.vendor = 0x0001; */
input_dev->phys = info->phys;
/* input_dev->id.product = 0x0002; */
/* input_dev->id.version = 0x0100; */
input_dev->dev.parent = &client->dev;
set_bit(EV_SYN, info->input_dev->evbit);
set_bit(EV_KEY, info->input_dev->evbit);
set_bit(EV_ABS, info->input_dev->evbit);
set_bit(INPUT_PROP_DIRECT, info->input_dev->propbit);
for (i = 0; i < MAX_SUPPORTED_BUTTON_NUM; i++)
set_bit(BUTTON_MAPPING_KEY[i], info->input_dev->keybit);
if (pdata->orientation & TOUCH_XY_SWAP) {
input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
info->cap_info.MinX,
info->cap_info.MaxX + ABS_PT_OFFSET,
0, 0);
input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
info->cap_info.MinY,
info->cap_info.MaxY + ABS_PT_OFFSET,
0, 0);
} else {
input_set_abs_params(info->input_dev, ABS_MT_POSITION_X,
info->cap_info.MinX,
info->cap_info.MaxX + ABS_PT_OFFSET,
0, 0);
input_set_abs_params(info->input_dev, ABS_MT_POSITION_Y,
info->cap_info.MinY,
info->cap_info.MaxY + ABS_PT_OFFSET,
0, 0);
}
input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MAJOR,
0, 255, 0, 0);
input_set_abs_params(info->input_dev, ABS_MT_WIDTH_MAJOR,
0, 255, 0, 0);
#if (TOUCH_POINT_MODE == 2)
input_set_abs_params(info->input_dev, ABS_MT_TOUCH_MINOR,
0, 255, 0, 0);
/* input_set_abs_params(info->input_dev, ABS_MT_WIDTH_MINOR,
0, 255, 0, 0); */
/* input_set_abs_params(info->input_dev, ABS_MT_ORIENTATION,
-128, 127, 0, 0); */
/* input_set_abs_params(info->input_dev, ABS_MT_ANGLE,
-90, 90, 0, 0);*/
input_set_abs_params(info->input_dev, ABS_MT_PALM,
0, 1, 0, 0);
#endif
set_bit(MT_TOOL_FINGER, info->input_dev->keybit);
input_mt_init_slots(info->input_dev, info->cap_info.multi_fingers,0);
zinitix_debug_msg("register %s input device \r\n",
info->input_dev->name);
input_set_drvdata(info->input_dev, info);
ret = input_register_device(info->input_dev);
if (ret) {
printk(KERN_ERR "unable to register %s input device\r\n",
info->input_dev->name);
goto err_input_register_device;
}
/* configure irq */
info->irq = gpio_to_irq(pdata->gpio_int);
if (info->irq < 0)
printk(KERN_INFO "error. gpio_to_irq(..) function is not \
supported? you should define GPIO_TOUCH_IRQ.\r\n");
zinitix_debug_msg("request irq (irq = %d, pin = %d) \r\n",
info->irq, pdata->gpio_int);
info->work_state = NOTHING;
#if TOUCH_BOOSTER
info->finger_cnt = 0;
#endif
sema_init(&info->work_lock, 1);
#if ESD_TIMER_INTERVAL
spin_lock_init(&info->lock);
INIT_WORK(&info->tmr_work, ts_tmr_work);
esd_tmr_workqueue =
create_singlethread_workqueue("esd_tmr_workqueue");
if (!esd_tmr_workqueue) {
dev_err(&client->dev, "Failed to create esd tmr work queue\n");
ret = -EPERM;
goto err_esd_input_unregister_device;
}
esd_timer_init(info);
esd_timer_start(CHECK_ESD_TIMER, info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Started esd timer\n");
#endif
#endif
ret = request_threaded_irq(info->irq, NULL, bt541_touch_work,
IRQF_TRIGGER_FALLING | IRQF_ONESHOT , BT541_TS_DEVICE, info);
if (ret) {
printk(KERN_ERR "unable to register irq.(%s)\r\n",
info->input_dev->name);
goto err_request_irq;
}
dev_info(&client->dev, "zinitix touch probe.\r\n");
sprd_i2c_ctl_chg_clk(1, 400000); // up h/w i2c 1 400k
#ifdef CONFIG_HAS_EARLYSUSPEND
info->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
info->early_suspend.suspend = bt541_ts_early_suspend;
info->early_suspend.resume = bt541_ts_late_resume;
register_early_suspend(&info->early_suspend);
#endif
#if defined(CONFIG_PM_RUNTIME) && !defined(CONFIG_HAS_EARLYSUSPEND)
pm_runtime_enable(&client->dev);
#endif
sema_init(&info->raw_data_lock, 1);
ret = misc_register(&touch_misc_device);
if (ret) {
dev_err(&client->dev, "Failed to register touch misc device\n");
goto err_misc_register;
}
#ifdef SEC_FACTORY_TEST
ret = init_sec_factory(info);
if (ret) {
dev_err(&client->dev, "Failed to init sec factory device\n");
goto err_kthread_create_failed;
}
#endif
return 0;
#ifdef SEC_FACTORY_TEST
err_kthread_create_failed:
kfree(info->factory_info);
kfree(info->raw_data);
#endif
err_misc_register:
free_irq(info->irq, info);
err_request_irq:
#if ESD_TIMER_INTERVAL
err_esd_input_unregister_device:
#endif
err_input_unregister_device:
input_unregister_device(info->input_dev);
err_input_register_device:
tsp_charger_status_cb = NULL;
err_power_sequence:
input_free_device(info->input_dev);
err_alloc:
kfree(info);
err_gpio_alloc:
gpio_free(pdata->gpio_int);
err_no_platform_data:
if (IS_ENABLED(CONFIG_OF))
devm_kfree(&client->dev, (void *)pdata);
dev_info(&client->dev, "Failed to probe\n");
return ret;
}
static int bt541_ts_remove(struct i2c_client *client)
{
struct bt541_ts_info *info = i2c_get_clientdata(client);
struct bt541_ts_platform_data *pdata = info->pdata;
disable_irq(info->irq);
down(&info->work_lock);
info->work_state = REMOVE;
#ifdef SEC_FACTORY_TEST
kfree(info->factory_info);
kfree(info->raw_data);
#endif
#if ESD_TIMER_INTERVAL
flush_work(&info->tmr_work);
write_reg(info->client, BT541_PERIODICAL_INTERRUPT_INTERVAL, 0);
esd_timer_stop(info);
#if defined(TSP_VERBOSE_DEBUG)
dev_info(&client->dev, "Stopped esd timer\n");
#endif
destroy_workqueue(esd_tmr_workqueue);
#endif
if (info->irq)
free_irq(info->irq, info);
misc_deregister(&touch_misc_device);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&info->early_suspend);
#endif
if (gpio_is_valid(pdata->gpio_int) != 0)
gpio_free(pdata->gpio_int);
tsp_charger_status_cb = NULL;
input_unregister_device(info->input_dev);
input_free_device(info->input_dev);
up(&info->work_lock);
kfree(info);
return 0;
}
void bt541_ts_shutdown(struct i2c_client *client)
{
struct bt541_ts_info *info = i2c_get_clientdata(client);
dev_info(&client->dev, "%s++\n",__func__);
disable_irq(info->irq);
down(&info->work_lock);
#if ESD_TIMER_INTERVAL
flush_work(&info->tmr_work);
esd_timer_stop(info);
#endif
up(&info->work_lock);
bt541_power_control(info, POWER_OFF);
dev_info(&client->dev, "%s--\n",__func__);
}
static struct i2c_device_id bt541_idtable[] = {
{BT541_TS_DEVICE, 0},
{ }
};
#if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND)
static const struct dev_pm_ops bt541_ts_pm_ops ={
#if defined(CONFIG_PM_RUNTIME)
SET_RUNTIME_PM_OPS(bt541_ts_suspend, bt541_ts_resume,NULL)
#else
SET_SYSTEM_SLEEP_PM_OPS(bt541_ts_suspend, bt541_ts_resume)
#endif
};
#endif
static struct i2c_driver bt541_ts_driver = {
.probe = bt541_ts_probe,
.remove = bt541_ts_remove,
.shutdown = bt541_ts_shutdown,
.id_table = bt541_idtable,
.driver = {
.owner = THIS_MODULE,
.name = BT541_TS_DEVICE,
.of_match_table = tsp_dt_ids,
#if defined(CONFIG_PM) && !defined(CONFIG_HAS_EARLYSUSPEND)
.pm = &bt541_ts_pm_ops,
#endif
},
};
extern unsigned int lpcharge;
static int __init bt541_ts_init(void)
{
pr_info("[TSP]: %s\n", __func__);
if (!lpcharge)
return i2c_add_driver(&bt541_ts_driver);
else
return 0;
}
static void __exit bt541_ts_exit(void)
{
i2c_del_driver(&bt541_ts_driver);
}
module_init(bt541_ts_init);
module_exit(bt541_ts_exit);
MODULE_DESCRIPTION("touch-screen device driver using i2c interface");
MODULE_AUTHOR("<mika.kim@samsung.com>");
MODULE_LICENSE("GPL");
|