diff options
-rw-r--r-- | drivers/i2c/busses/i2c-s3c2410.c | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index b723b0b..61c9365 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -201,18 +201,29 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) { - unsigned long iicstat = readl(i2c->regs + S3C2410_IICSTAT); + unsigned long iicstat; + unsigned long iiccon; dev_dbg(i2c->dev, "STOP\n"); /* stop the transfer */ + + /* Disable irq */ + s3c24xx_i2c_disable_irq(i2c); + + /* STOP signal generation : MTx(0xD0) */ + iicstat = readl(i2c->regs + S3C2410_IICSTAT); iicstat &= ~S3C2410_IICSTAT_START; writel(iicstat, i2c->regs + S3C2410_IICSTAT); - i2c->state = STATE_STOP; + /* Clear pending bit */ + iiccon = readl(i2c->regs + S3C2410_IICCON); + iiccon &= ~S3C2410_IICCON_IRQPEND; + writel(iiccon, i2c->regs + S3C2410_IICCON); s3c24xx_i2c_master_complete(i2c, ret); - s3c24xx_i2c_disable_irq(i2c); + + i2c->state = STATE_STOP; } /* helper functions to determine the current state in the set of @@ -484,7 +495,8 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) { - unsigned long timeout; + unsigned long iicstat, timeout; + int spins = 20; int ret; if (i2c->suspended) @@ -523,7 +535,38 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, /* ensure the stop has been through the bus */ - udelay(10); + dev_dbg(i2c->dev, "waiting for bus idle\n"); + + /* first, try busy waiting briefly */ + do { + cpu_relax(); + iicstat = readl(i2c->regs + S3C2410_IICSTAT); + } while ((iicstat & S3C2410_IICSTAT_START) && --spins); + + /* if that timed out sleep */ + if (!spins) { + msleep(1); + iicstat = readl(i2c->regs + S3C2410_IICSTAT); + } + + /* if still not finished, clean it up */ + spin_lock_irq(&i2c->lock); + + if (iicstat & S3C2410_IICSTAT_BUSBUSY) { + dev_dbg(i2c->dev, "timeout waiting for bus idle\n"); + + if (i2c->state != STATE_STOP) { + dev_dbg(i2c->dev, + "timeout : i2c interrupt hasn't occurred\n"); + s3c24xx_i2c_stop(i2c, 0); + } + + /* Disable Serial Out : To forcely terminate the connection */ + iicstat = readl(i2c->regs + S3C2410_IICSTAT); + iicstat &= ~S3C2410_IICSTAT_TXRXEN; + writel(iicstat, i2c->regs + S3C2410_IICSTAT); + } + spin_unlock_irq(&i2c->lock); out: return ret; |