mtd: move support for struct flash_platform_data's "type" into m25p80
Subsystems (2)
PATCH 1/1 mtd: move support for struct flash_platform_data's "type" 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.
---
Does this patch make sense to you? It has been compile-tested only.
--- drivers/mtd/devices/m25p80.c | 10 ++++++++-- drivers/mtd/spi-nor/spi-nor.c | 29 +---------------------------- 2 files changed, 9 insertions(+), 30 deletions(-)
drivers/mtd/devices/m25p80.c +8 -2
@@ -176,11 +176,14 @@ static int m25p_probe(struct spi_device *spi) {struct mtd_part_parser_data ppdata;struct flash_platform_data *data; +const struct spi_device_id *id =NULL ;struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ;int ret; + data =dev_get_platdata (&spi->dev); + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );if (!flash)return -ENOMEM ;
@@ -206,11 +209,14 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - ret =spi_nor_scan (nor,spi_get_device_id (spi), mode); +if (data && data->type) + id =spi_nor_match_id (data->type); +if (!id) + id =spi_get_device_id (spi); + ret =spi_nor_scan (nor, id, mode);if (ret)return ret; - data =dev_get_platdata (&spi->dev); ppdata.of_node = spi->dev.of_node; return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
drivers/mtd/spi-nor/spi-nor.c +1 -28
@@ -896,7 +896,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, enum read_mode mode) {struct flash_info *info; -struct flash_platform_data *data;struct device *dev = nor->dev;struct mtd_info *mtd = nor->mtd;struct device_node *np = dev->of_node;
@@ -907,28 +906,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,if (ret)return ret; -/* Platform data helps sort out which chip type we have, as -* well as how this board partitions it. If we don't have -* a chip ID, try the JEDEC id commands; they'll work for most -* newer chips, even if we don't recognize the particular chip. -*/ - data =dev_get_platdata (dev); -if (data && data->type) { -const struct spi_device_id *plat_id; - -for (i =0 ; i <ARRAY_SIZE (spi_nor_ids) -1 ; i++) { - plat_id = &spi_nor_ids[i]; -if (strcmp (data->type, plat_id->name)) -continue ; -break ; - } - -if (i <ARRAY_SIZE (spi_nor_ids) -1 ) - id = plat_id; -else -dev_warn (dev,"unrecognized id %s\n" , data->type); - } - info = (void *)id->driver_data;if (info->jedec_id) {
@@ -966,11 +943,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,write_sr (nor,0 ); } -if (data && data->name) - mtd->name = data->name; -else - mtd->name =dev_name (dev); - + mtd->name =dev_name (dev); mtd->type =MTD_NORFLASH ; mtd->writesize =1 ; mtd->flags =MTD_CAP_NORFLASH ;
Signature · 1 line
1.8.4.5
Quoted 9 lines · Rafał Miłecki
This "type" seems to be an extra hint for m25p80 about the flash. Some archs register
flash_platform_datawith "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 thespi_nor_match_idinstead of iteratingspi_nor_ids.Signed-off-by Rafał Miłecki <[email protected]>---
Does this patch make sense to you? It has been compile-tested only.
The patch mostly makes sense, and I really like the idea of killing struct flash_platform_data from spi-nor.c (it's m25p80-specific, really). But there's at least one potential hiccup here.
Quoted 25 lines
--- drivers/mtd/devices/m25p80.c | 10 ++++++++-- drivers/mtd/spi-nor/spi-nor.c | 29 +---------------------------- 2 files changed, 9 insertions(+), 30 deletions(-)drivers/mtd/devices/m25p80.c +3
-0@@ -176,11 +176,14 @@ static int m25p_probe(struct spi_device *spi) {struct mtd_part_parser_data ppdata;struct flash_platform_data *data; +const struct spi_device_id *id =NULL ;struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ;int ret; + data =dev_get_platdata (&spi->dev); + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );if (!flash)return -ENOMEM ;
drivers/mtd/devices/m25p80.c static int m25p_probe(struct spi_device *spi) · line 215
Quoted 8 lines
drivers/mtd/devices/m25p80.c +4
-1@@ -206,11 +209,14 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - ret =spi_nor_scan (nor,spi_get_device_id (spi), mode); +if (data && data->type) + id =spi_nor_match_id (data->type); +if (!id) + id =spi_get_device_id (spi);
This probably deserves a comment as to what each ID scan does.
Quoted 50 lines
drivers/mtd/devices/m25p80.c +1
-1+ ret =spi_nor_scan (nor, id, mode);if (ret)return ret; - data =dev_get_platdata (&spi->dev); ppdata.of_node = spi->dev.of_node; return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,drivers/mtd/spi-nor/spi-nor.c +0
-23@@ -896,7 +896,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, enum read_mode mode) {struct flash_info *info; -struct flash_platform_data *data;struct device *dev = nor->dev;struct mtd_info *mtd = nor->mtd;struct device_node *np = dev->of_node;@@ -907,28 +906,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,if (ret)return ret; -/* Platform data helps sort out which chip type we have, as -* well as how this board partitions it. If we don't have -* a chip ID, try the JEDEC id commands; they'll work for most -* newer chips, even if we don't recognize the particular chip. -*/ - data =dev_get_platdata (dev); -if (data && data->type) { -const struct spi_device_id *plat_id; - -for (i =0 ; i <ARRAY_SIZE (spi_nor_ids) -1 ; i++) { - plat_id = &spi_nor_ids[i]; -if (strcmp (data->type, plat_id->name)) -continue ; -break ; - } - -if (i <ARRAY_SIZE (spi_nor_ids) -1 ) - id = plat_id; -else -dev_warn (dev,"unrecognized id %s\n" , data->type); - } - info = (void *)id->driver_data;if (info->jedec_id) {
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · line 946
Quoted 9 lines
drivers/mtd/spi-nor/spi-nor.c +1
-5@@ -966,11 +943,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,write_sr (nor,0 ); } -if (data && data->name) - mtd->name = data->name; -else - mtd->name =dev_name (dev); - + mtd->name =dev_name (dev);
We have some potential issues here with the selection of mtd->name. It's nice if we don't change the naming for existing devices (i.e., those instantiated via flash_platform_data in m25p80). Perhaps you can move the m25p80 mtd->name assignment back into m25p80.c, and then this code can be:
if (!mtd->name) mtd->name = dev_name(dev);
drivers/mtd/spi-nor/spi-nor.c int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, · line 949
Quoted 3 lines
drivers/mtd/spi-nor/spi-nor.c +0
-0mtd->type =MTD_NORFLASH ; mtd->writesize =1 ; mtd->flags =MTD_CAP_NORFLASH ;
BTW, this patch has some conflicts with a (later) patch by Huang. Just FYI. I'll handle the conflicts or ask you to rebase when the time comes.
Thanks,
Brian
PATCH v2 1/1 mtd: move support for struct flash_platform_data into m25p80
In reply to Rafał MiłeckiThis "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.
---
V2: Comment usage of data->type
Set mtd.name in m25p80
--- drivers/mtd/devices/m25p80.c | 22 ++++++++++++++++++++-- drivers/mtd/spi-nor/spi-nor.c | 28 +--------------------------- 2 files changed, 21 insertions(+), 29 deletions(-)
drivers/mtd/devices/m25p80.c +20 -2
@@ -193,11 +193,14 @@ static int m25p_probe(struct spi_device *spi) {struct mtd_part_parser_data ppdata;struct flash_platform_data *data; +const struct spi_device_id *id =NULL ;struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ;int ret; + data =dev_get_platdata (&spi->dev); + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );if (!flash)return -ENOMEM ;
@@ -223,11 +226,26 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - ret =spi_nor_scan (nor,spi_get_device_id (spi), mode); + +if (data && data->name) + flash->mtd.name = data->name; + +/* For some (historical?) reason many platforms provide two different +* names in flash_platform_data: "name" and "type". Quite often name is +* set to "m25p80" and then "type" provides a real chip name. +* If that's the case, respsec "type" and ignore "name". +*/ +if (data && data->type) + id =spi_nor_match_id (data->type); + +/* If we didn't get name from platform, simply use "modalias". */ +if (!id) + id =spi_get_device_id (spi); + + ret =spi_nor_scan (nor, id, mode);if (ret)return ret; - data =dev_get_platdata (&spi->dev); ppdata.of_node = spi->dev.of_node; return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
drivers/mtd/spi-nor/spi-nor.c +1 -27
@@ -915,7 +915,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, enum read_mode mode) {struct flash_info *info; -struct flash_platform_data *data;struct device *dev = nor->dev;struct mtd_info *mtd = nor->mtd;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,if (ret)return ret; -/* Platform data helps sort out which chip type we have, as -* well as how this board partitions it. If we don't have -* a chip ID, try the JEDEC id commands; they'll work for most -* newer chips, even if we don't recognize the particular chip. -*/ - data =dev_get_platdata (dev); -if (data && data->type) { -const struct spi_device_id *plat_id; - -for (i =0 ; i <ARRAY_SIZE (spi_nor_ids) -1 ; i++) { - plat_id = &spi_nor_ids[i]; -if (strcmp (data->type, plat_id->name)) -continue ; -break ; - } - -if (i <ARRAY_SIZE (spi_nor_ids) -1 ) - id = plat_id; -else -dev_warn (dev,"unrecognized id %s\n" , data->type); - } - info = (void *)id->driver_data;if (info->jedec_id) {
@@ -985,11 +962,8 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,write_sr (nor,0 ); } -if (data && data->name) - mtd->name = data->name; -else +if (!mtd->name) mtd->name =dev_name (dev); - mtd->type =MTD_NORFLASH ; mtd->writesize =1 ; mtd->flags =MTD_CAP_NORFLASH ;
Signature · 1 line
1.8.4.5
PATCH v3 1/1 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.
---
V2: Comment usage of data->type
Set mtd.name in m25p80
V3: Fix "respect" spelling in the comment
Brian: do you think this comment about "name" and "type" is clear enough now? If so, could you pick this patch, please?
--- drivers/mtd/devices/m25p80.c | 22 ++++++++++++++++++++-- drivers/mtd/spi-nor/spi-nor.c | 28 +--------------------------- 2 files changed, 21 insertions(+), 29 deletions(-)
drivers/mtd/devices/m25p80.c +20 -2
@@ -193,11 +193,14 @@ static int m25p_probe(struct spi_device *spi) {struct mtd_part_parser_data ppdata;struct flash_platform_data *data; +const struct spi_device_id *id =NULL ;struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ;int ret; + data =dev_get_platdata (&spi->dev); + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );if (!flash)return -ENOMEM ;
@@ -223,11 +226,26 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - ret =spi_nor_scan (nor,spi_get_device_id (spi), mode); + +if (data && data->name) + flash->mtd.name = data->name; + +/* For some (historical?) reason many platforms provide two different +* names in flash_platform_data: "name" and "type". Quite often name is +* set to "m25p80" and then "type" provides a real chip name. +* If that's the case, respect "type" and ignore a "name". +*/ +if (data && data->type) + id =spi_nor_match_id (data->type); + +/* If we didn't get name from platform, simply use "modalias". */ +if (!id) + id =spi_get_device_id (spi); + + ret =spi_nor_scan (nor, id, mode);if (ret)return ret; - data =dev_get_platdata (&spi->dev); ppdata.of_node = spi->dev.of_node; return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,
drivers/mtd/spi-nor/spi-nor.c +1 -27
@@ -915,7 +915,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, enum read_mode mode) {struct flash_info *info; -struct flash_platform_data *data;struct device *dev = nor->dev;struct mtd_info *mtd = nor->mtd;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,if (ret)return ret; -/* Platform data helps sort out which chip type we have, as -* well as how this board partitions it. If we don't have -* a chip ID, try the JEDEC id commands; they'll work for most -* newer chips, even if we don't recognize the particular chip. -*/ - data =dev_get_platdata (dev); -if (data && data->type) { -const struct spi_device_id *plat_id; - -for (i =0 ; i <ARRAY_SIZE (spi_nor_ids) -1 ; i++) { - plat_id = &spi_nor_ids[i]; -if (strcmp (data->type, plat_id->name)) -continue ; -break ; - } - -if (i <ARRAY_SIZE (spi_nor_ids) -1 ) - id = plat_id; -else -dev_warn (dev,"unrecognized id %s\n" , data->type); - } - info = (void *)id->driver_data;if (info->jedec_id) {
@@ -985,11 +962,8 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,write_sr (nor,0 ); } -if (data && data->name) - mtd->name = data->name; -else +if (!mtd->name) mtd->name =dev_name (dev); - mtd->type =MTD_NORFLASH ; mtd->writesize =1 ; mtd->flags =MTD_CAP_NORFLASH ;
Signature · 1 line
1.8.4.5
Brian Norris
AppliedRe: [PATCH V3] mtd: move support for struct flash_platform_data into m25p80
Hi Rafal,
Quoted 6 lines · Rafał Miłecki
This "type" seems to be an extra hint for m25p80 about the flash. Some archs register
flash_platform_datawith "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 thespi_nor_match_idinstead of iteratingspi_nor_ids.
Quoted 8 lines
Signed-off-by Rafał Miłecki <[email protected]>---
V2: Comment usage ofdata->type
Set mtd.name in m25p80
V3: Fix "respect" spelling in the commentBrian: do you think this comment about "name" and "type" is clear enough now? If so, could you pick this patch, please?
I think the comments and patch look good now.
Unfortunately, I've delayed this a bit long, and in the meantime, we have another issue cropping up here that may cause conflicts:
http://lists.infradead.org/pipermail/linux-mtd/2014-September/055323.html
But anyway, I think his patch set is not quite ready, and this patch may get us in a better position to resolve his, so:
Applied to l2-mtd.git.
Ben, please base your work on l2-mtd.git/master. If we need to get your patch #1 into stable, then we can mark this patch as a dependency, I think.
Brian
Quoted 107 lines
--- drivers/mtd/devices/m25p80.c | 22 ++++++++++++++++++++-- drivers/mtd/spi-nor/spi-nor.c | 28 +--------------------------- 2 files changed, 21 insertions(+), 29 deletions(-)drivers/mtd/devices/m25p80.c +20
-2@@ -193,11 +193,14 @@ static int m25p_probe(struct spi_device *spi) {struct mtd_part_parser_data ppdata;struct flash_platform_data *data; +const struct spi_device_id *id =NULL ;struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ;int ret; + data =dev_get_platdata (&spi->dev); + flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );if (!flash)return -ENOMEM ;@@ -223,11 +226,26 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - ret =spi_nor_scan (nor,spi_get_device_id (spi), mode); + +if (data && data->name) + flash->mtd.name = data->name; + +/* For some (historical?) reason many platforms provide two different +* names in flash_platform_data: "name" and "type". Quite often name is +* set to "m25p80" and then "type" provides a real chip name. +* If that's the case, respect "type" and ignore a "name". +*/ +if (data && data->type) + id =spi_nor_match_id (data->type); + +/* If we didn't get name from platform, simply use "modalias". */ +if (!id) + id =spi_get_device_id (spi); + + ret =spi_nor_scan (nor, id, mode);if (ret)return ret; - data =dev_get_platdata (&spi->dev); ppdata.of_node = spi->dev.of_node; return mtd_device_parse_register(&flash->mtd, NULL, &ppdata,drivers/mtd/spi-nor/spi-nor.c +1
-27@@ -915,7 +915,6 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, enum read_mode mode) {struct flash_info *info; -struct flash_platform_data *data;struct device *dev = nor->dev;struct mtd_info *mtd = nor->mtd;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,if (ret)return ret; -/* Platform data helps sort out which chip type we have, as -* well as how this board partitions it. If we don't have -* a chip ID, try the JEDEC id commands; they'll work for most -* newer chips, even if we don't recognize the particular chip. -*/ - data =dev_get_platdata (dev); -if (data && data->type) { -const struct spi_device_id *plat_id; - -for (i =0 ; i <ARRAY_SIZE (spi_nor_ids) -1 ; i++) { - plat_id = &spi_nor_ids[i]; -if (strcmp (data->type, plat_id->name)) -continue ; -break ; - } - -if (i <ARRAY_SIZE (spi_nor_ids) -1 ) - id = plat_id; -else -dev_warn (dev,"unrecognized id %s\n" , data->type); - } - info = (void *)id->driver_data;if (info->jedec_id) {@@ -985,11 +962,8 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,write_sr (nor,0 ); } -if (data && data->name) - mtd->name = data->name; -else +if (!mtd->name) mtd->name =dev_name (dev); - mtd->type =MTD_NORFLASH ; mtd->writesize =1 ; mtd->flags =MTD_CAP_NORFLASH ;