]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/busses/i2c-mpc.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/roland...
[linux-2.6-omap-h63xx.git] / drivers / i2c / busses / i2c-mpc.c
index 851c3ed513d015e50b5c75c362a014dfa09c1c1d..18beb0ad7bf3ad1b9fc703c3c75952fd6017e848 100644 (file)
@@ -105,6 +105,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
                        schedule();
                        if (time_after(jiffies, orig_jiffies + timeout)) {
                                pr_debug("I2C: timeout\n");
+                               writeccr(i2c, 0);
                                result = -EIO;
                                break;
                        }
@@ -116,10 +117,12 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
                result = wait_event_interruptible_timeout(i2c->queue,
                        (i2c->interrupt & CSR_MIF), timeout * HZ);
 
-               if (unlikely(result < 0))
+               if (unlikely(result < 0)) {
                        pr_debug("I2C: wait interrupted\n");
-               else if (unlikely(!(i2c->interrupt & CSR_MIF))) {
+                       writeccr(i2c, 0);
+               } else if (unlikely(!(i2c->interrupt & CSR_MIF))) {
                        pr_debug("I2C: wait timeout\n");
+                       writeccr(i2c, 0);
                        result = -ETIMEDOUT;
                }
 
@@ -172,13 +175,12 @@ static void mpc_i2c_start(struct mpc_i2c *i2c)
 static void mpc_i2c_stop(struct mpc_i2c *i2c)
 {
        writeccr(i2c, CCR_MEN);
-       writeccr(i2c, 0);
 }
 
 static int mpc_write(struct mpc_i2c *i2c, int target,
                     const u8 * data, int length, int restart)
 {
-       int i;
+       int i, result;
        unsigned timeout = i2c->adap.timeout;
        u32 flags = restart ? CCR_RSTA : 0;
 
@@ -190,15 +192,17 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
        /* Write target byte */
        writeb((target << 1), i2c->base + MPC_I2C_DR);
 
-       if (i2c_wait(i2c, timeout, 1) < 0)
-               return -1;
+       result = i2c_wait(i2c, timeout, 1);
+       if (result < 0)
+               return result;
 
        for (i = 0; i < length; i++) {
                /* Write data byte */
                writeb(data[i], i2c->base + MPC_I2C_DR);
 
-               if (i2c_wait(i2c, timeout, 1) < 0)
-                       return -1;
+               result = i2c_wait(i2c, timeout, 1);
+               if (result < 0)
+                       return result;
        }
 
        return 0;
@@ -208,7 +212,7 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
                    u8 * data, int length, int restart)
 {
        unsigned timeout = i2c->adap.timeout;
-       int i;
+       int i, result;
        u32 flags = restart ? CCR_RSTA : 0;
 
        /* Start with MEN */
@@ -219,8 +223,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
        /* Write target address byte - this time with the read flag set */
        writeb((target << 1) | 1, i2c->base + MPC_I2C_DR);
 
-       if (i2c_wait(i2c, timeout, 1) < 0)
-               return -1;
+       result = i2c_wait(i2c, timeout, 1);
+       if (result < 0)
+               return result;
 
        if (length) {
                if (length == 1)
@@ -232,8 +237,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
        }
 
        for (i = 0; i < length; i++) {
-               if (i2c_wait(i2c, timeout, 0) < 0)
-                       return -1;
+               result = i2c_wait(i2c, timeout, 0);
+               if (result < 0)
+                       return result;
 
                /* Generate txack on next to last byte */
                if (i == length - 2)
@@ -261,6 +267,7 @@ static int mpc_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
        while (readb(i2c->base + MPC_I2C_SR) & CSR_MBB) {
                if (signal_pending(current)) {
                        pr_debug("I2C: Interrupted\n");
+                       writeccr(i2c, 0);
                        return -EINTR;
                }
                if (time_after(jiffies, orig_jiffies + HZ)) {
@@ -306,7 +313,6 @@ static struct i2c_adapter mpc_ops = {
        .algo = &mpc_algo,
        .class = I2C_CLASS_HWMON,
        .timeout = 1,
-       .retries = 1
 };
 
 static int fsl_i2c_probe(struct platform_device *pdev)
@@ -318,9 +324,9 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 
        pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
 
-       if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) {
+       i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
+       if (!i2c)
                return -ENOMEM;
-       }
 
        i2c->irq = platform_get_irq(pdev, 0);
        if (i2c->irq < 0) {
@@ -362,7 +368,7 @@ static int fsl_i2c_probe(struct platform_device *pdev)
 
       fail_add:
        if (i2c->irq != 0)
-               free_irq(i2c->irq, NULL);
+               free_irq(i2c->irq, i2c);
       fail_irq:
        iounmap(i2c->base);
       fail_map:
@@ -386,6 +392,9 @@ static int fsl_i2c_remove(struct platform_device *pdev)
        return 0;
 };
 
+/* work with hotplug and coldplug */
+MODULE_ALIAS("platform:fsl-i2c");
+
 /* Structure for a device driver */
 static struct platform_driver fsl_i2c_driver = {
        .probe = fsl_i2c_probe,