[i2c] [patch 2.6.24-rc1-git] i2c-algo-bit, don't yield()

David Brownell david-b at pacbell.net
Fri Nov 16 19:29:25 CET 2007


On Thursday 15 November 2007, Jean Delvare wrote:
> > Remove the "retry address stage" mechanism from i2c-algo-bit.  That
> > mechanism is not something that upper level code can rely on; hardly
> > any I2C adapter drivers implement it, much less do it correctly.
> 
> Adapters which do not implement it, or do not implement it correctly,
> do _not_ use i2c-algo-bit, so that comment is hardly relevant for a
> patch that only touches i2c-algo-bit. It would be more suitable for the
> future patch that will remove the structure field.

The reason the comment is there is because it shows part of the
Big Picture motivating patches removing this mechanism.


> Just kill try_address and call i2c_outb() directly?

Not at this time.  This is the natural place to put that
information about how I2C and SMBus have different rules,
which arguably merits a programming abstraction in its own
right...


> The rest looks good.

So, you can update that typo directly.  :)


> i2c-algo-pcf needs a similar update, can you please submit a patch?

Appended.

- Dave

=======
Remove i2c_adapter->retries support from i2c-algo-pcf ... this compiles,
but is untested.  The paths for ten bit addressing look especially broken;
they were also the only ones which would actually use those values.

Signed-off-by: David Brownell <dbrownell at users.sourceforge.net>
---
 drivers/i2c/algos/i2c-algo-pcf.c |   47 +++++++++++++++++----------------------
 1 file changed, 21 insertions(+), 26 deletions(-)

--- g26.orig/drivers/i2c/algos/i2c-algo-pcf.c	2007-11-16 09:59:49.000000000 -0800
+++ g26/drivers/i2c/algos/i2c-algo-pcf.c	2007-11-16 10:22:31.000000000 -0800
@@ -204,31 +204,27 @@ static int pcf_init_8584 (struct i2c_alg
  */
 
 static inline int try_address(struct i2c_algo_pcf_data *adap,
-		       unsigned char addr, int retries)
+		       unsigned char addr)
 {
-	int i, status, ret = -1;
+	int status;
 	int wfp;
-	for (i=0;i<retries;i++) {
-		i2c_outb(adap, addr);
-		i2c_start(adap);
-		status = get_pcf(adap, 1);
-		if ((wfp = wait_for_pin(adap, &status)) >= 0) {
-			if ((status & I2C_PCF_LRB) == 0) { 
-				i2c_stop(adap);
-				break;	/* success! */
-			}
-		}
-		if (wfp == -EINTR) {
-			/* arbitration lost */
-			udelay(adap->udelay);
-			return -EINTR;
-		}
+
+	i2c_outb(adap, addr);
+	i2c_start(adap);
+	status = get_pcf(adap, 1);
+	if ((wfp = wait_for_pin(adap, &status)) >= 0) {
+		if ((status & I2C_PCF_LRB) == 0)
+			i2c_stop(adap);
+	} else if (wfp == -EINTR) {
+		/* arbitration lost */
+		udelay(adap->udelay);
+		return -EINTR;
+	} else {
 		i2c_stop(adap);
 		udelay(adap->udelay);
 	}
-	DEB2(if (i) printk(KERN_DEBUG "i2c-algo-pcf.o: needed %d retries for %d\n",i,
-	                   addr));
-	return ret;
+
+	return -1;
 }
 
 
@@ -322,7 +318,7 @@ static int pcf_readbytes(struct i2c_adap
 
 
 static inline int pcf_doAddress(struct i2c_algo_pcf_data *adap,
-                                struct i2c_msg *msg, int retries) 
+                                struct i2c_msg *msg)
 {
 	unsigned short flags = msg->flags;
 	unsigned char addr;
@@ -332,7 +328,7 @@ static inline int pcf_doAddress(struct i
 		addr = 0xf0 | (( msg->addr >> 7) & 0x03);
 		DEB2(printk(KERN_DEBUG "addr0: %d\n",addr));
 		/* try extended address code...*/
-		ret = try_address(adap, addr, retries);
+		ret = try_address(adap, addr);
 		if (ret!=1) {
 			printk(KERN_ERR "died at extended address code.\n");
 			return -EREMOTEIO;
@@ -348,7 +344,7 @@ static inline int pcf_doAddress(struct i
 			i2c_repstart(adap);
 			/* okay, now switch into reading mode */
 			addr |= 0x01;
-			ret = try_address(adap, addr, retries);
+			ret = try_address(adap, addr);
 			if (ret!=1) {
 				printk(KERN_ERR "died at extended address code.\n");
 				return -EREMOTEIO;
@@ -390,7 +386,7 @@ static int pcf_xfer(struct i2c_adapter *
 		     pmsg->flags & I2C_M_RD ? "read" : "write",
                      pmsg->len, pmsg->addr, i + 1, num);)
     
-		ret = pcf_doAddress(adap, pmsg, i2c_adap->retries);
+		ret = pcf_doAddress(adap, pmsg);
 
 		/* Send START */
 		if (i == 0) {
@@ -476,8 +472,7 @@ int i2c_pcf_add_bus(struct i2c_adapter *
 	/* register new adapter to i2c module... */
 	adap->algo = &pcf_algo;
 
-	adap->timeout = 100;		/* default values, should	*/
-	adap->retries = 3;		/* be replaced by defines	*/
+	adap->timeout = 100;		/* default value */
 
 	if ((rval = pcf_init_8584(pcf_adap)))
 		return rval;



More information about the i2c mailing list