Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[linux.git] / drivers / i2c / busses / i2c-s3c2410.c
index 684d21e71e4afc9137f2d035d4b2d408a4696026..ae4491062e411a83a5729a1e267e2430f23f069c 100644 (file)
@@ -601,6 +601,31 @@ static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id)
        return IRQ_HANDLED;
 }
 
+/*
+ * Disable the bus so that we won't get any interrupts from now on, or try
+ * to drive any lines. This is the default state when we don't have
+ * anything to send/receive.
+ *
+ * If there is an event on the bus, or we have a pre-existing event at
+ * kernel boot time, we may not notice the event and the I2C controller
+ * will lock the bus with the I2C clock line low indefinitely.
+ */
+static inline void s3c24xx_i2c_disable_bus(struct s3c24xx_i2c *i2c)
+{
+       unsigned long tmp;
+
+       /* Stop driving the I2C pins */
+       tmp = readl(i2c->regs + S3C2410_IICSTAT);
+       tmp &= ~S3C2410_IICSTAT_TXRXEN;
+       writel(tmp, i2c->regs + S3C2410_IICSTAT);
+
+       /* We don't expect any interrupts now, and don't want send acks */
+       tmp = readl(i2c->regs + S3C2410_IICCON);
+       tmp &= ~(S3C2410_IICCON_IRQEN | S3C2410_IICCON_IRQPEND |
+               S3C2410_IICCON_ACKEN);
+       writel(tmp, i2c->regs + S3C2410_IICCON);
+}
+
 
 /* s3c24xx_i2c_set_master
  *
@@ -735,7 +760,11 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c,
 
        s3c24xx_i2c_wait_idle(i2c);
 
+       s3c24xx_i2c_disable_bus(i2c);
+
  out:
+       i2c->state = STATE_IDLE;
+
        return ret;
 }
 
@@ -1004,7 +1033,6 @@ static void s3c24xx_i2c_dt_gpio_free(struct s3c24xx_i2c *i2c)
 
 static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
 {
-       unsigned long iicon = S3C2410_IICCON_IRQEN | S3C2410_IICCON_ACKEN;
        struct s3c2410_platform_i2c *pdata;
        unsigned int freq;
 
@@ -1018,12 +1046,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
 
        dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
 
-       writel(iicon, i2c->regs + S3C2410_IICCON);
+       writel(0, i2c->regs + S3C2410_IICCON);
+       writel(0, i2c->regs + S3C2410_IICSTAT);
 
        /* we need to work out the divisors for the clock... */
 
        if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
-               writel(0, i2c->regs + S3C2410_IICCON);
                dev_err(i2c->dev, "cannot meet bus frequency required\n");
                return -EINVAL;
        }
@@ -1031,7 +1059,8 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
        /* todo - check that the i2c lines aren't being dragged anywhere */
 
        dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
-       dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon);
+       dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02x\n",
+               readl(i2c->regs + S3C2410_IICCON));
 
        return 0;
 }
@@ -1106,7 +1135,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
        i2c->adap.owner   = THIS_MODULE;
        i2c->adap.algo    = &s3c24xx_i2c_algorithm;
        i2c->adap.retries = 2;
-       i2c->adap.class   = I2C_CLASS_HWMON | I2C_CLASS_SPD;
+       i2c->adap.class   = I2C_CLASS_HWMON | I2C_CLASS_SPD | I2C_CLASS_DEPRECATED;
        i2c->tx_setup     = 50;
 
        init_waitqueue_head(&i2c->wait);