1 #include <linux/module.h>
2 #include <linux/delay.h>
3 #include <linux/earlysuspend.h>
4 #include <linux/hrtimer.h>
6 #include <linux/input.h>
7 #include <linux/interrupt.h>
9 #include <linux/platform_device.h>
10 #include <linux/async.h>
11 #include <mach/gpio.h>
12 #include <mach/iomux.h>
13 #include <linux/irq.h>
14 #include <mach/board.h>
15 #include <linux/kthread.h>
16 #include <linux/slab.h>
17 #include <linux/input/mt.h>
18 #include <linux/regulator/rk29-pwm-regulator.h>
19 #include <linux/regulator/machine.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/regulator/machine.h>
23 //#define FT5X0X_DEBUG
25 #define DBG(fmt, args...) printk("*** " fmt, ## args)
27 #define DBG(fmt, args...) do{}while(0)
30 #define EV_MENU KEY_MENU
32 #define I2C_SPEED 200*1000
35 #define SCREEN_MAX_X 1920
36 #define SCREEN_MAX_Y 1200
38 //#define TP_UPGRADE 1
42 #define VID_OF 0x51 //OuFei
43 #define VID_MD 0x53 //MuDong
45 #define VID_BM 0x5D //BaoMing
47 #define VID_DSW 0x8C //DingShengWei
48 #define VID_YM 0x94 //0xC0
49 static unsigned char g_vid;
51 #ifdef CONFIG_HAS_EARLYSUSPEND
52 static struct early_suspend ft5x0x_early_suspend;
55 #ifndef TOUCH_EN_LEVEL
56 #define TOUCH_EN_LEVEL GPIO_HIGH
59 static int ft5x0x_probe(struct i2c_client *client, const struct i2c_device_id *id);
68 static struct ts_event ts_point[MAX_POINT];
72 struct i2c_client *client;
73 struct input_dev *input_dev;
77 struct work_struct pen_event_work;
78 struct workqueue_struct *ts_workqueue;
81 struct i2c_client *g_client;
84 #define FT5X0X_REG_FIRMID 0xA6 /* ***************firmware version **********************/
86 /***********************************************************************
88 callback: write data to ctpm by i2c interface;
90 buffer[in]: data buffer;
91 length[in]: the length of the data buffer;
95 ************************************************************************/
96 static bool i2c_write_interface(u8* pbt_buf, int dw_lenth)
99 ret=i2c_master_send(g_client, pbt_buf, dw_lenth);
102 printk("[TSP]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
112 #define FTprintk(x...) printk(x)
114 #define FTprintk(x...) do{} while(0)
117 //#define CONFIG_FT5X0X_MULTITOUCH 1
118 #define FT5306_IIC_SPEED 250*1000 //300*1000
119 #define FT5X0X_REG_THRES 0x80 /* Thresshold, the threshold be low, the sensitivy will be high */
120 #define FT5X0X_REG_REPORT_RATE 0x88 /* **************report rate, in unit of 10Hz **************/
121 #define FT5X0X_REG_PMODE 0xA5 /* Power Consume Mode 0 -- active, 1 -- monitor, 3 -- sleep */
122 //#define FT5X0X_REG_FIRMID 0xA6 /* ***************firmware version **********************/
123 #define FT5X0X_REG_NOISE_MODE 0xb2 /* to enable or disable power noise, 1 -- enable, 0 -- disable */
126 #define PMODE_ACTIVE 0x00
127 #define PMODE_MONITOR 0x01
128 #define PMODE_STANDBY 0x02
129 #define PMODE_HIBERNATE 0x03
141 struct ft5x0x_ts_data {
142 struct i2c_client *client;
143 struct input_dev *input_dev;
145 int (*platform_sleep)(void);
146 int (*platform_wakeup)(void);
147 struct ts_event event;
148 struct work_struct pen_event_work;
149 struct workqueue_struct *ts_workqueue;
150 #ifdef CONFIG_HAS_EARLYSUSPEND
151 struct early_suspend ft5306_early_suspend;
155 /***********************************************************************/
157 #define FTS_PACKET_LENGTH 128
162 //#include "7022620120726B.txt"
163 //#include "101050-01A-ft_app.i"
164 //#include "ft_app_u30gt2.i"
165 #include "20130305-u30gt2-ft5506_app.i"
181 /***********************************************************************/
183 /***********************************************************************
185 callback: send data to ctpm by i2c interface;
187 txdata[in]: data buffer which is used to send data;
188 length[in]: the length of the data buffer;
192 ************************************************************************/
193 static int fts_i2c_txdata(u8 *txdata, int length)
199 msg.addr = g_client->addr;
203 msg.scl_rate = FT5306_IIC_SPEED;
204 ret = i2c_transfer(g_client->adapter, &msg, 1);
206 pr_err("%s i2c write error: %d\n", __func__, ret);
212 /***********************************************************************
214 callback: read register value ftom ctpm by i2c interface;
216 reg_name[in]: the register which you want to write;
217 tx_buf[in]: buffer which is contained of the writing value;
221 ************************************************************************/
222 static bool fts_register_write(u8 reg_name, u8* tx_buf)
224 u8 write_cmd[2] = {0};
226 write_cmd[0] = reg_name;
227 write_cmd[1] = *tx_buf;
229 /*call the write callback function*/
230 return i2c_write_interface(write_cmd, 2);
233 /***********************************************************************
235 callback: send a command to ctpm.
237 btcmd[in]: command code;
238 btPara1[in]: parameter 1;
239 btPara2[in]: parameter 2;
240 btPara3[in]: parameter 3;
241 num[in]: the valid input parameter numbers,
242 if only command code needed and no
243 parameters followed,then the num is 1;
247 ************************************************************************/
248 static bool cmd_write(u8 btcmd,u8 btPara1,u8 btPara2,u8 btPara3,u8 num)
250 u8 write_cmd[4] = {0};
252 write_cmd[0] = btcmd;
253 write_cmd[1] = btPara1;
254 write_cmd[2] = btPara2;
255 write_cmd[3] = btPara3;
256 return i2c_write_interface(write_cmd, num);
259 /***********************************************************************
261 callback: read data from ctpm by i2c interface;
263 buffer[in]: data buffer;
264 length[in]: the length of the data buffer;
268 ************************************************************************/
269 static bool i2c_read_interface(u8* pbt_buf, int dw_lenth)
273 ret=i2c_master_recv(g_client, pbt_buf, dw_lenth);
277 FTprintk("[TSP]i2c_read_interface error\n");
285 /***********************************************************************
287 callback: read a byte data from ctpm;
289 buffer[in]: read buffer;
290 length[in]: the size of read data;
294 ************************************************************************/
295 static bool byte_read(u8* buffer, int length)
297 return i2c_read_interface(buffer, length);
300 /***********************************************************************
302 callback: write a byte data to ctpm;
304 buffer[in]: write buffer;
305 length[in]: the size of write data;
309 ************************************************************************/
310 static bool byte_write(u8* buffer, int length)
313 return i2c_write_interface(buffer, length);
316 /***********************************************************************
318 callback: read register value ftom ctpm by i2c interface;
320 reg_name[in]: the register which you want to read;
321 rx_buf[in]: data buffer which is used to store register value;
322 rx_length[in]: the length of the data buffer;
326 ************************************************************************/
327 static bool fts_register_read(u8 reg_name, u8* rx_buf, int rx_length)
332 read_cmd[0] = reg_name;
335 /*send register addr*/
336 if(!i2c_write_interface(&read_cmd[0], cmd_len))
341 /*call the read callback function to get the register value*/
342 if(!i2c_read_interface(rx_buf, rx_length))
351 /***********************************************************************
353 callback: burn the FW to ctpm.
355 pbt_buf[in]: point to Head+FW ;
356 dw_lenth[in]: the length of the FW + 6(the Head length);
359 ERR_MODE: fail to switch to UPDATE mode;
360 ERR_READID: read id fail;
361 ERR_ERASE: erase chip fail;
362 ERR_STATUS: status error;
364 ************************************************************************/
365 E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(u8* pbt_buf, int dw_lenth)
367 u8 cmd,reg_val[2] = {0};
369 u8 packet_buf[FTS_PACKET_LENGTH + 6];
370 u8 auc_i2c_write_buf[10];
373 int j,temp,lenght,i_ret,packet_number, i = 0;
374 int i_is_new_protocol = 0;
377 /******write 0xaa to register 0xfc******/
379 fts_register_write(0xfc,&cmd);
382 /******write 0x55 to register 0xfc******/
384 fts_register_write(0xfc,&cmd);
385 FTprintk("[TSP] Step 1: Reset CTPM test\n");
390 /******write 0xaa to register 0xfc******/
392 fts_register_write(0xfc,&cmd);
395 /******write 0x55 to register 0xfc******/
397 fts_register_write(0xfc,&cmd);
398 FTprintk("[TSP] Step 1: Reset CTPM test\n");
402 /******write 0xaa to register 0xfc******/
404 fts_register_write(0xfc,&cmd);
407 /******write 0x55 to register 0xfc******/
409 fts_register_write(0xfc,&cmd);
410 FTprintk("[TSP] Step 1: Reset CTPM test\n");
417 /*******Step 2:Enter upgrade mode ****/
418 FTprintk("\n[TSP] Step 2:enter new update mode\n");
419 auc_i2c_write_buf[0] = 0x55;
420 auc_i2c_write_buf[1] = 0xaa;
421 printk("xhc-----------!!!!!!!!!\n");
425 i_ret = fts_i2c_txdata(auc_i2c_write_buf, 2);
427 }while(i_ret <= 0 && i < 10 );
431 i_is_new_protocol = 1;
434 /********Step 3:check READ-ID********/
436 cmd_write(0x90,0x00,0x00,0x00,4);
437 byte_read(reg_val,2);
438 printk("################## id0=0x%0x, id1=0x%0x\n", reg_val[0],reg_val[1]);
439 if (reg_val[0] == 0x79 && reg_val[1] == 0x6)
441 FTprintk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
446 //i_is_new_protocol = 1;
450 /*********Step 4:erase app**********/
451 if (i_is_new_protocol)
453 cmd_write(0x61,0x00,0x00,0x00,1);
457 cmd_write(0x60,0x00,0x00,0x00,1);
460 FTprintk("[TSP] Step 4: erase. \n");
464 /*Step 5:write firmware(FW) to ctpm flash*/
466 FTprintk("[TSP] Step 5: start upgrade. \n");
467 dw_lenth = dw_lenth - 8;
468 packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
469 packet_buf[0] = 0xbf;
470 packet_buf[1] = 0x00;
471 FTprintk("[TSP] packet_number = %d\n",packet_number);
472 for (j=0;j<packet_number;j++)
474 temp = j * FTS_PACKET_LENGTH;
475 packet_buf[2] = (u8)(temp>>8);
476 packet_buf[3] = (u8)temp;
477 lenght = FTS_PACKET_LENGTH;
478 packet_buf[4] = (u8)(lenght>>8);
479 packet_buf[5] = (u8)lenght;
481 for (i=0;i<FTS_PACKET_LENGTH;i++)
483 packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
484 bt_ecc ^= packet_buf[6+i];
487 byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
488 mdelay(FTS_PACKET_LENGTH/6 + 1);
489 if ((j * FTS_PACKET_LENGTH % 1024) == 0)
491 FTprintk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
495 if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
497 temp = packet_number * FTS_PACKET_LENGTH;
498 packet_buf[2] = (u8)(temp>>8);
499 packet_buf[3] = (u8)temp;
501 temp = (dw_lenth) % FTS_PACKET_LENGTH;
502 packet_buf[4] = (u8)(temp>>8);
503 packet_buf[5] = (u8)temp;
507 packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
508 bt_ecc ^= packet_buf[6+i];
511 byte_write(&packet_buf[0],temp+6);
515 /***********send the last six byte**********/
516 for (i = 0; i<6; i++)
519 packet_buf[2] = (u8)(temp>>8);
520 packet_buf[3] = (u8)temp;
522 packet_buf[4] = (u8)(temp>>8);
523 packet_buf[5] = (u8)temp;
524 packet_buf[6] = pbt_buf[ dw_lenth + i];
525 bt_ecc ^= packet_buf[6];
527 byte_write(&packet_buf[0],7);
531 /********send the opration head************/
532 cmd_write(0xcc,0x00,0x00,0x00,1);
533 byte_read(reg_val,1);
534 FTprintk("[TSP] Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
535 if(reg_val[0] != bt_ecc)
540 /*******Step 7: reset the new FW**********/
541 cmd_write(0x07,0x00,0x00,0x00,1);
543 fts_register_read(0xfc, buffer, 1);
547 fts_register_write(0xfc, &cmd);
548 mdelay(2500);//2500ms
551 fts_register_read(0xfc, buffer, 1);
553 }while (buffer[0] != 1);
558 int fts_ctpm_auto_clb(void)
560 unsigned char uc_temp;
564 printk("[FTS] start auto CLB.\n");
567 fts_register_write(0x0, ®_val);
570 fts_register_write(0x02, ®_val);
575 fts_register_read(0x0, ®_val, 1);
576 if ( ((reg_val&0x70)>>4) == 0x0) //return to normal mode, calibration finish
581 printk("[FTS] waiting calibration %d\n",i);
584 printk("[FTS] calibration OK.\n");
588 fts_register_write(0x0, ®_val); //goto factory mode
589 mdelay(100); //make sure already enter factory mode
591 fts_register_write(0x2, ®_val); //store CLB result
594 fts_register_write(0x0, ®_val); //return to normal mode
596 printk("[FTS] store CLB result OK.\n");
600 /***********************************************************************/
602 int fts_ctpm_fw_upgrade_with_i_file(void)
608 i_ret = fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
611 printk("[FTS] upgrade failed i_ret = %d.\n", i_ret);
613 fts_ctpm_auto_clb(); //start auto CLB
614 printk("[FTS] upgrade successfully....\n");
620 /***********************************************************************/
622 unsigned char fts_ctpm_get_upg_ver(void)
626 ui_sz = sizeof(CTPM_FW);
629 return CTPM_FW[ui_sz - 2];
639 /***********************************************************************************************
640 Name : ft5x0x_i2c_rxdata
649 ***********************************************************************************************/
650 int ft5x0x_i2c_Read(char * writebuf, int writelen, char *readbuf, int readlen)
656 struct i2c_msg msgs[] = {
658 .addr = g_client->addr,
662 .scl_rate = I2C_SPEED,
665 .addr = g_client->addr,
669 .scl_rate = I2C_SPEED,
672 ret = i2c_transfer(g_client->adapter, msgs, 2);
674 DBG("msg %s i2c read error: %d\n", __func__, ret);
678 struct i2c_msg msgs[] = {
680 .addr = g_client->addr,
684 .scl_rate = I2C_SPEED,
687 ret = i2c_transfer(g_client->adapter, msgs, 1);
689 DBG("msg %s i2c read error: %d\n", __func__, ret);
692 }EXPORT_SYMBOL(ft5x0x_i2c_Read);
693 /***********************************************************************************************
694 Name : ft5x0x_i2c_Write
699 Output :0-write success
701 function : write data by i2c
703 ***********************************************************************************************/
704 int ft5x0x_i2c_Write(char *writebuf, int writelen)
708 struct i2c_msg msg[] = {
710 .addr = g_client->addr,
714 .scl_rate = I2C_SPEED,
718 ret = i2c_transfer(g_client->adapter, msg, 1);
720 DBG("%s i2c write error: %d\n", __func__, ret);
723 }EXPORT_SYMBOL(ft5x0x_i2c_Write);
725 int ft5x0x_rx_data(struct i2c_client *client, char *rxData, int length)
728 char reg = rxData[0];
729 ret = i2c_master_reg8_recv(client, reg, rxData, length, I2C_SPEED);
730 return (ret > 0)? 0 : ret;
733 static int ft5x0x_tx_data(struct i2c_client *client, char *txData, int length)
736 char reg = txData[0];
737 ret = i2c_master_reg8_send(client, reg, &txData[1], length-1, I2C_SPEED);
738 return (ret > 0)? 0 : ret;
741 char ft5x0x_read_reg(struct i2c_client *client, int addr)
747 ret = ft5x0x_rx_data(client, &tmp, 1);
754 int ft5x0x_write_reg(struct i2c_client *client,int addr,int value)
761 ret = ft5x0x_tx_data(client, &buffer[0], 2);
765 static void ft5x0x_power_en(struct ft5x0x_data *tsdata, int on)
767 #if defined (TOUCH_POWER_PIN)
769 gpio_direction_output(tsdata->touch_en_gpio, TOUCH_EN_LEVEL);
770 gpio_set_value(tsdata->touch_en_gpio, TOUCH_EN_LEVEL);
773 gpio_direction_output(tsdata->touch_en_gpio, !TOUCH_EN_LEVEL);
774 gpio_set_value(tsdata->touch_en_gpio, !TOUCH_EN_LEVEL);
778 if( tsdata->reset_gpio <= 0 ){
779 struct regulator *vcc_tp;
780 vcc_tp = regulator_get(NULL, "vaux33"); // vcc28_cif
781 if (vcc_tp == NULL || IS_ERR(vcc_tp) ){
782 printk(">>>> get cif vaux33 ldo failed!\n");
787 regulator_set_voltage(vcc_tp, 3300000, 3300000);
788 regulator_enable(vcc_tp);
789 printk(" %s set vpll vcc28_cif=%dmV end\n", __func__, regulator_get_voltage(vcc_tp));
790 regulator_put(vcc_tp);
792 while(regulator_is_enabled(vcc_tp)>0){
793 regulator_disable(vcc_tp);
795 printk(" %s regulator disable vcc tp \n",__func__);
796 regulator_put(vcc_tp);
803 static void ft5x0x_chip_reset(struct ft5x0x_data *tsdata)
805 gpio_direction_output(tsdata->reset_gpio, 0);
806 gpio_set_value(tsdata->reset_gpio, 1);
808 gpio_set_value(tsdata->reset_gpio, 0);
810 gpio_set_value(tsdata->reset_gpio, 1);
815 static int ft_cmd_write(unsigned char btcmd, unsigned char btPara1, unsigned char btPara2,
816 unsigned char btPara3, int num)
818 unsigned char write_cmd[4] = {0};
820 write_cmd[0] = btcmd;
821 write_cmd[1] = btPara1;
822 write_cmd[2] = btPara2;
823 write_cmd[3] = btPara3;
824 // printk("&write_cmd=0x%08x, &write_cmd[0]=0x%08x\n", &write_cmd, &write_cmd[0]);
825 return i2c_write_interface(write_cmd, num);
829 static int ft5x0x_chip_init(struct i2c_client * client)
837 struct ft5x0x_data *tsdata = i2c_get_clientdata(client);
839 if( tsdata->reset_gpio > 0 ){
840 gpio_free(tsdata->reset_gpio);
841 err = gpio_request(tsdata->reset_gpio, "ft5x0x rst");
843 printk( "failed to request ft5x0x reset GPIO%d\n", tsdata->reset_gpio);
844 goto exit_alloc_gpio_rst_failed;
848 #if defined (TOUCH_POWER_PIN)
849 #if defined (TOUCH_POWER_MUX_NAME)
850 rk29_mux_api_set(TOUCH_POWER_MUX_NAME, TOUCH_POWER_MUX_MODE_GPIO);
852 gpio_free(tsdata->touch_en_gpio);
853 err = gpio_request(tsdata->touch_en_gpio, "ft5x0x power enable");
855 DBG( "failed to request ft5x0x power enable GPIO%d\n", tsdata->touch_en_gpio);
856 goto exit_alloc_gpio_power_failed;
860 ft5x0x_power_en(tsdata, 0);
862 ft5x0x_chip_reset(tsdata);
863 ft5x0x_power_en(tsdata, 1);
865 ft_cmd_write(0x07,0x00,0x00,0x00,1);
872 ret = ft5x0x_write_reg(client, reg, w_value); /* adjust frequency 70Hz */
874 printk(KERN_ERR "ft5x0x i2c txdata failed\n");
878 r_value = ft5x0x_read_reg(client, reg);
880 printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
883 printk("r_value = %d\n, i = %d, flag = %d", r_value, i, flag);
886 if (w_value != r_value) {
889 if (i > 10) { /* test 5 count */
902 ret = ft5x0x_read_reg(client, 0xA8);//read touchpad ID for adjust touchkey place
904 printk(KERN_ERR "ft5x0x i2c rxdata failed\n");
907 printk("ft5406 g_vid = 0x%X\n", ret);
912 #if defined (TOUCH_POWER_PIN)
913 exit_alloc_gpio_power_failed:
914 gpio_free(tsdata->touch_en_gpio);
916 exit_alloc_gpio_rst_failed:
917 gpio_free(tsdata->reset_gpio);
918 printk("%s error\n",__FUNCTION__);
922 static void key_led_ctrl(int on)
925 gpio_set_value(TOUCH_KEY_LED, on);
929 //static int g_screen_key=0;
931 static int ft5x0x_process_points(struct ft5x0x_data *data)
933 struct i2c_client *client = data->client;
937 int status = 0, id, x, y, touch_num;
940 // int back_press = 0, search_press=0, menu_press=0, home_press=0;
946 //printk("ft5406 g_vid = 0x%X\n", g_vid);
947 if (MAX_POINT == 5) {
948 ret = ft5x0x_rx_data(client, buf, 31);
950 ret = ft5x0x_rx_data(client, buf, 62);
954 printk("%s read_data i2c_rxdata failed: %d\n", __func__, ret);
959 if (MAX_POINT == 5) {
960 touch_num = buf[2] & 0x07;
962 touch_num = buf[2] & 0x0f;
965 if (touch_num == 0) {
966 for (i = 0; i < MAX_POINT; i++) {
967 input_mt_slot(data->input_dev, i);
968 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
971 input_sync(data->input_dev);
972 DBG("release all points!!!!!!\n");
977 if (data->last_point_num > touch_num) {
978 touch_num = data->last_point_num;
980 data->last_point_num = points;
983 for (i = 0; i < touch_num; i++) {
984 id = buf[5 + offset] >> 4;
985 status = buf[3 + offset] >> 6;
986 x = (s16)(buf[3 + offset] & 0x0F) << 8 | (s16)buf[4 + offset];
987 y = (s16)(buf[5 + offset] & 0x0F) << 8 | (s16)buf[6 + offset];
989 //p = buf[7 + offset];
990 //w = buf[8 + offset];
994 //printk("%d-%d(%d,%d)%d-%d\n", id, status, x, y, p, w);
995 DBG("TOUCH_NO=%d: ID=%d,(X=%d,Y=%d), status=%d, pressure=%d, w=%d\n", i, id, x, y, status, 0, 0);
997 if (x < (SCREEN_MAX_X + 10)) {
999 input_mt_slot(data->input_dev, id);
1000 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
1002 input_mt_slot(data->input_dev, id);
1003 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true);
1004 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 200);
1005 input_report_abs(data->input_dev, ABS_MT_POSITION_X, x);
1006 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, y);
1012 input_sync(data->input_dev);
1017 static void ft5x0x_delaywork_func(struct work_struct *work)
1019 struct ft5x0x_data *ft5x0x = container_of(work, struct ft5x0x_data, pen_event_work);
1020 struct i2c_client *client = ft5x0x->client;
1022 ft5x0x_process_points(ft5x0x);
1023 enable_irq(client->irq);
1026 static irqreturn_t ft5x0x_interrupt(int irq, void *handle)
1028 struct ft5x0x_data *ft5x0x_ts = handle;
1030 //printk("Enter:%s %d\n",__FUNCTION__,__LINE__);
1031 disable_irq_nosync(irq);
1032 //if (!work_pending(&ft5x0x_ts->pen_event_work)) {
1033 queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
1039 static int ft5x0x_remove(struct i2c_client *client)
1041 struct ft5x0x_data *ft5x0x = i2c_get_clientdata(client);
1043 input_unregister_device(ft5x0x->input_dev);
1044 input_free_device(ft5x0x->input_dev);
1045 free_irq(client->irq, ft5x0x);
1047 #ifdef CONFIG_HAS_EARLYSUSPEND
1048 unregister_early_suspend(&ft5x0x_early_suspend);
1053 #ifdef CONFIG_HAS_EARLYSUSPEND
1054 static void ft5x0x_suspend(struct early_suspend *h)
1059 struct ft5x0x_data *ft5x0x = i2c_get_clientdata(g_client);
1061 printk("==ft5x0x_ts_suspend=\n");
1067 err = ft5x0x_write_reg(g_client, reg, w_value); /* enter sleep mode */
1069 printk("ft5x0x enter sleep mode failed\n");
1072 disable_irq(g_client->irq);
1073 if( ft5x0x->reset_gpio <= 0 ){
1074 ft5x0x_power_en(ft5x0x, 0);
1078 static void ft5x0x_resume(struct early_suspend *h)
1080 struct ft5x0x_data *ft5x0x = i2c_get_clientdata(g_client);
1084 printk("==ft5x0x_ts_resume=\n");
1085 if( ft5x0x->reset_gpio > 0 ){
1086 ft5x0x_chip_reset(ft5x0x);
1088 ft5x0x_power_en(ft5x0x, 1);
1093 enable_irq(g_client->irq);
1096 static int ft5x0x_suspend(struct i2c_client *client, pm_message_t mesg)
1100 static int ft5x0x_resume(struct i2c_client *client)
1106 static const struct i2c_device_id ft5x0x_id[] = {
1111 MODULE_DEVICE_TABLE(i2c, ft5x0x_id);
1113 static struct i2c_driver ft5x0x_driver = {
1115 .name = "ft5x0x_ts",
1117 .id_table = ft5x0x_id,
1118 .probe = ft5x0x_probe,
1119 .remove = __devexit_p(ft5x0x_remove),
1120 #ifndef CONFIG_HAS_EARLYSUSPEND
1121 .suspend = &ft5x0x_suspend,
1122 .resume = &ft5x0x_resume,
1126 static int ft5x0x_client_init(struct i2c_client *client)
1128 struct ft5x0x_data *tsdata = i2c_get_clientdata(client);
1131 DBG("gpio_to_irq(%d) is %d\n", client->irq, gpio_to_irq(client->irq));
1132 if ( !gpio_is_valid(client->irq)) {
1133 DBG("+++++++++++gpio_is_invalid\n");
1137 gpio_free(client->irq);
1138 ret = gpio_request(client->irq, "ft5x0x_int");
1140 DBG( "failed to request ft5x0x GPIO%d\n", gpio_to_irq(client->irq));
1144 ret = gpio_direction_input(client->irq);
1146 DBG("failed to set ft5x0x gpio input\n");
1150 gpio_pull_updown(client->irq, GPIOPullUp);
1151 client->irq = gpio_to_irq(client->irq);
1152 //ft5x0x->irq = client->irq;
1153 ret = request_irq(client->irq, ft5x0x_interrupt, IRQF_TRIGGER_FALLING, client->dev.driver->name, tsdata);
1154 DBG("request irq is %d,ret is 0x%x\n", client->irq, ret);
1156 DBG(KERN_ERR "ft5x0x_client_init: request irq failed,ret is %d\n", ret);
1159 disable_irq(client->irq);
1164 static int ft5x0x_probe(struct i2c_client *client, const struct i2c_device_id *id)
1166 struct ft5x0x_data *ft5x0x_ts;
1167 struct ts_hw_data *pdata = client->dev.platform_data;
1171 unsigned char reg_version;
1173 unsigned char reg_value;
1176 printk("%s enter\n",__FUNCTION__);
1177 ft5x0x_ts = kzalloc(sizeof(struct ft5x0x_data), GFP_KERNEL);
1179 DBG("[ft5x0x]:alloc data failed.\n");
1181 goto exit_alloc_data_failed;
1184 memset(ts_point, 0x0, sizeof(struct ts_event) * MAX_POINT);
1187 ft5x0x_ts->client = client;
1188 ft5x0x_ts->last_point_num = 0;
1189 ft5x0x_ts->reset_gpio = pdata->reset_gpio;
1190 ft5x0x_ts->touch_en_gpio = pdata->touch_en_gpio;
1191 i2c_set_clientdata(client, ft5x0x_ts);
1193 err = ft5x0x_chip_init(client);
1196 "ft5x0x_probe: ft5x0x chip init failed\n");
1197 goto exit_request_gpio_irq_failed;
1200 err = ft5x0x_client_init(client);
1203 "ft5x0x_probe: ft5x0x_client_init failed\n");
1204 goto exit_request_gpio_irq_failed;
1207 ft5x0x_ts->input_dev = input_allocate_device();
1208 if (!ft5x0x_ts->input_dev) {
1211 "ft5x0x_probe: Failed to allocate input device\n");
1212 goto exit_input_allocate_device_failed;
1215 ft5x0x_ts->input_dev->name = "ft5x0x-ts";
1216 ft5x0x_ts->input_dev->dev.parent = &client->dev;
1218 err = input_register_device(ft5x0x_ts->input_dev);
1221 "ft5x0x_probe: Unable to register input device: %s\n",
1222 ft5x0x_ts->input_dev->name);
1223 goto exit_input_register_device_failed;
1226 INIT_WORK(&ft5x0x_ts->pen_event_work, ft5x0x_delaywork_func);
1227 ft5x0x_ts->ts_workqueue = create_singlethread_workqueue("ft5x0x_ts");
1228 if (!ft5x0x_ts->ts_workqueue) {
1230 goto exit_request_gpio_irq_failed;
1234 __set_bit(EV_SYN, ft5x0x_ts->input_dev->evbit);
1235 __set_bit(EV_KEY, ft5x0x_ts->input_dev->evbit);
1236 __set_bit(EV_ABS, ft5x0x_ts->input_dev->evbit);
1237 __set_bit(INPUT_PROP_DIRECT, ft5x0x_ts->input_dev->propbit);
1239 input_mt_init_slots(ft5x0x_ts->input_dev, MAX_POINT);
1240 input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
1241 input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
1242 input_set_abs_params(ft5x0x_ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
1244 /***wait CTP to bootup normally***/
1246 reg_version = FT5X0X_REG_FIRMID;
1247 ft5x0x_rx_data(client, ®_version,1);
1248 printk("------------------cdy == [TSP] firmware tpversion = 0x%2x-------------------------\n", reg_version);
1251 #ifdef TP_UPGRADE //write firmware
1252 fts_register_read(FT5X0X_REG_FIRMID, ®_version,1);
1253 FTprintk("[TSP] firmware version = 0x%2x\n", reg_version);
1254 if (fts_ctpm_get_upg_ver() != reg_version)
1256 FTprintk("[TSP] start upgrade new verison 0x%2x\n", fts_ctpm_get_upg_ver());
1258 err = fts_ctpm_fw_upgrade_with_i_file();
1261 FTprintk("[TSP] ugrade successfuly.\n");
1263 fts_register_read(FT5X0X_REG_FIRMID, ®_value,1);
1264 FTprintk("FTS_DBG from old version 0x%2x to new version = 0x%2x\n", reg_version, reg_value);
1268 FTprintk("[TSP] ugrade fail err=%d, line = %d.\n",err, __LINE__);
1275 #ifdef CONFIG_HAS_EARLYSUSPEND
1276 ft5x0x_early_suspend.suspend = ft5x0x_suspend;
1277 ft5x0x_early_suspend.resume = ft5x0x_resume;
1278 ft5x0x_early_suspend.level = 0x2;
1279 register_early_suspend(&ft5x0x_early_suspend);
1284 enable_irq(client->irq);
1287 exit_input_register_device_failed:
1288 input_free_device(ft5x0x_ts->input_dev);
1289 exit_input_allocate_device_failed:
1290 free_irq(client->irq, ft5x0x_ts);
1291 exit_request_gpio_irq_failed:
1293 #if defined (TOUCH_POWER_PIN)
1294 exit_alloc_gpio_power_failed:
1295 gpio_free(ft5x0x_ts->touch_en_gpio);
1298 exit_alloc_gpio_rst_failed:
1299 gpio_free(ft5x0x_ts->reset_gpio);
1301 exit_alloc_data_failed:
1302 printk("%s error\n",__FUNCTION__);
1306 static void __init ft5x0x_init_async(void *unused, async_cookie_t cookie)
1308 i2c_add_driver(&ft5x0x_driver);
1311 static int __init ft5x0x_mod_init(void)
1313 printk("ft5x0x module init\n");
1314 async_schedule(ft5x0x_init_async, NULL);
1318 static void __exit ft5x0x_mod_exit(void)
1320 i2c_del_driver(&ft5x0x_driver);
1323 module_init(ft5x0x_mod_init);
1324 module_exit(ft5x0x_mod_exit);
1326 MODULE_DESCRIPTION("ft5406 touch driver");
1327 MODULE_AUTHOR("zqqu<zqqu@yifangdigital.com>");
1328 MODULE_LICENSE("GPL");