* [PATCH v2] mtd: spinand: fmsh: add support for FM25G{01,02}B
[not found] <TYZPR01MB5556A3E71554A2EC08597EA4C9CDA@TYZPR01MB5556.apcprd01.prod.exchangelabs.com>
@ 2026-04-15 15:31 ` Ziyang Huang
2026-04-28 12:49 ` Miquel Raynal
0 siblings, 1 reply; 2+ messages in thread
From: Ziyang Huang @ 2026-04-15 15:31 UTC (permalink / raw)
To: miquel.raynal
Cc: richard, vigneshr, cnsztl, hzyitc, csharper2005,
mikhail.kshevetskiy, linux-mtd, linux-kernel
FM25G01B: https://www.fmsh.com/nvm/FM25G01B_ds_eng.pdf
FM25G02B: https://www.fmsh.com/nvm/FM25G02B_ds_eng.pdf
Signed-off-by: Ziyang Huang <hzyitc@outlook.com>
---
Changes since v1:
Fix copy-paste issue. (Correct FM25G01B size.)
drivers/mtd/nand/spi/fmsh.c | 101 ++++++++++++++++++++++++++++++++++++
1 file changed, 101 insertions(+)
diff --git a/drivers/mtd/nand/spi/fmsh.c b/drivers/mtd/nand/spi/fmsh.c
index f417955f7d1c..a9b219ae6c29 100644
--- a/drivers/mtd/nand/spi/fmsh.c
+++ b/drivers/mtd/nand/spi/fmsh.c
@@ -9,6 +9,16 @@
#include <linux/kernel.h>
#include <linux/mtd/spinand.h>
+#define FM25G01B_STATUS_ECC_MASK (7 << 4)
+ #define FM25G01B_STATUS_ECC_NO_BITFLIPS (0 << 4)
+ #define FM25G01B_STATUS_ECC_1_3_BITFLIPS (1 << 4)
+ #define FM25G01B_STATUS_ECC_4_BITFLIPS (2 << 4)
+ #define FM25G01B_STATUS_ECC_5_BITFLIPS (3 << 4)
+ #define FM25G01B_STATUS_ECC_6_BITFLIPS (4 << 4)
+ #define FM25G01B_STATUS_ECC_7_BITFLIPS (5 << 4)
+ #define FM25G01B_STATUS_ECC_8_BITFLIPS (6 << 4)
+ #define FM25G01B_STATUS_ECC_UNCOR_ERROR (7 << 4)
+
#define FM25S01BI3_STATUS_ECC_MASK (7 << 4)
#define FM25S01BI3_STATUS_ECC_NO_BITFLIPS (0 << 4)
#define FM25S01BI3_STATUS_ECC_1_3_BITFLIPS (1 << 4)
@@ -34,6 +44,72 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
+
+static int fm25g01b_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section)
+ return -ERANGE;
+
+ region->offset = 64;
+ region->length = 64;
+
+ return 0;
+}
+
+static int fm25g01b_ooblayout_free(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section > 3)
+ return -ERANGE;
+
+ if (section == 0) {
+ /* reserve 2 bytes for the BBM */
+ region->offset = 2;
+ region->length = 14;
+ } else {
+ region->offset = section * 16;
+ region->length = 16;
+ }
+
+ return 0;
+}
+
+static int fm25g01b_ecc_get_status(struct spinand_device *spinand,
+ u8 status)
+{
+ switch (status & FM25S01BI3_STATUS_ECC_MASK) {
+ case FM25G01B_STATUS_ECC_NO_BITFLIPS:
+ return 0;
+
+ case FM25G01B_STATUS_ECC_1_3_BITFLIPS:
+ return 3;
+
+ case FM25G01B_STATUS_ECC_4_BITFLIPS:
+ return 4;
+
+ case FM25G01B_STATUS_ECC_5_BITFLIPS:
+ return 5;
+
+ case FM25G01B_STATUS_ECC_6_BITFLIPS:
+ return 6;
+
+ case FM25G01B_STATUS_ECC_7_BITFLIPS:
+ return 7;
+
+ case FM25G01B_STATUS_ECC_8_BITFLIPS:
+ return 8;
+
+ case FM25G01B_STATUS_ECC_UNCOR_ERROR:
+ return -EBADMSG;
+
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
static int fm25s01a_ooblayout_ecc(struct mtd_info *mtd, int section,
struct mtd_oob_region *region)
{
@@ -102,6 +178,11 @@ static int fm25s01bi3_ooblayout_free(struct mtd_info *mtd, int section,
return 0;
}
+static const struct mtd_ooblayout_ops fm25g01b_ooblayout = {
+ .ecc = fm25g01b_ooblayout_ecc,
+ .free = fm25g01b_ooblayout_free,
+};
+
static const struct mtd_ooblayout_ops fm25s01a_ooblayout = {
.ecc = fm25s01a_ooblayout_ecc,
.free = fm25s01a_ooblayout_free,
@@ -113,6 +194,26 @@ static const struct mtd_ooblayout_ops fm25s01bi3_ooblayout = {
};
static const struct spinand_info fmsh_spinand_table[] = {
+ SPINAND_INFO("FM25G01B",
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xd1),
+ NAND_MEMORG(1, 2048, 128, 64, 1024, 21, 1, 1, 1),
+ NAND_ECCREQ(8, 528),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&fm25g01b_ooblayout,
+ fm25g01b_ecc_get_status)),
+ SPINAND_INFO("FM25G02B",
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xd2),
+ NAND_MEMORG(1, 2048, 128, 64, 2048, 41, 1, 1, 1),
+ NAND_ECCREQ(8, 528),
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ &write_cache_variants,
+ &update_cache_variants),
+ SPINAND_HAS_QE_BIT,
+ SPINAND_ECCINFO(&fm25g01b_ooblayout,
+ fm25g01b_ecc_get_status)),
SPINAND_INFO("FM25S01A",
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
--
2.40.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mtd: spinand: fmsh: add support for FM25G{01,02}B
2026-04-15 15:31 ` [PATCH v2] mtd: spinand: fmsh: add support for FM25G{01,02}B Ziyang Huang
@ 2026-04-28 12:49 ` Miquel Raynal
0 siblings, 0 replies; 2+ messages in thread
From: Miquel Raynal @ 2026-04-28 12:49 UTC (permalink / raw)
To: Ziyang Huang
Cc: richard, vigneshr, cnsztl, csharper2005, mikhail.kshevetskiy,
linux-mtd, linux-kernel
Hello Ziyang,
On 15/04/2026 at 23:31:41 +08, Ziyang Huang <hzyitc@outlook.com> wrote:
> FM25G01B: https://www.fmsh.com/nvm/FM25G01B_ds_eng.pdf
> FM25G02B: https://www.fmsh.com/nvm/FM25G02B_ds_eng.pdf
Before giving the links, the commit could be slightly more verbose, such
as "Add support for...".
> Signed-off-by: Ziyang Huang <hzyitc@outlook.com>
> ---
> Changes since v1:
> Fix copy-paste issue. (Correct FM25G01B size.)
>
> drivers/mtd/nand/spi/fmsh.c | 101 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 101 insertions(+)
>
> diff --git a/drivers/mtd/nand/spi/fmsh.c b/drivers/mtd/nand/spi/fmsh.c
> index f417955f7d1c..a9b219ae6c29 100644
> --- a/drivers/mtd/nand/spi/fmsh.c
> +++ b/drivers/mtd/nand/spi/fmsh.c
> @@ -9,6 +9,16 @@
> #include <linux/kernel.h>
> #include <linux/mtd/spinand.h>
>
> +#define FM25G01B_STATUS_ECC_MASK (7 << 4)
> + #define FM25G01B_STATUS_ECC_NO_BITFLIPS (0 << 4)
> + #define FM25G01B_STATUS_ECC_1_3_BITFLIPS (1 << 4)
> + #define FM25G01B_STATUS_ECC_4_BITFLIPS (2 << 4)
> + #define FM25G01B_STATUS_ECC_5_BITFLIPS (3 << 4)
> + #define FM25G01B_STATUS_ECC_6_BITFLIPS (4 << 4)
> + #define FM25G01B_STATUS_ECC_7_BITFLIPS (5 << 4)
> + #define FM25G01B_STATUS_ECC_8_BITFLIPS (6 << 4)
> + #define FM25G01B_STATUS_ECC_UNCOR_ERROR (7 << 4)
> +
> #define FM25S01BI3_STATUS_ECC_MASK (7 << 4)
> #define FM25S01BI3_STATUS_ECC_NO_BITFLIPS (0 << 4)
> #define FM25S01BI3_STATUS_ECC_1_3_BITFLIPS (1 << 4)
> @@ -34,6 +44,72 @@ static SPINAND_OP_VARIANTS(update_cache_variants,
> SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
> SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
>
> +
> +static int fm25g01b_ooblayout_ecc(struct mtd_info *mtd, int section,
> + struct mtd_oob_region *region)
> +{
> + if (section)
> + return -ERANGE;
> +
> + region->offset = 64;
> + region->length = 64;
> +
> + return 0;
> +}
> +
> +static int fm25g01b_ooblayout_free(struct mtd_info *mtd, int section,
> + struct mtd_oob_region *region)
> +{
> + if (section > 3)
> + return -ERANGE;
> +
> + if (section == 0) {
> + /* reserve 2 bytes for the BBM */
> + region->offset = 2;
> + region->length = 14;
> + } else {
> + region->offset = section * 16;
> + region->length = 16;
> + }
Isn't that just one big 62 bytes section starting at 2?
> +
> + return 0;
> +}
Rest lgtm.
Thanks,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-28 12:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <TYZPR01MB5556A3E71554A2EC08597EA4C9CDA@TYZPR01MB5556.apcprd01.prod.exchangelabs.com>
2026-04-15 15:31 ` [PATCH v2] mtd: spinand: fmsh: add support for FM25G{01,02}B Ziyang Huang
2026-04-28 12:49 ` Miquel Raynal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox