-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnt36xxx.c
2153 lines (1792 loc) · 52.2 KB
/
nt36xxx.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
/*
* Copyright (C) 2010 - 2017 Novatek, Inc.
* Copyright (C) 2019 XiaoMi, Inc.
*
* $Revision: 20544 $
* $Date: 2017-12-20 11:08:15 +0800 (週三, 20 十二月 2017) $
*
* 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.
*
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/gpio.h>
#include <linux/proc_fs.h>
#include <asm/uaccess.h>
#include <linux/input/mt.h>
#include <linux/of_gpio.h>
#include <linux/of_irq.h>
#include <linux/slab.h>
#include <linux/regulator/consumer.h>
#include <linux/hwinfo.h>
#ifdef CONFIG_DRM
#include <drm/drm_notifier.h>
#include <drm/drm_panel.h>
#include <linux/fb.h>
#endif
#include <linux/debugfs.h>
#include "nt36xxx.h"
#if NVT_TOUCH_EXT_PROC
extern int32_t nvt_extra_proc_init(void);
#endif
#if NVT_TOUCH_MP
extern int32_t nvt_mp_proc_init(void);
#endif
struct nvt_ts_data *ts;
static struct workqueue_struct *nvt_wq;
#if BOOT_UPDATE_FIRMWARE
static struct workqueue_struct *nvt_fwu_wq;
extern void Boot_Update_Firmware(struct work_struct *work);
#endif
static void nvt_resume_work(struct work_struct *work);
#if defined(CONFIG_DRM)
static int drm_notifier_callback(struct notifier_block *self, unsigned long event, void *data);
#endif
#define INPUT_EVENT_START 0
#define INPUT_EVENT_SENSITIVE_MODE_OFF 0
#define INPUT_EVENT_SENSITIVE_MODE_ON 1
#define INPUT_EVENT_STYLUS_MODE_OFF 2
#define INPUT_EVENT_STYLUS_MODE_ON 3
#define INPUT_EVENT_WAKUP_MODE_OFF 4
#define INPUT_EVENT_WAKUP_MODE_ON 5
#define INPUT_EVENT_COVER_MODE_OFF 6
#define INPUT_EVENT_COVER_MODE_ON 7
#define INPUT_EVENT_SLIDE_FOR_VOLUME 8
#define INPUT_EVENT_DOUBLE_TAP_FOR_VOLUME 9
#define INPUT_EVENT_SINGLE_TAP_FOR_VOLUME 10
#define INPUT_EVENT_LONG_SINGLE_TAP_FOR_VOLUME 11
#define INPUT_EVENT_PALM_OFF 12
#define INPUT_EVENT_PALM_ON 13
#define INPUT_EVENT_END 13
#define PROC_SYMLINK_PATH "touchpanel"
#if TOUCH_KEY_NUM > 0
const uint16_t touch_key_array[TOUCH_KEY_NUM] = {
KEY_BACK,
KEY_HOME,
KEY_MENU
};
#endif
#if WAKEUP_GESTURE
const uint16_t gesture_key_array[] = {
KEY_POWER, /*GESTURE_WORD_C*/
KEY_POWER, /*GESTURE_WORD_W*/
KEY_POWER, /*GESTURE_WORD_V*/
KEY_WAKEUP, /*GESTURE_DOUBLE_CLICK*/
KEY_POWER, /*GESTURE_WORD_Z*/
KEY_POWER, /*GESTURE_WORD_M*/
KEY_POWER, /*GESTURE_WORD_O*/
KEY_POWER, /*GESTURE_WORD_e*/
KEY_POWER, /*GESTURE_WORD_S*/
KEY_POWER, /*GESTURE_SLIDE_UP*/
KEY_POWER, /*GESTURE_SLIDE_DOWN*/
KEY_POWER, /*GESTURE_SLIDE_LEFT*/
KEY_POWER, /*GESTURE_SLIDE_RIGHT*/
};
#endif
static uint8_t bTouchIsAwake;
/*******************************************************
Description:
Novatek touchscreen i2c read function.
return:
Executive outcomes. 2---succeed. -5---I/O error
*******************************************************/
int32_t CTP_I2C_READ(struct i2c_client *client, uint16_t address, uint8_t *buf, uint16_t len)
{
struct i2c_msg msgs[2];
int32_t ret = -1;
int32_t retries = 0;
mutex_lock(&ts->xbuf_lock);
msgs[0].flags = !I2C_M_RD;
msgs[0].addr = address;
msgs[0].len = 1;
msgs[0].buf = &buf[0];
msgs[1].flags = I2C_M_RD;
msgs[1].addr = address;
msgs[1].len = len - 1;
msgs[1].buf = ts->xbuf;
while (retries < 5) {
ret = i2c_transfer(client->adapter, msgs, 2);
if (ret == 2)
break;
retries++;
msleep(20);
NVT_ERR("error, retry=%d\n", retries);
}
if (unlikely(retries == 5)) {
NVT_ERR("error, ret=%d\n", ret);
ret = -EIO;
}
memcpy(buf + 1, ts->xbuf, len - 1);
mutex_unlock(&ts->xbuf_lock);
return ret;
}
/*******************************************************
Description:
Novatek touchscreen i2c write function.
return:
Executive outcomes. 1---succeed. -5---I/O error
*******************************************************/
int32_t CTP_I2C_WRITE(struct i2c_client *client, uint16_t address, uint8_t *buf, uint16_t len)
{
struct i2c_msg msg;
int32_t ret = -1;
int32_t retries = 0;
mutex_lock(&ts->xbuf_lock);
msg.flags = !I2C_M_RD;
msg.addr = address;
msg.len = len;
memcpy(ts->xbuf, buf, len);
msg.buf = ts->xbuf;
while (retries < 5) {
ret = i2c_transfer(client->adapter, &msg, 1);
if (ret == 1)
break;
retries++;
msleep(20);
NVT_ERR("error, retry=%d\n", retries);
}
if (unlikely(retries == 5)) {
NVT_ERR("error, ret=%d\n", ret);
ret = -EIO;
}
mutex_unlock(&ts->xbuf_lock);
return ret;
}
/*******************************************************
Description:
Novatek touchscreen reset MCU then into idle mode
function.
return:
n.a.
*******************************************************/
void nvt_sw_reset_idle(void)
{
uint8_t buf[4] = {0};
/*---write i2c cmds to reset idle---*/
buf[0] = 0x00;
buf[1] = 0xA5;
CTP_I2C_WRITE(ts->client, I2C_HW_Address, buf, 2);
msleep(15);
}
/*******************************************************
Description:
Novatek touchscreen reset MCU (boot) function.
return:
n.a.
*******************************************************/
int nvt_bootloader_reset(void)
{
int ret = 0;
uint8_t buf[8] = {0};
/*write i2c cmds to reset*/
buf[0] = 0x00;
buf[1] = 0x69;
ret = CTP_I2C_WRITE(ts->client, I2C_HW_Address, buf, 2);
/*need 35ms delay after bootloader reset*/
msleep(35);
return ret;
}
/*******************************************************
Description:
Novatek touchscreen clear FW status function.
return:
Executive outcomes. 0---succeed. -1---fail.
*******************************************************/
int32_t nvt_clear_fw_status(void)
{
uint8_t buf[8] = {0};
int32_t i = 0;
const int32_t retry = 20;
for (i = 0; i < retry; i++) {
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---clear fw status---*/
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = 0x00;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 2);
/*---read fw status---*/
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = 0xFF;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
if (buf[1] == 0x00)
break;
msleep(10);
}
if (i >= retry) {
NVT_ERR("failed, i=%d, buf[1]=0x%02X\n", i, buf[1]);
return -EPERM;
} else {
return 0;
}
}
/*******************************************************
Description:
Novatek touchscreen check FW status function.
return:
Executive outcomes. 0---succeed. -1---failed.
*******************************************************/
int32_t nvt_check_fw_status(void)
{
uint8_t buf[8] = {0};
int32_t i = 0;
const int32_t retry = 50;
for (i = 0; i < retry; i++) {
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---read fw status---*/
buf[0] = EVENT_MAP_HANDSHAKING_or_SUB_CMD_BYTE;
buf[1] = 0x00;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 2);
if ((buf[1] & 0xF0) == 0xA0)
break;
msleep(10);
}
if (i >= retry) {
NVT_ERR("failed, i=%d, buf[1]=0x%02X\n", i, buf[1]);
return -1;
} else {
return 0;
}
}
/*******************************************************
Description:
Novatek touchscreen check FW reset state function.
return:
Executive outcomes. 0---succeed. -1---failed.
*******************************************************/
int32_t nvt_check_fw_reset_state(RST_COMPLETE_STATE check_reset_state)
{
uint8_t buf[8] = {0};
int32_t ret = 0;
int32_t retry = 0;
while (1) {
msleep(10);
/*---read reset state---*/
buf[0] = EVENT_MAP_RESET_COMPLETE;
buf[1] = 0x00;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 6);
if ((buf[1] >= check_reset_state) && (buf[1] <= RESET_STATE_MAX)) {
ret = 0;
break;
}
retry++;
if (unlikely(retry > 100)) {
NVT_ERR("error, retry=%d, buf[1]=0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X\n", retry, buf[1], buf[2], buf[3], buf[4], buf[5]);
ret = -1;
break;
}
}
return ret;
}
/*******************************************************
Description:
Novatek touchscreen get novatek project id information
function.
return:
Executive outcomes. 0---success. -1---fail.
*******************************************************/
int32_t nvt_read_pid(void)
{
uint8_t buf[3] = {0};
int32_t ret = 0;
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---read project id---*/
buf[0] = EVENT_MAP_PROJECTID;
buf[1] = 0x00;
buf[2] = 0x00;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 3);
ts->nvt_pid = (buf[2] << 8) + buf[1];
NVT_LOG("PID=%04X\n", ts->nvt_pid);
return ret;
}
/*******************************************************
Description:
Novatek touchscreen get firmware related information
function.
return:
Executive outcomes. 0---success. -1---fail.
*******************************************************/
int32_t nvt_get_fw_info(void)
{
uint8_t buf[64] = {0};
uint32_t retry_count = 0;
int32_t ret = 0;
info_retry:
/*---set xdata index to EVENT BUF ADDR---*/
buf[0] = 0xFF;
buf[1] = (ts->mmap->EVENT_BUF_ADDR >> 16) & 0xFF;
buf[2] = (ts->mmap->EVENT_BUF_ADDR >> 8) & 0xFF;
CTP_I2C_WRITE(ts->client, I2C_FW_Address, buf, 3);
/*---read fw info---*/
buf[0] = EVENT_MAP_FWINFO;
CTP_I2C_READ(ts->client, I2C_FW_Address, buf, 17);
ts->fw_ver = buf[1];
ts->x_num = buf[3];
ts->y_num = buf[4];
ts->abs_x_max = (uint16_t)((buf[5] << 8) | buf[6]);
ts->abs_y_max = (uint16_t)((buf[7] << 8) | buf[8]);
ts->max_button_num = buf[11];
/*---clear x_num, y_num if fw info is broken---*/
if ((buf[1] + buf[2]) != 0xFF) {
NVT_ERR("FW info is broken! fw_ver=0x%02X, ~fw_ver=0x%02X\n", buf[1], buf[2]);
ts->fw_ver = 0;
ts->x_num = 18;
ts->y_num = 32;
ts->abs_x_max = TOUCH_DEFAULT_MAX_WIDTH;
ts->abs_y_max = TOUCH_DEFAULT_MAX_HEIGHT;
ts->max_button_num = TOUCH_KEY_NUM;
if (retry_count < 3) {
retry_count++;
NVT_ERR("retry_count=%d\n", retry_count);
goto info_retry;
} else {
NVT_ERR("Set default fw_ver=%d, x_num=%d, y_num=%d, \
abs_x_max=%d, abs_y_max=%d, max_button_num=%d!\n",
ts->fw_ver, ts->x_num, ts->y_num,
ts->abs_x_max, ts->abs_y_max, ts->max_button_num);
ret = -1;
}
} else {
ret = 0;
}
/*---Get Novatek PID---*/
nvt_read_pid();
return ret;
}
/*******************************************************
Create Device Node (Proc Entry)
*******************************************************/
#if NVT_TOUCH_PROC
static struct proc_dir_entry *NVT_proc_entry;
#define DEVICE_NAME "NVTflash"
/*******************************************************
Description:
Novatek touchscreen /proc/NVTflash read function.
return:
Executive outcomes. 2---succeed. -5,-14---failed.
*******************************************************/
static ssize_t nvt_flash_read(struct file *file, char __user *buff, size_t count, loff_t *offp)
{
uint8_t str[68] = {0};
int32_t ret = -1;
int32_t retries = 0;
int8_t i2c_wr = 0;
if (count > sizeof(str)) {
NVT_ERR("error count=%zu\n", count);
return -EFAULT;
}
if (copy_from_user(str, buff, count)) {
NVT_ERR("copy from user error\n");
return -EFAULT;
}
i2c_wr = str[0] >> 7;
if (i2c_wr == 0) { /*I2C write*/
while (retries < 20) {
ret = CTP_I2C_WRITE(ts->client, (str[0] & 0x7F), &str[2], str[1]);
if (ret == 1)
break;
else
NVT_ERR("error, retries=%d, ret=%d\n", retries, ret);
retries++;
}
if (unlikely(retries == 20)) {
NVT_ERR("error, ret = %d\n", ret);
return -EIO;
}
return ret;
} else if (i2c_wr == 1) { /*I2C read*/
while (retries < 20) {
ret = CTP_I2C_READ(ts->client, (str[0] & 0x7F), &str[2], str[1]);
if (ret == 2)
break;
else
NVT_ERR("error, retries=%d, ret=%d\n", retries, ret);
retries++;
}
/* copy buff to user if i2c transfer */
if (retries < 20) {
if (copy_to_user(buff, str, count))
return -EFAULT;
}
if (unlikely(retries == 20)) {
NVT_ERR("error, ret = %d\n", ret);
return -EIO;
}
return ret;
} else {
NVT_ERR("Call error, str[0]=%d\n", str[0]);
return -EFAULT;
}
}
/*******************************************************
Description:
Novatek touchscreen /proc/NVTflash open function.
return:
Executive outcomes. 0---succeed. -12---failed.
*******************************************************/
static int32_t nvt_flash_open(struct inode *inode, struct file *file)
{
struct nvt_flash_data *dev;
dev = (struct nvt_flash_data *)kmalloc(sizeof(struct nvt_flash_data), GFP_KERNEL);
if (dev == NULL) {
NVT_ERR("Failed to allocate memory for nvt flash data\n");
return -ENOMEM;
}
rwlock_init(&dev->lock);
file->private_data = dev;
return 0;
}
/*******************************************************
Description:
Novatek touchscreen /proc/NVTflash close function.
return:
Executive outcomes. 0---succeed.
*******************************************************/
static int32_t nvt_flash_close(struct inode *inode, struct file *file)
{
struct nvt_flash_data *dev = file->private_data;
if (dev)
kfree(dev);
return 0;
}
static const struct file_operations nvt_flash_fops = {
.owner = THIS_MODULE,
.open = nvt_flash_open,
.release = nvt_flash_close,
.read = nvt_flash_read,
};
/*******************************************************
Description:
Novatek touchscreen /proc/NVTflash initial function.
return:
Executive outcomes. 0---succeed. -12---failed.
*******************************************************/
static int32_t nvt_flash_proc_init(void)
{
NVT_proc_entry = proc_create(DEVICE_NAME, 0444, NULL, &nvt_flash_fops);
if (NVT_proc_entry == NULL) {
NVT_ERR("Failed!\n");
return -ENOMEM;
} else {
NVT_LOG("Succeeded!\n");
}
NVT_LOG("============================================================\n");
NVT_LOG("Create /proc/NVTflash\n");
NVT_LOG("============================================================\n");
return 0;
}
#endif
#if WAKEUP_GESTURE
#define GESTURE_WORD_C 12
#define GESTURE_WORD_W 13
#define GESTURE_WORD_V 14
#define GESTURE_DOUBLE_CLICK 15
#define GESTURE_WORD_Z 16
#define GESTURE_WORD_M 17
#define GESTURE_WORD_O 18
#define GESTURE_WORD_e 19
#define GESTURE_WORD_S 20
#define GESTURE_SLIDE_UP 21
#define GESTURE_SLIDE_DOWN 22
#define GESTURE_SLIDE_LEFT 23
#define GESTURE_SLIDE_RIGHT 24
/* customized gesture id */
#define DATA_PROTOCOL 30
/* function page definition */
#define FUNCPAGE_GESTURE 1
/*******************************************************
Description:
Novatek touchscreen wake up gesture key report function.
return:
n.a.
*******************************************************/
void nvt_ts_wakeup_gesture_report(uint8_t gesture_id, uint8_t *data)
{
uint32_t keycode = 0;
uint8_t func_type = data[2];
uint8_t func_id = data[3];
/* support fw specifal data protocol */
if ((gesture_id == DATA_PROTOCOL) && (func_type == FUNCPAGE_GESTURE)) {
gesture_id = func_id;
} else if (gesture_id > DATA_PROTOCOL) {
NVT_ERR("gesture_id %d is invalid, func_type=%d, func_id=%d\n", gesture_id, func_type, func_id);
return;
}
NVT_LOG("gesture_id = %d\n", gesture_id);
switch (gesture_id) {
case GESTURE_WORD_C:
NVT_LOG("Gesture : Word-C.\n");
keycode = gesture_key_array[0];
break;
case GESTURE_WORD_W:
NVT_LOG("Gesture : Word-W.\n");
keycode = gesture_key_array[1];
break;
case GESTURE_WORD_V:
NVT_LOG("Gesture : Word-V.\n");
keycode = gesture_key_array[2];
break;
case GESTURE_DOUBLE_CLICK:
NVT_LOG("Gesture : Double Click.\n");
keycode = gesture_key_array[3];
break;
case GESTURE_WORD_Z:
NVT_LOG("Gesture : Word-Z.\n");
keycode = gesture_key_array[4];
break;
case GESTURE_WORD_M:
NVT_LOG("Gesture : Word-M.\n");
keycode = gesture_key_array[5];
break;
case GESTURE_WORD_O:
NVT_LOG("Gesture : Word-O.\n");
keycode = gesture_key_array[6];
break;
case GESTURE_WORD_e:
NVT_LOG("Gesture : Word-e.\n");
keycode = gesture_key_array[7];
break;
case GESTURE_WORD_S:
NVT_LOG("Gesture : Word-S.\n");
keycode = gesture_key_array[8];
break;
case GESTURE_SLIDE_UP:
NVT_LOG("Gesture : Slide UP.\n");
keycode = gesture_key_array[9];
break;
case GESTURE_SLIDE_DOWN:
NVT_LOG("Gesture : Slide DOWN.\n");
keycode = gesture_key_array[10];
break;
case GESTURE_SLIDE_LEFT:
NVT_LOG("Gesture : Slide LEFT.\n");
keycode = gesture_key_array[11];
break;
case GESTURE_SLIDE_RIGHT:
NVT_LOG("Gesture : Slide RIGHT.\n");
keycode = gesture_key_array[12];
break;
default:
break;
}
if (keycode > 0) {
input_report_key(ts->input_dev, keycode, 1);
input_sync(ts->input_dev);
input_report_key(ts->input_dev, keycode, 0);
input_sync(ts->input_dev);
}
}
#endif
/*******************************************************
Description:
Novatek touchscreen parse device tree function.
return:
n.a.
*******************************************************/
#ifdef CONFIG_OF
static int nvt_parse_dt(struct device *dev)
{
struct device_node *temp, *np = dev->of_node;
struct nvt_config_info *config_info;
int retval;
u32 temp_val;
const char *name;
ts->irq_gpio = of_get_named_gpio_flags(np, "novatek,irq-gpio", 0, &ts->irq_flags);
NVT_LOG("novatek,irq-gpio=%d\n", ts->irq_gpio);
ts->reset_gpio = of_get_named_gpio_flags(np, "novatek,reset-gpio", 0, NULL);
NVT_LOG("novatek,reset-gpio=%d\n", ts->reset_gpio);
ts->reset_tddi = of_get_named_gpio_flags(np, "novatek,reset-tddi", 0, NULL);
NVT_LOG("novatek,reset-tddi=%d\n", ts->reset_tddi);
retval = of_property_read_string(np, "novatek,vddio-reg-name", &name);
if (retval == -EINVAL)
ts->vddio_reg_name = NULL;
else if (retval < 0)
return -EINVAL;
else {
ts->vddio_reg_name = name;
NVT_LOG("vddio_reg_name = %s\n", name);
}
retval = of_property_read_string(np, "novatek,lab-reg-name", &name);
if (retval == -EINVAL)
ts->lab_reg_name = NULL;
else if (retval < 0)
return -EINVAL;
else {
ts->lab_reg_name = name;
NVT_LOG("lab_reg_name = %s\n", name);
}
retval = of_property_read_string(np, "novatek,ibb-reg-name", &name);
if (retval == -EINVAL)
ts->ibb_reg_name = NULL;
else if (retval < 0)
return -EINVAL;
else {
ts->ibb_reg_name = name;
NVT_LOG("ibb_reg_name = %s\n", name);
}
retval = of_property_read_u32(np, "novatek,config-array-size",
(u32 *) &ts->config_array_size);
if (retval) {
NVT_LOG("Unable to get array size\n");
return retval;
}
ts->config_array = devm_kzalloc(dev, ts->config_array_size *
sizeof(struct nvt_config_info),
GFP_KERNEL);
if (!ts->config_array) {
NVT_LOG("Unable to allocate memory\n");
return -ENOMEM;
}
config_info = ts->config_array;
for_each_child_of_node(np, temp) {
retval = of_property_read_u32(temp, "novatek,tp-vendor", &temp_val);
if (retval) {
NVT_LOG("Unable to read tp vendor\n");
} else {
config_info->tp_vendor = (u8) temp_val;
NVT_LOG("tp vendor: %u", config_info->tp_vendor);
}
retval = of_property_read_u32(temp, "novatek,hw-version", &temp_val);
if (retval) {
NVT_LOG("Unable to read tp hw version\n");
} else {
config_info->tp_hw_version = (u8) temp_val;
NVT_LOG("tp hw version: %u", config_info->tp_hw_version);
}
retval = of_property_read_string(temp, "novatek,fw-name",
&config_info->nvt_cfg_name);
if (retval && (retval != -EINVAL)) {
NVT_LOG("Unable to read cfg name\n");
} else {
NVT_LOG("fw_name: %s", config_info->nvt_cfg_name);
}
retval = of_property_read_string(temp, "novatek,limit-name",
&config_info->nvt_limit_name);
if (retval && (retval != -EINVAL)) {
NVT_LOG("Unable to read limit name\n");
} else {
NVT_LOG("limit_name: %s", config_info->nvt_limit_name);
}
config_info++;
}
return 0;
}
#else
static int nvt_parse_dt(struct device *dev)
{
ts->irq_gpio = NVTTOUCH_INT_PIN;
return 0;
}
#endif
static const char *nvt_get_config(struct nvt_ts_data *ts)
{
int i;
for (i = 0; i < ts->config_array_size; i++) {
if ((ts->lockdown_info[0] ==
ts->config_array[i].tp_vendor) &&
(ts->lockdown_info[3] ==
ts->config_array[i].tp_hw_version))
break;
}
if (i >= ts->config_array_size) {
NVT_LOG("can't find right config\n");
return BOOT_UPDATE_FIRMWARE_NAME;
}
NVT_LOG("Choose config %d: %s", i,
ts->config_array[i].nvt_cfg_name);
ts->current_index = i;
return ts->config_array[i].nvt_cfg_name;
}
static int nvt_get_reg(struct nvt_ts_data *ts, bool get)
{
int retval;
if (!get) {
retval = 0;
goto regulator_put;
}
if ((ts->vddio_reg_name != NULL) && (*ts->vddio_reg_name != 0)) {
ts->vddio_reg = regulator_get(&ts->client->dev,
ts->vddio_reg_name);
if (IS_ERR(ts->vddio_reg)) {
NVT_ERR("Failed to get power regulator\n");
retval = PTR_ERR(ts->vddio_reg);
goto regulator_put;
}
}
if ((ts->lab_reg_name != NULL) && (*ts->lab_reg_name != 0)) {
ts->lab_reg = regulator_get(&ts->client->dev,
ts->lab_reg_name);
if (IS_ERR(ts->lab_reg)) {
NVT_ERR("Failed to get lab regulator\n");
retval = PTR_ERR(ts->lab_reg);
goto regulator_put;
}
}
if ((ts->ibb_reg_name != NULL) && (*ts->ibb_reg_name != 0)) {
ts->ibb_reg = regulator_get(&ts->client->dev,
ts->ibb_reg_name);
if (IS_ERR(ts->ibb_reg)) {
NVT_ERR("Failed to get ibb regulator\n");
retval = PTR_ERR(ts->ibb_reg);
goto regulator_put;
}
}
return 0;
regulator_put:
if (ts->vddio_reg) {
regulator_put(ts->vddio_reg);
ts->vddio_reg = NULL;
}
if (ts->lab_reg) {
regulator_put(ts->lab_reg);
ts->lab_reg = NULL;
}
if (ts->ibb_reg) {
regulator_put(ts->ibb_reg);
ts->ibb_reg = NULL;
}
return retval;
}
static int nvt_enable_reg(struct nvt_ts_data *ts, bool enable)
{
int retval;
if (!enable) {
retval = 0;
goto disable_ibb_reg;
}
if (ts->vddio_reg) {
retval = regulator_enable(ts->vddio_reg);
if (retval < 0) {
NVT_ERR("Failed to enable vddio regulator\n");
goto exit;
}
}
if (ts->lab_reg && ts->lab_reg) {
retval = regulator_enable(ts->lab_reg);
if (retval < 0) {
NVT_ERR("Failed to enable lab regulator\n");
goto disable_vddio_reg;
}
}
if (ts->ibb_reg) {
retval = regulator_enable(ts->ibb_reg);
if (retval < 0) {
NVT_ERR("Failed to enable ibb regulator\n");
goto disable_lab_reg;
}
}
return 0;
disable_ibb_reg:
if (ts->ibb_reg)
regulator_disable(ts->ibb_reg);
disable_lab_reg:
if (ts->lab_reg)
regulator_disable(ts->lab_reg);
disable_vddio_reg:
if (ts->vddio_reg)
regulator_disable(ts->vddio_reg);
exit:
return retval;
}
/*******************************************************
Description:
Novatek touchscreen config and request gpio
return:
Executive outcomes. 0---succeed. not 0---failed.
*******************************************************/
static int nvt_gpio_config(struct nvt_ts_data *ts)
{
int32_t ret = 0;
/* request INT-pin (Input) */
if (gpio_is_valid(ts->irq_gpio)) {
ret = gpio_request_one(ts->irq_gpio, GPIOF_IN, "NVT-int");
if (ret) {
NVT_ERR("Failed to request NVT-int GPIO\n");
goto err_request_irq_gpio;
}
}
if (gpio_is_valid(ts->reset_gpio)) {
ret = gpio_request_one(ts->reset_gpio, GPIOF_OUT_INIT_HIGH, "NVT-reset");
if (ret) {
NVT_ERR("Failed to request reset-int GPIO\n");
goto err_request_reset_gpio;
}
gpio_direction_output(ts->reset_gpio, 1);
}
return ret;
err_request_reset_gpio: