Debian Codegraph @

drivers/mtd/nand/spi/toshiba.c

raw
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2018 exceet electronics GmbH
4 * Copyright (c) 2018 Kontron Electronics GmbH
5 *
6 * Author: Frieder Schrempf <[email protected]>
7 */
8
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/mtd/spinand.h>
12
13 /* Kioxia is new name of Toshiba memory. */
14 #define SPINAND_MFR_TOSHIBA 0x98
15 #define TOSH_STATUS_ECC_HAS_BITFLIPS_T (3 << 4)
16
17 static SPINAND_OP_VARIANTS(read_cache_variants,
18 SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
19 SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
20 SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
21 SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
22
23 static SPINAND_OP_VARIANTS(write_cache_x4_variants,
24 SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
25 SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
26
27 static SPINAND_OP_VARIANTS(update_cache_x4_variants,
28 SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
29 SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
30
31 /*
32 * Backward compatibility for 1st generation Serial NAND devices
33 * which don't support Quad Program Load operation.
34 */
35 static SPINAND_OP_VARIANTS(write_cache_variants,
36 SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
37
38 static SPINAND_OP_VARIANTS(update_cache_variants,
39 SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
40
41 static int tx58cxgxsxraix_ooblayout_ecc(struct mtd_info *mtd, int section,
42 struct mtd_oob_region *region)
43 {
44 if (section > 0)
45 return -ERANGE;
46
47 region->offset = mtd->oobsize / 2;
48 region->length = mtd->oobsize / 2;
49
50 return 0;
51 }
52
53 static int tx58cxgxsxraix_ooblayout_free(struct mtd_info *mtd, int section,
54 struct mtd_oob_region *region)
55 {
56 if (section > 0)
57 return -ERANGE;
58
59 /* 2 bytes reserved for BBM */
60 region->offset = 2;
61 region->length = (mtd->oobsize / 2) - 2;
62
63 return 0;
64 }
65
66 static const struct mtd_ooblayout_ops tx58cxgxsxraix_ooblayout = {
67 .ecc = tx58cxgxsxraix_ooblayout_ecc,
68 .free = tx58cxgxsxraix_ooblayout_free,
69 };
70
71 static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
72 u8 status)
73 {
74 struct nand_device *nand = spinand_to_nand(spinand);
75 u8 mbf = 0;
76 struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
77 0x30, spinand->scratchbuf);
78
79 switch (status & STATUS_ECC_MASK) {
80 case STATUS_ECC_NO_BITFLIPS:
81 return 0;
82
83 case STATUS_ECC_UNCOR_ERROR:
84 return -EBADMSG;
85
86 case STATUS_ECC_HAS_BITFLIPS:
87 case TOSH_STATUS_ECC_HAS_BITFLIPS_T:
88 /*
89 * Let's try to retrieve the real maximum number of bitflips
90 * in order to avoid forcing the wear-leveling layer to move
91 * data around if it's not necessary.
92 */
93 if (spi_mem_exec_op(spinand->spimem, &op))
94 return nanddev_get_ecc_conf(nand)->strength;
95
96 mbf = *(spinand->scratchbuf) >> 4;
97
98 if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
99 return nanddev_get_ecc_conf(nand)->strength;
100
101 return mbf;
102
103 default:
104 break;
105 }
106
107 return -EINVAL;
108 }
109
110 static const struct spinand_info toshiba_spinand_table[] = {
111 /* 3.3V 1Gb (1st generation) */
112 SPINAND_INFO("TC58CVG0S3HRAIG",
113 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xC2),
114 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
115 NAND_ECCREQ(8, 512),
116 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
117 &write_cache_variants,
118 &update_cache_variants),
119 0,
120 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
121 tx58cxgxsxraix_ecc_get_status)),
122 /* 3.3V 2Gb (1st generation) */
123 SPINAND_INFO("TC58CVG1S3HRAIG",
124 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCB),
125 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
126 NAND_ECCREQ(8, 512),
127 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
128 &write_cache_variants,
129 &update_cache_variants),
130 0,
131 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
132 tx58cxgxsxraix_ecc_get_status)),
133 /* 3.3V 4Gb (1st generation) */
134 SPINAND_INFO("TC58CVG2S0HRAIG",
135 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCD),
136 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
137 NAND_ECCREQ(8, 512),
138 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
139 &write_cache_variants,
140 &update_cache_variants),
141 0,
142 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
143 tx58cxgxsxraix_ecc_get_status)),
144 /* 1.8V 1Gb (1st generation) */
145 SPINAND_INFO("TC58CYG0S3HRAIG",
146 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xB2),
147 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
148 NAND_ECCREQ(8, 512),
149 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
150 &write_cache_variants,
151 &update_cache_variants),
152 0,
153 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
154 tx58cxgxsxraix_ecc_get_status)),
155 /* 1.8V 2Gb (1st generation) */
156 SPINAND_INFO("TC58CYG1S3HRAIG",
157 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBB),
158 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
159 NAND_ECCREQ(8, 512),
160 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
161 &write_cache_variants,
162 &update_cache_variants),
163 0,
164 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
165 tx58cxgxsxraix_ecc_get_status)),
166 /* 1.8V 4Gb (1st generation) */
167 SPINAND_INFO("TC58CYG2S0HRAIG",
168 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBD),
169 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
170 NAND_ECCREQ(8, 512),
171 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
172 &write_cache_variants,
173 &update_cache_variants),
174 0,
175 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
176 tx58cxgxsxraix_ecc_get_status)),
177
178 /*
179 * 2nd generation serial nand has HOLD_D which is equivalent to
180 * QE_BIT.
181 */
182 /* 3.3V 1Gb (2nd generation) */
183 SPINAND_INFO("TC58CVG0S3HRAIJ",
184 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE2),
185 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
186 NAND_ECCREQ(8, 512),
187 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
188 &write_cache_x4_variants,
189 &update_cache_x4_variants),
190 SPINAND_HAS_QE_BIT,
191 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
192 tx58cxgxsxraix_ecc_get_status)),
193 /* 3.3V 2Gb (2nd generation) */
194 SPINAND_INFO("TC58CVG1S3HRAIJ",
195 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xEB),
196 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
197 NAND_ECCREQ(8, 512),
198 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
199 &write_cache_x4_variants,
200 &update_cache_x4_variants),
201 SPINAND_HAS_QE_BIT,
202 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
203 tx58cxgxsxraix_ecc_get_status)),
204 /* 3.3V 4Gb (2nd generation) */
205 SPINAND_INFO("TC58CVG2S0HRAIJ",
206 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xED),
207 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
208 NAND_ECCREQ(8, 512),
209 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
210 &write_cache_x4_variants,
211 &update_cache_x4_variants),
212 SPINAND_HAS_QE_BIT,
213 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
214 tx58cxgxsxraix_ecc_get_status)),
215 /* 3.3V 8Gb (2nd generation) */
216 SPINAND_INFO("TH58CVG3S0HRAIJ",
217 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
218 NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
219 NAND_ECCREQ(8, 512),
220 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
221 &write_cache_x4_variants,
222 &update_cache_x4_variants),
223 SPINAND_HAS_QE_BIT,
224 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
225 tx58cxgxsxraix_ecc_get_status)),
226 /* 1.8V 1Gb (2nd generation) */
227 SPINAND_INFO("TC58CYG0S3HRAIJ",
228 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD2),
229 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
230 NAND_ECCREQ(8, 512),
231 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
232 &write_cache_x4_variants,
233 &update_cache_x4_variants),
234 SPINAND_HAS_QE_BIT,
235 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
236 tx58cxgxsxraix_ecc_get_status)),
237 /* 1.8V 2Gb (2nd generation) */
238 SPINAND_INFO("TC58CYG1S3HRAIJ",
239 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDB),
240 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
241 NAND_ECCREQ(8, 512),
242 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
243 &write_cache_x4_variants,
244 &update_cache_x4_variants),
245 SPINAND_HAS_QE_BIT,
246 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
247 tx58cxgxsxraix_ecc_get_status)),
248 /* 1.8V 4Gb (2nd generation) */
249 SPINAND_INFO("TC58CYG2S0HRAIJ",
250 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDD),
251 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
252 NAND_ECCREQ(8, 512),
253 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
254 &write_cache_x4_variants,
255 &update_cache_x4_variants),
256 SPINAND_HAS_QE_BIT,
257 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
258 tx58cxgxsxraix_ecc_get_status)),
259 /* 1.8V 8Gb (2nd generation) */
260 SPINAND_INFO("TH58CYG3S0HRAIJ",
261 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4),
262 NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
263 NAND_ECCREQ(8, 512),
264 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
265 &write_cache_x4_variants,
266 &update_cache_x4_variants),
267 SPINAND_HAS_QE_BIT,
268 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
269 tx58cxgxsxraix_ecc_get_status)),
270 /* 1.8V 1Gb (1st generation) */
271 SPINAND_INFO("TC58NYG0S3HBAI4",
272 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA1),
273 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
274 NAND_ECCREQ(8, 512),
275 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
276 &write_cache_variants,
277 &update_cache_variants),
278 0,
279 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
280 tx58cxgxsxraix_ecc_get_status)),
281 /* 1.8V 4Gb (1st generation) */
282 SPINAND_INFO("TH58NYG2S3HBAI4",
283 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xAC),
284 NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 1, 2, 1),
285 NAND_ECCREQ(8, 512),
286 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
287 &write_cache_x4_variants,
288 &update_cache_x4_variants),
289 SPINAND_HAS_QE_BIT,
290 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
291 tx58cxgxsxraix_ecc_get_status)),
292 /* 1.8V 8Gb (1st generation) */
293 SPINAND_INFO("TH58NYG3S0HBAI6",
294 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA3),
295 NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
296 NAND_ECCREQ(8, 512),
297 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
298 &write_cache_x4_variants,
299 &update_cache_x4_variants),
300 SPINAND_HAS_QE_BIT,
301 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
302 tx58cxgxsxraix_ecc_get_status)),
303 };
304
305 static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
306 };
307
308 const struct spinand_manufacturer toshiba_spinand_manufacturer = {
309 .id = SPINAND_MFR_TOSHIBA,
310 .name = "Toshiba",
311 .chips = toshiba_spinand_table,
312 .nchips = ARRAY_SIZE(toshiba_spinand_table),
313 .ops = &toshiba_spinand_manuf_ops,
314 };