diff mbox series

[6/6] input: elants: read touchscreen size for EKTF3624

Message ID 06f20ed8e50fe634c59cf3c585d37f1175133533.1575936961.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Superseded
Headers show
Series input: elants: Support Asus TF300T touchscreen | expand

Commit Message

Michał Mirosław Dec. 10, 2019, 12:19 a.m. UTC
EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded
in different registers.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/input/touchscreen/elants_i2c.c | 77 ++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 5 deletions(-)

Comments

Dmitry Osipenko Dec. 10, 2019, 1:23 a.m. UTC | #1
10.12.2019 03:19, Michał Mirosław пишет:
> EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded
> in different registers.
> 
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---
>  drivers/input/touchscreen/elants_i2c.c | 77 ++++++++++++++++++++++++--
>  1 file changed, 72 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
> index 27aca3971da5..e60a5eb9fb37 100644
> --- a/drivers/input/touchscreen/elants_i2c.c
> +++ b/drivers/input/touchscreen/elants_i2c.c
> @@ -34,7 +34,7 @@
>  #include <linux/input/touchscreen.h>
>  #include <linux/input/mt.h>
>  #include <linux/acpi.h>
> -#include <linux/of.h>
> +#include <linux/of_device.h>
>  #include <linux/gpio/consumer.h>
>  #include <linux/regulator/consumer.h>
>  #include <asm/unaligned.h>
> @@ -42,6 +42,10 @@
>  /* Device, Driver information */
>  #define DEVICE_NAME	"elants_i2c"
>  
> +/* Device IDs */
> +#define EKTH3500	0
> +#define EKTF3624	1
> +
>  /* Convert from rows or columns into resolution */
>  #define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
>  
> @@ -160,6 +164,7 @@ struct elants_data {
>  
>  	bool wake_irq_enabled;
>  	bool keep_power_in_suspend;
> +	u8 chip_id;
>  
>  	/* Must be last to be used for DMA operations */
>  	u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
> @@ -434,7 +439,53 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
>  	return 0;
>  }
>  
> -static int elants_i2c_query_ts_info(struct elants_data *ts)
> +static int elants_i2c_query_ts_info_ektf(struct elants_data *ts)
> +{
> +	struct i2c_client *client = ts->client;
> +	int error;
> +	u8 resp[4];
> +	u16 phy_x, phy_y;
> +	const u8 get_xres_cmd[] = {
> +		CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00
> +	};
> +	const u8 get_yres_cmd[] = {
> +		CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00
> +	};
> +
> +	/* Get X/Y size in mm */
> +	error = elants_i2c_execute_command(client, get_xres_cmd,
> +					   sizeof(get_xres_cmd),
> +					   resp, sizeof(resp), 1,
> +					   "get X size");
> +	if (error)
> +		return error;
> +
> +	phy_x = resp[2] | ((resp[3] & 0xF0) << 4);
> +
> +	error = elants_i2c_execute_command(client, get_yres_cmd,
> +					   sizeof(get_yres_cmd),
> +					   resp, sizeof(resp), 1,
> +					   "get Y size");
> +	if (error)
> +		return error;
> +
> +	phy_y = resp[2] | ((resp[3] & 0xF0) << 4);
> +
> +	/* calculate resolution from size */
> +	if (!ts->prop.max_x)
> +		ts->prop.max_x = 2240;
> +	ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
> +
> +	if (!ts->prop.max_y)
> +		ts->prop.max_y = 1408;
> +	ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
> +
> +	dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
> +
> +	return 0;
> +}
> +
> +static int elants_i2c_query_ts_info_ekth(struct elants_data *ts)
>  {
>  	struct i2c_client *client = ts->client;
>  	int error;
> @@ -587,8 +638,20 @@ static int elants_i2c_initialize(struct elants_data *ts)
>  		error = elants_i2c_query_test_version(ts);
>  	if (!error)
>  		error = elants_i2c_query_bc_version(ts);
> -	if (!error)
> -		error = elants_i2c_query_ts_info(ts);
> +
> +	switch (ts->chip_id) {
> +	case EKTH3500:
> +		if (!error)
> +			error = elants_i2c_query_ts_info_ekth(ts);
> +		break;
> +	case EKTF3624:
> +		if (!error)
> +			error = elants_i2c_query_ts_info_ektf(ts);
> +		break;
> +	default:
> +		unreachable();
> +		break;
> +	}
>  
>  	if (error)
>  		ts->iap_mode = ELAN_IAP_RECOVERY;
> @@ -1185,6 +1248,9 @@ static int elants_i2c_probe(struct i2c_client *client,
>  	ts->client = client;
>  	i2c_set_clientdata(client, ts);
>  
> +	if (client->dev.of_node)
> +		ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
> +
>  	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
>  	if (IS_ERR(ts->vcc33)) {
>  		error = PTR_ERR(ts->vcc33);
> @@ -1422,7 +1488,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
>  
>  #ifdef CONFIG_OF
>  static const struct of_device_id elants_of_match[] = {
> -	{ .compatible = "elan,ekth3500" },
> +	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
> +	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, elants_of_match);

It also should be possible to remove elants_of_match entirely and do the
following in the I2C ID table:

static const struct i2c_device_id elants_i2c_id[] = {
	{ "ekth3500", EKTH3500 },
	{ "ektf3624", EKTF3624 },
	{ }
};
MODULE_DEVICE_TABLE(i2c, elants_i2c_id);

Then OF core will take care of device ID matching by removing the
"elan," part from the compatible value of the device-tree and comparing
it with the values in elants_i2c_id[].

And then in elants_i2c_probe() you could :

	chip->chip_id = (uintptr_t)id->driver_data;

See "drivers/mfd/max77620.c" for the example.
Dmitry Osipenko Dec. 10, 2019, 1:48 a.m. UTC | #2
10.12.2019 04:23, Dmitry Osipenko пишет:
> 10.12.2019 03:19, Michał Mirosław пишет:
>> EKTF3624 as present in Asus TF300T tablet has touchscreen size encoded
>> in different registers.
>>
>> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
>> ---
>>  drivers/input/touchscreen/elants_i2c.c | 77 ++++++++++++++++++++++++--
>>  1 file changed, 72 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
>> index 27aca3971da5..e60a5eb9fb37 100644
>> --- a/drivers/input/touchscreen/elants_i2c.c
>> +++ b/drivers/input/touchscreen/elants_i2c.c
>> @@ -34,7 +34,7 @@
>>  #include <linux/input/touchscreen.h>
>>  #include <linux/input/mt.h>
>>  #include <linux/acpi.h>
>> -#include <linux/of.h>
>> +#include <linux/of_device.h>
>>  #include <linux/gpio/consumer.h>
>>  #include <linux/regulator/consumer.h>
>>  #include <asm/unaligned.h>
>> @@ -42,6 +42,10 @@
>>  /* Device, Driver information */
>>  #define DEVICE_NAME	"elants_i2c"
>>  
>> +/* Device IDs */
>> +#define EKTH3500	0
>> +#define EKTF3624	1
>> +
>>  /* Convert from rows or columns into resolution */
>>  #define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
>>  
>> @@ -160,6 +164,7 @@ struct elants_data {
>>  
>>  	bool wake_irq_enabled;
>>  	bool keep_power_in_suspend;
>> +	u8 chip_id;
>>  
>>  	/* Must be last to be used for DMA operations */
>>  	u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
>> @@ -434,7 +439,53 @@ static int elants_i2c_query_bc_version(struct elants_data *ts)
>>  	return 0;
>>  }
>>  
>> -static int elants_i2c_query_ts_info(struct elants_data *ts)
>> +static int elants_i2c_query_ts_info_ektf(struct elants_data *ts)
>> +{
>> +	struct i2c_client *client = ts->client;
>> +	int error;
>> +	u8 resp[4];
>> +	u16 phy_x, phy_y;
>> +	const u8 get_xres_cmd[] = {
>> +		CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00
>> +	};
>> +	const u8 get_yres_cmd[] = {
>> +		CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00
>> +	};
>> +
>> +	/* Get X/Y size in mm */
>> +	error = elants_i2c_execute_command(client, get_xres_cmd,
>> +					   sizeof(get_xres_cmd),
>> +					   resp, sizeof(resp), 1,
>> +					   "get X size");
>> +	if (error)
>> +		return error;
>> +
>> +	phy_x = resp[2] | ((resp[3] & 0xF0) << 4);
>> +
>> +	error = elants_i2c_execute_command(client, get_yres_cmd,
>> +					   sizeof(get_yres_cmd),
>> +					   resp, sizeof(resp), 1,
>> +					   "get Y size");
>> +	if (error)
>> +		return error;
>> +
>> +	phy_y = resp[2] | ((resp[3] & 0xF0) << 4);
>> +
>> +	/* calculate resolution from size */
>> +	if (!ts->prop.max_x)
>> +		ts->prop.max_x = 2240;
>> +	ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
>> +
>> +	if (!ts->prop.max_y)
>> +		ts->prop.max_y = 1408;
>> +	ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
>> +
>> +	dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
>> +
>> +	return 0;
>> +}
>> +
>> +static int elants_i2c_query_ts_info_ekth(struct elants_data *ts)
>>  {
>>  	struct i2c_client *client = ts->client;
>>  	int error;
>> @@ -587,8 +638,20 @@ static int elants_i2c_initialize(struct elants_data *ts)
>>  		error = elants_i2c_query_test_version(ts);
>>  	if (!error)
>>  		error = elants_i2c_query_bc_version(ts);
>> -	if (!error)
>> -		error = elants_i2c_query_ts_info(ts);
>> +
>> +	switch (ts->chip_id) {
>> +	case EKTH3500:
>> +		if (!error)
>> +			error = elants_i2c_query_ts_info_ekth(ts);
>> +		break;
>> +	case EKTF3624:
>> +		if (!error)
>> +			error = elants_i2c_query_ts_info_ektf(ts);
>> +		break;
>> +	default:
>> +		unreachable();
>> +		break;
>> +	}
>>  
>>  	if (error)
>>  		ts->iap_mode = ELAN_IAP_RECOVERY;
>> @@ -1185,6 +1248,9 @@ static int elants_i2c_probe(struct i2c_client *client,
>>  	ts->client = client;
>>  	i2c_set_clientdata(client, ts);
>>  
>> +	if (client->dev.of_node)
>> +		ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
>> +
>>  	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
>>  	if (IS_ERR(ts->vcc33)) {
>>  		error = PTR_ERR(ts->vcc33);
>> @@ -1422,7 +1488,8 @@ MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
>>  
>>  #ifdef CONFIG_OF
>>  static const struct of_device_id elants_of_match[] = {
>> -	{ .compatible = "elan,ekth3500" },
>> +	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
>> +	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
>>  	{ /* sentinel */ }
>>  };
>>  MODULE_DEVICE_TABLE(of, elants_of_match);
> 
> It also should be possible to remove elants_of_match entirely and do the
> following in the I2C ID table:
> 
> static const struct i2c_device_id elants_i2c_id[] = {
> 	{ "ekth3500", EKTH3500 },
> 	{ "ektf3624", EKTF3624 },
> 	{ }
> };
> MODULE_DEVICE_TABLE(i2c, elants_i2c_id);
> 
> Then OF core will take care of device ID matching by removing the
> "elan," part from the compatible value of the device-tree and comparing
> it with the values in elants_i2c_id[].
> 
> And then in elants_i2c_probe() you could :
> 
> 	chip->chip_id = (uintptr_t)id->driver_data;
> 
> See "drivers/mfd/max77620.c" for the example.
> 

But maybe it's not really worth the effort at all since we need to
override the sizes in device-tree anyway?

What about to just ignore the firmware values of eKTF3624 for simplicity?
kernel test robot Dec. 10, 2019, 6:32 p.m. UTC | #3
Hi "Michał,

I love your patch! Perhaps something to improve:

[auto build test WARNING on input/next]
[also build test WARNING on v5.5-rc1 next-20191209]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Micha-Miros-aw/input-elants-document-some-registers-and-values/20191210-140810
base:   https://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
config: x86_64-fedora-25 (attached as .config)
compiler: gcc-7 (Debian 7.5.0-1) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/input/touchscreen/elants_i2c.o: warning: objtool: elants_i2c_initialize() falls through to next function elants_i2c_resume()

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org Intel Corporation
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/elants_i2c.c b/drivers/input/touchscreen/elants_i2c.c
index 27aca3971da5..e60a5eb9fb37 100644
--- a/drivers/input/touchscreen/elants_i2c.c
+++ b/drivers/input/touchscreen/elants_i2c.c
@@ -34,7 +34,7 @@ 
 #include <linux/input/touchscreen.h>
 #include <linux/input/mt.h>
 #include <linux/acpi.h>
-#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/gpio/consumer.h>
 #include <linux/regulator/consumer.h>
 #include <asm/unaligned.h>
@@ -42,6 +42,10 @@ 
 /* Device, Driver information */
 #define DEVICE_NAME	"elants_i2c"
 
+/* Device IDs */
+#define EKTH3500	0
+#define EKTF3624	1
+
 /* Convert from rows or columns into resolution */
 #define ELAN_TS_RESOLUTION(n, m)   (((n) - 1) * (m))
 
@@ -160,6 +164,7 @@  struct elants_data {
 
 	bool wake_irq_enabled;
 	bool keep_power_in_suspend;
+	u8 chip_id;
 
 	/* Must be last to be used for DMA operations */
 	u8 buf[MAX_PACKET_SIZE] ____cacheline_aligned;
@@ -434,7 +439,53 @@  static int elants_i2c_query_bc_version(struct elants_data *ts)
 	return 0;
 }
 
-static int elants_i2c_query_ts_info(struct elants_data *ts)
+static int elants_i2c_query_ts_info_ektf(struct elants_data *ts)
+{
+	struct i2c_client *client = ts->client;
+	int error;
+	u8 resp[4];
+	u16 phy_x, phy_y;
+	const u8 get_xres_cmd[] = {
+		CMD_HEADER_READ, E_INFO_X_RES, 0x00, 0x00
+	};
+	const u8 get_yres_cmd[] = {
+		CMD_HEADER_READ, E_INFO_Y_RES, 0x00, 0x00
+	};
+
+	/* Get X/Y size in mm */
+	error = elants_i2c_execute_command(client, get_xres_cmd,
+					   sizeof(get_xres_cmd),
+					   resp, sizeof(resp), 1,
+					   "get X size");
+	if (error)
+		return error;
+
+	phy_x = resp[2] | ((resp[3] & 0xF0) << 4);
+
+	error = elants_i2c_execute_command(client, get_yres_cmd,
+					   sizeof(get_yres_cmd),
+					   resp, sizeof(resp), 1,
+					   "get Y size");
+	if (error)
+		return error;
+
+	phy_y = resp[2] | ((resp[3] & 0xF0) << 4);
+
+	/* calculate resolution from size */
+	if (!ts->prop.max_x)
+		ts->prop.max_x = 2240;
+	ts->x_res = DIV_ROUND_CLOSEST(ts->prop.max_x, phy_x);
+
+	if (!ts->prop.max_y)
+		ts->prop.max_y = 1408;
+	ts->y_res = DIV_ROUND_CLOSEST(ts->prop.max_y, phy_y);
+
+	dev_dbg(&client->dev, "phy_x=%d, phy_y=%d\n", phy_x, phy_y);
+
+	return 0;
+}
+
+static int elants_i2c_query_ts_info_ekth(struct elants_data *ts)
 {
 	struct i2c_client *client = ts->client;
 	int error;
@@ -587,8 +638,20 @@  static int elants_i2c_initialize(struct elants_data *ts)
 		error = elants_i2c_query_test_version(ts);
 	if (!error)
 		error = elants_i2c_query_bc_version(ts);
-	if (!error)
-		error = elants_i2c_query_ts_info(ts);
+
+	switch (ts->chip_id) {
+	case EKTH3500:
+		if (!error)
+			error = elants_i2c_query_ts_info_ekth(ts);
+		break;
+	case EKTF3624:
+		if (!error)
+			error = elants_i2c_query_ts_info_ektf(ts);
+		break;
+	default:
+		unreachable();
+		break;
+	}
 
 	if (error)
 		ts->iap_mode = ELAN_IAP_RECOVERY;
@@ -1185,6 +1248,9 @@  static int elants_i2c_probe(struct i2c_client *client,
 	ts->client = client;
 	i2c_set_clientdata(client, ts);
 
+	if (client->dev.of_node)
+		ts->chip_id = (uintptr_t)of_device_get_match_data(&client->dev);
+
 	ts->vcc33 = devm_regulator_get(&client->dev, "vcc33");
 	if (IS_ERR(ts->vcc33)) {
 		error = PTR_ERR(ts->vcc33);
@@ -1422,7 +1488,8 @@  MODULE_DEVICE_TABLE(acpi, elants_acpi_id);
 
 #ifdef CONFIG_OF
 static const struct of_device_id elants_of_match[] = {
-	{ .compatible = "elan,ekth3500" },
+	{ .compatible = "elan,ekth3500", .data = (void *)EKTH3500 },
+	{ .compatible = "elan,ektf3624", .data = (void *)EKTF3624 },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, elants_of_match);