aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-imx.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses/i2c-imx.c')
-rw-r--r--drivers/i2c/busses/i2c-imx.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index e3654d683e15..d1ff9408dc1f 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -47,6 +47,7 @@
47#include <linux/sched.h> 47#include <linux/sched.h>
48#include <linux/platform_device.h> 48#include <linux/platform_device.h>
49#include <linux/clk.h> 49#include <linux/clk.h>
50#include <linux/slab.h>
50 51
51#include <mach/irqs.h> 52#include <mach/irqs.h>
52#include <mach/hardware.h> 53#include <mach/hardware.h>
@@ -145,10 +146,10 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
145 "<%s> I2C Interrupted\n", __func__); 146 "<%s> I2C Interrupted\n", __func__);
146 return -EINTR; 147 return -EINTR;
147 } 148 }
148 if (time_after(jiffies, orig_jiffies + HZ / 1000)) { 149 if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
149 dev_dbg(&i2c_imx->adapter.dev, 150 dev_dbg(&i2c_imx->adapter.dev,
150 "<%s> I2C bus is busy\n", __func__); 151 "<%s> I2C bus is busy\n", __func__);
151 return -EIO; 152 return -ETIMEDOUT;
152 } 153 }
153 schedule(); 154 schedule();
154 } 155 }
@@ -226,7 +227,6 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
226 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 227 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
227 temp &= ~(I2CR_MSTA | I2CR_MTX); 228 temp &= ~(I2CR_MSTA | I2CR_MTX);
228 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 229 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
229 i2c_imx->stopped = 1;
230 } 230 }
231 if (cpu_is_mx1()) { 231 if (cpu_is_mx1()) {
232 /* 232 /*
@@ -236,8 +236,10 @@ static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
236 udelay(i2c_imx->disable_delay); 236 udelay(i2c_imx->disable_delay);
237 } 237 }
238 238
239 if (!i2c_imx->stopped) 239 if (!i2c_imx->stopped) {
240 i2c_imx_bus_busy(i2c_imx, 0); 240 i2c_imx_bus_busy(i2c_imx, 0);
241 i2c_imx->stopped = 1;
242 }
241 243
242 /* Disable I2C controller */ 244 /* Disable I2C controller */
243 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 245 writeb(0, i2c_imx->base + IMX_I2C_I2CR);
@@ -442,6 +444,8 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
442 result = i2c_imx_read(i2c_imx, &msgs[i]); 444 result = i2c_imx_read(i2c_imx, &msgs[i]);
443 else 445 else
444 result = i2c_imx_write(i2c_imx, &msgs[i]); 446 result = i2c_imx_write(i2c_imx, &msgs[i]);
447 if (result)
448 goto fail0;
445 } 449 }
446 450
447fail0: 451fail0:
@@ -496,22 +500,23 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
496 } 500 }
497 501
498 res_size = resource_size(res); 502 res_size = resource_size(res);
503
504 if (!request_mem_region(res->start, res_size, DRIVER_NAME)) {
505 ret = -EBUSY;
506 goto fail0;
507 }
508
499 base = ioremap(res->start, res_size); 509 base = ioremap(res->start, res_size);
500 if (!base) { 510 if (!base) {
501 dev_err(&pdev->dev, "ioremap failed\n"); 511 dev_err(&pdev->dev, "ioremap failed\n");
502 ret = -EIO; 512 ret = -EIO;
503 goto fail0; 513 goto fail1;
504 } 514 }
505 515
506 i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL); 516 i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL);
507 if (!i2c_imx) { 517 if (!i2c_imx) {
508 dev_err(&pdev->dev, "can't allocate interface\n"); 518 dev_err(&pdev->dev, "can't allocate interface\n");
509 ret = -ENOMEM; 519 ret = -ENOMEM;
510 goto fail1;
511 }
512
513 if (!request_mem_region(res->start, res_size, DRIVER_NAME)) {
514 ret = -EBUSY;
515 goto fail2; 520 goto fail2;
516 } 521 }
517 522
@@ -582,11 +587,11 @@ fail5:
582fail4: 587fail4:
583 clk_put(i2c_imx->clk); 588 clk_put(i2c_imx->clk);
584fail3: 589fail3:
585 release_mem_region(i2c_imx->res->start, resource_size(res));
586fail2:
587 kfree(i2c_imx); 590 kfree(i2c_imx);
588fail1: 591fail2:
589 iounmap(base); 592 iounmap(base);
593fail1:
594 release_mem_region(res->start, resource_size(res));
590fail0: 595fail0:
591 if (pdata && pdata->exit) 596 if (pdata && pdata->exit)
592 pdata->exit(&pdev->dev); 597 pdata->exit(&pdev->dev);
@@ -618,14 +623,13 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
618 623
619 clk_put(i2c_imx->clk); 624 clk_put(i2c_imx->clk);
620 625
621 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
622 iounmap(i2c_imx->base); 626 iounmap(i2c_imx->base);
627 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
623 kfree(i2c_imx); 628 kfree(i2c_imx);
624 return 0; 629 return 0;
625} 630}
626 631
627static struct platform_driver i2c_imx_driver = { 632static struct platform_driver i2c_imx_driver = {
628 .probe = i2c_imx_probe,
629 .remove = __exit_p(i2c_imx_remove), 633 .remove = __exit_p(i2c_imx_remove),
630 .driver = { 634 .driver = {
631 .name = DRIVER_NAME, 635 .name = DRIVER_NAME,