aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-imx.c
diff options
context:
space:
mode:
authorRichard Zhao <richard.zhao@freescale.com>2012-06-04 07:04:25 -0400
committerWolfram Sang <w.sang@pengutronix.de>2012-07-08 06:50:54 -0400
commit9f8a3e7fd5bd08e3fd9847c04a5a445e2994f6b3 (patch)
treeb574ff6df93e0b183a952de781d3e2737ceada18 /drivers/i2c/busses/i2c-imx.c
parent9cbb6b2b92d0fdade0fe00cc00e3658b44c86676 (diff)
i2c: imx: convert to use managed functions
- convert to use devm_request_and_ioremap, devm_kzalloc, devm_clk_get, devm_request_irq. - clean up unused variables. Signed-off-by: Richard Zhao <richard.zhao@freescale.com> Reviewed-by: Shubhrajyoti D <Shubhrajyoti@ti.com> Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-imx.c')
-rw-r--r--drivers/i2c/busses/i2c-imx.c71
1 files changed, 18 insertions, 53 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 8d6b504d65c4..a93e84650f99 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -118,10 +118,8 @@ static u16 __initdata i2c_clk_div[50][2] = {
118 118
119struct imx_i2c_struct { 119struct imx_i2c_struct {
120 struct i2c_adapter adapter; 120 struct i2c_adapter adapter;
121 struct resource *res;
122 struct clk *clk; 121 struct clk *clk;
123 void __iomem *base; 122 void __iomem *base;
124 int irq;
125 wait_queue_head_t queue; 123 wait_queue_head_t queue;
126 unsigned long i2csr; 124 unsigned long i2csr;
127 unsigned int disable_delay; 125 unsigned int disable_delay;
@@ -473,7 +471,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
473 struct imxi2c_platform_data *pdata = pdev->dev.platform_data; 471 struct imxi2c_platform_data *pdata = pdev->dev.platform_data;
474 struct pinctrl *pinctrl; 472 struct pinctrl *pinctrl;
475 void __iomem *base; 473 void __iomem *base;
476 resource_size_t res_size;
477 int irq, bitrate; 474 int irq, bitrate;
478 int ret; 475 int ret;
479 476
@@ -490,25 +487,15 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
490 return -ENOENT; 487 return -ENOENT;
491 } 488 }
492 489
493 res_size = resource_size(res); 490 base = devm_request_and_ioremap(&pdev->dev, res);
494 491 if (!base)
495 if (!request_mem_region(res->start, res_size, DRIVER_NAME)) {
496 dev_err(&pdev->dev, "request_mem_region failed\n");
497 return -EBUSY; 492 return -EBUSY;
498 }
499
500 base = ioremap(res->start, res_size);
501 if (!base) {
502 dev_err(&pdev->dev, "ioremap failed\n");
503 ret = -EIO;
504 goto fail1;
505 }
506 493
507 i2c_imx = kzalloc(sizeof(struct imx_i2c_struct), GFP_KERNEL); 494 i2c_imx = devm_kzalloc(&pdev->dev, sizeof(struct imx_i2c_struct),
495 GFP_KERNEL);
508 if (!i2c_imx) { 496 if (!i2c_imx) {
509 dev_err(&pdev->dev, "can't allocate interface\n"); 497 dev_err(&pdev->dev, "can't allocate interface\n");
510 ret = -ENOMEM; 498 return -ENOMEM;
511 goto fail2;
512 } 499 }
513 500
514 /* Setup i2c_imx driver structure */ 501 /* Setup i2c_imx driver structure */
@@ -518,29 +505,27 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
518 i2c_imx->adapter.dev.parent = &pdev->dev; 505 i2c_imx->adapter.dev.parent = &pdev->dev;
519 i2c_imx->adapter.nr = pdev->id; 506 i2c_imx->adapter.nr = pdev->id;
520 i2c_imx->adapter.dev.of_node = pdev->dev.of_node; 507 i2c_imx->adapter.dev.of_node = pdev->dev.of_node;
521 i2c_imx->irq = irq;
522 i2c_imx->base = base; 508 i2c_imx->base = base;
523 i2c_imx->res = res;
524 509
525 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 510 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
526 if (IS_ERR(pinctrl)) { 511 if (IS_ERR(pinctrl)) {
527 ret = PTR_ERR(pinctrl); 512 dev_err(&pdev->dev, "can't get/select pinctrl\n");
528 goto fail3; 513 return PTR_ERR(pinctrl);
529 } 514 }
530 515
531 /* Get I2C clock */ 516 /* Get I2C clock */
532 i2c_imx->clk = clk_get(&pdev->dev, "i2c_clk"); 517 i2c_imx->clk = devm_clk_get(&pdev->dev, "i2c_clk");
533 if (IS_ERR(i2c_imx->clk)) { 518 if (IS_ERR(i2c_imx->clk)) {
534 ret = PTR_ERR(i2c_imx->clk);
535 dev_err(&pdev->dev, "can't get I2C clock\n"); 519 dev_err(&pdev->dev, "can't get I2C clock\n");
536 goto fail3; 520 return PTR_ERR(i2c_imx->clk);
537 } 521 }
538 522
539 /* Request IRQ */ 523 /* Request IRQ */
540 ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx); 524 ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0,
525 pdev->name, i2c_imx);
541 if (ret) { 526 if (ret) {
542 dev_err(&pdev->dev, "can't claim irq %d\n", i2c_imx->irq); 527 dev_err(&pdev->dev, "can't claim irq %d\n", irq);
543 goto fail4; 528 return ret;
544 } 529 }
545 530
546 /* Init queue */ 531 /* Init queue */
@@ -565,7 +550,7 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
565 ret = i2c_add_numbered_adapter(&i2c_imx->adapter); 550 ret = i2c_add_numbered_adapter(&i2c_imx->adapter);
566 if (ret < 0) { 551 if (ret < 0) {
567 dev_err(&pdev->dev, "registration failed\n"); 552 dev_err(&pdev->dev, "registration failed\n");
568 goto fail5; 553 return ret;
569 } 554 }
570 555
571 of_i2c_register_devices(&i2c_imx->adapter); 556 of_i2c_register_devices(&i2c_imx->adapter);
@@ -573,28 +558,16 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
573 /* Set up platform driver data */ 558 /* Set up platform driver data */
574 platform_set_drvdata(pdev, i2c_imx); 559 platform_set_drvdata(pdev, i2c_imx);
575 560
576 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", i2c_imx->irq); 561 dev_dbg(&i2c_imx->adapter.dev, "claimed irq %d\n", irq);
577 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n", 562 dev_dbg(&i2c_imx->adapter.dev, "device resources from 0x%x to 0x%x\n",
578 i2c_imx->res->start, i2c_imx->res->end); 563 res->start, res->end);
579 dev_dbg(&i2c_imx->adapter.dev, "allocated %d bytes at 0x%x \n", 564 dev_dbg(&i2c_imx->adapter.dev, "allocated %d bytes at 0x%x\n",
580 res_size, i2c_imx->res->start); 565 resource_size(res), res->start);
581 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n", 566 dev_dbg(&i2c_imx->adapter.dev, "adapter name: \"%s\"\n",
582 i2c_imx->adapter.name); 567 i2c_imx->adapter.name);
583 dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n"); 568 dev_dbg(&i2c_imx->adapter.dev, "IMX I2C adapter registered\n");
584 569
585 return 0; /* Return OK */ 570 return 0; /* Return OK */
586
587fail5:
588 free_irq(i2c_imx->irq, i2c_imx);
589fail4:
590 clk_put(i2c_imx->clk);
591fail3:
592 kfree(i2c_imx);
593fail2:
594 iounmap(base);
595fail1:
596 release_mem_region(res->start, resource_size(res));
597 return ret; /* Return error number */
598} 571}
599 572
600static int __exit i2c_imx_remove(struct platform_device *pdev) 573static int __exit i2c_imx_remove(struct platform_device *pdev)
@@ -606,20 +579,12 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
606 i2c_del_adapter(&i2c_imx->adapter); 579 i2c_del_adapter(&i2c_imx->adapter);
607 platform_set_drvdata(pdev, NULL); 580 platform_set_drvdata(pdev, NULL);
608 581
609 /* free interrupt */
610 free_irq(i2c_imx->irq, i2c_imx);
611
612 /* setup chip registers to defaults */ 582 /* setup chip registers to defaults */
613 writeb(0, i2c_imx->base + IMX_I2C_IADR); 583 writeb(0, i2c_imx->base + IMX_I2C_IADR);
614 writeb(0, i2c_imx->base + IMX_I2C_IFDR); 584 writeb(0, i2c_imx->base + IMX_I2C_IFDR);
615 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 585 writeb(0, i2c_imx->base + IMX_I2C_I2CR);
616 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 586 writeb(0, i2c_imx->base + IMX_I2C_I2SR);
617 587
618 clk_put(i2c_imx->clk);
619
620 iounmap(i2c_imx->base);
621 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
622 kfree(i2c_imx);
623 return 0; 588 return 0;
624} 589}
625 590