-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoodix_ts_core.c
3567 lines (3106 loc) · 99.1 KB
/
goodix_ts_core.c
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
/*
* Goodix Touchscreen Driver
* Copyright (C) 2020 - 2021 Goodix, Inc.
*
* Copyright (C) 2022 XiaoMi, Inc.
*
* 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 a reference
* to you, when you are integrating the GOODiX's CTP IC into your system,
* 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/version.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>
#include <drm/mi_disp_notifier.h>
#include <linux/backlight.h>
#include <drm/dsi_display_fod.h>
#include <linux/power_supply.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
#include <linux/input/mt.h>
#define INPUT_TYPE_B_PROTOCOL
#endif
#include "goodix_ts_core.h"
#define GOODIX_DEFAULT_CFG_NAME "goodix_cfg_group.cfg"
#define GOOIDX_INPUT_PHYS "goodix_ts/input0"
#define PINCTRL_STATE_ACTIVE "pmx_ts_active"
#define PINCTRL_STATE_SUSPEND "pmx_ts_suspend"
#define PINCTRL_STATE_BOOT "pmx_ts_boot"
#define TS_ID_DET1 (336+96)
#define TS_ID_DET2 (336+68)
#ifdef CONFIG_TOUCH_BOOST
extern void touch_irq_boost(void);
#endif
#ifdef CONFIG_TOUCH_BOOST
#define EVENT_INPUT 0x1
extern void lpm_disable_for_dev(bool on, char event_dev);
#endif
extern struct device *global_spi_parent_device;
struct goodix_module goodix_modules;
int core_module_prob_sate = CORE_MODULE_UNPROBED;
struct goodix_ts_core *goodix_core_data;
static int goodix_send_ic_config(struct goodix_ts_core *cd, int type);
static void goodix_set_gesture_work(struct work_struct *work);
int goodix_ts_get_lockdown_info(struct goodix_ts_core *cd);
/**
* __do_register_ext_module - register external module
* to register into touch core modules structure
* return 0 on success, otherwise return < 0
*/
static int __do_register_ext_module(struct goodix_ext_module *module)
{
struct goodix_ext_module *ext_module, *next;
struct list_head *insert_point = &goodix_modules.head;
/* prority level *must* be set */
if (module->priority == EXTMOD_PRIO_RESERVED) {
ts_err("Priority of module [%s] needs to be set",
module->name);
return -EINVAL;
}
mutex_lock(&goodix_modules.mutex);
/* find insert point for the specified priority */
if (!list_empty(&goodix_modules.head)) {
list_for_each_entry_safe(ext_module, next,
&goodix_modules.head, list) {
if (ext_module == module) {
ts_info("Module [%s] already exists",
module->name);
mutex_unlock(&goodix_modules.mutex);
return 0;
}
}
/* smaller priority value with higher priority level */
list_for_each_entry_safe(ext_module, next,
&goodix_modules.head, list) {
if (ext_module->priority >= module->priority) {
insert_point = &ext_module->list;
break;
}
}
}
if (module->funcs && module->funcs->init) {
if (module->funcs->init(goodix_modules.core_data,
module) < 0) {
ts_err("Module [%s] init error",
module->name ? module->name : " ");
mutex_unlock(&goodix_modules.mutex);
return -EFAULT;
}
}
list_add(&module->list, insert_point->prev);
mutex_unlock(&goodix_modules.mutex);
ts_info("Module [%s] registered,priority:%u", module->name,
module->priority);
return 0;
}
static void goodix_register_ext_module_work(struct work_struct *work) {
struct goodix_ext_module *module =
container_of(work, struct goodix_ext_module, work);
ts_info("module register work IN");
/* driver probe failed */
if (core_module_prob_sate != CORE_MODULE_PROB_SUCCESS) {
ts_err("Can't register ext_module core error");
return;
}
if (__do_register_ext_module(module))
ts_err("failed register module: %s", module->name);
else
ts_info("success register module: %s", module->name);
}
static void goodix_core_module_init(void)
{
if (goodix_modules.initilized)
return;
goodix_modules.initilized = true;
INIT_LIST_HEAD(&goodix_modules.head);
mutex_init(&goodix_modules.mutex);
}
/**
* goodix_register_ext_module - interface for register external module
* to the core. This will create a workqueue to finish the real register
* work and return immediately. The user need to check the final result
* to make sure registe is success or fail.
*
* @module: pointer to external module to be register
* return: 0 ok, <0 failed
*/
int goodix_register_ext_module(struct goodix_ext_module *module)
{
if (!module)
return -EINVAL;
ts_info("goodix_register_ext_module IN");
goodix_core_module_init();
INIT_WORK(&module->work, goodix_register_ext_module_work);
schedule_work(&module->work);
ts_info("goodix_register_ext_module OUT");
return 0;
}
/**
* goodix_register_ext_module_no_wait
* return: 0 ok, <0 failed
*/
int goodix_register_ext_module_no_wait(struct goodix_ext_module *module)
{
if (!module)
return -EINVAL;
ts_info("goodix_register_ext_module_no_wait IN");
goodix_core_module_init();
/* driver probe failed */
if (core_module_prob_sate != CORE_MODULE_PROB_SUCCESS) {
ts_err("Can't register ext_module core error");
return -EINVAL;
}
return __do_register_ext_module(module);
}
/**
* goodix_unregister_ext_module - interface for external module
* to unregister external modules
*
* @module: pointer to external module
* return: 0 ok, <0 failed
*/
int goodix_unregister_ext_module(struct goodix_ext_module *module)
{
struct goodix_ext_module *ext_module, *next;
bool found = false;
if (!module)
return -EINVAL;
if (!goodix_modules.initilized)
return -EINVAL;
if (!goodix_modules.core_data)
return -ENODEV;
mutex_lock(&goodix_modules.mutex);
if (!list_empty(&goodix_modules.head)) {
list_for_each_entry_safe(ext_module, next,
&goodix_modules.head, list) {
if (ext_module == module) {
found = true;
break;
}
}
} else {
mutex_unlock(&goodix_modules.mutex);
return 0;
}
if (!found) {
ts_debug("Module [%s] never registed",
module->name);
mutex_unlock(&goodix_modules.mutex);
return 0;
}
list_del(&module->list);
mutex_unlock(&goodix_modules.mutex);
if (module->funcs && module->funcs->exit)
module->funcs->exit(goodix_modules.core_data, module);
ts_info("Moudle [%s] unregistered",
module->name ? module->name : " ");
return 0;
}
static void goodix_ext_sysfs_release(struct kobject *kobj)
{
ts_info("Kobject released!");
}
#define to_ext_module(kobj) container_of(kobj,\
struct goodix_ext_module, kobj)
#define to_ext_attr(attr) container_of(attr,\
struct goodix_ext_attribute, attr)
static ssize_t goodix_ext_sysfs_show(struct kobject *kobj,
struct attribute *attr, char *buf)
{
struct goodix_ext_module *module = to_ext_module(kobj);
struct goodix_ext_attribute *ext_attr = to_ext_attr(attr);
if (ext_attr->show)
return ext_attr->show(module, buf);
return -EIO;
}
static ssize_t goodix_ext_sysfs_store(struct kobject *kobj,
struct attribute *attr, const char *buf, size_t count)
{
struct goodix_ext_module *module = to_ext_module(kobj);
struct goodix_ext_attribute *ext_attr = to_ext_attr(attr);
if (ext_attr->store)
return ext_attr->store(module, buf, count);
return -EIO;
}
static const struct sysfs_ops goodix_ext_ops = {
.show = goodix_ext_sysfs_show,
.store = goodix_ext_sysfs_store
};
static struct kobj_type goodix_ext_ktype = {
.release = goodix_ext_sysfs_release,
.sysfs_ops = &goodix_ext_ops,
};
struct kobj_type *goodix_get_default_ktype(void)
{
return &goodix_ext_ktype;
}
struct kobject *goodix_get_default_kobj(void)
{
struct kobject *kobj = NULL;
if (!goodix_modules.core_data) {
ts_err("goodix_modules.core_data is null");
}
if (!goodix_modules.core_data->pdev) {
ts_err("goodix_modules.core_data->pdev is null");
}
if (goodix_modules.core_data &&
goodix_modules.core_data->pdev)
kobj = &goodix_modules.core_data->pdev->dev.kobj;
return kobj;
}
/* show driver infomation */
static ssize_t goodix_ts_driver_info_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "DriverVersion:%s\n",
GOODIX_DRIVER_VERSION);
}
/* show chip infoamtion */
static ssize_t goodix_ts_chip_info_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
struct goodix_fw_version chip_ver;
u8 temp_pid[8] = {0};
int ret;
int cnt = -EINVAL;
if (hw_ops->read_version) {
ret = hw_ops->read_version(core_data, &chip_ver);
if (!ret) {
memcpy(temp_pid, chip_ver.rom_pid, sizeof(chip_ver.rom_pid));
cnt = snprintf(&buf[0], PAGE_SIZE,
"rom_pid:%s\nrom_vid:%02x%02x%02x\n",
temp_pid, chip_ver.rom_vid[0],
chip_ver.rom_vid[1], chip_ver.rom_vid[2]);
cnt += snprintf(&buf[cnt], PAGE_SIZE,
"patch_pid:%s\npatch_vid:%02x%02x%02x%02x\n",
chip_ver.patch_pid, chip_ver.patch_vid[0],
chip_ver.patch_vid[1], chip_ver.patch_vid[2],
chip_ver.patch_vid[3]);
cnt += snprintf(&buf[cnt], PAGE_SIZE,
"sensorid:%d\n", chip_ver.sensor_id);
}
}
if (hw_ops->get_ic_info) {
ret = hw_ops->get_ic_info(core_data, &core_data->ic_info);
if (!ret) {
cnt += snprintf(&buf[cnt], PAGE_SIZE,
"config_id:%x\n", core_data->ic_info.version.config_id);
cnt += snprintf(&buf[cnt], PAGE_SIZE,
"config_version:%x\n", core_data->ic_info.version.config_version);
}
}
return cnt;
}
/* reset chip */
static ssize_t goodix_ts_reset_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0')
hw_ops->reset(core_data, GOODIX_NORMAL_RESET_DELAY_MS);
return count;
}
/* read config */
static ssize_t goodix_ts_read_cfg_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
int ret;
int i;
int offset;
char *cfg_buf = NULL;
cfg_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!cfg_buf)
return -ENOMEM;
if (hw_ops->read_config)
ret = hw_ops->read_config(core_data, cfg_buf, PAGE_SIZE);
else
ret = -EINVAL;
if (ret > 0) {
offset = 0;
for (i = 0; i < 200; i++) { // only print 200 bytes
offset += snprintf(&buf[offset], PAGE_SIZE - offset,
"%02x,", cfg_buf[i]);
if ((i + 1) % 20 == 0)
buf[offset++] = '\n';
}
}
kfree(cfg_buf);
if (ret <= 0)
return ret;
return offset;
}
/* read_debug_log */
static ssize_t goodix_ts_read_debug_log(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
int ret;
int i;
int offset;
char *cfg_buf = NULL;
cfg_buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!cfg_buf)
return -ENOMEM;
ret = hw_ops->read(core_data, 0x10194, cfg_buf, 224);
if (ret < 0) {
ts_err("failed read addr(%x) length(%d)", 0x10194, 224);
} else {
offset = 0;
for (i = 0; i < 224; i++) { // only print 224 bytes
offset += snprintf(&buf[offset], PAGE_SIZE - offset,
"%02x,", cfg_buf[i]);
if ((i + 1) % 20 == 0) {
buf[offset++] = '\n';
}
}
buf[offset] = '\n';
}
kfree(cfg_buf);
if (ret < 0)
return ret;
return offset;
}
static u8 ascii2hex(u8 a)
{
s8 value = 0;
if (a >= '0' && a <= '9')
value = a - '0';
else if (a >= 'A' && a <= 'F')
value = a - 'A' + 0x0A;
else if (a >= 'a' && a <= 'f')
value = a - 'a' + 0x0A;
else
value = 0xff;
return value;
}
static int goodix_ts_convert_0x_data(const u8 *buf, int buf_size,
u8 *out_buf, int *out_buf_len)
{
int i, m_size = 0;
int temp_index = 0;
u8 high, low;
for (i = 0; i < buf_size; i++) {
if (buf[i] == 'x' || buf[i] == 'X')
m_size++;
}
if (m_size <= 1) {
ts_err("cfg file ERROR, valid data count:%d", m_size);
return -EINVAL;
}
*out_buf_len = m_size;
for (i = 0; i < buf_size; i++) {
if (buf[i] != 'x' && buf[i] != 'X')
continue;
if (temp_index >= m_size) {
ts_err("exchange cfg data error, overflow,"
"temp_index:%d,m_size:%d",
temp_index, m_size);
return -EINVAL;
}
high = ascii2hex(buf[i + 1]);
low = ascii2hex(buf[i + 2]);
if (high == 0xff || low == 0xff) {
ts_err("failed convert: 0x%x, 0x%x",
buf[i + 1], buf[i + 2]);
return -EINVAL;
}
out_buf[temp_index++] = (high << 4) + low;
}
return 0;
}
/* send config */
static ssize_t goodix_ts_send_cfg_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
struct goodix_ic_config *config = NULL;
const struct firmware *cfg_img = NULL;
int en;
int ret;
if (sscanf(buf, "%d", &en) != 1)
return -EINVAL;
if (en != 1)
return -EINVAL;
hw_ops->irq_enable(core_data, false);
ret = request_firmware(&cfg_img, GOODIX_DEFAULT_CFG_NAME, dev);
if (ret < 0) {
ts_err("cfg file [%s] not available,errno:%d",
GOODIX_DEFAULT_CFG_NAME, ret);
goto exit;
} else {
ts_info("cfg file [%s] is ready", GOODIX_DEFAULT_CFG_NAME);
}
config = kzalloc(sizeof(*config), GFP_KERNEL);
if (!config)
goto exit;
if (goodix_ts_convert_0x_data(cfg_img->data, cfg_img->size,
config->data, &config->len)) {
ts_err("convert config data FAILED");
goto exit;
}
if (hw_ops->send_config) {
ret = hw_ops->send_config(core_data, config->data, config->len);
if (ret < 0)
ts_err("send config failed");
}
exit:
hw_ops->irq_enable(core_data, true);
kfree(config);
if (cfg_img)
release_firmware(cfg_img);
return count;
}
/* reg read/write */
static u32 rw_addr;
static u32 rw_len;
static u8 rw_flag;
static u8 store_buf[32];
static u8 show_buf[PAGE_SIZE];
static ssize_t goodix_ts_reg_rw_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
int ret;
if (!rw_addr || !rw_len) {
ts_err("address(0x%x) and length(%d) can't be null",
rw_addr, rw_len);
return -EINVAL;
}
if (rw_flag != 1) {
ts_err("invalid rw flag %d, only support [1/2]", rw_flag);
return -EINVAL;
}
ret = hw_ops->read(core_data, rw_addr, show_buf, rw_len);
if (ret < 0) {
ts_err("failed read addr(%x) length(%d)", rw_addr, rw_len);
return snprintf(buf, PAGE_SIZE, "failed read addr(%x), len(%d)\n",
rw_addr, rw_len);
}
return snprintf(buf, PAGE_SIZE, "0x%x,%d {%*ph}\n",
rw_addr, rw_len, rw_len, show_buf);
}
static ssize_t goodix_ts_reg_rw_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
char *pos = NULL;
char *token = NULL;
long result = 0;
int ret;
int i;
if (!buf || !count) {
ts_err("invalid parame");
goto err_out;
}
if (buf[0] == 'r') {
rw_flag = 1;
} else if (buf[0] == 'w') {
rw_flag = 2;
} else {
ts_err("string must start with 'r/w'");
goto err_out;
}
/* get addr */
pos = (char *)buf;
pos += 2;
token = strsep(&pos, ":");
if (!token) {
ts_err("invalid address info");
goto err_out;
} else {
if (kstrtol(token, 16, &result)) {
ts_err("failed get addr info");
goto err_out;
}
rw_addr = (u32)result;
ts_info("rw addr is 0x%x", rw_addr);
}
/* get length */
token = strsep(&pos, ":");
if (!token) {
ts_err("invalid length info");
goto err_out;
} else {
if (kstrtol(token, 0, &result)) {
ts_err("failed get length info");
goto err_out;
}
rw_len = (u32)result;
ts_info("rw length info is %d", rw_len);
if (rw_len > sizeof(store_buf)) {
ts_err("data len > %lu", sizeof(store_buf));
goto err_out;
}
}
if (rw_flag == 1)
return count;
for (i = 0; i < rw_len; i++) {
token = strsep(&pos, ":");
if (!token) {
ts_err("invalid data info");
goto err_out;
} else {
if (kstrtol(token, 16, &result)) {
ts_err("failed get data[%d] info", i);
goto err_out;
}
store_buf[i] = (u8)result;
ts_info("get data[%d]=0x%x", i, store_buf[i]);
}
}
ret = hw_ops->write(core_data, rw_addr, store_buf, rw_len);
if (ret < 0) {
ts_err("failed write addr(%x) data %*ph", rw_addr,
rw_len, store_buf);
goto err_out;
}
ts_info("%s write to addr (%x) with data %*ph",
"success", rw_addr, rw_len, store_buf);
return count;
err_out:
snprintf(show_buf, PAGE_SIZE, "%s\n",
"invalid params, format{r/w:4100:length:[41:21:31]}");
return -EINVAL;
}
/* show irq infomation */
static ssize_t goodix_ts_irq_info_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct irq_desc *desc;
size_t offset = 0;
int r;
r = snprintf(&buf[offset], PAGE_SIZE, "irq:%u\n", core_data->irq);
if (r < 0)
return -EINVAL;
offset += r;
r = snprintf(&buf[offset], PAGE_SIZE - offset, "state:%s\n",
atomic_read(&core_data->irq_enabled) ?
"enabled" : "disabled");
if (r < 0)
return -EINVAL;
desc = irq_to_desc(core_data->irq);
offset += r;
r = snprintf(&buf[offset], PAGE_SIZE - offset, "disable-depth:%d\n",
desc->depth);
if (r < 0)
return -EINVAL;
offset += r;
r = snprintf(&buf[offset], PAGE_SIZE - offset, "trigger-count:%zu\n",
core_data->irq_trig_cnt);
if (r < 0)
return -EINVAL;
offset += r;
r = snprintf(&buf[offset], PAGE_SIZE - offset,
"echo 0/1 > irq_info to disable/enable irq\n");
if (r < 0)
return -EINVAL;
offset += r;
return offset;
}
/* enable/disable irq */
static ssize_t goodix_ts_irq_info_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_hw_ops *hw_ops = core_data->hw_ops;
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0')
hw_ops->irq_enable(core_data, true);
else
hw_ops->irq_enable(core_data, false);
return count;
}
/* show esd status */
static ssize_t goodix_ts_esd_info_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
struct goodix_ts_esd *ts_esd = &core_data->ts_esd;
int r = 0;
r = snprintf(buf, PAGE_SIZE, "state:%s\n",
atomic_read(&ts_esd->esd_on) ?
"enabled" : "disabled");
return r;
}
/* enable/disable esd */
static ssize_t goodix_ts_esd_info_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0')
goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
else
goodix_ts_blocking_notify(NOTIFY_ESD_OFF, NULL);
return count;
}
/* debug level show */
static ssize_t goodix_ts_debug_log_show(struct device *dev,
struct device_attribute *attr,
char *buf)
{
int r = 0;
r = snprintf(buf, PAGE_SIZE, "state:%s\n",
debug_log_flag ?
"enabled" : "disabled");
return r;
}
/* debug level store */
static ssize_t goodix_ts_debug_log_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0')
debug_log_flag = true;
else
debug_log_flag = false;
return count;
}
/* double tap gesture show */
static ssize_t goodix_ts_double_tap_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int r = 0;
r = snprintf(buf, PAGE_SIZE, "state:%s\n",
goodix_core_data->double_wakeup ?
"enabled" : "disabled");
return r;
}
/* double tap gesture store */
static ssize_t goodix_ts_double_tap_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0') {
goodix_core_data->double_wakeup = 1;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
else {
goodix_core_data->double_wakeup = 0;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
return count;
}
/* aod gesture show */
static ssize_t goodix_ts_aod_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int r = 0;
r = snprintf(buf, PAGE_SIZE, "state:%s\n",
goodix_core_data->aod_status ?
"enabled" : "disabled");
return r;
}
/* aod gesture_store */
static ssize_t goodix_ts_aod_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0') {
goodix_core_data->aod_status = 1;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
else {
goodix_core_data->aod_status = 0;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
return count;
}
/* fod gesture show */
static ssize_t goodix_ts_fod_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int r = 0;
r = snprintf(buf, PAGE_SIZE, "state:%s\n",
goodix_core_data->fod_status ?
"enabled" : "disabled");
return r;
}
/* fod gesture_store */
static ssize_t goodix_ts_fod_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0') {
goodix_core_data->fod_status = 1;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
else {
goodix_core_data->fod_status = 0;
queue_work(goodix_core_data->gesture_wq, &goodix_core_data->gesture_work);
}
return count;
}
/* report_rate show */
static ssize_t goodix_report_rate_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int r = 0;
r = snprintf(buf, PAGE_SIZE, "touch report rate::%s\n",
goodix_core_data->report_rate == 240 ?
"240HZ" : "480HZ");
return r;
}
/* report_rate_store */
static ssize_t goodix_report_rate_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct goodix_ts_core *core_data = dev_get_drvdata(dev);
if (!buf || count <= 0)
return -EINVAL;
if (buf[0] != '0') {
goodix_core_data->report_rate = 480;
core_data->hw_ops->switch_report_rate(core_data, true);
} else {
goodix_core_data->report_rate = 240;
core_data->hw_ops->switch_report_rate(core_data, false);
}
return count;
}
static DEVICE_ATTR(driver_info, 0444, goodix_ts_driver_info_show, NULL);
static DEVICE_ATTR(chip_info, 0444, goodix_ts_chip_info_show, NULL);
static DEVICE_ATTR(reset, 0220, NULL, goodix_ts_reset_store);
static DEVICE_ATTR(send_cfg, 0220, NULL, goodix_ts_send_cfg_store);
static DEVICE_ATTR(read_cfg, 0444, goodix_ts_read_cfg_show, NULL);
static DEVICE_ATTR(cat_debug_log, 0444, goodix_ts_read_debug_log, NULL);
static DEVICE_ATTR(reg_rw, 0664, goodix_ts_reg_rw_show, goodix_ts_reg_rw_store);
static DEVICE_ATTR(irq_info, 0664, goodix_ts_irq_info_show, goodix_ts_irq_info_store);
static DEVICE_ATTR(esd_info, 0664, goodix_ts_esd_info_show, goodix_ts_esd_info_store);
static DEVICE_ATTR(debug_log, 0664, goodix_ts_debug_log_show, goodix_ts_debug_log_store);
static DEVICE_ATTR(double_tap_enable, 0664, goodix_ts_double_tap_show, goodix_ts_double_tap_store);
static DEVICE_ATTR(aod_enable, 0664, goodix_ts_aod_show, goodix_ts_aod_store);
static DEVICE_ATTR(switch_report_rate, 0664, goodix_report_rate_show, goodix_report_rate_store);
static DEVICE_ATTR(fod_enable, 0664, goodix_ts_fod_show, goodix_ts_fod_store);
static struct attribute *sysfs_attrs[] = {
&dev_attr_driver_info.attr,
&dev_attr_chip_info.attr,
&dev_attr_reset.attr,
&dev_attr_send_cfg.attr,
&dev_attr_read_cfg.attr,
&dev_attr_reg_rw.attr,
&dev_attr_irq_info.attr,
&dev_attr_esd_info.attr,
&dev_attr_debug_log.attr,
&dev_attr_cat_debug_log.attr,
&dev_attr_double_tap_enable.attr,
&dev_attr_aod_enable.attr,
&dev_attr_switch_report_rate.attr,
&dev_attr_fod_enable.attr,
NULL,
};
static const struct attribute_group sysfs_group = {
.attrs = sysfs_attrs,
};
static int goodix_ts_sysfs_init(struct goodix_ts_core *core_data)
{
int ret;
ret = sysfs_create_group(&core_data->pdev->dev.kobj, &sysfs_group);
if (ret) {
ts_err("failed create core sysfs group");
return ret;
}
return ret;
}
static void goodix_ts_sysfs_exit(struct goodix_ts_core *core_data)
{
sysfs_remove_group(&core_data->pdev->dev.kobj, &sysfs_group);
}
/* prosfs create */
static int rawdata_proc_show(struct seq_file *m, void *v)
{
struct ts_rawdata_info *info;
struct goodix_ts_core *cd = m->private;
int tx;
int rx;
int ret;
int i;