RE: Add restart support to i2c-pnx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kevin,

> Thanks for posting this patch. See comments below..
> I'll be happy to test your changes once the following items
> are clarified.
> 
> > The pathch is against 2.6.28.2, but it should apply to the
> > cureent GIT version as well.
> 
> This patch needs to be re-based against the latest version
> of the driver as it has changes that this patch will revert
> or won't apply to.

I re-based it against latest version of the kernel in GIT and 
also included your comments in the mail.

Is it O.K. now?

Regards,
Matej

P.S.: Changed the email client. I now attached the file as 
well as pasted it in-line.

-------------------------------------------------------------------
Current code in i2c-pnx.c doesn't support sending messages
with restart condition in it, for example:
S - (address | W) - Sr - (address | R) - ... - P

This patch adds this to the current code. It has been
tested on a custom board with LPC3152 CPU (similar to
Embedded Artists EA313x board) with uBlox GPS receiver
connected to I2C bus. It has been running over the night
without errors. 

Signed-off-by: Matej Kupljen <matej.kupljen@xxxxxxxxx>

--- i2c-pnx-orig.c	2011-02-02 21:30:19.000000000 +0100
+++ i2c-pnx.c	2011-02-02 21:49:02.000000000 +0100
@@ -78,7 +78,7 @@
  * Generate a START signal in the desired mode.
  */
 static int i2c_pnx_start(unsigned char slave_addr,
-	struct i2c_pnx_algo_data *alg_data)
+	struct i2c_pnx_algo_data *alg_data, int repeated)
 {
 	dev_dbg(&alg_data->adapter.dev, "%s(): addr 0x%x mode %d\n", __func__,
 		slave_addr, alg_data->mif.mode);
@@ -91,8 +91,8 @@
 		return -EINVAL;
 	}
 
-	/* First, make sure bus is idle */
-	if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) {
+	/* First, make sure bus is idle, if we are not doing repeated start */
+	if ((!repeated) && (wait_timeout(I2C_PNX_TIMEOUT, alg_data))) {
 		/* Somebody else is monopolizing the bus */
 		dev_err(&alg_data->adapter.dev,
 			"%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n",
@@ -441,7 +441,7 @@
 i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 {
 	struct i2c_msg *pmsg;
-	int rc = 0, completed = 0, i;
+	int rc = 0, completed = 0, i, repeated;
 	struct i2c_pnx_algo_data *alg_data = adap->algo_data;
 	u32 stat = ioread32(I2C_REG_STS(alg_data));
 
@@ -457,6 +457,7 @@
 
 		pmsg = &msgs[i];
 		addr = pmsg->addr;
+		repeated = 0;
 
 		if (pmsg->flags & I2C_M_TEN) {
 			dev_err(&alg_data->adapter.dev,
@@ -481,16 +482,23 @@
 		/* initialize the completion var */
 		init_completion(&alg_data->mif.complete);
 
-		/* Enable master interrupt */
-		iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
-				mcntrl_naie | mcntrl_drmie,
-			  I2C_REG_CTL(alg_data));
+		/* 
+		 * If this is not the only message, then we need to
+		 * send repeated start, but only if the flag allows it
+		 */
+		if((i > 0) && !(pmsg->flags & I2C_M_NOSTART))
+			repeated = 1;
 
 		/* Put start-code and slave-address on the bus. */
-		rc = i2c_pnx_start(addr, alg_data);
+		rc = i2c_pnx_start(addr, alg_data, repeated);
 		if (rc < 0)
 			break;
 
+		/* Enable master interrupt */
+		iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
+				mcntrl_naie | mcntrl_drmie,
+			  I2C_REG_CTL(alg_data));
+
 		/* Wait for completion */
 		wait_for_completion(&alg_data->mif.complete);
 
Current code in i2c-pnx.c doesn't support sending messages
with restart condition in it, for example:
S - (address | W) - Sr - (address | R) - ... - P

This patch adds this to the current code. It has been
tested on a custom board with LPC3152 CPU (similar to
Embedded Artists EA313x board) with uBlox GPS receiver
connected to I2C bus. It has been running over the night
without errors. 

Signed-off-by: Matej Kupljen <matej.kupljen@xxxxxxxxx>

--- i2c-pnx-orig.c	2011-02-02 21:30:19.000000000 +0100
+++ i2c-pnx.c	2011-02-02 21:49:02.000000000 +0100
@@ -78,7 +78,7 @@
  * Generate a START signal in the desired mode.
  */
 static int i2c_pnx_start(unsigned char slave_addr,
-	struct i2c_pnx_algo_data *alg_data)
+	struct i2c_pnx_algo_data *alg_data, int repeated)
 {
 	dev_dbg(&alg_data->adapter.dev, "%s(): addr 0x%x mode %d\n", __func__,
 		slave_addr, alg_data->mif.mode);
@@ -91,8 +91,8 @@
 		return -EINVAL;
 	}
 
-	/* First, make sure bus is idle */
-	if (wait_timeout(I2C_PNX_TIMEOUT, alg_data)) {
+	/* First, make sure bus is idle, if we are not doing repeated start */
+	if ((!repeated) && (wait_timeout(I2C_PNX_TIMEOUT, alg_data))) {
 		/* Somebody else is monopolizing the bus */
 		dev_err(&alg_data->adapter.dev,
 			"%s: Bus busy. Slave addr = %02x, cntrl = %x, stat = %x\n",
@@ -441,7 +441,7 @@
 i2c_pnx_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 {
 	struct i2c_msg *pmsg;
-	int rc = 0, completed = 0, i;
+	int rc = 0, completed = 0, i, repeated;
 	struct i2c_pnx_algo_data *alg_data = adap->algo_data;
 	u32 stat = ioread32(I2C_REG_STS(alg_data));
 
@@ -457,6 +457,7 @@
 
 		pmsg = &msgs[i];
 		addr = pmsg->addr;
+		repeated = 0;
 
 		if (pmsg->flags & I2C_M_TEN) {
 			dev_err(&alg_data->adapter.dev,
@@ -481,16 +482,23 @@
 		/* initialize the completion var */
 		init_completion(&alg_data->mif.complete);
 
-		/* Enable master interrupt */
-		iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
-				mcntrl_naie | mcntrl_drmie,
-			  I2C_REG_CTL(alg_data));
+		/* 
+		 * If this is not the only message, then we need to
+		 * send repeated start, but only if the flag allows it
+		 */
+		if((i > 0) && !(pmsg->flags & I2C_M_NOSTART))
+			repeated = 1;
 
 		/* Put start-code and slave-address on the bus. */
-		rc = i2c_pnx_start(addr, alg_data);
+		rc = i2c_pnx_start(addr, alg_data, repeated);
 		if (rc < 0)
 			break;
 
+		/* Enable master interrupt */
+		iowrite32(ioread32(I2C_REG_CTL(alg_data)) | mcntrl_afie |
+				mcntrl_naie | mcntrl_drmie,
+			  I2C_REG_CTL(alg_data));
+
 		/* Wait for completion */
 		wait_for_completion(&alg_data->mif.complete);
 

[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux