Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1489901

[PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction

From Jan Glauber <jglauber@cavium.com>
Newsgroups linux.kernel
Subject [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction
Date 2016-09-23 11:50 +0200
Message-ID <skvhf-1XI-5@gated-at.bofh.it> (permalink)
References <skvhf-1XI-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Add an additional status check before starting a transaction. If the
check fails wait for some time to tolerate multi-master mode. After the
timeout expires trigger the recovery.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 drivers/i2c/busses/i2c-octeon-core.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/i2c/busses/i2c-octeon-core.c b/drivers/i2c/busses/i2c-octeon-core.c
index 5e63b17..f526511 100644
--- a/drivers/i2c/busses/i2c-octeon-core.c
+++ b/drivers/i2c/busses/i2c-octeon-core.c
@@ -630,6 +630,31 @@ 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)
+{
+	u64 end = get_jiffies_64() + i2c->adap.timeout;
+	int stat, lines;
+
+	while (time_before64(get_jiffies_64(), end)) {
+		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;
+
+		if (stat == STAT_LOST_ARB_38 || stat == STAT_LOST_ARB_68 ||
+		    stat == STAT_LOST_ARB_78 || stat == STAT_LOST_ARB_B0)
+			break;
+
+		usleep_range(I2C_OCTEON_EVENT_WAIT / 2, I2C_OCTEON_EVENT_WAIT);
+	}
+
+	/* 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 +668,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

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/2] i2c: octeon: thunderx: Recovery fixes and improvements Jan Glauber <jglauber@cavium.com> - 2016-09-23 11:50 +0200
  [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before starting a transaction Jan Glauber <jglauber@cavium.com> - 2016-09-23 11:50 +0200
    Re: [PATCH v2 1/2] i2c: octeon: thunderx: Check bus state before  starting a transaction Wolfram Sang <wsa@the-dreams.de> - 2016-09-24 11:30 +0200
  [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access retries Jan Glauber <jglauber@cavium.com> - 2016-09-23 11:50 +0200
    Re: [PATCH v2 2/2] i2c: octeon: thunderx: Limit register access  retries Wolfram Sang <wsa@the-dreams.de> - 2016-09-24 11:30 +0200

csiph-web