diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/i2c/busses/i2c-imx.c | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/i2c/busses/i2c-imx.c')
-rw-r--r-- | drivers/i2c/busses/i2c-imx.c | 34 |
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 | ||
447 | fail0: | 451 | fail0: |
@@ -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: | |||
582 | fail4: | 587 | fail4: |
583 | clk_put(i2c_imx->clk); | 588 | clk_put(i2c_imx->clk); |
584 | fail3: | 589 | fail3: |
585 | release_mem_region(i2c_imx->res->start, resource_size(res)); | ||
586 | fail2: | ||
587 | kfree(i2c_imx); | 590 | kfree(i2c_imx); |
588 | fail1: | 591 | fail2: |
589 | iounmap(base); | 592 | iounmap(base); |
593 | fail1: | ||
594 | release_mem_region(res->start, resource_size(res)); | ||
590 | fail0: | 595 | fail0: |
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 | ||
627 | static struct platform_driver i2c_imx_driver = { | 632 | static 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, |