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
|
/*
* wacom_i2c_func.c - Wacom G5 Digitizer Controller (I2C bus)
*
*
* 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 of the License, 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/kernel.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/delay.h>
#include "wacom.h"
#ifdef CONFIG_SEC_FACTORY
static ssize_t epen_fac_select_firmware_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
u8 fw_update_way = FW_NONE;
int ret = 0;
input_info(true, &client->dev, "%s\n", __func__);
switch (*buf) {
case 'k':
case 'K':
fw_update_way = FW_BUILT_IN;
break;
case 't':
case 'T':
fw_update_way = FW_FACTORY_GARAGE;
break;
case 'u':
case 'U':
fw_update_way = FW_FACTORY_UNIT;
break;
default:
input_err(true, &client->dev, "wrong parameter\n");
return count;
}
ret = wacom_i2c_load_fw(wac_i2c, fw_update_way);
if (ret < 0) {
input_info(true, &client->dev, "failed to load fw data\n");
goto out;
}
wacom_i2c_unload_fw(wac_i2c);
out:
return count;
}
#endif
static ssize_t epen_firm_update_status_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int status = wac_i2c->wac_feature->update_status;
int ret = 0;
input_info(true, &client->dev, "%s:(%d)\n", __func__, status);
if (status == FW_UPDATE_PASS)
ret = snprintf(buf, PAGE_SIZE, "PASS\n");
else if (status == FW_UPDATE_RUNNING)
ret = snprintf(buf, PAGE_SIZE, "DOWNLOADING\n");
else if (status == FW_UPDATE_FAIL)
ret = snprintf(buf, PAGE_SIZE, "FAIL\n");
else
ret = 0;
return ret;
}
static ssize_t epen_firm_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: 0x%x|0x%X\n", __func__,
wac_i2c->wac_feature->fw_version, wac_i2c->fw_ver_file);
return snprintf(buf, PAGE_SIZE, "%04X\t%04X\n",
wac_i2c->wac_feature->fw_version, wac_i2c->fw_ver_file);
}
static ssize_t epen_firmware_update_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
u8 fw_update_way = FW_NONE;
input_info(true, &client->dev, "%s\n", __func__);
switch (*buf) {
#ifndef CONFIG_SAMSUNG_PRODUCT_SHIP
case 'i':
case 'I':
fw_update_way = FW_IN_SDCARD;
break;
#endif
case 'k':
case 'K':
fw_update_way = FW_BUILT_IN;
break;
#ifdef CONFIG_SEC_FACTORY
case 't':
case 'T':
fw_update_way = FW_FACTORY_GARAGE;
break;
case 'u':
case 'U':
fw_update_way = FW_FACTORY_UNIT;
break;
#endif
default:
input_err(true, &client->dev, "wrong parameter\n");
return count;
}
wacom_fw_update(wac_i2c, fw_update_way, true);
return count;
}
static ssize_t epen_reset_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
val = !(!val);
if (!val)
goto out;
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
wac_i2c->function_result &= ~EPEN_EVENT_SURVEY;
wac_i2c->survey_mode = EPEN_SURVEY_MODE_NONE;
/* Reset IC */
wacom_reset_hw(wac_i2c);
/* I2C Test */
wacom_i2c_query(wac_i2c);
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
input_info(true, &client->dev,
"%s: result %d\n", __func__, wac_i2c->query_status);
return count;
out:
input_err(true, &client->dev, "%s: invalid value %d\n", __func__, val);
return count;
}
static ssize_t epen_reset_result_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int ret = 0;
if (wac_i2c->query_status) {
input_info(true, &client->dev, "%s: PASS\n", __func__);
ret = snprintf(buf, PAGE_SIZE, "PASS\n");
} else {
input_err(true, &client->dev, "%s: FAIL\n", __func__);
ret = snprintf(buf, PAGE_SIZE, "FAIL\n");
}
return ret;
}
static ssize_t epen_checksum_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
val = !(!val);
if (!val)
goto out;
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
wacom_checksum(wac_i2c);
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
input_info(true, &client->dev,
"%s: result %d\n", __func__, wac_i2c->checksum_result);
return count;
out:
input_err(true, &client->dev, "%s: invalid value %d\n", __func__, val);
return count;
}
static ssize_t epen_checksum_result_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int ret;
if (wac_i2c->checksum_result) {
input_info(true, &client->dev, "checksum, PASS\n");
ret = snprintf(buf, PAGE_SIZE, "PASS\n");
} else {
input_err(true, &client->dev, "checksum, FAIL\n");
ret = snprintf(buf, PAGE_SIZE, "FAIL\n");
}
return ret;
}
int wacom_open_test(struct wacom_i2c *wac_i2c)
{
struct i2c_client *client = wac_i2c->client;
u8 cmd = 0;
u8 buf[COM_COORD_NUM + 1] = { 0, };
int ret = 0, retry = 0;
wac_i2c->connection_check = false;
wac_i2c->fail_channel = 0;
wac_i2c->min_adc_val = 0;
wac_i2c->error_cal = 0;
wac_i2c->min_cal_val = 0;
cmd = COM_SAMPLERATE_STOP;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret <= 0) {
input_err(true, &client->dev, "failed to send stop command\n");
return -1;
}
wac_i2c->samplerate_state = false;
msleep(50);
retry = 5;
while (retry--) {
if (wacom_get_irq_state(wac_i2c) > 0) {
u8 data[COM_COORD_NUM + 1] = { 0, };
ret = wacom_i2c_recv(wac_i2c, data, COM_COORD_NUM + 1,
WACOM_I2C_MODE_NORMAL);
if (ret < 0) {
input_err(true, &client->dev,
"%s: failed to receive\n", __func__);
} else {
input_err(true, &client->dev,
"%s: ignore gabage data\n", __func__);
}
} else {
break;
}
usleep_range(4500, 5500);
}
cmd = COM_OPEN_CHECK_START;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret <= 0) {
input_err(true, &client->dev, "failed to send stop command\n");
return -1;
}
msleep(2000);
retry = 10;
cmd = COM_OPEN_CHECK_STATUS;
do {
input_info(true, &client->dev,
"read status, retry %d\n", retry);
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret != 1) {
input_err(true, &client->dev,
"failed to send cmd(ret:%d)\n", ret);
usleep_range(4500, 5500);
continue;
}
usleep_range(500, 500);
ret = wacom_i2c_recv(wac_i2c, buf, COM_COORD_NUM, WACOM_I2C_MODE_NORMAL);
if (ret != COM_COORD_NUM) {
input_err(true, &client->dev,
"failed to recv data(ret:%d)\n", ret);
usleep_range(4500, 5500);
continue;
}
/*
* status value
* 0 : data is not ready
* 1 : PASS
* 2 : Fail (coil function error)
* 3 : Fail (All coil function error)
*/
if (buf[0] == 1) {
input_info(true, &client->dev, "Pass\n");
break;
}
msleep(50);
} while (retry--);
if (ret > 0) {
wac_i2c->connection_check = ((buf[0] == 1) && !buf[4]);
} else {
wac_i2c->connection_check = false;
return -1;
}
wac_i2c->fail_channel = buf[1];
wac_i2c->min_adc_val = buf[2] << 8 | buf[3];
wac_i2c->error_cal = buf[4];
wac_i2c->min_cal_val = buf[5] << 8 | buf[6];
input_info(true, &client->dev,
"%s: %s buf[0]:%d, buf[1]:%d, buf[2]:%d, buf[3]:%d, buf[4]:%d, buf[5]:%d, buf[6]:%d\n",
__func__, wac_i2c->connection_check ? "Pass" : "Fail",
buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
cmd = COM_SAMPLERATE_STOP;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret <= 0) {
input_err(true, &client->dev,
"failed to send stop cmd for end\n");
return -2;
}
cmd = COM_SAMPLERATE_START;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret <= 0) {
input_err(true, &client->dev,
"failed to send start cmd for end\n");
return -2;
}
wac_i2c->samplerate_state = true;
if (retry <= 0)
return -1;
return 0;
}
static ssize_t epen_connection_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int retry = 2;
int ret, module_ver = 2;
mutex_lock(&wac_i2c->lock);
input_info(true, &client->dev, "%s\n", __func__);
wac_i2c->is_open_test = true;
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
if (wac_i2c->fullscan_mode) {
input_info(true, &wac_i2c->client->dev, "%s: full scan OUT\n", __func__);
cancel_delayed_work_sync(&wac_i2c->gxscan_work);
cancel_delayed_work_sync(&wac_i2c->fullscan_work);
wac_i2c->tsp_noise_mode = set_spen_mode(EPEN_GLOBAL_SCAN_MODE);
wac_i2c->fullscan_mode = false;
}
wac_i2c->wacom_noise_state = WACOM_NOISE_LOW;
while (retry--) {
ret = wacom_open_test(wac_i2c);
if (!ret)
break;
input_err(true, &client->dev, "failed. retry %d\n", retry);
wacom_power(wac_i2c, false);
wac_i2c->function_result &= ~EPEN_EVENT_SURVEY;
wac_i2c->survey_mode = EPEN_SURVEY_MODE_NONE;
/* recommended delay in spec */
msleep(100);
wacom_power(wac_i2c, true);
if (ret == -1) {
msleep(150);
continue;
} else if (ret == -2) {
break;
}
}
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
mutex_unlock(&wac_i2c->lock);
input_info(true, &client->dev,
"connection_check : %d\n", wac_i2c->connection_check);
wac_i2c->is_open_test = false;
return snprintf(buf, PAGE_SIZE, "%s %d %d %d %s %d\n",
wac_i2c->connection_check ? "OK" : "NG",
module_ver, wac_i2c->fail_channel,
wac_i2c->min_adc_val, wac_i2c->error_cal ? "NG" : "OK",
wac_i2c->min_cal_val);
}
static ssize_t epen_saving_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
static u64 call_count;
int val;
call_count++;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
#ifdef CONFIG_SEC_FACTORY
input_info(true, &client->dev,
"%s : Not support power saving mode(%d) in Factory Bin [%lu]\n",
__func__, val, call_count);
return count;
#endif
wac_i2c->battery_saving_mode = !(!val);
input_info(true, &client->dev, "%s: ps %s & pen %s [%lu]\n",
__func__, wac_i2c->battery_saving_mode ? "on" : "off",
(wac_i2c->function_result & EPEN_EVENT_PEN_OUT) ? "out" : "in",
call_count);
if (!wac_i2c->power_enable && wac_i2c->battery_saving_mode) {
input_err(true, &wac_i2c->client->dev,
"%s: already power off, save & return\n", __func__);
return count;
}
if (!(wac_i2c->function_result & EPEN_EVENT_PEN_OUT)) {
wacom_select_survey_mode(wac_i2c, wac_i2c->screen_on);
if (wac_i2c->battery_saving_mode && (wac_i2c->wacom_noise_state != WACOM_NOISE_HIGH))
forced_release_fullscan(wac_i2c);
else
input_info(true, &client->dev, "high noise mode, skip tsp (F3 0)\n");
}
return count;
}
static ssize_t epen_insert_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
int pen_state = (wac_i2c->function_result & EPEN_EVENT_PEN_OUT);
input_info(true, &wac_i2c->client->dev, "%s : pen is %s\n", __func__,
pen_state ? "OUT" : "IN");
return snprintf(buf, PAGE_SIZE, "%d\n", pen_state ? 0 : 1);
}
static ssize_t epen_screen_off_memo_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val = 0;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
#ifdef CONFIG_SEC_FACTORY
input_info(true, &client->dev,
"%s : Not support screen off memo mode(%d) in Factory Bin\n",
__func__, val);
return count;
#endif
val = !(!val);
if (val)
wac_i2c->function_set |= EPEN_SETMODE_AOP_OPTION_SCREENOFFMEMO;
else
wac_i2c->function_set &= (~EPEN_SETMODE_AOP_OPTION_SCREENOFFMEMO);
input_info(true, &client->dev,
"%s: ps %s aop(%d) set(0x%x) ret(0x%x)\n", __func__,
wac_i2c->battery_saving_mode ? "on" : "off",
(wac_i2c->function_set & EPEN_SETMODE_AOP) ? 1 : 0,
wac_i2c->function_set, wac_i2c->function_result);
if (!wac_i2c->screen_on)
wacom_select_survey_mode(wac_i2c, false);
return count;
}
static ssize_t epen_aod_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val = 0;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
#ifdef CONFIG_SEC_FACTORY
input_info(true, &client->dev,
"%s : Not support aod mode(%d) in Factory Bin\n",
__func__, val);
return count;
#endif
val = !(!val);
if (val)
wac_i2c->function_set |= EPEN_SETMODE_AOP_OPTION_AOD_LCD_OFF;
else
wac_i2c->function_set &= ~EPEN_SETMODE_AOP_OPTION_AOD_LCD_ON;
input_info(true, &client->dev,
"%s: ps %s aop(%d) set(0x%x) ret(0x%x)\n", __func__,
wac_i2c->battery_saving_mode ? "on" : "off",
(wac_i2c->function_set & EPEN_SETMODE_AOP) ? 1 : 0,
wac_i2c->function_set, wac_i2c->function_result);
if (!wac_i2c->screen_on)
wacom_select_survey_mode(wac_i2c, false);
return count;
}
static ssize_t epen_aod_lcd_onoff_status_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val = 0;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
#ifdef CONFIG_SEC_FACTORY
input_info(true, &client->dev,
"%s : Not support aod mode(%d) in Factory Bin\n",
__func__, val);
return count;
#endif
val = !(!val);
if (val)
wac_i2c->function_set |= EPEN_SETMODE_AOP_OPTION_AOD_LCD_STATUS;
else
wac_i2c->function_set &= ~EPEN_SETMODE_AOP_OPTION_AOD_LCD_STATUS;
if (!(wac_i2c->function_set & EPEN_SETMODE_AOP_OPTION_AOD) || wac_i2c->screen_on)
goto out;
if (wac_i2c->survey_mode == EPEN_SURVEY_MODE_GARAGE_AOP) {
if ((wac_i2c->function_set & EPEN_SETMODE_AOP_OPTION_AOD_LCD_ON)
== EPEN_SETMODE_AOP_OPTION_AOD_LCD_OFF) {
forced_release_fullscan(wac_i2c);
}
wacom_i2c_set_survey_mode(wac_i2c, wac_i2c->survey_mode);
}
out:
input_info(true, &client->dev, "%s: screen %s, survey mode:0x%x, set:0x%x\n",
__func__, wac_i2c->screen_on ? "on" : "off",
wac_i2c->survey_mode, wac_i2c->function_set);
return count;
}
static ssize_t epen_aot_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val = 0;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
#ifdef CONFIG_SEC_FACTORY
input_info(true, &client->dev,
"%s : Not support aot mode(%d) in Factory Bin\n",
__func__, val);
return count;
#endif
val = !(!val);
if (val)
wac_i2c->function_set |= EPEN_SETMODE_AOP_OPTION_AOT;
else
wac_i2c->function_set &= (~EPEN_SETMODE_AOP_OPTION_AOT);
input_info(true, &client->dev,
"%s: ps %s aop(%d) set(0x%x) ret(0x%x)\n", __func__,
wac_i2c->battery_saving_mode ? "on" : "off",
(wac_i2c->function_set & EPEN_SETMODE_AOP) ? 1 : 0,
wac_i2c->function_set, wac_i2c->function_result);
if (!wac_i2c->screen_on)
wacom_select_survey_mode(wac_i2c, false);
return count;
}
static ssize_t epen_wcharging_mode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %s\n", __func__,
!wac_i2c->wcharging_mode ? "NORMAL" : "LOWSENSE");
return snprintf(buf, PAGE_SIZE, "%s\n",
!wac_i2c->wcharging_mode ? "NORMAL" : "LOWSENSE");
}
static ssize_t epen_wcharging_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int retval = 0;
if (kstrtoint(buf, 0, &retval)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->wcharging_mode = retval;
input_info(true, &client->dev, "%s: %d\n", __func__,
wac_i2c->wcharging_mode);
if (!wac_i2c->power_enable) {
input_err(true, &wac_i2c->client->dev,
"%s: power off, save & return\n", __func__);
return count;
}
retval = wacom_i2c_set_sense_mode(wac_i2c);
if (retval < 0) {
input_err(true, &client->dev,
"%s: do not set sensitivity mode, %d\n", __func__,
retval);
}
return count;
}
/*
BLE Charge Mode
0xE8 : Disable charge
0xE9 : Enable charge
0xEA : Reset ( 60s charge -> 4s/2min )
0xEB : Fast charge ( 9s/10s charge/off -> 4s/2min )
0xEC : Slow charge 1 (4s/2min )
0xED : Slow charge 2 (6s/2min )
0xEE : None
0xEF : Reset DSP
*/
void wacom_ble_charge_mode(struct wacom_i2c *wac_i2c, char mode)
{
struct i2c_client *client = wac_i2c->client;
int ret = 0;
char data[2] = { 0, 0 };
if (wac_i2c->is_open_test) {
input_err(true, &client->dev, "%s: other cmd is working\n", __func__);
return;
}
if (mode >= EPEN_BLE_C_MAX || mode == EPEN_BLE_C_NONE) {
input_err(true, &client->dev,
"%s: wrong mode, %d\n", __func__,
mode);
return;
}
if (mode == EPEN_BLE_C_DSPX) {
/* add abnormal ble reset case (while pen in status, do not ble charge) */
input_err(true, &client->dev, "%s: ble mode(%d)\n", __func__, mode);
data[0] = COM_SURVEYEXIT;
ret = wacom_i2c_send(wac_i2c, &data[0], 1, WACOM_I2C_MODE_NORMAL);
if (ret != 1) {
input_err(true, &client->dev,
"%s: failed to send 0x%x cmd(%d)\n", __func__,
data[0], ret);
return;
}
input_info(true, &client->dev, "%s: %02X\n", __func__, data[0]);
msleep(250);
data[0] = COM_PEN_CHECK_OUT + mode;
ret = wacom_i2c_send(wac_i2c, &data[0], 1, WACOM_I2C_MODE_NORMAL);
if (ret != 1) {
input_err(true, &client->dev,
"%s: failed to send 0x%x cmd(%d)\n", __func__,
data[0], ret);
}
input_info(true, &client->dev, "%s: %02X\n", __func__, data[0]);
msleep(130);
wacom_select_survey_mode(wac_i2c, wac_i2c->screen_on);
} else {
data[0] = COM_PEN_CHECK_OUT + mode;
ret = wacom_i2c_send(wac_i2c, &data[0], 1, WACOM_I2C_MODE_NORMAL);
if (ret != 1) {
input_err(true, &client->dev,
"%s: failed to send 0x%x cmd(%d)\n", __func__,
data[0], ret);
}
}
input_info(true, &client->dev, "%s: now %02X, prev %02X\n", __func__, data[0],
wac_i2c->ble_mode ? wac_i2c->ble_mode : 0);
wac_i2c->ble_mode = mode + COM_PEN_CHECK_OUT;
}
static ssize_t epen_ble_charging_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int retval = 0;
if (kstrtoint(buf, 0, &retval)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
if (!wac_i2c->power_enable) {
input_err(true, &wac_i2c->client->dev,
"%s: power off return\n", __func__);
return count;
}
wacom_ble_charge_mode(wac_i2c, (char)retval);
return count;
}
static ssize_t epen_keyboard_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->keyboard_cover_mode = !(!val);
input_info(true, &client->dev, "%s: %d\n", __func__, wac_i2c->keyboard_cover_mode);
return count;
}
#ifdef CONFIG_SEC_FACTORY
/* epen_disable_mode : Use in Factory mode for test test
* 0 : wacom ic on
* 1 : wacom ic off
*/
void epen_disable_mode(int mode)
{
struct wacom_i2c *wac_i2c = wacom_get_drv_data(NULL);
struct i2c_client *client = wac_i2c->client;
if (wac_i2c->epen_blocked == mode){
input_info(true, &client->dev, "%s: duplicate call %d!\n", __func__, mode);
return;
}
if (mode) {
input_info(true, &client->dev, "%s: power off\n", __func__);
wac_i2c->epen_blocked = mode;
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
wacom_power(wac_i2c, false);
wac_i2c->survey_mode = EPEN_SURVEY_MODE_NONE;
wac_i2c->function_result &= ~EPEN_EVENT_SURVEY;
wac_i2c->wacom_noise_state = WACOM_NOISE_LOW;
wac_i2c->tsp_noise_mode = set_spen_mode(EPEN_GLOBAL_SCAN_MODE);
wac_i2c->fullscan_mode = false;
forced_release(wac_i2c);
} else {
input_info(true, &client->dev, "%s: power on\n", __func__);
wacom_power(wac_i2c, true);
msleep(500);
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
wac_i2c->epen_blocked = mode;
}
input_info(true, &client->dev, "%s: done %d!\n", __func__, mode);
}
#else
/* epen_disable_mode : Use in Secure mode(TUI)
* 0 : enable wacom
* 1 : disable wacom
*/
void epen_disable_mode(int mode)
{
struct wacom_i2c *wac_i2c = wacom_get_drv_data(NULL);
struct i2c_client *client = wac_i2c->client;
static int depth;
if (mode) {
if (!depth++)
goto out;
} else {
if (!(--depth))
goto out;
if (depth < 0)
depth = 0;
}
input_info(true, &client->dev, "%s: %s(%d)!\n",
__func__, mode ? "on" : "off", depth);
return;
out:
wac_i2c->epen_blocked = mode;
if (!wac_i2c->power_enable && wac_i2c->epen_blocked) {
input_err(true, &wac_i2c->client->dev,
"%s: already power off, return\n", __func__);
return;
}
wacom_select_survey_mode(wac_i2c, wac_i2c->screen_on);
if (wac_i2c->epen_blocked && (wac_i2c->wacom_noise_state != WACOM_NOISE_HIGH))
forced_release_fullscan(wac_i2c);
else
input_info(true, &client->dev, "high noise mode, skip tsp (F3 0)\n");
input_info(true, &client->dev, "%s: %s(%d)!\n",
__func__, mode ? "on" : "off", depth);
}
#endif
EXPORT_SYMBOL(epen_disable_mode);
static ssize_t epen_disable_mode_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val = 0;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
val = !(!val);
input_info(true, &client->dev, "%s: %d\n", __func__, val);
epen_disable_mode(val);
return count;
}
static ssize_t epen_dex_enable_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %d\n",
__func__, wac_i2c->dex_mode);
return snprintf(buf, PAGE_SIZE, "%d\n", wac_i2c->dex_mode);
}
static ssize_t epen_dex_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int retval = 0;
if (!wac_i2c->pdata->support_dex) {
input_err(true, &client->dev, "%s: not support DeX mode\n",
__func__);
return count;
}
if (kstrtoint(buf, 0, &retval)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
if (retval < 0 || retval > DEX_MODE_ALL) {
input_err(true, &client->dev, "%s: invalid param %d\n",
__func__, retval);
return count;
}
forced_release(wac_i2c);
wac_i2c->dex_mode = retval;
if (wac_i2c->dex_mode & DEX_MODE_MOUSE)
wac_i2c->input_dev = wac_i2c->input_dev_pad;
else
wac_i2c->input_dev = wac_i2c->input_dev_pen;
input_info(true, &client->dev, "%s: %s (%s mode%s%s)\n",
__func__, wac_i2c->dex_mode ? "on" : "off",
wac_i2c->dex_mode & DEX_MODE_MOUSE ? "mouse" : "stylus",
wac_i2c->dex_mode & DEX_MODE_EDGE_CROP ? ", edge crop" : "",
wac_i2c->dex_mode & DEX_MODE_IRIS ? ", Iris" : "");
return count;
}
/* change&show dex_rate for test */
static ssize_t epen_dex_rate_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %d\n",
__func__, wac_i2c->pdata->dex_rate);
return snprintf(buf, PAGE_SIZE, "%d\n", wac_i2c->pdata->dex_rate);
}
static ssize_t epen_dex_rate_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int retval = 0;
if (!wac_i2c->pdata->support_dex) {
input_err(true, &client->dev, "%s: not support DeX mode\n",
__func__);
return count;
}
if (kstrtoint(buf, 0, &retval)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->pdata->dex_rate = retval;
input_info(true, &client->dev, "%s: %d\n", __func__, wac_i2c->pdata->dex_rate);
return count;
}
static ssize_t epen_pen_out_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %u\n", __func__,
wac_i2c->pen_out_count);
return snprintf(buf, PAGE_SIZE, "%u", wac_i2c->pen_out_count);
}
static ssize_t epen_clear_pen_out_count_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
if (buf[0] != 'c') {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->pen_out_count = 0;
input_info(true, &client->dev, "%s: clear\n", __func__);
return count;
}
static ssize_t epen_abnormal_reset_count_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %u\n", __func__,
wac_i2c->abnormal_reset_count);
return snprintf(buf, PAGE_SIZE, "%u", wac_i2c->abnormal_reset_count);
}
static ssize_t epen_clear_abnormal_reset_count_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
if (buf[0] != 'c') {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->abnormal_reset_count = 0;
input_info(true, &client->dev, "%s: clear\n", __func__);
return count;
}
static ssize_t epen_i2c_fail_count_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: %u\n", __func__,
wac_i2c->i2c_fail_count);
return snprintf(buf, PAGE_SIZE, "%u", wac_i2c->i2c_fail_count);
}
static ssize_t epen_clear_i2c_fail_count_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
if (buf[0] != 'c') {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
wac_i2c->i2c_fail_count = 0;
input_info(true, &client->dev, "%s: clear\n", __func__);
return count;
}
static ssize_t epen_connection_check_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: SDCONN:%d,SECCNT:%d,SADCVAL:%d,SECLVL:%d,SCALLVL:%d\n",
__func__, wac_i2c->connection_check,
wac_i2c->fail_channel, wac_i2c->min_adc_val,
wac_i2c->error_cal, wac_i2c->min_cal_val);
return snprintf(buf, PAGE_SIZE,
"\"SDCONN\":\"%d\",\"SECCNT\":\"%d\",\"SADCVAL\":\"%d\",\"SECLVL\":\"%d\",\"SCALLVL\":\"%d\"",
wac_i2c->connection_check, wac_i2c->fail_channel,
wac_i2c->min_adc_val, wac_i2c->error_cal,
wac_i2c->min_cal_val);
}
#ifdef CONFIG_SEC_FACTORY
static ssize_t epen_fac_garage_mode_enable(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int val;
u8 cmd;
int ret;
if (kstrtoint(buf, 0, &val)) {
input_err(true, &client->dev, "%s: failed to get param\n",
__func__);
return count;
}
val = !(!val);
if (!val)
wac_i2c->fac_garage_mode = 0;
cmd = COM_SAMPLERATE_STOP;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret < 0) {
input_err(true, &client->dev, "failed to send stop cmd %d\n",
ret);
msleep(50);
wac_i2c->fac_garage_mode = 0;
return count;
}
wac_i2c->samplerate_state = false;
if (val) {
msleep(50);
wac_i2c->fac_garage_mode = 1;
} else {
cmd = COM_SAMPLERATE_START;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret < 0) {
input_err(true, &client->dev,
"failed to sned start cmd %d\n",
ret);
return count;
}
wac_i2c->samplerate_state = true;
}
input_info(true, &client->dev, "%s: %d\n", __func__, val);
return count;
}
static ssize_t epen_fac_garage_mode_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
input_info(true, &client->dev, "%s: garage mode %s\n", __func__,
wac_i2c->fac_garage_mode ? "IN" : "OUT");
return snprintf(buf, PAGE_SIZE, "garage mode %s",
wac_i2c->fac_garage_mode ? "IN" : "OUT");
}
static ssize_t epen_fac_garage_rawdata_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
char data[10] = { 0, };
int ret;
u8 cmd;
if (!wac_i2c->fac_garage_mode) {
input_err(true, &client->dev, "not in factory garage mode\n");
return snprintf(buf, PAGE_SIZE, "NG");
}
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
cmd = COM_REQUESTGARAGEDATA;
ret = wacom_i2c_send(wac_i2c, &cmd, 1, WACOM_I2C_MODE_NORMAL);
if (ret < 0) {
input_err(true, &client->dev,
"failed to send request garage data command %d\n",
ret);
msleep(30);
goto out;
}
msleep(30);
ret = wacom_i2c_recv(wac_i2c, data, 10, WACOM_I2C_MODE_NORMAL);
if (ret < 0) {
input_err(true, &client->dev,
"failed to read garage raw data, %d\n", ret);
wac_i2c->garage_freq0 = wac_i2c->garage_freq1 = 0;
wac_i2c->garage_gain0 = wac_i2c->garage_gain1 = 0;
goto out;
}
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
input_info(true, &client->dev, "%x %x %x %x %x %x %x %x %x %x\n",
data[0], data[1], data[2], data[3], data[4], data[5],
data[6], data[7], data[8], data[9]);
wac_i2c->garage_gain0 = data[4];
wac_i2c->garage_freq0 = ((u16)data[5] << 8) + data[6];
wac_i2c->garage_gain1 = data[7];
wac_i2c->garage_freq1 = ((u16)data[8] << 8) + data[9];
input_info(true, &client->dev, "%s: %d, %d, %d, %d\n", __func__,
wac_i2c->garage_gain0, wac_i2c->garage_freq0,
wac_i2c->garage_gain1, wac_i2c->garage_freq1);
return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d", wac_i2c->garage_gain0,
wac_i2c->garage_freq0, wac_i2c->garage_gain1,
wac_i2c->garage_freq1);
out:
wacom_enable_irq(wac_i2c, true);
wacom_enable_pdct_irq(wac_i2c, true);
return snprintf(buf, PAGE_SIZE, "NG");
}
#endif
static ssize_t get_epen_pos_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct wacom_i2c *wac_i2c = dev_get_drvdata(dev);
struct i2c_client *client = wac_i2c->client;
int max_x, max_y;
if (wac_i2c->pdata->xy_switch) {
max_x = wac_i2c->pdata->max_y;
max_y = wac_i2c->pdata->max_x;
} else {
max_x = wac_i2c->pdata->max_x;
max_y = wac_i2c->pdata->max_y;
}
input_info(true, &client->dev,
"%s: id(%d), x(%d), y(%d), max_x(%d), max_y(%d)\n", __func__,
wac_i2c->survey_pos.id, wac_i2c->survey_pos.x, wac_i2c->survey_pos.y,
max_x, max_y);
return snprintf(buf, PAGE_SIZE, "%d,%d,%d,%d,%d\n",
wac_i2c->survey_pos.id, wac_i2c->survey_pos.x, wac_i2c->survey_pos.y,
max_x, max_y);
}
/* firmware update */
static DEVICE_ATTR(epen_firm_update, (S_IWUSR | S_IWGRP),
NULL, epen_firmware_update_store);
/* return firmware update status */
static DEVICE_ATTR(epen_firm_update_status, S_IRUGO,
epen_firm_update_status_show, NULL);
/* return firmware version */
static DEVICE_ATTR(epen_firm_version, S_IRUGO, epen_firm_version_show, NULL);
/* For SMD Test */
static DEVICE_ATTR(epen_reset, (S_IWUSR | S_IWGRP), NULL, epen_reset_store);
static DEVICE_ATTR(epen_reset_result, S_IRUGO, epen_reset_result_show, NULL);
/* For SMD Test. Check checksum */
static DEVICE_ATTR(epen_checksum, (S_IWUSR | S_IWGRP),
NULL, epen_checksum_store);
static DEVICE_ATTR(epen_checksum_result, S_IRUGO,
epen_checksum_result_show, NULL);
static DEVICE_ATTR(epen_connection, S_IRUGO, epen_connection_show, NULL);
static DEVICE_ATTR(epen_saving_mode, (S_IWUSR | S_IWGRP),
NULL, epen_saving_mode_store);
static DEVICE_ATTR(epen_insert, S_IRUGO,
epen_insert_show, NULL);
static DEVICE_ATTR(epen_wcharging_mode, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_wcharging_mode_show, epen_wcharging_mode_store);
static DEVICE_ATTR(epen_ble_charging_mode, (S_IWUSR | S_IWGRP),
NULL, epen_ble_charging_mode_store);
static DEVICE_ATTR(keyboard_mode, (S_IWUSR | S_IWGRP),
NULL, epen_keyboard_mode_store);
static DEVICE_ATTR(epen_disable_mode, (S_IWUSR | S_IWGRP),
NULL, epen_disable_mode_store);
static DEVICE_ATTR(screen_off_memo_enable, (S_IWUSR | S_IWGRP),
NULL, epen_screen_off_memo_enable_store);
static DEVICE_ATTR(get_epen_pos,
S_IRUGO, get_epen_pos_show, NULL);
static DEVICE_ATTR(aod_enable, (S_IWUSR | S_IWGRP),
NULL, epen_aod_enable_store);
static DEVICE_ATTR(aod_lcd_onoff_status, (S_IWUSR | S_IWGRP),
NULL, epen_aod_lcd_onoff_status_store);
static DEVICE_ATTR(aot_enable, (S_IWUSR | S_IWGRP),
NULL, epen_aot_enable_store);
static DEVICE_ATTR(dex_enable, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_dex_enable_show, epen_dex_enable_store);
static DEVICE_ATTR(dex_rate, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_dex_rate_show, epen_dex_rate_store);
static DEVICE_ATTR(pen_out_count, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_pen_out_count_show, epen_clear_pen_out_count_store);
static DEVICE_ATTR(abnormal_reset_count, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_abnormal_reset_count_show,
epen_clear_abnormal_reset_count_store);
static DEVICE_ATTR(i2c_fail_count, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_i2c_fail_count_show, epen_clear_i2c_fail_count_store);
static DEVICE_ATTR(epen_connection_check, 0444,
epen_connection_check_show, NULL);
#ifdef CONFIG_SEC_FACTORY
static DEVICE_ATTR(epen_fac_select_firmware, (S_IWUSR | S_IWGRP),
NULL, epen_fac_select_firmware_store);
static DEVICE_ATTR(epen_fac_garage_mode, (S_IRUGO | S_IWUSR | S_IWGRP),
epen_fac_garage_mode_show, epen_fac_garage_mode_enable);
static DEVICE_ATTR(epen_fac_garage_rawdata, S_IRUGO,
epen_fac_garage_rawdata_show, NULL);
#endif
static struct attribute *epen_attributes[] = {
&dev_attr_epen_firm_update.attr,
&dev_attr_epen_firm_update_status.attr,
&dev_attr_epen_firm_version.attr,
&dev_attr_epen_reset.attr,
&dev_attr_epen_reset_result.attr,
&dev_attr_epen_checksum.attr,
&dev_attr_epen_checksum_result.attr,
&dev_attr_epen_connection.attr,
&dev_attr_epen_saving_mode.attr,
&dev_attr_epen_insert.attr,
&dev_attr_epen_wcharging_mode.attr,
&dev_attr_epen_ble_charging_mode.attr,
&dev_attr_keyboard_mode.attr,
&dev_attr_epen_disable_mode.attr,
&dev_attr_screen_off_memo_enable.attr,
&dev_attr_get_epen_pos.attr,
&dev_attr_aod_enable.attr,
&dev_attr_aod_lcd_onoff_status.attr,
&dev_attr_aot_enable.attr,
&dev_attr_dex_enable.attr,
&dev_attr_dex_rate.attr,
&dev_attr_pen_out_count.attr,
&dev_attr_abnormal_reset_count.attr,
&dev_attr_i2c_fail_count.attr,
&dev_attr_epen_connection_check.attr,
#ifdef CONFIG_SEC_FACTORY
&dev_attr_epen_fac_select_firmware.attr,
&dev_attr_epen_fac_garage_mode.attr,
&dev_attr_epen_fac_garage_rawdata.attr,
#endif
NULL,
};
static struct attribute_group epen_attr_group = {
.attrs = epen_attributes,
};
int wacom_sec_init(struct wacom_i2c *wac_i2c)
{
struct i2c_client *client = wac_i2c->client;
int retval = 0;
wac_i2c->dev = sec_device_create(wac_i2c, "sec_epen");
if (IS_ERR(wac_i2c->dev)) {
input_err(true, &client->dev, "failed to create device\n");
retval = -ENODEV;
return retval;
}
dev_set_drvdata(wac_i2c->dev, wac_i2c);
retval = sysfs_create_group(&wac_i2c->dev->kobj, &epen_attr_group);
if (retval) {
input_err(true, &client->dev, "failed to create sysfs group\n");
goto err_sysfs_create_group;
}
retval = sysfs_create_link(&wac_i2c->dev->kobj,
&wac_i2c->input_dev->dev.kobj, "input");
if (retval) {
input_err(true, &client->dev, "failed to create sysfs link\n");
goto err_create_symlink;
}
return retval;
err_create_symlink:
sysfs_remove_group(&wac_i2c->dev->kobj, &epen_attr_group);
err_sysfs_create_group:
sec_device_destroy(wac_i2c->dev->devt);
return retval;
}
void wacom_sec_remove(struct wacom_i2c *wac_i2c)
{
sysfs_delete_link(&wac_i2c->dev->kobj,
&wac_i2c->input_dev->dev.kobj, "input");
sysfs_remove_group(&wac_i2c->dev->kobj, &epen_attr_group);
sec_device_destroy(wac_i2c->dev->devt);
}
|