Skip to contentSkip to conversation

mtd: spi-nor: export spi_nor_hwcaps_pp2cmd()

PATCH Applied Michael Walle 2 participants 4 messages Apr 29, 2022 – May 10, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 mtd: spi-nor: export spi_nor_hwcaps_pp2cmd()

The function will also be used by the debugfs module.

---
changes since v2:
- none

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
index a31d7fd45eb8..6f61e97ecd75 100644
@@ -1850,7 +1850,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
index 4788e628c335..007ea9896a06 100644
@@ -662,6 +662,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
#1 lore raw

PATCH v3 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 v2:
- add comment to enum spi_nor_option_flags
- fix module unloading/loading

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    |   7 +
 drivers/mtd/spi-nor/debugfs.c | 249 ++++++++++++++++++++++++++++++++++
 include/linux/mtd/spi-nor.h   |   2 +
 5 files changed, 261 insertions(+)
 create mode 100644 drivers/mtd/spi-nor/debugfs.c
drivers/mtd/spi-nor/Makefile +1 -0
index 6b904e439372..e347b435a038 100644
@@ -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
index 6f61e97ecd75..ce5d69317d46 100644
@@ -3127,6 +3127,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 +7 -0
index 007ea9896a06..858ef19a94bd 100644
@@ -114,6 +114,7 @@
 		   SPI_MEM_OP_NO_ADDR,					\
 		   SPI_MEM_OP_NO_DATA)
 
+/* Keep these in sync with the list in debugfs.c */
 enum spi_nor_option_flags {
 	SNOR_F_HAS_SR_TB	= BIT(0),
 	SNOR_F_NO_OP_CHIP_ERASE	= BIT(1),
@@ -698,4 +699,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 +249 -0

249 lines not on this page · raw message

include/linux/mtd/spi-nor.h +2 -0
index e505c4a5c530..1ede4c89805a 100644
@@ -363,6 +363,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
@@ -392,6 +393,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
Reviewed-by on v3 2/2
#2 lore raw

Re: [PATCH v3 2/2] mtd: spi-nor: expose internal parameters via debugfs

Quoted 7 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.

Did some basic testing, seems fine to me. I'll wait a couple more days if someone has any comments or else I'll apply it.

Signature · 3 lines
Regards,
Pratyush Yadav
Texas Instruments Inc.