Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / i2c / busses / i2c-s3c2410.c
index fcfa51c..f7d40f8 100644 (file)
@@ -20,6 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
 
+#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 
 #include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/err.h>
-#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
 
 #include <asm/hardware.h>
 #include <asm/irq.h>
 #include <asm/io.h>
 
-#include <asm/hardware/clock.h>
 #include <asm/arch/regs-gpio.h>
 #include <asm/arch/regs-iic.h>
 #include <asm/arch/iic.h>
@@ -533,7 +534,7 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int
 /* s3c24xx_i2c_xfer
  *
  * first port of call from the i2c bus code when an message needs
- * transfering across the i2c bus.
+ * transferring across the i2c bus.
 */
 
 static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
@@ -567,7 +568,6 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
 /* i2c bus registration info */
 
 static struct i2c_algorithm s3c24xx_i2c_algorithm = {
-       .name                   = "S3C2410-I2C-Algorithm",
        .master_xfer            = s3c24xx_i2c_xfer,
        .functionality          = s3c24xx_i2c_func,
 };
@@ -738,7 +738,6 @@ static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c)
 {
        if (i2c->clk != NULL && !IS_ERR(i2c->clk)) {
                clk_disable(i2c->clk);
-               clk_unuse(i2c->clk);
                clk_put(i2c->clk);
                i2c->clk = NULL;
        }
@@ -760,33 +759,31 @@ static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c)
  * called by the bus driver when a suitable device is found
 */
 
-static int s3c24xx_i2c_probe(struct device *dev)
+static int s3c24xx_i2c_probe(struct platform_device *pdev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
        struct s3c24xx_i2c *i2c = &s3c24xx_i2c;
        struct resource *res;
        int ret;
 
        /* find the clock and enable it */
 
-       i2c->dev = dev;
-       i2c->clk = clk_get(dev, "i2c");
+       i2c->dev = &pdev->dev;
+       i2c->clk = clk_get(&pdev->dev, "i2c");
        if (IS_ERR(i2c->clk)) {
-               dev_err(dev, "cannot get clock\n");
+               dev_err(&pdev->dev, "cannot get clock\n");
                ret = -ENOENT;
                goto out;
        }
 
-       dev_dbg(dev, "clock source %p\n", i2c->clk);
+       dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
 
-       clk_use(i2c->clk);
        clk_enable(i2c->clk);
 
        /* map the registers */
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (res == NULL) {
-               dev_err(dev, "cannot find IO resource\n");
+               dev_err(&pdev->dev, "cannot find IO resource\n");
                ret = -ENOENT;
                goto out;
        }
@@ -795,7 +792,7 @@ static int s3c24xx_i2c_probe(struct device *dev)
                                         pdev->name);
 
        if (i2c->ioarea == NULL) {
-               dev_err(dev, "cannot request IO\n");
+               dev_err(&pdev->dev, "cannot request IO\n");
                ret = -ENXIO;
                goto out;
        }
@@ -803,17 +800,17 @@ static int s3c24xx_i2c_probe(struct device *dev)
        i2c->regs = ioremap(res->start, (res->end-res->start)+1);
 
        if (i2c->regs == NULL) {
-               dev_err(dev, "cannot map IO\n");
+               dev_err(&pdev->dev, "cannot map IO\n");
                ret = -ENXIO;
                goto out;
        }
 
-       dev_dbg(dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
+       dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
 
        /* setup info block for the i2c core */
 
        i2c->adap.algo_data = i2c;
-       i2c->adap.dev.parent = dev;
+       i2c->adap.dev.parent = &pdev->dev;
 
        /* initialise the i2c controller */
 
@@ -827,7 +824,7 @@ static int s3c24xx_i2c_probe(struct device *dev)
 
        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
        if (res == NULL) {
-               dev_err(dev, "cannot find IRQ\n");
+               dev_err(&pdev->dev, "cannot find IRQ\n");
                ret = -ENOENT;
                goto out;
        }
@@ -836,23 +833,23 @@ static int s3c24xx_i2c_probe(struct device *dev)
                          pdev->name, i2c);
 
        if (ret != 0) {
-               dev_err(dev, "cannot claim IRQ\n");
+               dev_err(&pdev->dev, "cannot claim IRQ\n");
                goto out;
        }
 
        i2c->irq = res;
                
-       dev_dbg(dev, "irq resource %p (%ld)\n", res, res->start);
+       dev_dbg(&pdev->dev, "irq resource %p (%ld)\n", res, res->start);
 
        ret = i2c_add_adapter(&i2c->adap);
        if (ret < 0) {
-               dev_err(dev, "failed to add bus to i2c core\n");
+               dev_err(&pdev->dev, "failed to add bus to i2c core\n");
                goto out;
        }
 
-       dev_set_drvdata(dev, i2c);
+       platform_set_drvdata(pdev, i2c);
 
-       dev_info(dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
+       dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
 
  out:
        if (ret < 0)
@@ -866,27 +863,25 @@ static int s3c24xx_i2c_probe(struct device *dev)
  * called when device is removed from the bus
 */
 
-static int s3c24xx_i2c_remove(struct device *dev)
+static int s3c24xx_i2c_remove(struct platform_device *pdev)
 {
-       struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
+       struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
        
        if (i2c != NULL) {
                s3c24xx_i2c_free(i2c);
-               dev_set_drvdata(dev, NULL);
+               platform_set_drvdata(pdev, NULL);
        }
 
        return 0;
 }
 
 #ifdef CONFIG_PM
-static int s3c24xx_i2c_resume(struct device *dev, u32 level)
+static int s3c24xx_i2c_resume(struct platform_device *dev)
 {
-       struct s3c24xx_i2c *i2c = dev_get_drvdata(dev);
-       
-       if (i2c != NULL && level == RESUME_ENABLE) {
-               dev_dbg(dev, "resume: level %d\n", level);
+       struct s3c24xx_i2c *i2c = platform_get_drvdata(dev);
+
+       if (i2c != NULL)
                s3c24xx_i2c_init(i2c);
-       }
 
        return 0;
 }
@@ -897,37 +892,44 @@ static int s3c24xx_i2c_resume(struct device *dev, u32 level)
 
 /* device driver for platform bus bits */
 
-static struct device_driver s3c2410_i2c_driver = {
-       .name           = "s3c2410-i2c",
-       .bus            = &platform_bus_type,
+static struct platform_driver s3c2410_i2c_driver = {
        .probe          = s3c24xx_i2c_probe,
        .remove         = s3c24xx_i2c_remove,
        .resume         = s3c24xx_i2c_resume,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "s3c2410-i2c",
+       },
 };
 
-static struct device_driver s3c2440_i2c_driver = {
-       .name           = "s3c2440-i2c",
-       .bus            = &platform_bus_type,
+static struct platform_driver s3c2440_i2c_driver = {
        .probe          = s3c24xx_i2c_probe,
        .remove         = s3c24xx_i2c_remove,
        .resume         = s3c24xx_i2c_resume,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = "s3c2440-i2c",
+       },
 };
 
 static int __init i2c_adap_s3c_init(void)
 {
        int ret;
 
-       ret = driver_register(&s3c2410_i2c_driver);
-       if (ret == 0)
-               ret = driver_register(&s3c2440_i2c_driver); 
+       ret = platform_driver_register(&s3c2410_i2c_driver);
+       if (ret == 0) {
+               ret = platform_driver_register(&s3c2440_i2c_driver);
+               if (ret)
+                       platform_driver_unregister(&s3c2410_i2c_driver);
+       }
 
        return ret;
 }
 
 static void __exit i2c_adap_s3c_exit(void)
 {
-       driver_unregister(&s3c2410_i2c_driver);
-       driver_unregister(&s3c2440_i2c_driver);
+       platform_driver_unregister(&s3c2410_i2c_driver);
+       platform_driver_unregister(&s3c2440_i2c_driver);
 }
 
 module_init(i2c_adap_s3c_init);