All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] implement I2C retries for mXT1368
@ 2020-09-25 13:52 Jiada Wang
  2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jiada Wang @ 2020-09-25 13:52 UTC (permalink / raw)
  To: dmitry.torokhov, robh+dt, thierry.reding, digetx, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca,
	andrew_gabbasov, jiada_wang

According to datasheet, mXT1386 chip has a WAKE line, it is used
to wake the chip up from deep sleep mode before communicating with
it via the I2C-compatible interface.
    
if the WAKE line is connected to a GPIO line, the line must be
asserted 25 ms before the host attempts to communicate with the
mXT1386.
If the WAKE line is connected to the SCL pin, the mXT1386 will send
a NACK on the first attempt to address it, the host must then retry
25 ms later.
    
This patch adds compatible string "atmel,mXT1386" for mXT1386 controller,
when I2C transfer on mXT1386 fails, retry the transfer once after a
25 ms sleep.


Jiada Wang (3):
  dt-bindings: input: atmel: add compatible for mXT1386
  Input: atmel_mxt_ts - implement I2C retries for mXT1368
  ARM: tegra: add mXT1386 compatible

---
v2:
add bool retry_i2c_transfers to struct mxt_data,
to indicate whether retry is needed when i2c transfer fails

v1: initial version
---
 .../bindings/input/atmel,maxtouch.txt         |  1 +
 .../boot/dts/tegra20-acer-a500-picasso.dts    |  2 +-
 drivers/input/touchscreen/atmel_mxt_ts.c      | 62 +++++++++++++++----
 3 files changed, 52 insertions(+), 13 deletions(-)

-- 
2.17.1


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386
  2020-09-25 13:52 [PATCH v2 0/3] implement I2C retries for mXT1368 Jiada Wang
@ 2020-09-25 13:52 ` Jiada Wang
  2020-09-25 21:01   ` Dmitry Osipenko
  2020-09-28  6:59   ` Thierry Reding
  2020-09-25 13:52 ` [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368 Jiada Wang
  2020-09-25 13:52 ` [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible Jiada Wang
  2 siblings, 2 replies; 9+ messages in thread
From: Jiada Wang @ 2020-09-25 13:52 UTC (permalink / raw)
  To: dmitry.torokhov, robh+dt, thierry.reding, digetx, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca,
	andrew_gabbasov, jiada_wang

Document the mXT1386 compatible string.

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
---
 Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
index c88919480d37..c13fc0f3f00b 100644
--- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
+++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
@@ -3,6 +3,7 @@ Atmel maXTouch touchscreen/touchpad
 Required properties:
 - compatible:
     atmel,maxtouch
+    atmel,mXT1386
 
     The following compatibles have been used in various products but are
     deprecated:
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368
  2020-09-25 13:52 [PATCH v2 0/3] implement I2C retries for mXT1368 Jiada Wang
  2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
@ 2020-09-25 13:52 ` Jiada Wang
  2020-09-25 21:01   ` Dmitry Osipenko
  2020-09-25 13:52 ` [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible Jiada Wang
  2 siblings, 1 reply; 9+ messages in thread
From: Jiada Wang @ 2020-09-25 13:52 UTC (permalink / raw)
  To: dmitry.torokhov, robh+dt, thierry.reding, digetx, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca,
	andrew_gabbasov, jiada_wang

According to datasheet, mXT1386 chip has a WAKE line, it is used
to wake the chip up from deep sleep mode before communicating with
it via the I2C-compatible interface.

if the WAKE line is connected to a GPIO line, the line must be
asserted 25 ms before the host attempts to communicate with the mXT1386.
If the WAKE line is connected to the SCL pin, the mXT1386 will send a
NACK on the first attempt to address it, the host must then retry 25 ms
later.

This patch adds compatible string "atmel,mXT1386" for mXT1386 controller,
when I2C transfer on mXT1386 fails, retry the transfer once after a 25 ms
sleep.

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 62 +++++++++++++++++++-----
 1 file changed, 50 insertions(+), 12 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index 98f17fa3a892..c00743caed27 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -198,6 +198,7 @@ enum t100_type {
 #define MXT_CRC_TIMEOUT		1000	/* msec */
 #define MXT_FW_RESET_TIME	3000	/* msec */
 #define MXT_FW_CHG_TIMEOUT	300	/* msec */
+#define MXT_WAKEUP_TIME		25	/* msec */
 
 /* Command to unlock bootloader */
 #define MXT_UNLOCK_CMD_MSB	0xaa
@@ -340,6 +341,9 @@ struct mxt_data {
 	unsigned int t19_num_keys;
 
 	enum mxt_suspend_mode suspend_mode;
+
+	/* Indicates whether retry is needed when i2c transfer fails */
+	bool retry_i2c_transfers;
 };
 
 struct mxt_vb2_buffer {
@@ -627,7 +631,9 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock)
 static int __mxt_read_reg(struct i2c_client *client,
 			       u16 reg, u16 len, void *val)
 {
+	struct mxt_data *data = i2c_get_clientdata(client);
 	struct i2c_msg xfer[2];
+	bool retried = false;
 	u8 buf[2];
 	int ret;
 
@@ -646,22 +652,30 @@ static int __mxt_read_reg(struct i2c_client *client,
 	xfer[1].len = len;
 	xfer[1].buf = val;
 
-	ret = i2c_transfer(client->adapter, xfer, 2);
-	if (ret == 2) {
-		ret = 0;
-	} else {
-		if (ret >= 0)
-			ret = -EIO;
+retry_read:
+	ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer));
+	if (ret != ARRAY_SIZE(xfer)) {
+		if (data->retry_i2c_transfers && !retried) {
+			dev_dbg(&client->dev, "i2c retry\n");
+			/* TODO: add WAKE-GPIO support */
+			msleep(MXT_WAKEUP_TIME);
+			retried = true;
+			goto retry_read;
+		}
+		ret = ret < 0 ? ret : -EIO;
 		dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
 			__func__, ret);
+		return ret;
 	}
 
-	return ret;
+	return 0;
 }
 
 static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
 			   const void *val)
 {
+	struct mxt_data *data = i2c_get_clientdata(client);
+	bool retried = false;
 	u8 *buf;
 	size_t count;
 	int ret;
@@ -675,14 +689,21 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
 	buf[1] = (reg >> 8) & 0xff;
 	memcpy(&buf[2], val, len);
 
+retry_write:
 	ret = i2c_master_send(client, buf, count);
-	if (ret == count) {
-		ret = 0;
-	} else {
-		if (ret >= 0)
-			ret = -EIO;
+	if (ret != count) {
+		if (data->retry_i2c_transfers && !retried) {
+			dev_dbg(&client->dev, "i2c retry\n");
+			/* TODO: add WAKE-GPIO support */
+			msleep(MXT_WAKEUP_TIME);
+			retried = true;
+			goto retry_write;
+		}
+		ret = ret < 0 ? ret : -EIO;
 		dev_err(&client->dev, "%s: i2c send failed (%d)\n",
 			__func__, ret);
+	} else {
+		ret = 0;
 	}
 
 	kfree(buf);
@@ -3084,6 +3105,7 @@ static const struct dmi_system_id chromebook_T9_suspend_dmi[] = {
 
 static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
 {
+	struct device_node *np = client->dev.of_node;
 	struct mxt_data *data;
 	int error;
 
@@ -3158,6 +3180,20 @@ static int mxt_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		msleep(MXT_RESET_INVALID_CHG);
 	}
 
+	/*
+	 * The mXT1386 has a dedicated WAKE-line that could be connected to a
+	 * dedicated GPIO, or to the I2C SCL pin, or permanently asserted LOW.
+	 * It's used for waking controller from a deep-sleep and it needs to be
+	 * asserted LOW for 25 milliseconds before issuing I2C transfer if controller
+	 * was in a deep-sleep mode. If WAKE-line is connected to I2C SCL pin, then
+	 * the first I2C transfer will get an instant NAK and transfer needs to be
+	 * retried after 25ms. There are too many places in the code where the wake-up
+	 * needs to be inserted, hence it's much easier to add a retry to the common
+	 * I2C accessors, also given that the WAKE-GPIO is unsupported by the driver.
+	 */
+	if (of_device_is_compatible(np, "atmel,mXT1386"))
+		data->retry_i2c_transfers = true;
+
 	error = mxt_initialize(data);
 	if (error)
 		return error;
@@ -3235,6 +3271,7 @@ static SIMPLE_DEV_PM_OPS(mxt_pm_ops, mxt_suspend, mxt_resume);
 
 static const struct of_device_id mxt_of_match[] = {
 	{ .compatible = "atmel,maxtouch", },
+	{ .compatible = "atmel,mXT1386", },
 	/* Compatibles listed below are deprecated */
 	{ .compatible = "atmel,qt602240_ts", },
 	{ .compatible = "atmel,atmel_mxt_ts", },
@@ -3259,6 +3296,7 @@ static const struct i2c_device_id mxt_id[] = {
 	{ "atmel_mxt_tp", 0 },
 	{ "maxtouch", 0 },
 	{ "mXT224", 0 },
+	{ "mXT1386", 0 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, mxt_id);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible
  2020-09-25 13:52 [PATCH v2 0/3] implement I2C retries for mXT1368 Jiada Wang
  2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
  2020-09-25 13:52 ` [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368 Jiada Wang
@ 2020-09-25 13:52 ` Jiada Wang
  2020-09-25 21:02   ` Dmitry Osipenko
  2 siblings, 1 reply; 9+ messages in thread
From: Jiada Wang @ 2020-09-25 13:52 UTC (permalink / raw)
  To: dmitry.torokhov, robh+dt, thierry.reding, digetx, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca,
	andrew_gabbasov, jiada_wang

Add mXT1386 compatible for "touchscreen@4c".

Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
---
 arch/arm/boot/dts/tegra20-acer-a500-picasso.dts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
index 2d683c9a1a5d..7915b6e9190e 100644
--- a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
+++ b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
@@ -428,7 +428,7 @@
 		};
 
 		touchscreen@4c {
-			compatible = "atmel,maxtouch";
+			compatible = "atmel,mXT1386", "atmel,maxtouch";
 			reg = <0x4c>;
 
 			atmel,cfg_name = "maxtouch-acer-iconia-tab-a500.cfg";
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368
  2020-09-25 13:52 ` [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368 Jiada Wang
@ 2020-09-25 21:01   ` Dmitry Osipenko
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Osipenko @ 2020-09-25 21:01 UTC (permalink / raw)
  To: Jiada Wang, dmitry.torokhov, robh+dt, thierry.reding, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca, andrew_gabbasov

25.09.2020 16:52, Jiada Wang пишет:
> According to datasheet, mXT1386 chip has a WAKE line, it is used
> to wake the chip up from deep sleep mode before communicating with
> it via the I2C-compatible interface.
> 
> if the WAKE line is connected to a GPIO line, the line must be
> asserted 25 ms before the host attempts to communicate with the mXT1386.
> If the WAKE line is connected to the SCL pin, the mXT1386 will send a
> NACK on the first attempt to address it, the host must then retry 25 ms
> later.
> 
> This patch adds compatible string "atmel,mXT1386" for mXT1386 controller,
> when I2C transfer on mXT1386 fails, retry the transfer once after a 25 ms
> sleep.
> 
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
> ---
>  drivers/input/touchscreen/atmel_mxt_ts.c | 62 +++++++++++++++++++-----
>  1 file changed, 50 insertions(+), 12 deletions(-)

Hello, Jiada! Thank you very much!

Will be nice if this patch could land to v5.10 :)

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386
  2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
@ 2020-09-25 21:01   ` Dmitry Osipenko
  2020-09-28  6:59   ` Thierry Reding
  1 sibling, 0 replies; 9+ messages in thread
From: Dmitry Osipenko @ 2020-09-25 21:01 UTC (permalink / raw)
  To: Jiada Wang, dmitry.torokhov, robh+dt, thierry.reding, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca, andrew_gabbasov

25.09.2020 16:52, Jiada Wang пишет:
> Document the mXT1386 compatible string.
> 
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
> ---
>  Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> index c88919480d37..c13fc0f3f00b 100644
> --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> @@ -3,6 +3,7 @@ Atmel maXTouch touchscreen/touchpad
>  Required properties:
>  - compatible:
>      atmel,maxtouch
> +    atmel,mXT1386
>  
>      The following compatibles have been used in various products but are
>      deprecated:
> 

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible
  2020-09-25 13:52 ` [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible Jiada Wang
@ 2020-09-25 21:02   ` Dmitry Osipenko
  0 siblings, 0 replies; 9+ messages in thread
From: Dmitry Osipenko @ 2020-09-25 21:02 UTC (permalink / raw)
  To: Jiada Wang, dmitry.torokhov, robh+dt, thierry.reding, jonathanh
  Cc: nick, linux-input, linux-kernel, linux-tegra, erosca, andrew_gabbasov

25.09.2020 16:52, Jiada Wang пишет:
> Add mXT1386 compatible for "touchscreen@4c".
> 
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
> ---
>  arch/arm/boot/dts/tegra20-acer-a500-picasso.dts | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
> index 2d683c9a1a5d..7915b6e9190e 100644
> --- a/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
> +++ b/arch/arm/boot/dts/tegra20-acer-a500-picasso.dts
> @@ -428,7 +428,7 @@
>  		};
>  
>  		touchscreen@4c {
> -			compatible = "atmel,maxtouch";
> +			compatible = "atmel,mXT1386", "atmel,maxtouch";
>  			reg = <0x4c>;
>  
>  			atmel,cfg_name = "maxtouch-acer-iconia-tab-a500.cfg";
> 

Reviewed-by: Dmitry Osipenko <digetx@gmail.com>
Tested-by: Dmitry Osipenko <digetx@gmail.com>

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386
  2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
  2020-09-25 21:01   ` Dmitry Osipenko
@ 2020-09-28  6:59   ` Thierry Reding
  2020-09-30 14:22     ` Wang, Jiada
  1 sibling, 1 reply; 9+ messages in thread
From: Thierry Reding @ 2020-09-28  6:59 UTC (permalink / raw)
  To: Jiada Wang
  Cc: dmitry.torokhov, robh+dt, digetx, jonathanh, nick, linux-input,
	linux-kernel, linux-tegra, erosca, andrew_gabbasov

[-- Attachment #1: Type: text/plain, Size: 802 bytes --]

On Fri, Sep 25, 2020 at 10:52:55PM +0900, Jiada Wang wrote:
> Document the mXT1386 compatible string.
> 
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
> ---
>  Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> index c88919480d37..c13fc0f3f00b 100644
> --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
> @@ -3,6 +3,7 @@ Atmel maXTouch touchscreen/touchpad
>  Required properties:
>  - compatible:
>      atmel,maxtouch
> +    atmel,mXT1386

Compatible strings are preferred to be all lowercase.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386
  2020-09-28  6:59   ` Thierry Reding
@ 2020-09-30 14:22     ` Wang, Jiada
  0 siblings, 0 replies; 9+ messages in thread
From: Wang, Jiada @ 2020-09-30 14:22 UTC (permalink / raw)
  To: Thierry Reding
  Cc: dmitry.torokhov, robh+dt, digetx, jonathanh, nick, linux-input,
	linux-kernel, linux-tegra, erosca, andrew_gabbasov

Hi Thierry

Thanks for your comment

On 2020/09/28 15:59, Thierry Reding wrote:
> On Fri, Sep 25, 2020 at 10:52:55PM +0900, Jiada Wang wrote:
>> Document the mXT1386 compatible string.
>>
>> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
>> ---
>>   Documentation/devicetree/bindings/input/atmel,maxtouch.txt | 1 +
>>   1 file changed, 1 insertion(+)
>>
>> diff --git a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
>> index c88919480d37..c13fc0f3f00b 100644
>> --- a/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
>> +++ b/Documentation/devicetree/bindings/input/atmel,maxtouch.txt
>> @@ -3,6 +3,7 @@ Atmel maXTouch touchscreen/touchpad
>>   Required properties:
>>   - compatible:
>>       atmel,maxtouch
>> +    atmel,mXT1386
> 
> Compatible strings are preferred to be all lowercase.

I will update to use lowercase

Thanks,
Jiada
> 
> Thierry
> 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-09-30 14:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 13:52 [PATCH v2 0/3] implement I2C retries for mXT1368 Jiada Wang
2020-09-25 13:52 ` [PATCH v2 1/3] dt-bindings: input: atmel: add compatible for mXT1386 Jiada Wang
2020-09-25 21:01   ` Dmitry Osipenko
2020-09-28  6:59   ` Thierry Reding
2020-09-30 14:22     ` Wang, Jiada
2020-09-25 13:52 ` [PATCH v2 2/3] Input: atmel_mxt_ts - implement I2C retries for mXT1368 Jiada Wang
2020-09-25 21:01   ` Dmitry Osipenko
2020-09-25 13:52 ` [PATCH v2 3/3] ARM: tegra: add mXT1386 compatible Jiada Wang
2020-09-25 21:02   ` Dmitry Osipenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.