i2c: exynos5: bus recovery implementation
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): CGME20171130143017eucas1p172b94622814eff172a27176c82f6e6fe@eucas1p1.samsung.com
cover i2c: exynos5: bus recovery implementation
Hi,
This patchset adds bus recovery functionality to Exynos HSI2C, it is used in case of transmission timeouts.
Internal tests shows that it significantly improves I2C transmissions.
Andi, could you take a look at it/test, feedback welcome.
Later, I will post also patches to MHL chip which uses this functionality. MHL chip has known bug of being in incorrect state after hard reset, I2C bus recovery cures it.
Regards
Andrzej
Andrzej Hajda (3):
i2c: exynos5: change internal transmission timeout to 100ms
i2c: exynos5: implement bus recovery functionality
i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
drivers/i2c/busses/i2c-exynos5.c | 52 +++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-)
Signature · 1 line
2.15.0
PATCH 1/3 i2c: exynos5: change internal transmission timeout to 100ms
Exynos-I2C uses default timeout of 1 second for the whole transaction, including re-transmissions due to arbitration lost errors (-EAGAIN). To allow re-transmissions driver's internal timeout should be significantly lower, 100ms seems to be good candidate.
--- drivers/i2c/busses/i2c-exynos5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-exynos5.c +1 -1
@@ -170,7 +170,7 @@#define HSI2C_HS_TX_CLOCK 1000000#define HSI2C_FS_TX_CLOCK 100000 -#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(1000)) +#define EXYNOS5_I2C_TIMEOUT (msecs_to_jiffies(100))#define HSI2C_EXYNOS7 BIT(0)
Signature · 1 line
2.15.0
Wolfram Sang
AppliedRe: [1/3] i2c: exynos5: change internal transmission timeout to 100ms
Quoted 6 lines · Andrzej Hajda
Exynos-I2C uses default timeout of 1 second for the whole transaction, including re-transmissions due to arbitration lost errors (
-EAGAIN). To allow re-transmissions driver's internal timeout should be significantly lower, 100ms seems to be good candidate.Signed-off-by Andrzej Hajda <[email protected]>
Applied to for-next, thanks!
PATCH 2/3 i2c: exynos5: implement bus recovery functionality
In reply to Andrzej HajdaIn some circumstances I2C clients can be in abnormal state, to allow recover them from it I2C master can pulse SCL line until SDA line goes up and then generate STOP condition. Exynos driver does not have possibility to manipulate I2C lines directly, but it can provide similar functionality using manual commands. Replacing I2C adapter reset with bus recovery significantly incereases I2C bus robustness in case of timeouts.
--- drivers/i2c/busses/i2c-exynos5.c | 44 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-exynos5.c +43 -1
@@ -128,6 +128,10 @@#define HSI2C_TIMEOUT_EN (1u << 31)#define HSI2C_TIMEOUT_MASK 0xff +/* I2C_MANUAL_CMD register bits */ +#define HSI2C_CMD_READ_DATA (1u << 4) +#define HSI2C_CMD_SEND_STOP (1u << 2) +/* I2C_TRANS_STATUS register bits */ #define HSI2C_MASTER_BUSY (1u << 17)#define HSI2C_SLAVE_BUSY (1u << 16)
@@ -613,6 +617,26 @@ static void exynos5_i2c_message_start(struct exynos5_i2c *i2c, int stop)spin_unlock_irqrestore (&i2c->lock, flags); } +void exynos5_i2c_recovery (struct exynos5_i2c *i2c) +{ +u32 val; + + val =readl (i2c->regs +HSI2C_CTL ) |HSI2C_RXCHON ; +writel (val, i2c->regs +HSI2C_CTL ); + val =readl (i2c->regs +HSI2C_CONF ) & ~HSI2C_AUTO_MODE ; +writel (val, i2c->regs +HSI2C_CONF ); + +writel (HSI2C_CMD_READ_DATA , i2c->regs +HSI2C_MANUAL_CMD ); +exynos5_i2c_wait_bus_idle (i2c); +writel (HSI2C_CMD_SEND_STOP , i2c->regs +HSI2C_MANUAL_CMD ); +exynos5_i2c_wait_bus_idle (i2c); + + val =readl (i2c->regs +HSI2C_CTL ) & ~HSI2C_RXCHON ; +writel (val, i2c->regs +HSI2C_CTL ); + val =readl (i2c->regs +HSI2C_CONF ) |HSI2C_AUTO_MODE ; +writel (val, i2c->regs +HSI2C_CONF ); +} +static int exynos5_i2c_xfer_msg (struct exynos5_i2c *i2c,struct i2c_msg *msgs,int stop) {
@@ -642,7 +666,7 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, ret =exynos5_i2c_wait_bus_idle (i2c);if (ret <0 ) { -exynos5_i2c_reset (i2c); +exynos5_i2c_recovery (i2c);if (ret == -ETIMEDOUT )dev_warn (i2c->dev,"%s timeout\n" , (msgs->flags &I2C_M_RD ) ?"rx" :"tx" );
@@ -703,6 +727,23 @@ static const struct i2c_algorithm exynos5_i2c_algorithm = { .functionality = exynos5_i2c_func, }; +int exynos5_i2c_recover_bus (struct i2c_adapter *adap) +{ +struct exynos5_i2c *i2c = adap->algo_data; + +i2c_lock_adapter (adap); +clk_enable (i2c->clk); +exynos5_i2c_recovery (i2c); +clk_disable (i2c->clk); +i2c_unlock_adapter (adap); + +return 0 ; +} + +static struct i2c_bus_recovery_info exynos5_i2c_recovery_info = { + .recover_bus = exynos5_i2c_recover_bus +}; +static int exynos5_i2c_probe (struct platform_device *pdev) {struct device_node *np = pdev->dev.of_node;
@@ -773,6 +814,7 @@ static int exynos5_i2c_probe(struct platform_device *pdev) goto err_clk;exynos5_i2c_reset (i2c); + i2c->adap.bus_recovery_info = &exynos5_i2c_recovery_info; ret =i2c_add_adapter (&i2c->adap);if (ret <0 )
Signature · 1 line
2.15.0
Re: [2/3] i2c: exynos5: implement bus recovery functionality
Hi,
Quoted 5 lines · Andrzej Hajda
In some circumstances I2C clients can be in abnormal state, to allow recover them from it I2C master can pulse SCL line until SDA line goes up and then generate STOP condition. Exynos driver does not have possibility to manipulate I2C lines directly, but it can provide similar functionality using manual commands. Replacing I2C adapter reset with
Really? READ_DATA looks like 8 clock pulses, but you need 9.
drivers/i2c/busses/i2c-exynos5.c static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, · line 669
Quoted 12 lines
bus recovery significantly incereases I2C bus robustness in case of timeouts.
Signed-off-by Andrzej Hajda <[email protected]>drivers/i2c/busses/i2c-exynos5.c +1
-1@@ -642,7 +666,7 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, ret =exynos5_i2c_wait_bus_idle (i2c);if (ret <0 ) { -exynos5_i2c_reset (i2c); +exynos5_i2c_recovery (i2c);
Bus recovery is only defined for stalled busses, i.e. when SDA is stuck low. It is not a suitable method to deal with general timeouts.
drivers/i2c/busses/i2c-exynos5.c static const struct i2c_algorithm exynos5_i2c_algorithm = { · line 738
Quoted 9 lines
drivers/i2c/busses/i2c-exynos5.c +9
-0+int exynos5_i2c_recover_bus (struct i2c_adapter *adap) +{ +struct exynos5_i2c *i2c = adap->algo_data; + +i2c_lock_adapter (adap); +clk_enable (i2c->clk); +exynos5_i2c_recovery (i2c); +clk_disable (i2c->clk); +i2c_unlock_adapter (adap);
Why do you need to lock? Aren't you protected by the call to master_xfer which then detected a problem?
Regards,
Wolfram
Re: [2/3] i2c: exynos5: implement bus recovery functionality
Quoted 9 lines · Wolfram Sang
Hi,
Quoted 5 lines · Andrzej Hajda
In some circumstances I2C clients can be in abnormal state, to allow recover them from it I2C master can pulse SCL line until SDA line goes up and then generate STOP condition. Exynos driver does not have possibility to manipulate I2C lines directly, but it can provide similar functionality using manual commands. Replacing I2C adapter reset with
Really?
READ_DATAlooks like 8 clock pulses, but you need 9.
This is why I have used word 'similar' :) Unfortunately chip does not provide method to send exactly 9 pulses.
But according to [1] it is the worst case scenario, usually less than 9 pulses is enough.
Another solution I see is to READ_DATA twice, this way we will have 16 pulses.
[1]:
http://www.analog.com/media/en/technical-documentation/application-notes/54305147357414AN686_0.pdf
Quoted 6 lines
Quoted 4 lines
bus recovery significantly incereases I2C bus robustness in case of timeouts.
Signed-off-by Andrzej Hajda <[email protected]>
Quoted 8 lines
drivers/i2c/busses/i2c-exynos5.c static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, · line 669
Quoted 6 lines
drivers/i2c/busses/i2c-exynos5.c +1
-1@@ -642,7 +666,7 @@ static int exynos5_i2c_xfer_msg(struct exynos5_i2c *i2c, ret =exynos5_i2c_wait_bus_idle (i2c);if (ret <0 ) { -exynos5_i2c_reset (i2c); +exynos5_i2c_recovery (i2c);Bus recovery is only defined for stalled busses, i.e. when SDA is stuck low. It is not a suitable method to deal with general timeouts.
You are right, I though I do not have precise info that SDA is stuck low, but I guess status HSI2C_MASTER_ST_LOSE indicates is, I will check it.
Quoted 13 lines
drivers/i2c/busses/i2c-exynos5.c static const struct i2c_algorithm exynos5_i2c_algorithm = { · line 738
Quoted 11 lines
drivers/i2c/busses/i2c-exynos5.c +9
-0+int exynos5_i2c_recover_bus (struct i2c_adapter *adap) +{ +struct exynos5_i2c *i2c = adap->algo_data; + +i2c_lock_adapter (adap); +clk_enable (i2c->clk); +exynos5_i2c_recovery (i2c); +clk_disable (i2c->clk); +i2c_unlock_adapter (adap);Why do you need to lock? Aren't you protected by the call to
master_xferwhich then detected a problem?
If the problem is detected in master_xfer driver uses internal function exynos5_i2c_recovery,
but function exynos5_i2c_recover_bus is called by i2c_recover_bus, and the latter can be called from any context,
this is why I have added locking.
Regards
Andrzej
Quoted 5 lines
Regards,
Wolfram
Re: [2/3] i2c: exynos5: implement bus recovery functionality
Quoted 5 lines
Quoted 2 lines
Really?
READ_DATAlooks like 8 clock pulses, but you need 9.This is why I have used word 'similar' :) Unfortunately chip does not provide method to send exactly 9 pulses.
Pity :(
Quoted 2 lines
But according to [1] it is the worst case scenario, usually less than 9 pulses is enough.
The I2C specification says "should send nine clock pulses". A recovery mechanism which "usually works" doesn't sound very attractive.
Quoted 2 lines
Another solution I see is to
READ_DATAtwice, this way we will have 16 pulses.
Can't you clock a single pulse when requesting an ACK? Or does READ_DATE clock an ACK so we might end up with 9 pulses after all?
Quoted 5 lines
Quoted 2 lines
Bus recovery is only defined for stalled busses, i.e. when SDA is stuck low. It is not a suitable method to deal with general timeouts.
You are right, I though I do not have precise info that SDA is stuck low, but I guess status
HSI2C_MASTER_ST_LOSEindicates is, I will check it.
Thank you!
Quoted 8 lines
Quoted 7 lines
drivers/i2c/busses/i2c-exynos5.c static const struct i2c_algorithm exynos5_i2c_algorithm = { · line 738
Quoted 5 lines
drivers/i2c/busses/i2c-exynos5.c +5
-0+i2c_lock_adapter (adap); +clk_enable (i2c->clk); +exynos5_i2c_recovery (i2c); +clk_disable (i2c->clk); +i2c_unlock_adapter (adap);Why do you need to lock? Aren't you protected by the call to
master_xferwhich then detected a problem?
Quoted 5 lines
If the problem is detected in
master_xferdriver uses internal functionexynos5_i2c_recovery,
but functionexynos5_i2c_recover_busis called byi2c_recover_bus, and the latter can be called from any context,
this is why I have added locking.
But the wrong one? The adapter lock is for serializing access to the adapter using the I2C API. If you need to protect register access within your driver, then you need the lock within struct exynos5_i2c.
PATCH 3/3 i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
In reply to Andrzej HajdaHSI2C_MASTER_ST_LOSE state is not documented properly, extensive tests show that hardware is usually able to recover from this state without interrupting the transfer. On the other side enforcing transfer repetition in such case does not help in many situations, especially on busy systems and causes -EAGAIN and -ETIMEOUT errors. Moreover documentation says that such state can be caused by slave clock stretching, and should not be treated as an error.
--- drivers/i2c/busses/i2c-exynos5.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/i2c/busses/i2c-exynos5.c +0 -6
@@ -445,12 +445,6 @@ static irqreturn_t exynos5_i2c_irq(int irqno, void *dev_id) i2c->state = -ETIMEDOUT ; goto stop; } - - trans_status =readl (i2c->regs +HSI2C_TRANS_STATUS ); -if ((trans_status &HSI2C_MASTER_ST_MASK ) ==HSI2C_MASTER_ST_LOSE ) { - i2c->state = -EAGAIN ; - goto stop; - } }else if (int_status &HSI2C_INT_I2C ) { trans_status =readl (i2c->regs +HSI2C_TRANS_STATUS );if (trans_status &HSI2C_NO_DEV_ACK ) {
Signature · 1 line
2.15.0
Re: [3/3] i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
Quoted 9 lines · Andrzej Hajda
HSI2C_MASTER_ST_LOSEstate is not documented properly, extensive tests show that hardware is usually able to recover from this state without interrupting the transfer. On the other side enforcing transfer repetition in such case does not help in many situations, especially on busy systems and causes-EAGAINand-ETIMEOUTerrors. Moreover documentation says that such state can be caused by slave clock stretching, and should not be treated as an error.Signed-off-by Andrzej Hajda <[email protected]>
Can this be applied independently of my comments to patch 2?
Re: [3/3] i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
Quoted 9 lines · Wolfram Sang
Quoted 8 lines · Andrzej Hajda
HSI2C_MASTER_ST_LOSEstate is not documented properly, extensive tests show that hardware is usually able to recover from this state without interrupting the transfer. On the other side enforcing transfer repetition in such case does not help in many situations, especially on busy systems and causes-EAGAINand-ETIMEOUTerrors. Moreover documentation says that such state can be caused by slave clock stretching, and should not be treated as an error.
Quoted 3 lines
Quoted 1 line
Signed-off-by Andrzej Hajda <[email protected]>Can this be applied independently of my comments to patch 2?
Yes, please apply it alone. I will continue work on patch 2.
--
Regards
Andrzej
Re: [3/3] i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
Quoted 10 lines · Andrzej Hajda
Quoted 9 lines · Wolfram Sang
Quoted 8 lines · Andrzej Hajda
HSI2C_MASTER_ST_LOSEstate is not documented properly, extensive tests show that hardware is usually able to recover from this state without interrupting the transfer. On the other side enforcing transfer repetition in such case does not help in many situations, especially on busy systems and causes-EAGAINand-ETIMEOUTerrors. Moreover documentation says that such state can be caused by slave clock stretching, and should not be treated as an error.
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Andrzej Hajda <[email protected]>Can this be applied independently of my comments to patch 2?
Yes, please apply it alone. I will continue work on patch 2.
I just thought it might be nice to have a comment where you removed the code summarizing your findings. So we will remember about this in the future. Makes sense?
Re: [3/3] i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
Quoted 11 lines · Wolfram Sang
Quoted 10 lines · Andrzej Hajda
Quoted 9 lines · Wolfram Sang
Quoted 8 lines · Andrzej Hajda
HSI2C_MASTER_ST_LOSEstate is not documented properly, extensive tests show that hardware is usually able to recover from this state without interrupting the transfer. On the other side enforcing transfer repetition in such case does not help in many situations, especially on busy systems and causes-EAGAINand-ETIMEOUTerrors. Moreover documentation says that such state can be caused by slave clock stretching, and should not be treated as an error.
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Andrzej Hajda <[email protected]>Can this be applied independently of my comments to patch 2?
Yes, please apply it alone. I will continue work on patch 2.
I just thought it might be nice to have a comment where you removed the code summarizing your findings. So we will remember about this in the future. Makes sense?
Forgive me delayed response - holiday.
The code removed was something extra, so I am not sure if it is necessary to add comment to the code, git log should be enough.
Anyway I will post patches dealing with HSI2C_MASTER_ST_LOSE on transaction start very soon, so I can add relevant comment there.
Regards
Andrzej
Re: [3/3] i2c: exynos5: do not check TRANS_STATUS in case of Exynos7 variant
Hi Andrzej,
Quoted 1 line
Forgive me delayed response - holiday.
No worries!
Quoted 2 lines
The code removed was something extra, so I am not sure if it is necessary to add comment to the code, git log should be enough.
If somebody later discovers this "new bit" and implements support for it, I am not sure this person will check git log to see if there has ever been support added and later removed. Also, it helps me reviewing when gory details are explicitly mentioned in the code.
Quoted 2 lines
Anyway I will post patches dealing with
HSI2C_MASTER_ST_LOSEon transaction start very soon, so I can add relevant comment there.
Please do.
Kind regards,
Wolfram
Hi Andrzej,
Quoted 10 lines
This patchset adds bus recovery functionality to Exynos HSI2C, it is used in case of transmission timeouts.
Internal tests shows that it significantly improves I2C transmissions.Andi, could you take a look at it/test, feedback welcome.
Later, I will post also patches to MHL chip which uses this functionality. MHL chip has known bug of being in incorrect state after hard reset, I2C bus recovery cures it.
Quoted 8 lines
Regards
AndrzejAndrzej Hajda (3):
i2c: exynos5: change internal transmission timeout to 100ms
i2c: exynos5: implement bus recovery functionality
i2c: exynos5: do not checkTRANS_STATUSin case of Exynos7 variant
Thanks for the patches, they look good and I tested them.
You can add for all three
Thanks,
Andi