xref: /linux/drivers/mtd/nand/spi/winbond.c (revision 1b49e363252632d0493546511a41a65ed1a6fbbb)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2017 exceet electronics GmbH
4  *
5  * Authors:
6  *	Frieder Schrempf <frieder.schrempf@exceet.de>
7  *	Boris Brezillon <boris.brezillon@bootlin.com>
8  */
9 
10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #include <linux/mtd/spinand.h>
13 #include <linux/units.h>
14 #include <linux/delay.h>
15 
16 #define SPINAND_MFR_WINBOND		0xEF
17 
18 #define WINBOND_CFG_BUF_READ		BIT(3)
19 
20 #define W25N04KV_STATUS_ECC_5_8_BITFLIPS	(3 << 4)
21 
22 #define W25N0XJW_SR4			0xD0
23 #define W25N0XJW_SR4_HS			BIT(2)
24 
25 #define W35N01JW_VCR_IO_MODE_REG	0x00
26 #define W35N01JW_VCR_IO_MODE_SINGLE_SDR		0xFF
27 #define W35N01JW_VCR_IO_MODE_OCTAL_SDR		0xDF
28 #define W35N01JW_VCR_IO_MODE_OCTAL_DDR_DS	0xE7
29 #define W35N01JW_VCR_IO_MODE_OCTAL_DDR		0xC7
30 #define W35N01JW_VCR_DUMMY_CLOCK_REG	0x01
31 
32 /*
33  * "X2" in the core is equivalent to "dual output" in the datasheets,
34  * "X4" in the core is equivalent to "quad output" in the datasheets.
35  * Quad and octal capable chips feature an absolute maximum frequency of 166MHz.
36  */
37 
38 static SPINAND_OP_VARIANTS(read_cache_octal_variants,
39 		SPINAND_PAGE_READ_FROM_CACHE_8D_8D_8D_OP(0, 24, NULL, 0, 120 * HZ_PER_MHZ),
40 		SPINAND_PAGE_READ_FROM_CACHE_8D_8D_8D_OP(0, 16, NULL, 0, 86 * HZ_PER_MHZ),
41 		SPINAND_PAGE_READ_FROM_CACHE_1S_1D_8D_OP(0, 3, NULL, 0, 120 * HZ_PER_MHZ),
42 		SPINAND_PAGE_READ_FROM_CACHE_1S_1D_8D_OP(0, 2, NULL, 0, 105 * HZ_PER_MHZ),
43 		SPINAND_PAGE_READ_FROM_CACHE_1S_8S_8S_OP(0, 20, NULL, 0, 0),
44 		SPINAND_PAGE_READ_FROM_CACHE_1S_8S_8S_OP(0, 16, NULL, 0, 162 * HZ_PER_MHZ),
45 		SPINAND_PAGE_READ_FROM_CACHE_1S_8S_8S_OP(0, 12, NULL, 0, 124 * HZ_PER_MHZ),
46 		SPINAND_PAGE_READ_FROM_CACHE_1S_8S_8S_OP(0, 8, NULL, 0, 86 * HZ_PER_MHZ),
47 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_8S_OP(0, 2, NULL, 0, 0),
48 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_8S_OP(0, 1, NULL, 0, 133 * HZ_PER_MHZ),
49 		SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
50 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
51 
52 static SPINAND_OP_VARIANTS(write_cache_octal_variants,
53 		SPINAND_PROG_LOAD_8D_8D_8D_OP(true, 0, NULL, 0),
54 		SPINAND_PROG_LOAD_1S_8S_8S_OP(true, 0, NULL, 0),
55 		SPINAND_PROG_LOAD_1S_1S_8S_OP(0, NULL, 0),
56 		SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
57 
58 static SPINAND_OP_VARIANTS(update_cache_octal_variants,
59 		SPINAND_PROG_LOAD_8D_8D_8D_OP(false, 0, NULL, 0),
60 		SPINAND_PROG_LOAD_1S_8S_8S_OP(false, 0, NULL, 0),
61 		SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
62 
63 static SPINAND_OP_VARIANTS(read_cache_dual_quad_dtr_variants,
64 		SPINAND_PAGE_READ_FROM_CACHE_1S_4D_4D_OP(0, 8, NULL, 0, 80 * HZ_PER_MHZ),
65 		SPINAND_PAGE_READ_FROM_CACHE_1S_1D_4D_OP(0, 2, NULL, 0, 80 * HZ_PER_MHZ),
66 		SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 4, NULL, 0, 0),
67 		SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 2, NULL, 0, 104 * HZ_PER_MHZ),
68 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
69 		SPINAND_PAGE_READ_FROM_CACHE_1S_2D_2D_OP(0, 4, NULL, 0, 80 * HZ_PER_MHZ),
70 		SPINAND_PAGE_READ_FROM_CACHE_1S_1D_2D_OP(0, 2, NULL, 0, 80 * HZ_PER_MHZ),
71 		SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 2, NULL, 0, 0),
72 		SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 1, NULL, 0, 104 * HZ_PER_MHZ),
73 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
74 		SPINAND_PAGE_READ_FROM_CACHE_1S_1D_1D_OP(0, 2, NULL, 0, 80 * HZ_PER_MHZ),
75 		SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
76 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 54 * HZ_PER_MHZ));
77 
78 static SPINAND_OP_VARIANTS(read_cache_variants,
79 		SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 2, NULL, 0, 0),
80 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
81 		SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 1, NULL, 0, 0),
82 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
83 		SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
84 		SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
85 
86 static SPINAND_OP_VARIANTS(write_cache_variants,
87 		SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
88 		SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
89 
90 static SPINAND_OP_VARIANTS(update_cache_variants,
91 		SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
92 		SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
93 
94 #define SPINAND_WINBOND_WRITE_VCR_1S_1S_1S(reg, buf)			\
95 	SPI_MEM_OP(SPI_MEM_OP_CMD(0x81, 1),				\
96 		   SPI_MEM_OP_ADDR(3, reg, 1),				\
97 		   SPI_MEM_OP_NO_DUMMY,					\
98 		   SPI_MEM_OP_DATA_OUT(1, buf, 1))
99 
100 #define SPINAND_WINBOND_WRITE_VCR_8D_8D_8D(reg, buf)			\
101 	SPI_MEM_OP(SPI_MEM_DTR_OP_RPT_CMD(0x81, 8),			\
102 		   SPI_MEM_DTR_OP_ADDR(4, reg, 8),			\
103 		   SPI_MEM_OP_NO_DUMMY,					\
104 		   SPI_MEM_DTR_OP_DATA_OUT(2, buf, 8))
105 
106 static SPINAND_OP_VARIANTS(winbond_w35_ops,
107 		SPINAND_WINBOND_WRITE_VCR_1S_1S_1S(0, NULL),
108 		SPINAND_WINBOND_WRITE_VCR_8D_8D_8D(0, NULL));
109 
110 static struct spi_mem_op
spinand_fill_winbond_write_vcr_op(struct spinand_device * spinand,u8 reg,void * valptr)111 spinand_fill_winbond_write_vcr_op(struct spinand_device *spinand, u8 reg, void *valptr)
112 {
113 	return (spinand->bus_iface == SSDR) ?
114 		(struct spi_mem_op)SPINAND_WINBOND_WRITE_VCR_1S_1S_1S(reg, valptr) :
115 		(struct spi_mem_op)SPINAND_WINBOND_WRITE_VCR_8D_8D_8D(reg, valptr);
116 }
117 
118 #define SPINAND_WINBOND_SELECT_TARGET_1S_0_1S(buf)			\
119 	SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),				\
120 		   SPI_MEM_OP_NO_ADDR,					\
121 		   SPI_MEM_OP_NO_DUMMY,					\
122 		   SPI_MEM_OP_DATA_OUT(1, buf, 1))
123 
124 static SPINAND_OP_VARIANTS(winbond_w25_ops,
125 		SPINAND_WINBOND_SELECT_TARGET_1S_0_1S(NULL));
126 
127 static struct spi_mem_op
spinand_fill_winbond_select_target_op(struct spinand_device * spinand,void * valptr)128 spinand_fill_winbond_select_target_op(struct spinand_device *spinand, void *valptr)
129 {
130 	WARN_ON_ONCE(spinand->bus_iface != SSDR);
131 
132 	return (struct spi_mem_op)SPINAND_WINBOND_SELECT_TARGET_1S_0_1S(valptr);
133 }
134 
w25m02gv_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)135 static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
136 				  struct mtd_oob_region *region)
137 {
138 	if (section > 3)
139 		return -ERANGE;
140 
141 	region->offset = (16 * section) + 8;
142 	region->length = 8;
143 
144 	return 0;
145 }
146 
w25m02gv_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)147 static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
148 				   struct mtd_oob_region *region)
149 {
150 	if (section > 3)
151 		return -ERANGE;
152 
153 	region->offset = (16 * section) + 2;
154 	region->length = 6;
155 
156 	return 0;
157 }
158 
159 static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
160 	.ecc = w25m02gv_ooblayout_ecc,
161 	.free = w25m02gv_ooblayout_free,
162 };
163 
w25m02gv_select_target(struct spinand_device * spinand,unsigned int target)164 static int w25m02gv_select_target(struct spinand_device *spinand,
165 				  unsigned int target)
166 {
167 	struct spi_mem_op op = SPINAND_OP(spinand, winbond_select_target,
168 					  spinand->scratchbuf);
169 
170 	*spinand->scratchbuf = target;
171 	return spi_mem_exec_op(spinand->spimem, &op);
172 }
173 
w25n01kv_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)174 static int w25n01kv_ooblayout_ecc(struct mtd_info *mtd, int section,
175 				  struct mtd_oob_region *region)
176 {
177 	if (section > 3)
178 		return -ERANGE;
179 
180 	region->offset = 64 + (8 * section);
181 	region->length = 7;
182 
183 	return 0;
184 }
185 
w25n02kv_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)186 static int w25n02kv_ooblayout_ecc(struct mtd_info *mtd, int section,
187 				  struct mtd_oob_region *region)
188 {
189 	if (section > 3)
190 		return -ERANGE;
191 
192 	region->offset = 64 + (16 * section);
193 	region->length = 13;
194 
195 	return 0;
196 }
197 
w25n02kv_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)198 static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section,
199 				   struct mtd_oob_region *region)
200 {
201 	if (section > 3)
202 		return -ERANGE;
203 
204 	region->offset = (16 * section) + 2;
205 	region->length = 14;
206 
207 	return 0;
208 }
209 
210 static const struct mtd_ooblayout_ops w25n01kv_ooblayout = {
211 	.ecc = w25n01kv_ooblayout_ecc,
212 	.free = w25n02kv_ooblayout_free,
213 };
214 
215 static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
216 	.ecc = w25n02kv_ooblayout_ecc,
217 	.free = w25n02kv_ooblayout_free,
218 };
219 
w25n01jw_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)220 static int w25n01jw_ooblayout_ecc(struct mtd_info *mtd, int section,
221 				  struct mtd_oob_region *region)
222 {
223 	if (section > 3)
224 		return -ERANGE;
225 
226 	region->offset = (16 * section) + 12;
227 	region->length = 4;
228 
229 	return 0;
230 }
231 
w25n01jw_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)232 static int w25n01jw_ooblayout_free(struct mtd_info *mtd, int section,
233 				   struct mtd_oob_region *region)
234 {
235 	if (section > 3)
236 		return -ERANGE;
237 
238 	region->offset = (16 * section);
239 	region->length = 12;
240 
241 	/* Extract BBM */
242 	if (!section) {
243 		region->offset += 2;
244 		region->length -= 2;
245 	}
246 
247 	return 0;
248 }
249 
w35n01jw_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)250 static int w35n01jw_ooblayout_ecc(struct mtd_info *mtd, int section,
251 				  struct mtd_oob_region *region)
252 {
253 	if (section > 7)
254 		return -ERANGE;
255 
256 	region->offset = (16 * section) + 12;
257 	region->length = 4;
258 
259 	return 0;
260 }
261 
w35n01jw_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)262 static int w35n01jw_ooblayout_free(struct mtd_info *mtd, int section,
263 				   struct mtd_oob_region *region)
264 {
265 	if (section > 7)
266 		return -ERANGE;
267 
268 	region->offset = 16 * section;
269 	region->length = 12;
270 
271 	/* Extract BBM */
272 	if (!section) {
273 		region->offset += 2;
274 		region->length -= 2;
275 	}
276 
277 	return 0;
278 }
279 
280 static const struct mtd_ooblayout_ops w25n01jw_ooblayout = {
281 	.ecc = w25n01jw_ooblayout_ecc,
282 	.free = w25n01jw_ooblayout_free,
283 };
284 
285 static const struct mtd_ooblayout_ops w35n01jw_ooblayout = {
286 	.ecc = w35n01jw_ooblayout_ecc,
287 	.free = w35n01jw_ooblayout_free,
288 };
289 
w25n02kv_ecc_get_status(struct spinand_device * spinand,u8 status)290 static int w25n02kv_ecc_get_status(struct spinand_device *spinand,
291 				   u8 status)
292 {
293 	struct nand_device *nand = spinand_to_nand(spinand);
294 	u8 mbf = 0;
295 	struct spi_mem_op op = SPINAND_OP(spinand, get_feature,
296 					  0x30, spinand->scratchbuf);
297 
298 	switch (status & STATUS_ECC_MASK) {
299 	case STATUS_ECC_NO_BITFLIPS:
300 		return 0;
301 
302 	case STATUS_ECC_UNCOR_ERROR:
303 		return -EBADMSG;
304 
305 	case STATUS_ECC_HAS_BITFLIPS:
306 	case W25N04KV_STATUS_ECC_5_8_BITFLIPS:
307 		/*
308 		 * Let's try to retrieve the real maximum number of bitflips
309 		 * in order to avoid forcing the wear-leveling layer to move
310 		 * data around if it's not necessary.
311 		 */
312 		if (spi_mem_exec_op(spinand->spimem, &op))
313 			return nanddev_get_ecc_conf(nand)->strength;
314 
315 		mbf = *(spinand->scratchbuf) >> 4;
316 
317 		if (WARN_ON(mbf > nanddev_get_ecc_conf(nand)->strength || !mbf))
318 			return nanddev_get_ecc_conf(nand)->strength;
319 
320 		return mbf;
321 
322 	default:
323 		break;
324 	}
325 
326 	return -EINVAL;
327 }
328 
w25n0xjw_hs_cfg(struct spinand_device * spinand,enum spinand_bus_interface iface)329 static int w25n0xjw_hs_cfg(struct spinand_device *spinand,
330 			   enum spinand_bus_interface iface)
331 {
332 	const struct spi_mem_op *op;
333 	bool hs;
334 	u8 sr4;
335 	int ret;
336 
337 	if (iface != SSDR)
338 		return -EOPNOTSUPP;
339 
340 	op = spinand->op_templates->read_cache;
341 	if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
342 		hs = false;
343 	else if (op->cmd.buswidth == 1 && op->addr.buswidth == 1 &&
344 		 op->dummy.buswidth == 1 && op->data.buswidth == 1)
345 		hs = false;
346 	else if (!op->max_freq)
347 		hs = true;
348 	else
349 		hs = false;
350 
351 	ret = spinand_read_reg_op(spinand, W25N0XJW_SR4, &sr4);
352 	if (ret)
353 		return ret;
354 
355 	if (hs)
356 		sr4 |= W25N0XJW_SR4_HS;
357 	else
358 		sr4 &= ~W25N0XJW_SR4_HS;
359 
360 	ret = spinand_write_reg_op(spinand, W25N0XJW_SR4, sr4);
361 	if (ret)
362 		return ret;
363 
364 	return 0;
365 }
366 
w35n0xjw_write_vcr(struct spinand_device * spinand,u8 reg,u8 val)367 static int w35n0xjw_write_vcr(struct spinand_device *spinand, u8 reg, u8 val)
368 {
369 	struct spi_mem_op op = SPINAND_OP(spinand, winbond_write_vcr,
370 					  reg, spinand->scratchbuf);
371 	int ret;
372 
373 	*spinand->scratchbuf = val;
374 
375 	ret = spinand_write_enable_op(spinand);
376 	if (ret)
377 		return ret;
378 
379 	ret = spi_mem_exec_op(spinand->spimem, &op);
380 	if (ret)
381 		return ret;
382 
383 	/*
384 	 * Write VCR operation doesn't set the busy bit in SR, which means we
385 	 * cannot perform a status poll. Minimum time of 50ns is needed to
386 	 * complete the write.
387 	 */
388 	ndelay(50);
389 
390 	return 0;
391 }
392 
w35n0xjw_vcr_cfg(struct spinand_device * spinand,enum spinand_bus_interface iface)393 static int w35n0xjw_vcr_cfg(struct spinand_device *spinand,
394 			    enum spinand_bus_interface iface)
395 {
396 	const struct spi_mem_op *ref_op;
397 	unsigned int dummy_cycles;
398 	bool dtr, single;
399 	u8 io_mode;
400 	int ret;
401 
402 	switch (iface) {
403 	case SSDR:
404 		ref_op = spinand->ssdr_op_templates.read_cache;
405 		break;
406 	case ODTR:
407 		ref_op = spinand->odtr_op_templates.read_cache;
408 		break;
409 	default:
410 		return -EOPNOTSUPP;
411 	}
412 
413 	dummy_cycles = ((ref_op->dummy.nbytes * 8) / ref_op->dummy.buswidth) /
414 		(ref_op->dummy.dtr ? 2 : 1);
415 	switch (dummy_cycles) {
416 	case 8:
417 	case 12:
418 	case 16:
419 	case 20:
420 	case 24:
421 	case 28:
422 		break;
423 	default:
424 		return -EINVAL;
425 	}
426 
427 	ret = w35n0xjw_write_vcr(spinand, W35N01JW_VCR_DUMMY_CLOCK_REG, dummy_cycles);
428 	if (ret)
429 		return ret;
430 
431 	single = (ref_op->cmd.buswidth == 1 &&
432 		  ref_op->addr.buswidth == 1 &&
433 		  ref_op->data.buswidth == 1);
434 	dtr = (ref_op->cmd.dtr && ref_op->addr.dtr && ref_op->data.dtr);
435 	if (single && !dtr)
436 		io_mode = W35N01JW_VCR_IO_MODE_SINGLE_SDR;
437 	else if (!single && !dtr)
438 		io_mode = W35N01JW_VCR_IO_MODE_OCTAL_SDR;
439 	else if (!single && dtr)
440 		io_mode = W35N01JW_VCR_IO_MODE_OCTAL_DDR;
441 	else
442 		return -EINVAL;
443 
444 	ret = w35n0xjw_write_vcr(spinand, W35N01JW_VCR_IO_MODE_REG, io_mode);
445 	if (ret)
446 		return ret;
447 
448 	return 0;
449 }
450 
451 static const struct spinand_info winbond_spinand_table[] = {
452 	/* 512M-bit densities */
453 	SPINAND_INFO("W25N512GW", /* 1.8V */
454 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xba, 0x20),
455 		     NAND_MEMORG(1, 2048, 64, 64, 512, 10, 1, 1, 1),
456 		     NAND_ECCREQ(1, 512),
457 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
458 					      &write_cache_variants,
459 					      &update_cache_variants),
460 		     0,
461 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
462 	/* 1G-bit densities */
463 	SPINAND_INFO("W25N01GV", /* 3.3V */
464 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x21),
465 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
466 		     NAND_ECCREQ(1, 512),
467 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
468 					      &write_cache_variants,
469 					      &update_cache_variants),
470 		     0,
471 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
472 	SPINAND_INFO("W25N01GW", /* 1.8V */
473 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xba, 0x21),
474 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
475 		     NAND_ECCREQ(1, 512),
476 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
477 					      &write_cache_variants,
478 					      &update_cache_variants),
479 		     0,
480 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
481 	SPINAND_INFO("W25N01JW", /* high-speed 1.8V */
482 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xbc, 0x21),
483 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
484 		     NAND_ECCREQ(1, 512),
485 		     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
486 					      &write_cache_variants,
487 					      &update_cache_variants),
488 		     0,
489 		     SPINAND_ECCINFO(&w25n01jw_ooblayout, NULL),
490 		     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
491 	SPINAND_INFO("W25N01KV", /* 3.3V */
492 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xae, 0x21),
493 		     NAND_MEMORG(1, 2048, 96, 64, 1024, 20, 1, 1, 1),
494 		     NAND_ECCREQ(4, 512),
495 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
496 					      &write_cache_variants,
497 					      &update_cache_variants),
498 		     0,
499 		     SPINAND_ECCINFO(&w25n01kv_ooblayout, w25n02kv_ecc_get_status)),
500 	SPINAND_INFO("W35N01JW", /* 1.8V */
501 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdc, 0x21),
502 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 1, 1),
503 		     NAND_ECCREQ(1, 512),
504 		     SPINAND_INFO_OP_VARIANTS(&read_cache_octal_variants,
505 					      &write_cache_octal_variants,
506 					      &update_cache_octal_variants),
507 		     0,
508 		     SPINAND_INFO_VENDOR_OPS(&winbond_w35_ops),
509 		     SPINAND_ECCINFO(&w35n01jw_ooblayout, NULL),
510 		     SPINAND_CONFIGURE_CHIP(w35n0xjw_vcr_cfg)),
511 	SPINAND_INFO("W35N02JW", /* 1.8V */
512 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdf, 0x22),
513 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 2, 1),
514 		     NAND_ECCREQ(1, 512),
515 		     SPINAND_INFO_OP_VARIANTS(&read_cache_octal_variants,
516 					      &write_cache_octal_variants,
517 					      &update_cache_octal_variants),
518 		     0,
519 		     SPINAND_INFO_VENDOR_OPS(&winbond_w35_ops),
520 		     SPINAND_ECCINFO(&w35n01jw_ooblayout, NULL),
521 		     SPINAND_CONFIGURE_CHIP(w35n0xjw_vcr_cfg)),
522 	SPINAND_INFO("W35N04JW", /* 1.8V */
523 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdf, 0x23),
524 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 4, 1),
525 		     NAND_ECCREQ(1, 512),
526 		     SPINAND_INFO_OP_VARIANTS(&read_cache_octal_variants,
527 					      &write_cache_octal_variants,
528 					      &update_cache_octal_variants),
529 		     0,
530 		     SPINAND_INFO_VENDOR_OPS(&winbond_w35_ops),
531 		     SPINAND_ECCINFO(&w35n01jw_ooblayout, NULL),
532 		     SPINAND_CONFIGURE_CHIP(w35n0xjw_vcr_cfg)),
533 	/* 2G-bit densities */
534 	SPINAND_INFO("W25M02GV", /* 2x1G-bit 3.3V */
535 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab, 0x21),
536 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
537 		     NAND_ECCREQ(1, 512),
538 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
539 					      &write_cache_variants,
540 					      &update_cache_variants),
541 		     0,
542 		     SPINAND_INFO_VENDOR_OPS(&winbond_w25_ops),
543 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
544 		     SPINAND_SELECT_TARGET(w25m02gv_select_target)),
545 	SPINAND_INFO("W25N02JW", /* high-speed 1.8V */
546 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xbf, 0x22),
547 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 2, 1),
548 		     NAND_ECCREQ(1, 512),
549 		     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
550 					      &write_cache_variants,
551 					      &update_cache_variants),
552 		     0,
553 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
554 		     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
555 	SPINAND_INFO("W25N02KV", /* 3.3V */
556 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x22),
557 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
558 		     NAND_ECCREQ(8, 512),
559 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
560 					      &write_cache_variants,
561 					      &update_cache_variants),
562 		     0,
563 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
564 	SPINAND_INFO("W25N02KW", /* 1.8V */
565 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xba, 0x22),
566 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
567 		     NAND_ECCREQ(8, 512),
568 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
569 					      &write_cache_variants,
570 					      &update_cache_variants),
571 		     0,
572 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
573 	/* 4G-bit densities */
574 	SPINAND_INFO("W25N04KV", /* 3.3V */
575 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa, 0x23),
576 		     NAND_MEMORG(1, 2048, 128, 64, 4096, 40, 2, 1, 1),
577 		     NAND_ECCREQ(8, 512),
578 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
579 					      &write_cache_variants,
580 					      &update_cache_variants),
581 		     0,
582 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
583 	SPINAND_INFO("W25N04KW", /* 1.8V */
584 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xba, 0x23),
585 		     NAND_MEMORG(1, 2048, 128, 64, 4096, 40, 1, 1, 1),
586 		     NAND_ECCREQ(8, 512),
587 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
588 					      &write_cache_variants,
589 					      &update_cache_variants),
590 		     0,
591 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
592 };
593 
winbond_spinand_init(struct spinand_device * spinand)594 static int winbond_spinand_init(struct spinand_device *spinand)
595 {
596 	struct nand_device *nand = spinand_to_nand(spinand);
597 	unsigned int i;
598 
599 	/*
600 	 * Make sure all dies are in buffer read mode and not continuous read
601 	 * mode.
602 	 */
603 	for (i = 0; i < nand->memorg.ntargets; i++) {
604 		spinand_select_target(spinand, i);
605 		spinand_upd_cfg(spinand, WINBOND_CFG_BUF_READ,
606 				WINBOND_CFG_BUF_READ);
607 	}
608 
609 	return 0;
610 }
611 
612 static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
613 	.init = winbond_spinand_init,
614 };
615 
616 const struct spinand_manufacturer winbond_spinand_manufacturer = {
617 	.id = SPINAND_MFR_WINBOND,
618 	.name = "Winbond",
619 	.chips = winbond_spinand_table,
620 	.nchips = ARRAY_SIZE(winbond_spinand_table),
621 	.ops = &winbond_spinand_manuf_ops,
622 };
623