Re: [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-22 Thread Jan Glauber
On Wed, Sep 21, 2016 at 10:55:41PM +0200, Wolfram Sang wrote:
> On Wed, Sep 21, 2016 at 08:51:05AM +0200, Jan Glauber wrote:
> > Add an additional status check before starting a transaction and,
> > if required, trigger the recovery if the check fails.
> > 
> > Signed-off-by: Jan Glauber 
> 
> Won't this break multi-master setups?
> 

I'm afraid yes. I don't have a multi-master setup, but agree that we
should not break it.

How about re-checking if the bus is idle until a timeout
(i2c->adap.timeout ?) happens and only then recover?

Additionaly we can check for arbitration loss as Dmitry did in his
original patch.

--Jan


Re: [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-22 Thread Jan Glauber
On Wed, Sep 21, 2016 at 10:55:41PM +0200, Wolfram Sang wrote:
> On Wed, Sep 21, 2016 at 08:51:05AM +0200, Jan Glauber wrote:
> > Add an additional status check before starting a transaction and,
> > if required, trigger the recovery if the check fails.
> > 
> > Signed-off-by: Jan Glauber 
> 
> Won't this break multi-master setups?
> 

I'm afraid yes. I don't have a multi-master setup, but agree that we
should not break it.

How about re-checking if the bus is idle until a timeout
(i2c->adap.timeout ?) happens and only then recover?

Additionaly we can check for arbitration loss as Dmitry did in his
original patch.

--Jan


Re: [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-21 Thread Wolfram Sang
On Wed, Sep 21, 2016 at 08:51:05AM +0200, Jan Glauber wrote:
> Add an additional status check before starting a transaction and,
> if required, trigger the recovery if the check fails.
> 
> Signed-off-by: Jan Glauber 

Won't this break multi-master setups?



signature.asc
Description: PGP signature


Re: [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-21 Thread Wolfram Sang
On Wed, Sep 21, 2016 at 08:51:05AM +0200, Jan Glauber wrote:
> Add an additional status check before starting a transaction and,
> if required, trigger the recovery if the check fails.
> 
> Signed-off-by: Jan Glauber 

Won't this break multi-master setups?



signature.asc
Description: PGP signature


[PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-21 Thread Jan Glauber
Add an additional status check before starting a transaction and,
if required, trigger the recovery if the check fails.

Signed-off-by: Jan Glauber 
---
 drivers/i2c/busses/i2c-octeon-core.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c 
b/drivers/i2c/busses/i2c-octeon-core.c
index 5e63b17..b21aa3e 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -630,6 +630,22 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i2c 
*i2c, struct i2c_msg *msg
return ret;
 }
 
+static int octeon_i2c_check_bus(struct octeon_i2c *i2c)
+{
+   int stat, lines;
+
+   stat = octeon_i2c_stat_read(i2c);
+
+   /* get I2C line state */
+   lines = octeon_i2c_read_int(i2c) & (TWSI_INT_SCL | TWSI_INT_SDA);
+
+   if (stat == STAT_IDLE && lines == (TWSI_INT_SCL | TWSI_INT_SDA))
+   return 0;
+
+   /* bus check failed, try to recover */
+   return octeon_i2c_recovery(i2c);
+}
+
 /**
  * octeon_i2c_xfer - The driver's master_xfer function
  * @adap: Pointer to the i2c_adapter structure
@@ -643,6 +659,10 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct 
i2c_msg *msgs, int num)
struct octeon_i2c *i2c = i2c_get_adapdata(adap);
int i, ret = 0;
 
+   ret = octeon_i2c_check_bus(i2c);
+   if (ret)
+   goto out;
+
if (num == 1) {
if (msgs[0].len > 0 && msgs[0].len <= 8) {
if (msgs[0].flags & I2C_M_RD)
-- 
1.9.1



[PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction

2016-09-21 Thread Jan Glauber
Add an additional status check before starting a transaction and,
if required, trigger the recovery if the check fails.

Signed-off-by: Jan Glauber 
---
 drivers/i2c/busses/i2c-octeon-core.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c 
b/drivers/i2c/busses/i2c-octeon-core.c
index 5e63b17..b21aa3e 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -630,6 +630,22 @@ static int octeon_i2c_hlc_comp_write(struct octeon_i2c 
*i2c, struct i2c_msg *msg
return ret;
 }
 
+static int octeon_i2c_check_bus(struct octeon_i2c *i2c)
+{
+   int stat, lines;
+
+   stat = octeon_i2c_stat_read(i2c);
+
+   /* get I2C line state */
+   lines = octeon_i2c_read_int(i2c) & (TWSI_INT_SCL | TWSI_INT_SDA);
+
+   if (stat == STAT_IDLE && lines == (TWSI_INT_SCL | TWSI_INT_SDA))
+   return 0;
+
+   /* bus check failed, try to recover */
+   return octeon_i2c_recovery(i2c);
+}
+
 /**
  * octeon_i2c_xfer - The driver's master_xfer function
  * @adap: Pointer to the i2c_adapter structure
@@ -643,6 +659,10 @@ int octeon_i2c_xfer(struct i2c_adapter *adap, struct 
i2c_msg *msgs, int num)
struct octeon_i2c *i2c = i2c_get_adapdata(adap);
int i, ret = 0;
 
+   ret = octeon_i2c_check_bus(i2c);
+   if (ret)
+   goto out;
+
if (num == 1) {
if (msgs[0].len > 0 && msgs[0].len <= 8) {
if (msgs[0].flags & I2C_M_RD)
-- 
1.9.1