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/input.h>
22 #include <linux/input/mt.h>
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/kernel.h>
27 #include <linux/platform_device.h>
28 #include <linux/spi/spi.h>
29 #include <linux/slab.h>
30 #include <linux/fcntl.h>
31 #include <linux/delay.h>
32 #include <linux/device.h>
33 #include <linux/timer.h>
34 #include <linux/jiffies.h>
35 #include <linux/miscdevice.h>
36 #include <linux/types.h>
38 #include <linux/delay.h>
39 #include <linux/ioport.h>
40 #include <linux/input-polldev.h>
41 #include <linux/i2c.h>
42 #include <linux/workqueue.h>
43 #ifdef CONFIG_ANDROID_POWER
44 #include <linux/android_power.h>
46 #include <mach/hardware.h>
47 #include <asm/setup.h>
48 #include <asm/mach-types.h>
49 #include <asm/mach/arch.h>
50 #include <asm/mach/map.h>
51 #include <asm/mach/flash.h>
52 #include <asm/hardware/gic.h>
53 #include <mach/iomux.h>
54 #include <mach/gpio.h>
55 #include <mach/irqs.h>
56 //#include <mach/rk29_iomap.h>
57 #include <mach/board.h>
58 //#include <mach/rk29_nand.h>
59 //#include <mach/rk29_camera.h> /* ddl@rock-chips.com : camera support */
60 #include <media/soc_camera.h> /* ddl@rock-chips.com : camera support */
61 //#include <mach/vpu_mem.h>
62 #include <mach/sram.h>
63 #include <linux/earlysuspend.h>
64 static struct early_suspend ft5306_power;
69 #define CONFIG_FT5X0X_MULTITOUCH 1
71 #define FT5306_IIC_SPEED 50*1000 //300*1000
72 #define FT5X0X_REG_THRES 0x80 /* Thresshold, the threshold be low, the sensitivy will be high */
73 #define FT5X0X_REG_REPORT_RATE 0x88 /* **************report rate, in unit of 10Hz **************/
74 #define FT5X0X_REG_PMODE 0xA5 /* Power Consume Mode 0 -- active, 1 -- monitor, 3 -- sleep */
75 #define FT5X0X_REG_FIRMID 0xA6 /* ***************firmware version **********************/
76 #define FT5X0X_REG_NOISE_MODE 0xb2 /* to enable or disable power noise, 1 -- enable, 0 -- disable */
77 #define SCREEN_MAX_X 800
78 #define SCREEN_MAX_Y 480
79 #define FT5X0X_SWAP_XY 0
81 #define FT5X0X_NAME "ft5x0x_ts"//"synaptics_i2c_rmi"//"synaptics-rmi-ts"//
82 #define TOUCH_MAJOR_MAX 200
83 #define WIDTH_MAJOR_MAX 200
85 #define PMODE_ACTIVE 0x00
86 #define PMODE_MONITOR 0x01
87 #define PMODE_STANDBY 0x02
88 #define PMODE_HIBERNATE 0x03
92 s16 cur_touch_id[MAX_POINT];
93 s16 last_touch_id[MAX_POINT];
105 struct ft5x0x_ts_data {
106 struct i2c_client *client;
107 struct input_dev *input_dev;
109 struct ts_event event;
110 struct work_struct pen_event_work;
111 struct workqueue_struct *ts_workqueue;
113 static struct i2c_client *this_client;
115 /***********************************************************************/
117 #define FTS_PACKET_LENGTH 128
122 //#include "ft5406_app.i"
138 /***********************************************************************/
140 /***********************************************************************
142 callback: send data to ctpm by i2c interface;
144 txdata[in]: data buffer which is used to send data;
145 length[in]: the length of the data buffer;
149 ************************************************************************/
150 static int fts_i2c_txdata(u8 *txdata, int length)
156 msg.addr = this_client->addr;
160 msg.scl_rate = FT5306_IIC_SPEED;
162 ret = i2c_transfer(this_client->adapter, &msg, 1);
164 pr_err("%s i2c write error: %d\n", __func__, ret);
169 /***********************************************************************
171 callback: write data to ctpm by i2c interface;
173 buffer[in]: data buffer;
174 length[in]: the length of the data buffer;
178 ************************************************************************/
179 static bool i2c_write_interface(u8* pbt_buf, int dw_lenth)
182 ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
185 printk("[TSP]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
192 /***********************************************************************
194 callback: read register value ftom ctpm by i2c interface;
196 reg_name[in]: the register which you want to write;
197 tx_buf[in]: buffer which is contained of the writing value;
201 ************************************************************************/
202 static bool fts_register_write(u8 reg_name, u8* tx_buf)
204 u8 write_cmd[2] = {0};
206 write_cmd[0] = reg_name;
207 write_cmd[1] = *tx_buf;
209 /*call the write callback function*/
210 return i2c_write_interface(write_cmd, 2);
213 /***********************************************************************
215 callback: send a command to ctpm.
217 btcmd[in]: command code;
218 btPara1[in]: parameter 1;
219 btPara2[in]: parameter 2;
220 btPara3[in]: parameter 3;
221 num[in]: the valid input parameter numbers,
222 if only command code needed and no
223 parameters followed,then the num is 1;
227 ************************************************************************/
228 static bool cmd_write(u8 btcmd,u8 btPara1,u8 btPara2,u8 btPara3,u8 num)
230 u8 write_cmd[4] = {0};
232 write_cmd[0] = btcmd;
233 write_cmd[1] = btPara1;
234 write_cmd[2] = btPara2;
235 write_cmd[3] = btPara3;
236 return i2c_write_interface(write_cmd, num);
239 /***********************************************************************
241 callback: read data from ctpm by i2c interface;
243 buffer[in]: data buffer;
244 length[in]: the length of the data buffer;
248 ************************************************************************/
249 static bool i2c_read_interface(u8* pbt_buf, int dw_lenth)
253 ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);
257 printk("[TSP]i2c_read_interface error\n");
265 /***********************************************************************
267 callback: read a byte data from ctpm;
269 buffer[in]: read buffer;
270 length[in]: the size of read data;
274 ************************************************************************/
275 static bool byte_read(u8* buffer, int length)
277 return i2c_read_interface(buffer, length);
280 /***********************************************************************
282 callback: write a byte data to ctpm;
284 buffer[in]: write buffer;
285 length[in]: the size of write data;
289 ************************************************************************/
290 static bool byte_write(u8* buffer, int length)
293 return i2c_write_interface(buffer, length);
296 /***********************************************************************
298 callback: read register value ftom ctpm by i2c interface;
300 reg_name[in]: the register which you want to read;
301 rx_buf[in]: data buffer which is used to store register value;
302 rx_length[in]: the length of the data buffer;
306 ************************************************************************/
307 static bool fts_register_read(u8 reg_name, u8* rx_buf, int rx_length)
312 read_cmd[0] = reg_name;
315 /*send register addr*/
316 if(!i2c_write_interface(&read_cmd[0], cmd_len))
321 /*call the read callback function to get the register value*/
322 if(!i2c_read_interface(rx_buf, rx_length))
331 /***********************************************************************
333 callback: burn the FW to ctpm.
335 pbt_buf[in]: point to Head+FW ;
336 dw_lenth[in]: the length of the FW + 6(the Head length);
339 ERR_MODE: fail to switch to UPDATE mode;
340 ERR_READID: read id fail;
341 ERR_ERASE: erase chip fail;
342 ERR_STATUS: status error;
344 ************************************************************************/
345 E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(u8* pbt_buf, int dw_lenth)
347 u8 cmd,reg_val[2] = {0};
349 u8 packet_buf[FTS_PACKET_LENGTH + 6];
350 u8 auc_i2c_write_buf[10];
353 int j,temp,lenght,i_ret,packet_number, i = 0;
354 int i_is_new_protocol = 0;
357 /******write 0xaa to register 0xfc******/
359 fts_register_write(0xfc,&cmd);
362 /******write 0x55 to register 0xfc******/
364 fts_register_write(0xfc,&cmd);
365 printk("[TSP] Step 1: Reset CTPM test\n");
370 /*******Step 2:Enter upgrade mode ****/
371 printk("\n[TSP] Step 2:enter new update mode\n");
372 auc_i2c_write_buf[0] = 0x55;
373 auc_i2c_write_buf[1] = 0xaa;
377 i_ret = fts_i2c_txdata(auc_i2c_write_buf, 2);
379 }while(i_ret <= 0 && i < 10 );
383 i_is_new_protocol = 1;
386 /********Step 3:check READ-ID********/
387 cmd_write(0x90,0x00,0x00,0x00,4);
388 byte_read(reg_val,2);
389 if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
391 printk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
395 printk("[TSP] Step 3: error CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
397 //i_is_new_protocol = 1;
401 /*********Step 4:erase app**********/
402 if (i_is_new_protocol)
404 cmd_write(0x61,0x00,0x00,0x00,1);
408 cmd_write(0x60,0x00,0x00,0x00,1);
411 printk("[TSP] Step 4: erase. \n");
415 /*Step 5:write firmware(FW) to ctpm flash*/
417 printk("[TSP] Step 5: start upgrade. \n");
418 dw_lenth = dw_lenth - 8;
419 packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
420 packet_buf[0] = 0xbf;
421 packet_buf[1] = 0x00;
422 for (j=0;j<packet_number;j++)
424 temp = j * FTS_PACKET_LENGTH;
425 packet_buf[2] = (u8)(temp>>8);
426 packet_buf[3] = (u8)temp;
427 lenght = FTS_PACKET_LENGTH;
428 packet_buf[4] = (u8)(lenght>>8);
429 packet_buf[5] = (u8)lenght;
431 for (i=0;i<FTS_PACKET_LENGTH;i++)
433 packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
434 bt_ecc ^= packet_buf[6+i];
437 byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
438 mdelay(FTS_PACKET_LENGTH/6 + 1);
439 if ((j * FTS_PACKET_LENGTH % 1024) == 0)
441 printk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
445 if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
447 temp = packet_number * FTS_PACKET_LENGTH;
448 packet_buf[2] = (u8)(temp>>8);
449 packet_buf[3] = (u8)temp;
451 temp = (dw_lenth) % FTS_PACKET_LENGTH;
452 packet_buf[4] = (u8)(temp>>8);
453 packet_buf[5] = (u8)temp;
457 packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
458 bt_ecc ^= packet_buf[6+i];
461 byte_write(&packet_buf[0],temp+6);
465 /***********send the last six byte**********/
466 for (i = 0; i<6; i++)
469 packet_buf[2] = (u8)(temp>>8);
470 packet_buf[3] = (u8)temp;
472 packet_buf[4] = (u8)(temp>>8);
473 packet_buf[5] = (u8)temp;
474 packet_buf[6] = pbt_buf[ dw_lenth + i];
475 bt_ecc ^= packet_buf[6];
477 byte_write(&packet_buf[0],7);
481 /********send the opration head************/
482 cmd_write(0xcc,0x00,0x00,0x00,1);
483 byte_read(reg_val,1);
484 printk("[TSP] Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
485 if(reg_val[0] != bt_ecc)
490 /*******Step 7: reset the new FW**********/
491 cmd_write(0x07,0x00,0x00,0x00,1);
493 fts_register_read(0xfc, buffer, 1);
497 fts_register_write(0xfc, &cmd);
498 mdelay(2500);//2500ms
501 fts_register_read(0xfc, buffer, 1);
503 }while (buffer[0] != 1);
509 /***********************************************************************/
511 int fts_ctpm_fw_upgrade_with_i_file(void)
517 i_ret = fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
522 /***********************************************************************/
524 unsigned char fts_ctpm_get_upg_ver(void)
528 ui_sz = sizeof(CTPM_FW);
531 return CTPM_FW[ui_sz - 2];
538 static int ft5306_init_touchid(s16 touch_buf[], unsigned len,s16 init_val)
542 touch_buf[i] = init_val;
547 /*read the it7260 register ,used i2c bus*/
548 static int ft5306_read_regs(struct i2c_client *client, u8 reg, u8 buf[], unsigned len)
551 ret = i2c_master_reg8_recv(client, reg, buf, len, FT5306_IIC_SPEED);
556 /* set the it7260 registe,used i2c bus*/
557 static int ft5306_set_regs(struct i2c_client *client, u8 reg, u8 const buf[], unsigned short len)
560 ret = i2c_master_reg8_send(client, reg, buf, (int)len, FT5306_IIC_SPEED);
564 static void ft5306_queue_work(struct work_struct *work)
566 struct ft5x0x_ts_data *data = container_of(work, struct ft5x0x_ts_data, pen_event_work);
567 struct tp_event event;
570 int ret,i,offset,points;
572 #if CONFIG_FT5X0X_MULTITOUCH
573 ret = ft5306_read_regs(data->client,start_reg, buf, 6*MAX_POINT+1);
575 ret = ft5306_read_regs(data->client,start_reg, buf, 7);
578 dev_err(&data->client->dev, "ft5306_read_regs fail:%d!\n",ret);
579 enable_irq(data->irq);
583 points = buf[2] & 0x07;
584 memset(&event, 0, sizeof(struct tp_event));
585 #if CONFIG_FT5X0X_MULTITOUCH
586 ft5306_init_touchid(data->event.cur_touch_id,MAX_POINT,-1);
587 // dev_info(&data->client->dev,
588 // "ft5306 multiple report points = %d :\n",points);
589 for(i=0;i<points;i++){
591 #if (FT5X0X_SWAP_XY == 1)
592 event.y = (((s16)(buf[offset+0] & 0x0F))<<8) | ((s16)buf[offset+1]);
593 event.x = (((s16)(buf[offset+2] & 0x0F))<<8) | ((s16)buf[offset+3]);
595 event.x = (((s16)(buf[offset+0] & 0x0F))<<8) | ((s16)buf[offset+1]);
596 event.y = (((s16)(buf[offset+2] & 0x0F))<<8) | ((s16)buf[offset+3]);
598 event.id = (s16)(buf[offset+2] & 0xF0)>>4;
599 event.flag = ((buf[offset+0] & 0xc0) >> 6);
600 event.pressure = 200;
601 if(event.x<=SCREEN_MAX_X && event.y<=SCREEN_MAX_Y && event.id < MAX_POINT){
602 // dev_info(&data->client->dev,
603 // "ft5306 multiple report event[%d]:x = %d,y = %d,last_id = %d,cur_id = %d,flag = %d,pressure = %d\n",
604 // i,event.x,event.y,data->event.last_touch_id[event.id],event.id,event.flag,event.pressure);
605 input_mt_slot(data->input_dev, event.id);
606 data->event.cur_touch_id[event.id] = event.id;
607 if(data->event.last_touch_id[event.id] != event.id){
608 input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, event.id);
609 data->event.last_touch_id[event.id] = event.id;
611 input_report_abs(data->input_dev, ABS_MT_POSITION_X, event.x);
612 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event.y);
613 // dev_info(&data->client->dev,"new last_id=%d,cur_id = %d\n",data->event.last_touch_id[event.id],
614 // data->event.cur_touch_id[event.id]);
617 for(i=0;i<MAX_POINT;i++){
618 if(data->event.last_touch_id[i] != data->event.cur_touch_id[i]){
619 // dev_info(&data->client->dev,"release id=%d: last_id=%d,cur_id = %d\n",i,data->event.last_touch_id[i],
620 // data->event.cur_touch_id[i]);
621 data->event.last_touch_id[i] = data->event.cur_touch_id[i];
622 input_mt_slot(data->input_dev, i);
623 input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, data->event.cur_touch_id[i]);
628 input_report_abs(data->input_dev, ABS_PRESSURE, 0);
629 input_report_key(data->input_dev, BTN_TOUCH, 0);
630 input_sync(data->input_dev);
631 enable_irq(data->irq);
632 // dev_info(&data->client->dev, "ft5306 touch release\n");
635 event.x = (s16)(buf[3] & 0x0F)<<8 | (s16)buf[4];
636 event.y = (s16)(buf[5] & 0x0F)<<8 | (s16)buf[6];
638 input_report_abs(data->input_dev, ABS_X, event.x);
639 input_report_abs(data->input_dev, ABS_Y, event.y);
640 input_report_abs(data->input_dev, ABS_PRESSURE, event.pressure);
641 input_report_key(data->input_dev, BTN_TOUCH, 1);
642 //dev_info(&data->client->dev, "ft5306 single report event:x = %d,y = %d\n",event.x,event.y);
644 input_sync(data->input_dev);
645 enable_irq(data->irq);
649 static irqreturn_t ft5306_interrupt(int irq, void *dev_id)
651 struct ft5x0x_ts_data *ft5x0x_ts = dev_id;
653 //printk("ft5306_interrupt\n");
654 disable_irq_nosync(ft5x0x_ts->irq);
655 if (!work_pending(&ft5x0x_ts->pen_event_work))
656 queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
660 static int ft5306_suspend(struct i2c_client *client, pm_message_t mesg)
662 struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
663 struct ft5306_platform_data *pdata = client->dev.platform_data;
666 ft5306_set_regs(ft5x0x_ts->client, 0xA5, buf_w,1);
668 if (pdata->platform_sleep)
669 pdata->platform_sleep();
670 disable_irq(ft5x0x_ts->irq);
675 static int ft5306_resume(struct i2c_client *client)
677 struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
678 struct ft5306_platform_data *pdata = client->dev.platform_data;
680 enable_irq(ft5x0x_ts->irq);
681 if (pdata->platform_wakeup)
682 pdata->platform_wakeup();
686 static void ft5306_suspend_early(struct early_suspend *h)
688 ft5306_suspend(this_client,PMSG_SUSPEND);
691 static void ft5306_resume_early(struct early_suspend *h)
693 ft5306_resume(this_client);
695 static int __devexit ft5306_remove(struct i2c_client *client)
697 struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
699 free_irq(ft5x0x_ts->irq, ft5x0x_ts);
700 input_unregister_device(ft5x0x_ts->input_dev);
702 cancel_work_sync(&ft5x0x_ts->pen_event_work);
703 destroy_workqueue(ft5x0x_ts->ts_workqueue);
704 i2c_set_clientdata(client, NULL);
705 unregister_early_suspend(&ft5306_power);
710 static int ft5306_probe(struct i2c_client *client ,const struct i2c_device_id *id)
712 struct ft5x0x_ts_data *ft5x0x_ts;
713 struct input_dev *input_dev;
714 struct ft5306_platform_data *pdata = client->dev.platform_data;
720 const u8 buf_test[1] = {0};
721 unsigned char reg_value;
722 unsigned char reg_version;
724 dev_info(&client->dev, "ft5x0x_ts_probe!\n");
726 dev_err(&client->dev, "platform data is required!\n");
730 if (pdata->init_platform_hw)
731 pdata->init_platform_hw();
733 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
734 dev_err(&client->dev, "Must have I2C_FUNC_I2C.\n");
738 ft5x0x_ts = kzalloc(sizeof(*ft5x0x_ts), GFP_KERNEL);
745 ret=ft5306_set_regs(client,FT5X0X_REG_PMODE, buf_test,1);
751 printk("FT5306 I2C TEST ERROR!\n");
753 goto exit_i2c_test_fail;
756 err = ft5306_read_regs(client,FT5X0X_REG_PMODE,buf_r,1);
757 printk("read buf[FT5X0X_REG_PMODE] = %d\n", buf_r[0]);
760 input_dev = input_allocate_device();
763 printk("failed to allocate input device\n");
764 goto exit_input_dev_alloc_failed;
766 ft5x0x_ts->client = this_client = client;
767 ft5x0x_ts->irq = pdata->irq_pin;
768 ft5x0x_ts->input_dev = input_dev;
770 set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
771 set_bit(EV_ABS, input_dev->evbit);
773 #if CONFIG_FT5X0X_MULTITOUCH
774 ft5306_init_touchid(ft5x0x_ts->event.cur_touch_id,MAX_POINT,-1);
775 ft5306_init_touchid(ft5x0x_ts->event.last_touch_id,MAX_POINT,-1);
776 input_mt_init_slots(input_dev, MAX_POINT);
777 input_set_abs_params(input_dev,ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
778 input_set_abs_params(input_dev,ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
780 set_bit(ABS_X, input_dev->absbit);
781 set_bit(ABS_Y, input_dev->absbit);
782 set_bit(ABS_PRESSURE, input_dev->absbit);
783 set_bit(BTN_TOUCH, input_dev->keybit);
784 input_set_abs_params(input_dev, ABS_X, 0, SCREEN_MAX_X, 0, 0);
785 input_set_abs_params(input_dev, ABS_Y, 0, SCREEN_MAX_Y, 0, 0);
786 input_set_abs_params(input_dev, ABS_PRESSURE, 0, PRESS_MAX, 0 , 0);
789 input_dev->name = FT5X0X_NAME;
790 input_dev->id.bustype = BUS_I2C;
792 err = input_register_device(input_dev);
794 printk("ft5x0x_ts_probe: failed to register input device: \n");
795 goto exit_input_register_device_failed;
798 if (!ft5x0x_ts->irq) {
800 dev_err(&ft5x0x_ts->client->dev, "no IRQ?\n");
801 goto exit_no_irq_fail;
803 ft5x0x_ts->irq = gpio_to_irq(ft5x0x_ts->irq);
806 //INIT_WORK(&ft5x0x_ts->pen_event_work, ft5306_ts_pen_irq_work);
807 INIT_WORK(&ft5x0x_ts->pen_event_work, ft5306_queue_work);
808 ft5x0x_ts->ts_workqueue = create_singlethread_workqueue("ft5x0x_ts");
809 if (!ft5x0x_ts->ts_workqueue) {
811 goto exit_create_singlethread;
814 /***wait CTP to bootup normally***/
817 fts_register_read(FT5X0X_REG_FIRMID, ®_version,1);
818 printk("[TSP] firmware version = 0x%2x\n", reg_version);
819 fts_register_read(FT5X0X_REG_REPORT_RATE, ®_value,1);
820 printk("[TSP]firmware report rate = %dHz\n", reg_value*10);
821 fts_register_read(FT5X0X_REG_THRES, ®_value,1);
822 printk("[TSP]firmware threshold = %d\n", reg_value * 4);
823 fts_register_read(FT5X0X_REG_NOISE_MODE, ®_value,1);
824 printk("[TSP]nosie mode = 0x%2x\n", reg_value);
827 if (fts_ctpm_get_upg_ver() != reg_version)
829 printk("[TSP] start upgrade new verison 0x%2x\n", fts_ctpm_get_upg_ver());
831 err = fts_ctpm_fw_upgrade_with_i_file();
834 printk("[TSP] ugrade successfuly.\n");
836 fts_register_read(FT5X0X_REG_FIRMID, ®_value,1);
837 printk("FTS_DBG from old version 0x%2x to new version = 0x%2x\n", reg_version, reg_value);
841 printk("[TSP] ugrade fail err=%d, line = %d.\n",err, __LINE__);
847 //printk("client->dev.driver->name %s ,%d \n",client->dev.driver->name,ft5x0x_ts->irq);
848 ret = request_irq(ft5x0x_ts->irq, ft5306_interrupt, IRQF_TRIGGER_FALLING, client->dev.driver->name, ft5x0x_ts);
850 dev_err(&client->dev, "irq %d busy?\n", ft5x0x_ts->irq);
851 goto exit_irq_request_fail;
854 i2c_set_clientdata(client, ft5x0x_ts);
855 ft5306_power.suspend =ft5306_suspend_early;
856 ft5306_power.resume =ft5306_resume_early;
857 ft5306_power.level = 0x2;
858 register_early_suspend(&ft5306_power);
861 err = ft5306_set_regs(client,0x88,buf_w,1);
863 err = ft5306_read_regs(client,0x88,buf_r,1);
864 printk("read buf[0x88] = %d\n", buf_r[0]);
867 i2c_set_clientdata(client, NULL);
868 free_irq(ft5x0x_ts->irq,ft5x0x_ts);
869 exit_irq_request_fail:
870 cancel_work_sync(&ft5x0x_ts->pen_event_work);
871 destroy_workqueue(ft5x0x_ts->ts_workqueue);
872 exit_create_singlethread:
874 input_unregister_device(input_dev);
875 exit_input_register_device_failed:
876 input_free_device(input_dev);
877 exit_input_dev_alloc_failed:
879 if (pdata->exit_platform_hw)
880 pdata->exit_platform_hw();
887 static struct i2c_device_id ft5306_idtable[] = {
892 MODULE_DEVICE_TABLE(i2c, ft5306_idtable);
894 static struct i2c_driver ft5306_driver = {
896 .owner = THIS_MODULE,
899 .id_table = ft5306_idtable,
900 .probe = ft5306_probe,
901 .remove = __devexit_p(ft5306_remove),
904 static int __init ft5306_ts_init(void)
906 return i2c_add_driver(&ft5306_driver);
909 static void __exit ft5306_ts_exit(void)
911 printk("Touchscreen driver of ft5306 exited.\n");
912 i2c_del_driver(&ft5306_driver);
915 /***********************************************************************/
917 module_init(ft5306_ts_init);
918 module_exit(ft5306_ts_exit);
920 MODULE_AUTHOR("<wenfs@Focaltech-systems.com>");
921 MODULE_DESCRIPTION("FocalTech ft5x0x TouchScreen driver");