-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathit7259_driver.c
executable file
·3013 lines (2468 loc) · 85.7 KB
/
it7259_driver.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 Statement:
*
* This software/firmware and related documentation ("MediaTek Software") are
* protected under relevant copyright laws. The information contained herein
* is confidential and proprietary to MediaTek Inc. and/or its licensors.
* Without the prior written permission of MediaTek inc. and/or its licensors,
* any reproduction, modification, use or disclosure of MediaTek Software,
* and information contained herein, in whole or in part, shall be strictly prohibited.
*
* MediaTek Inc. (C) 2010. All rights reserved.
*
* BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
* THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
* CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
* SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
* STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
* CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* The following software/firmware and/or related documentation ("MediaTek Software")
* have been modified by MediaTek Inc. All revisions are subject to any receiver's
* applicable license agreements with MediaTek Inc.
*/
//#include <cust_eint.h>
#include "tpd_custom_it7259.h"
#ifndef TPD_NO_GPIO
//#include "cust_gpio_usage.h"
#endif
#include <linux/wakelock.h>
//#include <mach/mt_pm_ldo.h>
//#include <mach/mt_typedefs.h>
//#include <mach/mt_boot.h>
#include <mach/wd_api.h>
//#include "mt_boot_common.h"
#include <linux/regulator/consumer.h>
#include <linux/of_irq.h>
#include <linux/device.h>
//#define __IT7259_DEBUG_A158_JFSS__ //lshun use tp for A152
#define s32 int
//#define I2C_SUPPORT_RS_DMA
//extern kal_bool upmu_chr_det(upmu_chr_list_enum chr); // remove
//taikoto 20171108 add
extern struct input_dev *kpd_input_dev;
//taikoto 20171108 add end
unsigned int touch_irq = 0;
#define ABS(x) ((x<0)?-x:x)
#define TPD_OK 0
#define MAX_BUFFER_SIZE 144
#define CTP_NAME "IT7259"
#define IOC_MAGIC 'd'
#define IOCTL_SET _IOW(IOC_MAGIC, 1, struct ioctl_cmd168)
#define IOCTL_GET _IOR(IOC_MAGIC, 2, struct ioctl_cmd168)
#define HAS_8_BYTES_LIMIT
//#define MAX_BUFFER_SIZE 1028//144
#define MAX_CMD_BUFFER_SIZE 144
#define MAX_FINGER_NUMBER 10
#define MAX_PRESSURE 15
#define DEVICE_NAME "IT7259"
#define DEVICE_VENDOR 0
#define DEVICE_PRODUCT 0
#define DEVICE_VERSION 0
#define IT7259_X_RESOLUTION 672
#define IT7259_Y_RESOLUTION 672
#define SCREEN_X_RESOLUTION 1440
#define SCREEN_Y_RESOLUTION 768
#define VERSION_ABOVE_ANDROID_20
#define MAX_COUNT 3000
#define COMMAND_SUCCESS 0x0000
#define COMMAND_ERROR 0x0200
#define ERROR_QUERY_TIME_OUT 0x0800
#define QUERY_SUCCESS 0x00
#define QUERY_BUSY 0x01
#define QUERY_ERROR 0x02
#define MAX_FILE_SIZE 0x10000
#define IOC_MAGIC 'd'
#define IOCTL_SET _IOW(IOC_MAGIC, 1, struct ioctl_cmd168)
#define IOCTL_GET _IOR(IOC_MAGIC, 2, struct ioctl_cmd168)
#define IOCTL_AP_GET 0xF0
#define IOCTL_AP_SET 0xF1
#define IOCTL_AP_CMD 0xF2
#define IOCTL_AP_WRITE_FW 0xF3
#define IOCTL_AP_COMPARE_FLASH 0xF4
#define IOCTL_AP_SEND_FILE 0xF5
//add by FHH for I2C DMA mode start
#define MAX_I2C_NDMA_LEN 8
#define MAX_I2C_DMA_LEN 240 //should less than 256
static DEFINE_MUTEX(it7259_i2c_mutex);
//static int tpd_i2c_dma_write(struct i2c_client *client, u32 len, u8 const *data);
static int tpd_i2c_dma_read(struct i2c_client *client, u32 len, u8 const *data);
//add by FHH for I2C DMA mode end
extern struct tpd_device *tpd;
static int tpd_flag = 0;
static int tpd_halt=0;
#ifdef I2C_SUPPORT_RS_DMA
static u8 *I2CDMABuf_va = NULL;
static u32 I2CDMABuf_pa = NULL;
#endif
static struct task_struct *thread = NULL;
static DECLARE_WAIT_QUEUE_HEAD(waiter);
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/types.h>
#define MY_FILE "/data/spectrum_log.txt"
enum wk_wdt_type {
WK_WDT_LOC_TYPE,
WK_WDT_EXT_TYPE,
WK_WDT_LOC_TYPE_NOLOCK,
WK_WDT_EXT_TYPE_NOLOCK,
};
extern void mtk_wdt_restart(enum wk_wdt_type type);
/*
static void mtk_kick_wdt(void)
{
mtk_wdt_restart(WK_WDT_LOC_TYPE_NOLOCK);
mtk_wdt_restart(WK_WDT_EXT_TYPE_NOLOCK);
}
*/
typedef unsigned char BOOL;
typedef unsigned char BYTE;
typedef unsigned char uint8;
typedef unsigned short WORD;
typedef unsigned long int uint32;
typedef unsigned int UINT;
typedef signed char int8;
typedef signed short int16;
typedef signed long int int32;
//#define MAX_BUFFER_SIZE 256
#if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START;
static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END;
#endif
#if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX;
#endif
unsigned char APCmdBuffer[MAX_BUFFER_SIZE]; // byte 0: length byte 1~n: command byte n+1 : read length
//static bool waitCommandDone(void);
static void tpd_print_version(void);
static void tpd_eint_interrupt_handler(void);
static int touch_event_handler(void *unused);
static int tpd_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id);
static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info);
static int tpd_i2c_remove(struct i2c_client *client);
static int tpd_i2c_write(struct i2c_client *client, uint8_t *buf, int len);
static int tpd_i2c_read(struct i2c_client *client, uint8_t *buf, int len , uint8_t addr);
static int gfnIT7259_SpectrumModeTest(unsigned char ucStage);
static ssize_t IT7259_SpectrumTs_show(struct device *dev, struct device_attribute *attr, char *buf);
static ssize_t IT7259_SpectrumTs_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count);
static int i2cDMAReadFromIT7259(struct i2c_client *client, uint16_t addr, uint8_t *buf, int len );
//static int i2cDMAWriteToIT7259(struct i2c_client *client, uint16_t reg, uint8_t *buf, int len);
static int i2cDirectReadFromIT7259(struct i2c_client *client, uint16_t addr, uint8_t *buf, int len );
static int i2cDirectWriteToIT7259(struct i2c_client *client, uint16_t reg, uint8_t *buf, int len);
extern void mt65xx_eint_unmask(unsigned int line);
extern void mt65xx_eint_mask(unsigned int line);
extern int mtk_wdt_enable(enum wk_wdt_en en);
//lshun modify 20130615
//extern void mt65xx_eint_set_hw_debounce(unsigned int eint_num, unsigned int ms);
//extern unsigned int mt65xx_eint_set_sens(unsigned int eint_num, unsigned int sens);
//extern void mt65xx_eint_registration(unsigned int eint_num, unsigned int is_deb_en, unsigned int pol, void (EINT_FUNC_PTR)(void), unsigned int is_auto_umask);
static struct i2c_client *i2c_client = NULL;
static const struct i2c_device_id tpd_i2c_id[] ={{CTP_NAME,0},{}}; // {{"mtk-tpd",0},{}};
static unsigned short force[] = {0, 0x8C, I2C_CLIENT_END,I2C_CLIENT_END};
static const unsigned short * const forces[] = { force, NULL };
//static struct i2c_client_address_data addr_data = { .forces = forces,};
//static struct i2c_board_info __initdata it7259_i2c_tpd={ I2C_BOARD_INFO(CTP_NAME, (0x8c>>1))};
static const struct of_device_id tpd_of_match[] = {
{.compatible = "mediatek,cap_touch"},
{},
};
static struct i2c_driver tpd_i2c_driver = {
.driver = {
.name = CTP_NAME,
#ifdef CONFIG_OF
.of_match_table = tpd_of_match,
#endif
.owner = THIS_MODULE,
},
.probe = tpd_i2c_probe,
.remove = tpd_i2c_remove,
.detect = tpd_i2c_detect,
.driver.name = CTP_NAME, //"mtk-tpd",
.id_table = tpd_i2c_id,
// .address_list = forces,
};
struct ite7259_data {
rwlock_t lock;
unsigned short bufferIndex;
unsigned short length;
unsigned short buffer[MAX_BUFFER_SIZE];
};
struct ioctl_cmd168 {
unsigned short bufferIndex;
unsigned short length;
unsigned short buffer[MAX_BUFFER_SIZE];
};
static DEVICE_ATTR(spectrumts, S_IWUSR | S_IRUGO, IT7259_SpectrumTs_show, IT7259_SpectrumTs_store);
static struct attribute *ite_attrs[] = {
&dev_attr_spectrumts.attr,
NULL
};
static const struct attribute_group ite_attr_group = {
.attrs = ite_attrs,
};
//add by FHH for I2C DMA mode start
/*
static int tpd_i2c_dma_write(struct i2c_client *client, u32 len, u8 const *data)
{
u8* dmaVa = NULL;
dma_addr_t dmaPa = 0;
u32 written = 0 ;
u32 dmaLen = MAX_I2C_DMA_LEN;
u32 ext_flag;
int ret;
if ((len == 0) || (data == NULL) ) {
return -EIO;
}
mutex_lock(&it7259_i2c_mutex);
if (len < MAX_I2C_NDMA_LEN) {
client->ext_flag &= (~I2C_DMA_FLAG);
ret = i2c_master_send(client, data, len);
if (len != ret) {
mutex_unlock(&it7259_i2c_mutex);
pr_err("%s NDMA failed: ret=%d\n", __FUNCTION__, ret);
return -EIO;
}
}
else {
client->dev.coherent_dma_mask = DMA_BIT_MASK(32);
dmaVa = dma_alloc_coherent(&(client->dev), MAX_I2C_DMA_LEN, &dmaPa, GFP_KERNEL);
ext_flag = client->ext_flag;
client->ext_flag |= (I2C_ENEXT_FLAG | I2C_DMA_FLAG);
while (written < len) {
if (written + MAX_I2C_DMA_LEN > len) {
dmaLen = len - written;
}
memcpy(dmaVa, &data[written], dmaLen);
ret = i2c_master_send(client, (u8*)dmaPa, dmaLen);
if (dmaLen != ret) {
pr_err("%s DMA failed: ret=%d\n", __FUNCTION__, ret);
}
written += dmaLen;
}
dma_free_coherent(&(client->dev), MAX_I2C_DMA_LEN, dmaVa, dmaPa);
client->ext_flag = ext_flag;
}
mutex_unlock(&it7259_i2c_mutex);
return 0;
}
*/
static int tpd_i2c_dma_read(struct i2c_client *client, u32 len, u8 const *data)
{
u8* dmaVa = NULL;
dma_addr_t dmaPa = 0;
u32 read = 0 ;
u32 dmaLen = MAX_I2C_DMA_LEN;
u32 ext_flag;
int ret;
if ((!data) || (len == 0)) {
pr_err("%s data is null\n", __FUNCTION__);
return -EINVAL;
}
mutex_lock(&it7259_i2c_mutex);
if (len <= MAX_I2C_NDMA_LEN) {
client->ext_flag &= (~I2C_DMA_FLAG);
ret = i2c_master_recv(client, (char*)data, len);
if (len != ret) {
mutex_unlock(&it7259_i2c_mutex);
pr_err("%s NDMA failed: ret=%d, length=%d\n", __FUNCTION__, ret, len);
return -EIO;
}
} else {
client->dev.coherent_dma_mask = DMA_BIT_MASK(32);
dmaVa = dma_alloc_coherent(&(client->dev), MAX_I2C_DMA_LEN, &dmaPa, GFP_KERNEL);
ext_flag = client->ext_flag;
client->ext_flag |= (I2C_ENEXT_FLAG | I2C_DMA_FLAG);
while (read < len) {
if (read + MAX_I2C_DMA_LEN > len) {
dmaLen = len - read;
}
ret = i2c_master_recv(client, (u8*)dmaPa, dmaLen);
if (dmaLen != ret) {
pr_err("%s DMA failed: ret=%d\n", __FUNCTION__, ret);
}
memcpy((void*)&data[read], dmaVa, dmaLen);
read += dmaLen;
}
dma_free_coherent(&(client->dev), MAX_I2C_DMA_LEN, dmaVa, dmaPa);
client->ext_flag = ext_flag;
}
mutex_unlock(&it7259_i2c_mutex);
return 0;
}
//add by FHH for I2C DMA mode end
static long ite7259_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) {
//struct ite7259_data *dev = filp->private_data;
int retval = 0;
int i;
//unsigned char ucQuery;
unsigned char buffer[MAX_BUFFER_SIZE];
struct ioctl_cmd168 data;
unsigned char datalen;
unsigned char ent[] = {0x60, 0x00, 0x49, 0x54, 0x37, 0x32};
unsigned char ext[] = {0x60, 0x80, 0x49, 0x54, 0x37, 0x32};
pr_info("=ite7259_ioctl=\n");
memset(&data, 0, sizeof(struct ioctl_cmd168));
switch (cmd) {
case IOCTL_SET:
pr_info("=IOCTL_SET=\n");
if (!access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd))) {
retval = -EFAULT;
goto done;
}
if ( copy_from_user(&data, (int __user *)arg, sizeof(struct ioctl_cmd168)) ) {
retval = -EFAULT;
goto done;
}
buffer[0] = (unsigned char) data.bufferIndex;
pr_info("%.2X ", buffer[0]);
for (i = 1; i < data.length + 1; i++) {
buffer[i] = (unsigned char) data.buffer[i - 1];
pr_info("%.2X ", buffer[i]);
}
if (!memcmp(&(buffer[1]), ent, sizeof(ent))) {
pr_info("Disabling IRQ.\n");
//disable_irq(gl_ts->client->irq);
tpd_halt = 1;
//mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
}
if (!memcmp(&(buffer[1]), ext, sizeof(ext))) {
pr_info("Enabling IRQ.\n");
//enable_irq(gl_ts->client->irq);
tpd_halt = 0;
// mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
}
datalen = (unsigned char) (data.length + 1);
printk("IOCTL_SET: datalen=%d.\n",datalen);
retval = tpd_i2c_write(i2c_client, &buffer[0], datalen);
pr_info("SET:retval=%x\n", retval);
retval = 0;
break;
case IOCTL_GET:
pr_info("=IOCTL_GET=\n");
if (!access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd))) {
retval = -EFAULT;
goto done;
}
if (!access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd))) {
retval = -EFAULT;
goto done;
}
if ( copy_from_user(&data, (int __user *)arg, sizeof(struct ioctl_cmd168)) ) {
retval = -EFAULT;
goto done;
}
retval = tpd_i2c_read(i2c_client, (unsigned char*) buffer, (unsigned char) data.length, (unsigned char) data.bufferIndex);
pr_info("GET:retval=%x\n", retval);
retval = 0;
for (i = 0; i < data.length; i++) {
data.buffer[i] = (unsigned short) buffer[i];
}
pr_info("GET:bufferIndex=%x, dataLength=%d, buffer[0]=%x, buffer[1]=%x, buffer[2]=%x, buffer[3]=%x\n", data.bufferIndex, data.length, buffer[0], buffer[1], buffer[2], buffer[3]);
if ( copy_to_user((int __user *)arg, &data, sizeof(struct ioctl_cmd168)) ) {
retval = -EFAULT;
goto done;
}
break;
default:
retval = -ENOTTY;
break;
}
done:
pr_info("DONE! retval=%d\n", retval);
return (retval);
}
/**************************
The output log file format should be like below
Channel = 12
Tx = Off
Minima Frequency = 40
Maxima Frequency = 110
Number of Times = 10
Count = 1
4099
4130
4136
4086
.
.
Count = 2
4099
4130
4136
4086
.
.
**************************/
int i2cReadFromIT7259(struct i2c_client *client, unsigned char writeBuffer[], unsigned short writeLength,
unsigned char readDataBuffer[], unsigned short readDataLength)
{
#if 1
int ret;
if ((readDataLength > 7) ||(writeLength>7)) {
return -EINVAL;
}
client->addr = (client->addr & I2C_MASK_FLAG) | I2C_WR_FLAG | I2C_RS_FLAG;
memcpy(readDataBuffer, writeBuffer, writeLength);
ret = i2c_master_send(client, &readDataBuffer[0], (readDataLength << 8 | writeLength));
#else
int ret;
struct i2c_msg msgs[2] = { { .addr = client->addr, .flags = 0,
.len = writeLength, .buf = writeBuffer }, { .addr = client->addr, .flags =
I2C_M_RD, .len = readDataLength, .buf = readDataBuffer } };
printk("taikoto====in i2cReadFromIT7259 function===\n");
memset(readDataBuffer, 0xFF, readDataLength);
ret = i2c_transfer(client->adapter, msgs, 2);
#endif
return ret;
}
int i2cWriteToIT7259(struct i2c_client *client, unsigned char bufferIndex,
unsigned char const dataBuffer[], unsigned short dataLength)
{
#if 1
int ret;
char buffer4Write[8];
if (dataLength > 7) {
return -EINVAL;
}
buffer4Write[0] = bufferIndex;
memcpy(&(buffer4Write[1]), dataBuffer, dataLength);
client->addr = client->addr & I2C_MASK_FLAG;
ret = i2c_master_send(client, buffer4Write, dataLength+1);
return ret;
#else
unsigned char buffer4Write[256];
struct i2c_msg msgs[1] = { { .addr = client->addr, .flags = 0, .len =
dataLength + 1, .buf = buffer4Write } };
printk("taikoto====in i2cWriteToIT7259 function===\n");
buffer4Write[0] = bufferIndex;
memcpy(&(buffer4Write[1]), dataBuffer, dataLength);
return i2c_transfer(client->adapter, msgs, 1);
#endif
}
static int i2cAdvancedReadFromIT7259(struct i2c_client *client, unsigned char writeBuffer[], unsigned short writeLength,
unsigned char readDataBuffer[], unsigned short readDataLength) {
#if 1
int ret;
if ((readDataLength > 7) ||(writeLength>7)) {
return -EINVAL;
}
client->addr = (client->addr & I2C_MASK_FLAG) | I2C_WR_FLAG | I2C_RS_FLAG;
memcpy(readDataBuffer, writeBuffer, writeLength);
ret = i2c_master_send(client, &readDataBuffer[0], (readDataLength << 8 | writeLength));
#else
int ret;
struct i2c_msg msgs[2] = { { .addr = client->addr, .flags = 0,
.len = writeLength, .buf = writeBuffer }, { .addr = client->addr, .flags =
I2C_M_RD, .len = readDataLength, .buf = readDataBuffer } };
printk("taikoto====in read function===\r\n");
memset(readDataBuffer, 0xFF, readDataLength);
#if 0//def HAS_8_unsigned charS_LIMIT
//printk("====8 byte===\r\n");
if(readDataLength >= 8)
{
unsigned char ucCurReadIndex = 0;
unsigned char pucBuffer[128];
unsigned char pucBufferIndex =0;
memset(pucBuffer, 0xFF, 128);
if(bufferIndex == 0xA0)
pucBufferIndex = 0x05;
else if(bufferIndex == 0xE0)
pucBufferIndex = 0x07;
else if(bufferIndex == 0xC0)
pucBufferIndex = 0x06;
else
pucBufferIndex = 0x05;
if(IT7259ReadCommandBufferStart(pucBufferIndex))
{
unsigned short ucTotalLength = dataLength;
while(ucCurReadIndex< ucTotalLength)
{
unsigned char ucReadSize = 8;
if((ucCurReadIndex + ucReadSize)>=ucTotalLength)
{
ret = IT7259ReadCommandBufferContinue((ucTotalLength-ucCurReadIndex),&pucBuffer[ucCurReadIndex],true);
//pr_info("=read final %x--point[%x][%x][%x][%x][%x][%x][%x][%x]=\n",(ucTotalLength-ucCurReadIndex),
//pucBuffer[ucCurReadIndex+0],pucBuffer[ucCurReadIndex+1],pucBuffer[ucCurReadIndex+2],
//pucBuffer[ucCurReadIndex+3],pucBuffer[ucCurReadIndex+4],pucBuffer[ucCurReadIndex+5],pucBuffer[ucCurReadIndex+6],pucBuffer[ucCurReadIndex+7]);
ucCurReadIndex = ucTotalLength;
if(ret !=true)
return false;
break;
}
else
{
ret = IT7259ReadCommandBufferContinue(ucReadSize,&pucBuffer[ucCurReadIndex],false);
ucCurReadIndex+=ucReadSize;
if(ret !=true)
return false;
//pr_info("=read continue--point[%x][%x][%x][%x][%x][%x][%x][%x]=\n",
//pucBuffer[0],pucBuffer[1],pucBuffer[2],
//pucBuffer[3],pucBuffer[4],pucBuffer[5],pucBuffer[6],pucBuffer[7]);
}
}
memcpy(readDataBuffer,pucBuffer,readDataLength);
}
else
{
return false;
}
}
else
{
//printk("====8 byte 2===\r\n");
ret = i2c_transfer(client->adapter, msgs, 2);
}
#else
//printk("====in i2cAdvancedReadFromIT7259 ===");
ret = i2c_transfer(client->adapter, msgs, 2);
#endif
#endif
return ret;
}
/*
static int i2cAdvancedWriteToIT7259(struct i2c_client *client, unsigned char bufferIndex,
unsigned char const dataBuffer[], unsigned short dataLength)
{
//printk("====in write function===");
#if 0//def HAS_8_unsigned charS_LIMIT
int ret;
unsigned char buffer4Write[256];
if(dataLength>=7)
{
unsigned char ucCurWriteIndex = 0;
unsigned char pucBufferIndex =0;
memcpy(&(buffer4Write[0]), dataBuffer, dataLength);
if(bufferIndex == 0x20)
pucBufferIndex = 0x01;
else if(bufferIndex == 0x40)
pucBufferIndex = 0x02;
else
pucBufferIndex = 0x01;
if(IT7259WriteCommandBufferStart(pucBufferIndex))
{
unsigned short ucTotalLength = dataLength;
while(ucCurWriteIndex< ucTotalLength)
{
unsigned char ucWriteSize = 5;
if((ucCurWriteIndex + ucWriteSize)>=ucTotalLength)
{
ret = IT7259WriteCommandBufferContinue((ucTotalLength-ucCurWriteIndex),&buffer4Write[ucCurWriteIndex],true);
//pr_info("=write final %x--point[%x][%x][%x][%x][%x][%x][%x][%x]=\n",(ucTotalLength-ucCurWriteIndex),
//buffer4Write[ucCurWriteIndex+0],buffer4Write[ucCurWriteIndex+1],buffer4Write[ucCurWriteIndex+2],
//buffer4Write[ucCurWriteIndex+3],buffer4Write[ucCurWriteIndex+4],buffer4Write[ucCurWriteIndex+5],buffer4Write[ucCurWriteIndex+6],buffer4Write[ucCurWriteIndex+7]);
ucCurWriteIndex = ucTotalLength;
if(ret !=true)
{
//printk("==============WriteCommandBufferContinue final FAIL ========================");
return false;
}
break;
}
else
{
ret = IT7259WriteCommandBufferContinue(ucWriteSize,&buffer4Write[ucCurWriteIndex],false);
ucCurWriteIndex+=ucWriteSize;
//pr_info("=write continue--point[%x][%x][%x][%x][%x][%x][%x][%x]=\n",
//buffer4Write[ucCurWriteIndex],buffer4Write[ucCurWriteIndex+1],buffer4Write[ucCurWriteIndex+2],
//2buffer4Write[ucCurWriteIndex+3],buffer4Write[ucCurWriteIndex+4],buffer4Write[ucCurWriteIndex+5],buffer4Write[ucCurWriteIndex+6],buffer4Write[ucCurWriteIndex+7]);
if(ret !=true)
{
//printk("==============WriteCommandBufferContinue continue FAIL ========================");
return false;
}
}
}
}
else
{
return false;
}
}
else
{
struct i2c_msg msgs[1] = { { .addr = client->addr, .flags = 0, .len =
dataLength + 1, .buf = buffer4Write } };
buffer4Write[0] = bufferIndex;
memcpy(&(buffer4Write[1]), dataBuffer, dataLength);
return i2c_transfer(client->adapter, msgs, 1);
}
#else
unsigned char buffer4Write[256];
struct i2c_msg msgs[1] = { { .addr = client->addr, .flags = 0, .len =
dataLength + 1, .buf = buffer4Write } };
buffer4Write[0] = bufferIndex;
memcpy(&(buffer4Write[1]), dataBuffer, dataLength);
return i2c_transfer(client->adapter, msgs, 1);
#endif
}
*/
bool IT7259_SendCommand( unsigned char writeBuffer[], unsigned short writeLength,
unsigned char readDataBuffer[], unsigned short readDataLength) {
//int i;
//int tmp;
unsigned char ucQuery = 0xff;
unsigned char writeQueryBuffer[1];
//unsigned char buffer[128];
//unsigned char ucQueryBuffer[1];
//struct IT7259_ts_data *ts = gl_ts;
int ret;
int count = 0;
printk("==============IT7259_SendCommand ========================\n");
writeQueryBuffer[0] = 0x80;
// Identify Cap Sensor
do {
i2cReadFromIT7259(i2c_client, writeQueryBuffer, 1, &ucQuery, 1);
printk("it7259 : count is %d....",count);
count ++;
} while ((ucQuery & 0x01) && (count < MAX_COUNT));
printk("it7259 : ==============step 1: %d ========================\n",count);
//buffer[0] = 0x00;
if(count >= MAX_COUNT)
return false;
ret = i2cWriteToIT7259(i2c_client, 0x20, writeBuffer, writeLength);
if (ret < 0) {
return false;
}
printk("it7259 : ==============step 2: ========================\n");
count = 0 ;
ucQuery = 0xff;
do {
i2cReadFromIT7259(i2c_client, writeQueryBuffer, 1, &ucQuery, 1);
//i2cReadFromIT7259(ts->client, 0x80, &ucQuery, 1);
printk("%d....",count);
count ++;
} while ((ucQuery & 0x01) && (count < MAX_COUNT));
if(count >= MAX_COUNT)
return false;
printk("it7259 : ==============step 3: %d ========================\n",count);
//memset(&buffer, 0, sizeof(buffer));
//unsigned char writeBuffer[], unsigned short writeLength, unsigned char readDataBuffer[], unsigned short readDataLength
writeQueryBuffer[0] = 0xA0;
ret = i2cAdvancedReadFromIT7259(i2c_client, writeQueryBuffer, 1 , readDataBuffer, readDataLength);
//ret = i2cReadFromIT7259(i2c_client, writeQueryBuffer, 1, readDataBuffer, readDataLength);
if (ret < 0) {
return false;
}
pr_err("it7259 : ====Response--[%x][%x][%x][%x][%x][%x]=\n", readDataBuffer[0], readDataBuffer[1],
readDataBuffer[2], readDataBuffer[3], readDataBuffer[4], readDataBuffer[5]);
return true;
}
int gfnIT7259_SpectrumModeTest(unsigned char ucStage)
{
//printk("%s():\n", __func__);
//unsigned char ucQuery = QUERY_BUSY;
unsigned char pucCommandBuffer[1024];
unsigned int unWriteLength = 4;
unsigned int unReadLength = 2;
unsigned char ucTxMode = 0; //0: Tx Off, 1: Tx On
unsigned short wTmp=COMMAND_ERROR;
//unsigned int unCounter = 10;
unsigned int unMsgLen=0;
//struct IT7259_ts_data *ts = gl_ts;
unsigned char msg [128];
unsigned int i ,j= 0;
struct file *filp = NULL;
char receivedByte[9], *p;
int wAddreses;
mm_segment_t old_fs;
if(filp == NULL)
filp = filp_open(MY_FILE, O_RDWR | O_CREAT, 0666);
if (IS_ERR(filp)) {
printk("it7259 : Error occured while opening file %s, exiting...\n", MY_FILE);
set_fs(old_fs);
if(filp != NULL)
filp_close(filp, NULL);
return COMMAND_ERROR;
}
old_fs = get_fs();
set_fs(KERNEL_DS);
//if (!IS_ERR(filp)) {
filp->f_op->llseek(filp,0,0); // ?\8A\E6?標移?\B0\E6?案\E9?始\EF??\8D寫??
unMsgLen = sprintf(msg,"Channel = %d\r\n", ucStage);
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
unMsgLen = sprintf(msg,"Tx = Off\r\n");
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
unMsgLen = sprintf(msg,"Minima Frequency = 40\r\n");
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
unMsgLen = sprintf(msg,"Maxima Frequency = 110\r\n");
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
unMsgLen = sprintf(msg,"Number of Times = 10\r\n");
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
//unMsgLen = sprintf(msg,"Count = 1\r\n");
//filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
//filp->f_op->write(filp, (unsigned char *)pucCommandBuffer, 1024, &filp->f_pos);
//}
for(i = 1;i<11;i++){
unsigned int unRetry=0;
unMsgLen = sprintf(msg,"\r\nCount = %d\r\n", i);
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
pucCommandBuffer[0] = 0x1A;
pucCommandBuffer[1] = 0x01;
pucCommandBuffer[2] = ucTxMode;
pucCommandBuffer[3] = ucStage;
//send command
wTmp = IT7259_SendCommand(pucCommandBuffer,unWriteLength, pucCommandBuffer , unReadLength); //?^¶?data©??bregister?ìžm
if (wTmp != true) {
pr_err("msg: %s, wTmp = %d\r\n", msg, wTmp);
return COMMAND_ERROR;
}
//read memory
while(( (pucCommandBuffer[0] == 0x00)||(pucCommandBuffer[0] == 0xFF)||(pucCommandBuffer[1] == 0xFF))&&unRetry<10){
pucCommandBuffer[0] = 0x1A;
pucCommandBuffer[1] = 0x01;
pucCommandBuffer[2] = ucTxMode;
pucCommandBuffer[3] = ucStage;
wTmp = IT7259_SendCommand(pucCommandBuffer,unWriteLength, pucCommandBuffer , unReadLength);
pr_info("i= %d, Retry = %d\r\n",i,unRetry);
unRetry++;
if (wTmp != true)
return COMMAND_ERROR;
}
unRetry = 0;
wAddreses = (int)((pucCommandBuffer[1]<<8) | pucCommandBuffer[0]);
//pr_info("wAddreses : %X\r\n",wAddreses);
//?¹register?ª512?word?^š?¡C?\AC\C2?\82\AC@©wndirect access¡A¥?read memoryªºcommand¥hšú?^?\AC]¥i¥H¡A?ý?\ACUcommandªº?\AC芡€@?ž¥u¯??ª128bytes¡C¡A
//pr_info("SpectrumMode Read Buffer Start");
wTmp = i2cDMAReadFromIT7259(i2c_client, wAddreses,pucCommandBuffer, 1024);
//pr_info("SpectrumMode pucCommandBuffer\r\n");
//for(j=0;j<1024;j++)
// pr_info("%X, ",pucCommandBuffer[j]);
for(j=0;j<1024;j = j+2){
long intNumber;
sprintf(receivedByte, "0x%02X%02X", pucCommandBuffer[j+1], pucCommandBuffer[j]);
// pr_info("SpectrumMode pucCommandBuffer0: %X\r\n",pucCommandBuffer[j]);
// pr_info("SpectrumMode pucCommandBuffer1: %X\r\n",pucCommandBuffer[j+1]);
// pr_info("receivedByte: %s\r\n",receivedByte);
intNumber = simple_strtol(receivedByte, &p, 16);
unMsgLen = sprintf(msg,"%ld\r\n", intNumber);
filp->f_op->write(filp, msg, unMsgLen, &filp->f_pos);
}
//filp->f_op->write(filp, (unsigned char *)pucCommandBuffer, 1024, &filp->f_pos);
}
set_fs(old_fs);
if(filp != NULL)
filp_close(filp, NULL);
//reset FW
pucCommandBuffer[0] = 0x0C;
i2cWriteToIT7259(i2c_client, 0x20, pucCommandBuffer, 1);
mdelay(150);
if (wTmp != true)
return COMMAND_ERROR;
if (wTmp != COMMAND_SUCCESS)
return COMMAND_ERROR;
else
return COMMAND_SUCCESS;
}
int ite7259_open(struct inode *inode, struct file *filp) {
int i;
struct ite7259_data *dev;
pr_info("taikoto : =ite7259_open=\n");
dev = kmalloc(sizeof(struct ite7259_data), GFP_KERNEL);
if (dev == NULL) {
return -ENOMEM;
}
/* initialize members */
rwlock_init(&dev->lock);
for (i = 0; i < MAX_BUFFER_SIZE; i++) {
dev->buffer[i] = 0xFF;
}
filp->private_data = dev;
return 0; /* success */
}
int ite7259_close(struct inode *inode, struct file *filp) {
struct ite7259_data *dev = filp->private_data;
pr_info("taikoto : =ite7259_close=\n");
if (dev) {
kfree(dev);
}
return 0; /* success */
}
struct file_operations ite7259_fops = {
.owner = THIS_MODULE,
.open = ite7259_open,
.release = ite7259_close,
//.ioctl = ite7259_ioctl,
.unlocked_ioctl = ite7259_ioctl,
};
static struct miscdevice ctp_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = CTP_NAME,
.fops = &ite7259_fops,
};
static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info) {
// strcpy(info->type, "mtk-tpd");
strcpy(info->type, CTP_NAME);
return 0;
}
static int tpd_i2c_write(struct i2c_client *client, uint8_t *buf, int len)
{
int ret = 0;
#ifdef I2C_SUPPORT_RS_DMA
int i = 0;
printk("taikoto : start tpd_i2c_write len=%d.\n",len);
for(i = 0 ; i < len; i++){
I2CDMABuf_va[i] = buf[i];
}
if(len < 8){
client->addr = client->addr & I2C_MASK_FLAG;
return i2c_master_send(client, buf, len);
}else{
client->addr = client->addr & I2C_MASK_FLAG | I2C_DMA_FLAG;
return i2c_master_send(client, I2CDMABuf_pa, len);
}
#else
i2c_client->addr = i2c_client->addr & I2C_MASK_FLAG;
ret = i2c_master_send(i2c_client, &buf[0], len);
if(ret<0)
printk("%s error\n",__func__);
return ret;
#endif
return ret;
}
static int tpd_i2c_read(struct i2c_client *client, uint8_t *buf, int len , uint8_t addr)
{
int ret = 0;
//printk("start tpd_i2c_read len=%d.\n",len);
#ifdef I2C_SUPPORT_RS_DMA
int i = 0;
if(len <= 8){
buf[0] = addr;
i2c_client->addr = i2c_client->addr & I2C_MASK_FLAG | I2C_WR_FLAG | I2C_RS_FLAG;
ret = i2c_master_send(i2c_client, &buf[0], (len << 8 | 1));
}else{
/**
struct i2c_msg msg;
i2c_smbus_write_byte(i2c_client, addr);
msg.flags = i2c_client->flags & I2C_M_TEN;
msg.timing = 100;
msg.flags |= I2C_M_RD;
msg.len = len;
msg.ext_flag = i2c_client->ext_flag;
if(len <= 8)
{
msg.addr = i2c_client->addr & I2C_MASK_FLAG;
msg.buf = buf;
ret = i2c_transfer(i2c_client->adapter, &msg, 1);
return (ret == 1)? len : ret;
}else{
client->addr = client->addr & I2C_MASK_FLAG | I2C_DMA_FLAG ;
msg.addr = (i2c_client->addr & I2C_MASK_FLAG) | I2C_DMA_FLAG;
msg.buf = I2CDMABuf_pa;
ret = i2c_transfer(i2c_client->adapter, &msg, 1);