2 * drivers/input/touchscreen/ft5x0x_ts.c
4 * FocalTech ft5x0x TouchScreen driver.
6 * Copyright (c) 2010 Focal tech Ltd.
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 * note: only support mulititouch Wenfs 2010-10-01
21 #include <linux/irq.h>
22 #include <asm/mach/irq.h>
23 #include <linux/slab.h>
24 #include <linux/i2c.h>
25 #include <linux/input.h>
26 //#include "ft5x0x_i2c_ts.h"
27 #include "ft5506_wgj.h"
28 #include <linux/interrupt.h>
29 #include <linux/delay.h>
30 #include <linux/platform_device.h>
31 #include <linux/async.h>
32 #include <mach/gpio.h>
33 #include <mach/board.h>
34 #include <linux/earlysuspend.h>
35 #include <linux/input/mt.h>
38 //#include "ft5x06_ex_fun.h"
41 TOUCH_UP = 0, TOUCH_DOWN = 1,
43 #define TOUCH_NUMBER 10
45 static int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
48 struct FTS_TS_DATA_T {
49 struct i2c_client *client;
50 struct input_dev *input_dev;
51 struct FTS_TS_EVENT_T event;
52 struct work_struct pen_event_work;
53 struct workqueue_struct *ts_workqueue;
54 struct early_suspend early_suspend;
57 /* -------------- global variable definition -----------*/
58 static struct i2c_client *this_client;
59 static REPORT_FINGER_INFO_T _st_finger_infos[CFG_MAX_POINT_NUM];
60 //static unsigned int _sui_irq_num= IRQ_EINT(6);
61 static int _si_touch_num = 0;
65 int tsp_keycodes[CFG_NUMOFKEYS] ={
73 char *tsp_keyname[CFG_NUMOFKEYS] ={
81 static bool tsp_keystatus[CFG_NUMOFKEYS];
84 #ifdef CONFIG_HAS_EARLYSUSPEND
85 static void ft5x0x_ts_early_suspend(struct early_suspend *h);
86 static void ft5x0x_ts_late_resume(struct early_suspend *h);
90 /***********************************************************************
92 callback: read data from ctpm by i2c interface;
94 buffer[in]: data buffer;
95 length[in]: the length of the data buffer;
99 ************************************************************************/
100 static bool i2c_read_interface(u8* pbt_buf, int dw_lenth)
104 ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);
108 printk("[TSP]i2c_read_interface error\n");
117 /***********************************************************************
119 callback: write data to ctpm by i2c interface;
121 buffer[in]: data buffer;
122 length[in]: the length of the data buffer;
126 ************************************************************************/
127 static bool i2c_write_interface(u8* pbt_buf, int dw_lenth)
130 ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
133 printk("[TSP]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
142 /***********************************************************************
144 callback: read register value ftom ctpm by i2c interface;
146 reg_name[in]: the register which you want to read;
147 rx_buf[in]: data buffer which is used to store register value;
148 rx_length[in]: the length of the data buffer;
152 ************************************************************************/
153 static bool fts_register_read(u8 reg_name, u8* rx_buf, int rx_length)
158 read_cmd[0] = reg_name;
161 /*send register addr*/
162 if(!i2c_write_interface(&read_cmd[0], cmd_len))
167 /*call the read callback function to get the register value*/
168 if(!i2c_read_interface(rx_buf, rx_length))
178 /***********************************************************************
180 callback: read register value ftom ctpm by i2c interface;
182 reg_name[in]: the register which you want to write;
183 tx_buf[in]: buffer which is contained of the writing value;
187 ************************************************************************/
188 static bool fts_register_write(u8 reg_name, u8* tx_buf)
190 u8 write_cmd[2] = {0};
192 write_cmd[0] = reg_name;
193 write_cmd[1] = *tx_buf;
195 /*call the write callback function*/
196 return i2c_write_interface(write_cmd, 2);
202 /***********************************************************************
204 callback: report to the input system that the finger is put up;
209 ************************************************************************/
210 static void fts_ts_release(void)
212 struct FTS_TS_DATA_T *data = i2c_get_clientdata(this_client);
215 for ( i= 0; i<CFG_MAX_POINT_NUM; ++i )
217 if ( _st_finger_infos[i].u2_pressure == -1 )
220 input_mt_slot(data->input_dev, i);
221 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
224 input_report_abs(data->input_dev, ABS_MT_POSITION_X, _st_finger_infos[i].i2_x);
225 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, _st_finger_infos[i].i2_y);
226 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, _st_finger_infos[i].u2_pressure);
227 input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, _st_finger_infos[i].ui2_id);
228 input_mt_sync(data->input_dev);
232 if ( _st_finger_infos[i].u2_pressure == 0 )
233 _st_finger_infos[i].u2_pressure= -1;
238 printk("+++++++enter fts_ts_release++++++++\n");
239 input_sync(data->input_dev);
250 /***********************************************************************
252 callback: read touch data ftom ctpm by i2c interface;
254 rxdata[in]: data buffer which is used to store touch data;
255 length[in]: the length of the data buffer;
259 ************************************************************************/
260 static int fts_i2c_rxdata(u8 *rxdata, int length)
266 msg.addr = this_client->addr;
270 msg.scl_rate = FT5X0X_I2C_SPEED;
272 ret = i2c_transfer(this_client->adapter, &msg, 1);
275 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
278 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
282 msg.addr = this_client->addr;
283 msg.flags = I2C_M_RD;
286 msg.scl_rate = FT5X0X_I2C_SPEED;
287 ret = i2c_transfer(this_client->adapter, &msg, 1);
290 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
293 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
304 /***********************************************************************
306 callback: send data to ctpm by i2c interface;
308 txdata[in]: data buffer which is used to send data;
309 length[in]: the length of the data buffer;
313 ************************************************************************/
314 static int fts_i2c_txdata(u8 *txdata, int length)
320 msg.addr = this_client->addr;
324 msg.scl_rate = FT5X0X_I2C_SPEED;
326 ret = i2c_transfer(this_client->adapter, &msg, 1);
329 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
332 pr_err("msg %s line:%d i2c write error: %d\n", __func__, __LINE__,ret);
340 static int ft5x0x_set_reg(u8 addr, u8 para)
346 ret = fts_i2c_txdata(buf, 2);
348 pr_err("write reg failed! %#x ret: %d", buf[0], ret);
355 /***********************************************************************
357 callback: gather the finger information and calculate the X,Y
358 coordinate then report them to the input system;
363 ************************************************************************/
364 int fts_read_data(void)
366 struct FTS_TS_DATA_T *data = i2c_get_clientdata(this_client);
368 // static int key_id=0x80;
370 int id,i_count,ret = -1;
371 int touch_point_num = 0, touch_event, x, y;
372 int tmp, swap ,sync_flag = 0;
375 ret = fts_i2c_rxdata(buf, 1);
377 touch_point_num = buf[0]&0xf;
379 printk(KERN_ERR "get fingers failed!\n");
381 touch_point_num = 10;
383 if(touch_point_num > CFG_MAX_POINT_NUM)
384 printk("[Warning],+++++Touch number[%d] readed is larger than max point number+++++++++++++\n",touch_point_num);
388 if(touch_point_num != 0)
391 ret=fts_i2c_rxdata(buf, 6*touch_point_num);
396 id = buf[2+i_count*6]>>4;
397 // printk("Touch ID readed is id=%d\n",id);
398 // if(id <0 || id>CFG_MAX_POINT_NUM)
399 // printk("[ERROR] Touch ID readed is illegal!! id=%d\n",id);
401 touch_event = buf[i_count*6]>>6;
402 x =((buf[i_count*6]& 0x0f)<<8) |buf[i_count*6+1];
403 y =( (buf[i_count*6+2]& 0x0f)<<8) | buf[i_count*6+3];
416 if (touch_event == 0) //down
418 _st_finger_infos[i_count].u2_pressure= 1;//pressure;
419 _st_finger_infos[i_count].i2_x= (int16_t)x;
420 _st_finger_infos[i_count].i2_y= (int16_t)y;
422 else if (touch_event == 1) //up event
424 _st_finger_infos[i_count].u2_pressure= 0;
426 else if (touch_event == 2) //move
428 _st_finger_infos[i_count].u2_pressure= 1;//pressure;
429 _st_finger_infos[i_count].i2_x= (int16_t)x;
430 _st_finger_infos[i_count].i2_y= (int16_t)y;
432 else /*bad event, ignore*/
434 //printk("Bad event, ignore!!!\n");
439 if(_st_finger_infos[i_count].u2_pressure == 1)//down
441 input_mt_slot(data->input_dev, id);
442 input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, id);
443 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true);
444 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 1);
445 input_report_abs(data->input_dev, ABS_MT_POSITION_X, _st_finger_infos[i_count].i2_x);
446 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, _st_finger_infos[i_count].i2_y);
447 // printk("ABS_MT_POSITION_X == %d, ABS_MT_POSITION_Y == %d\n",_st_finger_infos[i_count].i2_x,_st_finger_infos[i_count].i2_y);
452 else if((_st_finger_infos[i_count].u2_pressure == 0)||(touch_event == 1))//up
454 input_mt_slot(data->input_dev, id);
455 input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, -1);
456 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
457 // input_sync(data->input_dev);
462 if(_st_finger_infos[i_count].u2_pressure == 0 )
464 _st_finger_infos[i_count].u2_pressure= -1;
466 // input_sync(data->input_dev);
470 }while(i_count < touch_point_num);
473 input_sync(data->input_dev);
474 // input_mt_sync(data->input_dev);
479 printk("[LAIBAO] ERROR: in %s, line %d, ret = %d\n",
480 __FUNCTION__, __LINE__, ret);
484 //If touch number is zero then release touch.
485 if(touch_point_num == 0 )
495 static void fts_work_func(struct work_struct *work)
497 //disable_irq(this_client->irq);
499 enable_irq(this_client->irq);
505 static irqreturn_t fts_ts_irq(int irq, void *dev_id)
507 struct FTS_TS_DATA_T *ft5x0x_ts = dev_id;
508 // printk(KERN_ALERT "fts_tp_irq\n");
509 if (!work_pending(&ft5x0x_ts->pen_event_work)) {
510 disable_irq_nosync(this_client->irq);
511 queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
519 /***********************************************************************
521 callback: send a command to ctpm.
523 btcmd[in]: command code;
524 btPara1[in]: parameter 1;
525 btPara2[in]: parameter 2;
526 btPara3[in]: parameter 3;
527 num[in]: the valid input parameter numbers,
528 if only command code needed and no
529 parameters followed,then the num is 1;
533 ************************************************************************/
534 static bool cmd_write(u8 btcmd,u8 btPara1,u8 btPara2,u8 btPara3,u8 num)
536 u8 write_cmd[4] = {0};
538 write_cmd[0] = btcmd;
539 write_cmd[1] = btPara1;
540 write_cmd[2] = btPara2;
541 write_cmd[3] = btPara3;
542 return i2c_write_interface(write_cmd, num);
548 /***********************************************************************
550 callback: write a byte data to ctpm;
552 buffer[in]: write buffer;
553 length[in]: the size of write data;
557 ************************************************************************/
558 static bool byte_write(u8* buffer, int length)
561 return i2c_write_interface(buffer, length);
567 /***********************************************************************
569 callback: read a byte data from ctpm;
571 buffer[in]: read buffer;
572 length[in]: the size of read data;
576 ************************************************************************/
577 static bool byte_read(u8* buffer, int length)
579 return i2c_read_interface(buffer, length);
586 #define FTS_PACKET_LENGTH 128
588 static unsigned char CTPM_FW[]=
590 //#include "ft_app.i"
591 #include "ft5506_app.f"
597 /***********************************************************************
599 callback: burn the FW to ctpm.
601 pbt_buf[in]: point to Head+FW ;
602 dw_lenth[in]: the length of the FW + 6(the Head length);
605 ERR_MODE: fail to switch to UPDATE mode;
606 ERR_READID: read id fail;
607 ERR_ERASE: erase chip fail;
608 ERR_STATUS: status error;
610 ************************************************************************/
611 E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(u8* pbt_buf, int dw_lenth)
613 u8 cmd,reg_val[2] = {0};
614 u8 packet_buf[FTS_PACKET_LENGTH + 6];
615 u8 auc_i2c_write_buf[10];
618 int j,temp,lenght,i_ret,packet_number, i = 0;
619 int i_is_new_protocol = 0;
622 /******write 0xaa to register 0xfc******/
624 fts_register_write(0xfc,&cmd);
627 /******write 0x55 to register 0xfc******/
629 fts_register_write(0xfc,&cmd);
630 printk("[TSP] Step 1: Reset CTPM test\n");
635 /*******Step 2:Enter upgrade mode ****/
636 printk("\n[TSP] Step 2:enter new update mode\n");
637 auc_i2c_write_buf[0] = 0x55;
638 auc_i2c_write_buf[1] = 0xaa;
642 i_ret = fts_i2c_txdata(auc_i2c_write_buf, 2);
644 }while(i_ret <= 0 && i < 10 );
648 i_is_new_protocol = 1;
652 /********Step 3:check READ-ID********/
653 cmd_write(0x90,0x00,0x00,0x00,4);
655 byte_read(reg_val,2);
657 printk("=============CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
659 //if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
660 if (reg_val[0] == 0x79 && reg_val[1] == 0x6)
662 printk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
667 //i_is_new_protocol = 1;
671 /*********Step 4:erase app**********/
672 if (i_is_new_protocol)
674 cmd_write(0x61,0x00,0x00,0x00,1);
678 cmd_write(0x60,0x00,0x00,0x00,1);
681 printk("[TSP] Step 4: erase. \n");
685 /*Step 5:write firmware(FW) to ctpm flash*/
687 printk("[TSP] Step 5: start upgrade. \n");
688 dw_lenth = dw_lenth - 8;
689 packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
690 packet_buf[0] = 0xbf;
691 packet_buf[1] = 0x00;
692 for (j=0;j<packet_number;j++)
694 temp = j * FTS_PACKET_LENGTH;
695 packet_buf[2] = (FTS_BYTE)(temp>>8);
696 packet_buf[3] = (FTS_BYTE)temp;
697 lenght = FTS_PACKET_LENGTH;
698 packet_buf[4] = (FTS_BYTE)(lenght>>8);
699 packet_buf[5] = (FTS_BYTE)lenght;
701 for (i=0;i<FTS_PACKET_LENGTH;i++)
703 packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
704 bt_ecc ^= packet_buf[6+i];
707 byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
708 mdelay(FTS_PACKET_LENGTH/6 + 1);
709 if ((j * FTS_PACKET_LENGTH % 1024) == 0)
711 printk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
715 if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
717 temp = packet_number * FTS_PACKET_LENGTH;
718 packet_buf[2] = (FTS_BYTE)(temp>>8);
719 packet_buf[3] = (FTS_BYTE)temp;
721 temp = (dw_lenth) % FTS_PACKET_LENGTH;
722 packet_buf[4] = (FTS_BYTE)(temp>>8);
723 packet_buf[5] = (FTS_BYTE)temp;
727 packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
728 bt_ecc ^= packet_buf[6+i];
731 byte_write(&packet_buf[0],temp+6);
735 /***********send the last six byte**********/
736 for (i = 0; i<6; i++)
739 packet_buf[2] = (FTS_BYTE)(temp>>8);
740 packet_buf[3] = (FTS_BYTE)temp;
742 packet_buf[4] = (FTS_BYTE)(temp>>8);
743 packet_buf[5] = (FTS_BYTE)temp;
744 packet_buf[6] = pbt_buf[ dw_lenth + i];
745 bt_ecc ^= packet_buf[6];
747 byte_write(&packet_buf[0],7);
751 /********send the opration head************/
752 cmd_write(0xcc,0x00,0x00,0x00,1);
753 byte_read(reg_val,1);
754 printk("[TSP] Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
755 if(reg_val[0] != bt_ecc)
760 /*******Step 7: reset the new FW**********/
761 cmd_write(0x07,0x00,0x00,0x00,1);
769 int fts_ctpm_fw_upgrade_with_i_file(void)
771 u8* pbt_buf = FTS_NULL;
775 i_ret = fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
780 unsigned char fts_ctpm_get_upg_ver(void)
784 ui_sz = sizeof(CTPM_FW);
787 return CTPM_FW[ui_sz - 2];
794 void ft5x0x_ts_set_standby(struct i2c_client *client, int enable)
797 struct laibao_platform_data *mach_info = client->dev.platform_data;
798 unsigned pwr_pin = mach_info->pwr_pin;
799 unsigned pwr_on_value = mach_info->pwr_on_value;
800 unsigned reset_pin = mach_info->reset_pin;
801 unsigned reset_value = mach_info->reset_value;
803 printk("%s : %s, enable = %d\n", __FILE__, __FUNCTION__,enable);
804 if(pwr_pin != INVALID_GPIO)
806 gpio_direction_output(pwr_pin, 0);
807 gpio_set_value(pwr_pin, enable ? pwr_on_value : !pwr_on_value);
809 if(reset_pin != INVALID_GPIO)
811 gpio_direction_output(reset_pin, enable ? reset_value : !reset_value);
812 gpio_set_value(reset_pin, enable ? reset_value : !reset_value);
816 #ifdef CONFIG_HAS_EARLYSUSPEND
818 static void ft5x0x_ts_early_suspend(struct early_suspend *h)
821 struct FTS_TS_DATA_T *data = i2c_get_clientdata(this_client);
822 printk("enter ft5x0x_ts_early_suspend\n");
824 disable_irq_nosync(this_client->irq);
825 ret = cancel_work_sync(&data->pen_event_work);
826 if (ret && this_client->irq) // if work was pending disable-count is now 2
827 enable_irq(this_client->irq);
828 // ft5x0x_set_reg(FT5X0X_REG_PMODE, PMODE_HIBERNATE);
829 // disable_irq(this_client->irq);
830 // ft5x0x_ts_set_standby(this_client,0);
835 static void ft5x0x_ts_early_suspend(struct early_suspend *handler)
838 struct ft5x0x_ts_dev *ts;
839 ts = container_of(handler, struct ft5x0x_ts_dev, early_suspend);
842 disable_irq_nosync(ts->irq);
843 ret = cancel_work_sync(&ts->pen_event_work);
844 if (ret && ts->irq) // if work was pending disable-count is now 2
847 ft5x0x_set_reg(FT5X0X_REG_PMODE, PMODE_HIBERNATE);
851 static void ft5x0x_ts_late_resume(struct early_suspend *h)
853 struct FTS_TS_DATA_T *data = i2c_get_clientdata(this_client);
854 //ft5x0x_ts_set_standby(this_client,1);
855 input_sync(data->input_dev);
857 gpio_direction_output(RK30_PIN4_PD0, 0);
859 gpio_set_value(RK30_PIN4_PD0,GPIO_HIGH);
862 enable_irq(this_client->irq);
863 printk("ft5x0x_ts_late_resume finish\n");
868 static void ft5x0x_ts_resume(struct early_suspend *handler)
870 struct ft5x0x_ts_dev *ts;
871 ts = container_of(handler, struct ft5x0x_ts_dev, early_suspend);
872 struct ts_event *event = &ts->event;
877 input_mt_slot(ts->input_dev, i);
878 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
880 input_sync(ts->input_dev);
881 event->point[i].status == 0;
883 gpio_direction_output(RK29_PIN6_PC3, 0);
884 // gpio_set_value(RK29_PIN6_PC3,GPIO_LOW);
886 gpio_set_value(RK29_PIN6_PC3,GPIO_HIGH);
898 #define ft5x0x_ts_early_suspend NULL
899 #define ft5x0x_ts_late_resume NULL
903 static int fts_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
905 struct FTS_TS_DATA_T *ft5x0x_ts;
906 struct input_dev *input_dev;
909 unsigned char reg_value;
910 unsigned char reg_version;
913 struct ft5506_platform_data *pdata = client->dev.platform_data;
915 printk("[LAIBAO] file(%s), function (%s), --probe start\n", __FILE__, __FUNCTION__);
917 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
919 goto exit_check_functionality_failed;
922 if (pdata->init_platform_hw) {
923 err = pdata->init_platform_hw();
925 printk("[LAIBAO] init_platform_hw failed\n");
926 goto exit_init_platform_hw_failed;
932 this_client = client;
933 err = i2c_master_reg8_recv(this_client, FT5X0X_REG_FIRMID, ®_version, 1, 200*1000);
935 printk("[LAIBAO] Device not found\n");
936 goto exit_device_not_found;
939 client->irq = gpio_to_irq(client->irq);
940 _sui_irq_num = client->irq;
942 ft5x0x_ts = kzalloc(sizeof(*ft5x0x_ts), GFP_KERNEL);
945 goto exit_alloc_data_failed;
948 //this_client = client;
949 ft5x0x_ts->client = client;
950 i2c_set_clientdata(client, ft5x0x_ts);
952 INIT_WORK(&ft5x0x_ts->pen_event_work, fts_work_func);
954 ft5x0x_ts->ts_workqueue = create_singlethread_workqueue(dev_name(&client->dev));
955 if (!ft5x0x_ts->ts_workqueue) {
957 goto exit_create_singlethread;
960 /***wait CTP to bootup normally***/
963 //fts_register_read(FT5X0X_REG_FIRMID, ®_version,1);
964 i2c_master_reg8_recv(this_client, FT5X0X_REG_FIRMID, ®_version, 1, 200*1000);
965 printk("[LAIBAO] firmware version = 0x%2x\n", reg_version);
966 //fts_register_read(FT5X0X_REG_REPORT_RATE, ®_value,1);
967 i2c_master_reg8_recv(this_client, FT5X0X_REG_REPORT_RATE, ®_value, 1, 200*1000);
968 printk("[LAIBAO] firmware report rate = %dHz\n", reg_value*10);
969 //fts_register_read(FT5X0X_REG_THRES, ®_value,1);
970 i2c_master_reg8_recv(this_client, FT5X0X_REG_THRES, ®_value, 1, 200*1000);
971 printk("[LAIBAO] firmware threshold = %d\n", reg_value * 4);
972 //fts_register_read(FT5X0X_REG_NOISE_MODE, ®_value,1);
973 i2c_master_reg8_recv(this_client, FT5X0X_REG_NOISE_MODE, ®_value, 1, 200*1000);
974 printk("[LAIBAO] nosie mode = 0x%2x\n", reg_value);
977 if (fts_ctpm_get_upg_ver() != reg_version)
979 printk("[LAIBAO] start upgrade new verison 0x%2x\n", fts_ctpm_get_upg_ver());
981 err = fts_ctpm_fw_upgrade_with_i_file();
984 printk("[LAIBAO] ugrade successfuly.\n");
986 fts_register_read(FT5X0X_REG_FIRMID, ®_value,1);
987 printk("FTS_DBG from old version 0x%2x to new version = 0x%2x\n", reg_version, reg_value);
991 printk("[LAIBAO] ugrade fail err=%d, line = %d.\n",
1003 printk("[LAIBAO]=========================_sui_irq_num = %d ================\n",_sui_irq_num);
1004 printk("[LAIBAO]=========================client->dev.driver->name = %s ================\n",client->dev.driver->name);
1005 err = request_irq(_sui_irq_num, fts_ts_irq, GPIOEdgelFalling, client->dev.driver->name, ft5x0x_ts);
1008 dev_err(&client->dev, "[LAIBAO] ft5x0x_probe: request irq failed\n");
1009 printk("[LAIBAO]=========================err = %d ================\n",err);
1010 goto exit_irq_request_failed;
1012 disable_irq(_sui_irq_num);
1015 input_dev = input_allocate_device();
1018 dev_err(&client->dev, "[LAIBAO]failed to allocate input device\n");
1019 goto exit_input_dev_alloc_failed;
1022 ft5x0x_ts->input_dev = input_dev;
1024 /***setup coordinate area******/
1025 //set_bit(EV_ABS, input_dev->evbit);
1026 //set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit);
1027 //set_bit(ABS_MT_POSITION_X, input_dev->absbit);
1028 //set_bit(ABS_MT_POSITION_Y, input_dev->absbit);
1029 //set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit);
1031 // input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
1033 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
1034 __set_bit(EV_ABS, input_dev->evbit);
1036 /****** for multi-touch *******/
1037 for (i=0; i<CFG_MAX_POINT_NUM; i++)
1038 _st_finger_infos[i].u2_pressure = -1;
1040 input_set_abs_params(input_dev,
1041 ABS_MT_POSITION_X, 0, SCREEN_MAX_X + SCREEN_BOUNDARY_ADJUST_VALUE, 0, 0);
1042 input_set_abs_params(input_dev,
1043 ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y + SCREEN_BOUNDARY_ADJUST_VALUE, 0, 0);
1044 // input_set_abs_params(input_dev,
1045 // ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
1046 //input_set_abs_params(input_dev,
1047 // ABS_MT_TRACKING_ID, 0, 30, 0, 0);
1048 // input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
1050 // input_set_abs_params(input_dev,
1051 // ABS_MT_TRACKING_ID, 0, CFG_MAX_POINT_NUM, 0, 0);
1054 input_mt_init_slots(input_dev, CFG_MAX_POINT_NUM);
1055 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
1057 /*****setup key code area******/
1058 //set_bit(EV_SYN, input_dev->evbit);
1059 //set_bit(EV_KEY, input_dev->evbit);
1060 //set_bit(BTN_TOUCH, input_dev->keybit);
1061 //input_dev->keycode = tsp_keycodes;
1062 //for(i = 0; i < CFG_NUMOFKEYS; i++)
1064 // input_set_capability(input_dev, EV_KEY, ((int*)input_dev->keycode)[i]);
1065 // tsp_keystatus[i] = KEY_RELEASE;
1068 input_dev->name = FT5X0X_NAME;
1069 input_dev->id.bustype = BUS_I2C;
1070 input_dev->id.vendor = 0xdead;
1071 input_dev->id.product = 0xbeef;
1072 input_dev->id.version = 10427;
1074 err = input_register_device(input_dev);
1076 dev_err(&client->dev,
1077 "fts_ts_probe: failed to register input device: %s\n",
1078 dev_name(&client->dev));
1079 goto exit_input_register_device_failed;
1083 #ifdef CONFIG_HAS_EARLYSUSPEND
1084 ft5x0x_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;
1085 ft5x0x_ts->early_suspend.suspend = ft5x0x_ts_early_suspend;
1086 ft5x0x_ts->early_suspend.resume = ft5x0x_ts_late_resume;
1087 register_early_suspend(&ft5x0x_ts->early_suspend);
1091 enable_irq(_sui_irq_num);
1092 printk("[LAIBAO] file(%s), function (%s), -- end\n", __FILE__, __FUNCTION__);
1095 exit_input_register_device_failed:
1096 input_free_device(input_dev);
1097 exit_input_dev_alloc_failed:
1098 free_irq(_sui_irq_num, ft5x0x_ts);
1099 exit_irq_request_failed:
1100 cancel_work_sync(&ft5x0x_ts->pen_event_work);
1101 destroy_workqueue(ft5x0x_ts->ts_workqueue);
1102 exit_create_singlethread:
1103 i2c_set_clientdata(client, NULL);
1105 exit_alloc_data_failed:
1106 exit_device_not_found:
1107 //if (pdata->exit_platform_hw)
1108 // pdata->exit_platform_hw();
1110 exit_init_platform_hw_failed:
1111 exit_check_functionality_failed:
1117 static int __devexit fts_ts_remove(struct i2c_client *client)
1119 struct FTS_TS_DATA_T *ft5x0x_ts;
1120 int _sui_irq_num=client->irq;
1122 ft5x0x_ts = (struct FTS_TS_DATA_T *)i2c_get_clientdata(client);
1123 free_irq(_sui_irq_num, ft5x0x_ts);
1124 input_unregister_device(ft5x0x_ts->input_dev);
1126 cancel_work_sync(&ft5x0x_ts->pen_event_work);
1127 destroy_workqueue(ft5x0x_ts->ts_workqueue);
1128 i2c_set_clientdata(client, NULL);
1133 static const struct i2c_device_id ft5x0x_ts_id[] = {
1139 MODULE_DEVICE_TABLE(i2c, ft5x0x_ts_id);
1141 static struct i2c_driver fts_ts_driver = {
1142 .probe = fts_ts_probe,
1143 .remove = fts_ts_remove,//devexit_p(fts_ts_remove),
1144 .id_table = ft5x0x_ts_id,
1146 .name = FT5X0X_NAME,
1150 static void __init fts_ts_initasync(void *unused, async_cookie_t cookie)
1152 i2c_add_driver(&fts_ts_driver);
1155 static int __init fts_ts_init(void)
1157 async_schedule(fts_ts_initasync, NULL);
1161 static void __exit fts_ts_exit(void)
1163 i2c_del_driver(&fts_ts_driver);
1166 module_init(fts_ts_init);
1167 module_exit(fts_ts_exit);
1169 MODULE_AUTHOR("<duxx@Focaltech-systems.com>");
1170 MODULE_DESCRIPTION("FocalTech ft5x0x TouchScreen driver");
1171 MODULE_LICENSE("GPL");