1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
|
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/i2c.h>
//#include <linux/earlysuspend.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/cdev.h>
#include <asm/uaccess.h>
#include <linux/pm_runtime.h>
#if defined(CONFIG_HAS_EARLYSUSPEND)
#include <linux/earlysuspend.h>
#endif
#include <linux/input/mt.h>
#include <linux/i2c.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/errno.h>
#include <mach/hardware.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/suspend.h>
#include <linux/async.h>
#include <linux/wait.h>
#include <linux/hrtimer.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/irq.h>
#include <linux/kthread.h>
#include <linux/firmware.h>
#include <linux/power/wmt_battery.h>
#include "../../../video/backlight/wmt_bl.h"
#include "lw86x0_ts.h"
#include "wmt_ts.h"
//#include "wmt_custom_lw86x0.h"
#define TIME_CHECK_CHARGE 3000
#define MAX_MULTI_DATA_SIZE 256
#define HDMI_BASE_ADDR (HDMI_TRANSMITTE_BASE_ADDR + 0xC000)
#define REG_HDMI_HOTPLUG_DETECT (HDMI_BASE_ADDR + 0x3ec)
struct i2c_client *lw_i2c_client = NULL;
struct i2c_client *client;//add by jackie
extern char g_dbgmode;
extern int COL_NUM;
extern int ROW_NUM;
extern int SKIP_ZERO_POINT;
struct wmtts_device lw86x0_tsdev;
static int tsirq_gpio;
static int skip_zero_num = 0;
u16 mcu_status_old = 0xffff;
u16 mcu_status = 0xffff;
typedef struct Fw_Version{ //add by jackie
u8 magic_num1;
u8 magic_num2;
u8 mj_ver;
u8 mn_ver;
}Fw_Ver;//add by jackie
//struct for report touch info
struct ts_event {
u16 x[SUPPORT_POINT_NUM_MAX];//point x
u16 y[SUPPORT_POINT_NUM_MAX];//point y
u16 pressure[SUPPORT_POINT_NUM_MAX];//point pressure
u8 touch_point;//touch point number
};
struct lw86x0_ts_data {
struct input_dev *input_dev;
struct ts_event event;
struct work_struct touch_event_work;
struct workqueue_struct *ts_workqueue;
#if defined(CONFIG_HAS_EARLYSUSPEND)
struct early_suspend early_suspend;
#endif
}l_tsdata;
static struct mutex ts_data_mutex;
static int l_powermode = -1;
static int l_hdmimode = -1;
static int l_keylen = 4;
static int l_baseaxis = 1; //0:x-axis,1:y-axis
int l_keypos[TS_KEY_NUM+1][2];
unsigned int l_tskey[TS_KEY_NUM][2] = {
{0,KEY_MENU},
{0,KEY_HOME},
{0,KEY_BACK},
{0,KEY_SEARCH},
};
static int l_early_suspend = 0; // 1:the early suspend function has been excuted
static int stop_timer = 0;
struct work_struct phone_status_work;
struct timer_list polling_phone_status_timer;
static int check_chip_status(void);
static int first_init_reg = 1;
static u16 auto_coff_value[20] = {0};
//static finger_up_status = 1;
u8 get_fw_file_check_sum(void);
u16 get_fw_check_sum(void);
extern int register_bl_notifier(struct notifier_block *nb);
extern int unregister_bl_notifier(struct notifier_block *nb);
//static struct ts_event old_event;
void swap_byte_in_buffer(u16* buf, int count )
{
int i;
for(i = 0; i < count; i++ )
{
buf[i] = swap16(buf[i]);
}
}
/**
** for read register
** rxbuf:read value
** txdata:read register address
** rxlength:read value length
**/
static int lw86x0_i2c_rxdata(char *rxbuf, char*txdata, int rxlength)
{
int ret;
//int reg;//add jackie
struct i2c_msg msgs[] = {
{
.addr = lw_i2c_client->addr,
.flags = 0,
.len = 2,
.buf = txdata,
},
{
.addr = lw_i2c_client->addr,
.flags = I2C_M_RD,
.len = rxlength,
.buf = rxbuf,
},
};
//ret = wmt_i2c_xfer_continue_if_4(msgs, 2, 1);
ret = i2c_transfer(lw_i2c_client->adapter, &msgs[0], 2);//add by jackie
if (ret != 2)
{
dbg("msg i2c rxdata error: %d\n", ret);
return -1;
}
else
{
return 0;
}
#if 0
struct i2c_msg xfer_msg[2];
if (reg < 0x80) {
i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg));
msleep(5);
}
return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT;
#endif
}
/**
** for write register
** txdata:register address and value u8
** length:txdata length
**/
static int lw86x0_i2c_txdata(char *txdata, int length)
{
int ret;
struct i2c_msg msg[] = {
{
.addr = lw_i2c_client->addr,
.flags = 0,
.len = length,
.buf = txdata,
},
};
ret = i2c_transfer(lw_i2c_client->adapter, &msg[0], 1);//1
//ret = wmt_i2c_xfer_continue_if_4(msg, 1, 1);
if (ret != 1)
{
dbg("i2c txdata error: %d\n", ret);
return -1;
}
else
{
return 0;
}
}
/**
** Interface write register for other functions
** addr:write register address
** value:write register value
**/
int lw86x0_write_reg(u16 addr, u16 value)
{
u8 buf[4];
int ret = -1;
unsigned char * pVal = (unsigned char *) &value;
unsigned char * pOffset = (unsigned char *) &addr;
buf[0] = pOffset[1];
buf[1] = pOffset[0];
buf[2] = pVal[1];
buf[3] = pVal[0];
ret = lw86x0_i2c_txdata(buf, 4);
if (ret < 0)
{
dbg("lw86x0_write_reg error: %d\n", ret);
return -1;
}
return 0;
}
/*int lw86x0_write_reg_multi(u16 start_addr, u16 value[], u16 num)
{
u8 buf[MAX_MULTI_DATA_SIZE];
int ret = -1;
int i = 0;
unsigned char * pVal = (unsigned char *) &value[0];
unsigned char * pOffset = (unsigned char *) &addr;
buf[0] = pOffset[1];
buf[1] = pOffset[0];
//buf[2] = pVal[1];
//buf[3] = pVal[0];
for(i = 0; i < num; i++)
{
pVal = (unsigned char *) &value[i];
buf[2*i + 2] = pVal[1];
buf[2*i + 3] = pVal[0];
}
ret = lw86x0_i2c_txdata(buf, num*2+2);
if (ret < 0)
{
dbg("lw86x0_write_reg error: %d\n", ret);
return -1;
}
return 0;
}*/
/**
** Interface read register for other functions
** addr:read register address
** pdata:read register value
** regcnt:read register count
**/
int lw86x0_read_reg(u16 addr, u16 *pdata, int regcnt)
{
int ret;
u16 offset_reverse = swap16(addr);
ret = lw86x0_i2c_rxdata((char*)pdata, (char*)&offset_reverse, 2*regcnt);
if (ret < 0)
{
dbg("lw86x0_read_reg error: %d\n", ret);
return -1;
}
else
{
swap_byte_in_buffer(pdata, regcnt);
return 0;
}
}
int wmt_ts_load_firmware(char* firmwarename, unsigned char** firmdata, int* fwlen)
{
int i;
const struct firmware *fw_entry;
for (i = 0; i < 3; i++) {
if(request_firmware(&fw_entry, firmwarename, &lw_i2c_client->dev)!=0)
printk(KERN_ERR "cat't request firmware #%d\n", i);
else
break;
}
if (i == 3)
return -EINVAL;
if (fw_entry->size <= 0) {
printk(KERN_ERR "load firmware error\n");
release_firmware(fw_entry);
return -1;
}
*firmdata = kzalloc(fw_entry->size + 1, GFP_KERNEL);
memcpy(*firmdata, fw_entry->data, fw_entry->size);
*fwlen = fw_entry->size;
release_firmware(fw_entry);
return 0;
}
static u16 *default_setting_table;
static int cfg_len;
static int load_cfgfile(void)
{
u32 val[2];
u16 temp[200];
int i = 0;
char cfgname[32] = {0};
u8 *pData;
int fileLen;
char *p;
char *s;
wmt_ts_get_configfilename(cfgname);
if (wmt_ts_load_firmware(cfgname, &pData, &fileLen)) {
errlog("Load config file failed~ \n");
return -1;
}
s = pData;
p = strstr(s, "COL_NUM");
sscanf(p, "COL_NUM=%d;", &COL_NUM);
p = strstr(s, "ROW_NUM");
sscanf(p, "ROW_NUM=%d;", &ROW_NUM);
p = strstr(s, "SKIP_ZERO_POINT");
sscanf(p, "SKIP_ZERO_POINT=%d;", &SKIP_ZERO_POINT);
dbg("COL_NUM=%d;ROW_NUM=%d;SKIP_ZERO_POINT=%d;",COL_NUM,ROW_NUM,SKIP_ZERO_POINT);
p = pData;
while (*p != '{') {
p++;
if(*p == '\0') {
errlog("Bad config file\n");
i = -1;
goto end;
}
}
while (*p != '}') {
if (!strncmp(p, "0x", 2)) {
i++;
if ((i & 0x0001) != 0) {
sscanf(p, "0x%x,0x%x,", val, val+1);
temp[i-1] = val[0] & 0x0000FFFF;
temp[i] = val[1] & 0x0000FFFF;
}
}
p++;
if(*p == '\0') {
i = -1;
errlog("Bad config file\n");
goto end;
}
};
dbg("the number of data:0x%x\n", i);
default_setting_table = kzalloc(i*2, GFP_KERNEL);
memcpy(default_setting_table, temp, i*2);
cfg_len = i;
dbg("paring config file end.\n");
end:
kfree(pData);
return i;
}
void lw86x0_stop_timer(int flags)
{
stop_timer = flags;
}
static u16 get_trim_info(void)
{
u16 trim_info = 0;
u8 buf[2] = {0};
lw86x0_write_reg(0x00e4, 0x0000);
lw86x0_write_reg(0x00e2, 0x0302);
lw86x0_write_reg(0x00e3, 0x0000);
lw86x0_write_reg(0x00e2, 0x034e);
lw86x0_write_reg(0x00e2, 0x0302);
lw86x0_read_reg(0x00e4, buf, 1);
lw86x0_write_reg(0x00e2, 0x0000);
trim_info = buf[1];
dbg("trim info is %04x",trim_info);
return trim_info;
}
/**
** load default register setting
**/
void lw86x0_load_def_setting(void)
{
int i = 0;
u16 trim_value = 0;
u16 trim_info = 0;
lw86x0_write_reg(0x00e6, 0x3311);
trim_info = get_trim_info();
for(i = 0; i < cfg_len / 2; i++)
{
if(default_setting_table[2*i] == 0xffff)
{
msleep(default_setting_table[2*i+1]);
}
else
{
if(default_setting_table[2*i] == 0x00ee)
{
lw86x0_read_reg(0x00ee, &trim_value, 1);
if(trim_value == 0x00a0)
{
trim_value = 0x00c0 + trim_info;
}
else
{
trim_value = 0x100 + trim_value;
}
lw86x0_write_reg(0x00ee, trim_value);
}
else
{
lw86x0_write_reg(default_setting_table[2*i], default_setting_table[2*i+1]);
}
//lw86x0_write_reg(default_setting_table[2*i], default_setting_table[2*i+1]);
}
/*if(i == 0)
{
msleep(100);
}*/
}
if(first_init_reg == 1)
{
for(i = 0; i < 19; i++)
{
lw86x0_read_reg(0x0092+i, &auto_coff_value[i], 1);
}
first_init_reg = 0;
}
else
{
lw86x0_write_reg(0x0035, 0x0070);
lw86x0_write_reg(0x0060, 0x0307);
lw86x0_write_reg(0x0091, 0x0200);
for(i = 0; i < 19; i++)
{
lw86x0_write_reg(0x0092+i, auto_coff_value[i]);
}
lw86x0_write_reg(0x0035, 0x2070);
msleep(100);
lw86x0_write_reg(0x0060, 0x0306);
}
}
/**
** set reset pin for lw86x0
**/
static void lw86x0_hw_reset(void)
{
wmt_rst_output(0);
//msleep(500);
msleep(30);
wmt_rst_output(1);
}
static void lw86x0_ts_release(void)
{
int i = 0;
struct lw86x0_ts_data *data = &l_tsdata;
int down = 0;
// dbg("lw86x0_ts_release");
for (i = 0; i < l_keylen; i++)
{
down |= l_tskey[i][0];
}
if (down != 0)
{
// if down clear the flag
for ( i = 0; i < l_keylen; i++)
{
l_tskey[i][0] = 0;
};
//dbg("key up!\n");
if (wmt_ts_enable_keyled())
wmt_ts_turnoff_light();
}
else
{
if (!lw86x0_tsdev.penup)
{
input_mt_sync(data->input_dev);
input_sync(data->input_dev);
//dbg("rpt pen\n");
}
lw86x0_tsdev.penup = 1;
//dbg("pen up\n");
//wake_up(&ts_penup_wait_queue);
}
}
/**
**set wmt touch key count
**/
void wmt_ts_set_keylen(int keylen)
{
l_keylen = keylen;
}
/**
**set wmt touch baseaxis
**axis:0--x axis,1--y axis.
**/
void wmt_ts_set_baseaxis(int axis)
{
l_baseaxis = axis;
}
/**
** set wmt touch key info struct keypos
** index:set key number
** min:key min point value
** max:key max point value
**/
void wmt_ts_set_keypos(int index, int min,int max)
{
l_keypos[index][0] = min;
l_keypos[index][1] = max;
}
/**
** report key info to wmt android
**/
#if 0
static int lw86x0_report_key_info(void)
{
struct lw86x0_ts_data *data = &l_tsdata;
u16 x, y;
u16 key_stpos,key_vrpos; // the stable and variable position for touch key
int i =0;
lw86x0_read_reg(0x0161, &x, 1);
lw86x0_read_reg(0x016B, &y, 1);
if (wmt_ts_enable_tskey() != 0)
{
switch (l_baseaxis)
{
case 0:
key_stpos = y;
key_vrpos = x;
break;
case 1:
default:
key_stpos = x;
key_vrpos = y;
break;
}
}
for (i=0;i < l_keylen;i++)
{
if ((key_vrpos>=l_keypos[i][0]) && (key_vrpos<=l_keypos[i][1]))
{
// report the key
if (0 == l_tskey[i][0])
{
input_report_key(data->input_dev, l_tskey[i][1], 1);
input_report_key(data->input_dev, l_tskey[i][1], 0);
input_sync(data->input_dev);
l_tskey[i][0] = 1;
dbg("report tskey:%d\n",i);
if (wmt_ts_enable_keyled())
wmt_ts_turnon_light();
}
return 1;//key
}
}
return 0;//no key
}
#endif
static void check_mode(void)
{
int dcin = wmt_charger_is_dc_plugin();
int hdmiin = (REG32_VAL(REG_HDMI_HOTPLUG_DETECT) & BIT31) >> 31;
if (dcin == l_powermode && hdmiin == l_hdmimode)
return;
if (!dcin && !hdmiin) {
klog("DC and HDMI removed\n");
lw86x0_write_reg(0x01e9, 0x0000);
} else {
klog("DC or HDMI in\n");
lw86x0_write_reg(0x01e9, 0x0001);
}
l_powermode = dcin;
l_hdmimode = hdmiin;
}
/**
** report touch info to wmt android
** touch_number: touch count
**/
static void lw86x0_report_touch_info(u16 touch_number)
{
struct lw86x0_ts_data *data = &l_tsdata;
struct ts_event *event = &data->event;
u16 i;
//old_event = *event;
//dbg("Enter into lw86x0_report_touch_info");
check_mode();
if(touch_number == 0)
{
input_mt_sync(data->input_dev);
input_sync(data->input_dev);
return;
}
if(touch_number> wmt_ts_get_fingernum()){
//dbg("Invalid Touch point count is found %d",touch_number);
return;
}
event->touch_point = touch_number;
//memset(event->x, 0, SUPPORT_POINT_NUM*sizeof(u16) );
//memset(event->y, 0, SUPPORT_POINT_NUM*sizeof(u16) );
//memset(event->pressure, 0, SUPPORT_POINT_NUM*sizeof(u16) );
for( i = 0; i <touch_number; i++ )
{
lw86x0_read_reg(0x0161+i, &event->x[i], 1);
lw86x0_read_reg(0x016B+i, &event->y[i], 1);
lw86x0_read_reg(0x0175+i, &event->pressure[i], 1);
}
for (i = 0; i < touch_number; i++)
{
int x = (event->x[i]) & 0x03ff;
int y = (event->y[i]) & 0x03ff;
int id = ((event->x[i])>>12)&0x000f;
int tmp;
if(x>wmt_ts_get_resolvX())
{
x = wmt_ts_get_resolvX();
}
if(y>wmt_ts_get_resolvY())
{
y= wmt_ts_get_resolvY();
}
if (wmt_ts_get_xaxis()) {
tmp = x;
x = y;
y = tmp;
}
if (wmt_ts_get_xdir())
x = wmt_ts_get_resolvX() - x;
if (wmt_ts_get_ydir())
y = wmt_ts_get_resolvY() - y;
if (wmt_ts_get_lcdexchg()) {
int tmp;
tmp = x;
x = y;
y = wmt_ts_get_resolvX() - tmp;
}
dbg("id %d [%d, %d] p %d",id, x, y, event->pressure[i]);
//input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,event->pressure[i]);
input_report_abs(data->input_dev, ABS_MT_POSITION_X, x);
input_report_abs(data->input_dev, ABS_MT_POSITION_Y, y);
input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, id);
input_mt_sync(data->input_dev);
}
/* SYN_REPORT */
input_sync(data->input_dev);
}
/**
**lw86x0 touch irq work function
**/
static void lw86x0_ts_touch_irq_work(struct work_struct *work)
{
u16 int_touch_status=0;
mutex_lock(&ts_data_mutex);
//dbg("Enter into lw86x0_ts_touch_irq_work");
//finger_up_status = 0;
lw86x0_read_reg(0x01f5, &int_touch_status, 1);
//dbg("Read 0x1f5 = %d",int_touch_status);
if( int_touch_status & 0x0001)
{
u16 touch_number=0;
lw86x0_read_reg(0x0160, &touch_number, 1);
//dbg("tn=%d\n",touch_number);
if(touch_number==0)
{
skip_zero_num++;
if(SKIP_ZERO_POINT==skip_zero_num)
{
dbg("tn=%d\n",touch_number);
lw86x0_write_reg(0x01f2, 0x0010);
lw86x0_report_touch_info(touch_number);
lw86x0_ts_release();
//finger_up_status = 1;
}
else if(SKIP_ZERO_POINT<skip_zero_num)
{
skip_zero_num = SKIP_ZERO_POINT+1;
}
}
else if(touch_number==15)
{
//dbg("touch_number=%d\n",touch_number);
}
else
{
dbg("tn=%d\n",touch_number);
lw86x0_write_reg(0x01f2, 0x0011);
skip_zero_num = 0;
lw86x0_report_touch_info(touch_number);
}
}
else
{
//finger_up_status = 1;
}
lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt
//mdelay(500);
//dbg("clear interrupt 1");
lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt
//mdelay(500);
//dbg("clear interrupt 2");
//lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt
//mdelay(500);
//dbg("clear interrupt 3");
//lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt
//mdelay(500);
//dbg("clear interrupt 4");
//dbg("Write 0x1f5 = 0xffff");
//lw86x0_read_reg(0x01f5, &int_touch_status, 1);
//dbg("Re-Read 0x1f5 = %d",int_touch_status);
if(g_dbgmode==0)
{
//dbg("Enable Irq");
wmt_enable_gpirq(tsirq_gpio);
}
mutex_unlock(&ts_data_mutex);
}
static irqreturn_t lw86x0_ts_interrupt(int irq, void *dev_id)
{
//dbg("enter lw86x0_ts_interrupt");
//if (!wmt_is_tsirq_enable(tsirq_gpio))
//{
// dbg("tsirq not enabled");
// return IRQ_NONE;
//}
if (wmt_is_tsint(tsirq_gpio))
{
wmt_clr_int(tsirq_gpio);
wmt_disable_gpirq(tsirq_gpio);
if(!l_early_suspend)
{
//dbg("tsirq enabled");
queue_work(l_tsdata.ts_workqueue, &l_tsdata.touch_event_work);
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void reset_chip(void)
{
printk("\nReset LW IC\n\n");
lw86x0_write_reg(0x00e6, 0x3311);
lw86x0_write_reg(0x00e0, 0x0005);
lw86x0_write_reg(0x0214, 0x0020);
lw86x0_write_reg(0x033d, 0x8100);
mdelay(500);
wmt_rst_output(0);
wmt_set_irq_mode(tsirq_gpio, 0);
mdelay(100);
wmt_rst_output(1);
wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING);
lw86x0_load_def_setting();
if(g_dbgmode==0)
{
wmt_enable_gpirq(tsirq_gpio);
}
}
static int check_chip_status(void)
{
u16 read_value = 0;
u16 read_sram = 0;
int ret = lw86x0_read_reg(0x00e6, &read_value, 1);
if(ret != 0)
{
reset_chip();
return 0;
}
if(read_value != 0x3311)
{
reset_chip();
return 0;
}
else
{
lw86x0_read_reg(0x00e0, &read_value, 1);
if(read_value != 0x0005 && read_value != 0x000d)
{
dbg("0x00e0!=0x0005,0x000d\n");
reset_chip();
return 0;
}
lw86x0_read_reg(0x0180, &read_sram, 1);
if(read_sram != 0)
{
dbg("0x0180!=0\n");
reset_chip();
return 0;
}
lw86x0_read_reg(0x0181, &mcu_status, 1);
if(mcu_status_old == mcu_status)
{
dbg("0x0180 old!=new\n");
reset_chip();
mcu_status_old = mcu_status;
return 0;
}
else
{
mcu_status_old = mcu_status;
return 1;
}
}
return 1;
}
static void phone_status_listener(struct work_struct *work)
{
if(stop_timer == 0)
{
check_chip_status();
}
}
static void lw86x0_ts_polling_phone_status(long unsigned int dev_addr)
{
schedule_work(&phone_status_work);
mod_timer(&polling_phone_status_timer, jiffies + msecs_to_jiffies(2000));
}
/**
** lw86x0 ts early suspend function
**/
#ifdef CONFIG_HAS_EARLYSUSPEND
static void ts_early_suspend(void)
{
wmt_disable_gpirq(tsirq_gpio);
}
//#ifdef CONFIG_HAS_EARLYSUSPEND
static void lw86x0_ts_early_suspend(struct early_suspend *handler)
{
printk("lw86x0_ts_early_suspend\n");
ts_early_suspend();
l_early_suspend = 1;
lw86x0_write_reg(0x000c, 0xffff);
lw86x0_write_reg(0x033d, 0x0d60);
lw86x0_write_reg(0x00e2, 0x0300);
lw86x0_write_reg(0x000d, 0x4000);
lw86x0_write_reg(0x00e5, 0x4c01);
stop_timer = 1;
}
/**
** lw86x0 late resume function
**/
static void ts_late_resume(void)
{
printk("ts_late_resume\n");
//wmt_disable_gpirq(tsirq_gpio);
//lw86x0_hw_reset();
l_early_suspend = 0;
wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING);
if(g_dbgmode==0)
{
printk("g_dbgmode==0\n");
wmt_enable_gpirq(tsirq_gpio);
}
}
static void lw86x0_ts_late_resume(struct early_suspend *handler)
{
printk("==lw86x0_ts_resume=\n");
int ret = check_chip_status();
if(ret == 1)
{
lw86x0_write_reg(0x000d, 0xc000);
lw86x0_write_reg(0x00e2, 0x0100);
lw86x0_write_reg(0x00e5, 0x4c00);
lw86x0_write_reg(0x000c, 0xffff);
}
ts_late_resume();
l_early_suspend = 0;
stop_timer = 0;
}
#endif
/**
** lw86x0 ts suspend function
**/
static int lw86x0_suspend(struct platform_device *pdev, pm_message_t state)
{
return 0;
}
/**
** lw86x0 resume function
**/
static int lw86x0_resume(struct platform_device *pdev)
{
lw86x0_hw_reset();
first_init_reg = 1;
lw86x0_load_def_setting();
return 0;
}
#ifdef SUPPORT_FW_UPGRADE
//add by jackie
#define BYTES_PER_PACKET 64
//#define FILEPATH "/etc/firmware/TOUCH.BIN"
int fileLen;
u8 *pData;
void read_data_from_fw_file(void)
{
char fwname[32] = {0};
wmt_ts_get_firmwfilename(fwname);
if (wmt_ts_load_firmware(fwname, &pData, &fileLen)) {
dbg("Load firmware file failed~ \n");
return;
}
}
u8 check_fw_version(void)
{
//Fw_Ver* pfwVerInFile = NULL;
//Fw_Ver fwVer;
u16 fw_check_sum;
u16 fw_file_check_sum = 0;
read_data_from_fw_file();
/*pfwVerInFile = (Fw_Ver* )&(pData[0x2000]);
printk("struct data:%c%c%d%d\n",pfwVerInFile->magic_num1,pfwVerInFile->magic_num2,pfwVerInFile->mj_ver,pfwVerInFile->mn_ver);//add by jackie
lw86x0_write_reg(0x00e6,0x3311);
lw86x0_flash_read((u8*)&fwVer,0x2000,4);
printk("lw86x0_flash:%c%c%d%d\n",fwVer.magic_num1,fwVer.magic_num2,fwVer.mj_ver,fwVer.mn_ver);//add by jackie
//printk("lw86x0_flash:%d%d\n",fwVer.magic_num1,fwVer.magic_num2);//add by jackie
if((fwVer.magic_num1!='L'||fwVer.magic_num2!='W')
||((fwVer.magic_num1=='L'&&fwVer.magic_num2=='W')
&&(pfwVerInFile->magic_num1=='L'&&pfwVerInFile->magic_num2=='W')
&&(fwVer.mj_ver!=pfwVerInFile->mj_ver || fwVer.mn_ver!=pfwVerInFile->mn_ver))
)*/
lw86x0_write_reg(0x00e6, 0x3311);
lw86x0_write_reg(0x0020, 0x9000);
lw86x0_write_reg(0x0002, 0x8900);
lw86x0_write_reg(0x0115, 0x0100);
lw86x0_write_reg(0x0020, 0x1000);
msleep(200);
fw_check_sum = get_fw_check_sum();
fw_file_check_sum = get_fw_file_check_sum();
printk("**********fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum);
if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum))
{
lw86x0_write_reg(0x0002, 0x8800);
printk("firmware crc check is not equal, update firmware......\n");
return 1;//return 1 means needing upgrade
}
else
{
printk("firmware is not updated......\n");
lw86x0_write_reg(0x0002, 0x8800);
return 0;
}
}
void fw_download(void)
{
int pkt_num = (fileLen+BYTES_PER_PACKET-1)/BYTES_PER_PACKET;
int i;
int last_pkt_size = ((int)fileLen) % BYTES_PER_PACKET;
printk("pkt_num is:%d\n",pkt_num);//add
if(last_pkt_size==0)
{
last_pkt_size = BYTES_PER_PACKET;
}
lw86x0_flash_write_prepare();
for(i=0;i<pkt_num;i++)
{
lw86x0_flash_write(&pData[i*BYTES_PER_PACKET],i*BYTES_PER_PACKET,(i==pkt_num-1)?last_pkt_size:BYTES_PER_PACKET);
}
lw86x0_flash_write_finish(fileLen);
printk("firmware is updated......\n");//add
}
u8 get_fw_file_check_sum(void)
{
//u16 dataLen;
//u8* pData = NULL;
u16 i;
u8 checksum = 0;
printk("**********dataLen = %04x\n",fileLen);
for(i=0;i<fileLen;i++)
{
checksum+=pData[i];
}
return checksum;
}
u16 get_fw_check_sum(void)
{
u8 cnt = 10;
u16 check_sum = 0;
//u16 fw_length = 0;
while(cnt>0)
{
lw86x0_read_reg(0x0182, &check_sum, 1);
printk("**********check_sum = %04x\n",check_sum);
if((check_sum&0xff00)==0x8000)
{
break;
}
cnt--;
msleep(100);
}
return check_sum;
}
static void fw_upgrader(void)
{
u16 fw_check_sum;
u16 fw_file_check_sum = 0;
if(check_fw_version()==0)
{
return;
}
lw86x0_write_reg(0x00e6, 0x3311);
fw_download();
lw86x0_write_reg(0x0020, 0x9000);
lw86x0_write_reg(0x0002, 0x8900);
lw86x0_write_reg(0x0115, 0x0100);
lw86x0_write_reg(0x0020, 0x1000);
msleep(200);
fw_check_sum = get_fw_check_sum();
fw_file_check_sum = get_fw_file_check_sum();
printk("**********fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum);
if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum))
{
printk("*********redownload fw\n");
fw_download();
lw86x0_write_reg(0x00e6, 0x3311);
lw86x0_write_reg(0x0020, 0x9000);
lw86x0_write_reg(0x0002, 0x8900);
lw86x0_write_reg(0x0115, 0x0100);
lw86x0_write_reg(0x0020, 0x1000);
msleep(200);
fw_check_sum = get_fw_check_sum();
fw_file_check_sum = get_fw_file_check_sum();
printk("**********re-check fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum);
if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum))
{
lw86x0_flash_write_prepare();
}
}
else
{
}
lw86x0_write_reg(0x0002, 0x8800);
kfree(pData);
lw86x0_hw_reset();
}
#endif
static int wmt_wakeup_bl_notify(struct notifier_block *nb, unsigned long event,
void *dummy)
{
//printk("get notify\n");
switch (event) {
case BL_CLOSE:
l_early_suspend = 1;
wmt_disable_gpirq(tsirq_gpio);
stop_timer = 1;
cancel_work_sync(&l_tsdata.touch_event_work);
cancel_work_sync(&phone_status_work);
printk("\nclose backlight\n\n");
break;
case BL_OPEN:
l_early_suspend = 0;
wmt_enable_gpirq(tsirq_gpio);
lw86x0_write_reg(0x01f5,0xffff);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
stop_timer = 0;
printk("\nopen backlight\n\n");
break;
}
return NOTIFY_OK;
}
static struct notifier_block wmt_bl_notify = {
.notifier_call = wmt_wakeup_bl_notify,
};
static int lw86x0_ts_probe(struct platform_device *pdev)
{
int err = 0;
int i = 0;
u16 read_from_e6 = 0;
lw_i2c_client = ts_get_i2c_client();//get i2c_client
memset(&l_tsdata, 0 ,sizeof(l_tsdata));
INIT_WORK(&l_tsdata.touch_event_work, lw86x0_ts_touch_irq_work);
mutex_init(&ts_data_mutex);
l_tsdata.ts_workqueue = create_singlethread_workqueue("lw86x0-ts-queue");
if (!l_tsdata.ts_workqueue) {
err = -ESRCH;
goto exit_create_singlethread;
}
l_tsdata.input_dev = input_allocate_device();
if (!l_tsdata.input_dev) {
err = -ENOMEM;
dbg("failed to allocate input device\n");
goto exit_input_dev_alloc_failed;
}
l_tsdata.input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
l_tsdata.input_dev->propbit[0] = BIT_MASK(INPUT_PROP_DIRECT);
if (wmt_ts_get_lcdexchg()) {
input_set_abs_params(l_tsdata.input_dev,
ABS_MT_POSITION_X, 0, wmt_ts_get_resolvY(), 0, 0);
input_set_abs_params(l_tsdata.input_dev,
ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvX(), 0, 0);
} else {
input_set_abs_params(l_tsdata.input_dev,
ABS_MT_POSITION_X, 0, wmt_ts_get_resolvX(), 0, 0);
input_set_abs_params(l_tsdata.input_dev,
ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvY(), 0, 0);
}
input_set_abs_params(l_tsdata.input_dev,
ABS_MT_TRACKING_ID, 0, 15, 0, 0);
l_tsdata.input_dev->name = LW86X0_NAME;
for (i = 0; i < TS_KEY_NUM; i++)
{
set_bit(l_tskey[i][1], l_tsdata.input_dev->keybit);
};
err = input_register_device(l_tsdata.input_dev);
if (err) {
errlog("lw86x0_ts_probe: failed to register input device.");
goto exit_input_register_device_failed;
}
#ifdef SUPPORT_FW_UPGRADE
fw_upgrader();
mdelay(500);
#endif
err = load_cfgfile();
if (err < 0)
goto exit_load_cfgfile_failed;
lw86x0_load_def_setting();
#ifdef CONFIG_HAS_EARLYSUSPEND
l_tsdata.early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB+ 1;
l_tsdata.early_suspend.suspend = lw86x0_ts_early_suspend;
l_tsdata.early_suspend.resume = lw86x0_ts_late_resume;
register_early_suspend(&l_tsdata.early_suspend);
#endif
// init interrupt gpio
tsirq_gpio = wmt_ts_get_gpionum();
wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING);//GIRQ_FALLING);
wmt_disable_gpirq(tsirq_gpio);
if(request_irq(wmt_get_tsirqnum(), lw86x0_ts_interrupt, IRQF_SHARED, "ts_lw86x0", l_tsdata.input_dev) < 0){
errlog("Could not allocate intrrupt for ts_lw86x0 !\n");
err = -1;
goto exit_register_irq;
}
lw86x0_ts_touch_irq_work(&l_tsdata.touch_event_work);
if(g_dbgmode==0)
{
wmt_enable_gpirq(tsirq_gpio);
}
msleep(5);
dbg("irqgpio=%d,irq=%d,resetgpio=%d\n", tsirq_gpio, wmt_get_tsirqnum(),wmt_ts_get_resetgpnum());
lw86x0_read_reg(0x00e6, &read_from_e6, 1);
if(read_from_e6 == 0x3311 || read_from_e6 == 0xa311)
{
INIT_WORK(&phone_status_work, phone_status_listener);
init_timer(&polling_phone_status_timer);
setup_timer(&polling_phone_status_timer, lw86x0_ts_polling_phone_status, (long unsigned int) pdev);
lw86x0_ts_polling_phone_status((long unsigned int) pdev);
}
register_bl_notifier(&wmt_bl_notify);
return 0;
exit_register_irq:
#ifdef CONFIG_HAS_EARLYSUSPEND//add by jackie
unregister_early_suspend(&l_tsdata.early_suspend);
#endif
kfree(default_setting_table);
exit_load_cfgfile_failed:
exit_input_register_device_failed:
input_free_device(l_tsdata.input_dev);
exit_input_dev_alloc_failed:
cancel_work_sync(&l_tsdata.touch_event_work);
destroy_workqueue(l_tsdata.ts_workqueue);
exit_create_singlethread:
return err;
}
static int lw86x0_ts_remove(struct platform_device *pdev)
{
kfree(default_setting_table);
#ifdef CONFIG_HAS_EARLYSUSPEND
unregister_early_suspend(&l_tsdata.early_suspend);
#endif
free_irq(wmt_get_tsirqnum(), l_tsdata.input_dev);
input_unregister_device(l_tsdata.input_dev);
flush_workqueue(l_tsdata.ts_workqueue);
cancel_work_sync(&l_tsdata.touch_event_work);
destroy_workqueue(l_tsdata.ts_workqueue);
mutex_destroy(&ts_data_mutex);
del_timer(&polling_phone_status_timer);
unregister_bl_notifier(&wmt_bl_notify);
dbg("remove...\n");
return 0;
}
static int lw86x0_ts_init(void)
{
dbg("lw86x0_ts_init\n");
lw86x0_hw_reset();
return 0;
}
static void lw86x0_ts_exit(void)
{
dbg("lw86x0_ts_exit\n");
}
struct wmtts_device lw86x0_tsdev = {
.driver_name = "s_lw86x0_ts",
.ts_id = "lw86x0",
.init = lw86x0_ts_init,
.exit = lw86x0_ts_exit,
.probe = lw86x0_ts_probe,
.remove = lw86x0_ts_remove,
.suspend = lw86x0_suspend,
.resume = lw86x0_resume,
.penup = 1,
};
|