5 The content of this patch has been adapted for Linux 4.19
7 Changes were made in Linux 5.x to add the bad-block limit
8 to the metadata available to the driver, adding a parameter
10 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
11 ^- New bad-block limit
13 This patch omits that parameter from the upstream patch
14 for compatibility with the Linux 4.19 driver.
18 From 049df13c4e63884fe6634db5568e08f65922256e Mon Sep 17 00:00:00 2001
19 From: Jeff Kletsky <git-commits@allycomm.com>
20 Date: Wed, 22 May 2019 15:05:55 -0700
21 Subject: [PATCH 3/3] mtd: spinand: Add support for GigaDevice GD5F1GQ4UFxxG
23 The GigaDevice GD5F1GQ4UFxxG SPI NAND is in current production devices
24 and, while it has the same logical layout as the E-series devices,
25 it differs in the SPI interfacing in significant ways.
27 This support is contingent on previous commits to:
29 * Add support for two-byte device IDs
30 * Define macros for page-read ops with three-byte addresses
32 http://www.gigadevice.com/datasheet/gd5f1gq4xfxxg/
34 Signed-off-by: Jeff Kletsky <git-commits@allycomm.com>
35 Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
36 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
38 drivers/mtd/nand/spi/gigadevice.c | 79 +++++++++++++++++++++++++------
39 1 file changed, 64 insertions(+), 15 deletions(-)
41 --- a/drivers/mtd/nand/spi/gigadevice.c
42 +++ b/drivers/mtd/nand/spi/gigadevice.c
44 #include <linux/mtd/spinand.h>
46 #define SPINAND_MFR_GIGADEVICE 0xC8
48 #define GD5FXGQ4XA_STATUS_ECC_1_7_BITFLIPS (1 << 4)
49 #define GD5FXGQ4XA_STATUS_ECC_8_BITFLIPS (3 << 4)
51 #define GD5FXGQ4UEXXG_REG_STATUS2 0xf0
53 +#define GD5FXGQ4UXFXXG_STATUS_ECC_MASK (7 << 4)
54 +#define GD5FXGQ4UXFXXG_STATUS_ECC_NO_BITFLIPS (0 << 4)
55 +#define GD5FXGQ4UXFXXG_STATUS_ECC_1_3_BITFLIPS (1 << 4)
56 +#define GD5FXGQ4UXFXXG_STATUS_ECC_UNCOR_ERROR (7 << 4)
58 static SPINAND_OP_VARIANTS(read_cache_variants,
59 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
60 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
61 @@ -22,6 +28,14 @@ static SPINAND_OP_VARIANTS(read_cache_va
62 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
63 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
65 +static SPINAND_OP_VARIANTS(read_cache_variants_f,
66 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
67 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP_3A(0, 1, NULL, 0),
68 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
69 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP_3A(0, 1, NULL, 0),
70 + SPINAND_PAGE_READ_FROM_CACHE_OP_3A(true, 0, 1, NULL, 0),
71 + SPINAND_PAGE_READ_FROM_CACHE_OP_3A(false, 0, 0, NULL, 0));
73 static SPINAND_OP_VARIANTS(write_cache_variants,
74 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
75 SPINAND_PROG_LOAD(true, 0, NULL, 0));
76 @@ -59,6 +73,11 @@ static int gd5fxgq4xa_ooblayout_free(str
80 +static const struct mtd_ooblayout_ops gd5fxgq4xa_ooblayout = {
81 + .ecc = gd5fxgq4xa_ooblayout_ecc,
82 + .free = gd5fxgq4xa_ooblayout_free,
85 static int gd5fxgq4xa_ecc_get_status(struct spinand_device *spinand,
88 @@ -83,7 +102,7 @@ static int gd5fxgq4xa_ecc_get_status(str
92 -static int gd5fxgq4uexxg_ooblayout_ecc(struct mtd_info *mtd, int section,
93 +static int gd5fxgq4_variant2_ooblayout_ecc(struct mtd_info *mtd, int section,
94 struct mtd_oob_region *region)
97 @@ -95,7 +114,7 @@ static int gd5fxgq4uexxg_ooblayout_ecc(s
101 -static int gd5fxgq4uexxg_ooblayout_free(struct mtd_info *mtd, int section,
102 +static int gd5fxgq4_variant2_ooblayout_free(struct mtd_info *mtd, int section,
103 struct mtd_oob_region *region)
106 @@ -108,6 +127,11 @@ static int gd5fxgq4uexxg_ooblayout_free(
110 +static const struct mtd_ooblayout_ops gd5fxgq4_variant2_ooblayout = {
111 + .ecc = gd5fxgq4_variant2_ooblayout_ecc,
112 + .free = gd5fxgq4_variant2_ooblayout_free,
115 static int gd5fxgq4uexxg_ecc_get_status(struct spinand_device *spinand,
118 @@ -150,15 +174,25 @@ static int gd5fxgq4uexxg_ecc_get_status(
122 -static const struct mtd_ooblayout_ops gd5fxgq4xa_ooblayout = {
123 - .ecc = gd5fxgq4xa_ooblayout_ecc,
124 - .free = gd5fxgq4xa_ooblayout_free,
126 +static int gd5fxgq4ufxxg_ecc_get_status(struct spinand_device *spinand,
129 + switch (status & GD5FXGQ4UXFXXG_STATUS_ECC_MASK) {
130 + case GD5FXGQ4UXFXXG_STATUS_ECC_NO_BITFLIPS:
133 -static const struct mtd_ooblayout_ops gd5fxgq4uexxg_ooblayout = {
134 - .ecc = gd5fxgq4uexxg_ooblayout_ecc,
135 - .free = gd5fxgq4uexxg_ooblayout_free,
137 + case GD5FXGQ4UXFXXG_STATUS_ECC_1_3_BITFLIPS:
140 + case GD5FXGQ4UXFXXG_STATUS_ECC_UNCOR_ERROR:
143 + default: /* (2 << 4) through (6 << 4) are 4-8 corrected errors */
144 + return ((status & GD5FXGQ4UXFXXG_STATUS_ECC_MASK) >> 4) + 2;
150 static const struct spinand_info gigadevice_spinand_table[] = {
151 SPINAND_INFO("GD5F1GQ4xA", 0xF1,
152 @@ -195,25 +229,40 @@ static const struct spinand_info gigadev
153 &write_cache_variants,
154 &update_cache_variants),
156 - SPINAND_ECCINFO(&gd5fxgq4uexxg_ooblayout,
157 + SPINAND_ECCINFO(&gd5fxgq4_variant2_ooblayout,
158 gd5fxgq4uexxg_ecc_get_status)),
159 + SPINAND_INFO("GD5F1GQ4UFxxG", 0xb148,
160 + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
161 + NAND_ECCREQ(8, 512),
162 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants_f,
163 + &write_cache_variants,
164 + &update_cache_variants),
166 + SPINAND_ECCINFO(&gd5fxgq4_variant2_ooblayout,
167 + gd5fxgq4ufxxg_ecc_get_status)),
170 static int gigadevice_spinand_detect(struct spinand_device *spinand)
172 u8 *id = spinand->id.data;
177 - * For GD NANDs, There is an address byte needed to shift in before IDs
178 - * are read out, so the first byte in raw_id is dummy.
179 + * Earlier GDF5-series devices (A,E) return [0][MID][DID]
180 + * Later (F) devices return [MID][DID1][DID2]
182 - if (id[1] != SPINAND_MFR_GIGADEVICE)
184 + if (id[0] == SPINAND_MFR_GIGADEVICE)
185 + did = (id[1] << 8) + id[2];
186 + else if (id[0] == 0 && id[1] == SPINAND_MFR_GIGADEVICE)
191 ret = spinand_match_and_init(spinand, gigadevice_spinand_table,
192 ARRAY_SIZE(gigadevice_spinand_table),