]> 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 9ae4b74f3d1a6017b636df911aa3bd12fc4c5853..40a1e4bc92f189b8127f6ae38a4f90a12b83282f 100644 (file)
@@ -2,13 +2,16 @@
  * TI OMAP I2C master mode driver
  *
  * Copyright (C) 2003 MontaVista Software, Inc.
- * Copyright (C) 2004 Texas Instruments.
- *
- * Updated to work with multiple I2C interfaces on 24xx by
- * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com>
  * Copyright (C) 2005 Nokia Corporation
+ * Copyright (C) 2004 - 2007 Texas Instruments.
  *
- * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com>
+ * Originally written by MontaVista Software, Inc.
+ * Additional contributions by:
+ *     Tony Lindgren <tony@atomide.com>
+ *     Imre Deak <imre.deak@nokia.com>
+ *     Juha Yrjölä <juha.yrjola@solidboot.com>
+ *     Syed Khasim <x0khasim@ti.com>
+ *     Nishant Menon <nm@ti.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -33,8 +36,7 @@
 #include <linux/completion.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
-
-#include <asm/io.h>
+#include <linux/io.h>
 
 /* timeout waiting for the controller to respond */
 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
@@ -154,9 +156,9 @@ static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
        return __raw_readw(i2c_dev->base + reg);
 }
 
-static int omap_i2c_get_clocks(struct omap_i2c_dev *dev)
+static int __init omap_i2c_get_clocks(struct omap_i2c_dev *dev)
 {
-       if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
+       if (cpu_is_omap16xx() || cpu_class_is_omap2()) {
                dev->iclk = clk_get(dev->dev, "i2c_ick");
                if (IS_ERR(dev->iclk)) {
                        dev->iclk = NULL;
@@ -189,6 +191,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);
@@ -201,10 +205,12 @@ 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) {
-               iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG);   /* Read clears */
+               iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
        } else {
                omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate);
 
@@ -266,7 +272,7 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
                        psc = fclk_rate / 12000000;
        }
 
-       if (cpu_is_omap2430()) {
+       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
 
                /* HSI2C controller internal clk rate should be 19.2 Mhz */
                internal_clk = 19200;
@@ -321,9 +327,9 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
 
        /* Enable interrupts */
        omap_i2c_write_reg(dev, OMAP_I2C_IE_REG,
-                          (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
-                           OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
-                           OMAP_I2C_IE_AL)  | ((dev->fifo_size) ?
+                       (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
+                       OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
+                       OMAP_I2C_IE_AL)  | ((dev->fifo_size) ?
                                (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0));
        return 0;
 }
@@ -389,8 +395,10 @@ static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
                w |= OMAP_I2C_CON_XA;
        if (!(msg->flags & I2C_M_RD))
                w |= OMAP_I2C_CON_TRX;
+
        if (!dev->b_hw && stop)
                w |= OMAP_I2C_CON_STP;
+
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
 
        /*
@@ -468,7 +476,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
        omap_i2c_unidle(dev);
 
-       if ((r = omap_i2c_wait_for_bb(dev)) < 0)
+       r = omap_i2c_wait_for_bb(dev);
+       if (r < 0)
                goto out;
 
        for (i = 0; i < num; i++) {
@@ -503,6 +512,9 @@ omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
        omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
 }
 
+/* rev1 devices are apparently only on some 15xx */
+#ifdef CONFIG_ARCH_OMAP15XX
+
 static irqreturn_t
 omap_i2c_rev1_isr(int this_irq, void *dev_id)
 {
@@ -557,6 +569,9 @@ omap_i2c_rev1_isr(int this_irq, void *dev_id)
 
        return IRQ_HANDLED;
 }
+#else
+#define omap_i2c_rev1_isr              NULL
+#endif
 
 static irqreturn_t
 omap_i2c_isr(int this_irq, void *dev_id)
@@ -608,7 +623,8 @@ omap_i2c_isr(int this_irq, void *dev_id)
                                        *dev->buf++ = w;
                                        dev->buf_len--;
                                        /* Data reg from 2430 is 8 bit wide */
-                                       if (!cpu_is_omap2430()) {
+                                       if (!cpu_is_omap2430() &&
+                                                       !cpu_is_omap34xx()) {
                                                if (dev->buf_len) {
                                                        *dev->buf++ = w >> 8;
                                                        dev->buf_len--;
@@ -646,7 +662,8 @@ omap_i2c_isr(int this_irq, void *dev_id)
                                        w = *dev->buf++;
                                        dev->buf_len--;
                                        /* Data reg from  2430 is 8 bit wide */
-                                       if (!cpu_is_omap2430()) {
+                                       if (!cpu_is_omap2430() &&
+                                                       !cpu_is_omap34xx()) {
                                                if (dev->buf_len) {
                                                        w |= *dev->buf++ << 8;
                                                        dev->buf_len--;
@@ -687,14 +704,14 @@ static const struct i2c_algorithm omap_i2c_algo = {
        .functionality  = omap_i2c_func,
 };
 
-static int
+static int __init
 omap_i2c_probe(struct platform_device *pdev)
 {
        struct omap_i2c_dev     *dev;
        struct i2c_adapter      *adap;
        struct resource         *mem, *irq, *ioarea;
        int r;
-       u32 *speed = NULL;
+       u32 speed = 0;
 
        /* NOTE: driver uses the static register mapping */
        mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -722,11 +739,12 @@ omap_i2c_probe(struct platform_device *pdev)
        }
 
        if (pdev->dev.platform_data != NULL)
-               speed = (u32 *) pdev->dev.platform_data;
+               speed = *(u32 *)pdev->dev.platform_data;
        else
-               *speed = 100; /* Defualt speed */
+               speed = 100;    /* Defualt speed */
 
-       dev->speed = *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);
@@ -745,7 +763,7 @@ omap_i2c_probe(struct platform_device *pdev)
        if (cpu_is_omap15xx())
                dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
 
-       if (cpu_is_omap2430()) {
+       if (cpu_is_omap2430() || cpu_is_omap34xx()) {
                u16 s;
 
                /* Set up the fifo size - Get total size */
@@ -775,6 +793,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;
@@ -791,8 +811,6 @@ omap_i2c_probe(struct platform_device *pdev)
                goto err_free_irq;
        }
 
-       omap_i2c_idle(dev);
-
        return 0;
 
 err_free_irq: