blob: ecd2b71b058d8206c3b18e4ec6abf2ccdf1c99e9 [file] [log] [blame]
developer41370d52022-03-16 16:01:59 +08001From 8c573d9419bf61f7b66b6114f1171f3a8a4a0e38 Mon Sep 17 00:00:00 2001
2From: Thirumalesha Narasimhappa <nthirumalesha7@gmail.com>
3Date: Sun, 8 Nov 2020 19:37:35 +0800
4Subject: [PATCH] mtd: spinand: micron: Add support for MT29F2G01AAAED
5
6The MT29F2G01AAAED is a single die, 2Gb Micron SPI NAND Flash with 4-bit
7ECC
8
9Signed-off-by: Thirumalesha Narasimhappa <nthirumalesha7@gmail.com>
10Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
11Link: https://lore.kernel.org/linux-mtd/20201108113735.2533-3-nthirumalesha7@gmail.com
12---
13 drivers/mtd/nand/spi/micron.c | 64 +++++++++++++++++++++++++++++++++++
14 1 file changed, 64 insertions(+)
15
16diff --git a/drivers/mtd/nand/spi/micron.c b/drivers/mtd/nand/spi/micron.c
17index afe3ba37dcfb8e..50b7295bc92226 100644
18--- a/drivers/mtd/nand/spi/micron.c
19+++ b/drivers/mtd/nand/spi/micron.c
20@@ -44,6 +44,19 @@ static SPINAND_OP_VARIANTS(x4_update_cache_variants,
21 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
22 SPINAND_PROG_LOAD(false, 0, NULL, 0));
23
24+/* Micron MT29F2G01AAAED Device */
25+static SPINAND_OP_VARIANTS(x4_read_cache_variants,
26+ SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
27+ SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
28+ SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
29+ SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
30+
31+static SPINAND_OP_VARIANTS(x1_write_cache_variants,
32+ SPINAND_PROG_LOAD(true, 0, NULL, 0));
33+
34+static SPINAND_OP_VARIANTS(x1_update_cache_variants,
35+ SPINAND_PROG_LOAD(false, 0, NULL, 0));
36+
37 static int micron_8_ooblayout_ecc(struct mtd_info *mtd, int section,
38 struct mtd_oob_region *region)
39 {
40@@ -74,6 +87,47 @@ static const struct mtd_ooblayout_ops micron_8_ooblayout = {
41 .free = micron_8_ooblayout_free,
42 };
43
44+static int micron_4_ooblayout_ecc(struct mtd_info *mtd, int section,
45+ struct mtd_oob_region *region)
46+{
47+ struct spinand_device *spinand = mtd_to_spinand(mtd);
48+
49+ if (section >= spinand->base.memorg.pagesize /
50+ mtd->ecc_step_size)
51+ return -ERANGE;
52+
53+ region->offset = (section * 16) + 8;
54+ region->length = 8;
55+
56+ return 0;
57+}
58+
59+static int micron_4_ooblayout_free(struct mtd_info *mtd, int section,
60+ struct mtd_oob_region *region)
61+{
62+ struct spinand_device *spinand = mtd_to_spinand(mtd);
63+
64+ if (section >= spinand->base.memorg.pagesize /
65+ mtd->ecc_step_size)
66+ return -ERANGE;
67+
68+ if (section) {
69+ region->offset = 16 * section;
70+ region->length = 8;
71+ } else {
72+ /* section 0 has two bytes reserved for the BBM */
73+ region->offset = 2;
74+ region->length = 6;
75+ }
76+
77+ return 0;
78+}
79+
80+static const struct mtd_ooblayout_ops micron_4_ooblayout = {
81+ .ecc = micron_4_ooblayout_ecc,
82+ .free = micron_4_ooblayout_free,
83+};
84+
85 static int micron_select_target(struct spinand_device *spinand,
86 unsigned int target)
87 {
88@@ -217,6 +271,16 @@ static const struct spinand_info micron_spinand_table[] = {
89 SPINAND_ECCINFO(&micron_8_ooblayout,
90 micron_8_ecc_get_status),
91 SPINAND_SELECT_TARGET(micron_select_target)),
92+ /* M69A 2Gb 3.3V */
93+ SPINAND_INFO("MT29F2G01AAAED",
94+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x9F),
95+ NAND_MEMORG(1, 2048, 64, 64, 2048, 80, 2, 1, 1),
96+ NAND_ECCREQ(4, 512),
97+ SPINAND_INFO_OP_VARIANTS(&x4_read_cache_variants,
98+ &x1_write_cache_variants,
99+ &x1_update_cache_variants),
100+ 0,
101+ SPINAND_ECCINFO(&micron_4_ooblayout, NULL)),
102 };
103
104 static int micron_spinand_init(struct spinand_device *spinand)