aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2014-09-28 16:36:54 -0400
committerBrian Norris <computersforpeace@gmail.com>2014-09-28 18:27:03 -0400
commit32f1b7c8352fd33d41bcec3cfb054ccdcfd40a42 (patch)
tree2d00a33a1d12b52cc13d4be89e4072973d27e771
parent57cf26c1b28572976c57f6dec9818be38bf37cbb (diff)
mtd: move support for struct flash_platform_data into m25p80
This "type" seems to be an extra hint for m25p80 about the flash. Some archs register flash_platform_data with "name" set to "m25p80" and then with a real flash name set in "type". It seems to be a trick specific to the m25p80 so let's move it out of spi-nor. Btw switch to the spi_nor_match_id instead of iterating spi_nor_ids. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r--drivers/mtd/devices/m25p80.c22
-rw-r--r--drivers/mtd/spi-nor/spi-nor.c28
2 files changed, 21 insertions, 29 deletions
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index ed7e0a1bed3c..dcda6287228d 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -193,11 +193,14 @@ static int m25p_probe(struct spi_device *spi)
193{ 193{
194 struct mtd_part_parser_data ppdata; 194 struct mtd_part_parser_data ppdata;
195 struct flash_platform_data *data; 195 struct flash_platform_data *data;
196 const struct spi_device_id *id = NULL;
196 struct m25p *flash; 197 struct m25p *flash;
197 struct spi_nor *nor; 198 struct spi_nor *nor;
198 enum read_mode mode = SPI_NOR_NORMAL; 199 enum read_mode mode = SPI_NOR_NORMAL;
199 int ret; 200 int ret;
200 201
202 data = dev_get_platdata(&spi->dev);
203
201 flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); 204 flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL);
202 if (!flash) 205 if (!flash)
203 return -ENOMEM; 206 return -ENOMEM;
@@ -223,11 +226,26 @@ static int m25p_probe(struct spi_device *spi)
223 mode = SPI_NOR_QUAD; 226 mode = SPI_NOR_QUAD;
224 else if (spi->mode & SPI_RX_DUAL) 227 else if (spi->mode & SPI_RX_DUAL)
225 mode = SPI_NOR_DUAL; 228 mode = SPI_NOR_DUAL;
226 ret = spi_nor_scan(nor, spi_get_device_id(spi), mode); 229
230 if (data && data->name)
231 flash->mtd.name = data->name;
232
233 /* For some (historical?) reason many platforms provide two different
234 * names in flash_platform_data: "name" and "type". Quite often name is
235 * set to "m25p80" and then "type" provides a real chip name.
236 * If that's the case, respect "type" and ignore a "name".
237 */
238 if (data && data->type)
239 id = spi_nor_match_id(data->type);
240
241 /* If we didn't get name from platform, simply use "modalias". */
242 if (!id)
243 id = spi_get_device_id(spi);
244
245 ret = spi_nor_scan(nor, id, mode);
227 if (ret) 246 if (ret)
228 return ret; 247 return ret;
229 248
230 data = dev_get_platdata(&spi->dev);
231 ppdata.of_node = spi->dev.of_node; 249 ppdata.of_node = spi->dev.of_node;
232 250
233 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata, 251 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 11459f6cee50..ae16aa2f6885 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -915,7 +915,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
915 enum read_mode mode) 915 enum read_mode mode)
916{ 916{
917 struct flash_info *info; 917 struct flash_info *info;
918 struct flash_platform_data *data;
919 struct device *dev = nor->dev; 918 struct device *dev = nor->dev;
920 struct mtd_info *mtd = nor->mtd; 919 struct mtd_info *mtd = nor->mtd;
921 struct device_node *np = dev->of_node; 920 struct device_node *np = dev->of_node;
@@ -926,28 +925,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
926 if (ret) 925 if (ret)
927 return ret; 926 return ret;
928 927
929 /* Platform data helps sort out which chip type we have, as
930 * well as how this board partitions it. If we don't have
931 * a chip ID, try the JEDEC id commands; they'll work for most
932 * newer chips, even if we don't recognize the particular chip.
933 */
934 data = dev_get_platdata(dev);
935 if (data && data->type) {
936 const struct spi_device_id *plat_id;
937
938 for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) {
939 plat_id = &spi_nor_ids[i];
940 if (strcmp(data->type, plat_id->name))
941 continue;
942 break;
943 }
944
945 if (i < ARRAY_SIZE(spi_nor_ids) - 1)
946 id = plat_id;
947 else
948 dev_warn(dev, "unrecognized id %s\n", data->type);
949 }
950
951 info = (void *)id->driver_data; 928 info = (void *)id->driver_data;
952 929
953 if (info->jedec_id) { 930 if (info->jedec_id) {
@@ -985,11 +962,8 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,
985 write_sr(nor, 0); 962 write_sr(nor, 0);
986 } 963 }
987 964
988 if (data && data->name) 965 if (!mtd->name)
989 mtd->name = data->name;
990 else
991 mtd->name = dev_name(dev); 966 mtd->name = dev_name(dev);
992
993 mtd->type = MTD_NORFLASH; 967 mtd->type = MTD_NORFLASH;
994 mtd->writesize = 1; 968 mtd->writesize = 1;
995 mtd->flags = MTD_CAP_NORFLASH; 969 mtd->flags = MTD_CAP_NORFLASH;