1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016-2017 Micron Technology, Inc.
6 * Peter Pan <peterpandong@micron.com>
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/mtd/spinand.h>
13 #define SPINAND_MFR_MICRON 0x2c
15 #define MICRON_STATUS_ECC_MASK GENMASK(7, 4)
16 #define MICRON_STATUS_ECC_NO_BITFLIPS (0 << 4)
17 #define MICRON_STATUS_ECC_1TO3_BITFLIPS (1 << 4)
18 #define MICRON_STATUS_ECC_4TO6_BITFLIPS (3 << 4)
19 #define MICRON_STATUS_ECC_7TO8_BITFLIPS (5 << 4)
21 #define MICRON_CFG_CR BIT(0)
24 * As per datasheet, die selection is done by the 6th bit of Die
25 * Select Register (Address 0xD0).
27 #define MICRON_DIE_SELECT_REG 0xD0
29 #define MICRON_SELECT_DIE(x) ((x) << 6)
31 static SPINAND_OP_VARIANTS(quadio_read_cache_variants
,
32 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL
, 0),
33 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL
, 0),
34 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL
, 0),
35 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL
, 0),
36 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL
, 0),
37 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL
, 0));
39 static SPINAND_OP_VARIANTS(x4_write_cache_variants
,
40 SPINAND_PROG_LOAD_X4(true, 0, NULL
, 0),
41 SPINAND_PROG_LOAD(true, 0, NULL
, 0));
43 static SPINAND_OP_VARIANTS(x4_update_cache_variants
,
44 SPINAND_PROG_LOAD_X4(false, 0, NULL
, 0),
45 SPINAND_PROG_LOAD(false, 0, NULL
, 0));
47 /* Micron MT29F2G01AAAED Device */
48 static SPINAND_OP_VARIANTS(x4_read_cache_variants
,
49 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL
, 0),
50 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL
, 0),
51 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL
, 0),
52 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL
, 0));
54 static SPINAND_OP_VARIANTS(x1_write_cache_variants
,
55 SPINAND_PROG_LOAD(true, 0, NULL
, 0));
57 static SPINAND_OP_VARIANTS(x1_update_cache_variants
,
58 SPINAND_PROG_LOAD(false, 0, NULL
, 0));
60 static int micron_8_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
61 struct mtd_oob_region
*region
)
66 region
->offset
= mtd
->oobsize
/ 2;
67 region
->length
= mtd
->oobsize
/ 2;
72 static int micron_8_ooblayout_free(struct mtd_info
*mtd
, int section
,
73 struct mtd_oob_region
*region
)
78 /* Reserve 2 bytes for the BBM. */
80 region
->length
= (mtd
->oobsize
/ 2) - 2;
85 static const struct mtd_ooblayout_ops micron_8_ooblayout
= {
86 .ecc
= micron_8_ooblayout_ecc
,
87 .free
= micron_8_ooblayout_free
,
90 static int micron_4_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
91 struct mtd_oob_region
*region
)
93 struct spinand_device
*spinand
= mtd_to_spinand(mtd
);
95 if (section
>= spinand
->base
.memorg
.pagesize
/
99 region
->offset
= (section
* 16) + 8;
105 static int micron_4_ooblayout_free(struct mtd_info
*mtd
, int section
,
106 struct mtd_oob_region
*region
)
108 struct spinand_device
*spinand
= mtd_to_spinand(mtd
);
110 if (section
>= spinand
->base
.memorg
.pagesize
/
115 region
->offset
= 16 * section
;
118 /* section 0 has two bytes reserved for the BBM */
126 static const struct mtd_ooblayout_ops micron_4_ooblayout
= {
127 .ecc
= micron_4_ooblayout_ecc
,
128 .free
= micron_4_ooblayout_free
,
131 static int micron_select_target(struct spinand_device
*spinand
,
134 struct spi_mem_op op
= SPINAND_SET_FEATURE_OP(MICRON_DIE_SELECT_REG
,
135 spinand
->scratchbuf
);
140 *spinand
->scratchbuf
= MICRON_SELECT_DIE(target
);
142 return spi_mem_exec_op(spinand
->spimem
, &op
);
145 static int micron_8_ecc_get_status(struct spinand_device
*spinand
,
148 switch (status
& MICRON_STATUS_ECC_MASK
) {
149 case STATUS_ECC_NO_BITFLIPS
:
152 case STATUS_ECC_UNCOR_ERROR
:
155 case MICRON_STATUS_ECC_1TO3_BITFLIPS
:
158 case MICRON_STATUS_ECC_4TO6_BITFLIPS
:
161 case MICRON_STATUS_ECC_7TO8_BITFLIPS
:
171 static const struct spinand_info micron_spinand_table
[] = {
173 SPINAND_INFO("MT29F2G01ABAGD",
174 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x24),
175 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
177 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
178 &x4_write_cache_variants
,
179 &x4_update_cache_variants
),
181 SPINAND_ECCINFO(µn_8_ooblayout
,
182 micron_8_ecc_get_status
)),
184 SPINAND_INFO("MT29F2G01ABBGD",
185 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x25),
186 NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
188 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
189 &x4_write_cache_variants
,
190 &x4_update_cache_variants
),
192 SPINAND_ECCINFO(µn_8_ooblayout
,
193 micron_8_ecc_get_status
)),
195 SPINAND_INFO("MT29F1G01ABAFD",
196 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x14),
197 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
199 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
200 &x4_write_cache_variants
,
201 &x4_update_cache_variants
),
203 SPINAND_ECCINFO(µn_8_ooblayout
,
204 micron_8_ecc_get_status
)),
206 SPINAND_INFO("MT29F1G01ABAFD",
207 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x15),
208 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
210 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
211 &x4_write_cache_variants
,
212 &x4_update_cache_variants
),
214 SPINAND_ECCINFO(µn_8_ooblayout
,
215 micron_8_ecc_get_status
)),
217 SPINAND_INFO("MT29F4G01ADAGD",
218 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x36),
219 NAND_MEMORG(1, 2048, 128, 64, 2048, 80, 2, 1, 2),
221 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
222 &x4_write_cache_variants
,
223 &x4_update_cache_variants
),
225 SPINAND_ECCINFO(µn_8_ooblayout
,
226 micron_8_ecc_get_status
),
227 SPINAND_SELECT_TARGET(micron_select_target
)),
229 SPINAND_INFO("MT29F4G01ABAFD",
230 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x34),
231 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
233 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
234 &x4_write_cache_variants
,
235 &x4_update_cache_variants
),
236 SPINAND_HAS_CR_FEAT_BIT
,
237 SPINAND_ECCINFO(µn_8_ooblayout
,
238 micron_8_ecc_get_status
)),
240 SPINAND_INFO("MT29F4G01ABBFD",
241 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x35),
242 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
244 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
245 &x4_write_cache_variants
,
246 &x4_update_cache_variants
),
247 SPINAND_HAS_CR_FEAT_BIT
,
248 SPINAND_ECCINFO(µn_8_ooblayout
,
249 micron_8_ecc_get_status
)),
251 SPINAND_INFO("MT29F8G01ADAFD",
252 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x46),
253 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 2),
255 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
256 &x4_write_cache_variants
,
257 &x4_update_cache_variants
),
258 SPINAND_HAS_CR_FEAT_BIT
,
259 SPINAND_ECCINFO(µn_8_ooblayout
,
260 micron_8_ecc_get_status
),
261 SPINAND_SELECT_TARGET(micron_select_target
)),
263 SPINAND_INFO("MT29F8G01ADBFD",
264 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x47),
265 NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 2),
267 SPINAND_INFO_OP_VARIANTS(&quadio_read_cache_variants
,
268 &x4_write_cache_variants
,
269 &x4_update_cache_variants
),
270 SPINAND_HAS_CR_FEAT_BIT
,
271 SPINAND_ECCINFO(µn_8_ooblayout
,
272 micron_8_ecc_get_status
),
273 SPINAND_SELECT_TARGET(micron_select_target
)),
275 SPINAND_INFO("MT29F2G01AAAED",
276 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY
, 0x9F),
277 NAND_MEMORG(1, 2048, 64, 64, 2048, 80, 2, 1, 1),
279 SPINAND_INFO_OP_VARIANTS(&x4_read_cache_variants
,
280 &x1_write_cache_variants
,
281 &x1_update_cache_variants
),
283 SPINAND_ECCINFO(µn_4_ooblayout
, NULL
)),
286 static int micron_spinand_init(struct spinand_device
*spinand
)
289 * M70A device series enable Continuous Read feature at Power-up,
290 * which is not supported. Disable this bit to avoid any possible
293 if (spinand
->flags
& SPINAND_HAS_CR_FEAT_BIT
)
294 return spinand_upd_cfg(spinand
, MICRON_CFG_CR
, 0);
299 static const struct spinand_manufacturer_ops micron_spinand_manuf_ops
= {
300 .init
= micron_spinand_init
,
303 const struct spinand_manufacturer micron_spinand_manufacturer
= {
304 .id
= SPINAND_MFR_MICRON
,
306 .chips
= micron_spinand_table
,
307 .nchips
= ARRAY_SIZE(micron_spinand_table
),
308 .ops
= µn_spinand_manuf_ops
,