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>
18 #include <linux/proc_fs.h>
19 #include <linux/input/mt.h>
20 #include "ili2102_ts.h"
22 static int ts_dbg_enable = 0;
25 ({if(ts_dbg_enable == 1) printk(msg);})
27 #define TOUCH_NUMBER 2
29 static volatile int touch_state[TOUCH_NUMBER] = {TOUCH_UP,TOUCH_UP};
30 static volatile unsigned int g_x[TOUCH_NUMBER] = {0},g_y[TOUCH_NUMBER] = {0};
32 struct ili2102_ts_data {
34 bool swap_xy; /* swap x and y axes */
42 int gpio_reset_active_low;
43 int pendown_iomux_mode;
44 int resetpin_iomux_mode;
45 char pendown_iomux_name[IOMUX_NAME_SIZE];
46 char resetpin_iomux_name[IOMUX_NAME_SIZE];
49 int valid_i2c_register;
50 struct i2c_client *client;
51 struct input_dev *input_dev;
53 struct delayed_work work;
54 struct workqueue_struct *ts_wq;
55 struct early_suspend early_suspend;
58 #ifdef CONFIG_HAS_EARLYSUSPEND
59 static void ili2102_ts_early_suspend(struct early_suspend *h);
60 static void ili2102_ts_late_resume(struct early_suspend *h);
63 #define ILI2102_TS_APK_SUPPORT 1
65 #if ILI2102_TS_APK_SUPPORT
77 static struct ili2102_ts_data *g_ts;
78 static struct dev_data g_dev;
81 #define ILITEK_I2C_RETRY_COUNT 3
82 #define ILITEK_FILE_DRIVER_NAME "ilitek_file"
83 #define ILITEK_DEBUG_LEVEL KERN_INFO
84 #define ILITEK_ERROR_LEVEL KERN_ALERT
86 // i2c command for ilitek touch screen
87 #define ILITEK_TP_CMD_READ_DATA 0x10
88 #define ILITEK_TP_CMD_READ_SUB_DATA 0x11
89 #define ILITEK_TP_CMD_GET_RESOLUTION 0x20
90 #define ILITEK_TP_CMD_GET_FIRMWARE_VERSION 0x40
91 #define ILITEK_TP_CMD_GET_PROTOCOL_VERSION 0x42
92 #define ILITEK_TP_CMD_CALIBRATION 0xCC
93 #define ILITEK_TP_CMD_ERASE_BACKGROUND 0xCE
95 // define the application command
96 #define ILITEK_IOCTL_BASE 100
97 #define ILITEK_IOCTL_I2C_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 0, unsigned char*)
98 #define ILITEK_IOCTL_I2C_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 1, int)
99 #define ILITEK_IOCTL_I2C_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 2, unsigned char*)
100 #define ILITEK_IOCTL_I2C_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 3, int)
101 #define ILITEK_IOCTL_USB_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 4, unsigned char*)
102 #define ILITEK_IOCTL_USB_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 5, int)
103 #define ILITEK_IOCTL_USB_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 6, unsigned char*)
104 #define ILITEK_IOCTL_USB_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 7, int)
105 #define ILITEK_IOCTL_I2C_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 8, int)
106 #define ILITEK_IOCTL_USB_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 9, int)
107 #define ILITEK_IOCTL_I2C_SET_ADDRESS _IOWR(ILITEK_IOCTL_BASE, 10, int)
108 #define ILITEK_IOCTL_I2C_UPDATE _IOWR(ILITEK_IOCTL_BASE, 11, int)
109 #define ILITEK_IOCTL_STOP_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 12, int)
110 #define ILITEK_IOCTL_START_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 13, int)
113 static ssize_t ili2102_proc_write(struct file *file, const char __user *buffer,
114 unsigned long count, void *data)
119 rc = get_user(c, buffer);
131 static const struct file_operations ili2102_proc_fops = {
132 .owner = THIS_MODULE,
133 .write = ili2102_proc_write,
136 static int ilitek_file_open(struct inode *inode, struct file *filp)
141 static ssize_t ilitek_file_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos)
144 unsigned char buffer[128]={0};
145 struct i2c_msg msg[2];
147 msg[0].addr = g_ts->client->addr;
148 msg[0].flags = g_ts->client->flags;
151 msg[0].scl_rate = 400*1000;
154 DBG("%s:count=0x%x\n",__FUNCTION__,count);
156 // before sending data to touch device, we need to check whether the device is working or not
157 if(g_ts->valid_i2c_register == 0){
158 printk(ILITEK_ERROR_LEVEL "%s, i2c device driver doesn't be registered\n", __func__);
162 // check the buffer size whether it exceeds the local buffer size or not
164 printk(ILITEK_ERROR_LEVEL "%s, buffer exceed 128 bytes\n", __func__);
168 // copy data from user space
169 ret = copy_from_user(buffer, buf, count-1);
171 printk(ILITEK_ERROR_LEVEL "%s, copy data from user space, failed", __func__);
176 if(strcmp(buffer, "calibrate") == 0){
177 buffer[0] = ILITEK_TP_CMD_ERASE_BACKGROUND;
179 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
181 printk(ILITEK_DEBUG_LEVEL "%s, i2c erase background, failed\n", __func__);
184 printk(ILITEK_DEBUG_LEVEL "%s, i2c erase background, success\n", __func__);
187 buffer[0] = ILITEK_TP_CMD_CALIBRATION;
190 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
192 printk(ILITEK_DEBUG_LEVEL "%s, i2c calibration, failed\n", __func__);
195 printk(ILITEK_DEBUG_LEVEL "%s, i2c calibration, success\n", __func__);
204 //static int ilitek_file_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
205 long ilitek_file_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
208 static unsigned char buffer[64]={0};
211 struct i2c_msg msg[2];
213 msg[0].addr = g_ts->client->addr;
214 msg[0].flags = g_ts->client->flags;
217 msg[0].scl_rate = 400*1000;
220 // parsing ioctl command
222 case ILITEK_IOCTL_I2C_WRITE_DATA:
223 ret = copy_from_user(buffer, (unsigned char*)arg, len);
225 printk(ILITEK_ERROR_LEVEL "%s, copy data from user space, failed\n", __func__);
228 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
230 printk(ILITEK_ERROR_LEVEL "%s, i2c write, failed\n", __func__);
235 case ILITEK_IOCTL_I2C_READ_DATA:
236 msg[0].addr = g_ts->client->addr;
237 msg[0].flags = g_ts->client->flags | I2C_M_RD;
240 msg[0].scl_rate = 400*1000;
242 ret = i2c_transfer(g_ts->client->adapter, msg, 1);
244 printk(ILITEK_ERROR_LEVEL "%s, i2c read, failed\n", __func__);
247 ret = copy_to_user((unsigned char*)arg, buffer, len);
249 printk(ILITEK_ERROR_LEVEL "%s, copy data to user space, failed\n", __func__);
253 case ILITEK_IOCTL_I2C_WRITE_LENGTH:
254 case ILITEK_IOCTL_I2C_READ_LENGTH:
257 case ILITEK_IOCTL_I2C_UPDATE_RESOLUTION:
258 case ILITEK_IOCTL_I2C_SET_ADDRESS:
259 case ILITEK_IOCTL_I2C_UPDATE:
261 case ILITEK_IOCTL_START_READ_DATA:
262 //g_ts.stop_polling = 0;
264 case ILITEK_IOCTL_STOP_READ_DATA:
265 //g_ts.stop_polling = 1;
271 DBG("%s:cmd=0x%x\n",__FUNCTION__,cmd);
277 static ssize_t ilitek_file_read(struct file *filp, char *buf, size_t count, loff_t *f_pos)
283 static int ilitek_file_close(struct inode *inode, struct file *filp)
289 // declare file operations
290 struct file_operations ilitek_fops = {
291 .unlocked_ioctl = ilitek_file_ioctl,
292 .read = ilitek_file_read,
293 .write = ilitek_file_write,
294 .open = ilitek_file_open,
295 .release = ilitek_file_close,
299 static int verify_coord(struct ili2102_ts_data *ts,unsigned int *x,unsigned int *y)
302 //DBG("%s:(%d/%d)\n",__FUNCTION__,*x, *y);
303 #ifndef CONFIG_MACH_RK29_TD8801_V2
304 if((*x< ts->x_min) || (*x > ts->x_max))
307 if((*y< ts->y_min) || (*y > ts->y_max))
311 /*android do not support min and max value*/
324 static int ili2102_init_panel(struct ili2102_ts_data *ts)
326 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
328 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
332 static void ili2102_ts_work_func(struct work_struct *work)
337 struct i2c_msg msg[2];
339 uint8_t buf[9];//uint32_t buf[4];
340 struct ili2102_ts_data *ts = container_of(work, struct ili2102_ts_data, work);
342 DBG("ili2102_ts_work_func\n");
344 /*Touch Information Report*/
347 msg[0].addr = ts->client->addr;
348 msg[0].flags = ts->client->flags;
350 msg[0].buf = &start_reg;
351 msg[0].scl_rate = 200*1000;
354 msg[1].addr = ts->client->addr;
355 msg[1].flags = ts->client->flags | I2C_M_RD;
358 msg[1].scl_rate = 200*1000;
361 ret = i2c_transfer(ts->client->adapter, msg, 2);
364 printk("%s:i2c_transfer fail, ret=%d\n",__FUNCTION__,ret);
368 for(i=0; i<TOUCH_NUMBER; i++)
371 if(!((buf[0]>>i)&0x01))
373 if (touch_state[i] == TOUCH_DOWN)
375 DBG("ili2102_ts_work_func:buf[%d]=%d\n",i,buf[i]);
376 //input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
377 //input_report_abs(ts->input_dev, ABS_MT_PRESSURE, 0);
378 input_mt_slot(ts->input_dev, i);
379 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);
381 touch_state[i] = TOUCH_UP;
382 DBG("i=%d,touch_up \n",i);
390 x = buf[1+(i<<2)] | (buf[2+(i<<2)] << 8);
391 y = buf[3+(i<<2)] | (buf[4+(i<<2)] << 8);
396 if (verify_coord(ts,&x,&y))//goto out;
398 printk("err:x=%d,y=%d\n",x,y);
402 #ifdef CONFIG_MACH_RK29_TD8801_V2
410 input_mt_slot(ts->input_dev, i);
411 input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);
412 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);
413 //input_report_abs(ts->input_dev, ABS_MT_PRESSURE, 100);
414 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
415 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);
418 touch_state[i] = TOUCH_DOWN;
420 DBG("touch_down i=%d X = %d, Y = %d\n",i, x, y);
427 input_sync(ts->input_dev);
432 schedule_delayed_work(&ts->work, msecs_to_jiffies(12));
438 enable_irq(ts->client->irq);
441 enable_irq(ts->client->irq);//intterupt pin will be high after i2c read so could enable irq at once
443 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);
447 static irqreturn_t ili2102_ts_irq_handler(int irq, void *dev_id)
449 struct ili2102_ts_data *ts = dev_id;
450 DBG("ili2102_ts_irq_handler=%d,%d\n",ts->client->irq,ts->use_irq);
452 disable_irq_nosync(ts->client->irq); //disable_irq(ts->client->irq);
453 queue_delayed_work(ts->ts_wq, &ts->work, 0);
457 static int __devinit setup_resetPin(struct i2c_client *client, struct ili2102_ts_data *ts)
459 struct ili2102_platform_data *pdata = client->dev.platform_data;
462 ts->gpio_reset = pdata->gpio_reset;
463 strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
464 ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
465 ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
467 DBG("%s=%d,%s,%d,%d\n",__FUNCTION__,ts->gpio_reset,ts->resetpin_iomux_name,ts->resetpin_iomux_mode,ts->gpio_reset_active_low);
469 if (!gpio_is_valid(ts->gpio_reset)) {
470 dev_err(&client->dev, "no gpio_reset?\n");
474 rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode);
475 err = gpio_request(ts->gpio_reset, "ili2102_resetPin");
477 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
482 //gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
484 err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
486 dev_err(&client->dev, "failed to set resetPin GPIO%d\n",
488 gpio_free(ts->gpio_reset);
494 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
501 static int __devinit setup_pendown(struct i2c_client *client, struct ili2102_ts_data *ts)
504 struct ili2102_platform_data *pdata = client->dev.platform_data;
507 dev_dbg(&client->dev, "no IRQ?\n");
511 if (!gpio_is_valid(pdata->gpio_pendown)) {
512 dev_err(&client->dev, "no gpio_pendown?\n");
516 ts->gpio_pendown = pdata->gpio_pendown;
517 strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
518 ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
520 DBG("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
522 if (!gpio_is_valid(ts->gpio_pendown)) {
523 dev_err(&client->dev, "no gpio_pendown?\n");
527 rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode);
528 err = gpio_request(ts->gpio_pendown, "ili2102_pendown");
530 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
535 err = gpio_pull_updown(ts->gpio_pendown, PullDisable);
537 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
539 gpio_free(ts->gpio_pendown);
545 static int ili2102_chip_Init(struct i2c_client *client)
550 struct i2c_msg msg[2];
552 /* get panel information:6bytes */
554 msg[0].addr =client->addr;
555 msg[0].flags = client->flags;
557 msg[0].buf = &start_reg;
558 msg[0].scl_rate = 400*1000;
561 ret = i2c_transfer(client->adapter, msg, 1);
563 printk("%s:err\n",__FUNCTION__);
566 mdelay(5);//tp need delay
568 msg[0].addr = client->addr;
569 msg[0].flags = client->flags |I2C_M_RD;
571 msg[0].buf = (u8*)&buf[0];
572 msg[0].scl_rate = 400*1000;
575 ret = i2c_transfer(client->adapter, msg, 1);
577 printk("%s:err\n",__FUNCTION__);
580 printk("%s:max_x=%d,max_y=%d,b[4]=0x%x,b[5]=0x%x\n",
581 __FUNCTION__,buf[0]|(buf[1]<<8),buf[2]|(buf[3]<<8),buf[4],buf[5]);
583 /*get firmware version:3bytes */
585 msg[0].addr =client->addr;
586 msg[0].flags = client->flags;
588 msg[0].buf = &start_reg;
589 msg[0].scl_rate = 400*1000;
592 ret = i2c_transfer(client->adapter, msg, 1);
594 printk("%s:err\n",__FUNCTION__);
597 mdelay(5);//tp need delay
599 msg[0].addr = client->addr;
600 msg[0].flags = client->flags | I2C_M_RD;
602 msg[0].buf = (u8*)&buf[0];
603 msg[0].scl_rate =400*1000;
606 ret = i2c_transfer(client->adapter, msg, 1);
608 printk("%s:err\n",__FUNCTION__);
611 printk("%s:Ver %d.%d.%d\n",__FUNCTION__,buf[0],buf[1],buf[2]);
617 static int ili2102_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
619 struct ili2102_ts_data *ts;
620 struct ili2102_platform_data *pdata = client->dev.platform_data;
623 printk("ili2102 TS probe\n");
625 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
626 printk(KERN_ERR "ili2102_ts_probe: need I2C_FUNC_I2C\n");
628 goto err_check_functionality_failed;
631 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
634 goto err_alloc_data_failed;
637 ts->ts_wq = create_singlethread_workqueue("ts_wq");
640 printk("%s:fail to create ts_wq,ret=0x%x\n",__FUNCTION__, ENOMEM);
643 //INIT_WORK(&ts->work, ili2102_ts_work_func);
644 INIT_DELAYED_WORK(&ts->work, ili2102_ts_work_func);
646 i2c_set_clientdata(client, ts);
648 ret = setup_resetPin(client,ts);
651 printk("ili2102 TS setup_resetPin fail\n");
652 goto err_alloc_data_failed;
655 ret=ili2102_chip_Init(ts->client);
658 printk("%s:chips init failed\n",__FUNCTION__);
659 goto err_resetpin_failed;
662 /* allocate input device */
663 ts->input_dev = input_allocate_device();
664 if (ts->input_dev == NULL) {
666 printk(KERN_ERR "ili2102_ts_probe: Failed to allocate input device\n");
667 goto err_input_dev_alloc_failed;
670 ts->model = pdata->model ? : 801;
671 ts->swap_xy = pdata->swap_xy;
672 ts->x_min = pdata->x_min;
673 ts->x_max = pdata->x_max;
674 ts->y_min = pdata->y_min;
675 ts->y_max = pdata->y_max;
676 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", dev_name(&client->dev));
677 snprintf(ts->name, sizeof(ts->name), "ili%d-touchscreen", ts->model);
678 ts->input_dev->phys = ts->phys;
679 ts->input_dev->name = ts->name;
680 ts->input_dev->dev.parent = &client->dev;
682 ts->valid_i2c_register = 1;
684 //ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS);
685 //ts->input_dev->absbit[0] =
686 //BIT(ABS_MT_POSITION_X) | BIT(ABS_MT_POSITION_Y) |
687 //BIT(ABS_MT_TOUCH_MAJOR) | BIT(ABS_MT_WIDTH_MAJOR); // for android
689 __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);
690 __set_bit(EV_ABS, ts->input_dev->evbit);
692 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X,
696 input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y,
700 input_mt_init_slots(ts->input_dev, TOUCH_NUMBER);
701 input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
702 //input_set_abs_params(ts->input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
704 /* ts->input_dev->name = ts->keypad_info->name; */
705 ret = input_register_device(ts->input_dev);
707 printk(KERN_ERR "ili2102_ts_probe: Unable to register %s input device\n", ts->input_dev->name);
708 goto err_input_register_device_failed;
711 client->irq = gpio_to_irq(client->irq);
714 ret = setup_pendown(client,ts);
717 printk("ili2102 TS setup_pendown fail\n");
718 goto err_input_register_device_failed;
721 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, client->name, ts);
723 DBG("ili2102 TS register ISR (irq=%d)\n", client->irq);
727 dev_err(&client->dev, "request_irq failed\n");
730 #if ILI2102_TS_APK_SUPPORT
731 // initialize global variable
733 memset(&g_dev, 0, sizeof(struct dev_data));
735 // allocate character device driver buffer
736 ret = alloc_chrdev_region(&g_dev.devno, 0, 1, ILITEK_FILE_DRIVER_NAME);
738 printk(ILITEK_ERROR_LEVEL "%s, can't allocate chrdev\n", __func__);
741 printk(ILITEK_DEBUG_LEVEL "%s, register chrdev(%d, %d)\n", __func__, MAJOR(g_dev.devno), MINOR(g_dev.devno));
743 // initialize character device driver
744 cdev_init(&g_dev.cdev, &ilitek_fops);
745 g_dev.cdev.owner = THIS_MODULE;
746 ret = cdev_add(&g_dev.cdev, g_dev.devno, 1);
748 printk(ILITEK_ERROR_LEVEL "%s, add character device error, ret %d\n", __func__, ret);
751 g_dev.class = class_create(THIS_MODULE, ILITEK_FILE_DRIVER_NAME);
752 if(IS_ERR(g_dev.class)){
753 printk(ILITEK_ERROR_LEVEL "%s, create class, error\n", __func__);
756 device_create(g_dev.class, NULL, g_dev.devno, NULL, "ilitek_ctrl");
759 #ifdef CONFIG_HAS_EARLYSUSPEND
760 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
761 ts->early_suspend.suspend = ili2102_ts_early_suspend;
762 ts->early_suspend.resume = ili2102_ts_late_resume;
763 register_early_suspend(&ts->early_suspend);
766 struct proc_dir_entry *ili2102_proc_entry;
767 ili2102_proc_entry = proc_create("driver/ili2102", 0777, NULL, &ili2102_proc_fops);
769 printk(KERN_INFO "ili2102_ts_probe: Start touchscreen %s in %s mode\n", ts->input_dev->name, ts->use_irq ? "interrupt" : "polling");
773 err_input_register_device_failed:
774 input_free_device(ts->input_dev);
776 gpio_free(ts->gpio_reset);
777 err_input_dev_alloc_failed:
779 err_alloc_data_failed:
780 err_check_functionality_failed:
784 static int ili2102_ts_remove(struct i2c_client *client)
786 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
787 unregister_early_suspend(&ts->early_suspend);
789 free_irq(client->irq, ts);
791 hrtimer_cancel(&ts->timer);
792 input_unregister_device(ts->input_dev);
794 cancel_delayed_work_sync(&ts->work);
797 #if ILI2102_TS_APK_SUPPORT
798 // delete character device driver
799 cdev_del(&g_dev.cdev);
800 unregister_chrdev_region(g_dev.devno, 1);
801 device_destroy(g_dev.class, g_dev.devno);
802 class_destroy(g_dev.class);
808 static int ili2102_ts_suspend(struct i2c_client *client, pm_message_t mesg)
811 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
812 uint8_t buf[1] = {0x30};
813 struct i2c_msg msg[1];
816 msg[0].addr =client->addr;
820 msg[0].scl_rate =400*1000;
823 ret = i2c_transfer(client->adapter, msg, 1);
825 printk("%s:err\n",__FUNCTION__);
828 ret = cancel_delayed_work_sync(&ts->work);
829 if (ret && ts->use_irq) /* if work was pending disable-count is now 2 */
830 enable_irq(client->irq);
834 free_irq(client->irq, ts);
835 //change irq type to IRQF_TRIGGER_FALLING to avoid system death
836 ret = request_irq(client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, client->name, ts);
838 disable_irq_nosync(client->irq);
842 printk("%s:request irq=%d failed,ret=%d\n",__FUNCTION__, ts->client->irq, ret);
845 hrtimer_cancel(&ts->timer);
847 DBG("%s\n",__FUNCTION__);
853 static void ili2102_ts_resume_work_func(struct work_struct *work)
855 struct ili2102_ts_data *ts = container_of(work, struct ili2102_ts_data, work);
858 PREPARE_DELAYED_WORK(&ts->work, ili2102_ts_work_func);
859 mdelay(100); //wait for 100ms before i2c operation
861 free_irq(ts->client->irq, ts);
862 ret = request_irq(ts->client->irq, ili2102_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW, ts->client->name, ts);
865 //enable_irq(ts->client->irq);
868 printk("%s:request irq=%d failed,ret=%d\n",__FUNCTION__,ts->client->irq,ret);
870 DBG("%s,irq=%d\n",__FUNCTION__,ts->client->irq);
874 static int ili2102_ts_resume(struct i2c_client *client)
876 struct ili2102_ts_data *ts = i2c_get_clientdata(client);
878 ili2102_init_panel(ts);
881 if(!delayed_work_pending(&ts->work)){
882 PREPARE_DELAYED_WORK(&ts->work, ili2102_ts_resume_work_func);
883 queue_delayed_work(ts->ts_wq, &ts->work, 0);
887 hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
890 DBG("%s\n",__FUNCTION__);
896 #ifdef CONFIG_HAS_EARLYSUSPEND
897 static void ili2102_ts_early_suspend(struct early_suspend *h)
899 struct ili2102_ts_data *ts;
900 ts = container_of(h, struct ili2102_ts_data, early_suspend);
901 ili2102_ts_suspend(ts->client, PMSG_SUSPEND);
904 static void ili2102_ts_late_resume(struct early_suspend *h)
906 struct ili2102_ts_data *ts;
907 ts = container_of(h, struct ili2102_ts_data, early_suspend);
908 ili2102_ts_resume(ts->client);
912 #define ILI2102_TS_NAME "ili2102_ts"
914 static const struct i2c_device_id ili2102_ts_id[] = {
915 { ILI2102_TS_NAME, 0 },
919 static struct i2c_driver ili2102_ts_driver = {
920 .probe = ili2102_ts_probe,
921 .remove = ili2102_ts_remove,
922 #ifndef CONFIG_HAS_EARLYSUSPEND
923 .suspend = ili2102_ts_early_suspend,
924 .resume = ili2102_ts_late_resume,
926 .id_table = ili2102_ts_id,
928 .name = ILI2102_TS_NAME,
932 static int __devinit ili2102_ts_init(void)
934 return i2c_add_driver(&ili2102_ts_driver);
937 static void __exit ili2102_ts_exit(void)
939 i2c_del_driver(&ili2102_ts_driver);
942 module_init(ili2102_ts_init);
943 module_exit(ili2102_ts_exit);
945 MODULE_DESCRIPTION("ili2102 Touchscreen Driver");
946 MODULE_LICENSE("GPL");