aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mmc
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2012-05-05 23:20:40 -0400
committerShawn Guo <shawn.guo@linaro.org>2012-05-12 20:05:45 -0400
commitdf06bfc724b58d649eef4bf51a953c7aeed9635f (patch)
treeb5b41a6902540546b92c307fa4dc323b6d2b3bea /drivers/mmc
parent81f38ee8e6a9472193337da248c30963a9741a30 (diff)
mmc: mxs-mmc: use devm_* helper to make cleanup simpler
Use devm_request_and_ioremap and devm_request_irq helpers to clean up the code a little bit. Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Marek Vasut <marex@denx.de> Acked-by: Chris Ball <cjb@laptop.org>
Diffstat (limited to 'drivers/mmc')
-rw-r--r--drivers/mmc/host/mxs-mmc.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/drivers/mmc/host/mxs-mmc.c b/drivers/mmc/host/mxs-mmc.c
index 5343190bb9d9..d2729e117ae1 100644
--- a/drivers/mmc/host/mxs-mmc.c
+++ b/drivers/mmc/host/mxs-mmc.c
@@ -146,8 +146,6 @@ struct mxs_mmc_host {
146 struct mmc_data *data; 146 struct mmc_data *data;
147 147
148 void __iomem *base; 148 void __iomem *base;
149 int irq;
150 struct resource *res;
151 struct resource *dma_res; 149 struct resource *dma_res;
152 struct clk *clk; 150 struct clk *clk;
153 unsigned int clk_rate; 151 unsigned int clk_rate;
@@ -695,7 +693,7 @@ static int mxs_mmc_probe(struct platform_device *pdev)
695{ 693{
696 struct mxs_mmc_host *host; 694 struct mxs_mmc_host *host;
697 struct mmc_host *mmc; 695 struct mmc_host *mmc;
698 struct resource *iores, *dmares, *r; 696 struct resource *iores, *dmares;
699 struct mxs_mmc_platform_data *pdata; 697 struct mxs_mmc_platform_data *pdata;
700 struct pinctrl *pinctrl; 698 struct pinctrl *pinctrl;
701 int ret = 0, irq_err, irq_dma; 699 int ret = 0, irq_err, irq_dma;
@@ -708,28 +706,20 @@ static int mxs_mmc_probe(struct platform_device *pdev)
708 if (!iores || !dmares || irq_err < 0 || irq_dma < 0) 706 if (!iores || !dmares || irq_err < 0 || irq_dma < 0)
709 return -EINVAL; 707 return -EINVAL;
710 708
711 r = request_mem_region(iores->start, resource_size(iores), pdev->name);
712 if (!r)
713 return -EBUSY;
714
715 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev); 709 mmc = mmc_alloc_host(sizeof(struct mxs_mmc_host), &pdev->dev);
716 if (!mmc) { 710 if (!mmc)
717 ret = -ENOMEM; 711 return -ENOMEM;
718 goto out_release_mem;
719 }
720 712
721 host = mmc_priv(mmc); 713 host = mmc_priv(mmc);
722 host->base = ioremap(r->start, resource_size(r)); 714 host->base = devm_request_and_ioremap(&pdev->dev, iores);
723 if (!host->base) { 715 if (!host->base) {
724 ret = -ENOMEM; 716 ret = -EADDRNOTAVAIL;
725 goto out_mmc_free; 717 goto out_mmc_free;
726 } 718 }
727 719
728 host->devid = pdev->id_entry->driver_data; 720 host->devid = pdev->id_entry->driver_data;
729 host->mmc = mmc; 721 host->mmc = mmc;
730 host->res = r;
731 host->dma_res = dmares; 722 host->dma_res = dmares;
732 host->irq = irq_err;
733 host->sdio_irq_en = 0; 723 host->sdio_irq_en = 0;
734 724
735 pinctrl = devm_pinctrl_get_select_default(&pdev->dev); 725 pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
@@ -741,7 +731,7 @@ static int mxs_mmc_probe(struct platform_device *pdev)
741 host->clk = clk_get(&pdev->dev, NULL); 731 host->clk = clk_get(&pdev->dev, NULL);
742 if (IS_ERR(host->clk)) { 732 if (IS_ERR(host->clk)) {
743 ret = PTR_ERR(host->clk); 733 ret = PTR_ERR(host->clk);
744 goto out_iounmap; 734 goto out_mmc_free;
745 } 735 }
746 clk_prepare_enable(host->clk); 736 clk_prepare_enable(host->clk);
747 737
@@ -782,7 +772,8 @@ static int mxs_mmc_probe(struct platform_device *pdev)
782 772
783 platform_set_drvdata(pdev, mmc); 773 platform_set_drvdata(pdev, mmc);
784 774
785 ret = request_irq(host->irq, mxs_mmc_irq_handler, 0, DRIVER_NAME, host); 775 ret = devm_request_irq(&pdev->dev, irq_err, mxs_mmc_irq_handler, 0,
776 DRIVER_NAME, host);
786 if (ret) 777 if (ret)
787 goto out_free_dma; 778 goto out_free_dma;
788 779
@@ -790,26 +781,20 @@ static int mxs_mmc_probe(struct platform_device *pdev)
790 781
791 ret = mmc_add_host(mmc); 782 ret = mmc_add_host(mmc);
792 if (ret) 783 if (ret)
793 goto out_free_irq; 784 goto out_free_dma;
794 785
795 dev_info(mmc_dev(host->mmc), "initialized\n"); 786 dev_info(mmc_dev(host->mmc), "initialized\n");
796 787
797 return 0; 788 return 0;
798 789
799out_free_irq:
800 free_irq(host->irq, host);
801out_free_dma: 790out_free_dma:
802 if (host->dmach) 791 if (host->dmach)
803 dma_release_channel(host->dmach); 792 dma_release_channel(host->dmach);
804out_clk_put: 793out_clk_put:
805 clk_disable_unprepare(host->clk); 794 clk_disable_unprepare(host->clk);
806 clk_put(host->clk); 795 clk_put(host->clk);
807out_iounmap:
808 iounmap(host->base);
809out_mmc_free: 796out_mmc_free:
810 mmc_free_host(mmc); 797 mmc_free_host(mmc);
811out_release_mem:
812 release_mem_region(iores->start, resource_size(iores));
813 return ret; 798 return ret;
814} 799}
815 800
@@ -817,12 +802,9 @@ static int mxs_mmc_remove(struct platform_device *pdev)
817{ 802{
818 struct mmc_host *mmc = platform_get_drvdata(pdev); 803 struct mmc_host *mmc = platform_get_drvdata(pdev);
819 struct mxs_mmc_host *host = mmc_priv(mmc); 804 struct mxs_mmc_host *host = mmc_priv(mmc);
820 struct resource *res = host->res;
821 805
822 mmc_remove_host(mmc); 806 mmc_remove_host(mmc);
823 807
824 free_irq(host->irq, host);
825
826 platform_set_drvdata(pdev, NULL); 808 platform_set_drvdata(pdev, NULL);
827 809
828 if (host->dmach) 810 if (host->dmach)
@@ -831,12 +813,8 @@ static int mxs_mmc_remove(struct platform_device *pdev)
831 clk_disable_unprepare(host->clk); 813 clk_disable_unprepare(host->clk);
832 clk_put(host->clk); 814 clk_put(host->clk);
833 815
834 iounmap(host->base);
835
836 mmc_free_host(mmc); 816 mmc_free_host(mmc);
837 817
838 release_mem_region(res->start, resource_size(res));
839
840 return 0; 818 return 0;
841} 819}
842 820