m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
Subsystems (3)
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
The first patch in the series restores the module aliases to m25p80, but it does so by duplicating the list of names. This should be suitable for stable, but it isn't viable in the longer term.
The following patches change the spi-nor interface so that this duplication is no longer necessary. This includes removing spi_nor::read_id, but it could be re-added after this with a different interface, e.g. returning a flash_info structure (which would need to be defined in spi_nor.h).
Ben.
Ben Hutchings (5):
m25p80,spi-nor: Fix module aliases for m25p80
spi-nor: Remove spi_nor::read_id operation
spi-nor: Make spi_nor_scan() take a chip type name, not an
spi_device_id
spi-nor: Replace struct spi_device_id with struct flash_info m25p80,spi-nor: Share the list of supported chip type names again
drivers/mtd/devices/m25p80.c | 13 +- drivers/mtd/spi-nor/fsl-quadspi.c | 7 +- drivers/mtd/spi-nor/spi-nor.c | 383 +++++++++++++++++++------------------- include/linux/mtd/spi-nor.h | 87 +++++++-- 4 files changed, 279 insertions(+), 211 deletions(-)
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/e8d08292/attachment.sig>
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
m25p80's device ID table is now spi_nor_ids, defined in spi-nor. The MODULE_DEVICE_TABLE() macro doesn't work with extern definitions, but its use was also removed at the same time. Now if m25p80 is built as a module it doesn't get the necessary aliases to be loaded automatically.
A clean solution to this will involve defining the list of device IDs in spi-nor.h and removing struct spi_device_id from the spi-nor API, but this is quite a large change.
As a quick fix suitable for stable, copy the device IDs back into m25p80.
--- drivers/mtd/devices/m25p80.c | 58 +++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/spi-nor/spi-nor.c | 5 ++-- include/linux/mtd/spi-nor.h | 3 +-- 3 files changed, 59 insertions(+), 7 deletions(-)
drivers/mtd/devices/m25p80.c +56 -2
@@ -196,6 +196,7 @@ static int m25p_probe(struct spi_device *spi)struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ; +const struct spi_device_id *id;int ret; flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );
@@ -223,7 +224,10 @@ 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); + id =spi_nor_match_id (spi_get_device_id (spi)->name); +if (WARN_ON (!id)) +return -ENODEV ; + ret =spi_nor_scan (nor, id, mode);if (ret)return ret;
@@ -245,12 +249,62 @@ static int m25p_remove(struct spi_device *spi) } +/* +* XXX This needs to be kept in sync with spi_nor_ids. We can't share +* it with spi-nor, because if this is built as a module then modpost +* won't be able to read it and add appropriate aliases. +*/ +static const struct spi_device_id m25p_ids[] = { + {"at25fs010" }, {"at25fs040" }, {"at25df041a" }, {"at25df321a" }, + {"at25df641" }, {"at26f004" }, {"at26df081a" }, {"at26df161a" }, + {"at26df321" }, {"at45db081d" }, + {"en25f32" }, {"en25p32" }, {"en25q32b" }, {"en25p64" }, + {"en25q64" }, {"en25qh128" }, {"en25qh256" }, + {"f25l32pa" }, + {"mr25h256" }, {"mr25h10" }, + {"gd25q32" }, {"gd25q64" }, + {"160s33b" }, {"320s33b" }, {"640s33b" }, + {"mx25l2005a" }, {"mx25l4005a" }, {"mx25l8005" }, {"mx25l1606e" }, + {"mx25l3205d" }, {"mx25l3255e" }, {"mx25l6405d" }, {"mx25l12805d" }, + {"mx25l12855e" },{"mx25l25635e" },{"mx25l25655e" },{"mx66l51235l" }, + {"mx66l1g55g" }, + {"n25q064" }, {"n25q128a11" }, {"n25q128a13" }, {"n25q256a" }, + {"n25q512a" }, {"n25q512ax3" }, {"n25q00" }, + {"pm25lv512" }, {"pm25lv010" }, {"pm25lq032" }, + {"s25sl032p" }, {"s25sl064p" }, {"s25fl256s0" }, {"s25fl256s1" }, + {"s25fl512s" }, {"s70fl01gs" }, {"s25sl12800" }, {"s25sl12801" }, + {"s25fl129p0" }, {"s25fl129p1" }, {"s25sl004a" }, {"s25sl008a" }, + {"s25sl016a" }, {"s25sl032a" }, {"s25sl064a" }, {"s25fl008k" }, + {"s25fl016k" }, {"s25fl064k" }, + {"sst25vf040b" },{"sst25vf080b" },{"sst25vf016b" },{"sst25vf032b" }, + {"sst25vf064c" },{"sst25wf512" }, {"sst25wf010" }, {"sst25wf020" }, + {"sst25wf040" }, + {"m25p05" }, {"m25p10" }, {"m25p20" }, {"m25p40" }, + {"m25p80" }, {"m25p16" }, {"m25p32" }, {"m25p64" }, + {"m25p128" }, {"n25q032" }, + {"m25p05-nonjedec" }, {"m25p10-nonjedec" }, {"m25p20-nonjedec" }, + {"m25p40-nonjedec" }, {"m25p80-nonjedec" }, {"m25p16-nonjedec" }, + {"m25p32-nonjedec" }, {"m25p64-nonjedec" }, {"m25p128-nonjedec" }, + {"m45pe10" }, {"m45pe80" }, {"m45pe16" }, + {"m25pe20" }, {"m25pe80" }, {"m25pe16" }, + {"m25px16" }, {"m25px32" }, {"m25px32-s0" }, {"m25px32-s1" }, + {"m25px64" }, + {"w25x10" }, {"w25x20" }, {"w25x40" }, {"w25x80" }, + {"w25x16" }, {"w25x32" }, {"w25q32" }, {"w25q32dw" }, + {"w25x64" }, {"w25q64" }, {"w25q128" }, {"w25q80" }, + {"w25q80bl" }, {"w25q128" }, {"w25q256" }, {"cat25c11" }, + {"cat25c03" }, {"cat25c09" }, {"cat25c17" }, {"cat25128" }, + { }, +}; +MODULE_DEVICE_TABLE (spi, m25p_ids); + +static struct spi_driver m25p80_driver = { .driver = { .name ="m25p80" , .owner =THIS_MODULE , }, - .id_table = spi_nor_ids, + .id_table = m25p_ids, .probe = m25p_probe, .remove = m25p_remove,
drivers/mtd/spi-nor/spi-nor.c +2 -3
@@ -473,7 +473,7 @@ struct flash_info {* more nor chips. This current list focusses on newer chips, which * have been converging on command sets which including JEDEC ID. */ -const struct spi_device_id spi_nor_ids[] = { +static const struct spi_device_id spi_nor_ids[] = {/* Atmel -- some are (confusingly) marketed as "DataFlash" */ {"at25fs010" ,INFO (0x1f6601 ,0 ,32 *1024 ,4 ,SECT_4K ) }, {"at25fs040" ,INFO (0x1f6604 ,0 ,64 *1024 ,8 ,SECT_4K ) },
@@ -637,7 +637,6 @@ const struct spi_device_id spi_nor_ids[] = { { "cat25128", CAT25_INFO(2048, 8, 64, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, { }, }; -EXPORT_SYMBOL_GPL (spi_nor_ids);static const struct spi_device_id *spi_nor_read_id (struct spi_nor *nor) {
@@ -1136,7 +1135,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, }EXPORT_SYMBOL_GPL (spi_nor_scan); -const struct spi_device_id *spi_nor_match_id (char *name) +const struct spi_device_id *spi_nor_match_id (const char *name) {const struct spi_device_id *id = spi_nor_ids;
include/linux/mtd/spi-nor.h +1 -2
@@ -201,7 +201,6 @@ struct spi_nor {*/ int spi_nor_scan (struct spi_nor *nor,const struct spi_device_id *id,enum read_mode mode); -extern const struct spi_device_id spi_nor_ids[];/** * spi_nor_match_id() - find the spi_device_id by the name
@@ -213,6 +212,6 @@ extern const struct spi_device_id spi_nor_ids[];* Return: returns the right spi_device_id pointer on success, * and returns NULL on failure. */ -const struct spi_device_id *spi_nor_match_id (char *name); +const struct spi_device_id *spi_nor_match_id (const char *name);#endif
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/d6454f26/attachment.sig>
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
+ Rafal
Rafal has been looking at the same area of code. I'd really like to get this patch into 3.18 if possible, so the more eyes the better.
Quoted 35 lines · Ben Hutchings
m25p80's device ID table is now
spi_nor_ids, defined in spi-nor. TheMODULE_DEVICE_TABLE()macro doesn't work with extern definitions, but its use was also removed at the same time. Now if m25p80 is built as a module it doesn't get the necessary aliases to be loaded automatically.A clean solution to this will involve defining the list of device IDs in
spi-nor.hand removing structspi_device_idfrom the spi-nor API, but this is quite a large change.As a quick fix suitable for stable, copy the device IDs back into m25p80.
Fixes 03e296f613af ("mtd: m25p80: use the SPI nor framework")Cc stable <[email protected]> # 3.16Signed-off-by Ben Hutchings <[email protected]>--- drivers/mtd/devices/m25p80.c | 58 +++++++++++++++++++++++++++++++++++++++++-- drivers/mtd/spi-nor/spi-nor.c | 5 ++-- include/linux/mtd/spi-nor.h | 3 +-- 3 files changed, 59 insertions(+), 7 deletions(-)drivers/mtd/devices/m25p80.c +1
-0@@ -196,6 +196,7 @@ static int m25p_probe(struct spi_device *spi)struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ; +const struct spi_device_id *id;int ret; flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );
drivers/mtd/devices/m25p80.c static int m25p_probe(struct spi_device *spi) · line 229
Quoted 7 lines
drivers/mtd/devices/m25p80.c +3
-1@@ -223,7 +224,10 @@ 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); + id =spi_nor_match_id (spi_get_device_id (spi)->name); +if (WARN_ON (!id)) +return -ENODEV ;
I'm not confident this logic is sound. And even if it is sound, does it belong in a patch for stable? You might take a look at Rafal's patch here:
http://lists.infradead.org/pipermail/linux-mtd/2014-September/055596.html
some of the matching logic is actually done via platform data, and I don't think this check for spi_nor_match_id() will catch it.
(Honestly, some of this name-matching / ID-matching stuff confuses me; there is at least one too many ways to choose a flash device for this driver.)
Quoted 113 lines
drivers/mtd/devices/m25p80.c +52
-1+ ret =spi_nor_scan (nor, id, mode);if (ret)return ret;@@ -245,12 +249,62 @@ static int m25p_remove(struct spi_device *spi) } +/* +* XXX This needs to be kept in sync with spi_nor_ids. We can't share +* it with spi-nor, because if this is built as a module then modpost +* won't be able to read it and add appropriate aliases. +*/ +static const struct spi_device_id m25p_ids[] = { + {"at25fs010" }, {"at25fs040" }, {"at25df041a" }, {"at25df321a" }, + {"at25df641" }, {"at26f004" }, {"at26df081a" }, {"at26df161a" }, + {"at26df321" }, {"at45db081d" }, + {"en25f32" }, {"en25p32" }, {"en25q32b" }, {"en25p64" }, + {"en25q64" }, {"en25qh128" }, {"en25qh256" }, + {"f25l32pa" }, + {"mr25h256" }, {"mr25h10" }, + {"gd25q32" }, {"gd25q64" }, + {"160s33b" }, {"320s33b" }, {"640s33b" }, + {"mx25l2005a" }, {"mx25l4005a" }, {"mx25l8005" }, {"mx25l1606e" }, + {"mx25l3205d" }, {"mx25l3255e" }, {"mx25l6405d" }, {"mx25l12805d" }, + {"mx25l12855e" },{"mx25l25635e" },{"mx25l25655e" },{"mx66l51235l" }, + {"mx66l1g55g" }, + {"n25q064" }, {"n25q128a11" }, {"n25q128a13" }, {"n25q256a" }, + {"n25q512a" }, {"n25q512ax3" }, {"n25q00" }, + {"pm25lv512" }, {"pm25lv010" }, {"pm25lq032" }, + {"s25sl032p" }, {"s25sl064p" }, {"s25fl256s0" }, {"s25fl256s1" }, + {"s25fl512s" }, {"s70fl01gs" }, {"s25sl12800" }, {"s25sl12801" }, + {"s25fl129p0" }, {"s25fl129p1" }, {"s25sl004a" }, {"s25sl008a" }, + {"s25sl016a" }, {"s25sl032a" }, {"s25sl064a" }, {"s25fl008k" }, + {"s25fl016k" }, {"s25fl064k" }, + {"sst25vf040b" },{"sst25vf080b" },{"sst25vf016b" },{"sst25vf032b" }, + {"sst25vf064c" },{"sst25wf512" }, {"sst25wf010" }, {"sst25wf020" }, + {"sst25wf040" }, + {"m25p05" }, {"m25p10" }, {"m25p20" }, {"m25p40" }, + {"m25p80" }, {"m25p16" }, {"m25p32" }, {"m25p64" }, + {"m25p128" }, {"n25q032" }, + {"m25p05-nonjedec" }, {"m25p10-nonjedec" }, {"m25p20-nonjedec" }, + {"m25p40-nonjedec" }, {"m25p80-nonjedec" }, {"m25p16-nonjedec" }, + {"m25p32-nonjedec" }, {"m25p64-nonjedec" }, {"m25p128-nonjedec" }, + {"m45pe10" }, {"m45pe80" }, {"m45pe16" }, + {"m25pe20" }, {"m25pe80" }, {"m25pe16" }, + {"m25px16" }, {"m25px32" }, {"m25px32-s0" }, {"m25px32-s1" }, + {"m25px64" }, + {"w25x10" }, {"w25x20" }, {"w25x40" }, {"w25x80" }, + {"w25x16" }, {"w25x32" }, {"w25q32" }, {"w25q32dw" }, + {"w25x64" }, {"w25q64" }, {"w25q128" }, {"w25q80" }, + {"w25q80bl" }, {"w25q128" }, {"w25q256" }, {"cat25c11" }, + {"cat25c03" }, {"cat25c09" }, {"cat25c17" }, {"cat25128" }, + { }, +}; +MODULE_DEVICE_TABLE (spi, m25p_ids); + +static struct spi_driver m25p80_driver = { .driver = { .name ="m25p80" , .owner =THIS_MODULE , }, - .id_table = spi_nor_ids, + .id_table = m25p_ids, .probe = m25p_probe, .remove = m25p_remove,drivers/mtd/spi-nor/spi-nor.c +2
-3@@ -473,7 +473,7 @@ struct flash_info {* more nor chips. This current list focusses on newer chips, which * have been converging on command sets which including JEDEC ID. */ -const struct spi_device_id spi_nor_ids[] = { +static const struct spi_device_id spi_nor_ids[] = {/* Atmel -- some are (confusingly) marketed as "DataFlash" */ {"at25fs010" ,INFO (0x1f6601 ,0 ,32 *1024 ,4 ,SECT_4K ) }, {"at25fs040" ,INFO (0x1f6604 ,0 ,64 *1024 ,8 ,SECT_4K ) },@@ -637,7 +637,6 @@ const struct spi_device_id spi_nor_ids[] = { { "cat25128", CAT25_INFO(2048, 8, 64, 2, SPI_NOR_NO_ERASE | SPI_NOR_NO_FR) }, { }, }; -EXPORT_SYMBOL_GPL (spi_nor_ids);static const struct spi_device_id *spi_nor_read_id (struct spi_nor *nor) {@@ -1136,7 +1135,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, }EXPORT_SYMBOL_GPL (spi_nor_scan); -const struct spi_device_id *spi_nor_match_id (char *name) +const struct spi_device_id *spi_nor_match_id (const char *name) {const struct spi_device_id *id = spi_nor_ids;include/linux/mtd/spi-nor.h +0
-1@@ -201,7 +201,6 @@ struct spi_nor {*/ int spi_nor_scan (struct spi_nor *nor,const struct spi_device_id *id,enum read_mode mode); -extern const struct spi_device_id spi_nor_ids[];/** * spi_nor_match_id() - find the spi_device_id by the name
include/linux/mtd/spi-nor.h extern const struct spi_device_id spi_nor_ids[]; · line 217
Quoted 7 lines
include/linux/mtd/spi-nor.h +1
-1@@ -213,6 +212,6 @@ extern const struct spi_device_id spi_nor_ids[];* Return: returns the right spi_device_id pointer on success, * and returns NULL on failure. */ -const struct spi_device_id *spi_nor_match_id (char *name); +const struct spi_device_id *spi_nor_match_id (const char *name);#endif
But aside from that, I think this patch is OK.
Brian
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
Quoted 4 lines · Brian Norris
+ Rafal
Rafal has been looking at the same area of code. I'd really like to get this patch into 3.18 if possible, so the more eyes the better.
Thanks Brian.
I took me a while to follow this issue, too bad I wasn't subscribed to the ML earlier. Let me try to sum it up.
1) The main urgent issue: broken auto-loading
Tracked in the thread: http://www.spinics.net/lists/linux-spi/msg01726.html
Problem: m25p80.c references spi_nor_ids (from external file) Short-term solution: duplicate IDs in the m25p80.c
Ben: just like Brian, I think the patch like this one ( [PATCH 1/5] m25p80,spi-nor: Fix module aliases for m25p80 ) is the way to go. However few comments:
a) I don't see why you modify m25p_probe in it.
b) I don't think the described clean solution (you described it in the commit message):
Quoted 3 lines
A clean solution to this will involve defining the list of device IDs in
spi-nor.hand removing structspi_device_idfrom the spi-nor API, but this is quite a large change.
is the correct one. I think there should be a single string to trigger m25p80 load and the rest should be handled using JEDEC, with some workarounds for incompatible devices only.
One thing I wonder about is sense of pushing this patch to the Linus's tree. Do you think we could prepare a real fix for Linus and leave this patch for stable@ only? I'm far from being an expert on such things, just asking.
2) On going cleanups
It seems there are at least 2 ppl (me, Ben) working on some cleanups independently.
a) There is (l2-mtd pushed) patch moving flash_platform_data into m25p80:
https://patchwork.ozlabs.org/patch/394219/
b) Removing spi_nor::read_id
https://patchwork.ozlabs.org/patch/389073/
Ben: I think this one has a NACK from me, because I'm going to use custom read_id in the bcm53xxspiflash driver.
See following thread for bcm53xxspiflash description:
http://comments.gmane.org/gmane.linux.drivers.mtd/54578
Initial commit (it uses read_id): https://patchwork.ozlabs.org/patch/381902/
c) Obsoleting spi_device_id
It seems we both were working on the same thing, me slightly slower however ;)
https://patchwork.ozlabs.org/patch/377917/
https://patchwork.ozlabs.org/patch/389074/
https://patchwork.ozlabs.org/patch/389075/
I still have to review calmly your changes, but they need to be rebased anyway.
d) Cleaning m25p80
https://patchwork.ozlabs.org/patch/389076/
Ben: As said before, I think we should do smarter in the m25p80. We should get rid of all that duplicated strings.
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
Quoted 8 lines · Rafa? Mi?ecki
1) The main urgent issue: broken auto-loading
Tracked in the thread: http://www.spinics.net/lists/linux-spi/msg01726.html
Problem:m25p80.creferencesspi_nor_ids(from external file) Short-term solution: duplicate IDs in them25p80.cBen: just like Brian, I think the patch like this one ( [PATCH 1/5] m25p80,spi-nor: Fix module aliases for m25p80 ) is the way to go. However few comments:
I started wondering... would this be possible to fix all m25p80 users instead? Make them always specify modalias as "m25p80" and then provide platform_data if needed?
Has anyone checked in how many places we use "wrong" (or should I say "weird") modaliases? I guess some would need to grep kernel for all possible names.
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
Quoted 10 lines · Rafa? Mi?ecki
Quoted 8 lines · Rafa? Mi?ecki
1) The main urgent issue: broken auto-loading
Tracked in the thread: http://www.spinics.net/lists/linux-spi/msg01726.html
Problem:m25p80.creferencesspi_nor_ids(from external file) Short-term solution: duplicate IDs in them25p80.cBen: just like Brian, I think the patch like this one ( [PATCH 1/5] m25p80,spi-nor: Fix module aliases for m25p80 ) is the way to go. However few comments:
Quoted 7 lines
I started wondering... would this be possible to fix all m25p80 users instead? Make them always specify modalias as "m25p80" and then provide
platform_dataif needed?Has anyone checked in how many places we use "wrong" (or should I say "weird") modaliases? I guess some would need to grep kernel for all possible names.
I did some (e)grepping, it seems we have:
1) Only 6 references (modalias) in arch/mips/ath79/
2) About 57 references (compatible) in arch/arm/boot/dts/
3) About 32 references (compatible) in arch/powerpc/boot/dts/
However it seems there is no way to provide platform_data in Device Tree files. So we have to support compatible (modalias) for now I guess.
The list (if someone would like to check) of used names in archs:
m25p128 m25p16 m25p32 m25p40 m25p64
mx25l12805d mx25l1606e mx25l25635e mx25l4005a mx25l6405d mx66l51235l n25q128a11 n25q128a13 n25q512a
s25fl008k s25fl256s1 s25fl512s s25sl064a s25sl12801 sst25vf016b sst25vf032b sst25vf040b sst25wf040
w25q128 w25q256 w25q32 w25q32dw w25q80bl w25x80
Signature · 1 line
Rafa?
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
In reply to Rafał MiłeckiQuoted 18 lines · Rafa? Mi?ecki
Quoted 4 lines · Brian Norris
+ Rafal
Rafal has been looking at the same area of code. I'd really like to get this patch into 3.18 if possible, so the more eyes the better.
Thanks Brian.
I took me a while to follow this issue, too bad I wasn't subscribed to the ML earlier. Let me try to sum it up.
1) The main urgent issue: broken auto-loading
Tracked in the thread: http://www.spinics.net/lists/linux-spi/msg01726.html
Problem:m25p80.creferencesspi_nor_ids(from external file) Short-term solution: duplicate IDs in them25p80.c
Quoted 5 lines
Ben: just like Brian, I think the patch like this one ( [PATCH 1/5] m25p80,spi-nor: Fix module aliases for m25p80 ) is the way to go. However few comments:
a) I don't see why you modify
m25p_probein it.
Because spi_nor_scan() requires a struct spi_device_id with the driver_data field pointing to a struct flash_info.
Quoted 8 lines
b) I don't think the described clean solution (you described it in the commit message):
Quoted 3 lines
A clean solution to this will involve defining the list of device IDs in
spi-nor.hand removing structspi_device_idfrom the spi-nor API, but this is quite a large change.is the correct one. I think there should be a single string to trigger m25p80 load and the rest should be handled using JEDEC, with some workarounds for incompatible devices only.
That certainly makes sense for Linux-specific platform data, but I don't think it works for Device Tree "compatible" strings (see
<http://mid.gmane.org/[email protected]>).
[...]
Quoted 7 lines
b) Removing
spi_nor::read_id
https://patchwork.ozlabs.org/patch/389073/
Ben: I think this one has a NACK from me, because I'm going to use customread_idin the bcm53xxspiflash driver.
See following thread for bcm53xxspiflash description:
http://comments.gmane.org/gmane.linux.drivers.mtd/54578
Initial commit (it usesread_id): https://patchwork.ozlabs.org/patch/381902/
[...]
But it has to use spi_nor_match_id() because of the driver_data requirement. This just illustrates that the read_id operation doesn't make sense as currently defined.
I accept that there will be a need for a read_id operation, but I think it should fill in a struct flash_info rather than requiring every chip to be described and named in spi-nor.c.
Ben.
Signature · 9 lines
Ben Hutchings The two most common things in the universe are hydrogen and stupidity. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140930/da598f26/attachment.sig>
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
Quoted 6 lines · Ben Hutchings
Quoted 5 lines · Rafa? Mi?ecki
b) I don't think the described clean solution (you described it in the commit message):
Quoted 3 lines
A clean solution to this will involve defining the list of device IDs in
spi-nor.hand removing structspi_device_idfrom the spi-nor API, but this is quite a large change.
Quoted 7 lines
Quoted 3 lines
is the correct one. I think there should be a single string to trigger m25p80 load and the rest should be handled using JEDEC, with some workarounds for incompatible devices only.
That certainly makes sense for Linux-specific platform data, but I don't think it works for Device Tree "compatible" strings (see
<http://mid.gmane.org/[email protected]>).
I think it might work.
Your quote from that thread:
"I think that a DT node is always supposed to include a compatible string for the specific device. It could also include a generic compatible string for SPI NOR chips, but the *only* thing a driver can do with that is to use the JEDEC ID command. It can't even generically read a single byte, since addresses may be either 3 or 4 bytes long! So I think that if a generic compatible string is defined, the DT binding must also define the properties that spi-nor currently reads out of its static table."
For every current entry (except the "*-nonjedec" entries; I don't think we should be supporting any more entries like this, and I'd like to kill the existing ones if possible), we can do just that; read out the JEDEC ID and go from there. (Rafal is also looking at non-JEDEC RDID commands, but that would just require a different type of binding.)
In fact, for most of these entries, we'll read out the ID and override the match provided by the driver anyway. See:
int spi_nor_scan(...)
{
...
[Note: almost all 'info' entries provide a non-zero jedec_id field]
if (info->jedec_id) {
const struct spi_device_id *jid;
jid = nor->read_id(nor);
if (IS_ERR(jid)) {
return PTR_ERR(jid);
} else if (jid != id) {
/*
* JEDEC knows better, so overwrite platform ID. We
* can't trust partitions any longer, but we'll let
* mtd apply them anyway, since some partitions may be
* marked read-only, and we don't want to lose that
* information, even if it's not 100% accurate.
*/
dev_warn(dev, "found %s, expected %s\n",
jid->name, id->name);
id = jid;
info = (void *)jid->driver_data;
}
}...
}
I think this chunk might be reworked (or at least, modify the comments) to note how we primarily expect to override the input ID. We might even drop the dev_warn() eventually, and make it more informative instead.
Quoted 8 lines
[...]
Quoted 7 lines
b) Removing
spi_nor::read_id
https://patchwork.ozlabs.org/patch/389073/
Ben: I think this one has a NACK from me, because I'm going to use customread_idin the bcm53xxspiflash driver.
See following thread for bcm53xxspiflash description:
http://comments.gmane.org/gmane.linux.drivers.mtd/54578
Initial commit (it usesread_id): https://patchwork.ozlabs.org/patch/381902/
Quoted 5 lines
[...]
But it has to use
spi_nor_match_id()because of thedriver_datarequirement. This just illustrates that theread_idoperation doesn't make sense as currently defined.
Right. I think it may turn out better to drop it and force a redesign for the next user.
Quoted 3 lines
I accept that there will be a need for a
read_idoperation, but I think it should fill in a structflash_inforather than requiring every chip to be described and named inspi-nor.c.
Maybe struct flash_info, but this still leaks more spi-nor.c internal info into drivers. Perhaps Rafal's use case could be served by a select-able 'READ ID' opcode, with his flash_info structs still stored in spi_nor_ids[] -- or possibly as a separate ID table within spi-nor.c.
But either way, I agree the current read_id() hook is not satisfactory.
Brian
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
In reply to Ben HutchingsQuoted 19 lines · Ben Hutchings
Quoted 18 lines · Rafa? Mi?ecki
Quoted 4 lines · Brian Norris
+ Rafal
Rafal has been looking at the same area of code. I'd really like to get this patch into 3.18 if possible, so the more eyes the better.
Thanks Brian.
I took me a while to follow this issue, too bad I wasn't subscribed to the ML earlier. Let me try to sum it up.
1) The main urgent issue: broken auto-loading
Tracked in the thread: http://www.spinics.net/lists/linux-spi/msg01726.html
Problem:m25p80.creferencesspi_nor_ids(from external file) Short-term solution: duplicate IDs in them25p80.c
Quoted 8 lines
Quoted 5 lines
Ben: just like Brian, I think the patch like this one ( [PATCH 1/5] m25p80,spi-nor: Fix module aliases for m25p80 ) is the way to go. However few comments:
a) I don't see why you modify
m25p_probein it.Because
spi_nor_scan()requires a structspi_device_idwith thedriver_datafield pointing to a structflash_info.
More friendly explanation: because spi_get_device_id uses driver's id_table (that was now changes to pure strings).
I see the point.
Quoted 5 lines
Quoted 5 lines
b) I don't think the described clean solution (you described it in the commit message):
Quoted 3 lines
A clean solution to this will involve defining the list of device IDs in
spi-nor.hand removing structspi_device_idfrom the spi-nor API, but this is quite a large change.
Quoted 7 lines
Quoted 3 lines
is the correct one. I think there should be a single string to trigger m25p80 load and the rest should be handled using JEDEC, with some workarounds for incompatible devices only.
That certainly makes sense for Linux-specific platform data, but I don't think it works for Device Tree "compatible" strings (see
<http://mid.gmane.org/[email protected]>).
We could simply follow the way Linux-specific platform data works. We could always use
compatible = "m25p80";
and then for some rare cases (where JEDEC fails) add something like model = "at25df321a";
Quoted 7 lines
Quoted 7 lines
b) Removing
spi_nor::read_id
https://patchwork.ozlabs.org/patch/389073/
Ben: I think this one has a NACK from me, because I'm going to use customread_idin the bcm53xxspiflash driver.
See following thread for bcm53xxspiflash description:
http://comments.gmane.org/gmane.linux.drivers.mtd/54578
Initial commit (it usesread_id): https://patchwork.ozlabs.org/patch/381902/
Quoted 5 lines
[...]
But it has to use
spi_nor_match_id()because of thedriver_datarequirement. This just illustrates that theread_idoperation doesn't make sense as currently defined.
I agree, however there is already a patch in progress handling that:
https://patchwork.ozlabs.org/patch/377917/
Quoted 3 lines
I accept that there will be a need for a
read_idoperation, but I think it should fill in a structflash_inforather than requiring every chip to be described and named inspi-nor.c.
Flashes not supporting JEDEC are usually some weird versions of normal flashes with JEDEC support. So I think we could still have them in the spi-nor database and let users provide the name instead of filling the whole struct flash_info.
Signature · 1 line
Rafa?
PATCH 1/5 m25p80,spi-nor: Fix module aliases for m25p80
In reply to Brian NorrisQuoted 3 lines · Brian Norris
(Honestly, some of this name-matching / ID-matching stuff confuses me; there is at least one too many ways to choose a flash device for this driver.)
It's not that complex once you track it. It's just ugly to tracks because of different structs, function calls and code locations.
1) All m25p80 users (arch code, SPI drivers, etc.) register struct spi_board_info
that contains "modalias". It it used to match a driver to load. In most (?) cases modalias is set to "m25p80"
2) Some m25p80 users decided to put a flash device name (e.g. "at25fs010", "mx25l2005a", "m25p05", "w25x10") as modalias of the struct spi_board_info. I think they are affected by the recent m25p80 change to use spi-not framework.
3) Other m25p80 users provide flash device name (e.g. "at25fs010", "mx25l2005a", "m25p05", "w25x10") using platform_data in the struct spi_board_info. It points to the struct flash_platform_data with "name" and "type" properties. It seems to me that "name" is never used.
My idea for fixing this:
1) Always use "m25p80" modalias (for m25p80 compatible hw). This will make m25p80 driver work without this huge id_table
2) Do not use "name" nor "type" in the struct flash_platform_data if the flash supports JEDEC
3) If the flash is m25p80 compatible, but doesn't support JEDEC, let's use "type" to let m25p80 work.
PATCH 2/5 spi-nor: Remove spi_nor::read_id operation
In reply to Ben HutchingsThere is currently no useful way to override the default implementation of this operation. The returned struct spi_device_id must have a pointer to struct flash_info in its private data, but this structure is defined inside spi-nor.
--- drivers/mtd/spi-nor/spi-nor.c | 4 +--- include/linux/mtd/spi-nor.h | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +1 -3
@@ -902,8 +902,6 @@ static int spi_nor_check(struct spi_nor *nor)return -EINVAL ; } -if (!nor->read_id) - nor->read_id = spi_nor_read_id;if (!nor->wait_till_ready) nor->wait_till_ready = spi_nor_wait_till_ready;
@@ -952,7 +950,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,if (info->jedec_id) {const struct spi_device_id *jid; - jid = nor->read_id (nor); + jid =spi_nor_read_id (nor);if (IS_ERR (jid)) {return PTR_ERR (jid); }else if (jid != id) {
include/linux/mtd/spi-nor.h +0 -3
@@ -139,8 +139,6 @@ enum spi_nor_ops {* @write_xfer: [OPTIONAL] the writefundamental primitive * @read_reg: [DRIVER-SPECIFIC] read out the register * @write_reg: [DRIVER-SPECIFIC] write data to the register -* @read_id: [REPLACEABLE] read out the ID data, and find -* the proper spi_device_id * @wait_till_ready: [REPLACEABLE] wait till the NOR becomes ready * @read: [DRIVER-SPECIFIC] read data from the SPI NOR * @write: [DRIVER-SPECIFIC] write data to the SPI NOR
@@ -172,7 +170,6 @@ struct spi_nor {int (*read_reg)(struct spi_nor *nor,u8 opcode,u8 *buf,int len);int (*write_reg)(struct spi_nor *nor,u8 opcode,u8 *buf,int len,int write_enable); -const struct spi_device_id *(*read_id)(struct spi_nor *nor);int (*wait_till_ready)(struct spi_nor *nor); int (*read)(struct spi_nor *nor, loff_t from,
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/2cc952ea/attachment-0001.sig>
PATCH 2/5 spi-nor: Remove spi_nor::read_id operation
Quoted 38 lines · Ben Hutchings
There is currently no useful way to override the default implementation of this operation. The returned struct
spi_device_idmust have a pointer to structflash_infoin its private data, but this structure is defined inside spi-nor.Signed-off-by Ben Hutchings <[email protected]>--- drivers/mtd/spi-nor/spi-nor.c | 4 +--- include/linux/mtd/spi-nor.h | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-)drivers/mtd/spi-nor/spi-nor.c +1
-3@@ -902,8 +902,6 @@ static int spi_nor_check(struct spi_nor *nor)return -EINVAL ; } -if (!nor->read_id) - nor->read_id = spi_nor_read_id;if (!nor->wait_till_ready) nor->wait_till_ready = spi_nor_wait_till_ready;@@ -952,7 +950,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,if (info->jedec_id) {const struct spi_device_id *jid; - jid = nor->read_id (nor); + jid =spi_nor_read_id (nor);if (IS_ERR (jid)) {return PTR_ERR (jid); }else if (jid != id) {include/linux/mtd/spi-nor.h +0
-0
include/linux/mtd/spi-nor.h enum spi_nor_ops { · line 143
Quoted 5 lines
include/linux/mtd/spi-nor.h +0
-2@@ -139,8 +139,6 @@ enum spi_nor_ops {* @write_xfer: [OPTIONAL] the writefundamental primitive * @read_reg: [DRIVER-SPECIFIC] read out the register * @write_reg: [DRIVER-SPECIFIC] write data to the register -* @read_id: [REPLACEABLE] read out the ID data, and find -* the proper spi_device_id
If we remove this hook, i guess we will add it back in the later. Other new drivers will use this hook.
so i suggest to keep it as it is.
thanks
Huang Shijie
PATCH 2/5 spi-nor: Remove spi_nor::read_id operation
Quoted 47 lines · Huang Shijie
Quoted 38 lines · Ben Hutchings
There is currently no useful way to override the default implementation of this operation. The returned struct
spi_device_idmust have a pointer to structflash_infoin its private data, but this structure is defined inside spi-nor.Signed-off-by Ben Hutchings <[email protected]>--- drivers/mtd/spi-nor/spi-nor.c | 4 +--- include/linux/mtd/spi-nor.h | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-)drivers/mtd/spi-nor/spi-nor.c +1
-3@@ -902,8 +902,6 @@ static int spi_nor_check(struct spi_nor *nor)return -EINVAL ; } -if (!nor->read_id) - nor->read_id = spi_nor_read_id;if (!nor->wait_till_ready) nor->wait_till_ready = spi_nor_wait_till_ready;@@ -952,7 +950,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,if (info->jedec_id) {const struct spi_device_id *jid; - jid = nor->read_id (nor); + jid =spi_nor_read_id (nor);if (IS_ERR (jid)) {return PTR_ERR (jid); }else if (jid != id) {include/linux/mtd/spi-nor.h +0
-0include/linux/mtd/spi-nor.h enum spi_nor_ops { · line 143
Quoted 5 lines
include/linux/mtd/spi-nor.h +0
-2@@ -139,8 +139,6 @@ enum spi_nor_ops {* @write_xfer: [OPTIONAL] the writefundamental primitive * @read_reg: [DRIVER-SPECIFIC] read out the register * @write_reg: [DRIVER-SPECIFIC] write data to the register -* @read_id: [REPLACEABLE] read out the ID data, and find -* the proper spi_device_id If we remove this hook, i guess we will add it back in the later. Other new drivers will use this hook.
Quoted 1 line
so i suggest to keep it as it is.
It may well be needed, but it can't be implemented in its current form.
Ben.
Signature · 9 lines
Ben Hutchings Make three consecutive correct guesses and you will be considered an expert. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140915/950cc586/attachment.sig>
PATCH 3/5 spi-nor: Make spi_nor_scan() take a chip type name, not an spi_device_id
In reply to Ben HutchingsDrivers currently call spi_nor_match_id() and then spi_nor_scan(). This adds a dependency on struct spi_device_id which we want to avoid. Make spi_nor_scan() do it for them.
--- drivers/mtd/devices/m25p80.c | 6 +----- drivers/mtd/spi-nor/fsl-quadspi.c | 7 +------ drivers/mtd/spi-nor/spi-nor.c | 29 +++++++++++++---------------- include/linux/mtd/spi-nor.h | 21 ++++----------------- 4 files changed, 19 insertions(+), 44 deletions(-)
drivers/mtd/devices/m25p80.c +1 -5
@@ -196,7 +196,6 @@ static int m25p_probe(struct spi_device *spi)struct m25p *flash;struct spi_nor *nor;enum read_mode mode =SPI_NOR_NORMAL ; -const struct spi_device_id *id;int ret; flash =devm_kzalloc (&spi->dev,sizeof (*flash),GFP_KERNEL );
@@ -224,10 +223,7 @@ static int m25p_probe(struct spi_device *spi) mode =SPI_NOR_QUAD ; else if (spi->mode & SPI_RX_DUAL) mode =SPI_NOR_DUAL ; - id =spi_nor_match_id (spi_get_device_id (spi)->name); -if (WARN_ON (!id)) -return -ENODEV ; - ret =spi_nor_scan (nor, id, mode); + ret =spi_nor_scan (nor,spi_get_device_id (spi)->name, mode);if (ret)return ret;
drivers/mtd/spi-nor/fsl-quadspi.c +1 -6
@@ -881,7 +881,6 @@ static int fsl_qspi_probe(struct platform_device *pdev)/* iterate the subnodes. */ for_each_available_child_of_node (dev->of_node, np) { -const struct spi_device_id *id;char modalias[40 ];/* skip the holes */
@@ -909,10 +908,6 @@ static int fsl_qspi_probe(struct platform_device *pdev)if (of_modalias_node (np, modalias,sizeof (modalias)) <0 ) goto map_failed; - id =spi_nor_match_id (modalias); -if (!id) - goto map_failed; - ret =of_property_read_u32 (np,"spi-max-frequency" , &q->clk_rate);if (ret <0 )
@@ -921,7 +916,7 @@ static int fsl_qspi_probe(struct platform_device *pdev)/* set the chip address for READID */ fsl_qspi_set_base_addr (q, nor); - ret =spi_nor_scan (nor, id,SPI_NOR_QUAD ); + ret =spi_nor_scan (nor, modalias,SPI_NOR_QUAD );if (ret) goto map_failed;
drivers/mtd/spi-nor/spi-nor.c +13 -16
@@ -28,6 +28,8 @@#define JEDEC_MFR (_jedec_id) ((_jedec_id) >> 16) +static const struct spi_device_id *spi_nor_match_id (const char *name); +/* * Read the status register, returning its value in the location * Return the status register value.
@@ -908,9 +910,9 @@ static int spi_nor_check(struct spi_nor *nor)return 0 ; } -int spi_nor_scan (struct spi_nor *nor,const struct spi_device_id *id, -enum read_mode mode) +int spi_nor_scan (struct spi_nor *nor,const char *name,enum read_mode mode) { +const struct spi_device_id *id =NULL ;struct flash_info *info;struct flash_platform_data *data;struct device *dev = nor->dev;
@@ -930,21 +932,17 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id,*/ 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 + id =spi_nor_match_id (data->type); +if (!id)dev_warn (dev,"unrecognized id %s\n" , data->type); } +if (!id && name) + id =spi_nor_match_id (name); + +if (!id) +return -ENODEV ; + info = (void *)id->driver_data;if (info->jedec_id) {
@@ -1133,7 +1131,7 @@ int spi_nor_scan(struct spi_nor *nor, const struct spi_device_id *id, }EXPORT_SYMBOL_GPL (spi_nor_scan); -const struct spi_device_id *spi_nor_match_id (const char *name) +static const struct spi_device_id *spi_nor_match_id (const char *name) {const struct spi_device_id *id = spi_nor_ids;
@@ -1144,7 +1142,6 @@ const struct spi_device_id *spi_nor_match_id(const char *name) }return NULL ; } -EXPORT_SYMBOL_GPL (spi_nor_match_id);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Huang Shijie <[email protected]>" );
include/linux/mtd/spi-nor.h +4 -17
@@ -184,31 +184,18 @@ struct spi_nor {/** * spi_nor_scan() - scan the SPI NOR * @nor: the spi_nor structure -* @id: the spi_device_id provided by the driver +* @name: the chip type name * @mode: the read mode supported by the driver * * The drivers can use this fuction to scan the SPI NOR. * In the scanning, it will try to get all the necessary information to * fill the mtd_info{} and the spi_nor{}. * -* The board may assigns a spi_device_id with @id which be used to compared with -* the spi_device_id detected by the scanning. +* The chip type name can be provided either through platform data or +* through the @name parameter. Platform data takes precedence. * * Return: 0 for success, others for failure. */ -int spi_nor_scan (struct spi_nor *nor,const struct spi_device_id *id, -enum read_mode mode); - -/** -* spi_nor_match_id() - find the spi_device_id by the name -* @name: the name of the spi_device_id -* -* The drivers use this function to find the spi_device_id -* specified by the @name. -* -* Return: returns the right spi_device_id pointer on success, -* and returns NULL on failure. -*/ -const struct spi_device_id *spi_nor_match_id (const char *name); +int spi_nor_scan (struct spi_nor *nor,const char *name,enum read_mode mode);#endif
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/b3c0f038/attachment.sig>
PATCH 4/5 spi-nor: Replace struct spi_device_id with struct flash_info
In reply to Ben Hutchingsspi-nor does not depend on the SPI layer, so its use of struct spi_device_id adds an unnecessary indirection. Add the chip type name to struct flash_info and remove the wrapping struct spi_device_id.
--- drivers/mtd/devices/m25p80.c | 2 +- drivers/mtd/spi-nor/spi-nor.c | 344 +++++++++++++++++++++--------------------- 2 files changed, 172 insertions(+), 174 deletions(-)
drivers/mtd/devices/m25p80.c +1 -1
@@ -246,7 +246,7 @@ static int m25p_remove(struct spi_device *spi)/* -* XXX This needs to be kept in sync with spi_nor_ids. We can't share +* XXX This needs to be kept in sync with spi_nor_info. We can't share * it with spi-nor, because if this is built as a module then modpost * won't be able to read it and add appropriate aliases. */
drivers/mtd/spi-nor/spi-nor.c +171 -173
465 lines not on this page · raw message
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/2c9f4918/attachment-0001.sig>
PATCH 5/5 m25p80,spi-nor: Share the list of supported chip type names again
In reply to Ben HutchingsMove the list of chip type names to spi-nor.h. To avoid putting all the chip type information there, we define this list as a macro SPI_NOR_ENUM_TYPES() that invokes another macro SPI_NOR_ENUM_TYPE() that must be defined to expand each name to whatever form it's needed.
In spi-nor.c, use it to define enumerators, then use the enumerators as indices when defining spi_nor_info so that we cannot accidentally use a name that's not on the list.
This is somewhat complicated by the fact that some names include hyphens. SPI_NOR_ENUM_TYPE() therefore takes separate string and C identifier parameters.
--- drivers/mtd/devices/m25p80.c | 47 +------ drivers/mtd/spi-nor/spi-nor.c | 287 ++++++++++++++++++++++-------------------- include/linux/mtd/spi-nor.h | 72 +++++++++++ 3 files changed, 227 insertions(+), 179 deletions(-)
drivers/mtd/devices/m25p80.c +3 -44
@@ -245,51 +245,10 @@ static int m25p_remove(struct spi_device *spi) } -/* -* XXX This needs to be kept in sync with spi_nor_info. We can't share -* it with spi-nor, because if this is built as a module then modpost -* won't be able to read it and add appropriate aliases. -*/ static const struct spi_device_id m25p_ids[] = { - {"at25fs010" }, {"at25fs040" }, {"at25df041a" }, {"at25df321a" }, - {"at25df641" }, {"at26f004" }, {"at26df081a" }, {"at26df161a" }, - {"at26df321" }, {"at45db081d" }, - {"en25f32" }, {"en25p32" }, {"en25q32b" }, {"en25p64" }, - {"en25q64" }, {"en25qh128" }, {"en25qh256" }, - {"f25l32pa" }, - {"mr25h256" }, {"mr25h10" }, - {"gd25q32" }, {"gd25q64" }, - {"160s33b" }, {"320s33b" }, {"640s33b" }, - {"mx25l2005a" }, {"mx25l4005a" }, {"mx25l8005" }, {"mx25l1606e" }, - {"mx25l3205d" }, {"mx25l3255e" }, {"mx25l6405d" }, {"mx25l12805d" }, - {"mx25l12855e" },{"mx25l25635e" },{"mx25l25655e" },{"mx66l51235l" }, - {"mx66l1g55g" }, - {"n25q064" }, {"n25q128a11" }, {"n25q128a13" }, {"n25q256a" }, - {"n25q512a" }, {"n25q512ax3" }, {"n25q00" }, - {"pm25lv512" }, {"pm25lv010" }, {"pm25lq032" }, - {"s25sl032p" }, {"s25sl064p" }, {"s25fl256s0" }, {"s25fl256s1" }, - {"s25fl512s" }, {"s70fl01gs" }, {"s25sl12800" }, {"s25sl12801" }, - {"s25fl129p0" }, {"s25fl129p1" }, {"s25sl004a" }, {"s25sl008a" }, - {"s25sl016a" }, {"s25sl032a" }, {"s25sl064a" }, {"s25fl008k" }, - {"s25fl016k" }, {"s25fl064k" }, - {"sst25vf040b" },{"sst25vf080b" },{"sst25vf016b" },{"sst25vf032b" }, - {"sst25vf064c" },{"sst25wf512" }, {"sst25wf010" }, {"sst25wf020" }, - {"sst25wf040" }, - {"m25p05" }, {"m25p10" }, {"m25p20" }, {"m25p40" }, - {"m25p80" }, {"m25p16" }, {"m25p32" }, {"m25p64" }, - {"m25p128" }, {"n25q032" }, - {"m25p05-nonjedec" }, {"m25p10-nonjedec" }, {"m25p20-nonjedec" }, - {"m25p40-nonjedec" }, {"m25p80-nonjedec" }, {"m25p16-nonjedec" }, - {"m25p32-nonjedec" }, {"m25p64-nonjedec" }, {"m25p128-nonjedec" }, - {"m45pe10" }, {"m45pe80" }, {"m45pe16" }, - {"m25pe20" }, {"m25pe80" }, {"m25pe16" }, - {"m25px16" }, {"m25px32" }, {"m25px32-s0" }, {"m25px32-s1" }, - {"m25px64" }, - {"w25x10" }, {"w25x20" }, {"w25x40" }, {"w25x80" }, - {"w25x16" }, {"w25x32" }, {"w25q32" }, {"w25q32dw" }, - {"w25x64" }, {"w25q64" }, {"w25q128" }, {"w25q80" }, - {"w25q80bl" }, {"w25q128" }, {"w25q256" }, {"cat25c11" }, - {"cat25c03" }, {"cat25c09" }, {"cat25c17" }, {"cat25128" }, +#define SPI_NOR_ENUM_TYPE(s, c) { s }, + SPI_NOR_ENUM_TYPES() +#undef SPI_NOR_ENUM_TYPE { }, };MODULE_DEVICE_TABLE (spi, m25p_ids);
drivers/mtd/spi-nor/spi-nor.c +152 -135
338 lines not on this page · raw message
include/linux/mtd/spi-nor.h +72 -0
76 lines not on this page · raw message
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/b5b0969d/attachment.sig>
PATCH 5/5 m25p80, spi-nor: Share the list of supported chip type names again
Hi Ben,
Quoted 5 lines · Ben Hutchings
Move the list of chip type names to
spi-nor.h. To avoid putting all the chip type information there, we define this list as a macroSPI_NOR_ENUM_TYPES()that invokes another macroSPI_NOR_ENUM_TYPE()that must be defined to expand each name to whatever form it's needed.
Quoted 7 lines
In
spi-nor.c, use it to define enumerators, then use the enumerators as indices when definingspi_nor_infoso that we cannot accidentally use a name that's not on the list.This is somewhat complicated by the fact that some names include hyphens.
SPI_NOR_ENUM_TYPE()therefore takes separate string and C identifier parameters.
Thanks for doing this!
However, the table generation still looks overly complicated to me, with too much duplication which needs to be kept in sync.
Quoted 12 lines
drivers/mtd/devices/m25p80.c +0
-5@@ -245,51 +245,10 @@ static int m25p_remove(struct spi_device *spi) } -/* -* XXX This needs to be kept in sync with spi_nor_info. We can't share -* it with spi-nor, because if this is built as a module then modpost -* won't be able to read it and add appropriate aliases. -*/ static const struct spi_device_id m25p_ids[] = {
[...]
drivers/mtd/spi-nor/spi-nor.c struct flash_info { · line 488
Quoted 13 lines
drivers/mtd/devices/m25p80.c +3
-0+#define SPI_NOR_ENUM_TYPE (s, c) { s }, + SPI_NOR_ENUM_TYPES() +#undef SPI_NOR_ENUM_TYPE { },drivers/mtd/spi-nor/spi-nor.c +2
-0/* NOTE: double check command sets and memory organization when you add * more nor chips. This current list focusses on newer chips, which * have been converging on command sets which including JEDEC ID. +* +* All chip type names must be added to __SPI_NOR_ENUM_TYPES in
Oops... These will get out of sync.
Quoted 9 lines
+ *
spi-nor.hbefore they can be used here (enforced by using the
+ * names to index this array).
*/static const struct flash_info spi_nor_info[] = { /* Atmel -- some are (confusingly) marketed as "DataFlash" */drivers/mtd/spi-nor/spi-nor.c +2
-2-INFO ("at25fs010" ,0x1f6601 ,0 ,32 *1024 ,4 ,SECT_4K ), - INFO("at25fs040", 0x1f6604, 0, 64 * 1024, 8, SECT_4K), +INFO (at25fs010,0x1f6601 ,0 ,32 *1024 ,4 ,SECT_4K ), + INFO(at25fs040, 0x1f6604, 0, 64 * 1024, 8, SECT_4K),
[...]
include/linux/mtd/spi-nor.h struct spi_nor { · line 203
Quoted 9 lines
include/linux/mtd/spi-nor.h +3
-0@@ -198,4 +198,76 @@ struct spi_nor {*/ int spi_nor_scan (struct spi_nor *nor,const char *name,enum read_mode mode); +#define __SPI_NOR_ENUM_TYPES (c_id, str_and_c_id) \ + c_id(at25fs010) c_id(at25fs040) c_id(at25df041a) \ + c_id(at25df321a) c_id(at25df641) c_id(at26f004) \
Can't you just have the IDs in a header file only, and let the header file generate either a struct flash_info or a struct spi_device_id table, using a macro defined by the file that includes it?
Cfr. include/uapi/asm-generic/unistd.h and its use of __SYSCALL()?
Or am I missing something (e.g. this is impossible due to the hyphens in the names?).
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
PATCH 5/5 m25p80,spi-nor: Share the list of supported chip type names again
Quoted 12 lines · Geert Uytterhoeven
Hi Ben,
Quoted 9 lines · Ben Hutchings
Move the list of chip type names to
spi-nor.h. To avoid putting all the chip type information there, we define this list as a macroSPI_NOR_ENUM_TYPES()that invokes another macroSPI_NOR_ENUM_TYPE()that must be defined to expand each name to whatever form it's needed.In
spi-nor.c, use it to define enumerators, then use the enumerators as indices when definingspi_nor_infoso that we cannot accidentally use a name that's not on the list.
Quoted 8 lines
Quoted 3 lines
This is somewhat complicated by the fact that some names include hyphens.
SPI_NOR_ENUM_TYPE()therefore takes separate string and C identifier parameters.Thanks for doing this!
However, the table generation still looks overly complicated to me, with too much duplication which needs to be kept in sync.
It does need to be kept in sync, but the compiler will check that.
[...]
Quoted 6 lines
Quoted 6 lines
include/linux/mtd/spi-nor.h +0
-0@@ -198,4 +198,76 @@ struct spi_nor {*/ int spi_nor_scan (struct spi_nor *nor,const char *name,enum read_mode mode);
Quoted 7 lines
include/linux/mtd/spi-nor.h struct spi_nor { · line 203
Quoted 3 lines
include/linux/mtd/spi-nor.h +3
-0+#define __SPI_NOR_ENUM_TYPES (c_id, str_and_c_id) \ + c_id(at25fs010) c_id(at25fs040) c_id(at25df041a) \ + c_id(at25df321a) c_id(at25df641) c_id(at26f004) \Can't you just have the IDs in a header file only, and let the header file generate either a struct
flash_infoor a structspi_device_idtable, using a macro defined by the file that includes it?
How would we match up the rest of the struct flash_info to the name?
Quoted 4 lines
Cfr.
include/uapi/asm-generic/unistd.hand its use of__SYSCALL()?Or am I missing something (e.g. this is impossible due to the hyphens in the names?).
Well the hyphens are only a problem because we want C identifiers. But we only need C identifiers so we can enforce that each struct flash_info matches a name on the list. If you can find a way to match them up without having to define enumerators, that would of course be preferable.
Ben.
Signature · 9 lines
Ben Hutchings Make three consecutive correct guesses and you will be considered an expert. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140915/90366ebe/attachment.sig>
PATCH 5/5 m25p80, spi-nor: Share the list of supported chip type names again
Hi Ben,
Quoted 10 lines · Ben Hutchings
Quoted 8 lines
include/linux/mtd/spi-nor.h struct spi_nor { · line 203
Quoted 4 lines
include/linux/mtd/spi-nor.h +3
-0+#define __SPI_NOR_ENUM_TYPES (c_id, str_and_c_id) \ + c_id(at25fs010) c_id(at25fs040) c_id(at25df041a) \ + c_id(at25df321a) c_id(at25df641) c_id(at26f004) \Can't you just have the IDs in a header file only, and let the header file generate either a struct
flash_infoor a structspi_device_idtable, using a macro defined by the file that includes it?How would we match up the rest of the struct
flash_infoto the name?
Ah, you use the enums to match the names to the rest of the flash_info. But you can do it in one-shot, can't you?
spi-nor-data.h:
FLASH_ENTRY("at25fs010", 0x1f6601, 0, 32 * 1024, 4, SECT_4K),FLASH_ENTRY("at25fs040", 0x1f6604, 0, 64 * 1024, 8, SECT_4K),
...
m25p80.c:
#define FLASH_ENTRY(_name, _jedec_id, _ext_id, _sector_size,
_n_sectors, _flags) \
{ .name = _name },static const struct spi_device_id m25p_ids[] = {
#include "spi-nor-data.h"
};
spi-nor.c:
#define FLASH_ENTRY(_name, _jedec_id, _ext_id, _sector_size,
_n_sectors, _flags) \
{ \
.name = _name, \
.jedec_id = (_jedec_id), \
.ext_id = (_ext_id), \
.sector_size = (_sector_size), \
.n_sectors = (_n_sectors), \
.page_size = 256, \
.flags = (_flags), \
}static const struct flash_info spi_nor_info[] = {
#include "spi-nor-data.h"
};
Then the whole table data in contained in one place (spi-nor-data.h). Am I still missing something?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
PATCH 5/5 m25p80,spi-nor: Share the list of supported chip type names again
Quoted 8 lines · Geert Uytterhoeven
Hi Ben,
Quoted 5 lines · Ben Hutchings
Quoted 5 lines
Quoted 4 lines
include/linux/mtd/spi-nor.h +3
-0+#define __SPI_NOR_ENUM_TYPES (c_id, str_and_c_id) \ + c_id(at25fs010) c_id(at25fs040) c_id(at25df041a) \ + c_id(at25df321a) c_id(at25df641) c_id(at26f004) \
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Can't you just have the IDs in a header file only, and let the header file generate either a struct
flash_infoor a structspi_device_idtable, using a macro defined by the file that includes it?How would we match up the rest of the struct
flash_infoto the name?Ah, you use the enums to match the names to the rest of the
flash_info. But you can do it in one-shot, can't you?
[...]
I know, but I didn't want to expose the data in a header file. As other people consider that a lesser evil than this rather complex approach, I'll do it the simple way.
Ben.
Signature · 9 lines
Ben Hutchings The two most common things in the universe are hydrogen and stupidity. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140930/2e442ad3/attachment.sig>
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
In reply to Ben HutchingsQuoted 9 lines · Ben Hutchings
The first patch in the series restores the module aliases to m25p80, but it does so by duplicating the list of names. This should be suitable for stable, but it isn't viable in the longer term.
The following patches change the spi-nor interface so that this duplication is no longer necessary. This includes removing
spi_nor::read_id, but it could be re-added after this with a different interface, e.g. returning aflash_infostructure (which would need to be defined inspi_nor.h).
Note that these patch are:
- Based on your 'testing' branch
- Untested by me, aside from compiling and checking that m25p80 has the expected module aliases
Ben.
Signature · 9 lines
Ben Hutchings The world is coming to an end. Please log off. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140914/5e97912a/attachment-0001.sig>
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
Quoted 5 lines · Ben Hutchings
Quoted 4 lines · Ben Hutchings
The first patch in the series restores the module aliases to m25p80, but it does so by duplicating the list of names. This should be suitable for stable, but it isn't viable in the longer term.
Quoted 8 lines
Quoted 5 lines
The following patches change the spi-nor interface so that this duplication is no longer necessary. This includes removing
spi_nor::read_id, but it could be re-added after this with a different interface, e.g. returning aflash_infostructure (which would need to be defined inspi_nor.h).Note that these patch are:
- Based on your 'testing' branch
Which testing branch? These two are the only official repos for MTD:
git git://git.infradead.org/linux-mtd.git
git git://git.infradead.org/l2-mtd.git
Quoted 2 lines
- Untested by me, aside from compiling and checking that m25p80 has the expected module aliases
Brian
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
Quoted 12 lines · Brian Norris
Quoted 11 lines · Ben Hutchings
Quoted 9 lines · Ben Hutchings
The first patch in the series restores the module aliases to m25p80, but it does so by duplicating the list of names. This should be suitable for stable, but it isn't viable in the longer term.
The following patches change the spi-nor interface so that this duplication is no longer necessary. This includes removing
spi_nor::read_id, but it could be re-added after this with a different interface, e.g. returning aflash_infostructure (which would need to be defined inspi_nor.h).
Quoted 8 lines
Quoted 2 lines
Note that these patch are:
- Based on your 'testing' branchWhich testing branch? These two are the only official repos for MTD:
git
git://git.infradead.org/linux-mtd.git
gitgit://git.infradead.org/l2-mtd.git
You had a testing branch ingit://git.infradead.org/users/norris/linux-mtd.git, and that included commit af249c3a0ca8 ('mtd: spi-nor: remove duplicated w25q128 entry') which this patch series depended on.
Ben.
Quoted 4 lines
Quoted 2 lines
- Untested by me, aside from compiling and checking that m25p80 has the expected module aliases
Brian
Signature · 9 lines
Ben Hutchings The two most common things in the universe are hydrogen and stupidity. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 811 bytes Desc: This is a digitally signed message part URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140930/d7e348b5/attachment.sig>
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
Quoted 8 lines · Ben Hutchings
Quoted 7 lines · Brian Norris
Quoted 2 lines · Ben Hutchings
Note that these patch are:
- Based on your 'testing' branchWhich testing branch? These two are the only official repos for MTD:
Quoted 7 lines
Quoted 2 lines
git
git://git.infradead.org/linux-mtd.git
gitgit://git.infradead.org/l2-mtd.gitYou had a testing branch in
git://git.infradead.org/users/norris/linux-mtd.git, and that included commitaf249c3a0ca8('mtd: spi-nor: remove duplicated w25q128 entry') which this patch series depended on.
That repository is very much unofficial. I have a MAINTAINERS patch queued up to add git://git.infradead.org/l2-mtd.git (our -next repo) to reduce future confusion.
Regards,
Brian
cover m25p80,spi-nor: Fix module aliases for m25p80; clean up chip identification
In reply to Ben HutchingsQuoted 3 lines · Ben Hutchings
The first patch in the series restores the module aliases to m25p80, but it does so by duplicating the list of names. This should be suitable for stable, but it isn't viable in the longer term.
Please don't CC patches not for the SPI subsystem to linux-spi, they
just clog up patchwork for no benefit.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20140928/d3329005/attachment-0001.sig>