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/gpio.h>
10 #include <linux/types.h>
11 #include <mach/iomux.h>
12 #include <linux/platform_device.h>
13 #include <linux/kthread.h>
14 #include <linux/sched.h>
15 #include <linux/irq.h>
16 #include <linux/cdev.h>
17 #include <asm/uaccess.h>
19 #include "ili2102_ts.h"
23 #define DBG(msg...) printk(msg);
28 #define TOUCH_NUMBER 2
30 static int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
31 static unsigned int g_x[TOUCH_NUMBER] = {0},g_y[TOUCH_NUMBER] = {0};
33 struct ili2102_ts_data {
35 bool swap_xy; /* swap x and y axes */
43 int gpio_reset_active_low;
44 int pendown_iomux_mode;
45 int resetpin_iomux_mode;
46 char pendown_iomux_name[IOMUX_NAME_SIZE];
47 char resetpin_iomux_name[IOMUX_NAME_SIZE];
50 int valid_i2c_register;
51 struct i2c_client *client;
52 struct input_dev *input_dev;
54 struct delayed_work work;
55 struct workqueue_struct *ts_wq;
56 struct early_suspend early_suspend;
59 #ifdef CONFIG_HAS_EARLYSUSPEND
60 static void ili2102_ts_early_suspend(struct early_suspend *h);
61 static void ili2102_ts_late_resume(struct early_suspend *h);
64 #define ILI2102_TS_APK_SUPPORT 1
66 #if ILI2102_TS_APK_SUPPORT
78 static struct ili2102_ts_data *g_ts;
79 static struct dev_data g_dev;
82 #define ILITEK_I2C_RETRY_COUNT 3
83 #define ILITEK_FILE_DRIVER_NAME "ilitek_file"
84 #define ILITEK_DEBUG_LEVEL KERN_INFO
85 #define ILITEK_ERROR_LEVEL KERN_ALERT
87 // i2c command for ilitek touch screen
88 #define ILITEK_TP_CMD_READ_DATA 0x10
89 #define ILITEK_TP_CMD_READ_SUB_DATA 0x11
90 #define ILITEK_TP_CMD_GET_RESOLUTION 0x20
91 #define ILITEK_TP_CMD_GET_FIRMWARE_VERSION 0x40
92 #define ILITEK_TP_CMD_GET_PROTOCOL_VERSION 0x42
93 #define ILITEK_TP_CMD_CALIBRATION 0xCC
94 #define ILITEK_TP_CMD_ERASE_BACKGROUND 0xCE
96 // define the application command
97 #define ILITEK_IOCTL_BASE 100
98 #define ILITEK_IOCTL_I2C_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 0, unsigned char*)
99 #define ILITEK_IOCTL_I2C_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 1, int)
100 #define ILITEK_IOCTL_I2C_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 2, unsigned char*)
101 #define ILITEK_IOCTL_I2C_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 3, int)
102 #define ILITEK_IOCTL_USB_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 4, unsigned char*)
103 #define ILITEK_IOCTL_USB_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 5, int)
104 #define ILITEK_IOCTL_USB_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 6, unsigned char*)
105 #define ILITEK_IOCTL_USB_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 7, int)
106 #define ILITEK_IOCTL_I2C_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 8, int)
107 #define ILITEK_IOCTL_USB_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 9, int)
108 #define ILITEK_IOCTL_I2C_SET_ADDRESS _IOWR(ILITEK_IOCTL_BASE, 10, int)
109 #define ILITEK_IOCTL_I2C_UPDATE _IOWR(ILITEK_IOCTL_BASE, 11, int)
110 #define ILITEK_IOCTL_STOP_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 12, int)
111 #define ILITEK_IOCTL_START_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 13, int)
113 static int ilitek_file_open(struct inode *inode, struct file *filp)
118 static ssize_t ilitek_file_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos)
121 unsigned char buffer[128]={0};
122 struct i2c_msg msg[2];
124 msg[0].addr = g_ts->client->addr;
125 msg[0].flags = g_ts->client->flags;
128 msg[0].scl_rate = 400*1000;
131 printk("%s:count=0x%x\n",__FUNCTION__,count);
133 // before sending data to touch device, we need to check whether the device is working or not
134 if(g_ts->valid_i2c_register == 0){
135 printk(ILITEK_ERROR_LEVEL "%s, i2c device driver doesn't be registered\n", __func__);
139 // check the buffer size whether it exceeds the local buffer size or not
141 printk(ILITEK_ERROR_LEVEL "%s, buffer exceed 128 bytes\n", __func__);
145 // copy data from user space
146 ret = copy_from_user(buffer, buf, count-1);
148 printk(ILITEK_ERROR_LEVEL "%s, copy data from user space, failed", __func__);
153 if(strcmp(buffer, "calibrate") == 0){
154 buffer[0] = ILITEK_TP_CMD_ERASE_BACKGROUND;
156 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
158 printk(ILITEK_DEBUG_LEVEL "%s, i2c erase background, failed\n", __func__);
161 printk(ILITEK_DEBUG_LEVEL "%s, i2c erase background, success\n", __func__);
164 buffer[0] = ILITEK_TP_CMD_CALIBRATION;
167 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
169 printk(ILITEK_DEBUG_LEVEL "%s, i2c calibration, failed\n", __func__);
172 printk(ILITEK_DEBUG_LEVEL "%s, i2c calibration, success\n", __func__);
181 static int ilitek_file_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
183 static unsigned char buffer[64]={0};
186 struct i2c_msg msg[2];
188 msg[0].addr = g_ts->client->addr;
189 msg[0].flags = g_ts->client->flags;
192 msg[0].scl_rate = 400*1000;
195 // parsing ioctl command
197 case ILITEK_IOCTL_I2C_WRITE_DATA:
198 ret = copy_from_user(buffer, (unsigned char*)arg, len);
200 printk(ILITEK_ERROR_LEVEL "%s, copy data from user space, failed\n", __func__);
203 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
205 printk(ILITEK_ERROR_LEVEL "%s, i2c write, failed\n", __func__);
210 case ILITEK_IOCTL_I2C_READ_DATA:
211 msg[0].addr = g_ts->client->addr;
212 msg[0].flags = g_ts->client->flags | I2C_M_RD;
215 msg[0].scl_rate = 400*1000;
217 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
219 printk(ILITEK_ERROR_LEVEL "%s, i2c read, failed\n", __func__);
222 ret = copy_to_user((unsigned char*)arg, buffer, len);
224 printk(ILITEK_ERROR_LEVEL "%s, copy data to user space, failed\n", __func__);
228 case ILITEK_IOCTL_I2C_WRITE_LENGTH:
229 case ILITEK_IOCTL_I2C_READ_LENGTH:
232 case ILITEK_IOCTL_I2C_UPDATE_RESOLUTION:
233 case ILITEK_IOCTL_I2C_SET_ADDRESS:
234 case ILITEK_IOCTL_I2C_UPDATE:
236 case ILITEK_IOCTL_START_READ_DATA:
237 //g_ts.stop_polling = 0;
239 case ILITEK_IOCTL_STOP_READ_DATA:
240 //g_ts.stop_polling = 1;
246 printk("%s:cmd=0x%x\n",__FUNCTION__,cmd);
252 static ssize_t ilitek_file_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
258 static int ilitek_file_close(struct inode *inode, struct file *filp)
264 // declare file operations
265 struct file_operations ilitek_fops = {
266 .ioctl = ilitek_file_ioctl,
267 .read = ilitek_file_read,
268 .write = ilitek_file_write,
269 .open = ilitek_file_open,
270 .release = ilitek_file_close,
274 static int verify_coord(struct ili2102_ts_data *ts,unsigned int *x,unsigned int *y)
277 //DBG("%s:(%d/%d)\n",__FUNCTION__,*x, *y);
278 if((*x< ts->x_min) || (*x > ts->x_max))
281 if((*y< ts->y_min) || (*y > ts->y_max))
286 static int ili2102_init_panel(struct ili2102_ts_data *ts)
288 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
292 static void ili2102_ts_work_func(struct work_struct *work)
297 struct i2c_msg msg[2];
299 uint8_t buf[9];//uint32_t buf[4];
300 struct ili2102_ts_data *ts = container_of(work, struct ili2102_ts_data, work);
302 DBG("ili2102_ts_work_func\n");
304 /*Touch Information Report*/
307 msg[0].addr = ts->client->addr;
308 msg[0].flags = ts->client->flags;
310 msg[0].buf = &start_reg;
311 msg[0].scl_rate = 400*1000;
314 msg[1].addr = ts->client->addr;
315 msg[1].flags = ts->client->flags | I2C_M_RD;
318 msg[1].scl_rate = 400*1000;
321 ret = i2c_transfer(ts->client->adapter, msg, 2);
324 printk("%s:i2c_transfer fail, ret=%d\n",__FUNCTION__,ret);
328 for(i=0; i<TOUCH_NUMBER; i++)
331 if(!((buf[0]>>i)&0x01))
333 if (touch_state[i] == TOUCH_DOWN)
335 DBG("ili2102_ts_work_func:buf[%d]=%d\n",i,buf[i]);
336 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0); //Finger Size
337 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0); //Touch Size
338 input_mt_sync(ts->input_dev);
340 touch_state[i] = TOUCH_UP;
349 x = buf[1+(i<<2)] | (buf[2+(i<<2)] << 8);
350 y = buf[3+(i<<2)] | (buf[4+(i<<2)] << 8);
355 if (verify_coord(ts,&x,&y))//goto out;
357 printk("err:x=%d,y=%d\n",x,y);
364 input_event(ts->input_dev, EV_ABS, ABS_MT_TRACKING_ID, i);
365 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1); //Finger Size
366 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
367 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
368 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 5); //Touch Size
369 input_mt_sync(ts->input_dev);
371 touch_state[i] = TOUCH_DOWN;
373 DBG("touch_down i=%d X = %d, Y = %d\n",i, x, y);
380 input_sync(ts->input_dev);
385 schedule_delayed_work(&ts->work, msecs_to_jiffies(10));
391 enable_irq(ts->client->irq);
394 enable_irq(ts->client->irq);//intterupt pin will be high after i2c read so could enable irq at once
396 DBG("pin=%d,level=%d,irq=%d\n\n",irq_to_gpio(ts->client->irq),gpio_get_value(irq_to_gpio(ts->client->irq)),ts->client->irq);
400 static irqreturn_t ili2102_ts_irq_handler(int irq, void *dev_id)
402 struct ili2102_ts_data *ts = dev_id;
403 DBG("ili2102_ts_irq_handler=%d,%d\n",ts->client->irq,ts->use_irq);
405 disable_irq_nosync(ts->client->irq); //disable_irq(ts->client->irq);
406 queue_delayed_work(ts->ts_wq, &ts->work, 0);
410 static int __devinit setup_resetPin(struct i2c_client *client, struct ili2102_ts_data *ts)
412 struct ili2102_platform_data *pdata = client->dev.platform_data;
415 ts->gpio_reset = pdata->gpio_reset;
416 strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
417 ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
418 ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
420 DBG("%s=%d,%s,%d,%d\n",__FUNCTION__,ts->gpio_reset,ts->resetpin_iomux_name,ts->resetpin_iomux_mode,ts->gpio_reset_active_low);
422 if (!gpio_is_valid(ts->gpio_reset)) {
423 dev_err(&client->dev, "no gpio_reset?\n");
427 rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode);
428 err = gpio_request(ts->gpio_reset, "ili2102_resetPin");
430 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
435 //gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
437 err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
439 dev_err(&client->dev, "failed to set resetPin GPIO%d\n",
441 gpio_free(ts->gpio_reset);
447 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
454 static int __devinit setup_pendown(struct i2c_client *client, struct ili2102_ts_data *ts)
457 struct ili2102_platform_data *pdata = client->dev.platform_data;
460 dev_dbg(&client->dev, "no IRQ?\n");
464 if (!gpio_is_valid(pdata->gpio_pendown)) {
465 dev_err(&client->dev, "no gpio_pendown?\n");
469 ts->gpio_pendown = pdata->gpio_pendown;
470 strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
471 ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
473 DBG("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
475 if (!gpio_is_valid(ts->gpio_pendown)) {
476 dev_err(&client->dev, "no gpio_pendown?\n");
480 rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode);
481 err = gpio_request(ts->gpio_pendown, "ili2102_pendown");
483 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
488 err = gpio_pull_updown(ts->gpio_pendown, PullDisable);
490 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
492 gpio_free(ts->gpio_pendown);
498 static int ili2102_chip_Init(struct i2c_client *client)
503 struct i2c_msg msg[2];
505 /* get panel information:6bytes */
507 msg[0].addr =client->addr;
508 msg[0].flags = client->flags;
510 msg[0].buf = &start_reg;
511 msg[0].scl_rate = 400*1000;
514 ret = i2c_transfer(client->adapter, msg, 1);
516 printk("%s:err\n",__FUNCTION__);
519 mdelay(5);//tp need delay
521 msg[0].addr = client->addr;
522 msg[0].flags = client->flags |I2C_M_RD;
524 msg[0].buf = (u8*)&buf[0];
525 msg[0].scl_rate = 400*1000;
528 ret = i2c_transfer(client->adapter, msg, 1);
530 printk("%s:err\n",__FUNCTION__);
533 printk("%s:max_x=%d,max_y=%d,b[4]=0x%x,b[5]=0x%x\n",
534 __FUNCTION__,buf[0]|(buf[1]<<8),buf[2]|(buf[3]<<8),buf[4],buf[5]);
536 /*get firmware version:3bytes */
538 msg[0].addr =client->addr;
539 msg[0].flags = client->flags;
541 msg[0].buf = &start_reg;
542 msg[0].scl_rate = 400*1000;
545 ret = i2c_transfer(client->adapter, msg, 1);
547 printk("%s:err\n",__FUNCTION__);
550 mdelay(5);//tp need delay
552 msg[0].addr = client->addr;
553 msg[0].flags = client->flags | I2C_M_RD;
555 msg[0].buf = (u8*)&buf[0];
556 msg[0].scl_rate =400*1000;
559 ret = i2c_transfer(client->adapter, msg, 1);
561 printk("%s:err\n",__FUNCTION__);
564 printk("%s:Ver %d.%d.%d\n",__FUNCTION__,buf[0],buf[1],buf[2]);
570 static int ili2102_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
572 struct ili2102_ts_data *ts;
573 struct ili2102_platform_data *pdata = client->dev.platform_data;
576 printk("ili2102 TS probe\n");
578 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
579 printk(KERN_ERR "ili2102_ts_probe: need I2C_FUNC_I2C\n");
581 goto err_check_functionality_failed;
584 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
587 goto err_alloc_data_failed;
590 ts->ts_wq = create_singlethread_workqueue("ts_wq");
593 printk("%s:fail to create ts_wq,ret=0x%x\n",__FUNCTION__, ENOMEM);
596 //INIT_WORK(&ts->work, ili2102_ts_work_func);
597 INIT_DELAYED_WORK(&ts->work, ili2102_ts_work_func);
599 i2c_set_clientdata(client, ts);
601 ret = setup_resetPin(client,ts);
604 printk("ili2102 TS setup_resetPin fail\n");
605 goto err_alloc_data_failed;
608 ret=ili2102_chip_Init(ts->client);
611 printk("%s:chips init failed\n",__FUNCTION__);
612 goto err_resetpin_failed;
615 /* allocate input device */
616 ts->input_dev = input_allocate_device();
617 if (ts->input_dev == NULL) {
619 printk(KERN_ERR "ili2102_ts_probe: Failed to allocate input device\n");
620 goto err_input_dev_alloc_failed;
623 ts->model = pdata->model ? : 801;
624 ts->swap_xy = pdata->swap_xy;
625 ts->x_min = pdata->x_min;
626 ts->x_max = pdata->x_max;
627 ts->y_min = pdata->y_min;
628 ts->y_max = pdata->y_max;
629 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));
630 snprintf(ts->name, sizeof(ts->name), "ili%d-touchscreen", ts->model);
631 ts->input_dev->phys = ts->phys;
632 ts->input_dev->name = ts->name;
633 ts->input_dev->dev.parent = &client->dev;
635 ts->valid_i2c_register = 1;
637 ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS);
638 //ts->input_dev->absbit[0] =
639 //BIT(ABS_MT_POSITION_X) | BIT(ABS_MT_POSITION_Y) |
640 //BIT(ABS_MT_TOUCH_MAJOR) | BIT(ABS_MT_WIDTH_MAJOR); // for android
641 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X,
645 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,
649 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0); //Finger Size
650 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 10, 0, 0); //Touch Size
652 /* ts->input_dev->name = ts->keypad_info->name; */
653 ret = input_register_device(ts->input_dev);
655 printk(KERN_ERR "ili2102_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
656 goto err_input_register_device_failed;
659 client->irq = gpio_to_irq(client->irq);
662 ret = setup_pendown(client,ts);
665 printk("ili2102 TS setup_pendown fail\n");
666 goto err_input_register_device_failed;
669 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, client->name, ts);
671 DBG("ili2102 TS register ISR (irq=%d)\n", client->irq);
675 dev_err(&client->dev, "request_irq failed\n");
678 #if ILI2102_TS_APK_SUPPORT
679 // initialize global variable
681 memset(&g_dev, 0, sizeof(struct dev_data));
683 // allocate character device driver buffer
684 ret = alloc_chrdev_region(&g_dev.devno, 0, 1, ILITEK_FILE_DRIVER_NAME);
686 printk(ILITEK_ERROR_LEVEL "%s, can't allocate chrdev\n", __func__);
689 printk(ILITEK_DEBUG_LEVEL "%s, register chrdev(%d, %d)\n", __func__, MAJOR(g_dev.devno), MINOR(g_dev.devno));
691 // initialize character device driver
692 cdev_init(&g_dev.cdev, &ilitek_fops);
693 g_dev.cdev.owner = THIS_MODULE;
694 ret = cdev_add(&g_dev.cdev, g_dev.devno, 1);
696 printk(ILITEK_ERROR_LEVEL "%s, add character device error, ret %d\n", __func__, ret);
699 g_dev.class = class_create(THIS_MODULE, ILITEK_FILE_DRIVER_NAME);
700 if(IS_ERR(g_dev.class)){
701 printk(ILITEK_ERROR_LEVEL "%s, create class, error\n", __func__);
704 device_create(g_dev.class, NULL, g_dev.devno, NULL, "ilitek_ctrl");
707 #ifdef CONFIG_HAS_EARLYSUSPEND
708 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
709 ts->early_suspend.suspend = ili2102_ts_early_suspend;
710 ts->early_suspend.resume = ili2102_ts_late_resume;
711 register_early_suspend(&ts->early_suspend);
714 printk(KERN_INFO "ili2102_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
718 err_input_register_device_failed:
719 input_free_device(ts->input_dev);
721 gpio_free(ts->gpio_reset);
722 err_input_dev_alloc_failed:
724 err_alloc_data_failed:
725 err_check_functionality_failed:
729 static int ili2102_ts_remove(struct i2c_client *client)
731 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
732 unregister_early_suspend(&ts->early_suspend);
734 free_irq(client->irq, ts);
736 hrtimer_cancel(&ts->timer);
737 input_unregister_device(ts->input_dev);
739 cancel_delayed_work_sync(&ts->work);
742 #if ILI2102_TS_APK_SUPPORT
743 // delete character device driver
744 cdev_del(&g_dev.cdev);
745 unregister_chrdev_region(g_dev.devno, 1);
746 device_destroy(g_dev.class, g_dev.devno);
747 class_destroy(g_dev.class);
753 static int ili2102_ts_suspend(struct i2c_client *client, pm_message_t mesg)
756 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
757 uint8_t buf[1] = {0x30};
758 struct i2c_msg msg[1];
762 free_irq(client->irq, ts);
763 //change irq type to IRQF_TRIGGER_FALLING to avoid system death
764 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, client->name, ts);
766 disable_irq_nosync(client->irq);
770 printk("%s:request irq=%d failed,ret=%d\n",__FUNCTION__, ts->client->irq, ret);
773 hrtimer_cancel(&ts->timer);
775 ret = cancel_delayed_work_sync(&ts->work);
776 //if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
777 //enable_irq(client->irq);
780 msg[0].addr =client->addr;
785 ret = i2c_transfer(client->adapter, msg, 1);
787 printk("%s:err\n",__FUNCTION__);
790 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
792 DBG("%s\n",__FUNCTION__);
798 static void ili2102_ts_resume_work_func(struct work_struct *work)
800 struct ili2102_ts_data *ts = container_of(work, struct ili2102_ts_data, work);
802 mdelay(100); //wait for 100ms before i2c operation
803 free_irq(ts->client->irq, ts);
804 ret = request_irq(ts->client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, ts->client->name, ts);
807 //enable_irq(ts->client->irq);
810 printk("%s:request irq=%d failed,ret=%d\n",__FUNCTION__,ts->client->irq,ret);
812 PREPARE_DELAYED_WORK(&ts->work, ili2102_ts_work_func);
813 printk("%s,irq=%d\n",__FUNCTION__,ts->client->irq);
817 static int ili2102_ts_resume(struct i2c_client *client)
819 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
821 ili2102_init_panel(ts);
824 if(!delayed_work_pending(&ts->work)){
825 PREPARE_DELAYED_WORK(&ts->work, ili2102_ts_resume_work_func);
826 queue_delayed_work(ts->ts_wq, &ts->work, 0);
830 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
833 DBG("%s\n",__FUNCTION__);
839 #ifdef CONFIG_HAS_EARLYSUSPEND
840 static void ili2102_ts_early_suspend(struct early_suspend *h)
842 struct ili2102_ts_data *ts;
843 ts = container_of(h, struct ili2102_ts_data, early_suspend);
844 ili2102_ts_suspend(ts->client, PMSG_SUSPEND);
847 static void ili2102_ts_late_resume(struct early_suspend *h)
849 struct ili2102_ts_data *ts;
850 ts = container_of(h, struct ili2102_ts_data, early_suspend);
851 ili2102_ts_resume(ts->client);
855 #define ILI2102_TS_NAME "ili2102_ts"
857 static const struct i2c_device_id ili2102_ts_id[] = {
858 { ILI2102_TS_NAME, 0 },
862 static struct i2c_driver ili2102_ts_driver = {
863 .probe = ili2102_ts_probe,
864 .remove = ili2102_ts_remove,
865 #ifndef CONFIG_HAS_EARLYSUSPEND
866 .suspend = ili2102_ts_early_suspend,
867 .resume = ili2102_ts_late_resume,
869 .id_table = ili2102_ts_id,
871 .name = ILI2102_TS_NAME,
875 static int __devinit ili2102_ts_init(void)
877 return i2c_add_driver(&ili2102_ts_driver);
880 static void __exit ili2102_ts_exit(void)
882 i2c_del_driver(&ili2102_ts_driver);
885 module_init(ili2102_ts_init);
886 module_exit(ili2102_ts_exit);
888 MODULE_DESCRIPTION("ili2102 Touchscreen Driver");
889 MODULE_LICENSE("GPL");