blob: 4e5a6eaecd7dfb1f6e961f974935758847959009 [file] [log] [blame]
Frieder Schrempfea4d7c82018-08-16 17:30:14 +02001// 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#ifndef __UBOOT__
11#include <linux/device.h>
12#include <linux/kernel.h>
13#endif
14#include <linux/mtd/spinand.h>
15
16#define SPINAND_MFR_WINBOND 0xEF
17
18#define WINBOND_CFG_BUF_READ BIT(3)
19
20static SPINAND_OP_VARIANTS(read_cache_variants,
21 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
22 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
23 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
24 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
25 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
26 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
27
28static SPINAND_OP_VARIANTS(write_cache_variants,
29 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
30 SPINAND_PROG_LOAD(true, 0, NULL, 0));
31
32static SPINAND_OP_VARIANTS(update_cache_variants,
33 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
34 SPINAND_PROG_LOAD(false, 0, NULL, 0));
35
36static int w25m02gv_ooblayout_ecc(struct mtd_info *mtd, int section,
37 struct mtd_oob_region *region)
38{
39 if (section > 3)
40 return -ERANGE;
41
42 region->offset = (16 * section) + 8;
43 region->length = 8;
44
45 return 0;
46}
47
48static int w25m02gv_ooblayout_free(struct mtd_info *mtd, int section,
49 struct mtd_oob_region *region)
50{
51 if (section > 3)
52 return -ERANGE;
53
54 region->offset = (16 * section) + 2;
55 region->length = 6;
56
57 return 0;
58}
59
60static const struct mtd_ooblayout_ops w25m02gv_ooblayout = {
61 .ecc = w25m02gv_ooblayout_ecc,
Simon Glass62fd1a42020-02-03 07:35:56 -070062 .rfree = w25m02gv_ooblayout_free,
Frieder Schrempfea4d7c82018-08-16 17:30:14 +020063};
64
65static int w25m02gv_select_target(struct spinand_device *spinand,
66 unsigned int target)
67{
68 struct spi_mem_op op = SPI_MEM_OP(SPI_MEM_OP_CMD(0xc2, 1),
69 SPI_MEM_OP_NO_ADDR,
70 SPI_MEM_OP_NO_DUMMY,
71 SPI_MEM_OP_DATA_OUT(1,
72 spinand->scratchbuf,
73 1));
74
75 *spinand->scratchbuf = target;
76 return spi_mem_exec_op(spinand->slave, &op);
77}
78
79static const struct spinand_info winbond_spinand_table[] = {
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +010080 SPINAND_INFO("W25M02GV",
81 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xab),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010082 NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 2),
Frieder Schrempfea4d7c82018-08-16 17:30:14 +020083 NAND_ECCREQ(1, 512),
84 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
85 &write_cache_variants,
86 &update_cache_variants),
87 0,
88 SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
89 SPINAND_SELECT_TARGET(w25m02gv_select_target)),
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +010090 SPINAND_INFO("W25N01GV",
91 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xaa),
Mikhail Kshevetskiy2a1e78b2023-01-10 12:58:40 +010092 NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
Robert Markoa2ee9162020-01-16 14:03:35 +010093 NAND_ECCREQ(1, 512),
94 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
95 &write_cache_variants,
96 &update_cache_variants),
97 0,
98 SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL)),
Frieder Schrempfea4d7c82018-08-16 17:30:14 +020099};
100
Frieder Schrempfea4d7c82018-08-16 17:30:14 +0200101static int winbond_spinand_init(struct spinand_device *spinand)
102{
103 struct nand_device *nand = spinand_to_nand(spinand);
104 unsigned int i;
105
106 /*
107 * Make sure all dies are in buffer read mode and not continuous read
108 * mode.
109 */
110 for (i = 0; i < nand->memorg.ntargets; i++) {
111 spinand_select_target(spinand, i);
112 spinand_upd_cfg(spinand, WINBOND_CFG_BUF_READ,
113 WINBOND_CFG_BUF_READ);
114 }
115
116 return 0;
117}
118
119static const struct spinand_manufacturer_ops winbond_spinand_manuf_ops = {
Frieder Schrempfea4d7c82018-08-16 17:30:14 +0200120 .init = winbond_spinand_init,
121};
122
123const struct spinand_manufacturer winbond_spinand_manufacturer = {
124 .id = SPINAND_MFR_WINBOND,
125 .name = "Winbond",
Mikhail Kshevetskiy72010312023-01-10 12:58:38 +0100126 .chips = winbond_spinand_table,
127 .nchips = ARRAY_SIZE(winbond_spinand_table),
Frieder Schrempfea4d7c82018-08-16 17:30:14 +0200128 .ops = &winbond_spinand_manuf_ops,
129};