mtd: spi-nor: support dumping sfdp tables
Subsystems (2)
v4 cover mtd: spi-nor: support dumping sfdp tables
Add the possibility to dump the SFDP data of a flash device.
More and more flash devices share the same flash ID and we need per device fixups. Usually, these fixups differentiate flashes by looking at differences in the SFDP data. Determining the difference is only possible if we have the SFDP data for all the flashes which share a flash ID. This will lay the foundation to dump the whole SFDP data of a flash device.
This is even more important, because some datasheets doesn't even contain the SFDP data. Fixups for these kind of flashes are nearly impossible to do.
I envision having a database of all the SFDP data for the flashes we support and make it a requirement to submit it when a new flash is added. This might or might not have legal implications. Thus I'd start with having that database private to the SPI NOR maintainers.
Changes since v3:
- move spi-nor attributes into spi-nor/ subdirectory, suggested by Alexander Williams.
Changes since v2:
- use .dev_groups of the driver to attach the attributes
- add manufacturer attribute
- rename attribute name to partname
- add ABI documentation
Changes since v1:
- use sysfs_emit()
- add comment about the allocation of the sfdp dwords
- free SFDP memory in the error path
- use BIN_ATTR_RO(sfdp, 0)
- use spi_nor_read_sfdp()
Changes since RFC:
- Don't read SFDP data after probe. The flash might already be switched to 8D-8D-8D mode. Instead, cache the SFDP data
- add two sysfs files: jedec-id and name
- change the file mode of the sfdp file from 0400 to 0444. There is no hardware access anymore.
Michael Walle (2):
mtd: spi-nor: sfdp: save a copy of the SFDP data
mtd: spi-nor: add initial sysfs support
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 12 +++ drivers/mtd/spi-nor/sfdp.c | 58 ++++++++++++ drivers/mtd/spi-nor/sysfs.c | 93 +++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 + 7 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.c
Signature · 1 line
2.20.1
PATCH v4 1/2 mtd: spi-nor: sfdp: save a copy of the SFDP data
Due to possible mode switching to 8D-8D-8D, it might not be possible to read the SFDP after the initial probe. To be able to dump the SFDP via sysfs afterwards, make a complete copy of it.
--- drivers/mtd/spi-nor/core.h | 10 +++++++ drivers/mtd/spi-nor/sfdp.c | 58 +++++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 ++ 3 files changed, 70 insertions(+)
drivers/mtd/spi-nor/core.h +10 -0
@@ -460,6 +460,16 @@ struct spi_nor_manufacturer {const struct spi_nor_fixups *fixups; }; +/** +* struct sfdp - SFDP data +* @num_dwords: number of entries in the dwords array +* @dwords: array of double words of the SFDP data +*/ +struct sfdp { +size_t num_dwords; +u32 *dwords; +}; +/* Manufacturer drivers. */ extern const struct spi_nor_manufacturer spi_nor_atmel;extern const struct spi_nor_manufacturer spi_nor_catalyst;
drivers/mtd/spi-nor/sfdp.c +58 -0
82 lines not on this page · raw message
include/linux/mtd/spi-nor.h +2 -0
@@ -383,6 +383,7 @@ struct spi_nor_flash_parameter;* @read_proto: the SPI protocol for read operations * @write_proto: the SPI protocol for write operations * @reg_proto: the SPI protocol for read_reg/write_reg/erase operations +* @sfdp: the SFDP data of the flash * @controller_ops: SPI NOR controller driver specific operations. * @params: [FLASH-SPECIFIC] SPI NOR flash parameters and settings. * The structure includes legacy flash parameters and
@@ -412,6 +413,7 @@ struct spi_nor {bool sst_write_second;u32 flags;enum spi_nor_cmd_ext cmd_ext_type; +struct sfdp *sfdp;const struct spi_nor_controller_ops *controller_ops;
Signature · 1 line
2.20.1
PATCH v4 2/2 mtd: spi-nor: add initial sysfs support
In reply to Michael WalleAdd support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes.
.../ABI/testing/sysfs-bus-spi-devices-spi-nor | 31 +++++++ drivers/mtd/spi-nor/Makefile | 2 +- drivers/mtd/spi-nor/core.c | 1 + drivers/mtd/spi-nor/core.h | 2 + drivers/mtd/spi-nor/sysfs.c | 93 +++++++++++++++++++ 5 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor create mode 100644 drivers/mtd/spi-nor/sysfs.c
Documentation/ABI/testing/sysfs-bus-spi-devices-spi-nor new file +31 -0
@@ -0,0 +1,31 @@ +What: /sys/bus/spi/devices/.../spi-nor/jedec_id +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) The JEDEC ID of the SPI NOR flash as reported by the + flash device. + + +What: /sys/bus/spi/devices/.../spi-nor/manufacturer +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Manufacturer of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../spi-nor/partname +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) Part name of the SPI NOR flash. + + +What: /sys/bus/spi/devices/.../spi-nor/sfdp +Date: April 2021 +KernelVersion: 5.14 +Contact: [email protected] +Description: (RO) This attribute is only present if the SPI NOR flash + device supports the "Read SFDP" command (5Ah). + + If present, it contains the complete SFDP (serial flash + discoverable parameters) binary data of the flash.
drivers/mtd/spi-nor/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -spi-nor-objs := core.o sfdp.o swp.o otp.o +spi-nor-objs := core.o sfdp.o swp.o otp.o sysfs.o spi-nor-objs += atmel.o spi-nor-objs += catalyst.o spi-nor-objs += eon.o
drivers/mtd/spi-nor/core.c +1 -0
@@ -3349,6 +3349,7 @@ static struct spi_mem_driver spi_nor_driver = { .driver = { .name = "spi-nor", .of_match_table = spi_nor_of_table, + .dev_groups = spi_nor_sysfs_groups, }, .id_table = spi_nor_dev_ids, },
drivers/mtd/spi-nor/core.h +2 -0
@@ -489,6 +489,8 @@ extern const struct spi_nor_manufacturer spi_nor_winbond;extern const struct spi_nor_manufacturer spi_nor_xilinx;extern const struct spi_nor_manufacturer spi_nor_xmc; +extern const struct attribute_group *spi_nor_sysfs_groups[]; +void spi_nor_spimem_setup_op (const struct spi_nor *nor,struct spi_mem_op *op,const enum spi_nor_protocol proto);
drivers/mtd/spi-nor/sysfs.c new file +93 -0
93 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v4 2/2] mtd: spi-nor: add initial sysfs support
Quoted 6 lines · Michael Walle
Add support to show the manufacturer, the partname and JEDEC identifier as well as to dump the SFDP table. Not all flashes list their SFDP table contents in their datasheet. So having that is useful. It might also be helpful in bug reports from users.
Signed-off-by Michael Walle <[email protected]>
Quoted 3 lines
---
Pratyush, Heiko, I've dropped your Acked and Tested-by because there were some changes.
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Quoted 9 lines · Michael Walle
Add the possibility to dump the SFDP data of a flash device.
More and more flash devices share the same flash ID and we need per device fixups. Usually, these fixups differentiate flashes by looking at differences in the SFDP data. Determining the difference is only possible if we have the SFDP data for all the flashes which share a flash ID. This will lay the foundation to dump the whole SFDP data of a flash device.
[...]
Applied to spi-nor/next, thanks!
[1/2] mtd: spi-nor: sfdp: save a copy of the SFDP data
https://git.kernel.org/mtd/c/65b6d89d45 [2/2] mtd: spi-nor: add initial sysfs support https://git.kernel.org/mtd/c/36ac022862
--
Regards
Vignesh