]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/i2c/busses/i2c-pxa.c
[I2C] pxa: provide late suspend and early resume hooks
[linux-2.6-omap-h63xx.git] / drivers / i2c / busses / i2c-pxa.c
index 78c0fc42bc735af653ef9d85590dea073a10aa89..518b57c795c819cb41a0bb9b012de3011eb2c50e 100644 (file)
 #include <linux/err.h>
 #include <linux/clk.h>
 
-#include <asm/hardware.h>
+#include <mach/hardware.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <asm/arch/i2c.h>
-#include <asm/arch/pxa-regs.h>
-#include <asm/arch/pxa2xx-gpio.h>
+#include <mach/i2c.h>
+#include <mach/pxa-regs.h>
 
 struct pxa_i2c {
        spinlock_t              lock;
@@ -61,6 +60,7 @@ struct pxa_i2c {
        u32                     icrlog[32];
 
        void __iomem            *reg_base;
+       unsigned int            reg_shift;
 
        unsigned long           iobase;
        unsigned long           iosize;
@@ -69,11 +69,11 @@ struct pxa_i2c {
        int                     use_pio;
 };
 
-#define _IBMR(i2c)     ((i2c)->reg_base + 0)
-#define _IDBR(i2c)     ((i2c)->reg_base + 8)
-#define _ICR(i2c)      ((i2c)->reg_base + 0x10)
-#define _ISR(i2c)      ((i2c)->reg_base + 0x18)
-#define _ISAR(i2c)     ((i2c)->reg_base + 0x20)
+#define _IBMR(i2c)     ((i2c)->reg_base + (0x0 << (i2c)->reg_shift))
+#define _IDBR(i2c)     ((i2c)->reg_base + (0x4 << (i2c)->reg_shift))
+#define _ICR(i2c)      ((i2c)->reg_base + (0x8 << (i2c)->reg_shift))
+#define _ISR(i2c)      ((i2c)->reg_base + (0xc << (i2c)->reg_shift))
+#define _ISAR(i2c)     ((i2c)->reg_base + (0x10 << (i2c)->reg_shift))
 
 /*
  * I2C Slave mode address
@@ -189,14 +189,14 @@ static inline int i2c_pxa_is_slavemode(struct pxa_i2c *i2c)
 
 static void i2c_pxa_abort(struct pxa_i2c *i2c)
 {
-       unsigned long timeout = jiffies + HZ/4;
+       int i = 250;
 
        if (i2c_pxa_is_slavemode(i2c)) {
                dev_dbg(&i2c->adap.dev, "%s: called in slave mode\n", __func__);
                return;
        }
 
-       while (time_before(jiffies, timeout) && (readl(_IBMR(i2c)) & 0x1) == 0) {
+       while ((i > 0) && (readl(_IBMR(i2c)) & 0x1) == 0) {
                unsigned long icr = readl(_ICR(i2c));
 
                icr &= ~ICR_START;
@@ -206,7 +206,8 @@ static void i2c_pxa_abort(struct pxa_i2c *i2c)
 
                show_state(i2c);
 
-               msleep(1);
+               mdelay(1);
+               i --;
        }
 
        writel(readl(_ICR(i2c)) & ~(ICR_MA | ICR_START | ICR_STOP),
@@ -908,12 +909,6 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
        struct pxa_i2c *i2c = adap->algo_data;
        int ret, i;
 
-       /* If the I2C controller is disabled we need to reset it (probably due
-          to a suspend/resume destroying state). We do this here as we can then
-          avoid worrying about resuming the controller before its users. */
-       if (!(readl(_ICR(i2c)) & ICR_IUE))
-               i2c_pxa_reset(i2c);
-
        for (i = adap->retries; i >= 0; i--) {
                ret = i2c_pxa_do_xfer(i2c, msgs, num);
                if (ret != I2C_RETRY)
@@ -945,32 +940,6 @@ static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
        .functionality  = i2c_pxa_functionality,
 };
 
-static void i2c_pxa_enable(struct platform_device *dev)
-{
-       if (cpu_is_pxa27x()) {
-               switch (dev->id) {
-               case 0:
-                       pxa_gpio_mode(GPIO117_I2CSCL_MD);
-                       pxa_gpio_mode(GPIO118_I2CSDA_MD);
-                       break;
-               case 1:
-                       local_irq_disable();
-                       PCFR |= PCFR_PI2CEN;
-                       local_irq_enable();
-                       break;
-               }
-       }
-}
-
-static void i2c_pxa_disable(struct platform_device *dev)
-{
-       if (cpu_is_pxa27x() && dev->id == 1) {
-               local_irq_disable();
-               PCFR &= ~PCFR_PI2CEN;
-               local_irq_enable();
-       }
-}
-
 #define res_len(r)             ((r)->end - (r)->start + 1)
 static int i2c_pxa_probe(struct platform_device *dev)
 {
@@ -1020,6 +989,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
                ret = -EIO;
                goto eremap;
        }
+       i2c->reg_shift = (cpu_is_pxa3xx() && (dev->id == 1)) ? 0 : 1;
 
        i2c->iobase = res->start;
        i2c->iosize = res_len(res);
@@ -1036,7 +1006,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
 #endif
 
        clk_enable(i2c->clk);
-       i2c_pxa_enable(dev);
 
        if (plat) {
                i2c->adap.class = plat->class;
@@ -1080,7 +1049,6 @@ eadapt:
                free_irq(irq, i2c);
 ereqirq:
        clk_disable(i2c->clk);
-       i2c_pxa_disable(dev);
        iounmap(i2c->reg_base);
 eremap:
        clk_put(i2c->clk);
@@ -1103,7 +1071,6 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
 
        clk_disable(i2c->clk);
        clk_put(i2c->clk);
-       i2c_pxa_disable(dev);
 
        iounmap(i2c->reg_base);
        release_mem_region(i2c->iobase, i2c->iosize);
@@ -1112,9 +1079,33 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int i2c_pxa_suspend_late(struct platform_device *dev, pm_message_t state)
+{
+       struct pxa_i2c *i2c = platform_get_drvdata(dev);
+       clk_disable(i2c->clk);
+       return 0;
+}
+
+static int i2c_pxa_resume_early(struct platform_device *dev)
+{
+       struct pxa_i2c *i2c = platform_get_drvdata(dev);
+
+       clk_enable(i2c->clk);
+       i2c_pxa_reset(i2c);
+
+       return 0;
+}
+#else
+#define i2c_pxa_suspend_late NULL
+#define i2c_pxa_resume_early NULL
+#endif
+
 static struct platform_driver i2c_pxa_driver = {
        .probe          = i2c_pxa_probe,
        .remove         = __exit_p(i2c_pxa_remove),
+       .suspend_late   = i2c_pxa_suspend_late,
+       .resume_early   = i2c_pxa_resume_early,
        .driver         = {
                .name   = "pxa2xx-i2c",
                .owner  = THIS_MODULE,