aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorVishwanathrao Badarkhe, Manish <manishv.b@ti.com>2013-03-04 20:44:45 -0500
committerWolfram Sang <wsa@the-dreams.de>2013-03-29 07:16:25 -0400
commit857968434bb6dbda0911f38ec46b0c3d0c963771 (patch)
treed4ba5ea19449444c192607fde5454b87e59dfbe2 /drivers/i2c/busses
parentadf68acf387a203d76315d72b36b829bde1d01b6 (diff)
i2c: davinci: update to devm_* API
Update the code to use devm_* API so that driver core will manage resources. Signed-off-by: Vishwanathrao Badarkhe, Manish <manishv.b@ti.com> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-davinci.c48
1 files changed, 14 insertions, 34 deletions
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 61f793b8789e..c01edacbfe33 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -643,7 +643,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
643{ 643{
644 struct davinci_i2c_dev *dev; 644 struct davinci_i2c_dev *dev;
645 struct i2c_adapter *adap; 645 struct i2c_adapter *adap;
646 struct resource *mem, *irq, *ioarea; 646 struct resource *mem, *irq;
647 int r; 647 int r;
648 648
649 /* NOTE: driver uses the static register mapping */ 649 /* NOTE: driver uses the static register mapping */
@@ -659,17 +659,11 @@ static int davinci_i2c_probe(struct platform_device *pdev)
659 return -ENODEV; 659 return -ENODEV;
660 } 660 }
661 661
662 ioarea = request_mem_region(mem->start, resource_size(mem), 662 dev = devm_kzalloc(&pdev->dev, sizeof(struct davinci_i2c_dev),
663 pdev->name); 663 GFP_KERNEL);
664 if (!ioarea) {
665 dev_err(&pdev->dev, "I2C region already claimed\n");
666 return -EBUSY;
667 }
668
669 dev = kzalloc(sizeof(struct davinci_i2c_dev), GFP_KERNEL);
670 if (!dev) { 664 if (!dev) {
671 r = -ENOMEM; 665 dev_err(&pdev->dev, "Memory allocation failed\n");
672 goto err_release_region; 666 return -ENOMEM;
673 } 667 }
674 668
675 init_completion(&dev->cmd_complete); 669 init_completion(&dev->cmd_complete);
@@ -699,22 +693,23 @@ static int davinci_i2c_probe(struct platform_device *pdev)
699 dev->pdata = &davinci_i2c_platform_data_default; 693 dev->pdata = &davinci_i2c_platform_data_default;
700 } 694 }
701 695
702 dev->clk = clk_get(&pdev->dev, NULL); 696 dev->clk = devm_clk_get(&pdev->dev, NULL);
703 if (IS_ERR(dev->clk)) { 697 if (IS_ERR(dev->clk)) {
704 r = -ENODEV; 698 r = -ENODEV;
705 goto err_free_mem; 699 goto err_free_mem;
706 } 700 }
707 clk_prepare_enable(dev->clk); 701 clk_prepare_enable(dev->clk);
708 702
709 dev->base = ioremap(mem->start, resource_size(mem)); 703 dev->base = devm_ioremap_resource(&pdev->dev, mem);
710 if (!dev->base) { 704 if (IS_ERR(dev->base)) {
711 r = -EBUSY; 705 r = PTR_ERR(dev->base);
712 goto err_mem_ioremap; 706 goto err_unuse_clocks;
713 } 707 }
714 708
715 i2c_davinci_init(dev); 709 i2c_davinci_init(dev);
716 710
717 r = request_irq(dev->irq, i2c_davinci_isr, 0, pdev->name, dev); 711 r = devm_request_irq(&pdev->dev, dev->irq, i2c_davinci_isr, 0,
712 pdev->name, dev);
718 if (r) { 713 if (r) {
719 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 714 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
720 goto err_unuse_clocks; 715 goto err_unuse_clocks;
@@ -723,7 +718,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
723 r = i2c_davinci_cpufreq_register(dev); 718 r = i2c_davinci_cpufreq_register(dev);
724 if (r) { 719 if (r) {
725 dev_err(&pdev->dev, "failed to register cpufreq\n"); 720 dev_err(&pdev->dev, "failed to register cpufreq\n");
726 goto err_free_irq; 721 goto err_unuse_clocks;
727 } 722 }
728 723
729 adap = &dev->adapter; 724 adap = &dev->adapter;
@@ -740,25 +735,17 @@ static int davinci_i2c_probe(struct platform_device *pdev)
740 r = i2c_add_numbered_adapter(adap); 735 r = i2c_add_numbered_adapter(adap);
741 if (r) { 736 if (r) {
742 dev_err(&pdev->dev, "failure adding adapter\n"); 737 dev_err(&pdev->dev, "failure adding adapter\n");
743 goto err_free_irq; 738 goto err_unuse_clocks;
744 } 739 }
745 of_i2c_register_devices(adap); 740 of_i2c_register_devices(adap);
746 741
747 return 0; 742 return 0;
748 743
749err_free_irq:
750 free_irq(dev->irq, dev);
751err_unuse_clocks: 744err_unuse_clocks:
752 iounmap(dev->base);
753err_mem_ioremap:
754 clk_disable_unprepare(dev->clk); 745 clk_disable_unprepare(dev->clk);
755 clk_put(dev->clk);
756 dev->clk = NULL; 746 dev->clk = NULL;
757err_free_mem: 747err_free_mem:
758 put_device(&pdev->dev); 748 put_device(&pdev->dev);
759 kfree(dev);
760err_release_region:
761 release_mem_region(mem->start, resource_size(mem));
762 749
763 return r; 750 return r;
764} 751}
@@ -766,7 +753,6 @@ err_release_region:
766static int davinci_i2c_remove(struct platform_device *pdev) 753static int davinci_i2c_remove(struct platform_device *pdev)
767{ 754{
768 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); 755 struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
769 struct resource *mem;
770 756
771 i2c_davinci_cpufreq_deregister(dev); 757 i2c_davinci_cpufreq_deregister(dev);
772 758
@@ -774,16 +760,10 @@ static int davinci_i2c_remove(struct platform_device *pdev)
774 put_device(&pdev->dev); 760 put_device(&pdev->dev);
775 761
776 clk_disable_unprepare(dev->clk); 762 clk_disable_unprepare(dev->clk);
777 clk_put(dev->clk);
778 dev->clk = NULL; 763 dev->clk = NULL;
779 764
780 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0); 765 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, 0);
781 free_irq(dev->irq, dev);
782 iounmap(dev->base);
783 kfree(dev);
784 766
785 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
786 release_mem_region(mem->start, resource_size(mem));
787 return 0; 767 return 0;
788} 768}
789 769