kernel: bump 6.1 to 6.1.36
[openwrt/openwrt.git] / target / linux / generic / backport-6.1 / 891-v6.2-mtd-spinand-winbond-add-W25N02KV.patch
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
5
6 Add support of Winbond W25N02KV flash
7
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
12 ---
13 drivers/mtd/nand/spi/winbond.c | 75 ++++++++++++++++++++++++++++++++++
14 1 file changed, 75 insertions(+)
15
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);
20 }
21
22 +static int w25n02kv_ooblayout_ecc(struct mtd_info *mtd, int section,
23 + struct mtd_oob_region *region)
24 +{
25 + if (section > 3)
26 + return -ERANGE;
27 +
28 + region->offset = 64 + (16 * section);
29 + region->length = 13;
30 +
31 + return 0;
32 +}
33 +
34 +static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section,
35 + struct mtd_oob_region *region)
36 +{
37 + if (section > 3)
38 + return -ERANGE;
39 +
40 + region->offset = (16 * section) + 2;
41 + region->length = 14;
42 +
43 + return 0;
44 +}
45 +
46 +static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
47 + .ecc = w25n02kv_ooblayout_ecc,
48 + .free = w25n02kv_ooblayout_free,
49 +};
50 +
51 +static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
52 + u8 status)
53 +{
54 + struct nand_device *nand = spinand_to_nand(spinand);
55 + u8 mbf = 0;
56 + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
57 +
58 + switch (status & STATUS_ECC_MASK) {
59 + case STATUS_ECC_NO_BITFLIPS:
60 + return 0;
61 +
62 + case STATUS_ECC_UNCOR_ERROR:
63 + return -EBADMSG;
64 +
65 + case STATUS_ECC_HAS_BITFLIPS:
66 + /*
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.
70 + */
71 + if (spi_mem_exec_op(spinand->spimem, &op))
72 + return nanddev_get_ecc_conf(nand)->strength;
73 +
74 + mbf >>= 4;
75 +
76 + if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
77 + return nanddev_get_ecc_conf(nand)->strength;
78 +
79 + return mbf;
80 +
81 + default:
82 + break;
83 + }
84 +
85 + return -EINVAL;
86 +}
87 +
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),
93 0,
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),
102 + 0,
103 + SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
104 };
105
106 static int winbond_spinand_init(struct spinand_device *spinand)