K97 项目相关修改
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / gt801_ts.c
index d7a46b25fc717773b7370c12b2a1ec46001e3f7b..42265676bf5b2023cc676630fd92e1085239d507 100755 (executable)
@@ -13,6 +13,7 @@
  * GNU General Public License for more details.
  */
 
+
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/earlysuspend.h>
     #define TOUCH_NUMBER 2
 #endif
 
-#define TOUCH_REG_NUM 5 //ÿ×é×ø±êÐèÒªµÄ¼Ä´æÆ÷ÊýĿ
+#define TOUCH_REG_NUM 5 //ÿ�������Ҫ�ļĴ�����Ŀ
 
 const unsigned char GT801_RegData[GT801_REGS_NUM]={    
-       0x19,0x05,0x06,0x28,0x02,0x14,0x14,0x10,0x40,0xB0,0x01,0xE0,0x03,0x4C,0x78,0x9A,0xBC,0xDE,0x65,0x43,0x20,0x11,0x00,0x00,0x00,0x00,0x05,0xCF,0x20,0x0B,0x0D,0x8D,0x32,0x3C,0x1E,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
+       0x19,0x05,0x06,0x28,0x02,0x14,0x14,0x10,0x40,0xB0,0x01,0xE0,0x03,0x4C,0x78,
+       0x9A,0xBC,0xDE,0x65,0x43,0x20,0x11,0x00,0x00,0x00,0x00,0x05,0xCF,0x20,0x0B,
+       0x0D,0x8D,0x32,0x3C,0x1E,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01
 };
 
 struct gt801_ts_data {
@@ -205,13 +209,21 @@ static void gt801_ts_work_func(struct work_struct *work)
                }
                else{
                        x = ((( ((unsigned short)buf[i+ptxh] )<< 8) ) | buf[i+ptxl]);
-                       y= (((((unsigned short)buf[i+ptyh] )<< 8) )| buf[i+ptyl]);
-                       
-                       if (ts->swap_xy)
+                       y = (((((unsigned short)buf[i+ptyh] )<< 8) )| buf[i+ptyl]);
+                       /* adjust the x and y to proper value  added by hhb@rock-chips.com*/
+                       if(x < 480){
+                               x = 480-x;
+                       }
+
+                       if(y < 800){
+                               y = 800-y;
+                       }
+
+                       if (ts->swap_xy){
                                swap(x, y);
+                       }
                        
-                       if (verify_coord(ts,&x,&y))
-                               ;//goto out;    
+                       if (verify_coord(ts,&x,&y));//goto out;
                        
                        gt801printk("input_report_abs--%d-%d-(%d/%d)\n", i,touch_state_index, x, y);    
                        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1); //Finger Size
@@ -228,12 +240,14 @@ static void gt801_ts_work_func(struct work_struct *work)
        
 #endif
 
-       if(syn_flag)
+       if(syn_flag){
                input_sync(ts->input_dev);
+       }
+
 out:
-       if (ts->use_irq) 
-               enable_irq(ts->client->irq);
-   
+       if (ts->use_irq) {
+               enable_irq(ts->client->irq);
+       }
        return;
 }
 static enum hrtimer_restart gt801_ts_timer_func(struct hrtimer *timer)
@@ -250,11 +264,12 @@ static enum hrtimer_restart gt801_ts_timer_func(struct hrtimer *timer)
 static irqreturn_t gt801_ts_irq_handler(int irq, void *dev_id)
 {
     struct gt801_ts_data *ts = dev_id;
-       gt801printk("%s=%d,%d\n",__FUNCTION__,ts->client->irq,ts->use_irq);
+    gt801printk("%s=%d,%d\n",__FUNCTION__,ts->client->irq,ts->use_irq);
        
-       //if (ts->use_irq)
+       if(ts->use_irq){
        disable_irq_nosync(ts->client->irq);
-    queue_work(gt801_wq, &ts->work);
+       }
+       queue_work(gt801_wq, &ts->work);
     return IRQ_HANDLED;
 }
 static int __devinit setup_resetPin(struct i2c_client *client, struct gt801_ts_data *ts)
@@ -284,8 +299,6 @@ static int __devinit setup_resetPin(struct i2c_client *client, struct gt801_ts_d
                return err;
        }
        
-       gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
-
        err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
        if (err) {
                dev_err(&client->dev, "failed to pulldown resetPin GPIO%d,err%d\n",
@@ -293,15 +306,13 @@ static int __devinit setup_resetPin(struct i2c_client *client, struct gt801_ts_d
                gpio_free(ts->gpio_reset);
                return err;
        }
-       
-    mdelay(100);
-
+       mdelay(100);
        gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
-
        mdelay(100);
-        
+
        return 0;
 }
+
 static int __devinit setup_pendown(struct i2c_client *client, struct gt801_ts_data *ts)
 {
        int err;
@@ -345,6 +356,7 @@ static int __devinit setup_pendown(struct i2c_client *client, struct gt801_ts_da
        }
        return 0;
 }
+
 static int gt801_chip_Init(struct i2c_client *client)
 {
        u8 i,j;
@@ -387,6 +399,7 @@ static int gt801_chip_Init(struct i2c_client *client)
        
        return ret;
 }
+
 static int gt801_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
     struct gt801_ts_data *ts;
@@ -564,6 +577,17 @@ static int gt801_ts_suspend(struct i2c_client *client, pm_message_t mesg)
     return 0;
 }
 
+
+static void gt801_ts_resume_work_func(struct work_struct *work)
+{
+       struct gt801_ts_data *ts = container_of(work, struct gt801_ts_data, work);
+       msleep(50);    //touch panel will generate an interrupt when it sleeps out,so as to avoid tihs by delaying 50ms
+       enable_irq(ts->client->irq);
+       PREPARE_WORK(&ts->work, gt801_ts_work_func);
+       printk("enabling gt801_ts IRQ %d\n", ts->client->irq);
+}
+
+
 static int gt801_ts_resume(struct i2c_client *client)
 {
     struct gt801_ts_data *ts = i2c_get_clientdata(client);
@@ -575,11 +599,14 @@ static int gt801_ts_resume(struct i2c_client *client)
     gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
        
     if (ts->use_irq) {
-        printk("enabling IRQ %d\n", client->irq);
-        enable_irq(client->irq);
+        if(!work_pending(&ts->work)){
+               PREPARE_WORK(&ts->work, gt801_ts_resume_work_func);
+               queue_work(gt801_wq, &ts->work);
+        }
     }
-    else
+    else {
         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);
+    }
 
     return 0;
 }