aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/fsmc_nand.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/nand/fsmc_nand.c')
-rw-r--r--drivers/mtd/nand/fsmc_nand.c134
1 files changed, 43 insertions, 91 deletions
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index e7ae63ab59c6..56b661972122 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -298,11 +298,6 @@ struct fsmc_nand_data {
298 unsigned int bank; 298 unsigned int bank;
299 struct clk *clk; 299 struct clk *clk;
300 300
301 struct resource *resregs;
302 struct resource *rescmd;
303 struct resource *resaddr;
304 struct resource *resdata;
305
306 struct fsmc_nand_timings *dev_timings; 301 struct fsmc_nand_timings *dev_timings;
307 302
308 void __iomem *data_va; 303 void __iomem *data_va;
@@ -706,88 +701,81 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
706 } 701 }
707 702
708 /* Allocate memory for the device structure (and zero it) */ 703 /* Allocate memory for the device structure (and zero it) */
709 host = kzalloc(sizeof(*host), GFP_KERNEL); 704 host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL);
710 if (!host) { 705 if (!host) {
711 dev_err(&pdev->dev, "failed to allocate device structure\n"); 706 dev_err(&pdev->dev, "failed to allocate device structure\n");
712 return -ENOMEM; 707 return -ENOMEM;
713 } 708 }
714 709
715 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); 710 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data");
716 if (!res) { 711 if (!res)
717 ret = -EIO; 712 return -EINVAL;
718 goto err_probe1;
719 }
720 713
721 host->resdata = request_mem_region(res->start, resource_size(res), 714 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
722 pdev->name); 715 pdev->name)) {
723 if (!host->resdata) { 716 dev_err(&pdev->dev, "Failed to get memory data resourse\n");
724 ret = -EIO; 717 return -ENOENT;
725 goto err_probe1;
726 } 718 }
727 719
728 host->data_va = ioremap(res->start, resource_size(res)); 720 host->data_va = devm_ioremap(&pdev->dev, res->start,
721 resource_size(res));
729 if (!host->data_va) { 722 if (!host->data_va) {
730 ret = -EIO; 723 dev_err(&pdev->dev, "data ioremap failed\n");
731 goto err_probe1; 724 return -ENOMEM;
732 } 725 }
733 726
734 host->resaddr = request_mem_region(res->start + pdata->ale_off, 727 if (!devm_request_mem_region(&pdev->dev, res->start + pdata->ale_off,
735 resource_size(res), pdev->name); 728 resource_size(res), pdev->name)) {
736 if (!host->resaddr) { 729 dev_err(&pdev->dev, "Failed to get memory ale resourse\n");
737 ret = -EIO; 730 return -ENOENT;
738 goto err_probe1;
739 } 731 }
740 732
741 host->addr_va = ioremap(res->start + pdata->ale_off, 733 host->addr_va = devm_ioremap(&pdev->dev, res->start + pdata->ale_off,
742 resource_size(res)); 734 resource_size(res));
743 if (!host->addr_va) { 735 if (!host->addr_va) {
744 ret = -EIO; 736 dev_err(&pdev->dev, "ale ioremap failed\n");
745 goto err_probe1; 737 return -ENOMEM;
746 } 738 }
747 739
748 host->rescmd = request_mem_region(res->start + pdata->cle_off, 740 if (!devm_request_mem_region(&pdev->dev, res->start + pdata->cle_off,
749 resource_size(res), pdev->name); 741 resource_size(res), pdev->name)) {
750 if (!host->rescmd) { 742 dev_err(&pdev->dev, "Failed to get memory cle resourse\n");
751 ret = -EIO; 743 return -ENOENT;
752 goto err_probe1;
753 } 744 }
754 745
755 host->cmd_va = ioremap(res->start + pdata->cle_off, resource_size(res)); 746 host->cmd_va = devm_ioremap(&pdev->dev, res->start + pdata->cle_off,
747 resource_size(res));
756 if (!host->cmd_va) { 748 if (!host->cmd_va) {
757 ret = -EIO; 749 dev_err(&pdev->dev, "ale ioremap failed\n");
758 goto err_probe1; 750 return -ENOMEM;
759 } 751 }
760 752
761 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs"); 753 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fsmc_regs");
762 if (!res) { 754 if (!res)
763 ret = -EIO; 755 return -EINVAL;
764 goto err_probe1;
765 }
766 756
767 host->resregs = request_mem_region(res->start, resource_size(res), 757 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
768 pdev->name); 758 pdev->name)) {
769 if (!host->resregs) { 759 dev_err(&pdev->dev, "Failed to get memory regs resourse\n");
770 ret = -EIO; 760 return -ENOENT;
771 goto err_probe1;
772 } 761 }
773 762
774 host->regs_va = ioremap(res->start, resource_size(res)); 763 host->regs_va = devm_ioremap(&pdev->dev, res->start,
764 resource_size(res));
775 if (!host->regs_va) { 765 if (!host->regs_va) {
776 ret = -EIO; 766 dev_err(&pdev->dev, "regs ioremap failed\n");
777 goto err_probe1; 767 return -ENOMEM;
778 } 768 }
779 769
780 host->clk = clk_get(&pdev->dev, NULL); 770 host->clk = clk_get(&pdev->dev, NULL);
781 if (IS_ERR(host->clk)) { 771 if (IS_ERR(host->clk)) {
782 dev_err(&pdev->dev, "failed to fetch block clock\n"); 772 dev_err(&pdev->dev, "failed to fetch block clock\n");
783 ret = PTR_ERR(host->clk); 773 return PTR_ERR(host->clk);
784 host->clk = NULL;
785 goto err_probe1;
786 } 774 }
787 775
788 ret = clk_enable(host->clk); 776 ret = clk_enable(host->clk);
789 if (ret) 777 if (ret)
790 goto err_probe1; 778 goto err_clk_enable;
791 779
792 /* 780 /*
793 * This device ID is actually a common AMBA ID as used on the 781 * This device ID is actually a common AMBA ID as used on the
@@ -852,7 +840,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
852 if (nand_scan_ident(&host->mtd, 1, NULL)) { 840 if (nand_scan_ident(&host->mtd, 1, NULL)) {
853 ret = -ENXIO; 841 ret = -ENXIO;
854 dev_err(&pdev->dev, "No NAND Device found!\n"); 842 dev_err(&pdev->dev, "No NAND Device found!\n");
855 goto err_probe; 843 goto err_scan_ident;
856 } 844 }
857 845
858 if (AMBA_REV_BITS(host->pid) >= 8) { 846 if (AMBA_REV_BITS(host->pid) >= 8) {
@@ -927,32 +915,10 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
927 return 0; 915 return 0;
928 916
929err_probe: 917err_probe:
918err_scan_ident:
930 clk_disable(host->clk); 919 clk_disable(host->clk);
931err_probe1: 920err_clk_enable:
932 if (host->clk) 921 clk_put(host->clk);
933 clk_put(host->clk);
934 if (host->regs_va)
935 iounmap(host->regs_va);
936 if (host->resregs)
937 release_mem_region(host->resregs->start,
938 resource_size(host->resregs));
939 if (host->cmd_va)
940 iounmap(host->cmd_va);
941 if (host->rescmd)
942 release_mem_region(host->rescmd->start,
943 resource_size(host->rescmd));
944 if (host->addr_va)
945 iounmap(host->addr_va);
946 if (host->resaddr)
947 release_mem_region(host->resaddr->start,
948 resource_size(host->resaddr));
949 if (host->data_va)
950 iounmap(host->data_va);
951 if (host->resdata)
952 release_mem_region(host->resdata->start,
953 resource_size(host->resdata));
954
955 kfree(host);
956 return ret; 922 return ret;
957} 923}
958 924
@@ -969,22 +935,8 @@ static int fsmc_nand_remove(struct platform_device *pdev)
969 nand_release(&host->mtd); 935 nand_release(&host->mtd);
970 clk_disable(host->clk); 936 clk_disable(host->clk);
971 clk_put(host->clk); 937 clk_put(host->clk);
972
973 iounmap(host->regs_va);
974 release_mem_region(host->resregs->start,
975 resource_size(host->resregs));
976 iounmap(host->cmd_va);
977 release_mem_region(host->rescmd->start,
978 resource_size(host->rescmd));
979 iounmap(host->addr_va);
980 release_mem_region(host->resaddr->start,
981 resource_size(host->resaddr));
982 iounmap(host->data_va);
983 release_mem_region(host->resdata->start,
984 resource_size(host->resdata));
985
986 kfree(host);
987 } 938 }
939
988 return 0; 940 return 0;
989} 941}
990 942