[PATCH 1/3] i2c: algo-bit add missing acknak

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Sat Nov 3 16:53:07 EDT 2012


This is need for sequential read/write.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/i2c/algos/i2c-algo-bit.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 37af27c..dc43eb8 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -390,6 +390,22 @@ static int sendbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 	return wrcount;
 }
 
+static int acknak(struct i2c_adapter *i2c_adap, int is_ack)
+{
+	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
+
+	/* assert: sda is high */
+	if (is_ack)		/* send ack */
+		setsda(adap, 0);
+	udelay((adap->udelay + 1) / 2);
+	if (sclhi(adap) < 0) {	/* timeout */
+		dev_err(&i2c_adap->dev, "readbytes: ack/nak timeout\n");
+		return -ETIMEDOUT;
+	}
+	scllo(adap);
+	return 0;
+}
+
 static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 {
 	int inval;
@@ -414,6 +430,10 @@ static int readbytes(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
 			(flags & I2C_M_NO_RD_ACK)
 				? "(no ack/nak)"
 				: (count ? "A" : "NA"));
+
+		inval = acknak(i2c_adap, count);
+		if (inval < 0)
+			return inval;
 	}
 	return rdcount;
 }
-- 
1.7.10.4




More information about the barebox mailing list