I2C: S3C2410: Check ACK on byte transmission
[pandora-kernel.git] / drivers / i2c / busses / i2c-s3c2410.c
index c44ada5..7ad22c5 100644 (file)
@@ -276,12 +276,12 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
        switch (i2c->state) {
 
        case STATE_IDLE:
-               dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __FUNCTION__);
+               dev_err(i2c->dev, "%s: called in STATE_IDLE\n", __func__);
                goto out;
                break;
 
        case STATE_STOP:
-               dev_err(i2c->dev, "%s: called in STATE_STOP\n", __FUNCTION__);
+               dev_err(i2c->dev, "%s: called in STATE_STOP\n", __func__);
                s3c24xx_i2c_disable_irq(i2c);           
                goto out_ack;
 
@@ -323,7 +323,17 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                 * end of the message, and if so, work out what to do
                 */
 
+               if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
+                       if (iicstat & S3C2410_IICSTAT_LASTBIT) {
+                               dev_dbg(i2c->dev, "WRITE: No Ack\n");
+
+                               s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
+                               goto out_ack;
+                       }
+               }
+
        retry_write:
+
                if (!is_msgend(i2c)) {
                        byte = i2c->msg->buf[i2c->msg_ptr++];
                        writeb(byte, i2c->regs + S3C2410_IICDS);
@@ -377,17 +387,6 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
                 * going to do any more read/write
                 */
 
-               if (!(i2c->msg->flags & I2C_M_IGNORE_NAK) &&
-                   !(is_msglast(i2c) && is_lastmsg(i2c))) {
-
-                       if (iicstat & S3C2410_IICSTAT_LASTBIT) {
-                               dev_dbg(i2c->dev, "READ: No Ack\n");
-
-                               s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
-                               goto out_ack;
-                       }
-               }
-
                byte = readb(i2c->regs + S3C2410_IICDS);
                i2c->msg->buf[i2c->msg_ptr++] = byte;
 
@@ -948,3 +947,4 @@ module_exit(i2c_adap_s3c_exit);
 MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:s3c2410-i2c");