]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/busses/i2c-omap.c
i2c-omap: fix I2C timeouts due to recursive omap_i2c_{un,}idle()
[linux-2.6-omap-h63xx.git] / drivers / i2c / busses / i2c-omap.c
index a8c8831313dc3658e5411509648fb992a25b515d..a9996063483e9c269c8a2e45e8e737ed0f923e33 100644 (file)
 #include <linux/clk.h>
 #include <linux/io.h>
 
-/* Hack to enable zero length transfers and smbus quick until clean fix
-   is available */
-#define OMAP_HACK
-
 /* timeout waiting for the controller to respond */
 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
 
@@ -206,6 +202,8 @@ static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
 
 static void omap_i2c_unidle(struct omap_i2c_dev *dev)
 {
+       WARN_ON(!dev->idle);
+
        if (dev->iclk != NULL)
                clk_enable(dev->iclk);
        clk_enable(dev->fclk);
@@ -218,6 +216,8 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
 {
        u16 iv;
 
+       WARN_ON(dev->idle);
+
        dev->iestate = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
        omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 0);
        if (dev->rev1)
@@ -373,16 +373,12 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
                             struct i2c_msg *msg, int stop)
 {
        struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
-#ifdef OMAP_HACK
-       u8 zero_byte = 0;
-#endif
        int r;
        u16 w;
 
        dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
                msg->addr, msg->len, msg->flags, stop);
 
-#ifndef OMAP_HACK
        if (msg->len == 0)
                return -EINVAL;
 
@@ -392,27 +388,6 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
        dev->buf = msg->buf;
        dev->buf_len = msg->len;
 
-#else
-
-       omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr);
-       /* REVISIT: Remove this hack when we can get I2C chips from board-*.c
-        *          files
-        * Sigh, seems we can't do zero length transactions. Thus, we
-        * can't probe for devices w/o actually sending/receiving at least
-        * a single byte. So we'll set count to 1 for the zero length
-        * transaction case and hope we don't cause grief for some
-        * arbitrary device due to random byte write/read during
-        * probes.
-        */
-       if (msg->len == 0) {
-               dev->buf = &zero_byte;
-               dev->buf_len = 1;
-       } else {
-               dev->buf = msg->buf;
-               dev->buf_len = msg->len;
-       }
-#endif
-
        omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len);
 
        /* Clear the FIFO Buffers */
@@ -529,11 +504,7 @@ out:
 static u32
 omap_i2c_func(struct i2c_adapter *adap)
 {
-#ifndef OMAP_HACK
        return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
-#else
-       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
-#endif
 }
 
 static inline void
@@ -781,6 +752,7 @@ omap_i2c_probe(struct platform_device *pdev)
                *speed = 100; /* Defualt speed */
 
        dev->speed = *speed;
+       dev->idle = 1;
        dev->dev = &pdev->dev;
        dev->irq = irq->start;
        dev->base = ioremap(mem->start, mem->end - mem->start + 1);
@@ -830,6 +802,8 @@ omap_i2c_probe(struct platform_device *pdev)
        dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n",
                 pdev->id, r >> 4, r & 0xf, dev->speed);
 
+       omap_i2c_idle(dev);
+
        adap = &dev->adapter;
        i2c_set_adapdata(adap, dev);
        adap->owner = THIS_MODULE;
@@ -846,8 +820,6 @@ omap_i2c_probe(struct platform_device *pdev)
                goto err_free_irq;
        }
 
-       omap_i2c_idle(dev);
-
        return 0;
 
 err_free_irq: