phonepad:fix touch screen driver bug
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / gt818_ts.c
index 6e55be7fba177da78e57929b96e9052773104a13..857607e8c1829a30662cd1357fc23b2f11cfe3b0 100644 (file)
@@ -40,6 +40,7 @@
 #include <linux/string.h>\r
 #include <linux/completion.h>\r
 #include <asm/uaccess.h>\r
+#include <linux/input/mt.h>\r
 \r
 #include "gt818_ts.h"\r
 \r
@@ -53,14 +54,12 @@ static struct workqueue_struct *goodix_wq;
 \r
 static const char *gt818_ts_name = "Goodix Capacitive TouchScreen";\r
 \r
-static struct point_queue finger_list;\r
+//static struct point_queue finger_list;\r
 \r
 struct i2c_client * i2c_connect_client = NULL;\r
 \r
 //EXPORT_SYMBOL(i2c_connect_client);\r
 \r
-static struct proc_dir_entry *goodix_proc_entry;\r
-       \r
 #ifdef CONFIG_HAS_EARLYSUSPEND\r
 static void goodix_ts_early_suspend(struct early_suspend *h);\r
 static void goodix_ts_late_resume(struct early_suspend *h);\r
@@ -76,6 +75,9 @@ static void goodix_ts_late_resume(struct early_suspend *h);
        #define MAX_KEY_NUM      (sizeof(gt818_key_array)/sizeof(gt818_key_array[0]))\r
 #endif\r
 \r
+unsigned int last_x[MAX_FINGER_NUM + 1]= {0};\r
+unsigned int last_y[MAX_FINGER_NUM + 1]= {0};\r
+\r
 \r
 /*Function as i2c_master_send */\r
 static int i2c_read_bytes(struct i2c_client *client, u8 *buf, int len)\r
@@ -231,7 +233,6 @@ static void goodix_ts_work_func(struct work_struct *work)
 \r
        u8  finger = 0;\r
        u8  key = 0;\r
-       u8 retry = 0;\r
        unsigned int  count = 0;\r
        unsigned int position = 0;      \r
        int temp = 0;\r
@@ -303,19 +304,23 @@ static void goodix_ts_work_func(struct work_struct *work)
 \r
        for(position = 1; position < MAX_FINGER_NUM + 1; position++)\r
        {\r
-               //printk("%s:positon:%d\n", __func__, position);\r
                if((finger_current[position] == 0) && (finger_last[position] != 0))\r
                {\r
-                       input_report_abs(ts->input_dev, ABS_MT_POSITION_X, 0);\r
-                       input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, 0);\r
-                       input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);\r
-                       input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);\r
-                       input_mt_sync(ts->input_dev);\r
+                       //printk("<<<<<<<<<<<<<<<<<<<%s:positon:%d (%d,%d)\n", __func__, position,last_x,last_y);\r
+                       //printk("<<<%d , %d ",finger_current[position],finger_last[position]);\r
+                       //input_mt_slot(ts->input_dev, position);\r
+                       //input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);\r
+                       //input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);\r
+                       //input_report_abs(ts->input_dev, ABS_MT_POSITION_X, last_x[position]);\r
+                       //input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, last_y[position]);\r
+                       //input_report_abs(ts->input_dev, ABS_MT_PRESSURE, 100);\r
+                       //input_mt_sync(ts->input_dev);\r
+                       input_mt_slot(ts->input_dev, position);\r
+                       input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, false);\r
                        syn_flag = 1;\r
                }\r
                else if(finger_current[position])\r
                {\r
-\r
                        x = (*(coor_point+3*(position-1)))*SCREEN_MAX_WIDTH/(TOUCH_MAX_WIDTH);\r
                        y = (*(coor_point+3*(position-1)+1))*SCREEN_MAX_HEIGHT/(TOUCH_MAX_HEIGHT);\r
                        pressure = (*(coor_point+3*(position-1)+2));\r
@@ -326,15 +331,25 @@ static void goodix_ts_work_func(struct work_struct *work)
                        if(y < SCREEN_MAX_HEIGHT){\r
                        //      y = SCREEN_MAX_HEIGHT-y;\r
                        }\r
-                       input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, position - 1);\r
+\r
+                       //printk(">>>>>>>>>>>>>>>>>%s:positon:%d (%d,%d)\n", __func__, position,x,y);\r
+                       input_mt_slot(ts->input_dev, position);\r
+                       input_mt_report_slot_state(ts->input_dev, MT_TOOL_FINGER, true);\r
                        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);\r
+                       input_report_abs(ts->input_dev, ABS_MT_PRESSURE, pressure);\r
                        input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);\r
                        input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);\r
-                       input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure);\r
-                       input_mt_sync(ts->input_dev);\r
+\r
+                       last_x[position] = x;\r
+                       last_y[position] = y;\r
+                       //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure);\r
+                       //input_mt_sync(ts->input_dev);\r
                        syn_flag = 1;\r
                }\r
-       }\r
+\r
+}\r
+input_sync(ts->input_dev);\r
+\r
 \r
 \r
 #ifdef HAVE_TOUCH_KEY\r
@@ -389,7 +404,7 @@ XFER_ERROR:
                enable_irq(ts->client->irq);\r
 \r
 }\r
-\r
+#if 0\r
 static int test_suspend_resume(struct gt818_ts_data *ts){\r
        while(1){\r
                ts->power(ts, 0);\r
@@ -399,7 +414,7 @@ static int test_suspend_resume(struct gt818_ts_data *ts){
        }\r
        return 0;\r
 }\r
-\r
+#endif\r
 \r
 static enum hrtimer_restart goodix_ts_timer_func(struct hrtimer *timer)\r
 {\r
@@ -484,11 +499,10 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
 {\r
        int ret = 0;\r
        int retry=0;\r
-       u8 goodix_id[3] = {0,0xff,0};\r
        struct gt818_ts_data *ts;\r
 \r
        struct gt818_platform_data *pdata;\r
-       dev_dbg(&client->dev,"Install touch driver.\n");\r
+       dev_info(&client->dev,"Install touch driver.\n");\r
        printk("gt818: Install touch driver.\n");\r
        //Check I2C function\r
        if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) \r
@@ -546,6 +560,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
                dev_err(&client->dev, "Warnning: I2C communication might be ERROR!\n");\r
                goto err_i2c_failed;\r
        }       \r
+\r
 #endif\r
 \r
        for(retry = 0; retry < 3; retry++)\r
@@ -576,10 +591,10 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
                goto err_input_dev_alloc_failed;\r
        }\r
 \r
-       ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;\r
-       ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);\r
-       ts->input_dev->absbit[0] = BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y) |\r
-                       BIT_MASK(ABS_MT_TOUCH_MAJOR) | BIT_MASK(ABS_MT_WIDTH_MAJOR);  // for android\r
+       //ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;\r
+       //ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);\r
+       //ts->input_dev->absbit[0] = BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y) |\r
+       //              BIT_MASK(ABS_MT_TOUCH_MAJOR) | BIT_MASK(ABS_MT_WIDTH_MAJOR);  // for android\r
 \r
 \r
 #ifdef HAVE_TOUCH_KEY\r
@@ -600,13 +615,16 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
        ts->input_dev->id.product = 0xBEEF;\r
        ts->input_dev->id.version = 10427;      //screen firmware version\r
 \r
+       __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);\r
+       __set_bit(EV_ABS, ts->input_dev->evbit);\r
 #ifdef GOODIX_MULTI_TOUCH\r
-\r
-       input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);\r
+       input_mt_init_slots(ts->input_dev, MAX_FINGER_NUM);\r
+       //input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);\r
        input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);\r
        input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, SCREEN_MAX_WIDTH, 0, 0);\r
        input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, SCREEN_MAX_HEIGHT, 0, 0);\r
-       input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, MAX_FINGER_NUM, 0, 0);\r
+       //input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, MAX_FINGER_NUM, 0, 0);\r
+       input_set_abs_params(ts->input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);\r
 #else\r
        input_set_abs_params(ts->input_dev, ABS_X, 0, SCREEN_MAX_HEIGHT, 0, 0);\r
        input_set_abs_params(ts->input_dev, ABS_Y, 0, SCREEN_MAX_WIDTH, 0, 0);\r
@@ -619,7 +637,7 @@ static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id
                goto err_input_register_device_failed;\r
        }\r
        ts->bad_data = 0;\r
-//     finger_list.length = 0;\r
+//     16finger_list.length = 0;\r
 \r
        client->irq = gpio_to_irq(pdata->gpio_pendown);         //If not defined in client\r
        if (client->irq)\r
@@ -697,7 +715,6 @@ err_i2c_failed:
        kfree(ts);\r
 err_alloc_data_failed:\r
 err_check_functionality_failed:\r
-err_create_proc_entry:\r
        return ret;\r
 }\r
 \r
@@ -834,6 +851,6 @@ late_initcall(goodix_ts_init);
 module_exit(goodix_ts_exit);\r
 \r
 MODULE_DESCRIPTION("Goodix Touchscreen Driver");\r
-MODULE_AUTHOR("hhb@rock-chips.com")\r
+MODULE_AUTHOR("hhb@rock-chips.com");\r
 MODULE_LICENSE("GPL");\r
 \r