1 From 6154c7a583483d7b69f53bea868efdc369edd563 Mon Sep 17 00:00:00 2001
2 From: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
3 Date: Mon, 10 Oct 2022 13:51:10 +0300
4 Subject: [PATCH] mtd: spinand: winbond: add Winbond W25N02KV flash support
6 Add support of Winbond W25N02KV flash
8 Signed-off-by: Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>
9 Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
10 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
11 Link: https://lore.kernel.org/linux-mtd/20221010105110.446674-2-mikhail.kshevetskiy@iopsys.eu
13 drivers/mtd/nand/spi/winbond.c | 75 ++++++++++++++++++++++++++++++++++
14 1 file changed, 75 insertions(+)
16 --- a/drivers/mtd/nand/spi/winbond.c
17 +++ b/drivers/mtd/nand/spi/winbond.c
18 @@ -74,6 +74,72 @@ static int w25m02gv_select_target(struct
19 return spi_mem_exec_op(spinand->spimem, &op);
22 +static int w25n02kv_ooblayout_ecc(struct mtd_info *mtd, int section,
23 + struct mtd_oob_region *region)
28 + region->offset = 64 + (16 * section);
29 + region->length = 13;
34 +static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section,
35 + struct mtd_oob_region *region)
40 + region->offset = (16 * section) + 2;
41 + region->length = 14;
46 +static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
47 + .ecc = w25n02kv_ooblayout_ecc,
48 + .free = w25n02kv_ooblayout_free,
51 +static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
54 + struct nand_device *nand = spinand_to_nand(spinand);
56 + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
58 + switch (status & STATUS_ECC_MASK) {
59 + case STATUS_ECC_NO_BITFLIPS:
62 + case STATUS_ECC_UNCOR_ERROR:
65 + case STATUS_ECC_HAS_BITFLIPS:
67 + * Let's try to retrieve the real maximum number of bitflips
68 + * in order to avoid forcing the wear-leveling layer to move
69 + * data around if it's not necessary.
71 + if (spi_mem_exec_op(spinand->spimem, &op))
72 + return nanddev_get_ecc_conf(nand)->strength;
76 + if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
77 + return nanddev_get_ecc_conf(nand)->strength;
88 static const struct spinand_info winbond_spinand_table[] = {
89 SPINAND_INFO("W25M02GV",
90 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab, 0x21),
91 @@ -94,6 +160,15 @@ static const struct spinand_info winbond
92 &update_cache_variants),
94 SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
95 + SPINAND_INFO("W25N02KV",
96 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22),
97 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
98 + NAND_ECCREQ(8, 512),
99 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
100 + &write_cache_variants,
101 + &update_cache_variants),
103 + SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
106 static int winbond_spinand_init(struct spinand_device *spinand)