linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
To: linux-i2c@vger.kernel.org
Cc: Jean Delvare <jdelvare@suse.de>,
	linux-renesas-soc@vger.kernel.org,
	Wolfram Sang <wsa+renesas@sang-engineering.com>
Subject: [PATCH] i2c: algo-bit: add support for I2C_M_STOP
Date: Sat, 17 Jun 2017 19:12:38 +0200	[thread overview]
Message-ID: <20170617171238.19638-1-wsa+renesas@sang-engineering.com> (raw)

Support for enforced STOPs will allow us to use SCCB compatible devices.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Notes: I don't actually have any SCCB compatible sensor but verified with a
logic analyzer that repeated starts got replaced with a stop + start sequence.
However, we have members in our team who might need this feature soon. I'll
likely wait for their Tested-by unless something unforseen happens.

 drivers/i2c/algos/i2c-algo-bit.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index a8e89df665b904..4758058352959d 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -549,12 +549,17 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
 	bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
 	i2c_start(adap);
 	for (i = 0; i < num; i++) {
+		bool did_stop = false;
+
 		pmsg = &msgs[i];
 		nak_ok = pmsg->flags & I2C_M_IGNORE_NAK;
 		if (!(pmsg->flags & I2C_M_NOSTART)) {
-			if (i) {
-				bit_dbg(3, &i2c_adap->dev, "emitting "
-					"repeated start condition\n");
+			if (did_stop) {
+				bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
+				i2c_start(adap);
+				did_stop = false;
+			} else if (i) {
+				bit_dbg(3, &i2c_adap->dev, "emitting repeated start condition\n");
 				i2c_repstart(adap);
 			}
 			ret = bit_doAddress(i2c_adap, pmsg);
@@ -588,6 +593,12 @@ static int bit_xfer(struct i2c_adapter *i2c_adap,
 				goto bailout;
 			}
 		}
+
+		if (pmsg->flags & I2C_M_STOP && i != num - 1) {
+			bit_dbg(3, &i2c_adap->dev, "emitting enforced stop condition\n");
+			i2c_stop(adap);
+			did_stop = true;
+		}
 	}
 	ret = i;
 
-- 
2.11.0

             reply	other threads:[~2017-06-17 17:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-17 17:12 Wolfram Sang [this message]
2017-06-19  8:30 ` [PATCH] i2c: algo-bit: add support for I2C_M_STOP Jean Delvare
2017-06-20 17:28   ` Wolfram Sang
2017-06-21  7:18     ` Jean Delvare
2017-06-21 14:30       ` Wolfram Sang
2017-06-22  9:06         ` Jean Delvare
2017-06-22 10:15           ` Wolfram Sang

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=20170617171238.19638-1-wsa+renesas@sang-engineering.com \
    --to=wsa+renesas@sang-engineering.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).