1 From 3552691616c940a7c4125c2678ba816653cd725e Mon Sep 17 00:00:00 2001
2 From: Jeff Kletsky <git-commits@allycomm.com>
3 Date: Tue, 18 Jun 2019 10:08:05 -0700
4 Subject: [PATCH] mtd: spinand: Add initial support for Paragon PN26G0xA
6 Add initial support for Paragon Technology
7 PN26G01Axxxxx and PN26G02Axxxxx SPI NAND
9 Datasheets available at
10 http://www.xtxtech.com/upfile/2016082517274590.pdf
11 http://www.xtxtech.com/upfile/2016082517282329.pdf
13 Signed-off-by: Jeff Kletsky <git-commits@allycomm.com>
14 Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
15 Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
17 ADOPTED FROM UPSTREAM due to upstream commit 377e517b5fa5 in Linux 5.2
18 which added another parameter to NAND_MEMORG
20 drivers/mtd/nand/spi/Makefile | 2 +-
21 drivers/mtd/nand/spi/core.c | 1 +
22 drivers/mtd/nand/spi/paragon.c | 147 +++++++++++++++++++++++++++++++++
23 include/linux/mtd/spinand.h | 1 +
24 4 files changed, 150 insertions(+), 1 deletion(-)
25 create mode 100644 drivers/mtd/nand/spi/paragon.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 toshiba.o winbond.o
32 +spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.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 @@ -763,6 +763,7 @@ static const struct spinand_manufacturer
37 &gigadevice_spinand_manufacturer,
38 ¯onix_spinand_manufacturer,
39 µn_spinand_manufacturer,
40 + ¶gon_spinand_manufacturer,
41 &toshiba_spinand_manufacturer,
42 &winbond_spinand_manufacturer,
45 +++ b/drivers/mtd/nand/spi/paragon.c
47 +// SPDX-License-Identifier: GPL-2.0
49 + * Copyright (C) 2019 Jeff Kletsky
51 + * Author: Jeff Kletsky <git-commits@allycomm.com>
54 +#include <linux/device.h>
55 +#include <linux/kernel.h>
56 +#include <linux/mtd/spinand.h>
59 +#define SPINAND_MFR_PARAGON 0xa1
62 +#define PN26G0XA_STATUS_ECC_BITMASK (3 << 4)
64 +#define PN26G0XA_STATUS_ECC_NONE_DETECTED (0 << 4)
65 +#define PN26G0XA_STATUS_ECC_1_7_CORRECTED (1 << 4)
66 +#define PN26G0XA_STATUS_ECC_ERRORED (2 << 4)
67 +#define PN26G0XA_STATUS_ECC_8_CORRECTED (3 << 4)
70 +static SPINAND_OP_VARIANTS(read_cache_variants,
71 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
72 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
73 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
74 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
75 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
76 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
78 +static SPINAND_OP_VARIANTS(write_cache_variants,
79 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
80 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
82 +static SPINAND_OP_VARIANTS(update_cache_variants,
83 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
84 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
87 +static int pn26g0xa_ooblayout_ecc(struct mtd_info *mtd, int section,
88 + struct mtd_oob_region *region)
93 + region->offset = 6 + (15 * section); /* 4 BBM + 2 user bytes */
94 + region->length = 13;
99 +static int pn26g0xa_ooblayout_free(struct mtd_info *mtd, int section,
100 + struct mtd_oob_region *region)
105 + if (section == 4) {
106 + region->offset = 64;
107 + region->length = 64;
109 + region->offset = 4 + (15 * section);
110 + region->length = 2;
116 +static int pn26g0xa_ecc_get_status(struct spinand_device *spinand,
119 + switch (status & PN26G0XA_STATUS_ECC_BITMASK) {
120 + case PN26G0XA_STATUS_ECC_NONE_DETECTED:
123 + case PN26G0XA_STATUS_ECC_1_7_CORRECTED:
124 + return 7; /* Return upper limit by convention */
126 + case PN26G0XA_STATUS_ECC_8_CORRECTED:
129 + case PN26G0XA_STATUS_ECC_ERRORED:
139 +static const struct mtd_ooblayout_ops pn26g0xa_ooblayout = {
140 + .ecc = pn26g0xa_ooblayout_ecc,
141 + .free = pn26g0xa_ooblayout_free,
145 +static const struct spinand_info paragon_spinand_table[] = {
146 + SPINAND_INFO("PN26G01A", 0xe1,
147 + NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
148 + NAND_ECCREQ(8, 512),
149 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
150 + &write_cache_variants,
151 + &update_cache_variants),
153 + SPINAND_ECCINFO(&pn26g0xa_ooblayout,
154 + pn26g0xa_ecc_get_status)),
155 + SPINAND_INFO("PN26G02A", 0xe2,
156 + NAND_MEMORG(1, 2048, 128, 64, 2048, 1, 1, 1),
157 + NAND_ECCREQ(8, 512),
158 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
159 + &write_cache_variants,
160 + &update_cache_variants),
162 + SPINAND_ECCINFO(&pn26g0xa_ooblayout,
163 + pn26g0xa_ecc_get_status)),
166 +static int paragon_spinand_detect(struct spinand_device *spinand)
168 + u8 *id = spinand->id.data;
171 + /* Read ID returns [0][MID][DID] */
173 + if (id[1] != SPINAND_MFR_PARAGON)
176 + ret = spinand_match_and_init(spinand, paragon_spinand_table,
177 + ARRAY_SIZE(paragon_spinand_table),
185 +static const struct spinand_manufacturer_ops paragon_spinand_manuf_ops = {
186 + .detect = paragon_spinand_detect,
189 +const struct spinand_manufacturer paragon_spinand_manufacturer = {
190 + .id = SPINAND_MFR_PARAGON,
192 + .ops = ¶gon_spinand_manuf_ops,
194 --- a/include/linux/mtd/spinand.h
195 +++ b/include/linux/mtd/spinand.h
196 @@ -227,6 +227,7 @@ struct spinand_manufacturer {
197 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
198 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
199 extern const struct spinand_manufacturer micron_spinand_manufacturer;
200 +extern const struct spinand_manufacturer paragon_spinand_manufacturer;
201 extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
202 extern const struct spinand_manufacturer winbond_spinand_manufacturer;