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>

authored by

Rafał Miłecki and committed by
Brian Norris
32f1b7c8 57cf26c1

+21 -29
+20 -2
drivers/mtd/devices/m25p80.c
··· 193 193 { 194 194 struct mtd_part_parser_data ppdata; 195 195 struct flash_platform_data *data; 196 + const struct spi_device_id *id = NULL; 196 197 struct m25p *flash; 197 198 struct spi_nor *nor; 198 199 enum read_mode mode = SPI_NOR_NORMAL; 199 200 int ret; 201 + 202 + data = dev_get_platdata(&spi->dev); 200 203 201 204 flash = devm_kzalloc(&spi->dev, sizeof(*flash), GFP_KERNEL); 202 205 if (!flash) ··· 226 223 mode = SPI_NOR_QUAD; 227 224 else if (spi->mode & SPI_RX_DUAL) 228 225 mode = SPI_NOR_DUAL; 229 - ret = spi_nor_scan(nor, spi_get_device_id(spi), mode); 226 + 227 + if (data && data->name) 228 + flash->mtd.name = data->name; 229 + 230 + /* For some (historical?) reason many platforms provide two different 231 + * names in flash_platform_data: "name" and "type". Quite often name is 232 + * set to "m25p80" and then "type" provides a real chip name. 233 + * If that's the case, respect "type" and ignore a "name". 234 + */ 235 + if (data && data->type) 236 + id = spi_nor_match_id(data->type); 237 + 238 + /* If we didn't get name from platform, simply use "modalias". */ 239 + if (!id) 240 + id = spi_get_device_id(spi); 241 + 242 + ret = spi_nor_scan(nor, id, mode); 230 243 if (ret) 231 244 return ret; 232 245 233 - data = dev_get_platdata(&spi->dev); 234 246 ppdata.of_node = spi->dev.of_node; 235 247 236 248 return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
+1 -27
drivers/mtd/spi-nor/spi-nor.c
··· 915 915 enum read_mode mode) 916 916 { 917 917 struct flash_info *info; 918 - struct flash_platform_data *data; 919 918 struct device *dev = nor->dev; 920 919 struct mtd_info *mtd = nor->mtd; 921 920 struct device_node *np = dev->of_node; ··· 924 925 ret = spi_nor_check(nor); 925 926 if (ret) 926 927 return ret; 927 - 928 - /* Platform data helps sort out which chip type we have, as 929 - * well as how this board partitions it. If we don't have 930 - * a chip ID, try the JEDEC id commands; they'll work for most 931 - * newer chips, even if we don't recognize the particular chip. 932 - */ 933 - data = dev_get_platdata(dev); 934 - if (data && data->type) { 935 - const struct spi_device_id *plat_id; 936 - 937 - for (i = 0; i < ARRAY_SIZE(spi_nor_ids) - 1; i++) { 938 - plat_id = &spi_nor_ids[i]; 939 - if (strcmp(data->type, plat_id->name)) 940 - continue; 941 - break; 942 - } 943 - 944 - if (i < ARRAY_SIZE(spi_nor_ids) - 1) 945 - id = plat_id; 946 - else 947 - dev_warn(dev, "unrecognized id %s\n", data->type); 948 - } 949 928 950 929 info = (void *)id->driver_data; 951 930 ··· 962 985 write_sr(nor, 0); 963 986 } 964 987 965 - if (data && data->name) 966 - mtd->name = data->name; 967 - else 988 + if (!mtd->name) 968 989 mtd->name = dev_name(dev); 969 - 970 990 mtd->type = MTD_NORFLASH; 971 991 mtd->writesize = 1; 972 992 mtd->flags = MTD_CAP_NORFLASH;