[PATCH 3/3] Input: elan_i2c - Remove duplicate repeat code

2015-03-08 Thread Duson Lin
Remove duplicate "repeat--" from function elan_initialize.

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/elan_i2c_core.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index f24078b..4b970e2 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -198,7 +198,6 @@ static int elan_initialize(struct elan_tp_data *data)
if (!error)
return 0;
 
-   repeat--;
msleep(30);
} while (--repeat > 0);
 
-- 
1.7.10.4

--
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 3/3] Input: elan_i2c - Remove duplicate repeat code

2015-03-08 Thread Duson Lin
Remove duplicate repeat-- from function elan_initialize.

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/elan_i2c_core.c |1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index f24078b..4b970e2 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -198,7 +198,6 @@ static int elan_initialize(struct elan_tp_data *data)
if (!error)
return 0;
 
-   repeat--;
msleep(30);
} while (--repeat  0);
 
-- 
1.7.10.4

--
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: elan_i2c - Return error code when resume fail.

2015-03-07 Thread Duson Lin
The resume function always return success, so stop event can not be
triggered when "suspend_stress_test" running. In order to debug more
easily, we add some error messages in elan_enable_power and
elan_disable_power funtion.

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/elan_i2c_core.c |   10 +++---
 drivers/input/mouse/elan_i2c_i2c.c  |7 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 16f9584..f24078b 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -111,6 +111,7 @@ static int elan_enable_power(struct elan_tp_data *data)
msleep(30);
} while (--repeat > 0);
 
+   dev_err(>client->dev, "Failed to enable power\n");
return error;
 }
 
@@ -138,6 +139,7 @@ static int elan_disable_power(struct elan_tp_data *data)
msleep(30);
} while (--repeat > 0);
 
+   dev_err(>client->dev, "Failed to disable power\n");
return error;
 }
 
@@ -1084,16 +1086,18 @@ static int __maybe_unused elan_resume(struct device 
*dev)
}
 
error = elan_enable_power(data);
-   if (error)
+   if (error) {
dev_err(dev, "power up when resuming failed: %d\n", error);
+   goto err;
+   }
 
error = elan_initialize(data);
if (error)
dev_err(dev, "initialize when resuming failed: %d\n", error);
 
+err:
enable_irq(data->client->irq);
-
-   return 0;
+   return error;
 }
 
 static SIMPLE_DEV_PM_OPS(elan_pm_ops, elan_suspend, elan_resume);
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 029941f..e29b28c 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -117,7 +117,12 @@ static int elan_i2c_write_cmd(struct i2c_client *client, 
u16 reg, u16 cmd)
int ret;
 
ret = i2c_transfer(client->adapter, , 1);
-   return ret == 1 ? 0 : (ret < 0 ? ret : -EIO);
+   if (ret != 1) {
+   dev_err(>dev, "writing cmd (0x%04x) fail.\n", reg);
+   return ret < 0 ? ret : -EIO;
+   }
+
+   return 0;
 }
 
 static int elan_i2c_initialize(struct i2c_client *client)
-- 
1.7.10.4

--
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: elan_i2c - Return error code when resume fail.

2015-03-07 Thread Duson Lin
The resume function always return success, so stop event can not be
triggered when suspend_stress_test running. In order to debug more
easily, we add some error messages in elan_enable_power and
elan_disable_power funtion.

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/elan_i2c_core.c |   10 +++---
 drivers/input/mouse/elan_i2c_i2c.c  |7 ++-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 16f9584..f24078b 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -111,6 +111,7 @@ static int elan_enable_power(struct elan_tp_data *data)
msleep(30);
} while (--repeat  0);
 
+   dev_err(data-client-dev, Failed to enable power\n);
return error;
 }
 
@@ -138,6 +139,7 @@ static int elan_disable_power(struct elan_tp_data *data)
msleep(30);
} while (--repeat  0);
 
+   dev_err(data-client-dev, Failed to disable power\n);
return error;
 }
 
@@ -1084,16 +1086,18 @@ static int __maybe_unused elan_resume(struct device 
*dev)
}
 
error = elan_enable_power(data);
-   if (error)
+   if (error) {
dev_err(dev, power up when resuming failed: %d\n, error);
+   goto err;
+   }
 
error = elan_initialize(data);
if (error)
dev_err(dev, initialize when resuming failed: %d\n, error);
 
+err:
enable_irq(data-client-irq);
-
-   return 0;
+   return error;
 }
 
 static SIMPLE_DEV_PM_OPS(elan_pm_ops, elan_suspend, elan_resume);
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 029941f..e29b28c 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -117,7 +117,12 @@ static int elan_i2c_write_cmd(struct i2c_client *client, 
u16 reg, u16 cmd)
int ret;
 
ret = i2c_transfer(client-adapter, msg, 1);
-   return ret == 1 ? 0 : (ret  0 ? ret : -EIO);
+   if (ret != 1) {
+   dev_err(client-dev, writing cmd (0x%04x) fail.\n, reg);
+   return ret  0 ? ret : -EIO;
+   }
+
+   return 0;
 }
 
 static int elan_i2c_initialize(struct i2c_client *client)
-- 
1.7.10.4

--
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] Input: elan_i2c - Compare signature metadata before update fw

2015-03-06 Thread Duson Lin
To match different firmware file format, we replace original firmware file size
checking with the signature metadata comparison when update firmware, If failed,
the update will be aborted.

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/elan_i2c.h   |6 +++---
 drivers/input/mouse/elan_i2c_core.c  |   23 +--
 drivers/input/mouse/elan_i2c_i2c.c   |1 -
 drivers/input/mouse/elan_i2c_smbus.c |1 -
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h
index 2e83862..e100c1b 100644
--- a/drivers/input/mouse/elan_i2c.h
+++ b/drivers/input/mouse/elan_i2c.h
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -33,8 +32,9 @@
 #define ETP_FW_IAP_PAGE_ERR(1 << 5)
 #define ETP_FW_IAP_INTF_ERR(1 << 4)
 #define ETP_FW_PAGE_SIZE   64
-#define ETP_FW_PAGE_COUNT  768
-#define ETP_FW_SIZE(ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT)
+#define ETP_FW_VAILDPAGE_COUNT 768
+#define ETP_FW_SIGNATURE_SIZE  6
+#define ETP_FW_SIGNATURE_ADDRESS   0xBFFA
 
 struct i2c_client;
 struct completion;
diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 0cb2be4..16f9584 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
+ * Version: 1.5.6
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -40,7 +40,7 @@
 #include "elan_i2c.h"
 
 #define DRIVER_NAME"elan_i2c"
-#define ELAN_DRIVER_VERSION"1.5.5"
+#define ELAN_DRIVER_VERSION"1.5.6"
 #define ETP_PRESSURE_OFFSET25
 #define ETP_MAX_PRESSURE   255
 #define ETP_FWIDTH_REDUCE  90
@@ -312,7 +312,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
iap_start_addr = get_unaligned_le16(>data[ETP_IAP_START_ADDR * 2]);
 
boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
-   for (i = boot_page_count; i < ETP_FW_PAGE_COUNT; i++) {
+   for (i = boot_page_count; i < ETP_FW_VAILDPAGE_COUNT; i++) {
u16 checksum = 0;
const u8 *page = >data[i * ETP_FW_PAGE_SIZE];
 
@@ -434,10 +434,11 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
 {
-   struct i2c_client *client = to_i2c_client(dev);
-   struct elan_tp_data *data = i2c_get_clientdata(client);
+   struct elan_tp_data *data = dev_get_drvdata(dev);
const struct firmware *fw;
int error;
+   const u8 *fw_signature;
+   static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
 
error = request_firmware(, ETP_FW_NAME, dev);
if (error) {
@@ -446,10 +447,12 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
return error;
}
 
-   /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */
-   if (fw->size != ETP_FW_SIZE) {
-   dev_err(dev, "invalid firmware size = %zu, expected %d.\n",
-   fw->size, ETP_FW_SIZE);
+   /* Firmware file must match signature data */
+   fw_signature = >data[ETP_FW_SIGNATURE_ADDRESS];
+   if (memcmp(fw_signature, signature, sizeof(signature)) != 0) {
+   dev_err(dev, "signature mismatch (expected %*ph, got %*ph)\n",
+(int)sizeof(signature), signature,
+(int)sizeof(signature), fw_signature);
error = -EBADF;
goto out_release_fw;
}
@@ -464,7 +467,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 
 out_release_fw:
release_firmware(fw);
-   return error ?: count;
+   return error?: count;
 }
 
 static ssize_t calibrate_store(struct device *dev,
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 97d4937..029941f 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
diff --git a/drivers/input/mouse/elan_i2c_smbus.c 
b/drivers/input/mouse/elan_i2c_smbus.c
index 359bf85..5cd4a05 100644
--- a/drivers/input/mouse/elan_i2c_smbus.c
+++ b/drivers/input/mouse/elan_i2c_smbus.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (

[PATCH] Input: elan_i2c - Compare signature metadata before update fw

2015-03-06 Thread Duson Lin
To match different firmware file format, we replace original firmware file size
checking with the signature metadata comparison when update firmware, If failed,
the update will be aborted.

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/elan_i2c.h   |6 +++---
 drivers/input/mouse/elan_i2c_core.c  |   23 +--
 drivers/input/mouse/elan_i2c_i2c.c   |1 -
 drivers/input/mouse/elan_i2c_smbus.c |1 -
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h
index 2e83862..e100c1b 100644
--- a/drivers/input/mouse/elan_i2c.h
+++ b/drivers/input/mouse/elan_i2c.h
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -33,8 +32,9 @@
 #define ETP_FW_IAP_PAGE_ERR(1  5)
 #define ETP_FW_IAP_INTF_ERR(1  4)
 #define ETP_FW_PAGE_SIZE   64
-#define ETP_FW_PAGE_COUNT  768
-#define ETP_FW_SIZE(ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT)
+#define ETP_FW_VAILDPAGE_COUNT 768
+#define ETP_FW_SIGNATURE_SIZE  6
+#define ETP_FW_SIGNATURE_ADDRESS   0xBFFA
 
 struct i2c_client;
 struct completion;
diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 0cb2be4..16f9584 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
+ * Version: 1.5.6
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -40,7 +40,7 @@
 #include elan_i2c.h
 
 #define DRIVER_NAMEelan_i2c
-#define ELAN_DRIVER_VERSION1.5.5
+#define ELAN_DRIVER_VERSION1.5.6
 #define ETP_PRESSURE_OFFSET25
 #define ETP_MAX_PRESSURE   255
 #define ETP_FWIDTH_REDUCE  90
@@ -312,7 +312,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
iap_start_addr = get_unaligned_le16(fw-data[ETP_IAP_START_ADDR * 2]);
 
boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
-   for (i = boot_page_count; i  ETP_FW_PAGE_COUNT; i++) {
+   for (i = boot_page_count; i  ETP_FW_VAILDPAGE_COUNT; i++) {
u16 checksum = 0;
const u8 *page = fw-data[i * ETP_FW_PAGE_SIZE];
 
@@ -434,10 +434,11 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
 {
-   struct i2c_client *client = to_i2c_client(dev);
-   struct elan_tp_data *data = i2c_get_clientdata(client);
+   struct elan_tp_data *data = dev_get_drvdata(dev);
const struct firmware *fw;
int error;
+   const u8 *fw_signature;
+   static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
 
error = request_firmware(fw, ETP_FW_NAME, dev);
if (error) {
@@ -446,10 +447,12 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
return error;
}
 
-   /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */
-   if (fw-size != ETP_FW_SIZE) {
-   dev_err(dev, invalid firmware size = %zu, expected %d.\n,
-   fw-size, ETP_FW_SIZE);
+   /* Firmware file must match signature data */
+   fw_signature = fw-data[ETP_FW_SIGNATURE_ADDRESS];
+   if (memcmp(fw_signature, signature, sizeof(signature)) != 0) {
+   dev_err(dev, signature mismatch (expected %*ph, got %*ph)\n,
+(int)sizeof(signature), signature,
+(int)sizeof(signature), fw_signature);
error = -EBADF;
goto out_release_fw;
}
@@ -464,7 +467,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 
 out_release_fw:
release_firmware(fw);
-   return error ?: count;
+   return error?: count;
 }
 
 static ssize_t calibrate_store(struct device *dev,
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 97d4937..029941f 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
diff --git a/drivers/input/mouse/elan_i2c_smbus.c 
b/drivers/input/mouse/elan_i2c_smbus.c
index 359bf85..5cd4a05 100644
--- a/drivers/input/mouse/elan_i2c_smbus.c
+++ b/drivers/input/mouse/elan_i2c_smbus.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012

[PATCH] Input: elan_i2c - Compare signature metadata before update fw

2015-01-23 Thread Duson Lin
To match different firmware file format, we replace original firmware file size
checking with the signature metadata comparison when update firmware, If failed,
the update will be aborted.

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/elan_i2c.h   |6 +++---
 drivers/input/mouse/elan_i2c_core.c  |   23 +--
 drivers/input/mouse/elan_i2c_i2c.c   |1 -
 drivers/input/mouse/elan_i2c_smbus.c |1 -
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h
index 2e83862..e100c1b 100644
--- a/drivers/input/mouse/elan_i2c.h
+++ b/drivers/input/mouse/elan_i2c.h
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -33,8 +32,9 @@
 #define ETP_FW_IAP_PAGE_ERR(1 << 5)
 #define ETP_FW_IAP_INTF_ERR(1 << 4)
 #define ETP_FW_PAGE_SIZE   64
-#define ETP_FW_PAGE_COUNT  768
-#define ETP_FW_SIZE(ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT)
+#define ETP_FW_VAILDPAGE_COUNT 768
+#define ETP_FW_SIGNATURE_SIZE  6
+#define ETP_FW_SIGNATURE_ADDRESS   0xBFFA
 
 struct i2c_client;
 struct completion;
diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 0cb2be4..16f9584 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
+ * Version: 1.5.6
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -40,7 +40,7 @@
 #include "elan_i2c.h"
 
 #define DRIVER_NAME"elan_i2c"
-#define ELAN_DRIVER_VERSION"1.5.5"
+#define ELAN_DRIVER_VERSION"1.5.6"
 #define ETP_PRESSURE_OFFSET25
 #define ETP_MAX_PRESSURE   255
 #define ETP_FWIDTH_REDUCE  90
@@ -312,7 +312,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
iap_start_addr = get_unaligned_le16(>data[ETP_IAP_START_ADDR * 2]);
 
boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
-   for (i = boot_page_count; i < ETP_FW_PAGE_COUNT; i++) {
+   for (i = boot_page_count; i < ETP_FW_VAILDPAGE_COUNT; i++) {
u16 checksum = 0;
const u8 *page = >data[i * ETP_FW_PAGE_SIZE];
 
@@ -434,10 +434,11 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
 {
-   struct i2c_client *client = to_i2c_client(dev);
-   struct elan_tp_data *data = i2c_get_clientdata(client);
+   struct elan_tp_data *data = dev_get_drvdata(dev);
const struct firmware *fw;
int error;
+   const u8 *fw_signature;
+   static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
 
error = request_firmware(, ETP_FW_NAME, dev);
if (error) {
@@ -446,10 +447,12 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
return error;
}
 
-   /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */
-   if (fw->size != ETP_FW_SIZE) {
-   dev_err(dev, "invalid firmware size = %zu, expected %d.\n",
-   fw->size, ETP_FW_SIZE);
+   /* Firmware file must match signature data */
+   fw_signature = >data[ETP_FW_SIGNATURE_ADDRESS];
+   if (memcmp(fw_signature, signature, sizeof(signature)) != 0) {
+   dev_err(dev, "signature mismatch (expected %*ph, got %*ph)\n",
+(int)sizeof(signature), signature,
+(int)sizeof(signature), fw_signature);
error = -EBADF;
goto out_release_fw;
}
@@ -464,7 +467,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 
 out_release_fw:
release_firmware(fw);
-   return error ?: count;
+   return error?: count;
 }
 
 static ssize_t calibrate_store(struct device *dev,
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 97d4937..029941f 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
diff --git a/drivers/input/mouse/elan_i2c_smbus.c 
b/drivers/input/mouse/elan_i2c_smbus.c
index 359bf85..5cd4a05 100644
--- a/drivers/input/mouse/elan_i2c_smbus.c
+++ b/drivers/input/mouse/elan_i2c_smbus.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) 
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (

[PATCH] Input: elan_i2c - Compare signature metadata before update fw

2015-01-23 Thread Duson Lin
To match different firmware file format, we replace original firmware file size
checking with the signature metadata comparison when update firmware, If failed,
the update will be aborted.

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/elan_i2c.h   |6 +++---
 drivers/input/mouse/elan_i2c_core.c  |   23 +--
 drivers/input/mouse/elan_i2c_i2c.c   |1 -
 drivers/input/mouse/elan_i2c_smbus.c |1 -
 4 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h
index 2e83862..e100c1b 100644
--- a/drivers/input/mouse/elan_i2c.h
+++ b/drivers/input/mouse/elan_i2c.h
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -33,8 +32,9 @@
 #define ETP_FW_IAP_PAGE_ERR(1  5)
 #define ETP_FW_IAP_INTF_ERR(1  4)
 #define ETP_FW_PAGE_SIZE   64
-#define ETP_FW_PAGE_COUNT  768
-#define ETP_FW_SIZE(ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT)
+#define ETP_FW_VAILDPAGE_COUNT 768
+#define ETP_FW_SIGNATURE_SIZE  6
+#define ETP_FW_SIGNATURE_ADDRESS   0xBFFA
 
 struct i2c_client;
 struct completion;
diff --git a/drivers/input/mouse/elan_i2c_core.c 
b/drivers/input/mouse/elan_i2c_core.c
index 0cb2be4..16f9584 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -4,7 +4,7 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
+ * Version: 1.5.6
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -40,7 +40,7 @@
 #include elan_i2c.h
 
 #define DRIVER_NAMEelan_i2c
-#define ELAN_DRIVER_VERSION1.5.5
+#define ELAN_DRIVER_VERSION1.5.6
 #define ETP_PRESSURE_OFFSET25
 #define ETP_MAX_PRESSURE   255
 #define ETP_FWIDTH_REDUCE  90
@@ -312,7 +312,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
iap_start_addr = get_unaligned_le16(fw-data[ETP_IAP_START_ADDR * 2]);
 
boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
-   for (i = boot_page_count; i  ETP_FW_PAGE_COUNT; i++) {
+   for (i = boot_page_count; i  ETP_FW_VAILDPAGE_COUNT; i++) {
u16 checksum = 0;
const u8 *page = fw-data[i * ETP_FW_PAGE_SIZE];
 
@@ -434,10 +434,11 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
 {
-   struct i2c_client *client = to_i2c_client(dev);
-   struct elan_tp_data *data = i2c_get_clientdata(client);
+   struct elan_tp_data *data = dev_get_drvdata(dev);
const struct firmware *fw;
int error;
+   const u8 *fw_signature;
+   static const u8 signature[] = {0xAA, 0x55, 0xCC, 0x33, 0xFF, 0xFF};
 
error = request_firmware(fw, ETP_FW_NAME, dev);
if (error) {
@@ -446,10 +447,12 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
return error;
}
 
-   /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */
-   if (fw-size != ETP_FW_SIZE) {
-   dev_err(dev, invalid firmware size = %zu, expected %d.\n,
-   fw-size, ETP_FW_SIZE);
+   /* Firmware file must match signature data */
+   fw_signature = fw-data[ETP_FW_SIGNATURE_ADDRESS];
+   if (memcmp(fw_signature, signature, sizeof(signature)) != 0) {
+   dev_err(dev, signature mismatch (expected %*ph, got %*ph)\n,
+(int)sizeof(signature), signature,
+(int)sizeof(signature), fw_signature);
error = -EBADF;
goto out_release_fw;
}
@@ -464,7 +467,7 @@ static ssize_t elan_sysfs_update_fw(struct device *dev,
 
 out_release_fw:
release_firmware(fw);
-   return error ?: count;
+   return error?: count;
 }
 
 static ssize_t calibrate_store(struct device *dev,
diff --git a/drivers/input/mouse/elan_i2c_i2c.c 
b/drivers/input/mouse/elan_i2c_i2c.c
index 97d4937..029941f 100644
--- a/drivers/input/mouse/elan_i2c_i2c.c
+++ b/drivers/input/mouse/elan_i2c_i2c.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
diff --git a/drivers/input/mouse/elan_i2c_smbus.c 
b/drivers/input/mouse/elan_i2c_smbus.c
index 359bf85..5cd4a05 100644
--- a/drivers/input/mouse/elan_i2c_smbus.c
+++ b/drivers/input/mouse/elan_i2c_smbus.c
@@ -4,7 +4,6 @@
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
  * Author: 林政維 (Duson Lin) duson...@emc.com.tw
- * Version: 1.5.5
  *
  * Based on cyapa driver:
  * copyright (c) 2011-2012

[PATCH v2] Input: add i2c/smbus driver for elan touchpad

2014-01-06 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  890 
 3 files changed, 901 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate "ELAN I2C Touchpad support"
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate "InPort/MS/ATIXL busmouse"
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..f7bfa22
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,890 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) 
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME"elan_i2c"
+#define ELAN_DRIVER_VERSION"1.4.6"
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (1<<6)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   

[PATCH v2] Input: add i2c/smbus driver for elan touchpad

2014-01-06 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  890 
 3 files changed, 901 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate ELAN I2C Touchpad support
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate InPort/MS/ATIXL busmouse
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..f7bfa22
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,890 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) duson...@emc.com.tw
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/firmware.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/input/mt.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/cdev.h
+#include linux/kernel.h
+#include linux/major.h
+#include linux/sched.h
+#include linux/input.h
+#include linux/uaccess.h
+#include linux/jiffies.h
+
+#define DRIVER_NAMEelan_i2c
+#define ELAN_DRIVER_VERSION1.4.6
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (16)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define

[PATCH v2] Input: add i2c/smbus driver for elan touchpad

2013-12-17 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  890 
 3 files changed, 901 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate "ELAN I2C Touchpad support"
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate "InPort/MS/ATIXL busmouse"
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..f7bfa22
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,890 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) 
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME"elan_i2c"
+#define ELAN_DRIVER_VERSION"1.4.6"
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (1<<6)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   

[PATCH v2] Input: add i2c/smbus driver for elan touchpad

2013-12-17 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  890 
 3 files changed, 901 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate ELAN I2C Touchpad support
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate InPort/MS/ATIXL busmouse
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..f7bfa22
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,890 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) duson...@emc.com.tw
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/firmware.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/input/mt.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/cdev.h
+#include linux/kernel.h
+#include linux/major.h
+#include linux/sched.h
+#include linux/input.h
+#include linux/uaccess.h
+#include linux/jiffies.h
+
+#define DRIVER_NAMEelan_i2c
+#define ELAN_DRIVER_VERSION1.4.6
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (16)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define

[PATCH] Input: add i2c/smbus driver for elan touchpad

2013-12-16 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  908 
 3 files changed, 919 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate "ELAN I2C Touchpad support"
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate "InPort/MS/ATIXL busmouse"
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..a5a11bb
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,908 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) 
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME"elan_i2c"
+#define ELAN_DRIVER_VERSION"1.4.6"
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (1<<6)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   

[PATCH] Input: add i2c/smbus driver for elan touchpad

2013-12-16 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c |  908 
 3 files changed, 919 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..095eccc 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate ELAN I2C Touchpad support
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say Y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate InPort/MS/ATIXL busmouse
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..a5a11bb
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,908 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) duson...@emc.com.tw
+ * Version: 1.4.6
+ *
+ * Based on cyapa driver:
+ * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
+ * copyright (c) 2011-2012 Google, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/firmware.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/input/mt.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/cdev.h
+#include linux/kernel.h
+#include linux/major.h
+#include linux/sched.h
+#include linux/input.h
+#include linux/uaccess.h
+#include linux/jiffies.h
+
+#define DRIVER_NAMEelan_i2c
+#define ELAN_DRIVER_VERSION1.4.6
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_SLEEP_CMD0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (16)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define

[PATCH] Add: (1) Detection for newer Elantech touchpads, so that kernel doesn't fall-back to default PS/2 driver. (2) Enable hardware version 4 touchpad right click function.

2013-12-08 Thread Duson Lin
Modify:
(1) crc_enabled only support for v3 and v4 touchpad, so initialize crc_enabled 
as false first and
check this hardware flag when hw_version as 3 or 4.

Signed-off-by: Duson Lin 
---
 drivers/input/mouse/elantech.c |   30 ++
 drivers/input/mouse/elantech.h |2 +-
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 8551dca..b3627cf 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1,5 +1,5 @@
 /*
- * Elantech Touchpad driver (v6)
+ * Elantech Touchpad driver (v7)
  *
  * Copyright (C) 2007-2009 Arjan Opmeer 
  *
@@ -486,6 +486,7 @@ static void elantech_input_sync_v4(struct psmouse *psmouse)
unsigned char *packet = psmouse->packet;
 
input_report_key(dev, BTN_LEFT, packet[0] & 0x01);
+   input_report_key(dev, BTN_RIGHT, packet[0] & 0x02);
input_mt_report_pointer_emulation(dev, true);
input_sync(dev);
 }
@@ -1047,9 +1048,7 @@ static int elantech_set_input_params(struct psmouse 
*psmouse)
 */
psmouse_warn(psmouse, "couldn't query resolution 
data.\n");
}
-   /* v4 is clickpad, with only one button. */
__set_bit(INPUT_PROP_BUTTONPAD, dev->propbit);
-   __clear_bit(BTN_RIGHT, dev->keybit);
__set_bit(BTN_TOOL_QUADTAP, dev->keybit);
/* For X to recognize me as touchpad. */
input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
@@ -1186,19 +1185,12 @@ static struct attribute_group elantech_attr_group = {
 
 static bool elantech_is_signature_valid(const unsigned char *param)
 {
-   static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10 };
-   int i;
-
if (param[0] == 0)
return false;
 
if (param[1] == 0)
return true;
 
-   for (i = 0; i < ARRAY_SIZE(rates); i++)
-   if (param[2] == rates[i])
-   return false;
-
return true;
 }
 
@@ -1298,6 +1290,14 @@ static int elantech_set_properties(struct elantech_data 
*etd)
 {
/* This represents the version of IC body. */
int ver = (etd->fw_version & 0x0f) >> 16;
+   /*
+* The signatures of v3 and v4 packets change depending on the
+* value of this hardware flag. But the v1 and v2 have not crc
+* check mechanism and the same hardware flag are also defined
+* as other function. So crc_enabled must be initialized as false 
+* first and checking by different hw_version.
+*/
+   etd->crc_enabled = false;
 
/* Early version of Elan touchpads doesn't obey the rule. */
if (etd->fw_version < 0x020030 || etd->fw_version == 0x020600)
@@ -1309,10 +1309,14 @@ static int elantech_set_properties(struct elantech_data 
*etd)
etd->hw_version = 2;
break;
case 5:
+   etd->crc_enabled = ((etd->fw_version & 0x4000) == 
0x4000);
etd->hw_version = 3;
break;
case 6:
case 7:
+   case 8:
+   case 10:
+   etd->crc_enabled = ((etd->fw_version & 0x4000) == 
0x4000);
etd->hw_version = 4;
break;
default:
@@ -1343,12 +1347,6 @@ static int elantech_set_properties(struct elantech_data 
*etd)
etd->reports_pressure = true;
}
 
-   /*
-* The signatures of v3 and v4 packets change depending on the
-* value of this hardware flag.
-*/
-   etd->crc_enabled = ((etd->fw_version & 0x4000) == 0x4000);
-
return 0;
 }
 
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h
index 036a04a..c963ac8 100644
--- a/drivers/input/mouse/elantech.h
+++ b/drivers/input/mouse/elantech.h
@@ -1,5 +1,5 @@
 /*
- * Elantech Touchpad driver (v6)
+ * Elantech Touchpad driver (v7)
  *
  * Copyright (C) 2007-2009 Arjan Opmeer 
  *
-- 
1.7.10.4

--
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] Add: (1) Detection for newer Elantech touchpads, so that kernel doesn't fall-back to default PS/2 driver. (2) Enable hardware version 4 touchpad right click function.

2013-12-08 Thread Duson Lin
Modify:
(1) crc_enabled only support for v3 and v4 touchpad, so initialize crc_enabled 
as false first and
check this hardware flag when hw_version as 3 or 4.

Signed-off-by: Duson Lin duson...@emc.com.tw
---
 drivers/input/mouse/elantech.c |   30 ++
 drivers/input/mouse/elantech.h |2 +-
 2 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/drivers/input/mouse/elantech.c b/drivers/input/mouse/elantech.c
index 8551dca..b3627cf 100644
--- a/drivers/input/mouse/elantech.c
+++ b/drivers/input/mouse/elantech.c
@@ -1,5 +1,5 @@
 /*
- * Elantech Touchpad driver (v6)
+ * Elantech Touchpad driver (v7)
  *
  * Copyright (C) 2007-2009 Arjan Opmeer ar...@opmeer.net
  *
@@ -486,6 +486,7 @@ static void elantech_input_sync_v4(struct psmouse *psmouse)
unsigned char *packet = psmouse-packet;
 
input_report_key(dev, BTN_LEFT, packet[0]  0x01);
+   input_report_key(dev, BTN_RIGHT, packet[0]  0x02);
input_mt_report_pointer_emulation(dev, true);
input_sync(dev);
 }
@@ -1047,9 +1048,7 @@ static int elantech_set_input_params(struct psmouse 
*psmouse)
 */
psmouse_warn(psmouse, couldn't query resolution 
data.\n);
}
-   /* v4 is clickpad, with only one button. */
__set_bit(INPUT_PROP_BUTTONPAD, dev-propbit);
-   __clear_bit(BTN_RIGHT, dev-keybit);
__set_bit(BTN_TOOL_QUADTAP, dev-keybit);
/* For X to recognize me as touchpad. */
input_set_abs_params(dev, ABS_X, x_min, x_max, 0, 0);
@@ -1186,19 +1185,12 @@ static struct attribute_group elantech_attr_group = {
 
 static bool elantech_is_signature_valid(const unsigned char *param)
 {
-   static const unsigned char rates[] = { 200, 100, 80, 60, 40, 20, 10 };
-   int i;
-
if (param[0] == 0)
return false;
 
if (param[1] == 0)
return true;
 
-   for (i = 0; i  ARRAY_SIZE(rates); i++)
-   if (param[2] == rates[i])
-   return false;
-
return true;
 }
 
@@ -1298,6 +1290,14 @@ static int elantech_set_properties(struct elantech_data 
*etd)
 {
/* This represents the version of IC body. */
int ver = (etd-fw_version  0x0f)  16;
+   /*
+* The signatures of v3 and v4 packets change depending on the
+* value of this hardware flag. But the v1 and v2 have not crc
+* check mechanism and the same hardware flag are also defined
+* as other function. So crc_enabled must be initialized as false 
+* first and checking by different hw_version.
+*/
+   etd-crc_enabled = false;
 
/* Early version of Elan touchpads doesn't obey the rule. */
if (etd-fw_version  0x020030 || etd-fw_version == 0x020600)
@@ -1309,10 +1309,14 @@ static int elantech_set_properties(struct elantech_data 
*etd)
etd-hw_version = 2;
break;
case 5:
+   etd-crc_enabled = ((etd-fw_version  0x4000) == 
0x4000);
etd-hw_version = 3;
break;
case 6:
case 7:
+   case 8:
+   case 10:
+   etd-crc_enabled = ((etd-fw_version  0x4000) == 
0x4000);
etd-hw_version = 4;
break;
default:
@@ -1343,12 +1347,6 @@ static int elantech_set_properties(struct elantech_data 
*etd)
etd-reports_pressure = true;
}
 
-   /*
-* The signatures of v3 and v4 packets change depending on the
-* value of this hardware flag.
-*/
-   etd-crc_enabled = ((etd-fw_version  0x4000) == 0x4000);
-
return 0;
 }
 
diff --git a/drivers/input/mouse/elantech.h b/drivers/input/mouse/elantech.h
index 036a04a..c963ac8 100644
--- a/drivers/input/mouse/elantech.h
+++ b/drivers/input/mouse/elantech.h
@@ -1,5 +1,5 @@
 /*
- * Elantech Touchpad driver (v6)
+ * Elantech Touchpad driver (v7)
  *
  * Copyright (C) 2007-2009 Arjan Opmeer ar...@opmeer.net
  *
-- 
1.7.10.4

--
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] Input: add i2c/smbus driver for elan touchpad

2013-11-22 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c | 1846 
 3 files changed, 1857 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..8ad4b38 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate "ELAN I2C Touchpad support"
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate "InPort/MS/ATIXL busmouse"
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..9892ee1
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,1846 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) 
+ * Version: 1.4.6
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME"elan_i2c"
+#define ELAN_DRIVER_VERSION"1.4.6"
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_DISABLE_TP   0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (1<<6)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   0x0101
+#define ETP_I2C_FW_VERSION_CMD 0x0102
+#define ETP_I2C_SM_VERSION_CMD 0x0103
+#define ETP_I2C_XY_TRACENUM_CMD

[PATCH] Input: add i2c/smbus driver for elan touchpad

2013-11-22 Thread Duson Lin
This driver adds support for elan i2c/smbus touchpad found on some laptops PC
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c | 1846 
 3 files changed, 1857 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..8ad4b38 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate ELAN I2C Touchpad support
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate InPort/MS/ATIXL busmouse
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..9892ee1
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,1846 @@
+/*
+ * Elan I2C/SMBus Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) duson...@emc.com.tw
+ * Version: 1.4.6
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/firmware.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/input/mt.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/cdev.h
+#include linux/kernel.h
+#include linux/major.h
+#include linux/sched.h
+#include linux/input.h
+#include linux/uaccess.h
+#include linux/jiffies.h
+
+#define DRIVER_NAMEelan_i2c
+#define ELAN_DRIVER_VERSION1.4.6
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+#define ELAN_ADAPTER_FUNC_SMBUS  2
+#define ELAN_ADAPTER_FUNC_BOTH   3
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan smbus command */
+#define ETP_SMBUS_IAP_CMD  0x00
+#define ETP_SMBUS_ENABLE_TP0x20
+#define ETP_SMBUS_DISABLE_TP   0x21
+#define ETP_SMBUS_IAP_PASSWORD_WRITE   0x29
+#define ETP_SMBUS_IAP_PASSWORD_READ0x80
+#define ETP_SMBUS_WRITE_FW_BLOCK   0x2A
+#define ETP_SMBUS_IAP_RESET_CMD0x2B
+#define ETP_SMBUS_RANGE_CMD0xA0
+#define ETP_SMBUS_FW_VERSION_CMD   0xA1
+#define ETP_SMBUS_XY_TRACENUM_CMD  0xA2
+#define ETP_SMBUS_SM_VERSION_CMD   0xA3
+#define ETP_SMBUS_UNIQUEID_CMD 0xA3
+#define ETP_SMBUS_RESOLUTION_CMD   0xA4
+#define ETP_SMBUS_HELLOPACKET_CMD  0xA7
+#define ETP_SMBUS_PACKET_QUERY 0xA8
+#define ETP_SMBUS_IAP_VERSION_CMD  0xAC
+#define ETP_SMBUS_IAP_CTRL_CMD 0xAD
+#define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE
+#define ETP_SMBUS_FW_CHECKSUM_CMD  0xAF
+#define ETP_SMBUS_MAX_BASELINE_CMD 0xC3
+#define ETP_SMBUS_MIN_BASELINE_CMD 0xC4
+#define ETP_SMBUS_CALIBRATE_QUERY  0xC5
+#define ETP_SMBUS_REPORT_LEN   32
+#define ETP_SMBUS_FINGER_DATA_OFFSET   2
+#define ETP_SMBUS_HELLOPACKET_LEN  5
+#define ETP_SMBUS_IAP_PASSWORD 0x1234
+#define ETP_SMBUS_IAP_MODE_ON  (16)
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD

[PATCH] Input: add i2c driver for elan i2c touchpad

2013-10-23 Thread Duson Lin
From: Duson Lin 

This driver adds support for elan i2c touchpad found on some laptops.
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c | 1439 
 3 files changed, 1450 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..8ad4b38 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate "ELAN I2C Touchpad support"
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate "InPort/MS/ATIXL busmouse"
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..bc6e957
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,1439 @@
+/*
+ * Elan I2C Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) 
+ * Version: 1.4.5
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME"elan_i2c"
+#define ELAN_DRIVER_VERSION"1.4.5"
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   0x0101
+#define ETP_I2C_FW_VERSION_CMD 0x0102
+#define ETP_I2C_SM_VERSION_CMD 0x0103
+#define ETP_I2C_XY_TRACENUM_CMD0x0105
+#define ETP_I2C_MAX_X_AXIS_CMD 0x0106
+#define ETP_I2C_MAX_Y_AXIS_CMD 0x0107
+#define ETP_I2C_RESOLUTION_CMD 0x0108
+#define ETP_I2C_IAP_VERSION_CMD0x0110
+#define ETP_I2C_SET_CMD0x0300
+#define ETP_I2C_MAX_BASELINE_CMD   0x0306
+#define ETP_I2C_MIN_BASELINE_CMD   0x0307
+#define ETP_I2C_FW_CHECKSUM_CMD0x030F
+#define ETP_I2C_IAP_CTRL_CMD   0x0310
+#define ETP_I2C_IAP_CMD0x0311
+#define ETP_I2C_IAP_RESET_CMD  0x0314
+#define ETP_I2C_IAP_CHECKSUM_CMD   0x0315
+#define ETP_I2C_CALIBRATE_CMD  0x0316
+#define ETP_I2C_REPORT_LEN 34
+#define ETP_I2C_FINGER_DATA_OFFSET 4
+#define ETP_I2C_REPORT_ID_OFFSET   2
+#define ETP_I2C_DESC_LENGTH30
+#define ETP_I2C_REPORT_DESC_LENGTH 158
+
+/* IAP F/W updater */
+#define ETP_FW_NAME"elan_i2c.bin"
+#define ETP_FW_IAP_REG_L   0x01
+#define ETP_FW_IAP_REG_H   0x06
+#define ETP_IAP_VERSION_ADDR   0x0082
+#define ETP_IAP_START_ADDR 0x0083
+#define ETP_IAP_RESET  0xF0F0
+#define ETP_ENABLE_FWUPDATE0x1EA5
+#define ETP_FW_IAP_MODE_ON (1<<9)
+#define ETP_FW_IAP_PAGE_ERR(1<<5)
+#define ETP_FW_IAP_INTERFACE_ERR (1<<4)
+#define ET

[PATCH] Input: add i2c driver for elan i2c touchpad

2013-10-23 Thread Duson Lin
From: Duson Lin duson...@emc.com.tw

This driver adds support for elan i2c touchpad found on some laptops.
---
 drivers/input/mouse/Kconfig|   10 +
 drivers/input/mouse/Makefile   |1 +
 drivers/input/mouse/elan_i2c.c | 1439 
 3 files changed, 1450 insertions(+)
 create mode 100644 drivers/input/mouse/elan_i2c.c

diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index effa9c5..8ad4b38 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -215,6 +215,16 @@ config MOUSE_CYAPA
  To compile this driver as a module, choose M here: the module will be
  called cyapa.
 
+config MOUSE_ELAN_I2C
+   tristate ELAN I2C Touchpad support
+   depends on I2C
+   help
+ This driver adds support for Elan I2C Trackpads.
+ Say y here if you have a ELAN I2C Touchpad.
+
+ To compile this driver as a module, choose M here: the module will be
+ called elan_i2c.
+
 config MOUSE_INPORT
tristate InPort/MS/ATIXL busmouse
depends on ISA
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index c25efdb..24a12a6 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH)  += appletouch.o
 obj-$(CONFIG_MOUSE_ATARI)  += atarimouse.o
 obj-$(CONFIG_MOUSE_BCM5974)+= bcm5974.o
 obj-$(CONFIG_MOUSE_CYAPA)  += cyapa.o
+obj-$(CONFIG_MOUSE_ELAN_I2C)   += elan_i2c.o
 obj-$(CONFIG_MOUSE_GPIO)   += gpio_mouse.o
 obj-$(CONFIG_MOUSE_INPORT) += inport.o
 obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
diff --git a/drivers/input/mouse/elan_i2c.c b/drivers/input/mouse/elan_i2c.c
new file mode 100644
index 000..bc6e957
--- /dev/null
+++ b/drivers/input/mouse/elan_i2c.c
@@ -0,0 +1,1439 @@
+/*
+ * Elan I2C Touchpad driver
+ *
+ * Copyright (c) 2013 ELAN Microelectronics Corp.
+ *
+ * Author: 林政維 (Duson Lin) duson...@emc.com.tw
+ * Version: 1.4.5
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published
+ * by the Free Software Foundation.
+ *
+ * Trademarks are the property of their respective owners.
+ */
+
+#include linux/delay.h
+#include linux/device.h
+#include linux/firmware.h
+#include linux/i2c.h
+#include linux/init.h
+#include linux/input/mt.h
+#include linux/interrupt.h
+#include linux/module.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/cdev.h
+#include linux/kernel.h
+#include linux/major.h
+#include linux/sched.h
+#include linux/input.h
+#include linux/uaccess.h
+#include linux/jiffies.h
+
+#define DRIVER_NAMEelan_i2c
+#define ELAN_DRIVER_VERSION1.4.5
+#define ETP_PRESSURE_OFFSET25
+#define ETP_MAX_PRESSURE   255
+#define ETP_FWIDTH_REDUCE  90
+#define ETP_FINGER_WIDTH   15
+
+#define ELAN_ADAPTER_FUNC_NONE   0
+#define ELAN_ADAPTER_FUNC_I2C1
+
+/* Length of Elan touchpad information */
+#define ETP_INF_LENGTH 2
+#define ETP_MAX_FINGERS5
+#define ETP_FINGER_DATA_LEN5
+#define ETP_REPORT_ID  0x5D
+#define ETP_MAX_REPORT_LEN 34
+#define ETP_ENABLE_ABS 0x0001
+#define ETP_ENABLE_CALIBRATE   0x0002
+#define ETP_DISABLE_CALIBRATE  0x
+
+/* Elan i2c command */
+#define ETP_I2C_RESET  0x0100
+#define ETP_I2C_WAKE_UP0x0800
+#define ETP_I2C_SLEEP  0x0801
+#define ETP_I2C_DESC_CMD   0x0001
+#define ETP_I2C_REPORT_DESC_CMD0x0002
+#define ETP_I2C_STAND_CMD  0x0005
+#define ETP_I2C_UNIQUEID_CMD   0x0101
+#define ETP_I2C_FW_VERSION_CMD 0x0102
+#define ETP_I2C_SM_VERSION_CMD 0x0103
+#define ETP_I2C_XY_TRACENUM_CMD0x0105
+#define ETP_I2C_MAX_X_AXIS_CMD 0x0106
+#define ETP_I2C_MAX_Y_AXIS_CMD 0x0107
+#define ETP_I2C_RESOLUTION_CMD 0x0108
+#define ETP_I2C_IAP_VERSION_CMD0x0110
+#define ETP_I2C_SET_CMD0x0300
+#define ETP_I2C_MAX_BASELINE_CMD   0x0306
+#define ETP_I2C_MIN_BASELINE_CMD   0x0307
+#define ETP_I2C_FW_CHECKSUM_CMD0x030F
+#define ETP_I2C_IAP_CTRL_CMD   0x0310
+#define ETP_I2C_IAP_CMD0x0311
+#define ETP_I2C_IAP_RESET_CMD  0x0314
+#define ETP_I2C_IAP_CHECKSUM_CMD   0x0315
+#define ETP_I2C_CALIBRATE_CMD  0x0316
+#define ETP_I2C_REPORT_LEN 34
+#define ETP_I2C_FINGER_DATA_OFFSET 4
+#define ETP_I2C_REPORT_ID_OFFSET   2
+#define ETP_I2C_DESC_LENGTH30
+#define ETP_I2C_REPORT_DESC_LENGTH 158
+
+/* IAP F/W updater */
+#define ETP_FW_NAMEelan_i2c.bin
+#define ETP_FW_IAP_REG_L   0x01
+#define ETP_FW_IAP_REG_H   0x06
+#define ETP_IAP_VERSION_ADDR   0x0082
+#define ETP_IAP_START_ADDR 0x0083
+#define