diff options
author | Thomas Petazzoni <thomas.petazzoni@free-electrons.com> | 2017-03-21 06:04:02 -0400 |
---|---|---|
committer | Boris Brezillon <boris.brezillon@free-electrons.com> | 2017-03-23 06:11:27 -0400 |
commit | a1b1e1d5bdfe79e3d3b28387dd43bb16531be5a4 (patch) | |
tree | ff603134b7728d4168314ba6c704131d8d39db76 | |
parent | c0d218c81621d847472e01f227eab3e4f0902ce2 (diff) |
mtd: nand: fsmc: finally remove fsmc_nand_platform_data
Since the driver now only supports DT probing, it doesn't make a lot of
sense to have a private data structure called platform_data, fill it in
with information coming from the DT, and then copying this into the
driver-specific structure fsmc_nand_data.
So instead, we remove fsmc_nand_platform_data entirely, and have
fsmc_nand_probe_config_dt() fill in the fsmc_nand_data structure
directly.
This requires calling fsmc_nand_probe_config_dt() after fsmc_nand_data
has been allocated instead of before.
Also, as an added bonus, we now propagate properly the return value of
fsmc_nand_probe_config_dt() instead of returning -ENODEV on failure. The
error message is also removed, since it no longer made any sense.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
-rw-r--r-- | drivers/mtd/nand/fsmc_nand.c | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c index 63055d7dcfef..4c6e239dcee8 100644 --- a/drivers/mtd/nand/fsmc_nand.c +++ b/drivers/mtd/nand/fsmc_nand.c | |||
@@ -133,26 +133,6 @@ enum access_mode { | |||
133 | }; | 133 | }; |
134 | 134 | ||
135 | /** | 135 | /** |
136 | * fsmc_nand_platform_data - platform specific NAND controller config | ||
137 | * @nand_timings: timing setup for the physical NAND interface | ||
138 | * @partitions: partition table for the platform, use a default fallback | ||
139 | * if this is NULL | ||
140 | * @nr_partitions: the number of partitions in the previous entry | ||
141 | * @options: different options for the driver | ||
142 | * @width: bus width | ||
143 | * @bank: default bank | ||
144 | * platform-specific. If the controller only supports one bank | ||
145 | * this may be set to NULL | ||
146 | */ | ||
147 | struct fsmc_nand_platform_data { | ||
148 | struct fsmc_nand_timings *nand_timings; | ||
149 | unsigned int options; | ||
150 | unsigned int bank; | ||
151 | |||
152 | enum access_mode mode; | ||
153 | }; | ||
154 | |||
155 | /** | ||
156 | * struct fsmc_nand_data - structure for FSMC NAND device state | 136 | * struct fsmc_nand_data - structure for FSMC NAND device state |
157 | * | 137 | * |
158 | * @pid: Part ID on the AMBA PrimeCell format | 138 | * @pid: Part ID on the AMBA PrimeCell format |
@@ -798,17 +778,18 @@ static bool filter(struct dma_chan *chan, void *slave) | |||
798 | } | 778 | } |
799 | 779 | ||
800 | static int fsmc_nand_probe_config_dt(struct platform_device *pdev, | 780 | static int fsmc_nand_probe_config_dt(struct platform_device *pdev, |
801 | struct device_node *np) | 781 | struct fsmc_nand_data *host, |
782 | struct nand_chip *nand) | ||
802 | { | 783 | { |
803 | struct fsmc_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); | 784 | struct device_node *np = pdev->dev.of_node; |
804 | u32 val; | 785 | u32 val; |
805 | int ret; | 786 | int ret; |
806 | 787 | ||
807 | pdata->options = 0; | 788 | nand->options = 0; |
808 | 789 | ||
809 | if (!of_property_read_u32(np, "bank-width", &val)) { | 790 | if (!of_property_read_u32(np, "bank-width", &val)) { |
810 | if (val == 2) { | 791 | if (val == 2) { |
811 | pdata->options |= NAND_BUSWIDTH_16; | 792 | nand->options |= NAND_BUSWIDTH_16; |
812 | } else if (val != 1) { | 793 | } else if (val != 1) { |
813 | dev_err(&pdev->dev, "invalid bank-width %u\n", val); | 794 | dev_err(&pdev->dev, "invalid bank-width %u\n", val); |
814 | return -EINVAL; | 795 | return -EINVAL; |
@@ -816,27 +797,27 @@ static int fsmc_nand_probe_config_dt(struct platform_device *pdev, | |||
816 | } | 797 | } |
817 | 798 | ||
818 | if (of_get_property(np, "nand-skip-bbtscan", NULL)) | 799 | if (of_get_property(np, "nand-skip-bbtscan", NULL)) |
819 | pdata->options |= NAND_SKIP_BBTSCAN; | 800 | nand->options |= NAND_SKIP_BBTSCAN; |
820 | 801 | ||
821 | pdata->nand_timings = devm_kzalloc(&pdev->dev, | 802 | host->dev_timings = devm_kzalloc(&pdev->dev, |
822 | sizeof(*pdata->nand_timings), GFP_KERNEL); | 803 | sizeof(*host->dev_timings), GFP_KERNEL); |
823 | if (!pdata->nand_timings) | 804 | if (!host->dev_timings) |
824 | return -ENOMEM; | 805 | return -ENOMEM; |
825 | ret = of_property_read_u8_array(np, "timings", (u8 *)pdata->nand_timings, | 806 | ret = of_property_read_u8_array(np, "timings", (u8 *)host->dev_timings, |
826 | sizeof(*pdata->nand_timings)); | 807 | sizeof(*host->dev_timings)); |
827 | if (ret) { | 808 | if (ret) { |
828 | dev_info(&pdev->dev, "No timings in dts specified, using default timings!\n"); | 809 | dev_info(&pdev->dev, "No timings in dts specified, using default timings!\n"); |
829 | pdata->nand_timings = NULL; | 810 | host->dev_timings = NULL; |
830 | } | 811 | } |
831 | 812 | ||
832 | /* Set default NAND bank to 0 */ | 813 | /* Set default NAND bank to 0 */ |
833 | pdata->bank = 0; | 814 | host->bank = 0; |
834 | if (!of_property_read_u32(np, "bank", &val)) { | 815 | if (!of_property_read_u32(np, "bank", &val)) { |
835 | if (val > 3) { | 816 | if (val > 3) { |
836 | dev_err(&pdev->dev, "invalid bank %u\n", val); | 817 | dev_err(&pdev->dev, "invalid bank %u\n", val); |
837 | return -EINVAL; | 818 | return -EINVAL; |
838 | } | 819 | } |
839 | pdata->bank = val; | 820 | host->bank = val; |
840 | } | 821 | } |
841 | return 0; | 822 | return 0; |
842 | } | 823 | } |
@@ -847,8 +828,6 @@ static int fsmc_nand_probe_config_dt(struct platform_device *pdev, | |||
847 | */ | 828 | */ |
848 | static int __init fsmc_nand_probe(struct platform_device *pdev) | 829 | static int __init fsmc_nand_probe(struct platform_device *pdev) |
849 | { | 830 | { |
850 | struct fsmc_nand_platform_data *pdata = dev_get_platdata(&pdev->dev); | ||
851 | struct device_node __maybe_unused *np = pdev->dev.of_node; | ||
852 | struct fsmc_nand_data *host; | 831 | struct fsmc_nand_data *host; |
853 | struct mtd_info *mtd; | 832 | struct mtd_info *mtd; |
854 | struct nand_chip *nand; | 833 | struct nand_chip *nand; |
@@ -858,22 +837,17 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) | |||
858 | u32 pid; | 837 | u32 pid; |
859 | int i; | 838 | int i; |
860 | 839 | ||
861 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
862 | if (!pdata) | ||
863 | return -ENOMEM; | ||
864 | |||
865 | pdev->dev.platform_data = pdata; | ||
866 | ret = fsmc_nand_probe_config_dt(pdev, np); | ||
867 | if (ret) { | ||
868 | dev_err(&pdev->dev, "no platform data\n"); | ||
869 | return -ENODEV; | ||
870 | } | ||
871 | |||
872 | /* Allocate memory for the device structure (and zero it) */ | 840 | /* Allocate memory for the device structure (and zero it) */ |
873 | host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); | 841 | host = devm_kzalloc(&pdev->dev, sizeof(*host), GFP_KERNEL); |
874 | if (!host) | 842 | if (!host) |
875 | return -ENOMEM; | 843 | return -ENOMEM; |
876 | 844 | ||
845 | nand = &host->nand; | ||
846 | |||
847 | ret = fsmc_nand_probe_config_dt(pdev, host, nand); | ||
848 | if (ret) | ||
849 | return ret; | ||
850 | |||
877 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); | 851 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand_data"); |
878 | host->data_va = devm_ioremap_resource(&pdev->dev, res); | 852 | host->data_va = devm_ioremap_resource(&pdev->dev, res); |
879 | if (IS_ERR(host->data_va)) | 853 | if (IS_ERR(host->data_va)) |
@@ -918,19 +892,15 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) | |||
918 | AMBA_PART_BITS(pid), AMBA_MANF_BITS(pid), | 892 | AMBA_PART_BITS(pid), AMBA_MANF_BITS(pid), |
919 | AMBA_REV_BITS(pid), AMBA_CONFIG_BITS(pid)); | 893 | AMBA_REV_BITS(pid), AMBA_CONFIG_BITS(pid)); |
920 | 894 | ||
921 | host->bank = pdata->bank; | ||
922 | host->dev = &pdev->dev; | 895 | host->dev = &pdev->dev; |
923 | host->dev_timings = pdata->nand_timings; | ||
924 | host->mode = pdata->mode; | ||
925 | 896 | ||
926 | if (host->mode == USE_DMA_ACCESS) | 897 | if (host->mode == USE_DMA_ACCESS) |
927 | init_completion(&host->dma_access_complete); | 898 | init_completion(&host->dma_access_complete); |
928 | 899 | ||
929 | /* Link all private pointers */ | 900 | /* Link all private pointers */ |
930 | mtd = nand_to_mtd(&host->nand); | 901 | mtd = nand_to_mtd(&host->nand); |
931 | nand = &host->nand; | ||
932 | nand_set_controller_data(nand, host); | 902 | nand_set_controller_data(nand, host); |
933 | nand_set_flash_node(nand, np); | 903 | nand_set_flash_node(nand, pdev->dev.of_node); |
934 | 904 | ||
935 | mtd->dev.parent = &pdev->dev; | 905 | mtd->dev.parent = &pdev->dev; |
936 | nand->IO_ADDR_R = host->data_va; | 906 | nand->IO_ADDR_R = host->data_va; |
@@ -945,7 +915,6 @@ static int __init fsmc_nand_probe(struct platform_device *pdev) | |||
945 | nand->ecc.mode = NAND_ECC_HW; | 915 | nand->ecc.mode = NAND_ECC_HW; |
946 | nand->ecc.hwctl = fsmc_enable_hwecc; | 916 | nand->ecc.hwctl = fsmc_enable_hwecc; |
947 | nand->ecc.size = 512; | 917 | nand->ecc.size = 512; |
948 | nand->options = pdata->options; | ||
949 | nand->badblockbits = 7; | 918 | nand->badblockbits = 7; |
950 | 919 | ||
951 | switch (host->mode) { | 920 | switch (host->mode) { |