Input: atmel_mxt_ts - implement I2C retries
Subsystems (3)
PATCH v2 1/1 Input: atmel_mxt_ts - implement I2C retries
From: Nick Dyer <[email protected]>
Some maXTouch chips (eg mXT1386) will not respond on the first I2C request when they are in a sleep state. It must be retried after a delay for the chip to wake up.
(cherry picked from ndyer/linux/for-upstream commit 63fd7a2cd03c3a572a5db39c52f4856819e1835d)
--- drivers/input/touchscreen/atmel_mxt_ts.c | 45 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/input/touchscreen/atmel_mxt_ts.c +30 -15
@@ -196,6 +196,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
@@ -626,6 +627,7 @@ static int __mxt_read_reg(struct i2c_client *client,struct i2c_msg xfer[2 ];u8 buf[2 ];int ret; +bool retry = false; buf[0 ] = reg &0xff ; buf[1 ] = (reg >>8 ) &0xff ;
@@ -642,17 +644,22 @@ 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 ; -dev_err (&client->dev,"%s: i2c transfer failed (%d)\n" , - __func__, ret); +retry_read: + ret =i2c_transfer (client->adapter, xfer,ARRAY_SIZE (xfer)); +if (ret !=ARRAY_SIZE (xfer)) { +if (!retry) { +dev_dbg (&client->dev,"%s: i2c retry\n" , __func__); +msleep (MXT_WAKEUP_TIME ); + retry = true; + goto retry_read; + }else { +dev_err (&client->dev,"%s: i2c transfer failed (%d)\n" , + __func__, ret); +return ret <0 ? ret : -EIO ; + } } -return ret; +return 0 ; } static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
@@ -661,6 +668,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,u8 *buf;size_t count;int ret; +bool retry = false; count = len +2 ; buf =kmalloc (count,GFP_KERNEL );
@@ -671,14 +679,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 ; +if (ret != count) { +if (!retry) { +dev_dbg (&client->dev,"%s: i2c retry\n" , __func__); +msleep (MXT_WAKEUP_TIME ); + retry = true; + goto retry_write; + }else { +dev_err (&client->dev,"%s: i2c send failed (%d)\n" , + __func__, ret); + ret = ret <0 ? ret : -EIO ; + } }else { -if (ret >=0 ) - ret = -EIO ; -dev_err (&client->dev,"%s: i2c send failed (%d)\n" , - __func__, ret); + ret =0 ; }kfree (buf);
Signature · 1 line
2.17.1
03.09.2020 18:59, Jiada Wang пишет:
Quoted 8 lines
From: Nick Dyer <[email protected]>
Some maXTouch chips (eg mXT1386) will not respond on the first I2C request when they are in a sleep state. It must be retried after a delay for the chip to wake up.
Signed-off-by Nick Dyer <[email protected]>Acked-by Yufeng Shen <[email protected]>
Quoted 8 lines
(cherry picked from ndyer/linux/for-upstream commit
63fd7a2cd03c3a572a5db39c52f4856819e1835d)[gdavis: Forward port and fix conflicts.]Signed-off-by George G. Davis <[email protected]>[jiada: return exact errno when i2c_transfer & i2c_master_send fails]Signed-off-by Jiada Wang <[email protected]>--- drivers/input/touchscreen/atmel_mxt_ts.c | 45 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 15 deletions(-)
Hello, Jiada!
Everything works well on Acer A500 tablet device that uses mXT1386 for the touchscreen controller! Thank you very much!
A message that is not in the archive (sent off-list or not yet received): CAHp75Vfw1bJ+0pRJKVJ=nCJ-5rVzYLjkP4iWPqiG-it0qp5GFg@mail.gmail.com
05.09.2020 21:02, Andy Shevchenko пишет:
...
Quoted 7 lines
#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 */Can we simple add
_MSunit suffix to the definition?
I'd expect this
Quoted 10 lines
/* Command to unlock bootloader */ #define MXT_UNLOCK_CMD_MSB 0xaa @@ -626,6 +627,7 @@ static int __mxt_read_reg(struct i2c_client *client, struct i2c_msg xfer[2]; u8 buf[2]; int ret; + bool retry = false;Keep this ordered by length.
and this to be separate patches that are cleaning whole driver code, otherwise there are no much benefits.
Hi Andy
Thanks for your comment
Quoted 14 lines · Andy Shevchenko
On Thursday, September 3, 2020, Jiada Wang <[email protected] <mailto:[email protected]>> wrote:
From: Nick Dyer <[email protected] <mailto:[email protected]>>
Some maXTouch chips (eg mXT1386) will not respond on the first I2C request
when they are in a sleep state. It must be retried after a delay for the chip to wake up.Signed-off-by Nick Dyer <[email protected]<mailto:[email protected]>>
Acked-by Yufeng Shen <[email protected]
Quoted 9 lines
<mailto:[email protected]>>
(cherry picked from ndyer/linux/for-upstream commit
63fd7a2cd03c3a572a5db39c52f4856819e1835d)It’s a noise for upstream.
sure, I will remove it
Quoted 22 lines
[gdavis: Forward port and fix conflicts.]
Signed-off-by: George G. Davis <[email protected]
<mailto:[email protected]>>
[jiada: return exact errno when i2c_transfer & i2c_master_send fails]
Signed-off-by: Jiada Wang <[email protected]
<mailto:[email protected]>>
---
drivers/input/touchscreen/atmel_mxt_ts.c | 45 ++++++++++++++++--------
1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c
b/drivers/input/touchscreen/atmel_mxt_ts.c
index a2189739e30f..5d4cb15d21dc 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -196,6 +196,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 */Quoted 1 line
Can we simple add
_MSunit suffix to the definition?
As Dmitry commented, I'd like to keep it as-is, probably a separate patch to update all these together.
Quoted 11 lines
/* Command to unlock bootloader */
#define MXT_UNLOCK_CMD_MSB 0xaa
@@ -626,6 +627,7 @@ static int __mxt_read_reg(struct i2c_client *client,
struct i2c_msg xfer[2];
u8 buf[2];
int ret;
+ bool retry = false;Quoted 1 line
Keep this ordered by length.
I will move "retry" upper.
Quoted 23 lines
buf[0] = reg & 0xff;
buf[1] = (reg >> 8) & 0xff;
@@ -642,17 +644,22 @@ 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;
- dev_err(&client->dev, "%s: i2c transfer failed (%d)\n",
- __func__, ret);
+retry_read:
+ ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer));
+ if (ret != ARRAY_SIZE(xfer)) {
+ if (!retry) {Quoted 1 line
Why not positive conditional?
to me, it's not much different either positive or negative conditional, can you elaborate more about this?
Quoted 7 lines
+ dev_dbg(&client->dev, "%s: i2c retry\n", __func__);
__func__is redundant fordev_dbg().
Quoted 8 lines
+ msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_read; + } else {Redundant in either case of conditional. Allows to drop indentation level.
I will remove the redundant conditional
Thanks,
Jiada
Quoted 67 lines
+ dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", + __func__, ret); + return ret < 0 ? ret : -EIO; + } } - return ret; + return 0; }Same comments about below.
static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, @@ -661,6 +668,7 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len, u8 *buf; size_t count; int ret; + bool retry = false; count = len + 2; buf = kmalloc(count, GFP_KERNEL); @@ -671,14 +679,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; + if (ret != count) { + if (!retry) { + dev_dbg(&client->dev, "%s: i2c retry\n", __func__); + msleep(MXT_WAKEUP_TIME); + retry = true; + goto retry_write; + } else { + dev_err(&client->dev, "%s: i2c send failed (%d)\n", + __func__, ret); + ret = ret < 0 ? ret : -EIO; + } } else { - if (ret >= 0) - ret = -EIO; - dev_err(&client->dev, "%s: i2c send failed (%d)\n", - __func__, ret); + ret = 0; } kfree(buf); -- 2.17.1Signature · 2 lines
With Best Regards, Andy Shevchenko