]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/busses/i2c-omap.c
Revert "i2c: i2c-omap: Fix standard and fast mode prescalers"
[linux-2.6-omap-h63xx.git] / drivers / i2c / busses / i2c-omap.c
index 61d2e5ad6d6c672b041304de364de4083a51c4a2..71b37ed4b72c1b246b600390cb3db94ed01b76ca 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
 #include <linux/completion.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
+#include <linux/io.h>
+
+/* I2C controller revisions */
+#define OMAP_I2C_REV_2                 0x20
 
-#include <asm/io.h>
+/* I2C controller revisions present on specific hardware */
+#define OMAP_I2C_REV_ON_2430           0x36
+#define OMAP_I2C_REV_ON_3430           0x3C
 
 /* timeout waiting for the controller to respond */
 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
@@ -43,6 +52,8 @@
 #define OMAP_I2C_IE_REG                        0x04
 #define OMAP_I2C_STAT_REG              0x08
 #define OMAP_I2C_IV_REG                        0x0c
+/* For OMAP3 I2C_IV has changed to I2C_WE (wakeup enable) */
+#define OMAP_I2C_WE_REG                        0x0c
 #define OMAP_I2C_SYSS_REG              0x10
 #define OMAP_I2C_BUF_REG               0x14
 #define OMAP_I2C_CNT_REG               0x18
 #define OMAP_I2C_STAT_NACK     (1 << 1)        /* No ack interrupt enable */
 #define OMAP_I2C_STAT_AL       (1 << 0)        /* Arbitration lost int ena */
 
+/* I2C WE wakeup enable register */
+#define OMAP_I2C_WE_XDR_WE     (1 << 14)       /* TX drain wakup */
+#define OMAP_I2C_WE_RDR_WE     (1 << 13)       /* RX drain wakeup */
+#define OMAP_I2C_WE_AAS_WE     (1 << 9)        /* Address as slave wakeup*/
+#define OMAP_I2C_WE_BF_WE      (1 << 8)        /* Bus free wakeup */
+#define OMAP_I2C_WE_STC_WE     (1 << 6)        /* Start condition wakeup */
+#define OMAP_I2C_WE_GC_WE      (1 << 5)        /* General call wakeup */
+#define OMAP_I2C_WE_DRDY_WE    (1 << 3)        /* TX/RX data ready wakeup */
+#define OMAP_I2C_WE_ARDY_WE    (1 << 2)        /* Reg access ready wakeup */
+#define OMAP_I2C_WE_NACK_WE    (1 << 1)        /* No acknowledgment wakeup */
+#define OMAP_I2C_WE_AL_WE      (1 << 0)        /* Arbitration lost wakeup */
+
+#define OMAP_I2C_WE_ALL                (OMAP_I2C_WE_XDR_WE | OMAP_I2C_WE_RDR_WE | \
+                               OMAP_I2C_WE_AAS_WE | OMAP_I2C_WE_BF_WE | \
+                               OMAP_I2C_WE_STC_WE | OMAP_I2C_WE_GC_WE | \
+                               OMAP_I2C_WE_DRDY_WE | OMAP_I2C_WE_ARDY_WE | \
+                               OMAP_I2C_WE_NACK_WE | OMAP_I2C_WE_AL_WE)
+
 /* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
 #define OMAP_I2C_BUF_RDMA_EN   (1 << 15)       /* RX DMA channel enable */
 #define OMAP_I2C_BUF_RXFIF_CLR (1 << 14)       /* RX FIFO Clear */
 #define OMAP_I2C_SYSTEST_SDA_O         (1 << 0)        /* SDA line drive out */
 #endif
 
-/* I2C System Status register (OMAP_I2C_SYSS): */
-#define OMAP_I2C_SYSS_RDONE            (1 << 0)        /* Reset Done */
+/* OCP_SYSSTATUS bit definitions */
+#define SYSS_RESETDONE_MASK            (1 << 0)
+
+/* OCP_SYSCONFIG bit definitions */
+#define SYSC_CLOCKACTIVITY_MASK                (0x3 << 8)
+#define SYSC_SIDLEMODE_MASK            (0x3 << 3)
+#define SYSC_ENAWAKEUP_MASK            (1 << 2)
+#define SYSC_SOFTRESET_MASK            (1 << 1)
+#define SYSC_AUTOIDLE_MASK             (1 << 0)
+
+#define SYSC_IDLEMODE_SMART            0x2
+#define SYSC_CLOCKACTIVITY_FCLK                0x2
 
-/* I2C System Configuration Register (OMAP_I2C_SYSC): */
-#define OMAP_I2C_SYSC_SRST             (1 << 1)        /* Soft Reset */
 
 struct omap_i2c_dev {
        struct device           *dev;
@@ -137,7 +174,7 @@ struct omap_i2c_dev {
                                                 * fifo_size==0 implies no fifo
                                                 * if set, should be trsh+1
                                                 */
-       unsigned                rev1:1;
+       u8                      rev;
        unsigned                b_hw:1;         /* bad h/w fixes */
        unsigned                idle:1;
        u16                     iestate;        /* Saved interrupt register */
@@ -189,6 +226,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 +240,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 */
+       if (dev->rev < OMAP_I2C_REV_2) {
+               iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG); /* Read clears */
        } else {
                omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, dev->iestate);
 
@@ -225,14 +266,14 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
        unsigned long timeout;
        unsigned long internal_clk = 0;
 
-       if (!dev->rev1) {
-               omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
+       if (dev->rev >= OMAP_I2C_REV_2) {
+               omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, SYSC_SOFTRESET_MASK);
                /* For some reason we need to set the EN bit before the
                 * reset done bit gets set. */
                timeout = jiffies + OMAP_I2C_TIMEOUT;
                omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
                while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
-                        OMAP_I2C_SYSS_RDONE)) {
+                        SYSS_RESETDONE_MASK)) {
                        if (time_after(jiffies, timeout)) {
                                dev_warn(dev->dev, "timeout waiting "
                                                "for controller reset\n");
@@ -240,6 +281,33 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
                        }
                        msleep(1);
                }
+
+               /* SYSC register is cleared by the reset; rewrite it */
+               if (dev->rev == OMAP_I2C_REV_ON_2430) {
+
+                       omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG,
+                                          SYSC_AUTOIDLE_MASK);
+
+               } else if (dev->rev >= OMAP_I2C_REV_ON_3430) {
+                       u32 v;
+
+                       v = SYSC_AUTOIDLE_MASK;
+                       v |= SYSC_ENAWAKEUP_MASK;
+                       v |= (SYSC_IDLEMODE_SMART <<
+                             __ffs(SYSC_SIDLEMODE_MASK));
+                       v |= (SYSC_CLOCKACTIVITY_FCLK <<
+                             __ffs(SYSC_CLOCKACTIVITY_MASK));
+
+                       omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, v);
+                       /*
+                        * Enabling all wakup sources to stop I2C freezing on
+                        * WFI instruction.
+                        * REVISIT: Some wkup sources might not be needed.
+                        */
+                       omap_i2c_write_reg(dev, OMAP_I2C_WE_REG,
+                                                       OMAP_I2C_WE_ALL);
+
+               }
        }
        omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
 
@@ -321,9 +389,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 +457,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 +538,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 +574,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 +631,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)
@@ -598,8 +675,9 @@ omap_i2c_isr(int this_irq, void *dev_id)
                                if (stat & OMAP_I2C_STAT_RRDY)
                                        num_bytes = dev->fifo_size;
                                else
-                                       num_bytes = omap_i2c_read_reg(dev,
-                                                       OMAP_I2C_BUFSTAT_REG);
+                                       num_bytes = (omap_i2c_read_reg(dev,
+                                                       OMAP_I2C_BUFSTAT_REG)
+                                                       >> 8) & 0x3F;
                        }
                        while (num_bytes) {
                                num_bytes--;
@@ -637,8 +715,9 @@ omap_i2c_isr(int this_irq, void *dev_id)
                                if (stat & OMAP_I2C_STAT_XRDY)
                                        num_bytes = dev->fifo_size;
                                else
-                                       num_bytes = omap_i2c_read_reg(dev,
-                                                       OMAP_I2C_BUFSTAT_REG);
+                                       num_bytes = (omap_i2c_read_reg(dev,
+                                                       OMAP_I2C_BUFSTAT_REG))
+                                                       & 0x3F;
                        }
                        while (num_bytes) {
                                num_bytes--;
@@ -695,6 +774,7 @@ omap_i2c_probe(struct platform_device *pdev)
        struct omap_i2c_dev     *dev;
        struct i2c_adapter      *adap;
        struct resource         *mem, *irq, *ioarea;
+       void *isr;
        int r;
        u32 speed = 0;
 
@@ -729,6 +809,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);
@@ -744,8 +825,7 @@ omap_i2c_probe(struct platform_device *pdev)
 
        omap_i2c_unidle(dev);
 
-       if (cpu_is_omap15xx())
-               dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
+       dev->rev = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
 
        if (cpu_is_omap2430() || cpu_is_omap34xx()) {
                u16 s;
@@ -766,16 +846,18 @@ omap_i2c_probe(struct platform_device *pdev)
        /* reset ASAP, clearing any IRQs */
        omap_i2c_init(dev);
 
-       r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr,
-                       0, pdev->name, dev);
+       isr = (dev->rev < OMAP_I2C_REV_2) ? omap_i2c_rev1_isr : omap_i2c_isr;
+       r = request_irq(dev->irq, isr, 0, pdev->name, dev);
 
        if (r) {
                dev_err(dev->dev, "failure requesting irq %i\n", dev->irq);
                goto err_unuse_clocks;
        }
-       r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
+
        dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n",
-                pdev->id, r >> 4, r & 0xf, dev->speed);
+                pdev->id, dev->rev >> 4, dev->rev & 0xf, dev->speed);
+
+       omap_i2c_idle(dev);
 
        adap = &dev->adapter;
        i2c_set_adapdata(adap, dev);
@@ -793,8 +875,6 @@ omap_i2c_probe(struct platform_device *pdev)
                goto err_free_irq;
        }
 
-       omap_i2c_idle(dev);
-
        return 0;
 
 err_free_irq: