1 #include <linux/init.h>
2 #include <linux/module.h>
3 #include <linux/delay.h>
5 #include <linux/input.h>
6 #include <linux/slab.h>
7 #include <linux/gpio.h>
8 #include <linux/sched.h>
9 #include <linux/kthread.h>
10 #include <linux/bitops.h>
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/byteorder/generic.h>
14 #ifdef CONFIG_HAS_EARLYSUSPEND
15 #include <linux/earlysuspend.h>
17 #include <linux/interrupt.h>
18 #include <linux/time.h>
19 #include <linux/rtpm_prio.h>
21 #include <linux/proc_fs.h>
22 #include <asm/uaccess.h>
26 #include "tpd_custom_GT818B.h"
27 #include <mach/mt_pm_ldo.h>
28 #include <mach/mt_typedefs.h>
29 #include <mach/mt_boot.h>
32 #include <cust_eint.h>
33 #include <linux/jiffies.h>
36 #include "cust_gpio_usage.h"
41 extern struct tpd_device
*tpd
;
43 static int tpd_flag
= 0;
44 static int tpd_halt
=0;
45 static struct task_struct
*thread
= NULL
;
46 static DECLARE_WAIT_QUEUE_HEAD(waiter
);
47 static DEFINE_MUTEX(esd_check
);
50 #ifdef TPD_HAVE_BUTTON
51 static int tpd_keys_local
[TPD_KEY_COUNT
] = TPD_KEYS
;
52 static int tpd_keys_dim_local
[TPD_KEY_COUNT
][4] = TPD_KEYS_DIM
;
54 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
55 static int tpd_wb_start_local
[TPD_WARP_CNT
] = TPD_WARP_START
;
56 static int tpd_wb_end_local
[TPD_WARP_CNT
] = TPD_WARP_END
;
58 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
59 //static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
60 static int tpd_def_calmat_local
[8] = TPD_CALIBRATION_MATRIX
;
63 static void tpd_eint_interrupt_handler(void);
64 static int touch_event_handler(void *unused
);
65 static int tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
);
66 static int tpd_i2c_detect(struct i2c_client
*client
, struct i2c_board_info
*info
);
67 static int tpd_i2c_remove(struct i2c_client
*client
);
69 extern void mt65xx_eint_unmask(unsigned int line
);
70 extern void mt65xx_eint_mask(unsigned int line
);
71 extern void mt65xx_eint_set_hw_debounce(kal_uint8 eintno
, kal_uint32 ms
);
72 extern kal_uint32
mt65xx_eint_set_sens(kal_uint8 eintno
, kal_bool sens
);
73 extern void mt65xx_eint_registration(kal_uint8 eintno
, kal_bool Dbounce_En
,
74 kal_bool ACT_Polarity
, void (EINT_FUNC_PTR
)(void),
78 extern s32
init_wr_node(struct i2c_client
*);
79 extern void uninit_wr_node(void);
82 extern int gt818_downloader( struct i2c_client
*client
, unsigned short ver
, unsigned char * data
);
83 //#define TPD_DITO_SENSOR
84 //#define TPD_CONDITION_SWITCH
85 #define TPD_RESET_ISSUE_WORKAROUND
86 #define TPD_MAX_RESET_COUNT 3
89 static struct delayed_work tpd_esd_check_work
;
90 static struct workqueue_struct
* tpd_esd_check_workqueue
= NULL
;
91 static void tpd_esd_check_func(struct work_struct
*);
92 #define ESD_CHECK_CIRCLE 500
93 #define ESD_CHECK_DATA_LEN 6
94 #define ESD_CHECK_TIME 3
95 unsigned char esd_check_data
[ESD_CHECK_TIME
*ESD_CHECK_DATA_LEN
];
96 int esd_checked_time
= 0;
100 #define TPD_CONFIG_REG_BASE 0x6A2
101 #define TPD_FREQ_CAL_RESULT 0x70F
102 #define TPD_TOUCH_INFO_REG_BASE 0x712
103 #define TPD_POINT_INFO_REG_BASE 0x722
104 #define TPD_VERSION_INFO_REG 0x713
105 #define TPD_VERSION_BASIC_REG 0x717
106 #define TPD_KEY_INFO_REG_BASE 0x721
107 #define TPD_POWER_MODE_REG 0x692
108 #define TPD_HANDSHAKING_START_REG 0xFFF
109 #define TPD_HANDSHAKING_END_REG 0x8000
110 #define TPD_FREQ_REG 0x1522
111 #define TPD_SOFT_RESET_MODE 0x01
112 #define TPD_POINT_INFO_LEN 8
113 #define TPD_MAX_POINTS 5
114 #define MAX_TRANSACTION_LENGTH 8
115 #define I2C_DEVICE_ADDRESS_LEN 2
116 #define I2C_MASTER_CLOCK 200 //400 ·¢ÏÖÔÚÖжÏÖÐIIC×ÊÔ´»áÉêÇë²»³É¹¦
118 //#define TPD_X_RES 480
119 //#define TPD_Y_RES 800
121 extern kal_bool
upmu_is_chr_det(void);
123 #define MAX_I2C_TRANSFER_SIZE (MAX_TRANSACTION_LENGTH - I2C_DEVICE_ADDRESS_LEN)
125 #define GT818_CONFIG_PROC_FILE "gt818_config"
126 #define CONFIG_LEN (106)
138 #ifdef TPD_DITO_SENSOR
140 static u8
*cfg_data_version_d
= cfg_data_version_b
;
141 static u8
*cfg_data_with_charger_version_d
= cfg_data_with_charger_version_b
;
144 static struct i2c_client
*i2c_client
= NULL
;
145 static const struct i2c_device_id tpd_i2c_id
[] = {{"gt818b",0},{}};
146 static unsigned short force
[] = {0, 0xBA, I2C_CLIENT_END
,I2C_CLIENT_END
};
147 static const unsigned short * const forces
[] = { force
, NULL
};
148 //static struct i2c_client_address_data addr_data = { .forces = forces,};
149 static struct i2c_board_info __initdata i2c_tpd
={ I2C_BOARD_INFO("gt818b", (0xBA>>1))};
150 static struct i2c_driver tpd_i2c_driver
=
152 .probe
= tpd_i2c_probe
,
153 .remove
= tpd_i2c_remove
,
154 .detect
= tpd_i2c_detect
,
155 .driver
.name
= "gt818b",
156 .id_table
= tpd_i2c_id
,
157 .address_list
= (const unsigned short*) forces
,
159 struct tpd_info_t tpd_info
;
160 static u8
*cfg_data
= NULL
;
161 static u8
*cfg_data_with_charger
= NULL
;
163 /* proc file system */
164 static int i2c_read_bytes( struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
);
165 static int i2c_write_bytes( struct i2c_client
*client
, u16 addr
, u8
*txbuf
, int len
);
166 static int i2c_write_dummy( struct i2c_client
*client
, u16 addr
);
167 static struct proc_dir_entry
*gt818_config_proc
= NULL
;
169 #define VELOCITY_CUSTOM_GT818B
170 #ifdef VELOCITY_CUSTOM_GT818B
171 #include <linux/device.h>
172 #include <linux/miscdevice.h>
173 #include <asm/uaccess.h>
175 #ifndef TPD_VELOCITY_CUSTOM_X
176 #define TPD_VELOCITY_CUSTOM_X 10
178 #ifndef TPD_VELOCITY_CUSTOM_Y
179 #define TPD_VELOCITY_CUSTOM_Y 10
182 // for magnify velocity********************************************
183 #define TOUCH_IOC_MAGIC 'A'
185 #define TPD_GET_VELOCITY_CUSTOM_X _IO(TOUCH_IOC_MAGIC,0)
186 #define TPD_GET_VELOCITY_CUSTOM_Y _IO(TOUCH_IOC_MAGIC,1)
188 int g_v_magnify_x
=TPD_VELOCITY_CUSTOM_X
;
189 int g_v_magnify_y
=TPD_VELOCITY_CUSTOM_Y
;
190 static int tpd_misc_open(struct inode
*inode
, struct file
*file
)
193 return nonseekable_open(inode
, file
);
195 /*----------------------------------------------------------------------------*/
196 static int tpd_misc_release(struct inode
*inode
, struct file
*file
)
200 /*----------------------------------------------------------------------------*/
202 static long tpd_unlocked_ioctl(struct file
*file
, unsigned int cmd
,
211 if(_IOC_DIR(cmd
) & _IOC_READ
)
213 err
= !access_ok(VERIFY_WRITE
, (void __user
*)arg
, _IOC_SIZE(cmd
));
215 else if(_IOC_DIR(cmd
) & _IOC_WRITE
)
217 err
= !access_ok(VERIFY_READ
, (void __user
*)arg
, _IOC_SIZE(cmd
));
222 printk("tpd: access error: %08X, (%2d, %2d)\n", cmd
, _IOC_DIR(cmd
), _IOC_SIZE(cmd
));
228 case TPD_GET_VELOCITY_CUSTOM_X
:
229 data
= (void __user
*) arg
;
236 if(copy_to_user(data
, &g_v_magnify_x
, sizeof(g_v_magnify_x
)))
243 case TPD_GET_VELOCITY_CUSTOM_Y
:
244 data
= (void __user
*) arg
;
251 if(copy_to_user(data
, &g_v_magnify_y
, sizeof(g_v_magnify_y
)))
260 printk("tpd: unknown IOCTL: 0x%08x\n", cmd
);
270 static struct file_operations tpd_fops
= {
271 // .owner = THIS_MODULE,
272 .open
= tpd_misc_open
,
273 .release
= tpd_misc_release
,
274 .unlocked_ioctl
= tpd_unlocked_ioctl
,
276 /*----------------------------------------------------------------------------*/
277 static struct miscdevice tpd_misc_device
= {
278 .minor
= MISC_DYNAMIC_MINOR
,
283 //**********************************************
287 static int gt818_config_read_proc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
290 char temp_data
[CONFIG_LEN
] = {0};
293 ptr
+= sprintf( ptr
, "==== GT818 config init value====\n" );
295 for ( i
= 0 ; i
< CONFIG_LEN
; i
++ )
297 ptr
+= sprintf( ptr
, "0x%02X ", cfg_data
[i
] );
300 ptr
+= sprintf( ptr
, "\n" );
303 ptr
+= sprintf( ptr
, "\n" );
304 ptr
+= sprintf( ptr
, "==== GT818 charger init config ====\n" );
305 for ( i
= 0 ; i
< CONFIG_LEN
; i
++ )
307 ptr
+= sprintf( ptr
, "0x%02X ", cfg_data_with_charger
[i
] );
310 ptr
+= sprintf( ptr
, "\n" );
312 ptr
+= sprintf( ptr
, "\n" );
313 ptr
+= sprintf( ptr
, "==== GT818 config real value====\n" );
314 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
315 i2c_read_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, temp_data
, CONFIG_LEN
);
316 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
317 for ( i
= 0 ; i
< CONFIG_LEN
; i
++ )
319 ptr
+= sprintf( ptr
, "0x%02X ", temp_data
[i
] );
322 ptr
+= sprintf( ptr
, "\n" );
324 ptr
+= sprintf( ptr
, "\n" );
326 return ( ptr
- page
);
329 static int gt818_config_write_proc(struct file
*file
, const char *buffer
, unsigned long count
, void *data
)
331 kal_bool temp
= upmu_is_chr_det();
333 TPD_DEBUG("write count %ld\n", count
);
335 if ( count
!= (CONFIG_LEN
*2 ) )
337 TPD_DEBUG("size not match [%d:%ld]\n", CONFIG_LEN
*2, count
);
341 if (copy_from_user( cfg_data
, buffer
, count
/2))
343 TPD_DEBUG("copy from user fail\n");
347 if (copy_from_user( cfg_data_with_charger
, buffer
+ CONFIG_LEN
, count
/2))
349 TPD_DEBUG("copy from user fail\n");
352 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
355 i2c_write_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, cfg_data_with_charger
, CONFIG_LEN
);
357 i2c_write_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, cfg_data
, CONFIG_LEN
);
359 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
363 #if 0 //#ifdef TPD_RESET_ISSUE_WORKAROUND
364 static int gt818_check_data(unsigned char *buffer
, int count
)
366 unsigned char buf
[128] = {0}; // need > sizeof(buffer)
367 int i
= 0, error
= -1, ret
= -1;
371 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
372 ret
= i2c_read_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, buf
, CONFIG_LEN
);
373 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
376 TPD_DMESG("read i2c error\n");
379 for(i
= 0; i
< CONFIG_LEN
; i
++) // the last one byte will be changed
381 if(buf
[i
] != cfg_data
[i
])
383 TPD_DMESG(TPD_DEVICE
" fail to write touch panel config, %d bytes, expect:0x%x, real:0x%x\n", i
,cfg_data
[i
], buf
[i
]);
390 TPD_DMESG(TPD_DEVICE
" write touch panel config OK, count:%d\n", count
);
397 for(i
= 0; i
< CONFIG_LEN
- 1; i
++)
399 printk(" 0x%02X", buf
[i
]);
403 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
404 i2c_write_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, cfg_data
, CONFIG_LEN
);
405 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
413 static int i2c_read_bytes( struct i2c_client
*client
, u16 addr
, u8
*rxbuf
, int len
)
415 u8 buffer
[I2C_DEVICE_ADDRESS_LEN
];
420 struct i2c_msg msg
[2] =
423 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
426 .len
= I2C_DEVICE_ADDRESS_LEN
,
427 .timing
= I2C_MASTER_CLOCK
430 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
432 .timing
= I2C_MASTER_CLOCK
439 TPD_DEBUG("i2c_read_bytes to device %02X address %04X len %d\n", client
->addr
, addr
, len
);
443 buffer
[0] = ( ( addr
+offset
) >> 8 ) & 0xFF;
444 buffer
[1] = ( addr
+offset
) & 0xFF;
446 msg
[1].buf
= &rxbuf
[offset
];
448 if ( left
> MAX_TRANSACTION_LENGTH
)
450 msg
[1].len
= MAX_TRANSACTION_LENGTH
;
451 left
-= MAX_TRANSACTION_LENGTH
;
452 offset
+= MAX_TRANSACTION_LENGTH
;
462 while ( i2c_transfer( client
->adapter
, &msg
[0], 2 ) != 2 )
468 TPD_DEBUG("I2C read 0x%X length=%d failed\n", addr
+ offset
, len
);
469 TPD_DMESG("I2C read 0x%X length=%d failed\n", addr
+ offset
, len
);
478 static int i2c_write_bytes( struct i2c_client
*client
, u16 addr
, u8
*txbuf
, int len
)
480 u8 buffer
[MAX_TRANSACTION_LENGTH
];
487 .addr
= ((client
->addr
&I2C_MASK_FLAG
)|(I2C_ENEXT_FLAG
)),
490 .timing
= I2C_MASTER_CLOCK
,
497 TPD_DEBUG("i2c_write_bytes to device %02X address %04X len %d\n", client
->addr
, addr
, len
);
503 buffer
[0] = ( (addr
+offset
) >> 8 ) & 0xFF;
504 buffer
[1] = ( addr
+offset
) & 0xFF;
506 if ( left
> MAX_I2C_TRANSFER_SIZE
)
508 memcpy( &buffer
[I2C_DEVICE_ADDRESS_LEN
], &txbuf
[offset
], MAX_I2C_TRANSFER_SIZE
);
509 msg
.len
= MAX_TRANSACTION_LENGTH
;
510 left
-= MAX_I2C_TRANSFER_SIZE
;
511 offset
+= MAX_I2C_TRANSFER_SIZE
;
515 memcpy( &buffer
[I2C_DEVICE_ADDRESS_LEN
], &txbuf
[offset
], left
);
516 msg
.len
= left
+ I2C_DEVICE_ADDRESS_LEN
;
520 TPD_DEBUG("byte left %d offset %d\n", left
, offset
);
522 while ( i2c_transfer( client
->adapter
, &msg
, 1 ) != 1 )
528 TPD_DEBUG("I2C write 0x%X%X length=%d failed\n", buffer
[0], buffer
[1], len
);
529 TPD_DMESG("I2C write 0x%X%X length=%d failed\n", buffer
[0], buffer
[1], len
);
533 TPD_DEBUG("I2C write retry %d addr 0x%X%X\n", retry
, buffer
[0], buffer
[1]);
541 static int i2c_write_dummy( struct i2c_client
*client
, u16 addr
)
543 u8 buffer
[MAX_TRANSACTION_LENGTH
];
547 .addr
= client
->addr
,
550 .timing
= I2C_MASTER_CLOCK
,
554 TPD_DEBUG("i2c_write_dummy to device %02X address %04X\n", client
->addr
, addr
);
556 buffer
[0] = (addr
>> 8) & 0xFF;
557 buffer
[1] = (addr
) & 0xFF;
559 i2c_transfer( client
->adapter
, &msg
, 1 );
564 static int tpd_i2c_detect(struct i2c_client
*client
, struct i2c_board_info
*info
)
566 strcpy(info
->type
, "mtk-tpd");
571 void tpd_reset_fuc(struct i2c_client
*client
)
576 TPD_DMESG("[mtk-tpd] tpd_reset_fuc: \n");
577 //power off, need confirm with SA
578 #ifdef TPD_POWER_SOURCE_CUSTOM
579 hwPowerDown(TPD_POWER_SOURCE_CUSTOM
, "TP");
581 hwPowerDown(MT65XX_POWER_LDO_VGP2
, "TP");
583 #ifdef TPD_POWER_SOURCE_1800
584 hwPowerDown(TPD_POWER_SOURCE_1800
, "TP");
589 //INT pin use gpio mode we do not want receive int before touch config done
591 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_GPIO
);
592 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
593 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
596 //power on, need confirm with SA
597 #ifdef TPD_POWER_SOURCE_CUSTOM
598 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
600 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
602 #ifdef TPD_POWER_SOURCE_1800
603 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
610 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
611 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
612 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
615 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
619 //i2c_write_dummy( client, TPD_HANDSHAKING_START_REG );
620 err
= i2c_read_bytes( client
, TPD_VERSION_INFO_REG
, (u8
*)&tpd_info
, sizeof( struct tpd_info_t
) );
621 //i2c_write_dummy( client, TPD_HANDSHAKING_END_REG );
624 TPD_DMESG(TPD_DEVICE
" fail to get tpd info %d\n", err
);
630 TPD_DMESG( "TPD info\n");
631 TPD_DMESG( "vendor %02X %02X\n", tpd_info
.vendor_id_1
, tpd_info
.vendor_id_2
);
632 TPD_DMESG( "product %02X %02X\n", tpd_info
.product_id_1
, tpd_info
.product_id_2
);
633 TPD_DMESG( "version %02X %02X\n", tpd_info
.version_1
, tpd_info
.version_2
);
637 // setting resolution, RES_X, RES_Y
638 #ifdef RES_AUTO_CONFIG
639 cfg_data
[59] = cfg_data_with_charger
[59] = (TPD_X_RES
&0xff);//(TPD_RES_X&0xff);
640 cfg_data
[60] = cfg_data_with_charger
[60] = ((TPD_X_RES
>>8)&0xff);//((TPD_RES_X>>8)&0xff);
641 cfg_data
[61] = cfg_data_with_charger
[61] = (TPD_Y_RES
&0xff);//(TPD_RES_Y&0xff);
642 cfg_data
[62] = cfg_data_with_charger
[62] = ((TPD_Y_RES
>>8)&0xff);//((TPD_RES_Y>>8)&0xff);
646 err
= i2c_write_bytes( client
, TPD_CONFIG_REG_BASE
, cfg_data
, CONFIG_LEN
);
650 int_type
= ((cfg_data
[55]>>3)&0x01);
652 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
653 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
654 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
655 //mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
659 //mt65xx_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE);
660 //mt65xx_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN);
661 //mt65xx_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_TOUCH_PANEL_POLARITY, tpd_eint_interrupt_handler, 1);
664 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_RISING
, tpd_eint_interrupt_handler
, 1);
668 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_FALLING
, tpd_eint_interrupt_handler
, 1);
671 TPD_DMESG("[mtk-tpd] tpd_reset_fuc: done\n");
674 static int tpd_i2c_probe(struct i2c_client
*client
, const struct i2c_device_id
*id
)
678 #ifdef AUTOUPDATE_FIRMWARE
680 u8 version_tmp
[2] = {0};
686 #ifdef TPD_RESET_ISSUE_WORKAROUND
693 #ifdef TPD_POWER_SOURCE_CUSTOM
694 //power on, need confirm with SA
695 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
697 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
699 #ifdef TPD_POWER_SOURCE_1800
700 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
704 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_GPIO
);
705 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
706 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
709 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
710 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
711 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
714 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
719 #ifdef TPD_POWER_SOURCE_CUSTOM
720 //power on, need confirm with SA
721 hwPowerOn(TPD_POWER_SOURCE_CUSTOM
, VOL_2800
, "TP");
723 hwPowerOn(MT65XX_POWER_LDO_VGP2
, VOL_2800
, "TP");
725 #ifdef TPD_POWER_SOURCE_1800
726 hwPowerOn(TPD_POWER_SOURCE_1800
, VOL_1800
, "TP");
730 // set deep sleep off
731 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
732 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
733 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
738 memset( &tpd_info
, 0, sizeof( struct tpd_info_t
) );
739 i2c_write_dummy( client
, TPD_HANDSHAKING_START_REG
);
740 err
= i2c_read_bytes( client
, TPD_VERSION_INFO_REG
, (u8
*)&tpd_info
, sizeof( struct tpd_info_t
) );
741 i2c_write_dummy( client
, TPD_HANDSHAKING_END_REG
);
744 TPD_DMESG(TPD_DEVICE
" fail to get tpd info %d\n", err
);
745 #ifdef TPD_RESET_ISSUE_WORKAROUND
746 if ( reset_count
< TPD_MAX_RESET_COUNT
)
756 TPD_DMESG( "TPD info\n");
757 TPD_DMESG( "vendor %02X %02X\n", tpd_info
.vendor_id_1
, tpd_info
.vendor_id_2
);
758 TPD_DMESG( "product %02X %02X\n", tpd_info
.product_id_1
, tpd_info
.product_id_2
);
759 TPD_DMESG( "version %02X %02X\n", tpd_info
.version_1
, tpd_info
.version_2
);
761 #ifdef AUTOUPDATE_FIRMWARE
762 //may be cause WCT time out if i2c ack error
763 for(i
= 0;i
< 10;i
++)
766 err
= i2c_read_bytes( client
, TPD_VERSION_BASIC_REG
, version_tmp
, 2 );
768 if(((tpd_info
.version_1
) !=version_tmp
[0])||((tpd_info
.version_2
) != version_tmp
[1]))
770 tpd_info
.version_1
= version_tmp
[0];
771 tpd_info
.version_2
= version_tmp
[1];
781 TPD_DMESG( "after check version %02X %02X\n", tpd_info
.version_1
, tpd_info
.version_2
);
785 tpd_info
.version_1
= 0xff;
786 tpd_info
.version_2
= 0xff;
787 TPD_DMESG( "after check version %02X %02X\n", tpd_info
.version_1
, tpd_info
.version_2
);
790 //check if upgradable
791 gt818_downloader( client
, tpd_info
.version_2
*256 + tpd_info
.version_1
, goodix_gt818_firmware
);
795 #ifdef VELOCITY_CUSTOM_GT818B
796 if((err
= misc_register(&tpd_misc_device
)))
798 printk("mtk_tpd: tpd_misc_device register failed\n");
805 // Create proc file system
806 gt818_config_proc
= create_proc_entry( GT818_CONFIG_PROC_FILE
, 0664, NULL
);
808 if ( gt818_config_proc
== NULL
)
810 TPD_DEBUG("create_proc_entry %s failed\n", GT818_CONFIG_PROC_FILE
);
814 gt818_config_proc
->read_proc
= gt818_config_read_proc
;
815 gt818_config_proc
->write_proc
= gt818_config_write_proc
;
818 #ifdef CREATE_WR_NODE
820 init_wr_node(client
);
823 if ( tpd_info
.version_1
< 0x7A ) // Chip version B or Version C
825 TPD_DMESG(TPD_DEVICE
" read version %02X , use B version config\n", tpd_info
.version_1
);
826 TPD_DMESG(TPD_DEVICE
" B version: 0x4B~0x59, C version 0x5A~0x79\n" );
827 cfg_data
= cfg_data_version_b
;
828 cfg_data_with_charger
= cfg_data_with_charger_version_b
;
830 else if ( tpd_info
.version_1
< 0xA0 )
832 TPD_DMESG(TPD_DEVICE
" read version %02X, use D version config\n", tpd_info
.version_1
);
833 TPD_DMESG(TPD_DEVICE
" D version: 0x7A~0x99, E version 0x9A~0xB9\n" );
834 cfg_data
= cfg_data_version_d
;
835 cfg_data_with_charger
= cfg_data_with_charger_version_d
;
839 TPD_DMESG(TPD_DEVICE
" unknow Chip version %02X ,use B version config\n", tpd_info
.version_1
);
840 cfg_data
= cfg_data_version_b
;
841 cfg_data_with_charger
= cfg_data_with_charger_version_b
;
843 // setting resolution, RES_X, RES_Y
844 #ifdef RES_AUTO_CONFIG
845 cfg_data
[59] = cfg_data_with_charger
[59] = (TPD_X_RES
&0xff);//(TPD_RES_X&0xff);
846 cfg_data
[60] = cfg_data_with_charger
[60] = ((TPD_X_RES
>>8)&0xff);//((TPD_RES_X>>8)&0xff);
847 cfg_data
[61] = cfg_data_with_charger
[61] = (TPD_Y_RES
&0xff);//(TPD_RES_Y&0xff);
848 cfg_data
[62] = cfg_data_with_charger
[62] = ((TPD_Y_RES
>>8)&0xff);//((TPD_RES_Y>>8)&0xff);
850 int_type
= ((cfg_data
[55]>>3)&0x01);
851 i2c_write_dummy( client
, TPD_HANDSHAKING_START_REG
);
852 err
= i2c_write_bytes( client
, TPD_CONFIG_REG_BASE
, cfg_data
, CONFIG_LEN
);
853 i2c_write_dummy( client
, TPD_HANDSHAKING_END_REG
);
854 #if 0 //#ifdef TPD_RESET_ISSUE_WORKAROUND
855 err
= gt818_check_data(cfg_data
, TPD_MAX_RESET_COUNT
);
858 TPD_DMESG(TPD_DEVICE
" retry TPD_MAX_RESET_COUNT fail to write tpd cfg %d\n", err
);
863 thread
= kthread_run(touch_event_handler
, 0, TPD_DEVICE
);
867 err
= PTR_ERR(thread
);
868 TPD_DMESG(TPD_DEVICE
" failed to create kernel thread: %d\n", err
);
871 #ifdef HAVE_TOUCH_KEY
872 //for(retry = 0; retry < MAX_KEY_NUM; retry++)
874 /// input_set_capability(tpd->dev,EV_KEY,touch_key_array[retry]);
879 #ifndef TPD_RESET_ISSUE_WORKAROUND
880 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
885 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
886 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
887 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
888 //mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
892 //mt65xx_eint_set_sens(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE);
893 //mt65xx_eint_set_hw_debounce(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN);
894 //mt65xx_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_EN, CUST_EINT_TOUCH_PANEL_POLARITY, tpd_eint_interrupt_handler, 1);
897 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_RISING
, tpd_eint_interrupt_handler
, 1);
901 mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM
, EINTF_TRIGGER_FALLING
, tpd_eint_interrupt_handler
, 1);
903 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
905 #ifndef TPD_RESET_ISSUE_WORKAROUND
906 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
911 tpd_esd_check_workqueue
= create_workqueue("tpd_esd_check");
913 INIT_DELAYED_WORK(&tpd_esd_check_work
, tpd_esd_check_func
);
915 err
= queue_delayed_work(tpd_esd_check_workqueue
, &tpd_esd_check_work
,ESD_CHECK_CIRCLE
);
923 static void tpd_eint_interrupt_handler(void)
925 //TPD_DMESG( "TPD interrupt!!!!!!\n" );
928 wake_up_interruptible(&waiter
);
930 static int tpd_i2c_remove(struct i2c_client
*client
)
932 #ifdef CREATE_WR_NODE
937 destroy_workqueue(tpd_esd_check_workqueue
);
945 static force_reset_guitar()
949 for ( i
= 0; i
< 5; i
++)
952 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
953 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
954 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
956 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
959 if (tpd_init_panel())
963 i2c_enable_commands(i2c_client
, TPD_I2C_DISABLE_REG
);
969 static int check_IC_sample(void) //
974 u8 raw_buffer_curr
[10] = {0};
975 u8 raw_buffer_last
[10] = {0};
979 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
980 err
= i2c_read_bytes( i2c_client
, 0x880, raw_buffer_curr
, 10 );
981 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
983 printk( " raw_buffer_curr: \n");
986 printk( " %x ",raw_buffer_curr
[j
]);
990 printk( "\n raw_buffer_last: \n");
993 printk( " %x ",raw_buffer_last
[j
]);
997 if(0 == memcmp(raw_buffer_last
,raw_buffer_curr
,10))
1001 TPD_DMESG( " check_count =%d \n",check_count
);
1004 memcpy(raw_buffer_last
,raw_buffer_curr
,10);
1008 if(3 == check_count
)
1010 TPD_DMESG( "ic do not sample \n");
1018 static void tpd_esd_check_func(struct work_struct
*work
)
1023 TPD_DMESG( "tpd_esd_check_func++\n");
1024 mutex_lock(&esd_check
);
1027 mutex_unlock(&esd_check
);
1028 TPD_DMESG( "tpd_esd_check_func return ..\n");
1031 //do not print error msg if ack error
1032 i2c_client
->addr
= i2c_client
->addr
| I2C_A_FILTER_MSG
;
1034 //check raw data if IC do not sample reset touch IC
1035 err
= check_IC_sample();
1038 TPD_DMESG( "IC do not sample \n");
1039 tpd_reset_fuc(i2c_client
);
1041 for (i
= 0; i
< 3; i
++)
1043 memset( &tpd_info
, 0, sizeof( struct tpd_info_t
) );
1044 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
1045 err
= i2c_read_bytes( i2c_client
, TPD_VERSION_INFO_REG
, (u8
*)&tpd_info
, sizeof( struct tpd_info_t
) );
1046 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1058 tpd_reset_fuc(i2c_client
);
1064 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1068 queue_delayed_work(tpd_esd_check_workqueue
, &tpd_esd_check_work
, ESD_CHECK_CIRCLE
);
1071 //do not print error msg if ack error
1072 i2c_client
->addr
= i2c_client
->addr
& (~I2C_A_FILTER_MSG
);
1073 mutex_unlock(&esd_check
);
1074 TPD_DMESG( "tpd_esd_check_func--\n");
1079 static void tpd_down(int x
, int y
, int size
, int id
)
1081 //TPD_DMESG( "TPD donw id=%d\n",id-1);
1082 input_report_abs(tpd
->dev
, ABS_PRESSURE
, size
/100);
1083 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
1084 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, size
/100);
1085 input_report_abs(tpd
->dev
, ABS_MT_WIDTH_MAJOR
, 0);
1086 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
1087 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
1088 /* track id Start 0 */
1089 input_report_abs(tpd
->dev
, ABS_MT_TRACKING_ID
, id
-1);
1090 input_mt_sync(tpd
->dev
);
1091 //TPD_DEBUG_PRINT_POINT( x, y, 1 );
1092 TPD_EM_PRINT(x
, y
, x
, y
, id
-1, 1);
1094 if (FACTORY_BOOT
== get_boot_mode()|| RECOVERY_BOOT
== get_boot_mode())
1096 tpd_button(x
, y
, 1);
1100 static void tpd_up(int x
, int y
, int id
)
1102 //TPD_DMESG( "TPD up id=%d\n",id-1);
1104 //input_report_abs(tpd->dev, ABS_PRESSURE, 0);
1105 input_report_key(tpd
->dev
, BTN_TOUCH
, 0);
1106 //input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0);
1107 //input_report_abs(tpd->dev, ABS_MT_WIDTH_MAJOR, 0);
1108 //input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
1109 //input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
1110 /* track id Start 0 */
1111 //input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id-1);
1112 input_mt_sync(tpd
->dev
);
1113 TPD_EM_PRINT(x
, y
, x
, y
, id
, 0);
1115 if (FACTORY_BOOT
== get_boot_mode()|| RECOVERY_BOOT
== get_boot_mode())
1117 tpd_button(x
, y
, 0);
1119 //TPD_DEBUG_PRINT_POINT( x, y, 0 );
1122 #ifdef HAVE_TOUCH_KEY
1123 static void tpd_down2(int x
, int y
)
1125 input_report_abs(tpd
->dev
, ABS_PRESSURE
, 8);
1126 input_report_key(tpd
->dev
, BTN_TOUCH
, 1);
1127 input_report_abs(tpd
->dev
, ABS_MT_TOUCH_MAJOR
, 8);
1128 input_report_abs(tpd
->dev
, ABS_MT_POSITION_X
, x
);
1129 input_report_abs(tpd
->dev
, ABS_MT_POSITION_Y
, y
);
1130 input_mt_sync(tpd
->dev
);
1131 //TPD_DMESG( "tpd_down2 \n");
1132 if (FACTORY_BOOT
== get_boot_mode()|| RECOVERY_BOOT
== get_boot_mode())
1134 //TPD_DMESG( "tpd_down2 button \n");
1135 tpd_button(x
, y
, 1);
1137 input_sync(tpd
->dev
);
1142 static void tpd_up2(int x
, int y
)
1144 // input_report_abs(tpd->dev, ABS_PRESSURE, 0);
1145 input_report_key(tpd
->dev
, BTN_TOUCH
, 0);
1146 //input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 0);
1147 input_mt_sync(tpd
->dev
);
1148 //TPD_DMESG( "tpd_up2 \n");
1149 if (FACTORY_BOOT
== get_boot_mode()|| RECOVERY_BOOT
== get_boot_mode())
1151 //TPD_DMESG( "tpd_up2 button\n");
1152 tpd_button(x
, y
, 0);
1154 input_sync(tpd
->dev
);
1159 static int touch_event_handler(void *unused
)
1161 struct sched_param param
= { .sched_priority
= RTPM_PRIO_TPD
};
1162 int x
, y
, size
, finger_num
= 0;
1163 int wrap_x
,wrap_y
=0;
1165 static u8 buffer
[ TPD_POINT_INFO_LEN
*TPD_MAX_POINTS
];
1166 static char buf_status
;
1167 //static u8 id_mask = 0;
1170 char temp_data
[CONFIG_LEN
] = {0};
1173 static int x_history
[TPD_MAX_POINTS
+1];
1174 static int y_history
[TPD_MAX_POINTS
+1];
1176 #ifdef HAVE_TOUCH_KEY
1177 static u8 last_key
= 0;
1179 unsigned int count
= 0;
1182 #ifdef TPD_CONDITION_SWITCH
1183 u8 charger_plug
= 0;
1188 sched_setscheduler(current
, SCHED_RR
, ¶m
);
1192 set_current_state(TASK_INTERRUPTIBLE
);
1200 wait_event_interruptible(waiter
, tpd_flag
!= 0);
1203 set_current_state(TASK_RUNNING
);
1205 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
1207 #ifdef TPD_CONDITION_SWITCH
1208 /* Workaround for common mode noise */
1210 temp
= upmu_is_chr_det();
1211 //TPD_DMESG("check charge, status:%d \n", upmu_is_chr_det());
1216 if ( temp
) // charger is on
1218 if ( charger_plug
== 0 )
1220 TPD_DEBUG("update configure for charger\n");
1221 //TPD_DMESG("update configure for charger\n");
1223 cfg
= cfg_data_with_charger
;
1228 if ( charger_plug
== 1 )
1230 TPD_DEBUG("update configure for no charger\n");
1231 //TPD_DMESG("update configure for no charger\n");
1239 TPD_DMESG("[mtk-tpd] charger change rewrite config \n");
1240 i2c_write_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, cfg
, CONFIG_LEN
);
1241 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1246 i2c_read_bytes( i2c_client
, TPD_TOUCH_INFO_REG_BASE
, buffer
, 1);
1247 TPD_DEBUG("[mtk-tpd] STATUS : %x\n", buffer
[0]);
1248 #ifdef HAVE_TOUCH_KEY
1249 i2c_read_bytes( i2c_client
, TPD_KEY_INFO_REG_BASE
, &key
, 1);
1250 TPD_DEBUG("[mtk-tpd] STATUS : %x\n", key
);
1254 finger_num
= buffer
[0] & 0x0f;
1255 buf_status
= buffer
[0] & 0xf0;
1257 if ( tpd
== NULL
|| tpd
->dev
== NULL
)
1259 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
); //kuuga add 11082401
1260 TPD_DEBUG("[mtk-tpd] tpd=%x, tpd->dev=%x\n",tpd
, tpd
->dev
);
1265 if ( 0x0f == buffer
[0] ) // send cfg again!!
1267 TPD_DMESG("[mtk-tpd] STATUS error : %x\n", buffer
[0]);
1268 TPD_DMESG("[mtk-tpd] dumpt error config: \n");
1270 //i2c_write_dummy( i2c_client, TPD_HANDSHAKING_START_REG );
1271 i2c_read_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, temp_data
, CONFIG_LEN
);
1272 //i2c_write_dummy( i2c_client, TPD_HANDSHAKING_END_REG );
1273 for ( i
= 0 ; i
< CONFIG_LEN
; i
++ )
1275 printk( "0x%02X ", temp_data
[i
] );
1280 TPD_DMESG("[mtk-tpd] dumpt error config done \n");
1282 tpd_reset_fuc(i2c_client
);
1284 TPD_DMESG("[mtk-tpd] dumpt config again : \n");
1285 //i2c_write_dummy( i2c_client, TPD_HANDSHAKING_START_REG );
1286 i2c_read_bytes( i2c_client
, TPD_CONFIG_REG_BASE
, temp_data
, CONFIG_LEN
);
1287 //i2c_write_dummy( i2c_client, TPD_HANDSHAKING_END_REG );
1288 for ( i
= 0 ; i
< CONFIG_LEN
; i
++ )
1290 printk( "0x%02X ", temp_data
[i
] );
1294 TPD_DMESG("[mtk-tpd] dumpt config done \n");
1295 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1299 if ( (buf_status
&0x30) != 0x20 ) //data not ready£¬so return
1301 TPD_DMESG("[mtk-tpd] STATUS : %x\n", buffer
[0]);
1302 TPD_DMESG("[mtk-tpd] data not ready return \n");
1303 // tpd_reset_fuc(i2c_client);
1304 //i2c_write_dummy( i2c_client, TPD_HANDSHAKING_END_REG ); //kuuga add 11082401
1308 if ( finger_num
> 5 ) //abnormal state £¬so return
1310 TPD_DMESG("[mtk-tpd] finger_num =%d abnormal state !\n",finger_num
);
1311 TPD_DMESG("[mtk-tpd] STATUS : %x\n", buffer
[0]);
1312 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
); //kuuga add 11082401
1317 i2c_read_bytes( i2c_client
, TPD_POINT_INFO_REG_BASE
, buffer
, finger_num
*TPD_POINT_INFO_LEN
);
1322 //In order to release INT
1323 i2c_read_bytes( i2c_client
, TPD_POINT_INFO_REG_BASE
, buffer
, 1);
1328 for ( idx
= 0 ; idx
< finger_num
; idx
++ )
1330 u8
*ptr
= &buffer
[ idx
*TPD_POINT_INFO_LEN
];
1333 if ( id
< TPD_MAX_POINTS
+1 )
1335 x
= ptr
[1] + (((int)ptr
[2]) << 8);
1336 y
= ptr
[3] + (((int)ptr
[4]) << 8);
1337 size
= ptr
[5] + (((int)ptr
[6]) << 8);
1339 wrap_x
= TPD_WARP_X(x
);
1340 wrap_y
= TPD_WARP_Y(y
);
1342 if(TPD_X_RES
== TPD_WARP_X(x
))
1346 if(0==TPD_WARP_X(x
))
1350 if(0==TPD_WARP_Y(y
))
1354 if(TPD_Y_RES
==TPD_WARP_Y(y
))
1359 tpd_down( wrap_x
, wrap_y
, size
, id
);
1361 cur_mask
|= ( 1 << id
);
1366 TPD_DEBUG("Invalid id %d\n", id
);
1369 // linux kernel update from 2.6.35 --> 3.0
1370 if ( cur_mask
!= id_mask
)
1372 u8 diff
= cur_mask
^id_mask
;
1374 //TPD_DMESG("diff= %x\n", diff );
1375 //TPD_DMESG("cur_mask= %d\n", cur_mask );
1379 if ( ( ( diff
& 0x01 ) == 1 ) &&
1380 ( ( cur_mask
>> idx
) & 0x01 ) == 0 )
1382 // check if key release
1383 tpd_up( TPD_WARP_X(x_history
[idx
]), TPD_WARP_Y(y_history
[idx
]), idx
);
1386 diff
= ( diff
>> 1 );
1393 if ( tpd
!= NULL
&& tpd
->dev
!= NULL
)
1394 input_sync(tpd
->dev
);
1397 #ifdef HAVE_TOUCH_KEY
1398 if((last_key
== 0)&&(key
== 0))
1402 for(count
= 0; count
< 4; count
++)
1404 //input_report_key(tpd->dev, touch_key_array[count], !!(key&(0x01<<count)));
1405 if( key
&(0x01<<count
) ) //key=1 menu ;key=2 home; key =4 back; key=8 search
1407 wrap_x
=touch_key_point_maping_array
[count
].point_x
;
1408 wrap_y
= touch_key_point_maping_array
[count
].point_y
;
1409 TPD_DMESG("button =%d %d\n",wrap_x
,wrap_y
);
1411 tpd_down2( wrap_x
, wrap_y
);
1414 if((last_key
!=0)&&(key
==0))
1422 // linux kernel update from 2.6.35 --> 3.0
1425 if ( tpd
!= NULL
&& tpd
->dev
!= NULL
)
1426 input_sync(tpd
->dev
);
1430 #ifdef HAVE_TOUCH_KEY
1432 if ( tpd
!= NULL
&& tpd
->dev
!= NULL
&& 0==key
&& 0==last_key
)
1434 //input_mt_sync(tpd->dev);
1438 tpd_up( TPD_WARP_X(x_history
[idx
]), TPD_WARP_Y(y_history
[idx
]), idx
);
1439 input_sync(tpd
->dev
);
1442 if ( tpd
!= NULL
&& tpd
->dev
!= NULL
)
1444 //input_mt_sync(tpd->dev);
1445 tpd_up( TPD_WARP_X(x_history
[idx
]), TPD_WARP_Y(y_history
[idx
]), idx
);
1446 input_sync(tpd
->dev
);
1453 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1455 } while ( !kthread_should_stop() );
1460 static int tpd_local_init(void)
1463 if(i2c_add_driver(&tpd_i2c_driver
)!=0)
1465 TPD_DMESG("unable to add i2c driver.\n");
1468 if(tpd_load_status
== 0) //if(tpd_load_status == 0) // disable auto load touch driver for linux3.0 porting
1470 TPD_DMESG("add error touch panel driver.\n");
1471 i2c_del_driver(&tpd_i2c_driver
);
1475 #ifdef TPD_HAVE_BUTTON
1476 tpd_button_setting(TPD_KEY_COUNT
, tpd_keys_local
, tpd_keys_dim_local
);// initialize tpd button data
1479 #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
1481 memcpy(tpd_wb_start
, tpd_wb_start_local
, TPD_WARP_CNT
*4);
1482 memcpy(tpd_wb_end
, tpd_wb_start_local
, TPD_WARP_CNT
*4);
1485 #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
1486 memcpy(tpd_calmat
, tpd_def_calmat_local
, 8*4);
1487 memcpy(tpd_def_calmat
, tpd_def_calmat_local
, 8*4);
1490 // set vendor string
1491 tpd
->dev
->id
.vendor
= (tpd_info
.vendor_id_2
<< 8 ) | tpd_info
.vendor_id_1
;
1492 tpd
->dev
->id
.product
= (tpd_info
.product_id_2
<< 8 ) | tpd_info
.product_id_1
;
1493 tpd
->dev
->id
.version
= (tpd_info
.version_2
<< 8 ) | tpd_info
.version_1
;
1495 TPD_DMESG("end %s, %d\n", __FUNCTION__
, __LINE__
);
1501 /* Function to manage low power suspend */
1502 //void tpd_suspend(struct i2c_client *client, pm_message_t message)
1503 static void tpd_suspend( struct early_suspend
*h
)
1506 TPD_DMESG("tpd_suspend\n");
1507 mutex_lock(&esd_check
);
1508 #if 0 // workaround for force tpd into sleep mode
1509 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_GPIO
);
1510 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_OUT
);
1511 mt_set_gpio_out(GPIO_CTP_EINT_PIN
, GPIO_OUT_ZERO
);
1515 cancel_delayed_work(&tpd_esd_check_work
);
1519 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
1520 i2c_write_bytes( i2c_client
, TPD_POWER_MODE_REG
, &mode
, 1 );
1521 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1522 mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM
);
1523 //mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
1525 mutex_unlock(&esd_check
);
1526 TPD_DMESG("tpd_suspend ok\n");
1529 /* Function to manage power-on resume */
1530 //void tpd_resume(struct i2c_client *client)
1531 static void tpd_resume( struct early_suspend
*h
)
1533 #ifdef TPD_RESET_ISSUE_WORKAROUND
1534 struct tpd_info_t tpd_info
;
1538 TPD_DMESG(TPD_DEVICE
" tpd_resume start \n");
1539 #ifdef TPD_RESET_ISSUE_WORKAROUND
1542 // use raising edge of INT to wakeup
1543 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_GPIO
);
1544 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_OUT
);
1545 mt_set_gpio_out(GPIO_CTP_EINT_PIN
, GPIO_OUT_ZERO
);
1547 mt_set_gpio_out(GPIO_CTP_EINT_PIN
, GPIO_OUT_ONE
);
1549 mt_set_gpio_out(GPIO_CTP_EINT_PIN
, GPIO_OUT_ZERO
);
1551 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
1552 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
1556 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_GPIO
);
1557 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
1558 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
1561 mt_set_gpio_mode(GPIO_CTP_RST_PIN
, GPIO_CTP_RST_PIN_M_GPIO
);
1562 mt_set_gpio_dir(GPIO_CTP_RST_PIN
, GPIO_DIR_OUT
);
1563 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ZERO
);
1566 mt_set_gpio_out(GPIO_CTP_RST_PIN
, GPIO_OUT_ONE
);
1567 msleep(20);// msleep(20)
1570 mt_set_gpio_mode(GPIO_CTP_EINT_PIN
, GPIO_CTP_EINT_PIN_M_EINT
);
1571 mt_set_gpio_dir(GPIO_CTP_EINT_PIN
, GPIO_DIR_IN
);
1572 mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN
, GPIO_PULL_DISABLE
);
1573 //mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
1577 mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM
);
1578 //mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
1580 #ifdef TPD_RESET_ISSUE_WORKAROUND
1582 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_START_REG
);
1583 //TODO: Remove the code after the stabliity test is passed
1584 memset( &tpd_info
, 0, sizeof( struct tpd_info_t
) );
1585 err
= i2c_read_bytes( i2c_client
, TPD_VERSION_INFO_REG
, (u8
*)&tpd_info
, sizeof( struct tpd_info_t
) );
1589 TPD_DMESG(TPD_DEVICE
" fail to get tpd info %d\n", err
);
1590 tpd_reset_fuc(i2c_client
);
1594 TPD_DMESG( "TPD info\n");
1595 TPD_DMESG( "vendor %02X %02X\n", tpd_info
.vendor_id_1
, tpd_info
.vendor_id_2
);
1596 TPD_DMESG( "product %02X %02X\n", tpd_info
.product_id_1
, tpd_info
.product_id_2
);
1597 TPD_DMESG( "version %02X %02X\n", tpd_info
.version_1
, tpd_info
.version_2
);
1600 i2c_write_dummy( i2c_client
, TPD_HANDSHAKING_END_REG
);
1604 queue_delayed_work(tpd_esd_check_workqueue
, &tpd_esd_check_work
,ESD_CHECK_CIRCLE
);
1607 TPD_DMESG(TPD_DEVICE
" tpd_resume end \n" );
1611 static struct tpd_driver_t tpd_device_driver
=
1613 .tpd_device_name
= "gt818",
1614 .tpd_local_init
= tpd_local_init
,
1615 .suspend
= tpd_suspend
,
1616 .resume
= tpd_resume
,
1617 #ifdef TPD_HAVE_BUTTON
1618 .tpd_have_button
= 1,
1620 .tpd_have_button
= 0,
1624 /* called when loaded into kernel */
1625 static int __init
tpd_driver_init(void)
1627 TPD_DMESG("MediaTek gt818 touch panel driver init\n");
1628 i2c_register_board_info(0, &i2c_tpd
, 1);
1629 if ( tpd_driver_add(&tpd_device_driver
) < 0)
1630 TPD_DMESG("add generic driver failed\n");
1635 /* should never be called */
1636 static void __exit
tpd_driver_exit(void)
1638 TPD_DMESG("MediaTek gt818 touch panel driver exit\n");
1639 //input_unregister_device(tpd->dev);
1640 tpd_driver_remove(&tpd_device_driver
);
1643 module_init(tpd_driver_init
);
1644 module_exit(tpd_driver_exit
);