[PATCH 2/2] Input: elants_i2c: fixed wake-on-touch issue

2016-01-03 Thread james.chen
From: "james.chen" 

Fix function of wake-on-touch on suspend/resume.
The function of device_may_wakeup will return true if
the device supports wake-on-touch (for example, kitty and buddy).
So, modify the code from "if (device_may_wakeup(dev))" to
"if (!device_may_wakeup(dev))". And adjust the condition check of
keep_power_in_suspend (designed for minnie).
2016.1.4: modify retry back to retry_cnt.

Signed-off-by: james.chen 
---
 drivers/input/touchscreen/elants_i2c.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 17cc20e..3739646 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1316,24 +1316,25 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
 
disable_irq(client->irq);
 
-   if (device_may_wakeup(dev) || ts->keep_power_in_suspend) {
+   if (device_may_wakeup(dev)) {
+   /*
+* The device will automatically enter idle mode
+* that has reduced power consumption.
+*/
+   ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
+   } else if (ts->keep_power_in_suspend) {
for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
error = elants_i2c_send(client, set_sleep_cmd,
-   sizeof(set_sleep_cmd));
+   sizeof(set_sleep_cmd));
if (!error)
break;
 
dev_err(>dev,
"suspend command failed: %d\n", error);
}
-
-   if (device_may_wakeup(dev))
-   ts->wake_irq_enabled =
-   (enable_irq_wake(client->irq) == 0);
} else {
-   elants_i2c_power_off(ts);
+   elants_i2c_power_off(ts);
}
-
return 0;
 }
 
@@ -1345,13 +1346,14 @@ static int __maybe_unused elants_i2c_resume(struct 
device *dev)
int retry_cnt;
int error;
 
-   if (device_may_wakeup(dev) && ts->wake_irq_enabled)
-   disable_irq_wake(client->irq);
-
-   if (ts->keep_power_in_suspend) {
+   if (device_may_wakeup(dev)) {
+   if (ts->wake_irq_enabled)
+   disable_irq_wake(client->irq);
+   elants_i2c_sw_reset(client);
+   } else if (ts->keep_power_in_suspend) {
for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
error = elants_i2c_send(client, set_active_cmd,
-   sizeof(set_active_cmd));
+   sizeof(set_active_cmd));
if (!error)
break;
 
@@ -1362,7 +1364,6 @@ static int __maybe_unused elants_i2c_resume(struct device 
*dev)
elants_i2c_power_on(ts);
elants_i2c_initialize(ts);
}
-
ts->state = ELAN_STATE_NORMAL;
enable_irq(client->irq);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] Input: elants_i2c: fixed wake-on-touch issue

2016-01-03 Thread james.chen
From: "james.chen" <james.c...@emc.com.tw>

Fix function of wake-on-touch on suspend/resume.
The function of device_may_wakeup will return true if
the device supports wake-on-touch (for example, kitty and buddy).
So, modify the code from "if (device_may_wakeup(dev))" to
"if (!device_may_wakeup(dev))". And adjust the condition check of
keep_power_in_suspend (designed for minnie).
2016.1.4: modify retry back to retry_cnt.

Signed-off-by: james.chen <james.c...@emc.com.tw>
---
 drivers/input/touchscreen/elants_i2c.c | 29 +++--
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 17cc20e..3739646 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1316,24 +1316,25 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
 
disable_irq(client->irq);
 
-   if (device_may_wakeup(dev) || ts->keep_power_in_suspend) {
+   if (device_may_wakeup(dev)) {
+   /*
+* The device will automatically enter idle mode
+* that has reduced power consumption.
+*/
+   ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
+   } else if (ts->keep_power_in_suspend) {
for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
error = elants_i2c_send(client, set_sleep_cmd,
-   sizeof(set_sleep_cmd));
+   sizeof(set_sleep_cmd));
if (!error)
break;
 
dev_err(>dev,
"suspend command failed: %d\n", error);
}
-
-   if (device_may_wakeup(dev))
-   ts->wake_irq_enabled =
-   (enable_irq_wake(client->irq) == 0);
} else {
-   elants_i2c_power_off(ts);
+   elants_i2c_power_off(ts);
}
-
return 0;
 }
 
@@ -1345,13 +1346,14 @@ static int __maybe_unused elants_i2c_resume(struct 
device *dev)
int retry_cnt;
int error;
 
-   if (device_may_wakeup(dev) && ts->wake_irq_enabled)
-   disable_irq_wake(client->irq);
-
-   if (ts->keep_power_in_suspend) {
+   if (device_may_wakeup(dev)) {
+   if (ts->wake_irq_enabled)
+   disable_irq_wake(client->irq);
+   elants_i2c_sw_reset(client);
+   } else if (ts->keep_power_in_suspend) {
for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
error = elants_i2c_send(client, set_active_cmd,
-   sizeof(set_active_cmd));
+   sizeof(set_active_cmd));
if (!error)
break;
 
@@ -1362,7 +1364,6 @@ static int __maybe_unused elants_i2c_resume(struct device 
*dev)
elants_i2c_power_on(ts);
elants_i2c_initialize(ts);
}
-
ts->state = ELAN_STATE_NORMAL;
enable_irq(client->irq);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CHROMIUM: Input: elants_i2c: fixed wake-on-touch issue

2015-12-17 Thread james.chen
From: "james.chen" 

Something wrong in suspend/resume of kernel v3.14 for the function of
wake-on-touch. The function of device_may_wakeup will return true if
the device supports wake-on-touch (for example, kitty and buddy).
So, modify the code from "if (device_may_wakeup(dev))" to
"if (!device_may_wakeup(dev))". And adjust the condition check of
keep_power_in_suspend (designed for minnie).

Signed-off-by: James Chen 
---
 drivers/input/touchscreen/elants_i2c.c | 37 +-
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 17cc20e..06ee814 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1307,7 +1307,7 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct elants_data *ts = i2c_get_clientdata(client);
const u8 set_sleep_cmd[] = { 0x54, 0x50, 0x00, 0x01 };
-   int retry_cnt;
+   int retry;
int error;
 
/* Command not support in IAP recovery mode */
@@ -1316,24 +1316,25 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
 
disable_irq(client->irq);
 
-   if (device_may_wakeup(dev) || ts->keep_power_in_suspend) {
-   for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
+   if (device_may_wakeup(dev)) {
+   /*
+* The device will automatically enter idle mode
+* that has reduced power consumption.
+*/
+   ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
+   } else if (ts->keep_power_in_suspend) {
+   for (retry = 0; retry < MAX_RETRIES; retry++) {
error = elants_i2c_send(client, set_sleep_cmd,
-   sizeof(set_sleep_cmd));
+   sizeof(set_sleep_cmd));
if (!error)
break;
 
dev_err(>dev,
"suspend command failed: %d\n", error);
}
-
-   if (device_may_wakeup(dev))
-   ts->wake_irq_enabled =
-   (enable_irq_wake(client->irq) == 0);
} else {
-   elants_i2c_power_off(ts);
+   elants_i2c_power_off(ts);
}
-
return 0;
 }
 
@@ -1342,16 +1343,17 @@ static int __maybe_unused elants_i2c_resume(struct 
device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct elants_data *ts = i2c_get_clientdata(client);
const u8 set_active_cmd[] = { 0x54, 0x58, 0x00, 0x01 };
-   int retry_cnt;
+   int retry;
int error;
 
-   if (device_may_wakeup(dev) && ts->wake_irq_enabled)
-   disable_irq_wake(client->irq);
-
-   if (ts->keep_power_in_suspend) {
-   for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
+   if (device_may_wakeup(dev)) {
+   if (ts->wake_irq_enabled)
+   disable_irq_wake(client->irq);
+   elants_i2c_sw_reset(client);
+   } else if (ts->keep_power_in_suspend) {
+   for (retry = 0; retry < MAX_RETRIES; retry++) {
error = elants_i2c_send(client, set_active_cmd,
-   sizeof(set_active_cmd));
+   sizeof(set_active_cmd));
if (!error)
break;
 
@@ -1362,7 +1364,6 @@ static int __maybe_unused elants_i2c_resume(struct device 
*dev)
elants_i2c_power_on(ts);
elants_i2c_initialize(ts);
}
-
ts->state = ELAN_STATE_NORMAL;
enable_irq(client->irq);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CHROMIUM: Input: elants_i2c: fixed wake-on-touch issue

2015-12-17 Thread james.chen
From: "james.chen" <james.c...@emc.com.tw>

Something wrong in suspend/resume of kernel v3.14 for the function of
wake-on-touch. The function of device_may_wakeup will return true if
the device supports wake-on-touch (for example, kitty and buddy).
So, modify the code from "if (device_may_wakeup(dev))" to
"if (!device_may_wakeup(dev))". And adjust the condition check of
keep_power_in_suspend (designed for minnie).

Signed-off-by: James Chen <james.c...@emc.com.tw>
---
 drivers/input/touchscreen/elants_i2c.c | 37 +-
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 17cc20e..06ee814 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1307,7 +1307,7 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct elants_data *ts = i2c_get_clientdata(client);
const u8 set_sleep_cmd[] = { 0x54, 0x50, 0x00, 0x01 };
-   int retry_cnt;
+   int retry;
int error;
 
/* Command not support in IAP recovery mode */
@@ -1316,24 +1316,25 @@ static int __maybe_unused elants_i2c_suspend(struct 
device *dev)
 
disable_irq(client->irq);
 
-   if (device_may_wakeup(dev) || ts->keep_power_in_suspend) {
-   for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
+   if (device_may_wakeup(dev)) {
+   /*
+* The device will automatically enter idle mode
+* that has reduced power consumption.
+*/
+   ts->wake_irq_enabled = (enable_irq_wake(client->irq) == 0);
+   } else if (ts->keep_power_in_suspend) {
+   for (retry = 0; retry < MAX_RETRIES; retry++) {
error = elants_i2c_send(client, set_sleep_cmd,
-   sizeof(set_sleep_cmd));
+   sizeof(set_sleep_cmd));
if (!error)
break;
 
dev_err(>dev,
"suspend command failed: %d\n", error);
}
-
-   if (device_may_wakeup(dev))
-   ts->wake_irq_enabled =
-   (enable_irq_wake(client->irq) == 0);
} else {
-   elants_i2c_power_off(ts);
+   elants_i2c_power_off(ts);
}
-
return 0;
 }
 
@@ -1342,16 +1343,17 @@ static int __maybe_unused elants_i2c_resume(struct 
device *dev)
struct i2c_client *client = to_i2c_client(dev);
struct elants_data *ts = i2c_get_clientdata(client);
const u8 set_active_cmd[] = { 0x54, 0x58, 0x00, 0x01 };
-   int retry_cnt;
+   int retry;
int error;
 
-   if (device_may_wakeup(dev) && ts->wake_irq_enabled)
-   disable_irq_wake(client->irq);
-
-   if (ts->keep_power_in_suspend) {
-   for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) {
+   if (device_may_wakeup(dev)) {
+   if (ts->wake_irq_enabled)
+   disable_irq_wake(client->irq);
+   elants_i2c_sw_reset(client);
+   } else if (ts->keep_power_in_suspend) {
+   for (retry = 0; retry < MAX_RETRIES; retry++) {
error = elants_i2c_send(client, set_active_cmd,
-   sizeof(set_active_cmd));
+   sizeof(set_active_cmd));
if (!error)
break;
 
@@ -1362,7 +1364,6 @@ static int __maybe_unused elants_i2c_resume(struct device 
*dev)
elants_i2c_power_on(ts);
elants_i2c_initialize(ts);
}
-
ts->state = ELAN_STATE_NORMAL;
enable_irq(client->irq);
 
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] MAINLINE: Input: elants_i2c: Extend the calibration timeout to 12 second.

2015-09-03 Thread james.chen
From: "james.chen" 

As the test result of chrome project buddy(23 inch),
the calibration time is about 9.2~10.5 second.
So, this patch extend the calibration timeout to 12 second.

BUG= none
TEST= Build and test on buddy project.

Signed-off-by: James Chen 
---
 drivers/input/touchscreen/elants_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index ddac134..17cc20e 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -102,7 +102,7 @@
 #define ELAN_FW_PAGESIZE   132
 
 /* calibration timeout definition */
-#define ELAN_CALI_TIMEOUT_MSEC 1
+#define ELAN_CALI_TIMEOUT_MSEC 12000
 
 #define ELAN_POWERON_DELAY_USEC500
 #define ELAN_RESET_DELAY_MSEC  20
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] MAINLINE: Input: elants_i2c: Extend the calibration timeout to 12 second.

2015-09-03 Thread james.chen
From: "james.chen" <james.c...@emc.com.tw>

As the test result of chrome project buddy(23 inch),
the calibration time is about 9.2~10.5 second.
So, this patch extend the calibration timeout to 12 second.

BUG= none
TEST= Build and test on buddy project.

Signed-off-by: James Chen <james.c...@emc.com.tw>
---
 drivers/input/touchscreen/elants_i2c.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index ddac134..17cc20e 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -102,7 +102,7 @@
 #define ELAN_FW_PAGESIZE   132
 
 /* calibration timeout definition */
-#define ELAN_CALI_TIMEOUT_MSEC 1
+#define ELAN_CALI_TIMEOUT_MSEC 12000
 
 #define ELAN_POWERON_DELAY_USEC500
 #define ELAN_RESET_DELAY_MSEC  20
-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and 3.14.

2015-06-05 Thread James.Chen
Hi Dmitry:

Thank you for your suggestion.
We will base on the top of mainline driver and re-submit the patch.

James

-Original Message-
From: linux-input-ow...@vger.kernel.org
[mailto:linux-input-ow...@vger.kernel.org] On Behalf Of Dmitry Torokhov
Sent: Friday, June 05, 2015 1:38 PM
To: james.chen
Cc: Herman Lin; Scott Liu; linux-kernel@vger.kernel.org;
linux-in...@vger.kernel.org; Jeff Chuang; Agnes Cheng
Subject: Re: [PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and
3.14.

Hi James,

On Wed, Jun 03, 2015 at 03:06:16PM +0800, james.chen wrote:
> From: "james.chen" 
> 
> This patch refer 3.10 driver code to solve firmware upgrade 
> issue(Change 266813) and enable noise-immunity(Change 243875).
> 
> BUG=chrome-os-partner:39373
> TEST=Test Elan Touch Screen on cyan project without problems.

As I mentioned elsewhere this does not simply address firmware upgrade and
noise immunity issues but rather overlays version that can be found in 3.10
ChromeOS kernel on top of mainline driver, removing a lot of cleanups and
fixes that went into preparing the driver for mainline inclusion.

Thanks.

--
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majord...@vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and 3.14.

2015-06-05 Thread James.Chen
Hi Dmitry:

Thank you for your suggestion.
We will base on the top of mainline driver and re-submit the patch.

James

-Original Message-
From: linux-input-ow...@vger.kernel.org
[mailto:linux-input-ow...@vger.kernel.org] On Behalf Of Dmitry Torokhov
Sent: Friday, June 05, 2015 1:38 PM
To: james.chen
Cc: Herman Lin; Scott Liu; linux-kernel@vger.kernel.org;
linux-in...@vger.kernel.org; Jeff Chuang; Agnes Cheng
Subject: Re: [PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and
3.14.

Hi James,

On Wed, Jun 03, 2015 at 03:06:16PM +0800, james.chen wrote:
 From: james.chen james.c...@emc.com.tw
 
 This patch refer 3.10 driver code to solve firmware upgrade 
 issue(Change 266813) and enable noise-immunity(Change 243875).
 
 BUG=chrome-os-partner:39373
 TEST=Test Elan Touch Screen on cyan project without problems.

As I mentioned elsewhere this does not simply address firmware upgrade and
noise immunity issues but rather overlays version that can be found in 3.10
ChromeOS kernel on top of mainline driver, removing a lot of cleanups and
fixes that went into preparing the driver for mainline inclusion.

Thanks.

--
Dmitry
--
To unsubscribe from this list: send the line unsubscribe linux-input in
the body of a message to majord...@vger.kernel.org More majordomo info at
http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and 3.14.

2015-06-03 Thread james.chen
From: "james.chen" 

This patch refer 3.10 driver code to solve firmware upgrade
issue(Change 266813) and enable noise-immunity(Change 243875).

BUG=chrome-os-partner:39373
TEST=Test Elan Touch Screen on cyan project without problems.
---
 drivers/input/touchscreen/elants_i2c.c | 2287 
 1 file changed, 1442 insertions(+), 845 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 0efd766..4abfcbc 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1,5 +1,5 @@
 /*
- * Elan Microelectronics touch panels with I2C interface
+ * Elan Microelectronics touchpanels with I2C interface
  *
  * Copyright (C) 2014 Elan Microelectronics Corporation.
  * Scott Liu 
@@ -16,12 +16,14 @@
  * Copyright (c) 2012 Benjamin Tissoires 
  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
  * Copyright (c) 2012 Red Hat, Inc
+ *
  */
 
 /*
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
  * may be copied, distributed, and modified under those terms.
+ *
  */
 
 #include 
@@ -33,195 +35,316 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
+/* debug option */
+static bool debug = false;
+module_param(debug, bool, 0444);
+MODULE_PARM_DESC(debug, "print a lot of debug information");
+
+#define elan_dbg(client, fmt, arg...) \
+   do { \
+   if (debug) \
+   dev_printk(KERN_DEBUG, >dev, fmt, ##arg); \
+   } while (0)
+
+#define ENTER_LOG() \
+   dev_dbg(>dev, "Enter: %s\n", __func__)
+
+
 /* Device, Driver information */
 #define DEVICE_NAME"elants_i2c"
-#define DRV_VERSION"1.0.9"
+#define DRV_VERSION"1.0.8"
+
+/* Finger report description */
+#define MAX_CONTACT_NUM10
+
+/* Buffer size, used for Read command handshake */
+#define FIFO_SIZE  64
+#define MAX_MESSAGE_SIZE   256
 
-/* Convert from rows or columns into resolution */
-#define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
 
-/* FW header data */
-#define HEADER_SIZE4
-#define FW_HDR_TYPE0
-#define FW_HDR_COUNT   1
-#define FW_HDR_LENGTH  2
+/*Convert from rows or columns into resolution */
+#define ELAN_TS_RESOLUTION(n, m)   ((n - 1) * m)
+
+/* Firmware boot mode packets definition */
+#define HELLO_PACKET_LEN   4
+#define RECOV_PACKET_LEN   4
+static const char hello_packet[HELLO_PACKET_LEN] = {0x55, 0x55, 0x55, 0x55};
+static const char recov_packet[RECOV_PACKET_LEN] = {0x55, 0x55, 0x80, 0x80};
+
+/* Finger report information */
+#defineREPORT_HEADER_10_FINGER 0x62
+#definePACKET_SIZE 55
+#defineMAX_PACKET_LEN  169
 
 /* Buffer mode Queue Header information */
-#define QUEUE_HEADER_SINGLE0x62
-#define QUEUE_HEADER_NORMAL0X63
-#define QUEUE_HEADER_WAIT  0x64
+#defineQUEUE_HEADER_SINGLE 0x62
+#defineQUEUE_HEADER_NORMAL 0X63
+#defineQUEUE_HEADER_WAIT   0x64
+#defineQUEUE_HEADER_SIZE   4
 
 /* Command header definition */
-#define CMD_HEADER_WRITE   0x54
-#define CMD_HEADER_READ0x53
-#define CMD_HEADER_6B_READ 0x5B
-#define CMD_HEADER_RESP0x52
-#define CMD_HEADER_6B_RESP 0x9B
-#define CMD_HEADER_HELLO   0x55
-#define CMD_HEADER_REK 0x66
-
-/* FW position data */
-#define PACKET_SIZE55
-#define MAX_CONTACT_NUM10
-#define FW_POS_HEADER  0
-#define FW_POS_STATE   1
-#define FW_POS_TOTAL   2
-#define FW_POS_XY  3
-#define FW_POS_CHECKSUM34
-#define FW_POS_WIDTH   35
-#define FW_POS_PRESSURE45
-
-#define HEADER_REPORT_10_FINGER0x62
-
-/* Header (4 bytes) plus 3 fill 10-finger packets */
-#define MAX_PACKET_SIZE169
-
-#define BOOT_TIME_DELAY_MS 50
+#defineCMD_HEADER_WRITE0x54
+#defineCMD_HEADER_READ 0x53
+#defineCMD_HEADER_5B_READ  0x5B
+#defineCMD_HEADER_RESP 0x52
+#defineCMD_HEADER_5B_RESP  0x9B
+#defineCMD_HEADER_HELLO0x55
+#defineCMD_HEADER_REK  0x66
+#define CMD_MAX_RESP_LEN   17
+
+/* FW information position */
+#defineFW_POS_HEADER   0
+#defineFW_POS_STATE1
+#defineFW_POS_TOTAL2
+#defineFW_POS_CHECKSUM 34
+#defineFW_POS_WIDTH35
+#defineFW_POS_PRESSURE 45
+
+/* test_bit definition */
+#defineLOCK_FILE_OPERATE   0
+#defineLOCK_CMD_HANDSHAKE  1
+#defineLOCK_FW_UPDATE  3
+
+#defineRET_OK  0
+#defineRET_CMDRSP  1
+#defineRET_FAIL-1
+
+/* define boot 

[PATCH] CHROMIUM: elants_i2c: Solved previous issue on 3.10 and 3.14.

2015-06-03 Thread james.chen
From: james.chen james.c...@emc.com.tw

This patch refer 3.10 driver code to solve firmware upgrade
issue(Change 266813) and enable noise-immunity(Change 243875).

BUG=chrome-os-partner:39373
TEST=Test Elan Touch Screen on cyan project without problems.
---
 drivers/input/touchscreen/elants_i2c.c | 2287 
 1 file changed, 1442 insertions(+), 845 deletions(-)

diff --git a/drivers/input/touchscreen/elants_i2c.c 
b/drivers/input/touchscreen/elants_i2c.c
index 0efd766..4abfcbc 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -1,5 +1,5 @@
 /*
- * Elan Microelectronics touch panels with I2C interface
+ * Elan Microelectronics touchpanels with I2C interface
  *
  * Copyright (C) 2014 Elan Microelectronics Corporation.
  * Scott Liu scott@emc.com.tw
@@ -16,12 +16,14 @@
  * Copyright (c) 2012 Benjamin Tissoires benjamin.tissoi...@gmail.com
  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
  * Copyright (c) 2012 Red Hat, Inc
+ *
  */
 
 /*
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
  * may be copied, distributed, and modified under those terms.
+ *
  */
 
 #include linux/module.h
@@ -33,195 +35,316 @@
 #include linux/delay.h
 #include linux/uaccess.h
 #include linux/buffer_head.h
+#include linux/version.h
 #include linux/slab.h
 #include linux/firmware.h
+#include linux/version.h
 #include linux/input/mt.h
 #include linux/acpi.h
 #include linux/of.h
 #include asm/unaligned.h
 
+/* debug option */
+static bool debug = false;
+module_param(debug, bool, 0444);
+MODULE_PARM_DESC(debug, print a lot of debug information);
+
+#define elan_dbg(client, fmt, arg...) \
+   do { \
+   if (debug) \
+   dev_printk(KERN_DEBUG, client-dev, fmt, ##arg); \
+   } while (0)
+
+#define ENTER_LOG() \
+   dev_dbg(client-dev, Enter: %s\n, __func__)
+
+
 /* Device, Driver information */
 #define DEVICE_NAMEelants_i2c
-#define DRV_VERSION1.0.9
+#define DRV_VERSION1.0.8
+
+/* Finger report description */
+#define MAX_CONTACT_NUM10
+
+/* Buffer size, used for Read command handshake */
+#define FIFO_SIZE  64
+#define MAX_MESSAGE_SIZE   256
 
-/* Convert from rows or columns into resolution */
-#define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
 
-/* FW header data */
-#define HEADER_SIZE4
-#define FW_HDR_TYPE0
-#define FW_HDR_COUNT   1
-#define FW_HDR_LENGTH  2
+/*Convert from rows or columns into resolution */
+#define ELAN_TS_RESOLUTION(n, m)   ((n - 1) * m)
+
+/* Firmware boot mode packets definition */
+#define HELLO_PACKET_LEN   4
+#define RECOV_PACKET_LEN   4
+static const char hello_packet[HELLO_PACKET_LEN] = {0x55, 0x55, 0x55, 0x55};
+static const char recov_packet[RECOV_PACKET_LEN] = {0x55, 0x55, 0x80, 0x80};
+
+/* Finger report information */
+#defineREPORT_HEADER_10_FINGER 0x62
+#definePACKET_SIZE 55
+#defineMAX_PACKET_LEN  169
 
 /* Buffer mode Queue Header information */
-#define QUEUE_HEADER_SINGLE0x62
-#define QUEUE_HEADER_NORMAL0X63
-#define QUEUE_HEADER_WAIT  0x64
+#defineQUEUE_HEADER_SINGLE 0x62
+#defineQUEUE_HEADER_NORMAL 0X63
+#defineQUEUE_HEADER_WAIT   0x64
+#defineQUEUE_HEADER_SIZE   4
 
 /* Command header definition */
-#define CMD_HEADER_WRITE   0x54
-#define CMD_HEADER_READ0x53
-#define CMD_HEADER_6B_READ 0x5B
-#define CMD_HEADER_RESP0x52
-#define CMD_HEADER_6B_RESP 0x9B
-#define CMD_HEADER_HELLO   0x55
-#define CMD_HEADER_REK 0x66
-
-/* FW position data */
-#define PACKET_SIZE55
-#define MAX_CONTACT_NUM10
-#define FW_POS_HEADER  0
-#define FW_POS_STATE   1
-#define FW_POS_TOTAL   2
-#define FW_POS_XY  3
-#define FW_POS_CHECKSUM34
-#define FW_POS_WIDTH   35
-#define FW_POS_PRESSURE45
-
-#define HEADER_REPORT_10_FINGER0x62
-
-/* Header (4 bytes) plus 3 fill 10-finger packets */
-#define MAX_PACKET_SIZE169
-
-#define BOOT_TIME_DELAY_MS 50
+#defineCMD_HEADER_WRITE0x54
+#defineCMD_HEADER_READ 0x53
+#defineCMD_HEADER_5B_READ  0x5B
+#defineCMD_HEADER_RESP 0x52
+#defineCMD_HEADER_5B_RESP  0x9B
+#defineCMD_HEADER_HELLO0x55
+#defineCMD_HEADER_REK  0x66
+#define CMD_MAX_RESP_LEN   17
+
+/* FW information position */
+#defineFW_POS_HEADER   0
+#defineFW_POS_STATE1
+#defineFW_POS_TOTAL2
+#defineFW_POS_CHECKSUM 34
+#defineFW_POS_WIDTH35
+#defineFW_POS_PRESSURE 45
+
+/* test_bit definition */
+#defineLOCK_FILE_OPERATE   0
+#define