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
|
/* abov_touchkey.c -- Linux driver for abov chip as touchkey
*
* Copyright (C) 2013 Samsung Electronics Co.Ltd
* Author: Junkyeong Kim <jk0430.kim@samsung.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* 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.
*
*/
#include <linux/delay.h>
#include <linux/firmware.h>
#include <linux/gpio.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/input.h>
#include <linux/input/mt.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <asm/unaligned.h>
#include <linux/regulator/consumer.h>
#include <linux/wakelock.h>
#include <linux/pinctrl/consumer.h>
#include <linux/hall.h>
#ifdef CONFIG_OF
#include <linux/of_gpio.h>
#endif
#undef CONFIG_INPUT_BOOSTER
#ifdef CONFIG_INPUT_BOOSTER
#include <linux/input/input_booster.h>
#endif
/* registers */
#define ABOV_BTNSTATUS 0x00
#define ABOV_FW_VER 0x01
#define ABOV_PCB_VER 0x02
#define ABOV_COMMAND 0x03
#define ABOV_THRESHOLD 0x04
#define ABOV_SETIDAC 0x06
#define ABOV_DIFFDATA 0x0A
#define ABOV_KEY_VALUE 0x10
#define ABOV_GLOVE 0x12
#define ABOV_VENDORID 0x13
#define ABOV_MODELNO 0x14
#define ABOV_RAWDATA 0x15
/* command */
#define CMD_LED_ON 0x10
#define CMD_LED_OFF 0x20
#define CMD_DATA_UPDATE 0x40
#define CMD_LED_CTRL_ON 0x60
#define CMD_LED_CTRL_OFF 0x70
#define CMD_STOP_MODE 0x80
#define CMD_GLOVE_ON 0x20
#define CMD_GLOVE_OFF 0x10
#define CMD_CRC_CHECK_START 0xAA
#define ABOV_TK_NAME "abov-touchkey"
#define FW_VERSION 0x13
#define FW_CHECKSUM_H 0x55
#define FW_CHECKSUM_L 0xA8
#define TK_FW_PATH_BIN "abov/abov_tk_royce.fw"
#define TK_FW_PATH_SDCARD "/sdcard/abov_fw.bin"
#define CRC_CHECK_WITHBOOTING
#define CRC_CHECK_FW_VER 0x10
#define ABOV_BOOT_DELAY 45
#ifdef CRC_CHECK_WITHBOOTING
#define ABOV_RESET_DELAY 100
#else
#define ABOV_RESET_DELAY 150
#endif
#define I2C_M_WR 0 /* for i2c */
enum {
BUILT_IN = 0,
SDCARD,
};
enum flip_status{
FLIP_OPEN = 0,
FLIP_CLOSE,
};
enum fw_update_status{
FW_UP_SUCCESS = 0,
FW_DOWNLOADING,
FW_UP_FAILED,
};
#ifdef CONFIG_SAMSUNG_LPM_MODE
extern int poweroff_charging;
#endif
extern unsigned int system_rev;
extern int get_lcd_attached(char *);
static int touchkey_keycode[] = { 0,
KEY_RECENT, KEY_BACK, KEY_HOMEPAGE, KEY_TKEY_WAKEUP,
};
struct abov_touchkey_platform_data {
unsigned long irq_flag;
int gpio_int;
int gpio_sda;
int gpio_scl;
int gpio_rst;
int gpio_hall;
int gpio_tkey_led_en;
struct regulator *vdd_io_vreg;
struct regulator *avdd_vreg;
const char *supply_name;
struct regulator *vtouch_3p3;
void (*input_event) (void *data);
int (*power) (struct abov_touchkey_platform_data *pdata, bool on);
int (*keyled) (bool on);
bool first_boot;
char *fw_path;
};
struct abov_tk_info {
struct i2c_client *client;
struct input_dev *input_dev;
struct abov_touchkey_platform_data *pdata;
struct mutex lock;
struct pinctrl *pinctrl;
struct device *dev;
const struct firmware *firm_data_bin;
const u8 *firm_data_ums;
char phys[32];
long firm_size;
int irq;
u16 menu_s;
u16 back_s;
u16 home_s;
u16 menu_raw;
u16 back_raw;
u16 home_raw;
int (*power) (bool on);
void (*input_event)(void *data);
int touchkey_count;
u8 fw_update_state;
u8 fw_ver;
u8 checksum_h;
u8 checksum_l;
bool enabled;
bool fw_update_possible;
bool glovemode;
bool wakeup_mode;
bool wakeup_state;
struct wake_lock report_wake_lock;
#ifdef CONFIG_DUAL_TSP
struct delayed_work switching_work;
struct notifier_block hall_ic_nb;
int flip_status;
int flip_status_current;
#endif
bool probe_done;
#ifdef CONFIG_INPUT_BOOSTER
struct input_booster *tkey_booster;
#endif
};
struct device *sec_device_create(void *drvdata, const char *fmt);
static int abov_touchkey_led_status;
static int abov_touchled_cmd_reserved;
static int abov_tk_suspend(struct device *dev);
static int abov_tk_input_open(struct input_dev *dev);
static void abov_tk_input_close(struct input_dev *dev);
int abov_power(struct abov_touchkey_platform_data *pdata, bool on);
#ifdef CONFIG_DUAL_TSP
static void abov_switching_tkey_work(struct work_struct *work);
static int abov_hall_ic_notify(struct notifier_block *nb,
unsigned long flip_cover, void *v);
static struct abov_tk_info *tkey_driver = NULL;
void abov_set_tkey_info(struct abov_tk_info *info)
{
if(info != NULL)
tkey_driver = info;
else
pr_info("%s : tkey info is null\n", __func__);
}
static struct abov_tk_info *abov_get_tkey_info(void)
{
return tkey_driver;
}
#endif
static int abov_glove_mode_enable(struct i2c_client *client, u8 cmd)
{
return i2c_smbus_write_byte_data(client, ABOV_GLOVE, cmd);
}
static int abov_tk_i2c_read(struct i2c_client *client,
u8 reg, u8 *val, unsigned int len)
{
struct abov_tk_info *info = i2c_get_clientdata(client);
struct i2c_msg msg;
int ret;
int retry = 3;
mutex_lock(&info->lock);
msg.addr = client->addr;
msg.flags = I2C_M_WR;
msg.len = 1;
msg.buf = ®
while (retry--) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret >= 0)
break;
dev_err(&client->dev, "%s fail(address set)(%d)\n",
__func__, retry);
msleep(10);
}
if (ret < 0) {
mutex_unlock(&info->lock);
return ret;
}
retry = 3;
msg.flags = 1;/*I2C_M_RD*/
msg.len = len;
msg.buf = val;
while (retry--) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret >= 0) {
mutex_unlock(&info->lock);
return 0;
}
dev_err(&client->dev, "%s fail(data read)(%d)\n",
__func__, retry);
msleep(10);
}
mutex_unlock(&info->lock);
return ret;
}
static int abov_tk_i2c_write(struct i2c_client *client,
u8 reg, u8 *val, unsigned int len)
{
struct abov_tk_info *info = i2c_get_clientdata(client);
struct i2c_msg msg[1];
unsigned char data[2];
int ret;
int retry = 3;
mutex_lock(&info->lock);
data[0] = reg;
data[1] = *val;
msg->addr = client->addr;
msg->flags = I2C_M_WR;
msg->len = 2;
msg->buf = data;
while (retry--) {
ret = i2c_transfer(client->adapter, msg, 1);
if (ret >= 0) {
mutex_unlock(&info->lock);
return 0;
}
dev_err(&client->dev, "%s fail(%d)\n",
__func__, retry);
msleep(10);
}
mutex_unlock(&info->lock);
return ret;
}
static void release_all_fingers(struct abov_tk_info *info)
{
struct i2c_client *client = info->client;
int i;
dev_dbg(&client->dev, "[TK] %s\n", __func__);
for (i = 1; i < info->touchkey_count; i++) {
input_report_key(info->input_dev,
touchkey_keycode[i], 0);
}
input_sync(info->input_dev);
#ifdef CONFIG_INPUT_BOOSTER
if (info->tkey_booster && info->tkey_booster->dvfs_set)
info->tkey_booster->dvfs_set(info->tkey_booster, 2);
#endif
}
static void abov_tk_reset_for_bootmode(struct abov_tk_info *info)
{
info->pdata->power(info->pdata, false);
msleep(50);
info->pdata->power(info->pdata, true);
}
static void abov_tk_reset(struct abov_tk_info *info)
{
struct i2c_client *client = info->client;
if (info->enabled == false)
return;
dev_notice(&client->dev, "%s++\n", __func__);
disable_irq_nosync(info->irq);
info->enabled = false;
release_all_fingers(info);
abov_tk_reset_for_bootmode(info);
msleep(ABOV_RESET_DELAY);
if (info->glovemode)
abov_glove_mode_enable(client, CMD_GLOVE_ON);
info->enabled = true;
enable_irq(info->irq);
dev_notice(&client->dev, "%s--\n", __func__);
}
static irqreturn_t abov_tk_interrupt(int irq, void *dev_id)
{
struct abov_tk_info *info = dev_id;
struct i2c_client *client = info->client;
int ret, retry;
u8 buf;
bool press = 0;
u8 key_data[info->touchkey_count];
u8 key_press[info->touchkey_count];
int i;
ret = abov_tk_i2c_read(client, ABOV_KEY_VALUE, &buf, 1);
if (ret < 0) {
retry = 3;
while (retry--) {
dev_err(&client->dev, "%s read fail(%d)\n",
__func__, retry);
ret = abov_tk_i2c_read(client, ABOV_KEY_VALUE, &buf, 1);
if (ret == 0)
break;
else
msleep(10);
}
if (retry == 0) {
abov_tk_reset(info);
return IRQ_HANDLED;
}
}
/* concept for L OS screen pinning (multi key)
*
* bit 7 6 5 4 3 2 1 0
* event - double home home back back menu menu
* - tab press release press release press release
*/
for (i = 1; i < info->touchkey_count; i++) {
if (i == 4) {
/* double tab event has only 1 bit */
key_data[i] = (buf >> ((i - 1) * 2)) & 0x01;
key_press[i] = key_data[i];
} else {
key_data[i] = (buf >> ((i - 1) * 2)) & 0x03;
key_press[i] = !(key_data[i] % 2);
}
if (key_data[i]) {
press |= key_press[i];
input_report_key(info->input_dev,
touchkey_keycode[i], key_press[i]);
#ifdef CONFIG_SAMSUNG_PRODUCT_SHIP
dev_info(&client->dev, "key %s ver:0x%x\n",
key_press[i] ? "P" : "R",
info->fw_ver);
#else
dev_info(&client->dev, "key %d %s ver:0x%x\n",
touchkey_keycode[i],
key_press[i] ? "P" : "R",
info->fw_ver);
#endif
}
}
input_sync(info->input_dev);
if (key_press[4]){
dev_info(&client->dev, "Double tab wakeup\n");
wake_lock_timeout(&info->report_wake_lock, 3 * HZ);
}
#ifdef CONFIG_INPUT_BOOSTER
if (info->tkey_booster && info->tkey_booster->dvfs_set)
info->tkey_booster->dvfs_set(info->tkey_booster, press);
#endif
return IRQ_HANDLED;
}
#ifdef CONFIG_INPUT_BOOSTER
static ssize_t boost_level_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
int val, stage;
struct dvfs value;
if (!info->tkey_booster) {
dev_err(&info->client->dev,
"%s: booster is NULL\n", __func__);
return count;
}
sscanf(buf, "%d", &val);
stage = 1 << val;
if (!(info->tkey_booster->dvfs_stage & stage)) {
dev_info(&info->client->dev,
"%s: wrong cmd %d\n", __func__, val);
return count;
}
info->tkey_booster->dvfs_boost_mode = stage;
dev_info(&info->client->dev,
"%s: dvfs_boost_mode = 0x%X\n",
__func__, info->tkey_booster->dvfs_boost_mode);
if (info->tkey_booster->dvfs_boost_mode == DVFS_STAGE_NONE) {
if (info->tkey_booster->dvfs_set)
info->tkey_booster->dvfs_set(info->tkey_booster, 2);
} else if (info->tkey_booster->dvfs_boost_mode == DVFS_STAGE_SINGLE) {
input_booster_get_default_setting("head", &value);
info->tkey_booster->dvfs_freq = value.cpu_freq;
dev_info(&info->client->dev,
"%s: boost_mode SINGLE, dvfs_freq = %d\n",
__func__, info->tkey_booster->dvfs_freq);
} else if (info->tkey_booster->dvfs_boost_mode == DVFS_STAGE_DUAL) {
input_booster_get_default_setting("tail", &value);
info->tkey_booster->dvfs_freq = value.cpu_freq;
dev_info(&info->client->dev,
"%s: boost_mode DUAL, dvfs_freq = %d\n",
__func__, info->tkey_booster->dvfs_freq);
}
return count;
}
#endif
static ssize_t touchkey_led_control(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
int data;
int ret;
u8 cmd;
ret = sscanf(buf, "%d", &data);
if (ret != 1) {
dev_err(&client->dev, "%s: cmd read err\n", __func__);
return count;
}
if (!(data == 0 || data == 1)) {
dev_err(&client->dev, "%s: wrong command(%d)\n",
__func__, data);
return count;
}
if (data == 1)
cmd = CMD_LED_ON;
else
cmd = CMD_LED_OFF;
if (!info->enabled){
abov_touchled_cmd_reserved = 1;
goto out;
}
ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
if (ret < 0){
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
abov_touchled_cmd_reserved = 1;
goto out;
}
abov_touchled_cmd_reserved = 0;
dev_info(&client->dev, "%s %s\n", __func__, data ? "ON" : "OFF");
out:
abov_touchkey_led_status = cmd;
return count;
}
static ssize_t touchkey_threshold_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
u8 r_buf;
int ret;
ret = abov_tk_i2c_read(client, ABOV_THRESHOLD, &r_buf, 1);
if (ret < 0) {
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
r_buf = 0;
}
return sprintf(buf, "%d\n", r_buf);
}
static void get_diff_data(struct abov_tk_info *info)
{
struct i2c_client *client = info->client;
u8 r_buf[6];
int ret;
ret = abov_tk_i2c_read(client, ABOV_DIFFDATA, r_buf, 6);
if (ret < 0) {
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
info->menu_s = 0;
info->back_s = 0;
info->home_s = 0;
return;
}
info->menu_s = (r_buf[0] << 8) | r_buf[1];
info->back_s = (r_buf[2] << 8) | r_buf[3];
info->home_s = (r_buf[4] << 8) | r_buf[5];
}
static ssize_t touchkey_menu_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_diff_data(info);
return sprintf(buf, "%d\n", info->menu_s);
}
static ssize_t touchkey_back_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_diff_data(info);
return sprintf(buf, "%d\n", info->back_s);
}
static ssize_t touchkey_home_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_diff_data(info);
return sprintf(buf, "%d\n", info->home_s);
}
static void get_raw_data(struct abov_tk_info *info)
{
struct i2c_client *client = info->client;
u8 r_buf[6];
int ret;
ret = abov_tk_i2c_read(client, ABOV_RAWDATA, r_buf, 6);
if (ret < 0) {
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
info->menu_raw = 0;
info->back_raw = 0;
info->home_raw = 0;
return;
}
info->menu_raw = (r_buf[0] << 8) | r_buf[1];
info->back_raw = (r_buf[2] << 8) | r_buf[3];
info->home_raw = (r_buf[4] << 8) | r_buf[5];
}
static ssize_t touchkey_menu_raw_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_raw_data(info);
return sprintf(buf, "%d\n", info->menu_raw);
}
static ssize_t touchkey_back_raw_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_raw_data(info);
return sprintf(buf, "%d\n", info->back_raw);
}
static ssize_t touchkey_home_raw_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
get_raw_data(info);
return sprintf(buf, "%d\n", info->home_raw);
}
static ssize_t bin_fw_ver(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
dev_dbg(&client->dev, "fw version bin : 0x%x\n", FW_VERSION);
return sprintf(buf, "0x%02x\n", FW_VERSION);
}
int get_tk_fw_version(struct abov_tk_info *info, bool bootmode)
{
struct i2c_client *client = info->client;
u8 buf;
int ret;
int retry = 3;
ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
if (ret < 0) {
while (retry--) {
dev_err(&client->dev, "%s read fail(%d)\n",
__func__, retry);
if (!bootmode)
abov_tk_reset(info);
else
return -1;
ret = abov_tk_i2c_read(client, ABOV_FW_VER, &buf, 1);
if (ret == 0)
break;
}
if (retry == 0)
return -1;
}
info->fw_ver = buf;
dev_info(&client->dev, "%s : 0x%x\n", __func__, buf);
return 0;
}
static ssize_t read_fw_ver(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
int ret;
if(info->flip_status == FLIP_CLOSE || !info->fw_ver){
ret = get_tk_fw_version(info, false);
if (ret < 0) {
dev_err(&client->dev, "%s read fail\n", __func__);
info->fw_ver = 0;
}
}
return sprintf(buf, "0x%02x\n", info->fw_ver);
}
static int abov_load_fw(struct abov_tk_info *info, u8 cmd)
{
struct i2c_client *client = info->client;
struct file *fp;
mm_segment_t old_fs;
long fsize, nread;
int ret = 0;
switch(cmd) {
case BUILT_IN:
ret = request_firmware(&info->firm_data_bin,
info->pdata->fw_path, &client->dev);
if (ret) {
dev_err(&client->dev,
"%s request_firmware fail(%d)\n", __func__, cmd);
return ret;
}
info->firm_size = info->firm_data_bin->size;
break;
case SDCARD:
old_fs = get_fs();
set_fs(get_ds());
fp = filp_open(TK_FW_PATH_SDCARD, O_RDONLY, S_IRUSR);
if (IS_ERR(fp)) {
dev_err(&client->dev,
"%s %s open error\n", __func__, TK_FW_PATH_SDCARD);
ret = -ENOENT;
goto fail_sdcard_open;
}
fsize = fp->f_path.dentry->d_inode->i_size;
info->firm_data_ums = kzalloc((size_t)fsize, GFP_KERNEL);
if (!info->firm_data_ums) {
dev_err(&client->dev,
"%s fail to kzalloc for fw\n", __func__);
ret = -ENOMEM;
goto fail_sdcard_kzalloc;
}
nread = vfs_read(fp,
(char __user *)info->firm_data_ums, fsize, &fp->f_pos);
if (nread != fsize) {
dev_err(&client->dev,
"%s fail to vfs_read file\n", __func__);
ret = -EINVAL;
goto fail_sdcard_size;
}
filp_close(fp, current->files);
set_fs(old_fs);
info->firm_size = nread;
break;
default:
ret = -1;
break;
}
dev_notice(&client->dev, "fw_size : %lu\n", info->firm_size);
dev_notice(&client->dev, "%s success\n", __func__);
return ret;
fail_sdcard_size:
kfree(&info->firm_data_ums);
fail_sdcard_kzalloc:
filp_close(fp, current->files);
fail_sdcard_open:
set_fs(old_fs);
return ret;
}
static void abov_release_fw(struct abov_tk_info *info, u8 cmd)
{
switch(cmd) {
case BUILT_IN:
release_firmware(info->firm_data_bin);
break;
case SDCARD:
kfree(info->firm_data_ums);
break;
default:
break;
}
}
static int abov_tk_check_busy(struct abov_tk_info *info)
{
int ret, count = 0;
unsigned char val = 0x00;
do {
ret = i2c_master_recv(info->client, &val, sizeof(val));
if (val) {
count++;
} else {
break;
}
} while(1);
if (count > 1000)
pr_err("%s: busy %d\n", __func__, count);
return ret;
}
static int abov_tk_i2c_read_checksum(struct abov_tk_info *info)
{
unsigned char data[6] = {0xAC, 0x9E, 0x10, 0x00, 0x3F, 0xFF};
unsigned char checksum[5] = {0, };
int ret;
unsigned char reg = 0x00;
i2c_master_send(info->client, data, 6);
usleep_range(5 * 1000, 5 * 1000);
abov_tk_check_busy(info);
ret = abov_tk_i2c_read(info->client, reg, checksum, 5);
dev_info(&info->client->dev, "%s: ret:%d [%X][%X][%X][%X][%X]\n",
__func__, ret, checksum[0], checksum[1], checksum[2]
, checksum[3], checksum[4]);
info->checksum_h = checksum[3];
info->checksum_l = checksum[4];
return 0;
}
static int abov_tk_fw_write(struct abov_tk_info *info, unsigned char *addrH,
unsigned char *addrL, unsigned char *val)
{
int length = 36, ret = 0;
unsigned char data[36];
data[0] = 0xAC;
data[1] = 0x7A;
memcpy(&data[2], addrH, 1);
memcpy(&data[3], addrL, 1);
memcpy(&data[4], val, 32);
ret = i2c_master_send(info->client, data, length);
if (ret != length) {
pr_err("%s: write fail[%x%x], %d\n", __func__, *addrH, *addrL, ret);
return ret;
}
usleep_range(2 * 1000, 2 * 1000);
abov_tk_check_busy(info);
return 0;
}
static int abov_tk_fw_mode_enter(struct abov_tk_info *info)
{
unsigned char data[3] = {0xAC, 0x5B, 0x2D};
int ret = 0;
ret = i2c_master_send(info->client, data, 3);
if (ret != 3) {
pr_err("%s: write fail %d\n", __func__, ret);
return ret;
}
return 0;
}
static int abov_tk_fw_update(struct abov_tk_info *info, u8 cmd)
{
int ret, ii = 0;
int count;
unsigned short address;
unsigned char addrH, addrL;
unsigned char data[32] = {0, };
count = info->firm_size / 32;
address = 0x1000;
abov_power(info->pdata, 0);
msleep(30);
abov_power(info->pdata, 1);
usleep_range(ABOV_BOOT_DELAY * 1000, ABOV_BOOT_DELAY * 1000);
ret = abov_tk_fw_mode_enter(info);
pr_info("%s: enter BL mode, ret = %d\n", __func__, ret);
msleep(1100);
for (ii = 0; ii < count; ii++) {
addrH = (unsigned char)((address >> 8) & 0xFF);
addrL = (unsigned char)(address & 0xFF);
if (cmd == BUILT_IN)
memcpy(data, &info->firm_data_bin->data[ii * 32], 32);
else if(cmd == SDCARD)
memcpy(data, &info->firm_data_ums[ii * 32], 32);
ret = abov_tk_fw_write(info, &addrH, &addrL, data);
if (ret < 0) {
pr_err("%s: err, no device : %d\n", __func__, ret);
return ret;
}
usleep_range(3 * 1000, 3 * 1000);
abov_tk_check_busy(info);
address += 0x20;
memset(data, 0, 32);
}
ret = abov_tk_i2c_read_checksum(info);
return ret;
}
static int abov_flash_fw(struct abov_tk_info *info, bool probe, u8 cmd)
{
struct i2c_client *client = info->client;
int retry = 3;
int ret;
ret = get_tk_fw_version(info, probe);
if (ret)
info->fw_ver = 0;
ret = abov_load_fw(info, cmd);
if (ret) {
dev_err(&client->dev,
"%s fw load fail\n", __func__);
return ret;
}
while (retry--) {
ret = abov_tk_fw_update(info, cmd);
if (ret < 0)
break;
if (cmd == BUILT_IN) {
if ((info->checksum_h != FW_CHECKSUM_H) ||
(info->checksum_l != FW_CHECKSUM_L)) {
dev_err(&client->dev,
"%s checksum fail. IC(0x%x,0x%x), BN(0x%x,0x%x) retry:%d\n",
__func__, info->checksum_h, info->checksum_l,
FW_CHECKSUM_H, FW_CHECKSUM_L, retry);
ret = -1;
continue;
}
}
abov_tk_reset_for_bootmode(info);
msleep(ABOV_RESET_DELAY);
ret = get_tk_fw_version(info, true);
if (ret) {
dev_err(&client->dev, "%s fw version read fail\n", __func__);
ret = -1;
continue;
}
if (info->fw_ver == 0) {
dev_err(&client->dev, "%s fw version fail (0x%x)\n",
__func__, info->fw_ver);
ret = -1;
continue;
}
if ((cmd == BUILT_IN) && (info->fw_ver != FW_VERSION)) {
dev_err(&client->dev, "%s fw version fail 0x%x, 0x%x\n",
__func__, info->fw_ver, FW_VERSION);
ret = -1;
continue;
}
ret = 0;
break;
}
abov_release_fw(info, cmd);
return ret;
}
static ssize_t touchkey_fw_update(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
int ret;
u8 cmd;
if (info->fw_update_possible == false) {
dev_err(&client->dev, "%s fail (no reset pin)\n", __func__);
info->fw_update_state = FW_UP_FAILED;
goto touchkey_fw_update_out;
}
switch(*buf) {
case 's':
case 'S':
cmd = BUILT_IN;
break;
case 'i':
case 'I':
cmd = SDCARD;
break;
default:
info->fw_update_state = FW_UP_FAILED;
goto touchkey_fw_update_out;
}
info->fw_update_state = FW_DOWNLOADING;
disable_irq(info->irq);
info->enabled = false;
ret = abov_flash_fw(info, false, cmd);
if (info->glovemode)
abov_glove_mode_enable(client, CMD_GLOVE_ON);
info->enabled = true;
enable_irq(info->irq);
if (ret) {
dev_err(&client->dev, "%s fail\n", __func__);
info->fw_update_state = FW_UP_FAILED;
} else {
dev_notice(&client->dev, "%s success\n", __func__);
info->fw_update_state = FW_UP_SUCCESS;
}
touchkey_fw_update_out:
dev_dbg(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
return count;
}
static ssize_t touchkey_fw_update_status(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
int count = 0;
dev_info(&client->dev, "%s : %d\n", __func__, info->fw_update_state);
if (info->fw_update_state == FW_UP_SUCCESS)
count = sprintf(buf, "PASS\n");
else if (info->fw_update_state == FW_DOWNLOADING)
count = sprintf(buf, "Downloading\n");
else if (info->fw_update_state == FW_UP_FAILED)
count = sprintf(buf, "Fail\n");
return count;
}
static ssize_t abov_glove_mode(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
struct i2c_client *client = info->client;
int scan_buffer;
int ret;
u8 cmd;
ret = sscanf(buf, "%d", &scan_buffer);
if (ret != 1) {
dev_err(&client->dev, "%s: cmd read err\n", __func__);
return count;
}
if (!(scan_buffer == 0 || scan_buffer == 1)) {
dev_err(&client->dev, "%s: wrong command(%d)\n",
__func__, scan_buffer);
return count;
}
if (!info->enabled)
return count;
if (info->glovemode == scan_buffer) {
dev_info(&client->dev, "%s same command(%d)\n",
__func__, scan_buffer);
return count;
}
if (scan_buffer == 1) {
dev_notice(&client->dev, "%s glove mode\n", __func__);
cmd = CMD_GLOVE_ON;
} else {
dev_notice(&client->dev, "%s normal mode\n", __func__);
cmd = CMD_GLOVE_OFF;
}
ret = abov_glove_mode_enable(client, cmd);
if (ret < 0) {
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
return count;
}
info->glovemode = scan_buffer;
return count;
}
static ssize_t abov_glove_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
return sprintf(buf, "%d\n", info->glovemode);
}
static ssize_t abov_wakeup_mode(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
int scan_buffer;
int ret;
ret = sscanf(buf, "%d", &scan_buffer);
if (ret != 1)
goto err;
if (!(scan_buffer == 0 || scan_buffer == 1))
goto err;
if(scan_buffer == 1)
info->wakeup_mode = true;
else
info->wakeup_mode = false;
dev_info(dev, "%s : Set to %s mode\n",
__func__, info->wakeup_mode ? "wakeup" : "normal");
err:
return count;
}
static ssize_t abov_wakeup_mode_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct abov_tk_info *info = dev_get_drvdata(dev);
return sprintf(buf, "%d\n", info->wakeup_mode);
}
static DEVICE_ATTR(touchkey_threshold, S_IRUGO, touchkey_threshold_show, NULL);
static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
touchkey_led_control);
static DEVICE_ATTR(touchkey_recent, S_IRUGO, touchkey_menu_show, NULL);
static DEVICE_ATTR(touchkey_back, S_IRUGO, touchkey_back_show, NULL);
static DEVICE_ATTR(touchkey_home, S_IRUGO, touchkey_home_show, NULL);
static DEVICE_ATTR(touchkey_recent_raw, S_IRUGO, touchkey_menu_raw_show, NULL);
static DEVICE_ATTR(touchkey_back_raw, S_IRUGO, touchkey_back_raw_show, NULL);
static DEVICE_ATTR(touchkey_home_raw, S_IRUGO, touchkey_home_raw_show, NULL);
static DEVICE_ATTR(touchkey_firm_version_phone, S_IRUGO, bin_fw_ver, NULL);
static DEVICE_ATTR(touchkey_firm_version_panel, S_IRUGO, read_fw_ver, NULL);
static DEVICE_ATTR(touchkey_firm_update, S_IRUGO | S_IWUSR | S_IWGRP, NULL,
touchkey_fw_update);
static DEVICE_ATTR(touchkey_firm_update_status, S_IRUGO | S_IWUSR | S_IWGRP,
touchkey_fw_update_status, NULL);
static DEVICE_ATTR(glove_mode, S_IRUGO | S_IWUSR | S_IWGRP,
abov_glove_mode_show, abov_glove_mode);
static DEVICE_ATTR(two_touch_wakeup_mode, S_IRUGO | S_IWUSR | S_IWGRP,
abov_wakeup_mode_show, abov_wakeup_mode);
#ifdef CONFIG_INPUT_BOOSTER
static DEVICE_ATTR(boost_level,
S_IWUSR | S_IWGRP, NULL, boost_level_store);
#endif
static struct attribute *sec_touchkey_attributes[] = {
&dev_attr_touchkey_threshold.attr,
&dev_attr_brightness.attr,
&dev_attr_touchkey_recent.attr,
&dev_attr_touchkey_back.attr,
&dev_attr_touchkey_home.attr,
&dev_attr_touchkey_recent_raw.attr,
&dev_attr_touchkey_back_raw.attr,
&dev_attr_touchkey_home_raw.attr,
&dev_attr_touchkey_firm_version_phone.attr,
&dev_attr_touchkey_firm_version_panel.attr,
&dev_attr_touchkey_firm_update.attr,
&dev_attr_touchkey_firm_update_status.attr,
&dev_attr_glove_mode.attr,
&dev_attr_two_touch_wakeup_mode.attr,
#ifdef CONFIG_INPUT_BOOSTER
&dev_attr_boost_level.attr,
#endif
NULL,
};
static struct attribute_group sec_touchkey_attr_group = {
.attrs = sec_touchkey_attributes,
};
static int abov_tk_fw_check(struct abov_tk_info *info)
{
struct i2c_client *client = info->client;
int ret;
#ifdef CRC_CHECK_WITHBOOTING
u8 checksum_cmd;
int i;
ret = abov_tk_i2c_read(client, ABOV_FW_VER, &checksum_cmd, 1);
if (ret < 0) {
dev_err(&client->dev, "%s fail(%d)\n", __func__, ret);
checksum_cmd = 0;
}
dev_info(&client->dev, "%s FW ver = 0x%x\n", __func__, checksum_cmd);
/* CRC Check */
if(checksum_cmd >= CRC_CHECK_FW_VER) {
checksum_cmd = CMD_CRC_CHECK_START;
ret = abov_tk_i2c_write(client, ABOV_FW_VER, &checksum_cmd, 1);
if (ret < 0) {
dev_err(&client->dev,
"%s %d fail(%d)\n", __func__, __LINE__, ret);
checksum_cmd = 0;
}
msleep(40);
for (i = 0; i < 30; i++) {
/* Read 0x01 to check pass */
ret = abov_tk_i2c_read(client, ABOV_FW_VER, &checksum_cmd, 1);
if (ret < 0) {
dev_err(&client->dev,
"%s %d fail(%d)\n", __func__, __LINE__, ret);
checksum_cmd = 0;
}
if (checksum_cmd != CMD_CRC_CHECK_START) {
dev_info(&client->dev,
"%s checksum result = 0x%x, %d\n",
__func__, checksum_cmd, i);
break;
}
usleep_range(5000, 5000);
}
} else {
msleep(80);
}
#endif
ret = get_tk_fw_version(info, true);
if (ret) {
dev_err(&client->dev,
"%s: i2c fail...[%d], addr[%d]\n",
__func__, ret, info->client->addr);
}
if (!info->fw_update_possible)
return ret;
if (ret || info->fw_ver < FW_VERSION || info->fw_ver > 0xf0) {
dev_err(&client->dev, "excute tk firmware update (0x%x -> 0x%x\n",
info->fw_ver, FW_VERSION);
ret = abov_flash_fw(info, true, BUILT_IN);
if (ret) {
dev_err(&client->dev,
"failed to abov_flash_fw (%d)\n", ret);
} else {
dev_info(&client->dev,
"fw update success\n");
}
}
return ret;
}
int abov_power(struct abov_touchkey_platform_data *pdata, bool on)
{
int ret = 0;
if (pdata->vtouch_3p3) {
if (on){
if (!pdata->first_boot && regulator_is_enabled(pdata->vtouch_3p3))
pr_err("%s: vtouch_3p3 is already enabled.\n",__func__);
else {
ret = regulator_enable(pdata->vtouch_3p3);
if (ret){
pr_err("%s: failed to enable vtouch_3p3. %d\n",
__func__, ret);
goto err;
}
}
} else {
if (regulator_is_enabled(pdata->vtouch_3p3)){
ret = regulator_disable(pdata->vtouch_3p3);
if (ret){
pr_err("%s: failed to disable vtouch_3p3. %d\n",
__func__, ret);
goto err;
}
} else {
pr_err("%s: vtouch_3p3 is already disabled.\n",__func__);
}
}
pr_info("%s: vtouch_3p3 is %s\n", __func__,
regulator_is_enabled(pdata->vtouch_3p3) ? "enabled" : "disabled");
}
err:
return ret;
}
static int abov_pinctrl_configure(struct abov_tk_info *info,
bool active)
{
struct pinctrl_state *set_state;
int retval;
if (active) {
set_state =
pinctrl_lookup_state(info->pinctrl,
"on_irq");
if (IS_ERR(set_state)) {
pr_err("%s: cannot get ts pinctrl active state\n", __func__);
return PTR_ERR(set_state);
}
} else {
set_state =
pinctrl_lookup_state(info->pinctrl,
"off_irq");
if (IS_ERR(set_state)) {
pr_err("%s: cannot get gpiokey pinctrl sleep state\n", __func__);
return PTR_ERR(set_state);
}
}
retval = pinctrl_select_state(info->pinctrl, set_state);
if (retval) {
pr_err("%s: cannot set ts pinctrl active state\n", __func__);
return retval;
}
return 0;
}
int abov_gpio_reg_init(struct device *dev,
struct abov_touchkey_platform_data *pdata)
{
int ret = 0;
ret = gpio_request(pdata->gpio_int, "tkey_gpio_int");
if(ret < 0){
dev_err(dev, "unable to request gpio_int\n");
return ret;
}
pdata->vtouch_3p3 = regulator_get(dev, pdata->supply_name);
if (IS_ERR(pdata->vtouch_3p3)) {
pdata->vtouch_3p3 = NULL;
dev_err(dev, "pdata->vtouch_3p3 get error\n");
return -1;
}
pdata->power = abov_power;
return ret;
}
#ifdef CONFIG_OF
static int abov_parse_dt(struct device *dev,
struct abov_touchkey_platform_data *pdata)
{
struct device_node *np = dev->of_node;
int retval = 0;
pdata->gpio_int = of_get_named_gpio(np, "abov,irq-gpio", 0);
if(pdata->gpio_int < 0){
dev_err(dev, "unable to get gpio_int\n");
return pdata->gpio_int;
}
pdata->gpio_scl = of_get_named_gpio(np, "abov,scl-gpio", 0);
if(pdata->gpio_scl < 0){
dev_err(dev, "unable to get gpio_scl\n");
return pdata->gpio_scl;
}
pdata->gpio_sda = of_get_named_gpio(np, "abov,sda-gpio", 0);
if(pdata->gpio_sda < 0){
dev_err(dev, "unable to get gpio_sda\n");
return pdata->gpio_sda;
}
pdata->gpio_hall = of_get_named_gpio(np, "abov,hall_flip-gpio", 0);
if(pdata->gpio_hall < 0){
dev_err(dev, "unable to get gpio_hall\n");
}
retval = of_property_read_string(np, "abov,fw_path", (const char **)&pdata->fw_path);
if (retval) {
dev_err(dev, "touchkey:failed to read fw_path %d\n", retval);
pdata->fw_path = TK_FW_PATH_BIN;
}
dev_info(dev, "%s: fw path %s\n", __func__, pdata->fw_path);
retval = of_property_read_string(np, "abov,vtouch_3p3", &pdata->supply_name);
if (retval)
dev_err(dev, "unable to get name of vtouch_3p3, %d\n", retval);
dev_info(dev, "%s: gpio_int:%d, gpio_scl:%d, gpio_sda:%d\n",
__func__, pdata->gpio_int, pdata->gpio_scl, pdata->gpio_sda);
return retval;
}
#else
static int abov_parse_dt(struct device *dev,
struct abov_touchkey_platform_data *pdata)
{
return -ENODEV;
}
#endif
static int abov_tk_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
struct abov_tk_info *info;
struct input_dev *input_dev;
int ret = 0;
pr_info("%s\n",__func__);
#if 0
if (get_lcd_attached("GET") == 0) {
dev_err(&client->dev, "%s : get_lcd_attached()=0 \n", __func__);
return -EIO;
}
#endif
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev,
"i2c_check_functionality fail\n");
return -EIO;
}
info = kzalloc(sizeof(struct abov_tk_info), GFP_KERNEL);
if (!info) {
dev_err(&client->dev, "Failed to allocate memory\n");
ret = -ENOMEM;
goto err_alloc;
}
input_dev = input_allocate_device();
if (!input_dev) {
dev_err(&client->dev,
"Failed to allocate memory for input device\n");
ret = -ENOMEM;
goto err_input_alloc;
}
info->probe_done = false;
#ifdef CONFIG_DUAL_TSP
abov_set_tkey_info(info);
info->flip_status = -1;
info->flip_status_current = -1;
#endif
info->client = client;
info->input_dev = input_dev;
info->wakeup_mode = false;
if (client->dev.of_node) {
struct abov_touchkey_platform_data *pdata;
pdata = devm_kzalloc(&client->dev,
sizeof(struct abov_touchkey_platform_data), GFP_KERNEL);
if (!pdata) {
dev_err(&client->dev, "Failed to allocate memory\n");
return -ENOMEM;
}
ret = abov_parse_dt(&client->dev, pdata);
if (ret)
return ret;
info->pdata = pdata;
} else
info->pdata = client->dev.platform_data;
if (info->pdata == NULL) {
pr_err("failed to get platform data\n");
goto err_config;
}
/* Get pinctrl if target uses pinctrl */
info->pinctrl = devm_pinctrl_get(&client->dev);
if (IS_ERR(info->pinctrl)) {
if (PTR_ERR(info->pinctrl) == -EPROBE_DEFER)
return -EPROBE_DEFER;
pr_err("%s: Target does not use pinctrl\n", __func__);
info->pinctrl = NULL;
}
if (info->pinctrl) {
ret = abov_pinctrl_configure(info, true);
if (ret)
pr_err("%s: cannot set ts pinctrl active state\n", __func__);
}
ret = abov_gpio_reg_init(&client->dev, info->pdata);
if(ret){
dev_err(&client->dev, "failed to init reg\n");
goto pwr_config;
}
info->pdata->first_boot = true;
info->pdata->power(info->pdata, true);
info->pdata->first_boot = false;
client->irq = gpio_to_irq(info->pdata->gpio_int);
info->irq = -1;
mutex_init(&info->lock);
wake_lock_init(&info->report_wake_lock, WAKE_LOCK_SUSPEND, "report_wake_lock");
info->fw_update_possible = true;
info->input_event = info->pdata->input_event;
info->touchkey_count = sizeof(touchkey_keycode) / sizeof(int);
i2c_set_clientdata(client, info);
ret = abov_tk_fw_check(info);
if (ret) {
dev_err(&client->dev,
"failed to firmware check (%d)\n", ret);
goto err_reg_input_dev;
}
snprintf(info->phys, sizeof(info->phys),
"%s/input0", dev_name(&client->dev));
input_dev->name = "sec_touchkey";
input_dev->phys = info->phys;
input_dev->id.bustype = BUS_HOST;
input_dev->dev.parent = &client->dev;
input_dev->open = abov_tk_input_open;
input_dev->close = abov_tk_input_close;
set_bit(EV_KEY, input_dev->evbit);
set_bit(KEY_RECENT, input_dev->keybit);
set_bit(KEY_BACK, input_dev->keybit);
set_bit(KEY_HOMEPAGE, input_dev->keybit);
set_bit(KEY_TKEY_WAKEUP, input_dev->keybit);
set_bit(EV_LED, input_dev->evbit);
set_bit(LED_MISC, input_dev->ledbit);
input_set_drvdata(input_dev, info);
ret = input_register_device(input_dev);
if (ret) {
dev_err(&client->dev, "failed to register input dev (%d)\n",
ret);
goto err_reg_input_dev;
}
info->enabled = true;
if (!info->pdata->irq_flag) {
ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
IRQF_TRIGGER_LOW | IRQF_ONESHOT, ABOV_TK_NAME, info);
} else {
ret = request_threaded_irq(client->irq, NULL, abov_tk_interrupt,
info->pdata->irq_flag, ABOV_TK_NAME, info);
}
if (ret < 0) {
dev_err(&client->dev, "Failed to register interrupt %d\n", ret);
goto err_req_irq;
}
info->irq = client->irq;
info->dev = sec_device_create(info, "sec_touchkey");
if (IS_ERR(info->dev))
dev_err(&client->dev,
"Failed to create device for the touchkey sysfs\n");
ret = sysfs_create_group(&info->dev->kobj,
&sec_touchkey_attr_group);
if (ret)
dev_err(&client->dev, "Failed to create sysfs group\n");
ret = sysfs_create_link(&info->dev->kobj,
&info->input_dev->dev.kobj, "input");
if (ret < 0) {
dev_err(&info->client->dev,
"%s: Failed to create input symbolic link\n",
__func__);
}
#ifdef CONFIG_INPUT_BOOSTER
info->tkey_booster = input_booster_allocate(INPUT_BOOSTER_ID_TKEY);
if (!info->tkey_booster) {
dev_err(&client->dev,
"%s: Failed to alloc mem for tsp_booster\n", __func__);
goto err_get_tkey_booster;
}
#endif
#ifdef CONFIG_DUAL_TSP
if(info->pdata->gpio_hall < 0)
/* default set : tkey enable */
info->flip_status = FLIP_CLOSE;
else
info->flip_status = !(gpio_get_value(info->pdata->gpio_hall));
dev_info(&client->dev, "%s: Folder is %sed now.\n",
__func__, info->flip_status ? "clos":"open");
if (!info->flip_status)
abov_tk_suspend(&client->dev);
#endif
#ifdef CONFIG_DUAL_TSP
INIT_DELAYED_WORK(&info->switching_work, abov_switching_tkey_work);
/* Hall IC notify priority -> ftn -> register */
info->hall_ic_nb.priority = 2;
info->hall_ic_nb.notifier_call = abov_hall_ic_notify;
hall_ic_register_notify(&info->hall_ic_nb);
dev_info(&client->dev, "%s,touchkey:hall ic register",__func__);
#endif
info->probe_done = true;
pr_info("%s done\n", __func__);
return 0;
#ifdef CONFIG_INPUT_BOOSTER
/* Delete annotation when use this code later */
//input_booster_free(info->tkey_booster);
//info->tkey_booster = NULL;
err_get_tkey_booster:
#endif
err_req_irq:
input_unregister_device(input_dev);
err_reg_input_dev:
wake_lock_destroy(&info->report_wake_lock);
mutex_destroy(&info->lock);
pwr_config:
err_config:
#ifdef CONFIG_DUAL_TSP
tkey_driver = NULL;
#endif
input_free_device(input_dev);
err_input_alloc:
kfree(info);
err_alloc:
return ret;
}
static int abov_tk_remove(struct i2c_client *client)
{
struct abov_tk_info *info = i2c_get_clientdata(client);
/* if (info->enabled)
info->pdata->power(0);
*/
info->enabled = false;
if (info->irq >= 0)
free_irq(info->irq, info);
input_unregister_device(info->input_dev);
input_free_device(info->input_dev);
#ifdef CONFIG_INPUT_BOOSTER
input_booster_free(info->tkey_booster);
info->tkey_booster = NULL;
#endif
kfree(info);
return 0;
}
static void abov_tk_shutdown(struct i2c_client *client)
{
struct abov_tk_info *info = i2c_get_clientdata(client);
u8 cmd = CMD_LED_OFF;
info->enabled = false;
abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
dev_err(&info->client->dev, "%s: done \n", __func__);
}
static int abov_tk_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct abov_tk_info *info = i2c_get_clientdata(client);
u8 cmd;
int ret;
if (!info->wakeup_state)
if (!info->enabled)
return 0;
printk("Inside abov_tk_suspend \n");
dev_dbg(&info->client->dev, "%s: users=%d\n", __func__,
info->input_dev->users);
if (info->wakeup_mode && info->flip_status == FLIP_CLOSE){
/*Enter WAKEUP mode*/
cmd = CMD_STOP_MODE;
ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &cmd, 1);
if (ret < 0){
dev_err(dev,
"%s : failed to write wakeup mode(%d)\n",
__func__, ret);
return 0;
}
dev_info(dev,
"%s : success to enter tkey wakeup state\n",
__func__);
release_all_fingers(info);
enable_irq_wake(info->irq);
info->enabled = false;
info->wakeup_state = true;
}
else {
disable_irq(info->irq);
info->enabled = false;
info->wakeup_state = false;
release_all_fingers(info);
info->pdata->power(info->pdata, false);
}
return 0;
}
static int abov_tk_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct abov_tk_info *info = i2c_get_clientdata(client);
u8 led_data;
int ret;
if (info->enabled)
return 0;
#ifdef CONFIG_DUAL_TSP
if (info->flip_status == FLIP_OPEN){
dev_err(&info->client->dev,
"%s: flip is opened, so resume is ignored.\n", __func__);
return 0;
}
#endif
printk("Inside abov_tk_resume \n");
dev_dbg(&info->client->dev, "%s: users=%d\n", __func__,
info->input_dev->users);
if (info->wakeup_state){
dev_info(dev, "%s: tkey wakeup\n", __func__);
disable_irq_wake(info->irq);
info->wakeup_state = false;
disable_irq(info->irq);
release_all_fingers(info);
info->pdata->power(info->pdata, false);
usleep_range(5 * 1000, 5 * 1000);
}
info->pdata->power(info->pdata, true);
msleep(ABOV_RESET_DELAY);
info->enabled = true;
if (info->glovemode)
{
printk("********00:%d \n",abov_glove_mode_enable(client, CMD_GLOVE_ON));
}
abov_touchkey_led_status = CMD_LED_ON;
printk("abov_touchled_cmd_reserved:%d,abov_touchkey_led_status=%d \n",
abov_touchled_cmd_reserved,abov_touchkey_led_status);
if (abov_touchled_cmd_reserved && \
abov_touchkey_led_status == CMD_LED_ON) {
abov_touchled_cmd_reserved = 0;
led_data = abov_touchkey_led_status;
ret = abov_tk_i2c_write(client, ABOV_BTNSTATUS, &led_data, 1);
dev_info(&info->client->dev, "%s: LED reserved on\n", __func__);
}
enable_irq(info->irq);
return 0;
}
#ifdef CONFIG_DUAL_TSP
static void abov_switching_tkey_work(struct work_struct *work)
{
struct abov_tk_info *info =
container_of(work, struct abov_tk_info,
switching_work.work);
if (info == NULL){
pr_err("[tkey] %s: tkey info is null\n", __func__);
return;
}
if (!info->probe_done){
dev_err(&info->client->dev,
"%s: touchkey probe is not done yet\n",
__func__);
return;
}
if(info->fw_update_state == FW_DOWNLOADING){
dev_err(&info->client->dev,
"%s: tk fw update is running. switching is ignored.\n",
__func__);
return;
}
dev_info(&info->client->dev,
"%s : flip: %d(now) change to %d, tk_enabled : %d\n",
__func__,info->flip_status, info->flip_status_current, info->enabled);
if (info->flip_status != info->flip_status_current)
{
info->flip_status = info->flip_status_current;
if (info->flip_status_current == FLIP_CLOSE) {
dev_info(&info->client->dev,
"%s : flip closed. tkey must be resumed.\n",
__func__);
abov_tk_resume(&info->client->dev);
}
else {
dev_info(&info->client->dev,
"%s : flip opened. tkey must be suspended\n",
__func__);
abov_tk_suspend(&info->client->dev);
}
}
}
static int abov_hall_ic_notify(struct notifier_block *nb,
unsigned long flip_cover, void *v)
{
struct abov_tk_info *info = abov_get_tkey_info();
pr_info("%s %s\n", __func__, flip_cover ? "close" : "open");
info->flip_status_current = flip_cover;
schedule_delayed_work(&info->switching_work,
msecs_to_jiffies(1));
return 0;
}
#endif
static int abov_tk_input_open(struct input_dev *dev)
{
struct abov_tk_info *info = input_get_drvdata(dev);
dev_info(&info->client->dev, "%s: users=%d\n", __func__,
info->input_dev->users);
abov_tk_resume(&info->client->dev);
if (info->pinctrl) {
int retval;
retval = abov_pinctrl_configure(info, true);
dev_info(&info->client->dev, "failed to put the pin in active state\n");
}
return 0;
}
static void abov_tk_input_close(struct input_dev *dev)
{
struct abov_tk_info *info = input_get_drvdata(dev);
dev_info(&info->client->dev, "%s: users=%d\n", __func__,
info->input_dev->users);
abov_tk_suspend(&info->client->dev);
if (info->pinctrl) {
int retval;
retval = abov_pinctrl_configure(info, false);
dev_info(&info->client->dev, "failed to put the pin in suspend state\n");
}
}
static const struct i2c_device_id abov_tk_id[] = {
{ABOV_TK_NAME, 0},
{}
};
MODULE_DEVICE_TABLE(i2c, abov_tk_id);
#ifdef CONFIG_OF
static struct of_device_id abov_match_table[] = {
{ .compatible = "abov,abov_touchkey",},
{ },
};
#else
#define abov_match_table NULL
#endif
static struct i2c_driver abov_tk_driver = {
.probe = abov_tk_probe,
.remove = abov_tk_remove,
.shutdown = abov_tk_shutdown,
.driver = {
.name = ABOV_TK_NAME,
.of_match_table = abov_match_table,
},
.id_table = abov_tk_id,
};
static int __init touchkey_init(void)
{
#ifdef CONFIG_SAMSUNG_LPM_MODE
// if (poweroff_charging) {
// pr_notice("%s : LPM Charging Mode!!\n", __func__);
// return 0;
// }
#endif
return i2c_add_driver(&abov_tk_driver);
}
static void __exit touchkey_exit(void)
{
i2c_del_driver(&abov_tk_driver);
}
module_init(touchkey_init);
module_exit(touchkey_exit);
/* Module information */
MODULE_AUTHOR("Samsung Electronics");
MODULE_DESCRIPTION("Touchkey driver for Abov MF16xx chip");
MODULE_LICENSE("GPL");
|