1 From a07e31adf2753cad2fd9790db5bfc047c81e8152 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 | 122 ++++++++++++++++++++++++++++++++++
23 include/linux/mtd/spinand.h | 1 +
24 4 files changed, 125 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 @@ -760,6 +760,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_match(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",
128 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE1),
129 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
130 + NAND_ECCREQ(8, 512),
131 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
132 + &write_cache_variants,
133 + &update_cache_variants),
134 + SPINAND_HAS_QE_BIT,
135 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
136 + xt26g0xa_ecc_get_status)),
137 + SPINAND_INFO("XT26G02A",
138 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE2),
139 + NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
140 + NAND_ECCREQ(8, 512),
141 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
142 + &write_cache_variants,
143 + &update_cache_variants),
144 + SPINAND_HAS_QE_BIT,
145 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
146 + xt26g0xa_ecc_get_status)),
147 + SPINAND_INFO("XT26G04A",
148 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE3),
149 + NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
150 + NAND_ECCREQ(8, 512),
151 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
152 + &write_cache_variants,
153 + &update_cache_variants),
154 + SPINAND_HAS_QE_BIT,
155 + SPINAND_ECCINFO(&xt26g0xa_ooblayout,
156 + xt26g0xa_ecc_get_status)),
159 +static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
162 +const struct spinand_manufacturer xtx_spinand_manufacturer = {
163 + .id = SPINAND_MFR_XTX,
165 + .chips = xtx_spinand_table,
166 + .nchips = ARRAY_SIZE(xtx_spinand_table),
167 + .ops = &xtx_spinand_manuf_ops,
169 --- a/include/linux/mtd/spinand.h
170 +++ b/include/linux/mtd/spinand.h
171 @@ -244,6 +244,7 @@ extern const struct spinand_manufacturer
172 extern const struct spinand_manufacturer paragon_spinand_manufacturer;
173 extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
174 extern const struct spinand_manufacturer winbond_spinand_manufacturer;
175 +extern const struct spinand_manufacturer xtx_spinand_manufacturer;
178 * struct spinand_op_variants - SPI NAND operation variants