kernel: backport a rewrite of the mips eBPF JIT implementation
[openwrt/openwrt.git] / target / linux / generic / pending-5.10 / 483-mtd-spinand-add-support-for-xtx-xt26g0xa.patch
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
5
6 Add support for XTX Technology XT26G01AXXXXX, XTX26G02AXXXXX and
7 XTX26G04AXXXXX SPI NAND.
8
9 These are 3V, 1G/2G/4Gbit serial SLC NAND flash devices with on-die ECC
10 (8bit strength per 512bytes).
11
12 Tested on Teltonika RUTX10 flashed with OpenWrt.
13
14 Datasheets available at
15 http://www.xtxtech.com/download/?AId=225
16 https://datasheet.lcsc.com/szlcsc/2005251034_XTX-XT26G01AWSEGA_C558841.pdf
17
18 Signed-off-by: Felix Matouschek <felix@matouschek.org>
19 ---
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
26
27 --- a/drivers/mtd/nand/spi/Makefile
28 +++ b/drivers/mtd/nand/spi/Makefile
29 @@ -1,3 +1,3 @@
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 &paragon_spinand_manufacturer,
38 &toshiba_spinand_manufacturer,
39 &winbond_spinand_manufacturer,
40 + &xtx_spinand_manufacturer,
41 };
42
43 static int spinand_manufacturer_match(struct spinand_device *spinand,
44 --- /dev/null
45 +++ b/drivers/mtd/nand/spi/xtx.c
46 @@ -0,0 +1,122 @@
47 +// SPDX-License-Identifier: GPL-2.0
48 +/*
49 + * Author:
50 + * Felix Matouschek <felix@matouschek.org>
51 + */
52 +
53 +#include <linux/device.h>
54 +#include <linux/kernel.h>
55 +#include <linux/mtd/spinand.h>
56 +
57 +#define SPINAND_MFR_XTX 0x0B
58 +
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)
63 +
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));
71 +
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));
75 +
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));
79 +
80 +static int xt26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
81 + struct mtd_oob_region *region)
82 +{
83 + if (section)
84 + return -ERANGE;
85 +
86 + region->offset = 8;
87 + region->length = 40;
88 +
89 + return 0;
90 +}
91 +
92 +static int xt26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
93 + struct mtd_oob_region *region)
94 +{
95 + if (section)
96 + return -ERANGE;
97 +
98 + region->offset = 1;
99 + region->length = 7;
100 +
101 + return 0;
102 +}
103 +
104 +static const struct mtd_ooblayout_ops xt26g0xa_ooblayout = {
105 + .ecc = xt26g0xa_ooblayout_ecc,
106 + .free = xt26g0xa_ooblayout_free,
107 +};
108 +
109 +static int xt26g0xa_ecc_get_status(struct spinand_device *spinand,
110 + u8 status)
111 +{
112 + switch (status & XT26G0XA_STATUS_ECC_MASK) {
113 + case XT26G0XA_STATUS_ECC_NO_DETECTED:
114 + return 0;
115 + case XT26G0XA_STATUS_ECC_8_CORRECTED:
116 + return 8;
117 + case XT26G0XA_STATUS_ECC_UNCOR_ERROR:
118 + return -EBADMSG;
119 + default: /* (1 << 2) through (7 << 2) are 1-7 corrected errors */
120 + return (status & XT26G0XA_STATUS_ECC_MASK) >> 2;
121 + }
122 +
123 + return -EINVAL;
124 +}
125 +
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)),
157 +};
158 +
159 +static const struct spinand_manufacturer_ops xtx_spinand_manuf_ops = {
160 +};
161 +
162 +const struct spinand_manufacturer xtx_spinand_manufacturer = {
163 + .id = SPINAND_MFR_XTX,
164 + .name = "XTX",
165 + .chips = xtx_spinand_table,
166 + .nchips = ARRAY_SIZE(xtx_spinand_table),
167 + .ops = &xtx_spinand_manuf_ops,
168 +};
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;
176
177 /**
178 * struct spinand_op_variants - SPI NAND operation variants