Skip to content

Commit f4c5c7f

Browse files
0xFelixmiquelraynal
authored andcommitted
mtd: spinand: Add support for XTX XT26G0xA
Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and XTX26G04AXXXXX SPI NAND. These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC (8bit strength per 512bytes). Tested on Teltonika RUTX10 flashed with OpenWrt. Links: - http://www.xtxtech.com/download/?AId=225 - https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf Signed-off-by: Felix Matouschek <felix@matouschek.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Link: https://lore.kernel.org/linux-mtd/20220418132803.664103-1-felix@matouschek.org
1 parent d9edc4b commit f4c5c7f

4 files changed

Lines changed: 132 additions & 1 deletion

File tree

drivers/mtd/nand/spi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o
2+
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

drivers/mtd/nand/spi/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ static const struct spinand_manufacturer *spinand_manufacturers[] = {
933933
&paragon_spinand_manufacturer,
934934
&toshiba_spinand_manufacturer,
935935
&winbond_spinand_manufacturer,
936+
&xtx_spinand_manufacturer,
936937
};
937938

938939
static int spinand_manufacturer_match(struct spinand_device *spinand,

drivers/mtd/nand/spi/xtx.c

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Author:
4+
* Felix Matouschek <felix@matouschek.org>
5+
*/
6+
7+
#include <linux/device.h>
8+
#include <linux/kernel.h>
9+
#include <linux/mtd/spinand.h>
10+
11+
#define SPINAND_MFR_XTX 0x0B
12+
13+
#define XT26G0XA_STATUS_ECC_MASK GENMASK(5, 2)
14+
#define XT26G0XA_STATUS_ECC_NO_DETECTED (0 << 2)
15+
#define XT26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
16+
#define XT26G0XA_STATUS_ECC_UNCOR_ERROR (2 << 4)
17+
18+
static SPINAND_OP_VARIANTS(read_cache_variants,
19+
SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
20+
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
21+
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
22+
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
23+
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
24+
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
25+
26+
static SPINAND_OP_VARIANTS(write_cache_variants,
27+
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
28+
SPINAND_PROG_LOAD(true, 0, NULL, 0));
29+
30+
static SPINAND_OP_VARIANTS(update_cache_variants,
31+
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
32+
SPINAND_PROG_LOAD(false, 0, NULL, 0));
33+
34+
static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
35+
struct mtd_oob_region *region)
36+
{
37+
if (section)
38+
return -ERANGE;
39+
40+
region->offset = 48;
41+
region->length = 16;
42+
43+
return 0;
44+
}
45+
46+
static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
47+
struct mtd_oob_region *region)
48+
{
49+
if (section)
50+
return -ERANGE;
51+
52+
region->offset = 1;
53+
region->length = 47;
54+
55+
return 0;
56+
}
57+
58+
static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
59+
.ecc = xt26g0xa_ooblayout_ecc,
60+
.free = xt26g0xa_ooblayout_free,
61+
};
62+
63+
static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
64+
u8 status)
65+
{
66+
status = status & XT26G0XA_STATUS_ECC_MASK;
67+
68+
switch (status) {
69+
case XT26G0XA_STATUS_ECC_NO_DETECTED:
70+
return 0;
71+
case XT26G0XA_STATUS_ECC_8_CORRECTED:
72+
return 8;
73+
case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
74+
return -EBADMSG;
75+
default:
76+
break;
77+
}
78+
79+
/* At this point values greater than (2 << 4) are invalid */
80+
if (status > XT26G0XA_STATUS_ECC_UNCOR_ERROR)
81+
return -EINVAL;
82+
83+
/* (1 << 2) through (7 << 2) are 1-7 corrected errors */
84+
return status >> 2;
85+
}
86+
87+
static const struct spinand_info xtx_spinand_table[] = {
88+
SPINAND_INFO("XT26G01A",
89+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE1),
90+
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
91+
NAND_ECCREQ(8, 512),
92+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
93+
&write_cache_variants,
94+
&update_cache_variants),
95+
SPINAND_HAS_QE_BIT,
96+
SPINAND_ECCINFO(&xt26g0xa_ooblayout,
97+
xt26g0xa_ecc_get_status)),
98+
SPINAND_INFO("XT26G02A",
99+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE2),
100+
NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
101+
NAND_ECCREQ(8, 512),
102+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
103+
&write_cache_variants,
104+
&update_cache_variants),
105+
SPINAND_HAS_QE_BIT,
106+
SPINAND_ECCINFO(&xt26g0xa_ooblayout,
107+
xt26g0xa_ecc_get_status)),
108+
SPINAND_INFO("XT26G04A",
109+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0xE3),
110+
NAND_MEMORG(1, 2048, 64, 128, 2048, 40, 1, 1, 1),
111+
NAND_ECCREQ(8, 512),
112+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
113+
&write_cache_variants,
114+
&update_cache_variants),
115+
SPINAND_HAS_QE_BIT,
116+
SPINAND_ECCINFO(&xt26g0xa_ooblayout,
117+
xt26g0xa_ecc_get_status)),
118+
};
119+
120+
static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
121+
};
122+
123+
const struct spinand_manufacturer xtx_spinand_manufacturer = {
124+
.id = SPINAND_MFR_XTX,
125+
.name = "XTX",
126+
.chips = xtx_spinand_table,
127+
.nchips = ARRAY_SIZE(xtx_spinand_table),
128+
.ops = &xtx_spinand_manuf_ops,
129+
};

include/linux/mtd/spinand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ extern const struct spinand_manufacturer micron_spinand_manufacturer;
266266
extern const struct spinand_manufacturer paragon_spinand_manufacturer;
267267
extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
268268
extern const struct spinand_manufacturer winbond_spinand_manufacturer;
269+
extern const struct spinand_manufacturer xtx_spinand_manufacturer;
269270

270271
/**
271272
* struct spinand_op_variants - SPI NAND operation variants

0 commit comments

Comments
 (0)