blob: b9908e792712520afc9cb972f2bdf6b32ab65db2 [file] [log] [blame]
Robert Marko24cb4092020-03-03 20:25:40 +01001// 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 <frieder.schrempf@kontron.de>
7 */
8
9#ifndef __UBOOT__
Robert Marko24cb4092020-03-03 20:25:40 +010010#include <linux/device.h>
11#include <linux/kernel.h>
12#endif
Simon Glassc06c1be2020-05-10 11:40:08 -060013#include <linux/bug.h>
Robert Marko24cb4092020-03-03 20:25:40 +010014#include <linux/mtd/spinand.h>
15
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010016/* Kioxia is new name of Toshiba memory. */
Robert Marko24cb4092020-03-03 20:25:40 +010017#define SPINAND_MFR_TOSHIBA 0x98
18#define TOSH_STATUS_ECC_HAS_BITFLIPS_T (3 << 4)
19
20static SPINAND_OP_VARIANTS(read_cache_variants,
21 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
22 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
23 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
24 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
25
Yoshio Furuyama16987e22020-05-10 22:06:42 +020026static SPINAND_OP_VARIANTS(write_cache_x4_variants,
27 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
28 SPINAND_PROG_LOAD(true, 0, NULL, 0));
29
30static SPINAND_OP_VARIANTS(update_cache_x4_variants,
31 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
32 SPINAND_PROG_LOAD(false, 0, NULL, 0));
33
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010034/*
Yoshio Furuyama16987e22020-05-10 22:06:42 +020035 * Backward compatibility for 1st generation Serial NAND devices
36 * which don't support Quad Program Load operation.
37 */
Robert Marko24cb4092020-03-03 20:25:40 +010038static SPINAND_OP_VARIANTS(write_cache_variants,
39 SPINAND_PROG_LOAD(true, 0, NULL, 0));
40
41static SPINAND_OP_VARIANTS(update_cache_variants,
42 SPINAND_PROG_LOAD(false, 0, NULL, 0));
43
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +020044static int tx58cxgxsxraix_ooblayout_ecc(struct mtd_info *mtd, int section,
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010045 struct mtd_oob_region *region)
Robert Marko24cb4092020-03-03 20:25:40 +010046{
47 if (section > 0)
48 return -ERANGE;
49
50 region->offset = mtd->oobsize / 2;
51 region->length = mtd->oobsize / 2;
52
53 return 0;
54}
55
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +020056static int tx58cxgxsxraix_ooblayout_free(struct mtd_info *mtd, int section,
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010057 struct mtd_oob_region *region)
Robert Marko24cb4092020-03-03 20:25:40 +010058{
59 if (section > 0)
60 return -ERANGE;
61
62 /* 2 bytes reserved for BBM */
63 region->offset = 2;
64 region->length = (mtd->oobsize / 2) - 2;
65
66 return 0;
67}
68
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +020069static const struct mtd_ooblayout_ops tx58cxgxsxraix_ooblayout = {
70 .ecc = tx58cxgxsxraix_ooblayout_ecc,
71 .rfree = tx58cxgxsxraix_ooblayout_free,
Robert Marko24cb4092020-03-03 20:25:40 +010072};
73
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +020074static int tx58cxgxsxraix_ecc_get_status(struct spinand_device *spinand,
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010075 u8 status)
Robert Marko24cb4092020-03-03 20:25:40 +010076{
77 struct nand_device *nand = spinand_to_nand(spinand);
78 u8 mbf = 0;
79 struct spi_mem_op op = SPINAND_GET_FEATURE_OP(0x30, &mbf);
80
81 switch (status & STATUS_ECC_MASK) {
82 case STATUS_ECC_NO_BITFLIPS:
83 return 0;
84
85 case STATUS_ECC_UNCOR_ERROR:
86 return -EBADMSG;
87
88 case STATUS_ECC_HAS_BITFLIPS:
89 case TOSH_STATUS_ECC_HAS_BITFLIPS_T:
90 /*
91 * Let's try to retrieve the real maximum number of bitflips
92 * in order to avoid forcing the wear-leveling layer to move
93 * data around if it's not necessary.
94 */
95 if (spi_mem_exec_op(spinand->slave, &op))
96 return nand->eccreq.strength;
97
98 mbf >>= 4;
99
100 if (WARN_ON(mbf > nand->eccreq.strength || !mbf))
101 return nand->eccreq.strength;
102
103 return mbf;
104
105 default:
106 break;
107 }
108
109 return -EINVAL;
110}
111
112static const struct spinand_info toshiba_spinand_table[] = {
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200113 /* 3.3V 1Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100114 SPINAND_INFO("TC58CVG0S3HRAIG",
115 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xC2),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100116 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100117 NAND_ECCREQ(8, 512),
118 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
119 &write_cache_variants,
120 &update_cache_variants),
121 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200122 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
123 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200124 /* 3.3V 2Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100125 SPINAND_INFO("TC58CVG1S3HRAIG",
126 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCB),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100127 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100128 NAND_ECCREQ(8, 512),
129 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
130 &write_cache_variants,
131 &update_cache_variants),
132 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200133 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
134 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200135 /* 3.3V 4Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100136 SPINAND_INFO("TC58CVG2S0HRAIG",
137 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xCD),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100138 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100139 NAND_ECCREQ(8, 512),
140 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
141 &write_cache_variants,
142 &update_cache_variants),
143 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200144 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
145 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200146 /* 1.8V 1Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100147 SPINAND_INFO("TC58CYG0S3HRAIG",
148 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xB2),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100149 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100150 NAND_ECCREQ(8, 512),
151 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
152 &write_cache_variants,
153 &update_cache_variants),
154 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200155 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
156 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200157 /* 1.8V 2Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100158 SPINAND_INFO("TC58CYG1S3HRAIG",
159 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBB),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100160 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100161 NAND_ECCREQ(8, 512),
162 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
163 &write_cache_variants,
164 &update_cache_variants),
165 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200166 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
167 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200168 /* 1.8V 4Gb (1st generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100169 SPINAND_INFO("TC58CYG2S0HRAIG",
170 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBD),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100171 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Robert Marko24cb4092020-03-03 20:25:40 +0100172 NAND_ECCREQ(8, 512),
173 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
174 &write_cache_variants,
175 &update_cache_variants),
176 0,
Yoshio Furuyama75d8abe2020-05-10 22:06:41 +0200177 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
178 tx58cxgxsxraix_ecc_get_status)),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200179
180 /*
181 * 2nd generation serial nand has HOLD_D which is equivalent to
182 * QE_BIT.
183 */
184 /* 3.3V 1Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100185 SPINAND_INFO("TC58CVG0S3HRAIJ",
186 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE2),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100187 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200188 NAND_ECCREQ(8, 512),
189 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
190 &write_cache_x4_variants,
191 &update_cache_x4_variants),
192 SPINAND_HAS_QE_BIT,
193 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
194 tx58cxgxsxraix_ecc_get_status)),
195 /* 3.3V 2Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100196 SPINAND_INFO("TC58CVG1S3HRAIJ",
197 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xEB),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100198 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200199 NAND_ECCREQ(8, 512),
200 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
201 &write_cache_x4_variants,
202 &update_cache_x4_variants),
203 SPINAND_HAS_QE_BIT,
204 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
205 tx58cxgxsxraix_ecc_get_status)),
206 /* 3.3V 4Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100207 SPINAND_INFO("TC58CVG2S0HRAIJ",
208 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xED),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100209 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200210 NAND_ECCREQ(8, 512),
211 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
212 &write_cache_x4_variants,
213 &update_cache_x4_variants),
214 SPINAND_HAS_QE_BIT,
215 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
216 tx58cxgxsxraix_ecc_get_status)),
217 /* 3.3V 8Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100218 SPINAND_INFO("TH58CVG3S0HRAIJ",
219 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100220 NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200221 NAND_ECCREQ(8, 512),
222 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
223 &write_cache_x4_variants,
224 &update_cache_x4_variants),
225 SPINAND_HAS_QE_BIT,
226 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
227 tx58cxgxsxraix_ecc_get_status)),
228 /* 1.8V 1Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100229 SPINAND_INFO("TC58CYG0S3HRAIJ",
230 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD2),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100231 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200232 NAND_ECCREQ(8, 512),
233 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
234 &write_cache_x4_variants,
235 &update_cache_x4_variants),
236 SPINAND_HAS_QE_BIT,
237 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
238 tx58cxgxsxraix_ecc_get_status)),
239 /* 1.8V 2Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100240 SPINAND_INFO("TC58CYG1S3HRAIJ",
241 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDB),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100242 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200243 NAND_ECCREQ(8, 512),
244 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
245 &write_cache_x4_variants,
246 &update_cache_x4_variants),
247 SPINAND_HAS_QE_BIT,
248 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
249 tx58cxgxsxraix_ecc_get_status)),
250 /* 1.8V 4Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100251 SPINAND_INFO("TC58CYG2S0HRAIJ",
252 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xDD),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100253 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200254 NAND_ECCREQ(8, 512),
255 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
256 &write_cache_x4_variants,
257 &update_cache_x4_variants),
258 SPINAND_HAS_QE_BIT,
259 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
260 tx58cxgxsxraix_ecc_get_status)),
261 /* 1.8V 8Gb (2nd generation) */
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100262 SPINAND_INFO("TH58CYG3S0HRAIJ",
263 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +0100264 NAND_MEMORG(1, 4096, 256, 64, 4096, 80, 1, 1, 1),
Yoshio Furuyama16987e22020-05-10 22:06:42 +0200265 NAND_ECCREQ(8, 512),
266 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
267 &write_cache_x4_variants,
268 &update_cache_x4_variants),
269 SPINAND_HAS_QE_BIT,
270 SPINAND_ECCINFO(&tx58cxgxsxraix_ooblayout,
271 tx58cxgxsxraix_ecc_get_status)),
Robert Marko24cb4092020-03-03 20:25:40 +0100272};
273
Robert Marko24cb4092020-03-03 20:25:40 +0100274static const struct spinand_manufacturer_ops toshiba_spinand_manuf_ops = {
Robert Marko24cb4092020-03-03 20:25:40 +0100275};
276
277const struct spinand_manufacturer toshiba_spinand_manufacturer = {
278 .id = SPINAND_MFR_TOSHIBA,
279 .name = "Toshiba",
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100280 .chips = toshiba_spinand_table,
281 .nchips = ARRAY_SIZE(toshiba_spinand_table),
Robert Marko24cb4092020-03-03 20:25:40 +0100282 .ops = &toshiba_spinand_manuf_ops,
283};