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/module.h>
23 #include <linux/init.h>
24 #include <linux/interrupt.h>
25 #include <linux/kernel.h>
26 #include <linux/platform_device.h>
27 #include <linux/spi/spi.h>
28 #include <linux/slab.h>
29 #include <linux/fcntl.h>
30 #include <linux/delay.h>
31 #include <linux/device.h>
32 #include <linux/timer.h>
33 #include <linux/jiffies.h>
34 #include <linux/miscdevice.h>
35 #include <linux/types.h>
37 #include <linux/delay.h>
38 #include <linux/ioport.h>
39 #include <linux/input-polldev.h>
40 #include <linux/i2c.h>
41 #include <linux/workqueue.h>
42 #ifdef CONFIG_ANDROID_POWER
43 #include <linux/android_power.h>
45 #include <mach/hardware.h>
46 #include <asm/setup.h>
47 #include <asm/mach-types.h>
48 #include <asm/mach/arch.h>
49 #include <asm/mach/map.h>
50 #include <asm/mach/flash.h>
51 #include <asm/hardware/gic.h>
52 #include <mach/iomux.h>
53 #include <mach/gpio.h>
54 #include <mach/irqs.h>
55 #include <mach/rk29_iomap.h>
56 #include <mach/board.h>
57 #include <mach/rk29_nand.h>
58 #include <mach/rk29_camera.h> /* ddl@rock-chips.com : camera support */
59 #include <media/soc_camera.h> /* ddl@rock-chips.com : camera support */
60 #include <mach/vpu_mem.h>
61 #include <mach/sram.h>
62 #ifdef CONFIG_HAS_EARLYSUSPEND
63 #include <linux/earlysuspend.h>
65 #include <linux/input/mt.h>
69 #define FTprintk(x...) printk(x)
71 #define FTprintk(x...) do{} while(0)
74 #define CONFIG_FT5X0X_MULTITOUCH 1
76 #define FT5306_IIC_SPEED 400*1000 //300*1000
77 #define TOUCH_RESET_PIN RK29_PIN6_PC3
78 #define FT5X0X_REG_THRES 0x80 /* Thresshold, the threshold be low, the sensitivy will be high */
79 #define FT5X0X_REG_REPORT_RATE 0x88 /* **************report rate, in unit of 10Hz **************/
80 #define FT5X0X_REG_PMODE 0xA5 /* Power Consume Mode 0 -- active, 1 -- monitor, 3 -- sleep */
81 #define FT5X0X_REG_FIRMID 0xA6 /* ***************firmware version **********************/
82 #define FT5X0X_REG_NOISE_MODE 0xb2 /* to enable or disable power noise, 1 -- enable, 0 -- disable */
83 #define SCREEN_MAX_X 480
84 #define SCREEN_MAX_Y 800
86 #define FT5X0X_NAME "ft5x0x_ts"//"synaptics_i2c_rmi"//"synaptics-rmi-ts"//
87 #define TOUCH_MAJOR_MAX 200
88 #define WIDTH_MAJOR_MAX 200
90 #define PMODE_ACTIVE 0x00
91 #define PMODE_MONITOR 0x01
92 #define PMODE_STANDBY 0x02
93 #define PMODE_HIBERNATE 0x03
126 struct ft5x0x_ts_data {
127 struct i2c_client *client;
128 struct input_dev *input_dev;
130 int (*platform_sleep)(void);
131 int (*platform_wakeup)(void);
132 struct ts_event event;
133 struct work_struct pen_event_work;
134 struct workqueue_struct *ts_workqueue;
135 #ifdef CONFIG_HAS_EARLYSUSPEND
136 struct early_suspend ft5306_early_suspend;
139 static struct i2c_client *this_client;
141 /***********************************************************************/
143 #define FTS_PACKET_LENGTH 128
148 #include "ft_app_5306.i"
164 /***********************************************************************/
166 /***********************************************************************
168 callback: send data to ctpm by i2c interface;
170 txdata[in]: data buffer which is used to send data;
171 length[in]: the length of the data buffer;
175 ************************************************************************/
176 static int fts_i2c_txdata(u8 *txdata, int length)
182 msg.addr = this_client->addr;
186 msg.scl_rate = FT5306_IIC_SPEED;
187 ret = i2c_transfer(this_client->adapter, &msg, 1);
189 pr_err("%s i2c write error: %d\n", __func__, ret);
194 /***********************************************************************
196 callback: write data to ctpm by i2c interface;
198 buffer[in]: data buffer;
199 length[in]: the length of the data buffer;
203 ************************************************************************/
204 static bool i2c_write_interface(u8* pbt_buf, int dw_lenth)
207 ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
210 FTprintk("[TSP]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
217 /***********************************************************************
219 callback: read register value ftom ctpm by i2c interface;
221 reg_name[in]: the register which you want to write;
222 tx_buf[in]: buffer which is contained of the writing value;
226 ************************************************************************/
227 static bool fts_register_write(u8 reg_name, u8* tx_buf)
229 u8 write_cmd[2] = {0};
231 write_cmd[0] = reg_name;
232 write_cmd[1] = *tx_buf;
234 /*call the write callback function*/
235 return i2c_write_interface(write_cmd, 2);
238 /***********************************************************************
240 callback: send a command to ctpm.
242 btcmd[in]: command code;
243 btPara1[in]: parameter 1;
244 btPara2[in]: parameter 2;
245 btPara3[in]: parameter 3;
246 num[in]: the valid input parameter numbers,
247 if only command code needed and no
248 parameters followed,then the num is 1;
252 ************************************************************************/
253 static bool cmd_write(u8 btcmd,u8 btPara1,u8 btPara2,u8 btPara3,u8 num)
255 u8 write_cmd[4] = {0};
257 write_cmd[0] = btcmd;
258 write_cmd[1] = btPara1;
259 write_cmd[2] = btPara2;
260 write_cmd[3] = btPara3;
261 return i2c_write_interface(write_cmd, num);
264 /***********************************************************************
266 callback: read data from ctpm by i2c interface;
268 buffer[in]: data buffer;
269 length[in]: the length of the data buffer;
273 ************************************************************************/
274 static bool i2c_read_interface(u8* pbt_buf, int dw_lenth)
278 ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);
282 FTprintk("[TSP]i2c_read_interface error\n");
290 /***********************************************************************
292 callback: read a byte data from ctpm;
294 buffer[in]: read buffer;
295 length[in]: the size of read data;
299 ************************************************************************/
300 static bool byte_read(u8* buffer, int length)
302 return i2c_read_interface(buffer, length);
305 /***********************************************************************
307 callback: write a byte data to ctpm;
309 buffer[in]: write buffer;
310 length[in]: the size of write data;
314 ************************************************************************/
315 static bool byte_write(u8* buffer, int length)
318 return i2c_write_interface(buffer, length);
321 /***********************************************************************
323 callback: read register value ftom ctpm by i2c interface;
325 reg_name[in]: the register which you want to read;
326 rx_buf[in]: data buffer which is used to store register value;
327 rx_length[in]: the length of the data buffer;
331 ************************************************************************/
332 static bool fts_register_read(u8 reg_name, u8* rx_buf, int rx_length)
337 read_cmd[0] = reg_name;
340 /*send register addr*/
341 if(!i2c_write_interface(&read_cmd[0], cmd_len))
346 /*call the read callback function to get the register value*/
347 if(!i2c_read_interface(rx_buf, rx_length))
356 /***********************************************************************
358 callback: burn the FW to ctpm.
360 pbt_buf[in]: point to Head+FW ;
361 dw_lenth[in]: the length of the FW + 6(the Head length);
364 ERR_MODE: fail to switch to UPDATE mode;
365 ERR_READID: read id fail;
366 ERR_ERASE: erase chip fail;
367 ERR_STATUS: status error;
369 ************************************************************************/
370 E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(u8* pbt_buf, int dw_lenth)
372 u8 cmd,reg_val[2] = {0};
374 u8 packet_buf[FTS_PACKET_LENGTH + 6];
375 u8 auc_i2c_write_buf[10];
378 int j,temp,lenght,i_ret,packet_number, i = 0;
379 int i_is_new_protocol = 0;
382 /******write 0xaa to register 0xfc******/
384 fts_register_write(0xfc,&cmd);
387 /******write 0x55 to register 0xfc******/
389 fts_register_write(0xfc,&cmd);
390 FTprintk("[TSP] Step 1: Reset CTPM test\n");
395 /*******Step 2:Enter upgrade mode ****/
396 FTprintk("\n[TSP] Step 2:enter new update mode\n");
397 auc_i2c_write_buf[0] = 0x55;
398 auc_i2c_write_buf[1] = 0xaa;
402 i_ret = fts_i2c_txdata(auc_i2c_write_buf, 2);
404 }while(i_ret <= 0 && i < 10 );
408 i_is_new_protocol = 1;
411 /********Step 3:check READ-ID********/
412 cmd_write(0x90,0x00,0x00,0x00,4);
413 byte_read(reg_val,2);
414 if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
416 FTprintk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
421 //i_is_new_protocol = 1;
425 /*********Step 4:erase app**********/
426 if (i_is_new_protocol)
428 cmd_write(0x61,0x00,0x00,0x00,1);
432 cmd_write(0x60,0x00,0x00,0x00,1);
435 FTprintk("[TSP] Step 4: erase. \n");
439 /*Step 5:write firmware(FW) to ctpm flash*/
441 FTprintk("[TSP] Step 5: start upgrade. \n");
442 dw_lenth = dw_lenth - 8;
443 packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
444 packet_buf[0] = 0xbf;
445 packet_buf[1] = 0x00;
446 FTprintk("[TSP] packet_number = %d\n",packet_number);
447 for (j=0;j<packet_number;j++)
449 temp = j * FTS_PACKET_LENGTH;
450 packet_buf[2] = (u8)(temp>>8);
451 packet_buf[3] = (u8)temp;
452 lenght = FTS_PACKET_LENGTH;
453 packet_buf[4] = (u8)(lenght>>8);
454 packet_buf[5] = (u8)lenght;
456 for (i=0;i<FTS_PACKET_LENGTH;i++)
458 packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
459 bt_ecc ^= packet_buf[6+i];
462 byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
463 mdelay(FTS_PACKET_LENGTH/6 + 1);
464 if ((j * FTS_PACKET_LENGTH % 1024) == 0)
466 FTprintk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
470 if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
472 temp = packet_number * FTS_PACKET_LENGTH;
473 packet_buf[2] = (u8)(temp>>8);
474 packet_buf[3] = (u8)temp;
476 temp = (dw_lenth) % FTS_PACKET_LENGTH;
477 packet_buf[4] = (u8)(temp>>8);
478 packet_buf[5] = (u8)temp;
482 packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
483 bt_ecc ^= packet_buf[6+i];
486 byte_write(&packet_buf[0],temp+6);
490 /***********send the last six byte**********/
491 for (i = 0; i<6; i++)
494 packet_buf[2] = (u8)(temp>>8);
495 packet_buf[3] = (u8)temp;
497 packet_buf[4] = (u8)(temp>>8);
498 packet_buf[5] = (u8)temp;
499 packet_buf[6] = pbt_buf[ dw_lenth + i];
500 bt_ecc ^= packet_buf[6];
502 byte_write(&packet_buf[0],7);
506 /********send the opration head************/
507 cmd_write(0xcc,0x00,0x00,0x00,1);
508 byte_read(reg_val,1);
509 FTprintk("[TSP] Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
510 if(reg_val[0] != bt_ecc)
515 /*******Step 7: reset the new FW**********/
516 cmd_write(0x07,0x00,0x00,0x00,1);
518 fts_register_read(0xfc, buffer, 1);
522 fts_register_write(0xfc, &cmd);
523 mdelay(2500);//2500ms
526 fts_register_read(0xfc, buffer, 1);
528 }while (buffer[0] != 1);
534 /***********************************************************************/
536 int fts_ctpm_fw_upgrade_with_i_file(void)
542 i_ret = fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
547 /***********************************************************************/
549 unsigned char fts_ctpm_get_upg_ver(void)
553 ui_sz = sizeof(CTPM_FW);
556 return CTPM_FW[ui_sz - 2];
563 /*read the it7260 register ,used i2c bus*/
564 static int ft5306_read_regs(struct i2c_client *client, u8 reg, u8 *buf, unsigned len)
567 ret = i2c_master_reg8_recv(client, reg, buf, len, FT5306_IIC_SPEED);
571 /* set the it7260 registe,used i2c bus*/
572 static int ft5306_set_regs(struct i2c_client *client, u8 reg, u8 *buf, unsigned short len)
575 ret = i2c_master_reg8_send(client, reg, buf, (int)len, FT5306_IIC_SPEED);
579 static void ft5306_queue_work(struct work_struct *work)
581 struct ft5x0x_ts_data *data = container_of(work, struct ft5x0x_ts_data, pen_event_work);
582 struct tp_event event;
585 int ret,i,offset,points;
586 static u8 points_last_flag[MAX_POINT]={0};
587 struct tp_event current_events[MAX_POINT];
589 #if CONFIG_FT5X0X_MULTITOUCH
590 ret = ft5306_read_regs(data->client,start_reg, buf, 6*MAX_POINT+1);
592 ret = ft5306_read_regs(data->client,start_reg, buf, 7);
595 dev_err(&data->client->dev, "ft5306_read_regs fail:%d!\n",ret);
596 enable_irq(data->irq);
600 for (i=0; i<32; i++) {
601 FTprintk("buf[%d] = 0x%x \n", i, buf[i]);
605 points = buf[2] & 0x07;
606 //dev_info(&data->client->dev, "ft5306_read_and_report_data points = %d\n",points);
608 #if CONFIG_FT5X0X_MULTITOUCH
609 //input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
610 //input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 0);
612 for(i=0;i<MAX_POINT;i++)
614 if(points_last_flag[i]!=0)
616 FTprintk("Point UP event.id=%d\n",i);
617 input_mt_slot(data->input_dev, i);
618 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
622 memset(points_last_flag, 0, sizeof(points_last_flag));
623 //input_mt_sync(data->input_dev);
625 input_report_abs(data->input_dev, ABS_PRESSURE, 0);
626 input_report_key(data->input_dev, BTN_TOUCH, 0);
628 input_sync(data->input_dev);
629 enable_irq(data->irq);
632 memset(&event, 0, sizeof(struct tp_event));
633 #if CONFIG_FT5X0X_MULTITOUCH
634 memset(current_events, 0, sizeof(current_events));
636 for(i=0;i<points;i++){
638 event.x = (((s16)(buf[offset+0] & 0x0F))<<8) | ((s16)buf[offset+1]);
639 event.y = (((s16)(buf[offset+2] & 0x0F))<<8) | ((s16)buf[offset+3]);
640 event.id = (s16)(buf[offset+2] & 0xF0)>>4;
641 event.flag = ((buf[offset+0] & 0xc0) >> 6);
642 event.pressure = 200;
643 FTprintk("x=%d, y=%d event.id=%d event.flag=%d\n",event.x,event.y,event.id,event.flag);
644 if(event.x<=SCREEN_MAX_X && event.y<=SCREEN_MAX_Y+60){
645 //dev_info(&data->client->dev,
646 // "ft5306 multiple report event[%d]:x = %d,y = %d,id = %d,flag = %d,pressure = %d\n",
647 // i,event.x,event.y,event.id,event.flag,event.pressure);
649 memcpy(¤t_events[event.id], &event, sizeof(event));
650 //points_current[event.id] = event.flag;
654 for(i=0;i<MAX_POINT;i++)
656 if((current_events[i].flag == 0) && (points_last_flag[i] != 0))
658 FTprintk("Point UP event.id=%d\n",i);
659 input_mt_slot(data->input_dev, i);
660 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, false);
662 else if(current_events[i].flag)
664 FTprintk("Point DN event.id=%d\n",i);
665 input_mt_slot(data->input_dev, i);
666 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, true);
667 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 1);
668 //input_report_abs(data->input_dev, ABS_MT_PRESSURE, event.pressure);
669 input_report_abs(data->input_dev, ABS_MT_POSITION_X, current_events[i].x);
670 input_report_abs(data->input_dev, ABS_MT_POSITION_Y, current_events[i].y);
672 points_last_flag[i] = current_events[i].flag;
675 event.x = (s16)(buf[3] & 0x0F)<<8 | (s16)buf[4];
676 event.y = (s16)(buf[5] & 0x0F)<<8 | (s16)buf[6];
678 input_report_abs(data->input_dev, ABS_X, event.x);
679 input_report_abs(data->input_dev, ABS_Y, event.y);
680 //input_report_abs(data->input_dev, ABS_PRESSURE, event.pressure);
681 input_report_key(data->input_dev, BTN_TOUCH, 1);
684 //dev_info(&data->client->dev, "ft5306 single report event:x = %d,y = %d\n",event.x,event.y);
686 //dev_info(&data->client->dev, "ft5306 sync\n",event.x,event.y);
687 input_sync(data->input_dev);
688 enable_irq(data->irq);
692 static irqreturn_t ft5306_interrupt(int irq, void *dev_id)
694 struct ft5x0x_ts_data *ft5x0x_ts = dev_id;
695 FTprintk("[TSP] ft5306_interrupt\n");
696 disable_irq_nosync(ft5x0x_ts->irq);
697 if (!work_pending(&ft5x0x_ts->pen_event_work))
698 queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
701 #ifdef CONFIG_HAS_EARLYSUSPEND
703 static int ft5306_suspend(struct early_suspend *h)
705 struct ft5x0x_ts_data *ft5x0x_ts;
708 ft5x0x_ts = container_of(h, struct ft5x0x_ts_data, ft5306_early_suspend);
709 FTprintk("TSP ft5306_suspend\n");
710 //if (ft5x0x_ts->platform_sleep){
711 // ft5x0x_ts->platform_sleep();
713 err = ft5306_set_regs(this_client,0xA5,buf_w,1);
715 printk("ft5306_set_regs OK!!\n");
716 disable_irq(ft5x0x_ts->irq);
721 static int ft5306_resume(struct early_suspend *h)
723 struct ft5x0x_ts_data *ft5x0x_ts;
724 ft5x0x_ts = container_of(h, struct ft5x0x_ts_data, ft5306_early_suspend);
725 FTprintk("TSP ft5306_resume\n");
726 enable_irq(ft5x0x_ts->irq);
727 //if (ft5x0x_ts->platform_wakeup)
728 //ft5x0x_ts->platform_wakeup();
729 gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
731 gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
736 static int __devexit ft5306_remove(struct i2c_client *client)
738 struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
740 free_irq(ft5x0x_ts->irq, ft5x0x_ts);
741 input_unregister_device(ft5x0x_ts->input_dev);
743 cancel_work_sync(&ft5x0x_ts->pen_event_work);
744 destroy_workqueue(ft5x0x_ts->ts_workqueue);
745 i2c_set_clientdata(client, NULL);
746 #ifdef CONFIG_HAS_EARLYSUSPEND
747 unregister_early_suspend(&ft5x0x_ts->ft5306_early_suspend);
753 static int ft5306_probe(struct i2c_client *client ,const struct i2c_device_id *id)
755 struct ft5x0x_ts_data *ft5x0x_ts;
756 struct input_dev *input_dev;
757 struct ft5406_platform_data *pdata = client->dev.platform_data;
763 const u8 buf_test[1] = {0};
764 unsigned char reg_value;
765 unsigned char reg_version;
767 dev_info(&client->dev, "ft5306_ts_probe!\n");
769 dev_err(&client->dev, "platform data is required!\n");
773 if (pdata->init_platform_hw)
774 pdata->init_platform_hw();
775 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)){
776 dev_err(&client->dev, "Must have I2C_FUNC_I2C.\n");
780 ft5x0x_ts = kzalloc(sizeof(*ft5x0x_ts), GFP_KERNEL);
781 ft5x0x_ts->platform_wakeup = pdata->platform_wakeup;
782 ft5x0x_ts->platform_sleep = pdata->platform_sleep;
789 ret=ft5306_set_regs(client,FT5X0X_REG_PMODE, buf_test,1);
795 FTprintk("FT5306 I2C TEST ERROR!\n");
797 goto exit_i2c_test_fail;
800 input_dev = input_allocate_device();
803 FTprintk("failed to allocate input device\n");
804 goto exit_input_dev_alloc_failed;
806 ft5x0x_ts->client = this_client = client;
807 ft5x0x_ts->irq = client->irq;
808 ft5x0x_ts->input_dev = input_dev;
810 #if CONFIG_FT5X0X_MULTITOUCH
811 __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
812 __set_bit(EV_ABS, input_dev->evbit);
814 input_mt_init_slots(input_dev, MAX_POINT);
815 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
816 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_X, 0, 0);
817 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_Y, 0, 0);
818 //input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, MAX_POINT, 0, 0);
819 //input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
822 set_bit(ABS_X, input_dev->absbit);
823 set_bit(ABS_Y, input_dev->absbit);
824 set_bit(ABS_PRESSURE, input_dev->absbit);
825 set_bit(BTN_TOUCH, input_dev->keybit);
826 input_set_abs_params(input_dev, ABS_X, 0, SCREEN_MAX_X, 0, 0);
827 input_set_abs_params(input_dev, ABS_Y, 0, SCREEN_MAX_Y, 0, 0);
828 //input_set_abs_params(input_dev, ABS_PRESSURE, 0, PRESS_MAX, 0 , 0);
831 //input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
832 //input_dev->keybit[BIT_WORD(BTN_START)] = BIT_MASK(BTN_START);
833 //set_bit(EV_ABS, input_dev->evbit);
834 //set_bit(EV_KEY, input_dev->evbit);
836 input_dev->name = "ft5x0x_ts-touchscreen"; //dev_name(&client->dev)
837 err = input_register_device(input_dev);
839 FTprintk("ft5306_ts_probe: failed to register input device: \n");
840 goto exit_input_register_device_failed;
843 if (!ft5x0x_ts->irq) {
845 dev_err(&ft5x0x_ts->client->dev, "no IRQ?\n");
846 goto exit_no_irq_fail;
848 ft5x0x_ts->irq = gpio_to_irq(ft5x0x_ts->irq);
851 INIT_WORK(&ft5x0x_ts->pen_event_work, ft5306_queue_work);
852 ft5x0x_ts->ts_workqueue = create_singlethread_workqueue("ft5x0x_ts");
853 if (!ft5x0x_ts->ts_workqueue) {
855 goto exit_create_singlethread;
858 /***wait CTP to bootup normally***/
860 #if 1 //write firmware
861 fts_register_read(FT5X0X_REG_FIRMID, ®_version,1);
862 FTprintk("[TSP] firmware version = 0x%2x\n", reg_version);
863 if (fts_ctpm_get_upg_ver() != reg_version)
865 FTprintk("[TSP] start upgrade new verison 0x%2x\n", fts_ctpm_get_upg_ver());
867 err = fts_ctpm_fw_upgrade_with_i_file();
870 FTprintk("[TSP] ugrade successfuly.\n");
872 fts_register_read(FT5X0X_REG_FIRMID, ®_value,1);
873 FTprintk("FTS_DBG from old version 0x%2x to new version = 0x%2x\n", reg_version, reg_value);
877 FTprintk("[TSP] ugrade fail err=%d, line = %d.\n",err, __LINE__);
882 ret = request_irq(ft5x0x_ts->irq, ft5306_interrupt, IRQF_TRIGGER_FALLING, client->dev.driver->name, ft5x0x_ts);
884 dev_err(&client->dev, "irq %d busy?\n", ft5x0x_ts->irq);
885 goto exit_irq_request_fail;
887 i2c_set_clientdata(client, ft5x0x_ts);
888 #ifdef CONFIG_HAS_EARLYSUSPEND
889 ft5x0x_ts->ft5306_early_suspend.suspend =ft5306_suspend;
890 ft5x0x_ts->ft5306_early_suspend.resume =ft5306_resume;
891 ft5x0x_ts->ft5306_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;;
892 register_early_suspend(&ft5x0x_ts->ft5306_early_suspend);
895 err = ft5306_set_regs(client,0x88,buf_w,1);
897 err = ft5306_read_regs(client,0x88,buf_r,1);
898 FTprintk("read buf[0x88] = %d\n", buf_r[0]);
901 i2c_set_clientdata(client, NULL);
902 free_irq(ft5x0x_ts->irq,ft5x0x_ts);
903 exit_irq_request_fail:
904 cancel_work_sync(&ft5x0x_ts->pen_event_work);
905 destroy_workqueue(ft5x0x_ts->ts_workqueue);
906 exit_create_singlethread:
908 input_unregister_device(input_dev);
909 exit_input_register_device_failed:
910 input_free_device(input_dev);
911 exit_input_dev_alloc_failed:
913 if (pdata->exit_platform_hw)
914 pdata->exit_platform_hw();
921 static struct i2c_device_id ft5306_idtable[] = {
926 MODULE_DEVICE_TABLE(i2c, ft5306_idtable);
928 static struct i2c_driver ft5306_driver = {
930 .owner = THIS_MODULE,
933 .id_table = ft5306_idtable,
934 .probe = ft5306_probe,
935 .suspend = ft5306_suspend,
936 .resume = ft5306_resume,
937 .remove = __devexit_p(ft5306_remove),
940 static int __init ft5306_ts_init(void)
942 return i2c_add_driver(&ft5306_driver);
945 static void __exit ft5306_ts_exit(void)
947 FTprintk("Touchscreen driver of ft5306 exited.\n");
948 i2c_del_driver(&ft5306_driver);
952 /***********************************************************************/
954 module_init(ft5306_ts_init);
955 module_exit(ft5306_ts_exit);
957 MODULE_AUTHOR("<wenfs@Focaltech-systems.com>");
958 MODULE_DESCRIPTION("FocalTech ft5x0x TouchScreen driver");