[PATCH v1 2/3] mtd: spi-nor: Add features support by parse sfdp

Jaime Liao jaimeliao.tw at gmail.com
Thu Jul 13 03:50:57 PDT 2023


From: JaimeLiao <jaimeliao.tw at gmail.com>

Add SECT_4K, DUAL_READ, QUAD_READ, OCTAL_DTR_READ feature
checking by parsing sfdp tables.

Signed-off-by: JaimeLiao <jaimeliao.tw at gmail.com>
---
 drivers/mtd/spi-nor/sfdp.c | 25 +++++++++++++++++++++++++
 drivers/mtd/spi-nor/sfdp.h |  2 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c
index b3b11dfed789..cff3e9d6d061 100644
--- a/drivers/mtd/spi-nor/sfdp.c
+++ b/drivers/mtd/spi-nor/sfdp.c
@@ -463,6 +463,24 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 	/* Fix endianness of the BFPT DWORDs. */
 	le32_to_cpu_array(bfpt.dwords, BFPT_DWORD_MAX);
 
+	/* Checking Sector Size 4K */
+	switch (bfpt.dwords[SFDP_DWORD(1)] & BFPT_DWORD1_SECT_SIZE_MASK ) {
+	case BFPT_DWORD1_SUPPORT_SECT_4K:
+		nor->flags |= SNOR_F_SECT_4K;
+	default:
+		break;
+	}
+
+	/* Checking 1-1-2 Fast Read */
+	if (bfpt.dwords[SFDP_DWORD(1)] & BFPT_DWORD1_FAST_READ_1_1_2) {
+		nor->flags |= SNOR_F_DUAL_READ;
+	}
+
+	/* Checking 1-1-4 Fast Read */
+	if (bfpt.dwords[SFDP_DWORD(1)] & BFPT_DWORD1_FAST_READ_1_1_4) {
+		nor->flags |= SNOR_F_QUAD_READ;
+	}
+
 	/* Number of address bytes. */
 	switch (bfpt.dwords[SFDP_DWORD(1)] & BFPT_DWORD1_ADDRESS_BYTES_MASK) {
 	case BFPT_DWORD1_ADDRESS_BYTES_3_ONLY:
@@ -1218,6 +1236,7 @@ static int spi_nor_parse_profile1(struct spi_nor *nor,
 }
 
 #define SCCR_DWORD22_OCTAL_DTR_EN_VOLATILE		BIT(31)
+#define SCCR_DWORD22_OCTAL_DTR_MODE			BIT(23)
 
 /**
  * spi_nor_parse_sccr() - Parse the Status, Control and Configuration Register
@@ -1264,6 +1283,12 @@ static int spi_nor_parse_sccr(struct spi_nor *nor,
 		      dwords[SFDP_DWORD(22)]))
 		nor->flags |= SNOR_F_IO_MODE_EN_VOLATILE;
 
+	if (FIELD_GET(SCCR_DWORD22_OCTAL_DTR_MODE,
+		      dwords[SFDP_DWORD(22)])) {
+		nor->flags |= SNOR_F_OCTAL_DTR_READ;
+		nor->flags |= SNOR_F_OCTAL_DTR_PP;
+	}
+
 out:
 	kfree(dwords);
 	return ret;
diff --git a/drivers/mtd/spi-nor/sfdp.h b/drivers/mtd/spi-nor/sfdp.h
index 6eb99e1cdd61..84a98e3f8710 100644
--- a/drivers/mtd/spi-nor/sfdp.h
+++ b/drivers/mtd/spi-nor/sfdp.h
@@ -31,6 +31,8 @@ struct sfdp_bfpt {
 #define BFPT_DWORD_MAX_JESD216B			16
 
 /* 1st DWORD. */
+#define BFPT_DWORD1_SECT_SIZE_MASK		GENMASK(1, 0)
+#define BFPT_DWORD1_SUPPORT_SECT_4K		(0x1UL << 0)
 #define BFPT_DWORD1_FAST_READ_1_1_2		BIT(16)
 #define BFPT_DWORD1_ADDRESS_BYTES_MASK		GENMASK(18, 17)
 #define BFPT_DWORD1_ADDRESS_BYTES_3_ONLY	(0x0UL << 17)
-- 
2.25.1




More information about the linux-mtd mailing list