All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Glauber <jglauber@cavium.com>
To: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org,
	Jan Glauber <jglauber@cavium.com>
Subject: [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction
Date: Wed, 21 Sep 2016 08:51:05 +0200	[thread overview]
Message-ID: <21b1db0af4c62a53dc2fcec1e0b1f7b412e6f1be.1474439371.git.jglauber@cavium.com> (raw)
In-Reply-To: <cover.1474439371.git.jglauber@cavium.com>
In-Reply-To: <cover.1474439371.git.jglauber@cavium.com>

Add an additional status check before starting a transaction and,
if required, trigger the recovery if the check fails.

Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 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

  parent reply	other threads:[~2016-09-21  6:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-21  6:51 [PATCH 0/5] i2c: octeon,thunderx: Recovery fixes and improvements Jan Glauber
2016-09-21  6:51 ` [PATCH 1/5] i2c: octeon,thunderx: Fix set SCL recovery function Jan Glauber
2016-09-21 21:00   ` Wolfram Sang
2016-09-21  6:51 ` [PATCH 2/5] i2c: octeon,thunderx: Avoid sending STOP during recovery Jan Glauber
2016-09-21 21:00   ` Wolfram Sang
2016-09-21  6:51 ` [PATCH 3/5] i2c: octeon,thunderx: Fix high-level controller status check Jan Glauber
2016-09-21 21:01   ` Wolfram Sang
2016-09-21  6:51 ` Jan Glauber [this message]
2016-09-21 20:55   ` [PATCH 4/5] i2c: octeon,thunderx: Check bus state before starting a transaction Wolfram Sang
2016-09-22 16:08     ` Jan Glauber
2016-09-22 16:08       ` Jan Glauber
2016-09-21  6:51 ` [PATCH 5/5] i2c: octeon,thunderx: Limit register access retries Jan Glauber
2016-09-21 21:03   ` Wolfram Sang
2016-09-22 16:40     ` Jan Glauber
2016-09-22 16:40       ` Jan Glauber

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21b1db0af4c62a53dc2fcec1e0b1f7b412e6f1be.1474439371.git.jglauber@cavium.com \
    --to=jglauber@cavium.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.