1 From 8ffe91b6b429277bd7bd79267ba836edf951dce2 Mon Sep 17 00:00:00 2001
2 From: Felix Matouschek <felix@matouschek.org>
3 Date: Fri, 2 Jul 2021 20:31:23 +0200
4 Subject: [PATCH] mtd: spinand: Add support for XTX XT26G0xA
6 Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and
7 XTX26G04AXXXXX SPI NAND.
9 These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC
10 (8bit strength per 512bytes).
12 Tested on Teltonika RUTX10 flashed with OpenWrt.
14 Datasheets available at
15 http://www.xtxtech.com/download/?AId=225
16 https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf
18 Signed-off-by: Felix Matouschek <felix@matouschek.org>
20 drivers/mtd/nand/spi/Makefile | 2 +-
21 drivers/mtd/nand/spi/core.c | 1 +
22 drivers/mtd/nand/spi/xtx.c | 139 ++++++++++++++++++++++++++++++++++
23 include/linux/mtd/spinand.h | 1 +
24 4 files changed, 142 insertions(+), 1 deletion(-)
25 create mode 100644 drivers/mtd/nand/spi/xtx.c
27 --- a/drivers/mtd/nand/spi/Makefile
28 +++ b/drivers/mtd/nand/spi/Makefile
30 # SPDX-License-Identifier: GPL-2.0
31 -spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
32 +spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
33 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
34 --- a/drivers/mtd/nand/spi/core.c
35 +++ b/drivers/mtd/nand/spi/core.c
36 @@ -758,6 +758,7 @@ static const struct spinand_manufacturer
37 ¶gon_spinand_manufacturer,
38 &toshiba_spinand_manufacturer,
39 &winbond_spinand_manufacturer,
40 + &xtx_spinand_manufacturer,
43 static int spinand_manufacturer_detect(struct spinand_device *spinand)
45 +++ b/drivers/mtd/nand/spi/xtx.c
47 +// SPDX-License-Identifier: GPL-2.0
50 + * Felix Matouschek <felix@matouschek.org>
53 +#include <linux/device.h>
54 +#include <linux/kernel.h>
55 +#include <linux/mtd/spinand.h>
57 +#define SPINAND_MFR_XTX 0x0B
59 +#define XT26G0XA_STATUS_ECC_MASK GENMASK(5, 2)
60 +#define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2)
61 +#define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
62 +#define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4)
64 +static SPINAND_OP_VARIANTS(read_cache_variants,
65 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
66 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
67 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
68 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
69 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
70 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
72 +static SPINAND_OP_VARIANTS(write_cache_variants,
73 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
74 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
76 +static SPINAND_OP_VARIANTS(update_cache_variants,
77 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
78 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
80 +static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
81 + struct mtd_oob_region *region)
87 + region->length = 40;
92 +static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
93 + struct mtd_oob_region *region)
104 +static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
105 + .ecc = xt26g0xa_ooblayout_ecc,
106 + .free = xt26g0xa_ooblayout_free,
109 +static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
112 + switch (status & XT26G0XA_STATUS_ECC_MASK) {
113 + case XT26G0XA_STATUS_ECC_NO_DETECTED:
115 + case XT26G0XA_STATUS_ECC_8_CORRECTED:
117 + case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
119 + default: /* (1 << 2) through (7 << 2) are 1-7 corrected errors */
120 + return (status & XT26G0XA_STATUS_ECC_MASK) >> 2;
126 +static const struct spinand_info xtx_spinand_table[] = {
127 + SPINAND_INFO("XT26G01A", 0xE1,
128 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
129 + NAND_ECCREQ(8, 512),
130 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
131 + &write_cache_variants,
132 + &update_cache_variants),
133 + SPINAND_HAS_QE_BIT,
134 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
135 + xt26g0xa_ecc_get_status)),
136 + SPINAND_INFO("XT26G02A", 0xE2,
137 + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
138 + NAND_ECCREQ(8, 512),
139 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
140 + &write_cache_variants,
141 + &update_cache_variants),
142 + SPINAND_HAS_QE_BIT,
143 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
144 + xt26g0xa_ecc_get_status)),
145 + SPINAND_INFO("XT26G04A", 0xE3,
146 + NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
147 + NAND_ECCREQ(8, 512),
148 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
149 + &write_cache_variants,
150 + &update_cache_variants),
151 + SPINAND_HAS_QE_BIT,
152 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
153 + xt26g0xa_ecc_get_status)),
156 +static int xtx_spinand_detect(struct spinand_device *spinand)
158 + u8 *id = spinand->id.data;
162 + * XTX SPI NAND read ID needs a dummy byte, so the first byte in
163 + * raw_id is garbage.
165 + if (id[1] != SPINAND_MFR_XTX)
168 + ret = spinand_match_and_init(spinand, xtx_spinand_table,
169 + ARRAY_SIZE(xtx_spinand_table),
177 +static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
178 + .detect = xtx_spinand_detect,
181 +const struct spinand_manufacturer xtx_spinand_manufacturer = {
182 + .id = SPINAND_MFR_XTX,
184 + .ops = &xtx_spinand_manuf_ops,
186 --- a/include/linux/mtd/spinand.h
187 +++ b/include/linux/mtd/spinand.h
188 @@ -230,6 +230,7 @@ extern const struct spinand_manufacturer
189 extern const struct spinand_manufacturer paragon_spinand_manufacturer;
190 extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
191 extern const struct spinand_manufacturer winbond_spinand_manufacturer;
192 +extern const struct spinand_manufacturer xtx_spinand_manufacturer;
195 * struct spinand_op_variants - SPI NAND operation variants