i2c: Obsolete i2c-ixp2000, i2c-ixp4xx and scx200_i2c
[safe/jmp/linux-2.6] / drivers / i2c / busses / i2c-mpc.c
index 03c23ce..ee65aa1 100644 (file)
  * warranty of any kind, whether express or implied.
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/sched.h>
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/platform_device.h>
+
 #include <asm/io.h>
 #include <linux/fsl_devices.h>
 #include <linux/i2c.h>
@@ -62,7 +63,7 @@ static __inline__ void writeccr(struct mpc_i2c *i2c, u32 x)
        writeb(x, i2c->base + MPC_I2C_CR);
 }
 
-static irqreturn_t mpc_i2c_isr(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t mpc_i2c_isr(int irq, void *dev_id)
 {
        struct mpc_i2c *i2c = dev_id;
        if (readb(i2c->base + MPC_I2C_SR) & CSR_MIF) {
@@ -271,9 +272,7 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
        return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
 }
 
-static struct i2c_algorithm mpc_algo = {
-       .name = "MPC algorithm",
-       .id = I2C_ALGO_MPC107,
+static const struct i2c_algorithm mpc_algo = {
        .master_xfer = mpc_xfer,
        .functionality = mpc_functionality,
 };
@@ -281,13 +280,112 @@ static struct i2c_algorithm mpc_algo = {
 static struct i2c_adapter mpc_ops = {
        .owner = THIS_MODULE,
        .name = "MPC adapter",
-       .id = I2C_ALGO_MPC107 | I2C_HW_MPC107,
+       .id = I2C_HW_MPC107,
        .algo = &mpc_algo,
        .class = I2C_CLASS_HWMON,
        .timeout = 1,
        .retries = 1
 };
 
+static int fsl_i2c_probe(struct platform_device *pdev)
+{
+       int result = 0;
+       struct mpc_i2c *i2c;
+       struct fsl_i2c_platform_data *pdata;
+       struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+       pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
+
+       if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) {
+               return -ENOMEM;
+       }
+
+       i2c->irq = platform_get_irq(pdev, 0);
+       if (i2c->irq < 0) {
+               result = -ENXIO;
+               goto fail_get_irq;
+       }
+       i2c->flags = pdata->device_flags;
+       init_waitqueue_head(&i2c->queue);
+
+       i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION);
+
+       if (!i2c->base) {
+               printk(KERN_ERR "i2c-mpc - failed to map controller\n");
+               result = -ENOMEM;
+               goto fail_map;
+       }
+
+       if (i2c->irq != 0)
+               if ((result = request_irq(i2c->irq, mpc_i2c_isr,
+                                         IRQF_SHARED, "i2c-mpc", i2c)) < 0) {
+                       printk(KERN_ERR
+                              "i2c-mpc - failed to attach interrupt\n");
+                       goto fail_irq;
+               }
+
+       mpc_i2c_setclock(i2c);
+       platform_set_drvdata(pdev, i2c);
+
+       i2c->adap = mpc_ops;
+       i2c_set_adapdata(&i2c->adap, i2c);
+       i2c->adap.dev.parent = &pdev->dev;
+       if ((result = i2c_add_adapter(&i2c->adap)) < 0) {
+               printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
+               goto fail_add;
+       }
+
+       return result;
+
+      fail_add:
+       if (i2c->irq != 0)
+               free_irq(i2c->irq, NULL);
+      fail_irq:
+       iounmap(i2c->base);
+      fail_map:
+      fail_get_irq:
+       kfree(i2c);
+       return result;
+};
+
+static int fsl_i2c_remove(struct platform_device *pdev)
+{
+       struct mpc_i2c *i2c = platform_get_drvdata(pdev);
+
+       i2c_del_adapter(&i2c->adap);
+       platform_set_drvdata(pdev, NULL);
+
+       if (i2c->irq != 0)
+               free_irq(i2c->irq, i2c);
+
+       iounmap(i2c->base);
+       kfree(i2c);
+       return 0;
+};
+
+/* Structure for a device driver */
+static struct platform_driver fsl_i2c_driver = {
+       .probe = fsl_i2c_probe,
+       .remove = fsl_i2c_remove,
+       .driver = {
+               .owner = THIS_MODULE,
+               .name = "fsl-i2c",
+       },
+};
+
+static int __init fsl_i2c_init(void)
+{
+       return platform_driver_register(&fsl_i2c_driver);
+}
+
+static void __exit fsl_i2c_exit(void)
+{
+       platform_driver_unregister(&fsl_i2c_driver);
+}
+
+module_init(fsl_i2c_init);
+module_exit(fsl_i2c_exit);
+
 MODULE_AUTHOR("Adrian Cox <adrian@humboldt.co.uk>");
 MODULE_DESCRIPTION
     ("I2C-Bus adapter for MPC107 bridge and MPC824x/85xx/52xx processors");