mtd: spi-nor: export spi_nor_hwcaps_pp2cmd()
Subsystems (2)
PATCH v2 1/2 mtd: spi-nor: export spi_nor_hwcaps_pp2cmd()
The function will also be used by the debugfs module.
---
changes since rfc (v1):
- none
drivers/mtd/spi-nor/core.c | 2 +- drivers/mtd/spi-nor/core.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/core.c +1 -1
@@ -1880,7 +1880,7 @@ int spi_nor_hwcaps_read2cmd(u32 hwcaps) ARRAY_SIZE(hwcaps_read2cmd)); } -static int spi_nor_hwcaps_pp2cmd (u32 hwcaps) +int spi_nor_hwcaps_pp2cmd (u32 hwcaps) {static const int hwcaps_pp2cmd[][2 ] = { {SNOR_HWCAPS_PP ,SNOR_CMD_PP },
drivers/mtd/spi-nor/core.h +1 -0
@@ -669,6 +669,7 @@ int spi_nor_otp_lock_sr2(struct spi_nor *nor, unsigned int region);int spi_nor_otp_is_locked_sr2 (struct spi_nor *nor,unsigned int region);int spi_nor_hwcaps_read2cmd (u32 hwcaps); +int spi_nor_hwcaps_pp2cmd (u32 hwcaps);u8 spi_nor_convert_3to4_read (u8 opcode); void spi_nor_set_read_settings(struct spi_nor_read_command *read, u8 num_mode_clocks,
Signature · 1 line
2.30.2
PATCH v2 2/2 mtd: spi-nor: expose internal parameters via debugfs
There is no way to gather all information to verify support for a new flash chip. Also if you want to convert an existing flash chip to the new SFDP parsing, there is not enough information to determine if the flash will work like before. To ease this development, expose internal parameters via the debugfs.
---
changes since rfc (v1):
- rebase onto latest next
- drop spi_nor_debugfs_unregister() and use devm_add_action() instead
- output style fixes, (0x prefix, whitespace around '|')
drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/core.c | 2 + drivers/mtd/spi-nor/core.h | 6 + drivers/mtd/spi-nor/debugfs.c | 248 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 + 5 files changed, 259 insertions(+) create mode 100644 drivers/mtd/spi-nor/debugfs.c
drivers/mtd/spi-nor/Makefile +1 -0
@@ -17,6 +17,7 @@ spi-nor-objs += sst.o spi-nor-objs += winbond.o spi-nor-objs += xilinx.o spi-nor-objs += xmc.o +spi-nor-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o obj-$(CONFIG_MTD_SPI_NOR) += controllers/
drivers/mtd/spi-nor/core.c +2 -0
@@ -3157,6 +3157,8 @@ static int spi_nor_probe(struct spi_mem *spimem)if (ret)return ret; +spi_nor_debugfs_register (nor); +/* * None of the existing parts have > 512B pages, but let's play safe * and add this logic so that if anyone ever adds support for such
drivers/mtd/spi-nor/core.h +6 -0
@@ -705,4 +705,10 @@ static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) return container_of(mtd, struct spi_nor, mtd); } +#ifdef CONFIG_DEBUG_FS +void spi_nor_debugfs_register (struct spi_nor *nor); +#else +static inline void spi_nor_debugfs_register (struct spi_nor *nor) {} +#endif +#endif /* __LINUX_MTD_SPI_NOR_INTERNAL_H */
drivers/mtd/spi-nor/debugfs.c new file +248 -0
248 lines not on this page · raw message
include/linux/mtd/spi-nor.h +2 -0
@@ -365,6 +365,7 @@ struct spi_nor_flash_parameter;* @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 +* @debugfs_root: pointer to the debugfs directory * @controller_ops: SPI NOR controller driver specific operations. * @params: [FLASH-SPECIFIC] SPI NOR flash parameters and settings. * The structure includes legacy flash parameters and
@@ -394,6 +395,7 @@ struct spi_nor {u32 flags;enum spi_nor_cmd_ext cmd_ext_type;struct sfdp *sfdp; +struct dentry *debugfs_root;const struct spi_nor_controller_ops *controller_ops;
Signature · 1 line
2.30.2
Re: [PATCH v2 2/2] mtd: spi-nor: expose internal parameters via debugfs
Hi Michael,
Quoted 86 lines · Michael Walle
There is no way to gather all information to verify support for a new flash chip. Also if you want to convert an existing flash chip to the new SFDP parsing, there is not enough information to determine if the flash will work like before. To ease this development, expose internal parameters via the debugfs.
Signed-off-by Michael Walle <[email protected]>---
changes since rfc (v1):
- rebase onto latest next
- dropspi_nor_debugfs_unregister()and usedevm_add_action()instead
- output style fixes, (0x prefix, whitespace around '|')drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/core.c | 2 + drivers/mtd/spi-nor/core.h | 6 + drivers/mtd/spi-nor/debugfs.c | 248 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spi-nor.h | 2 + 5 files changed, 259 insertions(+) create mode 100644 drivers/mtd/spi-nor/debugfs.cdrivers/mtd/spi-nor/Makefile +1
-0@@ -17,6 +17,7 @@ spi-nor-objs += sst.o spi-nor-objs += winbond.o spi-nor-objs += xilinx.o spi-nor-objs += xmc.o +spi-nor-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o obj-$(CONFIG_MTD_SPI_NOR) += controllers/drivers/mtd/spi-nor/core.c +2
-0@@ -3157,6 +3157,8 @@ static int spi_nor_probe(struct spi_mem *spimem)if (ret)return ret; +spi_nor_debugfs_register (nor); +/* * None of the existing parts have > 512B pages, but let's play safe * and add this logic so that if anyone ever adds support for such drivers/mtd/spi-nor/core.h +6
-0@@ -705,4 +705,10 @@ static inline struct spi_nor *mtd_to_spi_nor(struct mtd_info *mtd) return container_of(mtd, struct spi_nor, mtd); } +#ifdef CONFIG_DEBUG_FS +void spi_nor_debugfs_register (struct spi_nor *nor); +#else +static inline void spi_nor_debugfs_register (struct spi_nor *nor) {} +#endif +#endif /* __LINUX_MTD_SPI_NOR_INTERNAL_H */ drivers/mtd/spi-nor/debugfs.c new file +19
-0@@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <linux/mtd/spi-nor.h> +#include <linux/spi/spi.h> +#include <linux/spi/spi-mem.h> +#include <linux/debugfs.h> + +#include "core.h" + +static struct dentry *rootdir; + +#define SNOR_F_NAME (name) [ilog2(SNOR_F_##name)] = #name +static const char *const snor_f_names[] = { +SNOR_F_NAME (HAS_SR_TB ), +SNOR_F_NAME (NO_OP_CHIP_ERASE ), +SNOR_F_NAME (BROKEN_RESET ), + SNOR_F_NAME(4B_OPCODES), +SNOR_F_NAME (HAS_4BAIT ), +SNOR_F_NAME (HAS_LOCK ),
drivers/mtd/spi-nor/debugfs.c line 29
Quoted 10 lines
drivers/mtd/spi-nor/debugfs.c new file +10
-0+SNOR_F_NAME (HAS_16BIT_SR ), +SNOR_F_NAME (NO_READ_CR ), +SNOR_F_NAME (HAS_SR_TB_BIT6 ), +SNOR_F_NAME (HAS_4BIT_BP ), +SNOR_F_NAME (HAS_SR_BP3_BIT6 ), +SNOR_F_NAME (IO_MODE_EN_VOLATILE ), +SNOR_F_NAME (SOFT_RESET ), + SNOR_F_NAME(SWP_IS_VOLATILE), +}; +#undef SNOR_F_NAME
You said you would add a comment here. Changed your mind?
Quoted 24 lines
drivers/mtd/spi-nor/debugfs.c new file +24
-0+ +static const char *spi_nor_protocol_name (enum spi_nor_protocol proto) +{ +switch (proto) { +case SNOR_PROTO_1_1_1 :return "1S-1S-1S" ; +case SNOR_PROTO_1_1_2 :return "1S-1S-2S" ; +case SNOR_PROTO_1_1_4 :return "1S-1S-4S" ; +case SNOR_PROTO_1_1_8 :return "1S-1S-8S" ; +case SNOR_PROTO_1_2_2 :return "1S-2S-2S" ; +case SNOR_PROTO_1_4_4 :return "1S-4S-4S" ; +case SNOR_PROTO_1_8_8 :return "1S-8S-8S" ; +case SNOR_PROTO_2_2_2 :return "2S-2S-2S" ; +case SNOR_PROTO_4_4_4 :return "4S-4S-4S" ; +case SNOR_PROTO_8_8_8 :return "8S-8S-8S" ; +case SNOR_PROTO_1_1_1_DTR :return "1D-1D-1D" ; +case SNOR_PROTO_1_2_2_DTR :return "1D-2D-2D" ; +case SNOR_PROTO_1_4_4_DTR :return "1D-4D-4D" ; +case SNOR_PROTO_1_8_8_DTR :return "1D-8D-8D" ; +case SNOR_PROTO_8_8_8_DTR :return "8D-8D-8D" ; + } + +return "<unknown>" ; +} +
[...]
Quoted 7 lines
drivers/mtd/spi-nor/debugfs.c new file +7
-0+ +static void spi_nor_debugfs_unregister (void *data) +{ +struct spi_nor *nor = data; + +debugfs_remove (nor->debugfs_root); + nor->debugfs_root =NULL ;
drivers/mtd/spi-nor/debugfs.c line 236
Quoted 10 lines
drivers/mtd/spi-nor/debugfs.c new file +10
-0+} + +void spi_nor_debugfs_register (struct spi_nor *nor) +{ +struct dentry *d; +int ret; + +/* Create rootdir once. Will never be deleted again. */ +if (!rootdir) + rootdir =debugfs_create_dir ("spi-nor" ,NULL );
If I compile SPI NOR as module, I insmod it, rmmod it, and then insmod it again, I get:
[ 360.623465] spi-nor spi0.0: mt35xu512aba (65536 Kbytes) [ 360.623478] debugfs: Directory 'spi-nor' with parent '/' already present! [ 360.632237] spi-nor spi1.0: mt25qu512a (65536 Kbytes)
I guess when you remove the module, rootdir also gets destroyed, and then gets re-initialized on probing again. I am not familiar enough with the debugfs APIs to suggest a fix though.
Patch looks good to me otherwise.
Quoted 35 lines
drivers/mtd/spi-nor/debugfs.c new file +12
-0+ + ret =devm_add_action (nor->dev, spi_nor_debugfs_unregister, nor); +if (ret) +return ; + + d =debugfs_create_dir (dev_name (nor->dev), rootdir); + nor->debugfs_root = d; + +debugfs_create_file ("params" ,0444 , d, nor, &spi_nor_params_fops); +debugfs_create_file ("capabilities" ,0444 , d, nor, + &spi_nor_capabilities_fops); +}include/linux/mtd/spi-nor.h +2
-0@@ -365,6 +365,7 @@ struct spi_nor_flash_parameter;* @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 +* @debugfs_root: pointer to the debugfs directory * @controller_ops: SPI NOR controller driver specific operations. * @params: [FLASH-SPECIFIC] SPI NOR flash parameters and settings. * The structure includes legacy flash parameters and @@ -394,6 +395,7 @@ struct spi_nor {u32 flags;enum spi_nor_cmd_ext cmd_ext_type;struct sfdp *sfdp; +struct dentry *debugfs_root;const struct spi_nor_controller_ops *controller_ops;Signature · 1 line
2.30.2
Signature · 3 lines
Regards, Pratyush Yadav Texas Instruments Inc.
Re: [PATCH v2 2/2] mtd: spi-nor: expose internal parameters via debugfs
Hi,
Quoted 12 lines
Quoted 12 lines
drivers/mtd/spi-nor/debugfs.c new file +12
-0+#define SNOR_F_NAME (name) [ilog2(SNOR_F_##name)] = #name +static const char *const snor_f_names[] = { +SNOR_F_NAME (HAS_SR_TB ), +SNOR_F_NAME (NO_OP_CHIP_ERASE ), +SNOR_F_NAME (BROKEN_RESET ), + SNOR_F_NAME(4B_OPCODES), +SNOR_F_NAME (HAS_4BAIT ), +SNOR_F_NAME (HAS_LOCK ), +SNOR_F_NAME (HAS_16BIT_SR ), +SNOR_F_NAME (NO_READ_CR ), +SNOR_F_NAME (HAS_SR_TB_BIT6 ), +SNOR_F_NAME (HAS_4BIT_BP ),
Quoted 8 lines
drivers/mtd/spi-nor/debugfs.c line 29
Quoted 6 lines
drivers/mtd/spi-nor/debugfs.c new file +6
-0+SNOR_F_NAME (HAS_SR_BP3_BIT6 ), +SNOR_F_NAME (IO_MODE_EN_VOLATILE ), +SNOR_F_NAME (SOFT_RESET ), + SNOR_F_NAME(SWP_IS_VOLATILE), +}; +#undef SNOR_F_NAMEYou said you would add a comment here. Changed your mind?
No, it just slipped through.
Quoted 12 lines
drivers/mtd/spi-nor/debugfs.c line 236
Quoted 8 lines
drivers/mtd/spi-nor/debugfs.c new file +8
-0+void spi_nor_debugfs_register (struct spi_nor *nor) +{ +struct dentry *d; +int ret; + +/* Create rootdir once. Will never be deleted again. */ +if (!rootdir) + rootdir =debugfs_create_dir ("spi-nor" ,NULL );If I compile SPI NOR as module, I insmod it, rmmod it, and then insmod it again, I get:
Quoted 8 lines
[ 360.623465] spi-nor spi0.0: mt35xu512aba (65536 Kbytes) [ 360.623478] debugfs: Directory 'spi-nor' with parent '/' already present! [ 360.632237] spi-nor spi1.0: mt25qu512a (65536 Kbytes)I guess when you remove the module, rootdir also gets destroyed, and then gets re-initialized on probing again. I am not familiar enough with the debugfs APIs to suggest a fix though.
Thanks for testing. And yes, you are right. I've changed that code quite a few times for this damn subdirectory. But it seems I didn't get it right. Usually, it's created in the module_init() but since we just have an implicit one (and I don't really want to change that), that's not an option. Some subsystems don't create a subdirectory at all, which doesn't appeal to me.
I'll first lookup if the directory is already there, if it is, use it, if not, create it. That should work. FWIW, the mvpp2 network card driver does it too.
-michael
Quoted 3 lines · Michael Walle
The function will also be used by the debugfs module.
Signed-off-by Michael Walle <[email protected]>
Signature · 7 lines
Regards, Pratyush Yadav Texas Instruments Inc. ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/