forked from torvalds/linux
/
ft5x_ts.c
1979 lines (1713 loc) · 50.2 KB
/
ft5x_ts.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
/*
* drivers/input/touchscreen/ft5x0x_ts.c
*
* FocalTech ft5x TouchScreen driver.
*
* Copyright (c) 2010 Focal tech Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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.
*
*
* note: only support mulititouch Wenfs 2010-10-01
* for this touchscreen to work, it's slave addr must be set to 0x7e | 0x70
*/
#include <linux/i2c.h>
#include <linux/input.h>
#include "ft5x_ts.h"
#ifdef CONFIG_HAS_EARLYSUSPEND
#include <linux/pm.h>
#include <linux/earlysuspend.h>
#endif
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/async.h>
#include <linux/hrtimer.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <mach/irqs.h>
#include <mach/system.h>
#include <mach/hardware.h>
#include <mach/sys_config.h>
#include "ctp_platform_ops.h"
#define FOR_TSLIB_TEST
//#define PRINT_INT_INFO
//#define PRINT_POINT_INFO
//#define DEBUG
//#define TOUCH_KEY_SUPPORT
#ifdef TOUCH_KEY_SUPPORT
//#define TOUCH_KEY_LIGHT_SUPPORT
//#define TOUCH_KEY_FOR_EVB13
//#define TOUCH_KEY_FOR_ANGDA
#ifdef TOUCH_KEY_FOR_ANGDA
#define TOUCH_KEY_X_LIMIT (60000)
#define TOUCH_KEY_NUMBER (4)
#endif
#ifdef TOUCH_KEY_FOR_EVB13
#define TOUCH_KEY_LOWER_X_LIMIT (848)
#define TOUCH_KEY_HIGHER_X_LIMIT (852)
#define TOUCH_KEY_NUMBER (5)
#endif
#endif
//#define CONFIG_SUPPORT_FTS_CTP_UPG
struct i2c_dev{
struct list_head list;
struct i2c_adapter *adap;
struct device *dev;
};
static struct class *i2c_dev_class;
static LIST_HEAD (i2c_dev_list);
static DEFINE_SPINLOCK(i2c_dev_list_lock);
#define FT5X_NAME "ft5x_ts"//"synaptics_i2c_rmi"//"synaptics-rmi-ts"//
#define CHARDEV_NAME "aw_i2c_ts"
static struct i2c_client *this_client;
#ifdef TOUCH_KEY_LIGHT_SUPPORT
static int gpio_light_hdle = 0;
#endif
#ifdef TOUCH_KEY_SUPPORT
static int key_tp = 0;
static int key_val = 0;
#endif
#ifdef PRINT_POINT_INFO
#define print_point_info(fmt, args...) \
do{ \
pr_info(fmt, ##args); \
}while(0)
#else
#define print_point_info(fmt, args...) //
#endif
#ifdef PRINT_INT_INFO
#define print_int_info(fmt, args...) \
do{ \
pr_info(fmt, ##args); \
}while(0)
#else
#define print_int_info(fmt, args...) //
#endif
///////////////////////////////////////////////
//specific tp related macro: need be configured for specific tp
#define CTP_IRQ_NO (gpio_int_info[0].port_num)
#define CTP_IRQ_MODE (NEGATIVE_EDGE)
#define CTP_NAME FT5X_NAME
#define TS_RESET_LOW_PERIOD (1)
#define TS_INITIAL_HIGH_PERIOD (30)
#define TS_WAKEUP_LOW_PERIOD (20)
#define TS_WAKEUP_HIGH_PERIOD (20)
#define TS_POLL_DELAY (10) /* ms delay between samples */
#define TS_POLL_PERIOD (10) /* ms delay between samples */
#define SCREEN_MAX_X (screen_max_x)
#define SCREEN_MAX_Y (screen_max_y)
#define PRESS_MAX (255)
static void* __iomem gpio_addr = NULL;
static int gpio_int_hdle = 0;
static int gpio_wakeup_hdle = 0;
static int gpio_reset_hdle = 0;
static int gpio_wakeup_enable = 1;
static int gpio_reset_enable = 1;
static user_gpio_set_t gpio_int_info[1];
static int screen_max_x = 0;
static int screen_max_y = 0;
static int revert_x_flag = 0;
static int revert_y_flag = 0;
static int exchange_x_y_flag = 0;
static int int_cfg_addr[]={PIO_INT_CFG0_OFFSET,PIO_INT_CFG1_OFFSET,
PIO_INT_CFG2_OFFSET, PIO_INT_CFG3_OFFSET};
/* Addresses to scan */
static union{
unsigned short dirty_addr_buf[2];
const unsigned short normal_i2c[2];
}u_i2c_addr = {{0x00},};
static __u32 twi_id = 0;
/*
* ctp_get_pendown_state : get the int_line data state,
*
* return value:
* return PRESS_DOWN: if down
* return FREE_UP: if up,
* return 0: do not need process, equal free up.
*/
static int ctp_get_pendown_state(void)
{
unsigned int reg_val;
static int state = FREE_UP;
//get the input port state
reg_val = readl(gpio_addr + PIOH_DATA);
//pr_info("reg_val = %x\n",reg_val);
if(!(reg_val & (1<<CTP_IRQ_NO))){
state = PRESS_DOWN;
print_int_info("pen down. \n");
}else{ //touch panel is free up
state = FREE_UP;
print_int_info("free up. \n");
}
return state;
}
/**
* ctp_clear_penirq - clear int pending
*
*/
static void ctp_clear_penirq(void)
{
int reg_val;
//clear the IRQ_EINT29 interrupt pending
//pr_info("clear pend irq pending\n");
reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
//writel(reg_val,gpio_addr + PIO_INT_STAT_OFFSET);
//writel(reg_val&(1<<(IRQ_EINT21)),gpio_addr + PIO_INT_STAT_OFFSET);
if((reg_val = (reg_val&(1<<(CTP_IRQ_NO))))){
print_int_info("==CTP_IRQ_NO=\n");
writel(reg_val,gpio_addr + PIO_INT_STAT_OFFSET);
}
return;
}
/**
* ctp_set_irq_mode - according sysconfig's subkey "ctp_int_port" to config int port.
*
* return value:
* 0: success;
* others: fail;
*/
static int ctp_set_irq_mode(char *major_key, char *subkey, ext_int_mode int_mode)
{
int ret = 0;
__u32 reg_num = 0;
__u32 reg_addr = 0;
__u32 reg_val = 0;
//config gpio to int mode
pr_info("%s: config gpio to int mode. \n", __func__);
#ifndef SYSCONFIG_GPIO_ENABLE
#else
if(gpio_int_hdle){
gpio_release(gpio_int_hdle, 2);
}
gpio_int_hdle = gpio_request_ex(major_key, subkey);
if(!gpio_int_hdle){
pr_info("request tp_int_port failed. \n");
ret = -1;
goto request_tp_int_port_failed;
}
gpio_get_one_pin_status(gpio_int_hdle, gpio_int_info, subkey, 1);
pr_info("%s, %d: gpio_int_info, port = %d, port_num = %d. \n", __func__, __LINE__, \
gpio_int_info[0].port, gpio_int_info[0].port_num);
#endif
#ifdef AW_GPIO_INT_API_ENABLE
#else
pr_info(" INTERRUPT CONFIG\n");
reg_num = (gpio_int_info[0].port_num)%8;
reg_addr = (gpio_int_info[0].port_num)/8;
reg_val = readl(gpio_addr + int_cfg_addr[reg_addr]);
reg_val &= (~(7 << (reg_num * 4)));
reg_val |= (int_mode << (reg_num * 4));
writel(reg_val,gpio_addr+int_cfg_addr[reg_addr]);
ctp_clear_penirq();
reg_val = readl(gpio_addr+PIO_INT_CTRL_OFFSET);
reg_val |= (1 << (gpio_int_info[0].port_num));
writel(reg_val,gpio_addr+PIO_INT_CTRL_OFFSET);
udelay(1);
#endif
request_tp_int_port_failed:
return ret;
}
/**
* ctp_set_gpio_mode - according sysconfig's subkey "ctp_io_port" to config io port.
*
* return value:
* 0: success;
* others: fail;
*/
static int ctp_set_gpio_mode(void)
{
//int reg_val;
int ret = 0;
//config gpio to io mode
pr_info("%s: config gpio to io mode. \n", __func__);
#ifndef SYSCONFIG_GPIO_ENABLE
#else
if(gpio_int_hdle){
gpio_release(gpio_int_hdle, 2);
}
gpio_int_hdle = gpio_request_ex("ctp_para", "ctp_io_port");
if(!gpio_int_hdle){
pr_info("request ctp_io_port failed. \n");
ret = -1;
goto request_tp_io_port_failed;
}
#endif
return ret;
request_tp_io_port_failed:
return ret;
}
/**
* ctp_judge_int_occur - whether interrupt occur.
*
* return value:
* 0: int occur;
* others: no int occur;
*/
static int ctp_judge_int_occur(void)
{
//int reg_val[3];
int reg_val;
int ret = -1;
reg_val = readl(gpio_addr + PIO_INT_STAT_OFFSET);
if(reg_val&(1<<(CTP_IRQ_NO))){
ret = 0;
}
return ret;
}
/**
* ctp_free_platform_resource - corresponding with ctp_init_platform_resource
*
*/
static void ctp_free_platform_resource(void)
{
if(gpio_addr){
iounmap(gpio_addr);
}
if(gpio_int_hdle){
gpio_release(gpio_int_hdle, 2);
}
if(gpio_wakeup_hdle){
gpio_release(gpio_wakeup_hdle, 2);
}
if(gpio_reset_hdle){
gpio_release(gpio_reset_hdle, 2);
}
return;
}
/**
* ctp_init_platform_resource - initialize platform related resource
* return value: 0 : success
* -EIO : i/o err.
*
*/
static int ctp_init_platform_resource(void)
{
int ret = 0;
gpio_addr = ioremap(PIO_BASE_ADDRESS, PIO_RANGE_SIZE);
//pr_info("%s, gpio_addr = 0x%x. \n", __func__, gpio_addr);
if(!gpio_addr) {
ret = -EIO;
goto exit_ioremap_failed;
}
// gpio_wakeup_enable = 1;
gpio_wakeup_hdle = gpio_request_ex("ctp_para", "ctp_wakeup");
if(!gpio_wakeup_hdle) {
pr_warning("%s: tp_wakeup request gpio fail!\n", __func__);
gpio_wakeup_enable = 0;
}
gpio_reset_hdle = gpio_request_ex("ctp_para", "ctp_reset");
if(!gpio_reset_hdle) {
pr_warning("%s: tp_reset request gpio fail!\n", __func__);
gpio_reset_enable = 0;
}
return ret;
exit_ioremap_failed:
ctp_free_platform_resource();
return ret;
}
/**
* ctp_fetch_sysconfig_para - get config info from sysconfig.fex file.
* return value:
* = 0; success;
* < 0; err
*/
static int ctp_fetch_sysconfig_para(void)
{
int ret = -1;
int ctp_used = -1;
char name[I2C_NAME_SIZE];
__u32 twi_addr = 0;
//__u32 twi_id = 0;
script_parser_value_type_t type = SCIRPT_PARSER_VALUE_TYPE_STRING;
pr_info("%s. \n", __func__);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_used", &ctp_used, 1)){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
if(1 != ctp_used){
pr_err("%s: ctp_unused. \n", __func__);
//ret = 1;
return ret;
}
if(SCRIPT_PARSER_OK != script_parser_fetch_ex("ctp_para", "ctp_name", (int *)(&name), &type, sizeof(name)/sizeof(int))){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
if(strcmp(CTP_NAME, name)){
pr_err("%s: name %s does not match CTP_NAME. \n", __func__, name);
pr_err(CTP_NAME);
//ret = 1;
return ret;
}
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_twi_addr", &twi_addr, sizeof(twi_addr)/sizeof(__u32))){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
//big-endian or small-endian?
//pr_info("%s: before: ctp_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", __func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);
u_i2c_addr.dirty_addr_buf[0] = twi_addr;
u_i2c_addr.dirty_addr_buf[1] = I2C_CLIENT_END;
pr_info("%s: after: ctp_twi_addr is 0x%x, dirty_addr_buf: 0x%hx. dirty_addr_buf[1]: 0x%hx \n", __func__, twi_addr, u_i2c_addr.dirty_addr_buf[0], u_i2c_addr.dirty_addr_buf[1]);
//pr_info("%s: after: ctp_twi_addr is 0x%x, u32_dirty_addr_buf: 0x%hx. u32_dirty_addr_buf[1]: 0x%hx \n", __func__, twi_addr, u32_dirty_addr_buf[0],u32_dirty_addr_buf[1]);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_twi_id", &twi_id, sizeof(twi_id)/sizeof(__u32))){
pr_err("%s: script_parser_fetch err. \n", name);
goto script_parser_fetch_err;
}
pr_info("%s: ctp_twi_id is %d. \n", __func__, twi_id);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_screen_max_x", &screen_max_x, 1)){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: screen_max_x = %d. \n", __func__, screen_max_x);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_screen_max_y", &screen_max_y, 1)){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: screen_max_y = %d. \n", __func__, screen_max_y);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_revert_x_flag", &revert_x_flag, 1)){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: revert_x_flag = %d. \n", __func__, revert_x_flag);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_revert_y_flag", &revert_y_flag, 1)){
pr_err("%s: script_parser_fetch err. \n", __func__);
goto script_parser_fetch_err;
}
pr_info("%s: revert_y_flag = %d. \n", __func__, revert_y_flag);
if(SCRIPT_PARSER_OK != script_parser_fetch("ctp_para", "ctp_exchange_x_y_flag", &exchange_x_y_flag, 1)){
pr_err("ft5x_ts: script_parser_fetch err. \n");
goto script_parser_fetch_err;
}
pr_info("%s: exchange_x_y_flag = %d. \n", __func__, exchange_x_y_flag);
return 0;
script_parser_fetch_err:
pr_notice("=========script_parser_fetch_err============\n");
return ret;
}
/**
* ctp_reset - function
*
*/
static void ctp_reset(void)
{
if(gpio_reset_enable){
pr_info("%s. \n", __func__);
if(EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_reset_hdle, 0, "ctp_reset")){
pr_info("%s: err when operate gpio. \n", __func__);
}
mdelay(TS_RESET_LOW_PERIOD);
if(EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_reset_hdle, 1, "ctp_reset")){
pr_info("%s: err when operate gpio. \n", __func__);
}
mdelay(TS_INITIAL_HIGH_PERIOD);
}
}
/**
* ctp_wakeup - function
*
*/
static void ctp_wakeup(void)
{
if(1 == gpio_wakeup_enable){
pr_info("%s. \n", __func__);
if(EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_wakeup_hdle, 0, "ctp_wakeup")){
pr_info("%s: err when operate gpio. \n", __func__);
}
mdelay(TS_WAKEUP_LOW_PERIOD);
if(EGPIO_SUCCESS != gpio_write_one_pin_value(gpio_wakeup_hdle, 1, "ctp_wakeup")){
pr_info("%s: err when operate gpio. \n", __func__);
}
mdelay(TS_WAKEUP_HIGH_PERIOD);
}
return;
}
/**
* ctp_detect - Device detection callback for automatic device creation
* return value:
* = 0; success;
* < 0; err
*/
int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
{
struct i2c_adapter *adapter = client->adapter;
if(twi_id == adapter->nr)
{
pr_info("%s: Detected chip %s at adapter %d, address 0x%02x\n",
__func__, CTP_NAME, i2c_adapter_id(adapter), client->addr);
strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
return 0;
}else{
return -ENODEV;
}
}
////////////////////////////////////////////////////////////////
static struct ctp_platform_ops ctp_ops = {
.get_pendown_state = ctp_get_pendown_state,
.clear_penirq = ctp_clear_penirq,
.set_irq_mode = ctp_set_irq_mode,
.set_gpio_mode = ctp_set_gpio_mode,
.judge_int_occur = ctp_judge_int_occur,
.init_platform_resource = ctp_init_platform_resource,
.free_platform_resource = ctp_free_platform_resource,
.fetch_sysconfig_para = ctp_fetch_sysconfig_para,
.ts_reset = ctp_reset,
.ts_wakeup = ctp_wakeup,
.ts_detect = ctp_detect,
};
int fts_ctpm_fw_upgrade_with_i_file(void);
static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
{
struct i2c_dev *i2c_dev;
spin_lock(&i2c_dev_list_lock);
list_for_each_entry(i2c_dev,&i2c_dev_list,list){
pr_info("--line = %d ,i2c_dev->adapt->nr = %d,index = %d.\n",__LINE__,i2c_dev->adap->nr,index);
if(i2c_dev->adap->nr == index){
goto found;
}
}
i2c_dev = NULL;
found:
spin_unlock(&i2c_dev_list_lock);
return i2c_dev ;
}
static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
{
struct i2c_dev *i2c_dev;
if (adap->nr >= I2C_MINORS){
pr_info("i2c-dev:out of device minors (%d) \n",adap->nr);
return ERR_PTR (-ENODEV);
}
i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
if (!i2c_dev){
return ERR_PTR(-ENOMEM);
}
i2c_dev->adap = adap;
spin_lock(&i2c_dev_list_lock);
list_add_tail(&i2c_dev->list, &i2c_dev_list);
spin_unlock(&i2c_dev_list_lock);
return i2c_dev;
}
static int ft5x_i2c_rxdata(char *rxdata, int length);
struct ts_event {
u16 x1;
u16 y1;
u16 x2;
u16 y2;
u16 x3;
u16 y3;
u16 x4;
u16 y4;
u16 x5;
u16 y5;
u16 pressure;
s16 touch_ID1;
s16 touch_ID2;
s16 touch_ID3;
s16 touch_ID4;
s16 touch_ID5;
u8 touch_point;
};
struct ft5x_ts_data {
struct input_dev *input_dev;
struct ts_event event;
struct work_struct pen_event_work;
struct workqueue_struct *ts_workqueue;
#ifdef CONFIG_HAS_EARLYSUSPEND
struct early_suspend early_suspend;
#endif
};
/* ---------------------------------------------------------------------
*
* Focal Touch panel upgrade related driver
*
*
----------------------------------------------------------------------*/
typedef enum
{
ERR_OK,
ERR_MODE,
ERR_READID,
ERR_ERASE,
ERR_STATUS,
ERR_ECC,
ERR_DL_ERASE_FAIL,
ERR_DL_PROGRAM_FAIL,
ERR_DL_VERIFY_FAIL
}E_UPGRADE_ERR_TYPE;
typedef unsigned char FTS_BYTE; //8 bit
typedef unsigned short FTS_WORD; //16 bit
typedef unsigned int FTS_DWRD; //16 bit
typedef unsigned char FTS_BOOL; //8 bit
#define FTS_NULL 0x0
#define FTS_TRUE 0x01
#define FTS_FALSE 0x0
#define I2C_CTPM_ADDRESS (0x70>>1)
void delay_ms(FTS_WORD w_ms)
{
//platform related, please implement this function
msleep( w_ms );
}
/*
[function]:
callback: read data from ctpm by i2c interface,implemented by special user;
[parameters]:
bt_ctpm_addr[in] :the address of the ctpm;
pbt_buf[out] :data buffer;
dw_lenth[in] :the length of the data buffer;
[return]:
FTS_TRUE :success;
FTS_FALSE :fail;
*/
int i2c_read_interface(u8 bt_ctpm_addr, u8* pbt_buf, u16 dw_lenth)
{
int ret;
ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);
if(ret != dw_lenth){
pr_info("ret = %d. \n", ret);
pr_info("i2c_read_interface error\n");
return FTS_FALSE;
}
return FTS_TRUE;
}
/*
[function]:
callback: write data to ctpm by i2c interface,implemented by special user;
[parameters]:
bt_ctpm_addr[in] :the address of the ctpm;
pbt_buf[in] :data buffer;
dw_lenth[in] :the length of the data buffer;
[return]:
FTS_TRUE :success;
FTS_FALSE :fail;
*/
int i2c_write_interface(u8 bt_ctpm_addr, u8* pbt_buf, u16 dw_lenth)
{
int ret;
ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
if(ret != dw_lenth){
pr_info("i2c_write_interface error\n");
return FTS_FALSE;
}
return FTS_TRUE;
}
/***************************************************************************************/
/*
[function]:
read out the register value.
[parameters]:
e_reg_name[in] :register name;
pbt_buf[out] :the returned register value;
bt_len[in] :length of pbt_buf, should be set to 2;
[return]:
FTS_TRUE :success;
FTS_FALSE :io fail;
*/
u8 fts_register_read(u8 e_reg_name, u8* pbt_buf, u8 bt_len)
{
u8 read_cmd[3]= {0};
u8 cmd_len = 0;
read_cmd[0] = e_reg_name;
cmd_len = 1;
/*call the write callback function*/
// if(!i2c_write_interface(I2C_CTPM_ADDRESS, &read_cmd, cmd_len))
// {
// return FTS_FALSE;
// }
if(!i2c_write_interface(I2C_CTPM_ADDRESS, read_cmd, cmd_len)) {//change by zhengdixu
return FTS_FALSE;
}
/*call the read callback function to get the register value*/
if(!i2c_read_interface(I2C_CTPM_ADDRESS, pbt_buf, bt_len)){
return FTS_FALSE;
}
return FTS_TRUE;
}
/*
[function]:
write a value to register.
[parameters]:
e_reg_name[in] :register name;
pbt_buf[in] :the returned register value;
[return]:
FTS_TRUE :success;
FTS_FALSE :io fail;
*/
int fts_register_write(u8 e_reg_name, u8 bt_value)
{
FTS_BYTE write_cmd[2] = {0};
write_cmd[0] = e_reg_name;
write_cmd[1] = bt_value;
/*call the write callback function*/
//return i2c_write_interface(I2C_CTPM_ADDRESS, &write_cmd, 2);
return i2c_write_interface(I2C_CTPM_ADDRESS, write_cmd, 2); //change by zhengdixu
}
/*
[function]:
send a command to ctpm.
[parameters]:
btcmd[in] :command code;
btPara1[in] :parameter 1;
btPara2[in] :parameter 2;
btPara3[in] :parameter 3;
num[in] :the valid input parameter numbers, if only command code needed and no parameters followed,then the num is 1;
[return]:
FTS_TRUE :success;
FTS_FALSE :io fail;
*/
int cmd_write(u8 btcmd,u8 btPara1,u8 btPara2,u8 btPara3,u8 num)
{
FTS_BYTE write_cmd[4] = {0};
write_cmd[0] = btcmd;
write_cmd[1] = btPara1;
write_cmd[2] = btPara2;
write_cmd[3] = btPara3;
//return i2c_write_interface(I2C_CTPM_ADDRESS, &write_cmd, num);
return i2c_write_interface(I2C_CTPM_ADDRESS, write_cmd, num);//change by zhengdixu
}
/*
[function]:
write data to ctpm , the destination address is 0.
[parameters]:
pbt_buf[in] :point to data buffer;
bt_len[in] :the data numbers;
[return]:
FTS_TRUE :success;
FTS_FALSE :io fail;
*/
int byte_write(u8* pbt_buf, u16 dw_len)
{
return i2c_write_interface(I2C_CTPM_ADDRESS, pbt_buf, dw_len);
}
/*
[function]:
read out data from ctpm,the destination address is 0.
[parameters]:
pbt_buf[out] :point to data buffer;
bt_len[in] :the data numbers;
[return]:
FTS_TRUE :success;
FTS_FALSE :io fail;
*/
int byte_read(u8* pbt_buf, u8 bt_len)
{
return i2c_read_interface(I2C_CTPM_ADDRESS, pbt_buf, bt_len);
//ft5x_i2c_rxdata
}
/*
[function]:
burn the FW to ctpm.
[parameters]:(ref. SPEC)
pbt_buf[in] :point to Head+FW ;
dw_lenth[in]:the length of the FW + 6(the Head length);
bt_ecc[in] :the ECC of the FW
[return]:
ERR_OK :no error;
ERR_MODE :fail to switch to UPDATE mode;
ERR_READID :read id fail;
ERR_ERASE :erase chip fail;
ERR_STATUS :status error;
ERR_ECC :ecc error.
*/
#define FTS_PACKET_LENGTH 128 //2//4//8//16//32//64//128//256
static unsigned char CTPM_FW[]=
{
#include "ft_app.i"
};
unsigned char fts_ctpm_get_i_file_ver(void)
{
unsigned int ui_sz;
ui_sz = sizeof(CTPM_FW);
if (ui_sz > 2)
{
return CTPM_FW[ui_sz - 2];
}
else
{
//TBD, error handling?
return 0xff; //default value
}
}
E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(u8* pbt_buf, u16 dw_lenth)
{
u8 reg_val[2] = {0};
FTS_BOOL i_ret = 0;
u16 i = 0;
u16 packet_number;
u16 j;
u16 temp;
u16 lenght;
u8 packet_buf[FTS_PACKET_LENGTH + 6];
u8 auc_i2c_write_buf[10];
u8 bt_ecc;
/*********Step 1:Reset CTPM *****/
/*write 0xaa to register 0xfc*/
delay_ms(100);
fts_register_write(0xfc,0xaa);
delay_ms(50);
/*write 0x55 to register 0xfc*/
fts_register_write(0xfc,0x55);
pr_info("Step 1: Reset CTPM test\n");
delay_ms(30);
/*********Step 2:Enter upgrade mode *****/
auc_i2c_write_buf[0] = 0x55;
auc_i2c_write_buf[1] = 0xaa;
i = 0;
do{
i++;
i_ret = i2c_write_interface(I2C_CTPM_ADDRESS, auc_i2c_write_buf, 2);
pr_info("Step 2: Enter update mode. \n");
delay_ms(5);
}while((FTS_FALSE == i_ret) && i<5);
/*********Step 3:check READ-ID***********************/
/*send the opration head*/
i = 0;
do{
if(i > 3)
{
cmd_write(0x07,0x00,0x00,0x00,1);
return ERR_READID;
}
/*read out the CTPM ID*/
pr_info("====Step 3:check READ-ID====");
cmd_write(0x90,0x00,0x00,0x00,4);
byte_read(reg_val,2);
i++;
delay_ms(5);
pr_info("Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
}while(reg_val[1] != 0x03);//while(reg_val[0] != 0x79 || reg_val[1] != 0x03);
/*********Step 4:erase app*******************************/
cmd_write(0x61,0x00,0x00,0x00,1);
delay_ms(1500);
pr_info("Step 4: erase. \n");
/*********Step 5:write firmware(FW) to ctpm flash*********/
bt_ecc = 0;
pr_info("Step 5: start upgrade. \n");
dw_lenth = dw_lenth - 8;
packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
packet_buf[0] = 0xbf;
packet_buf[1] = 0x00;
for (j=0;j<packet_number;j++)
{
temp = j * FTS_PACKET_LENGTH;
packet_buf[2] = (FTS_BYTE)(temp>>8);
packet_buf[3] = (FTS_BYTE)temp;
lenght = FTS_PACKET_LENGTH;
packet_buf[4] = (FTS_BYTE)(lenght>>8);
packet_buf[5] = (FTS_BYTE)lenght;
for (i=0;i<FTS_PACKET_LENGTH;i++)
{
packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
bt_ecc ^= packet_buf[6+i];
}
byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
delay_ms(FTS_PACKET_LENGTH/6 + 1);
if ((j * FTS_PACKET_LENGTH % 1024) == 0)
{
pr_info("upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
}
}
if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
{
temp = packet_number * FTS_PACKET_LENGTH;
packet_buf[2] = (FTS_BYTE)(temp>>8);
packet_buf[3] = (FTS_BYTE)temp;
temp = (dw_lenth) % FTS_PACKET_LENGTH;
packet_buf[4] = (FTS_BYTE)(temp>>8);
packet_buf[5] = (FTS_BYTE)temp;
for (i=0;i<temp;i++)
{
packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
bt_ecc ^= packet_buf[6+i];
}
byte_write(&packet_buf[0],temp+6);
delay_ms(20);
}
//send the last six byte
for (i = 0; i<6; i++)
{
temp = 0x6ffa + i;
packet_buf[2] = (FTS_BYTE)(temp>>8);
packet_buf[3] = (FTS_BYTE)temp;
temp =1;
packet_buf[4] = (FTS_BYTE)(temp>>8);
packet_buf[5] = (FTS_BYTE)temp;
packet_buf[6] = pbt_buf[ dw_lenth + i];
bt_ecc ^= packet_buf[6];
byte_write(&packet_buf[0],7);
delay_ms(20);
}
/*********Step 6: read out checksum***********************/
/*send the opration head*/
//cmd_write(0xcc,0x00,0x00,0x00,1);//把0xcc当作寄存器地址,去读出一个字节
// byte_read(reg_val,1);//change by zhengdixu
fts_register_read(0xcc, reg_val,1);
pr_info("Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
if(reg_val[0] != bt_ecc)
{
cmd_write(0x07,0x00,0x00,0x00,1);
return ERR_ECC;
}
/*********Step 7: reset the new FW***********************/
cmd_write(0x07,0x00,0x00,0x00,1);
msleep(30);
return ERR_OK;
}
int fts_ctpm_auto_clb(void)
{
unsigned char uc_temp;