Skip to contentSkip to conversation

Input: elan_i2c - Make hardware buttons work properly on Asus ROG G752xx

PATCH In review Maxime Bellengé 3 participants 3 messages Aug 16, 2017 – Aug 17, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: elan_i2c - Make hardware buttons work properly on Asus ROG G752xx

Asus ROG G752xx laptops have hardware buttons. Currently only the left button works if a finger touches the pad which is not very convenient.

I couldn't find a clear pattern based on ic type and product id to determine if the device has hardware buttons or if it is a clickpad as it is vendor dependant. So I chose to base the patch on dmi as I couldn't find any other laptop based on elan i2c and having hardware buttons.

---
 drivers/input/mouse/elan_i2c_core.c | 40 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/input/mouse/elan_i2c_core.c +39 -1
index 3b616cb7c67f..fa417105898f 100644
@@ -37,6 +37,7 @@
 #include <linux/of.h>
 #include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
+#include <linux/dmi.h>
 
 #include "elan_i2c.h"
 
@@ -923,6 +924,7 @@ static void elan_report_absolute(struct elan_tp_data *data, u8 *packet)
 	}
 
 	input_report_key(input, BTN_LEFT, tp_info & 0x01);
+        input_report_key(input, BTN_RIGHT, tp_info & 0x02);
 	input_report_abs(input, ABS_DISTANCE, hover_event != 0);
 	input_mt_report_pointer_emulation(input, true);
 	input_sync(input);
@@ -960,6 +962,39 @@ static irqreturn_t elan_isr(int irq, void *dev_id)
 }
 
 /*
+ * Asus ROG G752xx have hardware buttons
+ */
+ static const struct dmi_system_id elan_dmi_has_hw_buttons[] = {
+ #if defined(CONFIG_DMI) && defined(CONFIG_X86)
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VT"),
+ 		},
+ 	},
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VS"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VY"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VL"),
+ 		},
+ 	},
+ #endif
+ 	{ }
+ };
+
+/*
  ******************************************************************
  * Elan initialization functions
  ******************************************************************
@@ -991,7 +1026,10 @@ static int elan_setup_input_device(struct elan_tp_data *data)
 
 	__set_bit(EV_ABS, input->evbit);
 	__set_bit(INPUT_PROP_POINTER, input->propbit);
-	__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+        if (dmi_check_system(elan_dmi_has_hw_buttons)) {
+                __set_bit(BTN_RIGHT, input->keybit);
+        } else
+	       __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 	__set_bit(BTN_LEFT, input->keybit);
 
 	/* Set up ST parameters */
Signature · 1 line
2.13.5
maintainer
#1 lore raw
Quoted 9 lines · Maxime Bellengé

Asus ROG G752xx laptops have hardware buttons. Currently only the left button works if a finger touches the pad which is not very convenient.

I couldn't find a clear pattern based on ic type and product id to determine if the device has hardware buttons or if it is a clickpad as it is vendor dependant. So I chose to base the patch on dmi as I couldn't find any other laptop based on elan i2c and having hardware buttons.

KT, any feedback here?

Quoted 80 lines
---
 drivers/input/mouse/elan_i2c_core.c | 40 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/input/mouse/elan_i2c_core.c +39 -1
index 3b616cb7c67f..fa417105898f 100644
@@ -37,6 +37,7 @@
 #include <linux/of.h>
 #include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
+#include <linux/dmi.h>
 
 #include "elan_i2c.h"
 
@@ -923,6 +924,7 @@ static void elan_report_absolute(struct elan_tp_data *data, u8 *packet)
 	}
 
 	input_report_key(input, BTN_LEFT, tp_info & 0x01);
+        input_report_key(input, BTN_RIGHT, tp_info & 0x02);
 	input_report_abs(input, ABS_DISTANCE, hover_event != 0);
 	input_mt_report_pointer_emulation(input, true);
 	input_sync(input);
@@ -960,6 +962,39 @@ static irqreturn_t elan_isr(int irq, void *dev_id)
 }
 
 /*
+ * Asus ROG G752xx have hardware buttons
+ */
+ static const struct dmi_system_id elan_dmi_has_hw_buttons[] = {
+ #if defined(CONFIG_DMI) && defined(CONFIG_X86)
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VT"),
+ 		},
+ 	},
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VS"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VY"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VL"),
+ 		},
+ 	},
+ #endif
+ 	{ }
+ };
+
+/*
  ******************************************************************
  * Elan initialization functions
  ******************************************************************
@@ -991,7 +1026,10 @@ static int elan_setup_input_device(struct elan_tp_data *data)
 
 	__set_bit(EV_ABS, input->evbit);
 	__set_bit(INPUT_PROP_POINTER, input->propbit);
-	__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+        if (dmi_check_system(elan_dmi_has_hw_buttons)) {
+                __set_bit(BTN_RIGHT, input->keybit);
+        } else
+	       __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 	__set_bit(BTN_LEFT, input->keybit);
 
 	/* Set up ST parameters */
Signature · 1 line
2.13.5
Signature · 1 line
Dmitry
#2 lore raw

-----Original Message-----
From: Dmitry Torokhov [mailto:[email protected]]
Sent: Thursday, August 17, 2017 2:27 AM
To: Maxime Bellengé; KT Liao
Cc: [email protected]; [email protected]
Subject: Re: [PATCH] Input: elan_i2c - Make hardware buttons work properly on Asus ROG G752xx

Quoted 9 lines · Maxime Bellengé

Asus ROG G752xx laptops have hardware buttons. Currently only the left button works if a finger touches the pad which is not very convenient.

I couldn't find a clear pattern based on ic type and product id to determine if the device has hardware buttons or if it is a clickpad as it is vendor dependant. So I chose to base the patch on dmi as I couldn't find any other laptop based on elan i2c and having hardware buttons.

KT, any feedback here?
Basically, I think it's ok to use DMI_MATCH because
(1) It's rare to see such kind of platform.
(2) Only one file need to be modified

We have a command to get button type.
I quickly make a patch as attached file but I don't have the platform to test it now.
It would be great if Maxime can help to try it. Or I will test it and upstream next week.

thanks

drivers/input/mouse/elan_i2c_core.c static void elan_report_absolute(struct elan_tp_data

Quoted 19 lines
---
 drivers/input/mouse/elan_i2c_core.c | 40 
++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
drivers/input/mouse/elan_i2c_core.c +1 -0
index 3b616cb7c67f..fa417105898f 100644
@@ -37,6 +37,7 @@
 #include <linux/of.h>
 #include <linux/regulator/consumer.h>  #include <asm/unaligned.h>
+#include <linux/dmi.h>
 
 #include "elan_i2c.h"
 
@@ -923,6 +924,7 @@ static void elan_report_absolute(struct elan_tp_data

*data, u8 *packet)

Quoted 62 lines
drivers/input/mouse/elan_i2c_core.c +37 -1
 	}
 
 	input_report_key(input, BTN_LEFT, tp_info & 0x01);
+        input_report_key(input, BTN_RIGHT, tp_info & 0x02);
 	input_report_abs(input, ABS_DISTANCE, hover_event != 0);
 	input_mt_report_pointer_emulation(input, true);
 	input_sync(input);
@@ -960,6 +962,39 @@ static irqreturn_t elan_isr(int irq, void 
 *dev_id)  }
 
 /*
+ * Asus ROG G752xx have hardware buttons */ static const struct 
+ dmi_system_id elan_dmi_has_hw_buttons[] = { #if defined(CONFIG_DMI) 
+ && defined(CONFIG_X86)
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VT"),
+ 		},
+ 	},
+ 	{
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VS"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VY"),
+ 		},
+ 	},
+        {
+ 		.matches = {
+ 			DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
+ 			DMI_MATCH(DMI_PRODUCT_NAME, "G752VL"),
+ 		},
+ 	},
+ #endif
+ 	{ }
+ };
+
+/*
  ******************************************************************
  * Elan initialization functions
  ******************************************************************
@@ -991,7 +1026,10 @@ static int elan_setup_input_device(struct 
 elan_tp_data *data)
 
 	__set_bit(EV_ABS, input->evbit);
 	__set_bit(INPUT_PROP_POINTER, input->propbit);
-	__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+        if (dmi_check_system(elan_dmi_has_hw_buttons)) {
+                __set_bit(BTN_RIGHT, input->keybit);
+        } else
+	       __set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
 	__set_bit(BTN_LEFT, input->keybit);
 

/* Set up ST parameters */
--
2.13.5

Signature · 1 line
Dmitry
Quoted 1 line

From 5182667893b96dbc8bb91808d9582b4d4c45b6ce Mon Sep 17 00:00:00 2001

From: KT Liao <[email protected]>
Date: Thu, 17 Aug 2017 21:55:45 +0800
Subject: [PATCH] Input: elan_i2c - Add support for two physical button

Extend infomation accessing to judge and support L/R button-pad

---
 drivers/input/mouse/elan_i2c.h       |  2 +-
 drivers/input/mouse/elan_i2c_core.c  |  9 +++++++--
 drivers/input/mouse/elan_i2c_i2c.c   | 13 ++++++++++++-
 drivers/input/mouse/elan_i2c_smbus.c |  4 +++-
 4 files changed, 23 insertions(+), 5 deletions(-)
drivers/input/mouse/elan_i2c.h +1 -1
index 61c2024..599544c 100644
@@ -58,7 +58,7 @@ struct elan_transport_ops {
 
 	int (*get_version)(struct i2c_client *client, bool iap, u8 *version);
 	int (*get_sm_version)(struct i2c_client *client,
-			      u16 *ic_type, u8 *version);
+			      u16 *ic_type, u8 *version, u8 *clickpad);
 	int (*get_checksum)(struct i2c_client *client, bool iap, u16 *csum);
 	int (*get_product_id)(struct i2c_client *client, u16 *id);
 
drivers/input/mouse/elan_i2c_core.c +7 -2
index 0d111322..59baced 100644
@@ -95,6 +95,7 @@ struct elan_tp_data {
 	u8			min_baseline;
 	u8			max_baseline;
 	bool			baseline_ready;
+	u8			clickpad;
 };
 
 static int elan_get_fwinfo(u16 ic_type, u16 *validpage_count,
@@ -213,7 +214,7 @@ static int elan_query_product(struct elan_tp_data *data)
 		return error;
 
 	error = data->ops->get_sm_version(data->client, &data->ic_type,
-					  &data->sm_version);
+					  &data->sm_version, &data->clickpad);
 	if (error)
 		return error;
 
@@ -923,6 +924,7 @@ static void elan_report_absolute(struct elan_tp_data *data, u8 *packet)
 	}
 
 	input_report_key(input, BTN_LEFT, tp_info & 0x01);
+	input_report_key(input, BTN_RIGHT, tp_info & 0x02);
 	input_report_abs(input, ABS_DISTANCE, hover_event != 0);
 	input_mt_report_pointer_emulation(input, true);
 	input_sync(input);
@@ -991,7 +993,10 @@ static int elan_setup_input_device(struct elan_tp_data *data)
 
 	__set_bit(EV_ABS, input->evbit);
 	__set_bit(INPUT_PROP_POINTER, input->propbit);
-	__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+	if (data->clickpad)
+		__set_bit(INPUT_PROP_BUTTONPAD, input->propbit);
+	else
+		__set_bit(BTN_RIGHT, input->keybit);
 	__set_bit(BTN_LEFT, input->keybit);
 
 	/* Set up ST parameters */
drivers/input/mouse/elan_i2c_i2c.c +12 -1
index 80172f2..15b1330 100644
@@ -288,7 +288,8 @@ static int elan_i2c_get_version(struct i2c_client *client,
 }
 
 static int elan_i2c_get_sm_version(struct i2c_client *client,
-				   u16 *ic_type, u8 *version)
+				   u16 *ic_type, u8 *version,
+				   u8 *clickpad)
 {
 	int error;
 	u8 pattern_ver;
@@ -317,6 +318,7 @@ static int elan_i2c_get_sm_version(struct i2c_client *client,
 			return error;
 		}
 		*version = val[1];
+		*clickpad = val[0] & 0x10;
 	} else {
 		error = elan_i2c_read_cmd(client, ETP_I2C_OSM_VERSION_CMD, val);
 		if (error) {
@@ -326,6 +328,15 @@ static int elan_i2c_get_sm_version(struct i2c_client *client,
 		}
 		*version = val[0];
 		*ic_type = val[1];
+
+		error = elan_i2c_read_cmd(client, ETP_I2C_NSM_VERSION_CMD,
+					  val);
+		if (error) {
+			dev_err(&client->dev, "failed to get SM version: %d\n",
+				error);
+			return error;
+		}
+		*clickpad = val[0] & 0x10;
 	}
 
 	return 0;
drivers/input/mouse/elan_i2c_smbus.c +3 -1
index df7a57c..29f9952 100644
@@ -166,7 +166,8 @@ static int elan_smbus_get_version(struct i2c_client *client,
 }
 
 static int elan_smbus_get_sm_version(struct i2c_client *client,
-				     u16 *ic_type, u8 *version)
+				     u16 *ic_type, u8 *version,
+				     u8 *clickpad)
 {
 	int error;
 	u8 val[3];
@@ -180,6 +181,7 @@ static int elan_smbus_get_sm_version(struct i2c_client *client,
 
 	*version = val[0];
 	*ic_type = val[1];
+	*clickpad = val[0] & 0x10;
 	return 0;
 }
 
Signature · 1 line
2.7.4