]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/algos/i2c-algo-pcf.c
Merge branch 'v28-range-hrtimers-for-linus-v2' of git://git.kernel.org/pub/scm/linux...
[linux-2.6-omap-h63xx.git] / drivers / i2c / algos / i2c-algo-pcf.c
index 8907b0191677e73b7ef6358fe9d8c937e8e49326..3e01992230b8bb3214ff424a3923b72da1606e10 100644 (file)
@@ -78,6 +78,36 @@ static void i2c_stop(struct i2c_algo_pcf_data *adap)
        set_pcf(adap, 1, I2C_PCF_STOP);
 }
 
+static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
+{
+       DEB2(printk(KERN_INFO
+               "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
+                *status));
+
+       /* Cleanup from LAB -- reset and enable ESO.
+        * This resets the PCF8584; since we've lost the bus, no
+        * further attempts should be made by callers to clean up
+        * (no i2c_stop() etc.)
+        */
+       set_pcf(adap, 1, I2C_PCF_PIN);
+       set_pcf(adap, 1, I2C_PCF_ESO);
+
+       /* We pause for a time period sufficient for any running
+        * I2C transaction to complete -- the arbitration logic won't
+        * work properly until the next START is seen.
+        * It is assumed the bus driver or client has set a proper value.
+        *
+        * REVISIT: should probably use msleep instead of mdelay if we
+        * know we can sleep.
+        */
+       if (adap->lab_mdelay)
+               mdelay(adap->lab_mdelay);
+
+       DEB2(printk(KERN_INFO
+               "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
+               get_pcf(adap, 1)));
+}
+
 static int wait_for_bb(struct i2c_algo_pcf_data *adap) {
 
        int timeout = DEF_TIMEOUT;
@@ -105,27 +135,11 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) {
        *status = get_pcf(adap, 1);
 #ifndef STUB_I2C
        while (timeout-- && (*status & I2C_PCF_PIN)) {
-               adap->waitforpin();
+               adap->waitforpin(adap->data);
                *status = get_pcf(adap, 1);
        }
        if (*status & I2C_PCF_LAB) {
-               DEB2(printk(KERN_INFO 
-                       "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
-                        *status));
-               /* Cleanup from LAB-- reset and enable ESO.
-                * This resets the PCF8584; since we've lost the bus, no
-                * further attempts should be made by callers to clean up 
-                * (no i2c_stop() etc.)
-                */
-               set_pcf(adap, 1, I2C_PCF_PIN);
-               set_pcf(adap, 1, I2C_PCF_ESO);
-               /* TODO: we should pause for a time period sufficient for any
-                * running I2C transaction to complete-- the arbitration
-                * logic won't work properly until the next START is seen.
-                */
-               DEB2(printk(KERN_INFO 
-                       "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n", 
-                       get_pcf(adap,1)));
+               handle_lab(adap, status);
                return(-EINTR);
        }
 #endif
@@ -194,7 +208,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
                return -ENXIO;
        }
        
-       printk(KERN_DEBUG "i2c-algo-pcf.o: deteted and initialized PCF8584.\n");
+       printk(KERN_DEBUG "i2c-algo-pcf.o: detected and initialized PCF8584.\n");
 
        return 0;
 }
@@ -317,13 +331,16 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
        int i;
        int ret=0, timeout, status;
     
+       if (adap->xfer_begin)
+               adap->xfer_begin(adap->data);
 
        /* Check for bus busy */
        timeout = wait_for_bb(adap);
        if (timeout) {
                DEB2(printk(KERN_ERR "i2c-algo-pcf.o: "
                            "Timeout waiting for BB in pcf_xfer\n");)
-               return -EIO;
+               i = -EIO;
+               goto out;
        }
        
        for (i = 0;ret >= 0 && i < num; i++) {
@@ -345,12 +362,14 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
                if (timeout) {
                        if (timeout == -EINTR) {
                                /* arbitration lost */
-                               return (-EINTR);
+                               i = -EINTR;
+                               goto out;
                        }
                        i2c_stop(adap);
                        DEB2(printk(KERN_ERR "i2c-algo-pcf.o: Timeout waiting "
                                    "for PIN(1) in pcf_xfer\n");)
-                       return (-EREMOTEIO);
+                       i = -EREMOTEIO;
+                       goto out;
                }
     
 #ifndef STUB_I2C
@@ -358,7 +377,8 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
                if (status & I2C_PCF_LRB) {
                        i2c_stop(adap);
                        DEB2(printk(KERN_ERR "i2c-algo-pcf.o: No LRB(1) in pcf_xfer\n");)
-                       return (-EREMOTEIO);
+                       i = -EREMOTEIO;
+                       goto out;
                }
 #endif
     
@@ -390,6 +410,9 @@ static int pcf_xfer(struct i2c_adapter *i2c_adap,
                }
        }
 
+out:
+       if (adap->xfer_end)
+               adap->xfer_end(adap->data);
        return (i);
 }