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
|
/*
* 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"
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_PROC;
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[4] = { 0, };
int ret = 0, retry = 10;
wac_i2c->connection_check = false;
wac_i2c->fail_channel = 0;
wac_i2c->min_adc_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;
}
usleep_range(500, 500);
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);
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);
continue;
}
usleep_range(500, 500);
ret = wacom_i2c_recv(wac_i2c, buf, 4, WACOM_I2C_MODE_NORMAL);
if (ret != 4) {
input_err(true, &client->dev,
"failed to recv data(ret:%d)\n", ret);
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);
} else {
wac_i2c->connection_check = false;
return -1;
}
wac_i2c->fail_channel = buf[1];
wac_i2c->min_adc_val = buf[2] << 8 | buf[3];
input_info(true, &client->dev,
"%s: %s buf[0]:%d, buf[1]:%d, buf[2]:%d, buf[3]:%d\n",
__func__, wac_i2c->connection_check ? "Pass" : "Fail",
buf[0], buf[1], buf[2], buf[3]);
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;
}
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 = 1;
mutex_lock(&wac_i2c->lock);
input_info(true, &client->dev, "%s\n", __func__);
wacom_enable_irq(wac_i2c, false);
wacom_enable_pdct_irq(wac_i2c, false);
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);
return snprintf(buf, PAGE_SIZE, "%s %d %d %d\n",
wac_i2c->connection_check ? "OK" : "NG",
module_ver, wac_i2c->fail_channel,
wac_i2c->min_adc_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->tsp_noise_mode = set_spen_mode(EPEN_GLOBAL_SCAN_MODE); */
}
}
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;
else
wac_i2c->function_set &= (~EPEN_SETMODE_AOP_OPTION_AOD);
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;
}
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;
}
/* epen_disable_mode : Use in Secure mode(TUI) and Factory mode
* 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: %d(%d)!\n", __func__, mode, 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);
input_info(true, &client->dev, "%s: %d(%d)!\n", __func__, mode, depth);
}
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_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\n",
__func__, wac_i2c->connection_check,
wac_i2c->fail_channel, wac_i2c->min_adc_val);
return snprintf(buf, PAGE_SIZE, "SDCONN:%d,SECCNT:%d,SADCVAL:%d",
wac_i2c->connection_check, wac_i2c->fail_channel,
wac_i2c->min_adc_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;
}
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;
}
}
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(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(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(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_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_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_dex_enable.attr,
&dev_attr_dex_rate.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_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);
}
|