hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/mtd/nand/spi/esmt.c
....@@ -29,7 +29,7 @@
2929 SPINAND_PROG_LOAD(false, 0, NULL, 0));
3030
3131 static int f50lxx41x_ooblayout_ecc(struct mtd_info *mtd, int section,
32
- struct mtd_oob_region *region)
32
+ struct mtd_oob_region *region)
3333 {
3434 if (section > 3)
3535 return -ERANGE;
....@@ -41,7 +41,7 @@
4141 }
4242
4343 static int f50lxx41x_ooblayout_free(struct mtd_info *mtd, int section,
44
- struct mtd_oob_region *region)
44
+ struct mtd_oob_region *region)
4545 {
4646 if (section > 3)
4747 return -ERANGE;
....@@ -57,6 +57,60 @@
5757 .free = f50lxx41x_ooblayout_free,
5858 };
5959
60
+static int f50l2g41ka_ooblayout_ecc(struct mtd_info *mtd, int section,
61
+ struct mtd_oob_region *region)
62
+{
63
+ if (section)
64
+ return -ERANGE;
65
+
66
+ region->offset = mtd->oobsize / 2;
67
+ region->length = mtd->oobsize / 2;
68
+
69
+ return 0;
70
+}
71
+
72
+static int f50l2g41ka_ooblayout_free(struct mtd_info *mtd, int section,
73
+ struct mtd_oob_region *region)
74
+{
75
+ if (section)
76
+ return -ERANGE;
77
+
78
+ region->offset = 2;
79
+ region->length = mtd->oobsize / 2 - 2;
80
+
81
+ return 0;
82
+}
83
+
84
+static const struct mtd_ooblayout_ops f50l2g41ka_ooblayout = {
85
+ .ecc = f50l2g41ka_ooblayout_ecc,
86
+ .free = f50l2g41ka_ooblayout_free,
87
+};
88
+
89
+/*
90
+ * ecc bits: 0xC0[4,6]
91
+ * [0b000], No bit errors were detected;
92
+ * [0b001] and [0b011], 1~6 Bit errors were detected and corrected. Not
93
+ * reach Flipping Bits;
94
+ * [0b101], Bit error count equals the bit flip
95
+ * detection threshold
96
+ * [0b010], Multiple bit errors were detected and
97
+ * not corrected.
98
+ * others, Reserved.
99
+ */
100
+static int f50l2g41ka_ecc_ecc_get_status(struct spinand_device *spinand,
101
+ u8 status)
102
+{
103
+ struct nand_device *nand = spinand_to_nand(spinand);
104
+ u8 eccsr = (status & GENMASK(6, 4)) >> 4;
105
+
106
+ if (eccsr <= 1 || eccsr == 3)
107
+ return eccsr;
108
+ else if (eccsr == 5)
109
+ return nanddev_get_ecc_requirements(nand)->strength;
110
+ else
111
+ return -EBADMSG;
112
+}
113
+
60114 static const struct spinand_info esmt_spinand_table[] = {
61115 SPINAND_INFO("F50L1G41LB",
62116 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x01),
....@@ -67,6 +121,15 @@
67121 &update_cache_variants),
68122 0,
69123 SPINAND_ECCINFO(&f50lxx41x_ooblayout, NULL)),
124
+ SPINAND_INFO("F50L2G41KA",
125
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x41, 0x7F),
126
+ NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
127
+ NAND_ECCREQ(8, 512),
128
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
129
+ &write_cache_variants,
130
+ &update_cache_variants),
131
+ 0,
132
+ SPINAND_ECCINFO(&f50l2g41ka_ooblayout, f50l2g41ka_ecc_ecc_get_status)),
70133 };
71134
72135 static const struct spinand_manufacturer_ops esmt_spinand_manuf_ops = {