hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/mtd/nand/spi/winbond.c
....@@ -14,6 +14,7 @@
1414 #define SPINAND_MFR_WINBOND 0xEF
1515
1616 #define WINBOND_CFG_BUF_READ BIT(3)
17
+#define WINBOND_STATUS_ECC_HAS_BITFLIPS_T (3 << 4)
1718
1819 static SPINAND_OP_VARIANTS(read_cache_variants,
1920 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
....@@ -74,9 +75,63 @@
7475 return spi_mem_exec_op(spinand->spimem, &op);
7576 }
7677
78
+static int w25n02kv_ooblayout_ecc(struct mtd_info *mtd, int section,
79
+ struct mtd_oob_region *region)
80
+{
81
+ if (section)
82
+ return -ERANGE;
83
+
84
+ region->offset = 64;
85
+ region->length = 64;
86
+
87
+ return 0;
88
+}
89
+
90
+static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section,
91
+ struct mtd_oob_region *region)
92
+{
93
+ if (section)
94
+ return -ERANGE;
95
+
96
+ /* Reserve 2 bytes for the BBM. */
97
+ region->offset = 2;
98
+ region->length = 62;
99
+
100
+ return 0;
101
+}
102
+
103
+static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
104
+ .ecc = w25n02kv_ooblayout_ecc,
105
+ .free = w25n02kv_ooblayout_free,
106
+};
107
+
108
+static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
109
+ u8 status)
110
+{
111
+ struct nand_device *nand = spinand_to_nand(spinand);
112
+
113
+ switch (status & STATUS_ECC_MASK) {
114
+ case STATUS_ECC_NO_BITFLIPS:
115
+ return 0;
116
+
117
+ case STATUS_ECC_UNCOR_ERROR:
118
+ return -EBADMSG;
119
+
120
+ case STATUS_ECC_HAS_BITFLIPS:
121
+ return 1;
122
+
123
+ default:
124
+ return nanddev_get_ecc_requirements(nand)->strength;
125
+ }
126
+
127
+ return -EINVAL;
128
+}
129
+
130
+
77131 static const struct spinand_info winbond_spinand_table[] = {
78
- SPINAND_INFO("W25M02GV", 0xAB,
79
- NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 2),
132
+ SPINAND_INFO("W25M02GV",
133
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab),
134
+ NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
80135 NAND_ECCREQ(1, 512),
81136 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
82137 &write_cache_variants,
....@@ -84,32 +139,77 @@
84139 0,
85140 SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
86141 SPINAND_SELECT_TARGET(w25m02gv_select_target)),
142
+ SPINAND_INFO("W25N512GV",
143
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAA, 0x20),
144
+ NAND_MEMORG(1, 2048, 64, 64, 512, 10, 1, 1, 1),
145
+ NAND_ECCREQ(1, 512),
146
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
147
+ &write_cache_variants,
148
+ &update_cache_variants),
149
+ 0,
150
+ SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
151
+ SPINAND_SELECT_TARGET(w25m02gv_select_target)),
152
+ SPINAND_INFO("W25N01GV",
153
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAA, 0x21),
154
+ NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
155
+ NAND_ECCREQ(1, 512),
156
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
157
+ &write_cache_variants,
158
+ &update_cache_variants),
159
+ 0,
160
+ SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
161
+ SPINAND_SELECT_TARGET(w25m02gv_select_target)),
162
+ SPINAND_INFO("W25N02KV",
163
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAA, 0x22),
164
+ NAND_MEMORG(1, 2048, 128, 64, 2048, 20, 1, 1, 1),
165
+ NAND_ECCREQ(8, 512),
166
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
167
+ &write_cache_variants,
168
+ &update_cache_variants),
169
+ 0,
170
+ SPINAND_ECCINFO(&w25n02kv_ooblayout,
171
+ w25n02kv_ecc_get_status)),
172
+ SPINAND_INFO("W25N04KV",
173
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAA, 0x23),
174
+ NAND_MEMORG(1, 2048, 128, 64, 4096, 40, 1, 1, 1),
175
+ NAND_ECCREQ(8, 512),
176
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
177
+ &write_cache_variants,
178
+ &update_cache_variants),
179
+ 0,
180
+ SPINAND_ECCINFO(&w25n02kv_ooblayout,
181
+ w25n02kv_ecc_get_status)),
182
+ SPINAND_INFO("W25N01GW",
183
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBA, 0x21),
184
+ NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
185
+ NAND_ECCREQ(1, 512),
186
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
187
+ &write_cache_variants,
188
+ &update_cache_variants),
189
+ 0,
190
+ SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
191
+ SPINAND_SELECT_TARGET(w25m02gv_select_target)),
192
+ SPINAND_INFO("W25N02KW",
193
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBA, 0x22),
194
+ NAND_MEMORG(1, 2048, 128, 64, 2048, 20, 1, 1, 1),
195
+ NAND_ECCREQ(8, 512),
196
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
197
+ &write_cache_variants,
198
+ &update_cache_variants),
199
+ 0,
200
+ SPINAND_ECCINFO(&w25n02kv_ooblayout,
201
+ w25n02kv_ecc_get_status)),
202
+ SPINAND_INFO("W25N01KV",
203
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAE, 0x21),
204
+ NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
205
+ NAND_ECCREQ(4, 512),
206
+ SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
207
+ &write_cache_variants,
208
+ &update_cache_variants),
209
+ 0,
210
+ SPINAND_ECCINFO(&w25n02kv_ooblayout,
211
+ w25n02kv_ecc_get_status)),
87212 };
88
-
89
-/**
90
- * winbond_spinand_detect - initialize device related part in spinand_device
91
- * struct if it is a Winbond device.
92
- * @spinand: SPI NAND device structure
93
- */
94
-static int winbond_spinand_detect(struct spinand_device *spinand)
95
-{
96
- u8 *id = spinand->id.data;
97
- int ret;
98
-
99
- /*
100
- * Winbond SPI NAND read ID need a dummy byte,
101
- * so the first byte in raw_id is dummy.
102
- */
103
- if (id[1] != SPINAND_MFR_WINBOND)
104
- return 0;
105
-
106
- ret = spinand_match_and_init(spinand, winbond_spinand_table,
107
- ARRAY_SIZE(winbond_spinand_table), id[2]);
108
- if (ret)
109
- return ret;
110
-
111
- return 1;
112
-}
113213
114214 static int winbond_spinand_init(struct spinand_device *spinand)
115215 {
....@@ -130,12 +230,13 @@
130230 }
131231
132232 static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
133
- .detect = winbond_spinand_detect,
134233 .init = winbond_spinand_init,
135234 };
136235
137236 const struct spinand_manufacturer winbond_spinand_manufacturer = {
138237 .id = SPINAND_MFR_WINBOND,
139238 .name = "Winbond",
239
+ .chips = winbond_spinand_table,
240
+ .nchips = ARRAY_SIZE(winbond_spinand_table),
140241 .ops = &winbond_spinand_manuf_ops,
141242 };