From 20e287dc58047abbeb23886e1a99ca44ceb04eb4 Mon Sep 17 00:00:00 2001
From: cliff_yu <cliff_yu@asus.com>
Date: Mon, 5 Jan 2015 11:01:10 +0800
Subject: [PATCH] Anthias: Touch: 18874482: reset TP when going to interactive
 mode

bug: 18874482

(1) fixing tilt to wake and power button wake first touch issue
(2) fixing phantom touch issue

Change-Id: Ib4759179e04b3684df4bff3c294704e7d67d1b43
Reviewed-on: http://mcrd1-22-pc.corpnet.asus/code-review/master/157519
Reviewed-by: Cliff Yu <cliff_yu@asus.com>
Tested-by: Cliff Yu <cliff_yu@asus.com>
Reviewed-by: Carol_Jiang <carol_jiang@asus.com>
Tested-by: Carol_Jiang <carol_jiang@asus.com>
---
 arch/arm/mach-msm/wi500q_evb2_gpio_pinmux.h    |  7 +++++++
 arch/arm/mach-msm/wi500q_gpio_pinmux_setting.h |  7 +++++++
 arch/arm/mach-msm/wi500q_sr2_gpio_pinmux.h     |  7 +++++++
 arch/arm/mach-msm/wi500q_sr_gpio_pinmux.h      |  7 +++++++
 drivers/input/touchscreen/it7260_ts_i2c.c      | 16 +++++++++++++++-
 5 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-msm/wi500q_evb2_gpio_pinmux.h b/arch/arm/mach-msm/wi500q_evb2_gpio_pinmux.h
index 81fce48df868..38312a1b4926 100755
--- a/arch/arm/mach-msm/wi500q_evb2_gpio_pinmux.h
+++ b/arch/arm/mach-msm/wi500q_evb2_gpio_pinmux.h
@@ -76,6 +76,13 @@ static struct msm_gpiomux_config wi500q_evb2_msm8226_gpio_configs[] __initdata=
 // ASUS_BSP BerylHou ---
 
 // ASUS_BSP +++ Cliff_Yu "TOUCH"
+	{
+		.gpio = 16,
+		.settings = {
+			[GPIOMUX_ACTIVE]    = &touch_reset,
+			[GPIOMUX_SUSPENDED] = &touch_reset,
+		},
+	},
 	{
 		.gpio = 17,
 		.settings = {
diff --git a/arch/arm/mach-msm/wi500q_gpio_pinmux_setting.h b/arch/arm/mach-msm/wi500q_gpio_pinmux_setting.h
index 09129f8a0be2..ebdd22b23ac8 100644
--- a/arch/arm/mach-msm/wi500q_gpio_pinmux_setting.h
+++ b/arch/arm/mach-msm/wi500q_gpio_pinmux_setting.h
@@ -154,6 +154,13 @@ static struct gpiomux_setting touch_int = {				//IT7260
     .pull = GPIOMUX_PULL_NONE,
     .dir = GPIOMUX_IN,
 };
+
+static struct gpiomux_setting touch_reset = {			//IT7260
+    .func = GPIOMUX_FUNC_GPIO,
+    .drv = GPIOMUX_DRV_2MA,
+    .pull = GPIOMUX_PULL_NONE,
+    .dir = GPIOMUX_IN,
+};
 //ASUS_BSP --- Cliff_Yu "Touch Porting"
 
 // ASUS_BSP BerylHou +++ "BT config"
diff --git a/arch/arm/mach-msm/wi500q_sr2_gpio_pinmux.h b/arch/arm/mach-msm/wi500q_sr2_gpio_pinmux.h
index e4bed9476cc7..8c5a849b9623 100755
--- a/arch/arm/mach-msm/wi500q_sr2_gpio_pinmux.h
+++ b/arch/arm/mach-msm/wi500q_sr2_gpio_pinmux.h
@@ -66,6 +66,13 @@ static struct msm_gpiomux_config wi500q_sr2_msm8226_gpio_configs[] __initdata= {
         },
 // ASUS_BSP --- Maggie_Lee "I2C"
 // ASUS_BSP +++ Cliff_Yu "TOUCH"
+	{
+		.gpio = 16,
+		.settings = {
+			[GPIOMUX_ACTIVE]    = &touch_reset,
+			[GPIOMUX_SUSPENDED] = &touch_reset,
+		},
+	},
 	{
 		.gpio = 17,
 		.settings = {
diff --git a/arch/arm/mach-msm/wi500q_sr_gpio_pinmux.h b/arch/arm/mach-msm/wi500q_sr_gpio_pinmux.h
index e60c48154f4d..ee1b037b70f3 100755
--- a/arch/arm/mach-msm/wi500q_sr_gpio_pinmux.h
+++ b/arch/arm/mach-msm/wi500q_sr_gpio_pinmux.h
@@ -66,6 +66,13 @@ static struct msm_gpiomux_config wi500q_sr_msm8226_gpio_configs[] __initdata= {
         },
 // ASUS_BSP --- Maggie_Lee "I2C"
 // ASUS_BSP +++ Cliff_Yu "TOUCH"
+	{
+		.gpio = 16,
+		.settings = {
+			[GPIOMUX_ACTIVE]    = &touch_reset,
+			[GPIOMUX_SUSPENDED] = &touch_reset,
+		},
+	},
 	{
 		.gpio = 17,
 		.settings = {
diff --git a/drivers/input/touchscreen/it7260_ts_i2c.c b/drivers/input/touchscreen/it7260_ts_i2c.c
index e9cb98c54e73..96eda9cf89bc 100644
--- a/drivers/input/touchscreen/it7260_ts_i2c.c
+++ b/drivers/input/touchscreen/it7260_ts_i2c.c
@@ -470,6 +470,13 @@ static void chipLowPowerMode(bool low)
 			queue_delayed_work(IT7260_wq, &gl_ts->touchidle_on_work, 500);
 		} else {
 			cancel_delayed_work(&gl_ts->touchidle_on_work);
+			
+			//Touch Reset
+			gpio_direction_output(16,1);
+			msleep(50);
+			gpio_direction_output(16,0);
+			msleep(50);
+			
 			if (!allow_irq_wake){
 				smp_wmb();
 				disable_irq_wake(gl_ts->client->irq);
@@ -866,7 +873,7 @@ static void readTouchDataPoint(void)
 	}
 	
 	if ((pointData.palm & PD_PALM_FLAG_BIT) && !isDeviceSuspend && !hadPalmDown) {
-		if (jiffies - last_time_exit_low > HZ/5){
+		if (jiffies - last_time_exit_low > HZ/4){
 			isDeviceSuspend = true;
 			hadPalmDown = true;
 			sendPalmEvt();
@@ -1061,6 +1068,7 @@ static int IT7260_ts_probe(struct i2c_client *client, const struct i2c_device_id
 	struct IT7260_i2c_platform_data *pdata;
 	uint8_t rsp[2];
 	int ret = -1;
+	int err;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		LOGE("need I2C_FUNC_I2C\n");
@@ -1177,6 +1185,11 @@ static int IT7260_ts_probe(struct i2c_client *client, const struct i2c_device_id
 	}
 	wake_lock_init(&touch_lock, WAKE_LOCK_SUSPEND, "touch-lock");
 	
+	err = gpio_request(16, "CTP_RST_N");
+	if (err<0){
+		printk("IT7260: gpio_request 16 error: %d\n",err);
+	}
+	
 	devicePresent = true;
 
 	i2cWriteNoReadyCheck(BUF_COMMAND, cmdStart, sizeof(cmdStart));
@@ -1380,6 +1393,7 @@ static int __init IT7260_ts_init(void)
 static void __exit IT7260_ts_exit(void)
 {
 	i2c_del_driver(&IT7260_ts_driver);
+	gpio_free(16);
 	#ifdef CONFIG_ASUS_UTILITY
 	unregister_mode_notifier(&display_mode_notifier);
     	#endif
-- 
GitLab