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_LOW:GPIO_HIGH);
290 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
294 static void ili2102_ts_work_func(struct work_struct *work)
299 struct i2c_msg msg[2];
301 uint8_t buf[9];//uint32_t buf[4];
302 struct ili2102_ts_data *ts = container_of(work, struct ili2102_ts_data, work);
304 DBG("ili2102_ts_work_func\n");
306 /*Touch Information Report*/
309 msg[0].addr = ts->client->addr;
310 msg[0].flags = ts->client->flags;
312 msg[0].buf = &start_reg;
313 msg[0].scl_rate = 400*1000;
316 msg[1].addr = ts->client->addr;
317 msg[1].flags = ts->client->flags | I2C_M_RD;
320 msg[1].scl_rate = 400*1000;
323 ret = i2c_transfer(ts->client->adapter, msg, 2);
326 printk("%s:i2c_transfer fail, ret=%d\n",__FUNCTION__,ret);
330 for(i=0; i<TOUCH_NUMBER; i++)
333 if(!((buf[0]>>i)&0x01))
335 if (touch_state[i] == TOUCH_DOWN)
337 DBG("ili2102_ts_work_func:buf[%d]=%d\n",i,buf[i]);
338 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0); //Finger Size
339 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0); //Touch Size
340 input_mt_sync(ts->input_dev);
342 touch_state[i] = TOUCH_UP;
351 x = buf[1+(i<<2)] | (buf[2+(i<<2)] << 8);
352 y = buf[3+(i<<2)] | (buf[4+(i<<2)] << 8);
357 if (verify_coord(ts,&x,&y))//goto out;
359 printk("err:x=%d,y=%d\n",x,y);
366 input_event(ts->input_dev, EV_ABS, ABS_MT_TRACKING_ID, i);
367 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1); //Finger Size
368 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
369 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
370 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 5); //Touch Size
371 input_mt_sync(ts->input_dev);
373 touch_state[i] = TOUCH_DOWN;
375 DBG("touch_down i=%d X = %d, Y = %d\n",i, x, y);
382 input_sync(ts->input_dev);
387 schedule_delayed_work(&ts->work, msecs_to_jiffies(10));
393 enable_irq(ts->client->irq);
396 enable_irq(ts->client->irq);//intterupt pin will be high after i2c read so could enable irq at once
398 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);
402 static irqreturn_t ili2102_ts_irq_handler(int irq, void *dev_id)
404 struct ili2102_ts_data *ts = dev_id;
405 DBG("ili2102_ts_irq_handler=%d,%d\n",ts->client->irq,ts->use_irq);
407 disable_irq_nosync(ts->client->irq); //disable_irq(ts->client->irq);
408 queue_delayed_work(ts->ts_wq, &ts->work, 0);
412 static int __devinit setup_resetPin(struct i2c_client *client, struct ili2102_ts_data *ts)
414 struct ili2102_platform_data *pdata = client->dev.platform_data;
417 ts->gpio_reset = pdata->gpio_reset;
418 strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
419 ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
420 ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
422 DBG("%s=%d,%s,%d,%d\n",__FUNCTION__,ts->gpio_reset,ts->resetpin_iomux_name,ts->resetpin_iomux_mode,ts->gpio_reset_active_low);
424 if (!gpio_is_valid(ts->gpio_reset)) {
425 dev_err(&client->dev, "no gpio_reset?\n");
429 rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode);
430 err = gpio_request(ts->gpio_reset, "ili2102_resetPin");
432 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
437 //gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
439 err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
441 dev_err(&client->dev, "failed to set resetPin GPIO%d\n",
443 gpio_free(ts->gpio_reset);
449 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
456 static int __devinit setup_pendown(struct i2c_client *client, struct ili2102_ts_data *ts)
459 struct ili2102_platform_data *pdata = client->dev.platform_data;
462 dev_dbg(&client->dev, "no IRQ?\n");
466 if (!gpio_is_valid(pdata->gpio_pendown)) {
467 dev_err(&client->dev, "no gpio_pendown?\n");
471 ts->gpio_pendown = pdata->gpio_pendown;
472 strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
473 ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
475 DBG("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
477 if (!gpio_is_valid(ts->gpio_pendown)) {
478 dev_err(&client->dev, "no gpio_pendown?\n");
482 rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode);
483 err = gpio_request(ts->gpio_pendown, "ili2102_pendown");
485 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
490 err = gpio_pull_updown(ts->gpio_pendown, PullDisable);
492 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
494 gpio_free(ts->gpio_pendown);
500 static int ili2102_chip_Init(struct i2c_client *client)
505 struct i2c_msg msg[2];
507 /* get panel information:6bytes */
509 msg[0].addr =client->addr;
510 msg[0].flags = client->flags;
512 msg[0].buf = &start_reg;
513 msg[0].scl_rate = 400*1000;
516 ret = i2c_transfer(client->adapter, msg, 1);
518 printk("%s:err\n",__FUNCTION__);
521 mdelay(5);//tp need delay
523 msg[0].addr = client->addr;
524 msg[0].flags = client->flags |I2C_M_RD;
526 msg[0].buf = (u8*)&buf[0];
527 msg[0].scl_rate = 400*1000;
530 ret = i2c_transfer(client->adapter, msg, 1);
532 printk("%s:err\n",__FUNCTION__);
535 printk("%s:max_x=%d,max_y=%d,b[4]=0x%x,b[5]=0x%x\n",
536 __FUNCTION__,buf[0]|(buf[1]<<8),buf[2]|(buf[3]<<8),buf[4],buf[5]);
538 /*get firmware version:3bytes */
540 msg[0].addr =client->addr;
541 msg[0].flags = client->flags;
543 msg[0].buf = &start_reg;
544 msg[0].scl_rate = 400*1000;
547 ret = i2c_transfer(client->adapter, msg, 1);
549 printk("%s:err\n",__FUNCTION__);
552 mdelay(5);//tp need delay
554 msg[0].addr = client->addr;
555 msg[0].flags = client->flags | I2C_M_RD;
557 msg[0].buf = (u8*)&buf[0];
558 msg[0].scl_rate =400*1000;
561 ret = i2c_transfer(client->adapter, msg, 1);
563 printk("%s:err\n",__FUNCTION__);
566 printk("%s:Ver %d.%d.%d\n",__FUNCTION__,buf[0],buf[1],buf[2]);
572 static int ili2102_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
574 struct ili2102_ts_data *ts;
575 struct ili2102_platform_data *pdata = client->dev.platform_data;
578 printk("ili2102 TS probe\n");
580 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
581 printk(KERN_ERR "ili2102_ts_probe: need I2C_FUNC_I2C\n");
583 goto err_check_functionality_failed;
586 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
589 goto err_alloc_data_failed;
592 ts->ts_wq = create_singlethread_workqueue("ts_wq");
595 printk("%s:fail to create ts_wq,ret=0x%x\n",__FUNCTION__, ENOMEM);
598 //INIT_WORK(&ts->work, ili2102_ts_work_func);
599 INIT_DELAYED_WORK(&ts->work, ili2102_ts_work_func);
601 i2c_set_clientdata(client, ts);
603 ret = setup_resetPin(client,ts);
606 printk("ili2102 TS setup_resetPin fail\n");
607 goto err_alloc_data_failed;
610 ret=ili2102_chip_Init(ts->client);
613 printk("%s:chips init failed\n",__FUNCTION__);
614 goto err_resetpin_failed;
617 /* allocate input device */
618 ts->input_dev = input_allocate_device();
619 if (ts->input_dev == NULL) {
621 printk(KERN_ERR "ili2102_ts_probe: Failed to allocate input device\n");
622 goto err_input_dev_alloc_failed;
625 ts->model = pdata->model ? : 801;
626 ts->swap_xy = pdata->swap_xy;
627 ts->x_min = pdata->x_min;
628 ts->x_max = pdata->x_max;
629 ts->y_min = pdata->y_min;
630 ts->y_max = pdata->y_max;
631 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));
632 snprintf(ts->name, sizeof(ts->name), "ili%d-touchscreen", ts->model);
633 ts->input_dev->phys = ts->phys;
634 ts->input_dev->name = ts->name;
635 ts->input_dev->dev.parent = &client->dev;
637 ts->valid_i2c_register = 1;
639 ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS);
640 //ts->input_dev->absbit[0] =
641 //BIT(ABS_MT_POSITION_X) | BIT(ABS_MT_POSITION_Y) |
642 //BIT(ABS_MT_TOUCH_MAJOR) | BIT(ABS_MT_WIDTH_MAJOR); // for android
643 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X,
647 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,
651 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0); //Finger Size
652 input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 10, 0, 0); //Touch Size
654 /* ts->input_dev->name = ts->keypad_info->name; */
655 ret = input_register_device(ts->input_dev);
657 printk(KERN_ERR "ili2102_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
658 goto err_input_register_device_failed;
661 client->irq = gpio_to_irq(client->irq);
664 ret = setup_pendown(client,ts);
667 printk("ili2102 TS setup_pendown fail\n");
668 goto err_input_register_device_failed;
671 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, client->name, ts);
673 DBG("ili2102 TS register ISR (irq=%d)\n", client->irq);
677 dev_err(&client->dev, "request_irq failed\n");
680 #if ILI2102_TS_APK_SUPPORT
681 // initialize global variable
683 memset(&g_dev, 0, sizeof(struct dev_data));
685 // allocate character device driver buffer
686 ret = alloc_chrdev_region(&g_dev.devno, 0, 1, ILITEK_FILE_DRIVER_NAME);
688 printk(ILITEK_ERROR_LEVEL "%s, can't allocate chrdev\n", __func__);
691 printk(ILITEK_DEBUG_LEVEL "%s, register chrdev(%d, %d)\n", __func__, MAJOR(g_dev.devno), MINOR(g_dev.devno));
693 // initialize character device driver
694 cdev_init(&g_dev.cdev, &ilitek_fops);
695 g_dev.cdev.owner = THIS_MODULE;
696 ret = cdev_add(&g_dev.cdev, g_dev.devno, 1);
698 printk(ILITEK_ERROR_LEVEL "%s, add character device error, ret %d\n", __func__, ret);
701 g_dev.class = class_create(THIS_MODULE, ILITEK_FILE_DRIVER_NAME);
702 if(IS_ERR(g_dev.class)){
703 printk(ILITEK_ERROR_LEVEL "%s, create class, error\n", __func__);
706 device_create(g_dev.class, NULL, g_dev.devno, NULL, "ilitek_ctrl");
709 #ifdef CONFIG_HAS_EARLYSUSPEND
710 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
711 ts->early_suspend.suspend = ili2102_ts_early_suspend;
712 ts->early_suspend.resume = ili2102_ts_late_resume;
713 register_early_suspend(&ts->early_suspend);
716 printk(KERN_INFO "ili2102_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
720 err_input_register_device_failed:
721 input_free_device(ts->input_dev);
723 gpio_free(ts->gpio_reset);
724 err_input_dev_alloc_failed:
726 err_alloc_data_failed:
727 err_check_functionality_failed:
731 static int ili2102_ts_remove(struct i2c_client *client)
733 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
734 unregister_early_suspend(&ts->early_suspend);
736 free_irq(client->irq, ts);
738 hrtimer_cancel(&ts->timer);
739 input_unregister_device(ts->input_dev);
741 cancel_delayed_work_sync(&ts->work);
744 #if ILI2102_TS_APK_SUPPORT
745 // delete character device driver
746 cdev_del(&g_dev.cdev);
747 unregister_chrdev_region(g_dev.devno, 1);
748 device_destroy(g_dev.class, g_dev.devno);
749 class_destroy(g_dev.class);
755 static int ili2102_ts_suspend(struct i2c_client *client, pm_message_t mesg)
758 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
759 uint8_t buf[1] = {0x30};
760 struct i2c_msg msg[1];
764 free_irq(client->irq, ts);
765 //change irq type to IRQF_TRIGGER_FALLING to avoid system death
766 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, client->name, ts);
768 disable_irq_nosync(client->irq);
772 printk("%s:request irq=%d failed,ret=%d\n",__FUNCTION__, ts->client->irq, ret);
775 hrtimer_cancel(&ts->timer);
777 ret = cancel_delayed_work_sync(&ts->work);
778 //if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
779 //enable_irq(client->irq);
782 msg[0].addr =client->addr;
787 ret = i2c_transfer(client->adapter, msg, 1);
789 printk("%s:err\n",__FUNCTION__);
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");