X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fi2c%2Fbusses%2Fi2c-s3c2410.c;h=4ca6de209b8b6225406f459f64969ef7db94fb25;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=9cb69744a71b1d8d536cb3063bef4f77be4d8e7c;hpb=87fc8d1bb10cd459024a742c6a10961fefcef18f;p=linux-2.6.git diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index 9cb69744a..4ca6de209 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -1,6 +1,6 @@ /* linux/drivers/i2c/busses/i2c-s3c2410.c * - * Copyright (C) 2004 Simtec Electronics + * Copyright (C) 2004,2005 Simtec Electronics * Ben Dooks * * S3C2410 I2C Controller @@ -32,13 +32,13 @@ #include #include #include -#include +#include +#include #include #include #include -#include #include #include #include @@ -188,6 +188,9 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, } else stat |= S3C2410_IICSTAT_MASTER_TX; + if (msg->flags & I2C_M_REV_DIR_ADDR) + addr ^= 1; + // todo - check for wether ack wanted or not s3c24xx_i2c_enable_ack(i2c); @@ -287,7 +290,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { /* ack was not received... */ - dev_err(i2c->dev, "ack was not received\n" ); + dev_dbg(i2c->dev, "ack was not received\n"); s3c24xx_i2c_stop(i2c, -EREMOTEIO); goto out_ack; } @@ -420,8 +423,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat) * top level IRQ servicing routine */ -static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id, - struct pt_regs *regs) +static irqreturn_t s3c24xx_i2c_irq(int irqno, void *dev_id) { struct s3c24xx_i2c *i2c = dev_id; unsigned long status; @@ -483,7 +485,7 @@ static int s3c24xx_i2c_set_master(struct s3c24xx_i2c *i2c) * this starts an i2c transfer */ -static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg msgs[], int num) +static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) { unsigned long timeout; int ret; @@ -530,11 +532,11 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg msgs[], in /* 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, - struct i2c_msg msgs[], int num) + struct i2c_msg *msgs, int num) { struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data; int retry; @@ -555,11 +557,17 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, return -EREMOTEIO; } +/* declare our i2c functionality */ +static u32 s3c24xx_i2c_func(struct i2c_adapter *adap) +{ + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_PROTOCOL_MANGLING; +} + /* i2c bus registration info */ -static struct i2c_algorithm s3c24xx_i2c_algorithm = { - .name = "S3C2410-I2C-Algorithm", +static const struct i2c_algorithm s3c24xx_i2c_algorithm = { .master_xfer = s3c24xx_i2c_xfer, + .functionality = s3c24xx_i2c_func, }; static struct s3c24xx_i2c s3c24xx_i2c = { @@ -567,8 +575,10 @@ static struct s3c24xx_i2c s3c24xx_i2c = { .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), .adap = { .name = "s3c2410-i2c", + .owner = THIS_MODULE, .algo = &s3c24xx_i2c_algorithm, .retries = 2, + .class = I2C_CLASS_HWMON, }, }; @@ -726,7 +736,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; } @@ -748,33 +757,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; } @@ -783,7 +790,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; } @@ -791,17 +798,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 */ @@ -815,32 +822,32 @@ 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; } - ret = request_irq(res->start, s3c24xx_i2c_irq, SA_INTERRUPT, + ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 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) @@ -854,27 +861,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; } @@ -885,37 +890,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);