Input: /input/mouse/elan_i2c_core.c Fix some Asus touchapod which casue TP no funciton sometimes, the patch detect some specific touchpad and run a special initialize
diff mbox

Message ID 1467979929-3409-1-git-send-email-kt.liao@emc.com.tw
State Under Review
Headers show

Commit Message

KT Liao July 8, 2016, 12:12 p.m. UTC
Signed-off-by: KT Liao <kt.liao@emc.com.tw>
---
 drivers/input/mouse/elan_i2c_core.c | 81 +++++++++++++++++++++++++++++--------
 1 file changed, 65 insertions(+), 16 deletions(-)

Comments

Dmitry Torokhov July 9, 2016, 12:24 a.m. UTC | #1
Hi KT,

On Fri, Jul 08, 2016 at 08:12:09PM +0800, KT Liao wrote:
> Signed-off-by: KT Liao <kt.liao@emc.com.tw>

Please make sure you add a blan line between change subject and the rest
of description. Then git send-email will compose your email properly
instead of lumping everything into one long line subject.

> ---
>  drivers/input/mouse/elan_i2c_core.c | 81 +++++++++++++++++++++++++++++--------
>  1 file changed, 65 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
> index 2f58985..1c200fb 100644
> --- a/drivers/input/mouse/elan_i2c_core.c
> +++ b/drivers/input/mouse/elan_i2c_core.c
> @@ -3,8 +3,8 @@
>   *
>   * Copyright (c) 2013 ELAN Microelectronics Corp.
>   *
> - * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
> - * Version: 1.6.0
> + * Author: KT Liao <kt.liao@emc.com.tw>
> + * Version: 1.6.2
>   *
>   * 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.6.1"
> +#define ELAN_DRIVER_VERSION	"1.6.2"
>  #define ELAN_VENDOR_ID		0x04f3
>  #define ETP_MAX_PRESSURE	255
>  #define ETP_FWIDTH_REDUCE	90
> @@ -95,6 +95,8 @@ struct elan_tp_data {
>  	bool			baseline_ready;
>  };
>  
> +static int check_ASUS_special_fw(struct elan_tp_data *data);
> +
>  static int elan_get_fwinfo(u8 iap_version, u16 *validpage_count,
>  			   u16 *signature_address)
>  {
> @@ -210,21 +212,40 @@ static int __elan_initialize(struct elan_tp_data *data)
>  		return error;
>  	}
>  
> -	data->mode |= ETP_ENABLE_ABS;
> -	error = data->ops->set_mode(client, data->mode);
> -	if (error) {
> -		dev_err(&client->dev,
> -			"failed to switch to absolute mode: %d\n", error);
> -		return error;
> -	}
> +	/* If it's the special FW, it need a different flow for mode change.*/
> +	if (check_ASUS_special_fw(data)) {
> +		error = data->ops->sleep_control(client, false);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to wake device up: %d\n", error);
> +			return error;
> +		}
>  
> -	error = data->ops->sleep_control(client, false);
> -	if (error) {
> -		dev_err(&client->dev,
> -			"failed to wake device up: %d\n", error);
> -		return error;
> -	}
> +		msleep(200);
>  
> +		data->mode |= ETP_ENABLE_ABS;
> +		error = data->ops->set_mode(client, data->mode);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to switch to absolute mode: %d\n", error);
> +			return error;
> +		}
> +	} else {
> +		data->mode |= ETP_ENABLE_ABS;
> +		error = data->ops->set_mode(client, data->mode);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to switch to absolute mode: %d\n", error);
> +			return error;
> +		}
> +
> +		error = data->ops->sleep_control(client, false);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to wake device up: %d\n", error);
> +			return error;
> +		}
> +	}
>  	return 0;
>  }
>  
> @@ -757,6 +778,34 @@ out:
>  	return retval;
>  }
>  
> +static int check_ASUS_special_fw(struct elan_tp_data *data)
> +{
> +	struct i2c_client *client = data->client;
> +	int error;
> +
> +	error = data->ops->get_product_id(client, &data->product_id);
> +	if (error)
> +		return false;
> +
> +	error = data->ops->get_sm_version(client, &data->ic_type,
> +					  &data->sm_version);
> +	if (error)
> +		return false;

That means we'd be fetching product ID and IC type twice when
initializing the device. Can we come with a way to do it once?

> +
> +	if (data->ic_type == 0x0E) {

Maybe

	if (dat->ic_type != 0x0e)
		return false;

? Then you would not need to indent the switch statement.

> +		switch (data->product_id) {
> +		case 0x05:
> +		case 0x06:
> +		case 0x07:
> +		case 0x09:
> +		case 0x13:
> +			return true;
> +		default:
> +			return false;
> +		}
> +	}
> +	return false;
> +}
>  
>  static DEVICE_ATTR_WO(acquire);
>  static DEVICE_ATTR_RO(min);
> -- 
> 2.7.4
> 

Thanks.
廖崇榮 July 11, 2016, 12:40 p.m. UTC | #2
Hi Dmitry,

-----Original Message-----
From: Dmitry Torokhov [mailto:dmitry.torokhov@gmail.com] 
Sent: Saturday, July 09, 2016 8:25 AM
To: KT Liao
Cc: linux-kernel@vger.kernel.org; linux-input@vger.kernel.org; phoenix@emc.com.tw; kt.liao@emc.com.tw
Subject: Re: [PATCH] Input: /input/mouse/elan_i2c_core.c Fix some Asus touchapod which casue TP no funciton sometimes, the patch detect some specific touchpad and run a special initialize

Hi KT,

On Fri, Jul 08, 2016 at 08:12:09PM +0800, KT Liao wrote:
> Signed-off-by: KT Liao <kt.liao@emc.com.tw>

Please make sure you add a blan line between change subject and the rest of description. Then git send-email will compose your email properly instead of lumping everything into one long line subject.
[KT] :Sorry, I will fix it in the later upstream
> ---
>  drivers/input/mouse/elan_i2c_core.c | 81 
> +++++++++++++++++++++++++++++--------
>  1 file changed, 65 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/input/mouse/elan_i2c_core.c 
> b/drivers/input/mouse/elan_i2c_core.c
> index 2f58985..1c200fb 100644
> --- a/drivers/input/mouse/elan_i2c_core.c
> +++ b/drivers/input/mouse/elan_i2c_core.c
> @@ -3,8 +3,8 @@
>   *
>   * Copyright (c) 2013 ELAN Microelectronics Corp.
>   *
> - * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
> - * Version: 1.6.0
> + * Author: KT Liao <kt.liao@emc.com.tw>
> + * Version: 1.6.2
>   *
>   * 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.6.1"
> +#define ELAN_DRIVER_VERSION	"1.6.2"
>  #define ELAN_VENDOR_ID		0x04f3
>  #define ETP_MAX_PRESSURE	255
>  #define ETP_FWIDTH_REDUCE	90
> @@ -95,6 +95,8 @@ struct elan_tp_data {
>  	bool			baseline_ready;
>  };
>  
> +static int check_ASUS_special_fw(struct elan_tp_data *data);
> +
>  static int elan_get_fwinfo(u8 iap_version, u16 *validpage_count,
>  			   u16 *signature_address)
>  {
> @@ -210,21 +212,40 @@ static int __elan_initialize(struct elan_tp_data *data)
>  		return error;
>  	}
>  
> -	data->mode |= ETP_ENABLE_ABS;
> -	error = data->ops->set_mode(client, data->mode);
> -	if (error) {
> -		dev_err(&client->dev,
> -			"failed to switch to absolute mode: %d\n", error);
> -		return error;
> -	}
> +	/* If it's the special FW, it need a different flow for mode change.*/
> +	if (check_ASUS_special_fw(data)) {
> +		error = data->ops->sleep_control(client, false);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to wake device up: %d\n", error);
> +			return error;
> +		}
>  
> -	error = data->ops->sleep_control(client, false);
> -	if (error) {
> -		dev_err(&client->dev,
> -			"failed to wake device up: %d\n", error);
> -		return error;
> -	}
> +		msleep(200);
>  
> +		data->mode |= ETP_ENABLE_ABS;
> +		error = data->ops->set_mode(client, data->mode);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to switch to absolute mode: %d\n", error);
> +			return error;
> +		}
> +	} else {
> +		data->mode |= ETP_ENABLE_ABS;
> +		error = data->ops->set_mode(client, data->mode);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to switch to absolute mode: %d\n", error);
> +			return error;
> +		}
> +
> +		error = data->ops->sleep_control(client, false);
> +		if (error) {
> +			dev_err(&client->dev,
> +				"failed to wake device up: %d\n", error);
> +			return error;
> +		}
> +	}
>  	return 0;
>  }
>  
> @@ -757,6 +778,34 @@ out:
>  	return retval;
>  }
>  
> +static int check_ASUS_special_fw(struct elan_tp_data *data) {
> +	struct i2c_client *client = data->client;
> +	int error;
> +
> +	error = data->ops->get_product_id(client, &data->product_id);
> +	if (error)
> +		return false;
> +
> +	error = data->ops->get_sm_version(client, &data->ic_type,
> +					  &data->sm_version);
> +	if (error)
> +		return false;

That means we'd be fetching product ID and IC type twice when initializing the device. Can we come with a way to do it once?
[KT]:Because the elan_query_device_info() is behind the elan_initialize(). That's why I fetching product ID and IC type in the elan_initialize()
    I will discuss with FW team and then execute elan_query_device_info() first to get product_id and ic_type. 
> +
> +	if (data->ic_type == 0x0E) {

Maybe

	if (dat->ic_type != 0x0e)
		return false;

? Then you would not need to indent the switch statement.
[KT] : OK, fix in the next patch
> +		switch (data->product_id) {
> +		case 0x05:
> +		case 0x06:
> +		case 0x07:
> +		case 0x09:
> +		case 0x13:
> +			return true;
> +		default:
> +			return false;
> +		}
> +	}
> +	return false;
> +}
>  
>  static DEVICE_ATTR_WO(acquire);
>  static DEVICE_ATTR_RO(min);
> --
> 2.7.4
> 

Thanks.
Dmitry Torokhov July 11, 2016, 5:03 p.m. UTC | #3
On Mon, Jul 11, 2016 at 08:40:58PM +0800, 廖崇榮 wrote:
> > +
> > +	error = data->ops->get_sm_version(client, &data->ic_type,
> > +					  &data->sm_version);
> > +	if (error)
> > +		return false;
> 
> That means we'd be fetching product ID and IC type twice when initializing the device. Can we come with a way to do it once?
> [KT]:Because the elan_query_device_info() is behind the elan_initialize(). That's why I fetching product ID and IC type in the elan_initialize()
>     I will discuss with FW team and then execute elan_query_device_info() first to get product_id and ic_type. 

We might need to split fetching product ID and IC type form the rest of
the device info.

Thanks.
廖崇榮 July 12, 2016, 2:19 p.m. UTC | #4
Hi Dmitry,

-----Original Message-----
From: 'Dmitry Torokhov' [mailto:dmitry.torokhov@gmail.com] 
Sent: Tuesday, July 12, 2016 1:03 AM
To: 廖崇榮
Cc: 'KT Liao'; linux-kernel@vger.kernel.org; linux-input@vger.kernel.org; phoenix@emc.com.tw
Subject: Re: [PATCH] Input: /input/mouse/elan_i2c_core.c Fix some Asus touchapod which casue TP no funciton sometimes, the patch detect some specific touchpad and run a special initialize

On Mon, Jul 11, 2016 at 08:40:58PM +0800, 廖崇榮 wrote:
> > +
> > +	error = data->ops->get_sm_version(client, &data->ic_type,
> > +					  &data->sm_version);
> > +	if (error)
> > +		return false;
> 
> That means we'd be fetching product ID and IC type twice when initializing the device. Can we come with a way to do it once?
> [KT]:Because the elan_query_device_info() is behind the elan_initialize(). That's why I fetching product ID and IC type in the elan_initialize()
>     I will discuss with FW team and then execute elan_query_device_info() first to get product_id and ic_type. 

We might need to split fetching product ID and IC type form the rest of the device info.
[KT] : ok, I will extract "product ID" and "IC type" to another query-device function. and it won't change original flow too much.

Thanks.

--
Dmitry

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

Patch
diff mbox

diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index 2f58985..1c200fb 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -3,8 +3,8 @@ 
  *
  * Copyright (c) 2013 ELAN Microelectronics Corp.
  *
- * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
- * Version: 1.6.0
+ * Author: KT Liao <kt.liao@emc.com.tw>
+ * Version: 1.6.2
  *
  * 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.6.1"
+#define ELAN_DRIVER_VERSION	"1.6.2"
 #define ELAN_VENDOR_ID		0x04f3
 #define ETP_MAX_PRESSURE	255
 #define ETP_FWIDTH_REDUCE	90
@@ -95,6 +95,8 @@  struct elan_tp_data {
 	bool			baseline_ready;
 };
 
+static int check_ASUS_special_fw(struct elan_tp_data *data);
+
 static int elan_get_fwinfo(u8 iap_version, u16 *validpage_count,
 			   u16 *signature_address)
 {
@@ -210,21 +212,40 @@  static int __elan_initialize(struct elan_tp_data *data)
 		return error;
 	}
 
-	data->mode |= ETP_ENABLE_ABS;
-	error = data->ops->set_mode(client, data->mode);
-	if (error) {
-		dev_err(&client->dev,
-			"failed to switch to absolute mode: %d\n", error);
-		return error;
-	}
+	/* If it's the special FW, it need a different flow for mode change.*/
+	if (check_ASUS_special_fw(data)) {
+		error = data->ops->sleep_control(client, false);
+		if (error) {
+			dev_err(&client->dev,
+				"failed to wake device up: %d\n", error);
+			return error;
+		}
 
-	error = data->ops->sleep_control(client, false);
-	if (error) {
-		dev_err(&client->dev,
-			"failed to wake device up: %d\n", error);
-		return error;
-	}
+		msleep(200);
 
+		data->mode |= ETP_ENABLE_ABS;
+		error = data->ops->set_mode(client, data->mode);
+		if (error) {
+			dev_err(&client->dev,
+				"failed to switch to absolute mode: %d\n", error);
+			return error;
+		}
+	} else {
+		data->mode |= ETP_ENABLE_ABS;
+		error = data->ops->set_mode(client, data->mode);
+		if (error) {
+			dev_err(&client->dev,
+				"failed to switch to absolute mode: %d\n", error);
+			return error;
+		}
+
+		error = data->ops->sleep_control(client, false);
+		if (error) {
+			dev_err(&client->dev,
+				"failed to wake device up: %d\n", error);
+			return error;
+		}
+	}
 	return 0;
 }
 
@@ -757,6 +778,34 @@  out:
 	return retval;
 }
 
+static int check_ASUS_special_fw(struct elan_tp_data *data)
+{
+	struct i2c_client *client = data->client;
+	int error;
+
+	error = data->ops->get_product_id(client, &data->product_id);
+	if (error)
+		return false;
+
+	error = data->ops->get_sm_version(client, &data->ic_type,
+					  &data->sm_version);
+	if (error)
+		return false;
+
+	if (data->ic_type == 0x0E) {
+		switch (data->product_id) {
+		case 0x05:
+		case 0x06:
+		case 0x07:
+		case 0x09:
+		case 0x13:
+			return true;
+		default:
+			return false;
+		}
+	}
+	return false;
+}
 
 static DEVICE_ATTR_WO(acquire);
 static DEVICE_ATTR_RO(min);