td8801: fixup multitouch of pixcir_tp in kernel-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / eeti_egalax_i2c.c
index 961c245fea2b4bdead0d0e230176d7911e0ecb29..8177406c93731cd83ebd3f2ce4e02118e93db112 100755 (executable)
 #include <linux/kfifo.h>
 #include <linux/version.h>
 #include <linux/input.h>
+#include <linux/input/mt.h>
 #include <linux/irq.h>
 #include <linux/async.h>
 #include <mach/board.h>
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+#include <linux/earlysuspend.h>
+#endif
+
 //#define DEBUG
 #ifdef CONFIG_EETI_EGALAX_DEBUG
        #define TS_DEBUG(fmt,args...)  printk( KERN_DEBUG "[egalax_i2c]: " fmt, ## args)
@@ -57,7 +62,7 @@ static int global_minor = 0;
 #define EETI_I2C_RATE   (200*1000)
 #define MAX_I2C_LEN            10
 #define FIFO_SIZE              PAGE_SIZE
-#define MAX_SUPPORT_POINT      5
+#define MAX_SUPPORT_POINT      2
 #define REPORTID_MOUSE         0x01
 #define REPORTID_VENDOR                0x03
 #define REPORTID_MTOUCH                0x04
@@ -67,6 +72,8 @@ static int global_minor = 0;
 #define        EGALAX_IOCWAKEUP        _IO(EGALAX_IOC_MAGIC, 1)
 #define EGALAX_IOC_MAXNR       1
 
+#define EETI_EARLYSUSPEND_LEVEL        151
+
 struct point_data {
        short Status;
        short X;
@@ -83,6 +90,13 @@ struct _egalax_i2c {
        int irq;
 };
 
+#ifdef CONFIG_HAS_EARLYSUSPEND 
+struct suspend_info {
+       struct early_suspend early_suspend;
+       struct _egalax_i2c *egalax_i2c;
+};
+#endif
+
 struct egalax_char_dev
 {
        int OpenCnts;
@@ -276,7 +290,7 @@ static int wakeup_controller(int gpio)
        return ret;
 }
 
-static int egalax_cdev_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long args)
+static long egalax_cdev_ioctl(struct file *filp, unsigned int cmd, unsigned long args)
 {      
        //struct egalax_char_dev *cdev = file->private_data;
        int ret=0;
@@ -357,18 +371,20 @@ static void ProcessReport(unsigned char *buf, int buflen)
        {
                for(i=0; i<MAX_SUPPORT_POINT;i++)
                {
-                       if(PointBuf[i].Status >= 0)
+                       if(PointBuf[i].Status > 0)
                        {
-                               input_report_abs(input_dev, ABS_MT_TRACKING_ID, i);                     
+                               input_mt_slot(input_dev, i);
+                               input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true);
                                input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, PointBuf[i].Status);
-                               input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 0);
                                input_report_abs(input_dev, ABS_MT_POSITION_X, PointBuf[i].X);
                                input_report_abs(input_dev, ABS_MT_POSITION_Y, PointBuf[i].Y);
-
-                               input_mt_sync(input_dev);
-
-                               if(PointBuf[i].Status == 0)
-                                       PointBuf[i].Status--;
+                               PointBuf[i].Status = 0;
+                       }
+                       else if (PointBuf[i].Status == 0)
+                       {
+                               input_mt_slot(input_dev, i);
+                               input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false);
+                               PointBuf[i].Status = -1;
                        }
                }
                input_sync(input_dev);
@@ -395,14 +411,14 @@ static struct input_dev * allocate_Input_Dev(void)
        pInputDev->id.bustype = BUS_I2C;
        pInputDev->id.vendor = 0x0EEF;
        pInputDev->id.product = 0x0020;
-       
-       set_bit(EV_ABS, pInputDev->evbit);
 
+       __set_bit(INPUT_PROP_DIRECT, pInputDev->propbit);
+       __set_bit(EV_ABS, pInputDev->evbit);
+
+       input_mt_init_slots(pInputDev, MAX_SUPPORT_POINT);
        input_set_abs_params(pInputDev, ABS_MT_POSITION_X, 0, CONFIG_EETI_EGALAX_MAX_X, 0, 0);
        input_set_abs_params(pInputDev, ABS_MT_POSITION_Y, 0, CONFIG_EETI_EGALAX_MAX_Y, 0, 0);
        input_set_abs_params(pInputDev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
-       input_set_abs_params(pInputDev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
-       input_set_abs_params(pInputDev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
 
        ret = input_register_device(pInputDev);
        if(ret) 
@@ -477,23 +493,25 @@ static void egalax_i2c_wq(struct work_struct *work)
 
 #ifndef _NON_INPUT_DEV
        if (gpio_get_value(gpio) && egalax_i2c->work_state > 0 && !egalax_i2c->skip_packet) {
-               int i, reported = 0;
+               int i;
                for(i = 0; i < MAX_SUPPORT_POINT; i++) {
                        if (PointBuf[i].Status > 0) {
                                TS_DEBUG("point %d still down\n", i);
-                               input_report_abs(input_dev, ABS_MT_TRACKING_ID, i);
+                               input_mt_slot(input_dev, i);
+                               input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, true);
                                input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 0);
-                               input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 0);
                                input_report_abs(input_dev, ABS_MT_POSITION_X, PointBuf[i].X);
                                input_report_abs(input_dev, ABS_MT_POSITION_Y, PointBuf[i].Y);
-
-                               input_mt_sync(input_dev);
                                PointBuf[i].Status = 0;
-                               reported = 1;
+                       }
+                       else if (PointBuf[i].Status == 0)
+                       {
+                               input_mt_slot(input_dev, i);
+                               input_mt_report_slot_state(input_dev, MT_TOOL_FINGER, false);
+                               PointBuf[i].Status = -1;
                        }
                }
-               if (reported)
-                       input_sync(input_dev);
+               input_sync(input_dev);
        }
 #endif
 
@@ -501,9 +519,8 @@ static void egalax_i2c_wq(struct work_struct *work)
                egalax_i2c->skip_packet = 0;
 
        mutex_unlock(&egalax_i2c->mutex_wq);
-       
-       if( egalax_i2c->work_state > 0 )
-               enable_irq(p_egalax_i2c_dev->irq);
+
+       enable_irq(p_egalax_i2c_dev->irq);
 
        TS_DEBUG("egalax_i2c_wq leave\n");
 }
@@ -549,9 +566,13 @@ static int egalax_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
        
        i2c_master_normal_send(client, cmdbuf, MAX_I2C_LEN, EETI_I2C_RATE);
 
-       egalax_i2c->work_state = 0;
        disable_irq(p_egalax_i2c_dev->irq);
-       cancel_work_sync(&egalax_i2c->work);
+       egalax_i2c->work_state = 0;
+       if (cancel_work_sync(&egalax_i2c->work)) {
+               /* if work was pending disable-count is now 2 */
+               pr_info("%s: work was pending\n", __func__);
+               enable_irq(p_egalax_i2c_dev->irq);
+       }
 
        printk(KERN_DEBUG "[egalax_i2c]: device suspend done\n");       
 
@@ -588,11 +609,45 @@ static int egalax_i2c_resume(struct i2c_client *client)
 
        return 0;
 }
+
+#ifdef CONFIG_HAS_EARLYSUSPEND 
+
+static void egalax_i2c_early_suspend(struct early_suspend *h)
+{
+       pm_message_t mesg = {.event = 0};
+       struct suspend_info *info = container_of(h,struct suspend_info,early_suspend);
+       struct i2c_client *client = info->egalax_i2c->client;
+       egalax_i2c_suspend(client,mesg);
+
+}
+static void egalax_i2c_early_resume(struct early_suspend *h)
+{
+   
+    struct suspend_info *info = container_of(h,struct suspend_info,early_suspend);
+    struct i2c_client *client = info->egalax_i2c->client;
+
+    egalax_i2c_resume(client);
+
+}
+
+#endif
+
+
+
 #else
 #define egalax_i2c_suspend       NULL
 #define egalax_i2c_resume        NULL
 #endif
 
+#ifdef CONFIG_HAS_EARLYSUSPEND 
+static struct suspend_info suspend_info = {
+       .early_suspend.suspend = egalax_i2c_early_suspend,
+       .early_suspend.resume = egalax_i2c_early_resume,
+       .early_suspend.level = EETI_EARLYSUSPEND_LEVEL,
+};
+#endif
+
+
 static int __devinit egalax_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
        int ret;
@@ -654,6 +709,13 @@ if (pdata->init_platform_hw)
        device_init_wakeup(&client->dev, 0);
 #endif
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+
+
+       suspend_info.egalax_i2c = p_egalax_i2c_dev;
+       register_early_suspend(&suspend_info.early_suspend);
+#endif
+
        printk(KERN_DEBUG "[egalax_i2c]: probe done\n");
        return 0;
 
@@ -722,8 +784,8 @@ static struct i2c_driver egalax_i2c_driver = {
        .id_table       = egalax_i2c_idtable,
        .probe          = egalax_i2c_probe,
        .remove         = __devexit_p(egalax_i2c_remove),
-       .suspend        = egalax_i2c_suspend,
-       .resume         = egalax_i2c_resume,
+       //.suspend      = egalax_i2c_suspend,
+       //.resume               = egalax_i2c_resume,
 };
 
 static const struct file_operations egalax_cdev_fops = {