Input: atmel_mxt_ts - implement I2C retries
Subsystems (3)
PATCH v4 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.
[jiada: return exact errno when i2c_transfer & i2c_master_send fails
rename "retry" to "retried" and keep its order in length set "ret" to correct errno before calling dev_err() remove reduntant conditional]
--- drivers/input/touchscreen/atmel_mxt_ts.c | 38 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-)
drivers/input/touchscreen/atmel_mxt_ts.c +26 -12
@@ -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
@@ -624,6 +625,7 @@ static int __mxt_read_reg(struct i2c_client *client, u16 reg, u16 len, void *val) { struct i2c_msg xfer[2]; +bool retried = false;u8 buf[2 ];int ret;
@@ -642,22 +644,28 @@ 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 (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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) { +bool retried = false;u8 *buf;size_t count;int ret;
@@ -671,14 +679,20 @@ 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 (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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);
Signature · 1 line
2.17.1
Quoted 7 lines · Jiada Wang
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.
Quoted 8 lines
Signed-off-by Nick Dyer <[email protected]>[gdavis: Forward port and fix conflicts.]Signed-off-by George G. Davis <[email protected]>[jiada: return exact errno when
i2c_transfer&i2c_master_sendfails
rename "retry" to "retried" and keep its order in length set "ret" to correct errno before callingdev_err()remove reduntant conditional]
redundant
Quoted 3 lines
Signed-off-by Jiada Wang <[email protected]>Reviewed-by Dmitry Osipenko <[email protected]>Tested-by Dmitry Osipenko <[email protected]>
...
Quoted 1 line
+ bool retried = false;
I thought Dmitry wants that to be retry
drivers/input/touchscreen/atmel_mxt_ts.c static int __mxt_read_reg(struct i2c_client *client,
Quoted 13 lines
u8 buf[2]; int ret;drivers/input/touchscreen/atmel_mxt_ts.c +3
-6- 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)) {
I'm wondering why you can't leave 2 as is and change it to ARRAY_SIZE in a separate patch?
Also why switch from positive to negative conditional?
Quoted 15 lines
drivers/input/touchscreen/atmel_mxt_ts.c +9
-1+if (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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 ; }
..
Quoted 1 line
+ bool retried = false;
Same comments here, in this function.
Quoted 20 lines
drivers/input/touchscreen/atmel_mxt_ts.c +11
-5+retry_write: ret =i2c_master_send (client, buf, count); -if (ret == count) { - ret =0 ; - }else { -if (ret >=0 ) - ret = -EIO ; +if (ret != count) { +if (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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 ; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
13.09.2020 11:43, Andy Shevchenko пишет:
Quoted 5 lines
...
Quoted 1 line
+ bool retried = false;
I thought Dmitry wants that to be retry
In the comment to v2 you suggested to negate the condition, hence I thought it's YOU who wants it to be retried.
The "retried" is a very common form among kernel drivers, so it's good to me.
Quoted 11 lines
Quoted 10 lines
u8 buf[2]; int ret;drivers/input/touchscreen/atmel_mxt_ts.c +1
-6- ret =i2c_transfer (client->adapter, xfer,2 ); -if (ret ==2 ) { - ret =0 ; - }else { -if (ret >=0 ) - ret = -EIO ; +retry_read:
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c static int __mxt_read_reg(struct i2c_client *client, · line 649
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c +2
-0+ ret =i2c_transfer (client->adapter, xfer,ARRAY_SIZE (xfer)); +if (ret !=ARRAY_SIZE (xfer)) {
...> Also why switch from positive to negative conditional?
This will make code less readable because of the goto, and thus, there will be two branches for handling of the returned value instead of one + goto. Hence this part is good to me as-is.
Quoted 15 lines
Quoted 15 lines
drivers/input/touchscreen/atmel_mxt_ts.c +9
-1+if (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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 ; }
Quoted 9 lines · Dmitry Osipenko
13.09.2020 11:43, Andy Shevchenko пишет:
Quoted 5 lines
...
Quoted 1 line
+ bool retried = false;
I thought Dmitry wants that to be retry
In the comment to v2 you suggested to negate the condition,
Where? I just checked a few messages before and I found that I asked the same question: why is negative conditional used instead of positive.
Quoted 2 lines
hence I
thought it's YOU who wants it to be retried.
I see. Let's see how it goes with positive conditionals first.
Quoted 14 lines
The "retried" is a very common form among kernel drivers, so it's good to me.
Quoted 11 lines
Quoted 10 lines
u8 buf[2]; int ret;drivers/input/touchscreen/atmel_mxt_ts.c +1
-6- ret =i2c_transfer (client->adapter, xfer,2 ); -if (ret ==2 ) { - ret =0 ; - }else { -if (ret >=0 ) - ret = -EIO ; +retry_read:
Quoted 7 lines
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c static int __mxt_read_reg(struct i2c_client *client, · line 649
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c +2
-0+ ret =i2c_transfer (client->adapter, xfer,ARRAY_SIZE (xfer)); +if (ret !=ARRAY_SIZE (xfer)) {...> Also why switch from positive to negative conditional?
This will make code less readable because of the goto, and thus, there will be two branches for handling of the returned value instead of one + goto. Hence this part is good to me as-is.
But it's not the purpose of this patch, right? Style changes should be really separated from the fix. And since it's a fix it should have a Fixes tag.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
drivers/input/touchscreen/atmel_mxt_ts.c +9
-1+if (!retried) { +dev_dbg (&client->dev,"i2c retry\n" ); +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 ; }
Signature · 2 lines
With Best Regards, Andy Shevchenko
14.09.2020 16:49, Andy Shevchenko пишет:
Quoted 7 lines · Dmitry Osipenko
Quoted 6 lines
13.09.2020 11:43, Andy Shevchenko пишет:
Quoted 3 lines
...
Quoted 1 line
+ bool retried = false;
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
I thought Dmitry wants that to be retry
In the comment to v2 you suggested to negate the condition,
Where? I just checked a few messages before and I found that I asked the same question: why is negative conditional used instead of positive.
I'm reading this as imperative "make it positive", and thus, assumed that you asked to do so because the "retry" implies a positive condition, while "retried" implies the negative.
If you've added "Could you please explain why", then I'd read it as a question.
Quoted 22 lines
Quoted 2 lines
hence I
thought it's YOU who wants it to be retried.I see. Let's see how it goes with positive conditionals first.
Quoted 16 lines
The "retried" is a very common form among kernel drivers, so it's good to me.
Quoted 13 lines
Quoted 13 lines
u8 buf[2]; int ret;drivers/input/touchscreen/atmel_mxt_ts.c +3
-6- 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)) {
Quoted 8 lines
Quoted 5 lines
...> Also why switch from positive to negative conditional?
This will make code less readable because of the goto, and thus, there will be two branches for handling of the returned value instead of one + goto. Hence this part is good to me as-is.
But it's not the purpose of this patch, right? Style changes should be really separated from the fix.
This should be up to a particular maintainer to decide. Usually nobody requires patches to be overly pedantic, this may turn away contributors because it feels like an unnecessary bikeshedding. It's more preferred to accept patch as-is if it does right thing and then maintainer could modify the patch, making cosmetic changes.
Quoted 1 line
And since it's a fix it should have a Fixes tag.
It shouldn't be a fix, but a new feature because apparently the 1386 controller wasn't ever intended to be properly supported before this patch.
Quoted 2 lines · Dmitry Osipenko
14.09.2020 16:49, Andy Shevchenko пишет:
Quoted 1 line · Dmitry Osipenko
...
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c static int __mxt_read_reg(struct i2c_client *client, · line 649
Quoted 2 lines
drivers/input/touchscreen/atmel_mxt_ts.c +2
-0+ ret =i2c_transfer (client->adapter, xfer,ARRAY_SIZE (xfer)); +if (ret !=ARRAY_SIZE (xfer)) {...> Also why switch from positive to negative conditional?
This will make code less readable because of the goto, and thus, there will be two branches for handling of the returned value instead of one + goto. Hence this part is good to me as-is.
Quoted 6 lines
Quoted 2 lines
But it's not the purpose of this patch, right? Style changes should be really separated from the fix.
This should be up to a particular maintainer to decide. Usually nobody requires patches to be overly pedantic, this may turn away contributors because it feels like an unnecessary bikeshedding.
Let's see what Wolfram thinks about this.
Quoted 3 lines
It's more preferred
to accept patch as-is if it does right thing and then maintainer could modify the patch, making cosmetic changes.
It depends on the maintainer's workflow (which may be different from maintainer to maintainer).
Quoted 4 lines
Quoted 1 line
And since it's a fix it should have a Fixes tag.
It shouldn't be a fix, but a new feature because apparently the 1386 controller wasn't ever intended to be properly supported before this patch.
Thanks for clarification. Indeed in this case no tag is needed.
Signature · 2 lines
With Best Regards, Andy Shevchenko
14.09.2020 18:50, Andy Shevchenko пишет:
...
Quoted 6 lines
Quoted 3 lines
It's more preferred
to accept patch as-is if it does right thing and then maintainer could modify the patch, making cosmetic changes.It depends on the maintainer's workflow (which may be different from maintainer to maintainer).
Sure!
It's awesome that you're pointing out it all in the reviews because it's important to have such things explained and definitely should help to improve quality of further of patches! But it shouldn't be necessary to demand a very minor changes, IMO.
In particular Jiada was submitting this and lots of other atmel_mxt_ts patches for about a year now without much progress yet, and you probably should know how a frustrating experience this could be for a contributor since you're a longtime kernel developer.
Dmitry Torokhov
maintainerHi Jiada,
Quoted 5 lines · Jiada Wang
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Thanks.
Signature · 1 line
Dmitry
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first __mxt_read_reg() returns I2C NACK on reading out TS hardware info.
2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first __mxt_write_reg() invoked from mxt_start() returns I2C NACK.
I think placing the retries within __mxt_read() / write_reg() should be the most universal option.
Perhaps it should be possible to add mxt_wake() that will read out some generic register and then this helper should be invoked after HW resetting (before mxt_read_info_block()) and from mxt_start() (before mxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.
AFAIK, there shouldn't be any extra benefits from the retrying other than to handle the deep-sleep of mxt1386.
Dmitry Torokhov
maintainerQuoted 32 lines · Dmitry Osipenko
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.
Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic register
I do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)
should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerQuoted 52 lines · Dmitry Torokhov
Quoted 32 lines · Dmitry Osipenko
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic registerI do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.
Quoted 4 lines
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
By the way, I would like to avoid the unnecessary retries in probe paths if possible. I.e. on Chrome OS we really keep an eye on boot times and in case of multi-sourced touchscreens we may legitimately not have device at given address.
Thanks.
Signature · 1 line
Dmitry
14.09.2020 22:36, Dmitry Torokhov пишет:
Quoted 53 lines · Dmitry Torokhov
Quoted 52 lines · Dmitry Osipenko
Quoted 32 lines
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic registerI do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.
Quoted 4 lines
Quoted 4 lines
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
The WAKE-GPIO was never supported and I'm not sure whether anyone actually needs it. I think we could ignore this case until anyone would really need and could test it.
Quoted 4 lines
By the way, I would like to avoid the unnecessary retries in probe paths if possible. I.e. on Chrome OS we really keep an eye on boot times and in case of multi-sourced touchscreens we may legitimately not have device at given address.
We could add a new MXT1386 DT compatible and then do:
static void mxt_wake(struct mxt_data *data)
{
struct i2c_client *client = data->client;
struct device *dev = &data->client->dev;
union i2c_smbus_data dummy;
if (!of_device_is_compatible(dev, "atmel,mXT1386"))
return;
/* TODO: add WAKE-GPIO support */
i2c_smbus_xfer(client->adapter, client->addr,
0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE,
&dummy);
msleep(MXT_WAKEUP_TIME);
}Jiada, will you be able to re-work this patch? Please note that the new "atmel,mXT1386" DT compatible needs to be added into the atmel,maxtouch.txt binding.
Dmitry Torokhov
maintainerQuoted 54 lines · Dmitry Osipenko
14.09.2020 22:36, Dmitry Torokhov пишет:
Quoted 53 lines · Dmitry Torokhov
Quoted 52 lines · Dmitry Osipenko
Quoted 32 lines
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic registerI do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.
Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
The WAKE-GPIO was never supported and I'm not sure whether anyone actually needs it. I think we could ignore this case until anyone would really need and could test it.
Right, I am not advocating adding GPIO control right away, I was simply arguing why I believe we should separate wakeup handling from normal communication handling.
Quoted 26 lines
Quoted 5 lines
By the way, I would like to avoid the unnecessary retries in probe paths if possible. I.e. on Chrome OS we really keep an eye on boot times and in case of multi-sourced touchscreens we may legitimately not have device at given address.
We could add a new MXT1386 DT compatible and then do:
static void
mxt_wake(struct mxt_data *data){ struct i2c_client *client = data->client; struct device *dev = &data->client->dev; union i2c_smbus_data dummy; if (!of_device_is_compatible(dev, "atmel,mXT1386")) return; /* TODO: add WAKE-GPIO support */ i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy); msleep(MXT_WAKEUP_TIME); }
Quoted 3 lines
Jiada, will you be able to re-work this patch? Please note that the new "atmel,mXT1386" DT compatible needs to be added into the atmel,maxtouch.txt binding.
Another option is to have a device property "atmel,wakeup-type" or something, in case there are more Atmel variants needing this.
Rob, any preferences here?
Thanks.
Signature · 1 line
Dmitry
Quoted 95 lines · Dmitry Torokhov
Quoted 54 lines · Dmitry Osipenko
14.09.2020 22:36, Dmitry Torokhov пишет:
Quoted 53 lines · Dmitry Torokhov
Quoted 52 lines · Dmitry Osipenko
Quoted 32 lines
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic registerI do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.Quoted 8 lines
Quoted 4 lines
Quoted 4 lines
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
The WAKE-GPIO was never supported and I'm not sure whether anyone actually needs it. I think we could ignore this case until anyone would really need and could test it.
Right, I am not advocating adding GPIO control right away, I was simply arguing why I believe we should separate wakeup handling from normal communication handling.
Quoted 26 lines
Quoted 5 lines
By the way, I would like to avoid the unnecessary retries in probe paths if possible. I.e. on Chrome OS we really keep an eye on boot times and in case of multi-sourced touchscreens we may legitimately not have device at given address.
We could add a new MXT1386 DT compatible and then do:
static void
mxt_wake(struct mxt_data *data){ struct i2c_client *client = data->client; struct device *dev = &data->client->dev; union i2c_smbus_data dummy; if (!of_device_is_compatible(dev, "atmel,mXT1386")) return; /* TODO: add WAKE-GPIO support */ i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy); msleep(MXT_WAKEUP_TIME); }
Quoted 8 lines
Quoted 3 lines
Jiada, will you be able to re-work this patch? Please note that the new "atmel,mXT1386" DT compatible needs to be added into the atmel,maxtouch.txt binding.
Another option is to have a device property "atmel,wakeup-type" or something, in case there are more Atmel variants needing this.
Rob, any preferences here?
If device specific, then I prefer to be implied by the compatible. If board specific, then a property is appropriate. Seems like this is the former case.
Rob
Hi Dmitry
Quoted 88 lines · Dmitry Osipenko
14.09.2020 22:36, Dmitry Torokhov пишет:
Quoted 53 lines · Dmitry Torokhov
Quoted 52 lines · Dmitry Osipenko
Quoted 32 lines
13.09.2020 19:56, Dmitry Torokhov пишет:
Quoted 5 lines
Hi Jiada,
Quoted 2 lines · Jiada Wang
From: Nick Dyer <[email protected]>
Quoted 7 lines
Quoted 3 lines
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.
Do we know when the chip is in sleep state? Can we do a quick I2C transaction in this case instead of adding retry logic to everything? Or there is another benefit for having such retry logic?
Hello!
Please take a look at page 29 of:
https://ww1.microchip.com/downloads/en/DeviceDoc/mXT1386_1vx_Datasheet_LX.pdf
It says that the retry is needed after waking up from a deep-sleep mode.
There are at least two examples when it's needed:
1. Driver probe. Controller could be in a deep-sleep mode at the probe time, and then first
__mxt_read_reg()returns I2C NACK on reading out TS hardware info.2. Touchscreen input device is opened. The touchscreen is in a deep-sleep mode at the time when input device is opened, hence first
__mxt_write_reg()invoked frommxt_start()returns I2C NACK.Quoted 5 lines
I think placing the retries within
__mxt_read()/write_reg()should be the most universal option.Perhaps it should be possible to add
mxt_wake()that will read out some generic registerI do not think we need to read a particular register, just doing a quick read:
i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy)should suffice.
Quoted 4 lines
and then this helper should be invoked after HW
resetting (beforemxt_read_info_block()) and frommxt_start()(beforemxt_set_t7_power_cfg()). But this approach feels a bit fragile to me.Quoted 4 lines
Quoted 4 lines
Actually, reading the spec, it all depends on how the WAKE pin is wired up on a given board. In certain setups retrying transaction is the right approach, while in others explicit control is needed. So indeed, we need a "wake" helper that we should call in probe and resume paths.
The WAKE-GPIO was never supported and I'm not sure whether anyone actually needs it. I think we could ignore this case until anyone would really need and could test it.
Quoted 4 lines
By the way, I would like to avoid the unnecessary retries in probe paths if possible. I.e. on Chrome OS we really keep an eye on boot times and in case of multi-sourced touchscreens we may legitimately not have device at given address.
We could add a new MXT1386 DT compatible and then do:
static void
mxt_wake(struct mxt_data *data){ struct i2c_client *client = data->client; struct device *dev = &data->client->dev; union i2c_smbus_data dummy; if (!of_device_is_compatible(dev, "atmel,mXT1386")) return; /* TODO: add WAKE-GPIO support */ i2c_smbus_xfer(client->adapter, client->addr, 0, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &dummy); msleep(MXT_WAKEUP_TIME); }
Quoted 3 lines
Jiada, will you be able to re-work this patch? Please note that the new "atmel,mXT1386" DT compatible needs to be added into the atmel,maxtouch.txt binding.
Yes, I can re-work this patch, and add one more change to dts-binding.
to summarize long discussion in this thread,
I think what I need to do are:
1) since the change will be different from current one, I will need to start a new patch
2) call mxt_wake() in mxt_probe() and mxt_resume()
3) update atmel,maxtouch.txt binding
please correct me if I am wrong.
Thanks,
Jiada
Quoted 1 line
15.09.2020 18:55, Wang, Jiada пишет:
...
Quoted 11 lines
Quoted 3 lines
Jiada, will you be able to re-work this patch? Please note that the new "atmel,mXT1386" DT compatible needs to be added into the atmel,maxtouch.txt binding.
Yes, I can re-work this patch, and add one more change to dts-binding.
to summarize long discussion in this thread,
I think what I need to do are:
1) since the change will be different from current one, I will need to start a new patch
2) callmxt_wake()inmxt_probe()andmxt_resume()
in mxt_initialize(), mxt_load_fw() and mxt_start()
Quoted 3 lines
3) update atmel,maxtouch.txt binding
please correct me if I am wrong.
sounds good