Skip to content

Commit a9d94a2

Browse files
zmlin1998miquelraynal
authored andcommitted
mtd: spinand: macronix: Add support for read retry
Add read retry support. The Special Read for Data Recovery operation is enabled by Set Feature function. There are 5 modes for the user to recover the lost data. Signed-off-by: Cheng Ming Lin <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent f2cb43c commit a9d94a2

File tree

1 file changed

+64
-15
lines changed

1 file changed

+64
-15
lines changed

drivers/mtd/nand/spi/macronix.c

Lines changed: 64 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#define MACRONIX_ECCSR_BF_LAST_PAGE(eccsr) FIELD_GET(GENMASK(3, 0), eccsr)
1515
#define MACRONIX_ECCSR_BF_ACCUMULATED_PAGES(eccsr) FIELD_GET(GENMASK(7, 4), eccsr)
1616
#define MACRONIX_CFG_CONT_READ BIT(2)
17+
#define MACRONIX_FEATURE_ADDR_READ_RETRY 0x70
18+
#define MACRONIX_NUM_READ_RETRY_MODES 5
1719

1820
#define STATUS_ECC_HAS_BITFLIPS_THRESHOLD (3 << 4)
1921

@@ -136,6 +138,23 @@ static int macronix_set_cont_read(struct spinand_device *spinand, bool enable)
136138
return 0;
137139
}
138140

141+
/**
142+
* macronix_set_read_retry - Set the retry mode
143+
* @spinand: SPI NAND device
144+
* @retry_mode: Specify which retry mode to set
145+
*
146+
* Return: 0 on success, a negative error code otherwise.
147+
*/
148+
static int macronix_set_read_retry(struct spinand_device *spinand,
149+
unsigned int retry_mode)
150+
{
151+
struct spi_mem_op op = SPINAND_SET_FEATURE_OP(MACRONIX_FEATURE_ADDR_READ_RETRY,
152+
spinand->scratchbuf);
153+
154+
*spinand->scratchbuf = retry_mode;
155+
return spi_mem_exec_op(spinand->spimem, &op);
156+
}
157+
139158
static const struct spinand_info macronix_spinand_table[] = {
140159
SPINAND_INFO("MX35LF1GE4AB",
141160
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x12),
@@ -168,7 +187,9 @@ static const struct spinand_info macronix_spinand_table[] = {
168187
SPINAND_HAS_QE_BIT,
169188
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
170189
macronix_ecc_get_status),
171-
SPINAND_CONT_READ(macronix_set_cont_read)),
190+
SPINAND_CONT_READ(macronix_set_cont_read)
191+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
192+
macronix_set_read_retry)),
172193
SPINAND_INFO("MX35LF4GE4AD",
173194
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x37, 0x03),
174195
NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),
@@ -179,7 +200,9 @@ static const struct spinand_info macronix_spinand_table[] = {
179200
SPINAND_HAS_QE_BIT,
180201
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
181202
macronix_ecc_get_status),
182-
SPINAND_CONT_READ(macronix_set_cont_read)),
203+
SPINAND_CONT_READ(macronix_set_cont_read)
204+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
205+
macronix_set_read_retry)),
183206
SPINAND_INFO("MX35LF1G24AD",
184207
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x14, 0x03),
185208
NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
@@ -188,7 +211,9 @@ static const struct spinand_info macronix_spinand_table[] = {
188211
&write_cache_variants,
189212
&update_cache_variants),
190213
SPINAND_HAS_QE_BIT,
191-
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
214+
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
215+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
216+
macronix_set_read_retry)),
192217
SPINAND_INFO("MX35LF2G24AD",
193218
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24, 0x03),
194219
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
@@ -198,7 +223,9 @@ static const struct spinand_info macronix_spinand_table[] = {
198223
&update_cache_variants),
199224
SPINAND_HAS_QE_BIT |
200225
SPINAND_HAS_PROG_PLANE_SELECT_BIT,
201-
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
226+
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
227+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
228+
macronix_set_read_retry)),
202229
SPINAND_INFO("MX35LF2G24AD-Z4I8",
203230
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x64, 0x03),
204231
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -207,7 +234,9 @@ static const struct spinand_info macronix_spinand_table[] = {
207234
&write_cache_variants,
208235
&update_cache_variants),
209236
SPINAND_HAS_QE_BIT,
210-
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
237+
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
238+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
239+
macronix_set_read_retry)),
211240
SPINAND_INFO("MX35LF4G24AD",
212241
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35, 0x03),
213242
NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1),
@@ -217,7 +246,9 @@ static const struct spinand_info macronix_spinand_table[] = {
217246
&update_cache_variants),
218247
SPINAND_HAS_QE_BIT |
219248
SPINAND_HAS_PROG_PLANE_SELECT_BIT,
220-
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
249+
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
250+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
251+
macronix_set_read_retry)),
221252
SPINAND_INFO("MX35LF4G24AD-Z4I8",
222253
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x75, 0x03),
223254
NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -226,7 +257,9 @@ static const struct spinand_info macronix_spinand_table[] = {
226257
&write_cache_variants,
227258
&update_cache_variants),
228259
SPINAND_HAS_QE_BIT,
229-
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
260+
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL),
261+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
262+
macronix_set_read_retry)),
230263
SPINAND_INFO("MX31LF1GE4BC",
231264
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x1e),
232265
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
@@ -270,7 +303,9 @@ static const struct spinand_info macronix_spinand_table[] = {
270303
SPINAND_HAS_QE_BIT |
271304
SPINAND_HAS_PROG_PLANE_SELECT_BIT,
272305
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
273-
macronix_ecc_get_status)),
306+
macronix_ecc_get_status),
307+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
308+
macronix_set_read_retry)),
274309
SPINAND_INFO("MX35UF4G24AD-Z4I8",
275310
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xf5, 0x03),
276311
NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -280,7 +315,9 @@ static const struct spinand_info macronix_spinand_table[] = {
280315
&update_cache_variants),
281316
SPINAND_HAS_QE_BIT,
282317
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
283-
macronix_ecc_get_status)),
318+
macronix_ecc_get_status),
319+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
320+
macronix_set_read_retry)),
284321
SPINAND_INFO("MX35UF4GE4AD",
285322
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb7, 0x03),
286323
NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
@@ -291,7 +328,9 @@ static const struct spinand_info macronix_spinand_table[] = {
291328
SPINAND_HAS_QE_BIT,
292329
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
293330
macronix_ecc_get_status),
294-
SPINAND_CONT_READ(macronix_set_cont_read)),
331+
SPINAND_CONT_READ(macronix_set_cont_read)
332+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
333+
macronix_set_read_retry)),
295334
SPINAND_INFO("MX35UF2G14AC",
296335
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa0),
297336
NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
@@ -314,7 +353,9 @@ static const struct spinand_info macronix_spinand_table[] = {
314353
SPINAND_HAS_QE_BIT |
315354
SPINAND_HAS_PROG_PLANE_SELECT_BIT,
316355
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
317-
macronix_ecc_get_status)),
356+
macronix_ecc_get_status),
357+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
358+
macronix_set_read_retry)),
318359
SPINAND_INFO("MX35UF2G24AD-Z4I8",
319360
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xe4, 0x03),
320361
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -324,7 +365,9 @@ static const struct spinand_info macronix_spinand_table[] = {
324365
&update_cache_variants),
325366
SPINAND_HAS_QE_BIT,
326367
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
327-
macronix_ecc_get_status)),
368+
macronix_ecc_get_status),
369+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
370+
macronix_set_read_retry)),
328371
SPINAND_INFO("MX35UF2GE4AD",
329372
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa6, 0x03),
330373
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
@@ -335,7 +378,9 @@ static const struct spinand_info macronix_spinand_table[] = {
335378
SPINAND_HAS_QE_BIT,
336379
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
337380
macronix_ecc_get_status),
338-
SPINAND_CONT_READ(macronix_set_cont_read)),
381+
SPINAND_CONT_READ(macronix_set_cont_read)
382+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
383+
macronix_set_read_retry)),
339384
SPINAND_INFO("MX35UF2GE4AC",
340385
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa2, 0x01),
341386
NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
@@ -366,7 +411,9 @@ static const struct spinand_info macronix_spinand_table[] = {
366411
&update_cache_variants),
367412
SPINAND_HAS_QE_BIT,
368413
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
369-
macronix_ecc_get_status)),
414+
macronix_ecc_get_status),
415+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
416+
macronix_set_read_retry)),
370417
SPINAND_INFO("MX35UF1GE4AD",
371418
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x96, 0x03),
372419
NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
@@ -377,7 +424,9 @@ static const struct spinand_info macronix_spinand_table[] = {
377424
SPINAND_HAS_QE_BIT,
378425
SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
379426
macronix_ecc_get_status),
380-
SPINAND_CONT_READ(macronix_set_cont_read)),
427+
SPINAND_CONT_READ(macronix_set_cont_read)
428+
SPINAND_READ_RETRY(MACRONIX_NUM_READ_RETRY_MODES,
429+
macronix_set_read_retry)),
381430
SPINAND_INFO("MX35UF1GE4AC",
382431
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x92, 0x01),
383432
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),

0 commit comments

Comments
 (0)