include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / i2c / busses / i2c-pxa.c
index bdb1f75..14d249f 100644 (file)
@@ -12,7 +12,7 @@
  *
  *  History:
  *    Apr 2002: Initial version [CS]
- *    Jun 2002: Properly seperated algo/adap [FB]
+ *    Jun 2002: Properly separated algo/adap [FB]
  *    Jan 2003: Fixed several bugs concerning interrupt handling [Kai-Uwe Bloem]
  *    Jan 2003: added limited signal handling [Kai-Uwe Bloem]
  *    Sep 2004: Major rework to ensure efficient bus handling [RMK]
 #include <linux/platform_device.h>
 #include <linux/err.h>
 #include <linux/clk.h>
+#include <linux/slab.h>
 
-#include <mach/hardware.h>
 #include <asm/irq.h>
 #include <asm/io.h>
-#include <mach/i2c.h>
+#include <plat/i2c.h>
+
+/*
+ * I2C register offsets will be shifted 0 or 1 bit left, depending on
+ * different SoCs
+ */
+#define REG_SHIFT_0    (0 << 0)
+#define REG_SHIFT_1    (1 << 0)
+#define REG_SHIFT(d)   ((d) & 0x1)
+
+static const struct platform_device_id i2c_pxa_id_table[] = {
+       { "pxa2xx-i2c",         REG_SHIFT_1 },
+       { "pxa3xx-pwri2c",      REG_SHIFT_0 },
+       { },
+};
+MODULE_DEVICE_TABLE(platform, i2c_pxa_id_table);
 
 /*
  * I2C registers and bit definitions
@@ -210,11 +225,12 @@ static irqreturn_t i2c_pxa_handler(int this_irq, void *dev_id);
 static void i2c_pxa_scream_blue_murder(struct pxa_i2c *i2c, const char *why)
 {
        unsigned int i;
-       printk("i2c: error: %s\n", why);
-       printk("i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
+       printk(KERN_ERR "i2c: error: %s\n", why);
+       printk(KERN_ERR "i2c: msg_num: %d msg_idx: %d msg_ptr: %d\n",
                i2c->msg_num, i2c->msg_idx, i2c->msg_ptr);
-       printk("i2c: ICR: %08x ISR: %08x\n"
-              "i2c: log: ", readl(_ICR(i2c)), readl(_ISR(i2c)));
+       printk(KERN_ERR "i2c: ICR: %08x ISR: %08x\n",
+              readl(_ICR(i2c)), readl(_ISR(i2c)));
+       printk(KERN_DEBUG "i2c: log: ");
        for (i = 0; i < i2c->irqlogidx; i++)
                printk("[%08x:%08x] ", i2c->isrlog[i], i2c->icrlog[i]);
        printk("\n");
@@ -264,10 +280,10 @@ static int i2c_pxa_wait_bus_not_busy(struct pxa_i2c *i2c)
                show_state(i2c);
        }
 
-       if (timeout <= 0)
+       if (timeout < 0)
                show_state(i2c);
 
-       return timeout <= 0 ? I2C_RETRY : 0;
+       return timeout < 0 ? I2C_RETRY : 0;
 }
 
 static int i2c_pxa_wait_master(struct pxa_i2c *i2c)
@@ -611,7 +627,7 @@ static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)
                show_state(i2c);
        }
 
-       if (timeout <= 0) {
+       if (timeout < 0) {
                show_state(i2c);
                dev_err(&i2c->adap.dev,
                        "i2c_pxa: timeout waiting for bus free\n");
@@ -978,12 +994,12 @@ static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
        .functionality  = i2c_pxa_functionality,
 };
 
-#define res_len(r)             ((r)->end - (r)->start + 1)
 static int i2c_pxa_probe(struct platform_device *dev)
 {
        struct pxa_i2c *i2c;
        struct resource *res;
        struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
+       struct platform_device_id *id = platform_get_device_id(dev);
        int ret;
        int irq;
 
@@ -992,7 +1008,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
        if (res == NULL || irq < 0)
                return -ENODEV;
 
-       if (!request_mem_region(res->start, res_len(res), res->name))
+       if (!request_mem_region(res->start, resource_size(res), res->name))
                return -ENOMEM;
 
        i2c = kzalloc(sizeof(struct pxa_i2c), GFP_KERNEL);
@@ -1022,15 +1038,15 @@ static int i2c_pxa_probe(struct platform_device *dev)
                goto eclk;
        }
 
-       i2c->reg_base = ioremap(res->start, res_len(res));
+       i2c->reg_base = ioremap(res->start, resource_size(res));
        if (!i2c->reg_base) {
                ret = -EIO;
                goto eremap;
        }
-       i2c->reg_shift = (cpu_is_pxa3xx() && (dev->id == 1)) ? 0 : 1;
+       i2c->reg_shift = REG_SHIFT(id->driver_data);
 
        i2c->iobase = res->start;
-       i2c->iosize = res_len(res);
+       i2c->iosize = resource_size(res);
 
        i2c->irq = irq;
 
@@ -1094,7 +1110,7 @@ eremap:
 eclk:
        kfree(i2c);
 emalloc:
-       release_mem_region(res->start, res_len(res));
+       release_mem_region(res->start, resource_size(res));
        return ret;
 }
 
@@ -1119,36 +1135,46 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
 }
 
 #ifdef CONFIG_PM
-static int i2c_pxa_suspend_late(struct platform_device *dev, pm_message_t state)
+static int i2c_pxa_suspend_noirq(struct device *dev)
 {
-       struct pxa_i2c *i2c = platform_get_drvdata(dev);
+       struct platform_device *pdev = to_platform_device(dev);
+       struct pxa_i2c *i2c = platform_get_drvdata(pdev);
+
        clk_disable(i2c->clk);
+
        return 0;
 }
 
-static int i2c_pxa_resume_early(struct platform_device *dev)
+static int i2c_pxa_resume_noirq(struct device *dev)
 {
-       struct pxa_i2c *i2c = platform_get_drvdata(dev);
+       struct platform_device *pdev = to_platform_device(dev);
+       struct pxa_i2c *i2c = platform_get_drvdata(pdev);
 
        clk_enable(i2c->clk);
        i2c_pxa_reset(i2c);
 
        return 0;
 }
+
+static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
+       .suspend_noirq = i2c_pxa_suspend_noirq,
+       .resume_noirq = i2c_pxa_resume_noirq,
+};
+
+#define I2C_PXA_DEV_PM_OPS (&i2c_pxa_dev_pm_ops)
 #else
-#define i2c_pxa_suspend_late NULL
-#define i2c_pxa_resume_early NULL
+#define I2C_PXA_DEV_PM_OPS 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,
+               .pm     = I2C_PXA_DEV_PM_OPS,
        },
+       .id_table       = i2c_pxa_id_table,
 };
 
 static int __init i2c_adap_pxa_init(void)