diff options
author | Kedareswara rao Appana <appana.durga.rao@xilinx.com> | 2013-12-19 10:05:06 -0500 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-01-04 17:35:02 -0500 |
commit | 168e722dcb9acb77a703080d59d47d9ac3958278 (patch) | |
tree | b3518091a97745414bbd0d5439c45f91654e851b /drivers/i2c | |
parent | 617bdcbc3cb2c828771c2632bd8d57f7df5eea5c (diff) |
i2c: xilinx: Use devm_* functions
Simplified the probe and remove functions using devm_* functions
Signed-off-by: Kedareswara rao Appana <appanad@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/busses/i2c-xiic.c | 65 |
1 files changed, 15 insertions, 50 deletions
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 2d559896c678..6f9918f37b91 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/module.h> | 32 | #include <linux/module.h> |
33 | #include <linux/init.h> | 33 | #include <linux/init.h> |
34 | #include <linux/errno.h> | 34 | #include <linux/errno.h> |
35 | #include <linux/err.h> | ||
35 | #include <linux/delay.h> | 36 | #include <linux/delay.h> |
36 | #include <linux/platform_device.h> | 37 | #include <linux/platform_device.h> |
37 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
@@ -697,33 +698,21 @@ static int xiic_i2c_probe(struct platform_device *pdev) | |||
697 | int ret, irq; | 698 | int ret, irq; |
698 | u8 i; | 699 | u8 i; |
699 | 700 | ||
701 | i2c = devm_kzalloc(&pdev->dev, sizeof(*i2c), GFP_KERNEL); | ||
702 | if (!i2c) | ||
703 | return -ENOMEM; | ||
704 | |||
700 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 705 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
701 | if (!res) | 706 | i2c->base = devm_ioremap_resource(&pdev->dev, res); |
702 | goto resource_missing; | 707 | if (IS_ERR(i2c->base)) |
708 | return PTR_ERR(i2c->base); | ||
703 | 709 | ||
704 | irq = platform_get_irq(pdev, 0); | 710 | irq = platform_get_irq(pdev, 0); |
705 | if (irq < 0) | 711 | if (irq < 0) |
706 | goto resource_missing; | 712 | return irq; |
707 | 713 | ||
708 | pdata = dev_get_platdata(&pdev->dev); | 714 | pdata = dev_get_platdata(&pdev->dev); |
709 | 715 | ||
710 | i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); | ||
711 | if (!i2c) | ||
712 | return -ENOMEM; | ||
713 | |||
714 | if (!request_mem_region(res->start, resource_size(res), pdev->name)) { | ||
715 | dev_err(&pdev->dev, "Memory region busy\n"); | ||
716 | ret = -EBUSY; | ||
717 | goto request_mem_failed; | ||
718 | } | ||
719 | |||
720 | i2c->base = ioremap(res->start, resource_size(res)); | ||
721 | if (!i2c->base) { | ||
722 | dev_err(&pdev->dev, "Unable to map registers\n"); | ||
723 | ret = -EIO; | ||
724 | goto map_failed; | ||
725 | } | ||
726 | |||
727 | /* hook up driver to tree */ | 716 | /* hook up driver to tree */ |
728 | platform_set_drvdata(pdev, i2c); | 717 | platform_set_drvdata(pdev, i2c); |
729 | i2c->adap = xiic_adapter; | 718 | i2c->adap = xiic_adapter; |
@@ -733,10 +722,11 @@ static int xiic_i2c_probe(struct platform_device *pdev) | |||
733 | 722 | ||
734 | spin_lock_init(&i2c->lock); | 723 | spin_lock_init(&i2c->lock); |
735 | init_waitqueue_head(&i2c->wait); | 724 | init_waitqueue_head(&i2c->wait); |
736 | ret = request_irq(irq, xiic_isr, 0, pdev->name, i2c); | 725 | |
737 | if (ret) { | 726 | ret = devm_request_irq(&pdev->dev, irq, xiic_isr, 0, pdev->name, i2c); |
727 | if (ret < 0) { | ||
738 | dev_err(&pdev->dev, "Cannot claim IRQ\n"); | 728 | dev_err(&pdev->dev, "Cannot claim IRQ\n"); |
739 | goto request_irq_failed; | 729 | return ret; |
740 | } | 730 | } |
741 | 731 | ||
742 | xiic_reinit(i2c); | 732 | xiic_reinit(i2c); |
@@ -745,7 +735,8 @@ static int xiic_i2c_probe(struct platform_device *pdev) | |||
745 | ret = i2c_add_adapter(&i2c->adap); | 735 | ret = i2c_add_adapter(&i2c->adap); |
746 | if (ret) { | 736 | if (ret) { |
747 | dev_err(&pdev->dev, "Failed to add adapter\n"); | 737 | dev_err(&pdev->dev, "Failed to add adapter\n"); |
748 | goto add_adapter_failed; | 738 | xiic_deinit(i2c); |
739 | return ret; | ||
749 | } | 740 | } |
750 | 741 | ||
751 | if (pdata) { | 742 | if (pdata) { |
@@ -755,43 +746,17 @@ static int xiic_i2c_probe(struct platform_device *pdev) | |||
755 | } | 746 | } |
756 | 747 | ||
757 | return 0; | 748 | return 0; |
758 | |||
759 | add_adapter_failed: | ||
760 | free_irq(irq, i2c); | ||
761 | request_irq_failed: | ||
762 | xiic_deinit(i2c); | ||
763 | iounmap(i2c->base); | ||
764 | map_failed: | ||
765 | release_mem_region(res->start, resource_size(res)); | ||
766 | request_mem_failed: | ||
767 | kfree(i2c); | ||
768 | |||
769 | return ret; | ||
770 | resource_missing: | ||
771 | dev_err(&pdev->dev, "IRQ or Memory resource is missing\n"); | ||
772 | return -ENOENT; | ||
773 | } | 749 | } |
774 | 750 | ||
775 | static int xiic_i2c_remove(struct platform_device *pdev) | 751 | static int xiic_i2c_remove(struct platform_device *pdev) |
776 | { | 752 | { |
777 | struct xiic_i2c *i2c = platform_get_drvdata(pdev); | 753 | struct xiic_i2c *i2c = platform_get_drvdata(pdev); |
778 | struct resource *res; | ||
779 | 754 | ||
780 | /* remove adapter & data */ | 755 | /* remove adapter & data */ |
781 | i2c_del_adapter(&i2c->adap); | 756 | i2c_del_adapter(&i2c->adap); |
782 | 757 | ||
783 | xiic_deinit(i2c); | 758 | xiic_deinit(i2c); |
784 | 759 | ||
785 | free_irq(platform_get_irq(pdev, 0), i2c); | ||
786 | |||
787 | iounmap(i2c->base); | ||
788 | |||
789 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
790 | if (res) | ||
791 | release_mem_region(res->start, resource_size(res)); | ||
792 | |||
793 | kfree(i2c); | ||
794 | |||
795 | return 0; | 760 | return 0; |
796 | } | 761 | } |
797 | 762 | ||